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