1 /******************************************************************************
3 * Copyright(c) 2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
25 /**************************************************************
28 * This file is for RTL8192E Co-exist mechanism
31 * 2012/11/15 Cosa first check in.
33 **************************************************************/
35 /**************************************************************
37 **************************************************************/
38 #include "halbt_precomp.h"
39 /**************************************************************
40 * Global variables, these are static variables
41 **************************************************************/
42 static struct coex_dm_8192e_2ant glcoex_dm_8192e_2ant;
43 static struct coex_dm_8192e_2ant *coex_dm = &glcoex_dm_8192e_2ant;
44 static struct coex_sta_8192e_2ant glcoex_sta_8192e_2ant;
45 static struct coex_sta_8192e_2ant *coex_sta = &glcoex_sta_8192e_2ant;
47 static const char *const GLBtInfoSrc8192e2Ant[] = {
50 "BT Info[bt auto report]",
53 static u32 glcoex_ver_date_8192e_2ant = 20130902;
54 static u32 glcoex_ver_8192e_2ant = 0x34;
56 /**************************************************************
57 * local function proto type if needed
58 **************************************************************/
59 /**************************************************************
60 * local function start with halbtc8192e2ant_
61 **************************************************************/
62 static u8 halbtc8192e2ant_btrssi_state(u8 level_num, u8 rssi_thresh,
66 u8 btrssi_state = coex_sta->pre_bt_rssi_state;
68 btrssi = coex_sta->bt_rssi;
71 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
72 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
73 btc_alg_dbg(ALGO_BT_RSSI_STATE,
74 "BT Rssi pre state = LOW\n");
75 if (btrssi >= (rssi_thresh +
76 BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) {
77 btrssi_state = BTC_RSSI_STATE_HIGH;
78 btc_alg_dbg(ALGO_BT_RSSI_STATE,
79 "BT Rssi state switch to High\n");
81 btrssi_state = BTC_RSSI_STATE_STAY_LOW;
82 btc_alg_dbg(ALGO_BT_RSSI_STATE,
83 "BT Rssi state stay at Low\n");
86 btc_alg_dbg(ALGO_BT_RSSI_STATE,
87 "BT Rssi pre state = HIGH\n");
88 if (btrssi < rssi_thresh) {
89 btrssi_state = BTC_RSSI_STATE_LOW;
90 btc_alg_dbg(ALGO_BT_RSSI_STATE,
91 "BT Rssi state switch to Low\n");
93 btrssi_state = BTC_RSSI_STATE_STAY_HIGH;
94 btc_alg_dbg(ALGO_BT_RSSI_STATE,
95 "BT Rssi state stay at High\n");
98 } else if (level_num == 3) {
99 if (rssi_thresh > rssi_thresh1) {
100 btc_alg_dbg(ALGO_BT_RSSI_STATE,
101 "BT Rssi thresh error!!\n");
102 return coex_sta->pre_bt_rssi_state;
105 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
106 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
107 btc_alg_dbg(ALGO_BT_RSSI_STATE,
108 "BT Rssi pre state = LOW\n");
109 if (btrssi >= (rssi_thresh +
110 BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) {
111 btrssi_state = BTC_RSSI_STATE_MEDIUM;
112 btc_alg_dbg(ALGO_BT_RSSI_STATE,
113 "BT Rssi state switch to Medium\n");
115 btrssi_state = BTC_RSSI_STATE_STAY_LOW;
116 btc_alg_dbg(ALGO_BT_RSSI_STATE,
117 "BT Rssi state stay at Low\n");
119 } else if ((coex_sta->pre_bt_rssi_state ==
120 BTC_RSSI_STATE_MEDIUM) ||
121 (coex_sta->pre_bt_rssi_state ==
122 BTC_RSSI_STATE_STAY_MEDIUM)) {
123 btc_alg_dbg(ALGO_BT_RSSI_STATE,
124 "[BTCoex], BT Rssi pre state = MEDIUM\n");
125 if (btrssi >= (rssi_thresh1 +
126 BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) {
127 btrssi_state = BTC_RSSI_STATE_HIGH;
128 btc_alg_dbg(ALGO_BT_RSSI_STATE,
129 "BT Rssi state switch to High\n");
130 } else if (btrssi < rssi_thresh) {
131 btrssi_state = BTC_RSSI_STATE_LOW;
132 btc_alg_dbg(ALGO_BT_RSSI_STATE,
133 "BT Rssi state switch to Low\n");
135 btrssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
136 btc_alg_dbg(ALGO_BT_RSSI_STATE,
137 "BT Rssi state stay at Medium\n");
140 btc_alg_dbg(ALGO_BT_RSSI_STATE,
141 "BT Rssi pre state = HIGH\n");
142 if (btrssi < rssi_thresh1) {
143 btrssi_state = BTC_RSSI_STATE_MEDIUM;
144 btc_alg_dbg(ALGO_BT_RSSI_STATE,
145 "BT Rssi state switch to Medium\n");
147 btrssi_state = BTC_RSSI_STATE_STAY_HIGH;
148 btc_alg_dbg(ALGO_BT_RSSI_STATE,
149 "BT Rssi state stay at High\n");
154 coex_sta->pre_bt_rssi_state = btrssi_state;
159 static u8 halbtc8192e2ant_wifirssi_state(struct btc_coexist *btcoexist,
160 u8 index, u8 level_num, u8 rssi_thresh,
164 u8 wifirssi_state = coex_sta->pre_wifi_rssi_state[index];
166 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifirssi);
168 if (level_num == 2) {
169 if ((coex_sta->pre_wifi_rssi_state[index] ==
170 BTC_RSSI_STATE_LOW) ||
171 (coex_sta->pre_wifi_rssi_state[index] ==
172 BTC_RSSI_STATE_STAY_LOW)) {
173 if (wifirssi >= (rssi_thresh +
174 BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) {
175 wifirssi_state = BTC_RSSI_STATE_HIGH;
176 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
177 "wifi RSSI state switch to High\n");
179 wifirssi_state = BTC_RSSI_STATE_STAY_LOW;
180 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
181 "wifi RSSI state stay at Low\n");
184 if (wifirssi < rssi_thresh) {
185 wifirssi_state = BTC_RSSI_STATE_LOW;
186 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
187 "wifi RSSI state switch to Low\n");
189 wifirssi_state = BTC_RSSI_STATE_STAY_HIGH;
190 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
191 "wifi RSSI state stay at High\n");
194 } else if (level_num == 3) {
195 if (rssi_thresh > rssi_thresh1) {
196 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
197 "wifi RSSI thresh error!!\n");
198 return coex_sta->pre_wifi_rssi_state[index];
201 if ((coex_sta->pre_wifi_rssi_state[index] ==
202 BTC_RSSI_STATE_LOW) ||
203 (coex_sta->pre_wifi_rssi_state[index] ==
204 BTC_RSSI_STATE_STAY_LOW)) {
205 if (wifirssi >= (rssi_thresh +
206 BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) {
207 wifirssi_state = BTC_RSSI_STATE_MEDIUM;
208 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
209 "wifi RSSI state switch to Medium\n");
211 wifirssi_state = BTC_RSSI_STATE_STAY_LOW;
212 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
213 "wifi RSSI state stay at Low\n");
215 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
216 BTC_RSSI_STATE_MEDIUM) ||
217 (coex_sta->pre_wifi_rssi_state[index] ==
218 BTC_RSSI_STATE_STAY_MEDIUM)) {
219 if (wifirssi >= (rssi_thresh1 +
220 BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) {
221 wifirssi_state = BTC_RSSI_STATE_HIGH;
222 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
223 "wifi RSSI state switch to High\n");
224 } else if (wifirssi < rssi_thresh) {
225 wifirssi_state = BTC_RSSI_STATE_LOW;
226 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
227 "wifi RSSI state switch to Low\n");
229 wifirssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
230 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
231 "wifi RSSI state stay at Medium\n");
234 if (wifirssi < rssi_thresh1) {
235 wifirssi_state = BTC_RSSI_STATE_MEDIUM;
236 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
237 "wifi RSSI state switch to Medium\n");
239 wifirssi_state = BTC_RSSI_STATE_STAY_HIGH;
240 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
241 "wifi RSSI state stay at High\n");
246 coex_sta->pre_wifi_rssi_state[index] = wifirssi_state;
248 return wifirssi_state;
251 static void btc8192e2ant_monitor_bt_enable_dis(struct btc_coexist *btcoexist)
253 static bool pre_bt_disabled;
254 static u32 bt_disable_cnt;
255 bool bt_active = true, bt_disabled = false;
257 /* This function check if bt is disabled */
259 if (coex_sta->high_priority_tx == 0 &&
260 coex_sta->high_priority_rx == 0 &&
261 coex_sta->low_priority_tx == 0 &&
262 coex_sta->low_priority_rx == 0)
265 if (coex_sta->high_priority_tx == 0xffff &&
266 coex_sta->high_priority_rx == 0xffff &&
267 coex_sta->low_priority_tx == 0xffff &&
268 coex_sta->low_priority_rx == 0xffff)
274 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
276 btc_alg_dbg(ALGO_BT_MONITOR,
277 "[BTCoex], BT is enabled !!\n");
280 btc_alg_dbg(ALGO_BT_MONITOR,
281 "[BTCoex], bt all counters = 0, %d times!!\n",
283 if (bt_disable_cnt >= 2) {
285 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
287 btc_alg_dbg(ALGO_BT_MONITOR,
288 "[BTCoex], BT is disabled !!\n");
291 if (pre_bt_disabled != bt_disabled) {
292 btc_alg_dbg(ALGO_BT_MONITOR,
293 "[BTCoex], BT is from %s to %s!!\n",
294 (pre_bt_disabled ? "disabled" : "enabled"),
295 (bt_disabled ? "disabled" : "enabled"));
296 pre_bt_disabled = bt_disabled;
300 static u32 halbtc8192e2ant_decidera_mask(struct btc_coexist *btcoexist,
301 u8 sstype, u32 ra_masktype)
303 u32 disra_mask = 0x0;
305 switch (ra_masktype) {
306 case 0: /* normal mode */
308 disra_mask = 0x0; /* enable 2ss */
310 disra_mask = 0xfff00000;/* disable 2ss */
312 case 1: /* disable cck 1/2 */
314 disra_mask = 0x00000003;/* enable 2ss */
316 disra_mask = 0xfff00003;/* disable 2ss */
318 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
320 disra_mask = 0x0001f1f7;/* enable 2ss */
322 disra_mask = 0xfff1f1f7;/* disable 2ss */
331 static void halbtc8192e2ant_Updatera_mask(struct btc_coexist *btcoexist,
332 bool force_exec, u32 dis_ratemask)
334 coex_dm->curra_mask = dis_ratemask;
336 if (force_exec || (coex_dm->prera_mask != coex_dm->curra_mask))
337 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_ra_mask,
338 &coex_dm->curra_mask);
339 coex_dm->prera_mask = coex_dm->curra_mask;
342 static void btc8192e2ant_autorate_fallback_retry(struct btc_coexist *btcoexist,
343 bool force_exec, u8 type)
345 bool wifi_under_bmode = false;
347 coex_dm->cur_arfrtype = type;
349 if (force_exec || (coex_dm->pre_arfrtype != coex_dm->cur_arfrtype)) {
350 switch (coex_dm->cur_arfrtype) {
351 case 0: /* normal mode */
352 btcoexist->btc_write_4byte(btcoexist, 0x430,
353 coex_dm->backup_arfr_cnt1);
354 btcoexist->btc_write_4byte(btcoexist, 0x434,
355 coex_dm->backup_arfr_cnt2);
358 btcoexist->btc_get(btcoexist,
359 BTC_GET_BL_WIFI_UNDER_B_MODE,
361 if (wifi_under_bmode) {
362 btcoexist->btc_write_4byte(btcoexist, 0x430,
364 btcoexist->btc_write_4byte(btcoexist, 0x434,
367 btcoexist->btc_write_4byte(btcoexist, 0x430,
369 btcoexist->btc_write_4byte(btcoexist, 0x434,
378 coex_dm->pre_arfrtype = coex_dm->cur_arfrtype;
381 static void halbtc8192e2ant_retrylimit(struct btc_coexist *btcoexist,
382 bool force_exec, u8 type)
384 coex_dm->cur_retrylimit_type = type;
386 if (force_exec || (coex_dm->pre_retrylimit_type !=
387 coex_dm->cur_retrylimit_type)) {
388 switch (coex_dm->cur_retrylimit_type) {
389 case 0: /* normal mode */
390 btcoexist->btc_write_2byte(btcoexist, 0x42a,
391 coex_dm->backup_retrylimit);
393 case 1: /* retry limit = 8 */
394 btcoexist->btc_write_2byte(btcoexist, 0x42a,
402 coex_dm->pre_retrylimit_type = coex_dm->cur_retrylimit_type;
405 static void halbtc8192e2ant_ampdu_maxtime(struct btc_coexist *btcoexist,
406 bool force_exec, u8 type)
408 coex_dm->cur_ampdutime_type = type;
410 if (force_exec || (coex_dm->pre_ampdutime_type !=
411 coex_dm->cur_ampdutime_type)) {
412 switch (coex_dm->cur_ampdutime_type) {
413 case 0: /* normal mode */
414 btcoexist->btc_write_1byte(btcoexist, 0x456,
415 coex_dm->backup_ampdu_maxtime);
417 case 1: /* AMPDU timw = 0x38 * 32us */
418 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
425 coex_dm->pre_ampdutime_type = coex_dm->cur_ampdutime_type;
428 static void halbtc8192e2ant_limited_tx(struct btc_coexist *btcoexist,
429 bool force_exec, u8 ra_masktype,
430 u8 arfr_type, u8 retrylimit_type,
433 u32 disra_mask = 0x0;
435 coex_dm->curra_masktype = ra_masktype;
436 disra_mask = halbtc8192e2ant_decidera_mask(btcoexist,
439 halbtc8192e2ant_Updatera_mask(btcoexist, force_exec, disra_mask);
440 btc8192e2ant_autorate_fallback_retry(btcoexist, force_exec, arfr_type);
441 halbtc8192e2ant_retrylimit(btcoexist, force_exec, retrylimit_type);
442 halbtc8192e2ant_ampdu_maxtime(btcoexist, force_exec, ampdutime_type);
445 static void halbtc8192e2ant_limited_rx(struct btc_coexist *btcoexist,
446 bool force_exec, bool rej_ap_agg_pkt,
447 bool bt_ctrl_agg_buf_size,
450 bool reject_rx_agg = rej_ap_agg_pkt;
451 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
452 u8 rx_agg_size = agg_buf_size;
454 /*********************************************
455 * Rx Aggregation related setting
456 *********************************************/
457 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
459 /* decide BT control aggregation buf size or not */
460 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
461 &bt_ctrl_rx_agg_size);
462 /* aggregation buf size, only work
463 * when BT control Rx aggregation size.
465 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
466 /* real update aggregation setting */
467 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
470 static void halbtc8192e2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
472 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
473 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
478 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
479 reg_hp_tx = u32tmp & MASKLWORD;
480 reg_hp_rx = (u32tmp & MASKHWORD)>>16;
482 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
483 reg_lp_tx = u32tmp & MASKLWORD;
484 reg_lp_rx = (u32tmp & MASKHWORD)>>16;
486 coex_sta->high_priority_tx = reg_hp_tx;
487 coex_sta->high_priority_rx = reg_hp_rx;
488 coex_sta->low_priority_tx = reg_lp_tx;
489 coex_sta->low_priority_rx = reg_lp_rx;
491 btc_alg_dbg(ALGO_BT_MONITOR,
492 "[BTCoex] High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
493 reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
494 btc_alg_dbg(ALGO_BT_MONITOR,
495 "[BTCoex] Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
496 reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
499 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
502 static void halbtc8192e2ant_querybt_info(struct btc_coexist *btcoexist)
504 u8 h2c_parameter[1] = {0};
506 coex_sta->c2h_bt_info_req_sent = true;
508 h2c_parameter[0] |= BIT0; /* trigger */
510 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
511 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
514 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
517 static void halbtc8192e2ant_update_btlink_info(struct btc_coexist *btcoexist)
519 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
520 bool bt_hson = false;
522 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hson);
524 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
525 bt_link_info->sco_exist = coex_sta->sco_exist;
526 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
527 bt_link_info->pan_exist = coex_sta->pan_exist;
528 bt_link_info->hid_exist = coex_sta->hid_exist;
530 /* work around for HS mode. */
532 bt_link_info->pan_exist = true;
533 bt_link_info->bt_link_exist = true;
536 /* check if Sco 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->sco_only = true;
543 bt_link_info->sco_only = false;
545 /* check if A2dp 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->a2dp_only = true;
552 bt_link_info->a2dp_only = false;
554 /* check if Pan 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->pan_only = true;
561 bt_link_info->pan_only = false;
563 /* check if Hid only */
564 if (!bt_link_info->sco_exist &&
565 !bt_link_info->a2dp_exist &&
566 !bt_link_info->pan_exist &&
567 bt_link_info->hid_exist)
568 bt_link_info->hid_only = true;
570 bt_link_info->hid_only = false;
573 static u8 halbtc8192e2ant_action_algorithm(struct btc_coexist *btcoexist)
575 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
576 struct btc_stack_info *stack_info = &btcoexist->stack_info;
577 bool bt_hson = false;
578 u8 algorithm = BT_8192E_2ANT_COEX_ALGO_UNDEFINED;
579 u8 numdiffprofile = 0;
581 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hson);
583 if (!bt_link_info->bt_link_exist) {
584 btc_alg_dbg(ALGO_TRACE,
585 "No BT link exists!!!\n");
589 if (bt_link_info->sco_exist)
591 if (bt_link_info->hid_exist)
593 if (bt_link_info->pan_exist)
595 if (bt_link_info->a2dp_exist)
598 if (numdiffprofile == 1) {
599 if (bt_link_info->sco_exist) {
600 btc_alg_dbg(ALGO_TRACE,
602 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;
604 if (bt_link_info->hid_exist) {
605 btc_alg_dbg(ALGO_TRACE,
607 algorithm = BT_8192E_2ANT_COEX_ALGO_HID;
608 } else if (bt_link_info->a2dp_exist) {
609 btc_alg_dbg(ALGO_TRACE,
611 algorithm = BT_8192E_2ANT_COEX_ALGO_A2DP;
612 } else if (bt_link_info->pan_exist) {
614 btc_alg_dbg(ALGO_TRACE,
617 BT_8192E_2ANT_COEX_ALGO_PANHS;
619 btc_alg_dbg(ALGO_TRACE,
622 BT_8192E_2ANT_COEX_ALGO_PANEDR;
626 } else if (numdiffprofile == 2) {
627 if (bt_link_info->sco_exist) {
628 if (bt_link_info->hid_exist) {
629 btc_alg_dbg(ALGO_TRACE,
631 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;
632 } else if (bt_link_info->a2dp_exist) {
633 btc_alg_dbg(ALGO_TRACE,
634 "SCO + A2DP ==> SCO\n");
635 algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;
636 } else if (bt_link_info->pan_exist) {
638 btc_alg_dbg(ALGO_TRACE,
640 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;
642 btc_alg_dbg(ALGO_TRACE,
645 BT_8192E_2ANT_COEX_ALGO_SCO_PAN;
649 if (bt_link_info->hid_exist &&
650 bt_link_info->a2dp_exist) {
651 if (stack_info->num_of_hid >= 2) {
652 btc_alg_dbg(ALGO_TRACE,
655 BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
657 btc_alg_dbg(ALGO_TRACE,
660 BT_8192E_2ANT_COEX_ALGO_HID_A2DP;
662 } else if (bt_link_info->hid_exist &&
663 bt_link_info->pan_exist) {
665 btc_alg_dbg(ALGO_TRACE,
667 algorithm = BT_8192E_2ANT_COEX_ALGO_HID;
669 btc_alg_dbg(ALGO_TRACE,
672 BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;
674 } else if (bt_link_info->pan_exist &&
675 bt_link_info->a2dp_exist) {
677 btc_alg_dbg(ALGO_TRACE,
680 BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS;
682 btc_alg_dbg(ALGO_TRACE,
683 "A2DP + PAN(EDR)\n");
685 BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP;
689 } else if (numdiffprofile == 3) {
690 if (bt_link_info->sco_exist) {
691 if (bt_link_info->hid_exist &&
692 bt_link_info->a2dp_exist) {
693 btc_alg_dbg(ALGO_TRACE,
694 "SCO + HID + A2DP ==> HID\n");
695 algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;
696 } else if (bt_link_info->hid_exist &&
697 bt_link_info->pan_exist) {
699 btc_alg_dbg(ALGO_TRACE,
700 "SCO + HID + PAN(HS)\n");
701 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;
703 btc_alg_dbg(ALGO_TRACE,
704 "SCO + HID + PAN(EDR)\n");
706 BT_8192E_2ANT_COEX_ALGO_SCO_PAN;
708 } else if (bt_link_info->pan_exist &&
709 bt_link_info->a2dp_exist) {
711 btc_alg_dbg(ALGO_TRACE,
712 "SCO + A2DP + PAN(HS)\n");
713 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;
715 btc_alg_dbg(ALGO_TRACE,
716 "SCO + A2DP + PAN(EDR)\n");
718 BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;
722 if (bt_link_info->hid_exist &&
723 bt_link_info->pan_exist &&
724 bt_link_info->a2dp_exist) {
726 btc_alg_dbg(ALGO_TRACE,
727 "HID + A2DP + PAN(HS)\n");
729 BT_8192E_2ANT_COEX_ALGO_HID_A2DP;
731 btc_alg_dbg(ALGO_TRACE,
732 "HID + A2DP + PAN(EDR)\n");
734 BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
738 } else if (numdiffprofile >= 3) {
739 if (bt_link_info->sco_exist) {
740 if (bt_link_info->hid_exist &&
741 bt_link_info->pan_exist &&
742 bt_link_info->a2dp_exist) {
744 btc_alg_dbg(ALGO_TRACE,
745 "ErrorSCO+HID+A2DP+PAN(HS)\n");
748 btc_alg_dbg(ALGO_TRACE,
749 "SCO+HID+A2DP+PAN(EDR)\n");
751 BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;
760 static void halbtc8192e2ant_setfw_dac_swinglevel(struct btc_coexist *btcoexist,
763 u8 h2c_parameter[1] = {0};
765 /* There are several type of dacswing
766 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
768 h2c_parameter[0] = dac_swinglvl;
770 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
771 "[BTCoex], Set Dac Swing Level = 0x%x\n", dac_swinglvl);
772 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
773 "[BTCoex], FW write 0x64 = 0x%x\n", h2c_parameter[0]);
775 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
778 static void halbtc8192e2ant_set_fwdec_btpwr(struct btc_coexist *btcoexist,
781 u8 h2c_parameter[1] = {0};
783 h2c_parameter[0] = dec_btpwr_lvl;
785 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
786 "[BTCoex] decrease Bt Power level = %d, FW write 0x62 = 0x%x\n",
787 dec_btpwr_lvl, h2c_parameter[0]);
789 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
792 static void halbtc8192e2ant_dec_btpwr(struct btc_coexist *btcoexist,
793 bool force_exec, u8 dec_btpwr_lvl)
795 btc_alg_dbg(ALGO_TRACE_FW,
796 "[BTCoex], %s Dec BT power level = %d\n",
797 (force_exec ? "force to" : ""), dec_btpwr_lvl);
798 coex_dm->cur_dec_bt_pwr = dec_btpwr_lvl;
801 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
802 "[BTCoex], preBtDecPwrLvl=%d, curBtDecPwrLvl=%d\n",
803 coex_dm->pre_dec_bt_pwr, coex_dm->cur_dec_bt_pwr);
805 halbtc8192e2ant_set_fwdec_btpwr(btcoexist, coex_dm->cur_dec_bt_pwr);
807 coex_dm->pre_dec_bt_pwr = coex_dm->cur_dec_bt_pwr;
810 static void halbtc8192e2ant_set_bt_autoreport(struct btc_coexist *btcoexist,
811 bool enable_autoreport)
813 u8 h2c_parameter[1] = {0};
815 h2c_parameter[0] = 0;
817 if (enable_autoreport)
818 h2c_parameter[0] |= BIT0;
820 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
821 "[BTCoex], BT FW auto report : %s, FW write 0x68 = 0x%x\n",
822 (enable_autoreport ? "Enabled!!" : "Disabled!!"),
825 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
828 static void halbtc8192e2ant_bt_autoreport(struct btc_coexist *btcoexist,
830 bool enable_autoreport)
832 btc_alg_dbg(ALGO_TRACE_FW,
833 "[BTCoex], %s BT Auto report = %s\n",
834 (force_exec ? "force to" : ""),
835 ((enable_autoreport) ? "Enabled" : "Disabled"));
836 coex_dm->cur_bt_auto_report = enable_autoreport;
839 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
840 "[BTCoex] bPreBtAutoReport=%d, bCurBtAutoReport=%d\n",
841 coex_dm->pre_bt_auto_report,
842 coex_dm->cur_bt_auto_report);
844 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
847 halbtc8192e2ant_set_bt_autoreport(btcoexist,
848 coex_dm->cur_bt_auto_report);
850 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
853 static void halbtc8192e2ant_fw_dac_swinglvl(struct btc_coexist *btcoexist,
854 bool force_exec, u8 fw_dac_swinglvl)
856 btc_alg_dbg(ALGO_TRACE_FW,
857 "[BTCoex], %s set FW Dac Swing level = %d\n",
858 (force_exec ? "force to" : ""), fw_dac_swinglvl);
859 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swinglvl;
862 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
863 "[BTCoex] preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n",
864 coex_dm->pre_fw_dac_swing_lvl,
865 coex_dm->cur_fw_dac_swing_lvl);
867 if (coex_dm->pre_fw_dac_swing_lvl ==
868 coex_dm->cur_fw_dac_swing_lvl)
872 halbtc8192e2ant_setfw_dac_swinglevel(btcoexist,
873 coex_dm->cur_fw_dac_swing_lvl);
875 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
878 static void btc8192e2ant_set_sw_rf_rx_lpf_corner(struct btc_coexist *btcoexist,
879 bool rx_rf_shrink_on)
881 if (rx_rf_shrink_on) {
882 /* Shrink RF Rx LPF corner */
883 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
884 "[BTCoex], Shrink RF Rx LPF corner!!\n");
885 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
888 /* Resume RF Rx LPF corner
889 * After initialized, we can use coex_dm->btRf0x1eBackup
891 if (btcoexist->initilized) {
892 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
893 "[BTCoex], Resume RF Rx LPF corner!!\n");
894 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
896 coex_dm->bt_rf0x1e_backup);
901 static void halbtc8192e2ant_rf_shrink(struct btc_coexist *btcoexist,
902 bool force_exec, bool rx_rf_shrink_on)
904 btc_alg_dbg(ALGO_TRACE_SW,
905 "[BTCoex], %s turn Rx RF Shrink = %s\n",
906 (force_exec ? "force to" : ""),
907 ((rx_rf_shrink_on) ? "ON" : "OFF"));
908 coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
911 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
912 "[BTCoex]bPreRfRxLpfShrink=%d,bCurRfRxLpfShrink=%d\n",
913 coex_dm->pre_rf_rx_lpf_shrink,
914 coex_dm->cur_rf_rx_lpf_shrink);
916 if (coex_dm->pre_rf_rx_lpf_shrink ==
917 coex_dm->cur_rf_rx_lpf_shrink)
920 btc8192e2ant_set_sw_rf_rx_lpf_corner(btcoexist,
921 coex_dm->cur_rf_rx_lpf_shrink);
923 coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
926 static void halbtc8192e2ant_set_dac_swingreg(struct btc_coexist *btcoexist,
931 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
932 "[BTCoex], Write SwDacSwing = 0x%x\n", level);
933 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x883, 0x3e, val);
936 static void btc8192e2ant_setsw_full_swing(struct btc_coexist *btcoexist,
941 halbtc8192e2ant_set_dac_swingreg(btcoexist, sw_dac_swinglvl);
943 halbtc8192e2ant_set_dac_swingreg(btcoexist, 0x18);
946 static void halbtc8192e2ant_DacSwing(struct btc_coexist *btcoexist,
947 bool force_exec, bool dac_swingon,
950 btc_alg_dbg(ALGO_TRACE_SW,
951 "[BTCoex], %s turn DacSwing=%s, dac_swinglvl = 0x%x\n",
952 (force_exec ? "force to" : ""),
953 ((dac_swingon) ? "ON" : "OFF"), dac_swinglvl);
954 coex_dm->cur_dac_swing_on = dac_swingon;
955 coex_dm->cur_dac_swing_lvl = dac_swinglvl;
958 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
959 "[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl = 0x%x, ",
960 coex_dm->pre_dac_swing_on,
961 coex_dm->pre_dac_swing_lvl);
962 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
963 "bCurDacSwingOn=%d, curDacSwingLvl = 0x%x\n",
964 coex_dm->cur_dac_swing_on,
965 coex_dm->cur_dac_swing_lvl);
967 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
968 (coex_dm->pre_dac_swing_lvl == coex_dm->cur_dac_swing_lvl))
972 btc8192e2ant_setsw_full_swing(btcoexist, dac_swingon, dac_swinglvl);
974 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
975 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
978 static void halbtc8192e2ant_set_agc_table(struct btc_coexist *btcoexist,
981 /* BB AGC Gain Table */
983 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
984 "[BTCoex], BB Agc Table On!\n");
985 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x0a1A0001);
986 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x091B0001);
987 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x081C0001);
988 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x071D0001);
989 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x061E0001);
990 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x051F0001);
992 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
993 "[BTCoex], BB Agc Table Off!\n");
994 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001);
995 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001);
996 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001);
997 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001);
998 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001);
999 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001);
1003 static void halbtc8192e2ant_AgcTable(struct btc_coexist *btcoexist,
1004 bool force_exec, bool agc_table_en)
1006 btc_alg_dbg(ALGO_TRACE_SW,
1007 "[BTCoex], %s %s Agc Table\n",
1008 (force_exec ? "force to" : ""),
1009 ((agc_table_en) ? "Enable" : "Disable"));
1010 coex_dm->cur_agc_table_en = agc_table_en;
1013 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
1014 "[BTCoex], bPreAgcTableEn=%d, bCurAgcTableEn=%d\n",
1015 coex_dm->pre_agc_table_en,
1016 coex_dm->cur_agc_table_en);
1018 if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
1021 halbtc8192e2ant_set_agc_table(btcoexist, agc_table_en);
1023 coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
1026 static void halbtc8192e2ant_set_coex_table(struct btc_coexist *btcoexist,
1027 u32 val0x6c0, u32 val0x6c4,
1028 u32 val0x6c8, u8 val0x6cc)
1030 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
1031 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
1032 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1034 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
1035 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
1036 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1038 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
1039 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
1040 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1042 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
1043 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
1044 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1047 static void halbtc8192e2ant_coex_table(struct btc_coexist *btcoexist,
1049 u32 val0x6c0, u32 val0x6c4,
1050 u32 val0x6c8, u8 val0x6cc)
1052 btc_alg_dbg(ALGO_TRACE_SW,
1053 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, ",
1054 (force_exec ? "force to" : ""), val0x6c0);
1055 btc_alg_dbg(ALGO_TRACE_SW,
1056 "0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
1057 val0x6c4, val0x6c8, val0x6cc);
1058 coex_dm->cur_val0x6c0 = val0x6c0;
1059 coex_dm->cur_val0x6c4 = val0x6c4;
1060 coex_dm->cur_val0x6c8 = val0x6c8;
1061 coex_dm->cur_val0x6cc = val0x6cc;
1064 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
1065 "[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c4 = 0x%x, ",
1066 coex_dm->pre_val0x6c0, coex_dm->pre_val0x6c4);
1067 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
1068 "preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n",
1069 coex_dm->pre_val0x6c8, coex_dm->pre_val0x6cc);
1070 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
1071 "[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c4 = 0x%x\n",
1072 coex_dm->cur_val0x6c0, coex_dm->cur_val0x6c4);
1073 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
1074 "curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n",
1075 coex_dm->cur_val0x6c8, coex_dm->cur_val0x6cc);
1077 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1078 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1079 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1080 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1083 halbtc8192e2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
1084 val0x6c8, val0x6cc);
1086 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1087 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1088 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1089 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1092 static void btc8192e2ant_coex_tbl_w_type(struct btc_coexist *btcoexist,
1093 bool force_exec, u8 type)
1097 halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x55555555,
1098 0x5a5a5a5a, 0xffffff, 0x3);
1101 halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
1102 0x5a5a5a5a, 0xffffff, 0x3);
1105 halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x55555555,
1106 0x5ffb5ffb, 0xffffff, 0x3);
1109 halbtc8192e2ant_coex_table(btcoexist, force_exec, 0xdfffdfff,
1110 0x5fdb5fdb, 0xffffff, 0x3);
1113 halbtc8192e2ant_coex_table(btcoexist, force_exec, 0xdfffdfff,
1114 0x5ffb5ffb, 0xffffff, 0x3);
1121 static void halbtc8192e2ant_set_fw_ignore_wlanact(struct btc_coexist *btcoexist,
1124 u8 h2c_parameter[1] = {0};
1127 h2c_parameter[0] |= BIT0; /* function enable */
1129 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
1130 "[BTCoex]set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
1133 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1136 static void halbtc8192e2ant_IgnoreWlanAct(struct btc_coexist *btcoexist,
1137 bool force_exec, bool enable)
1139 btc_alg_dbg(ALGO_TRACE_FW,
1140 "[BTCoex], %s turn Ignore WlanAct %s\n",
1141 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
1142 coex_dm->cur_ignore_wlan_act = enable;
1145 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1146 "[BTCoex], bPreIgnoreWlanAct = %d ",
1147 coex_dm->pre_ignore_wlan_act);
1148 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1149 "bCurIgnoreWlanAct = %d!!\n",
1150 coex_dm->cur_ignore_wlan_act);
1152 if (coex_dm->pre_ignore_wlan_act ==
1153 coex_dm->cur_ignore_wlan_act)
1156 halbtc8192e2ant_set_fw_ignore_wlanact(btcoexist, enable);
1158 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1161 static void halbtc8192e2ant_SetFwPstdma(struct btc_coexist *btcoexist, u8 byte1,
1162 u8 byte2, u8 byte3, u8 byte4, u8 byte5)
1164 u8 h2c_parameter[5] = {0};
1166 h2c_parameter[0] = byte1;
1167 h2c_parameter[1] = byte2;
1168 h2c_parameter[2] = byte3;
1169 h2c_parameter[3] = byte4;
1170 h2c_parameter[4] = byte5;
1172 coex_dm->ps_tdma_para[0] = byte1;
1173 coex_dm->ps_tdma_para[1] = byte2;
1174 coex_dm->ps_tdma_para[2] = byte3;
1175 coex_dm->ps_tdma_para[3] = byte4;
1176 coex_dm->ps_tdma_para[4] = byte5;
1178 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
1179 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1181 h2c_parameter[1] << 24 | h2c_parameter[2] << 16 |
1182 h2c_parameter[3] << 8 | h2c_parameter[4]);
1184 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1187 static void btc8192e2ant_sw_mec1(struct btc_coexist *btcoexist,
1188 bool shrink_rx_lpf, bool low_penalty_ra,
1189 bool limited_dig, bool btlan_constrain)
1191 halbtc8192e2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
1194 static void btc8192e2ant_sw_mec2(struct btc_coexist *btcoexist,
1195 bool agc_table_shift, bool adc_backoff,
1196 bool sw_dac_swing, u32 dac_swinglvl)
1198 halbtc8192e2ant_AgcTable(btcoexist, NORMAL_EXEC, agc_table_shift);
1199 halbtc8192e2ant_DacSwing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1203 static void halbtc8192e2ant_ps_tdma(struct btc_coexist *btcoexist,
1204 bool force_exec, bool turn_on, u8 type)
1206 btc_alg_dbg(ALGO_TRACE_FW,
1207 "[BTCoex], %s turn %s PS TDMA, type=%d\n",
1208 (force_exec ? "force to" : ""),
1209 (turn_on ? "ON" : "OFF"), type);
1210 coex_dm->cur_ps_tdma_on = turn_on;
1211 coex_dm->cur_ps_tdma = type;
1214 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1215 "[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1216 coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on);
1217 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1218 "[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1219 coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma);
1221 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1222 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1229 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1a,
1233 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x12,
1237 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1c,
1241 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x10,
1245 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1a,
1249 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x12,
1253 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1c,
1257 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xa3, 0x10,
1261 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1a,
1265 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x12,
1269 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1c,
1273 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x10,
1277 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1a,
1281 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x12,
1285 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1c,
1289 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x12,
1293 halbtc8192e2ant_SetFwPstdma(btcoexist, 0x61, 0x20,
1297 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x5,
1301 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x25,
1305 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x25,
1309 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x15,
1313 halbtc8192e2ant_SetFwPstdma(btcoexist, 0xe3, 0x1a,
1318 /* disable PS tdma */
1322 halbtc8192e2ant_SetFwPstdma(btcoexist, 0x8, 0x0, 0x0,
1324 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
1327 halbtc8192e2ant_SetFwPstdma(btcoexist, 0x0, 0x0, 0x0,
1330 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20);
1335 /* update pre state */
1336 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1337 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1340 static void halbtc8192e2ant_set_switch_sstype(struct btc_coexist *btcoexist,
1343 u8 mimops = BTC_MIMO_PS_DYNAMIC;
1344 u32 disra_mask = 0x0;
1346 btc_alg_dbg(ALGO_TRACE,
1347 "[BTCoex], REAL set SS Type = %d\n", sstype);
1349 disra_mask = halbtc8192e2ant_decidera_mask(btcoexist, sstype,
1350 coex_dm->curra_masktype);
1351 halbtc8192e2ant_Updatera_mask(btcoexist, FORCE_EXEC, disra_mask);
1354 halbtc8192e2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1355 /* switch ofdm path */
1356 btcoexist->btc_write_1byte(btcoexist, 0xc04, 0x11);
1357 btcoexist->btc_write_1byte(btcoexist, 0xd04, 0x1);
1358 btcoexist->btc_write_4byte(btcoexist, 0x90c, 0x81111111);
1359 /* switch cck patch */
1360 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xe77, 0x4, 0x1);
1361 btcoexist->btc_write_1byte(btcoexist, 0xa07, 0x81);
1362 mimops = BTC_MIMO_PS_STATIC;
1363 } else if (sstype == 2) {
1364 halbtc8192e2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
1365 btcoexist->btc_write_1byte(btcoexist, 0xc04, 0x33);
1366 btcoexist->btc_write_1byte(btcoexist, 0xd04, 0x3);
1367 btcoexist->btc_write_4byte(btcoexist, 0x90c, 0x81121313);
1368 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xe77, 0x4, 0x0);
1369 btcoexist->btc_write_1byte(btcoexist, 0xa07, 0x41);
1370 mimops = BTC_MIMO_PS_DYNAMIC;
1372 /* set rx 1ss or 2ss */
1373 btcoexist->btc_set(btcoexist, BTC_SET_ACT_SEND_MIMO_PS, &mimops);
1376 static void halbtc8192e2ant_switch_sstype(struct btc_coexist *btcoexist,
1377 bool force_exec, u8 new_sstype)
1379 btc_alg_dbg(ALGO_TRACE,
1380 "[BTCoex], %s Switch SS Type = %d\n",
1381 (force_exec ? "force to" : ""), new_sstype);
1382 coex_dm->cur_sstype = new_sstype;
1385 if (coex_dm->pre_sstype == coex_dm->cur_sstype)
1388 halbtc8192e2ant_set_switch_sstype(btcoexist, coex_dm->cur_sstype);
1390 coex_dm->pre_sstype = coex_dm->cur_sstype;
1393 static void halbtc8192e2ant_coex_alloff(struct btc_coexist *btcoexist)
1396 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1397 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
1398 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
1401 btc8192e2ant_sw_mec1(btcoexist, false, false, false, false);
1402 btc8192e2ant_sw_mec2(btcoexist, false, false, false, 0x18);
1405 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 0);
1408 static void halbtc8192e2ant_init_coex_dm(struct btc_coexist *btcoexist)
1410 /* force to reset coex mechanism */
1412 halbtc8192e2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1413 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, FORCE_EXEC, 6);
1414 halbtc8192e2ant_dec_btpwr(btcoexist, FORCE_EXEC, 0);
1416 btc8192e2ant_coex_tbl_w_type(btcoexist, FORCE_EXEC, 0);
1417 halbtc8192e2ant_switch_sstype(btcoexist, FORCE_EXEC, 2);
1419 btc8192e2ant_sw_mec1(btcoexist, false, false, false, false);
1420 btc8192e2ant_sw_mec2(btcoexist, false, false, false, 0x18);
1423 static void halbtc8192e2ant_action_bt_inquiry(struct btc_coexist *btcoexist)
1425 bool low_pwr_disable = true;
1427 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1430 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
1432 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 2);
1433 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1434 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
1435 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
1437 btc8192e2ant_sw_mec1(btcoexist, false, false, false, false);
1438 btc8192e2ant_sw_mec2(btcoexist, false, false, false, 0x18);
1441 static bool halbtc8192e2ant_is_common_action(struct btc_coexist *btcoexist)
1443 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1444 bool common = false, wifi_connected = false, wifi_busy = false;
1445 bool bt_hson = false, low_pwr_disable = false;
1447 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hson);
1448 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1450 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1452 if (bt_link_info->sco_exist || bt_link_info->hid_exist)
1453 halbtc8192e2ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 0, 0, 0);
1455 halbtc8192e2ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1457 if (!wifi_connected) {
1458 low_pwr_disable = false;
1459 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1462 btc_alg_dbg(ALGO_TRACE,
1463 "[BTCoex], Wifi non-connected idle!!\n");
1465 if ((BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1466 coex_dm->bt_status) ||
1467 (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE ==
1468 coex_dm->bt_status)) {
1469 halbtc8192e2ant_switch_sstype(btcoexist,
1471 btc8192e2ant_coex_tbl_w_type(btcoexist,
1473 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1476 halbtc8192e2ant_switch_sstype(btcoexist,
1478 btc8192e2ant_coex_tbl_w_type(btcoexist,
1480 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1484 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
1485 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
1487 btc8192e2ant_sw_mec1(btcoexist, false, false, false, false);
1488 btc8192e2ant_sw_mec2(btcoexist, false, false, false, 0x18);
1492 if (BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1493 coex_dm->bt_status) {
1494 low_pwr_disable = false;
1495 btcoexist->btc_set(btcoexist,
1496 BTC_SET_ACT_DISABLE_LOW_POWER,
1499 btc_alg_dbg(ALGO_TRACE,
1500 "Wifi connected + BT non connected-idle!!\n");
1502 halbtc8192e2ant_switch_sstype(btcoexist,
1504 btc8192e2ant_coex_tbl_w_type(btcoexist,
1506 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1508 halbtc8192e2ant_fw_dac_swinglvl(btcoexist,
1510 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
1512 btc8192e2ant_sw_mec1(btcoexist, false, false,
1514 btc8192e2ant_sw_mec2(btcoexist, false, false,
1518 } else if (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE ==
1519 coex_dm->bt_status) {
1520 low_pwr_disable = true;
1521 btcoexist->btc_set(btcoexist,
1522 BTC_SET_ACT_DISABLE_LOW_POWER,
1527 btc_alg_dbg(ALGO_TRACE,
1528 "Wifi connected + BT connected-idle!!\n");
1530 halbtc8192e2ant_switch_sstype(btcoexist,
1532 btc8192e2ant_coex_tbl_w_type(btcoexist,
1534 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1536 halbtc8192e2ant_fw_dac_swinglvl(btcoexist,
1538 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
1540 btc8192e2ant_sw_mec1(btcoexist, true, false,
1542 btc8192e2ant_sw_mec2(btcoexist, false, false,
1547 low_pwr_disable = true;
1548 btcoexist->btc_set(btcoexist,
1549 BTC_SET_ACT_DISABLE_LOW_POWER,
1553 btc_alg_dbg(ALGO_TRACE,
1554 "Wifi Connected-Busy + BT Busy!!\n");
1557 btc_alg_dbg(ALGO_TRACE,
1558 "Wifi Connected-Idle + BT Busy!!\n");
1560 halbtc8192e2ant_switch_sstype(btcoexist,
1562 btc8192e2ant_coex_tbl_w_type(btcoexist,
1564 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1566 halbtc8192e2ant_fw_dac_swinglvl(btcoexist,
1568 halbtc8192e2ant_dec_btpwr(btcoexist,
1570 btc8192e2ant_sw_mec1(btcoexist, false,
1571 false, false, false);
1572 btc8192e2ant_sw_mec2(btcoexist, false,
1573 false, false, 0x18);
1581 static void btc8192e_int1(struct btc_coexist *btcoexist, bool tx_pause,
1585 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1586 "[BTCoex], TxPause = 1\n");
1588 if (coex_dm->cur_ps_tdma == 71) {
1589 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1591 coex_dm->tdma_adj_type = 5;
1592 } else if (coex_dm->cur_ps_tdma == 1) {
1593 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1595 coex_dm->tdma_adj_type = 5;
1596 } else if (coex_dm->cur_ps_tdma == 2) {
1597 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1599 coex_dm->tdma_adj_type = 6;
1600 } else if (coex_dm->cur_ps_tdma == 3) {
1601 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1603 coex_dm->tdma_adj_type = 7;
1604 } else if (coex_dm->cur_ps_tdma == 4) {
1605 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1607 coex_dm->tdma_adj_type = 8;
1609 if (coex_dm->cur_ps_tdma == 9) {
1610 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1612 coex_dm->tdma_adj_type = 13;
1613 } else if (coex_dm->cur_ps_tdma == 10) {
1614 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1616 coex_dm->tdma_adj_type = 14;
1617 } else if (coex_dm->cur_ps_tdma == 11) {
1618 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1620 coex_dm->tdma_adj_type = 15;
1621 } else if (coex_dm->cur_ps_tdma == 12) {
1622 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1624 coex_dm->tdma_adj_type = 16;
1628 if (coex_dm->cur_ps_tdma == 5) {
1629 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1631 coex_dm->tdma_adj_type = 6;
1632 } else if (coex_dm->cur_ps_tdma == 6) {
1633 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1635 coex_dm->tdma_adj_type = 7;
1636 } else if (coex_dm->cur_ps_tdma == 7) {
1637 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1639 coex_dm->tdma_adj_type = 8;
1640 } else if (coex_dm->cur_ps_tdma == 13) {
1641 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1643 coex_dm->tdma_adj_type = 14;
1644 } else if (coex_dm->cur_ps_tdma == 14) {
1645 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1647 coex_dm->tdma_adj_type = 15;
1648 } else if (coex_dm->cur_ps_tdma == 15) {
1649 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1651 coex_dm->tdma_adj_type = 16;
1653 } else if (result == 1) {
1654 if (coex_dm->cur_ps_tdma == 8) {
1655 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1657 coex_dm->tdma_adj_type = 7;
1658 } else if (coex_dm->cur_ps_tdma == 7) {
1659 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1661 coex_dm->tdma_adj_type = 6;
1662 } else if (coex_dm->cur_ps_tdma == 6) {
1663 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1665 coex_dm->tdma_adj_type = 5;
1666 } else if (coex_dm->cur_ps_tdma == 16) {
1667 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1669 coex_dm->tdma_adj_type = 15;
1670 } else if (coex_dm->cur_ps_tdma == 15) {
1671 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1673 coex_dm->tdma_adj_type = 14;
1674 } else if (coex_dm->cur_ps_tdma == 14) {
1675 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1677 coex_dm->tdma_adj_type = 13;
1681 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1682 "[BTCoex], TxPause = 0\n");
1683 if (coex_dm->cur_ps_tdma == 5) {
1684 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1686 coex_dm->tdma_adj_type = 71;
1687 } else if (coex_dm->cur_ps_tdma == 6) {
1688 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1690 coex_dm->tdma_adj_type = 2;
1691 } else if (coex_dm->cur_ps_tdma == 7) {
1692 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1694 coex_dm->tdma_adj_type = 3;
1695 } else if (coex_dm->cur_ps_tdma == 8) {
1696 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1698 coex_dm->tdma_adj_type = 4;
1700 if (coex_dm->cur_ps_tdma == 13) {
1701 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1703 coex_dm->tdma_adj_type = 9;
1704 } else if (coex_dm->cur_ps_tdma == 14) {
1705 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1707 coex_dm->tdma_adj_type = 10;
1708 } else if (coex_dm->cur_ps_tdma == 15) {
1709 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1711 coex_dm->tdma_adj_type = 11;
1712 } else if (coex_dm->cur_ps_tdma == 16) {
1713 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1715 coex_dm->tdma_adj_type = 12;
1719 if (coex_dm->cur_ps_tdma == 71) {
1720 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1722 coex_dm->tdma_adj_type = 1;
1723 } else if (coex_dm->cur_ps_tdma == 1) {
1724 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1726 coex_dm->tdma_adj_type = 2;
1727 } else if (coex_dm->cur_ps_tdma == 2) {
1728 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1730 coex_dm->tdma_adj_type = 3;
1731 } else if (coex_dm->cur_ps_tdma == 3) {
1732 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1734 coex_dm->tdma_adj_type = 4;
1735 } else if (coex_dm->cur_ps_tdma == 9) {
1736 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1738 coex_dm->tdma_adj_type = 10;
1739 } else if (coex_dm->cur_ps_tdma == 10) {
1740 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1742 coex_dm->tdma_adj_type = 11;
1743 } else if (coex_dm->cur_ps_tdma == 11) {
1744 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1746 coex_dm->tdma_adj_type = 12;
1748 } else if (result == 1) {
1749 if (coex_dm->cur_ps_tdma == 4) {
1750 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1752 coex_dm->tdma_adj_type = 3;
1753 } else if (coex_dm->cur_ps_tdma == 3) {
1754 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1756 coex_dm->tdma_adj_type = 2;
1757 } else if (coex_dm->cur_ps_tdma == 2) {
1758 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1760 coex_dm->tdma_adj_type = 1;
1761 } else if (coex_dm->cur_ps_tdma == 1) {
1762 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1764 coex_dm->tdma_adj_type = 71;
1765 } else if (coex_dm->cur_ps_tdma == 12) {
1766 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1768 coex_dm->tdma_adj_type = 11;
1769 } else if (coex_dm->cur_ps_tdma == 11) {
1770 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1772 coex_dm->tdma_adj_type = 10;
1773 } else if (coex_dm->cur_ps_tdma == 10) {
1774 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1776 coex_dm->tdma_adj_type = 9;
1782 static void btc8192e_int2(struct btc_coexist *btcoexist, bool tx_pause,
1786 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1787 "[BTCoex], TxPause = 1\n");
1788 if (coex_dm->cur_ps_tdma == 1) {
1789 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1791 coex_dm->tdma_adj_type = 6;
1792 } else if (coex_dm->cur_ps_tdma == 2) {
1793 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1795 coex_dm->tdma_adj_type = 6;
1796 } else if (coex_dm->cur_ps_tdma == 3) {
1797 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1799 coex_dm->tdma_adj_type = 7;
1800 } else if (coex_dm->cur_ps_tdma == 4) {
1801 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1803 coex_dm->tdma_adj_type = 8;
1805 if (coex_dm->cur_ps_tdma == 9) {
1806 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1808 coex_dm->tdma_adj_type = 14;
1809 } else if (coex_dm->cur_ps_tdma == 10) {
1810 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1812 coex_dm->tdma_adj_type = 14;
1813 } else if (coex_dm->cur_ps_tdma == 11) {
1814 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1816 coex_dm->tdma_adj_type = 15;
1817 } else if (coex_dm->cur_ps_tdma == 12) {
1818 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1820 coex_dm->tdma_adj_type = 16;
1823 if (coex_dm->cur_ps_tdma == 5) {
1824 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1826 coex_dm->tdma_adj_type = 6;
1827 } else if (coex_dm->cur_ps_tdma == 6) {
1828 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1830 coex_dm->tdma_adj_type = 7;
1831 } else if (coex_dm->cur_ps_tdma == 7) {
1832 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1834 coex_dm->tdma_adj_type = 8;
1835 } else if (coex_dm->cur_ps_tdma == 13) {
1836 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1838 coex_dm->tdma_adj_type = 14;
1839 } else if (coex_dm->cur_ps_tdma == 14) {
1840 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1842 coex_dm->tdma_adj_type = 15;
1843 } else if (coex_dm->cur_ps_tdma == 15) {
1844 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1846 coex_dm->tdma_adj_type = 16;
1848 } else if (result == 1) {
1849 if (coex_dm->cur_ps_tdma == 8) {
1850 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1852 coex_dm->tdma_adj_type = 7;
1853 } else if (coex_dm->cur_ps_tdma == 7) {
1854 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1856 coex_dm->tdma_adj_type = 6;
1857 } else if (coex_dm->cur_ps_tdma == 6) {
1858 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1860 coex_dm->tdma_adj_type = 6;
1861 } else if (coex_dm->cur_ps_tdma == 16) {
1862 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1864 coex_dm->tdma_adj_type = 15;
1865 } else if (coex_dm->cur_ps_tdma == 15) {
1866 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1868 coex_dm->tdma_adj_type = 14;
1869 } else if (coex_dm->cur_ps_tdma == 14) {
1870 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1872 coex_dm->tdma_adj_type = 14;
1876 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1877 "[BTCoex], TxPause = 0\n");
1878 if (coex_dm->cur_ps_tdma == 5) {
1879 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1881 coex_dm->tdma_adj_type = 2;
1882 } else if (coex_dm->cur_ps_tdma == 6) {
1883 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1885 coex_dm->tdma_adj_type = 2;
1886 } else if (coex_dm->cur_ps_tdma == 7) {
1887 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1889 coex_dm->tdma_adj_type = 3;
1890 } else if (coex_dm->cur_ps_tdma == 8) {
1891 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1893 coex_dm->tdma_adj_type = 4;
1895 if (coex_dm->cur_ps_tdma == 13) {
1896 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1898 coex_dm->tdma_adj_type = 10;
1899 } else if (coex_dm->cur_ps_tdma == 14) {
1900 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1902 coex_dm->tdma_adj_type = 10;
1903 } else if (coex_dm->cur_ps_tdma == 15) {
1904 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1906 coex_dm->tdma_adj_type = 11;
1907 } else if (coex_dm->cur_ps_tdma == 16) {
1908 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1910 coex_dm->tdma_adj_type = 12;
1913 if (coex_dm->cur_ps_tdma == 1) {
1914 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1916 coex_dm->tdma_adj_type = 2;
1917 } else if (coex_dm->cur_ps_tdma == 2) {
1918 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1920 coex_dm->tdma_adj_type = 3;
1921 } else if (coex_dm->cur_ps_tdma == 3) {
1922 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1924 coex_dm->tdma_adj_type = 4;
1925 } else if (coex_dm->cur_ps_tdma == 9) {
1926 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1928 coex_dm->tdma_adj_type = 10;
1929 } else if (coex_dm->cur_ps_tdma == 10) {
1930 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1932 coex_dm->tdma_adj_type = 11;
1933 } else if (coex_dm->cur_ps_tdma == 11) {
1934 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1936 coex_dm->tdma_adj_type = 12;
1938 } else if (result == 1) {
1939 if (coex_dm->cur_ps_tdma == 4) {
1940 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1942 coex_dm->tdma_adj_type = 3;
1943 } else if (coex_dm->cur_ps_tdma == 3) {
1944 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1946 coex_dm->tdma_adj_type = 2;
1947 } else if (coex_dm->cur_ps_tdma == 2) {
1948 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1950 coex_dm->tdma_adj_type = 2;
1951 } else if (coex_dm->cur_ps_tdma == 12) {
1952 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1954 coex_dm->tdma_adj_type = 11;
1955 } else if (coex_dm->cur_ps_tdma == 11) {
1956 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1958 coex_dm->tdma_adj_type = 10;
1959 } else if (coex_dm->cur_ps_tdma == 10) {
1960 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1962 coex_dm->tdma_adj_type = 10;
1968 static void btc8192e_int3(struct btc_coexist *btcoexist, bool tx_pause,
1972 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1973 "[BTCoex], TxPause = 1\n");
1974 if (coex_dm->cur_ps_tdma == 1) {
1975 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1977 coex_dm->tdma_adj_type = 7;
1978 } else if (coex_dm->cur_ps_tdma == 2) {
1979 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1981 coex_dm->tdma_adj_type = 7;
1982 } else if (coex_dm->cur_ps_tdma == 3) {
1983 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1985 coex_dm->tdma_adj_type = 7;
1986 } else if (coex_dm->cur_ps_tdma == 4) {
1987 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1989 coex_dm->tdma_adj_type = 8;
1991 if (coex_dm->cur_ps_tdma == 9) {
1992 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1994 coex_dm->tdma_adj_type = 15;
1995 } else if (coex_dm->cur_ps_tdma == 10) {
1996 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1998 coex_dm->tdma_adj_type = 15;
1999 } else if (coex_dm->cur_ps_tdma == 11) {
2000 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2002 coex_dm->tdma_adj_type = 15;
2003 } else if (coex_dm->cur_ps_tdma == 12) {
2004 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2006 coex_dm->tdma_adj_type = 16;
2009 if (coex_dm->cur_ps_tdma == 5) {
2010 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2012 coex_dm->tdma_adj_type = 7;
2013 } else if (coex_dm->cur_ps_tdma == 6) {
2014 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2016 coex_dm->tdma_adj_type = 7;
2017 } else if (coex_dm->cur_ps_tdma == 7) {
2018 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2020 coex_dm->tdma_adj_type = 8;
2021 } else if (coex_dm->cur_ps_tdma == 13) {
2022 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2024 coex_dm->tdma_adj_type = 15;
2025 } else if (coex_dm->cur_ps_tdma == 14) {
2026 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2028 coex_dm->tdma_adj_type = 15;
2029 } else if (coex_dm->cur_ps_tdma == 15) {
2030 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2032 coex_dm->tdma_adj_type = 16;
2034 } else if (result == 1) {
2035 if (coex_dm->cur_ps_tdma == 8) {
2036 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2038 coex_dm->tdma_adj_type = 7;
2039 } else if (coex_dm->cur_ps_tdma == 7) {
2040 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2042 coex_dm->tdma_adj_type = 7;
2043 } else if (coex_dm->cur_ps_tdma == 6) {
2044 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2046 coex_dm->tdma_adj_type = 7;
2047 } else if (coex_dm->cur_ps_tdma == 16) {
2048 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2050 coex_dm->tdma_adj_type = 15;
2051 } else if (coex_dm->cur_ps_tdma == 15) {
2052 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2054 coex_dm->tdma_adj_type = 15;
2055 } else if (coex_dm->cur_ps_tdma == 14) {
2056 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2058 coex_dm->tdma_adj_type = 15;
2062 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2063 "[BTCoex], TxPause = 0\n");
2064 if (coex_dm->cur_ps_tdma == 5) {
2065 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2067 coex_dm->tdma_adj_type = 3;
2068 } else if (coex_dm->cur_ps_tdma == 6) {
2069 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2071 coex_dm->tdma_adj_type = 3;
2072 } else if (coex_dm->cur_ps_tdma == 7) {
2073 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2075 coex_dm->tdma_adj_type = 3;
2076 } else if (coex_dm->cur_ps_tdma == 8) {
2077 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2079 coex_dm->tdma_adj_type = 4;
2081 if (coex_dm->cur_ps_tdma == 13) {
2082 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2084 coex_dm->tdma_adj_type = 11;
2085 } else if (coex_dm->cur_ps_tdma == 14) {
2086 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2088 coex_dm->tdma_adj_type = 11;
2089 } else if (coex_dm->cur_ps_tdma == 15) {
2090 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2092 coex_dm->tdma_adj_type = 11;
2093 } else if (coex_dm->cur_ps_tdma == 16) {
2094 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2096 coex_dm->tdma_adj_type = 12;
2099 if (coex_dm->cur_ps_tdma == 1) {
2100 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2102 coex_dm->tdma_adj_type = 3;
2103 } else if (coex_dm->cur_ps_tdma == 2) {
2104 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2106 coex_dm->tdma_adj_type = 3;
2107 } else if (coex_dm->cur_ps_tdma == 3) {
2108 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2110 coex_dm->tdma_adj_type = 4;
2111 } else if (coex_dm->cur_ps_tdma == 9) {
2112 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2114 coex_dm->tdma_adj_type = 11;
2115 } else if (coex_dm->cur_ps_tdma == 10) {
2116 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2118 coex_dm->tdma_adj_type = 11;
2119 } else if (coex_dm->cur_ps_tdma == 11) {
2120 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2122 coex_dm->tdma_adj_type = 12;
2124 } else if (result == 1) {
2125 if (coex_dm->cur_ps_tdma == 4) {
2126 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2128 coex_dm->tdma_adj_type = 3;
2129 } else if (coex_dm->cur_ps_tdma == 3) {
2130 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2132 coex_dm->tdma_adj_type = 3;
2133 } else if (coex_dm->cur_ps_tdma == 2) {
2134 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2136 coex_dm->tdma_adj_type = 3;
2137 } else if (coex_dm->cur_ps_tdma == 12) {
2138 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2140 coex_dm->tdma_adj_type = 11;
2141 } else if (coex_dm->cur_ps_tdma == 11) {
2142 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2144 coex_dm->tdma_adj_type = 11;
2145 } else if (coex_dm->cur_ps_tdma == 10) {
2146 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2148 coex_dm->tdma_adj_type = 11;
2154 static void halbtc8192e2ant_tdma_duration_adjust(struct btc_coexist *btcoexist,
2155 bool sco_hid, bool tx_pause,
2158 static int up, dn, m, n, wait_cnt;
2159 /* 0: no change, +1: increase WiFi duration,
2160 * -1: decrease WiFi duration
2165 btc_alg_dbg(ALGO_TRACE_FW,
2166 "[BTCoex], TdmaDurationAdjust()\n");
2168 if (!coex_dm->auto_tdma_adjust) {
2169 coex_dm->auto_tdma_adjust = true;
2170 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2171 "[BTCoex], first run TdmaDurationAdjust()!!\n");
2174 if (max_interval == 1) {
2175 halbtc8192e2ant_ps_tdma(btcoexist,
2178 coex_dm->tdma_adj_type = 13;
2179 } else if (max_interval == 2) {
2180 halbtc8192e2ant_ps_tdma(btcoexist,
2183 coex_dm->tdma_adj_type = 14;
2184 } else if (max_interval == 3) {
2185 halbtc8192e2ant_ps_tdma(btcoexist,
2188 coex_dm->tdma_adj_type = 15;
2190 halbtc8192e2ant_ps_tdma(btcoexist,
2193 coex_dm->tdma_adj_type = 15;
2196 if (max_interval == 1) {
2197 halbtc8192e2ant_ps_tdma(btcoexist,
2200 coex_dm->tdma_adj_type = 9;
2201 } else if (max_interval == 2) {
2202 halbtc8192e2ant_ps_tdma(btcoexist,
2205 coex_dm->tdma_adj_type = 10;
2206 } else if (max_interval == 3) {
2207 halbtc8192e2ant_ps_tdma(btcoexist,
2210 coex_dm->tdma_adj_type = 11;
2212 halbtc8192e2ant_ps_tdma(btcoexist,
2215 coex_dm->tdma_adj_type = 11;
2220 if (max_interval == 1) {
2221 halbtc8192e2ant_ps_tdma(btcoexist,
2224 coex_dm->tdma_adj_type = 5;
2225 } else if (max_interval == 2) {
2226 halbtc8192e2ant_ps_tdma(btcoexist,
2229 coex_dm->tdma_adj_type = 6;
2230 } else if (max_interval == 3) {
2231 halbtc8192e2ant_ps_tdma(btcoexist,
2234 coex_dm->tdma_adj_type = 7;
2236 halbtc8192e2ant_ps_tdma(btcoexist,
2239 coex_dm->tdma_adj_type = 7;
2242 if (max_interval == 1) {
2243 halbtc8192e2ant_ps_tdma(btcoexist,
2246 coex_dm->tdma_adj_type = 1;
2247 } else if (max_interval == 2) {
2248 halbtc8192e2ant_ps_tdma(btcoexist,
2251 coex_dm->tdma_adj_type = 2;
2252 } else if (max_interval == 3) {
2253 halbtc8192e2ant_ps_tdma(btcoexist,
2256 coex_dm->tdma_adj_type = 3;
2258 halbtc8192e2ant_ps_tdma(btcoexist,
2261 coex_dm->tdma_adj_type = 3;
2273 /* accquire the BT TRx retry count from BT_Info byte2 */
2274 retry_cnt = coex_sta->bt_retry_cnt;
2275 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2276 "[BTCoex], retry_cnt = %d\n", retry_cnt);
2277 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2278 "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_cnt=%d\n",
2279 up, dn, m, n, wait_cnt);
2282 /* no retry in the last 2-second duration */
2283 if (retry_cnt == 0) {
2296 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2297 "[BTCoex]Increase wifi duration!!\n");
2299 } else if (retry_cnt <= 3) {
2320 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2321 "Reduce wifi duration for retry<3\n");
2337 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2338 "Decrease wifi duration for retryCounter>3!!\n");
2341 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2342 "[BTCoex], max Interval = %d\n", max_interval);
2343 if (max_interval == 1)
2344 btc8192e_int1(btcoexist, tx_pause, result);
2345 else if (max_interval == 2)
2346 btc8192e_int2(btcoexist, tx_pause, result);
2347 else if (max_interval == 3)
2348 btc8192e_int3(btcoexist, tx_pause, result);
2351 /* if current PsTdma not match with
2352 * the recorded one (when scan, dhcp...),
2353 * then we have to adjust it back to the previous record one.
2355 if (coex_dm->cur_ps_tdma != coex_dm->tdma_adj_type) {
2356 bool scan = false, link = false, roam = false;
2358 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2359 "[BTCoex], PsTdma type dismatch!!!, ");
2360 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2361 "curPsTdma=%d, recordPsTdma=%d\n",
2362 coex_dm->cur_ps_tdma, coex_dm->tdma_adj_type);
2364 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2365 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2366 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2368 if (!scan && !link && !roam)
2369 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2371 coex_dm->tdma_adj_type);
2373 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2374 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2378 /* SCO only or SCO+PAN(HS) */
2379 static void halbtc8192e2ant_action_sco(struct btc_coexist *btcoexist)
2381 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_STAY_LOW;
2384 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2386 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2387 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2389 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2391 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 4);
2393 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2395 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2396 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2397 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2398 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2399 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2400 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2401 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2402 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2403 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2404 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2405 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2406 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2409 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2412 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2413 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2414 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2415 btc8192e2ant_sw_mec1(btcoexist, true, true,
2417 btc8192e2ant_sw_mec2(btcoexist, true, false,
2420 btc8192e2ant_sw_mec1(btcoexist, true, true,
2422 btc8192e2ant_sw_mec2(btcoexist, false, false,
2426 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2427 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2428 btc8192e2ant_sw_mec1(btcoexist, false, true,
2430 btc8192e2ant_sw_mec2(btcoexist, true, false,
2433 btc8192e2ant_sw_mec1(btcoexist, false, true,
2435 btc8192e2ant_sw_mec2(btcoexist, false, false,
2441 static void halbtc8192e2ant_action_sco_pan(struct btc_coexist *btcoexist)
2443 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_STAY_LOW;
2446 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2448 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2449 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2451 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2453 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 4);
2455 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2457 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2458 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2459 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2460 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
2461 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2462 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2463 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2464 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
2465 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2466 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2467 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2468 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
2471 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2474 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2475 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2476 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2477 btc8192e2ant_sw_mec1(btcoexist, true, true,
2479 btc8192e2ant_sw_mec2(btcoexist, true, false,
2482 btc8192e2ant_sw_mec1(btcoexist, true, true,
2484 btc8192e2ant_sw_mec2(btcoexist, false, false,
2488 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2489 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2490 btc8192e2ant_sw_mec1(btcoexist, false, true,
2492 btc8192e2ant_sw_mec2(btcoexist, true, false,
2495 btc8192e2ant_sw_mec1(btcoexist, false, true,
2497 btc8192e2ant_sw_mec2(btcoexist, false, false,
2503 static void halbtc8192e2ant_action_hid(struct btc_coexist *btcoexist)
2505 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2508 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2509 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2511 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2512 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2514 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2516 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2518 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 3);
2520 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2521 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2522 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2523 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2524 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2525 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2526 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2527 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2528 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2529 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2530 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2531 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2535 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2536 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2537 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2538 btc8192e2ant_sw_mec1(btcoexist, true, true,
2540 btc8192e2ant_sw_mec2(btcoexist, true, false,
2543 btc8192e2ant_sw_mec1(btcoexist, true, true,
2545 btc8192e2ant_sw_mec2(btcoexist, false, false,
2549 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2550 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2551 btc8192e2ant_sw_mec1(btcoexist, false, true,
2553 btc8192e2ant_sw_mec2(btcoexist, true, false,
2556 btc8192e2ant_sw_mec1(btcoexist, false, true,
2558 btc8192e2ant_sw_mec2(btcoexist, false, false,
2564 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2565 static void halbtc8192e2ant_action_a2dp(struct btc_coexist *btcoexist)
2567 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2569 bool long_dist = false;
2571 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2572 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2574 if ((btrssi_state == BTC_RSSI_STATE_LOW ||
2575 btrssi_state == BTC_RSSI_STATE_STAY_LOW) &&
2576 (wifirssi_state == BTC_RSSI_STATE_LOW ||
2577 wifirssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2578 btc_alg_dbg(ALGO_TRACE,
2579 "[BTCoex], A2dp, wifi/bt rssi both LOW!!\n");
2583 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 2);
2584 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
2587 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2588 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2592 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2595 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 0);
2597 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 2);
2600 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 17);
2601 coex_dm->auto_tdma_adjust = false;
2602 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2604 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2605 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2606 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2608 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2609 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2610 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2611 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2613 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2614 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2615 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2616 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2618 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2623 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2624 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2625 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2626 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2627 btc8192e2ant_sw_mec1(btcoexist, true, false,
2629 btc8192e2ant_sw_mec2(btcoexist, true, false,
2632 btc8192e2ant_sw_mec1(btcoexist, true, false,
2634 btc8192e2ant_sw_mec2(btcoexist, false, false,
2638 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2639 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2640 btc8192e2ant_sw_mec1(btcoexist, false, false,
2642 btc8192e2ant_sw_mec2(btcoexist, true, false,
2645 btc8192e2ant_sw_mec1(btcoexist, false, false,
2647 btc8192e2ant_sw_mec2(btcoexist, false, false,
2653 static void halbtc8192e2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2655 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2658 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2659 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2661 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2662 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2664 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2665 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 2);
2667 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2668 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2669 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false, true, 2);
2670 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2671 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2672 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2673 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2675 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2676 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2677 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2678 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2680 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2684 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2685 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2686 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2687 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2688 btc8192e2ant_sw_mec1(btcoexist, true, false,
2690 btc8192e2ant_sw_mec2(btcoexist, true, false,
2693 btc8192e2ant_sw_mec1(btcoexist, true, false,
2695 btc8192e2ant_sw_mec2(btcoexist, false, false,
2699 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2700 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2701 btc8192e2ant_sw_mec1(btcoexist, false, false,
2703 btc8192e2ant_sw_mec2(btcoexist, true, false,
2706 btc8192e2ant_sw_mec1(btcoexist, false, false,
2708 btc8192e2ant_sw_mec2(btcoexist, false, false,
2714 static void halbtc8192e2ant_action_pan_edr(struct btc_coexist *btcoexist)
2716 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2719 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2720 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2722 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2723 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2725 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2727 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 2);
2729 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2730 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2731 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2732 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2733 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2734 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2735 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2736 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
2737 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2738 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2739 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2740 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
2744 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2745 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2746 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2747 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2748 btc8192e2ant_sw_mec1(btcoexist, true, false,
2750 btc8192e2ant_sw_mec2(btcoexist, true, false,
2753 btc8192e2ant_sw_mec1(btcoexist, true, false,
2755 btc8192e2ant_sw_mec2(btcoexist, false, false,
2759 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2760 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2761 btc8192e2ant_sw_mec1(btcoexist, false, false,
2763 btc8192e2ant_sw_mec2(btcoexist, true, false,
2766 btc8192e2ant_sw_mec1(btcoexist, false, false,
2768 btc8192e2ant_sw_mec2(btcoexist, false, false,
2775 static void halbtc8192e2ant_action_pan_hs(struct btc_coexist *btcoexist)
2777 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2780 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2781 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2783 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2784 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2786 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2788 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 2);
2790 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2791 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2792 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2793 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2794 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2795 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2796 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2797 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2798 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2800 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
2802 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2803 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2804 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2805 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2806 btc8192e2ant_sw_mec1(btcoexist, true, false,
2808 btc8192e2ant_sw_mec2(btcoexist, true, false,
2811 btc8192e2ant_sw_mec1(btcoexist, true, false,
2813 btc8192e2ant_sw_mec2(btcoexist, false, false,
2817 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2818 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2819 btc8192e2ant_sw_mec1(btcoexist, false, false,
2821 btc8192e2ant_sw_mec2(btcoexist, true, false,
2824 btc8192e2ant_sw_mec1(btcoexist, false, false,
2826 btc8192e2ant_sw_mec2(btcoexist, false, false,
2833 static void halbtc8192e2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
2835 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2838 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2839 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2841 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2842 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2844 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2846 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 2);
2848 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2850 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2851 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2852 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2853 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false, true, 3);
2854 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2855 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2856 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2857 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2859 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2860 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2861 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2862 halbtc8192e2ant_tdma_duration_adjust(btcoexist, false,
2867 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2868 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2869 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2870 btc8192e2ant_sw_mec1(btcoexist, true, false,
2872 btc8192e2ant_sw_mec2(btcoexist, true, false,
2875 btc8192e2ant_sw_mec1(btcoexist, true, false,
2877 btc8192e2ant_sw_mec2(btcoexist, false, false,
2881 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2882 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2883 btc8192e2ant_sw_mec1(btcoexist, false, false,
2885 btc8192e2ant_sw_mec2(btcoexist, true, false,
2888 btc8192e2ant_sw_mec1(btcoexist, false, false,
2890 btc8192e2ant_sw_mec2(btcoexist, false, false,
2896 static void halbtc8192e2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
2898 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2901 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2902 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2904 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2906 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2907 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2909 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2911 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 3);
2913 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2914 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2915 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2916 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
2917 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2918 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2919 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2920 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2922 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2923 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2924 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2925 halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2930 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2931 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2932 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2933 btc8192e2ant_sw_mec1(btcoexist, true, true,
2935 btc8192e2ant_sw_mec2(btcoexist, true, false,
2938 btc8192e2ant_sw_mec1(btcoexist, true, true,
2940 btc8192e2ant_sw_mec2(btcoexist, false, false,
2944 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2945 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2946 btc8192e2ant_sw_mec1(btcoexist, false, true,
2948 btc8192e2ant_sw_mec2(btcoexist, true, false,
2951 btc8192e2ant_sw_mec1(btcoexist, false, true,
2953 btc8192e2ant_sw_mec2(btcoexist, false, false,
2959 /* HID+A2DP+PAN(EDR) */
2960 static void btc8192e2ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
2962 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
2965 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
2966 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
2968 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
2969 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2971 halbtc8192e2ant_fw_dac_swinglvl(btcoexist, NORMAL_EXEC, 6);
2973 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2975 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 3);
2977 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
2978 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
2979 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
2980 halbtc8192e2ant_tdma_duration_adjust(btcoexist, true, true, 3);
2981 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
2982 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
2983 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
2984 halbtc8192e2ant_tdma_duration_adjust(btcoexist, true, false, 3);
2985 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
2986 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2987 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
2988 halbtc8192e2ant_tdma_duration_adjust(btcoexist, true, false, 3);
2992 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2993 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
2994 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2995 btc8192e2ant_sw_mec1(btcoexist, true, true,
2997 btc8192e2ant_sw_mec2(btcoexist, true, false,
3000 btc8192e2ant_sw_mec1(btcoexist, true, true,
3002 btc8192e2ant_sw_mec2(btcoexist, false, false,
3006 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
3007 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3008 btc8192e2ant_sw_mec1(btcoexist, false, true,
3010 btc8192e2ant_sw_mec2(btcoexist, true, false,
3013 btc8192e2ant_sw_mec1(btcoexist, false, true,
3015 btc8192e2ant_sw_mec2(btcoexist, false, false,
3021 static void halbtc8192e2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
3023 u8 wifirssi_state, btrssi_state = BTC_RSSI_STATE_HIGH;
3026 wifirssi_state = halbtc8192e2ant_wifirssi_state(btcoexist, 0, 2, 15, 0);
3027 btrssi_state = halbtc8192e2ant_btrssi_state(3, 34, 42);
3029 halbtc8192e2ant_switch_sstype(btcoexist, NORMAL_EXEC, 1);
3030 halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3032 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3034 btc8192e2ant_coex_tbl_w_type(btcoexist, NORMAL_EXEC, 3);
3036 if ((btrssi_state == BTC_RSSI_STATE_LOW) ||
3037 (btrssi_state == BTC_RSSI_STATE_STAY_LOW)) {
3038 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 0);
3039 halbtc8192e2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3040 } else if ((btrssi_state == BTC_RSSI_STATE_MEDIUM) ||
3041 (btrssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
3042 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 2);
3043 halbtc8192e2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3044 } else if ((btrssi_state == BTC_RSSI_STATE_HIGH) ||
3045 (btrssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3046 halbtc8192e2ant_dec_btpwr(btcoexist, NORMAL_EXEC, 4);
3047 halbtc8192e2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3051 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3052 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
3053 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3054 btc8192e2ant_sw_mec1(btcoexist, true, true,
3056 btc8192e2ant_sw_mec2(btcoexist, true, false,
3059 btc8192e2ant_sw_mec1(btcoexist, true, true,
3061 btc8192e2ant_sw_mec2(btcoexist, false, false,
3065 if ((wifirssi_state == BTC_RSSI_STATE_HIGH) ||
3066 (wifirssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3067 btc8192e2ant_sw_mec1(btcoexist, false, true,
3069 btc8192e2ant_sw_mec2(btcoexist, true, false,
3072 btc8192e2ant_sw_mec1(btcoexist, false, true,
3074 btc8192e2ant_sw_mec2(btcoexist, false, false,
3080 static void halbtc8192e2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3084 btc_alg_dbg(ALGO_TRACE,
3085 "[BTCoex], RunCoexistMechanism()===>\n");
3087 if (btcoexist->manual_control) {
3088 btc_alg_dbg(ALGO_TRACE,
3089 "[BTCoex], return for Manual CTRL <===\n");
3093 if (coex_sta->under_ips) {
3094 btc_alg_dbg(ALGO_TRACE,
3095 "[BTCoex], wifi is under IPS !!!\n");
3099 algorithm = halbtc8192e2ant_action_algorithm(btcoexist);
3100 if (coex_sta->c2h_bt_inquiry_page &&
3101 (BT_8192E_2ANT_COEX_ALGO_PANHS != algorithm)) {
3102 btc_alg_dbg(ALGO_TRACE,
3103 "[BTCoex], BT is under inquiry/page scan !!\n");
3104 halbtc8192e2ant_action_bt_inquiry(btcoexist);
3108 coex_dm->cur_algorithm = algorithm;
3109 btc_alg_dbg(ALGO_TRACE,
3110 "[BTCoex], Algorithm = %d\n", coex_dm->cur_algorithm);
3112 if (halbtc8192e2ant_is_common_action(btcoexist)) {
3113 btc_alg_dbg(ALGO_TRACE,
3114 "[BTCoex], Action 2-Ant common\n");
3115 coex_dm->auto_tdma_adjust = false;
3117 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3118 btc_alg_dbg(ALGO_TRACE,
3119 "[BTCoex] preAlgorithm=%d, curAlgorithm=%d\n",
3120 coex_dm->pre_algorithm,
3121 coex_dm->cur_algorithm);
3122 coex_dm->auto_tdma_adjust = false;
3124 switch (coex_dm->cur_algorithm) {
3125 case BT_8192E_2ANT_COEX_ALGO_SCO:
3126 btc_alg_dbg(ALGO_TRACE,
3127 "Action 2-Ant, algorithm = SCO\n");
3128 halbtc8192e2ant_action_sco(btcoexist);
3130 case BT_8192E_2ANT_COEX_ALGO_SCO_PAN:
3131 btc_alg_dbg(ALGO_TRACE,
3132 "Action 2-Ant, algorithm = SCO+PAN(EDR)\n");
3133 halbtc8192e2ant_action_sco_pan(btcoexist);
3135 case BT_8192E_2ANT_COEX_ALGO_HID:
3136 btc_alg_dbg(ALGO_TRACE,
3137 "Action 2-Ant, algorithm = HID\n");
3138 halbtc8192e2ant_action_hid(btcoexist);
3140 case BT_8192E_2ANT_COEX_ALGO_A2DP:
3141 btc_alg_dbg(ALGO_TRACE,
3142 "Action 2-Ant, algorithm = A2DP\n");
3143 halbtc8192e2ant_action_a2dp(btcoexist);
3145 case BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS:
3146 btc_alg_dbg(ALGO_TRACE,
3147 "Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
3148 halbtc8192e2ant_action_a2dp_pan_hs(btcoexist);
3150 case BT_8192E_2ANT_COEX_ALGO_PANEDR:
3151 btc_alg_dbg(ALGO_TRACE,
3152 "Action 2-Ant, algorithm = PAN(EDR)\n");
3153 halbtc8192e2ant_action_pan_edr(btcoexist);
3155 case BT_8192E_2ANT_COEX_ALGO_PANHS:
3156 btc_alg_dbg(ALGO_TRACE,
3157 "Action 2-Ant, algorithm = HS mode\n");
3158 halbtc8192e2ant_action_pan_hs(btcoexist);
3160 case BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP:
3161 btc_alg_dbg(ALGO_TRACE,
3162 "Action 2-Ant, algorithm = PAN+A2DP\n");
3163 halbtc8192e2ant_action_pan_edr_a2dp(btcoexist);
3165 case BT_8192E_2ANT_COEX_ALGO_PANEDR_HID:
3166 btc_alg_dbg(ALGO_TRACE,
3167 "Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3168 halbtc8192e2ant_action_pan_edr_hid(btcoexist);
3170 case BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3171 btc_alg_dbg(ALGO_TRACE,
3172 "Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3173 btc8192e2ant_action_hid_a2dp_pan_edr(btcoexist);
3175 case BT_8192E_2ANT_COEX_ALGO_HID_A2DP:
3176 btc_alg_dbg(ALGO_TRACE,
3177 "Action 2-Ant, algorithm = HID+A2DP\n");
3178 halbtc8192e2ant_action_hid_a2dp(btcoexist);
3181 btc_alg_dbg(ALGO_TRACE,
3182 "Action 2-Ant, algorithm = unknown!!\n");
3183 /* halbtc8192e2ant_coex_alloff(btcoexist); */
3186 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3190 static void halbtc8192e2ant_init_hwconfig(struct btc_coexist *btcoexist,
3196 btc_iface_dbg(INTF_INIT,
3197 "[BTCoex], 2Ant Init HW Config!!\n");
3200 /* backup rf 0x1e value */
3201 coex_dm->bt_rf0x1e_backup =
3202 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A,
3205 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
3207 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
3209 coex_dm->backup_retrylimit = btcoexist->btc_read_2byte(
3212 coex_dm->backup_ampdu_maxtime = btcoexist->btc_read_1byte(
3217 /* antenna sw ctrl to bt */
3218 btcoexist->btc_write_1byte(btcoexist, 0x4f, 0x6);
3219 btcoexist->btc_write_1byte(btcoexist, 0x944, 0x24);
3220 btcoexist->btc_write_4byte(btcoexist, 0x930, 0x700700);
3221 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20);
3222 if (btcoexist->chip_interface == BTC_INTF_USB)
3223 btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
3225 btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
3227 btc8192e2ant_coex_tbl_w_type(btcoexist, FORCE_EXEC, 0);
3229 /* antenna switch control parameter */
3230 btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555);
3232 /* coex parameters */
3233 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3234 /* 0x790[5:0] = 0x5 */
3235 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3238 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
3240 /* enable counter statistics */
3241 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
3244 btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
3245 /* enable mailbox interface */
3246 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x40);
3248 btcoexist->btc_write_2byte(btcoexist, 0x40, u16tmp);
3250 /* enable PTA I2C mailbox */
3251 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x101);
3253 btcoexist->btc_write_1byte(btcoexist, 0x101, u8tmp);
3255 /* enable bt clock when wifi is disabled. */
3256 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x93);
3258 btcoexist->btc_write_1byte(btcoexist, 0x93, u8tmp);
3259 /* enable bt clock when suspend. */
3260 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
3262 btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
3265 /*************************************************************
3266 * work around function start with wa_halbtc8192e2ant_
3267 *************************************************************/
3269 /************************************************************
3270 * extern function start with EXhalbtc8192e2ant_
3271 ************************************************************/
3273 void ex_halbtc8192e2ant_init_hwconfig(struct btc_coexist *btcoexist)
3275 halbtc8192e2ant_init_hwconfig(btcoexist, true);
3278 void ex_halbtc8192e2ant_init_coex_dm(struct btc_coexist *btcoexist)
3280 btc_iface_dbg(INTF_INIT,
3281 "[BTCoex], Coex Mechanism Init!!\n");
3282 halbtc8192e2ant_init_coex_dm(btcoexist);
3285 void ex_halbtc8192e2ant_display_coex_info(struct btc_coexist *btcoexist)
3287 struct btc_board_info *board_info = &btcoexist->board_info;
3288 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3289 struct rtl_priv *rtlpriv = btcoexist->adapter;
3290 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3293 bool roam = false, scan = false, link = false, wifi_under_5g = false;
3294 bool bt_hson = false, wifi_busy = false;
3295 int wifirssi = 0, bt_hs_rssi = 0;
3296 u32 wifi_bw, wifi_traffic_dir;
3297 u8 wifi_dot11_chnl, wifi_hs_chnl;
3298 u32 fw_ver = 0, bt_patch_ver = 0;
3300 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3301 "\r\n ============[BT Coexist info]============");
3303 if (btcoexist->manual_control) {
3304 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3305 "\r\n ===========[Under Manual Control]===========");
3306 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3307 "\r\n ==========================================");
3310 if (!board_info->bt_exist) {
3311 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
3315 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3316 "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
3317 board_info->pg_ant_num, board_info->btdm_ant_num);
3319 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d",
3320 "BT stack/ hci ext ver",
3321 ((stack_info->profile_notified) ? "Yes" : "No"),
3322 stack_info->hci_version);
3324 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3325 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3326 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3327 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
3328 "CoexVer/ FwVer/ PatchVer",
3329 glcoex_ver_date_8192e_2ant, glcoex_ver_8192e_2ant,
3330 fw_ver, bt_patch_ver, bt_patch_ver);
3332 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hson);
3333 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
3335 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
3336 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)",
3337 "Dot11 channel / HsMode(HsChnl)",
3338 wifi_dot11_chnl, bt_hson, wifi_hs_chnl);
3340 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %3ph ",
3341 "H2C Wifi inform bt chnl Info", coex_dm->wifi_chnl_info);
3343 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifirssi);
3344 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
3345 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3346 "Wifi rssi/ HS rssi", wifirssi, bt_hs_rssi);
3348 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3349 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3350 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3351 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
3352 "Wifi link/ roam/ scan", link, roam, scan);
3354 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3355 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3356 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3357 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
3359 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ",
3360 "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
3361 ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
3362 (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
3363 ((!wifi_busy) ? "idle" :
3364 ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
3365 "uplink" : "downlink")));
3367 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = [%s/ %d/ %d] ",
3368 "BT [status/ rssi/ retryCnt]",
3369 ((btcoexist->bt_info.bt_disabled) ? ("disabled") :
3370 ((coex_sta->c2h_bt_inquiry_page) ?
3371 ("inquiry/page scan") :
3372 ((BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3373 coex_dm->bt_status) ? "non-connected idle" :
3374 ((BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE ==
3375 coex_dm->bt_status) ? "connected-idle" : "busy")))),
3376 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
3378 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d / %d / %d",
3379 "SCO/HID/PAN/A2DP", stack_info->sco_exist,
3380 stack_info->hid_exist, stack_info->pan_exist,
3381 stack_info->a2dp_exist);
3382 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
3384 bt_info_ext = coex_sta->bt_info_ext;
3385 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
3386 "BT Info A2DP rate",
3387 (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
3389 for (i = 0; i < BT_INFO_SRC_8192E_2ANT_MAX; i++) {
3390 if (coex_sta->bt_info_c2h_cnt[i]) {
3391 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3392 "\r\n %-35s = %7ph(%d)",
3393 GLBtInfoSrc8192e2Ant[i],
3394 coex_sta->bt_info_c2h[i],
3395 coex_sta->bt_info_c2h_cnt[i]);
3399 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/%s",
3400 "PS state, IPS/LPS",
3401 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
3402 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
3403 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3405 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ", "SS Type",
3406 coex_dm->cur_sstype);
3409 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3410 "============[Sw mechanism]============");
3411 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
3412 "SM1[ShRf/ LpRA/ LimDig]", coex_dm->cur_rf_rx_lpf_shrink,
3413 coex_dm->cur_low_penalty_ra, coex_dm->limited_dig);
3414 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3415 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3416 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
3417 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
3419 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ", "Rate Mask",
3420 btcoexist->bt_info.ra_mask);
3423 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3424 "============[Fw mechanism]============");
3426 ps_tdma_case = coex_dm->cur_ps_tdma;
3427 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3428 "\r\n %-35s = %5ph case-%d (auto:%d)",
3429 "PS TDMA", coex_dm->ps_tdma_para,
3430 ps_tdma_case, coex_dm->auto_tdma_adjust);
3432 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d ",
3433 "DecBtPwr/ IgnWlanAct",
3434 coex_dm->cur_dec_bt_pwr, coex_dm->cur_ignore_wlan_act);
3437 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3438 "============[Hw setting]============");
3440 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x",
3441 "RF-A, 0x1e initVal", coex_dm->bt_rf0x1e_backup);
3443 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
3444 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm->backup_arfr_cnt1,
3445 coex_dm->backup_arfr_cnt2, coex_dm->backup_retrylimit,
3446 coex_dm->backup_ampdu_maxtime);
3448 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
3449 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
3450 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
3451 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
3452 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
3453 "0x430/0x434/0x42a/0x456",
3454 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
3456 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc04);
3457 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xd04);
3458 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x90c);
3459 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3460 "0xc04/ 0xd04/ 0x90c", u32tmp[0], u32tmp[1], u32tmp[2]);
3462 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
3463 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x", "0x778",
3466 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x92c);
3467 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x930);
3468 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3469 "0x92c/ 0x930", (u8tmp[0]), u32tmp[0]);
3471 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
3472 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x4f);
3473 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3474 "0x40/ 0x4f", u8tmp[0], u8tmp[1]);
3476 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
3477 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
3478 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3479 "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
3481 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
3482 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x", "0xc50(dig)",
3485 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
3486 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
3487 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
3488 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
3489 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3490 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3491 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
3492 u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
3494 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3495 "0x770(hp rx[31:16]/tx[15:0])",
3496 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
3497 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3498 "0x774(lp rx[31:16]/tx[15:0])",
3499 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
3500 #if (BT_AUTO_REPORT_ONLY_8192E_2ANT == 1)
3501 halbtc8192e2ant_monitor_bt_ctr(btcoexist);
3503 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
3506 void ex_halbtc8192e2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
3508 if (BTC_IPS_ENTER == type) {
3509 btc_iface_dbg(INTF_NOTIFY,
3510 "[BTCoex], IPS ENTER notify\n");
3511 coex_sta->under_ips = true;
3512 halbtc8192e2ant_coex_alloff(btcoexist);
3513 } else if (BTC_IPS_LEAVE == type) {
3514 btc_iface_dbg(INTF_NOTIFY,
3515 "[BTCoex], IPS LEAVE notify\n");
3516 coex_sta->under_ips = false;
3520 void ex_halbtc8192e2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
3522 if (BTC_LPS_ENABLE == type) {
3523 btc_iface_dbg(INTF_NOTIFY,
3524 "[BTCoex], LPS ENABLE notify\n");
3525 coex_sta->under_lps = true;
3526 } else if (BTC_LPS_DISABLE == type) {
3527 btc_iface_dbg(INTF_NOTIFY,
3528 "[BTCoex], LPS DISABLE notify\n");
3529 coex_sta->under_lps = false;
3533 void ex_halbtc8192e2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
3535 if (BTC_SCAN_START == type)
3536 btc_iface_dbg(INTF_NOTIFY,
3537 "[BTCoex], SCAN START notify\n");
3538 else if (BTC_SCAN_FINISH == type)
3539 btc_iface_dbg(INTF_NOTIFY,
3540 "[BTCoex], SCAN FINISH notify\n");
3543 void ex_halbtc8192e2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
3545 if (BTC_ASSOCIATE_START == type)
3546 btc_iface_dbg(INTF_NOTIFY,
3547 "[BTCoex], CONNECT START notify\n");
3548 else if (BTC_ASSOCIATE_FINISH == type)
3549 btc_iface_dbg(INTF_NOTIFY,
3550 "[BTCoex], CONNECT FINISH notify\n");
3553 void ex_halbtc8192e2ant_media_status_notify(struct btc_coexist *btcoexist,
3556 u8 h2c_parameter[3] = {0};
3558 u8 wifi_center_chnl;
3560 if (btcoexist->manual_control ||
3561 btcoexist->stop_coex_dm ||
3562 btcoexist->bt_info.bt_disabled)
3565 if (BTC_MEDIA_CONNECT == type)
3566 btc_iface_dbg(INTF_NOTIFY,
3567 "[BTCoex], MEDIA connect notify\n");
3569 btc_iface_dbg(INTF_NOTIFY,
3570 "[BTCoex], MEDIA disconnect notify\n");
3572 /* only 2.4G we need to inform bt the chnl mask */
3573 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
3575 if ((BTC_MEDIA_CONNECT == type) &&
3576 (wifi_center_chnl <= 14)) {
3577 h2c_parameter[0] = 0x1;
3578 h2c_parameter[1] = wifi_center_chnl;
3579 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3580 if (BTC_WIFI_BW_HT40 == wifi_bw)
3581 h2c_parameter[2] = 0x30;
3583 h2c_parameter[2] = 0x20;
3586 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3587 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3588 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3590 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
3591 "[BTCoex], FW write 0x66 = 0x%x\n",
3592 h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
3595 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3598 void ex_halbtc8192e2ant_special_packet_notify(struct btc_coexist *btcoexist,
3601 if (type == BTC_PACKET_DHCP)
3602 btc_iface_dbg(INTF_NOTIFY,
3603 "[BTCoex], DHCP Packet notify\n");
3606 void ex_halbtc8192e2ant_bt_info_notify(struct btc_coexist *btcoexist,
3607 u8 *tmp_buf, u8 length)
3610 u8 i, rsp_source = 0;
3611 bool bt_busy = false, limited_dig = false;
3612 bool wifi_connected = false;
3614 coex_sta->c2h_bt_info_req_sent = false;
3616 rsp_source = tmp_buf[0] & 0xf;
3617 if (rsp_source >= BT_INFO_SRC_8192E_2ANT_MAX)
3618 rsp_source = BT_INFO_SRC_8192E_2ANT_WIFI_FW;
3619 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3621 btc_iface_dbg(INTF_NOTIFY,
3622 "[BTCoex], Bt info[%d], length=%d, hex data = [",
3623 rsp_source, length);
3624 for (i = 0; i < length; i++) {
3625 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3627 bt_info = tmp_buf[i];
3629 btc_iface_dbg(INTF_NOTIFY,
3630 "0x%02x]\n", tmp_buf[i]);
3632 btc_iface_dbg(INTF_NOTIFY,
3633 "0x%02x, ", tmp_buf[i]);
3636 if (BT_INFO_SRC_8192E_2ANT_WIFI_FW != rsp_source) {
3637 coex_sta->bt_retry_cnt = /* [3:0] */
3638 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3641 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
3643 coex_sta->bt_info_ext =
3644 coex_sta->bt_info_c2h[rsp_source][4];
3646 /* Here we need to resend some wifi info to BT
3647 * because bt is reset and loss of the info.
3649 if ((coex_sta->bt_info_ext & BIT1)) {
3650 btc_alg_dbg(ALGO_TRACE,
3651 "bit1, send wifi BW&Chnl to BT!!\n");
3652 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3655 ex_halbtc8192e2ant_media_status_notify(
3659 ex_halbtc8192e2ant_media_status_notify(
3661 BTC_MEDIA_DISCONNECT);
3664 if ((coex_sta->bt_info_ext & BIT3)) {
3665 if (!btcoexist->manual_control &&
3666 !btcoexist->stop_coex_dm) {
3667 btc_alg_dbg(ALGO_TRACE,
3668 "bit3, BT NOT ignore Wlan active!\n");
3669 halbtc8192e2ant_IgnoreWlanAct(btcoexist,
3674 /* BT already NOT ignore Wlan active,
3679 #if (BT_AUTO_REPORT_ONLY_8192E_2ANT == 0)
3680 if ((coex_sta->bt_info_ext & BIT4)) {
3681 /* BT auto report already enabled, do nothing */
3683 halbtc8192e2ant_bt_autoreport(btcoexist, FORCE_EXEC,
3689 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3690 if (bt_info & BT_INFO_8192E_2ANT_B_INQ_PAGE)
3691 coex_sta->c2h_bt_inquiry_page = true;
3693 coex_sta->c2h_bt_inquiry_page = false;
3695 /* set link exist status */
3696 if (!(bt_info&BT_INFO_8192E_2ANT_B_CONNECTION)) {
3697 coex_sta->bt_link_exist = false;
3698 coex_sta->pan_exist = false;
3699 coex_sta->a2dp_exist = false;
3700 coex_sta->hid_exist = false;
3701 coex_sta->sco_exist = false;
3702 } else {/* connection exists */
3703 coex_sta->bt_link_exist = true;
3704 if (bt_info & BT_INFO_8192E_2ANT_B_FTP)
3705 coex_sta->pan_exist = true;
3707 coex_sta->pan_exist = false;
3708 if (bt_info & BT_INFO_8192E_2ANT_B_A2DP)
3709 coex_sta->a2dp_exist = true;
3711 coex_sta->a2dp_exist = false;
3712 if (bt_info & BT_INFO_8192E_2ANT_B_HID)
3713 coex_sta->hid_exist = true;
3715 coex_sta->hid_exist = false;
3716 if (bt_info & BT_INFO_8192E_2ANT_B_SCO_ESCO)
3717 coex_sta->sco_exist = true;
3719 coex_sta->sco_exist = false;
3722 halbtc8192e2ant_update_btlink_info(btcoexist);
3724 if (!(bt_info&BT_INFO_8192E_2ANT_B_CONNECTION)) {
3725 coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
3726 btc_alg_dbg(ALGO_TRACE,
3727 "[BTCoex], BT Non-Connected idle!!!\n");
3728 } else if (bt_info == BT_INFO_8192E_2ANT_B_CONNECTION) {
3729 coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE;
3730 btc_alg_dbg(ALGO_TRACE,
3731 "[BTCoex], bt_infoNotify(), BT Connected-idle!!!\n");
3732 } else if ((bt_info&BT_INFO_8192E_2ANT_B_SCO_ESCO) ||
3733 (bt_info&BT_INFO_8192E_2ANT_B_SCO_BUSY)) {
3734 coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_SCO_BUSY;
3735 btc_alg_dbg(ALGO_TRACE,
3736 "[BTCoex], bt_infoNotify(), BT SCO busy!!!\n");
3737 } else if (bt_info&BT_INFO_8192E_2ANT_B_ACL_BUSY) {
3738 coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_ACL_BUSY;
3739 btc_alg_dbg(ALGO_TRACE,
3740 "[BTCoex], bt_infoNotify(), BT ACL busy!!!\n");
3742 coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_MAX;
3743 btc_alg_dbg(ALGO_TRACE,
3744 "[BTCoex]bt_infoNotify(), BT Non-Defined state!!!\n");
3747 if ((BT_8192E_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3748 (BT_8192E_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3749 (BT_8192E_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
3754 limited_dig = false;
3757 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3759 coex_dm->limited_dig = limited_dig;
3760 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
3762 halbtc8192e2ant_run_coexist_mechanism(btcoexist);
3765 void ex_halbtc8192e2ant_stack_operation_notify(struct btc_coexist *btcoexist,
3770 void ex_halbtc8192e2ant_halt_notify(struct btc_coexist *btcoexist)
3772 btc_iface_dbg(INTF_NOTIFY, "[BTCoex], Halt notify\n");
3774 halbtc8192e2ant_IgnoreWlanAct(btcoexist, FORCE_EXEC, true);
3775 ex_halbtc8192e2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3778 void ex_halbtc8192e2ant_periodical(struct btc_coexist *btcoexist)
3780 static u8 dis_ver_info_cnt;
3781 u32 fw_ver = 0, bt_patch_ver = 0;
3782 struct btc_board_info *board_info = &btcoexist->board_info;
3783 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3785 btc_alg_dbg(ALGO_TRACE,
3786 "=======================Periodical=======================\n");
3787 if (dis_ver_info_cnt <= 5) {
3788 dis_ver_info_cnt += 1;
3789 btc_iface_dbg(INTF_INIT,
3790 "************************************************\n");
3791 btc_iface_dbg(INTF_INIT,
3792 "Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
3793 board_info->pg_ant_num, board_info->btdm_ant_num,
3794 board_info->btdm_ant_pos);
3795 btc_iface_dbg(INTF_INIT,
3796 "BT stack/ hci ext ver = %s / %d\n",
3797 ((stack_info->profile_notified) ? "Yes" : "No"),
3798 stack_info->hci_version);
3799 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
3801 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3802 btc_iface_dbg(INTF_INIT,
3803 "CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
3804 glcoex_ver_date_8192e_2ant, glcoex_ver_8192e_2ant,
3805 fw_ver, bt_patch_ver, bt_patch_ver);
3806 btc_iface_dbg(INTF_INIT,
3807 "************************************************\n");
3810 #if (BT_AUTO_REPORT_ONLY_8192E_2ANT == 0)
3811 halbtc8192e2ant_querybt_info(btcoexist);
3812 halbtc8192e2ant_monitor_bt_ctr(btcoexist);
3813 btc8192e2ant_monitor_bt_enable_dis(btcoexist);
3815 if (halbtc8192e2ant_iswifi_status_changed(btcoexist) ||
3816 coex_dm->auto_tdma_adjust)
3817 halbtc8192e2ant_run_coexist_mechanism(btcoexist);