net: wireless: rockchip_wlan: add rtl8723bs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / hal / btc / HalBtc8812a2Ant.c
1 /* ************************************************************
2  * Description:
3  *
4  * This file is for RTL8812A Co-exist mechanism
5  *
6  * History
7  * 2012/08/22 Cosa first check in.
8  * 2012/11/14 Cosa Revise for 8812A 2Ant out sourcing.
9  *
10  * ************************************************************ */
11
12 /* ************************************************************
13  * include files
14  * ************************************************************ */
15 #include "Mp_Precomp.h"
16
17 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
18
19 #if (RTL8812A_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_8812a_2ant       glcoex_dm_8812a_2ant;
25 static struct  coex_dm_8812a_2ant       *coex_dm = &glcoex_dm_8812a_2ant;
26 static struct  coex_sta_8812a_2ant      glcoex_sta_8812a_2ant;
27 static struct  coex_sta_8812a_2ant      *coex_sta = &glcoex_sta_8812a_2ant;
28
29 const char *const glbt_info_src_8812a_2ant[] = {
30         "BT Info[wifi fw]",
31         "BT Info[bt rsp]",
32         "BT Info[bt auto report]",
33 };
34
35 u32     glcoex_ver_date_8812a_2ant = 20150724;
36 u32     glcoex_ver_8812a_2ant = 0x37;
37
38 /* ************************************************************
39  * local function proto type if needed
40  * ************************************************************
41  * ************************************************************
42  * local function start with halbtc8812a2ant_
43  * ************************************************************ */
44 u8 halbtc8812a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
45 {
46         s32                     bt_rssi = 0;
47         u8                      bt_rssi_state = coex_sta->pre_bt_rssi_state;
48
49         bt_rssi = coex_sta->bt_rssi;
50
51         if (level_num == 2) {
52                 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
53                     (coex_sta->pre_bt_rssi_state ==
54                      BTC_RSSI_STATE_STAY_LOW)) {
55                         if (bt_rssi >= (rssi_thresh +
56                                         BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
57                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
58                         else
59                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
60                 } else {
61                         if (bt_rssi < rssi_thresh)
62                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
63                         else
64                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
65                 }
66         } else if (level_num == 3) {
67                 if (rssi_thresh > rssi_thresh1) {
68                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
69                                     "[BTCoex], BT Rssi thresh error!!\n");
70                         BTC_TRACE(trace_buf);
71                         return coex_sta->pre_bt_rssi_state;
72                 }
73
74                 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
75                     (coex_sta->pre_bt_rssi_state ==
76                      BTC_RSSI_STATE_STAY_LOW)) {
77                         if (bt_rssi >= (rssi_thresh +
78                                         BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
79                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
80                         else
81                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
82                 } else if ((coex_sta->pre_bt_rssi_state ==
83                             BTC_RSSI_STATE_MEDIUM) ||
84                            (coex_sta->pre_bt_rssi_state ==
85                             BTC_RSSI_STATE_STAY_MEDIUM)) {
86                         if (bt_rssi >= (rssi_thresh1 +
87                                         BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
88                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
89                         else if (bt_rssi < rssi_thresh)
90                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
91                         else
92                                 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
93                 } else {
94                         if (bt_rssi < rssi_thresh1)
95                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
96                         else
97                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
98                 }
99         }
100
101         coex_sta->pre_bt_rssi_state = bt_rssi_state;
102
103         return bt_rssi_state;
104 }
105
106 u8 halbtc8812a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
107            IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
108 {
109         s32                     wifi_rssi = 0;
110         u8                      wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
111
112         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
113
114         if (level_num == 2) {
115                 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
116                     ||
117                     (coex_sta->pre_wifi_rssi_state[index] ==
118                      BTC_RSSI_STATE_STAY_LOW)) {
119                         if (wifi_rssi >= (rssi_thresh +
120                                           BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
121                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
122                         else
123                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
124                 } else {
125                         if (wifi_rssi < rssi_thresh)
126                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
127                         else
128                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
129                 }
130         } else if (level_num == 3) {
131                 if (rssi_thresh > rssi_thresh1) {
132                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
133                                     "[BTCoex], wifi RSSI thresh error!!\n");
134                         BTC_TRACE(trace_buf);
135                         return coex_sta->pre_wifi_rssi_state[index];
136                 }
137
138                 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
139                     ||
140                     (coex_sta->pre_wifi_rssi_state[index] ==
141                      BTC_RSSI_STATE_STAY_LOW)) {
142                         if (wifi_rssi >= (rssi_thresh +
143                                           BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
144                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
145                         else
146                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
147                 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
148                             BTC_RSSI_STATE_MEDIUM) ||
149                            (coex_sta->pre_wifi_rssi_state[index] ==
150                             BTC_RSSI_STATE_STAY_MEDIUM)) {
151                         if (wifi_rssi >= (rssi_thresh1 +
152                                           BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
153                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
154                         else if (wifi_rssi < rssi_thresh)
155                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
156                         else
157                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
158                 } else {
159                         if (wifi_rssi < rssi_thresh1)
160                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
161                         else
162                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
163                 }
164         }
165
166         coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
167
168         return wifi_rssi_state;
169 }
170
171 void halbtc8812a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
172 {
173         struct  btc_stack_info  *stack_info = &btcoexist->stack_info;
174         static u32      bt_disable_cnt = 0;
175         boolean                 bt_active = true, bt_disabled = false;
176
177         /* This function check if bt is disabled */
178
179         /* only 8812a need to consider if core stack is installed. */
180         if (!stack_info->hci_version)
181                 bt_active = false;
182
183         if (coex_sta->high_priority_tx == 0 &&
184             coex_sta->high_priority_rx == 0 &&
185             coex_sta->low_priority_tx == 0 &&
186             coex_sta->low_priority_rx == 0)
187                 bt_active = false;
188         if (coex_sta->high_priority_tx == 0xffff &&
189             coex_sta->high_priority_rx == 0xffff &&
190             coex_sta->low_priority_tx == 0xffff &&
191             coex_sta->low_priority_rx == 0xffff)
192                 bt_active = false;
193         if (bt_active) {
194                 bt_disable_cnt = 0;
195                 bt_disabled = false;
196                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
197                                    &bt_disabled);
198                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
199                             "[BTCoex], BT is enabled !!\n");
200                 BTC_TRACE(trace_buf);
201         } else {
202                 bt_disable_cnt++;
203                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
204                             "[BTCoex], bt is detected as disabled %d times!!\n",
205                             bt_disable_cnt);
206                 BTC_TRACE(trace_buf);
207                 if (bt_disable_cnt >= 2) {
208                         bt_disabled = true;
209                         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
210                                            &bt_disabled);
211                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
212                                     "[BTCoex], BT is disabled !!\n");
213                         BTC_TRACE(trace_buf);
214                 }
215         }
216         if (coex_sta->bt_disabled != bt_disabled) {
217                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
218                             "[BTCoex], BT is from %s to %s!!\n",
219                             (coex_sta->bt_disabled ? "disabled" : "enabled"),
220                             (bt_disabled ? "disabled" : "enabled"));
221                 BTC_TRACE(trace_buf);
222                 coex_sta->bt_disabled = bt_disabled;
223                 if (!bt_disabled) {
224                 } else {
225                 }
226         }
227 }
228
229 u32 halbtc8812a2ant_decide_ra_mask(IN struct btc_coexist *btcoexist,
230                                    IN u32 ra_mask_type)
231 {
232         u32     dis_ra_mask = 0x0;
233
234         switch (ra_mask_type) {
235         case 0: /* normal mode */
236                 dis_ra_mask = 0x0;
237                 break;
238         case 1: /* disable cck 1/2 */
239                 dis_ra_mask = 0x00000003;
240                 break;
241         case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4                         */
242                 dis_ra_mask = 0x0001f1f7;
243                 break;
244         default:
245                 break;
246         }
247
248         return dis_ra_mask;
249 }
250
251 void halbtc8812a2ant_update_ra_mask(IN struct btc_coexist *btcoexist,
252                                     IN boolean force_exec, IN u32 dis_rate_mask)
253 {
254         coex_dm->cur_ra_mask = dis_rate_mask;
255
256         if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
257                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
258                                    &coex_dm->cur_ra_mask);
259         coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
260 }
261
262 void halbtc8812a2ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
263                 IN boolean force_exec, IN u8 type)
264 {
265         boolean wifi_under_b_mode = false;
266
267         coex_dm->cur_arfr_type = type;
268
269         if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
270                 switch (coex_dm->cur_arfr_type) {
271                 case 0: /* normal mode */
272                         btcoexist->btc_write_4byte(btcoexist, 0x430,
273                                                    coex_dm->backup_arfr_cnt1);
274                         btcoexist->btc_write_4byte(btcoexist, 0x434,
275                                                    coex_dm->backup_arfr_cnt2);
276                         break;
277                 case 1:
278                         btcoexist->btc_get(btcoexist,
279                                            BTC_GET_BL_WIFI_UNDER_B_MODE,
280                                            &wifi_under_b_mode);
281                         if (wifi_under_b_mode) {
282                                 btcoexist->btc_write_4byte(btcoexist,
283                                                            0x430, 0x0);
284                                 btcoexist->btc_write_4byte(btcoexist,
285                                                            0x434, 0x01010101);
286                         } else {
287                                 btcoexist->btc_write_4byte(btcoexist,
288                                                            0x430, 0x0);
289                                 btcoexist->btc_write_4byte(btcoexist,
290                                                            0x434, 0x04030201);
291                         }
292                         break;
293                 default:
294                         break;
295                 }
296         }
297
298         coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
299 }
300
301 void halbtc8812a2ant_retry_limit(IN struct btc_coexist *btcoexist,
302                                  IN boolean force_exec, IN u8 type)
303 {
304         coex_dm->cur_retry_limit_type = type;
305
306         if (force_exec ||
307             (coex_dm->pre_retry_limit_type !=
308              coex_dm->cur_retry_limit_type)) {
309                 switch (coex_dm->cur_retry_limit_type) {
310                 case 0: /* normal mode */
311                         btcoexist->btc_write_2byte(btcoexist, 0x42a,
312                                                    coex_dm->backup_retry_limit);
313                         break;
314                 case 1: /* retry limit=8 */
315                         btcoexist->btc_write_2byte(btcoexist, 0x42a,
316                                                    0x0808);
317                         break;
318                 default:
319                         break;
320                 }
321         }
322
323         coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
324 }
325
326 void halbtc8812a2ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
327                                     IN boolean force_exec, IN u8 type)
328 {
329         coex_dm->cur_ampdu_time_type = type;
330
331         if (force_exec ||
332             (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
333                 switch (coex_dm->cur_ampdu_time_type) {
334                 case 0: /* normal mode */
335                         btcoexist->btc_write_1byte(btcoexist, 0x456,
336                                            coex_dm->backup_ampdu_max_time);
337                         break;
338                 case 1: /* AMPDU timw = 0x38 * 32us */
339                         btcoexist->btc_write_1byte(btcoexist, 0x456,
340                                                    0x38);
341                         break;
342                 default:
343                         break;
344                 }
345         }
346
347         coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
348 }
349
350 void halbtc8812a2ant_limited_tx(IN struct btc_coexist *btcoexist,
351                 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
352                                 IN u8 retry_limit_type, IN u8 ampdu_time_type)
353 {
354         u32     dis_ra_mask = 0x0;
355
356         coex_dm->cur_ra_mask_type = ra_mask_type;
357         dis_ra_mask = halbtc8812a2ant_decide_ra_mask(btcoexist, ra_mask_type);
358         halbtc8812a2ant_update_ra_mask(btcoexist, force_exec, dis_ra_mask);
359
360         halbtc8812a2ant_auto_rate_fallback_retry(btcoexist, force_exec,
361                         arfr_type);
362         halbtc8812a2ant_retry_limit(btcoexist, force_exec, retry_limit_type);
363         halbtc8812a2ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
364 }
365
366 void halbtc8812a2ant_limited_rx(IN struct btc_coexist *btcoexist,
367                         IN boolean force_exec, IN boolean rej_ap_agg_pkt,
368                         IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
369 {
370         boolean reject_rx_agg = rej_ap_agg_pkt;
371         boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
372         u8      rx_agg_size = agg_buf_size;
373
374         /* ============================================ */
375         /*      Rx Aggregation related setting */
376         /* ============================================ */
377         btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
378                            &reject_rx_agg);
379         /* decide BT control aggregation buf size or not */
380         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
381                            &bt_ctrl_rx_agg_size);
382         /* aggregation buf size, only work when BT control Rx aggregation size. */
383         btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
384         /* real update aggregation setting */
385         btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
386
387
388 }
389
390 void halbtc8812a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
391 {
392         u32                     reg_hp_txrx, reg_lp_txrx, u32tmp;
393         u32                     reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
394
395         reg_hp_txrx = 0x770;
396         reg_lp_txrx = 0x774;
397
398         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
399         reg_hp_tx = u32tmp & MASKLWORD;
400         reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
401
402         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
403         reg_lp_tx = u32tmp & MASKLWORD;
404         reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
405
406         coex_sta->high_priority_tx = reg_hp_tx;
407         coex_sta->high_priority_rx = reg_hp_rx;
408         coex_sta->low_priority_tx = reg_lp_tx;
409         coex_sta->low_priority_rx = reg_lp_rx;
410
411         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
412                 "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
413                     reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
414         BTC_TRACE(trace_buf);
415         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
416                 "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
417                     reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
418         BTC_TRACE(trace_buf);
419
420         /* reset counter */
421         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
422 }
423
424 void halbtc8812a2ant_query_bt_info(IN struct btc_coexist *btcoexist)
425 {
426         u8      data_len = 3;
427         u8      buf[5] = {0};
428
429         if (!coex_sta->bt_disabled) {
430                 if (!coex_sta->bt_info_query_cnt ||
431                     (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_2ANT_BT_RSP]
432                      - coex_sta->bt_info_query_cnt) > 2) {
433                         buf[0] = data_len;
434                         buf[1] = 0x1;   /* polling enable, 1=enable, 0=disable */
435                         buf[2] = 0x2;   /* polling time in seconds */
436                         buf[3] = 0x1;   /* auto report enable, 1=enable, 0=disable */
437
438                         btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO,
439                                            (void *)&buf[0]);
440                 }
441         }
442         coex_sta->bt_info_query_cnt++;
443 }
444
445 boolean halbtc8812a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
446 {
447         static boolean  pre_wifi_busy = false, pre_under_4way = false,
448                         pre_bt_hs_on = false;
449         boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
450         boolean wifi_connected = false;
451
452         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
453                            &wifi_connected);
454         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
455         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
456         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
457                            &under_4way);
458
459         if (wifi_connected) {
460                 if (wifi_busy != pre_wifi_busy) {
461                         pre_wifi_busy = wifi_busy;
462                         return true;
463                 }
464                 if (under_4way != pre_under_4way) {
465                         pre_under_4way = under_4way;
466                         return true;
467                 }
468                 if (bt_hs_on != pre_bt_hs_on) {
469                         pre_bt_hs_on = bt_hs_on;
470                         return true;
471                 }
472         }
473
474         return false;
475 }
476
477 void halbtc8812a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
478 {
479         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
480         boolean                         bt_hs_on = false;
481
482         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
483
484         bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
485         bt_link_info->sco_exist = coex_sta->sco_exist;
486         bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
487         bt_link_info->pan_exist = coex_sta->pan_exist;
488         bt_link_info->hid_exist = coex_sta->hid_exist;
489         bt_link_info->acl_busy = coex_sta->acl_busy;
490
491         /* work around for HS mode. */
492         if (bt_hs_on) {
493                 bt_link_info->pan_exist = true;
494                 bt_link_info->bt_link_exist = true;
495         }
496
497         /* check if Sco only */
498         if (bt_link_info->sco_exist &&
499             !bt_link_info->a2dp_exist &&
500             !bt_link_info->pan_exist &&
501             !bt_link_info->hid_exist)
502                 bt_link_info->sco_only = true;
503         else
504                 bt_link_info->sco_only = false;
505
506         /* check if A2dp only */
507         if (!bt_link_info->sco_exist &&
508             bt_link_info->a2dp_exist &&
509             !bt_link_info->pan_exist &&
510             !bt_link_info->hid_exist)
511                 bt_link_info->a2dp_only = true;
512         else
513                 bt_link_info->a2dp_only = false;
514
515         /* check if Pan only */
516         if (!bt_link_info->sco_exist &&
517             !bt_link_info->a2dp_exist &&
518             bt_link_info->pan_exist &&
519             !bt_link_info->hid_exist)
520                 bt_link_info->pan_only = true;
521         else
522                 bt_link_info->pan_only = false;
523
524         /* check if Hid only */
525         if (!bt_link_info->sco_exist &&
526             !bt_link_info->a2dp_exist &&
527             !bt_link_info->pan_exist &&
528             bt_link_info->hid_exist)
529                 bt_link_info->hid_only = true;
530         else
531                 bt_link_info->hid_only = false;
532 }
533
534 u8 halbtc8812a2ant_action_algorithm(IN struct btc_coexist *btcoexist)
535 {
536         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
537         struct  btc_stack_info  *stack_info = &btcoexist->stack_info;
538         boolean                         bt_hs_on = false;
539         u8                              algorithm = BT_8812A_2ANT_COEX_ALGO_UNDEFINED;
540         u8                              num_of_diff_profile = 0;
541
542         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
543
544         if (!bt_link_info->bt_link_exist) {
545                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
546                             "[BTCoex], No BT link exists!!!\n");
547                 BTC_TRACE(trace_buf);
548                 return algorithm;
549         }
550
551         if (bt_link_info->sco_exist)
552                 num_of_diff_profile++;
553         if (bt_link_info->hid_exist)
554                 num_of_diff_profile++;
555         if (bt_link_info->pan_exist)
556                 num_of_diff_profile++;
557         if (bt_link_info->a2dp_exist)
558                 num_of_diff_profile++;
559
560         if (num_of_diff_profile == 0) {
561                 if (bt_link_info->acl_busy) {
562                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
563                                     "[BTCoex], ACL Busy only\n");
564                         BTC_TRACE(trace_buf);
565                         algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR;
566                 }
567         } else if (num_of_diff_profile == 1) {
568                 if (bt_link_info->sco_exist) {
569                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
570                                     "[BTCoex], SCO only\n");
571                         BTC_TRACE(trace_buf);
572                         algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
573                 } else {
574                         if (bt_link_info->hid_exist) {
575                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
576                                             "[BTCoex], HID only\n");
577                                 BTC_TRACE(trace_buf);
578                                 algorithm = BT_8812A_2ANT_COEX_ALGO_HID;
579                         } else if (bt_link_info->a2dp_exist) {
580                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
581                                             "[BTCoex], A2DP only\n");
582                                 BTC_TRACE(trace_buf);
583                                 algorithm = BT_8812A_2ANT_COEX_ALGO_A2DP;
584                         } else if (bt_link_info->pan_exist) {
585                                 if (bt_hs_on) {
586                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
587                                                     "[BTCoex], PAN(HS) only\n");
588                                         BTC_TRACE(trace_buf);
589                                         algorithm =
590                                                 BT_8812A_2ANT_COEX_ALGO_PANHS;
591                                 } else {
592                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
593                                                 "[BTCoex], PAN(EDR) only\n");
594                                         BTC_TRACE(trace_buf);
595                                         algorithm =
596                                                 BT_8812A_2ANT_COEX_ALGO_PANEDR;
597                                 }
598                         }
599                 }
600         } else if (num_of_diff_profile == 2) {
601                 if (bt_link_info->sco_exist) {
602                         if (bt_link_info->hid_exist) {
603                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
604                                             "[BTCoex], SCO + HID\n");
605                                 BTC_TRACE(trace_buf);
606                                 algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID;
607                         } else if (bt_link_info->a2dp_exist) {
608                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
609                                             "[BTCoex], SCO + A2DP ==> SCO\n");
610                                 BTC_TRACE(trace_buf);
611                                 algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
612                         } else if (bt_link_info->pan_exist) {
613                                 if (bt_hs_on) {
614                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
615                                                 "[BTCoex], SCO + PAN(HS)\n");
616                                         BTC_TRACE(trace_buf);
617                                         algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
618                                 } else {
619                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
620                                                 "[BTCoex], SCO + PAN(EDR)\n");
621                                         BTC_TRACE(trace_buf);
622                                         algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
623                                 }
624                         }
625                 } else {
626                         if (bt_link_info->hid_exist &&
627                             bt_link_info->a2dp_exist) {
628                                 if (stack_info->num_of_hid >= 2) {
629                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
630                                                     "[BTCoex], HID*2 + A2DP\n");
631                                         BTC_TRACE(trace_buf);
632                                         algorithm =
633                                                 BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
634                                 } else {
635                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
636                                                     "[BTCoex], HID + A2DP\n");
637                                         BTC_TRACE(trace_buf);
638                                         algorithm =
639                                                 BT_8812A_2ANT_COEX_ALGO_HID_A2DP;
640                                 }
641                         } else if (bt_link_info->hid_exist &&
642                                    bt_link_info->pan_exist) {
643                                 if (bt_hs_on) {
644                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
645                                                 "[BTCoex], HID + PAN(HS)\n");
646                                         BTC_TRACE(trace_buf);
647                                         algorithm =
648                                                 BT_8812A_2ANT_COEX_ALGO_HID;
649                                 } else {
650                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
651                                                 "[BTCoex], HID + PAN(EDR)\n");
652                                         BTC_TRACE(trace_buf);
653                                         algorithm =
654                                                 BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
655                                 }
656                         } else if (bt_link_info->pan_exist &&
657                                    bt_link_info->a2dp_exist) {
658                                 if (bt_hs_on) {
659                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
660                                                 "[BTCoex], A2DP + PAN(HS)\n");
661                                         BTC_TRACE(trace_buf);
662                                         algorithm =
663                                                 BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS;
664                                 } else {
665                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
666                                                 "[BTCoex], A2DP + PAN(EDR)\n");
667                                         BTC_TRACE(trace_buf);
668                                         algorithm =
669                                                 BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP;
670                                 }
671                         }
672                 }
673         } else if (num_of_diff_profile == 3) {
674                 if (bt_link_info->sco_exist) {
675                         if (bt_link_info->hid_exist &&
676                             bt_link_info->a2dp_exist) {
677                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
678                                         "[BTCoex], SCO + HID + A2DP ==> HID\n");
679                                 BTC_TRACE(trace_buf);
680                                 algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
681                         } else if (bt_link_info->hid_exist &&
682                                    bt_link_info->pan_exist) {
683                                 if (bt_hs_on) {
684                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
685                                                 "[BTCoex], SCO + HID + PAN(HS)\n");
686                                         BTC_TRACE(trace_buf);
687                                         algorithm =
688                                                 BT_8812A_2ANT_COEX_ALGO_SCO_HID;
689                                 } else {
690                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
691                                                 "[BTCoex], SCO + HID + PAN(EDR)\n");
692                                         BTC_TRACE(trace_buf);
693                                         algorithm =
694                                                 BT_8812A_2ANT_COEX_ALGO_SCO_HID;
695                                 }
696                         } else if (bt_link_info->pan_exist &&
697                                    bt_link_info->a2dp_exist) {
698                                 if (bt_hs_on) {
699                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
700                                                 "[BTCoex], SCO + A2DP + PAN(HS)\n");
701                                         BTC_TRACE(trace_buf);
702                                         algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
703                                 } else {
704                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
705                                                 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
706                                         BTC_TRACE(trace_buf);
707                                         algorithm =
708                                                 BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
709                                 }
710                         }
711                 } else {
712                         if (bt_link_info->hid_exist &&
713                             bt_link_info->pan_exist &&
714                             bt_link_info->a2dp_exist) {
715                                 if (bt_hs_on) {
716                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
717                                                 "[BTCoex], HID + A2DP + PAN(HS)\n");
718                                         BTC_TRACE(trace_buf);
719                                         algorithm =
720                                                 BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS;
721                                 } else {
722                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
723                                                 "[BTCoex], HID + A2DP + PAN(EDR)\n");
724                                         BTC_TRACE(trace_buf);
725                                         algorithm =
726                                                 BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
727                                 }
728                         }
729                 }
730         } else if (num_of_diff_profile >= 3) {
731                 if (bt_link_info->sco_exist) {
732                         if (bt_link_info->hid_exist &&
733                             bt_link_info->pan_exist &&
734                             bt_link_info->a2dp_exist) {
735                                 if (bt_hs_on) {
736                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
737                                                 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
738                                         BTC_TRACE(trace_buf);
739                                 } else {
740                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
741                                                 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
742                                         BTC_TRACE(trace_buf);
743                                         algorithm =
744                                                 BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
745                                 }
746                         }
747                 }
748         }
749
750         return algorithm;
751 }
752
753 void halbtc8812a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist,
754                 IN u8 dac_swing_lvl)
755 {
756         u8                      h2c_parameter[1] = {0};
757
758         /* There are several type of dacswing */
759         /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
760         h2c_parameter[0] = dac_swing_lvl;
761
762         btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
763 }
764
765 void halbtc8812a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist,
766                                        IN u8 dec_bt_pwr_lvl)
767 {
768         u8      data_len = 4;
769         u8      buf[6] = {0};
770
771         buf[0] = data_len;
772         buf[1] = 0x3;           /* OP_Code */
773         buf[2] = 0x2;           /* OP_Code_Length */
774         if (dec_bt_pwr_lvl)
775                 buf[3] = 0x1;   /* OP_Code_Content */
776         else
777                 buf[3] = 0x0;
778         buf[4] = dec_bt_pwr_lvl;/* pwr_level */
779
780         btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
781                            (void *)&buf[0]);
782 }
783
784 void halbtc8812a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist,
785                                 IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
786 {
787         coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
788
789         if (!force_exec) {
790                 if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
791                         return;
792         }
793         halbtc8812a2ant_set_fw_dec_bt_pwr(btcoexist,
794                                           coex_dm->cur_bt_dec_pwr_lvl);
795
796         coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
797 }
798
799 void halbtc8812a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist,
800                               IN boolean force_exec, IN u8 fw_dac_swing_lvl)
801 {
802         coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
803
804         if (!force_exec) {
805                 if (coex_dm->pre_fw_dac_swing_lvl ==
806                     coex_dm->cur_fw_dac_swing_lvl)
807                         return;
808         }
809
810         halbtc8812a2ant_set_fw_dac_swing_level(btcoexist,
811                                                coex_dm->cur_fw_dac_swing_lvl);
812
813         coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
814 }
815
816 void halbtc8812a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist,
817                 IN boolean rx_rf_shrink_on)
818 {
819         if (rx_rf_shrink_on) {
820                 /* Shrink RF Rx LPF corner */
821                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
822                             "[BTCoex], Shrink RF Rx LPF corner!!\n");
823                 BTC_TRACE(trace_buf);
824                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff,
825                                           0xffffc);
826         } else {
827                 /* Resume RF Rx LPF corner */
828                 /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */
829                 if (btcoexist->initilized) {
830                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
831                                     "[BTCoex], Resume RF Rx LPF corner!!\n");
832                         BTC_TRACE(trace_buf);
833                         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
834                                           0xfffff, coex_dm->bt_rf_0x1e_backup);
835                 }
836         }
837 }
838
839 void halbtc8812a2ant_rf_shrink(IN struct btc_coexist *btcoexist,
840                        IN boolean force_exec, IN boolean rx_rf_shrink_on)
841 {
842         coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
843
844         if (!force_exec) {
845                 if (coex_dm->pre_rf_rx_lpf_shrink ==
846                     coex_dm->cur_rf_rx_lpf_shrink)
847                         return;
848         }
849         halbtc8812a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
850                                                 coex_dm->cur_rf_rx_lpf_shrink);
851
852         coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
853 }
854
855 void halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
856                 *btcoexist, IN boolean low_penalty_ra)
857 {
858         u8      tmp_u1;
859
860         tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd);
861         tmp_u1 |= BIT(0);
862         if (low_penalty_ra) {
863                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
864                             "[BTCoex], Tx rate adaptive, set low penalty!!\n");
865                 BTC_TRACE(trace_buf);
866                 tmp_u1 &= ~BIT(2);
867         } else {
868                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
869                             "[BTCoex], Tx rate adaptive, set normal!!\n");
870                 BTC_TRACE(trace_buf);
871                 tmp_u1 |= BIT(2);
872         }
873
874         btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1);
875 }
876
877 void halbtc8812a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
878                             IN boolean force_exec, IN boolean low_penalty_ra)
879 {
880         return;
881         coex_dm->cur_low_penalty_ra = low_penalty_ra;
882
883         if (!force_exec) {
884                 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
885                         return;
886         }
887         halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
888                         coex_dm->cur_low_penalty_ra);
889
890         coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
891 }
892
893 void halbtc8812a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist,
894                                        IN u32 level)
895 {
896         u8      val = (u8)level;
897
898         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
899                     "[BTCoex], Write SwDacSwing = 0x%x\n", level);
900         BTC_TRACE(trace_buf);
901         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
902 }
903
904 void halbtc8812a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist
905                 *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl)
906 {
907         if (sw_dac_swing_on)
908                 halbtc8812a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
909         else
910                 halbtc8812a2ant_set_dac_swing_reg(btcoexist, 0x18);
911 }
912
913
914 void halbtc8812a2ant_dac_swing(IN struct btc_coexist *btcoexist,
915         IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl)
916 {
917         coex_dm->cur_dac_swing_on = dac_swing_on;
918         coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
919
920         if (!force_exec) {
921                 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
922                     (coex_dm->pre_dac_swing_lvl ==
923                      coex_dm->cur_dac_swing_lvl))
924                         return;
925         }
926         delay_ms(30);
927         halbtc8812a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on,
928                         dac_swing_lvl);
929
930         coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
931         coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
932 }
933
934 void halbtc8812a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist,
935                                       IN boolean adc_back_off)
936 {
937         if (adc_back_off) {
938                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
939                             "[BTCoex], BB BackOff Level On!\n");
940                 BTC_TRACE(trace_buf);
941                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
942         } else {
943                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
944                             "[BTCoex], BB BackOff Level Off!\n");
945                 BTC_TRACE(trace_buf);
946                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
947         }
948 }
949
950 void halbtc8812a2ant_adc_back_off(IN struct btc_coexist *btcoexist,
951                           IN boolean force_exec, IN boolean adc_back_off)
952 {
953         coex_dm->cur_adc_back_off = adc_back_off;
954
955         if (!force_exec) {
956                 if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
957                         return;
958         }
959         halbtc8812a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
960
961         coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
962 }
963
964 void halbtc8812a2ant_set_agc_table(IN struct btc_coexist *btcoexist,
965                                    IN boolean agc_table_en)
966 {
967         u8              rssi_adjust_val = 0;
968
969         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
970         if (agc_table_en) {
971                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
972                             "[BTCoex], Agc Table On!\n");
973                 BTC_TRACE(trace_buf);
974                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
975                                           0x28F4B);
976                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
977                                           0x10AB2);
978                 rssi_adjust_val = 8;
979         } else {
980                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
981                             "[BTCoex], Agc Table Off!\n");
982                 BTC_TRACE(trace_buf);
983                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
984                                           0x2884B);
985                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
986                                           0x104B2);
987         }
988         btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
989
990         /* set rssi_adjust_val for wifi module. */
991         btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
992                            &rssi_adjust_val);
993 }
994
995 void halbtc8812a2ant_agc_table(IN struct btc_coexist *btcoexist,
996                                IN boolean force_exec, IN boolean agc_table_en)
997 {
998         coex_dm->cur_agc_table_en = agc_table_en;
999
1000         if (!force_exec) {
1001                 if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
1002                         return;
1003         }
1004         halbtc8812a2ant_set_agc_table(btcoexist, agc_table_en);
1005
1006         coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
1007 }
1008
1009 void halbtc8812a2ant_set_coex_table(IN struct btc_coexist *btcoexist,
1010             IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
1011 {
1012         btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1013
1014         btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1015
1016         btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1017
1018         btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1019 }
1020
1021 void halbtc8812a2ant_coex_table(IN struct btc_coexist *btcoexist,
1022                         IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
1023                                 IN u32 val0x6c8, IN u8 val0x6cc)
1024 {
1025         coex_dm->cur_val0x6c0 = val0x6c0;
1026         coex_dm->cur_val0x6c4 = val0x6c4;
1027         coex_dm->cur_val0x6c8 = val0x6c8;
1028         coex_dm->cur_val0x6cc = val0x6cc;
1029
1030         if (!force_exec) {
1031                 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1032                     (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1033                     (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1034                     (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1035                         return;
1036         }
1037         halbtc8812a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1038                                        val0x6cc);
1039
1040         coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1041         coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1042         coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1043         coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1044 }
1045
1046 void halbtc8812a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
1047                 IN boolean force_exec, IN u8 type)
1048 {
1049         switch (type) {
1050         case 0:
1051                 halbtc8812a2ant_coex_table(btcoexist, force_exec,
1052                                    0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
1053                 break;
1054         case 1:
1055                 halbtc8812a2ant_coex_table(btcoexist, force_exec,
1056                                    0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
1057                 break;
1058         case 2:
1059                 halbtc8812a2ant_coex_table(btcoexist, force_exec,
1060                                    0x55555555, 0x5ffb5ffb, 0xffffff, 0x3);
1061                 break;
1062         case 3:
1063                 halbtc8812a2ant_coex_table(btcoexist, force_exec,
1064                                    0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
1065                 break;
1066         case 4:
1067                 halbtc8812a2ant_coex_table(btcoexist, force_exec,
1068                                    0xdfffdfff, 0x5fdb5fdb, 0xffffff, 0x3);
1069                 break;
1070         case 5:
1071                 halbtc8812a2ant_coex_table(btcoexist, force_exec,
1072                                    0x5ddd5ddd, 0x5fdb5fdb, 0xffffff, 0x3);
1073                 break;
1074
1075         default:
1076                 break;
1077         }
1078 }
1079
1080 void halbtc8812a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1081                 IN boolean enable)
1082 {
1083         u8      data_len = 3;
1084         u8      buf[5] = {0};
1085
1086         buf[0] = data_len;
1087         buf[1] = 0x1;                   /* OP_Code */
1088         buf[2] = 0x1;                   /* OP_Code_Length */
1089         if (enable)
1090                 buf[3] = 0x1;           /* OP_Code_Content */
1091         else
1092                 buf[3] = 0x0;
1093
1094         btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
1095                            (void *)&buf[0]);
1096 }
1097
1098 void halbtc8812a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1099                                      IN boolean force_exec, IN boolean enable)
1100 {
1101         coex_dm->cur_ignore_wlan_act = enable;
1102
1103         if (!force_exec) {
1104                 if (coex_dm->pre_ignore_wlan_act ==
1105                     coex_dm->cur_ignore_wlan_act)
1106                         return;
1107         }
1108         halbtc8812a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1109
1110         coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1111 }
1112
1113 void halbtc8812a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1114            IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1115 {
1116         u8                      h2c_parameter[5] = {0};
1117         u8                      real_byte1 = byte1, real_byte5 = byte5;
1118         boolean                 ap_enable = false;
1119
1120         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1121                            &ap_enable);
1122
1123         if (ap_enable) {
1124                 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1125                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1126                                     "[BTCoex], FW for 1Ant AP mode\n");
1127                         BTC_TRACE(trace_buf);
1128                         real_byte1 &= ~BIT(4);
1129                         real_byte1 |= BIT(5);
1130
1131                         real_byte5 |= BIT(5);
1132                         real_byte5 &= ~BIT(6);
1133                 }
1134         }
1135
1136         h2c_parameter[0] = real_byte1;
1137         h2c_parameter[1] = byte2;
1138         h2c_parameter[2] = byte3;
1139         h2c_parameter[3] = byte4;
1140         h2c_parameter[4] = real_byte5;
1141
1142
1143         coex_dm->ps_tdma_para[0] = real_byte1;
1144         coex_dm->ps_tdma_para[1] = byte2;
1145         coex_dm->ps_tdma_para[2] = byte3;
1146         coex_dm->ps_tdma_para[3] = byte4;
1147         coex_dm->ps_tdma_para[4] = real_byte5;
1148
1149         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1150 }
1151
1152 void halbtc8812a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
1153                                   IN u8 lps_val, IN u8 rpwm_val)
1154 {
1155         u8      lps = lps_val;
1156         u8      rpwm = rpwm_val;
1157
1158         btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1159         btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1160 }
1161
1162 void halbtc8812a2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
1163                       IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
1164 {
1165         coex_dm->cur_lps = lps_val;
1166         coex_dm->cur_rpwm = rpwm_val;
1167
1168         if (!force_exec) {
1169                 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1170                     (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1171                         return;
1172         }
1173         halbtc8812a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1174
1175         coex_dm->pre_lps = coex_dm->cur_lps;
1176         coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1177 }
1178
1179 void halbtc8812a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist,
1180                            IN boolean shrink_rx_lpf, IN boolean low_penalty_ra,
1181                            IN boolean limited_dig, IN boolean bt_lna_constrain)
1182 {
1183         /*
1184         u32     wifi_bw;
1185
1186         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
1187
1188         if(BTC_WIFI_BW_HT40 != wifi_bw)
1189         {
1190                 if (shrink_rx_lpf)
1191                         shrink_rx_lpf = false;
1192         }
1193         */
1194
1195         halbtc8812a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
1196         /* halbtc8812a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); */
1197 }
1198
1199 void halbtc8812a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist,
1200                            IN boolean agc_table_shift, IN boolean adc_back_off,
1201                            IN boolean sw_dac_swing, IN u32 dac_swing_lvl)
1202 {
1203         /* halbtc8812a2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */
1204         halbtc8812a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off);
1205         halbtc8812a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1206                                   dac_swing_lvl);
1207 }
1208
1209 void halbtc8812a2ant_set_ant_path(IN struct btc_coexist *btcoexist,
1210           IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
1211 {
1212         u8                      u8tmp = 0;
1213
1214         if (init_hwcfg) {
1215                 btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400);
1216                 btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1);
1217         } else if (wifi_off) {
1218
1219         }
1220
1221         /* ext switch setting */
1222         switch (ant_pos_type) {
1223         case BTC_ANT_WIFI_AT_CPL_MAIN:
1224                 break;
1225         case BTC_ANT_WIFI_AT_CPL_AUX:
1226                 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
1227                 u8tmp &= ~BIT(3);
1228                 u8tmp |= BIT(2);
1229                 btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp);
1230                 break;
1231         default:
1232                 break;
1233         }
1234 }
1235
1236 void halbtc8812a2ant_ps_tdma(IN struct btc_coexist *btcoexist,
1237                      IN boolean force_exec, IN boolean turn_on, IN u8 type)
1238 {
1239         coex_dm->cur_ps_tdma_on = turn_on;
1240         coex_dm->cur_ps_tdma = type;
1241
1242         if (!force_exec) {
1243                 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1244                     (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1245                         return;
1246         }
1247         if (turn_on) {
1248                 switch (type) {
1249                 case 1:
1250                 default:
1251                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1252                                                       0x1a, 0x1a, 0xa1, 0x90);
1253                         break;
1254                 case 2:
1255                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1256                                                       0x12, 0x12, 0xa1, 0x90);
1257                         break;
1258                 case 3:
1259                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1260                                                       0x1c, 0x3, 0xb1, 0x90);
1261                         break;
1262                 case 4:
1263                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1264                                                       0x10, 0x3, 0xb1, 0x90);
1265                         break;
1266                 case 5:
1267                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1268                                                       0x1a, 0x1a, 0x21, 0x10);
1269                         break;
1270                 case 6:
1271                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1272                                                       0x12, 0x12, 0x21, 0x10);
1273                         break;
1274                 case 7:
1275                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1276                                                       0x1c, 0x3, 0x21, 0x10);
1277                         break;
1278                 case 8:
1279                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1280                                                       0x10, 0x3, 0x21, 0x10);
1281                         break;
1282                 case 9:
1283                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1284                                                       0x1a, 0x1a, 0xa1, 0x10);
1285                         break;
1286                 case 10:
1287                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1288                                                       0x12, 0x12, 0xa1, 0x10);
1289                         break;
1290                 case 11:
1291                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1292                                                       0x1c, 0x3, 0xb1, 0x10);
1293                         break;
1294                 case 12:
1295                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1296                                                       0x10, 0x3, 0xb1, 0x10);
1297                         break;
1298                 case 13:
1299                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1300                                                       0x1a, 0x1a, 0x21, 0x10);
1301                         break;
1302                 case 14:
1303                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1304                                                       0x12, 0x12, 0x21, 0x10);
1305                         break;
1306                 case 15:
1307                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1308                                                       0x1c, 0x3, 0x21, 0x10);
1309                         break;
1310                 case 16:
1311                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1312                                                       0x10, 0x3, 0x21, 0x10);
1313                         break;
1314                 case 17:
1315                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1316                                                       0x35, 0x3, 0xb1, 0x11);
1317                         break;
1318                 case 18:
1319                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1320                                                       0x5, 0x5, 0xe1, 0x90);
1321                         break;
1322                 case 19:
1323                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1324                                                       0x25, 0x25, 0xe1, 0x90);
1325                         break;
1326                 case 20:
1327                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1328                                                       0x25, 0x25, 0x60, 0x90);
1329                         break;
1330                 case 21:
1331                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1332                                                       0x15, 0x3, 0x70, 0x90);
1333                         break;
1334                 case 22:
1335                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x61,
1336                                                       0x1a, 0x1a, 0x21, 0x10);
1337                         break;
1338                 case 23:
1339                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1340                                                       0x1c, 0x03, 0x31, 0x10);
1341                         break;
1342
1343                 case 71:
1344                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1345                                                       0x1a, 0x1a, 0xe1, 0x90);
1346                         break;
1347
1348                 /* following cases is for wifi rssi low, started from 81 */
1349                 case 81:
1350                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1351                                                       0x3a, 0x3, 0x90, 0x50);
1352                         break;
1353                 case 82:
1354                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1355                                                       0x2b, 0x3, 0x90, 0x50);
1356                         break;
1357                 case 83:
1358                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1359                                                       0x21, 0x3, 0x90, 0x50);
1360                         break;
1361                 case 84:
1362                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1363                                                       0x15, 0x3, 0x90, 0x50);
1364                         break;
1365                 case 85:
1366                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1367                                                       0x1d, 0x1d, 0x80, 0x50);
1368                         break;
1369                 case 86:
1370                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1371                                                       0x15, 0x15, 0x80, 0x50);
1372                         break;
1373                 }
1374         } else {
1375                 /* disable PS tdma */
1376                 switch (type) {
1377                 case 0: /* ANT2PTA, 0x778=0x1 */
1378                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x8,
1379                                                       0x0, 0x0, 0x0, 0x0);
1380                         break;
1381                 case 1: /* ANT2BT, 0x778=3 */
1382                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
1383                                                       0x0, 0x0, 0x8, 0x0);
1384                         delay_ms(5);
1385                         halbtc8812a2ant_set_ant_path(btcoexist,
1386                                      BTC_ANT_WIFI_AT_CPL_AUX, false, false);
1387                         break;
1388                 default:
1389                         halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
1390                                                       0x0, 0x0, 0x0, 0x0);
1391                         break;
1392                 }
1393         }
1394
1395         /* update pre state */
1396         coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1397         coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1398 }
1399
1400 void halbtc8812a2ant_coex_all_off(IN struct btc_coexist *btcoexist)
1401 {
1402         /* fw all off */
1403         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1404         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1405         halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1406
1407         /* sw all off */
1408         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1409         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1410
1411         /* hw all off */
1412         halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1413 }
1414
1415 void halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
1416 {
1417         /* force to reset coex mechanism */
1418
1419         halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1420         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1421         halbtc8812a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0);
1422
1423         halbtc8812a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1424
1425         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1426         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1427 }
1428
1429 void halbtc8812a2ant_ps_tdma_check_for_power_save_state(
1430         IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1431 {
1432         u8      lps_mode = 0x0;
1433
1434         btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1435
1436         if (lps_mode) { /* already under LPS state */
1437                 if (new_ps_state) {
1438                         /* keep state under LPS, do nothing. */
1439                 } else {
1440                         /* will leave LPS state, turn off psTdma first */
1441                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1442                                                 0);
1443                 }
1444         } else {                                        /* NO PS state */
1445                 if (new_ps_state) {
1446                         /* will enter LPS state, turn off psTdma first */
1447                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1448                                                 0);
1449                 } else {
1450                         /* keep state under NO PS state, do nothing. */
1451                 }
1452         }
1453 }
1454
1455 void halbtc8812a2ant_power_save_state(IN struct btc_coexist *btcoexist,
1456                       IN u8 ps_type, IN boolean low_pwr_disable, IN u8 lps_val,
1457                                       IN u8 rpwm_val)
1458 {
1459         switch (ps_type) {
1460         case BTC_PS_WIFI_NATIVE:
1461                 btcoexist->btc_set(btcoexist,
1462                                    BTC_SET_ACT_DISABLE_LOW_POWER,
1463                                    &low_pwr_disable);
1464                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1465                                    NULL);
1466                 break;
1467         case BTC_PS_LPS_ON:
1468                 halbtc8812a2ant_ps_tdma_check_for_power_save_state(
1469                         btcoexist, true);
1470                 halbtc8812a2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1471                                          lps_val, rpwm_val);
1472                 btcoexist->btc_set(btcoexist,
1473                                    BTC_SET_ACT_DISABLE_LOW_POWER,
1474                                    &low_pwr_disable);
1475                 /* power save must executed before psTdma. */
1476                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1477                                    NULL);
1478                 break;
1479         default:
1480                 break;
1481         }
1482 }
1483
1484 void halbtc8812a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1485 {
1486         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
1487                                          0x0, 0x0);
1488
1489         halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1490         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1491         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1492         halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1493
1494         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1495         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1496 }
1497
1498 boolean halbtc8812a2ant_is_common_action(IN struct btc_coexist *btcoexist)
1499 {
1500         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
1501         boolean                         common = false, wifi_connected = false, wifi_busy = false;
1502         boolean                         bt_hs_on = false;
1503
1504         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1505         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1506                            &wifi_connected);
1507         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1508
1509
1510         if (coex_sta->c2h_bt_inquiry_page) {
1511                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1512                             "[BTCoex], BT is under inquiry/page scan !!\n");
1513                 BTC_TRACE(trace_buf);
1514                 halbtc8812a2ant_action_bt_inquiry(btcoexist);
1515                 return true;
1516         }
1517
1518         if (bt_link_info->sco_exist || bt_link_info->hid_exist)
1519                 halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 0, 0, 0);
1520         else
1521                 halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1522
1523         if (!wifi_connected) {
1524                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1525                                                  false, 0x0, 0x0);
1526                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
1527                                            0x8);
1528
1529                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1530                             "[BTCoex], Wifi non-connected idle!!\n");
1531                 BTC_TRACE(trace_buf);
1532
1533                 if ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1534                      coex_dm->bt_status) ||
1535                     (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE ==
1536                      coex_dm->bt_status)) {
1537                         halbtc8812a2ant_coex_table_with_type(btcoexist,
1538                                                              NORMAL_EXEC, 1);
1539                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1540                                                 0);
1541                 } else {
1542                         halbtc8812a2ant_coex_table_with_type(btcoexist,
1543                                                              NORMAL_EXEC, 0);
1544                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1545                                                 1);
1546                 }
1547
1548                 halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1549                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1550
1551                 halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false,
1552                                               false);
1553                 halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false,
1554                                               0x18);
1555
1556                 common = true;
1557         } else {
1558                 if (BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1559                     coex_dm->bt_status) {
1560                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1561                                 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1562                         BTC_TRACE(trace_buf);
1563                         halbtc8812a2ant_power_save_state(btcoexist,
1564                                          BTC_PS_WIFI_NATIVE, false, 0x0, 0x0);
1565                         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1566                                                    false, false, 0x8);
1567
1568                         halbtc8812a2ant_coex_table_with_type(btcoexist,
1569                                                              NORMAL_EXEC, 0);
1570                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1571                                                 0);
1572                         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1573                                                          6);
1574                         halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1575
1576                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
1577                                                       false, false);
1578                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
1579                                                       false, 0x18);
1580
1581                         common = true;
1582                 } else if (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE ==
1583                            coex_dm->bt_status) {
1584                         if (bt_hs_on)
1585                                 return false;
1586
1587                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1588                                 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1589                         BTC_TRACE(trace_buf);
1590                         halbtc8812a2ant_power_save_state(btcoexist,
1591                                          BTC_PS_WIFI_NATIVE, true, 0x0, 0x0);
1592                         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1593                                                    false, false, 0x8);
1594
1595                         halbtc8812a2ant_coex_table_with_type(btcoexist,
1596                                                              NORMAL_EXEC, 0);
1597                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1598                                                 0);
1599                         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1600                                                          6);
1601                         halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1602
1603                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
1604                                                       false, false);
1605                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
1606                                                       false, 0x18);
1607
1608                         common = true;
1609                 } else {
1610                         if (wifi_busy) {
1611                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1612                                         "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1613                                 BTC_TRACE(trace_buf);
1614                                 common = false;
1615                         } else {
1616                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1617                                         "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1618                                 BTC_TRACE(trace_buf);
1619
1620                                 halbtc8812a2ant_power_save_state(btcoexist,
1621                                          BTC_PS_WIFI_NATIVE, true, 0x0, 0x0);
1622
1623                                 halbtc8812a2ant_limited_rx(btcoexist,
1624                                            NORMAL_EXEC, false, false, 0x8);
1625
1626                                 halbtc8812a2ant_coex_table_with_type(btcoexist,
1627                                                              NORMAL_EXEC, 0);
1628
1629                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1630                                                         true, 17);
1631
1632                                 halbtc8812a2ant_fw_dac_swing_lvl(btcoexist,
1633                                                          NORMAL_EXEC, 6);
1634                                 halbtc8812a2ant_dec_bt_pwr(btcoexist,
1635                                                            NORMAL_EXEC, 0);
1636                                 halbtc8812a2ant_sw_mechanism1(btcoexist, false,
1637                                                       false, false, false);
1638                                 halbtc8812a2ant_sw_mechanism2(btcoexist, false,
1639                                                       false, false, 0x18);
1640                                 common = true;
1641                         }
1642                 }
1643         }
1644
1645         return common;
1646 }
1647
1648 void halbtc8812a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist,
1649                 IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval)
1650 {
1651         static s32              up, dn, m, n, wait_count;
1652         s32                     result;   /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1653         u8                      retry_count = 0;
1654
1655         coex_dm->auto_tdma_adjust_low_rssi = false;
1656
1657         if (!coex_dm->auto_tdma_adjust) {
1658                 coex_dm->auto_tdma_adjust = true;
1659                 {
1660                         if (sco_hid) {
1661                                 if (tx_pause) {
1662                                         if (max_interval == 1) {
1663                                                 halbtc8812a2ant_ps_tdma(
1664                                                         btcoexist, NORMAL_EXEC,
1665                                                         true, 13);
1666                                                 coex_dm->ps_tdma_du_adj_type =
1667                                                         13;
1668                                         } else if (max_interval == 2) {
1669                                                 halbtc8812a2ant_ps_tdma(
1670                                                         btcoexist, NORMAL_EXEC,
1671                                                         true, 14);
1672                                                 coex_dm->ps_tdma_du_adj_type =
1673                                                         14;
1674                                         } else if (max_interval == 3) {
1675                                                 halbtc8812a2ant_ps_tdma(
1676                                                         btcoexist, NORMAL_EXEC,
1677                                                         true, 15);
1678                                                 coex_dm->ps_tdma_du_adj_type =
1679                                                         15;
1680                                         } else {
1681                                                 halbtc8812a2ant_ps_tdma(
1682                                                         btcoexist, NORMAL_EXEC,
1683                                                         true, 15);
1684                                                 coex_dm->ps_tdma_du_adj_type =
1685                                                         15;
1686                                         }
1687                                 } else {
1688                                         if (max_interval == 1) {
1689                                                 halbtc8812a2ant_ps_tdma(
1690                                                         btcoexist, NORMAL_EXEC,
1691                                                         true, 9);
1692                                                 coex_dm->ps_tdma_du_adj_type =
1693                                                         9;
1694                                         } else if (max_interval == 2) {
1695                                                 halbtc8812a2ant_ps_tdma(
1696                                                         btcoexist, NORMAL_EXEC,
1697                                                         true, 10);
1698                                                 coex_dm->ps_tdma_du_adj_type =
1699                                                         10;
1700                                         } else if (max_interval == 3) {
1701                                                 halbtc8812a2ant_ps_tdma(
1702                                                         btcoexist, NORMAL_EXEC,
1703                                                         true, 11);
1704                                                 coex_dm->ps_tdma_du_adj_type =
1705                                                         11;
1706                                         } else {
1707                                                 halbtc8812a2ant_ps_tdma(
1708                                                         btcoexist, NORMAL_EXEC,
1709                                                         true, 11);
1710                                                 coex_dm->ps_tdma_du_adj_type =
1711                                                         11;
1712                                         }
1713                                 }
1714                         } else {
1715                                 if (tx_pause) {
1716                                         if (max_interval == 1) {
1717                                                 halbtc8812a2ant_ps_tdma(
1718                                                         btcoexist, NORMAL_EXEC,
1719                                                         true, 5);
1720                                                 coex_dm->ps_tdma_du_adj_type =
1721                                                         5;
1722                                         } else if (max_interval == 2) {
1723                                                 halbtc8812a2ant_ps_tdma(
1724                                                         btcoexist, NORMAL_EXEC,
1725                                                         true, 6);
1726                                                 coex_dm->ps_tdma_du_adj_type =
1727                                                         6;
1728                                         } else if (max_interval == 3) {
1729                                                 halbtc8812a2ant_ps_tdma(
1730                                                         btcoexist, NORMAL_EXEC,
1731                                                         true, 7);
1732                                                 coex_dm->ps_tdma_du_adj_type =
1733                                                         7;
1734                                         } else {
1735                                                 halbtc8812a2ant_ps_tdma(
1736                                                         btcoexist, NORMAL_EXEC,
1737                                                         true, 7);
1738                                                 coex_dm->ps_tdma_du_adj_type =
1739                                                         7;
1740                                         }
1741                                 } else {
1742                                         if (max_interval == 1) {
1743                                                 halbtc8812a2ant_ps_tdma(
1744                                                         btcoexist, NORMAL_EXEC,
1745                                                         true, 1);
1746                                                 coex_dm->ps_tdma_du_adj_type =
1747                                                         1;
1748                                         } else if (max_interval == 2) {
1749                                                 halbtc8812a2ant_ps_tdma(
1750                                                         btcoexist, NORMAL_EXEC,
1751                                                         true, 2);
1752                                                 coex_dm->ps_tdma_du_adj_type =
1753                                                         2;
1754                                         } else if (max_interval == 3) {
1755                                                 halbtc8812a2ant_ps_tdma(
1756                                                         btcoexist, NORMAL_EXEC,
1757                                                         true, 3);
1758                                                 coex_dm->ps_tdma_du_adj_type =
1759                                                         3;
1760                                         } else {
1761                                                 halbtc8812a2ant_ps_tdma(
1762                                                         btcoexist, NORMAL_EXEC,
1763                                                         true, 3);
1764                                                 coex_dm->ps_tdma_du_adj_type =
1765                                                         3;
1766                                         }
1767                                 }
1768                         }
1769                 }
1770                 /* ============ */
1771                 up = 0;
1772                 dn = 0;
1773                 m = 1;
1774                 n = 3;
1775                 result = 0;
1776                 wait_count = 0;
1777         } else {
1778                 /* accquire the BT TRx retry count from BT_Info byte2 */
1779                 retry_count = coex_sta->bt_retry_cnt;
1780                 result = 0;
1781                 wait_count++;
1782
1783                 if (retry_count ==
1784                     0) { /* no retry in the last 2-second duration */
1785                         up++;
1786                         dn--;
1787
1788                         if (dn <= 0)
1789                                 dn = 0;
1790
1791                         if (up >= n) {  /* if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
1792                                 wait_count = 0;
1793                                 n = 3;
1794                                 up = 0;
1795                                 dn = 0;
1796                                 result = 1;
1797                         }
1798                 } else if (retry_count <=
1799                            3) { /* <=3 retry in the last 2-second duration */
1800                         up--;
1801                         dn++;
1802
1803                         if (up <= 0)
1804                                 up = 0;
1805
1806                         if (dn == 2) {  /* if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
1807                                 if (wait_count <= 2)
1808                                         m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */
1809                                 else
1810                                         m = 1;
1811
1812                                 if (m >= 20)  /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
1813                                         m = 20;
1814
1815                                 n = 3 * m;
1816                                 up = 0;
1817                                 dn = 0;
1818                                 wait_count = 0;
1819                                 result = -1;
1820                         }
1821                 } else { /* retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
1822                         if (wait_count == 1)
1823                                 m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */
1824                         else
1825                                 m = 1;
1826
1827                         if (m >= 20)  /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
1828                                 m = 20;
1829
1830                         n = 3 * m;
1831                         up = 0;
1832                         dn = 0;
1833                         wait_count = 0;
1834                         result = -1;
1835                 }
1836
1837                 if (max_interval == 1) {
1838                         if (tx_pause) {
1839                                 if (coex_dm->cur_ps_tdma == 71) {
1840                                         halbtc8812a2ant_ps_tdma(btcoexist,
1841                                                         NORMAL_EXEC, true, 5);
1842                                         coex_dm->ps_tdma_du_adj_type = 5;
1843                                 } else if (coex_dm->cur_ps_tdma == 1) {
1844                                         halbtc8812a2ant_ps_tdma(btcoexist,
1845                                                         NORMAL_EXEC, true, 5);
1846                                         coex_dm->ps_tdma_du_adj_type = 5;
1847                                 } else if (coex_dm->cur_ps_tdma == 2) {
1848                                         halbtc8812a2ant_ps_tdma(btcoexist,
1849                                                         NORMAL_EXEC, true, 6);
1850                                         coex_dm->ps_tdma_du_adj_type = 6;
1851                                 } else if (coex_dm->cur_ps_tdma == 3) {
1852                                         halbtc8812a2ant_ps_tdma(btcoexist,
1853                                                         NORMAL_EXEC, true, 7);
1854                                         coex_dm->ps_tdma_du_adj_type = 7;
1855                                 } else if (coex_dm->cur_ps_tdma == 4) {
1856                                         halbtc8812a2ant_ps_tdma(btcoexist,
1857                                                         NORMAL_EXEC, true, 8);
1858                                         coex_dm->ps_tdma_du_adj_type = 8;
1859                                 }
1860                                 if (coex_dm->cur_ps_tdma == 9) {
1861                                         halbtc8812a2ant_ps_tdma(btcoexist,
1862                                                         NORMAL_EXEC, true, 13);
1863                                         coex_dm->ps_tdma_du_adj_type = 13;
1864                                 } else if (coex_dm->cur_ps_tdma == 10) {
1865                                         halbtc8812a2ant_ps_tdma(btcoexist,
1866                                                         NORMAL_EXEC, true, 14);
1867                                         coex_dm->ps_tdma_du_adj_type = 14;
1868                                 } else if (coex_dm->cur_ps_tdma == 11) {
1869                                         halbtc8812a2ant_ps_tdma(btcoexist,
1870                                                         NORMAL_EXEC, true, 15);
1871                                         coex_dm->ps_tdma_du_adj_type = 15;
1872                                 } else if (coex_dm->cur_ps_tdma == 12) {
1873                                         halbtc8812a2ant_ps_tdma(btcoexist,
1874                                                         NORMAL_EXEC, true, 16);
1875                                         coex_dm->ps_tdma_du_adj_type = 16;
1876                                 }
1877
1878                                 if (result == -1) {
1879                                         if (coex_dm->cur_ps_tdma == 5) {
1880                                                 halbtc8812a2ant_ps_tdma(
1881                                                         btcoexist, NORMAL_EXEC,
1882                                                         true, 6);
1883                                                 coex_dm->ps_tdma_du_adj_type =
1884                                                         6;
1885                                         } else if (coex_dm->cur_ps_tdma == 6) {
1886                                                 halbtc8812a2ant_ps_tdma(
1887                                                         btcoexist, NORMAL_EXEC,
1888                                                         true, 7);
1889                                                 coex_dm->ps_tdma_du_adj_type =
1890                                                         7;
1891                                         } else if (coex_dm->cur_ps_tdma == 7) {
1892                                                 halbtc8812a2ant_ps_tdma(
1893                                                         btcoexist, NORMAL_EXEC,
1894                                                         true, 8);
1895                                                 coex_dm->ps_tdma_du_adj_type =
1896                                                         8;
1897                                         } else if (coex_dm->cur_ps_tdma == 13) {
1898                                                 halbtc8812a2ant_ps_tdma(
1899                                                         btcoexist, NORMAL_EXEC,
1900                                                         true, 14);
1901                                                 coex_dm->ps_tdma_du_adj_type =
1902                                                         14;
1903                                         } else if (coex_dm->cur_ps_tdma == 14) {
1904                                                 halbtc8812a2ant_ps_tdma(
1905                                                         btcoexist, NORMAL_EXEC,
1906                                                         true, 15);
1907                                                 coex_dm->ps_tdma_du_adj_type =
1908                                                         15;
1909                                         } else if (coex_dm->cur_ps_tdma == 15) {
1910                                                 halbtc8812a2ant_ps_tdma(
1911                                                         btcoexist, NORMAL_EXEC,
1912                                                         true, 16);
1913                                                 coex_dm->ps_tdma_du_adj_type =
1914                                                         16;
1915                                         }
1916                                 } else if (result == 1) {
1917                                         if (coex_dm->cur_ps_tdma == 8) {
1918                                                 halbtc8812a2ant_ps_tdma(
1919                                                         btcoexist, NORMAL_EXEC,
1920                                                         true, 7);
1921                                                 coex_dm->ps_tdma_du_adj_type =
1922                                                         7;
1923                                         } else if (coex_dm->cur_ps_tdma == 7) {
1924                                                 halbtc8812a2ant_ps_tdma(
1925                                                         btcoexist, NORMAL_EXEC,
1926                                                         true, 6);
1927                                                 coex_dm->ps_tdma_du_adj_type =
1928                                                         6;
1929                                         } else if (coex_dm->cur_ps_tdma == 6) {
1930                                                 halbtc8812a2ant_ps_tdma(
1931                                                         btcoexist, NORMAL_EXEC,
1932                                                         true, 5);
1933                                                 coex_dm->ps_tdma_du_adj_type =
1934                                                         5;
1935                                         } else if (coex_dm->cur_ps_tdma == 16) {
1936                                                 halbtc8812a2ant_ps_tdma(
1937                                                         btcoexist, NORMAL_EXEC,
1938                                                         true, 15);
1939                                                 coex_dm->ps_tdma_du_adj_type =
1940                                                         15;
1941                                         } else if (coex_dm->cur_ps_tdma == 15) {
1942                                                 halbtc8812a2ant_ps_tdma(
1943                                                         btcoexist, NORMAL_EXEC,
1944                                                         true, 14);
1945                                                 coex_dm->ps_tdma_du_adj_type =
1946                                                         14;
1947                                         } else if (coex_dm->cur_ps_tdma == 14) {
1948                                                 halbtc8812a2ant_ps_tdma(
1949                                                         btcoexist, NORMAL_EXEC,
1950                                                         true, 13);
1951                                                 coex_dm->ps_tdma_du_adj_type =
1952                                                         13;
1953                                         }
1954                                 }
1955                         } else {
1956                                 if (coex_dm->cur_ps_tdma == 5) {
1957                                         halbtc8812a2ant_ps_tdma(btcoexist,
1958                                                         NORMAL_EXEC, true, 71);
1959                                         coex_dm->ps_tdma_du_adj_type = 71;
1960                                 } else if (coex_dm->cur_ps_tdma == 6) {
1961                                         halbtc8812a2ant_ps_tdma(btcoexist,
1962                                                         NORMAL_EXEC, true, 2);
1963                                         coex_dm->ps_tdma_du_adj_type = 2;
1964                                 } else if (coex_dm->cur_ps_tdma == 7) {
1965                                         halbtc8812a2ant_ps_tdma(btcoexist,
1966                                                         NORMAL_EXEC, true, 3);
1967                                         coex_dm->ps_tdma_du_adj_type = 3;
1968                                 } else if (coex_dm->cur_ps_tdma == 8) {
1969                                         halbtc8812a2ant_ps_tdma(btcoexist,
1970                                                         NORMAL_EXEC, true, 4);
1971                                         coex_dm->ps_tdma_du_adj_type = 4;
1972                                 }
1973                                 if (coex_dm->cur_ps_tdma == 13) {
1974                                         halbtc8812a2ant_ps_tdma(btcoexist,
1975                                                         NORMAL_EXEC, true, 9);
1976                                         coex_dm->ps_tdma_du_adj_type = 9;
1977                                 } else if (coex_dm->cur_ps_tdma == 14) {
1978                                         halbtc8812a2ant_ps_tdma(btcoexist,
1979                                                         NORMAL_EXEC, true, 10);
1980                                         coex_dm->ps_tdma_du_adj_type = 10;
1981                                 } else if (coex_dm->cur_ps_tdma == 15) {
1982                                         halbtc8812a2ant_ps_tdma(btcoexist,
1983                                                         NORMAL_EXEC, true, 11);
1984                                         coex_dm->ps_tdma_du_adj_type = 11;
1985                                 } else if (coex_dm->cur_ps_tdma == 16) {
1986                                         halbtc8812a2ant_ps_tdma(btcoexist,
1987                                                         NORMAL_EXEC, true, 12);
1988                                         coex_dm->ps_tdma_du_adj_type = 12;
1989                                 }
1990
1991                                 if (result == -1) {
1992                                         if (coex_dm->cur_ps_tdma == 71) {
1993                                                 halbtc8812a2ant_ps_tdma(
1994                                                         btcoexist, NORMAL_EXEC,
1995                                                         true, 1);
1996                                                 coex_dm->ps_tdma_du_adj_type =
1997                                                         1;
1998                                         } else if (coex_dm->cur_ps_tdma == 1) {
1999                                                 halbtc8812a2ant_ps_tdma(
2000                                                         btcoexist, NORMAL_EXEC,
2001                                                         true, 2);
2002                                                 coex_dm->ps_tdma_du_adj_type =
2003                                                         2;
2004                                         } else if (coex_dm->cur_ps_tdma == 2) {
2005                                                 halbtc8812a2ant_ps_tdma(
2006                                                         btcoexist, NORMAL_EXEC,
2007                                                         true, 3);
2008                                                 coex_dm->ps_tdma_du_adj_type =
2009                                                         3;
2010                                         } else if (coex_dm->cur_ps_tdma == 3) {
2011                                                 halbtc8812a2ant_ps_tdma(
2012                                                         btcoexist, NORMAL_EXEC,
2013                                                         true, 4);
2014                                                 coex_dm->ps_tdma_du_adj_type =
2015                                                         4;
2016                                         } else if (coex_dm->cur_ps_tdma == 9) {
2017                                                 halbtc8812a2ant_ps_tdma(
2018                                                         btcoexist, NORMAL_EXEC,
2019                                                         true, 10);
2020                                                 coex_dm->ps_tdma_du_adj_type =
2021                                                         10;
2022                                         } else if (coex_dm->cur_ps_tdma == 10) {
2023                                                 halbtc8812a2ant_ps_tdma(
2024                                                         btcoexist, NORMAL_EXEC,
2025                                                         true, 11);
2026                                                 coex_dm->ps_tdma_du_adj_type =
2027                                                         11;
2028                                         } else if (coex_dm->cur_ps_tdma == 11) {
2029                                                 halbtc8812a2ant_ps_tdma(
2030                                                         btcoexist, NORMAL_EXEC,
2031                                                         true, 12);
2032                                                 coex_dm->ps_tdma_du_adj_type =
2033                                                         12;
2034                                         }
2035                                 } else if (result == 1) {
2036                                         if (coex_dm->cur_ps_tdma == 4) {
2037                                                 halbtc8812a2ant_ps_tdma(
2038                                                         btcoexist, NORMAL_EXEC,
2039                                                         true, 3);
2040                                                 coex_dm->ps_tdma_du_adj_type =
2041                                                         3;
2042                                         } else if (coex_dm->cur_ps_tdma == 3) {
2043                                                 halbtc8812a2ant_ps_tdma(
2044                                                         btcoexist, NORMAL_EXEC,
2045                                                         true, 2);
2046                                                 coex_dm->ps_tdma_du_adj_type =
2047                                                         2;
2048                                         } else if (coex_dm->cur_ps_tdma == 2) {
2049                                                 halbtc8812a2ant_ps_tdma(
2050                                                         btcoexist, NORMAL_EXEC,
2051                                                         true, 1);
2052                                                 coex_dm->ps_tdma_du_adj_type =
2053                                                         1;
2054                                         } else if (coex_dm->cur_ps_tdma == 1) {
2055                                                 halbtc8812a2ant_ps_tdma(
2056                                                         btcoexist, NORMAL_EXEC,
2057                                                         true, 71);
2058                                                 coex_dm->ps_tdma_du_adj_type =
2059                                                         71;
2060                                         } else if (coex_dm->cur_ps_tdma == 12) {
2061                                                 halbtc8812a2ant_ps_tdma(
2062                                                         btcoexist, NORMAL_EXEC,
2063                                                         true, 11);
2064                                                 coex_dm->ps_tdma_du_adj_type =
2065                                                         11;
2066                                         } else if (coex_dm->cur_ps_tdma == 11) {
2067                                                 halbtc8812a2ant_ps_tdma(
2068                                                         btcoexist, NORMAL_EXEC,
2069                                                         true, 10);
2070                                                 coex_dm->ps_tdma_du_adj_type =
2071                                                         10;
2072                                         } else if (coex_dm->cur_ps_tdma == 10) {
2073                                                 halbtc8812a2ant_ps_tdma(
2074                                                         btcoexist, NORMAL_EXEC,
2075                                                         true, 9);
2076                                                 coex_dm->ps_tdma_du_adj_type =
2077                                                         9;
2078                                         }
2079                                 }
2080                         }
2081                 } else if (max_interval == 2) {
2082                         if (tx_pause) {
2083                                 if (coex_dm->cur_ps_tdma == 1) {
2084                                         halbtc8812a2ant_ps_tdma(btcoexist,
2085                                                         NORMAL_EXEC, true, 6);
2086                                         coex_dm->ps_tdma_du_adj_type = 6;
2087                                 } else if (coex_dm->cur_ps_tdma == 2) {
2088                                         halbtc8812a2ant_ps_tdma(btcoexist,
2089                                                         NORMAL_EXEC, true, 6);
2090                                         coex_dm->ps_tdma_du_adj_type = 6;
2091                                 } else if (coex_dm->cur_ps_tdma == 3) {
2092                                         halbtc8812a2ant_ps_tdma(btcoexist,
2093                                                         NORMAL_EXEC, true, 7);
2094                                         coex_dm->ps_tdma_du_adj_type = 7;
2095                                 } else if (coex_dm->cur_ps_tdma == 4) {
2096                                         halbtc8812a2ant_ps_tdma(btcoexist,
2097                                                         NORMAL_EXEC, true, 8);
2098                                         coex_dm->ps_tdma_du_adj_type = 8;
2099                                 }
2100                                 if (coex_dm->cur_ps_tdma == 9) {
2101                                         halbtc8812a2ant_ps_tdma(btcoexist,
2102                                                         NORMAL_EXEC, true, 14);
2103                                         coex_dm->ps_tdma_du_adj_type = 14;
2104                                 } else if (coex_dm->cur_ps_tdma == 10) {
2105                                         halbtc8812a2ant_ps_tdma(btcoexist,
2106                                                         NORMAL_EXEC, true, 14);
2107                                         coex_dm->ps_tdma_du_adj_type = 14;
2108                                 } else if (coex_dm->cur_ps_tdma == 11) {
2109                                         halbtc8812a2ant_ps_tdma(btcoexist,
2110                                                         NORMAL_EXEC, true, 15);
2111                                         coex_dm->ps_tdma_du_adj_type = 15;
2112                                 } else if (coex_dm->cur_ps_tdma == 12) {
2113                                         halbtc8812a2ant_ps_tdma(btcoexist,
2114                                                         NORMAL_EXEC, true, 16);
2115                                         coex_dm->ps_tdma_du_adj_type = 16;
2116                                 }
2117                                 if (result == -1) {
2118                                         if (coex_dm->cur_ps_tdma == 5) {
2119                                                 halbtc8812a2ant_ps_tdma(
2120                                                         btcoexist, NORMAL_EXEC,
2121                                                         true, 6);
2122                                                 coex_dm->ps_tdma_du_adj_type =
2123                                                         6;
2124                                         } else if (coex_dm->cur_ps_tdma == 6) {
2125                                                 halbtc8812a2ant_ps_tdma(
2126                                                         btcoexist, NORMAL_EXEC,
2127                                                         true, 7);
2128                                                 coex_dm->ps_tdma_du_adj_type =
2129                                                         7;
2130                                         } else if (coex_dm->cur_ps_tdma == 7) {
2131                                                 halbtc8812a2ant_ps_tdma(
2132                                                         btcoexist, NORMAL_EXEC,
2133                                                         true, 8);
2134                                                 coex_dm->ps_tdma_du_adj_type =
2135                                                         8;
2136                                         } else if (coex_dm->cur_ps_tdma == 13) {
2137                                                 halbtc8812a2ant_ps_tdma(
2138                                                         btcoexist, NORMAL_EXEC,
2139                                                         true, 14);
2140                                                 coex_dm->ps_tdma_du_adj_type =
2141                                                         14;
2142                                         } else if (coex_dm->cur_ps_tdma == 14) {
2143                                                 halbtc8812a2ant_ps_tdma(
2144                                                         btcoexist, NORMAL_EXEC,
2145                                                         true, 15);
2146                                                 coex_dm->ps_tdma_du_adj_type =
2147                                                         15;
2148                                         } else if (coex_dm->cur_ps_tdma == 15) {
2149                                                 halbtc8812a2ant_ps_tdma(
2150                                                         btcoexist, NORMAL_EXEC,
2151                                                         true, 16);
2152                                                 coex_dm->ps_tdma_du_adj_type =
2153                                                         16;
2154                                         }
2155                                 } else if (result == 1) {
2156                                         if (coex_dm->cur_ps_tdma == 8) {
2157                                                 halbtc8812a2ant_ps_tdma(
2158                                                         btcoexist, NORMAL_EXEC,
2159                                                         true, 7);
2160                                                 coex_dm->ps_tdma_du_adj_type =
2161                                                         7;
2162                                         } else if (coex_dm->cur_ps_tdma == 7) {
2163                                                 halbtc8812a2ant_ps_tdma(
2164                                                         btcoexist, NORMAL_EXEC,
2165                                                         true, 6);
2166                                                 coex_dm->ps_tdma_du_adj_type =
2167                                                         6;
2168                                         } else if (coex_dm->cur_ps_tdma == 6) {
2169                                                 halbtc8812a2ant_ps_tdma(
2170                                                         btcoexist, NORMAL_EXEC,
2171                                                         true, 6);
2172                                                 coex_dm->ps_tdma_du_adj_type =
2173                                                         6;
2174                                         } else if (coex_dm->cur_ps_tdma == 16) {
2175                                                 halbtc8812a2ant_ps_tdma(
2176                                                         btcoexist, NORMAL_EXEC,
2177                                                         true, 15);
2178                                                 coex_dm->ps_tdma_du_adj_type =
2179                                                         15;
2180                                         } else if (coex_dm->cur_ps_tdma == 15) {
2181                                                 halbtc8812a2ant_ps_tdma(
2182                                                         btcoexist, NORMAL_EXEC,
2183                                                         true, 14);
2184                                                 coex_dm->ps_tdma_du_adj_type =
2185                                                         14;
2186                                         } else if (coex_dm->cur_ps_tdma == 14) {
2187                                                 halbtc8812a2ant_ps_tdma(
2188                                                         btcoexist, NORMAL_EXEC,
2189                                                         true, 14);
2190                                                 coex_dm->ps_tdma_du_adj_type =
2191                                                         14;
2192                                         }
2193                                 }
2194                         } else {
2195                                 if (coex_dm->cur_ps_tdma == 5) {
2196                                         halbtc8812a2ant_ps_tdma(btcoexist,
2197                                                         NORMAL_EXEC, true, 2);
2198                                         coex_dm->ps_tdma_du_adj_type = 2;
2199                                 } else if (coex_dm->cur_ps_tdma == 6) {
2200                                         halbtc8812a2ant_ps_tdma(btcoexist,
2201                                                         NORMAL_EXEC, true, 2);
2202                                         coex_dm->ps_tdma_du_adj_type = 2;
2203                                 } else if (coex_dm->cur_ps_tdma == 7) {
2204                                         halbtc8812a2ant_ps_tdma(btcoexist,
2205                                                         NORMAL_EXEC, true, 3);
2206                                         coex_dm->ps_tdma_du_adj_type = 3;
2207                                 } else if (coex_dm->cur_ps_tdma == 8) {
2208                                         halbtc8812a2ant_ps_tdma(btcoexist,
2209                                                         NORMAL_EXEC, true, 4);
2210                                         coex_dm->ps_tdma_du_adj_type = 4;
2211                                 }
2212                                 if (coex_dm->cur_ps_tdma == 13) {
2213                                         halbtc8812a2ant_ps_tdma(btcoexist,
2214                                                         NORMAL_EXEC, true, 10);
2215                                         coex_dm->ps_tdma_du_adj_type = 10;
2216                                 } else if (coex_dm->cur_ps_tdma == 14) {
2217                                         halbtc8812a2ant_ps_tdma(btcoexist,
2218                                                         NORMAL_EXEC, true, 10);
2219                                         coex_dm->ps_tdma_du_adj_type = 10;
2220                                 } else if (coex_dm->cur_ps_tdma == 15) {
2221                                         halbtc8812a2ant_ps_tdma(btcoexist,
2222                                                         NORMAL_EXEC, true, 11);
2223                                         coex_dm->ps_tdma_du_adj_type = 11;
2224                                 } else if (coex_dm->cur_ps_tdma == 16) {
2225                                         halbtc8812a2ant_ps_tdma(btcoexist,
2226                                                         NORMAL_EXEC, true, 12);
2227                                         coex_dm->ps_tdma_du_adj_type = 12;
2228                                 }
2229                                 if (result == -1) {
2230                                         if (coex_dm->cur_ps_tdma == 1) {
2231                                                 halbtc8812a2ant_ps_tdma(
2232                                                         btcoexist, NORMAL_EXEC,
2233                                                         true, 2);
2234                                                 coex_dm->ps_tdma_du_adj_type =
2235                                                         2;
2236                                         } else if (coex_dm->cur_ps_tdma == 2) {
2237                                                 halbtc8812a2ant_ps_tdma(
2238                                                         btcoexist, NORMAL_EXEC,
2239                                                         true, 3);
2240                                                 coex_dm->ps_tdma_du_adj_type =
2241                                                         3;
2242                                         } else if (coex_dm->cur_ps_tdma == 3) {
2243                                                 halbtc8812a2ant_ps_tdma(
2244                                                         btcoexist, NORMAL_EXEC,
2245                                                         true, 4);
2246                                                 coex_dm->ps_tdma_du_adj_type =
2247                                                         4;
2248                                         } else if (coex_dm->cur_ps_tdma == 9) {
2249                                                 halbtc8812a2ant_ps_tdma(
2250                                                         btcoexist, NORMAL_EXEC,
2251                                                         true, 10);
2252                                                 coex_dm->ps_tdma_du_adj_type =
2253                                                         10;
2254                                         } else if (coex_dm->cur_ps_tdma == 10) {
2255                                                 halbtc8812a2ant_ps_tdma(
2256                                                         btcoexist, NORMAL_EXEC,
2257                                                         true, 11);
2258                                                 coex_dm->ps_tdma_du_adj_type =
2259                                                         11;
2260                                         } else if (coex_dm->cur_ps_tdma == 11) {
2261                                                 halbtc8812a2ant_ps_tdma(
2262                                                         btcoexist, NORMAL_EXEC,
2263                                                         true, 12);
2264                                                 coex_dm->ps_tdma_du_adj_type =
2265                                                         12;
2266                                         }
2267                                 } else if (result == 1) {
2268                                         if (coex_dm->cur_ps_tdma == 4) {
2269                                                 halbtc8812a2ant_ps_tdma(
2270                                                         btcoexist, NORMAL_EXEC,
2271                                                         true, 3);
2272                                                 coex_dm->ps_tdma_du_adj_type =
2273                                                         3;
2274                                         } else if (coex_dm->cur_ps_tdma == 3) {
2275                                                 halbtc8812a2ant_ps_tdma(
2276                                                         btcoexist, NORMAL_EXEC,
2277                                                         true, 2);
2278                                                 coex_dm->ps_tdma_du_adj_type =
2279                                                         2;
2280                                         } else if (coex_dm->cur_ps_tdma == 2) {
2281                                                 halbtc8812a2ant_ps_tdma(
2282                                                         btcoexist, NORMAL_EXEC,
2283                                                         true, 2);
2284                                                 coex_dm->ps_tdma_du_adj_type =
2285                                                         2;
2286                                         } else if (coex_dm->cur_ps_tdma == 12) {
2287                                                 halbtc8812a2ant_ps_tdma(
2288                                                         btcoexist, NORMAL_EXEC,
2289                                                         true, 11);
2290                                                 coex_dm->ps_tdma_du_adj_type =
2291                                                         11;
2292                                         } else if (coex_dm->cur_ps_tdma == 11) {
2293                                                 halbtc8812a2ant_ps_tdma(
2294                                                         btcoexist, NORMAL_EXEC,
2295                                                         true, 10);
2296                                                 coex_dm->ps_tdma_du_adj_type =
2297                                                         10;
2298                                         } else if (coex_dm->cur_ps_tdma == 10) {
2299                                                 halbtc8812a2ant_ps_tdma(
2300                                                         btcoexist, NORMAL_EXEC,
2301                                                         true, 10);
2302                                                 coex_dm->ps_tdma_du_adj_type =
2303                                                         10;
2304                                         }
2305                                 }
2306                         }
2307                 } else if (max_interval == 3) {
2308                         if (tx_pause) {
2309                                 if (coex_dm->cur_ps_tdma == 1) {
2310                                         halbtc8812a2ant_ps_tdma(btcoexist,
2311                                                         NORMAL_EXEC, true, 7);
2312                                         coex_dm->ps_tdma_du_adj_type = 7;
2313                                 } else if (coex_dm->cur_ps_tdma == 2) {
2314                                         halbtc8812a2ant_ps_tdma(btcoexist,
2315                                                         NORMAL_EXEC, true, 7);
2316                                         coex_dm->ps_tdma_du_adj_type = 7;
2317                                 } else if (coex_dm->cur_ps_tdma == 3) {
2318                                         halbtc8812a2ant_ps_tdma(btcoexist,
2319                                                         NORMAL_EXEC, true, 7);
2320                                         coex_dm->ps_tdma_du_adj_type = 7;
2321                                 } else if (coex_dm->cur_ps_tdma == 4) {
2322                                         halbtc8812a2ant_ps_tdma(btcoexist,
2323                                                         NORMAL_EXEC, true, 8);
2324                                         coex_dm->ps_tdma_du_adj_type = 8;
2325                                 }
2326                                 if (coex_dm->cur_ps_tdma == 9) {
2327                                         halbtc8812a2ant_ps_tdma(btcoexist,
2328                                                         NORMAL_EXEC, true, 15);
2329                                         coex_dm->ps_tdma_du_adj_type = 15;
2330                                 } else if (coex_dm->cur_ps_tdma == 10) {
2331                                         halbtc8812a2ant_ps_tdma(btcoexist,
2332                                                         NORMAL_EXEC, true, 15);
2333                                         coex_dm->ps_tdma_du_adj_type = 15;
2334                                 } else if (coex_dm->cur_ps_tdma == 11) {
2335                                         halbtc8812a2ant_ps_tdma(btcoexist,
2336                                                         NORMAL_EXEC, true, 15);
2337                                         coex_dm->ps_tdma_du_adj_type = 15;
2338                                 } else if (coex_dm->cur_ps_tdma == 12) {
2339                                         halbtc8812a2ant_ps_tdma(btcoexist,
2340                                                         NORMAL_EXEC, true, 16);
2341                                         coex_dm->ps_tdma_du_adj_type = 16;
2342                                 }
2343                                 if (result == -1) {
2344                                         if (coex_dm->cur_ps_tdma == 5) {
2345                                                 halbtc8812a2ant_ps_tdma(
2346                                                         btcoexist, NORMAL_EXEC,
2347                                                         true, 7);
2348                                                 coex_dm->ps_tdma_du_adj_type =
2349                                                         7;
2350                                         } else if (coex_dm->cur_ps_tdma == 6) {
2351                                                 halbtc8812a2ant_ps_tdma(
2352                                                         btcoexist, NORMAL_EXEC,
2353                                                         true, 7);
2354                                                 coex_dm->ps_tdma_du_adj_type =
2355                                                         7;
2356                                         } else if (coex_dm->cur_ps_tdma == 7) {
2357                                                 halbtc8812a2ant_ps_tdma(
2358                                                         btcoexist, NORMAL_EXEC,
2359                                                         true, 8);
2360                                                 coex_dm->ps_tdma_du_adj_type =
2361                                                         8;
2362                                         } else if (coex_dm->cur_ps_tdma == 13) {
2363                                                 halbtc8812a2ant_ps_tdma(
2364                                                         btcoexist, NORMAL_EXEC,
2365                                                         true, 15);
2366                                                 coex_dm->ps_tdma_du_adj_type =
2367                                                         15;
2368                                         } else if (coex_dm->cur_ps_tdma == 14) {
2369                                                 halbtc8812a2ant_ps_tdma(
2370                                                         btcoexist, NORMAL_EXEC,
2371                                                         true, 15);
2372                                                 coex_dm->ps_tdma_du_adj_type =
2373                                                         15;
2374                                         } else if (coex_dm->cur_ps_tdma == 15) {
2375                                                 halbtc8812a2ant_ps_tdma(
2376                                                         btcoexist, NORMAL_EXEC,
2377                                                         true, 16);
2378                                                 coex_dm->ps_tdma_du_adj_type =
2379                                                         16;
2380                                         }
2381                                 } else if (result == 1) {
2382                                         if (coex_dm->cur_ps_tdma == 8) {
2383                                                 halbtc8812a2ant_ps_tdma(
2384                                                         btcoexist, NORMAL_EXEC,
2385                                                         true, 7);
2386                                                 coex_dm->ps_tdma_du_adj_type =
2387                                                         7;
2388                                         } else if (coex_dm->cur_ps_tdma == 7) {
2389                                                 halbtc8812a2ant_ps_tdma(
2390                                                         btcoexist, NORMAL_EXEC,
2391                                                         true, 7);
2392                                                 coex_dm->ps_tdma_du_adj_type =
2393                                                         7;
2394                                         } else if (coex_dm->cur_ps_tdma == 6) {
2395                                                 halbtc8812a2ant_ps_tdma(
2396                                                         btcoexist, NORMAL_EXEC,
2397                                                         true, 7);
2398                                                 coex_dm->ps_tdma_du_adj_type =
2399                                                         7;
2400                                         } else if (coex_dm->cur_ps_tdma == 16) {
2401                                                 halbtc8812a2ant_ps_tdma(
2402                                                         btcoexist, NORMAL_EXEC,
2403                                                         true, 15);
2404                                                 coex_dm->ps_tdma_du_adj_type =
2405                                                         15;
2406                                         } else if (coex_dm->cur_ps_tdma == 15) {
2407                                                 halbtc8812a2ant_ps_tdma(
2408                                                         btcoexist, NORMAL_EXEC,
2409                                                         true, 15);
2410                                                 coex_dm->ps_tdma_du_adj_type =
2411                                                         15;
2412                                         } else if (coex_dm->cur_ps_tdma == 14) {
2413                                                 halbtc8812a2ant_ps_tdma(
2414                                                         btcoexist, NORMAL_EXEC,
2415                                                         true, 15);
2416                                                 coex_dm->ps_tdma_du_adj_type =
2417                                                         15;
2418                                         }
2419                                 }
2420                         } else {
2421                                 if (coex_dm->cur_ps_tdma == 5) {
2422                                         halbtc8812a2ant_ps_tdma(btcoexist,
2423                                                         NORMAL_EXEC, true, 3);
2424                                         coex_dm->ps_tdma_du_adj_type = 3;
2425                                 } else if (coex_dm->cur_ps_tdma == 6) {
2426                                         halbtc8812a2ant_ps_tdma(btcoexist,
2427                                                         NORMAL_EXEC, true, 3);
2428                                         coex_dm->ps_tdma_du_adj_type = 3;
2429                                 } else if (coex_dm->cur_ps_tdma == 7) {
2430                                         halbtc8812a2ant_ps_tdma(btcoexist,
2431                                                         NORMAL_EXEC, true, 3);
2432                                         coex_dm->ps_tdma_du_adj_type = 3;
2433                                 } else if (coex_dm->cur_ps_tdma == 8) {
2434                                         halbtc8812a2ant_ps_tdma(btcoexist,
2435                                                         NORMAL_EXEC, true, 4);
2436                                         coex_dm->ps_tdma_du_adj_type = 4;
2437                                 }
2438                                 if (coex_dm->cur_ps_tdma == 13) {
2439                                         halbtc8812a2ant_ps_tdma(btcoexist,
2440                                                         NORMAL_EXEC, true, 11);
2441                                         coex_dm->ps_tdma_du_adj_type = 11;
2442                                 } else if (coex_dm->cur_ps_tdma == 14) {
2443                                         halbtc8812a2ant_ps_tdma(btcoexist,
2444                                                         NORMAL_EXEC, true, 11);
2445                                         coex_dm->ps_tdma_du_adj_type = 11;
2446                                 } else if (coex_dm->cur_ps_tdma == 15) {
2447                                         halbtc8812a2ant_ps_tdma(btcoexist,
2448                                                         NORMAL_EXEC, true, 11);
2449                                         coex_dm->ps_tdma_du_adj_type = 11;
2450                                 } else if (coex_dm->cur_ps_tdma == 16) {
2451                                         halbtc8812a2ant_ps_tdma(btcoexist,
2452                                                         NORMAL_EXEC, true, 12);
2453                                         coex_dm->ps_tdma_du_adj_type = 12;
2454                                 }
2455                                 if (result == -1) {
2456                                         if (coex_dm->cur_ps_tdma == 1) {
2457                                                 halbtc8812a2ant_ps_tdma(
2458                                                         btcoexist, NORMAL_EXEC,
2459                                                         true, 3);
2460                                                 coex_dm->ps_tdma_du_adj_type =
2461                                                         3;
2462                                         } else if (coex_dm->cur_ps_tdma == 2) {
2463                                                 halbtc8812a2ant_ps_tdma(
2464                                                         btcoexist, NORMAL_EXEC,
2465                                                         true, 3);
2466                                                 coex_dm->ps_tdma_du_adj_type =
2467                                                         3;
2468                                         } else if (coex_dm->cur_ps_tdma == 3) {
2469                                                 halbtc8812a2ant_ps_tdma(
2470                                                         btcoexist, NORMAL_EXEC,
2471                                                         true, 4);
2472                                                 coex_dm->ps_tdma_du_adj_type =
2473                                                         4;
2474                                         } else if (coex_dm->cur_ps_tdma == 9) {
2475                                                 halbtc8812a2ant_ps_tdma(
2476                                                         btcoexist, NORMAL_EXEC,
2477                                                         true, 11);
2478                                                 coex_dm->ps_tdma_du_adj_type =
2479                                                         11;
2480                                         } else if (coex_dm->cur_ps_tdma == 10) {
2481                                                 halbtc8812a2ant_ps_tdma(
2482                                                         btcoexist, NORMAL_EXEC,
2483                                                         true, 11);
2484                                                 coex_dm->ps_tdma_du_adj_type =
2485                                                         11;
2486                                         } else if (coex_dm->cur_ps_tdma == 11) {
2487                                                 halbtc8812a2ant_ps_tdma(
2488                                                         btcoexist, NORMAL_EXEC,
2489                                                         true, 12);
2490                                                 coex_dm->ps_tdma_du_adj_type =
2491                                                         12;
2492                                         }
2493                                 } else if (result == 1) {
2494                                         if (coex_dm->cur_ps_tdma == 4) {
2495                                                 halbtc8812a2ant_ps_tdma(
2496                                                         btcoexist, NORMAL_EXEC,
2497                                                         true, 3);
2498                                                 coex_dm->ps_tdma_du_adj_type =
2499                                                         3;
2500                                         } else if (coex_dm->cur_ps_tdma == 3) {
2501                                                 halbtc8812a2ant_ps_tdma(
2502                                                         btcoexist, NORMAL_EXEC,
2503                                                         true, 3);
2504                                                 coex_dm->ps_tdma_du_adj_type =
2505                                                         3;
2506                                         } else if (coex_dm->cur_ps_tdma == 2) {
2507                                                 halbtc8812a2ant_ps_tdma(
2508                                                         btcoexist, NORMAL_EXEC,
2509                                                         true, 3);
2510                                                 coex_dm->ps_tdma_du_adj_type =
2511                                                         3;
2512                                         } else if (coex_dm->cur_ps_tdma == 12) {
2513                                                 halbtc8812a2ant_ps_tdma(
2514                                                         btcoexist, NORMAL_EXEC,
2515                                                         true, 11);
2516                                                 coex_dm->ps_tdma_du_adj_type =
2517                                                         11;
2518                                         } else if (coex_dm->cur_ps_tdma == 11) {
2519                                                 halbtc8812a2ant_ps_tdma(
2520                                                         btcoexist, NORMAL_EXEC,
2521                                                         true, 11);
2522                                                 coex_dm->ps_tdma_du_adj_type =
2523                                                         11;
2524                                         } else if (coex_dm->cur_ps_tdma == 10) {
2525                                                 halbtc8812a2ant_ps_tdma(
2526                                                         btcoexist, NORMAL_EXEC,
2527                                                         true, 11);
2528                                                 coex_dm->ps_tdma_du_adj_type =
2529                                                         11;
2530                                         }
2531                                 }
2532                         }
2533                 }
2534         }
2535
2536         /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
2537         /* then we have to adjust it back to the previous record one. */
2538         if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
2539                 boolean scan = false, link = false, roam = false;
2540                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2541                         "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n",
2542                             coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
2543                 BTC_TRACE(trace_buf);
2544
2545                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2546                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2547                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2548
2549                 if (!scan && !link && !roam)
2550                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2551                                                 coex_dm->ps_tdma_du_adj_type);
2552                 else {
2553                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2554                                 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2555                         BTC_TRACE(trace_buf);
2556                 }
2557         }
2558 }
2559
2560 /* ******************
2561  * pstdma for wifi rssi low
2562  * ****************** */
2563 void halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
2564         IN struct btc_coexist *btcoexist/* , */ /* IN u8 wifi_status */)
2565 {
2566         static s32              up, dn, m, n, wait_count;
2567         s32                     result;   /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
2568         u8                      retry_count = 0, bt_info_ext;
2569
2570         coex_dm->auto_tdma_adjust = false;
2571
2572         retry_count = coex_sta->bt_retry_cnt;
2573         bt_info_ext = coex_sta->bt_info_ext;
2574
2575         if (!coex_dm->auto_tdma_adjust_low_rssi) {
2576                 coex_dm->auto_tdma_adjust_low_rssi = true;
2577
2578                 if (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) {
2579                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2580                                                 83);
2581                         coex_dm->ps_tdma_du_adj_type = 83;
2582                 } else {
2583                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 82);
2584                         coex_dm->ps_tdma_du_adj_type = 82;
2585                 }
2586                 /* ============ */
2587                 up = 0;
2588                 dn = 0;
2589                 m = 1;
2590                 n = 3;
2591                 result = 0;
2592                 wait_count = 0;
2593         } else {
2594                 /* accquire the BT TRx retry count from BT_Info byte2
2595                 *               retry_count = coex_sta->bt_retry_cnt;
2596                 *               bt_info_ext = coex_sta->bt_info_ext; */
2597                 result = 0;
2598                 wait_count++;
2599
2600                 if ((coex_sta->low_priority_tx) > 1150 ||
2601                     (coex_sta->low_priority_rx) > 1250)
2602                         retry_count++;
2603
2604                 if (retry_count ==
2605                     0) { /* no retry in the last 2-second duration */
2606                         up++;
2607                         dn--;
2608
2609                         if (dn <= 0)
2610                                 dn = 0;
2611
2612                         if (up >= n) {  /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
2613                                 wait_count = 0;
2614                                 n = 3;
2615                                 up = 0;
2616                                 dn = 0;
2617                                 result = 1;
2618                         }
2619                 } else if (retry_count <=
2620                            3) { /* <=3 retry in the last 2-second duration */
2621                         up--;
2622                         dn++;
2623
2624                         if (up <= 0)
2625                                 up = 0;
2626
2627                         if (dn == 2) {  /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
2628                                 if (wait_count <= 2)
2629                                         m++; /* to avoid loop between the two levels */
2630                                 else
2631                                         m = 1;
2632
2633                                 if (m >= 20)  /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
2634                                         m = 20;
2635
2636                                 n = 3 * m;
2637                                 up = 0;
2638                                 dn = 0;
2639                                 wait_count = 0;
2640                                 result = -1;
2641                         }
2642                 } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
2643                         if (wait_count == 1)
2644                                 m++; /* to avoid loop between the two levels */
2645                         else
2646                                 m = 1;
2647
2648                         if (m >= 20)  /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
2649                                 m = 20;
2650
2651                         n = 3 * m;
2652                         up = 0;
2653                         dn = 0;
2654                         wait_count = 0;
2655                         result = -1;
2656                 }
2657
2658                 if (result == -1) {
2659                         if ((BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
2660                             ((coex_dm->cur_ps_tdma == 81) ||
2661                              (coex_dm->cur_ps_tdma == 82))) {
2662                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2663                                                         true, 84);
2664                                 coex_dm->ps_tdma_du_adj_type = 84;
2665                         } else if (coex_dm->cur_ps_tdma == 81) {
2666                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2667                                                         true, 82);
2668                                 coex_dm->ps_tdma_du_adj_type = 82;
2669                         } else if (coex_dm->cur_ps_tdma == 82) {
2670                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2671                                                         true, 83);
2672                                 coex_dm->ps_tdma_du_adj_type = 83;
2673                         } else if (coex_dm->cur_ps_tdma == 83) {
2674                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2675                                                         true, 84);
2676                                 coex_dm->ps_tdma_du_adj_type = 84;
2677                         }
2678                 } else if (result == 1) {
2679                         if ((BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
2680                             ((coex_dm->cur_ps_tdma == 81) ||
2681                              (coex_dm->cur_ps_tdma == 82))) {
2682                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2683                                                         true, 83);
2684                                 coex_dm->ps_tdma_du_adj_type = 83;
2685                         } else if (coex_dm->cur_ps_tdma == 84) {
2686                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2687                                                         true, 83);
2688                                 coex_dm->ps_tdma_du_adj_type = 83;
2689                         } else if (coex_dm->cur_ps_tdma == 83) {
2690                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2691                                                         true, 82);
2692                                 coex_dm->ps_tdma_du_adj_type = 82;
2693                         } else if (coex_dm->cur_ps_tdma == 82) {
2694                                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2695                                                         true, 81);
2696                                 coex_dm->ps_tdma_du_adj_type = 81;
2697                         }
2698                 }
2699
2700                 if (coex_dm->cur_ps_tdma != 81 &&
2701                     coex_dm->cur_ps_tdma != 82 &&
2702                     coex_dm->cur_ps_tdma != 83 &&
2703                     coex_dm->cur_ps_tdma != 84) {
2704                         /* recover to previous adjust type */
2705                         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2706                                                 coex_dm->ps_tdma_du_adj_type);
2707                 }
2708         }
2709 }
2710
2711 void halbtc8812a2ant_get_bt_rssi_threshold(IN struct btc_coexist *btcoexist,
2712                 IN u8 *pThres0, IN u8 *pThres1)
2713 {
2714         u8 ant_type;
2715
2716         btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &ant_type);
2717
2718         switch (ant_type) {
2719         case BTC_ANT_TYPE_0:
2720                 *pThres0 = 100;
2721                 *pThres1 = 100;
2722                 break;
2723         case BTC_ANT_TYPE_1:
2724                 *pThres0 = 34;
2725                 *pThres1 = 42;
2726                 break;
2727         case BTC_ANT_TYPE_2:
2728                 *pThres0 = 34;
2729                 *pThres1 = 42;
2730                 break;
2731         case BTC_ANT_TYPE_3:
2732                 *pThres0 = 34;
2733                 *pThres1 = 42;
2734                 break;
2735         case BTC_ANT_TYPE_4:
2736                 *pThres0 = 34;
2737                 *pThres1 = 42;
2738                 break;
2739         default:
2740                 break;
2741         }
2742 }
2743
2744
2745
2746 void halbtc8812a2ant_action_sco(IN struct btc_coexist *btcoexist)
2747 {
2748         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2749                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
2750         u32             wifi_bw;
2751         u8              bt_thresh0 = 0, bt_thresh1 = 0;
2752
2753
2754         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2755                                               &bt_thresh1);
2756         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2757                         bt_thresh1);
2758
2759         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2760                           0);
2761         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
2762
2763         /* power save state */
2764         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
2765                                          0x0, 0x0);
2766
2767         /* coex table */
2768         if (BTC_RSSI_LOW(bt_rssi_state))
2769                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2770         else
2771                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2772
2773         /* pstdma */
2774         if (BTC_RSSI_LOW(bt_rssi_state))
2775                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2776         else
2777                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2778
2779         /* decrease BT power */
2780         if (BTC_RSSI_LOW(bt_rssi_state))
2781                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2782         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
2783                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2784         else
2785                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
2786
2787         /* limited Rx */
2788         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2789
2790         /* fw dac swing level */
2791         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2792
2793
2794         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2795         /* sw mechanism */
2796         if (BTC_WIFI_BW_HT40 == wifi_bw) {
2797                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2798                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2799                                                       false, false);
2800                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2801                                                       true, 0x6);
2802                 } else {
2803                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2804                                                       false, false);
2805                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2806                                                       true, 0x6);
2807                 }
2808         } else {
2809                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2810                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2811                                                       false, false);
2812                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2813                                                       true, 0x6);
2814                 } else {
2815                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2816                                                       false, false);
2817                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2818                                                       true, 0x6);
2819                 }
2820         }
2821 }
2822
2823 void halbtc8812a2ant_action_sco_hid(IN struct btc_coexist *btcoexist)
2824 {
2825         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2826                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
2827         u32             wifi_bw;
2828         u8              bt_thresh0 = 0, bt_thresh1 = 0;
2829
2830         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2831                                               &bt_thresh1);
2832         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2833                         bt_thresh1);
2834
2835         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2836                           0);
2837         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
2838
2839         /* power save state */
2840         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
2841                                          0x0, 0x0);
2842
2843         /* coex table */
2844         halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2845
2846         /* pstdma */
2847         if (BTC_RSSI_LOW(bt_rssi_state))
2848                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2849         else
2850                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2851
2852         /* decrease BT power     */
2853         if (BTC_RSSI_LOW(bt_rssi_state))
2854                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2855         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
2856                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2857         else
2858                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
2859
2860         /* limited Rx */
2861         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x8);
2862
2863         /* fw dac swing level */
2864         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2865
2866
2867         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2868         /* sw mechanism */
2869         if (BTC_WIFI_BW_HT40 == wifi_bw) {
2870                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2871                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2872                                                       false, false);
2873                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2874                                                       false, 0x6);
2875                 } else {
2876                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2877                                                       false, false);
2878                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2879                                                       false, 0x6);
2880                 }
2881         } else {
2882                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2883                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2884                                                       false, false);
2885                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2886                                                       false, 0x6);
2887                 } else {
2888                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2889                                                       false, false);
2890                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2891                                                       false, 0x6);
2892                 }
2893         }
2894 }
2895
2896 void halbtc8812a2ant_action_hid(IN struct btc_coexist *btcoexist)
2897 {
2898         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2899                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
2900         u32             wifi_bw;
2901         u8              bt_thresh0 = 0, bt_thresh1 = 0;
2902
2903         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2904                                               &bt_thresh1);
2905         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2906                         bt_thresh1);
2907
2908         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2909                           0);
2910         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
2911
2912         /* power save state */
2913         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
2914                                          0x0, 0x0);
2915
2916         /* coex table */
2917         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
2918                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
2919         else
2920                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2921
2922         /* pstdma */
2923         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
2924                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2925         else
2926                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2927
2928         /* decrease BT power */
2929         if (BTC_RSSI_LOW(bt_rssi_state))
2930                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2931         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
2932                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2933         else
2934                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
2935
2936         /* limited Rx */
2937         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
2938                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2939                                            0x8);
2940         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
2941                  (!BTC_RSSI_LOW(bt_rssi_state)))
2942                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2943                                            0x8);
2944         else
2945                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
2946                                            0x8);
2947
2948
2949         /* fw dac swing level */
2950         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2951
2952         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2953         /* sw mechanism */
2954         if (BTC_WIFI_BW_HT40 == wifi_bw) {
2955                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2956                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2957                                                       false, false);
2958                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2959                                                       false, 0x18);
2960                 } else {
2961                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2962                                                       false, false);
2963                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2964                                                       false, 0x18);
2965                 }
2966         } else {
2967                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2968                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2969                                                       false, false);
2970                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2971                                                       false, 0x18);
2972                 } else {
2973                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2974                                                       false, false);
2975                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2976                                                       false, 0x18);
2977                 }
2978         }
2979 }
2980
2981 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2982 void halbtc8812a2ant_action_a2dp(IN struct btc_coexist *btcoexist)
2983 {
2984         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2985                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
2986         u32             wifi_bw;
2987         u8              bt_thresh0 = 0, bt_thresh1 = 0;
2988         boolean                 ap_enable = false;
2989
2990         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2991                            &ap_enable);
2992
2993         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2994                                               &bt_thresh1);
2995         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2996                         bt_thresh1);
2997
2998         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2999                           0);
3000         /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3001
3002         /* power save state */
3003         if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3004                                     (!BTC_RSSI_LOW(bt_rssi_state))))
3005                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3006                                                  true, 0x0, 0x0);
3007         else
3008                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3009                                                  0x50, 0x4);
3010
3011         /* coex table */
3012         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3013                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3014         else
3015                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3016
3017         /* pstdma */
3018         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3019                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
3020                                                      1);
3021         else
3022                 halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
3023                         btcoexist);
3024
3025         /* decrease BT power */
3026         if (BTC_RSSI_LOW(bt_rssi_state))
3027                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3028         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3029                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3030         else
3031                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3032
3033         /* limited Rx */
3034         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3035
3036         /* fw dac swing level */
3037         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3038
3039
3040         /* sw mechanism */
3041         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3042         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3043                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3044                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3045                                                       false, false);
3046                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3047                                                       false, 0x18);
3048                 } else {
3049                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3050                                                       false, false);
3051                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3052                                                       false, 0x18);
3053                 }
3054         } else {
3055                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3056                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3057                                                       false, false);
3058                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3059                                                       false, 0x18);
3060                 } else {
3061                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3062                                                       false, false);
3063                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3064                                                       false, 0x18);
3065                 }
3066         }
3067 }
3068
3069 void halbtc8812a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
3070 {
3071         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3072                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3073         u32             wifi_bw;
3074         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3075
3076         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3077                                               &bt_thresh1);
3078         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3079                         bt_thresh1);
3080
3081         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3082                           0);
3083         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3084
3085         /* power save state */
3086         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
3087                                          0x0, 0x0);
3088
3089         /* coex table    */
3090         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3091                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3092         else
3093                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3094
3095         /* pstdma        */
3096         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3097                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
3098                                                      2);
3099         else
3100                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
3101
3102         /* decrease BT power */
3103         if (BTC_RSSI_LOW(bt_rssi_state))
3104                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3105         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3106                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3107         else
3108                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3109
3110         /* limited Rx */
3111         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3112
3113         /* fw dac swing level */
3114         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3115
3116
3117         /* sw mechanism */
3118         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3119         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3120                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3121                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3122                                                       false, false);
3123                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3124                                                       true, 0x6);
3125                 } else {
3126                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3127                                                       false, false);
3128                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3129                                                       true, 0x6);
3130                 }
3131         } else {
3132                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3133                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3134                                                       false, false);
3135                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3136                                                       true, 0x6);
3137                 } else {
3138                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3139                                                       false, false);
3140                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3141                                                       true, 0x6);
3142                 }
3143         }
3144 }
3145
3146 void halbtc8812a2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
3147 {
3148         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3149                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3150         u32             wifi_bw;
3151         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3152         boolean         ap_enable = false;
3153
3154         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3155                            &ap_enable);
3156
3157
3158         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3159                                               &bt_thresh1);
3160         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3161                         bt_thresh1);
3162
3163         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3164                           0);
3165         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3166
3167         /* power save state */
3168         if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3169                                     (!BTC_RSSI_LOW(bt_rssi_state))))
3170                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3171                                                  true, 0x0, 0x0);
3172         else
3173                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3174                                                  0x50, 0x4);
3175
3176         /* coex table */
3177         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3178                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3179         else
3180                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3181
3182         /* pstdma */
3183         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3184                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
3185         else
3186                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85);
3187
3188         /* decrease BT power */
3189         if (BTC_RSSI_LOW(bt_rssi_state))
3190                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3191         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3192                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3193         else
3194                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3195
3196         /* limited Rx */
3197         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3198
3199         /* fw dac swing level */
3200         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3201
3202
3203         /* sw mechanism */
3204         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3205         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3206                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3207                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3208                                                       false, false);
3209                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3210                                                       false, 0x18);
3211                 } else {
3212                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3213                                                       false, false);
3214                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3215                                                       false, 0x18);
3216                 }
3217         } else {
3218                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3219                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3220                                                       false, false);
3221                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3222                                                       false, 0x18);
3223                 } else {
3224                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3225                                                       false, false);
3226                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3227                                                       false, 0x18);
3228                 }
3229         }
3230 }
3231
3232 /* PAN(HS) only */
3233 void halbtc8812a2ant_action_pan_hs(IN struct btc_coexist *btcoexist)
3234 {
3235         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3236                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3237         u32             wifi_bw;
3238
3239         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3240                           0);
3241         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
3242
3243         /* power save state */
3244         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
3245                                          0x0, 0x0);
3246
3247         /* coex table */
3248         halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3249
3250         /* pstdma */
3251         halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3252
3253         /* decrease BT power */
3254         if (BTC_RSSI_LOW(bt_rssi_state))
3255                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3256         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3257                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3258         else
3259                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3260
3261         /* limited Rx */
3262         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3263
3264         /* fw dac swing level */
3265         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3266
3267
3268         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3269         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3270                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3271                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3272                                                       false, false);
3273                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3274                                                       false, 0x18);
3275                 } else {
3276                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3277                                                       false, false);
3278                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3279                                                       false, 0x18);
3280                 }
3281         } else {
3282                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3283                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3284                                                       false, false);
3285                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3286                                                       false, 0x18);
3287                 } else {
3288                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3289                                                       false, false);
3290                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3291                                                       false, 0x18);
3292                 }
3293         }
3294 }
3295
3296 /* PAN(EDR)+A2DP */
3297 void halbtc8812a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
3298 {
3299         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3300                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3301         u32             wifi_bw;
3302         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3303         boolean                 ap_enable = false;
3304
3305         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3306                            &ap_enable);
3307
3308         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3309                                               &bt_thresh1);
3310         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3311                         bt_thresh1);
3312
3313
3314         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3315                           0);
3316         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3317
3318         /* power save state      */
3319         if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3320                                     (!BTC_RSSI_LOW(bt_rssi_state))))
3321                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3322                                                  true, 0x0, 0x0);
3323         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3324                  (!BTC_RSSI_LOW(bt_rssi_state)))
3325                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3326                                                  true, 0x0, 0x0);
3327         else
3328                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3329                                                  0x50, 0x4);
3330
3331         /* coex table */
3332         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3333                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3334         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3335                  (!BTC_RSSI_LOW(bt_rssi_state)))
3336                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3337         else
3338                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3339
3340         /* pstdma */
3341         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3342                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
3343                                                      3);
3344         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3345                  (!BTC_RSSI_LOW(bt_rssi_state)))
3346                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, true, 3);
3347         else {
3348                 coex_dm->auto_tdma_adjust = false;
3349                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86);
3350         }
3351
3352         /* decrease BT power */
3353         if (BTC_RSSI_LOW(bt_rssi_state))
3354                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3355         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3356                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3357         else
3358                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3359
3360         /* limited Rx */
3361         halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3362
3363         /* fw dac swing level */
3364         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3365
3366
3367         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3368         /* sw mechanism  */
3369         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3370                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3371                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3372                                                       false, false);
3373                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3374                                                       false, 0x18);
3375                 } else {
3376                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3377                                                       false, false);
3378                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3379                                                       false, 0x18);
3380                 }
3381         } else {
3382                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3383                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3384                                                       false, false);
3385                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3386                                                       false, 0x18);
3387                 } else {
3388                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3389                                                       false, false);
3390                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3391                                                       false, 0x18);
3392                 }
3393         }
3394 }
3395
3396 void halbtc8812a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
3397 {
3398         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3399                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3400         u32             wifi_bw;
3401         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3402         boolean                 ap_enable = false;
3403
3404         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3405                            &ap_enable);
3406
3407         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3408                                               &bt_thresh1);
3409         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3410                         bt_thresh1);
3411
3412         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3413                           0);
3414         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3415
3416         /* power save state */
3417         if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3418                                     (!BTC_RSSI_LOW(bt_rssi_state))))
3419                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3420                                                  true, 0x0, 0x0);
3421         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3422                  (!BTC_RSSI_LOW(bt_rssi_state)))
3423                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3424                                                  true, 0x0, 0x0);
3425         else
3426                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3427                                                  0x50, 0x4);
3428
3429         /* coex table */
3430         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3431                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3432         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3433                  (!BTC_RSSI_LOW(bt_rssi_state)))
3434                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3435         else
3436                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3437
3438         /* pstdma */
3439         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3440                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
3441         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3442                  (!BTC_RSSI_LOW(bt_rssi_state)))
3443                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
3444         else
3445                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85);
3446
3447         /* decrease BT power */
3448         if (BTC_RSSI_LOW(bt_rssi_state))
3449                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3450         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3451                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3452         else
3453                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3454
3455         /* limited Rx */
3456         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3457                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3458                                            0x8);
3459         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3460                  (!BTC_RSSI_LOW(bt_rssi_state)))
3461                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3462                                            0x8);
3463         else
3464                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3465                                            0x8);
3466
3467         /* fw dac swing level */
3468         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3469
3470
3471         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3472         /* sw mechanism */
3473         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3474                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3475                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3476                                                       false, false);
3477                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3478                                                       false, 0x18);
3479                 } else {
3480                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3481                                                       false, false);
3482                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3483                                                       false, 0x18);
3484                 }
3485         } else {
3486                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3487                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3488                                                       false, false);
3489                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3490                                                       false, 0x18);
3491                 } else {
3492                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3493                                                       false, false);
3494                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3495                                                       false, 0x18);
3496                 }
3497         }
3498 }
3499
3500 /* HID+A2DP+PAN(EDR) */
3501 void halbtc8812a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
3502 {
3503         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3504                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3505         u32             wifi_bw;
3506         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3507         boolean                 ap_enable = false;
3508
3509         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3510                            &ap_enable);
3511
3512         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3513                                               &bt_thresh1);
3514         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3515                         bt_thresh1);
3516
3517         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3518                           0);
3519         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3520
3521         /* power save state */
3522         if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3523                                     (!BTC_RSSI_LOW(bt_rssi_state))))
3524                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3525                                                  true, 0x0, 0x0);
3526         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3527                  (!BTC_RSSI_LOW(bt_rssi_state)))
3528                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3529                                                  true, 0x0, 0x0);
3530         else
3531                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3532                                                  0x50, 0x4);
3533
3534         /* coex table */
3535         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3536                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3537         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3538                  (!BTC_RSSI_LOW(bt_rssi_state)))
3539                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3540         else
3541                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3542
3543         /* pstdma */
3544         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3545                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 3);
3546         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3547                  (!BTC_RSSI_LOW(bt_rssi_state)))
3548                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
3549         else {
3550                 coex_dm->auto_tdma_adjust = false;
3551                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86);
3552         }
3553
3554         /* decrease BT power */
3555         if (BTC_RSSI_LOW(bt_rssi_state))
3556                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3557         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3558                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3559         else
3560                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3561
3562         /* limited Rx */
3563         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3564                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3565                                            0x8);
3566         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3567                  (!BTC_RSSI_LOW(bt_rssi_state)))
3568                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3569                                            0x8);
3570         else
3571                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3572                                            0x8);
3573
3574
3575         /* fw dac swing level */
3576         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3577
3578         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3579         /* sw mechanism */
3580         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3581                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3582                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3583                                                       false, false);
3584                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3585                                                       false, 0x18);
3586                 } else {
3587                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3588                                                       false, false);
3589                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3590                                                       false, 0x18);
3591                 }
3592         } else {
3593                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3594                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3595                                                       false, false);
3596                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3597                                                       false, 0x18);
3598                 } else {
3599                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3600                                                       false, false);
3601                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3602                                                       false, 0x18);
3603                 }
3604         }
3605 }
3606
3607 void halbtc8812a2ant_action_hid_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
3608 {
3609         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3610                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3611         u32             wifi_bw;
3612         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3613
3614         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3615                                               &bt_thresh1);
3616         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3617                         bt_thresh1);
3618
3619
3620         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3621                           0);
3622         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3623
3624         /* power save state */
3625         halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
3626                                          0x0, 0x0);
3627
3628         /* coex table */
3629         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3630                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3631         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3632                  (!BTC_RSSI_LOW(bt_rssi_state)))
3633                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3634         else
3635                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3636
3637         /* pstdma */
3638         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3639                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3640         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3641                  (!BTC_RSSI_LOW(bt_rssi_state)))
3642                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3643         else
3644                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3645
3646         /* decrease BT power */
3647         if (BTC_RSSI_LOW(bt_rssi_state))
3648                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3649         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3650                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3651         else
3652                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3653
3654         /* limited Rx */
3655         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3656                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3657                                            0x8);
3658         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3659                  (!BTC_RSSI_LOW(bt_rssi_state)))
3660                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3661                                            0x8);
3662         else
3663                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3664                                            0x8);
3665
3666         /* fw dac swing level */
3667         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3668
3669
3670         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3671         /* sw mechanism */
3672         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3673                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3674                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3675                                                       false, false);
3676                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3677                                                       false, 0x18);
3678                 } else {
3679                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3680                                                       false, false);
3681                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3682                                                       false, 0x18);
3683                 }
3684         } else {
3685                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3686                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3687                                                       false, false);
3688                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3689                                                       false, 0x18);
3690                 } else {
3691                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3692                                                       false, false);
3693                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3694                                                       false, 0x18);
3695                 }
3696         }
3697 }
3698
3699 void halbtc8812a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
3700 {
3701         u8              wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3702                         bt_rssi_state = BTC_RSSI_STATE_HIGH;
3703         u32             wifi_bw;
3704         u8              bt_thresh0 = 0, bt_thresh1 = 0;
3705         boolean                 ap_enable = false;
3706
3707         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3708                            &ap_enable);
3709
3710         halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3711                                               &bt_thresh1);
3712         bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3713                         bt_thresh1);
3714
3715         wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3716                           0);
3717         /*      bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3718
3719         /* power save state      */
3720         if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3721                                     (!BTC_RSSI_LOW(bt_rssi_state))))
3722                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3723                                                  true, 0x0, 0x0);
3724         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3725                  (!BTC_RSSI_LOW(bt_rssi_state)))
3726                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3727                                                  true, 0x0, 0x0);
3728         else
3729                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3730                                                  0x50, 0x4);
3731
3732         /* coex table */
3733         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3734                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3735         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3736                  (!BTC_RSSI_LOW(bt_rssi_state)))
3737                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3738         else
3739                 halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3740
3741         /* pstdma */
3742         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3743                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3744         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3745                  (!BTC_RSSI_LOW(bt_rssi_state)))
3746                 halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3747         else {
3748                 coex_dm->auto_tdma_adjust = false;
3749                 halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 82);
3750         }
3751
3752         /* decrease BT power */
3753         if (BTC_RSSI_LOW(bt_rssi_state))
3754                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3755         else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3756                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3757         else
3758                 halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3759
3760         /* limited Rx */
3761         if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3762                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3763                                            0x8);
3764         else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3765                  (!BTC_RSSI_LOW(bt_rssi_state)))
3766                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3767                                            0x8);
3768         else
3769                 halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3770                                            0x8);
3771
3772         /* fw dac swing level */
3773         halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3774
3775
3776         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3777         /* sw mechanism */
3778         if (BTC_WIFI_BW_HT40 == wifi_bw) {
3779                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3780                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3781                                                       false, false);
3782                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3783                                                       false, 0x18);
3784                 } else {
3785                         halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3786                                                       false, false);
3787                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3788                                                       false, 0x18);
3789                 }
3790         } else {
3791                 if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3792                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3793                                                       false, false);
3794                         halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3795                                                       false, 0x18);
3796                 } else {
3797                         halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3798                                                       false, false);
3799                         halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3800                                                       false, 0x18);
3801                 }
3802         }
3803 }
3804
3805
3806 void halbtc8812a2ant_coex_under_5g(IN struct btc_coexist *btcoexist)
3807 {
3808         halbtc8812a2ant_coex_all_off(btcoexist);
3809
3810         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3811                 "[BTCoex], Under 5G, force set BT to ignore Wlan active!!\n");
3812         BTC_TRACE(trace_buf);
3813         halbtc8812a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
3814 }
3815 /* **************************************************** */
3816 void halbtc8812a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
3817 {
3818         boolean                         wifi_under_5g = false;
3819         u8                              algorithm = 0;
3820
3821         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3822                     "[BTCoex], RunCoexistMechanism()===>\n");
3823         BTC_TRACE(trace_buf);
3824
3825         if (btcoexist->manual_control) {
3826                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3827                         "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3828                 BTC_TRACE(trace_buf);
3829                 return;
3830         }
3831
3832         if (btcoexist->stop_coex_dm) {
3833                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3834                         "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3835                 BTC_TRACE(trace_buf);
3836                 return;
3837         }
3838
3839         if (coex_sta->under_ips) {
3840                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3841                             "[BTCoex], wifi is under IPS !!!\n");
3842                 BTC_TRACE(trace_buf);
3843                 return;
3844         }
3845
3846         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3847         if (wifi_under_5g) {
3848                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3849                         "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3850                 BTC_TRACE(trace_buf);
3851                 halbtc8812a2ant_coex_under_5g(btcoexist);
3852                 return;
3853         }
3854
3855
3856         algorithm = halbtc8812a2ant_action_algorithm(btcoexist);
3857         if (coex_sta->c2h_bt_inquiry_page &&
3858             (BT_8812A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3859                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3860                             "[BTCoex], BT is under inquiry/page scan !!\n");
3861                 BTC_TRACE(trace_buf);
3862                 halbtc8812a2ant_action_bt_inquiry(btcoexist);
3863                 return;
3864         }
3865
3866         coex_dm->cur_algorithm = algorithm;
3867         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
3868                     coex_dm->cur_algorithm);
3869         BTC_TRACE(trace_buf);
3870
3871         if (halbtc8812a2ant_is_common_action(btcoexist)) {
3872                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3873                             "[BTCoex], Action 2-Ant common.\n");
3874                 BTC_TRACE(trace_buf);
3875                 coex_dm->auto_tdma_adjust = false;
3876                 coex_dm->auto_tdma_adjust_low_rssi = false;
3877         } else {
3878                 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3879                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3880                                 "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n",
3881                                 coex_dm->pre_algorithm, coex_dm->cur_algorithm);
3882                         BTC_TRACE(trace_buf);
3883                         coex_dm->auto_tdma_adjust = false;
3884                         coex_dm->auto_tdma_adjust_low_rssi = false;
3885                 }
3886                 switch (coex_dm->cur_algorithm) {
3887                 case BT_8812A_2ANT_COEX_ALGO_SCO:
3888                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3889                                 "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
3890                         BTC_TRACE(trace_buf);
3891                         halbtc8812a2ant_action_sco(btcoexist);
3892                         break;
3893                 case BT_8812A_2ANT_COEX_ALGO_SCO_HID:
3894                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3895                                 "[BTCoex], Action 2-Ant, algorithm = SCO+HID.\n");
3896                         BTC_TRACE(trace_buf);
3897                         halbtc8812a2ant_action_sco_hid(btcoexist);
3898                         break;
3899                 case BT_8812A_2ANT_COEX_ALGO_HID:
3900                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3901                                 "[BTCoex], Action 2-Ant, algorithm = HID.\n");
3902                         BTC_TRACE(trace_buf);
3903                         halbtc8812a2ant_action_hid(btcoexist);
3904                         break;
3905                 case BT_8812A_2ANT_COEX_ALGO_A2DP:
3906                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3907                                 "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
3908                         BTC_TRACE(trace_buf);
3909                         halbtc8812a2ant_action_a2dp(btcoexist);
3910                         break;
3911                 case BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS:
3912                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3913                                 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
3914                         BTC_TRACE(trace_buf);
3915                         halbtc8812a2ant_action_a2dp_pan_hs(btcoexist);
3916                         break;
3917                 case BT_8812A_2ANT_COEX_ALGO_PANEDR:
3918                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3919                                 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
3920                         BTC_TRACE(trace_buf);
3921                         halbtc8812a2ant_action_pan_edr(btcoexist);
3922                         break;
3923                 case BT_8812A_2ANT_COEX_ALGO_PANHS:
3924                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3925                                 "[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
3926                         BTC_TRACE(trace_buf);
3927                         halbtc8812a2ant_action_pan_hs(btcoexist);
3928                         break;
3929                 case BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP:
3930                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3931                                 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
3932                         BTC_TRACE(trace_buf);
3933                         halbtc8812a2ant_action_pan_edr_a2dp(btcoexist);
3934                         break;
3935                 case BT_8812A_2ANT_COEX_ALGO_PANEDR_HID:
3936                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3937                                 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
3938                         BTC_TRACE(trace_buf);
3939                         halbtc8812a2ant_action_pan_edr_hid(btcoexist);
3940                         break;
3941                 case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3942                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3943                                 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
3944                         BTC_TRACE(trace_buf);
3945                         halbtc8812a2ant_action_hid_a2dp_pan_edr(
3946                                 btcoexist);
3947                         break;
3948                 case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS:
3949                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3950                                 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN(HS).\n");
3951                         BTC_TRACE(trace_buf);
3952                         halbtc8812a2ant_action_hid_a2dp_pan_hs(
3953                                 btcoexist);
3954                         break;
3955                 case BT_8812A_2ANT_COEX_ALGO_HID_A2DP:
3956                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3957                                 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
3958                         BTC_TRACE(trace_buf);
3959                         halbtc8812a2ant_action_hid_a2dp(btcoexist);
3960                         break;
3961                 default:
3962                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3963                                 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3964                         BTC_TRACE(trace_buf);
3965                         halbtc8812a2ant_coex_all_off(btcoexist);
3966                         break;
3967                 }
3968                 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3969         }
3970
3971 }
3972
3973 void halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
3974                                     IN boolean back_up)
3975 {
3976         u8      u8tmp = 0;
3977
3978         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3979                     "[BTCoex], 2Ant Init HW Config!!\n");
3980         BTC_TRACE(trace_buf);
3981
3982         if (back_up) {
3983                 /* backup rf 0x1e value */
3984                 coex_dm->bt_rf_0x1e_backup =
3985                         btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e,
3986                                                   0xfffff);
3987
3988                 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
3989                                             0x430);
3990                 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
3991                                             0x434);
3992                 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
3993                                                       btcoexist, 0x42a);
3994                 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
3995                                 btcoexist, 0x456);
3996         }
3997
3998         /* ant sw control to BT */
3999         halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, true,
4000                                      false);
4001
4002         /* 0x790[5:0]=0x5 */
4003         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
4004         u8tmp &= 0xc0;
4005         u8tmp |= 0x5;
4006         btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
4007
4008         /* PTA parameter */
4009         btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0);
4010         btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff);
4011         btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555);
4012         btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555);
4013
4014         /* coex parameters */
4015         btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
4016
4017         /* enable counter statistics */
4018         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
4019
4020         /* enable PTA */
4021         btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
4022
4023         /* bt clock related */
4024         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4);
4025         u8tmp |= BIT(7);
4026         btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp);
4027
4028         /* bt clock related */
4029         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
4030         u8tmp |= BIT(1);
4031         btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
4032 }
4033
4034 /* ************************************************************
4035  * work around function start with wa_halbtc8812a2ant_
4036  * ************************************************************
4037  * ************************************************************
4038  * extern function start with ex_halbtc8812a2ant_
4039  * ************************************************************ */
4040 void ex_halbtc8812a2ant_power_on_setting(IN struct btc_coexist *btcoexist)
4041 {
4042 }
4043
4044 void ex_halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
4045                                        IN boolean wifi_only)
4046 {
4047         halbtc8812a2ant_init_hw_config(btcoexist, true);
4048         btcoexist->stop_coex_dm = false;
4049 }
4050
4051 void ex_halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
4052 {
4053         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4054                     "[BTCoex], Coex Mechanism Init!!\n");
4055         BTC_TRACE(trace_buf);
4056         btcoexist->stop_coex_dm = false;
4057         halbtc8812a2ant_init_coex_dm(btcoexist);
4058 }
4059
4060 void ex_halbtc8812a2ant_display_coex_info(IN struct btc_coexist *btcoexist)
4061 {
4062         struct  btc_board_info          *board_info = &btcoexist->board_info;
4063         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
4064         u8                              *cli_buf = btcoexist->cli_buf;
4065         u8                              u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
4066         u16                             u16tmp[4];
4067         u32                             u32tmp[4];
4068         u32                             fw_ver = 0, bt_patch_ver = 0;
4069
4070         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4071                    "\r\n ============[BT Coexist info]============");
4072         CL_PRINTF(cli_buf);
4073
4074         if (btcoexist->manual_control) {
4075                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4076                         "\r\n ============[Under Manual Control]============");
4077                 CL_PRINTF(cli_buf);
4078                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4079                            "\r\n ==========================================");
4080                 CL_PRINTF(cli_buf);
4081         }
4082
4083         if (btcoexist->stop_coex_dm) {
4084                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4085                            "\r\n ============[Coex is STOPPED]============");
4086                 CL_PRINTF(cli_buf);
4087                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4088                            "\r\n ==========================================");
4089                 CL_PRINTF(cli_buf);
4090         }
4091
4092         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
4093                    "Ant PG number/ Ant mechanism:",
4094                    board_info->pg_ant_num, board_info->btdm_ant_num);
4095         CL_PRINTF(cli_buf);
4096
4097         btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
4098         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4099         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4100                    "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
4101                    "CoexVer/ FwVer/ PatchVer",
4102                    glcoex_ver_date_8812a_2ant, glcoex_ver_8812a_2ant, fw_ver,
4103                    bt_patch_ver, bt_patch_ver);
4104         CL_PRINTF(cli_buf);
4105
4106         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
4107                    "Wifi channel informed to BT",
4108                    coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4109                    coex_dm->wifi_chnl_info[2]);
4110         CL_PRINTF(cli_buf);
4111
4112         /* wifi status */
4113         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4114                    "============[Wifi Status]============");
4115         CL_PRINTF(cli_buf);
4116         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
4117
4118         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4119                    "============[BT Status]============");
4120         CL_PRINTF(cli_buf);
4121         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
4122                    "BT [status/ rssi/ retryCnt]",
4123                    ((coex_sta->bt_disabled) ? ("disabled") :    ((
4124                    coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
4125                            : ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4126                                coex_dm->bt_status) ? "non-connected idle" :
4127                 ((BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
4128                                        ? "connected-idle" : "busy")))),
4129                    coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
4130         CL_PRINTF(cli_buf);
4131
4132         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
4133                    "SCO/HID/PAN/A2DP",
4134                    bt_link_info->sco_exist, bt_link_info->hid_exist,
4135                    bt_link_info->pan_exist, bt_link_info->a2dp_exist);
4136         CL_PRINTF(cli_buf);
4137         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
4138
4139         bt_info_ext = coex_sta->bt_info_ext;
4140         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
4141                    "BT Info A2DP rate",
4142                    (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
4143         CL_PRINTF(cli_buf);
4144
4145         for (i = 0; i < BT_INFO_SRC_8812A_2ANT_MAX; i++) {
4146                 if (coex_sta->bt_info_c2h_cnt[i]) {
4147                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4148                                 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
4149                                    glbt_info_src_8812a_2ant[i],
4150                                    coex_sta->bt_info_c2h[i][0],
4151                                    coex_sta->bt_info_c2h[i][1],
4152                                    coex_sta->bt_info_c2h[i][2],
4153                                    coex_sta->bt_info_c2h[i][3],
4154                                    coex_sta->bt_info_c2h[i][4],
4155                                    coex_sta->bt_info_c2h[i][5],
4156                                    coex_sta->bt_info_c2h[i][6],
4157                                    coex_sta->bt_info_c2h_cnt[i]);
4158                         CL_PRINTF(cli_buf);
4159                 }
4160         }
4161
4162         /* Sw mechanism  */
4163         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4164                    "============[Sw mechanism]============");
4165         CL_PRINTF(cli_buf);
4166         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
4167                    "SM1[ShRf/ LpRA/ LimDig]",
4168                    coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
4169                    coex_dm->limited_dig);
4170         CL_PRINTF(cli_buf);
4171         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
4172                    "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
4173                    coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
4174                    coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
4175         CL_PRINTF(cli_buf);
4176
4177         /* Fw mechanism          */
4178         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4179                    "============[Fw mechanism]============");
4180         CL_PRINTF(cli_buf);
4181
4182         ps_tdma_case = coex_dm->cur_ps_tdma;
4183         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4184                 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d/%d)",
4185                    "PS TDMA",
4186                    coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4187                    coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4188                    coex_dm->ps_tdma_para[4],
4189                    ps_tdma_case, coex_dm->auto_tdma_adjust,
4190                    coex_dm->auto_tdma_adjust_low_rssi);
4191         CL_PRINTF(cli_buf);
4192
4193         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
4194                    "DecBtPwr/ IgnWlanAct",
4195                    coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act);
4196         CL_PRINTF(cli_buf);
4197
4198         /* Hw setting            */
4199         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4200                    "============[Hw setting]============");
4201         CL_PRINTF(cli_buf);
4202
4203         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x",
4204                    "RF-A, 0x1e initVal",
4205                    coex_dm->bt_rf_0x1e_backup);
4206         CL_PRINTF(cli_buf);
4207
4208         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
4209                    "backup ARFR1/ARFR2/RL/AMaxTime",
4210                    coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
4211                    coex_dm->backup_retry_limit,
4212                    coex_dm->backup_ampdu_max_time);
4213         CL_PRINTF(cli_buf);
4214
4215         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
4216         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
4217         u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
4218         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
4219         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
4220                    "0x430/0x434/0x42a/0x456",
4221                    u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
4222         CL_PRINTF(cli_buf);
4223
4224         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4225         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
4226         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x ",
4227                    "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
4228                    u8tmp[0], u8tmp[1]);
4229         CL_PRINTF(cli_buf);
4230
4231         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
4232         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
4233         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4234                    "0x8db(ADC)/0xc5b[29:25](DAC)",
4235                    ((u8tmp[0] & 0x60) >> 5), ((u8tmp[1] & 0x3e) >> 1));
4236         CL_PRINTF(cli_buf);
4237
4238         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3);
4239         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
4240         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4241                    "0xcb3/ 0xcb7",
4242                    u8tmp[0], u8tmp[1]);
4243         CL_PRINTF(cli_buf);
4244
4245         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4246         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4247         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
4248         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
4249                    "0x40/ 0x4c[24:23]/ 0x974",
4250                    u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]);
4251         CL_PRINTF(cli_buf);
4252
4253         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4254         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4255         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4256                    "0x550(bcn ctrl)/0x522",
4257                    u32tmp[0], u8tmp[0]);
4258         CL_PRINTF(cli_buf);
4259
4260         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
4261         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
4262         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4263                    "0xc50(DIG)/0xa0a(CCK-TH)",
4264                    u32tmp[0], u8tmp[0]);
4265         CL_PRINTF(cli_buf);
4266
4267         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
4268         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
4269         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
4270         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4271                    "0xf48/ 0xa5b (FA cnt-- OFDM : CCK)",
4272                    u32tmp[0], (u8tmp[0] << 8) + u8tmp[1]);
4273         CL_PRINTF(cli_buf);
4274
4275         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4276         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4277         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4278         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
4279         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4280                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4281                    "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
4282                    u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
4283         CL_PRINTF(cli_buf);
4284
4285         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4286                    "0x770(high-pri rx/tx)",
4287                    coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4288         CL_PRINTF(cli_buf);
4289         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4290                    "0x774(low-pri rx/tx)",
4291                    coex_sta->low_priority_rx, coex_sta->low_priority_tx);
4292         CL_PRINTF(cli_buf);
4293 #if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 1)
4294         halbtc8812a2ant_monitor_bt_ctr(btcoexist);
4295 #endif
4296         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
4297 }
4298
4299
4300 void ex_halbtc8812a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4301 {
4302         boolean wifi_under_5g = false;
4303
4304         if (btcoexist->manual_control ||        btcoexist->stop_coex_dm)
4305                 return;
4306
4307         if (BTC_IPS_ENTER == type) {
4308                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4309                             "[BTCoex], IPS ENTER notify\n");
4310                 BTC_TRACE(trace_buf);
4311                 coex_sta->under_ips = true;
4312                 halbtc8812a2ant_coex_all_off(btcoexist);
4313                 halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX,
4314                                              false, true);
4315
4316                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4317                         "[BTCoex], IPS notify, force set BT to ignore Wlan active!!\n");
4318                 BTC_TRACE(trace_buf);
4319                 halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4320                 ex_halbtc8812a2ant_media_status_notify(btcoexist,
4321                                                        BTC_MEDIA_DISCONNECT);
4322         } else if (BTC_IPS_LEAVE == type) {
4323                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4324                             "[BTCoex], IPS LEAVE notify\n");
4325                 BTC_TRACE(trace_buf);
4326                 coex_sta->under_ips = false;
4327
4328                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
4329                                    &wifi_under_5g);
4330                 if (!wifi_under_5g) {
4331                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4332                                 "[BTCoex], IPS notify, force set BT NOT to ignore Wlan active!!\n");
4333                         BTC_TRACE(trace_buf);
4334                         halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC,
4335                                                         false);
4336                 }
4337         }
4338 }
4339
4340 void ex_halbtc8812a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4341 {
4342
4343         if (btcoexist->manual_control ||        btcoexist->stop_coex_dm)
4344                 return;
4345
4346         if (BTC_LPS_ENABLE == type) {
4347                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4348                             "[BTCoex], LPS ENABLE notify\n");
4349                 BTC_TRACE(trace_buf);
4350                 coex_sta->under_lps = true;
4351         } else if (BTC_LPS_DISABLE == type) {
4352                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4353                             "[BTCoex], LPS DISABLE notify\n");
4354                 BTC_TRACE(trace_buf);
4355                 coex_sta->under_lps = false;
4356         }
4357 }
4358
4359 void ex_halbtc8812a2ant_scan_notify(IN struct btc_coexist *btcoexist,
4360                                     IN u8 type)
4361 {
4362         if (BTC_SCAN_START == type) {
4363                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4364                             "[BTCoex], SCAN START notify\n");
4365                 BTC_TRACE(trace_buf);
4366         } else if (BTC_SCAN_FINISH == type) {
4367                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4368                             "[BTCoex], SCAN FINISH notify\n");
4369                 BTC_TRACE(trace_buf);
4370         }
4371 }
4372
4373 void ex_halbtc8812a2ant_connect_notify(IN struct btc_coexist *btcoexist,
4374                                        IN u8 type)
4375 {
4376         if (BTC_ASSOCIATE_START == type) {
4377                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4378                             "[BTCoex], CONNECT START notify\n");
4379                 BTC_TRACE(trace_buf);
4380         } else if (BTC_ASSOCIATE_FINISH == type) {
4381                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4382                             "[BTCoex], CONNECT FINISH notify\n");
4383                 BTC_TRACE(trace_buf);
4384         }
4385 }
4386
4387 void ex_halbtc8812a2ant_media_status_notify(IN struct btc_coexist *btcoexist,
4388                 IN u8 type)
4389 {
4390         u8                      data_len = 5;
4391         u8                      buf[6] = {0};
4392         u8                      h2c_parameter[3] = {0};
4393         u32                     wifi_bw;
4394         u8                      wifi_central_chnl;
4395
4396         if (btcoexist->manual_control ||
4397             btcoexist->stop_coex_dm ||
4398             coex_sta->bt_disabled)
4399                 return;
4400
4401         if (BTC_MEDIA_CONNECT == type) {
4402                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4403                             "[BTCoex], MEDIA connect notify\n");
4404                 BTC_TRACE(trace_buf);
4405         } else {
4406                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4407                             "[BTCoex], MEDIA disconnect notify\n");
4408                 BTC_TRACE(trace_buf);
4409         }
4410
4411         /* only 2.4G we need to inform bt the chnl mask */
4412         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
4413                            &wifi_central_chnl);
4414         if ((BTC_MEDIA_CONNECT == type) &&
4415             (wifi_central_chnl <= 14)) {
4416                 h2c_parameter[0] = 0x1;
4417                 h2c_parameter[1] = wifi_central_chnl;
4418                 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
4419                 if (BTC_WIFI_BW_HT40 == wifi_bw)
4420                         h2c_parameter[2] = 0x30;
4421                 else
4422                         h2c_parameter[2] = 0x20;
4423         }
4424
4425         coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
4426         coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
4427         coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
4428
4429         buf[0] = data_len;
4430         buf[1] = 0x5;                           /* OP_Code */
4431         buf[2] = 0x3;                           /* OP_Code_Length */
4432         buf[3] = h2c_parameter[0];      /* OP_Code_Content */
4433         buf[4] = h2c_parameter[1];
4434         buf[5] = h2c_parameter[2];
4435
4436         btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
4437                            (void *)&buf[0]);
4438 }
4439
4440 void ex_halbtc8812a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
4441                 IN u8 type)
4442 {
4443         if (type == BTC_PACKET_DHCP) {
4444                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4445                             "[BTCoex], DHCP Packet notify\n");
4446                 BTC_TRACE(trace_buf);
4447         }
4448
4449 }
4450
4451 void ex_halbtc8812a2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
4452                                        IN u8 *tmp_buf, IN u8 length)
4453 {
4454         u8                      bt_info = 0;
4455         u8                      i, rsp_source = 0;
4456         boolean                 bt_busy = false, limited_dig = false;
4457         boolean                 wifi_connected = false, wifi_under_5g = false;
4458
4459         coex_sta->c2h_bt_info_req_sent = false;
4460         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4461
4462         rsp_source = tmp_buf[0] & 0xf;
4463         if (rsp_source >= BT_INFO_SRC_8812A_2ANT_MAX)
4464                 rsp_source = BT_INFO_SRC_8812A_2ANT_WIFI_FW;
4465         coex_sta->bt_info_c2h_cnt[rsp_source]++;
4466
4467         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4468                     "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
4469                     length);
4470         BTC_TRACE(trace_buf);
4471         for (i = 0; i < length; i++) {
4472                 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
4473                 if (i == 1)
4474                         bt_info = tmp_buf[i];
4475                 if (i == length - 1) {
4476                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
4477                                     tmp_buf[i]);
4478                         BTC_TRACE(trace_buf);
4479                 } else {
4480                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
4481                                     tmp_buf[i]);
4482                         BTC_TRACE(trace_buf);
4483                 }
4484         }
4485
4486         if (BT_INFO_SRC_8812A_2ANT_WIFI_FW != rsp_source) {
4487                 coex_sta->bt_retry_cnt =        /* [3:0] */
4488                         coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
4489
4490                 coex_sta->bt_rssi =
4491                         coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4492
4493                 coex_sta->bt_info_ext =
4494                         coex_sta->bt_info_c2h[rsp_source][4];
4495
4496                 /* Here we need to resend some wifi info to BT */
4497                 /* because bt is reset and loss of the info. */
4498                 if ((coex_sta->bt_info_ext & BIT(1))) {
4499                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4500                                 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
4501                         BTC_TRACE(trace_buf);
4502                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4503                                            &wifi_connected);
4504                         if (wifi_connected)
4505                                 ex_halbtc8812a2ant_media_status_notify(
4506                                         btcoexist, BTC_MEDIA_CONNECT);
4507                         else
4508                                 ex_halbtc8812a2ant_media_status_notify(
4509                                         btcoexist, BTC_MEDIA_DISCONNECT);
4510                 }
4511
4512                 if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
4513                         /* BT already ignored WlanAct */
4514                         if (!btcoexist->manual_control &&
4515                             !btcoexist->stop_coex_dm) {
4516                                 if (!coex_sta->under_ips) {
4517                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4518                                                 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4519                                         BTC_TRACE(trace_buf);
4520                                         halbtc8812a2ant_ignore_wlan_act(
4521                                                 btcoexist, FORCE_EXEC, false);
4522                                 }
4523                         }
4524                 } else {
4525                         /* BT already NOT ignore Wlan active, do nothing here. */
4526
4527                         if (coex_sta->under_ips) {
4528                                 /* work around for 8812a combo hw bug => when IPS, wlanAct is always high. */
4529                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4530                                         "[BTCoex], wifi is under IPS, set BT to ignore Wlan active!!\n");
4531                                 BTC_TRACE(trace_buf);
4532                                 halbtc8812a2ant_ignore_wlan_act(btcoexist,
4533                                                         FORCE_EXEC, true);
4534                         }
4535                 }
4536         }
4537
4538         /* check BIT2 first ==> check if bt is under inquiry or page scan */
4539         if (bt_info & BT_INFO_8812A_2ANT_B_INQ_PAGE)
4540                 coex_sta->c2h_bt_inquiry_page = true;
4541         else
4542                 coex_sta->c2h_bt_inquiry_page = false;
4543
4544         /* set link exist status */
4545         if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) {
4546                 coex_sta->bt_link_exist = false;
4547                 coex_sta->pan_exist = false;
4548                 coex_sta->a2dp_exist = false;
4549                 coex_sta->hid_exist = false;
4550                 coex_sta->sco_exist = false;
4551                 coex_sta->acl_busy = false;
4552         } else {        /* connection exists */
4553                 coex_sta->bt_link_exist = true;
4554                 if (bt_info & BT_INFO_8812A_2ANT_B_FTP)
4555                         coex_sta->pan_exist = true;
4556                 else
4557                         coex_sta->pan_exist = false;
4558                 if (bt_info & BT_INFO_8812A_2ANT_B_A2DP)
4559                         coex_sta->a2dp_exist = true;
4560                 else
4561                         coex_sta->a2dp_exist = false;
4562                 if (bt_info & BT_INFO_8812A_2ANT_B_HID)
4563                         coex_sta->hid_exist = true;
4564                 else
4565                         coex_sta->hid_exist = false;
4566                 if (bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO)
4567                         coex_sta->sco_exist = true;
4568                 else
4569                         coex_sta->sco_exist = false;
4570                 if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY)
4571                         coex_sta->acl_busy = true;
4572                 else
4573                         coex_sta->acl_busy = false;
4574
4575         }
4576
4577         halbtc8812a2ant_update_bt_link_info(btcoexist);
4578
4579         if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) {
4580                 coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
4581                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4582                         "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4583                 BTC_TRACE(trace_buf);
4584         } else if (bt_info ==
4585                 BT_INFO_8812A_2ANT_B_CONNECTION) {      /* connection exists but no busy */
4586                 coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE;
4587                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4588                             "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4589                 BTC_TRACE(trace_buf);
4590         } else if ((bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO) ||
4591                    (bt_info & BT_INFO_8812A_2ANT_B_SCO_BUSY)) {
4592                 coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_SCO_BUSY;
4593                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4594                             "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4595                 BTC_TRACE(trace_buf);
4596         } else if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY) {
4597                 coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_ACL_BUSY;
4598                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4599                             "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4600                 BTC_TRACE(trace_buf);
4601         } else {
4602                 coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_MAX;
4603                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4604                         "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4605                 BTC_TRACE(trace_buf);
4606         }
4607
4608         if ((BT_8812A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
4609             (BT_8812A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
4610             (BT_8812A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
4611                 bt_busy = true;
4612                 if (!wifi_under_5g)
4613                         limited_dig = true;
4614         } else {
4615                 bt_busy = false;
4616                 limited_dig = false;
4617         }
4618
4619         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
4620
4621         coex_dm->limited_dig = limited_dig;
4622         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
4623
4624         halbtc8812a2ant_run_coexist_mechanism(btcoexist);
4625 }
4626
4627 void ex_halbtc8812a2ant_rf_status_notify(IN struct btc_coexist *btcoexist,
4628                 IN u8 type)
4629 {
4630         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
4631         BTC_TRACE(trace_buf);
4632
4633         if (BTC_RF_ON == type) {
4634                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4635                             "[BTCoex], RF is turned ON!!\n");
4636                 BTC_TRACE(trace_buf);
4637                 btcoexist->stop_coex_dm = false;
4638         }
4639         if (BTC_RF_OFF == type) {
4640                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4641                             "[BTCoex], RF is turned OFF!!\n");
4642                 BTC_TRACE(trace_buf);
4643
4644                 halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
4645                                                  true, 0x0, 0x0);
4646                 halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
4647                 /* halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC, false, true); */
4648                 halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4649                 btcoexist->stop_coex_dm = true;
4650
4651         }
4652 }
4653
4654
4655 void ex_halbtc8812a2ant_halt_notify(IN struct btc_coexist *btcoexist)
4656 {
4657
4658         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
4659         BTC_TRACE(trace_buf);
4660
4661         halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, false,
4662                                      true);
4663         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4664                 "[BTCoex], Halt notify, force set BT to ignore Wlan active!!\n");
4665         BTC_TRACE(trace_buf);
4666         halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4667         ex_halbtc8812a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
4668
4669         /* 0x522=0xff, pause tx */
4670         btcoexist->btc_write_1byte(btcoexist, 0x522, 0xff);
4671         /* 0x40[7:6]=2'b01, modify BT mode. */
4672         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0xc0, 0x2);
4673         btcoexist->stop_coex_dm = true;
4674 }
4675
4676 void ex_halbtc8812a2ant_periodical(IN struct btc_coexist *btcoexist)
4677 {
4678 #if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 0)
4679         halbtc8812a2ant_query_bt_info(btcoexist);
4680         halbtc8812a2ant_monitor_bt_ctr(btcoexist);
4681         halbtc8812a2ant_monitor_bt_enable_disable(btcoexist);
4682 #else
4683         if (halbtc8812a2ant_is_wifi_status_changed(btcoexist) ||
4684             coex_dm->auto_tdma_adjust ||
4685             coex_dm->auto_tdma_adjust_low_rssi)
4686                 halbtc8812a2ant_run_coexist_mechanism(btcoexist);
4687 #endif
4688 }
4689
4690 void ex_halbtc8812a2ant_dbg_control(IN struct btc_coexist *btcoexist,
4691                                     IN u8 op_code, IN u8 op_len, IN u8 *pdata)
4692 {
4693         switch (op_code) {
4694         case BTC_DBG_SET_COEX_DEC_BT_PWR:
4695                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4696                             "[BTCoex], Set Dec BT power\n");
4697                 BTC_TRACE(trace_buf);
4698                 {
4699                         u8      data_len = 4;
4700                         u8      buf[6] = {0};
4701                         u8      dec_bt_pwr = 0, pwr_level = 0;
4702                         if (op_len == 2) {
4703                                 dec_bt_pwr = pdata[0];
4704                                 pwr_level = pdata[1];
4705
4706                                 buf[0] = data_len;
4707                                 buf[1] = 0x3;           /* OP_Code */
4708                                 buf[2] = 0x2;           /* OP_Code_Length */
4709
4710                                 buf[3] = dec_bt_pwr;    /* OP_Code_Content */
4711                                 buf[4] = pwr_level;
4712                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4713                                         "[BTCoex], Set Dec BT power=%d, pwr_level=%d\n",
4714                                             dec_bt_pwr, pwr_level);
4715                                 BTC_TRACE(trace_buf);
4716                                 btcoexist->btc_set(btcoexist,
4717                                                    BTC_SET_ACT_CTRL_BT_COEX,
4718                                                    (void *)&buf[0]);
4719                         }
4720                 }
4721                 break;
4722
4723         case BTC_DBG_SET_COEX_BT_AFH_MAP:
4724                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4725                             "[BTCoex], Set BT AFH Map\n");
4726                 BTC_TRACE(trace_buf);
4727                 {
4728                         u8      data_len = 5;
4729                         u8      buf[6] = {0};
4730                         if (op_len == 3) {
4731                                 buf[0] = data_len;
4732                                 buf[1] = 0x5;                           /* OP_Code */
4733                                 buf[2] = 0x3;                           /* OP_Code_Length */
4734
4735                                 buf[3] = pdata[0];                      /* OP_Code_Content */
4736                                 buf[4] = pdata[1];
4737                                 buf[5] = pdata[2];
4738
4739                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4740                                         "[BTCoex], Set BT AFH Map = %02x %02x %02x\n",
4741                                             pdata[0], pdata[1], pdata[2]);
4742                                 BTC_TRACE(trace_buf);
4743                                 btcoexist->btc_set(btcoexist,
4744                                                    BTC_SET_ACT_CTRL_BT_COEX,
4745                                                    (void *)&buf[0]);
4746                         }
4747                 }
4748                 break;
4749
4750         case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:
4751                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4752                             "[BTCoex], Set BT Ignore Wlan Active\n");
4753                 BTC_TRACE(trace_buf);
4754                 {
4755                         u8      data_len = 3;
4756                         u8      buf[6] = {0};
4757                         if (op_len == 1) {
4758                                 buf[0] = data_len;
4759                                 buf[1] = 0x1;                   /* OP_Code */
4760                                 buf[2] = 0x1;                   /* OP_Code_Length */
4761
4762                                 buf[3] = pdata[0];              /* OP_Code_Content */
4763                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4764                                         "[BTCoex], Set BT Ignore Wlan Active = 0x%x\n",
4765                                             pdata[0]);
4766                                 BTC_TRACE(trace_buf);
4767
4768                                 btcoexist->btc_set(btcoexist,
4769                                                    BTC_SET_ACT_CTRL_BT_COEX,
4770                                                    (void *)&buf[0]);
4771                         }
4772                 }
4773                 break;
4774
4775         default:
4776                 break;
4777         }
4778 }
4779
4780 #endif
4781
4782 #endif  /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */