net: wireless: rockchip_wlan: add rtl8723ds support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723ds / hal / btc / HalBtc8192e1Ant.c
1 /* ************************************************************
2  * Description:
3  *
4  * This file is for RTL8192E Co-exist mechanism
5  *
6  * History
7  * 2012/11/15 Cosa first check in.
8  *
9  * ************************************************************ */
10
11 /* ************************************************************
12  * include files
13  * ************************************************************ */
14 #include "Mp_Precomp.h"
15
16 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
17
18 #if (RTL8192E_SUPPORT == 1)
19 /* ************************************************************
20  * Global variables, these are static variables
21  * ************************************************************ */
22 static u8        *trace_buf = &gl_btc_trace_buf[0];
23 static struct  coex_dm_8192e_1ant               glcoex_dm_8192e_1ant;
24 static struct  coex_dm_8192e_1ant       *coex_dm = &glcoex_dm_8192e_1ant;
25 static struct  coex_sta_8192e_1ant              glcoex_sta_8192e_1ant;
26 static struct  coex_sta_8192e_1ant      *coex_sta = &glcoex_sta_8192e_1ant;
27
28 const char *const glbt_info_src_8192e_1ant[] = {
29         "BT Info[wifi fw]",
30         "BT Info[bt rsp]",
31         "BT Info[bt auto report]",
32 };
33
34 u32     glcoex_ver_date_8192e_1ant = 20140527;
35 u32     glcoex_ver_8192e_1ant = 0x4f;
36
37 /* ************************************************************
38  * local function proto type if needed
39  * ************************************************************
40  * ************************************************************
41  * local function start with halbtc8192e1ant_
42  * ************************************************************ */
43 u8 halbtc8192e1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
44 {
45         s32                     bt_rssi = 0;
46         u8                      bt_rssi_state = coex_sta->pre_bt_rssi_state;
47
48         bt_rssi = coex_sta->bt_rssi;
49
50         if (level_num == 2) {
51                 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
52                     (coex_sta->pre_bt_rssi_state ==
53                      BTC_RSSI_STATE_STAY_LOW)) {
54                         if (bt_rssi >= (rssi_thresh +
55                                         BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
56                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
57                         else
58                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
59                 } else {
60                         if (bt_rssi < rssi_thresh)
61                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
62                         else
63                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
64                 }
65         } else if (level_num == 3) {
66                 if (rssi_thresh > rssi_thresh1) {
67                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
68                                     "[BTCoex], BT Rssi thresh error!!\n");
69                         BTC_TRACE(trace_buf);
70                         return coex_sta->pre_bt_rssi_state;
71                 }
72
73                 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
74                     (coex_sta->pre_bt_rssi_state ==
75                      BTC_RSSI_STATE_STAY_LOW)) {
76                         if (bt_rssi >= (rssi_thresh +
77                                         BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
78                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
79                         else
80                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
81                 } else if ((coex_sta->pre_bt_rssi_state ==
82                             BTC_RSSI_STATE_MEDIUM) ||
83                            (coex_sta->pre_bt_rssi_state ==
84                             BTC_RSSI_STATE_STAY_MEDIUM)) {
85                         if (bt_rssi >= (rssi_thresh1 +
86                                         BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
87                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
88                         else if (bt_rssi < rssi_thresh)
89                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
90                         else
91                                 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
92                 } else {
93                         if (bt_rssi < rssi_thresh1)
94                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
95                         else
96                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
97                 }
98         }
99
100         coex_sta->pre_bt_rssi_state = bt_rssi_state;
101
102         return bt_rssi_state;
103 }
104
105 u8 halbtc8192e1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
106            IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
107 {
108         s32                     wifi_rssi = 0;
109         u8                      wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
110
111         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
112
113         if (level_num == 2) {
114                 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
115                     ||
116                     (coex_sta->pre_wifi_rssi_state[index] ==
117                      BTC_RSSI_STATE_STAY_LOW)) {
118                         if (wifi_rssi >= (rssi_thresh +
119                                           BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
120                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
121                         else
122                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
123                 } else {
124                         if (wifi_rssi < rssi_thresh)
125                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
126                         else
127                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
128                 }
129         } else if (level_num == 3) {
130                 if (rssi_thresh > rssi_thresh1) {
131                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
132                                     "[BTCoex], wifi RSSI thresh error!!\n");
133                         BTC_TRACE(trace_buf);
134                         return coex_sta->pre_wifi_rssi_state[index];
135                 }
136
137                 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
138                     ||
139                     (coex_sta->pre_wifi_rssi_state[index] ==
140                      BTC_RSSI_STATE_STAY_LOW)) {
141                         if (wifi_rssi >= (rssi_thresh +
142                                           BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
143                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
144                         else
145                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
146                 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
147                             BTC_RSSI_STATE_MEDIUM) ||
148                            (coex_sta->pre_wifi_rssi_state[index] ==
149                             BTC_RSSI_STATE_STAY_MEDIUM)) {
150                         if (wifi_rssi >= (rssi_thresh1 +
151                                           BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
152                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
153                         else if (wifi_rssi < rssi_thresh)
154                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
155                         else
156                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
157                 } else {
158                         if (wifi_rssi < rssi_thresh1)
159                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
160                         else
161                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
162                 }
163         }
164
165         coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
166
167         return wifi_rssi_state;
168 }
169
170 void halbtc8192e1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
171                                     IN boolean force_exec, IN u32 dis_rate_mask)
172 {
173         coex_dm->cur_ra_mask = dis_rate_mask;
174
175         if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
176                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
177                                    &coex_dm->cur_ra_mask);
178         coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
179 }
180
181 void halbtc8192e1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
182                 IN boolean force_exec, IN u8 type)
183 {
184         boolean wifi_under_b_mode = false;
185
186         coex_dm->cur_arfr_type = type;
187
188         if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
189                 switch (coex_dm->cur_arfr_type) {
190                 case 0: /* normal mode */
191                         btcoexist->btc_write_4byte(btcoexist, 0x430,
192                                                    coex_dm->backup_arfr_cnt1);
193                         btcoexist->btc_write_4byte(btcoexist, 0x434,
194                                                    coex_dm->backup_arfr_cnt2);
195                         break;
196                 case 1:
197                         btcoexist->btc_get(btcoexist,
198                                            BTC_GET_BL_WIFI_UNDER_B_MODE,
199                                            &wifi_under_b_mode);
200                         if (wifi_under_b_mode) {
201                                 btcoexist->btc_write_4byte(btcoexist,
202                                                            0x430, 0x0);
203                                 btcoexist->btc_write_4byte(btcoexist,
204                                                            0x434, 0x01010101);
205                         } else {
206                                 btcoexist->btc_write_4byte(btcoexist,
207                                                            0x430, 0x0);
208                                 btcoexist->btc_write_4byte(btcoexist,
209                                                            0x434, 0x04030201);
210                         }
211                         break;
212                 default:
213                         break;
214                 }
215         }
216
217         coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
218 }
219
220 void halbtc8192e1ant_retry_limit(IN struct btc_coexist *btcoexist,
221                                  IN boolean force_exec, IN u8 type)
222 {
223         coex_dm->cur_retry_limit_type = type;
224
225         if (force_exec ||
226             (coex_dm->pre_retry_limit_type !=
227              coex_dm->cur_retry_limit_type)) {
228                 switch (coex_dm->cur_retry_limit_type) {
229                 case 0: /* normal mode */
230                         btcoexist->btc_write_2byte(btcoexist, 0x42a,
231                                                    coex_dm->backup_retry_limit);
232                         break;
233                 case 1: /* retry limit=8 */
234                         btcoexist->btc_write_2byte(btcoexist, 0x42a,
235                                                    0x0808);
236                         break;
237                 default:
238                         break;
239                 }
240         }
241
242         coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
243 }
244
245 void halbtc8192e1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
246                                     IN boolean force_exec, IN u8 type)
247 {
248         coex_dm->cur_ampdu_time_type = type;
249
250         if (force_exec ||
251             (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
252                 switch (coex_dm->cur_ampdu_time_type) {
253                 case 0: /* normal mode */
254                         btcoexist->btc_write_1byte(btcoexist, 0x456,
255                                            coex_dm->backup_ampdu_max_time);
256                         break;
257                 case 1: /* AMPDU timw = 0x38 * 32us */
258                         btcoexist->btc_write_1byte(btcoexist, 0x456,
259                                                    0x38);
260                         break;
261                 default:
262                         break;
263                 }
264         }
265
266         coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
267 }
268
269 void halbtc8192e1ant_limited_tx(IN struct btc_coexist *btcoexist,
270                 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
271                                 IN u8 retry_limit_type, IN u8 ampdu_time_type)
272 {
273         switch (ra_mask_type) {
274         case 0: /* normal mode */
275                 halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
276                                                0x0);
277                 break;
278         case 1: /* disable cck 1/2 */
279                 halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
280                                                0x00000003);
281                 break;
282         case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
283                 halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
284                                                0x0001f1f7);
285                 break;
286         default:
287                 break;
288         }
289
290         halbtc8192e1ant_auto_rate_fallback_retry(btcoexist, force_exec,
291                         arfr_type);
292         halbtc8192e1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
293         halbtc8192e1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
294 }
295
296 void halbtc8192e1ant_limited_rx(IN struct btc_coexist *btcoexist,
297                         IN boolean force_exec, IN boolean rej_ap_agg_pkt,
298                         IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
299 {
300         boolean reject_rx_agg = rej_ap_agg_pkt;
301         boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
302         u8      rx_agg_size = agg_buf_size;
303
304         /* ============================================ */
305         /*      Rx Aggregation related setting */
306         /* ============================================ */
307         btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
308                            &reject_rx_agg);
309         /* decide BT control aggregation buf size or not */
310         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
311                            &bt_ctrl_rx_agg_size);
312         /* aggregation buf size, only work when BT control Rx aggregation size. */
313         btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
314         /* real update aggregation setting */
315         btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
316
317
318 }
319
320 void halbtc8192e1ant_query_bt_info(IN struct btc_coexist *btcoexist)
321 {
322         u8                      h2c_parameter[1] = {0};
323
324         coex_sta->c2h_bt_info_req_sent = true;
325
326         h2c_parameter[0] |= BIT(0);     /* trigger */
327
328         btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
329 }
330
331 void halbtc8192e1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
332 {
333         u32                     reg_hp_txrx, reg_lp_txrx, u32tmp;
334         u32                     reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
335         static u8               num_of_bt_counter_chk = 0;
336
337         /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
338         /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
339
340         if (coex_sta->under_ips) {
341                 coex_sta->high_priority_tx = 65535;
342                 coex_sta->high_priority_rx = 65535;
343                 coex_sta->low_priority_tx = 65535;
344                 coex_sta->low_priority_rx = 65535;
345                 return;
346         }
347
348         reg_hp_txrx = 0x770;
349         reg_lp_txrx = 0x774;
350
351         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
352         reg_hp_tx = u32tmp & MASKLWORD;
353         reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
354
355         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
356         reg_lp_tx = u32tmp & MASKLWORD;
357         reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
358
359         coex_sta->high_priority_tx = reg_hp_tx;
360         coex_sta->high_priority_rx = reg_hp_rx;
361         coex_sta->low_priority_tx = reg_lp_tx;
362         coex_sta->low_priority_rx = reg_lp_rx;
363
364         if ((coex_sta->low_priority_tx >= 1050)  &&
365             (!coex_sta->c2h_bt_inquiry_page))
366                 coex_sta->pop_event_cnt++;
367
368         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
369                     "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
370                     reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
371         BTC_TRACE(trace_buf);
372
373         /* reset counter */
374         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
375
376         if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) &&
377             (reg_lp_rx == 0)) {
378                 num_of_bt_counter_chk++;
379                 if (num_of_bt_counter_chk >= 3) {
380                         halbtc8192e1ant_query_bt_info(btcoexist);
381                         num_of_bt_counter_chk = 0;
382                 }
383         }
384 }
385
386
387 void halbtc8192e1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
388 {
389         s32     wifi_rssi = 0;
390         boolean wifi_busy = false, wifi_under_b_mode = false;
391         static u8 cck_lock_counter = 0;
392
393         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
394         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
395         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
396                            &wifi_under_b_mode);
397
398         if (coex_sta->under_ips) {
399                 coex_sta->crc_ok_cck = 0;
400                 coex_sta->crc_ok_11g = 0;
401                 coex_sta->crc_ok_11n = 0;
402                 coex_sta->crc_ok_11n_agg = 0;
403
404                 coex_sta->crc_err_cck = 0;
405                 coex_sta->crc_err_11g = 0;
406                 coex_sta->crc_err_11n = 0;
407                 coex_sta->crc_err_11n_agg = 0;
408         } else {
409                 coex_sta->crc_ok_cck    = btcoexist->btc_read_4byte(btcoexist,
410                                           0xf88);
411                 coex_sta->crc_ok_11g    = btcoexist->btc_read_2byte(btcoexist,
412                                           0xf94);
413                 coex_sta->crc_ok_11n    = btcoexist->btc_read_2byte(btcoexist,
414                                           0xf90);
415                 coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
416                                            0xfb8);
417
418                 coex_sta->crc_err_cck    = btcoexist->btc_read_4byte(btcoexist,
419                                            0xf84);
420                 coex_sta->crc_err_11g    = btcoexist->btc_read_2byte(btcoexist,
421                                            0xf96);
422                 coex_sta->crc_err_11n    = btcoexist->btc_read_2byte(btcoexist,
423                                            0xf92);
424                 coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
425                                             0xfba);
426         }
427
428
429         /* reset counter */
430         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1);
431         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0);
432
433         if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
434                 if ((coex_dm->bt_status == BT_8192E_1ANT_BT_STATUS_ACL_BUSY) ||
435                     (coex_dm->bt_status ==
436                      BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
437                     (coex_dm->bt_status ==
438                      BT_8192E_1ANT_BT_STATUS_SCO_BUSY)) {
439                         if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g +
440                                                     coex_sta->crc_ok_11n +
441                                                     coex_sta->crc_ok_11n_agg)) {
442                                 if (cck_lock_counter < 5)
443                                         cck_lock_counter++;
444                         } else {
445                                 if (cck_lock_counter > 0)
446                                         cck_lock_counter--;
447                         }
448
449                 } else {
450                         if (cck_lock_counter > 0)
451                                 cck_lock_counter--;
452                 }
453         } else {
454                 if (cck_lock_counter > 0)
455                         cck_lock_counter--;
456         }
457
458         if (!coex_sta->pre_ccklock) {
459
460                 if (cck_lock_counter >= 5)
461                         coex_sta->cck_lock = true;
462                 else
463                         coex_sta->cck_lock = false;
464         } else {
465                 if (cck_lock_counter == 0)
466                         coex_sta->cck_lock = false;
467                 else
468                         coex_sta->cck_lock = true;
469         }
470
471         coex_sta->pre_ccklock =  coex_sta->cck_lock;
472
473
474 }
475
476 boolean halbtc8192e1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
477 {
478         static boolean  pre_wifi_busy = false, pre_under_4way = false,
479                         pre_bt_hs_on = false;
480         boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
481         boolean wifi_connected = false;
482
483         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
484                            &wifi_connected);
485         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
486         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
487         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
488                            &under_4way);
489
490         if (wifi_connected) {
491                 if (wifi_busy != pre_wifi_busy) {
492                         pre_wifi_busy = wifi_busy;
493                         return true;
494                 }
495                 if (under_4way != pre_under_4way) {
496                         pre_under_4way = under_4way;
497                         return true;
498                 }
499                 if (bt_hs_on != pre_bt_hs_on) {
500                         pre_bt_hs_on = bt_hs_on;
501                         return true;
502                 }
503         }
504
505         return false;
506 }
507
508 void halbtc8192e1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
509 {
510         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
511         boolean                         bt_hs_on = false;
512
513         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
514
515         bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
516         bt_link_info->sco_exist = coex_sta->sco_exist;
517         bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
518         bt_link_info->pan_exist = coex_sta->pan_exist;
519         bt_link_info->hid_exist = coex_sta->hid_exist;
520
521         /* work around for HS mode. */
522         if (bt_hs_on) {
523                 bt_link_info->pan_exist = true;
524                 bt_link_info->bt_link_exist = true;
525         }
526
527         /* check if Sco only */
528         if (bt_link_info->sco_exist &&
529             !bt_link_info->a2dp_exist &&
530             !bt_link_info->pan_exist &&
531             !bt_link_info->hid_exist)
532                 bt_link_info->sco_only = true;
533         else
534                 bt_link_info->sco_only = false;
535
536         /* check if A2dp only */
537         if (!bt_link_info->sco_exist &&
538             bt_link_info->a2dp_exist &&
539             !bt_link_info->pan_exist &&
540             !bt_link_info->hid_exist)
541                 bt_link_info->a2dp_only = true;
542         else
543                 bt_link_info->a2dp_only = false;
544
545         /* check if Pan only */
546         if (!bt_link_info->sco_exist &&
547             !bt_link_info->a2dp_exist &&
548             bt_link_info->pan_exist &&
549             !bt_link_info->hid_exist)
550                 bt_link_info->pan_only = true;
551         else
552                 bt_link_info->pan_only = false;
553
554         /* check if Hid 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->hid_only = true;
560         else
561                 bt_link_info->hid_only = false;
562 }
563
564 u8 halbtc8192e1ant_action_algorithm(IN struct btc_coexist *btcoexist)
565 {
566         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
567         boolean                         bt_hs_on = false;
568         u8                              algorithm = BT_8192E_1ANT_COEX_ALGO_UNDEFINED;
569         u8                              num_of_diff_profile = 0;
570
571         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
572
573         if (!bt_link_info->bt_link_exist) {
574                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
575                             "[BTCoex], No BT link exists!!!\n");
576                 BTC_TRACE(trace_buf);
577                 return algorithm;
578         }
579
580         if (bt_link_info->sco_exist)
581                 num_of_diff_profile++;
582         if (bt_link_info->hid_exist)
583                 num_of_diff_profile++;
584         if (bt_link_info->pan_exist)
585                 num_of_diff_profile++;
586         if (bt_link_info->a2dp_exist)
587                 num_of_diff_profile++;
588
589         if (num_of_diff_profile == 1) {
590                 if (bt_link_info->sco_exist) {
591                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
592                                     "[BTCoex], BT Profile = SCO only\n");
593                         BTC_TRACE(trace_buf);
594                         algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
595                 } else {
596                         if (bt_link_info->hid_exist) {
597                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
598                                         "[BTCoex], BT Profile = HID only\n");
599                                 BTC_TRACE(trace_buf);
600                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
601                         } else if (bt_link_info->a2dp_exist) {
602                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
603                                         "[BTCoex], BT Profile = A2DP only\n");
604                                 BTC_TRACE(trace_buf);
605                                 algorithm = BT_8192E_1ANT_COEX_ALGO_A2DP;
606                         } else if (bt_link_info->pan_exist) {
607                                 if (bt_hs_on) {
608                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
609                                                 "[BTCoex], BT Profile = PAN(HS) only\n");
610                                         BTC_TRACE(trace_buf);
611                                         algorithm =
612                                                 BT_8192E_1ANT_COEX_ALGO_PANHS;
613                                 } else {
614                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
615                                                 "[BTCoex], BT Profile = PAN(EDR) only\n");
616                                         BTC_TRACE(trace_buf);
617                                         algorithm =
618                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR;
619                                 }
620                         }
621                 }
622         } else if (num_of_diff_profile == 2) {
623                 if (bt_link_info->sco_exist) {
624                         if (bt_link_info->hid_exist) {
625                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
626                                         "[BTCoex], BT Profile = SCO + HID\n");
627                                 BTC_TRACE(trace_buf);
628                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
629                         } else if (bt_link_info->a2dp_exist) {
630                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
631                                         "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
632                                 BTC_TRACE(trace_buf);
633                                 algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
634                         } else if (bt_link_info->pan_exist) {
635                                 if (bt_hs_on) {
636                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
637                                                 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
638                                         BTC_TRACE(trace_buf);
639                                         algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
640                                 } else {
641                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
642                                                 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
643                                         BTC_TRACE(trace_buf);
644                                         algorithm =
645                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
646                                 }
647                         }
648                 } else {
649                         if (bt_link_info->hid_exist &&
650                             bt_link_info->a2dp_exist) {
651                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
652                                         "[BTCoex], BT Profile = HID + A2DP\n");
653                                 BTC_TRACE(trace_buf);
654                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
655                         } else if (bt_link_info->hid_exist &&
656                                    bt_link_info->pan_exist) {
657                                 if (bt_hs_on) {
658                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
659                                                 "[BTCoex], BT Profile = HID + PAN(HS)\n");
660                                         BTC_TRACE(trace_buf);
661                                         algorithm =
662                                                 BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
663                                 } else {
664                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
665                                                 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
666                                         BTC_TRACE(trace_buf);
667                                         algorithm =
668                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
669                                 }
670                         } else if (bt_link_info->pan_exist &&
671                                    bt_link_info->a2dp_exist) {
672                                 if (bt_hs_on) {
673                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
674                                                 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
675                                         BTC_TRACE(trace_buf);
676                                         algorithm =
677                                                 BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS;
678                                 } else {
679                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
680                                                 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
681                                         BTC_TRACE(trace_buf);
682                                         algorithm =
683                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP;
684                                 }
685                         }
686                 }
687         } else if (num_of_diff_profile == 3) {
688                 if (bt_link_info->sco_exist) {
689                         if (bt_link_info->hid_exist &&
690                             bt_link_info->a2dp_exist) {
691                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
692                                         "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
693                                 BTC_TRACE(trace_buf);
694                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
695                         } else if (bt_link_info->hid_exist &&
696                                    bt_link_info->pan_exist) {
697                                 if (bt_hs_on) {
698                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
699                                                 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
700                                         BTC_TRACE(trace_buf);
701                                         algorithm =
702                                                 BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
703                                 } else {
704                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
705                                                 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
706                                         BTC_TRACE(trace_buf);
707                                         algorithm =
708                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
709                                 }
710                         } else if (bt_link_info->pan_exist &&
711                                    bt_link_info->a2dp_exist) {
712                                 if (bt_hs_on) {
713                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
714                                                 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
715                                         BTC_TRACE(trace_buf);
716                                         algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
717                                 } else {
718                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
719                                                 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
720                                         BTC_TRACE(trace_buf);
721                                         algorithm =
722                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
723                                 }
724                         }
725                 } else {
726                         if (bt_link_info->hid_exist &&
727                             bt_link_info->pan_exist &&
728                             bt_link_info->a2dp_exist) {
729                                 if (bt_hs_on) {
730                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
731                                                 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
732                                         BTC_TRACE(trace_buf);
733                                         algorithm =
734                                                 BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
735                                 } else {
736                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
737                                                 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
738                                         BTC_TRACE(trace_buf);
739                                         algorithm =
740                                                 BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
741                                 }
742                         }
743                 }
744         } else if (num_of_diff_profile >= 3) {
745                 if (bt_link_info->sco_exist) {
746                         if (bt_link_info->hid_exist &&
747                             bt_link_info->pan_exist &&
748                             bt_link_info->a2dp_exist) {
749                                 if (bt_hs_on) {
750                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
751                                                 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
752                                         BTC_TRACE(trace_buf);
753
754                                 } else {
755                                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
756                                                 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
757                                         BTC_TRACE(trace_buf);
758                                         algorithm =
759                                                 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
760                                 }
761                         }
762                 }
763         }
764
765         return algorithm;
766 }
767
768 void halbtc8192e1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
769                                         IN boolean enable_auto_report)
770 {
771         u8                      h2c_parameter[1] = {0};
772
773         h2c_parameter[0] = 0;
774
775         if (enable_auto_report)
776                 h2c_parameter[0] |= BIT(0);
777
778         btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
779 }
780
781 void halbtc8192e1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
782                     IN boolean force_exec, IN boolean enable_auto_report)
783 {
784         coex_dm->cur_bt_auto_report = enable_auto_report;
785
786         if (!force_exec) {
787                 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
788                         return;
789         }
790         halbtc8192e1ant_set_bt_auto_report(btcoexist,
791                                            coex_dm->cur_bt_auto_report);
792
793         coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
794 }
795
796 void halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
797                 *btcoexist, IN boolean low_penalty_ra)
798 {
799         u8                      h2c_parameter[6] = {0};
800
801         h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
802
803         if (low_penalty_ra) {
804                 h2c_parameter[1] |= BIT(0);
805                 h2c_parameter[2] =
806                         0x00;  /* normal rate except MCS7/6/5, OFDM54/48/36 */
807                 h2c_parameter[3] = 0xf7;  /* MCS7 or OFDM54 */
808                 h2c_parameter[4] = 0xf8;  /* MCS6 or OFDM48 */
809                 h2c_parameter[5] = 0xf9;        /* MCS5 or OFDM36        */
810         }
811
812         btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
813 }
814
815 void halbtc8192e1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
816                             IN boolean force_exec, IN boolean low_penalty_ra)
817 {
818         coex_dm->cur_low_penalty_ra = low_penalty_ra;
819
820         if (!force_exec) {
821                 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
822                         return;
823         }
824         halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
825                         coex_dm->cur_low_penalty_ra);
826
827         coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
828 }
829
830 void halbtc8192e1ant_set_coex_table(IN struct btc_coexist *btcoexist,
831             IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
832 {
833         btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
834
835         btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
836
837         btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
838
839         btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
840 }
841
842 void halbtc8192e1ant_coex_table(IN struct btc_coexist *btcoexist,
843                         IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
844                                 IN u32 val0x6c8, IN u8 val0x6cc)
845 {
846         coex_dm->cur_val0x6c0 = val0x6c0;
847         coex_dm->cur_val0x6c4 = val0x6c4;
848         coex_dm->cur_val0x6c8 = val0x6c8;
849         coex_dm->cur_val0x6cc = val0x6cc;
850
851         if (!force_exec) {
852                 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
853                     (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
854                     (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
855                     (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
856                         return;
857         }
858         halbtc8192e1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
859                                        val0x6cc);
860
861         coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
862         coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
863         coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
864         coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
865 }
866
867 void halbtc8192e1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
868                 IN boolean force_exec, IN u8 type)
869 {
870         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
871                     "[BTCoex], ********** CoexTable(%d) **********\n", type);
872         BTC_TRACE(trace_buf);
873
874         coex_sta->coex_table_type = type;
875
876         switch (type) {
877         case 0:
878                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
879                                    0x55555555, 0x55555555, 0xffffff, 0x3);
880                 break;
881         case 1:
882                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
883                                    0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
884                 break;
885         case 2:
886                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
887                                    0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
888                 break;
889         case 3:
890                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
891                                    0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
892                 break;
893         case 4:
894                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
895                                    0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
896                 break;
897         case 5:
898                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
899                                    0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3);
900                 break;
901         case 6:
902                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
903                                    0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
904                 break;
905         case 7:
906                 halbtc8192e1ant_coex_table(btcoexist, force_exec,
907                                    0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
908                 break;
909         default:
910                 break;
911         }
912 }
913
914 void halbtc8192e1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
915                 IN boolean enable)
916 {
917         u8                      h2c_parameter[1] = {0};
918
919         if (enable) {
920                 h2c_parameter[0] |= BIT(0);             /* function enable */
921         }
922
923         btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
924 }
925
926 void halbtc8192e1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
927                                      IN boolean force_exec, IN boolean enable)
928 {
929         coex_dm->cur_ignore_wlan_act = enable;
930
931         if (!force_exec) {
932                 if (coex_dm->pre_ignore_wlan_act ==
933                     coex_dm->cur_ignore_wlan_act)
934                         return;
935         }
936         halbtc8192e1ant_set_fw_ignore_wlan_act(btcoexist, enable);
937
938         coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
939 }
940
941 void halbtc8192e1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
942                                   IN u8 lps_val, IN u8 rpwm_val)
943 {
944         u8      lps = lps_val;
945         u8      rpwm = rpwm_val;
946
947         btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
948         btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
949 }
950
951 void halbtc8192e1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
952                       IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
953 {
954         coex_dm->cur_lps = lps_val;
955         coex_dm->cur_rpwm = rpwm_val;
956
957         if (!force_exec) {
958                 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
959                     (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
960                         return;
961         }
962         halbtc8192e1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
963
964         coex_dm->pre_lps = coex_dm->cur_lps;
965         coex_dm->pre_rpwm = coex_dm->cur_rpwm;
966 }
967
968 void halbtc8192e1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
969                                   IN boolean low_penalty_ra)
970 {
971         halbtc8192e1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
972 }
973
974 void halbtc8192e1ant_set_ant_path(IN struct btc_coexist *btcoexist,
975           IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
976 {
977         u32                     u32tmp = 0;
978
979         if (init_hwcfg) {
980                 btcoexist->btc_write_1byte(btcoexist, 0x944, 0x24);
981                 btcoexist->btc_write_4byte(btcoexist, 0x930, 0x700700);
982                 if (btcoexist->chip_interface == BTC_INTF_USB)
983                         btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
984                 else
985                         btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
986
987                 /* 0x4c[27][24]='00', Set Antenna to BB */
988                 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
989                 u32tmp &= ~BIT(24);
990                 u32tmp &= ~BIT(27);
991                 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
992         } else if (wifi_off) {
993                 if (btcoexist->chip_interface == BTC_INTF_USB)
994                         btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
995                 else
996                         btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
997
998                 /* 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1 */
999                 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1000                 u32tmp |= BIT(24);
1001                 u32tmp |= BIT(27);
1002                 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
1003         }
1004
1005         /* ext switch setting */
1006         switch (ant_pos_type) {
1007         case BTC_ANT_PATH_WIFI:
1008                 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
1009                 break;
1010         case BTC_ANT_PATH_BT:
1011                 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20);
1012                 break;
1013         default:
1014         case BTC_ANT_PATH_PTA:
1015                 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
1016                 break;
1017         }
1018 }
1019
1020 void halbtc8192e1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1021            IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1022 {
1023         u8                      h2c_parameter[5] = {0};
1024         u8                      real_byte1 = byte1, real_byte5 = byte5;
1025         boolean                 ap_enable = false;
1026
1027         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1028                            &ap_enable);
1029
1030         if (ap_enable) {
1031                 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1032                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1033                                     "[BTCoex], FW for 1Ant AP mode\n");
1034                         BTC_TRACE(trace_buf);
1035                         real_byte1 &= ~BIT(4);
1036                         real_byte1 |= BIT(5);
1037
1038                         real_byte5 |= BIT(5);
1039                         real_byte5 &= ~BIT(6);
1040                 }
1041         }
1042
1043         h2c_parameter[0] = real_byte1;
1044         h2c_parameter[1] = byte2;
1045         h2c_parameter[2] = byte3;
1046         h2c_parameter[3] = byte4;
1047         h2c_parameter[4] = real_byte5;
1048
1049         coex_dm->ps_tdma_para[0] = real_byte1;
1050         coex_dm->ps_tdma_para[1] = byte2;
1051         coex_dm->ps_tdma_para[2] = byte3;
1052         coex_dm->ps_tdma_para[3] = byte4;
1053         coex_dm->ps_tdma_para[4] = real_byte5;
1054
1055         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1056 }
1057
1058
1059 void halbtc8192e1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1060                      IN boolean force_exec, IN boolean turn_on, IN u8 type)
1061 {
1062         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1063         boolean                 wifi_busy = false;
1064         u8                      rssi_adjust_val = 0;
1065         u8                      ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51,
1066                                 ps_tdma_byte3_val =  0x10;
1067         s8                      wifi_duration_adjust = 0x0;
1068
1069         coex_dm->cur_ps_tdma_on = turn_on;
1070         coex_dm->cur_ps_tdma = type;
1071
1072         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1073
1074         if (coex_dm->cur_ps_tdma_on) {
1075                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1076                             "[BTCoex], ********** TDMA(on, %d) **********\n",
1077                             coex_dm->cur_ps_tdma);
1078                 BTC_TRACE(trace_buf);
1079         } else {
1080                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1081                             "[BTCoex], ********** TDMA(off, %d) **********\n",
1082                             coex_dm->cur_ps_tdma);
1083                 BTC_TRACE(trace_buf);
1084         }
1085
1086         if (!force_exec) {
1087                 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1088                     (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1089                         return;
1090         }
1091
1092         if (coex_sta->scan_ap_num <= 5)
1093                 wifi_duration_adjust = 5;
1094         else if (coex_sta->scan_ap_num >= 40)
1095                 wifi_duration_adjust = -15;
1096         else if (coex_sta->scan_ap_num >= 20)
1097                 wifi_duration_adjust = -10;
1098
1099         if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */
1100                 ps_tdma_byte0_val = 0x61;  /* no null-pkt */
1101                 ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */
1102                 ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */
1103         }
1104
1105         if ((type == 3) || (type == 13) || (type == 14))
1106                 ps_tdma_byte4_val = ps_tdma_byte4_val &
1107                             0xbf;  /* no dynamic slot for multi-profile */
1108
1109         if (bt_link_info->slave_role == true)
1110                 ps_tdma_byte4_val = ps_tdma_byte4_val |
1111                         0x1;  /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1112
1113         if (turn_on) {
1114                 switch (type) {
1115                 default:
1116                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1117                                       0x1a, 0x1a, 0x0, ps_tdma_byte4_val);
1118                         break;
1119                 case 1:
1120                         halbtc8192e1ant_set_fw_pstdma(btcoexist,
1121                                                       ps_tdma_byte0_val, 0x3a +
1122                                               wifi_duration_adjust, 0x03,
1123                                       ps_tdma_byte3_val, ps_tdma_byte4_val);
1124                         break;
1125                 case 2:
1126                         halbtc8192e1ant_set_fw_pstdma(btcoexist,
1127                                                       ps_tdma_byte0_val, 0x2d +
1128                                               wifi_duration_adjust, 0x03,
1129                                       ps_tdma_byte3_val, ps_tdma_byte4_val);
1130                         break;
1131                 case 3:
1132                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1133                                       0x1d, 0x1d, 0x0, ps_tdma_byte4_val);
1134                         break;
1135                 case 4:
1136                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1137                                                       0x15, 0x3, 0x14, 0x0);
1138                         break;
1139                 case 5:
1140                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1141                                                       0x15, 0x3, 0x11, 0x11);
1142                         break;
1143                 case 6:
1144                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1145                                                       0x20, 0x3, 0x11, 0x11);
1146                         break;
1147                 case 7:
1148                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
1149                                                       0xc, 0x5, 0x0, 0x0);
1150                         break;
1151                 case 8:
1152                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1153                                                       0x25, 0x3, 0x10, 0x0);
1154                         break;
1155                 case 9:
1156                         halbtc8192e1ant_set_fw_pstdma(btcoexist,
1157                                               ps_tdma_byte0_val, 0x21, 0x3,
1158                                       ps_tdma_byte3_val, ps_tdma_byte4_val);
1159                         break;
1160                 case 10:
1161                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
1162                                                       0xa, 0xa, 0x0, 0x40);
1163                         break;
1164                 case 11:
1165                         halbtc8192e1ant_set_fw_pstdma(btcoexist,
1166                                               ps_tdma_byte0_val, 0x21, 0x03,
1167                                       ps_tdma_byte3_val, ps_tdma_byte4_val);
1168                         break;
1169                 case 12:
1170                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1171                                                       0x0a, 0x0a, 0x0, 0x50);
1172                         break;
1173                 case 13:
1174                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1175                                       0x12, 0x12, 0x0, ps_tdma_byte4_val);
1176                         break;
1177                 case 14:
1178                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1179                                       0x21, 0x3, 0x10, ps_tdma_byte4_val);
1180                         break;
1181                 case 15:
1182                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
1183                                                       0xa, 0x3, 0x8, 0x0);
1184                         break;
1185                 case 16:
1186                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1187                                                       0x15, 0x3, 0x10, 0x0);
1188                         break;
1189                 case 18:
1190                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1191                                                       0x25, 0x3, 0x10, 0x0);
1192                         break;
1193                 case 20:
1194                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1195                                                       0x3f, 0x03, 0x11, 0x10);
1196                         break;
1197                 case 21:
1198                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1199                                                       0x25, 0x03, 0x11, 0x11);
1200                         break;
1201                 case 22:
1202                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1203                                                       0x25, 0x03, 0x11, 0x10);
1204                         break;
1205                 case 23:
1206                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1207                                                       0x25, 0x3, 0x31, 0x18);
1208                         break;
1209                 case 24:
1210                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1211                                                       0x15, 0x3, 0x31, 0x18);
1212                         break;
1213                 case 25:
1214                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1215                                                       0xa, 0x3, 0x31, 0x18);
1216                         break;
1217                 case 26:
1218                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1219                                                       0xa, 0x3, 0x31, 0x18);
1220                         break;
1221                 case 27:
1222                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1223                                                       0x25, 0x3, 0x31, 0x98);
1224                         break;
1225                 case 28:
1226                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x69,
1227                                                       0x25, 0x3, 0x31, 0x0);
1228                         break;
1229                 case 29:
1230                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xab,
1231                                                       0x1a, 0x1a, 0x1, 0x10);
1232                         break;
1233                 case 30:
1234                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1235                                                       0x30, 0x3, 0x10, 0x10);
1236                         break;
1237                 case 31:
1238                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3,
1239                                                       0x1a, 0x1a, 0, 0x58);
1240                         break;
1241                 case 32:
1242                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1243                                                       0x35, 0x3, 0x11, 0x11);
1244                         break;
1245                 case 33:
1246                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xa3,
1247                                                       0x25, 0x3, 0x30, 0x90);
1248                         break;
1249                 case 34:
1250                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x53,
1251                                                       0x1a, 0x1a, 0x0, 0x10);
1252                         break;
1253                 case 35:
1254                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x63,
1255                                                       0x1a, 0x1a, 0x0, 0x10);
1256                         break;
1257                 case 36:
1258                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3,
1259                                                       0x12, 0x3, 0x14, 0x50);
1260                         break;
1261                 case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1262                         /* here softap mode screen off will cost 70-80mA for phone */
1263                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x23,
1264                                                       0x18, 0x00, 0x10, 0x24);
1265                         break;
1266                 }
1267         } else {
1268
1269                 /* disable PS tdma */
1270                 switch (type) {
1271                 case 8: /* PTA Control */
1272                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x8,
1273                                                       0x0, 0x0, 0x0, 0x0);
1274                         halbtc8192e1ant_set_ant_path(btcoexist,
1275                                              BTC_ANT_PATH_PTA, false, false);
1276                         break;
1277                 case 0:
1278                 default:  /* Software control, Antenna at BT side */
1279                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0,
1280                                                       0x0, 0x0, 0x0, 0x0);
1281                         halbtc8192e1ant_set_ant_path(btcoexist,
1282                                              BTC_ANT_PATH_BT, false, false);
1283                         break;
1284                 case 9:   /* Software control, Antenna at WiFi side */
1285                         halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0,
1286                                                       0x0, 0x0, 0x0, 0x0);
1287                         halbtc8192e1ant_set_ant_path(btcoexist,
1288                                              BTC_ANT_PATH_WIFI, false, false);
1289                         break;
1290                 }
1291         }
1292         rssi_adjust_val = 0;
1293         btcoexist->btc_set(btcoexist,
1294                 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1295
1296
1297         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1298                 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
1299                     btcoexist->btc_read_4byte(btcoexist, 0x948),
1300                     btcoexist->btc_read_1byte(btcoexist, 0x765),
1301                     btcoexist->btc_read_1byte(btcoexist, 0x67));
1302         BTC_TRACE(trace_buf);
1303         /* update pre state */
1304         coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1305         coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1306 }
1307
1308 void halbtc8192e1ant_coex_all_off(IN struct btc_coexist *btcoexist)
1309 {
1310         /* sw all off */
1311         halbtc8192e1ant_sw_mechanism(btcoexist, false);
1312
1313         /* hw all off */
1314         halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1315 }
1316
1317 boolean halbtc8192e1ant_is_common_action(IN struct btc_coexist *btcoexist)
1318 {
1319         boolean                 common = false, wifi_connected = false, wifi_busy = false;
1320
1321         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1322                            &wifi_connected);
1323         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1324
1325         if (!wifi_connected &&
1326             BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1327             coex_dm->bt_status) {
1328                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1329                         "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1330                 BTC_TRACE(trace_buf);
1331                 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1332
1333                 common = true;
1334         } else if (wifi_connected &&
1335                    (BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1336                     coex_dm->bt_status)) {
1337                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1338                         "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1339                 BTC_TRACE(trace_buf);
1340                 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1341
1342                 common = true;
1343         } else if (!wifi_connected &&
1344                 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1345                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1346                         "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1347                 BTC_TRACE(trace_buf);
1348                 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1349
1350                 common = true;
1351         } else if (wifi_connected &&
1352                 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1353                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1354                             "[BTCoex], Wifi connected + BT connected-idle!!\n");
1355                 BTC_TRACE(trace_buf);
1356                 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1357
1358                 common = true;
1359         } else if (!wifi_connected &&
1360                 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
1361                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1362                             "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1363                 BTC_TRACE(trace_buf);
1364                 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1365
1366                 common = true;
1367         } else {
1368                 if (wifi_busy) {
1369                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1370                                 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1371                         BTC_TRACE(trace_buf);
1372                 } else {
1373                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1374                                 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1375                         BTC_TRACE(trace_buf);
1376                 }
1377
1378                 common = false;
1379         }
1380
1381         return common;
1382 }
1383
1384
1385 void halbtc8192e1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist
1386                 *btcoexist, IN u8 wifi_status)
1387 {
1388         static s32              up, dn, m, n, wait_count;
1389         s32                     result;   /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1390         u8                      retry_count = 0, bt_info_ext;
1391         boolean                 wifi_busy = false;
1392         /*static boolean        pre_wifi_busy = false;*/
1393
1394         if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status)
1395                 wifi_busy = true;
1396         else
1397                 wifi_busy = false;
1398
1399         if ((BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
1400              wifi_status) ||
1401             (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
1402             (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT ==
1403              wifi_status)) {
1404                 if (coex_dm->cur_ps_tdma != 1 &&
1405                     coex_dm->cur_ps_tdma != 2 &&
1406                     coex_dm->cur_ps_tdma != 3 &&
1407                     coex_dm->cur_ps_tdma != 9) {
1408                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1409                                                 9);
1410                         coex_dm->ps_tdma_du_adj_type = 9;
1411
1412                         up = 0;
1413                         dn = 0;
1414                         m = 1;
1415                         n = 3;
1416                         result = 0;
1417                         wait_count = 0;
1418                 }
1419                 return;
1420         }
1421
1422         if (!coex_dm->auto_tdma_adjust) {
1423                 coex_dm->auto_tdma_adjust = true;
1424
1425                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1426                 coex_dm->ps_tdma_du_adj_type = 2;
1427                 /* ============ */
1428                 up = 0;
1429                 dn = 0;
1430                 m = 1;
1431                 n = 3;
1432                 result = 0;
1433                 wait_count = 0;
1434         } else {
1435                 /* accquire the BT TRx retry count from BT_Info byte2 */
1436                 retry_count = coex_sta->bt_retry_cnt;
1437                 bt_info_ext = coex_sta->bt_info_ext;
1438
1439                 if ((coex_sta->low_priority_tx) > 1050 ||
1440                     (coex_sta->low_priority_rx) > 1250)
1441                         retry_count++;
1442
1443                 result = 0;
1444                 wait_count++;
1445
1446                 if (retry_count ==
1447                     0) { /* no retry in the last 2-second duration */
1448                         up++;
1449                         dn--;
1450
1451                         if (dn <= 0)
1452                                 dn = 0;
1453
1454                         if (up >= n) {  /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
1455                                 wait_count = 0;
1456                                 n = 3;
1457                                 up = 0;
1458                                 dn = 0;
1459                                 result = 1;
1460                         }
1461                 } else if (retry_count <=
1462                            3) { /* <=3 retry in the last 2-second duration */
1463                         up--;
1464                         dn++;
1465
1466                         if (up <= 0)
1467                                 up = 0;
1468
1469                         if (dn == 2) {  /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
1470                                 if (wait_count <= 2)
1471                                         m++; /* to avoid loop between the two levels */
1472                                 else
1473                                         m = 1;
1474
1475                                 if (m >= 20)  /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
1476                                         m = 20;
1477
1478                                 n = 3 * m;
1479                                 up = 0;
1480                                 dn = 0;
1481                                 wait_count = 0;
1482                                 result = -1;
1483                         }
1484                 } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
1485                         if (wait_count == 1)
1486                                 m++; /* to avoid loop between the two levels */
1487                         else
1488                                 m = 1;
1489
1490                         if (m >= 20)  /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
1491                                 m = 20;
1492
1493                         n = 3 * m;
1494                         up = 0;
1495                         dn = 0;
1496                         wait_count = 0;
1497                         result = -1;
1498                 }
1499
1500                 if (result == -1) {
1501                         if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
1502                             ((coex_dm->cur_ps_tdma == 1) ||
1503                              (coex_dm->cur_ps_tdma == 2))) {
1504                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1505                                                         true, 9);
1506                                 coex_dm->ps_tdma_du_adj_type = 9;
1507                         } else if (coex_dm->cur_ps_tdma == 1) {
1508                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1509                                                         true, 2);
1510                                 coex_dm->ps_tdma_du_adj_type = 2;
1511                         } else if (coex_dm->cur_ps_tdma == 2) {
1512                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1513                                                         true, 9);
1514                                 coex_dm->ps_tdma_du_adj_type = 9;
1515                         } else if (coex_dm->cur_ps_tdma == 9) {
1516                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1517                                                         true, 11);
1518                                 coex_dm->ps_tdma_du_adj_type = 11;
1519                         }
1520                 } else if (result == 1) {
1521                         if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
1522                             ((coex_dm->cur_ps_tdma == 1) ||
1523                              (coex_dm->cur_ps_tdma == 2))) {
1524                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1525                                                         true, 9);
1526                                 coex_dm->ps_tdma_du_adj_type = 9;
1527                         } else if (coex_dm->cur_ps_tdma == 11) {
1528                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1529                                                         true, 9);
1530                                 coex_dm->ps_tdma_du_adj_type = 9;
1531                         } else if (coex_dm->cur_ps_tdma == 9) {
1532                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1533                                                         true, 2);
1534                                 coex_dm->ps_tdma_du_adj_type = 2;
1535                         } else if (coex_dm->cur_ps_tdma == 2) {
1536                                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1537                                                         true, 1);
1538                                 coex_dm->ps_tdma_du_adj_type = 1;
1539                         }
1540                 } else { /* no change */
1541                         /* Bryant Modify
1542                         if(wifi_busy != pre_wifi_busy)
1543                         {
1544                                 pre_wifi_busy = wifi_busy;
1545                                 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma);
1546                         }
1547                         */
1548                 }
1549
1550                 if (coex_dm->cur_ps_tdma != 1 &&
1551                     coex_dm->cur_ps_tdma != 2 &&
1552                     coex_dm->cur_ps_tdma != 9 &&
1553                     coex_dm->cur_ps_tdma != 11) {
1554                         /* recover to previous adjust type */
1555                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1556                                                 coex_dm->ps_tdma_du_adj_type);
1557                 }
1558         }
1559 }
1560
1561 void halbtc8192e1ant_ps_tdma_check_for_power_save_state(
1562         IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1563 {
1564         u8      lps_mode = 0x0;
1565
1566         btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1567
1568         if (lps_mode) { /* already under LPS state */
1569                 if (new_ps_state) {
1570                         /* keep state under LPS, do nothing. */
1571                 } else {
1572                         /* will leave LPS state, turn off psTdma first */
1573                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1574                                                 0);
1575                 }
1576         } else {                                        /* NO PS state */
1577                 if (new_ps_state) {
1578                         /* will enter LPS state, turn off psTdma first */
1579                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1580                                                 0);
1581                 } else {
1582                         /* keep state under NO PS state, do nothing. */
1583                 }
1584         }
1585 }
1586
1587 void halbtc8192e1ant_power_save_state(IN struct btc_coexist *btcoexist,
1588                               IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1589 {
1590         boolean         low_pwr_disable = false;
1591
1592         switch (ps_type) {
1593         case BTC_PS_WIFI_NATIVE:
1594                 /* recover to original 32k low power setting */
1595                 low_pwr_disable = false;
1596                 btcoexist->btc_set(btcoexist,
1597                                    BTC_SET_ACT_DISABLE_LOW_POWER,
1598                                    &low_pwr_disable);
1599                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1600                                    NULL);
1601                 coex_sta->force_lps_on = false;
1602                 break;
1603         case BTC_PS_LPS_ON:
1604                 halbtc8192e1ant_ps_tdma_check_for_power_save_state(
1605                         btcoexist, true);
1606                 halbtc8192e1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1607                                          lps_val, rpwm_val);
1608                 /* when coex force to enter LPS, do not enter 32k low power. */
1609                 low_pwr_disable = true;
1610                 btcoexist->btc_set(btcoexist,
1611                                    BTC_SET_ACT_DISABLE_LOW_POWER,
1612                                    &low_pwr_disable);
1613                 /* power save must executed before psTdma.                       */
1614                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1615                                    NULL);
1616                 coex_sta->force_lps_on = true;
1617                 break;
1618         case BTC_PS_LPS_OFF:
1619                 halbtc8192e1ant_ps_tdma_check_for_power_save_state(
1620                         btcoexist, false);
1621                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1622                                    NULL);
1623                 coex_sta->force_lps_on = false;
1624                 break;
1625         default:
1626                 break;
1627         }
1628 }
1629
1630 void halbtc8192e1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1631 {
1632         halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1633         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
1634 }
1635
1636 void halbtc8192e1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1637 {
1638         static u32              bt_disable_cnt = 0;
1639         boolean                 bt_active = true, bt_disabled = false;
1640
1641         /* This function check if bt is disabled */
1642
1643         if (coex_sta->high_priority_tx == 0 &&
1644             coex_sta->high_priority_rx == 0 &&
1645             coex_sta->low_priority_tx == 0 &&
1646             coex_sta->low_priority_rx == 0)
1647                 bt_active = false;
1648         if (coex_sta->high_priority_tx == 0xffff &&
1649             coex_sta->high_priority_rx == 0xffff &&
1650             coex_sta->low_priority_tx == 0xffff &&
1651             coex_sta->low_priority_rx == 0xffff)
1652                 bt_active = false;
1653         if (bt_active) {
1654                 bt_disable_cnt = 0;
1655                 bt_disabled = false;
1656                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1657                                    &bt_disabled);
1658                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1659                             "[BTCoex], BT is enabled !!\n");
1660                 BTC_TRACE(trace_buf);
1661         } else {
1662                 bt_disable_cnt++;
1663                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1664                             "[BTCoex], bt all counters=0, %d times!!\n",
1665                             bt_disable_cnt);
1666                 BTC_TRACE(trace_buf);
1667                 if (bt_disable_cnt >= 2) {
1668                         bt_disabled = true;
1669                         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1670                                            &bt_disabled);
1671                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1672                                     "[BTCoex], BT is disabled !!\n");
1673                         BTC_TRACE(trace_buf);
1674                         halbtc8192e1ant_action_wifi_only(btcoexist);
1675                 }
1676         }
1677         if (coex_sta->bt_disabled != bt_disabled) {
1678                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1679                             "[BTCoex], BT is from %s to %s!!\n",
1680                             (coex_sta->bt_disabled ? "disabled" : "enabled"),
1681                             (bt_disabled ? "disabled" : "enabled"));
1682                 BTC_TRACE(trace_buf);
1683                 coex_sta->bt_disabled = bt_disabled;
1684                 if (!bt_disabled) {
1685                 } else {
1686                         btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1687                                            NULL);
1688                         btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1689                                            NULL);
1690                 }
1691         }
1692 }
1693
1694 /* *********************************************
1695  *
1696  *      Software Coex Mechanism start
1697  *
1698  * ********************************************* */
1699
1700 /* SCO only or SCO+PAN(HS) */
1701
1702 /*
1703 void halbtc8192e1ant_action_sco(IN struct btc_coexist* btcoexist)
1704 {
1705         halbtc8192e1ant_sw_mechanism(btcoexist, true);
1706 }
1707
1708
1709 void halbtc8192e1ant_action_hid(IN struct btc_coexist* btcoexist)
1710 {
1711         halbtc8192e1ant_sw_mechanism(btcoexist, true);
1712 }
1713
1714
1715 void halbtc8192e1ant_action_a2dp(IN struct btc_coexist* btcoexist)
1716 {
1717         halbtc8192e1ant_sw_mechanism(btcoexist, false);
1718 }
1719
1720 void halbtc8192e1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
1721 {
1722         halbtc8192e1ant_sw_mechanism(btcoexist, false);
1723 }
1724
1725 void halbtc8192e1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
1726 {
1727         halbtc8192e1ant_sw_mechanism(btcoexist, false);
1728 }
1729
1730
1731 void halbtc8192e1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
1732 {
1733         halbtc8192e1ant_sw_mechanism(btcoexist, false);
1734 }
1735
1736
1737 void halbtc8192e1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
1738 {
1739         halbtc8192e1ant_sw_mechanism(btcoexist, false);
1740 }
1741
1742 void halbtc8192e1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
1743 {
1744         halbtc8192e1ant_sw_mechanism(btcoexist, true);
1745 }
1746
1747
1748 void halbtc8192e1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
1749 {
1750         halbtc8192e1ant_sw_mechanism(btcoexist, true);
1751 }
1752
1753 void halbtc8192e1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
1754 {
1755         halbtc8192e1ant_sw_mechanism(btcoexist, true);
1756 }
1757
1758 */
1759
1760 /* *********************************************
1761  *
1762  *      Non-Software Coex Mechanism start
1763  *
1764  * ********************************************* */
1765 void halbtc8192e1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1766 {
1767         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1768                                          0x0);
1769
1770         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1771         halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1772 }
1773
1774 void halbtc8192e1ant_action_hs(IN struct btc_coexist *btcoexist)
1775 {
1776         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1777         halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1778 }
1779
1780 void halbtc8192e1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1781 {
1782         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1783         boolean                 wifi_connected = false, ap_enable = false, wifi_busy = false,
1784                                 bt_busy = false;
1785
1786         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1787                            &ap_enable);
1788         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1789                            &wifi_connected);
1790         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1791         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1792
1793         if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1794                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1795                                                  0x0, 0x0);
1796                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1797
1798                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1799         } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1800                    (bt_link_info->a2dp_exist)) {
1801                 /* SCO/HID/A2DP  busy */
1802                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1803                                                  0x0, 0x0);
1804                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1805
1806                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1807         } else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1808                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1809                                                  0x0, 0x0);
1810                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1811
1812                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1813         } else {
1814                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1815                                                  0x0, 0x0);
1816                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1817
1818                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1819         }
1820 }
1821
1822 void halbtc8192e1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1823                 *btcoexist, IN u8 wifi_status)
1824 {
1825         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1826         boolean wifi_connected = false;
1827
1828         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1829                            &wifi_connected);
1830
1831         /* tdma and coex table */
1832
1833         if (bt_link_info->sco_exist) {
1834                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1835                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1836         } else { /* HID */
1837                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1838                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1839         }
1840 }
1841
1842 void halbtc8192e1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1843                 *btcoexist, IN u8 wifi_status)
1844 {
1845         u8              bt_rssi_state;
1846
1847         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1848         bt_rssi_state = halbtc8192e1ant_bt_rssi_state(2, 28, 0);
1849
1850         if ((coex_sta->low_priority_rx >= 1000)  &&
1851             (coex_sta->low_priority_rx != 65535))
1852                 bt_link_info->slave_role = true;
1853         else
1854                 bt_link_info->slave_role = false;
1855
1856         if (bt_link_info->hid_only) { /* HID */
1857                 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
1858                                 wifi_status);
1859                 coex_dm->auto_tdma_adjust = false;
1860                 return;
1861         } else if (bt_link_info->a2dp_only) { /* A2DP            */
1862                 if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1863                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1864                                                 32);
1865                         halbtc8192e1ant_coex_table_with_type(btcoexist,
1866                                                              NORMAL_EXEC, 4);
1867                         coex_dm->auto_tdma_adjust = false;
1868                 } else {
1869                         halbtc8192e1ant_tdma_duration_adjust_for_acl(btcoexist,
1870                                         wifi_status);
1871 #if 0
1872                         if (coex_sta->cck_lock)
1873                                 halbtc8192e1ant_coex_table_with_type(btcoexist,
1874                                                              NORMAL_EXEC, 3);
1875                         else
1876 #endif
1877                                 halbtc8192e1ant_coex_table_with_type(btcoexist,
1878                                                              NORMAL_EXEC, 4);
1879                         coex_dm->auto_tdma_adjust = true;
1880                 }
1881         } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1882                    (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1883                 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1884                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
1885                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1886                 coex_dm->auto_tdma_adjust = false;
1887         } else if (bt_link_info->hid_exist &&
1888                    bt_link_info->a2dp_exist) { /* HID+A2DP */
1889                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1890                 coex_dm->auto_tdma_adjust = false;
1891
1892                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
1893         } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1894                 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP)                    */
1895                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1896                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1897                 coex_dm->auto_tdma_adjust = false;
1898         } else {
1899                 /* BT no-profile busy (0x9) */
1900                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1901                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1902                 coex_dm->auto_tdma_adjust = false;
1903         }
1904 }
1905
1906 void halbtc8192e1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1907 {
1908         /* power save state */
1909         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1910                                          0x0);
1911
1912         /* tdma and coex table */
1913         halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1914         halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1915 }
1916
1917 void halbtc8192e1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1918                 *btcoexist)
1919 {
1920         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1921
1922         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1923                                          0x0);
1924
1925         /* tdma and coex table */
1926         if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1927                 if (bt_link_info->a2dp_exist) {
1928                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1929                                                 32);
1930                         halbtc8192e1ant_coex_table_with_type(btcoexist,
1931                                                              NORMAL_EXEC, 4);
1932                 } else if (bt_link_info->a2dp_exist &&
1933                            bt_link_info->pan_exist) {
1934                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1935                                                 22);
1936                         halbtc8192e1ant_coex_table_with_type(btcoexist,
1937                                                              NORMAL_EXEC, 4);
1938                 } else {
1939                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1940                                                 20);
1941                         halbtc8192e1ant_coex_table_with_type(btcoexist,
1942                                                              NORMAL_EXEC, 4);
1943                 }
1944         } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1945                    (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1946                     coex_dm->bt_status)) {
1947                 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
1948                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1949         } else {
1950                 /* Bryant Add */
1951                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1952                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1953         }
1954 }
1955
1956 void halbtc8192e1ant_action_wifi_not_connected_asso_auth(
1957         IN struct btc_coexist *btcoexist)
1958 {
1959         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1960
1961         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1962                                          0x0);
1963
1964         /* tdma and coex table */
1965         if ((bt_link_info->sco_exist)  || (bt_link_info->hid_exist) ||
1966             (bt_link_info->a2dp_exist)) {
1967                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1968                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1969         } else if (bt_link_info->pan_exist) {
1970                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1971                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1972         } else {
1973                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1974                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1975         }
1976 }
1977
1978 void halbtc8192e1ant_action_wifi_connected_scan(IN struct btc_coexist
1979                 *btcoexist)
1980 {
1981         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1982
1983         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1984                                          0x0);
1985
1986         /* tdma and coex table */
1987         if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1988                 if (bt_link_info->a2dp_exist) {
1989                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1990                                                 32);
1991                         halbtc8192e1ant_coex_table_with_type(btcoexist,
1992                                                              NORMAL_EXEC, 4);
1993                 } else if (bt_link_info->a2dp_exist &&
1994                            bt_link_info->pan_exist) {
1995                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1996                                                 22);
1997                         halbtc8192e1ant_coex_table_with_type(btcoexist,
1998                                                              NORMAL_EXEC, 4);
1999                 } else {
2000                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2001                                                 20);
2002                         halbtc8192e1ant_coex_table_with_type(btcoexist,
2003                                                              NORMAL_EXEC, 4);
2004                 }
2005         } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2006                    (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2007                     coex_dm->bt_status)) {
2008                 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
2009                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2010         } else {
2011                 /* Bryant Add */
2012                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2013                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2014         }
2015 }
2016
2017 void halbtc8192e1ant_action_wifi_connected_specific_packet(
2018         IN struct btc_coexist *btcoexist)
2019 {
2020         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2021
2022         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
2023                                          0x0);
2024
2025         /* tdma and coex table */
2026         if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
2027             (bt_link_info->a2dp_exist)) {
2028                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2029                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2030         } else if (bt_link_info->pan_exist) {
2031                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
2032                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2033         } else {
2034                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2035                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2036         }
2037 }
2038
2039 void halbtc8192e1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
2040 {
2041         boolean wifi_busy = false;
2042         boolean         scan = false, link = false, roam = false;
2043         boolean         under_4way = false, ap_enable = false;
2044
2045         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2046                     "[BTCoex], CoexForWifiConnect()===>\n");
2047         BTC_TRACE(trace_buf);
2048
2049         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
2050                            &under_4way);
2051         if (under_4way) {
2052                 halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist);
2053                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2054                         "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2055                 BTC_TRACE(trace_buf);
2056                 return;
2057         }
2058
2059         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2060         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2061         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2062         if (scan || link || roam) {
2063                 if (scan)
2064                         halbtc8192e1ant_action_wifi_connected_scan(btcoexist);
2065                 else
2066                         halbtc8192e1ant_action_wifi_connected_specific_packet(
2067                                 btcoexist);
2068                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2069                         "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2070                 BTC_TRACE(trace_buf);
2071                 return;
2072         }
2073
2074         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2075                            &ap_enable);
2076         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2077
2078         /* power save state */
2079         if (!ap_enable &&
2080             BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
2081             !btcoexist->bt_link_info.hid_only) {
2082                 if (btcoexist->bt_link_info.a2dp_only) {        /* A2DP */
2083                         if (!wifi_busy)
2084                                 halbtc8192e1ant_power_save_state(btcoexist,
2085                                                  BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2086                         else { /* busy */
2087                                 if (coex_sta->scan_ap_num >=
2088                                     BT_8192E_1ANT_WIFI_NOISY_THRESH)  /* no force LPS, no PS-TDMA, use pure TDMA */
2089                                         halbtc8192e1ant_power_save_state(
2090                                                 btcoexist, BTC_PS_WIFI_NATIVE,
2091                                                 0x0, 0x0);
2092                                 else
2093                                         halbtc8192e1ant_power_save_state(
2094                                                 btcoexist, BTC_PS_LPS_ON, 0x50,
2095                                                 0x4);
2096                         }
2097                 } else if ((coex_sta->pan_exist == false) &&
2098                            (coex_sta->a2dp_exist == false) &&
2099                            (coex_sta->hid_exist == false))
2100                         halbtc8192e1ant_power_save_state(btcoexist,
2101                                                  BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2102                 else
2103                         halbtc8192e1ant_power_save_state(btcoexist,
2104                                                  BTC_PS_LPS_ON, 0x50, 0x4);
2105         } else
2106                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2107                                                  0x0, 0x0);
2108
2109         /* tdma and coex table */
2110         if (!wifi_busy) {
2111                 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2112                         halbtc8192e1ant_action_wifi_connected_bt_acl_busy(
2113                                 btcoexist,
2114                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2115                 } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY ==
2116                             coex_dm->bt_status) ||
2117                            (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2118                             coex_dm->bt_status)) {
2119                         halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
2120                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2121                 } else {
2122                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2123                                                 8);
2124
2125                         if ((coex_sta->high_priority_tx) +
2126                             (coex_sta->high_priority_rx) <= 60)
2127                                 halbtc8192e1ant_coex_table_with_type(btcoexist,
2128                                                              NORMAL_EXEC, 2);
2129                         else
2130                                 halbtc8192e1ant_coex_table_with_type(btcoexist,
2131                                                              NORMAL_EXEC, 7);
2132                 }
2133         } else {
2134                 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2135                         halbtc8192e1ant_action_wifi_connected_bt_acl_busy(
2136                                 btcoexist,
2137                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2138                 } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY ==
2139                             coex_dm->bt_status) ||
2140                            (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2141                             coex_dm->bt_status)) {
2142                         halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
2143                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2144                 } else {
2145                         halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2146                                                 8);
2147
2148                         if ((coex_sta->high_priority_tx) +
2149                             (coex_sta->high_priority_rx) <= 60)
2150                                 halbtc8192e1ant_coex_table_with_type(btcoexist,
2151                                                              NORMAL_EXEC, 2);
2152                         else
2153                                 halbtc8192e1ant_coex_table_with_type(btcoexist,
2154                                                              NORMAL_EXEC, 7);
2155                 }
2156         }
2157 }
2158
2159 void halbtc8192e1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
2160 {
2161         u8                              algorithm = 0;
2162
2163         algorithm = halbtc8192e1ant_action_algorithm(btcoexist);
2164         coex_dm->cur_algorithm = algorithm;
2165
2166         if (halbtc8192e1ant_is_common_action(btcoexist)) {
2167
2168         } else {
2169                 switch (coex_dm->cur_algorithm) {
2170                 case BT_8192E_1ANT_COEX_ALGO_SCO:
2171                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2172                                     "[BTCoex], Action algorithm = SCO.\n");
2173                         BTC_TRACE(trace_buf);
2174                         /* halbtc8192e1ant_action_sco(btcoexist); */
2175                         break;
2176                 case BT_8192E_1ANT_COEX_ALGO_HID:
2177                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2178                                     "[BTCoex], Action algorithm = HID.\n");
2179                         BTC_TRACE(trace_buf);
2180                         /* halbtc8192e1ant_action_hid(btcoexist); */
2181                         break;
2182                 case BT_8192E_1ANT_COEX_ALGO_A2DP:
2183                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2184                                     "[BTCoex], Action algorithm = A2DP.\n");
2185                         BTC_TRACE(trace_buf);
2186                         /* halbtc8192e1ant_action_a2dp(btcoexist); */
2187                         break;
2188                 case BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS:
2189                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2190                                 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
2191                         BTC_TRACE(trace_buf);
2192                         /* halbtc8192e1ant_action_a2dp_pan_hs(btcoexist); */
2193                         break;
2194                 case BT_8192E_1ANT_COEX_ALGO_PANEDR:
2195                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2196                                     "[BTCoex], Action algorithm = PAN(EDR).\n");
2197                         BTC_TRACE(trace_buf);
2198                         /* halbtc8192e1ant_action_pan_edr(btcoexist); */
2199                         break;
2200                 case BT_8192E_1ANT_COEX_ALGO_PANHS:
2201                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2202                                     "[BTCoex], Action algorithm = HS mode.\n");
2203                         BTC_TRACE(trace_buf);
2204                         /* halbtc8192e1ant_action_pan_hs(btcoexist); */
2205                         break;
2206                 case BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP:
2207                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2208                                     "[BTCoex], Action algorithm = PAN+A2DP.\n");
2209                         BTC_TRACE(trace_buf);
2210                         /* halbtc8192e1ant_action_pan_edr_a2dp(btcoexist); */
2211                         break;
2212                 case BT_8192E_1ANT_COEX_ALGO_PANEDR_HID:
2213                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2214                                 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
2215                         BTC_TRACE(trace_buf);
2216                         /* halbtc8192e1ant_action_pan_edr_hid(btcoexist); */
2217                         break;
2218                 case BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2219                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2220                                 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
2221                         BTC_TRACE(trace_buf);
2222                         /* halbtc8192e1ant_action_hid_a2dp_pan_edr(btcoexist); */
2223                         break;
2224                 case BT_8192E_1ANT_COEX_ALGO_HID_A2DP:
2225                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2226                                     "[BTCoex], Action algorithm = HID+A2DP.\n");
2227                         BTC_TRACE(trace_buf);
2228                         /* halbtc8192e1ant_action_hid_a2dp(btcoexist); */
2229                         break;
2230                 default:
2231                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2232                                 "[BTCoex], Action algorithm = coexist All Off!!\n");
2233                         BTC_TRACE(trace_buf);
2234                         /* halbtc8192e1ant_coex_all_off(btcoexist); */
2235                         break;
2236                 }
2237                 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2238         }
2239 }
2240
2241 void halbtc8192e1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2242 {
2243         struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2244         boolean wifi_connected = false, bt_hs_on = false;
2245         boolean increase_scan_dev_num = false;
2246         boolean bt_ctrl_agg_buf_size = false;
2247         boolean miracast_plus_bt = false;
2248         u8      agg_buf_size = 5;
2249         u32     wifi_link_status = 0;
2250         u32     num_of_wifi_link = 0;
2251
2252         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2253                     "[BTCoex], RunCoexistMechanism()===>\n");
2254         BTC_TRACE(trace_buf);
2255
2256         if (btcoexist->manual_control) {
2257                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2258                         "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2259                 BTC_TRACE(trace_buf);
2260                 return;
2261         }
2262
2263         if (btcoexist->stop_coex_dm) {
2264                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2265                         "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2266                 BTC_TRACE(trace_buf);
2267                 return;
2268         }
2269
2270         if (coex_sta->under_ips) {
2271                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2272                             "[BTCoex], wifi is under IPS !!!\n");
2273                 BTC_TRACE(trace_buf);
2274                 return;
2275         }
2276
2277         if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2278             (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2279             (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2280                 increase_scan_dev_num = true;
2281
2282         btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2283                            &increase_scan_dev_num);
2284         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2285                            &wifi_connected);
2286
2287         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2288                            &wifi_link_status);
2289         num_of_wifi_link = wifi_link_status >> 16;
2290
2291         if ((num_of_wifi_link >= 2) ||
2292             (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2293                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2294                         "############# [BTCoex],  Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
2295                             num_of_wifi_link, wifi_link_status);
2296                 BTC_TRACE(trace_buf);
2297
2298                 if (bt_link_info->bt_link_exist) {
2299                         halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
2300                                                    0, 1);
2301                         miracast_plus_bt = true;
2302                 } else {
2303                         halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2304                                                    0, 0);
2305                         miracast_plus_bt = false;
2306                 }
2307                 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
2308                                    &miracast_plus_bt);
2309                 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2310                                            bt_ctrl_agg_buf_size, agg_buf_size);
2311
2312                 if ((bt_link_info->a2dp_exist) &&
2313                     (coex_sta->c2h_bt_inquiry_page)) {
2314                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2315                                 "############# [BTCoex],  BT Is Inquirying\n");
2316                         BTC_TRACE(trace_buf);
2317                         halbtc8192e1ant_action_bt_inquiry(btcoexist);
2318                 } else
2319                         halbtc8192e1ant_action_wifi_multi_port(btcoexist);
2320
2321                 return;
2322         } else {
2323                 miracast_plus_bt = false;
2324                 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
2325                                    &miracast_plus_bt);
2326         }
2327
2328         if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
2329                 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
2330
2331                 if (bt_link_info->sco_exist)
2332                         halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC,
2333                                                    false, true, 0x5);
2334                 else
2335                         halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC,
2336                                                    false, true, 0x8);
2337
2338                 halbtc8192e1ant_sw_mechanism(btcoexist, true);
2339                 halbtc8192e1ant_run_sw_coexist_mechanism(
2340                         btcoexist);  /* just print debug message */
2341         } else {
2342                 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2343
2344                 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2345                                            0x5);
2346
2347                 halbtc8192e1ant_sw_mechanism(btcoexist, false);
2348                 halbtc8192e1ant_run_sw_coexist_mechanism(
2349                         btcoexist); /* just print debug message */
2350         }
2351
2352         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2353         if (coex_sta->c2h_bt_inquiry_page) {
2354                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2355                             "############# [BTCoex],  BT Is Inquirying\n");
2356                 BTC_TRACE(trace_buf);
2357                 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2358                 return;
2359         } else if (bt_hs_on) {
2360                 halbtc8192e1ant_action_hs(btcoexist);
2361                 return;
2362         }
2363
2364
2365         if (!wifi_connected) {
2366                 boolean scan = false, link = false, roam = false;
2367
2368                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2369                             "[BTCoex], wifi is non connected-idle !!!\n");
2370                 BTC_TRACE(trace_buf);
2371
2372                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2373                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2374                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2375
2376                 if (scan || link || roam) {
2377                         if (scan)
2378                                 halbtc8192e1ant_action_wifi_not_connected_scan(
2379                                         btcoexist);
2380                         else
2381                                 halbtc8192e1ant_action_wifi_not_connected_asso_auth(
2382                                         btcoexist);
2383                 } else
2384                         halbtc8192e1ant_action_wifi_not_connected(btcoexist);
2385         } else  /* wifi LPS/Busy */
2386                 halbtc8192e1ant_action_wifi_connected(btcoexist);
2387 }
2388
2389 void halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2390 {
2391         /* force to reset coex mechanism */
2392
2393         /* sw all off */
2394         halbtc8192e1ant_sw_mechanism(btcoexist, false);
2395
2396         /* halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2397         halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2398
2399         coex_sta->pop_event_cnt = 0;
2400 }
2401
2402 void halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2403                                     IN boolean wifi_only)
2404 {
2405         u16     u16tmp = 0;
2406         u8      u8tmp = 0;
2407
2408         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2409                     "[BTCoex], 1Ant Init HW Config!!\n");
2410         BTC_TRACE(trace_buf);
2411
2412         /* antenna sw ctrl to bt */
2413         halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true, false);
2414
2415         halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2416
2417         /* antenna switch control parameter */
2418         btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555);
2419
2420         /* coex parameters */
2421         btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
2422         /* 0x790[5:0]=0x5 */
2423         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2424         u8tmp &= 0xc0;
2425         u8tmp |= 0x5;
2426         btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2427
2428         /* enable counter statistics */
2429         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
2430
2431         /* enable PTA */
2432         btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
2433         /* enable mailbox interface */
2434         u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x40);
2435         u16tmp |= BIT(9);
2436         btcoexist->btc_write_2byte(btcoexist, 0x40, u16tmp);
2437
2438         /* enable PTA I2C mailbox */
2439         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x101);
2440         u8tmp |= BIT(4);
2441         btcoexist->btc_write_1byte(btcoexist, 0x101, u8tmp);
2442
2443         /* enable bt clock when wifi is disabled. */
2444         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x93);
2445         u8tmp |= BIT(0);
2446         btcoexist->btc_write_1byte(btcoexist, 0x93, u8tmp);
2447         /* enable bt clock when suspend. */
2448         u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
2449         u8tmp |= BIT(0);
2450         btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
2451 }
2452
2453
2454 /*
2455 void halbtc8192e1ant_wifi_off_hw_cfg(IN struct btc_coexist* btcoexist)
2456 {
2457
2458
2459 }
2460 */
2461
2462 /* ************************************************************
2463  * work around function start with wa_halbtc8192e1ant_
2464  * ************************************************************
2465  * ************************************************************
2466  * extern function start with ex_halbtc8192e1ant_
2467  * ************************************************************ */
2468 void ex_halbtc8192e1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2469 {
2470 #if 0
2471         struct  btc_board_info  *board_info = &btcoexist->board_info;
2472         u8 u8tmp = 0x0;
2473         u16 u16tmp = 0x0;
2474
2475         btcoexist->stop_coex_dm = true;
2476
2477         btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20);
2478
2479         /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2480         u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
2481         btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
2482
2483         /* set GRAN_BT = 1 */
2484         btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
2485         /* set WLAN_ACT = 0 */
2486         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
2487
2488         /*  */
2489         /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
2490         /* Local setting bit define */
2491         /*      BIT0: "0" for no antenna inverse; "1" for antenna inverse  */
2492         /*      BIT1: "0" for internal switch; "1" for external switch */
2493         /*      BIT2: "0" for one antenna; "1" for two antenna */
2494         /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
2495         if (btcoexist->chip_interface == BTC_INTF_USB) {
2496                 /* fixed at S0 for USB interface */
2497                 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
2498
2499                 u8tmp |= 0x1;   /* antenna inverse */
2500                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
2501
2502                 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2503         } else {
2504                 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2505                 if (board_info->single_ant_path == 0) {
2506                         /* set to S1 */
2507                         btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280);
2508                         board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2509                 } else if (board_info->single_ant_path == 1) {
2510                         /* set to S0 */
2511                         btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
2512                         u8tmp |= 0x1;   /* antenna inverse */
2513                         board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2514                 }
2515
2516                 if (btcoexist->chip_interface == BTC_INTF_PCI)
2517                         btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
2518                                                              u8tmp);
2519                 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
2520                         btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
2521                                                              u8tmp);
2522         }
2523 #endif
2524 }
2525
2526 void ex_halbtc8192e1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
2527 {
2528 }
2529
2530 void ex_halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2531                                        IN boolean wifi_only)
2532 {
2533         halbtc8192e1ant_init_hw_config(btcoexist, wifi_only);
2534         btcoexist->stop_coex_dm = false;
2535 }
2536
2537 void ex_halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2538 {
2539         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2540                     "[BTCoex], Coex Mechanism Init!!\n");
2541         BTC_TRACE(trace_buf);
2542
2543         btcoexist->stop_coex_dm = false;
2544
2545         halbtc8192e1ant_init_coex_dm(btcoexist);
2546
2547         halbtc8192e1ant_query_bt_info(btcoexist);
2548 }
2549
2550 void ex_halbtc8192e1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2551 {
2552         struct  btc_board_info          *board_info = &btcoexist->board_info;
2553         struct  btc_bt_link_info        *bt_link_info = &btcoexist->bt_link_info;
2554         u8                              *cli_buf = btcoexist->cli_buf;
2555         u8                              u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2556         u32                             u32tmp[4];
2557         u32                             fw_ver = 0, bt_patch_ver = 0;
2558
2559         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2560                    "\r\n ============[BT Coexist info]============");
2561         CL_PRINTF(cli_buf);
2562
2563         if (btcoexist->manual_control) {
2564                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2565                         "\r\n ============[Under Manual Control]============");
2566                 CL_PRINTF(cli_buf);
2567                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2568                            "\r\n ==========================================");
2569                 CL_PRINTF(cli_buf);
2570         }
2571         if (btcoexist->stop_coex_dm) {
2572                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2573                            "\r\n ============[Coex is STOPPED]============");
2574                 CL_PRINTF(cli_buf);
2575                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2576                            "\r\n ==========================================");
2577                 CL_PRINTF(cli_buf);
2578         }
2579
2580         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
2581                    "Ant PG number/ Ant mechanism:",
2582                    board_info->pg_ant_num, board_info->btdm_ant_num);
2583         CL_PRINTF(cli_buf);
2584
2585         btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
2586         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2587         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2588                    "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
2589                    "CoexVer/ FwVer/ PatchVer",
2590                    glcoex_ver_date_8192e_1ant, glcoex_ver_8192e_1ant, fw_ver,
2591                    bt_patch_ver, bt_patch_ver);
2592         CL_PRINTF(cli_buf);
2593
2594         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2595                    "Wifi channel informed to BT",
2596                    coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2597                    coex_dm->wifi_chnl_info[2]);
2598         CL_PRINTF(cli_buf);
2599
2600         /* wifi status */
2601         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2602                    "============[Wifi Status]============");
2603         CL_PRINTF(cli_buf);
2604         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2605
2606         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2607                    "============[BT Status]============");
2608         CL_PRINTF(cli_buf);
2609
2610         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2611                    "BT [status/ rssi/ retryCnt]",
2612                    ((coex_sta->bt_disabled) ? ("disabled") :    ((
2613                    coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2614                            : ((BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2615                                coex_dm->bt_status) ? "non-connected idle" :
2616                 ((BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2617                                        ? "connected-idle" : "busy")))),
2618                    coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2619         CL_PRINTF(cli_buf);
2620
2621         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2622                    "SCO/HID/PAN/A2DP",
2623                    bt_link_info->sco_exist, bt_link_info->hid_exist,
2624                    bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2625         CL_PRINTF(cli_buf);
2626         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2627
2628         bt_info_ext = coex_sta->bt_info_ext;
2629         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2630                    "BT Info A2DP rate",
2631                    (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2632         CL_PRINTF(cli_buf);
2633
2634         for (i = 0; i < BT_INFO_SRC_8192E_1ANT_MAX; i++) {
2635                 if (coex_sta->bt_info_c2h_cnt[i]) {
2636                         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2637                                 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2638                                    glbt_info_src_8192e_1ant[i],
2639                                    coex_sta->bt_info_c2h[i][0],
2640                                    coex_sta->bt_info_c2h[i][1],
2641                                    coex_sta->bt_info_c2h[i][2],
2642                                    coex_sta->bt_info_c2h[i][3],
2643                                    coex_sta->bt_info_c2h[i][4],
2644                                    coex_sta->bt_info_c2h[i][5],
2645                                    coex_sta->bt_info_c2h[i][6],
2646                                    coex_sta->bt_info_c2h_cnt[i]);
2647                         CL_PRINTF(cli_buf);
2648                 }
2649         }
2650
2651         if (!btcoexist->manual_control) {
2652                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2653                            "============[mechanisms]============");
2654                 CL_PRINTF(cli_buf);
2655
2656                 ps_tdma_case = coex_dm->cur_ps_tdma;
2657                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2658                         "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2659                            "PS TDMA",
2660                            coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2661                            coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2662                            coex_dm->ps_tdma_para[4], ps_tdma_case,
2663                            coex_dm->auto_tdma_adjust);
2664                 CL_PRINTF(cli_buf);
2665
2666                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2667                            "Latest error condition(should be 0)",
2668                            coex_dm->error_condition);
2669                 CL_PRINTF(cli_buf);
2670
2671                 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2672                            "IgnWlanAct",
2673                            coex_dm->cur_ignore_wlan_act);
2674                 CL_PRINTF(cli_buf);
2675         }
2676
2677         /* Hw setting            */
2678         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2679                    "============[Hw setting]============");
2680         CL_PRINTF(cli_buf);
2681
2682         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc04);
2683         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xd04);
2684         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x90c);
2685         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2686                    "0xc04/ 0xd04/ 0x90c",
2687                    u32tmp[0], u32tmp[1], u32tmp[2]);
2688         CL_PRINTF(cli_buf);
2689
2690         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2691         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778",
2692                    u8tmp[0]);
2693         CL_PRINTF(cli_buf);
2694
2695         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x92c);
2696         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x930);
2697         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2698                    "0x92c/ 0x930",
2699                    (u8tmp[0]), u32tmp[0]);
2700         CL_PRINTF(cli_buf);
2701
2702         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2703         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x4f);
2704         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2705                    "0x40/ 0x4f",
2706                    u8tmp[0], u8tmp[1]);
2707         CL_PRINTF(cli_buf);
2708
2709         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2710         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2711         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2712                    "0x550(bcn ctrl)/0x522",
2713                    u32tmp[0], u8tmp[0]);
2714         CL_PRINTF(cli_buf);
2715
2716         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2717         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2718                    u32tmp[0]);
2719         CL_PRINTF(cli_buf);
2720
2721         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2722         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2723         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2724         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
2725         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2726                    "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2727                    "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
2728                    u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
2729         CL_PRINTF(cli_buf);
2730
2731         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2732                    "0x770(hp rx[31:16]/tx[15:0])",
2733                    coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2734         CL_PRINTF(cli_buf);
2735         CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2736                    "0x774(lp rx[31:16]/tx[15:0])",
2737                    coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2738         CL_PRINTF(cli_buf);
2739 #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 1)
2740         halbtc8192e1ant_monitor_bt_ctr(btcoexist);
2741 #endif
2742
2743         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2744 }
2745
2746 void ex_halbtc8192e1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2747 {
2748         if (btcoexist->manual_control ||        btcoexist->stop_coex_dm)
2749                 return;
2750
2751         if (BTC_IPS_ENTER == type) {
2752                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2753                             "[BTCoex], IPS ENTER notify\n");
2754                 BTC_TRACE(trace_buf);
2755                 coex_sta->under_ips = true;
2756
2757                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2758                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2759                 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2760                                              true);
2761         } else if (BTC_IPS_LEAVE == type) {
2762                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2763                             "[BTCoex], IPS LEAVE notify\n");
2764                 BTC_TRACE(trace_buf);
2765                 coex_sta->under_ips = false;
2766
2767                 halbtc8192e1ant_init_hw_config(btcoexist, false);
2768                 halbtc8192e1ant_init_coex_dm(btcoexist);
2769                 halbtc8192e1ant_query_bt_info(btcoexist);
2770         }
2771 }
2772
2773 void ex_halbtc8192e1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2774 {
2775         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2776                 return;
2777
2778         if (BTC_LPS_ENABLE == type) {
2779                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2780                             "[BTCoex], LPS ENABLE notify\n");
2781                 BTC_TRACE(trace_buf);
2782                 coex_sta->under_lps = true;
2783         } else if (BTC_LPS_DISABLE == type) {
2784                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2785                             "[BTCoex], LPS DISABLE notify\n");
2786                 BTC_TRACE(trace_buf);
2787                 coex_sta->under_lps = false;
2788         }
2789 }
2790
2791 void ex_halbtc8192e1ant_scan_notify(IN struct btc_coexist *btcoexist,
2792                                     IN u8 type)
2793 {
2794         boolean wifi_connected = false, bt_hs_on = false;
2795         u32     wifi_link_status = 0;
2796         u32     num_of_wifi_link = 0;
2797         boolean bt_ctrl_agg_buf_size = false;
2798         u8      agg_buf_size = 5;
2799
2800         u8 u8tmpa, u8tmpb;
2801         u32 u32tmp;
2802
2803         if (btcoexist->manual_control ||
2804             btcoexist->stop_coex_dm)
2805                 return;
2806
2807         if (BTC_SCAN_START == type) {
2808                 coex_sta->wifi_is_high_pri_task = true;
2809                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2810                             "[BTCoex], SCAN START notify\n");
2811                 BTC_TRACE(trace_buf);
2812
2813                 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2814                         8);  /* Force antenna setup for no scan result issue */
2815                 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
2816                 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
2817                 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
2818
2819
2820                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2821                             "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2822                             u32tmp,  u8tmpa, u8tmpb);
2823                 BTC_TRACE(trace_buf);
2824         } else {
2825                 coex_sta->wifi_is_high_pri_task = false;
2826                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2827                             "[BTCoex], SCAN FINISH notify\n");
2828                 BTC_TRACE(trace_buf);
2829
2830                 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2831                                    &coex_sta->scan_ap_num);
2832         }
2833
2834         if (coex_sta->bt_disabled)
2835                 return;
2836
2837         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2838         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2839                            &wifi_connected);
2840
2841         halbtc8192e1ant_query_bt_info(btcoexist);
2842
2843         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2844                            &wifi_link_status);
2845         num_of_wifi_link = wifi_link_status >> 16;
2846         if (num_of_wifi_link >= 2) {
2847                 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2848                 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2849                                            bt_ctrl_agg_buf_size, agg_buf_size);
2850                 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
2851                 return;
2852         }
2853
2854         if (coex_sta->c2h_bt_inquiry_page) {
2855                 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2856                 return;
2857         } else if (bt_hs_on) {
2858                 halbtc8192e1ant_action_hs(btcoexist);
2859                 return;
2860         }
2861
2862         if (BTC_SCAN_START == type) {
2863                 if (!wifi_connected)    /* non-connected scan */
2864                         halbtc8192e1ant_action_wifi_not_connected_scan(
2865                                 btcoexist);
2866                 else    /* wifi is connected */
2867                         halbtc8192e1ant_action_wifi_connected_scan(btcoexist);
2868         } else if (BTC_SCAN_FINISH == type) {
2869                 if (!wifi_connected)    /* non-connected scan */
2870                         halbtc8192e1ant_action_wifi_not_connected(btcoexist);
2871                 else
2872                         halbtc8192e1ant_action_wifi_connected(btcoexist);
2873         }
2874 }
2875
2876 void ex_halbtc8192e1ant_connect_notify(IN struct btc_coexist *btcoexist,
2877                                        IN u8 type)
2878 {
2879         boolean wifi_connected = false, bt_hs_on = false;
2880         u32     wifi_link_status = 0;
2881         u32     num_of_wifi_link = 0;
2882         boolean bt_ctrl_agg_buf_size = false;
2883         u8      agg_buf_size = 5;
2884
2885         if (btcoexist->manual_control ||
2886             btcoexist->stop_coex_dm ||
2887             coex_sta->bt_disabled)
2888                 return;
2889
2890         if (BTC_ASSOCIATE_START == type) {
2891                 coex_sta->wifi_is_high_pri_task = true;
2892                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2893                             "[BTCoex], CONNECT START notify\n");
2894                 BTC_TRACE(trace_buf);
2895                 coex_dm->arp_cnt = 0;
2896         } else {
2897                 coex_sta->wifi_is_high_pri_task = false;
2898                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2899                             "[BTCoex], CONNECT FINISH notify\n");
2900                 BTC_TRACE(trace_buf);
2901                 /* coex_dm->arp_cnt = 0; */
2902         }
2903
2904         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2905                            &wifi_link_status);
2906         num_of_wifi_link = wifi_link_status >> 16;
2907         if (num_of_wifi_link >= 2) {
2908                 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2909                 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2910                                            bt_ctrl_agg_buf_size, agg_buf_size);
2911                 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
2912                 return;
2913         }
2914
2915         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2916         if (coex_sta->c2h_bt_inquiry_page) {
2917                 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2918                 return;
2919         } else if (bt_hs_on) {
2920                 halbtc8192e1ant_action_hs(btcoexist);
2921                 return;
2922         }
2923
2924         if (BTC_ASSOCIATE_START == type)
2925                 halbtc8192e1ant_action_wifi_not_connected_asso_auth(btcoexist);
2926         else if (BTC_ASSOCIATE_FINISH == type) {
2927                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2928                                    &wifi_connected);
2929                 if (!wifi_connected) /* non-connected scan */
2930                         halbtc8192e1ant_action_wifi_not_connected(btcoexist);
2931                 else
2932                         halbtc8192e1ant_action_wifi_connected(btcoexist);
2933         }
2934 }
2935
2936 void ex_halbtc8192e1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2937                 IN u8 type)
2938 {
2939         u8                      h2c_parameter[3] = {0};
2940         u32                     wifi_bw;
2941         u8                      wifi_central_chnl;
2942         boolean                 wifi_under_b_mode = false;
2943
2944         if (btcoexist->manual_control ||
2945             btcoexist->stop_coex_dm ||
2946             coex_sta->bt_disabled)
2947                 return;
2948
2949         if (BTC_MEDIA_CONNECT == type) {
2950                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2951                             "[BTCoex], MEDIA connect notify\n");
2952                 BTC_TRACE(trace_buf);
2953
2954                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
2955                                    &wifi_under_b_mode);
2956
2957                 /* Set CCK Tx/Rx high Pri except 11b mode */
2958                 if (wifi_under_b_mode) {
2959                         btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2960                                                    0x00); /* CCK Tx */
2961                         btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2962                                                    0x00); /* CCK Rx */
2963                 } else {
2964                         btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2965                                                    0x10); /* CCK Tx */
2966                         btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2967                                                    0x10); /* CCK Rx */
2968                 }
2969
2970                 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2971                                             0x430);
2972                 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2973                                             0x434);
2974                 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2975                                                       btcoexist, 0x42a);
2976                 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2977                                 btcoexist, 0x456);
2978         } else {
2979                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2980                             "[BTCoex], MEDIA disconnect notify\n");
2981                 BTC_TRACE(trace_buf);
2982                 coex_dm->arp_cnt = 0;
2983
2984                 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
2985                 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
2986         }
2987
2988         /* only 2.4G we need to inform bt the chnl mask */
2989         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2990                            &wifi_central_chnl);
2991         if ((BTC_MEDIA_CONNECT == type) &&
2992             (wifi_central_chnl <= 14)) {
2993                 /* h2c_parameter[0] = 0x1; */
2994                 h2c_parameter[0] = 0x0;
2995                 h2c_parameter[1] = wifi_central_chnl;
2996                 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2997                 if (BTC_WIFI_BW_HT40 == wifi_bw)
2998                         h2c_parameter[2] = 0x30;
2999                 else
3000                         h2c_parameter[2] = 0x20;
3001         }
3002
3003         coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3004         coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3005         coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3006
3007         btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3008 }
3009
3010 void ex_halbtc8192e1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
3011                 IN u8 type)
3012 {
3013         boolean bt_hs_on = false;
3014         u32     wifi_link_status = 0;
3015         u32     num_of_wifi_link = 0;
3016         boolean bt_ctrl_agg_buf_size = false;
3017         u8      agg_buf_size = 5;
3018
3019         if (btcoexist->manual_control ||
3020             btcoexist->stop_coex_dm ||
3021             coex_sta->bt_disabled)
3022                 return;
3023
3024         if (BTC_PACKET_DHCP == type ||
3025             BTC_PACKET_EAPOL == type ||
3026             BTC_PACKET_ARP == type) {
3027                 if (BTC_PACKET_ARP == type) {
3028                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3029                                     "[BTCoex], specific Packet ARP notify\n");
3030                         BTC_TRACE(trace_buf);
3031
3032                         coex_dm->arp_cnt++;
3033                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3034                                     "[BTCoex], ARP Packet Count = %d\n",
3035                                     coex_dm->arp_cnt);
3036                         BTC_TRACE(trace_buf);
3037
3038                         if (coex_dm->arp_cnt >=
3039                             10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
3040                                 coex_sta->wifi_is_high_pri_task = false;
3041                         else
3042                                 coex_sta->wifi_is_high_pri_task = true;
3043                 } else {
3044                         coex_sta->wifi_is_high_pri_task = true;
3045                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3046                                 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
3047                         BTC_TRACE(trace_buf);
3048                 }
3049         } else {
3050                 coex_sta->wifi_is_high_pri_task = false;
3051                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3052                         "[BTCoex], specific Packet [Type = %d] notify\n", type);
3053                 BTC_TRACE(trace_buf);
3054         }
3055
3056         coex_sta->specific_pkt_period_cnt = 0;
3057
3058         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3059                            &wifi_link_status);
3060         num_of_wifi_link = wifi_link_status >> 16;
3061         if (num_of_wifi_link >= 2) {
3062                 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3063                 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3064                                            bt_ctrl_agg_buf_size, agg_buf_size);
3065                 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
3066                 return;
3067         }
3068
3069         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3070         if (coex_sta->c2h_bt_inquiry_page) {
3071                 halbtc8192e1ant_action_bt_inquiry(btcoexist);
3072                 return;
3073         } else if (bt_hs_on) {
3074                 halbtc8192e1ant_action_hs(btcoexist);
3075                 return;
3076         }
3077
3078         if (BTC_PACKET_DHCP == type ||
3079             BTC_PACKET_EAPOL == type ||
3080             ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task)))
3081                 halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist);
3082 }
3083
3084 void ex_halbtc8192e1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
3085                                        IN u8 *tmp_buf, IN u8 length)
3086 {
3087         u8                              bt_info = 0;
3088         u8                              i, rsp_source = 0;
3089         boolean                         wifi_connected = false;
3090         boolean                         bt_busy = false;
3091
3092         coex_sta->c2h_bt_info_req_sent = false;
3093
3094         rsp_source = tmp_buf[0] & 0xf;
3095         if (rsp_source >= BT_INFO_SRC_8192E_1ANT_MAX)
3096                 rsp_source = BT_INFO_SRC_8192E_1ANT_WIFI_FW;
3097         coex_sta->bt_info_c2h_cnt[rsp_source]++;
3098
3099         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3100                     "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
3101                     length);
3102         BTC_TRACE(trace_buf);
3103         for (i = 0; i < length; i++) {
3104                 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3105                 if (i == 1)
3106                         bt_info = tmp_buf[i];
3107                 if (i == length - 1) {
3108                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
3109                                     tmp_buf[i]);
3110                         BTC_TRACE(trace_buf);
3111                 } else {
3112                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
3113                                     tmp_buf[i]);
3114                         BTC_TRACE(trace_buf);
3115                 }
3116         }
3117
3118         if (BT_INFO_SRC_8192E_1ANT_WIFI_FW != rsp_source) {
3119                 coex_sta->bt_retry_cnt =        /* [3:0] */
3120                         coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3121
3122                 if (coex_sta->bt_retry_cnt >= 1)
3123                         coex_sta->pop_event_cnt++;
3124
3125                 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
3126                         coex_sta->c2h_bt_page = true;
3127                 else
3128                         coex_sta->c2h_bt_page = false;
3129
3130                 coex_sta->bt_rssi =
3131                         coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90;
3132                 /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */
3133
3134                 coex_sta->bt_info_ext =
3135                         coex_sta->bt_info_c2h[rsp_source][4];
3136
3137                 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
3138                                            & 0x40);
3139                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
3140                                    &coex_sta->bt_tx_rx_mask);
3141                 if (!coex_sta->bt_tx_rx_mask) {
3142                         /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
3143                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3144                                 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3145                         BTC_TRACE(trace_buf);
3146                         btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3147                                                   0x3c, 0x15);
3148                 }
3149
3150                 /* Here we need to resend some wifi info to BT */
3151                 /* because bt is reset and loss of the info. */
3152                 if (coex_sta->bt_info_ext & BIT(1)) {
3153                         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3154                                 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3155                         BTC_TRACE(trace_buf);
3156                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3157                                            &wifi_connected);
3158                         if (wifi_connected)
3159                                 ex_halbtc8192e1ant_media_status_notify(
3160                                         btcoexist, BTC_MEDIA_CONNECT);
3161                         else
3162                                 ex_halbtc8192e1ant_media_status_notify(
3163                                         btcoexist, BTC_MEDIA_DISCONNECT);
3164                 }
3165
3166                 if (coex_sta->bt_info_ext & BIT(3)) {
3167                         if (!btcoexist->manual_control &&
3168                             !btcoexist->stop_coex_dm) {
3169                                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3170                                         "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
3171                                 BTC_TRACE(trace_buf);
3172                                 halbtc8192e1ant_ignore_wlan_act(btcoexist,
3173                                                         FORCE_EXEC, false);
3174                         }
3175                 } else {
3176                         /* BT already NOT ignore Wlan active, do nothing here. */
3177                 }
3178 #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)
3179                 if ((coex_sta->bt_info_ext & BIT(4))) {
3180                         /* BT auto report already enabled, do nothing */
3181                 } else
3182                         halbtc8192e1ant_bt_auto_report(btcoexist, FORCE_EXEC,
3183                                                        true);
3184 #endif
3185         }
3186
3187         /* check BIT2 first ==> check if bt is under inquiry or page scan */
3188         if (bt_info & BT_INFO_8192E_1ANT_B_INQ_PAGE)
3189                 coex_sta->c2h_bt_inquiry_page = true;
3190         else
3191                 coex_sta->c2h_bt_inquiry_page = false;
3192
3193         /* set link exist status */
3194         if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) {
3195                 coex_sta->bt_link_exist = false;
3196                 coex_sta->pan_exist = false;
3197                 coex_sta->a2dp_exist = false;
3198                 coex_sta->hid_exist = false;
3199                 coex_sta->sco_exist = false;
3200         } else {        /* connection exists */
3201                 coex_sta->bt_link_exist = true;
3202                 if (bt_info & BT_INFO_8192E_1ANT_B_FTP)
3203                         coex_sta->pan_exist = true;
3204                 else
3205                         coex_sta->pan_exist = false;
3206                 if (bt_info & BT_INFO_8192E_1ANT_B_A2DP)
3207                         coex_sta->a2dp_exist = true;
3208                 else
3209                         coex_sta->a2dp_exist = false;
3210                 if (bt_info & BT_INFO_8192E_1ANT_B_HID)
3211                         coex_sta->hid_exist = true;
3212                 else
3213                         coex_sta->hid_exist = false;
3214                 if (bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO)
3215                         coex_sta->sco_exist = true;
3216                 else
3217                         coex_sta->sco_exist = false;
3218         }
3219
3220         halbtc8192e1ant_update_bt_link_info(btcoexist);
3221
3222         bt_info = bt_info &
3223                 0x1f;  /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
3224
3225         if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) {
3226                 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3227                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3228                         "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
3229                 BTC_TRACE(trace_buf);
3230         } else if (bt_info ==
3231                 BT_INFO_8192E_1ANT_B_CONNECTION) {      /* connection exists but no busy */
3232                 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE;
3233                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3234                             "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3235                 BTC_TRACE(trace_buf);
3236         } else if ((bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO) ||
3237                    (bt_info & BT_INFO_8192E_1ANT_B_SCO_BUSY)) {
3238                 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_SCO_BUSY;
3239                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3240                             "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3241                 BTC_TRACE(trace_buf);
3242         } else if (bt_info & BT_INFO_8192E_1ANT_B_ACL_BUSY) {
3243                 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
3244                         coex_dm->auto_tdma_adjust = false;
3245                 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_ACL_BUSY;
3246                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3247                             "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3248                 BTC_TRACE(trace_buf);
3249         } else {
3250                 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_MAX;
3251                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3252                         "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
3253                 BTC_TRACE(trace_buf);
3254         }
3255
3256         if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3257             (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3258             (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3259                 bt_busy = true;
3260         else
3261                 bt_busy = false;
3262         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3263
3264         halbtc8192e1ant_run_coexist_mechanism(btcoexist);
3265 }
3266
3267 void ex_halbtc8192e1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
3268                 IN u8 type)
3269 {
3270         u32     u32tmp;
3271         u8      u8tmpa, u8tmpb, u8tmpc;
3272
3273         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
3274         BTC_TRACE(trace_buf);
3275
3276         if (BTC_RF_ON == type) {
3277                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3278                             "[BTCoex], RF is turned ON!!\n");
3279                 BTC_TRACE(trace_buf);
3280                 btcoexist->stop_coex_dm = false;
3281         } else if (BTC_RF_OFF == type) {
3282                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3283                             "[BTCoex], RF is turned OFF!!\n");
3284                 BTC_TRACE(trace_buf);
3285
3286                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3287                                                  0x0, 0x0);
3288                 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3289                 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3290                                              true);
3291
3292                 halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3293                 btcoexist->stop_coex_dm = true;
3294
3295                 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
3296                 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
3297                 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
3298                 u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e);
3299
3300
3301                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3302                         "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
3303                             u32tmp,  u8tmpa, u8tmpb, u8tmpc);
3304                 BTC_TRACE(trace_buf);
3305
3306         }
3307 }
3308
3309 void ex_halbtc8192e1ant_halt_notify(IN struct btc_coexist *btcoexist)
3310 {
3311         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3312         BTC_TRACE(trace_buf);
3313
3314         halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3315                                          0x0);
3316         halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3317         halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
3318
3319         halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3320
3321         ex_halbtc8192e1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3322
3323         btcoexist->stop_coex_dm = true;
3324 }
3325
3326 void ex_halbtc8192e1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3327                                    IN u8 pnp_state)
3328 {
3329         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3330         BTC_TRACE(trace_buf);
3331
3332         if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3333                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3334                             "[BTCoex], Pnp notify to SLEEP\n");
3335                 BTC_TRACE(trace_buf);
3336
3337                 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3338                                                  0x0, 0x0);
3339                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3340                 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3341                 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3342                                              true);
3343
3344                 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3345                 /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3346                 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3347                 coex_sta->under_ips = false;
3348                 coex_sta->under_lps = false;
3349                 btcoexist->stop_coex_dm = true;
3350         } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3351                 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3352                             "[BTCoex], Pnp notify to WAKE UP\n");
3353                 BTC_TRACE(trace_buf);
3354                 btcoexist->stop_coex_dm = false;
3355                 halbtc8192e1ant_init_hw_config(btcoexist, false);
3356                 halbtc8192e1ant_init_coex_dm(btcoexist);
3357                 halbtc8192e1ant_query_bt_info(btcoexist);
3358         }
3359 }
3360
3361 void ex_halbtc8192e1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
3362 {
3363         BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3364                 "[BTCoex], *****************Coex DM Reset*****************\n");
3365         BTC_TRACE(trace_buf);
3366
3367         halbtc8192e1ant_init_hw_config(btcoexist, false);
3368         /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
3369         /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0); */
3370         halbtc8192e1ant_init_coex_dm(btcoexist);
3371 }
3372
3373 void ex_halbtc8192e1ant_periodical(IN struct btc_coexist *btcoexist)
3374 {
3375 #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)
3376         halbtc8192e1ant_query_bt_info(btcoexist);
3377         halbtc8192e1ant_monitor_bt_enable_disable(btcoexist);
3378 #else
3379         halbtc8192e1ant_monitor_bt_ctr(btcoexist);
3380         halbtc8192e1ant_monitor_wifi_ctr(btcoexist);
3381
3382         if (halbtc8192e1ant_is_wifi_status_changed(btcoexist) ||
3383             coex_dm->auto_tdma_adjust)
3384
3385                 halbtc8192e1ant_run_coexist_mechanism(btcoexist);
3386
3387         coex_sta->specific_pkt_period_cnt++;
3388 #endif
3389 }
3390
3391
3392 void ex_halbtc8192e1ant_dbg_control(IN struct btc_coexist *btcoexist,
3393                                     IN u8 op_code, IN u8 op_len, IN u8 *pdata)
3394 {
3395         switch (op_code) {
3396         case BTC_DBG_SET_COEX_NORMAL:
3397                 btcoexist->manual_control = false;
3398                 halbtc8192e1ant_init_coex_dm(btcoexist);
3399                 break;
3400         case BTC_DBG_SET_COEX_WIFI_ONLY:
3401                 btcoexist->manual_control = true;
3402                 halbtc8192e1ant_power_save_state(btcoexist,
3403                                                  BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3404                 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3405                                         9);
3406                 break;
3407         case BTC_DBG_SET_COEX_BT_ONLY:
3408                 /* todo */
3409                 break;
3410         default:
3411                 break;
3412         }
3413 }
3414
3415 #endif  /*  #if (RTL8192E_SUPPORT == 1) */
3416
3417 #endif  /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */