net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / hal / btc / halbtc8822b1ant.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
17 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
18
19 #if (RTL8822B_SUPPORT == 1)
20 /* ************************************************************
21  * Global variables, these are static variables
22  * ************************************************************ */
23 static u8        *trace_buf = &gl_btc_trace_buf[0];
24 static struct  coex_dm_8822b_1ant               glcoex_dm_8822b_1ant;
25 static struct  coex_dm_8822b_1ant       *coex_dm = &glcoex_dm_8822b_1ant;
26 static struct  coex_sta_8822b_1ant              glcoex_sta_8822b_1ant;
27 static struct  coex_sta_8822b_1ant      *coex_sta = &glcoex_sta_8822b_1ant;
28 static struct  psdscan_sta_8822b_1ant   gl_psd_scan_8822b_1ant;
29 static struct  psdscan_sta_8822b_1ant *psd_scan = &gl_psd_scan_8822b_1ant;
30 static struct   rfe_type_8822b_1ant             gl_rfe_type_8822b_1ant;
31 static struct   rfe_type_8822b_1ant             *rfe_type = &gl_rfe_type_8822b_1ant;
32
33
34
35 const char *const glbt_info_src_8822b_1ant[] = {
36         "BT Info[wifi fw]",
37         "BT Info[bt rsp]",
38         "BT Info[bt auto report]",
39 };
40
41 u32     glcoex_ver_date_8822b_1ant = 20161026;
42 u32     glcoex_ver_8822b_1ant = 0x34;
43 u32     glcoex_ver_btdesired_8822b_1ant = 0x28;
44
45
46 /* ************************************************************
47  * local function proto type if needed
48  * ************************************************************
49  * ************************************************************
50  * local function start with halbtc8822b1ant_
51  * ************************************************************ */
52 u8 halbtc8822b1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
53 {
54         s32                     bt_rssi = 0;
55         u8                      bt_rssi_state = coex_sta->pre_bt_rssi_state;
56
57         bt_rssi = coex_sta->bt_rssi;
58
59         if (level_num == 2) {
60                 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
61                     (coex_sta->pre_bt_rssi_state ==
62                      BTC_RSSI_STATE_STAY_LOW)) {
63                         if (bt_rssi >= (rssi_thresh +
64                                         BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
65                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
66                         else
67                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
68                 } else {
69                         if (bt_rssi < rssi_thresh)
70                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
71                         else
72                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
73                 }
74         } else if (level_num == 3) {
75                 if (rssi_thresh > rssi_thresh1) {
76                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
77                                     "[BTCoex], BT Rssi thresh error!!\n");
78                         BTC_TRACE(trace_buf);
79                         return coex_sta->pre_bt_rssi_state;
80                 }
81
82                 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
83                     (coex_sta->pre_bt_rssi_state ==
84                      BTC_RSSI_STATE_STAY_LOW)) {
85                         if (bt_rssi >= (rssi_thresh +
86                                         BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
87                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
88                         else
89                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
90                 } else if ((coex_sta->pre_bt_rssi_state ==
91                             BTC_RSSI_STATE_MEDIUM) ||
92                            (coex_sta->pre_bt_rssi_state ==
93                             BTC_RSSI_STATE_STAY_MEDIUM)) {
94                         if (bt_rssi >= (rssi_thresh1 +
95                                         BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
96                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
97                         else if (bt_rssi < rssi_thresh)
98                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
99                         else
100                                 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
101                 } else {
102                         if (bt_rssi < rssi_thresh1)
103                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
104                         else
105                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
106                 }
107         }
108
109         coex_sta->pre_bt_rssi_state = bt_rssi_state;
110
111         return bt_rssi_state;
112 }
113
114 u8 halbtc8822b1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
115            IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
116 {
117         s32                     wifi_rssi = 0;
118         u8                      wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
119
120         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
121
122         if (level_num == 2) {
123                 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
124                     ||
125                     (coex_sta->pre_wifi_rssi_state[index] ==
126                      BTC_RSSI_STATE_STAY_LOW)) {
127                         if (wifi_rssi >= (rssi_thresh +
128                                           BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
129                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
130                         else
131                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
132                 } else {
133                         if (wifi_rssi < rssi_thresh)
134                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
135                         else
136                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
137                 }
138         } else if (level_num == 3) {
139                 if (rssi_thresh > rssi_thresh1) {
140                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
141                                     "[BTCoex], wifi RSSI thresh error!!\n");
142                         BTC_TRACE(trace_buf);
143                         return coex_sta->pre_wifi_rssi_state[index];
144                 }
145
146                 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
147                     ||
148                     (coex_sta->pre_wifi_rssi_state[index] ==
149                      BTC_RSSI_STATE_STAY_LOW)) {
150                         if (wifi_rssi >= (rssi_thresh +
151                                           BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
152                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
153                         else
154                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
155                 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
156                             BTC_RSSI_STATE_MEDIUM) ||
157                            (coex_sta->pre_wifi_rssi_state[index] ==
158                             BTC_RSSI_STATE_STAY_MEDIUM)) {
159                         if (wifi_rssi >= (rssi_thresh1 +
160                                           BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
161                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
162                         else if (wifi_rssi < rssi_thresh)
163                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
164                         else
165                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
166                 } else {
167                         if (wifi_rssi < rssi_thresh1)
168                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
169                         else
170                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
171                 }
172         }
173
174         coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
175
176         return wifi_rssi_state;
177 }
178
179 void halbtc8822b1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
180                                     IN boolean force_exec, IN u32 dis_rate_mask)
181 {
182         coex_dm->cur_ra_mask = dis_rate_mask;
183
184         if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
185                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
186                                    &coex_dm->cur_ra_mask);
187         coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
188 }
189
190 void halbtc8822b1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
191                 IN boolean force_exec, IN u8 type)
192 {
193         boolean wifi_under_b_mode = false;
194
195         coex_dm->cur_arfr_type = type;
196
197         if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
198                 switch (coex_dm->cur_arfr_type) {
199                 case 0: /* normal mode */
200                         btcoexist->btc_write_4byte(btcoexist, 0x430,
201                                                    coex_dm->backup_arfr_cnt1);
202                         btcoexist->btc_write_4byte(btcoexist, 0x434,
203                                                    coex_dm->backup_arfr_cnt2);
204                         break;
205                 case 1:
206                         btcoexist->btc_get(btcoexist,
207                                            BTC_GET_BL_WIFI_UNDER_B_MODE,
208                                            &wifi_under_b_mode);
209                         if (wifi_under_b_mode) {
210                                 btcoexist->btc_write_4byte(btcoexist,
211                                                            0x430, 0x0);
212                                 btcoexist->btc_write_4byte(btcoexist,
213                                                            0x434, 0x01010101);
214                         } else {
215                                 btcoexist->btc_write_4byte(btcoexist,
216                                                            0x430, 0x0);
217                                 btcoexist->btc_write_4byte(btcoexist,
218                                                            0x434, 0x04030201);
219                         }
220                         break;
221                 default:
222                         break;
223                 }
224         }
225
226         coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
227 }
228
229 void halbtc8822b1ant_retry_limit(IN struct btc_coexist *btcoexist,
230                                  IN boolean force_exec, IN u8 type)
231 {
232         coex_dm->cur_retry_limit_type = type;
233
234         if (force_exec ||
235             (coex_dm->pre_retry_limit_type !=
236              coex_dm->cur_retry_limit_type)) {
237                 switch (coex_dm->cur_retry_limit_type) {
238                 case 0: /* normal mode */
239                         btcoexist->btc_write_2byte(btcoexist, 0x42a,
240                                                    coex_dm->backup_retry_limit);
241                         break;
242                 case 1: /* retry limit=8 */
243                         btcoexist->btc_write_2byte(btcoexist, 0x42a,
244                                                    0x0808);
245                         break;
246                 default:
247                         break;
248                 }
249         }
250
251         coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
252 }
253
254 void halbtc8822b1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
255                                     IN boolean force_exec, IN u8 type)
256 {
257         coex_dm->cur_ampdu_time_type = type;
258
259         if (force_exec ||
260             (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
261                 switch (coex_dm->cur_ampdu_time_type) {
262                 case 0: /* normal mode */
263                         btcoexist->btc_write_1byte(btcoexist, 0x456,
264                                            coex_dm->backup_ampdu_max_time);
265                         break;
266                 case 1: /* AMPDU timw = 0x38 * 32us */
267                         btcoexist->btc_write_1byte(btcoexist, 0x456,
268                                                    0x38);
269                         break;
270                 default:
271                         break;
272                 }
273         }
274
275         coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
276 }
277
278 void halbtc8822b1ant_limited_tx(IN struct btc_coexist *btcoexist,
279                 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
280                                 IN u8 retry_limit_type, IN u8 ampdu_time_type)
281 {
282         switch (ra_mask_type) {
283         case 0: /* normal mode */
284                 halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
285                                                0x0);
286                 break;
287         case 1: /* disable cck 1/2 */
288                 halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
289                                                0x00000003);
290                 break;
291         case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
292                 halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
293                                                0x0001f1f7);
294                 break;
295         default:
296                 break;
297         }
298
299         halbtc8822b1ant_auto_rate_fallback_retry(btcoexist, force_exec,
300                         arfr_type);
301         halbtc8822b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
302         halbtc8822b1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
303 }
304
305 /*
306 rx agg size setting :
307 1:      true / don't care / don't care
308 max: false / false / don't care
309 7:     false / true / 7
310 */
311
312 void halbtc8822b1ant_limited_rx(IN struct btc_coexist *btcoexist,
313                         IN boolean force_exec, IN boolean rej_ap_agg_pkt,
314                         IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
315 {
316         boolean reject_rx_agg = rej_ap_agg_pkt;
317         boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
318         u8      rx_agg_size = agg_buf_size;
319
320         /* ============================================ */
321         /*      Rx Aggregation related setting */
322         /* ============================================ */
323         btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
324                            &reject_rx_agg);
325         /* decide BT control aggregation buf size or not */
326         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
327                            &bt_ctrl_rx_agg_size);
328         /* aggregation buf size, only work when BT control Rx aggregation size. */
329         btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
330         /* real update aggregation setting */
331         btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
332
333
334 }
335
336 void halbtc8822b1ant_query_bt_info(IN struct btc_coexist *btcoexist)
337 {
338         u8                      h2c_parameter[1] = {0};
339
340         coex_sta->c2h_bt_info_req_sent = true;
341
342         h2c_parameter[0] |= BIT(0);     /* trigger */
343
344         btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
345 }
346
347 void halbtc8822b1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
348 {
349         u32                     reg_hp_txrx, reg_lp_txrx, u32tmp;
350         u32                     reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
351         static u8               num_of_bt_counter_chk = 0, cnt_slave = 0;
352         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
353
354         /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
355         /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
356
357         if (coex_sta->under_ips) {
358                 /* coex_sta->high_priority_tx = 65535; */
359                 /* coex_sta->high_priority_rx = 65535; */
360                 /* coex_sta->low_priority_tx = 65535; */
361                 /* coex_sta->low_priority_rx = 65535; */
362                 /* return; */
363         }
364
365         reg_hp_txrx = 0x770;
366         reg_lp_txrx = 0x774;
367
368         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
369         reg_hp_tx = u32tmp & MASKLWORD;
370         reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
371
372         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
373         reg_lp_tx = u32tmp & MASKLWORD;
374         reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
375
376         coex_sta->high_priority_tx = reg_hp_tx;
377         coex_sta->high_priority_rx = reg_hp_rx;
378         coex_sta->low_priority_tx = reg_lp_tx;
379         coex_sta->low_priority_rx = reg_lp_rx;
380
381         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
382                     "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
383                     reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
384         BTC_TRACE(trace_buf);
385
386         /* reset counter */
387         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
388
389         if ((coex_sta->low_priority_tx > 1150)  &&
390             (!coex_sta->c2h_bt_inquiry_page))
391                 coex_sta->pop_event_cnt++;
392
393         if ((coex_sta->low_priority_rx >= 1150) &&
394             (coex_sta->low_priority_rx >= coex_sta->low_priority_tx)
395             && (!coex_sta->under_ips)  &&
396             (!coex_sta->c2h_bt_inquiry_page) &&
397             (coex_sta->bt_link_exist))  {
398                 if (cnt_slave >= 3) {
399                         bt_link_info->slave_role = true;
400                         cnt_slave = 3;
401                 } else
402                         cnt_slave++;
403         } else {
404                 if (cnt_slave == 0)     {
405                         bt_link_info->slave_role = false;
406                         cnt_slave = 0;
407                 } else
408                         cnt_slave--;
409
410         }
411
412         if ((coex_sta->high_priority_tx == 0) &&
413             (coex_sta->high_priority_rx == 0) &&
414             (coex_sta->low_priority_tx == 0) &&
415             (coex_sta->low_priority_rx == 0)) {
416                 num_of_bt_counter_chk++;
417
418                 if (num_of_bt_counter_chk >= 3) {
419                         halbtc8822b1ant_query_bt_info(
420                                 btcoexist);
421                         num_of_bt_counter_chk = 0;
422                 }
423         }
424 #if 0
425         /* Add Hi-Pri Tx/Rx counter to avoid false detection */
426         if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) &&
427             (coex_sta->high_priority_tx + coex_sta->high_priority_rx
428              >= 160)
429             && (!coex_sta->c2h_bt_inquiry_page))
430                 coex_sta->bt_hi_pri_link_exist = true;
431         else
432                 coex_sta->bt_hi_pri_link_exist = false;
433
434         if ((coex_sta->acl_busy) &&
435             (coex_sta->num_of_profile == 0)) {
436                 if (coex_sta->low_priority_tx +
437                     coex_sta->low_priority_rx >= 160) {
438                         coex_sta->pan_exist = true;
439                         coex_sta->num_of_profile++;
440                         coex_sta->wrong_profile_notification++;
441                 }
442         }
443 #endif
444
445 }
446
447
448 void halbtc8822b1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
449 {
450         s32 wifi_rssi = 0;
451         boolean wifi_busy = false, wifi_under_b_mode = false;
452         static u8 cck_lock_counter = 0;
453         u32 total_cnt;
454
455         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
456         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
457         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
458                            &wifi_under_b_mode);
459
460         if (coex_sta->under_ips) {
461                 coex_sta->crc_ok_cck = 0;
462                 coex_sta->crc_ok_11g = 0;
463                 coex_sta->crc_ok_11n = 0;
464                 coex_sta->crc_ok_11n_agg = 0;
465
466                 coex_sta->crc_err_cck = 0;
467                 coex_sta->crc_err_11g = 0;
468                 coex_sta->crc_err_11n = 0;
469                 coex_sta->crc_err_11n_agg = 0;
470         } else {
471                 coex_sta->crc_ok_cck    = btcoexist->btc_read_2byte(
472                                                   btcoexist,
473                                                   0xf04);
474                 coex_sta->crc_ok_11g    = btcoexist->btc_read_2byte(
475                                                   btcoexist,
476                                                   0xf14);
477                 coex_sta->crc_ok_11n    = btcoexist->btc_read_2byte(
478                                                   btcoexist,
479                                                   0xf10);
480                 coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(
481                                                    btcoexist,
482                                                    0xf0c);
483
484                 coex_sta->crc_err_cck    = btcoexist->btc_read_2byte(
485                            btcoexist, 0xf00) +  btcoexist->btc_read_2byte(
486                                                    btcoexist, 0xf06);
487
488                 coex_sta->crc_err_11g    = btcoexist->btc_read_2byte(
489                                                    btcoexist,
490                                                    0xf16);
491                 coex_sta->crc_err_11n    = btcoexist->btc_read_2byte(
492                                                    btcoexist,
493                                                    0xf12);
494                 coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(
495                                                     btcoexist,
496                                                     0xf0e);
497         }
498
499
500         /* reset counter */
501         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);
502         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);
503
504         if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
505                 total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g
506                             +
507                             coex_sta->crc_ok_11n +
508                             coex_sta->crc_ok_11n_agg;
509
510                 if ((coex_dm->bt_status ==
511                      BT_8822B_1ANT_BT_STATUS_ACL_BUSY) ||
512                     (coex_dm->bt_status ==
513                      BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
514                     (coex_dm->bt_status ==
515                      BT_8822B_1ANT_BT_STATUS_SCO_BUSY)) {
516                         if (coex_sta->crc_ok_cck > (total_cnt -
517                                                     coex_sta->crc_ok_cck)) {
518                                 if (cck_lock_counter < 3)
519                                         cck_lock_counter++;
520                         } else {
521                                 if (cck_lock_counter > 0)
522                                         cck_lock_counter--;
523                         }
524
525                 } else {
526                         if (cck_lock_counter > 0)
527                                 cck_lock_counter--;
528                 }
529         } else {
530                 if (cck_lock_counter > 0)
531                         cck_lock_counter--;
532         }
533
534         if (!coex_sta->pre_ccklock) {
535
536                 if (cck_lock_counter >= 3)
537                         coex_sta->cck_lock = true;
538                 else
539                         coex_sta->cck_lock = false;
540         } else {
541                 if (cck_lock_counter == 0)
542                         coex_sta->cck_lock = false;
543                 else
544                         coex_sta->cck_lock = true;
545         }
546
547         if (coex_sta->cck_lock)
548                 coex_sta->cck_ever_lock = true;
549
550         coex_sta->pre_ccklock =  coex_sta->cck_lock;
551
552
553 }
554
555
556 boolean halbtc8822b1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
557 {
558         static boolean  pre_wifi_busy = false, pre_under_4way = false,
559                         pre_bt_hs_on = false, pre_bt_off = false;
560         boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
561         boolean wifi_connected = false;
562
563         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
564                            &wifi_connected);
565         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
566         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
567         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
568                            &under_4way);
569         if (coex_sta->bt_disabled != pre_bt_off) {
570                 pre_bt_off = coex_sta->bt_disabled;
571
572                 if (coex_sta->bt_disabled)
573                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
574                                     "[BTCoex], BT is disabled !!\n");
575                 else
576                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
577                                     "[BTCoex], BT is enabled !!\n");
578
579                 BTC_TRACE(trace_buf);
580
581                 coex_sta->bt_coex_supported_feature = 0;
582                 coex_sta->bt_coex_supported_version = 0;
583                 return true;
584         }
585
586         if (wifi_connected) {
587                 if (wifi_busy != pre_wifi_busy) {
588                         pre_wifi_busy = wifi_busy;
589                         return true;
590                 }
591                 if (under_4way != pre_under_4way) {
592                         pre_under_4way = under_4way;
593                         return true;
594                 }
595                 if (bt_hs_on != pre_bt_hs_on) {
596                         pre_bt_hs_on = bt_hs_on;
597                         return true;
598                 }
599         }
600
601         return false;
602 }
603
604 void halbtc8822b1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
605 {
606         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
607         boolean                         bt_hs_on = false;
608
609         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
610
611         bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
612         bt_link_info->sco_exist = coex_sta->sco_exist;
613         bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
614         bt_link_info->pan_exist = coex_sta->pan_exist;
615         bt_link_info->hid_exist = coex_sta->hid_exist;
616         bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist;
617         bt_link_info->acl_busy = coex_sta->acl_busy;
618
619         /* work around for HS mode. */
620         if (bt_hs_on) {
621                 bt_link_info->pan_exist = true;
622                 bt_link_info->bt_link_exist = true;
623         }
624
625         /* check if Sco only */
626         if (bt_link_info->sco_exist &&
627             !bt_link_info->a2dp_exist &&
628             !bt_link_info->pan_exist &&
629             !bt_link_info->hid_exist)
630                 bt_link_info->sco_only = true;
631         else
632                 bt_link_info->sco_only = false;
633
634         /* check if A2dp only */
635         if (!bt_link_info->sco_exist &&
636             bt_link_info->a2dp_exist &&
637             !bt_link_info->pan_exist &&
638             !bt_link_info->hid_exist)
639                 bt_link_info->a2dp_only = true;
640         else
641                 bt_link_info->a2dp_only = false;
642
643         /* check if Pan only */
644         if (!bt_link_info->sco_exist &&
645             !bt_link_info->a2dp_exist &&
646             bt_link_info->pan_exist &&
647             !bt_link_info->hid_exist)
648                 bt_link_info->pan_only = true;
649         else
650                 bt_link_info->pan_only = false;
651
652         /* check if Hid only */
653         if (!bt_link_info->sco_exist &&
654             !bt_link_info->a2dp_exist &&
655             !bt_link_info->pan_exist &&
656             bt_link_info->hid_exist)
657                 bt_link_info->hid_only = true;
658         else
659                 bt_link_info->hid_only = false;
660 }
661
662 void halbtc8822b1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist,
663                 IN u8 type)
664 {
665         u8                      h2c_parameter[3] = {0};
666         u32                     wifi_bw;
667         u8                      wifi_central_chnl;
668
669         /* only 2.4G we need to inform bt the chnl mask */
670         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
671                            &wifi_central_chnl);
672         if ((BTC_MEDIA_CONNECT == type) &&
673             (wifi_central_chnl <= 14)) {
674
675                 h2c_parameter[0] =
676                         0x1;  /* enable BT AFH skip WL channel for 8822b because BT Rx LO interference */
677                 h2c_parameter[1] = wifi_central_chnl;
678
679                 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
680
681                 if (BTC_WIFI_BW_HT40 == wifi_bw)
682                         h2c_parameter[2] = 0x30;
683                 else
684                         h2c_parameter[2] = 0x20;
685         }
686
687         coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
688         coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
689         coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
690
691         btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
692
693 }
694
695 u8 halbtc8822b1ant_action_algorithm(IN struct btc_coexist *btcoexist)
696 {
697         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
698         boolean                         bt_hs_on = false;
699         u8                              algorithm = BT_8822B_1ANT_COEX_ALGO_UNDEFINED;
700         u8                              num_of_diff_profile = 0;
701
702         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
703
704         if (!bt_link_info->bt_link_exist) {
705                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
706                             "[BTCoex], No BT link exists!!!\n");
707                 BTC_TRACE(trace_buf);
708                 return algorithm;
709         }
710
711         if (bt_link_info->sco_exist)
712                 num_of_diff_profile++;
713         if (bt_link_info->hid_exist)
714                 num_of_diff_profile++;
715         if (bt_link_info->pan_exist)
716                 num_of_diff_profile++;
717         if (bt_link_info->a2dp_exist)
718                 num_of_diff_profile++;
719
720         if (num_of_diff_profile == 1) {
721                 if (bt_link_info->sco_exist) {
722                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
723                                     "[BTCoex], BT Profile = SCO only\n");
724                         BTC_TRACE(trace_buf);
725                         algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
726                 } else {
727                         if (bt_link_info->hid_exist) {
728                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
729                                         "[BTCoex], BT Profile = HID only\n");
730                                 BTC_TRACE(trace_buf);
731                                 algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
732                         } else if (bt_link_info->a2dp_exist) {
733                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
734                                         "[BTCoex], BT Profile = A2DP only\n");
735                                 BTC_TRACE(trace_buf);
736                                 algorithm = BT_8822B_1ANT_COEX_ALGO_A2DP;
737                         } else if (bt_link_info->pan_exist) {
738                                 if (bt_hs_on) {
739                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
740                                                 "[BTCoex], BT Profile = PAN(HS) only\n");
741                                         BTC_TRACE(trace_buf);
742                                         algorithm =
743                                                 BT_8822B_1ANT_COEX_ALGO_PANHS;
744                                 } else {
745                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
746                                                 "[BTCoex], BT Profile = PAN(EDR) only\n");
747                                         BTC_TRACE(trace_buf);
748                                         algorithm =
749                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR;
750                                 }
751                         }
752                 }
753         } else if (num_of_diff_profile == 2) {
754                 if (bt_link_info->sco_exist) {
755                         if (bt_link_info->hid_exist) {
756                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
757                                         "[BTCoex], BT Profile = SCO + HID\n");
758                                 BTC_TRACE(trace_buf);
759                                 algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
760                         } else if (bt_link_info->a2dp_exist) {
761                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
762                                         "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
763                                 BTC_TRACE(trace_buf);
764                                 algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
765                         } else if (bt_link_info->pan_exist) {
766                                 if (bt_hs_on) {
767                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
768                                                 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
769                                         BTC_TRACE(trace_buf);
770                                         algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
771                                 } else {
772                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
773                                                 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
774                                         BTC_TRACE(trace_buf);
775                                         algorithm =
776                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
777                                 }
778                         }
779                 } else {
780                         if (bt_link_info->hid_exist &&
781                             bt_link_info->a2dp_exist) {
782                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
783                                         "[BTCoex], BT Profile = HID + A2DP\n");
784                                 BTC_TRACE(trace_buf);
785                                 algorithm = BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
786                         } else if (bt_link_info->hid_exist &&
787                                    bt_link_info->pan_exist) {
788                                 if (bt_hs_on) {
789                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
790                                                 "[BTCoex], BT Profile = HID + PAN(HS)\n");
791                                         BTC_TRACE(trace_buf);
792                                         algorithm =
793                                                 BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
794                                 } else {
795                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
796                                                 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
797                                         BTC_TRACE(trace_buf);
798                                         algorithm =
799                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
800                                 }
801                         } else if (bt_link_info->pan_exist &&
802                                    bt_link_info->a2dp_exist) {
803                                 if (bt_hs_on) {
804                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
805                                                 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
806                                         BTC_TRACE(trace_buf);
807                                         algorithm =
808                                                 BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS;
809                                 } else {
810                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
811                                                 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
812                                         BTC_TRACE(trace_buf);
813                                         algorithm =
814                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP;
815                                 }
816                         }
817                 }
818         } else if (num_of_diff_profile == 3) {
819                 if (bt_link_info->sco_exist) {
820                         if (bt_link_info->hid_exist &&
821                             bt_link_info->a2dp_exist) {
822                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
823                                         "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
824                                 BTC_TRACE(trace_buf);
825                                 algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
826                         } else if (bt_link_info->hid_exist &&
827                                    bt_link_info->pan_exist) {
828                                 if (bt_hs_on) {
829                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
830                                                 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
831                                         BTC_TRACE(trace_buf);
832                                         algorithm =
833                                                 BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
834                                 } else {
835                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
836                                                 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
837                                         BTC_TRACE(trace_buf);
838                                         algorithm =
839                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
840                                 }
841                         } else if (bt_link_info->pan_exist &&
842                                    bt_link_info->a2dp_exist) {
843                                 if (bt_hs_on) {
844                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
845                                                 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
846                                         BTC_TRACE(trace_buf);
847                                         algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
848                                 } else {
849                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
850                                                 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
851                                         BTC_TRACE(trace_buf);
852                                         algorithm =
853                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
854                                 }
855                         }
856                 } else {
857                         if (bt_link_info->hid_exist &&
858                             bt_link_info->pan_exist &&
859                             bt_link_info->a2dp_exist) {
860                                 if (bt_hs_on) {
861                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
862                                                 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
863                                         BTC_TRACE(trace_buf);
864                                         algorithm =
865                                                 BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
866                                 } else {
867                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
868                                                 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
869                                         BTC_TRACE(trace_buf);
870                                         algorithm =
871                                                 BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
872                                 }
873                         }
874                 }
875         } else if (num_of_diff_profile >= 3) {
876                 if (bt_link_info->sco_exist) {
877                         if (bt_link_info->hid_exist &&
878                             bt_link_info->pan_exist &&
879                             bt_link_info->a2dp_exist) {
880                                 if (bt_hs_on) {
881                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
882                                                 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
883                                         BTC_TRACE(trace_buf);
884
885                                 } else {
886                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
887                                                 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
888                                         BTC_TRACE(trace_buf);
889                                         algorithm =
890                                                 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
891                                 }
892                         }
893                 }
894         }
895
896         return algorithm;
897 }
898
899 void halbtc8822b1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
900                                         IN boolean enable_auto_report)
901 {
902         u8                      h2c_parameter[1] = {0};
903
904         h2c_parameter[0] = 0;
905
906         if (enable_auto_report)
907                 h2c_parameter[0] |= BIT(0);
908
909         btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
910 }
911
912 void halbtc8822b1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
913                     IN boolean force_exec, IN boolean enable_auto_report)
914 {
915         coex_dm->cur_bt_auto_report = enable_auto_report;
916
917         if (!force_exec) {
918                 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
919                         return;
920         }
921         halbtc8822b1ant_set_bt_auto_report(btcoexist,
922                                            coex_dm->cur_bt_auto_report);
923
924         coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
925 }
926
927
928
929 void halbtc8822b1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
930                 *btcoexist, IN boolean low_penalty_ra)
931 {
932         u8                      h2c_parameter[6] = {0};
933
934         h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
935
936         if (low_penalty_ra) {
937                 h2c_parameter[1] |= BIT(0);
938                 h2c_parameter[2] =
939                         0x00;  /* normal rate except MCS7/6/5, OFDM54/48/36 */
940                 h2c_parameter[3] = 0xf7;  /* MCS7 or OFDM54 */
941                 h2c_parameter[4] = 0xf8;  /* MCS6 or OFDM48 */
942                 h2c_parameter[5] = 0xf9;        /* MCS5 or OFDM36        */
943         }
944
945         btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
946 }
947
948 void halbtc8822b1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
949                             IN boolean force_exec, IN boolean low_penalty_ra)
950 {
951 #if 1
952         coex_dm->cur_low_penalty_ra = low_penalty_ra;
953
954         if (!force_exec) {
955                 if (coex_dm->pre_low_penalty_ra ==
956                     coex_dm->cur_low_penalty_ra)
957                         return;
958         }
959
960         if (low_penalty_ra)
961                 btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
962         else
963                 btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0);
964
965         coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
966
967 #endif
968 }
969
970 void halbtc8822b1ant_write_score_board(
971         IN      struct  btc_coexist             *btcoexist,
972         IN      u16                             bitpos,
973         IN      boolean         state
974 )
975 {
976
977         static u16 originalval = 0x8002;
978
979         if (state)
980                 originalval = originalval | bitpos;
981         else
982                 originalval = originalval & (~bitpos);
983
984         btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
985 }
986
987 void halbtc8822b1ant_read_score_board(
988         IN      struct  btc_coexist             *btcoexist,
989         IN   u16                                *score_board_val
990 )
991 {
992
993         *score_board_val = (btcoexist->btc_read_2byte(btcoexist,
994                             0xaa)) & 0x7fff;
995 }
996
997 void halbtc8822b1ant_post_state_to_bt(
998         IN      struct  btc_coexist             *btcoexist,
999         IN      u16                                             type,
1000         IN  boolean                 state
1001 )
1002 {
1003
1004         halbtc8822b1ant_write_score_board(btcoexist, (u16) type, state);
1005
1006 }
1007
1008
1009 void halbtc8822b1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1010 {
1011         static u32              bt_disable_cnt = 0;
1012         boolean                 bt_active = true, bt_disabled = false,
1013                                 wifi_under_5g = false;
1014         u16             u16tmp;
1015
1016         /* This function check if bt is disabled */
1017 #if 0
1018         if (coex_sta->high_priority_tx == 0 &&
1019             coex_sta->high_priority_rx == 0 &&
1020             coex_sta->low_priority_tx == 0 &&
1021             coex_sta->low_priority_rx == 0)
1022                 bt_active = false;
1023         if (coex_sta->high_priority_tx == 0xffff &&
1024             coex_sta->high_priority_rx == 0xffff &&
1025             coex_sta->low_priority_tx == 0xffff &&
1026             coex_sta->low_priority_rx == 0xffff)
1027                 bt_active = false;
1028
1029
1030 #else
1031
1032         /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */
1033         halbtc8822b1ant_read_score_board(btcoexist, &u16tmp);
1034
1035         bt_active = u16tmp & BIT(1);
1036
1037
1038 #endif
1039
1040         if (bt_active) {
1041                 bt_disable_cnt = 0;
1042                 bt_disabled = false;
1043                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1044                                    &bt_disabled);
1045         } else {
1046
1047                 bt_disable_cnt++;
1048                 if (bt_disable_cnt >= 2) {
1049                         bt_disabled = true;
1050                         bt_disable_cnt = 2;
1051                 }
1052
1053                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1054                                    &bt_disabled);
1055         }
1056
1057
1058         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
1059                            &wifi_under_5g);
1060
1061         if ((wifi_under_5g) || (bt_disabled))
1062                 halbtc8822b1ant_low_penalty_ra(btcoexist,
1063                                                NORMAL_EXEC, false);
1064         else
1065                 halbtc8822b1ant_low_penalty_ra(btcoexist,
1066                                                NORMAL_EXEC, true);
1067
1068
1069         if (coex_sta->bt_disabled != bt_disabled) {
1070                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1071                             "[BTCoex], BT is from %s to %s!!\n",
1072                             (coex_sta->bt_disabled ? "disabled" :
1073                              "enabled"),
1074                             (bt_disabled ? "disabled" : "enabled"));
1075                 BTC_TRACE(trace_buf);
1076                 coex_sta->bt_disabled = bt_disabled;
1077         }
1078
1079 }
1080
1081
1082
1083 void halbtc8822b1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist,
1084                                         boolean isenable)
1085 {
1086         static u8                       bitVal[5] = {0, 0, 0, 0, 0};
1087         static boolean          state = false;
1088
1089         if (state == isenable)
1090                 return;
1091
1092         state = isenable;
1093
1094         if (isenable) {
1095
1096                 /* enable GNT_WL, GNT_BT to GPIO for debug */
1097                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
1098
1099                 /* store original value */
1100                 bitVal[0] = (btcoexist->btc_read_1byte(btcoexist,
1101                                        0x66) & BIT(4)) >> 4;    /*0x66[4] */
1102                 bitVal[1] = (btcoexist->btc_read_1byte(btcoexist,
1103                                                0x67) & BIT(0));         /*0x66[8] */
1104                 bitVal[2] = (btcoexist->btc_read_1byte(btcoexist,
1105                                        0x42) & BIT(3)) >> 3;  /*0x40[19] */
1106                 bitVal[3] = (btcoexist->btc_read_1byte(btcoexist,
1107                                        0x65) & BIT(7)) >> 7;  /*0x64[15] */
1108                 bitVal[4] = (btcoexist->btc_read_1byte(btcoexist,
1109                                        0x72) & BIT(2)) >> 2;  /*0x70[18] */
1110
1111                 /*  switch GPIO Mux */
1112                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1113                                                    0x0);  /*0x66[4] = 0 */
1114                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1115                                                    0x0);  /*0x66[8] = 0 */
1116                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1117                                                    0x0);  /*0x40[19] = 0 */
1118                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1119                                                    0x0);  /*0x64[15] = 0 */
1120                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1121                                                    0x0);  /*0x70[18] = 0 */
1122
1123
1124         } else {
1125                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
1126
1127                 /*  Restore original value  */
1128                 /*  switch GPIO Mux */
1129                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1130                                                    bitVal[0]);  /*0x66[4] = 0 */
1131                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1132                                                    bitVal[1]);  /*0x66[8] = 0 */
1133                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1134                                            bitVal[2]);  /*0x40[19] = 0 */
1135                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1136                                            bitVal[3]);  /*0x64[15] = 0 */
1137                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1138                                            bitVal[4]);  /*0x70[18] = 0 */
1139         }
1140
1141 }
1142
1143
1144 u32 halbtc8822b1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist,
1145                 IN u16 reg_addr)
1146 {
1147         u32 j = 0;
1148
1149
1150         /* wait for ready bit before access 0x1700               */
1151         btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
1152
1153         do {
1154                 j++;
1155         } while (((btcoexist->btc_read_1byte(btcoexist,
1156                                              0x1703) & BIT(5)) == 0) &&
1157                  (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
1158
1159
1160         return btcoexist->btc_read_4byte(btcoexist,
1161                                          0x1708);  /* get read data */
1162
1163 }
1164
1165 void halbtc8822b1ant_ltecoex_indirect_write_reg(IN struct btc_coexist
1166                 *btcoexist,
1167                 IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value)
1168 {
1169         u32 val, i = 0, j = 0, bitpos = 0;
1170
1171
1172         if (bit_mask == 0x0)
1173                 return;
1174         if (bit_mask == 0xffffffff) {
1175                 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1176                                            reg_value); /* put write data */
1177
1178                 /* wait for ready bit before access 0x1700 */
1179                 do {
1180                         j++;
1181                 } while (((btcoexist->btc_read_1byte(btcoexist,
1182                                                      0x1703) & BIT(5)) == 0) &&
1183                         (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
1184
1185
1186                 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1187                                            0xc00F0000 | reg_addr);
1188         } else {
1189                 for (i = 0; i <= 31; i++) {
1190                         if (((bit_mask >> i) & 0x1) == 0x1) {
1191                                 bitpos = i;
1192                                 break;
1193                         }
1194                 }
1195
1196                 /* read back register value before write */
1197                 val = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
1198                                 reg_addr);
1199                 val = (val & (~bit_mask)) | (reg_value << bitpos);
1200
1201                 /* put write data value */
1202                 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1203                                            val); /* put write data */
1204
1205                 /* wait for ready bit before access 0x1700               */
1206                 do {
1207                         j++;
1208                 } while (((btcoexist->btc_read_1byte(btcoexist,
1209                                                      0x1703) & BIT(5)) == 0) &&
1210                         (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
1211
1212                 /* write data add*/
1213
1214                 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1215                                            0xc00F0000 | reg_addr);
1216
1217         }
1218
1219 }
1220
1221 void halbtc8822b1ant_ltecoex_enable(IN struct btc_coexist *btcoexist,
1222                                     IN boolean enable)
1223 {
1224         u8 val;
1225
1226         val = (enable) ? 1 : 0;
1227         /* 0x38[7] */
1228         halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
1229                         val);  /* 0x38[7] */
1230
1231 }
1232
1233
1234 void halbtc8822b1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist,
1235                 IN boolean wifi_control)
1236 {
1237         u8 val;
1238
1239         val = (wifi_control) ? 1 : 0;
1240         /* 0x70[26] */
1241         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
1242                                            val); /* 0x70[26] */
1243
1244 }
1245
1246 void halbtc8822b1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist,
1247                         IN u8 control_block, IN boolean sw_control, IN u8 state)
1248 {
1249         u32 val = 0, bit_mask;
1250
1251         state = state & 0x1;
1252         /*LTE indirect 0x38=0xccxx (sw : gnt_wl=1,sw gnt_bt=1)
1253         0x38=0xddxx (sw : gnt_bt=1 , sw gnt_wl=0)
1254         0x38=0x55xx(hw pta :gnt_wl /gnt_bt ) */
1255         val = (sw_control) ? ((state << 1) | 0x1) : 0;
1256
1257         switch (control_block) {
1258         case BT_8822B_1ANT_GNT_BLOCK_RFC_BB:
1259         default:
1260                 bit_mask = 0xc000;
1261                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1262                                 0x38, bit_mask, val); /* 0x38[15:14] */
1263                 bit_mask = 0x0c00;
1264                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1265                                 0x38, bit_mask, val); /* 0x38[11:10]                                             */
1266                 break;
1267         case BT_8822B_1ANT_GNT_BLOCK_RFC:
1268                 bit_mask = 0xc000;
1269                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1270                                 0x38, bit_mask, val); /* 0x38[15:14] */
1271                 break;
1272         case BT_8822B_1ANT_GNT_BLOCK_BB:
1273                 bit_mask = 0x0c00;
1274                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1275                                 0x38, bit_mask, val); /* 0x38[11:10] */
1276                 break;
1277
1278         }
1279
1280 }
1281
1282 void halbtc8822b1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist,
1283                         IN u8 control_block, IN boolean sw_control, IN u8 state)
1284 {
1285         u32 val = 0, bit_mask;
1286         /*LTE indirect 0x38=0xccxx (sw : gnt_wl=1,sw gnt_bt=1)
1287         0x38=0xddxx (sw : gnt_bt=1 , sw gnt_wl=0)
1288         0x38=0x55xx(hw pta :gnt_wl /gnt_bt ) */
1289
1290         state = state & 0x1;
1291         val = (sw_control) ? ((state << 1) | 0x1) : 0;
1292
1293         switch (control_block) {
1294         case BT_8822B_1ANT_GNT_BLOCK_RFC_BB:
1295         default:
1296                 bit_mask = 0x3000;
1297                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1298                                 0x38, bit_mask, val); /* 0x38[13:12] */
1299                 bit_mask = 0x0300;
1300                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1301                                 0x38, bit_mask, val); /* 0x38[9:8]                                               */
1302                 break;
1303         case BT_8822B_1ANT_GNT_BLOCK_RFC:
1304                 bit_mask = 0x3000;
1305                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1306                                 0x38, bit_mask, val); /* 0x38[13:12] */
1307                 break;
1308         case BT_8822B_1ANT_GNT_BLOCK_BB:
1309                 bit_mask = 0x0300;
1310                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
1311                                 0x38, bit_mask, val); /* 0x38[9:8] */
1312                 break;
1313
1314         }
1315
1316 }
1317
1318 void halbtc8822b1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist,
1319                 IN u8 table_type, IN u16 table_content)
1320 {
1321         u16 reg_addr = 0x0000;
1322
1323         switch (table_type) {
1324         case BT_8822B_1ANT_CTT_WL_VS_LTE:
1325                 reg_addr = 0xa0;
1326                 break;
1327         case BT_8822B_1ANT_CTT_BT_VS_LTE:
1328                 reg_addr = 0xa4;
1329                 break;
1330         }
1331
1332         if (reg_addr != 0x0000)
1333                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
1334                         0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */
1335
1336
1337 }
1338
1339
1340 void halbtc8822b1ant_ltcoex_set_break_table(IN struct btc_coexist *btcoexist,
1341                 IN u8 table_type, IN u8 table_content)
1342 {
1343         u16 reg_addr = 0x0000;
1344
1345         switch (table_type) {
1346         case BT_8822B_1ANT_LBTT_WL_BREAK_LTE:
1347                 reg_addr = 0xa8;
1348                 break;
1349         case BT_8822B_1ANT_LBTT_BT_BREAK_LTE:
1350                 reg_addr = 0xac;
1351                 break;
1352         case BT_8822B_1ANT_LBTT_LTE_BREAK_WL:
1353                 reg_addr = 0xb0;
1354                 break;
1355         case BT_8822B_1ANT_LBTT_LTE_BREAK_BT:
1356                 reg_addr = 0xb4;
1357                 break;
1358         }
1359
1360         if (reg_addr != 0x0000)
1361                 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
1362                         0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */
1363
1364
1365 }
1366
1367 void halbtc8822b1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist,
1368                 IN boolean force_exec,  IN u8 interval,
1369                 IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2,
1370                 IN u8 val0x6c4_b3)
1371 {
1372         static u8 pre_h2c_parameter[6] = {0};
1373         u8      cur_h2c_parameter[6] = {0};
1374         u8 i, match_cnt = 0;
1375
1376         cur_h2c_parameter[0] = 0x7;     /* op_code, 0x7= wlan toggle slot*/
1377
1378         cur_h2c_parameter[1] = interval;
1379         cur_h2c_parameter[2] = val0x6c4_b0;
1380         cur_h2c_parameter[3] = val0x6c4_b1;
1381         cur_h2c_parameter[4] = val0x6c4_b2;
1382         cur_h2c_parameter[5] = val0x6c4_b3;
1383
1384         if (!force_exec) {
1385                 for (i = 1; i <= 5; i++) {
1386                         if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
1387                                 break;
1388
1389                         match_cnt++;
1390                 }
1391
1392                 if (match_cnt == 5)
1393                         return;
1394         }
1395
1396         for (i = 1; i <= 5; i++)
1397                 pre_h2c_parameter[i] = cur_h2c_parameter[i];
1398
1399         btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter);
1400 }
1401
1402 void halbtc8822b1ant_set_coex_table(IN struct btc_coexist *btcoexist,
1403             IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
1404 {
1405         btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1406
1407         btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1408
1409         btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1410
1411         btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1412 }
1413
1414 void halbtc8822b1ant_coex_table(IN struct btc_coexist *btcoexist,
1415                         IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
1416                                 IN u32 val0x6c8, IN u8 val0x6cc)
1417 {
1418         coex_dm->cur_val0x6c0 = val0x6c0;
1419         coex_dm->cur_val0x6c4 = val0x6c4;
1420         coex_dm->cur_val0x6c8 = val0x6c8;
1421         coex_dm->cur_val0x6cc = val0x6cc;
1422
1423
1424
1425         if (!force_exec) {
1426                 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1427                     (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1428                     (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1429                     (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1430                         return;
1431         }
1432         halbtc8822b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1433                                        val0x6cc);
1434
1435         coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1436         coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1437         coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1438         coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1439 }
1440
1441 void halbtc8822b1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
1442                 IN boolean force_exec, IN u8 type)
1443 {
1444         u32     break_table;
1445         u8      select_table;
1446
1447
1448
1449         coex_sta->coex_table_type = type;
1450
1451         if (coex_sta->concurrent_rx_mode_on == true) {
1452                 break_table = 0xf0ffffff;       /* set WL hi-pri can break BT */
1453                 select_table = 0x3;             /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
1454         } else {
1455                 break_table = 0xffffff;
1456                 select_table = 0x3;
1457         }
1458
1459         switch (type) {
1460         case 0:
1461                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1462                                            0x55555555, 0x55555555, break_table,
1463                                            select_table);
1464                 break;
1465         case 1:
1466                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1467                                            0x55555555, 0x5a5a5a5a, break_table,
1468                                            select_table);
1469                 break;
1470         case 2:
1471                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1472                                            0xaa5a5a5a, 0xaa5a5a5a, break_table,
1473                                            select_table);
1474                 break;
1475         case 3:
1476                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1477                                            0x55555555, 0xaa5a5a5a, break_table,
1478                                            select_table);
1479                 break;
1480         case 4:
1481                 halbtc8822b1ant_coex_table(btcoexist,
1482                                            force_exec, 0xaa555555, 0xaa5a5a5a,
1483                                            break_table, select_table);
1484                 break;
1485         case 5:
1486                 halbtc8822b1ant_coex_table(btcoexist,
1487                                            force_exec, 0x5a5a5a5a, 0x5a5a5a5a,
1488                                            break_table, select_table);
1489                 break;
1490         case 6:
1491                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1492                                            0x55555555, 0xaaaaaaaa, break_table,
1493                                            select_table);
1494                 break;
1495         case 7:
1496                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1497                                            0xaaaaaaaa, 0xaaaaaaaa, break_table,
1498                                            select_table);
1499                 break;
1500         case 8:
1501                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1502                                            0xffffffff, 0xffffffff, break_table,
1503                                            select_table);
1504                 break;
1505         case 9:
1506                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1507                                            0x5a5a5555, 0xaaaa5a5a, break_table,
1508                                            select_table);
1509                 break;
1510         case 10:
1511                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1512                                            0xaaaa5aaa, 0xaaaa5aaa, break_table,
1513                                            select_table);
1514                 break;
1515         case 11:
1516                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1517                                            0xaaaaa5aa, 0xaaaaaaaa, break_table,
1518                                            select_table);
1519                 break;
1520         case 12:
1521                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1522                                            0xaaaaa5aa, 0xaaaaa5aa, break_table,
1523                                            select_table);
1524                 break;
1525         case 13:
1526                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1527                                            0x55555555, 0xaaaa5a5a, break_table,
1528                                            select_table);
1529                 break;
1530         case 14:
1531                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1532                                            0x5a5a555a, 0xaaaa5a5a, break_table,
1533                                            select_table);
1534                 break;
1535         case 15:
1536                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1537                                            0x55555555, 0xaaaa55aa, break_table,
1538                                            select_table);
1539                 break;
1540         case 16:
1541                 halbtc8822b1ant_coex_table(btcoexist, force_exec,
1542                                            0x5a5a555a, 0x5a5a555a, break_table,
1543                                            select_table);
1544                 break;
1545
1546         default:
1547                 break;
1548         }
1549 }
1550
1551 void halbtc8822b1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1552                 IN boolean enable)
1553 {
1554
1555
1556         u8                      h2c_parameter[1] = {0};
1557
1558         if (enable)
1559                 h2c_parameter[0] |= BIT(0);             /* function enable */
1560
1561         btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1562 }
1563
1564 void halbtc8822b1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1565                                      IN boolean force_exec, IN boolean enable)
1566 {
1567
1568         coex_dm->cur_ignore_wlan_act = enable;
1569
1570         if (!force_exec) {
1571                 if (coex_dm->pre_ignore_wlan_act ==
1572                     coex_dm->cur_ignore_wlan_act) {
1573
1574                         coex_dm->pre_ignore_wlan_act =
1575                                 coex_dm->cur_ignore_wlan_act;
1576                         return;
1577                 }
1578         }
1579
1580         halbtc8822b1ant_set_fw_ignore_wlan_act(btcoexist, enable);
1581
1582         coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1583 }
1584
1585 void halbtc8822b1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
1586                                   IN u8 lps_val, IN u8 rpwm_val)
1587 {
1588         u8      lps = lps_val;
1589         u8      rpwm = rpwm_val;
1590
1591         btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1592         btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1593 }
1594
1595 void halbtc8822b1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
1596                       IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
1597 {
1598         coex_dm->cur_lps = lps_val;
1599         coex_dm->cur_rpwm = rpwm_val;
1600
1601         if (!force_exec) {
1602                 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1603                     (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1604                         return;
1605         }
1606         halbtc8822b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1607
1608         coex_dm->pre_lps = coex_dm->cur_lps;
1609         coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1610 }
1611
1612 void halbtc8822b1ant_ps_tdma_check_for_power_save_state(
1613         IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1614 {
1615         u8      lps_mode = 0x0;
1616         u8      h2c_parameter[5] = {0x8, 0, 0, 0, 0};
1617
1618         btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1619
1620         if (lps_mode) { /* already under LPS state */
1621                 if (new_ps_state) {
1622                         /* keep state under LPS, do nothing. */
1623                 } else {
1624                         /* will leave LPS state, turn off psTdma first */
1625
1626                         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1627                                                 h2c_parameter);
1628                 }
1629         } else {                                        /* NO PS state */
1630                 if (new_ps_state) {
1631                         /* will enter LPS state, turn off psTdma first */
1632
1633                         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1634                                                 h2c_parameter);
1635                 } else {
1636                         /* keep state under NO PS state, do nothing. */
1637                 }
1638         }
1639 }
1640
1641
1642 void halbtc8822b1ant_power_save_state(IN struct btc_coexist *btcoexist,
1643                               IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1644 {
1645         boolean         low_pwr_disable = false;
1646
1647         switch (ps_type) {
1648         case BTC_PS_WIFI_NATIVE:
1649                 /* recover to original 32k low power setting */
1650                 coex_sta->force_lps_on = false;
1651                 low_pwr_disable = false;
1652                 btcoexist->btc_set(btcoexist,
1653                                    BTC_SET_ACT_DISABLE_LOW_POWER,
1654                                    &low_pwr_disable);
1655                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1656                                    NULL);
1657                 coex_sta->force_lps_on = false;
1658                 break;
1659         case BTC_PS_LPS_ON:
1660
1661                 coex_sta->force_lps_on = true;
1662                 halbtc8822b1ant_ps_tdma_check_for_power_save_state(
1663                         btcoexist, true);
1664                 halbtc8822b1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1665                                          lps_val, rpwm_val);
1666                 /* when coex force to enter LPS, do not enter 32k low power. */
1667                 low_pwr_disable = true;
1668                 btcoexist->btc_set(btcoexist,
1669                                    BTC_SET_ACT_DISABLE_LOW_POWER,
1670                                    &low_pwr_disable);
1671                 /* power save must executed before psTdma.                       */
1672                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1673                                    NULL);
1674                 coex_sta->force_lps_on = true;
1675                 break;
1676         case BTC_PS_LPS_OFF:
1677
1678                 coex_sta->force_lps_on = false;
1679                 halbtc8822b1ant_ps_tdma_check_for_power_save_state(
1680                         btcoexist, false);
1681                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1682                                    NULL);
1683                 coex_sta->force_lps_on = false;
1684                 break;
1685         default:
1686                 break;
1687         }
1688 }
1689
1690
1691 void halbtc8822b1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1692            IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1693 {
1694         u8                      h2c_parameter[5] = {0};
1695         u8                      real_byte1 = byte1, real_byte5 = byte5;
1696         boolean         ap_enable = false;
1697
1698         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1699                            &ap_enable);
1700
1701         if (ap_enable) {
1702                 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1703
1704                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1705                                     "[BTCoex], FW for 1Ant AP mode\n");
1706                         BTC_TRACE(trace_buf);
1707
1708                         real_byte1 &= ~BIT(4);
1709                         real_byte1 |= BIT(5);
1710
1711                         real_byte5 |= BIT(5);
1712                         real_byte5 &= ~BIT(6);
1713
1714                         halbtc8822b1ant_power_save_state(btcoexist,
1715                                                  BTC_PS_WIFI_NATIVE, 0x0,
1716                                                          0x0);
1717                 }
1718         } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1719
1720                 halbtc8822b1ant_power_save_state(btcoexist,
1721                                                  BTC_PS_LPS_ON, 0x50,
1722                                                  0x4);
1723         } else {
1724                 halbtc8822b1ant_power_save_state(btcoexist,
1725                                                  BTC_PS_WIFI_NATIVE, 0x0,
1726                                                  0x0);
1727         }
1728
1729
1730         h2c_parameter[0] = real_byte1;
1731         h2c_parameter[1] = byte2;
1732         h2c_parameter[2] = byte3;
1733         h2c_parameter[3] = byte4;
1734         h2c_parameter[4] = real_byte5;
1735
1736         coex_dm->ps_tdma_para[0] = real_byte1;
1737         coex_dm->ps_tdma_para[1] = byte2;
1738         coex_dm->ps_tdma_para[2] = byte3;
1739         coex_dm->ps_tdma_para[3] = byte4;
1740         coex_dm->ps_tdma_para[4] = real_byte5;
1741
1742         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1743 }
1744
1745 void halbtc8822b1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1746                      IN boolean force_exec, IN boolean turn_on, IN u8 type)
1747 {
1748         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1749         struct  btc_board_info  *board_info = &btcoexist->board_info;
1750         boolean                 wifi_busy = false;
1751         static u8                       psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0;
1752         static boolean   pre_wifi_busy = false;
1753
1754         coex_dm->cur_ps_tdma_on = turn_on;
1755         coex_dm->cur_ps_tdma = type;
1756
1757         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1758
1759         if (wifi_busy != pre_wifi_busy) {
1760                 force_exec = true;
1761                 pre_wifi_busy = wifi_busy;
1762         }
1763
1764         /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1765         if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
1766                 psTdmaByte4Modify = 0x1;
1767         else
1768                 psTdmaByte4Modify = 0x0;
1769
1770         if (pre_psTdmaByte4Modify != psTdmaByte4Modify) {
1771
1772                 force_exec = true;
1773                 pre_psTdmaByte4Modify = psTdmaByte4Modify;
1774         }
1775
1776         if (coex_dm->cur_ps_tdma_on) {
1777                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1778                             "[BTCoex], ********TDMA(on, %d) **********\n",
1779                             coex_dm->cur_ps_tdma);
1780                 BTC_TRACE(trace_buf);
1781         } else {
1782                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1783                             "[BTCoex], **********TDMA(off, %d) **********\n",
1784                             coex_dm->cur_ps_tdma);
1785                 BTC_TRACE(trace_buf);
1786         }
1787
1788         if (!force_exec) {
1789                 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1790                     (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) {
1791                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1792                                 "[BTCoex], return for no-TDMA case change\n");
1793                         BTC_TRACE(trace_buf);
1794
1795                         return;
1796                 }
1797         }
1798
1799
1800         if (turn_on) {
1801
1802                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
1803                                            0x1);  /* enable TBTT nterrupt */
1804
1805                 switch (type) {
1806                 default:
1807                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1808                                               0x51, 0x1a, 0x1a, 0x0, 0x10);
1809                         break;
1810                 case 1:
1811                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1812                                               0x61, 0x3a, 0x03, 0x11, 0x10);
1813                         break;
1814                 case 3:
1815                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1816                                               0x51, 0x3a, 0x03, 0x10, 0x10);
1817                         break;
1818                 case 4:
1819                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1820                                               0x51, 0x21, 0x03, 0x10, 0x10);
1821                         break;
1822                 case 5:
1823                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1824                                               0x61, 0x15, 0x3, 0x11, 0x11);
1825                         break;
1826                 case 7:
1827                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1828                                               0x61, 0x10, 0x03, 0x10,  0x14 |
1829                                                       psTdmaByte4Modify);
1830                         break;
1831                 case 8:
1832                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1833                                               0x51, 0x10, 0x03, 0x10,  0x14 |
1834                                                       psTdmaByte4Modify);
1835                         break;
1836                 case 13:
1837                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1838                                               0x51, 0x25, 0x03, 0x10,  0x10 |
1839                                                       psTdmaByte4Modify);
1840                         break;
1841                 case 14:
1842                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1843                                               0x51, 0x15, 0x03, 0x10,  0x10 |
1844                                                       psTdmaByte4Modify);
1845                         break;
1846                 case 15:
1847                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1848                                               0x51, 0x20, 0x03, 0x10,  0x10 |
1849                                                       psTdmaByte4Modify);
1850                         break;
1851                 case 17:
1852                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1853                                               0x61, 0x10, 0x03, 0x11,  0x14 |
1854                                                       psTdmaByte4Modify);
1855                         break;
1856
1857                 case 20:
1858                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1859                                               0x61, 0x30, 0x03, 0x11, 0x10);
1860                         break;
1861                 case 22:
1862                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1863                                               0x61, 0x25, 0x03, 0x11, 0x10);
1864                         break;
1865                 case 32:
1866                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1867                                               0x61, 0x35, 0x3, 0x11, 0x11);
1868                         break;
1869                 case 33:
1870                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1871                                               0x61, 0x35, 0x03, 0x11, 0x10);
1872                         break;
1873                 case 41:
1874                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1875                                               0x51, 0x45, 0x3, 0x11, 0x11);
1876                         break;
1877                 case 42:
1878                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1879                                               0x51, 0x1e, 0x3, 0x10, 0x14 |
1880                                                       psTdmaByte4Modify);
1881                         break;
1882                 case 43:
1883                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1884                                               0x51, 0x45, 0x3, 0x10, 0x14);
1885                         break;
1886                 case 44:
1887                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1888                                               0x51, 0x25, 0x3, 0x10, 0x10);
1889                         break;
1890                 case 45:
1891                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1892                                               0x51, 0x29, 0x3, 0x10, 0x10);
1893                         break;
1894                 case 46:
1895                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1896                                               0x51, 0x1a, 0x3, 0x10, 0x10);
1897                         break;
1898                 case 47:
1899                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1900                                               0x51, 0x32, 0x3, 0x10, 0x10);
1901                         break;
1902                 case 48:
1903                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1904                                               0x51, 0x29, 0x3, 0x10, 0x10);
1905                         break;
1906                 case 49:
1907                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1908                                               0x55, 0x1e, 0x3, 0x10, 0x54);
1909                         break;
1910
1911                 }
1912         } else {
1913
1914                 switch (type) {
1915                 case 0:
1916                 default:  /* Software control, Antenna at BT side */
1917                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1918                                                       0x0, 0x0, 0x0, 0x0, 0x0);
1919                         /*
1920                         halbtc8822b1ant_set_ant_path(btcoexist,
1921                                              BTC_ANT_PATH_BT, FORCE_EXEC, false,
1922                                                      false); */
1923                         break;
1924                 case 8: /* PTA Control */
1925                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1926                                                       0x8, 0x0, 0x0, 0x0, 0x0);
1927                         /*
1928                         halbtc8822b1ant_set_ant_path(btcoexist,
1929                                      BTC_ANT_PATH_PTA, FORCE_EXEC,  false,
1930                                      false);  */
1931                         break;
1932                 case 9:   /* Software control, Antenna at WiFi side */
1933                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1934                                                       0x0, 0x0, 0x0, 0x0, 0x0);
1935                         /*
1936                         halbtc8822b1ant_set_ant_path(btcoexist,
1937                                              BTC_ANT_PATH_WIFI, FORCE_EXEC,false,false); */
1938                         break;
1939                 case 10:        /* under 5G , 0x778=1*/
1940                         halbtc8822b1ant_set_fw_pstdma(btcoexist,
1941                                                       0x0, 0x0, 0x0, 0x0, 0x0);
1942
1943                         /*
1944                         halbtc8822b1ant_set_ant_path(btcoexist,
1945                                              BTC_ANT_PATH_WIFI5G, FORCE_EXEC, false,
1946                                                      false);    */
1947
1948                         break;
1949                 }
1950         }
1951
1952
1953         /* update pre state */
1954         coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1955         coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1956 }
1957
1958
1959 void halbtc8822b1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
1960                                   IN boolean low_penalty_ra)
1961 {
1962         halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
1963 }
1964 /*rf4 type by efuse , and for ant at main aux inverse use , because is 2x2 ,and control types are the same ,does not need */
1965
1966 void halbtc8822b1ant_set_rfe_type(IN struct btc_coexist *btcoexist)
1967 {
1968         struct  btc_board_info *board_info = &btcoexist->board_info;
1969
1970         /* Ext switch buffer mux */
1971                 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
1972                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
1973                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
1974
1975         /* the following setup should be got from Efuse in the future */
1976         rfe_type->rfe_module_type = board_info->rfe_type;
1977
1978         rfe_type->ext_ant_switch_ctrl_polarity = 0;
1979
1980         switch (rfe_type->rfe_module_type) {
1981         case 0:
1982         default:
1983                 rfe_type->ext_ant_switch_exist = true;
1984                 rfe_type->ext_ant_switch_type =
1985                         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
1986                 break;
1987         case 1:
1988                 rfe_type->ext_ant_switch_exist = true;
1989                 rfe_type->ext_ant_switch_type =
1990                         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
1991                 break;
1992         case 2:
1993                 rfe_type->ext_ant_switch_exist = true;
1994                 rfe_type->ext_ant_switch_type =
1995                         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
1996                 break;
1997         case 3:
1998                 rfe_type->ext_ant_switch_exist = true;
1999                 rfe_type->ext_ant_switch_type =
2000                         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2001                 break;
2002         case 4:
2003                 rfe_type->ext_ant_switch_exist = true;
2004                 rfe_type->ext_ant_switch_type =
2005                         BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SP3T;          /* SP3T  */;
2006                 break;
2007         }
2008
2009
2010 }
2011
2012 /*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
2013
2014 void halbtc8822b1ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist,
2015                         IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type)
2016 {
2017         struct  btc_board_info  *board_info = &btcoexist->board_info;
2018         boolean switch_polatiry_inverse = false;
2019         u8              regval_0xcbd = 0, regval_0x64;
2020         u32             u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
2021         /* Ext switch buffer mux */
2022                 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2023                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2024                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2025
2026         if (!rfe_type->ext_ant_switch_exist)
2027                 return;
2028
2029         coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8)  + pos_type;
2030
2031         if (!force_exec) {
2032                 if (coex_dm->pre_ext_ant_switch_status ==
2033                     coex_dm->cur_ext_ant_switch_status)
2034                         return;
2035         }
2036
2037         coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
2038
2039         /* swap control polarity if use different switch control polarity*/
2040         /*  Normal switch polarity for SPDT, 0xcbd[1:0] = 2b'01 => Ant to BTG,  0xcbd[1:0] = 2b'10 => Ant to WLG */
2041         switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ?
2042                            ~switch_polatiry_inverse : switch_polatiry_inverse);
2043
2044
2045         switch (pos_type) {
2046         default:
2047         case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT:
2048         case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE:
2049
2050                 break;
2051         case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG:
2052                 break;
2053         case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA:
2054                 break;
2055         }
2056
2057
2058         if (rfe_type->ext_ant_switch_type ==
2059             BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT) {
2060                 switch (ctrl_type) {
2061                 default:
2062                 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
2063                         btcoexist->btc_write_1byte_bitmask(
2064                                 btcoexist, 0x4e, 0x80,
2065                                 0x0);  /*  0x4c[23] = 0 */
2066                         btcoexist->btc_write_1byte_bitmask(
2067                                 btcoexist, 0x4f, 0x01,
2068                                 0x1);  /* 0x4c[24] = 1 */
2069                         btcoexist->btc_write_1byte_bitmask(
2070                                 btcoexist, 0xcb4, 0xff,
2071                                 0x77);  /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
2072
2073                         regval_0xcbd = (switch_polatiry_inverse
2074                                         == false ?  0x1 :
2075                                 0x2);    /* 0xcbd[1:0] = 2b'01 for no switch_polatiry_inverse, ANTSWB =1, ANTSW =0  */
2076                         btcoexist->btc_write_1byte_bitmask(
2077                                 btcoexist, 0xcbd, 0x3,
2078                                 regval_0xcbd);
2079
2080                         break;
2081                 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
2082                         btcoexist->btc_write_1byte_bitmask(
2083                                 btcoexist, 0x4e, 0x80,
2084                                 0x0);  /* 0x4c[23] = 0 */
2085                         btcoexist->btc_write_1byte_bitmask(
2086                                 btcoexist, 0x4f, 0x01,
2087                                 0x1);  /* 0x4c[24] = 1 */
2088                         btcoexist->btc_write_1byte_bitmask(
2089                                 btcoexist, 0xcb4, 0xff,
2090                                 0x66);  /* PTA,  DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
2091
2092                         regval_0xcbd = (switch_polatiry_inverse
2093                                         == false ?  0x2 :
2094                                 0x1);    /* 0xcbd[1:0] = 2b'10 for no switch_polatiry_inverse, ANTSWB =1, ANTSW =0  @ GNT_BT=1 */
2095                         btcoexist->btc_write_1byte_bitmask(
2096                                 btcoexist, 0xcbd, 0x3,
2097                                 regval_0xcbd);
2098
2099                         break;
2100                 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV
2101                                 :
2102                         btcoexist->btc_write_1byte_bitmask(
2103                                 btcoexist, 0x4e, 0x80,
2104                                 0x0);  /* 0x4c[23] = 0 */
2105                         btcoexist->btc_write_1byte_bitmask(
2106                                 btcoexist, 0x4f, 0x01,
2107                                 0x1);  /* 0x4c[24] = 1 */
2108                         btcoexist->btc_write_1byte_bitmask(
2109                                 btcoexist, 0xcb4, 0xff,
2110                                 0x88);  /* */
2111
2112                         /* no regval_0xcbd setup required, because  antenna switch control value by antenna diversity */
2113
2114                         break;
2115                 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
2116                         btcoexist->btc_write_1byte_bitmask(
2117                                 btcoexist, 0x4e, 0x80,
2118                                 0x1);  /*  0x4c[23] = 1 */
2119
2120                         regval_0x64 = (switch_polatiry_inverse
2121                                        == false ?  0x0 :
2122                                 0x1);    /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
2123                         btcoexist->btc_write_1byte_bitmask(
2124                                 btcoexist, 0x64, 0x1,
2125                                 regval_0x64);
2126                         break;
2127                 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
2128                         btcoexist->btc_write_1byte_bitmask(
2129                                 btcoexist, 0x4e, 0x80,
2130                                 0x0);  /* 0x4c[23] = 0 */
2131                         btcoexist->btc_write_1byte_bitmask(
2132                                 btcoexist, 0x4f, 0x01,
2133                                 0x0);  /* 0x4c[24] = 0 */
2134
2135                         /* no  setup required, because  antenna switch control value by BT vendor 0xac[1:0] */
2136                         break;
2137                 }
2138         }
2139
2140         u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcbc);
2141         u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2142         u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
2143
2144         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2145                 "[BTCoex], ********** (After Ext Ant switch setup) 0xcbc = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x**********\n",
2146                     u32tmp1, u32tmp2, u32tmp3);
2147         BTC_TRACE(trace_buf);
2148
2149
2150 }
2151
2152 /*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*/
2153
2154 void halbtc8822b1ant_set_ant_path(IN struct btc_coexist *btcoexist,
2155                                   IN u8 ant_pos_type, IN boolean force_exec,
2156                                   IN u8 phase)
2157
2158 {
2159         struct  btc_board_info *board_info = &btcoexist->board_info;
2160         u8                      u8tmp = 0;
2161         u32                     u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
2162         /* Ext switch buffer mux */
2163                 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2164                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2165                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2166
2167         coex_dm->cur_ant_pos_type = (ant_pos_type << 8)  + phase;
2168
2169         if (!force_exec) {
2170                 if (coex_dm->cur_ant_pos_type ==
2171                     coex_dm->pre_ant_pos_type)
2172                         return;
2173         }
2174
2175         coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
2176
2177 #if 1
2178         u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
2179                         0x38);
2180         u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
2181                         0x54);
2182         u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2183
2184         u8tmp  = btcoexist->btc_read_1byte(btcoexist, 0x73);
2185
2186         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2187                 "[BTCoex], ********** (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
2188                     u32tmp3, u8tmp, u32tmp1, u32tmp2);
2189         BTC_TRACE(trace_buf);
2190 #endif
2191
2192         switch (phase) {
2193         case BT_8822B_1ANT_PHASE_COEX_INIT:
2194                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2195                         "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_COEX_INIT) **********\n");
2196                 BTC_TRACE(trace_buf);
2197
2198                 /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
2199                 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2200
2201                 /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
2202                 halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
2203                                                BT_8822B_1ANT_CTT_WL_VS_LTE,
2204                                                        0xffff);
2205
2206                 /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
2207                 halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
2208                                                BT_8822B_1ANT_CTT_BT_VS_LTE,
2209                                                        0xffff);
2210
2211                 /* set GNT_BT to SW high */
2212                 halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
2213                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2214                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2215                                            BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2216
2217                 /* set GNT_WL to SW low */
2218                 halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
2219                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2220                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2221                                            BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
2222
2223                 /* set Path control owner to WL at initial step */
2224                 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
2225                                 BT_8822B_1ANT_PCO_WLSIDE);
2226
2227                 coex_sta->run_time_state = false;
2228
2229                 /* Ext switch buffer mux */
2230                 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2231                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991,
2232                                                    0x3, 0x0);
2233                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe,
2234                                                    0x8, 0x0);
2235
2236                 if (BTC_ANT_PATH_AUTO == ant_pos_type)
2237                         ant_pos_type = BTC_ANT_PATH_BT;
2238
2239                 break;
2240         case BT_8822B_1ANT_PHASE_WLANONLY_INIT:
2241                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2242                         "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLANONLY_INIT) **********\n");
2243                 BTC_TRACE(trace_buf);
2244
2245                 /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
2246                 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2247
2248                 /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
2249                 halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
2250                                                BT_8822B_1ANT_CTT_WL_VS_LTE,
2251                                                        0xffff);
2252
2253                 /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
2254                 halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
2255                                                BT_8822B_1ANT_CTT_BT_VS_LTE,
2256                                                        0xffff);
2257
2258                 /* set GNT_BT to SW Low */
2259                 halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
2260                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2261                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2262                                            BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
2263
2264                 /* Set GNT_WL to SW high */
2265                 halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
2266                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2267                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2268                                            BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2269
2270                 /* set Path control owner to WL at initial step */
2271                 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
2272                                 BT_8822B_1ANT_PCO_WLSIDE);
2273
2274                 coex_sta->run_time_state = false;
2275
2276                 /* Ext switch buffer mux */
2277                 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2278                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991,
2279                                                    0x3, 0x0);
2280                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe,
2281                                                    0x8, 0x0);
2282
2283                 if (BTC_ANT_PATH_AUTO == ant_pos_type)
2284                         ant_pos_type = BTC_ANT_PATH_WIFI;
2285
2286                 break;
2287         case BT_8822B_1ANT_PHASE_WLAN_OFF:
2288                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2289                         "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLAN_OFF) **********\n");
2290                 BTC_TRACE(trace_buf);
2291
2292                 /* Disable LTE Coex Function in WiFi side */
2293                 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2294
2295                 /* set Path control owner to BT */
2296                 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
2297                                 BT_8822B_1ANT_PCO_BTSIDE);
2298
2299                 /* Set Ext Ant Switch to BT control at wifi off step */
2300                 halbtc8822b1ant_set_ext_ant_switch(btcoexist,
2301                                                    FORCE_EXEC,
2302                                    BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
2303                                    BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
2304
2305                 coex_sta->run_time_state = false;
2306
2307                 break;
2308         case BT_8822B_1ANT_PHASE_2G_RUNTIME:
2309                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2310                         "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_2G_RUNTIME) **********\n");
2311                 BTC_TRACE(trace_buf);
2312
2313                 /* set GNT_BT to PTA */
2314                 halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
2315                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2316                                            BT_8822B_1ANT_GNT_CTRL_BY_PTA,
2317                                            BT_8822B_1ANT_SIG_STA_SET_BY_HW);
2318
2319                 /* Set GNT_WL to PTA */
2320                 halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
2321                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2322                                            BT_8822B_1ANT_GNT_CTRL_BY_PTA,
2323                                            BT_8822B_1ANT_SIG_STA_SET_BY_HW);
2324
2325                 /* set Path control owner to WL at runtime step */
2326                 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
2327                                 BT_8822B_1ANT_PCO_WLSIDE);
2328
2329                 coex_sta->run_time_state = true;
2330
2331                 if (BTC_ANT_PATH_AUTO == ant_pos_type)
2332                         ant_pos_type = BTC_ANT_PATH_PTA;
2333
2334                 break;
2335         case BT_8822B_1ANT_PHASE_5G_RUNTIME:
2336                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2337                         "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_5G_RUNTIME) **********\n");
2338                 BTC_TRACE(trace_buf);
2339
2340                 /* set GNT_BT to SW Hi */
2341                 halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
2342                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2343                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2344                                            BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2345
2346                 /* Set GNT_WL to SW Hi */
2347                 halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
2348                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2349                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2350                                            BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2351
2352                 /* set Path control owner to WL at runtime step */
2353                 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
2354                                 BT_8822B_1ANT_PCO_WLSIDE);
2355
2356                 coex_sta->run_time_state = true;
2357
2358                 if (BTC_ANT_PATH_AUTO == ant_pos_type)
2359                         ant_pos_type =
2360                                 BTC_ANT_PATH_WIFI5G;
2361
2362                 break;
2363         case BT_8822B_1ANT_PHASE_BTMPMODE:
2364                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2365                         "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_BTMPMODE) **********\n");
2366                 BTC_TRACE(trace_buf);
2367
2368                 /* Disable LTE Coex Function in WiFi side */
2369                 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2370
2371                 /* set GNT_BT to SW Hi */
2372                 halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
2373                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2374                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2375                                            BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2376
2377                 /* Set GNT_WL to SW Lo */
2378                 halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
2379                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2380                                                    BT_8822B_1ANT_GNT_CTRL_BY_SW,
2381                                            BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
2382
2383                 /* set Path control owner to WL */
2384                 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
2385                                 BT_8822B_1ANT_PCO_WLSIDE);
2386
2387                 coex_sta->run_time_state = false;
2388
2389                 /* Set Ext Ant Switch to BT side at BT MP mode */
2390                 if (BTC_ANT_PATH_AUTO == ant_pos_type)
2391                         ant_pos_type = BTC_ANT_PATH_BT;
2392
2393                 break;
2394         }
2395
2396
2397         if (phase != BT_8822B_1ANT_PHASE_WLAN_OFF) {
2398                 switch (ant_pos_type) {
2399                 case BTC_ANT_PATH_WIFI:
2400                         halbtc8822b1ant_set_ext_ant_switch(
2401                                 btcoexist,
2402                                 force_exec,
2403                                 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2404                                 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG);
2405                         break;
2406                 case BTC_ANT_PATH_WIFI5G
2407                                 :
2408                         halbtc8822b1ant_set_ext_ant_switch(
2409                                 btcoexist,
2410                                 force_exec,
2411                                 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2412                                 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA);
2413                         break;
2414                 case BTC_ANT_PATH_BT:
2415                         halbtc8822b1ant_set_ext_ant_switch(
2416                                 btcoexist,
2417                                 force_exec,
2418                                 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2419                                 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT);
2420                         break;
2421                 default:
2422                 case BTC_ANT_PATH_PTA:
2423                         halbtc8822b1ant_set_ext_ant_switch(
2424                                 btcoexist,
2425                                 force_exec,
2426                                 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA,
2427                                 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
2428                         break;
2429                 }
2430
2431         }
2432 #if 1
2433         u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
2434         u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
2435         u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2436
2437         u8tmp  = btcoexist->btc_read_1byte(btcoexist, 0x73);
2438
2439         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2440                 "[BTCoex], ********** (After Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
2441                     u32tmp3, u8tmp, u32tmp1, u32tmp2);
2442         BTC_TRACE(trace_buf);
2443
2444 #endif
2445
2446 }
2447
2448
2449 void halbtc8822b1ant_coex_all_off(IN struct btc_coexist *btcoexist)
2450 {
2451         /* sw all off */
2452         halbtc8822b1ant_sw_mechanism(btcoexist, false);
2453
2454         /* hw all off */
2455         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2456 }
2457 boolean halbtc8822b1ant_is_common_action(IN struct btc_coexist *btcoexist)
2458 {
2459         boolean                 common = false, wifi_connected = false, wifi_busy = false;
2460
2461         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2462                            &wifi_connected);
2463         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2464
2465         if (!wifi_connected &&
2466             BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2467             coex_dm->bt_status) {
2468                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2469                         "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
2470                 BTC_TRACE(trace_buf);
2471
2472                 /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
2473
2474                 common = true;
2475         } else if (wifi_connected &&
2476                    (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2477                     coex_dm->bt_status)) {
2478                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2479                         "[BTCoex], Wifi connected + BT non connected-idle!!\n");
2480                 BTC_TRACE(trace_buf);
2481
2482                 /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
2483
2484                 common = true;
2485         } else if (!wifi_connected &&
2486                    (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE ==
2487                     coex_dm->bt_status)) {
2488                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2489                         "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
2490                 BTC_TRACE(trace_buf);
2491
2492                 /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
2493
2494                 common = true;
2495         } else if (wifi_connected &&
2496                    (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE ==
2497                     coex_dm->bt_status)) {
2498                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2499                             "[BTCoex], Wifi connected + BT connected-idle!!\n");
2500                 BTC_TRACE(trace_buf);
2501
2502                 /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
2503
2504                 common = true;
2505         } else if (!wifi_connected &&
2506                    (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE !=
2507                     coex_dm->bt_status)) {
2508                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2509                             "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
2510                 BTC_TRACE(trace_buf);
2511
2512                 /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
2513
2514                 common = true;
2515         } else {
2516                 if (wifi_busy) {
2517                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2518                                 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
2519                         BTC_TRACE(trace_buf);
2520                 } else {
2521                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2522                                 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
2523                         BTC_TRACE(trace_buf);
2524                 }
2525
2526                 common = false;
2527         }
2528
2529         return common;
2530 }
2531
2532 void halbtc8822b1ant_action_wifi_under5g(IN struct btc_coexist *btcoexist)
2533 {
2534         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2535                     "[BTCoex], under 5g start\n");
2536         BTC_TRACE(trace_buf);
2537         /* for test : s3 bt disappear , fail rate 1/600*/
2538 /*
2539         halbtc8822b1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
2540 */
2541 /*set sw gnt wl bt  high*/
2542         halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
2543                                                          BT_8822B_1ANT_PHASE_5G_RUNTIME);
2544
2545         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2546         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2547 /*
2548         halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2549
2550         halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
2551 */
2552 }
2553
2554
2555
2556 void halbtc8822b1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
2557 {
2558         boolean wifi_under_5g = false;
2559
2560         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2561         if (wifi_under_5g) {
2562                 halbtc8822b1ant_action_wifi_under5g(btcoexist);
2563
2564                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2565                         "[BTCoex], ********** (wlan only -- under 5g ) **********\n");
2566                 BTC_TRACE(trace_buf);
2567                 return;
2568         }
2569
2570         halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2571         halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2572
2573         halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
2574                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
2575
2576         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2577                 "[BTCoex], ********** (wlan only -- under 2g ) **********\n");
2578         BTC_TRACE(trace_buf);
2579
2580 }
2581
2582 /* *********************************************
2583  *
2584  *      Software Coex Mechanism start
2585  *
2586  * ********************************************* */
2587
2588 /* SCO only or SCO+PAN(HS) */
2589
2590 /*
2591 void halbtc8822b1ant_action_sco(IN struct btc_coexist* btcoexist)
2592 {
2593         halbtc8822b1ant_sw_mechanism(btcoexist, true);
2594 }
2595
2596
2597 void halbtc8822b1ant_action_hid(IN struct btc_coexist* btcoexist)
2598 {
2599         halbtc8822b1ant_sw_mechanism(btcoexist, true);
2600 }
2601
2602
2603 void halbtc8822b1ant_action_a2dp(IN struct btc_coexist* btcoexist)
2604 {
2605         halbtc8822b1ant_sw_mechanism(btcoexist, false);
2606 }
2607
2608 void halbtc8822b1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
2609 {
2610         halbtc8822b1ant_sw_mechanism(btcoexist, false);
2611 }
2612
2613 void halbtc8822b1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
2614 {
2615         halbtc8822b1ant_sw_mechanism(btcoexist, false);
2616 }
2617
2618
2619 void halbtc8822b1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
2620 {
2621         halbtc8822b1ant_sw_mechanism(btcoexist, false);
2622 }
2623
2624
2625 void halbtc8822b1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
2626 {
2627         halbtc8822b1ant_sw_mechanism(btcoexist, false);
2628 }
2629
2630 void halbtc8822b1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
2631 {
2632         halbtc8822b1ant_sw_mechanism(btcoexist, true);
2633 }
2634
2635
2636 void halbtc8822b1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
2637 {
2638         halbtc8822b1ant_sw_mechanism(btcoexist, true);
2639 }
2640
2641 void halbtc8822b1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
2642 {
2643         halbtc8822b1ant_sw_mechanism(btcoexist, true);
2644 }
2645
2646 */
2647
2648 /* *********************************************
2649  *
2650  *      Non-Software Coex Mechanism start
2651  *
2652  * ********************************************* */
2653 void halbtc8822b1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
2654 {
2655         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2656                     "[BTCoex],action_bt_whck_test\n");
2657         BTC_TRACE(trace_buf);
2658
2659         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2660
2661         halbtc8822b1ant_set_ant_path(btcoexist,
2662                                      BTC_ANT_PATH_AUTO,
2663                                      NORMAL_EXEC,
2664                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
2665
2666         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2667 }
2668
2669 void halbtc8822b1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
2670 {
2671         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2672                     "[BTCoex],action_wifi_multi_port\n");
2673         BTC_TRACE(trace_buf);
2674
2675         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2676
2677         halbtc8822b1ant_set_ant_path(btcoexist,
2678                                      BTC_ANT_PATH_AUTO,
2679                                      NORMAL_EXEC,
2680                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
2681
2682         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2683 }
2684
2685 void halbtc8822b1ant_action_hs(IN struct btc_coexist *btcoexist)
2686 {
2687         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2688                     "[BTCoex], action_hs\n");
2689         BTC_TRACE(trace_buf);
2690
2691         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2692
2693         halbtc8822b1ant_set_ant_path(btcoexist,
2694                                      BTC_ANT_PATH_AUTO,
2695                                      NORMAL_EXEC,
2696                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
2697
2698         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2699 }
2700
2701 /*"""bt inquiry"""" + wifi any + bt any*/
2702 void halbtc8822b1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
2703 {
2704
2705         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2706         boolean                 wifi_connected = false, ap_enable = false, wifi_busy = false,
2707                                 bt_busy = false;
2708
2709
2710         boolean         wifi_scan = false, link = false, roam = false;
2711
2712         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2713                     "[BTCoex], ********** (bt inquiry) **********\n");
2714         BTC_TRACE(trace_buf);
2715         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2716                            &ap_enable);
2717         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2718                            &wifi_connected);
2719         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2720         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
2721
2722
2723         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
2724         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2725         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2726
2727
2728         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2729                 "[BTCoex], ********** scan = %d,  link =%d, roam = %d**********\n",
2730                     wifi_scan, link, roam);
2731         BTC_TRACE(trace_buf);
2732
2733         if ((link) || (roam) || (coex_sta->wifi_is_high_pri_task)) {
2734
2735                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2736                         "[BTCoex], ********** (bt inquiry wifi  connect or scan ) **********\n");
2737                 BTC_TRACE(trace_buf);
2738
2739                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
2740
2741                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2742
2743         } else if ((wifi_scan) && (coex_sta->bt_create_connection)) {
2744
2745                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2746                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2747
2748         } else if ((!wifi_connected) && (!wifi_scan)) {
2749
2750                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2751                         "[BTCoex], ********** (bt inquiry wifi non connect) **********\n");
2752                 BTC_TRACE(trace_buf);
2753
2754                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2755
2756                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2757
2758         } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) {
2759
2760                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2761                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2762         } else if (bt_link_info->a2dp_exist) {
2763
2764                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2765
2766                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
2767         } else if (wifi_scan) {
2768
2769                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
2770
2771                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2772         } else if (wifi_busy) {
2773
2774                 /* for BT inquiry/page fail after S4 resume */
2775                 /* halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);            */
2776                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2777
2778                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2779                                                      6);
2780         } else {
2781                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2782                         "[BTCoex], ********** (bt inquiry wifi connect) **********\n");
2783                 BTC_TRACE(trace_buf);
2784
2785                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2786
2787                 halbtc8822b1ant_set_ant_path(btcoexist,
2788                                              BTC_ANT_PATH_AUTO,
2789                                              NORMAL_EXEC,
2790                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
2791
2792                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2793                                                      4);
2794         }
2795
2796         /*
2797                 if ((wifi_link) || (wifi_roam) || (coex_sta->wifi_is_high_pri_task)) {
2798
2799                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
2800                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2801
2802                 } else if ((wifi_scan) && (coex_sta->bt_create_connection)) {
2803
2804                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2805                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2806
2807                 } else if ((!wifi_connected) && (!wifi_scan)) {
2808
2809                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2810
2811                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2812                 } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) {
2813
2814                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2815                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2816
2817                 } else if (bt_link_info->a2dp_exist) {
2818
2819                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2820
2821                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2822                 } else if (wifi_scan) {
2823
2824                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
2825
2826                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2827
2828                 } else if (wifi_busy) {
2829                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21);
2830
2831                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2832                 } else {
2833                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 19);
2834
2835                         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2836                 }
2837         */
2838 }
2839
2840 void halbtc8822b1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
2841                 *btcoexist, IN u8 wifi_status)
2842 {
2843
2844         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2845
2846         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
2847
2848         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2849                     "[BTCoex], ********** (bt sco hid only busy) **********\n");
2850         BTC_TRACE(trace_buf);
2851
2852         /*SCO  + wifi connected idle or busy / 0x778=1@wifi slot*/
2853         if (bt_link_info->sco_exist) {
2854
2855                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
2856                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2857                 /*case16 for connect SCO first then connect a2sp fail issue*/
2858                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 16);
2859
2860         } else { /* HID  + wifi connected idle or busy / 0x778=1@wifi slot */
2861
2862                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
2863
2864                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2865                 /*case16 for connect HID first then connect a2sp fail issue*/
2866                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 16);
2867
2868         }
2869 }
2870
2871 /*wifi connected + bt acl busy*/
2872 void halbtc8822b1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
2873                 *btcoexist, IN u8 wifi_status)
2874 {
2875
2876         u8              bt_rssi_state;
2877         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2878         boolean wifi_busy = false, wifi_turbo = false;
2879         u32  wifi_bw = 1;
2880
2881         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
2882                                    &wifi_bw);
2883 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2884         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2885                                    &coex_sta->scan_ap_num);
2886         bt_rssi_state = halbtc8822b1ant_bt_rssi_state(2, 28, 0);
2887
2888         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2889 "[BTCoex], ********** (wifi connect acl busy) **********\n");
2890         BTC_TRACE(trace_buf);
2891
2892
2893
2894         if (bt_link_info->hid_only) { /* HID  + wifi connected idle or busy / 0x778=1@wifi slot */
2895
2896
2897
2898
2899                 btcoexist->btc_write_1byte_bitmask(
2900                         btcoexist, 0x45e, 0x8, 0x1);
2901
2902
2903
2904                 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
2905                                 wifi_status);
2906                 return;
2907         } else if (
2908                 bt_link_info->a2dp_only) { /* A2DP  + wifi connected idle or busy */
2909                 if (BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
2910
2911
2912                         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e,
2913                                                            0x8, 0x1);
2914
2915                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2916                                                 32);
2917                         halbtc8822b1ant_coex_table_with_type(btcoexist,
2918                                                              NORMAL_EXEC, 0);
2919                 } else {
2920                         if (coex_sta->scan_ap_num >=
2921                             BT_8822B_1ANT_WIFI_NOISY_THRESH)  {
2922                                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2923                                                         true,
2924                                                         17);
2925                         }       else {
2926
2927
2928
2929
2930                                 btcoexist->btc_write_1byte_bitmask(
2931                                         btcoexist, 0x45e, 0x8, 0x1);
2932
2933                                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2934                                                         true,
2935                                                         42);
2936
2937                                 halbtc8822b1ant_coex_table_with_type(btcoexist,
2938                                 NORMAL_EXEC, 1);
2939                 }
2940 /*
2941                         halbtc8822b1ant_coex_table_with_type(btcoexist,
2942                                                              NORMAL_EXEC, 1);
2943 */
2944                         coex_dm->auto_tdma_adjust = true;
2945                 }
2946
2947                 /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
2948         } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
2949                    (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
2950                 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
2951
2952                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
2953                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 47);
2954                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2955                                                      6);
2956         } else if (bt_link_info->hid_exist &&
2957                    bt_link_info->a2dp_exist) { /* HID+A2DP */
2958
2959                 btcoexist->btc_write_1byte_bitmask(
2960                         btcoexist, 0x45e, 0x8, 0x1);
2961                 if (!wifi_busy) {
2962 /*a2dp glitch while wl idle , change the 0x6c0=5a5a5a5a->5555or aaaa55aa*/
2963                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2964                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2965                                                                 true,
2966                                                                 32);
2967                         } else if (wifi_bw == 0) { /* 11bg mode */
2968                         halbtc8822b1ant_coex_table_with_type(btcoexist,
2969                                                                                  NORMAL_EXEC, 1);
2970                           halbtc8822b1ant_set_wltoggle_coex_table(
2971                                 btcoexist,
2972                                 NORMAL_EXEC,
2973                                 0x3, 0xaa,
2974                                 0x5a, 0xaa,
2975                                 0xaa);
2976                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2977                                                                 true,
2978                                                                 49);
2979                 } else {
2980                 /*if in open space , and ask wl tp , 0x60=6135031111,55555555,aaaa55aa*/
2981                 halbtc8822b1ant_coex_table_with_type(btcoexist,
2982                                                                                  NORMAL_EXEC, 1);
2983                 halbtc8822b1ant_set_wltoggle_coex_table(btcoexist, NORMAL_EXEC, 0x2, 0xaa, 0x5a, 0xaa, 0xaa);
2984                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 49);
2985 }
2986                 /*
2987                                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2988                                                                      1);
2989                 */
2990
2991
2992
2993
2994         } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
2995                 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP)*/
2996                 /*
2997                 if (BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status)
2998                         halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2999                                                 4);
3000                 else
3001                 */
3002
3003                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
3004                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 47);
3005                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3006                                                      1);
3007         } else {
3008                 /* BT no-profile busy (0x9) */
3009
3010                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
3011                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
3012                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3013                                                      1);
3014         }
3015 }
3016
3017 /*wifi not connected + bt action*/
3018 void halbtc8822b1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
3019 {
3020         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3021                     "[BTCoex], ********** (wifi not connect) **********\n");
3022         BTC_TRACE(trace_buf);
3023
3024         /* tdma and coex table */
3025         halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
3026
3027         halbtc8822b1ant_set_ant_path(btcoexist,
3028                                      BTC_ANT_PATH_AUTO,
3029                                      NORMAL_EXEC,
3030                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
3031
3032         halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3033 }
3034
3035 /*""""wl not connected scan"""" + bt action*/
3036 void halbtc8822b1ant_action_wifi_not_connected_scan(IN struct btc_coexist
3037                 *btcoexist)
3038 {
3039
3040         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3041         boolean wifi_connected = false, bt_hs_on = false;
3042         u32     wifi_link_status = 0;
3043         u32     num_of_wifi_link = 0;
3044         boolean bt_ctrl_agg_buf_size = false;
3045         u8      agg_buf_size = 5;
3046
3047         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3048                 "[BTCoex], ********** (wifi non connect scan) **********\n");
3049         BTC_TRACE(trace_buf);
3050
3051         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3052         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3053                            &wifi_link_status);
3054
3055         num_of_wifi_link = wifi_link_status >> 16;
3056
3057         if (num_of_wifi_link >= 2) {
3058                 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3059                 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3060                                            bt_ctrl_agg_buf_size, agg_buf_size);
3061
3062                 if (coex_sta->c2h_bt_inquiry_page) {
3063                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3064                                 "############# [BTCoex],  BT Is Inquirying\n");
3065                         BTC_TRACE(trace_buf);
3066                         halbtc8822b1ant_action_bt_inquiry(btcoexist);
3067                 } else
3068                         halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3069                 return;
3070         }
3071
3072         if (coex_sta->c2h_bt_inquiry_page) {
3073                 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3074                 return;
3075         } else if (bt_hs_on) {
3076                 halbtc8822b1ant_action_hs(btcoexist);
3077                 return;
3078         }
3079
3080         /* tdma and coex table */
3081         if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
3082                 if (bt_link_info->a2dp_exist) {
3083                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3084                                                 32);
3085                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3086                                                              NORMAL_EXEC, 1);
3087                 } else if (bt_link_info->a2dp_exist &&
3088                            bt_link_info->pan_exist) {
3089                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3090                                                 22);
3091                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3092                                                              NORMAL_EXEC, 1);
3093                 } else {
3094                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3095                                                 20);
3096                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3097                                                              NORMAL_EXEC, 1);
3098                 }
3099         } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3100                    (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3101                     coex_dm->bt_status)) {
3102                 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
3103                                 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
3104         } else {
3105
3106                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3107
3108                 halbtc8822b1ant_set_ant_path(btcoexist,
3109                                              BTC_ANT_PATH_AUTO,
3110                                              NORMAL_EXEC,
3111                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
3112
3113                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3114                                                      5);
3115         }
3116 }
3117
3118 /*""""wl not connected asso"""" + bt action*/
3119 void halbtc8822b1ant_action_wifi_not_connected_asso_auth(
3120         IN struct btc_coexist *btcoexist)
3121 {
3122
3123         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3124         boolean wifi_connected = false, bt_hs_on = false;
3125         u32 wifi_link_status = 0;
3126         u32 num_of_wifi_link = 0;
3127         boolean bt_ctrl_agg_buf_size = false;
3128         u8      agg_buf_size = 5;
3129
3130         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3131                 "[BTCoex], ********** (wifi non connect asso_auth) **********\n");
3132         BTC_TRACE(trace_buf);
3133
3134         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3135         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3136                            &wifi_link_status);
3137
3138         num_of_wifi_link = wifi_link_status >> 16;
3139
3140         if (num_of_wifi_link >= 2) {
3141
3142                 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3143                 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3144                                            bt_ctrl_agg_buf_size,
3145                                            agg_buf_size);
3146
3147                 if (coex_sta->c2h_bt_inquiry_page) {
3148                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3149                                 "############# [BTCoex],  BT Is Inquirying\n");
3150                         BTC_TRACE(trace_buf);
3151                         halbtc8822b1ant_action_bt_inquiry(btcoexist);
3152                 } else
3153                         halbtc8822b1ant_action_wifi_multi_port(
3154                                 btcoexist);
3155                 return;
3156         }
3157
3158         if (coex_sta->c2h_bt_inquiry_page) {
3159                 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3160                 return;
3161         } else if (bt_hs_on) {
3162                 halbtc8822b1ant_action_hs(btcoexist);
3163                 return;
3164         }
3165
3166
3167         /* tdma and coex table */
3168         if ((bt_link_info->sco_exist)  || (bt_link_info->hid_exist) ||
3169             (bt_link_info->a2dp_exist)) {
3170
3171                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
3172                 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
3173         } else if (bt_link_info->pan_exist) {
3174                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
3175                 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
3176         } else {
3177
3178                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3179
3180                 halbtc8822b1ant_set_ant_path(btcoexist,
3181                                              BTC_ANT_PATH_AUTO,
3182                                              NORMAL_EXEC,
3183                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
3184
3185                 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
3186         }
3187 }
3188
3189 /*""""wl  connected scan"""" + bt action*/
3190 void halbtc8822b1ant_action_wifi_connected_scan(IN struct btc_coexist
3191                 *btcoexist)
3192 {
3193
3194         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3195         boolean wifi_connected = false, bt_hs_on = false;
3196         u32     wifi_link_status = 0;
3197         u32     num_of_wifi_link = 0;
3198         boolean bt_ctrl_agg_buf_size = false;
3199         u8      agg_buf_size = 5;
3200
3201         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3202                     "[BTCoex], ********** (wifi connect scan) **********\n");
3203         BTC_TRACE(trace_buf);
3204
3205         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3206         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3207                            &wifi_link_status);
3208
3209         num_of_wifi_link = wifi_link_status >> 16;
3210
3211         if (num_of_wifi_link >= 2) {
3212                 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3213                 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3214                                            bt_ctrl_agg_buf_size, agg_buf_size);
3215
3216                 if (coex_sta->c2h_bt_inquiry_page) {
3217                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3218                                 "############# [BTCoex],  BT Is Inquirying\n");
3219                         BTC_TRACE(trace_buf);
3220                         halbtc8822b1ant_action_bt_inquiry(btcoexist);
3221                 } else
3222                         halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3223                 return;
3224         }
3225
3226         if (coex_sta->c2h_bt_inquiry_page) {
3227                 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3228                 return;
3229         } else if (bt_hs_on) {
3230                 halbtc8822b1ant_action_hs(btcoexist);
3231                 return;
3232         }
3233
3234         /* tdma and coex table */
3235         if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
3236                 if (bt_link_info->a2dp_exist) {
3237                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3238                                                 32);
3239                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3240                                                              NORMAL_EXEC, 1);
3241                 } else if (bt_link_info->a2dp_exist &&
3242                            bt_link_info->pan_exist) {
3243                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3244                                                 22);
3245                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3246                                                              NORMAL_EXEC, 1);
3247                 } else {
3248                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3249                                                 20);
3250                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3251                                                              NORMAL_EXEC, 1);
3252                 }
3253         } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3254                    (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3255                     coex_dm->bt_status)) {
3256                 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
3257                                 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
3258         } else {
3259
3260                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3261
3262                 halbtc8822b1ant_set_ant_path(btcoexist,
3263                                              BTC_ANT_PATH_AUTO,
3264                                              NORMAL_EXEC,
3265                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
3266
3267                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3268                                                      6);
3269         }
3270 }
3271
3272 /*""""wl  connected specific packet"""" + bt action*/
3273 void halbtc8822b1ant_action_wifi_connected_specific_packet(
3274         IN struct btc_coexist *btcoexist)
3275 {
3276
3277         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3278         boolean wifi_connected = false, bt_hs_on = false;
3279         u32     wifi_link_status = 0;
3280         u32     num_of_wifi_link = 0;
3281         boolean bt_ctrl_agg_buf_size = false;
3282         u8      agg_buf_size = 5;
3283         boolean wifi_busy = false;
3284
3285         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3286                 "[BTCoex], ********** (wifi connect specific packet) **********\n");
3287         BTC_TRACE(trace_buf);
3288
3289         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3290         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3291                            &wifi_link_status);
3292
3293         num_of_wifi_link = wifi_link_status >> 16;
3294
3295         if (num_of_wifi_link >= 2) {
3296                 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3297                 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3298                                            bt_ctrl_agg_buf_size, agg_buf_size);
3299
3300                 if (coex_sta->c2h_bt_inquiry_page) {
3301                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3302                                 "############# [BTCoex],  BT Is Inquirying\n");
3303                         BTC_TRACE(trace_buf);
3304                         halbtc8822b1ant_action_bt_inquiry(btcoexist);
3305                 } else
3306                         halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3307                 return;
3308         }
3309
3310         if (coex_sta->c2h_bt_inquiry_page) {
3311                 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3312                 return;
3313         } else if (bt_hs_on) {
3314                 halbtc8822b1ant_action_hs(btcoexist);
3315                 return;
3316         }
3317
3318
3319         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3320
3321         /* no specific packet process for both WiFi and BT very busy */
3322         if ((wifi_busy) && ((bt_link_info->pan_exist) ||
3323                             (coex_sta->num_of_profile >= 2)))
3324                 return;
3325
3326         /* tdma and coex table */
3327         if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
3328                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
3329                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3330         } else if (bt_link_info->a2dp_exist) {
3331                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
3332                 /*for a2dp glitch,change from 1 to 15*/
3333                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3334                                                      15);
3335         } else if (bt_link_info->pan_exist) {
3336                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
3337                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3338                                                      1);
3339         } else {
3340
3341                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3342
3343                 halbtc8822b1ant_set_ant_path(btcoexist,
3344                                              BTC_ANT_PATH_AUTO,
3345                                              NORMAL_EXEC,
3346                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
3347
3348                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3349                                                      5);
3350         }
3351 }
3352
3353 /*wifi connected input point : to set different ps and tdma case (+bt different case)*/
3354 void halbtc8822b1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
3355 {
3356
3357         boolean wifi_busy = false;
3358         boolean         scan = false, link = false, roam = false;
3359         boolean         under_4way = false, ap_enable = false, wifi_under_5g = false;
3360         u8 wifi_rssi_state;
3361
3362
3363         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3364                     "[BTCoex], CoexForWifiConnect()===>\n");
3365         BTC_TRACE(trace_buf);
3366
3367         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3368
3369         if (wifi_under_5g) {
3370
3371                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3372                         "[BTCoex], CoexForWifiConnect(), return for wifi is under 5g<===\n");
3373                 BTC_TRACE(trace_buf);
3374
3375                 halbtc8822b1ant_action_wifi_under5g(btcoexist);
3376
3377                 return;
3378         }
3379
3380         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3381                 "[BTCoex], CoexForWifiConnect(), return for wifi is under 2g<===\n");
3382         BTC_TRACE(trace_buf);
3383
3384         halbtc8822b1ant_set_ant_path(btcoexist,
3385                                      BTC_ANT_PATH_AUTO,
3386                                      NORMAL_EXEC,
3387                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
3388
3389
3390         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
3391                            &under_4way);
3392
3393         if (under_4way) {
3394                 halbtc8822b1ant_action_wifi_connected_specific_packet(
3395                         btcoexist);
3396                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3397                         "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
3398                 BTC_TRACE(trace_buf);
3399                 return;
3400         }
3401
3402         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3403         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3404         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3405         if (scan || link || roam) {
3406                 if (scan)
3407                         halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
3408                 else
3409                         halbtc8822b1ant_action_wifi_connected_specific_packet(
3410                                 btcoexist);
3411                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3412                         "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
3413                 BTC_TRACE(trace_buf);
3414                 return;
3415         }
3416
3417         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3418                            &ap_enable);
3419         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3420
3421         /* tdma and coex table */
3422         if (!wifi_busy) {
3423                 if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
3424                         halbtc8822b1ant_action_wifi_connected_bt_acl_busy(
3425                                 btcoexist,
3426                                 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
3427                 } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY ==
3428                             coex_dm->bt_status) ||
3429                            (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3430                             coex_dm->bt_status)) {
3431                         halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
3432                                 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
3433                 } else {
3434
3435                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3436                                                 8);
3437
3438                         halbtc8822b1ant_set_ant_path(btcoexist,
3439                                                      BTC_ANT_PATH_AUTO,
3440                                                      NORMAL_EXEC,
3441                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
3442
3443                         if ((coex_sta->high_priority_tx) +
3444                             (coex_sta->high_priority_rx) <= 60)
3445                                 /*sy modify case16 -> case17*/
3446                                 halbtc8822b1ant_coex_table_with_type(btcoexist,
3447                                                              NORMAL_EXEC, 1);
3448                         else
3449                                 halbtc8822b1ant_coex_table_with_type(btcoexist,
3450                                                              NORMAL_EXEC, 1);
3451                 }
3452         } else {
3453                 if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
3454                         halbtc8822b1ant_action_wifi_connected_bt_acl_busy(
3455                                 btcoexist,
3456                                 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
3457                 } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY ==
3458                             coex_dm->bt_status) ||
3459                            (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3460                             coex_dm->bt_status)) {
3461                         halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
3462                                 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
3463                 } else {
3464
3465
3466
3467                         halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3468                                                 8);
3469
3470                         halbtc8822b1ant_set_ant_path(btcoexist,
3471                                                      BTC_ANT_PATH_AUTO,
3472                                                      NORMAL_EXEC,
3473                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
3474
3475                         /*
3476
3477                                                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3478                                                                                         32);
3479
3480                                                 halbtc8822b1ant_set_ant_path(btcoexist,
3481                                                 BTC_ANT_PATH_AUTO, NORMAL_EXEC, BT_8822B_1ANT_PHASE_2G_RUNTIME);
3482                         */
3483
3484
3485
3486                         wifi_rssi_state = halbtc8822b1ant_wifi_rssi_state(
3487                                                   btcoexist, 1, 2, 25, 0);
3488
3489                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3490                                 "[BTCoex], ********** before  **********\n");
3491                         BTC_TRACE(trace_buf);
3492 /*
3493                         if ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3494                              coex_dm->bt_status)  &&
3495                             (coex_sta->scan_ap_num <= 3) &&
3496                             (wifi_rssi_state == BTC_RSSI_STATE_LOW ||
3497                              wifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
3498 */
3499                         if (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3500                         coex_dm->bt_status) {
3501                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3502                                         "[BTCoex], ********** scan ap <3 coex table=0xaaaaaaaa **********\n");
3503                                 BTC_TRACE(trace_buf);
3504
3505                                 halbtc8822b1ant_coex_table_with_type(btcoexist,
3506                                                              NORMAL_EXEC, 7);
3507                         } else
3508
3509                                 halbtc8822b1ant_coex_table_with_type(btcoexist,
3510                                                              NORMAL_EXEC, 1);
3511
3512
3513
3514                         /*
3515                                                 else if ((coex_sta->high_priority_tx +
3516                                                                                  coex_sta->high_priority_rx) <= 60)
3517                                                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3518                                                                                      NORMAL_EXEC, 1);
3519                                                 else
3520                                                         halbtc8822b1ant_coex_table_with_type(btcoexist,
3521                                                                                      NORMAL_EXEC, 4);
3522                         */
3523                 }
3524         }
3525 }
3526
3527 void halbtc8822b1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
3528 {
3529
3530         u8                              algorithm = 0;
3531
3532         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3533                     "[BTCoex], ********** (runswcoexmech) **********\n");
3534         BTC_TRACE(trace_buf);
3535         algorithm = halbtc8822b1ant_action_algorithm(btcoexist);
3536         coex_dm->cur_algorithm = algorithm;
3537
3538         if (halbtc8822b1ant_is_common_action(btcoexist)) {
3539
3540         } else {
3541                 switch (coex_dm->cur_algorithm) {
3542                 case BT_8822B_1ANT_COEX_ALGO_SCO:
3543                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3544                                     "[BTCoex], Action algorithm = SCO.\n");
3545                         BTC_TRACE(trace_buf);
3546                         /* halbtc8822b1ant_action_sco(btcoexist); */
3547                         break;
3548                 case BT_8822B_1ANT_COEX_ALGO_HID:
3549                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3550                                     "[BTCoex], Action algorithm = HID.\n");
3551                         BTC_TRACE(trace_buf);
3552                         /* halbtc8822b1ant_action_hid(btcoexist); */
3553                         break;
3554                 case BT_8822B_1ANT_COEX_ALGO_A2DP:
3555                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3556                                     "[BTCoex], Action algorithm = A2DP.\n");
3557                         BTC_TRACE(trace_buf);
3558                         /* halbtc8822b1ant_action_a2dp(btcoexist); */
3559                         break;
3560                 case BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS:
3561                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3562                                 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
3563                         BTC_TRACE(trace_buf);
3564                         /* halbtc8822b1ant_action_a2dp_pan_hs(btcoexist); */
3565                         break;
3566                 case BT_8822B_1ANT_COEX_ALGO_PANEDR:
3567                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3568                                     "[BTCoex], Action algorithm = PAN(EDR).\n");
3569                         BTC_TRACE(trace_buf);
3570                         /* halbtc8822b1ant_action_pan_edr(btcoexist); */
3571                         break;
3572                 case BT_8822B_1ANT_COEX_ALGO_PANHS:
3573                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3574                                     "[BTCoex], Action algorithm = HS mode.\n");
3575                         BTC_TRACE(trace_buf);
3576                         /* halbtc8822b1ant_action_pan_hs(btcoexist); */
3577                         break;
3578                 case BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP:
3579                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3580                                     "[BTCoex], Action algorithm = PAN+A2DP.\n");
3581                         BTC_TRACE(trace_buf);
3582                         /* halbtc8822b1ant_action_pan_edr_a2dp(btcoexist); */
3583                         break;
3584                 case BT_8822B_1ANT_COEX_ALGO_PANEDR_HID:
3585                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3586                                 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
3587                         BTC_TRACE(trace_buf);
3588                         /* halbtc8822b1ant_action_pan_edr_hid(btcoexist); */
3589                         break;
3590                 case BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
3591                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3592                                 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
3593                         BTC_TRACE(trace_buf);
3594                         /* halbtc8822b1ant_action_hid_a2dp_pan_edr(btcoexist); */
3595                         break;
3596                 case BT_8822B_1ANT_COEX_ALGO_HID_A2DP:
3597                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3598                                     "[BTCoex], Action algorithm = HID+A2DP.\n");
3599                         BTC_TRACE(trace_buf);
3600                         /* halbtc8822b1ant_action_hid_a2dp(btcoexist); */
3601                         break;
3602                 default:
3603                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3604                                 "[BTCoex], Action algorithm = coexist All Off!!\n");
3605                         BTC_TRACE(trace_buf);
3606                         /* halbtc8822b1ant_coex_all_off(btcoexist); */
3607                         break;
3608                 }
3609                 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3610         }
3611 }
3612
3613 void halbtc8822b1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
3614 {
3615
3616         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3617         boolean wifi_connected = false, bt_hs_on = false;
3618         boolean increase_scan_dev_num = false;
3619         boolean bt_ctrl_agg_buf_size = false;
3620         boolean miracast_plus_bt = false;
3621         u8      agg_buf_size = 5;
3622         u32     wifi_link_status = 0;
3623         u32     num_of_wifi_link = 0, wifi_bw;
3624         u8      iot_peer = BTC_IOT_PEER_UNKNOWN;
3625         boolean wifi_under_5g = false;
3626
3627
3628         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3629                     "[BTCoex], RunCoexistMechanism()===>\n");
3630         BTC_TRACE(trace_buf);
3631
3632         if (btcoexist->manual_control) {
3633                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3634                         "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3635                 BTC_TRACE(trace_buf);
3636                 return;
3637         }
3638
3639         if (btcoexist->stop_coex_dm) {
3640                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3641                         "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3642                 BTC_TRACE(trace_buf);
3643                 return;
3644         }
3645
3646         if (coex_sta->under_ips) {
3647                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3648                             "[BTCoex], wifi is under IPS !!!\n");
3649                 BTC_TRACE(trace_buf);
3650                 return;
3651         }
3652
3653         if (!coex_sta->run_time_state) {
3654                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3655                         "[BTCoex], return for run_time_state = false !!!\n");
3656                 BTC_TRACE(trace_buf);
3657                 return;
3658         }
3659
3660         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3661         if (wifi_under_5g) {
3662                 halbtc8822b1ant_action_wifi_under5g(btcoexist);
3663
3664                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3665                             "[BTCoex], WiFi is under 5G!!!\n");
3666                 BTC_TRACE(trace_buf);
3667                 return;
3668         }
3669
3670         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3671                     "[BTCoex], WiFi is under 2G!!!\n");
3672         BTC_TRACE(trace_buf);
3673
3674         halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3675                                      NORMAL_EXEC,
3676                                      BT_8822B_1ANT_PHASE_2G_RUNTIME);
3677
3678         if (coex_sta->bt_whck_test) {
3679                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3680                             "[BTCoex], BT is under WHCK TEST!!!\n");
3681                 BTC_TRACE(trace_buf);
3682                 halbtc8822b1ant_action_bt_whck_test(btcoexist);
3683                 return;
3684         }
3685
3686         if (coex_sta->bt_disabled) {
3687                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3688                             "[BTCoex], BT is disabled !!!\n");
3689                 halbtc8822b1ant_action_wifi_only(btcoexist);
3690                 return;
3691         }
3692
3693         if ((BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3694             (BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3695             (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3696                 increase_scan_dev_num = true;
3697
3698         btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
3699                            &increase_scan_dev_num);
3700         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3701                            &wifi_connected);
3702
3703         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3704                            &wifi_link_status);
3705         num_of_wifi_link = wifi_link_status >> 16;
3706
3707         if ((num_of_wifi_link >= 2) ||
3708             (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3709                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3710                         "############# [BTCoex],  Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3711                             num_of_wifi_link, wifi_link_status);
3712                 BTC_TRACE(trace_buf);
3713
3714                 if (bt_link_info->bt_link_exist) {
3715                         halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
3716                                                    0, 1);
3717                         miracast_plus_bt = true;
3718                 } else {
3719                         halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
3720                                                    0, 0);
3721                         miracast_plus_bt = false;
3722                 }
3723                 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3724                                    &miracast_plus_bt);
3725                 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3726                                            bt_ctrl_agg_buf_size, agg_buf_size);
3727
3728                 if ((bt_link_info->a2dp_exist) &&
3729                     (coex_sta->c2h_bt_inquiry_page)) {
3730                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3731                                 "############# [BTCoex],  BT Is Inquirying\n");
3732                         BTC_TRACE(trace_buf);
3733                         halbtc8822b1ant_action_bt_inquiry(btcoexist);
3734                 } else
3735                         halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3736
3737                 return;
3738         }
3739
3740         miracast_plus_bt = false;
3741         btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3742                            &miracast_plus_bt);
3743
3744         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3745
3746         if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
3747                 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
3748
3749                 btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
3750
3751                 if (BTC_IOT_PEER_CISCO != iot_peer) {
3752                         if (bt_link_info->sco_exist) /* if (bt_link_info->bt_hi_pri_link_exist) */
3753                                 halbtc8822b1ant_limited_rx(btcoexist,
3754                                            NORMAL_EXEC, true, false, 0x5);
3755                         else
3756                                 halbtc8822b1ant_limited_rx(btcoexist,
3757                                            NORMAL_EXEC, false, false, 0x5);
3758                 } else {
3759                         if (bt_link_info->sco_exist)
3760                                 halbtc8822b1ant_limited_rx(btcoexist,
3761                                            NORMAL_EXEC, true, false, 0x5);
3762                         else {
3763                                 if (BTC_WIFI_BW_HT40 == wifi_bw)
3764                                         halbtc8822b1ant_limited_rx(btcoexist,
3765                                                 NORMAL_EXEC, false, true, 0x10);
3766                                 else
3767                                         halbtc8822b1ant_limited_rx(btcoexist,
3768                                                 NORMAL_EXEC, false, true, 0x8);
3769                         }
3770                 }
3771
3772                 halbtc8822b1ant_sw_mechanism(btcoexist, true);
3773                 halbtc8822b1ant_run_sw_coexist_mechanism(
3774                         btcoexist);  /* just print debug message */
3775         } else {
3776                 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3777
3778                 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3779                                            0x5);
3780
3781                 halbtc8822b1ant_sw_mechanism(btcoexist, false);
3782                 halbtc8822b1ant_run_sw_coexist_mechanism(
3783                         btcoexist); /* just print debug message */
3784         }
3785
3786         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3787         if (coex_sta->c2h_bt_inquiry_page) {
3788                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3789                             "############# [BTCoex],  BT Is Inquirying\n");
3790                 BTC_TRACE(trace_buf);
3791                 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3792                 return;
3793         } else if (bt_hs_on) {
3794                 halbtc8822b1ant_action_hs(btcoexist);
3795                 return;
3796         }
3797
3798
3799         if (!wifi_connected) {
3800                 boolean scan = false, link = false, roam = false;
3801
3802                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3803                             "[BTCoex], wifi is non connected-idle !!!\n");
3804                 BTC_TRACE(trace_buf);
3805
3806                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3807                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3808                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3809
3810                 if (scan || link || roam) {
3811                         if (scan)
3812                                 halbtc8822b1ant_action_wifi_not_connected_scan(
3813                                         btcoexist);
3814                         else
3815                                 halbtc8822b1ant_action_wifi_not_connected_asso_auth(
3816                                         btcoexist);
3817                 } else
3818                         halbtc8822b1ant_action_wifi_not_connected(btcoexist);
3819         } else  /* wifi LPS/Busy */
3820                 halbtc8822b1ant_action_wifi_connected(btcoexist);
3821 }
3822
3823 u32 halbtc8822b1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val)
3824 {
3825         u8      j;
3826         u32     tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0;
3827         u32     result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200,
3828                                    174, 151, 132, 115, 100, 86, 74, 62, 51, 42,
3829                                                            32, 23, 15, 7, 0
3830                                                               };
3831
3832         if (val == 0)
3833                 return 0;
3834
3835         tmp = val;
3836
3837         while (1) {
3838                 if (tmp == 1)
3839                         break;
3840
3841                 tmp = (tmp >> 1);
3842                 shiftcount++;
3843         }
3844
3845
3846         val_integerd_b = shiftcount + 1;
3847
3848         tmp2 = 1;
3849         for (j = 1; j <= val_integerd_b; j++)
3850                 tmp2 = tmp2 * 2;
3851
3852         tmp = (val * 100) / tmp2;
3853         tindex = tmp / 5;
3854
3855         if (tindex > 20)
3856                 tindex = 20;
3857
3858         val_fractiond_b = table_fraction[tindex];
3859
3860         result = val_integerd_b * 100 - val_fractiond_b;
3861
3862         return result;
3863
3864
3865 }
3866
3867 void halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
3868 {
3869         /* force to reset coex mechanism */
3870
3871         halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
3872
3873         /* sw all off */
3874         halbtc8822b1ant_sw_mechanism(btcoexist, false);
3875
3876         /* halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
3877         /* halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */
3878
3879         coex_sta->pop_event_cnt = 0;
3880 }
3881
3882 void halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
3883                                     IN boolean back_up, IN boolean wifi_only)
3884 {
3885
3886         u8      u8tmp = 0;
3887         boolean                 wifi_under_5g = false;
3888         u32                             u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
3889
3890
3891         u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3892         u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
3893         u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
3894
3895         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3896                 "[BTCoex], ********** (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
3897                     u32tmp3, u32tmp1, u32tmp2);
3898         BTC_TRACE(trace_buf);
3899
3900         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3901                     "[BTCoex], 1Ant Init HW Config!!\n");
3902         BTC_TRACE(trace_buf);
3903
3904         coex_sta->bt_coex_supported_feature = 0;
3905         coex_sta->bt_coex_supported_version = 0;
3906
3907         /* Setup RF front end type */
3908         halbtc8822b1ant_set_rfe_type(btcoexist);
3909
3910         /* 0xf0[15:12] --> Chip Cut information */
3911         coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
3912                                  0xf1) & 0xf0) >> 4;
3913
3914         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
3915                                            0x1);  /* enable TBTT nterrupt */
3916
3917         /* BT report packet sample rate  */
3918         /* 0x790[5:0]=0x5 */
3919         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3920         u8tmp &= 0xc0;
3921         u8tmp |= 0x5;
3922         btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
3923
3924         /* Enable BT counter statistics */
3925         btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
3926
3927         /* Enable PTA (3-wire function form BT side) */
3928         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3929         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
3930
3931         /* Enable PTA (tx/rx signal form WiFi side) */
3932         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
3933         /*GNT_BT=1 while select both */
3934         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
3935
3936         /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
3937         /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);*/
3938
3939         /* enable GNT_WL */
3940         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0);
3941         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0);
3942
3943         if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)
3944                 halbtc8822b1ant_post_state_to_bt(btcoexist,
3945                                          BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
3946
3947         /* Antenna config */
3948         if (wifi_only) {
3949
3950                 coex_sta->concurrent_rx_mode_on = false;
3951                 halbtc8822b1ant_set_ant_path(btcoexist,
3952                                              BTC_ANT_PATH_WIFI,
3953                                              FORCE_EXEC,
3954                                              BT_8822B_1ANT_PHASE_WLANONLY_INIT);
3955         } else {
3956
3957                 coex_sta->concurrent_rx_mode_on = true;
3958
3959                 halbtc8822b1ant_set_ant_path(btcoexist,
3960                                              BTC_ANT_PATH_AUTO,
3961                                              FORCE_EXEC,
3962                                              BT_8822B_1ANT_PHASE_COEX_INIT);
3963         }
3964
3965
3966         /* PTA parameter */
3967         halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
3968
3969         halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true);
3970
3971 }
3972
3973
3974 void halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist *btcoexist,
3975                 IN boolean back_up, IN boolean wifi_only)
3976 {
3977
3978         u8      u8tmp = 0;
3979         boolean         wifi_under_5g = false;
3980         u32                     u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
3981
3982
3983         /* 0xf0[15:12] --> Chip Cut information */
3984         coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
3985                                  0xf1) & 0xf0) >> 4;
3986
3987         /* enable TBTT interrupt */
3988         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
3989                                            0x1);
3990
3991         /* enable GNT_WL */
3992         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0);
3993         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0);
3994
3995         /* Antenna config */
3996         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
3997                                            0x0);  /*  0x4c[23] = 0 */
3998         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
3999                                            0x1);  /* 0x4c[24] = 1 */
4000         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff,
4001                 0x77);  /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
4002
4003
4004         /* Ext switch buffer mux */
4005         btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
4006         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
4007         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
4008
4009         /*enable sw control gnt_wl=1 / gnt_bt=1 */
4010         btcoexist->btc_write_1byte(btcoexist, 0x73, 0x0e);
4011
4012         btcoexist->btc_write_4byte(btcoexist, 0x1704, 0x0000ff00);
4013
4014         btcoexist->btc_write_4byte(btcoexist, 0x1700, 0xc00f0038);
4015
4016
4017         /* ant switch WL2G or WL5G*/
4018         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
4019                            &wifi_under_5g);
4020         if (wifi_under_5g)
4021
4022                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
4023                                                    0x3, 1);
4024
4025         else
4026
4027                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
4028                                                    0x3, 2);
4029
4030 }
4031
4032 void halbtc8822b1ant_psd_showdata(IN struct btc_coexist *btcoexist)
4033 {
4034         u8              *cli_buf = btcoexist->cli_buf;
4035         u32             delta_freq_per_point;
4036         u32             freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2;
4037
4038         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4039                    "\r\n\n============[PSD info]  (%d)============\n",
4040                    psd_scan->psd_gen_count);
4041         CL_PRINTF(cli_buf);
4042
4043         if (psd_scan->psd_gen_count == 0) {
4044                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n");
4045                 CL_PRINTF(cli_buf);
4046                 return;
4047         }
4048
4049         if (psd_scan->psd_point == 0)
4050                 delta_freq_per_point = 0;
4051         else
4052                 delta_freq_per_point = psd_scan->psd_band_width /
4053                                        psd_scan->psd_point;
4054
4055         /* if (psd_scan->is_psd_show_max_only) */
4056         if (0) {
4057                 psd_rep1 = psd_scan->psd_max_value / 100;
4058                 psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100;
4059
4060                 freq = ((psd_scan->real_cent_freq - 20) * 1000000 +
4061                         psd_scan->psd_max_value_point * delta_freq_per_point);
4062                 freq1 = freq / 1000000;
4063                 freq2 = freq / 1000 - freq1 * 1000;
4064
4065                 if (freq2 < 100)
4066                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4067                                    "\r\n Freq = %d.0%d MHz",
4068                                    freq1, freq2);
4069                 else
4070                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4071                                    "\r\n Freq = %d.%d MHz",
4072                                    freq1, freq2);
4073
4074                 if (psd_rep2 < 10)
4075                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4076                                    ", Value = %d.0%d dB, (%d)\n",
4077                                    psd_rep1, psd_rep2, psd_scan->psd_max_value);
4078                 else
4079                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4080                                    ", Value = %d.%d dB, (%d)\n",
4081                                    psd_rep1, psd_rep2, psd_scan->psd_max_value);
4082
4083                 CL_PRINTF(cli_buf);
4084         } else {
4085                 m = psd_scan->psd_start_point;
4086                 n = psd_scan->psd_start_point;
4087                 i = 1;
4088                 j = 1;
4089
4090                 while (1) {
4091                         do {
4092                                 freq = ((psd_scan->real_cent_freq - 20) *
4093                                         1000000 + m *
4094                                         delta_freq_per_point);
4095                                 freq1 = freq / 1000000;
4096                                 freq2 = freq / 1000 - freq1 * 1000;
4097
4098                                 if (i == 1) {
4099                                         if (freq2 == 0)
4100                                                 CL_SPRINTF(cli_buf,
4101                                                            BT_TMP_BUF_SIZE,
4102                                                            "\r\n Freq%6d.000",
4103                                                            freq1);
4104                                         else if (freq2 < 100)
4105                                                 CL_SPRINTF(cli_buf,
4106                                                            BT_TMP_BUF_SIZE,
4107                                                            "\r\n Freq%6d.0%2d",
4108                                                            freq1,
4109                                                            freq2);
4110                                         else
4111                                                 CL_SPRINTF(cli_buf,
4112                                                            BT_TMP_BUF_SIZE,
4113                                                            "\r\n Freq%6d.%3d",
4114                                                            freq1,
4115                                                            freq2);
4116                                 } else if ((i % 8 == 0) ||
4117                                            (m == psd_scan->psd_stop_point)) {
4118                                         if (freq2 == 0)
4119                                                 CL_SPRINTF(cli_buf,
4120                                                            BT_TMP_BUF_SIZE,
4121                                                            "%6d.000\n", freq1);
4122                                         else if (freq2 < 100)
4123                                                 CL_SPRINTF(cli_buf,
4124                                                            BT_TMP_BUF_SIZE,
4125                                                            "%6d.0%2d\n", freq1,
4126                                                            freq2);
4127                                         else
4128                                                 CL_SPRINTF(cli_buf,
4129                                                            BT_TMP_BUF_SIZE,
4130                                                            "%6d.%3d\n", freq1,
4131                                                            freq2);
4132                                 } else {
4133                                         if (freq2 == 0)
4134                                                 CL_SPRINTF(cli_buf,
4135                                                            BT_TMP_BUF_SIZE,
4136                                                            "%6d.000", freq1);
4137                                         else if (freq2 < 100)
4138                                                 CL_SPRINTF(cli_buf,
4139                                                            BT_TMP_BUF_SIZE,
4140                                                            "%6d.0%2d", freq1,
4141                                                            freq2);
4142                                         else
4143                                                 CL_SPRINTF(cli_buf,
4144                                                            BT_TMP_BUF_SIZE,
4145                                                            "%6d.%3d", freq1,
4146                                                            freq2);
4147                                 }
4148
4149                                 i++;
4150                                 m++;
4151                                 CL_PRINTF(cli_buf);
4152
4153                         } while ((i <= 8) && (m <= psd_scan->psd_stop_point));
4154
4155
4156                         do {
4157                                 psd_rep1 = psd_scan->psd_report_max_hold[n] /
4158                                            100;
4159                                 psd_rep2 = psd_scan->psd_report_max_hold[n] -
4160                                            psd_rep1 *
4161                                            100;
4162
4163                                 if (j == 1) {
4164                                         if (psd_rep2 < 10)
4165                                                 CL_SPRINTF(cli_buf,
4166                                                            BT_TMP_BUF_SIZE,
4167                                                            "\r\n Val %7d.0%d",
4168                                                            psd_rep1,
4169                                                            psd_rep2);
4170                                         else
4171                                                 CL_SPRINTF(cli_buf,
4172                                                            BT_TMP_BUF_SIZE,
4173                                                            "\r\n Val %7d.%d",
4174                                                            psd_rep1,
4175                                                            psd_rep2);
4176                                 } else if ((j % 8 == 0)  ||
4177                                            (n == psd_scan->psd_stop_point)) {
4178                                         if (psd_rep2 < 10)
4179                                                 CL_SPRINTF(cli_buf,
4180                                                            BT_TMP_BUF_SIZE,
4181                                                         "%7d.0%d\n", psd_rep1,
4182                                                            psd_rep2);
4183                                         else
4184                                                 CL_SPRINTF(cli_buf,
4185                                                            BT_TMP_BUF_SIZE,
4186                                                            "%7d.%d\n", psd_rep1,
4187                                                            psd_rep2);
4188                                 } else {
4189                                         if (psd_rep2 < 10)
4190                                                 CL_SPRINTF(cli_buf,
4191                                                            BT_TMP_BUF_SIZE,
4192                                                            "%7d.0%d", psd_rep1,
4193                                                            psd_rep2);
4194                                         else
4195                                                 CL_SPRINTF(cli_buf,
4196                                                            BT_TMP_BUF_SIZE,
4197                                                            "%7d.%d", psd_rep1,
4198                                                            psd_rep2);
4199                                 }
4200
4201                                 j++;
4202                                 n++;
4203                                 CL_PRINTF(cli_buf);
4204
4205                         } while ((j <= 8) && (n <= psd_scan->psd_stop_point));
4206
4207                         if ((m > psd_scan->psd_stop_point) ||
4208                             (n > psd_scan->psd_stop_point))
4209                                 break;
4210
4211                         i = 1;
4212                         j = 1;
4213
4214                 }
4215         }
4216
4217
4218 }
4219
4220 void halbtc8822b1ant_psd_max_holddata(IN struct btc_coexist *btcoexist,
4221                                       IN u32 gen_count)
4222 {
4223         u32     i = 0, i_max = 0, val_max = 0;
4224
4225         if (gen_count == 1) {
4226                 memcpy(psd_scan->psd_report_max_hold,
4227                        psd_scan->psd_report,
4228                        BT_8822B_1ANT_ANTDET_PSD_POINTS * sizeof(u32));
4229
4230                 for (i = psd_scan->psd_start_point;
4231                      i <= psd_scan->psd_stop_point; i++) {
4232
4233                 }
4234
4235                 psd_scan->psd_max_value_point = 0;
4236                 psd_scan->psd_max_value = 0;
4237
4238         } else {
4239                 for (i = psd_scan->psd_start_point;
4240                      i <= psd_scan->psd_stop_point; i++) {
4241                         if (psd_scan->psd_report[i] >
4242                             psd_scan->psd_report_max_hold[i])
4243                                 psd_scan->psd_report_max_hold[i] =
4244                                         psd_scan->psd_report[i];
4245
4246                         /* search Max Value */
4247                         if (i == psd_scan->psd_start_point) {
4248                                 i_max = i;
4249                                 val_max = psd_scan->psd_report_max_hold[i];
4250                         } else {
4251                                 if (psd_scan->psd_report_max_hold[i] >
4252                                     val_max) {
4253                                         i_max = i;
4254                                         val_max = psd_scan->psd_report_max_hold[i];
4255                                 }
4256                         }
4257
4258
4259
4260                 }
4261
4262                 psd_scan->psd_max_value_point = i_max;
4263                 psd_scan->psd_max_value = val_max;
4264
4265         }
4266
4267
4268 }
4269
4270 u32 halbtc8822b1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point)
4271 {
4272         /* reg 0x808[9:0]: FFT data x */
4273         /* reg 0x808[22]: 0-->1 to get 1 FFT data y */
4274         /* reg 0x8b4[15:0]: FFT data y report */
4275
4276         u32 val = 0, psd_report = 0;
4277
4278         val = btcoexist->btc_read_4byte(btcoexist, 0x808);
4279
4280         val &= 0xffbffc00;
4281         val |= point;
4282
4283         btcoexist->btc_write_4byte(btcoexist, 0x808, val);
4284
4285         val |= 0x00400000;
4286         btcoexist->btc_write_4byte(btcoexist, 0x808, val);
4287
4288
4289         val = btcoexist->btc_read_4byte(btcoexist, 0x8b4);
4290
4291         psd_report = val & 0x0000ffff;
4292
4293         return psd_report;
4294 }
4295
4296
4297 void halbtc8822b1ant_psd_sweep_point(IN struct btc_coexist *btcoexist,
4298              IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points,
4299                                      IN u32 avgnum)
4300 {
4301         u32      i, val, n, k = 0;
4302         u32     points1 = 0, psd_report = 0;
4303         u32     start_p = 0, stop_p = 0, delta_freq_per_point = 156250;
4304         u32    psd_center_freq = 20 * 10 ^ 6, freq, freq1, freq2;
4305         boolean outloop = false;
4306         u8       flag = 0;
4307         u32     tmp, psd_rep1, psd_rep2;
4308         u32     wifi_original_channel = 1;
4309
4310         psd_scan->is_psd_running = true;
4311
4312         do {
4313                 switch (flag) {
4314                 case 0:  /* Get PSD parameters */
4315                 default:
4316
4317                         psd_scan->psd_band_width = 40 * 1000000;
4318                         psd_scan->psd_point = points;
4319                         psd_scan->psd_start_base = points / 2;
4320                         psd_scan->psd_avg_num = avgnum;
4321                         psd_scan->real_cent_freq = cent_freq;
4322                         psd_scan->real_offset = offset;
4323                         psd_scan->real_span = span;
4324
4325
4326                         points1 = psd_scan->psd_point;
4327                         delta_freq_per_point = psd_scan->psd_band_width /
4328                                                psd_scan->psd_point;
4329
4330                         /* PSD point setup */
4331                         val = btcoexist->btc_read_4byte(btcoexist, 0x808);
4332                         val &= 0xffff0fff;
4333
4334                         switch (psd_scan->psd_point) {
4335                         case 128:
4336                                 val |= 0x0;
4337                                 break;
4338                         case 256:
4339                         default:
4340                                 val |= 0x00004000;
4341                                 break;
4342                         case 512:
4343                                 val |= 0x00008000;
4344                                 break;
4345                         case 1024:
4346                                 val |= 0x0000c000;
4347                                 break;
4348                         }
4349
4350                         switch (psd_scan->psd_avg_num) {
4351                         case 1:
4352                                 val |= 0x0;
4353                                 break;
4354                         case 8:
4355                                 val |= 0x00001000;
4356                                 break;
4357                         case 16:
4358                                 val |= 0x00002000;
4359                                 break;
4360                         case 32:
4361                         default:
4362                                 val |= 0x00003000;
4363                                 break;
4364                         }
4365                         btcoexist->btc_write_4byte(btcoexist, 0x808, val);
4366
4367                         flag = 1;
4368                         break;
4369                 case 1:   /* calculate the PSD point index from freq/offset/span */
4370                         psd_center_freq = psd_scan->psd_band_width / 2 +
4371                                           offset * (1000000);
4372
4373                         start_p = psd_scan->psd_start_base + (psd_center_freq -
4374                                 span * (1000000) / 2) / delta_freq_per_point;
4375                         psd_scan->psd_start_point = start_p -
4376                                                     psd_scan->psd_start_base;
4377
4378                         stop_p = psd_scan->psd_start_base + (psd_center_freq +
4379                                 span * (1000000) / 2) / delta_freq_per_point;
4380                         psd_scan->psd_stop_point = stop_p -
4381                                                    psd_scan->psd_start_base - 1;
4382
4383                         flag = 2;
4384                         break;
4385                 case 2:  /* set RF channel/BW/Mode */
4386
4387                         /* set 3-wire off */
4388                         val = btcoexist->btc_read_4byte(btcoexist, 0x88c);
4389                         val |= 0x00300000;
4390                         btcoexist->btc_write_4byte(btcoexist, 0x88c, val);
4391
4392                         /* CCK off */
4393                         val = btcoexist->btc_read_4byte(btcoexist, 0x800);
4394                         val &= 0xfeffffff;
4395                         btcoexist->btc_write_4byte(btcoexist, 0x800, val);
4396
4397                         /* store WiFi original channel */
4398                         wifi_original_channel = btcoexist->btc_get_rf_reg(
4399                                         btcoexist, BTC_RF_A, 0x18, 0x3ff);
4400
4401                         /* Set RF channel */
4402                         if (cent_freq == 2484)
4403                                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
4404                                                           0x18, 0x3ff, 0xe);
4405                         else
4406                                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
4407                                           0x18, 0x3ff, (cent_freq - 2412) / 5 +
4408                                                   1); /* WiFi TRx Mask on */
4409
4410                         /* Set  RF mode = Rx, RF Gain = 0x8a0 */
4411                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0,
4412                                                   0xfffff, 0x308a0);
4413
4414                         /* Set RF Rx filter corner */
4415                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
4416                                                   0xfffff, 0x3e4);
4417
4418                         /* Set TRx mask off */
4419                         /* un-lock TRx Mask setup */
4420                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd,
4421                                                   0x80, 0x1);
4422                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf,
4423                                                   0x1, 0x1);
4424
4425                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
4426                                                   0xfffff, 0x0);
4427
4428                         flag = 3;
4429                         break;
4430                 case 3:
4431                         memset(psd_scan->psd_report, 0,
4432                                psd_scan->psd_point * sizeof(u32));
4433                         start_p = psd_scan->psd_start_point +
4434                                   psd_scan->psd_start_base;
4435                         stop_p = psd_scan->psd_stop_point +
4436                                  psd_scan->psd_start_base + 1;
4437
4438                         i = start_p;
4439
4440                         while (i < stop_p) {
4441                                 if (i >= points1)
4442                                         psd_report =
4443                                                 halbtc8822b1ant_psd_getdata(
4444                                                         btcoexist, i - points1);
4445                                 else
4446                                         psd_report =
4447                                                 halbtc8822b1ant_psd_getdata(
4448                                                         btcoexist, i);
4449
4450                                 if (psd_report == 0)
4451                                         tmp = 0;
4452                                 else
4453                                         /* tmp =  20*log10((double)psd_report); */
4454                                         /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */
4455                                         tmp = 6 * halbtc8822b1ant_psd_log2base(
4456                                                       btcoexist, psd_report);
4457
4458                                 n = i - psd_scan->psd_start_base;
4459                                 psd_scan->psd_report[n] =  tmp;
4460                                 psd_rep1 = psd_scan->psd_report[n] / 100;
4461                                 psd_rep2 = psd_scan->psd_report[n] - psd_rep1 *
4462                                            100;
4463
4464                                 freq = ((cent_freq - 20) * 1000000 + n *
4465                                         delta_freq_per_point);
4466                                 freq1 = freq / 1000000;
4467                                 freq2 = freq / 1000 - freq1 * 1000;
4468
4469                                 i++;
4470
4471                                 k = 0;
4472
4473                                 /* Add Delay between PSD point */
4474                                 while (1) {
4475                                         if (k++ > 20000)
4476                                                 break;
4477                                 }
4478
4479                         }
4480
4481                         flag = 100;
4482                         break;
4483                 case 99:        /* error */
4484
4485                         outloop = true;
4486                         break;
4487                 case 100: /* recovery */
4488
4489                         /* set 3-wire on */
4490                         val = btcoexist->btc_read_4byte(btcoexist, 0x88c);
4491                         val &= 0xffcfffff;
4492                         btcoexist->btc_write_4byte(btcoexist, 0x88c, val);
4493
4494                         /* CCK on */
4495                         val = btcoexist->btc_read_4byte(btcoexist, 0x800);
4496                         val |= 0x01000000;
4497                         btcoexist->btc_write_4byte(btcoexist, 0x800, val);
4498
4499                         /* PSD off */
4500                         val = btcoexist->btc_read_4byte(btcoexist, 0x808);
4501                         val &= 0xffbfffff;
4502                         btcoexist->btc_write_4byte(btcoexist, 0x808, val);
4503
4504                         /* TRx Mask on */
4505                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
4506                                                   0xfffff, 0x780);
4507
4508                         /* lock TRx Mask setup */
4509                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd,
4510                                                   0x80, 0x0);
4511                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf,
4512                                                   0x1, 0x0);
4513
4514                         /* Set RF Rx filter corner */
4515                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
4516                                                   0xfffff, 0x0);
4517
4518                         /* restore WiFi original channel */
4519                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18,
4520                                                   0x3ff, wifi_original_channel);
4521
4522                         outloop = true;
4523                         break;
4524
4525                 }
4526
4527         } while (!outloop);
4528
4529
4530
4531         psd_scan->is_psd_running = false;
4532
4533
4534 }
4535
4536 #if (BTC_COEX_OFFLOAD == 1)
4537 void halbtc8822b1ant_wifi_info_notify(IN struct btc_coexist *btcoexist)
4538 {
4539         u8                      h2c_para[4] = {0};
4540         u8                      opcode_ver = 0;
4541         u8                      ap_num = 0;
4542         s32                     wifi_rssi = 0;
4543         boolean                 wifi_busy = false;
4544
4545         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
4546         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
4547         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
4548
4549         h2c_para[0] = ap_num;                                   /* AP number */
4550         h2c_para[1] = (u8)wifi_busy;            /* Busy */
4551         h2c_para[2] = (u8)wifi_rssi;                    /* RSSI */
4552
4553         btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_INFO_NOTIFY,
4554                                         opcode_ver, &h2c_para[0], 3);
4555 }
4556
4557 void halbtc8822b1ant_setManual(IN struct btc_coexist *btcoexist,
4558                                IN boolean manual)
4559 {
4560         u8                      h2c_para[4] = {0};
4561         u8                      opcode_ver = 0;
4562         u8                      set_type = 0;
4563
4564         if (manual)
4565                 set_type = 1;
4566         else
4567                 set_type = 0;
4568
4569         h2c_para[0] = set_type;                         /* set_type */
4570
4571         btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_SET_CONTROL,
4572                                         opcode_ver,
4573                                         &h2c_para[0], 1);
4574 }
4575
4576 /* ************************************************************
4577  * work around function start with wa_halbtc8822b1ant_
4578  * ************************************************************
4579  * ************************************************************
4580  * extern function start with ex_halbtc8822b1ant_
4581  * ************************************************************ */
4582
4583 void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist)
4584 {}
4585 void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
4586 {}
4587 void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
4588                                        IN boolean wifi_only)
4589 {}
4590 void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
4591 {}
4592 void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4593 {
4594         u8                      h2c_para[4] = {0};
4595         u8                      opcode_ver = 0;
4596         u8                      ips_notify = 0;
4597
4598         if (BTC_IPS_ENTER == type) {
4599                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4600                             "[BTCoex], IPS ENTER notify\n");
4601                 BTC_TRACE(trace_buf);
4602                 ips_notify = 1;
4603         } else if (BTC_IPS_LEAVE == type) {
4604                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4605                             "[BTCoex], IPS LEAVE notify\n");
4606                 BTC_TRACE(trace_buf);
4607         }
4608
4609         h2c_para[0] = ips_notify;               /* IPS notify */
4610         h2c_para[1] = 0xff;                     /* LPS notify */
4611         h2c_para[2] = 0xff;                     /* RF state notify */
4612         h2c_para[3] = 0xff;                     /* pnp notify */
4613
4614         btcoexist->btc_coex_h2c_process(btcoexist,
4615                                         COL_OP_WIFI_POWER_STATE_NOTIFY,
4616                                         opcode_ver, &h2c_para[0], 4);
4617 }
4618 void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4619 {
4620         u8                      h2c_para[4] = {0};
4621         u8                      opcode_ver = 0;
4622         u8                      lps_notify = 0;
4623
4624         if (BTC_LPS_ENABLE == type) {
4625                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4626                             "[BTCoex], LPS ENABLE notify\n");
4627                 BTC_TRACE(trace_buf);
4628                 lps_notify = 1;
4629         } else if (BTC_LPS_DISABLE == type) {
4630                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4631                             "[BTCoex], LPS DISABLE notify\n");
4632                 BTC_TRACE(trace_buf);
4633         }
4634
4635         h2c_para[0] = 0xff;                     /* IPS notify */
4636         h2c_para[1] = lps_notify;               /* LPS notify */
4637         h2c_para[2] = 0xff;                     /* RF state notify */
4638         h2c_para[3] = 0xff;                     /* pnp notify */
4639
4640         btcoexist->btc_coex_h2c_process(btcoexist,
4641                                         COL_OP_WIFI_POWER_STATE_NOTIFY,
4642                                         opcode_ver, &h2c_para[0], 4);
4643 }
4644
4645 void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist,
4646                                     IN u8 type)
4647 {
4648         u8                      h2c_para[4] = {0};
4649         u8                      opcode_ver = 0;
4650         u8                      scan_start = 0;
4651         boolean                 under_4way = false;
4652
4653         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
4654                            &under_4way);
4655         if (BTC_SCAN_START == type) {
4656                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4657                             "[BTCoex], SCAN START notify\n");
4658                 BTC_TRACE(trace_buf);
4659                 scan_start = 1;
4660         } else {
4661                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4662                             "[BTCoex], SCAN FINISH notify\n");
4663                 BTC_TRACE(trace_buf);
4664         }
4665
4666         h2c_para[0] = scan_start;               /* scan notify */
4667         h2c_para[1] = 0xff;                     /* connect notify */
4668         h2c_para[2] = 0xff;                     /* specific packet notify */
4669         if (under_4way)
4670                 h2c_para[3] = 1;                        /* under 4way progress */
4671         else
4672                 h2c_para[3] = 0;
4673
4674         btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY,
4675                                         opcode_ver, &h2c_para[0], 4);
4676 }
4677
4678 void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist,
4679                                        IN u8 type)
4680 {
4681         u8                      h2c_para[4] = {0};
4682         u8                      opcode_ver = 0;
4683         u8                      connect_start = 0;
4684         boolean                 under_4way = false;
4685
4686         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
4687                            &under_4way);
4688         if (BTC_ASSOCIATE_START == type) {
4689                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4690                             "[BTCoex], CONNECT START notify\n");
4691                 BTC_TRACE(trace_buf);
4692                 connect_start = 1;
4693         } else {
4694                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4695                             "[BTCoex], CONNECT FINISH notify\n");
4696                 BTC_TRACE(trace_buf);
4697         }
4698
4699         h2c_para[0] = 0xff;                     /* scan notify */
4700         h2c_para[1] = connect_start;    /* connect notify */
4701         h2c_para[2] = 0xff;                     /* specific packet notify */
4702         if (under_4way)
4703                 h2c_para[3] = 1;                        /* under 4way progress */
4704         else
4705                 h2c_para[3] = 0;
4706
4707         btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY,
4708                                         opcode_ver, &h2c_para[0], 4);
4709 }
4710
4711 void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist,
4712                 IN u8 type)
4713 {
4714         u32                     wifi_bw;
4715         u8                      wifi_central_chnl;
4716         u8                      h2c_para[5] = {0};
4717         u8                      opcode_ver = 0;
4718         u8                      port = 0, connected = 0, freq = 0, bandwidth = 0, iot_peer = 0;
4719         boolean                 wifi_under_5g = false;
4720
4721         if (BTC_MEDIA_CONNECT == type)
4722                 connected = 1;
4723
4724         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
4725         bandwidth = (u8)wifi_bw;
4726         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4727         if (wifi_under_5g)
4728                 freq = 1;
4729         else
4730                 freq = 0;
4731         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
4732                            &wifi_central_chnl);
4733         btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
4734
4735         h2c_para[0] = (connected << 4) |
4736                 port;   /* port need to be implemented in the future (p2p port, ...) */
4737         h2c_para[1] = (freq << 4) | bandwidth;
4738         h2c_para[2] = wifi_central_chnl;
4739         h2c_para[3] = iot_peer;
4740         btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_STATUS_NOTIFY,
4741                                         opcode_ver, &h2c_para[0], 4);
4742 }
4743
4744 void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
4745                 IN u8 type)
4746 {
4747         u8                      h2c_para[4] = {0};
4748         u8                      opcode_ver = 0;
4749         u8                      connect_start = 0;
4750         boolean                 under_4way = false;
4751
4752         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
4753                            &under_4way);
4754
4755         h2c_para[0] = 0xff;                     /* scan notify */
4756         h2c_para[1] = 0xff;                     /* connect notify */
4757         h2c_para[2] = type;                     /* specific packet notify */
4758         if (under_4way)
4759                 h2c_para[3] = 1;                        /* under 4way progress */
4760         else
4761                 h2c_para[3] = 0;
4762
4763         btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY,
4764                                         opcode_ver, &h2c_para[0], 4);
4765 }
4766
4767 void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
4768                                        IN u8 *tmp_buf, IN u8 length)
4769 {}
4770 void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
4771                 IN u8 type)
4772 {
4773         u8                      h2c_para[4] = {0};
4774         u8                      opcode_ver = 0;
4775         u8                      rfstate_notify = 0;
4776
4777         if (BTC_RF_ON == type) {
4778                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4779                             "[BTCoex], RF is turned ON!!\n");
4780                 BTC_TRACE(trace_buf);
4781                 rfstate_notify = 1;
4782         } else if (BTC_RF_OFF == type) {
4783                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4784                             "[BTCoex], RF is turned OFF!!\n");
4785                 BTC_TRACE(trace_buf);
4786         }
4787
4788         h2c_para[0] = 0xff;                     /* IPS notify */
4789         h2c_para[1] = 0xff;                     /* LPS notify */
4790         h2c_para[2] = rfstate_notify;   /* RF state notify */
4791         h2c_para[3] = 0xff;                     /* pnp notify */
4792
4793         btcoexist->btc_coex_h2c_process(btcoexist,
4794                                         COL_OP_WIFI_POWER_STATE_NOTIFY,
4795                                         opcode_ver, &h2c_para[0], 4);
4796 }
4797
4798 void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist)
4799 {}
4800 void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist,
4801                                    IN u8 pnp_state)
4802 {
4803         u8                      h2c_para[4] = {0};
4804         u8                      opcode_ver = 0;
4805         u8                      pnp_notify = 0;
4806
4807         if (BTC_WIFI_PNP_SLEEP == pnp_state) {
4808                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4809                             "[BTCoex], Pnp notify to SLEEP\n");
4810                 BTC_TRACE(trace_buf);
4811                 pnp_notify = 1;
4812         } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
4813                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4814                             "[BTCoex], Pnp notify to WAKE UP\n");
4815                 BTC_TRACE(trace_buf);
4816         }
4817
4818         h2c_para[0] = 0xff;                     /* IPS notify */
4819         h2c_para[1] = 0xff;                     /* LPS notify */
4820         h2c_para[2] = 0xff;                     /* RF state notify */
4821         h2c_para[3] = pnp_notify;               /* pnp notify */
4822
4823         btcoexist->btc_coex_h2c_process(btcoexist,
4824                                         COL_OP_WIFI_POWER_STATE_NOTIFY,
4825                                         opcode_ver, &h2c_para[0], 4);
4826 }
4827
4828 void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
4829 {}
4830 void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist)
4831 {
4832
4833         halbtc8822b1ant_wifi_info_notify(btcoexist);
4834 }
4835
4836 void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist)
4837 {
4838         struct  btc_board_info          *board_info = &btcoexist->board_info;
4839         struct  btc_stack_info          *stack_info = &btcoexist->stack_info;
4840         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
4841         u8                              *cli_buf = btcoexist->cli_buf;
4842         u8                              u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
4843         u16                             u16tmp[4];
4844         u32                             u32tmp[4];
4845         u32                             fa_ofdm, fa_cck, cca_ofdm, cca_cck;
4846         u32                             fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
4847         static u8                       pop_report_in_10s = 0;
4848         u32                     phyver = 0;
4849         boolean                 lte_coex_on = false;
4850
4851         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4852                    "\r\n ============[BT Coexist info]============");
4853         CL_PRINTF(cli_buf);
4854
4855         if (btcoexist->manual_control) {
4856                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4857                         "\r\n ============[Under Manual Control]============");
4858                 CL_PRINTF(cli_buf);
4859                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4860                            "\r\n ==========================================");
4861                 CL_PRINTF(cli_buf);
4862         }
4863         if (btcoexist->stop_coex_dm) {
4864                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4865                            "\r\n ============[Coex is STOPPED]============");
4866                 CL_PRINTF(cli_buf);
4867                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4868                            "\r\n ==========================================");
4869                 CL_PRINTF(cli_buf);
4870         }
4871
4872         if (psd_scan->ant_det_try_count == 0) {
4873                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4874                            "\r\n %-35s = %d/ %d/ %s / %d",
4875                            "Ant PG Num/ Mech/ Pos/ RFE",
4876                            board_info->pg_ant_num, board_info->btdm_ant_num,
4877                            (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4878                             ? "Main" : "Aux"),
4879                            rfe_type->rfe_module_type);
4880                 CL_PRINTF(cli_buf);
4881         } else {
4882                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4883                            "\r\n %-35s = %d/ %d/ %s/ %d  (%d/%d/%d)",
4884                            "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4885                            board_info->pg_ant_num,
4886                            board_info->btdm_ant_num_by_ant_det,
4887                            (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4888                             ? "Main" : "Aux"),
4889                            rfe_type->rfe_module_type,
4890                            psd_scan->ant_det_try_count,
4891                            psd_scan->ant_det_fail_count,
4892                            psd_scan->ant_det_result);
4893                 CL_PRINTF(cli_buf);
4894
4895                 if (board_info->btdm_ant_det_finish) {
4896                         if (psd_scan->ant_det_result != 12)
4897                                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
4898                                         "Ant Det PSD Value",
4899                                         psd_scan->ant_det_peak_val);
4900                         else
4901                                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4902                                         "\r\n %-35s = %d",
4903                                         "Ant Det PSD Value",
4904                                 psd_scan->ant_det_psd_scan_peak_val / 100);
4905
4906                         CL_PRINTF(cli_buf);
4907                 }
4908         }
4909
4910         btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
4911         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4912         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4913                    "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
4914                    "CoexVer/ FwVer/ PatchVer",
4915                    glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant, fw_ver,
4916                    bt_patch_ver, bt_patch_ver);
4917         CL_PRINTF(cli_buf);
4918
4919         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
4920                    "Wifi channel informed to BT",
4921                    coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4922                    coex_dm->wifi_chnl_info[2]);
4923         CL_PRINTF(cli_buf);
4924         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
4925                    "WifibHiPri/ Ccklock/ CckEverLock",
4926                    (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
4927                    (coex_sta->cck_lock ? "Yes" : "No"),
4928                    (coex_sta->cck_ever_lock ? "Yes" : "No"));
4929         CL_PRINTF(cli_buf);
4930
4931         /* wifi status */
4932         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4933                    "============[Wifi Status]============");
4934         CL_PRINTF(cli_buf);
4935         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
4936
4937         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4938                    "============[BT Status]============");
4939         CL_PRINTF(cli_buf);
4940
4941         pop_report_in_10s++;
4942         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ",
4943                    "BT [status/ rssi/ retryCnt/ popCnt]",
4944                    ((coex_sta->bt_disabled) ? ("disabled") :    ((
4945                    coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
4946                            : ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4947                                coex_dm->bt_status) ? "non-connected idle" :
4948                 ((BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
4949                                        ? "connected-idle" : "busy")))),
4950                    coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
4951                    coex_sta->pop_event_cnt);
4952         CL_PRINTF(cli_buf);
4953
4954         if (pop_report_in_10s >= 5) {
4955                 coex_sta->pop_event_cnt = 0;
4956                 pop_report_in_10s = 0;
4957         }
4958
4959         if (coex_sta->num_of_profile != 0)
4960                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4961                         "\r\n %-35s = %s%s%s%s%s",
4962                         "Profiles",
4963                         ((bt_link_info->a2dp_exist) ? "A2DP," : ""),
4964                         ((bt_link_info->sco_exist) ?  "SCO," : ""),
4965                         ((bt_link_info->hid_exist) ?
4966                         ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : "HID(2/18),") : ""),
4967                         ((bt_link_info->pan_exist) ?  "PAN," : ""),
4968                         ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
4969         else
4970                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4971                         "\r\n %-35s = None", "Profiles");
4972
4973         CL_PRINTF(cli_buf);
4974
4975         if (bt_link_info->a2dp_exist) {
4976                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s",
4977                         "A2DP Rate/Bitpool/Auto_Slot",
4978                         ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
4979                         coex_sta->a2dp_bit_pool,
4980                         ((coex_sta->is_autoslot) ? "On" : "Off"));
4981                 CL_PRINTF(cli_buf);
4982         }
4983
4984         if (bt_link_info->hid_exist) {
4985                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4986                            "HID PairNum/Forbid_Slot",
4987                          coex_sta->hid_pair_cnt,
4988                          coex_sta->forbidden_slot
4989                          );
4990                 CL_PRINTF(cli_buf);
4991         }
4992
4993         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x/ 0x%x",
4994                 "Role/IgnWlanAct/Feature/BLEScan",
4995                 ((bt_link_info->slave_role) ? "Slave" : "Master"),
4996                 ((coex_dm->cur_ignore_wlan_act) ? "Yes":"No"),
4997                 coex_sta->bt_coex_supported_feature,
4998                 coex_sta->bt_ble_scan_type);
4999         CL_PRINTF(cli_buf);
5000
5001         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
5002                                    "ReInit/ReLink/IgnWlact/Page/NameReq",
5003                          coex_sta->cnt_ReInit,
5004                    coex_sta->cnt_setupLink,
5005                          coex_sta->cnt_IgnWlanAct,
5006                                  coex_sta->cnt_Page,
5007                          coex_sta->cnt_RemoteNameReq
5008                          );
5009                 CL_PRINTF(cli_buf);
5010
5011         halbtc8822b1ant_read_score_board(btcoexist,     &u16tmp[0]);
5012
5013         if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
5014             (coex_sta->bt_reg_vendor_ac == 0xffff))
5015                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x",
5016                            "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]);
5017         else
5018                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5019                            "\r\n %-35s = 0x%x/ 0x%x/ %04x",
5020                            "0xae[4]/0xac[1:0]/Scoreboard",
5021                          ((coex_sta->bt_reg_vendor_ae & BIT(4))>>4),
5022                            coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
5023         CL_PRINTF(cli_buf);
5024
5025         for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) {
5026                 if (coex_sta->bt_info_c2h_cnt[i]) {
5027                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5028                                 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
5029                                    glbt_info_src_8822b_1ant[i],
5030                                    coex_sta->bt_info_c2h[i][0],
5031                                    coex_sta->bt_info_c2h[i][1],
5032                                    coex_sta->bt_info_c2h[i][2],
5033                                    coex_sta->bt_info_c2h[i][3],
5034                                    coex_sta->bt_info_c2h[i][4],
5035                                    coex_sta->bt_info_c2h[i][5],
5036                                    coex_sta->bt_info_c2h[i][6],
5037                                    coex_sta->bt_info_c2h_cnt[i]);
5038                         CL_PRINTF(cli_buf);
5039                 }
5040         }
5041
5042
5043         if (btcoexist->manual_control)
5044                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5045                         "============[mechanisms] (before Manual)============");
5046         else
5047                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5048                            "============[mechanisms]============");
5049         CL_PRINTF(cli_buf);
5050
5051         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
5052                    "SM[LowPenaltyRA]",
5053                    coex_dm->cur_low_penalty_ra);
5054         CL_PRINTF(cli_buf);
5055
5056         ps_tdma_case = coex_dm->cur_ps_tdma;
5057         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5058                    "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)",
5059                    "PS TDMA",
5060                    coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
5061                    coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
5062                    coex_dm->ps_tdma_para[4], ps_tdma_case,
5063                    (coex_dm->cur_ps_tdma_on ? "On" : "Off"),
5064                    (coex_dm->auto_tdma_adjust ? "Adj" : "Fix"));
5065
5066         CL_PRINTF(cli_buf);
5067
5068         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
5069                    "WL/BT Coex Table Type",
5070                    coex_sta->coex_table_type);
5071         CL_PRINTF(cli_buf);
5072
5073         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
5074         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
5075         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
5076         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5077                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
5078                    "0x6c0/0x6c4/0x6c8(coexTable)",
5079                    u32tmp[0], u32tmp[1], u32tmp[2]);
5080         CL_PRINTF(cli_buf);
5081
5082         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
5083         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
5084         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5085                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
5086                    "0x778/0x6cc/IgnWlanAct",
5087                    u8tmp[0], u32tmp[0],  coex_dm->cur_ignore_wlan_act);
5088         CL_PRINTF(cli_buf);
5089
5090         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5091                         0xa0);
5092         u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5093                         0xa4);
5094
5095         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
5096                    "LTE Coex Table W_L/B_L",
5097                    u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
5098         CL_PRINTF(cli_buf);
5099
5100         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5101                         0xa8);
5102         u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5103                         0xac);
5104         u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5105                         0xb0);
5106         u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5107                         0xb4);
5108
5109         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5110                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
5111                    "LTE Break Table W_L/B_L/L_W/L_B",
5112                    u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
5113                    u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
5114         CL_PRINTF(cli_buf);
5115
5116         /* Hw setting            */
5117         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5118                    "============[Hw setting]============");
5119         CL_PRINTF(cli_buf);
5120 /*
5121         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
5122         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
5123         u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
5124         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
5125         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
5126                    "0x430/0x434/0x42a/0x456",
5127                    u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
5128         CL_PRINTF(cli_buf);
5129 */
5130
5131         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
5132         u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
5133         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
5134
5135         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s",
5136                    "LTE CoexOn/Path Ctrl Owner",
5137                    (int)((u32tmp[0]&BIT(7)) >> 7),
5138                    ((u8tmp[0]&BIT(2)) ? "WL" : "BT"));
5139         CL_PRINTF(cli_buf);
5140
5141         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5142                    "LTE 3Wire/OPMode/UART/UARTMode",
5143                    (int)((u32tmp[0]&BIT(6)) >> 6),
5144                    (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
5145                    (int)((u32tmp[0]&BIT(3)) >> 3),
5146                    (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
5147         CL_PRINTF(cli_buf);
5148
5149         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s",
5150                    "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg",
5151                    (int)((u32tmp[0]&BIT(12)) >> 12),
5152                    (int)((u32tmp[0]&BIT(14)) >> 14),
5153                    ((u8tmp[0]&BIT(3)) ? "On" : "Off"));
5154         CL_PRINTF(cli_buf);
5155
5156         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
5157
5158         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5159                    "GNT_WL/GNT_BT/LTE_Busy/UART_Busy",
5160                    (int)((u32tmp[0]&BIT(2)) >> 2),
5161                    (int)((u32tmp[0]&BIT(3)) >> 3),
5162                    (int)((u32tmp[0]&BIT(1)) >> 1), (int)(u32tmp[0]&BIT(0)));
5163         CL_PRINTF(cli_buf);
5164
5165
5166         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
5167         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
5168
5169         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
5170                    "0x4c6[4]/0x40[5] (WL/BT PTA)",
5171                    (int)((u8tmp[0] & BIT(4)) >> 4),
5172                    (int)((u8tmp[1] & BIT(5)) >> 5));
5173         CL_PRINTF(cli_buf);
5174
5175         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
5176         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
5177         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
5178         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s",
5179                    "0x550(bcn ctrl)/0x522/4-RxAGC",
5180                    u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off");
5181         CL_PRINTF(cli_buf);
5182
5183         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
5184         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
5185         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
5186         u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
5187
5188         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
5189         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
5190
5191         fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) + ((u32tmp[1] & 0xffff0000)
5192                         >> 16) + (u32tmp[1] & 0xffff) + (u32tmp[2] & 0xffff) +
5193                    ((u32tmp[3] & 0xffff0000) >> 16) + (u32tmp[3] &
5194                                    0xffff);
5195         fa_cck = (u8tmp[0] << 8) + u8tmp[1];
5196
5197         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
5198
5199         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5200                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
5201                    "0xc50/OFDM-CCA/OFDM-FA/CCK-FA",
5202                    u32tmp[1] & 0xff, u32tmp[0] & 0xffff, fa_ofdm, fa_cck);
5203         CL_PRINTF(cli_buf);
5204
5205
5206         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5207                    "CRC_OK CCK/11g/11n/11n-Agg",
5208                    coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
5209                    coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_agg);
5210         CL_PRINTF(cli_buf);
5211
5212         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5213                    "CRC_Err CCK/11g/11n/11n-Agg",
5214                    coex_sta->crc_err_cck, coex_sta->crc_err_11g,
5215                    coex_sta->crc_err_11n, coex_sta->crc_err_11n_agg);
5216         CL_PRINTF(cli_buf);
5217
5218         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
5219                    "0x770(high-pri rx/tx)",
5220                    coex_sta->high_priority_rx, coex_sta->high_priority_tx);
5221         CL_PRINTF(cli_buf);
5222         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
5223                    "0x774(low-pri rx/tx)",
5224                    coex_sta->low_priority_rx, coex_sta->low_priority_tx);
5225         CL_PRINTF(cli_buf);
5226 #if (BT_AUTO_REPORT_ONLY_8822B_1ANT == 1)
5227         /* halbtc8822b1ant_monitor_bt_ctr(btcoexist); */
5228 #endif
5229         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
5230 }
5231 void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist,
5232                 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
5233 {}
5234 void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist)
5235 {}
5236 void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist,
5237                                     IN u8 op_code, IN u8 op_len, IN u8 *pdata)
5238 {
5239         switch (op_code) {
5240         case BTC_DBG_SET_COEX_MANUAL_CTRL: {
5241                 boolean         manual = (boolean) *pdata;
5242
5243                 halbtc8822b1ant_setManual(btcoexist, manual);
5244         }
5245         break;
5246         default:
5247                 break;
5248         }
5249 }
5250
5251 #else
5252 void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist)
5253 {
5254         struct  btc_board_info  *board_info = &btcoexist->board_info;
5255         u8 u8tmp = 0x0;
5256         u16 u16tmp = 0x0;
5257
5258         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5259                 "xxxxxxxxxxxxxxxx Execute 8822b 1-Ant PowerOn Setting!! xxxxxxxxxxxxxxxx\n");
5260         BTC_TRACE(trace_buf);
5261
5262         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5263                     "Ant Det Finish = %s, Ant Det Number  = %d\n",
5264                     board_info->btdm_ant_det_finish ? "Yes" : "No",
5265                     board_info->btdm_ant_num_by_ant_det);
5266         BTC_TRACE(trace_buf);
5267
5268         btcoexist->stop_coex_dm = true;
5269
5270         /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
5271         u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
5272         btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
5273
5274         /* set Path control owner to WiFi */
5275         halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
5276                         BT_8822B_1ANT_PCO_WLSIDE);
5277
5278         /* set GNT_BT to high */
5279         halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
5280                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
5281                                            BT_8822B_1ANT_GNT_CTRL_BY_SW,
5282                                            BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
5283         /* Set GNT_WL to low */
5284         halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
5285                                            BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
5286                                            BT_8822B_1ANT_GNT_CTRL_BY_SW,
5287                                            BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
5288
5289         /* set WLAN_ACT = 0 */
5290         /* btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); */
5291
5292         /* SD1 Chunchu red x issue */
5293         btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0);
5294
5295         halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true);
5296
5297         /* */
5298         /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
5299         /* Local setting bit define */
5300         /*      BIT0: "0" for no antenna inverse; "1" for antenna inverse  */
5301         /*      BIT1: "0" for internal switch; "1" for external switch */
5302         /*      BIT2: "0" for one antenna; "1" for two antenna */
5303         /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
5304
5305         u8tmp = 0;
5306         board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
5307
5308         if (btcoexist->chip_interface == BTC_INTF_USB)
5309                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
5310         else if (btcoexist->chip_interface == BTC_INTF_SDIO)
5311                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
5312
5313         BTC_TRACE(trace_buf);
5314
5315
5316 }
5317
5318 void ex_halbtc8822b1ant_power_on_setting_without_bt(IN struct btc_coexist
5319                 *btcoexist)
5320 {
5321         struct  btc_board_info  *board_info = &btcoexist->board_info;
5322         u8 u8tmp = 0x0;
5323         u16 u16tmp = 0x0;
5324
5325         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5326                     " 8822b 1-Ant PowerOn Setting without bt\n");
5327         BTC_TRACE(trace_buf);
5328
5329         btcoexist->stop_coex_dm = true;
5330
5331         /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
5332         u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
5333         btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
5334
5335
5336         /* SD1 Chunchu red x issue */
5337         btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0);
5338
5339         u8tmp = 0;
5340         board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
5341
5342         if (btcoexist->chip_interface == BTC_INTF_USB)
5343                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
5344         else if (btcoexist->chip_interface == BTC_INTF_SDIO)
5345                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
5346
5347
5348
5349 }
5350
5351
5352 void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
5353 {
5354 }
5355
5356 void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
5357                                        IN boolean wifi_only)
5358 {
5359         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5360                     "[BTCoex], ********** (ini hw config) **********\n");
5361
5362         halbtc8822b1ant_init_hw_config(btcoexist, true, wifi_only);
5363         btcoexist->stop_coex_dm = false;
5364 }
5365
5366 void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist
5367                 *btcoexist,
5368                 IN boolean wifi_only)
5369 {
5370         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5371                     "[BTCoex], ********** (ini hw config) **********\n");
5372
5373         halbtc8822b1ant_init_hw_config_without_bt(btcoexist, true, wifi_only);
5374         btcoexist->stop_coex_dm = true;
5375 }
5376
5377 void ex_halbtc8822b1ant_antenna_switch_without_bt(IN struct btc_coexist
5378                 *btcoexist)
5379 {
5380
5381         boolean wifi_under_5g = false;
5382
5383
5384         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5385
5386         if (wifi_under_5g)
5387
5388                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
5389                                                    0x3, 1);
5390
5391         else
5392                 btcoexist->btc_write_1byte_bitmask(btcoexist,
5393                                                    0xcbd, 0x3, 2);
5394
5395
5396 }
5397
5398 void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
5399 {
5400         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5401                     "[BTCoex], Coex Mechanism Init!!\n");
5402         BTC_TRACE(trace_buf);
5403
5404         btcoexist->stop_coex_dm = false;
5405
5406         halbtc8822b1ant_init_coex_dm(btcoexist);
5407
5408         halbtc8822b1ant_query_bt_info(btcoexist);
5409 }
5410
5411 void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist)
5412 {
5413
5414         struct  btc_board_info          *board_info = &btcoexist->board_info;
5415         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
5416         u8                              *cli_buf = btcoexist->cli_buf;
5417         u8                              u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
5418         u16                             u16tmp[4];
5419         u32                             fa_ofdm, fa_cck, cca_ofdm, cca_cck;
5420         u32                             u32tmp[4];
5421         u32                             fa_of_dm;
5422         u32                             fw_ver = 0, bt_patch_ver = 0;
5423         static u8                       pop_report_in_10s = 0;
5424         u32                       phyver = 0;
5425          /*u32 pnp_wake_cnt=0;*/
5426
5427         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5428                     "[BTCoex], ********** (display coexinfo) **********\n");
5429         BTC_TRACE(trace_buf);
5430         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5431                 "[BTCoex], ********** displaycoexinfostart, 0xcb4/0xcbd = 0x%x/0x%x\n",
5432                     btcoexist->btc_read_1byte(btcoexist, 0xcb4),
5433                     btcoexist->btc_read_1byte(btcoexist, 0xcbd));
5434         BTC_TRACE(trace_buf);
5435
5436         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5437                    "\r\n ============[BT Coexist info]============");
5438         CL_PRINTF(cli_buf);
5439
5440         if (btcoexist->manual_control) {
5441                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5442                         "\r\n ============[Under Manual Control]============");
5443                 CL_PRINTF(cli_buf);
5444                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5445                            "\r\n ==========================================");
5446                 CL_PRINTF(cli_buf);
5447         }
5448
5449         if (btcoexist->stop_coex_dm) {
5450                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5451                            "\r\n ============[Coex is STOPPED]============");
5452                 CL_PRINTF(cli_buf);
5453                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5454                            "\r\n ==========================================");
5455                 CL_PRINTF(cli_buf);
5456         }
5457
5458         if (psd_scan->ant_det_try_count == 0) {
5459                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5460                            "\r\n %-35s = %d/ %d/ %d/ %d",
5461                            "Ant PG Num/ Mech/ Pos/ RFE",
5462                            board_info->pg_ant_num, board_info->btdm_ant_num,
5463                            board_info->btdm_ant_pos,
5464                            rfe_type->rfe_module_type);
5465                 CL_PRINTF(cli_buf);
5466         } else {
5467                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5468                            "\r\n %-35s = %d/ %d/ %d/ %d  (%d/%d/%d)",
5469                            "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
5470                            board_info->pg_ant_num,
5471                            board_info->btdm_ant_num_by_ant_det,
5472                            board_info->btdm_ant_pos,
5473                            rfe_type->rfe_module_type,
5474                            psd_scan->ant_det_try_count,
5475                            psd_scan->ant_det_fail_count,
5476                            psd_scan->ant_det_result);
5477                 CL_PRINTF(cli_buf);
5478
5479                 if (board_info->btdm_ant_det_finish) {
5480                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
5481                                    "Ant Det PSD Value",
5482                                    psd_scan->ant_det_peak_val);
5483                         CL_PRINTF(cli_buf);
5484                 }
5485         }
5486         /*btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);*/
5487         bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
5488         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
5489         phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
5490         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5491                    "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
5492                    "CoexVer WL/  BT_Desired/ BT_Report",
5493                    glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant,
5494                    glcoex_ver_btdesired_8822b_1ant,
5495                    ((coex_sta->bt_coex_supported_version & 0xff00) >>
5496                     8),
5497                    (((coex_sta->bt_coex_supported_version & 0xff00) >>
5498                      8) >=
5499                     glcoex_ver_btdesired_8822b_1ant ? "Match" :
5500                     "Mis-Match"));
5501         CL_PRINTF(cli_buf);
5502
5503         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5504                    "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
5505                    "W_FW/ B_FW/ Phy/ Kt",
5506                    fw_ver, bt_patch_ver, phyver,
5507                    coex_sta->cut_version + 65);
5508         CL_PRINTF(cli_buf);
5509
5510
5511
5512
5513         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
5514                    "Wifi channel informed to BT",
5515                    coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
5516                    coex_dm->wifi_chnl_info[2]);
5517         CL_PRINTF(cli_buf);
5518         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
5519                    "WifibHiPri/ Ccklock/ CckEverLock",
5520                    (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
5521                    (coex_sta->cck_lock ? "Yes" : "No"),
5522                    (coex_sta->cck_ever_lock ? "Yes" : "No"));
5523         CL_PRINTF(cli_buf);
5524
5525         /* wifi status */
5526         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5527                    "============[Wifi Status]============");
5528         CL_PRINTF(cli_buf);
5529         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
5530
5531         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5532                    "============[BT Status]============");
5533         CL_PRINTF(cli_buf);
5534
5535         pop_report_in_10s++;
5536         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ",
5537                    "BT [status/ rssi/ retryCnt/ popCnt]",
5538                    ((coex_sta->bt_disabled) ? ("disabled") :    ((
5539                    coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
5540                            : ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
5541                                coex_dm->bt_status) ? "non-connected idle" :
5542                 ((BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
5543                                        ? "connected-idle" : "busy")))),
5544                    coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
5545                    coex_sta->pop_event_cnt);
5546         CL_PRINTF(cli_buf);
5547         /*bt rssi */
5548         /*bt pop_even_cnt : bt retry*/
5549
5550         if (pop_report_in_10s >= 5) {
5551                 coex_sta->pop_event_cnt = 0;
5552                 pop_report_in_10s = 0;
5553         }
5554
5555         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5556                    "\r\n %-35s = %d / %d / %d / %d / %d",
5557                    "SCO/HID/PAN/A2DP/Hi-Pri",
5558                    bt_link_info->sco_exist, bt_link_info->hid_exist,
5559                    bt_link_info->pan_exist, bt_link_info->a2dp_exist,
5560                    bt_link_info->bt_hi_pri_link_exist);
5561         CL_PRINTF(cli_buf);
5562
5563         {
5564                 bt_info_ext = coex_sta->bt_info_ext;
5565
5566                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5567                            "\r\n %-35s = %s / %s / %d/ %x/ %02x",
5568                            "Role/A2DP Rate/Bitpool/Feature/Ver",
5569                            ((bt_link_info->slave_role) ? "Slave" : "Master"),
5570                            (bt_info_ext & BIT(0)) ? "BR" : "EDR",
5571                            coex_sta->a2dp_bit_pool,
5572                            coex_sta->bt_coex_supported_feature,
5573                         ((coex_sta->bt_coex_supported_version & 0xff00) >> 8));
5574                 CL_PRINTF(cli_buf);
5575         }
5576
5577         /*bt info*/
5578         for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) {
5579                 if (coex_sta->bt_info_c2h_cnt[i]) {
5580                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5581                                 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
5582                                    glbt_info_src_8822b_1ant[i],
5583                                    coex_sta->bt_info_c2h[i][0],
5584                                    coex_sta->bt_info_c2h[i][1],
5585                                    coex_sta->bt_info_c2h[i][2],
5586                                    coex_sta->bt_info_c2h[i][3],
5587                                    coex_sta->bt_info_c2h[i][4],
5588                                    coex_sta->bt_info_c2h[i][5],
5589                                    coex_sta->bt_info_c2h[i][6],
5590                                    coex_sta->bt_info_c2h_cnt[i]);
5591                         CL_PRINTF(cli_buf);
5592                 }
5593         }
5594
5595
5596         if (btcoexist->manual_control)
5597                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5598                         "============[mechanisms] (before Manual)============");
5599         else
5600                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5601                            "============[mechanisms]============");
5602         CL_PRINTF(cli_buf);
5603
5604         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
5605                    "SM[LowPenaltyRA]",
5606                    coex_dm->cur_low_penalty_ra);
5607         CL_PRINTF(cli_buf);
5608
5609         /*(ps)tdma*/
5610         ps_tdma_case = coex_dm->cur_ps_tdma;
5611         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5612                    "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)",
5613                    "PS TDMA",
5614                    coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
5615                    coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
5616                    coex_dm->ps_tdma_para[4], ps_tdma_case,
5617                    (coex_dm->cur_ps_tdma_on ? "On" : "Off"),
5618                    (coex_dm->auto_tdma_adjust ? "Adj" : "Fix"));
5619
5620         CL_PRINTF(cli_buf);
5621
5622         /*coex table type*/
5623         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
5624                    "WL/BT Coex Table Type",
5625                    coex_sta->coex_table_type);
5626         CL_PRINTF(cli_buf);
5627
5628         /*coex table :0x6c0 0x6c4 , break table: 0x6c8*/
5629         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
5630         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
5631         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
5632         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5633                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
5634                    "0x6c0/0x6c4/0x6c8(coexTable)",
5635                    u32tmp[0], u32tmp[1], u32tmp[2]);
5636         CL_PRINTF(cli_buf);
5637
5638         /*PTA : 0x778=1/3/d , WL BA,RTS,CTS :0x6cc  H/L pri */
5639         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
5640         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
5641         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5642                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
5643                    "0x778/0x6cc/IgnWlanAct",
5644                    u8tmp[0], u32tmp[0],  coex_dm->cur_ignore_wlan_act);
5645         CL_PRINTF(cli_buf);
5646
5647
5648         /*LTE : WL/LTE coex table : 0xa0 */
5649
5650         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5651                         0xa0);
5652
5653         /*LTE : BT/LTE coex table : 0xa4 */
5654         u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5655                         0xa4);
5656
5657         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
5658                    "LTE Coex Table W_L/B_L",
5659                    u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
5660         CL_PRINTF(cli_buf);
5661
5662         /*LTE : WL/LTE break table : 0xa8 */
5663         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5664                         0xa8);
5665         /*LTE : WL/LTE break table : 0xac */
5666         u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5667                         0xac);
5668         /*LTE : LTE/WL break table : 0xb0 */
5669         u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5670                         0xb0);
5671         /*LTE : LTE/BT break table : 0xb4 */
5672         u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
5673                         0xb4);
5674
5675         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5676                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
5677                    "LTE Break Table W_L/B_L/L_W/L_B",
5678                    u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
5679                    u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
5680         CL_PRINTF(cli_buf);
5681
5682         /* Hw setting            */
5683         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
5684                    "============[Hw setting]============");
5685         CL_PRINTF(cli_buf);
5686
5687
5688         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
5689         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
5690         u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
5691         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
5692         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
5693                    "0x430/0x434/0x42a/0x456",
5694                    u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
5695         CL_PRINTF(cli_buf);
5696
5697         /*ANT setting*/
5698         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb4);
5699         u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xcbd);
5700         u8tmp[3] = btcoexist->btc_read_1byte(btcoexist, 0x1991);
5701
5702         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
5703                    "0xcb4/0xcbd/0x1991",
5704                    u8tmp[1], u8tmp[2], u8tmp[3]);
5705         CL_PRINTF(cli_buf);
5706
5707         /*LTE on/off , Path ctrl owner*/
5708         /*sy add*/
5709         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
5710         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
5711         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
5712         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
5713                    "0x73/ 0x4c/ 0x64[0]", u8tmp[0],
5714                    (u32tmp[0] & (BIT(24) | BIT(23))) >> 23,
5715                    u8tmp[1] & 0x1);
5716         CL_PRINTF(cli_buf);
5717
5718
5719         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
5720         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s",
5721                    "LTE CoexOn/Path Ctrl Owner",
5722                    (int)((u32tmp[0]&BIT(7)) >> 7),
5723                    ((u8tmp[0]&BIT(2)) ? "WL" : "BT"));
5724         CL_PRINTF(cli_buf);
5725
5726         /*LTE mode*/
5727         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5728                    "LTE 3Wire/OPMode/UART/UARTMode",
5729                    (int)((u32tmp[0]&BIT(6)) >> 6),
5730                    (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
5731                    (int)((u32tmp[0]&BIT(3)) >> 3),
5732                    (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
5733         CL_PRINTF(cli_buf);
5734
5735         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s",
5736                    "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg",
5737                    (int)((u32tmp[0]&BIT(12)) >> 12),
5738                    (int)((u32tmp[0]&BIT(14)) >> 14),
5739                    ((u8tmp[0]&BIT(3)) ? "On" : "Off"));
5740         CL_PRINTF(cli_buf);
5741
5742         u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
5743
5744         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5745                    "GNT_WL/GNT_BT/LTE_Busy/UART_Busy",
5746                    (int)((u32tmp[0]&BIT(2)) >> 2),
5747                    (int)((u32tmp[0]&BIT(3)) >> 3),
5748                    (int)((u32tmp[0]&BIT(1)) >> 1), (int)(u32tmp[0]&BIT(0)));
5749         CL_PRINTF(cli_buf);
5750
5751
5752         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
5753         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
5754
5755         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
5756                    "0x4c6[4]/0x40[5] (WL/BT PTA)",
5757                    (int)((u8tmp[0] & BIT(4)) >> 4),
5758                    (int)((u8tmp[1] & BIT(5)) >> 5));
5759         CL_PRINTF(cli_buf);
5760
5761         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
5762         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
5763         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
5764         u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
5765         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5766                    "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
5767                    "0x550/0x522/4-RxAGC/0xc50",
5768                 u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
5769         CL_PRINTF(cli_buf);
5770
5771         fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
5772                         PHYDM_INFO_FA_OFDM);
5773         fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
5774                         PHYDM_INFO_FA_CCK);
5775         cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
5776                         PHYDM_INFO_CCA_OFDM);
5777         cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
5778                         PHYDM_INFO_CCA_CCK);
5779
5780         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
5781                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
5782                    "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
5783                    cca_cck, fa_cck, cca_ofdm, fa_ofdm);
5784         CL_PRINTF(cli_buf);
5785
5786
5787 #if 1
5788         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5789                    "CRC_OK CCK/11g/11n/11ac",
5790                    coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
5791                    coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
5792         CL_PRINTF(cli_buf);
5793
5794         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
5795                    "CRC_Err CCK/11g/11n/11ac",
5796                    coex_sta->crc_err_cck, coex_sta->crc_err_11g,
5797                    coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
5798         CL_PRINTF(cli_buf);
5799 #endif
5800
5801         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
5802                    "Wifi-HiPri/ Ccklock/ CckEverLock",
5803                    (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
5804                    (coex_sta->cck_lock ? "Yes" : "No"),
5805                    (coex_sta->cck_ever_lock ? "Yes" : "No"));
5806         CL_PRINTF(cli_buf);
5807
5808         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
5809                    "0x770(high-pri rx/tx)",
5810                    coex_sta->high_priority_rx, coex_sta->high_priority_tx);
5811         CL_PRINTF(cli_buf);
5812         /*0x774:bt low pri trx*/
5813         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
5814                    "0x774(low-pri rx/tx)",
5815                    coex_sta->low_priority_rx, coex_sta->low_priority_tx);
5816         CL_PRINTF(cli_buf);
5817
5818         halbtc8822b1ant_read_score_board(btcoexist,     &u16tmp[0]);
5819
5820         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x",
5821                    "ScoreBoard[14:0] (from BT)", u16tmp[0]);
5822
5823         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
5824         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5825                 "[BTCoex], ********** displaycoexinfo end, 0xcb4/0xcbd = 0x%x/0x%x\n",
5826                     btcoexist->btc_read_1byte(btcoexist, 0xcb4),
5827                     btcoexist->btc_read_1byte(btcoexist, 0xcbd));
5828         BTC_TRACE(trace_buf);
5829         /*
5830         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5831                         "[BTCoex], ********** pnp_wake_cnt = %d\n", pnp_wake_cnt);
5832         BTC_TRACE(trace_buf);
5833         */
5834 }
5835
5836
5837 void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
5838 {
5839
5840         if (btcoexist->manual_control ||        btcoexist->stop_coex_dm)
5841                 return;
5842
5843
5844         if (BTC_IPS_ENTER == type) {
5845
5846                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5847                             "[BTCoex], IPS ENTER notify\n");
5848                 BTC_TRACE(trace_buf);
5849                 coex_sta->under_ips = true;
5850
5851                 /* Write WL "Active" in Score-board for LPS off */
5852                 halbtc8822b1ant_post_state_to_bt(btcoexist,
5853                                 BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
5854
5855                 halbtc8822b1ant_post_state_to_bt(btcoexist,
5856                                 BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
5857
5858                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
5859
5860                 halbtc8822b1ant_set_ant_path(btcoexist,
5861                                              BTC_ANT_PATH_AUTO,
5862                                              FORCE_EXEC,
5863                                              BT_8822B_1ANT_PHASE_WLAN_OFF);
5864
5865                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
5866         } else if (BTC_IPS_LEAVE == type) {
5867
5868                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5869                             "[BTCoex], IPS LEAVE notify\n");
5870                 BTC_TRACE(trace_buf);
5871                 halbtc8822b1ant_post_state_to_bt(btcoexist,
5872                                 BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
5873
5874                 halbtc8822b1ant_post_state_to_bt(btcoexist,
5875                                 BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
5876
5877                 /*leave IPS : run ini hw config (exclude wifi only)*/
5878                 halbtc8822b1ant_init_hw_config(btcoexist, false, false);
5879                 /*sw all off*/
5880                 halbtc8822b1ant_init_coex_dm(btcoexist);
5881                 /*leave IPS : Query bt info*/
5882                 halbtc8822b1ant_query_bt_info(btcoexist);
5883
5884                 coex_sta->under_ips = false;
5885         }
5886 }
5887
5888 void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
5889 {
5890         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
5891                 return;
5892
5893         if (BTC_LPS_ENABLE == type) {
5894                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5895                             "[BTCoex], LPS ENABLE notify\n");
5896                 BTC_TRACE(trace_buf);
5897                 coex_sta->under_lps = true;
5898
5899                 if (coex_sta->force_lps_on == true) { /* LPS No-32K */
5900                         /* Write WL "Active" in Score-board for PS-TDMA */
5901                         halbtc8822b1ant_post_state_to_bt(btcoexist,
5902                                          BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
5903
5904                 } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */
5905                         /* Write WL "Non-Active" in Score-board for Native-PS */
5906                         halbtc8822b1ant_post_state_to_bt(btcoexist,
5907                                  BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
5908
5909                 }
5910         } else if (BTC_LPS_DISABLE == type) {
5911                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5912                             "[BTCoex], LPS DISABLE notify\n");
5913                 BTC_TRACE(trace_buf);
5914                 coex_sta->under_lps = false;
5915
5916                 /* Write WL "Active" in Score-board for LPS off */
5917                 halbtc8822b1ant_post_state_to_bt(btcoexist,
5918                                          BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
5919
5920         }
5921 }
5922
5923
5924 void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist,
5925                                     IN u8 type)
5926 {
5927         boolean wifi_connected = false;
5928         boolean wifi_under_5g = false;
5929
5930         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5931                     "[BTCoex], SCAN notify()\n");
5932         BTC_TRACE(trace_buf);
5933
5934         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
5935                            &wifi_connected);
5936
5937
5938
5939         if (btcoexist->manual_control ||
5940             btcoexist->stop_coex_dm)
5941                 return;
5942
5943         if (BTC_SCAN_START == type) {
5944                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5945
5946                 if (wifi_under_5g) {
5947                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5948                                 "[BTCoex], ********** (scan_notify_5g_scan_start) **********\n");
5949                         BTC_TRACE(trace_buf);
5950                         halbtc8822b1ant_action_wifi_under5g(btcoexist);
5951                         return;
5952                 }
5953
5954                 /* under 2.4G */
5955                 coex_sta->wifi_is_high_pri_task = true;
5956
5957                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5958                         "[BTCoex], ********** (scan_notify_2g_scan_start) **********\n");
5959                 BTC_TRACE(trace_buf);
5960
5961                 if (!wifi_connected) {  /* non-connected scan */
5962                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5963                                 "[BTCoex], ********** wifi is not connected scan **********\n");
5964                         BTC_TRACE(trace_buf);
5965                         halbtc8822b1ant_action_wifi_not_connected_scan(
5966                                 btcoexist);
5967                 } else {        /* wifi is connected */
5968                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5969                                 "[BTCoex], ********** wifi is connected scan **********\n");
5970                         BTC_TRACE(trace_buf);
5971                         halbtc8822b1ant_action_wifi_connected_scan(
5972                                 btcoexist);
5973                 }
5974
5975                 return;
5976         }
5977
5978         if (BTC_SCAN_START_2G == type) {
5979                 coex_sta->wifi_is_high_pri_task = true;
5980
5981                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5982                         "[BTCoex], ********** (scan_notify_2g_sacn_start_for_switch_band_used) **********\n");
5983                 BTC_TRACE(trace_buf);
5984
5985                 if (!wifi_connected) {  /* non-connected scan */
5986                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5987                                 "[BTCoex], ********** wifi is not connected **********\n");
5988                         BTC_TRACE(trace_buf);
5989
5990                         halbtc8822b1ant_action_wifi_not_connected_scan(
5991                                 btcoexist);
5992                 } else  { /* wifi is connected */
5993                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5994                                 "[BTCoex], ********** wifi is connected **********\n");
5995                         BTC_TRACE(trace_buf);
5996                         halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
5997                 }
5998         } else {
5999                 coex_sta->wifi_is_high_pri_task = false;
6000
6001                 /*WL scan finish , then get and update sacn ap numbers */
6002                 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
6003                                    &coex_sta->scan_ap_num);
6004
6005                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6006                         "[BTCoex], ********** (scan_finish_notify) **********\n");
6007                 BTC_TRACE(trace_buf);
6008
6009                 if (!wifi_connected)    /* non-connected scan */
6010                         halbtc8822b1ant_action_wifi_not_connected(btcoexist);
6011                 else {
6012                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6013                                 "[BTCoex], ********** scan_finish_notify wifi is connected **********\n");
6014                         BTC_TRACE(trace_buf);
6015                         halbtc8822b1ant_action_wifi_connected(btcoexist);
6016                 }
6017         }
6018 }
6019
6020
6021
6022 void ex_halbtc8822b1ant_scan_notify_without_bt(IN struct btc_coexist *btcoexist,
6023                 IN u8 type)
6024 {
6025
6026         boolean wifi_under_5g = false;
6027
6028         if (BTC_SCAN_START == type) {
6029                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
6030
6031                 if (wifi_under_5g) {
6032                         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
6033                                                            0x3, 1);
6034                         return;
6035                 }
6036
6037                 /* under 2.4G */
6038                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
6039                                                    0x3, 2);
6040                 return;
6041         }
6042         if (BTC_SCAN_START_2G == type)
6043                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2);
6044 }
6045
6046 void ex_halbtc8822b1ant_switchband_notify(IN struct btc_coexist *btcoexist,
6047                 IN u8 type)
6048 {
6049
6050         boolean wifi_connected = false;
6051
6052
6053         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6054                     "[BTCoex], ********** (switchband_notify) **********\n");
6055         BTC_TRACE(trace_buf);
6056
6057         if (btcoexist->manual_control ||
6058             btcoexist->stop_coex_dm)
6059                 return;
6060
6061
6062         if (type == BTC_SWITCH_TO_5G) {
6063                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6064                         "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_5G) **********\n");
6065                 BTC_TRACE(trace_buf);
6066
6067                 halbtc8822b1ant_action_wifi_under5g(btcoexist);
6068                 return;
6069         } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
6070                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6071                         "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G (no for scan)) **********\n");
6072                 BTC_TRACE(trace_buf);
6073
6074                 halbtc8822b1ant_run_coexist_mechanism(btcoexist);
6075
6076         } else {
6077                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6078                         "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G) **********\n");
6079                 BTC_TRACE(trace_buf);
6080
6081                 ex_halbtc8822b1ant_scan_notify(btcoexist,
6082                                                BTC_SCAN_START_2G);
6083         }
6084
6085 }
6086
6087
6088 void ex_halbtc8822b1ant_switchband_notify_without_bt(IN struct btc_coexist
6089                 *btcoexist,
6090                 IN u8 type)
6091 {
6092         boolean wifi_under_5g = false;
6093
6094         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
6095
6096         if (type == BTC_SWITCH_TO_5G) {
6097
6098                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
6099                                                    0x3, 1);
6100                 return;
6101         } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
6102
6103                 if (wifi_under_5g)
6104
6105                         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
6106                                                            0x3, 1);
6107
6108                 else
6109                         btcoexist->btc_write_1byte_bitmask(btcoexist,
6110                                                            0xcbd, 0x3, 2);
6111         } else {
6112
6113                 ex_halbtc8822b1ant_scan_notify_without_bt(btcoexist,
6114                                 BTC_SCAN_START_2G);
6115         }
6116
6117 }
6118
6119 void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist,
6120                                        IN u8 type)
6121 {
6122         boolean wifi_connected = false;
6123
6124         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6125                     "[BTCoex], ********** (connect notify) **********\n");
6126         BTC_TRACE(trace_buf);
6127
6128         halbtc8822b1ant_post_state_to_bt(btcoexist,
6129                                          BT_8822B_1ANT_SCOREBOARD_SCAN, true);
6130
6131         if (btcoexist->manual_control ||
6132             btcoexist->stop_coex_dm)
6133                 return;
6134
6135
6136         if ((BTC_ASSOCIATE_5G_START == type) ||
6137             (BTC_ASSOCIATE_5G_FINISH == type)) {
6138
6139                 if (BTC_ASSOCIATE_5G_START == type) {
6140
6141                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6142                                 "[BTCoex], ********** (5G associate start notify) **********\n");
6143                         BTC_TRACE(trace_buf);
6144
6145                         halbtc8822b1ant_action_wifi_under5g(btcoexist);
6146
6147                 } else if (BTC_ASSOCIATE_5G_FINISH == type) {
6148
6149                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6150                                 "[BTCoex], ********** (5G associate finish notify) **********\n");
6151                         BTC_TRACE(trace_buf);
6152
6153                 }
6154
6155                 return;
6156
6157         }
6158
6159
6160         if (BTC_ASSOCIATE_START == type) {
6161
6162                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6163                             "[BTCoex], 2G CONNECT START notify\n");
6164                 BTC_TRACE(trace_buf);
6165
6166                 coex_sta->wifi_is_high_pri_task = true;
6167
6168                 halbtc8822b1ant_set_ant_path(btcoexist,
6169                                              BTC_ANT_PATH_AUTO,
6170                                              FORCE_EXEC,
6171                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
6172
6173                 coex_dm->arp_cnt = 0;
6174
6175                 halbtc8822b1ant_action_wifi_not_connected_asso_auth(btcoexist);
6176
6177         } else {
6178
6179                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6180                             "[BTCoex], 2G CONNECT Finish notify\n");
6181                 BTC_TRACE(trace_buf);
6182                 coex_sta->wifi_is_high_pri_task = false;
6183
6184                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
6185                                    &wifi_connected);
6186
6187                 if (!wifi_connected) /* non-connected scan */
6188                         halbtc8822b1ant_action_wifi_not_connected(btcoexist);
6189                 else
6190                         halbtc8822b1ant_action_wifi_connected(btcoexist);
6191         }
6192
6193 }
6194
6195 void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist,
6196                 IN u8 type)
6197 {
6198         boolean                 wifi_under_b_mode = false;
6199         boolean wifi_under_5g = false;
6200         u32                     cnt_bt_cal_chk = 0;
6201         boolean                 is_in_mp_mode = false;
6202         u8                      u8tmp = 0;
6203         u32                     u32tmp1 = 0, u32tmp2 = 0;
6204
6205
6206         if (btcoexist->manual_control ||
6207             btcoexist->stop_coex_dm)
6208                 return;
6209
6210
6211         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
6212
6213
6214
6215
6216         if (BTC_MEDIA_CONNECT == type) {
6217
6218                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6219                             "[BTCoex], 2g media connect notify");
6220                 BTC_TRACE(trace_buf);
6221
6222                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6223                                          BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
6224
6225                 if (wifi_under_5g) {
6226                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6227                                     "[BTCoex], 5g media notify\n");
6228 BTC_TRACE(trace_buf);
6229
6230                         halbtc8822b1ant_action_wifi_under5g(btcoexist);
6231                         return;
6232                 }
6233                 /* Force antenna setup for no scan result issue */
6234                 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
6235                                              FORCE_EXEC,
6236                                              BT_8822B_1ANT_PHASE_2G_RUNTIME);
6237
6238                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
6239                                    &wifi_under_b_mode);
6240
6241                 /* Set CCK Tx/Rx high Pri except 11b mode */
6242                 if (wifi_under_b_mode) {
6243
6244                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6245                                 "[BTCoex], ********** (media status notity under b mode) **********\n");
6246                         BTC_TRACE(trace_buf);
6247                         btcoexist->btc_write_1byte(btcoexist, 0x6cd,
6248                                                    0x00); /* CCK Tx */
6249                         btcoexist->btc_write_1byte(btcoexist, 0x6cf,
6250                                                    0x00); /* CCK Rx */
6251                 } else {
6252                         /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */
6253                         /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */
6254                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6255                                 "[BTCoex], ********** (media status notity not under b mode) **********\n");
6256                         BTC_TRACE(trace_buf);
6257                         btcoexist->btc_write_1byte(btcoexist, 0x6cd,
6258                                                    0x00); /* CCK Tx */
6259                         btcoexist->btc_write_1byte(btcoexist, 0x6cf,
6260                                                    0x10); /* CCK Rx */
6261                 }
6262
6263                 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
6264                                             0x430);
6265                 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
6266                                             0x434);
6267                 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
6268                                                       btcoexist, 0x42a);
6269                 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
6270                                 btcoexist, 0x456);
6271         } else {
6272                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6273                             "[BTCoex], 2g media disconnect notify\n");
6274                 BTC_TRACE(trace_buf);
6275                 coex_dm->arp_cnt = 0;
6276
6277                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6278                                  BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
6279
6280                 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
6281                 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
6282
6283                 coex_sta->cck_ever_lock = false;
6284         }
6285
6286         halbtc8822b1ant_update_wifi_channel_info(btcoexist, type);
6287
6288 }
6289
6290 void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
6291                 IN u8 type)
6292 {
6293         boolean under_4way = false, wifi_under_5g = false;
6294
6295         if (btcoexist->manual_control ||
6296             btcoexist->stop_coex_dm)
6297                 return;
6298
6299         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
6300         if (wifi_under_5g) {
6301                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6302                             "[BTCoex], 5g special packet notify\n");
6303                 BTC_TRACE(trace_buf);
6304
6305                 halbtc8822b1ant_action_wifi_under5g(btcoexist);
6306                 return;
6307         }
6308
6309         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
6310                            &under_4way);
6311
6312         if (under_4way) {
6313
6314                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6315                             "[BTCoex], specific Packet ---- under_4way!!\n");
6316                 BTC_TRACE(trace_buf);
6317
6318                 coex_sta->wifi_is_high_pri_task = true;
6319                 coex_sta->specific_pkt_period_cnt = 2;
6320         } else if (BTC_PACKET_ARP == type) {
6321
6322                 coex_dm->arp_cnt++;
6323
6324                 if (coex_sta->wifi_is_high_pri_task) {
6325                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6326                                 "[BTCoex], specific Packet ARP notify -cnt = %d\n",
6327                                     coex_dm->arp_cnt);
6328                         BTC_TRACE(trace_buf);
6329                 }
6330
6331         } else {
6332
6333                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6334                         "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
6335                             type);
6336                 BTC_TRACE(trace_buf);
6337
6338                 coex_sta->wifi_is_high_pri_task = true;
6339                 coex_sta->specific_pkt_period_cnt = 2;
6340         }
6341
6342         if (coex_sta->wifi_is_high_pri_task)
6343                 halbtc8822b1ant_action_wifi_connected_specific_packet(
6344                         btcoexist);
6345
6346 }
6347
6348 void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
6349                                        IN u8 *tmp_buf, IN u8 length)
6350 {
6351         u8                              bt_info = 0;
6352         u8                              i, rsp_source = 0;
6353         boolean                         bt_busy = false;
6354         boolean                         wifi_connected = false;
6355         boolean wifi_under_5g = false;
6356
6357
6358         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
6359
6360         coex_sta->c2h_bt_info_req_sent = false;
6361         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6362                     "[BTCoex], ********** (BtInfo Notify) **********\n");
6363         BTC_TRACE(trace_buf);
6364
6365         rsp_source = tmp_buf[0] & 0xf;
6366         if (rsp_source >= BT_INFO_SRC_8822B_1ANT_MAX)
6367                 rsp_source = BT_INFO_SRC_8822B_1ANT_WIFI_FW;
6368         coex_sta->bt_info_c2h_cnt[rsp_source]++;
6369
6370         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6371                     "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
6372                     length);
6373         BTC_TRACE(trace_buf);
6374
6375         for (i = 0; i < length; i++) {
6376                 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
6377                 if (i == 1)
6378                         bt_info = tmp_buf[i];
6379                 if (i == length - 1) {
6380                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
6381                                     tmp_buf[i]);
6382                         BTC_TRACE(trace_buf);
6383                 } else {
6384                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
6385                                     tmp_buf[i]);
6386                         BTC_TRACE(trace_buf);
6387                 }
6388         }
6389
6390
6391         if (BT_INFO_SRC_8822B_1ANT_WIFI_FW != rsp_source) {
6392
6393                 /* if 0xff, it means BT is under WHCK test */
6394                 if (bt_info == 0xff)
6395                         coex_sta->bt_whck_test = true;
6396                 else
6397                         coex_sta->bt_whck_test = false;
6398
6399                 coex_sta->bt_retry_cnt =        /* [3:0] */
6400                         coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
6401
6402                 if (coex_sta->bt_retry_cnt >= 1)
6403                         coex_sta->pop_event_cnt++;
6404
6405                 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
6406                         coex_sta->c2h_bt_page = true;
6407                 else
6408                         coex_sta->c2h_bt_page = false;
6409
6410                 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x80)
6411                         coex_sta->bt_create_connection = true;
6412                 else
6413                         coex_sta->bt_create_connection = false;
6414
6415                 /* unit: %, value-100 to translate to unit: dBm */
6416                 coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 +
6417                                     10;
6418
6419                 /* coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; */
6420
6421                 if ((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) {
6422                         coex_sta->a2dp_bit_pool =
6423                                 coex_sta->bt_info_c2h[rsp_source][6];
6424                 } else
6425                         coex_sta->a2dp_bit_pool = 0;
6426
6427                 if (coex_sta->bt_info_c2h[rsp_source][1] & 0x9)
6428                         coex_sta->acl_busy = true;
6429                 else
6430                         coex_sta->acl_busy = false;
6431
6432                 coex_sta->bt_info_ext =
6433                         coex_sta->bt_info_c2h[rsp_source][4];
6434
6435                 /* Here we need to resend some wifi info to BT */
6436                 /* because bt is reset and loss of the info. */
6437
6438                 if ((!btcoexist->manual_control) &&
6439                     (!btcoexist->stop_coex_dm)) {
6440
6441                         /*      Re-Init */
6442                         if (coex_sta->bt_info_ext & BIT(1)) {
6443                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6444                                         "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
6445                                 BTC_TRACE(trace_buf);
6446                                 btcoexist->btc_get(btcoexist,
6447                                                    BTC_GET_BL_WIFI_CONNECTED,
6448                                                    &wifi_connected);
6449                                 if (wifi_connected)
6450                                         halbtc8822b1ant_update_wifi_channel_info(
6451                                                 btcoexist,
6452                                                 BTC_MEDIA_CONNECT);
6453                                 else
6454                                         halbtc8822b1ant_update_wifi_channel_info(
6455                                                 btcoexist,
6456                                                 BTC_MEDIA_DISCONNECT);
6457                         }
6458
6459                         /*      If Ignore_WLanAct && not SetUp_Link */
6460                         if ((coex_sta->bt_info_ext & BIT(3)) &&
6461                             (!(coex_sta->bt_info_ext & BIT(2)))) {
6462
6463                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6464                                         "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
6465                                 BTC_TRACE(trace_buf);
6466                                 halbtc8822b1ant_ignore_wlan_act(btcoexist,
6467                                                                 FORCE_EXEC,
6468                                                                 false);
6469                         }
6470                 }
6471                 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6472                 if (bt_info & BT_INFO_8822B_1ANT_B_INQ_PAGE)
6473                         coex_sta->c2h_bt_inquiry_page = true;
6474                 else
6475                         coex_sta->c2h_bt_inquiry_page = false;
6476         }
6477
6478         coex_sta->num_of_profile = 0;
6479
6480         /* set link exist status */
6481         if (!(bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
6482                 coex_sta->bt_link_exist = false;
6483                 coex_sta->pan_exist = false;
6484                 coex_sta->a2dp_exist = false;
6485                 coex_sta->hid_exist = false;
6486                 coex_sta->sco_exist = false;
6487
6488                 coex_sta->bt_hi_pri_link_exist = false;
6489         } else {        /* connection exists */
6490                 coex_sta->bt_link_exist = true;
6491                 if (bt_info & BT_INFO_8822B_1ANT_B_FTP) {
6492                         coex_sta->pan_exist = true;
6493                         coex_sta->num_of_profile++;
6494                 } else
6495                         coex_sta->pan_exist = false;
6496                 if (bt_info & BT_INFO_8822B_1ANT_B_A2DP) {
6497                         coex_sta->a2dp_exist = true;
6498                         coex_sta->num_of_profile++;
6499                 } else
6500                         coex_sta->a2dp_exist = false;
6501                 if (bt_info & BT_INFO_8822B_1ANT_B_HID) {
6502                         coex_sta->hid_exist = true;
6503                         coex_sta->num_of_profile++;
6504                 } else
6505                         coex_sta->hid_exist = false;
6506                 if (bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) {
6507                         coex_sta->sco_exist = true;
6508                         coex_sta->num_of_profile++;
6509                 } else
6510                         coex_sta->sco_exist = false;
6511
6512         }
6513
6514         halbtc8822b1ant_update_bt_link_info(btcoexist);
6515
6516         bt_info = bt_info &
6517                 0x1f;  /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
6518
6519         if (!(bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
6520                 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
6521                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6522                         "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
6523                 BTC_TRACE(trace_buf);
6524         } else if (bt_info ==
6525                 BT_INFO_8822B_1ANT_B_CONNECTION) {      /* connection exists but no busy */
6526                 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE;
6527                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6528                             "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
6529                 BTC_TRACE(trace_buf);
6530         } else if ((bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) ||
6531                    (bt_info & BT_INFO_8822B_1ANT_B_SCO_BUSY)) {
6532                 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_SCO_BUSY;
6533                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6534                             "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
6535                 BTC_TRACE(trace_buf);
6536         } else if (bt_info & BT_INFO_8822B_1ANT_B_ACL_BUSY) {
6537                 if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
6538                         coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_ACL_BUSY;
6539                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6540                             "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
6541                 BTC_TRACE(trace_buf);
6542         } else {
6543                 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_MAX;
6544                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6545                         "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
6546                 BTC_TRACE(trace_buf);
6547         }
6548
6549         if ((BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
6550             (BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
6551             (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
6552                 bt_busy = true;
6553         else
6554                 bt_busy = false;
6555
6556         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
6557
6558         halbtc8822b1ant_run_coexist_mechanism(btcoexist);
6559 }
6560
6561 void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
6562                 IN u8 type)
6563 {
6564         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
6565         BTC_TRACE(trace_buf);
6566
6567         if (BTC_RF_ON == type) {
6568                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6569                             "[BTCoex], RF is turned ON!!\n");
6570                 BTC_TRACE(trace_buf);
6571                 btcoexist->stop_coex_dm = false;
6572
6573                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6574                                          BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
6575                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6576                                          BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
6577
6578         } else if (BTC_RF_OFF == type) {
6579                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6580                             "[BTCoex], RF is turned OFF!!\n");
6581                 BTC_TRACE(trace_buf);
6582
6583                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6584                                  BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
6585                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6586                                          BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
6587                 halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
6588
6589                 halbtc8822b1ant_set_ant_path(btcoexist,
6590                                              BTC_ANT_PATH_AUTO,
6591                                              FORCE_EXEC,
6592                                              BT_8822B_1ANT_PHASE_WLAN_OFF);
6593                 /* for test : s3 bt disppear , fail rate 1/600*/
6594
6595                 halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
6596
6597                 btcoexist->stop_coex_dm = true;
6598         }
6599 }
6600
6601 void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist)
6602 {
6603
6604         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
6605         BTC_TRACE(trace_buf);
6606
6607         halbtc8822b1ant_post_state_to_bt(btcoexist,
6608                                  BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
6609         halbtc8822b1ant_post_state_to_bt(btcoexist,
6610                                          BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
6611
6612         halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
6613
6614         halbtc8822b1ant_set_ant_path(btcoexist,
6615                                      BTC_ANT_PATH_AUTO,
6616                                      FORCE_EXEC,
6617                                      BT_8822B_1ANT_PHASE_WLAN_OFF);
6618         /* for test : s3 bt disppear , fail rate 1/600*/
6619
6620         halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
6621
6622         ex_halbtc8822b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
6623
6624         halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, false);
6625
6626         btcoexist->stop_coex_dm = true;
6627 }
6628
6629
6630 void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist,
6631                                    IN u8 pnp_state)
6632 {
6633         boolean wifi_under_5g = false;
6634
6635         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
6636         BTC_TRACE(trace_buf);
6637
6638 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
6639         if (BTC_WIFI_PNP_SLEEP == pnp_state) {
6640                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6641                             "[BTCoex], Pnp notify to SLEEP\n");
6642                 BTC_TRACE(trace_buf);
6643
6644                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6645                                  BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
6646                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6647                                          BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
6648                 /*
6649                                 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
6650
6651                                 halbtc8822b1ant_set_ant_path(btcoexist,
6652                                                                         BTC_ANT_PATH_AUTO,
6653                                                                 FORCE_EXEC,
6654                                                                 BT_8822B_1ANT_PHASE_WLAN_OFF);
6655
6656                                 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
6657                                                                      5);
6658
6659                                 halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, false);
6660                 */
6661                 btcoexist->stop_coex_dm = true;
6662         } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
6663                 /*pnp_wake_cnt++;*/
6664                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6665                             "[BTCoex], Pnp notify to WAKE UP\n");
6666                 BTC_TRACE(trace_buf);
6667
6668                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6669                                          BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
6670                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6671                                          BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
6672
6673                 btcoexist->stop_coex_dm = false;
6674         }
6675 }
6676
6677 void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
6678 {
6679         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6680                 "[BTCoex], *****************Coex DM Reset*****************\n");
6681         BTC_TRACE(trace_buf);
6682
6683         halbtc8822b1ant_init_hw_config(btcoexist, false, false);
6684         halbtc8822b1ant_init_coex_dm(btcoexist);
6685 }
6686
6687 void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist)
6688 {
6689
6690         struct  btc_board_info  *board_info = &btcoexist->board_info;
6691         boolean wifi_busy = false;
6692         u16 bt_scoreboard_val = 0;
6693         u32 bt_patch_ver;
6694         static u8 cnt = 0;
6695         boolean bt_relink_finish = false;
6696
6697         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6698                 "[BTCoex], ==========================Periodical===========================\n");
6699         BTC_TRACE(trace_buf);
6700
6701 #if (BT_AUTO_REPORT_ONLY_8822B_1ANT == 0)
6702         halbtc8822b1ant_query_bt_info(btcoexist);
6703 #endif
6704
6705         halbtc8822b1ant_monitor_bt_ctr(btcoexist);
6706         halbtc8822b1ant_monitor_wifi_ctr(btcoexist);
6707
6708         halbtc8822b1ant_monitor_bt_enable_disable(btcoexist);
6709
6710         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
6711         halbtc8822b1ant_read_score_board(btcoexist, &bt_scoreboard_val);
6712
6713         if (wifi_busy) {
6714                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6715                         BT_8822B_1ANT_SCOREBOARD_WLBUSY, true);
6716                 if (bt_scoreboard_val & BIT(6))
6717                         halbtc8822b1ant_query_bt_info(btcoexist);
6718         } else {
6719                 halbtc8822b1ant_post_state_to_bt(btcoexist,
6720                         BT_8822B_1ANT_SCOREBOARD_WLBUSY, false);
6721         }
6722
6723         /* for 4-way, DHCP, EAPOL packet */
6724         if (coex_sta->specific_pkt_period_cnt > 0) {
6725
6726                 coex_sta->specific_pkt_period_cnt--;
6727
6728                 if ((coex_sta->specific_pkt_period_cnt == 0) &&
6729                     (coex_sta->wifi_is_high_pri_task))
6730                         coex_sta->wifi_is_high_pri_task = false;
6731
6732                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
6733                         "[BTCoex], ***************** Hi-Pri Task = %s*****************\n",
6734                             (coex_sta->wifi_is_high_pri_task ? "Yes" :
6735                              "No"));
6736                 BTC_TRACE(trace_buf);
6737         }
6738
6739         if (!coex_sta->bt_disabled) {
6740                 if (coex_sta->bt_coex_supported_feature == 0)
6741                         btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, &coex_sta->bt_coex_supported_feature);
6742
6743                 if ((coex_sta->bt_coex_supported_version == 0) ||
6744                         (coex_sta->bt_coex_supported_version == 0xffff))
6745                         btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
6746
6747                 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
6748                 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
6749
6750                 if (halbtc8822b1ant_is_wifi_status_changed(btcoexist))
6751                         halbtc8822b1ant_run_coexist_mechanism(btcoexist);
6752
6753         }
6754 }
6755
6756 void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist,
6757                 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
6758 {
6759 }
6760
6761 void ex_halbtc8822b1ant_antenna_isolation(IN struct btc_coexist *btcoexist,
6762                 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
6763 {
6764
6765
6766 }
6767
6768 void ex_halbtc8822b1ant_psd_scan(IN struct btc_coexist *btcoexist,
6769                  IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
6770 {
6771
6772
6773 }
6774
6775 void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist)
6776 {
6777
6778 }
6779
6780 void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist,
6781                                     IN u8 op_code, IN u8 op_len, IN u8 *pdata)
6782 {}
6783 #endif  /*  #if(BTC_COEX_OFFLOAD == 1) */
6784
6785 #endif
6786
6787 #else
6788
6789 void ex_halbtc8822b1ant_switch_band_without_bt(IN struct btc_coexist *btcoexist,
6790                 IN boolean wifi_only_5g)
6791 {
6792         /* ant switch WL2G or WL5G*/
6793         if (wifi_only_5g)
6794
6795                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 1);
6796
6797         else
6798
6799                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2);
6800
6801 }
6802
6803 void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist
6804                 *btcoexist)
6805 {
6806         /* enable GNT_WL */
6807
6808         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1,
6809                                            0x0);
6810
6811         /* Antenna config */
6812         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
6813                                            0x80, 0x0);  /*  0x4c[23] = 0 */
6814         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
6815                                            0x01, 0x1);  /* 0x4c[24] = 1 */
6816         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
6817                 0xff, 0x77);    /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
6818
6819
6820         /* Ext switch buffer mux */
6821         btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
6822         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991,
6823                                            0x3, 0x0);
6824         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe,
6825                                            0x8, 0x0);
6826
6827         /*enable sw control gnt_wl=1 / gnt_bt=1 */
6828         btcoexist->btc_write_1byte(btcoexist, 0x73, 0x0e);
6829
6830         btcoexist->btc_write_4byte(btcoexist, 0x1704,
6831                                    0x0000ff00);
6832
6833         btcoexist->btc_write_4byte(btcoexist, 0x1700,
6834                                    0xc00f0038);
6835 }
6836
6837 #endif  /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */
6838
6839
6840