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