1 /***************************************************************
4 * This file is for RTL8723B Co-exist mechanism
7 * 2012/11/15 Cosa first check in.
9 ***************************************************************/
11 /***************************************************************
13 ***************************************************************/
14 #include "halbt_precomp.h"
15 /***************************************************************
16 * Global variables, these are static variables
17 ***************************************************************/
18 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant
;
19 static struct coex_dm_8723b_1ant
*coex_dm
= &glcoex_dm_8723b_1ant
;
20 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant
;
21 static struct coex_sta_8723b_1ant
*coex_sta
= &glcoex_sta_8723b_1ant
;
23 static const char *const glb_infosrc8723b1ant
[] = {
26 "BT Info[bt auto report]",
29 static u32 glcoex_ver_date_8723b_1ant
= 20130918;
30 static u32 glcoex_ver_8723b_1ant
= 0x47;
32 /***************************************************************
33 * local function proto type if needed
34 ***************************************************************/
35 /***************************************************************
36 * local function start with halbtc8723b1ant_
37 ***************************************************************/
38 static u8
halbtc8723b1ant_bt_rssi_state(u8 level_num
, u8 rssi_thresh
,
42 u8 rssi_state
= coex_sta
->pre_bt_rssi_state
;
44 bt_rssi
= coex_sta
->bt_rssi
;
47 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
48 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
49 if (bt_rssi
>= rssi_thresh
+
50 BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT
) {
51 rssi_state
= BTC_RSSI_STATE_HIGH
;
52 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
53 "[BTCoex], BT Rssi state switch to High\n");
55 rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
56 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
57 "[BTCoex], BT Rssi state stay at Low\n");
60 if (bt_rssi
< rssi_thresh
) {
61 rssi_state
= BTC_RSSI_STATE_LOW
;
62 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
63 "[BTCoex], BT Rssi state switch to Low\n");
65 rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
66 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
67 "[BTCoex], BT Rssi state stay at High\n");
70 } else if (level_num
== 3) {
71 if (rssi_thresh
> rssi_thresh1
) {
72 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
73 "[BTCoex], BT Rssi thresh error!!\n");
74 return coex_sta
->pre_bt_rssi_state
;
77 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
78 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
79 if (bt_rssi
>= rssi_thresh
+
80 BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT
) {
81 rssi_state
= BTC_RSSI_STATE_MEDIUM
;
82 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
83 "[BTCoex], BT Rssi state switch to Medium\n");
85 rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
86 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
87 "[BTCoex], BT Rssi state stay at Low\n");
89 } else if ((coex_sta
->pre_bt_rssi_state
==
90 BTC_RSSI_STATE_MEDIUM
) ||
91 (coex_sta
->pre_bt_rssi_state
==
92 BTC_RSSI_STATE_STAY_MEDIUM
)) {
93 if (bt_rssi
>= rssi_thresh1
+
94 BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT
) {
95 rssi_state
= BTC_RSSI_STATE_HIGH
;
96 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
97 "[BTCoex], BT Rssi state switch to High\n");
98 } else if (bt_rssi
< rssi_thresh
) {
99 rssi_state
= BTC_RSSI_STATE_LOW
;
100 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
101 "[BTCoex], BT Rssi state switch to Low\n");
103 rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
104 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
105 "[BTCoex], BT Rssi state stay at Medium\n");
108 if (bt_rssi
< rssi_thresh1
) {
109 rssi_state
= BTC_RSSI_STATE_MEDIUM
;
110 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
111 "[BTCoex], BT Rssi state switch to Medium\n");
113 rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
114 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_RSSI_STATE
,
115 "[BTCoex], BT Rssi state stay at High\n");
120 coex_sta
->pre_bt_rssi_state
= rssi_state
;
125 static u8
halbtc8723b1ant_wifi_rssi_state(struct btc_coexist
*btcoexist
,
126 u8 index
, u8 level_num
,
127 u8 rssi_thresh
, u8 rssi_thresh1
)
130 u8 wifi_rssi_state
= coex_sta
->pre_wifi_rssi_state
[index
];
132 btcoexist
->btc_get(btcoexist
,
133 BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
135 if (level_num
== 2) {
136 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
137 BTC_RSSI_STATE_LOW
) ||
138 (coex_sta
->pre_wifi_rssi_state
[index
] ==
139 BTC_RSSI_STATE_STAY_LOW
)) {
140 if (wifi_rssi
>= rssi_thresh
+
141 BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT
) {
142 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
143 BTC_PRINT(BTC_MSG_ALGORITHM
,
144 ALGO_WIFI_RSSI_STATE
,
145 "[BTCoex], wifi RSSI state switch to High\n");
147 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
148 BTC_PRINT(BTC_MSG_ALGORITHM
,
149 ALGO_WIFI_RSSI_STATE
,
150 "[BTCoex], wifi RSSI state stay at Low\n");
153 if (wifi_rssi
< rssi_thresh
) {
154 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
155 BTC_PRINT(BTC_MSG_ALGORITHM
,
156 ALGO_WIFI_RSSI_STATE
,
157 "[BTCoex], wifi RSSI state switch to Low\n");
159 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
160 BTC_PRINT(BTC_MSG_ALGORITHM
,
161 ALGO_WIFI_RSSI_STATE
,
162 "[BTCoex], wifi RSSI state stay at High\n");
165 } else if (level_num
== 3) {
166 if (rssi_thresh
> rssi_thresh1
) {
167 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_WIFI_RSSI_STATE
,
168 "[BTCoex], wifi RSSI thresh error!!\n");
169 return coex_sta
->pre_wifi_rssi_state
[index
];
172 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
173 BTC_RSSI_STATE_LOW
) ||
174 (coex_sta
->pre_wifi_rssi_state
[index
] ==
175 BTC_RSSI_STATE_STAY_LOW
)) {
176 if (wifi_rssi
>= rssi_thresh
+
177 BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT
) {
178 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
179 BTC_PRINT(BTC_MSG_ALGORITHM
,
180 ALGO_WIFI_RSSI_STATE
,
181 "[BTCoex], wifi RSSI state switch to Medium\n");
183 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
184 BTC_PRINT(BTC_MSG_ALGORITHM
,
185 ALGO_WIFI_RSSI_STATE
,
186 "[BTCoex], wifi RSSI state stay at Low\n");
188 } else if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
189 BTC_RSSI_STATE_MEDIUM
) ||
190 (coex_sta
->pre_wifi_rssi_state
[index
] ==
191 BTC_RSSI_STATE_STAY_MEDIUM
)) {
192 if (wifi_rssi
>= rssi_thresh1
+
193 BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT
) {
194 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
195 BTC_PRINT(BTC_MSG_ALGORITHM
,
196 ALGO_WIFI_RSSI_STATE
,
197 "[BTCoex], wifi RSSI state switch to High\n");
198 } else if (wifi_rssi
< rssi_thresh
) {
199 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
200 BTC_PRINT(BTC_MSG_ALGORITHM
,
201 ALGO_WIFI_RSSI_STATE
,
202 "[BTCoex], wifi RSSI state switch to Low\n");
204 wifi_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
205 BTC_PRINT(BTC_MSG_ALGORITHM
,
206 ALGO_WIFI_RSSI_STATE
,
207 "[BTCoex], wifi RSSI state stay at Medium\n");
210 if (wifi_rssi
< rssi_thresh1
) {
211 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
212 BTC_PRINT(BTC_MSG_ALGORITHM
,
213 ALGO_WIFI_RSSI_STATE
,
214 "[BTCoex], wifi RSSI state switch to Medium\n");
216 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
217 BTC_PRINT(BTC_MSG_ALGORITHM
,
218 ALGO_WIFI_RSSI_STATE
,
219 "[BTCoex], wifi RSSI state stay at High\n");
224 coex_sta
->pre_wifi_rssi_state
[index
] = wifi_rssi_state
;
226 return wifi_rssi_state
;
229 static void halbtc8723b1ant_updatera_mask(struct btc_coexist
*btcoexist
,
230 bool force_exec
, u32 dis_rate_mask
)
232 coex_dm
->curra_mask
= dis_rate_mask
;
234 if (force_exec
|| (coex_dm
->prera_mask
!= coex_dm
->curra_mask
))
235 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_UPDATE_ra_mask
,
236 &coex_dm
->curra_mask
);
238 coex_dm
->prera_mask
= coex_dm
->curra_mask
;
241 static void auto_rate_fallback_retry(struct btc_coexist
*btcoexist
,
242 bool force_exec
, u8 type
)
244 bool wifi_under_bmode
= false;
246 coex_dm
->cur_arfr_type
= type
;
248 if (force_exec
|| (coex_dm
->pre_arfr_type
!= coex_dm
->cur_arfr_type
)) {
249 switch (coex_dm
->cur_arfr_type
) {
250 case 0: /* normal mode */
251 btcoexist
->btc_write_4byte(btcoexist
, 0x430,
252 coex_dm
->backup_arfr_cnt1
);
253 btcoexist
->btc_write_4byte(btcoexist
, 0x434,
254 coex_dm
->backup_arfr_cnt2
);
257 btcoexist
->btc_get(btcoexist
,
258 BTC_GET_BL_WIFI_UNDER_B_MODE
,
260 if (wifi_under_bmode
) {
261 btcoexist
->btc_write_4byte(btcoexist
,
263 btcoexist
->btc_write_4byte(btcoexist
,
266 btcoexist
->btc_write_4byte(btcoexist
,
268 btcoexist
->btc_write_4byte(btcoexist
,
277 coex_dm
->pre_arfr_type
= coex_dm
->cur_arfr_type
;
280 static void halbtc8723b1ant_retry_limit(struct btc_coexist
*btcoexist
,
281 bool force_exec
, u8 type
)
283 coex_dm
->cur_retry_limit_type
= type
;
285 if (force_exec
|| (coex_dm
->pre_retry_limit_type
!=
286 coex_dm
->cur_retry_limit_type
)) {
287 switch (coex_dm
->cur_retry_limit_type
) {
288 case 0: /* normal mode */
289 btcoexist
->btc_write_2byte(btcoexist
, 0x42a,
290 coex_dm
->backup_retry_limit
);
292 case 1: /* retry limit = 8 */
293 btcoexist
->btc_write_2byte(btcoexist
, 0x42a, 0x0808);
300 coex_dm
->pre_retry_limit_type
= coex_dm
->cur_retry_limit_type
;
303 static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist
*btcoexist
,
304 bool force_exec
, u8 type
)
306 coex_dm
->cur_ampdu_time_type
= type
;
308 if (force_exec
|| (coex_dm
->pre_ampdu_time_type
!=
309 coex_dm
->cur_ampdu_time_type
)) {
310 switch (coex_dm
->cur_ampdu_time_type
) {
311 case 0: /* normal mode */
312 btcoexist
->btc_write_1byte(btcoexist
, 0x456,
313 coex_dm
->backup_ampdu_max_time
);
315 case 1: /* AMPDU timw = 0x38 * 32us */
316 btcoexist
->btc_write_1byte(btcoexist
,
324 coex_dm
->pre_ampdu_time_type
= coex_dm
->cur_ampdu_time_type
;
327 static void halbtc8723b1ant_limited_tx(struct btc_coexist
*btcoexist
,
328 bool force_exec
, u8 ra_masktype
,
329 u8 arfr_type
, u8 retry_limit_type
,
332 switch (ra_masktype
) {
333 case 0: /* normal mode */
334 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
, 0x0);
336 case 1: /* disable cck 1/2 */
337 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
,
340 /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4*/
342 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
,
349 auto_rate_fallback_retry(btcoexist
, force_exec
, arfr_type
);
350 halbtc8723b1ant_retry_limit(btcoexist
, force_exec
, retry_limit_type
);
351 halbtc8723b1ant_ampdu_maxtime(btcoexist
, force_exec
, ampdu_time_type
);
354 static void halbtc8723b1ant_limited_rx(struct btc_coexist
*btcoexist
,
355 bool force_exec
, bool rej_ap_agg_pkt
,
356 bool b_bt_ctrl_agg_buf_size
, u8 agg_buf_size
)
358 bool reject_rx_agg
= rej_ap_agg_pkt
;
359 bool bt_ctrl_rx_agg_size
= b_bt_ctrl_agg_buf_size
;
360 u8 rxaggsize
= agg_buf_size
;
362 /**********************************************
363 * Rx Aggregation related setting
364 **********************************************/
365 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_TO_REJ_AP_AGG_PKT
,
367 /* decide BT control aggregation buf size or not */
368 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
369 &bt_ctrl_rx_agg_size
);
370 /* aggregation buf size, only work
371 *when BT control Rx aggregation size. */
372 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rxaggsize
);
373 /* real update aggregation setting */
374 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
377 static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
379 u32 reg_hp_txrx
, reg_lp_txrx
, u32tmp
;
380 u32 reg_hp_tx
= 0, reg_hp_rx
= 0;
381 u32 reg_lp_tx
= 0, reg_lp_rx
= 0;
386 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
387 reg_hp_tx
= u32tmp
& MASKLWORD
;
388 reg_hp_rx
= (u32tmp
& MASKHWORD
) >> 16;
390 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
391 reg_lp_tx
= u32tmp
& MASKLWORD
;
392 reg_lp_rx
= (u32tmp
& MASKHWORD
) >> 16;
394 coex_sta
->high_priority_tx
= reg_hp_tx
;
395 coex_sta
->high_priority_rx
= reg_hp_rx
;
396 coex_sta
->low_priority_tx
= reg_lp_tx
;
397 coex_sta
->low_priority_rx
= reg_lp_rx
;
400 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
403 static void halbtc8723b1ant_query_bt_info(struct btc_coexist
*btcoexist
)
405 u8 h2c_parameter
[1] = {0};
407 coex_sta
->c2h_bt_info_req_sent
= true;
409 h2c_parameter
[0] |= BIT(0); /* trigger*/
411 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
,
412 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
415 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
418 static bool is_wifi_status_changed(struct btc_coexist
*btcoexist
)
420 static bool pre_wifi_busy
;
421 static bool pre_under_4way
, pre_bt_hs_on
;
422 bool wifi_busy
= false, under_4way
= false, bt_hs_on
= false;
423 bool wifi_connected
= false;
425 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
427 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
428 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
429 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
432 if (wifi_connected
) {
433 if (wifi_busy
!= pre_wifi_busy
) {
434 pre_wifi_busy
= wifi_busy
;
437 if (under_4way
!= pre_under_4way
) {
438 pre_under_4way
= under_4way
;
441 if (bt_hs_on
!= pre_bt_hs_on
) {
442 pre_bt_hs_on
= bt_hs_on
;
450 static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
452 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
453 bool bt_hs_on
= false;
455 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
457 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
458 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
459 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
460 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
461 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
463 /* work around for HS mode. */
465 bt_link_info
->pan_exist
= true;
466 bt_link_info
->bt_link_exist
= true;
469 /* check if Sco only */
470 if (bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
471 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
472 bt_link_info
->sco_only
= true;
474 bt_link_info
->sco_only
= false;
476 /* check if A2dp only */
477 if (!bt_link_info
->sco_exist
&& bt_link_info
->a2dp_exist
&&
478 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
479 bt_link_info
->a2dp_only
= true;
481 bt_link_info
->a2dp_only
= false;
483 /* check if Pan only */
484 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
485 bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
486 bt_link_info
->pan_only
= true;
488 bt_link_info
->pan_only
= false;
490 /* check if Hid only */
491 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
492 !bt_link_info
->pan_exist
&& bt_link_info
->hid_exist
)
493 bt_link_info
->hid_only
= true;
495 bt_link_info
->hid_only
= false;
498 static u8
halbtc8723b1ant_action_algorithm(struct btc_coexist
*btcoexist
)
500 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
501 bool bt_hs_on
= false;
502 u8 algorithm
= BT_8723B_1ANT_COEX_ALGO_UNDEFINED
;
503 u8 numofdiffprofile
= 0;
505 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
507 if (!bt_link_info
->bt_link_exist
) {
508 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
509 "[BTCoex], No BT link exists!!!\n");
513 if (bt_link_info
->sco_exist
)
515 if (bt_link_info
->hid_exist
)
517 if (bt_link_info
->pan_exist
)
519 if (bt_link_info
->a2dp_exist
)
522 if (numofdiffprofile
== 1) {
523 if (bt_link_info
->sco_exist
) {
524 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
525 "[BTCoex], BT Profile = SCO only\n");
526 algorithm
= BT_8723B_1ANT_COEX_ALGO_SCO
;
528 if (bt_link_info
->hid_exist
) {
529 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
530 "[BTCoex], BT Profile = HID only\n");
531 algorithm
= BT_8723B_1ANT_COEX_ALGO_HID
;
532 } else if (bt_link_info
->a2dp_exist
) {
533 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
534 "[BTCoex], BT Profile = A2DP only\n");
535 algorithm
= BT_8723B_1ANT_COEX_ALGO_A2DP
;
536 } else if (bt_link_info
->pan_exist
) {
538 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
539 "[BTCoex], BT Profile = PAN(HS) only\n");
541 BT_8723B_1ANT_COEX_ALGO_PANHS
;
543 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
544 "[BTCoex], BT Profile = PAN(EDR) only\n");
546 BT_8723B_1ANT_COEX_ALGO_PANEDR
;
550 } else if (numofdiffprofile
== 2) {
551 if (bt_link_info
->sco_exist
) {
552 if (bt_link_info
->hid_exist
) {
553 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
554 "[BTCoex], BT Profile = SCO + HID\n");
555 algorithm
= BT_8723B_1ANT_COEX_ALGO_HID
;
556 } else if (bt_link_info
->a2dp_exist
) {
557 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
558 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
559 algorithm
= BT_8723B_1ANT_COEX_ALGO_SCO
;
560 } else if (bt_link_info
->pan_exist
) {
562 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
563 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
564 algorithm
= BT_8723B_1ANT_COEX_ALGO_SCO
;
566 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
567 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
569 BT_8723B_1ANT_COEX_ALGO_PANEDR_HID
;
573 if (bt_link_info
->hid_exist
&&
574 bt_link_info
->a2dp_exist
) {
575 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
576 "[BTCoex], BT Profile = HID + A2DP\n");
577 algorithm
= BT_8723B_1ANT_COEX_ALGO_HID_A2DP
;
578 } else if (bt_link_info
->hid_exist
&&
579 bt_link_info
->pan_exist
) {
581 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
582 "[BTCoex], BT Profile = HID + PAN(HS)\n");
584 BT_8723B_1ANT_COEX_ALGO_HID_A2DP
;
586 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
587 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
589 BT_8723B_1ANT_COEX_ALGO_PANEDR_HID
;
591 } else if (bt_link_info
->pan_exist
&&
592 bt_link_info
->a2dp_exist
) {
594 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
595 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
597 BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS
;
599 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
600 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
602 BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP
;
606 } else if (numofdiffprofile
== 3) {
607 if (bt_link_info
->sco_exist
) {
608 if (bt_link_info
->hid_exist
&&
609 bt_link_info
->a2dp_exist
) {
610 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
611 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
612 algorithm
= BT_8723B_1ANT_COEX_ALGO_HID
;
613 } else if (bt_link_info
->hid_exist
&&
614 bt_link_info
->pan_exist
) {
616 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
617 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
619 BT_8723B_1ANT_COEX_ALGO_HID_A2DP
;
621 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
622 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
624 BT_8723B_1ANT_COEX_ALGO_PANEDR_HID
;
626 } else if (bt_link_info
->pan_exist
&&
627 bt_link_info
->a2dp_exist
) {
629 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
630 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
631 algorithm
= BT_8723B_1ANT_COEX_ALGO_SCO
;
633 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
634 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
636 BT_8723B_1ANT_COEX_ALGO_PANEDR_HID
;
640 if (bt_link_info
->hid_exist
&&
641 bt_link_info
->pan_exist
&&
642 bt_link_info
->a2dp_exist
) {
644 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
645 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
647 BT_8723B_1ANT_COEX_ALGO_HID_A2DP
;
649 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
650 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
652 BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR
;
656 } else if (numofdiffprofile
>= 3) {
657 if (bt_link_info
->sco_exist
) {
658 if (bt_link_info
->hid_exist
&&
659 bt_link_info
->pan_exist
&&
660 bt_link_info
->a2dp_exist
) {
662 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
663 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
665 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
666 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR) ==>PAN(EDR)+HID\n");
668 BT_8723B_1ANT_COEX_ALGO_PANEDR_HID
;
677 static void set_sw_penalty_tx_rate_adapt(struct btc_coexist
*btcoexist
,
680 u8 h2c_parameter
[6] = {0};
682 h2c_parameter
[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
684 if (low_penalty_ra
) {
685 h2c_parameter
[1] |= BIT(0);
686 /*normal rate except MCS7/6/5, OFDM54/48/36 */
687 h2c_parameter
[2] = 0x00;
688 h2c_parameter
[3] = 0xf7; /*MCS7 or OFDM54 */
689 h2c_parameter
[4] = 0xf8; /*MCS6 or OFDM48 */
690 h2c_parameter
[5] = 0xf9; /*MCS5 or OFDM36 */
693 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
,
694 "[BTCoex], set WiFi Low-Penalty Retry: %s",
695 (low_penalty_ra
? "ON!!" : "OFF!!"));
697 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
700 static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
701 bool force_exec
, bool low_penalty_ra
)
703 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
706 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
709 set_sw_penalty_tx_rate_adapt(btcoexist
, coex_dm
->cur_low_penalty_ra
);
711 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
714 static void halbtc8723b1ant_set_coex_table(struct btc_coexist
*btcoexist
,
715 u32 val0x6c0
, u32 val0x6c4
,
716 u32 val0x6c8
, u8 val0x6cc
)
718 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
,
719 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0
);
720 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
722 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
,
723 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4
);
724 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
726 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
,
727 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8
);
728 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
730 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
,
731 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc
);
732 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
735 static void halbtc8723b1ant_coex_table(struct btc_coexist
*btcoexist
,
736 bool force_exec
, u32 val0x6c0
,
737 u32 val0x6c4
, u32 val0x6c8
,
740 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW
,
741 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
742 (force_exec
? "force to" : ""),
743 val0x6c0
, val0x6c4
, val0x6cc
);
744 coex_dm
->cur_val0x6c0
= val0x6c0
;
745 coex_dm
->cur_val0x6c4
= val0x6c4
;
746 coex_dm
->cur_val0x6c8
= val0x6c8
;
747 coex_dm
->cur_val0x6cc
= val0x6cc
;
750 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
751 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
752 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
753 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
756 halbtc8723b1ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
,
759 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
760 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
761 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
762 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
765 static void coex_table_with_type(struct btc_coexist
*btcoexist
,
766 bool force_exec
, u8 type
)
770 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
771 0x55555555, 0xffffff, 0x3);
774 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
775 0x5a5a5a5a, 0xffffff, 0x3);
778 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
779 0x5a5a5a5a, 0xffffff, 0x3);
782 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
783 0xaaaaaaaa, 0xffffff, 0x3);
786 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
787 0x5aaa5aaa, 0xffffff, 0x3);
790 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
791 0xaaaa5a5a, 0xffffff, 0x3);
794 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
795 0xaaaa5a5a, 0xffffff, 0x3);
798 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
799 0xaaaaaaaa, 0xffffff, 0x3);
806 static void set_fw_ignore_wlan_act(struct btc_coexist
*btcoexist
,
809 u8 h2c_parameter
[1] = {0};
812 h2c_parameter
[0] |= BIT(0); /* function enable */
814 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
,
815 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
818 btcoexist
->btc_fill_h2c(btcoexist
, 0x63, 1, h2c_parameter
);
821 static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
822 bool force_exec
, bool enable
)
824 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW
,
825 "[BTCoex], %s turn Ignore WlanAct %s\n",
826 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
827 coex_dm
->cur_ignore_wlan_act
= enable
;
830 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
831 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
832 coex_dm
->pre_ignore_wlan_act
,
833 coex_dm
->cur_ignore_wlan_act
);
835 if (coex_dm
->pre_ignore_wlan_act
==
836 coex_dm
->cur_ignore_wlan_act
)
839 set_fw_ignore_wlan_act(btcoexist
, enable
);
841 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
844 static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
,
845 u8 byte1
, u8 byte2
, u8 byte3
,
848 u8 h2c_parameter
[5] = {0};
849 u8 real_byte1
= byte1
, real_byte5
= byte5
;
850 bool ap_enable
= false;
852 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
856 if ((byte1
& BIT(4)) && !(byte1
& BIT(5))) {
857 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
858 "[BTCoex], FW for 1Ant AP mode\n");
859 real_byte1
&= ~BIT(4);
860 real_byte1
|= BIT(5);
862 real_byte5
|= BIT(5);
863 real_byte5
&= ~BIT(6);
867 h2c_parameter
[0] = real_byte1
;
868 h2c_parameter
[1] = byte2
;
869 h2c_parameter
[2] = byte3
;
870 h2c_parameter
[3] = byte4
;
871 h2c_parameter
[4] = real_byte5
;
873 coex_dm
->ps_tdma_para
[0] = real_byte1
;
874 coex_dm
->ps_tdma_para
[1] = byte2
;
875 coex_dm
->ps_tdma_para
[2] = byte3
;
876 coex_dm
->ps_tdma_para
[3] = byte4
;
877 coex_dm
->ps_tdma_para
[4] = real_byte5
;
879 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
,
880 "[BTCoex], PS-TDMA H2C cmd = 0x%x%08x\n",
882 h2c_parameter
[1] << 24 |
883 h2c_parameter
[2] << 16 |
884 h2c_parameter
[3] << 8 |
887 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
890 static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist
*btcoexist
,
891 u8 lps_val
, u8 rpwm_val
)
896 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_LPS_VAL
, &lps
);
897 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RPWM_VAL
, &rpwm
);
900 static void halbtc8723b1ant_lpsrpwm(struct btc_coexist
*btcoexist
,
902 u8 lps_val
, u8 rpwm_val
)
904 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW
,
905 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
906 (force_exec
? "force to" : ""), lps_val
, rpwm_val
);
907 coex_dm
->cur_lps
= lps_val
;
908 coex_dm
->cur_rpwm
= rpwm_val
;
911 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
912 "[BTCoex], LPS-RxBeaconMode = 0x%x, LPS-RPWM = 0x%x!!\n",
913 coex_dm
->cur_lps
, coex_dm
->cur_rpwm
);
915 if ((coex_dm
->pre_lps
== coex_dm
->cur_lps
) &&
916 (coex_dm
->pre_rpwm
== coex_dm
->cur_rpwm
)) {
917 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
918 "[BTCoex], LPS-RPWM_Last = 0x%x, LPS-RPWM_Now = 0x%x!!\n",
919 coex_dm
->pre_rpwm
, coex_dm
->cur_rpwm
);
924 halbtc8723b1ant_set_lps_rpwm(btcoexist
, lps_val
, rpwm_val
);
926 coex_dm
->pre_lps
= coex_dm
->cur_lps
;
927 coex_dm
->pre_rpwm
= coex_dm
->cur_rpwm
;
930 static void halbtc8723b1ant_sw_mechanism(struct btc_coexist
*btcoexist
,
933 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
,
934 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra
);
936 halbtc8723b1ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
939 static void halbtc8723b1ant_setantpath(struct btc_coexist
*btcoexist
,
940 u8 ant_pos_type
, bool init_hw_cfg
,
943 struct btc_board_info
*brd_info
= &btcoexist
->board_info
;
944 u32 fw_ver
= 0, u32tmp
= 0;
945 bool pg_ext_switch
= false;
946 bool use_ext_switch
= false;
947 u8 h2c_parameter
[2] = {0};
949 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_EXT_SWITCH
, &pg_ext_switch
);
950 /* [31:16] = fw ver, [15:0] = fw sub ver */
951 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
953 if ((fw_ver
< 0xc0000) || pg_ext_switch
)
954 use_ext_switch
= true;
957 /*BT select s0/s1 is controlled by WiFi */
958 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x1);
960 /*Force GNT_BT to Normal */
961 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x765, 0x18, 0x0);
962 } else if (wifi_off
) {
963 /*Force GNT_BT to High */
964 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x765, 0x18, 0x3);
965 /*BT select s0/s1 is controlled by BT */
966 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x0);
968 /* 0x4c[24:23] = 00, Set Antenna control by BT_RFE_CTRL
969 * BT Vendor 0xac = 0xf002 */
970 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
973 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
976 if (use_ext_switch
) {
978 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna ctrl by WL/BT */
979 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
982 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
984 if (brd_info
->btdm_ant_pos
==
985 BTC_ANTENNA_AT_MAIN_PORT
) {
986 /* Main Ant to BT for IPS case 0x4c[23] = 1 */
987 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
991 /*tell firmware "no antenna inverse"*/
992 h2c_parameter
[0] = 0;
993 h2c_parameter
[1] = 1; /*ext switch type*/
994 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
997 /*Aux Ant to BT for IPS case 0x4c[23] = 1 */
998 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1002 /*tell firmware "antenna inverse"*/
1003 h2c_parameter
[0] = 1;
1004 h2c_parameter
[1] = 1; /*ext switch type*/
1005 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1010 /* fixed internal switch first*/
1011 /* fixed internal switch S1->WiFi, S0->BT*/
1012 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1013 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x0);
1014 else/* fixed internal switch S0->WiFi, S1->BT*/
1015 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x280);
1017 /* ext switch setting */
1018 switch (ant_pos_type
) {
1019 case BTC_ANT_PATH_WIFI
:
1020 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1021 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1025 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1029 case BTC_ANT_PATH_BT
:
1030 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1031 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1035 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1040 case BTC_ANT_PATH_PTA
:
1041 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1042 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1046 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1054 /* 0x4c[23] = 1, 0x4c[24] = 0 Antenna control by 0x64*/
1055 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
1058 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
1060 if (brd_info
->btdm_ant_pos
==
1061 BTC_ANTENNA_AT_MAIN_PORT
) {
1062 /*Main Ant to WiFi for IPS case 0x4c[23] = 1*/
1063 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1067 /*tell firmware "no antenna inverse"*/
1068 h2c_parameter
[0] = 0;
1069 h2c_parameter
[1] = 0; /*internal switch type*/
1070 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1073 /*Aux Ant to BT for IPS case 0x4c[23] = 1*/
1074 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1078 /*tell firmware "antenna inverse"*/
1079 h2c_parameter
[0] = 1;
1080 h2c_parameter
[1] = 0; /*internal switch type*/
1081 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1086 /* fixed external switch first*/
1087 /*Main->WiFi, Aux->BT*/
1088 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1089 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x92c,
1091 else/*Main->BT, Aux->WiFi */
1092 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x92c,
1095 /* internal switch setting*/
1096 switch (ant_pos_type
) {
1097 case BTC_ANT_PATH_WIFI
:
1098 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1099 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
1102 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
1105 case BTC_ANT_PATH_BT
:
1106 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1107 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
1110 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
1114 case BTC_ANT_PATH_PTA
:
1115 if (brd_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1116 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
1119 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
1126 static void halbtc8723b1ant_ps_tdma(struct btc_coexist
*btcoexist
,
1127 bool force_exec
, bool turn_on
, u8 type
)
1129 bool wifi_busy
= false;
1130 u8 rssi_adjust_val
= 0;
1132 coex_dm
->cur_ps_tdma_on
= turn_on
;
1133 coex_dm
->cur_ps_tdma
= type
;
1135 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1138 if (coex_dm
->cur_ps_tdma_on
)
1139 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
1140 "[BTCoex], ******** TDMA(on, %d) *********\n",
1141 coex_dm
->cur_ps_tdma
);
1143 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
1144 "[BTCoex], ******** TDMA(off, %d) ********\n",
1145 coex_dm
->cur_ps_tdma
);
1147 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1148 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1154 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1a,
1158 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x3a,
1161 rssi_adjust_val
= 11;
1164 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x2b,
1166 rssi_adjust_val
= 14;
1169 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1d,
1173 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1175 rssi_adjust_val
= 17;
1178 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x15,
1182 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x20,
1186 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xc,
1190 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1194 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x21,
1196 rssi_adjust_val
= 18;
1199 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1203 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x15,
1205 rssi_adjust_val
= 20;
1208 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x0a,
1212 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x15,
1216 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x21,
1220 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1224 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1226 rssi_adjust_val
= 18;
1229 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1231 rssi_adjust_val
= 14;
1234 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x35,
1238 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x25,
1242 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x25,
1246 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1248 rssi_adjust_val
= 22;
1251 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1253 rssi_adjust_val
= 22;
1256 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1258 rssi_adjust_val
= 22;
1261 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1263 rssi_adjust_val
= 22;
1266 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1268 rssi_adjust_val
= 22;
1271 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x69, 0x25,
1275 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xab, 0x1a,
1279 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x14,
1283 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1a,
1287 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0xa,
1291 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x25,
1295 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x53, 0x1a,
1299 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x63, 0x1a,
1303 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x12,
1306 /* SoftAP only with no sta associated, BT disable ,
1307 * TDMA mode for power saving
1308 * here softap mode screen off will cost 70-80mA for phone */
1310 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x23, 0x18,
1316 case 8: /*PTA Control */
1317 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x8, 0x0,
1319 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_PTA
,
1323 default: /*Software control, Antenna at BT side */
1324 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0,
1326 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_BT
,
1329 case 9: /*Software control, Antenna at WiFi side */
1330 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0,
1332 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_WIFI
,
1337 rssi_adjust_val
= 0;
1338 btcoexist
->btc_set(btcoexist
,
1339 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE
,
1342 /* update pre state */
1343 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1344 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1347 static bool halbtc8723b1ant_is_common_action(struct btc_coexist
*btcoexist
)
1349 bool commom
= false, wifi_connected
= false;
1350 bool wifi_busy
= false;
1352 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1354 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1356 if (!wifi_connected
&&
1357 BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
== coex_dm
->bt_status
) {
1358 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1359 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1360 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1362 } else if (wifi_connected
&&
1363 (BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
==
1364 coex_dm
->bt_status
)) {
1365 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1366 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1367 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1369 } else if (!wifi_connected
&&
1370 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
==
1371 coex_dm
->bt_status
)) {
1372 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1373 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1374 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1376 } else if (wifi_connected
&&
1377 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
==
1378 coex_dm
->bt_status
)) {
1379 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1380 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1381 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1383 } else if (!wifi_connected
&&
1384 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
!=
1385 coex_dm
->bt_status
)) {
1386 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1387 ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
1388 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1392 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1393 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1395 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1396 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1404 static void tdma_duration_adjust_for_acl(struct btc_coexist
*btcoexist
,
1407 static s32 up
, dn
, m
, n
, wait_count
;
1408 /* 0: no change, +1: increase WiFi duration,
1409 * -1: decrease WiFi duration */
1411 u8 retry_count
= 0, bt_info_ext
;
1412 bool wifi_busy
= false;
1414 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW
,
1415 "[BTCoex], TdmaDurationAdjustForAcl()\n");
1417 if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
== wifi_status
)
1422 if ((BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN
==
1424 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
== wifi_status
) ||
1425 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT
== wifi_status
)) {
1426 if (coex_dm
->cur_ps_tdma
!= 1 && coex_dm
->cur_ps_tdma
!= 2 &&
1427 coex_dm
->cur_ps_tdma
!= 3 && coex_dm
->cur_ps_tdma
!= 9) {
1428 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1430 coex_dm
->ps_tdma_du_adj_type
= 9;
1442 if (!coex_dm
->auto_tdma_adjust
) {
1443 coex_dm
->auto_tdma_adjust
= true;
1444 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
1445 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1447 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 2);
1448 coex_dm
->ps_tdma_du_adj_type
= 2;
1457 /*accquire the BT TRx retry count from BT_Info byte2 */
1458 retry_count
= coex_sta
->bt_retry_cnt
;
1459 bt_info_ext
= coex_sta
->bt_info_ext
;
1462 /* no retry in the last 2-second duration */
1463 if (retry_count
== 0) {
1476 BTC_PRINT(BTC_MSG_ALGORITHM
,
1477 ALGO_TRACE_FW_DETAIL
,
1478 "[BTCoex], Increase wifi duration!!\n");
1480 } else if (retry_count
<= 3) {
1488 if (wait_count
<= 2)
1501 BTC_PRINT(BTC_MSG_ALGORITHM
,
1502 ALGO_TRACE_FW_DETAIL
,
1503 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1506 if (wait_count
== 1)
1519 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
1520 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1524 if ((BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(bt_info_ext
)) &&
1525 ((coex_dm
->cur_ps_tdma
== 1) ||
1526 (coex_dm
->cur_ps_tdma
== 2))) {
1527 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1529 coex_dm
->ps_tdma_du_adj_type
= 9;
1530 } else if (coex_dm
->cur_ps_tdma
== 1) {
1531 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1533 coex_dm
->ps_tdma_du_adj_type
= 2;
1534 } else if (coex_dm
->cur_ps_tdma
== 2) {
1535 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1537 coex_dm
->ps_tdma_du_adj_type
= 9;
1538 } else if (coex_dm
->cur_ps_tdma
== 9) {
1539 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1541 coex_dm
->ps_tdma_du_adj_type
= 11;
1543 } else if (result
== 1) {
1544 if ((BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(bt_info_ext
)) &&
1545 ((coex_dm
->cur_ps_tdma
== 1) ||
1546 (coex_dm
->cur_ps_tdma
== 2))) {
1547 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1549 coex_dm
->ps_tdma_du_adj_type
= 9;
1550 } else if (coex_dm
->cur_ps_tdma
== 11) {
1551 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1553 coex_dm
->ps_tdma_du_adj_type
= 9;
1554 } else if (coex_dm
->cur_ps_tdma
== 9) {
1555 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1557 coex_dm
->ps_tdma_du_adj_type
= 2;
1558 } else if (coex_dm
->cur_ps_tdma
== 2) {
1559 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1561 coex_dm
->ps_tdma_du_adj_type
= 1;
1563 } else { /*no change */
1564 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
,
1565 "[BTCoex],********* TDMA(on, %d) ********\n",
1566 coex_dm
->cur_ps_tdma
);
1569 if (coex_dm
->cur_ps_tdma
!= 1 && coex_dm
->cur_ps_tdma
!= 2 &&
1570 coex_dm
->cur_ps_tdma
!= 9 && coex_dm
->cur_ps_tdma
!= 11) {
1571 /* recover to previous adjust type */
1572 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1573 coex_dm
->ps_tdma_du_adj_type
);
1578 static void pstdmacheckforpowersavestate(struct btc_coexist
*btcoexist
,
1583 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_LPS_MODE
, &lps_mode
);
1585 if (lps_mode
) { /* already under LPS state */
1587 /* keep state under LPS, do nothing. */
1589 /* will leave LPS state, turn off psTdma first */
1590 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1593 } else { /* NO PS state */
1595 /* will enter LPS state, turn off psTdma first */
1596 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1599 /* keep state under NO PS state, do nothing. */
1604 static void halbtc8723b1ant_power_save_state(struct btc_coexist
*btcoexist
,
1605 u8 ps_type
, u8 lps_val
,
1608 bool low_pwr_disable
= false;
1611 case BTC_PS_WIFI_NATIVE
:
1612 /* recover to original 32k low power setting */
1613 low_pwr_disable
= false;
1614 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1616 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1619 pstdmacheckforpowersavestate(btcoexist
, true);
1620 halbtc8723b1ant_lpsrpwm(btcoexist
, NORMAL_EXEC
, lps_val
,
1622 /* when coex force to enter LPS, do not enter 32k low power. */
1623 low_pwr_disable
= true;
1624 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1626 /* power save must executed before psTdma. */
1627 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1629 case BTC_PS_LPS_OFF
:
1630 pstdmacheckforpowersavestate(btcoexist
, false);
1631 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
, NULL
);
1638 /***************************************************
1640 * Software Coex Mechanism start
1642 ***************************************************/
1643 /* SCO only or SCO+PAN(HS) */
1644 static void halbtc8723b1ant_action_sco(struct btc_coexist
*btcoexist
)
1646 halbtc8723b1ant_sw_mechanism(btcoexist
, true);
1649 static void halbtc8723b1ant_action_hid(struct btc_coexist
*btcoexist
)
1651 halbtc8723b1ant_sw_mechanism(btcoexist
, true);
1654 /*A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
1655 static void halbtc8723b1ant_action_a2dp(struct btc_coexist
*btcoexist
)
1657 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1660 static void halbtc8723b1ant_action_a2dp_pan_hs(struct btc_coexist
*btcoexist
)
1662 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1665 static void halbtc8723b1ant_action_pan_edr(struct btc_coexist
*btcoexist
)
1667 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1671 static void halbtc8723b1ant_action_pan_hs(struct btc_coexist
*btcoexist
)
1673 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1677 static void halbtc8723b1ant_action_pan_edr_a2dp(struct btc_coexist
*btcoexist
)
1679 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
1682 static void halbtc8723b1ant_action_pan_edr_hid(struct btc_coexist
*btcoexist
)
1684 halbtc8723b1ant_sw_mechanism(btcoexist
, true);
1687 /* HID+A2DP+PAN(EDR) */
1688 static void action_hid_a2dp_pan_edr(struct btc_coexist
*btcoexist
)
1690 halbtc8723b1ant_sw_mechanism(btcoexist
, true);
1693 static void halbtc8723b1ant_action_hid_a2dp(struct btc_coexist
*btcoexist
)
1695 halbtc8723b1ant_sw_mechanism(btcoexist
, true);
1698 /*****************************************************
1700 * Non-Software Coex Mechanism start
1702 *****************************************************/
1703 static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist
*btcoexist
)
1705 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1708 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1709 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1712 static void halbtc8723b1ant_action_hs(struct btc_coexist
*btcoexist
)
1714 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1715 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1718 static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1720 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1721 bool wifi_connected
= false, ap_enable
= false;
1723 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
1725 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1728 if (!wifi_connected
) {
1729 halbtc8723b1ant_power_save_state(btcoexist
,
1730 BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1731 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1732 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1733 } else if (bt_link_info
->sco_exist
|| bt_link_info
->hid_only
) {
1734 /* SCO/HID-only busy */
1735 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1737 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
1738 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1741 halbtc8723b1ant_power_save_state(btcoexist
,
1745 halbtc8723b1ant_power_save_state(btcoexist
,
1749 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 30);
1750 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1754 static void action_bt_sco_hid_only_busy(struct btc_coexist
*btcoexist
,
1757 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1758 bool wifi_connected
= false;
1760 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1763 /* tdma and coex table */
1765 if (bt_link_info
->sco_exist
) {
1766 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1767 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1769 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 6);
1770 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 5);
1774 static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
1775 struct btc_coexist
*btcoexist
,
1778 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1781 rssi_state
= halbtc8723b1ant_bt_rssi_state(2, 28, 0);
1783 if (bt_link_info
->hid_only
) { /*HID */
1784 action_bt_sco_hid_only_busy(btcoexist
, wifi_status
);
1785 coex_dm
->auto_tdma_adjust
= false;
1787 } else if (bt_link_info
->a2dp_only
) { /*A2DP */
1788 if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
== wifi_status
) {
1789 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false,
1791 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1792 coex_dm
->auto_tdma_adjust
= false;
1793 } else if ((rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1794 (rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1795 tdma_duration_adjust_for_acl(btcoexist
, wifi_status
);
1796 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1797 } else { /*for low BT RSSI */
1798 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1800 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1801 coex_dm
->auto_tdma_adjust
= false;
1803 } else if (bt_link_info
->hid_exist
&&
1804 bt_link_info
->a2dp_exist
) { /*HID+A2DP */
1805 if ((rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1806 (rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1807 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1809 coex_dm
->auto_tdma_adjust
= false;
1810 } else { /*for low BT RSSI*/
1811 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1813 coex_dm
->auto_tdma_adjust
= false;
1816 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 6);
1817 /*PAN(OPP, FTP), HID+PAN(OPP, FTP) */
1818 } else if (bt_link_info
->pan_only
||
1819 (bt_link_info
->hid_exist
&& bt_link_info
->pan_exist
)) {
1820 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1821 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 6);
1822 coex_dm
->auto_tdma_adjust
= false;
1823 /*A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP)*/
1824 } else if ((bt_link_info
->a2dp_exist
&& bt_link_info
->pan_exist
) ||
1825 (bt_link_info
->hid_exist
&& bt_link_info
->a2dp_exist
&&
1826 bt_link_info
->pan_exist
)) {
1827 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 13);
1828 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1829 coex_dm
->auto_tdma_adjust
= false;
1831 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
1832 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1833 coex_dm
->auto_tdma_adjust
= false;
1837 static void action_wifi_not_connected(struct btc_coexist
*btcoexist
)
1839 /* power save state */
1840 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1843 /* tdma and coex table */
1844 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1845 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1848 static void action_wifi_not_connected_scan(struct btc_coexist
*btcoexist
)
1850 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1851 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1854 /* tdma and coex table */
1855 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
1856 if (bt_link_info
->a2dp_exist
&& bt_link_info
->pan_exist
) {
1857 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1859 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1860 } else if (bt_link_info
->pan_only
) {
1861 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1863 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1865 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1867 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1869 } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
1870 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
==
1871 coex_dm
->bt_status
)) {
1872 action_bt_sco_hid_only_busy(btcoexist
,
1873 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1875 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1876 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1880 static void action_wifi_not_connected_asso_auth(struct btc_coexist
*btcoexist
)
1882 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1884 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1887 if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
== coex_dm
->bt_status
) ||
1888 (bt_link_info
->sco_exist
) || (bt_link_info
->hid_only
) ||
1889 (bt_link_info
->a2dp_only
) || (bt_link_info
->pan_only
)) {
1890 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1891 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1893 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1894 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1898 static void action_wifi_connected_scan(struct btc_coexist
*btcoexist
)
1900 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1902 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1905 /* tdma and coex table */
1906 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
1907 if (bt_link_info
->a2dp_exist
&& bt_link_info
->pan_exist
) {
1908 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1910 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1911 } else if (bt_link_info
->pan_only
) {
1912 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1914 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1916 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1918 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1920 } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
1921 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
==
1922 coex_dm
->bt_status
)) {
1923 action_bt_sco_hid_only_busy(btcoexist
,
1924 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1926 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1927 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1931 static void action_wifi_connected_special_packet(struct btc_coexist
*btcoexist
)
1933 bool hs_connecting
= false;
1934 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1936 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_CONNECTING
, &hs_connecting
);
1938 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1941 /* tdma and coex table */
1942 if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
== coex_dm
->bt_status
) ||
1943 (bt_link_info
->sco_exist
) || (bt_link_info
->hid_only
) ||
1944 (bt_link_info
->a2dp_only
) || (bt_link_info
->pan_only
)) {
1945 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1946 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1948 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1949 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1953 static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist
*btcoexist
)
1955 bool wifi_busy
= false;
1956 bool scan
= false, link
= false, roam
= false;
1957 bool under_4way
= false, ap_enable
= false;
1959 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1960 "[BTCoex], CoexForWifiConnect() ===>\n");
1962 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
1965 action_wifi_connected_special_packet(btcoexist
);
1966 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1967 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1971 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
1972 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
1973 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
1975 if (scan
|| link
|| roam
) {
1977 action_wifi_connected_scan(btcoexist
);
1979 action_wifi_connected_special_packet(btcoexist
);
1980 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
1981 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1985 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
1987 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1988 /* power save state */
1990 BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
&&
1991 !btcoexist
->bt_link_info
.hid_only
) {
1992 if (!wifi_busy
&& btcoexist
->bt_link_info
.a2dp_only
)
1993 halbtc8723b1ant_power_save_state(btcoexist
,
1997 halbtc8723b1ant_power_save_state(btcoexist
,
2001 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2004 /* tdma and coex table */
2006 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
2007 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist
,
2008 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
2009 } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY
==
2010 coex_dm
->bt_status
) ||
2011 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
==
2012 coex_dm
->bt_status
)) {
2013 action_bt_sco_hid_only_busy(btcoexist
,
2014 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
2016 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2018 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2021 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
2022 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist
,
2023 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
2024 } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY
==
2025 coex_dm
->bt_status
) ||
2026 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
==
2027 coex_dm
->bt_status
)) {
2028 action_bt_sco_hid_only_busy(btcoexist
,
2029 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
2031 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
2032 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2037 static void run_sw_coexist_mechanism(struct btc_coexist
*btcoexist
)
2041 algorithm
= halbtc8723b1ant_action_algorithm(btcoexist
);
2042 coex_dm
->cur_algorithm
= algorithm
;
2044 if (!halbtc8723b1ant_is_common_action(btcoexist
)) {
2045 switch (coex_dm
->cur_algorithm
) {
2046 case BT_8723B_1ANT_COEX_ALGO_SCO
:
2047 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2048 "[BTCoex], Action algorithm = SCO.\n");
2049 halbtc8723b1ant_action_sco(btcoexist
);
2051 case BT_8723B_1ANT_COEX_ALGO_HID
:
2052 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2053 "[BTCoex], Action algorithm = HID.\n");
2054 halbtc8723b1ant_action_hid(btcoexist
);
2056 case BT_8723B_1ANT_COEX_ALGO_A2DP
:
2057 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2058 "[BTCoex], Action algorithm = A2DP.\n");
2059 halbtc8723b1ant_action_a2dp(btcoexist
);
2061 case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS
:
2062 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2063 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
2064 halbtc8723b1ant_action_a2dp_pan_hs(btcoexist
);
2066 case BT_8723B_1ANT_COEX_ALGO_PANEDR
:
2067 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2068 "[BTCoex], Action algorithm = PAN(EDR).\n");
2069 halbtc8723b1ant_action_pan_edr(btcoexist
);
2071 case BT_8723B_1ANT_COEX_ALGO_PANHS
:
2072 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2073 "[BTCoex], Action algorithm = HS mode.\n");
2074 halbtc8723b1ant_action_pan_hs(btcoexist
);
2076 case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP
:
2077 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2078 "[BTCoex], Action algorithm = PAN+A2DP.\n");
2079 halbtc8723b1ant_action_pan_edr_a2dp(btcoexist
);
2081 case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID
:
2082 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2083 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
2084 halbtc8723b1ant_action_pan_edr_hid(btcoexist
);
2086 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR
:
2087 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2088 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
2089 action_hid_a2dp_pan_edr(btcoexist
);
2091 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP
:
2092 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2093 "[BTCoex], Action algorithm = HID+A2DP.\n");
2094 halbtc8723b1ant_action_hid_a2dp(btcoexist
);
2097 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2098 "[BTCoex], Action algorithm = coexist All Off!!\n");
2101 coex_dm
->pre_algorithm
= coex_dm
->cur_algorithm
;
2105 static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
2107 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2108 bool wifi_connected
= false, bt_hs_on
= false;
2109 bool increase_scan_dev_num
= false;
2110 bool b_bt_ctrl_agg_buf_size
= false;
2111 u8 agg_buf_size
= 5;
2112 u8 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
2113 u32 wifi_link_status
= 0;
2114 u32 num_of_wifi_link
= 0;
2116 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2117 "[BTCoex], RunCoexistMechanism() ===>\n");
2119 if (btcoexist
->manual_control
) {
2120 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2121 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2125 if (btcoexist
->stop_coex_dm
) {
2126 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2127 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2131 if (coex_sta
->under_ips
) {
2132 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2133 "[BTCoex], wifi is under IPS !!!\n");
2137 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
2138 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
2139 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
))
2140 increase_scan_dev_num
= true;
2142 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_INC_SCAN_DEV_NUM
,
2143 &increase_scan_dev_num
);
2145 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2148 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2150 num_of_wifi_link
= wifi_link_status
>> 16;
2151 if (num_of_wifi_link
>= 2) {
2152 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2153 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2154 b_bt_ctrl_agg_buf_size
,
2156 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2160 if (!bt_link_info
->sco_exist
&& !bt_link_info
->hid_exist
) {
2161 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2163 if (wifi_connected
) {
2165 halbtc8723b1ant_wifi_rssi_state(btcoexist
,
2167 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2168 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2169 halbtc8723b1ant_limited_tx(btcoexist
,
2173 halbtc8723b1ant_limited_tx(btcoexist
,
2178 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
,
2183 if (bt_link_info
->sco_exist
) {
2184 b_bt_ctrl_agg_buf_size
= true;
2186 } else if (bt_link_info
->hid_exist
) {
2187 b_bt_ctrl_agg_buf_size
= true;
2189 } else if (bt_link_info
->a2dp_exist
|| bt_link_info
->pan_exist
) {
2190 b_bt_ctrl_agg_buf_size
= true;
2193 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2194 b_bt_ctrl_agg_buf_size
, agg_buf_size
);
2196 run_sw_coexist_mechanism(btcoexist
);
2198 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2200 if (coex_sta
->c2h_bt_inquiry_page
) {
2201 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2203 } else if (bt_hs_on
) {
2204 halbtc8723b1ant_action_hs(btcoexist
);
2208 if (!wifi_connected
) {
2209 bool scan
= false, link
= false, roam
= false;
2211 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2212 "[BTCoex], wifi is non connected-idle !!!\n");
2214 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2215 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2216 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2218 if (scan
|| link
|| roam
) {
2220 action_wifi_not_connected_scan(btcoexist
);
2222 action_wifi_not_connected_asso_auth(btcoexist
);
2224 action_wifi_not_connected(btcoexist
);
2226 } else { /* wifi LPS/Busy */
2227 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2231 static void halbtc8723b1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2234 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
2236 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2237 coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
2240 static void init_hw_config(struct btc_coexist
*btcoexist
, bool backup
)
2244 u32 cnt_bt_cal_chk
= 0;
2246 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
2247 "[BTCoex], 1Ant Init HW Config!!\n");
2249 if (backup
) {/* backup rf 0x1e value */
2250 coex_dm
->backup_arfr_cnt1
=
2251 btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2252 coex_dm
->backup_arfr_cnt2
=
2253 btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2254 coex_dm
->backup_retry_limit
=
2255 btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2256 coex_dm
->backup_ampdu_max_time
=
2257 btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2260 /* WiFi goto standby while GNT_BT 0-->1 */
2261 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x780);
2262 /* BT goto standby while GNT_BT 1-->0 */
2263 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x2, 0xfffff, 0x500);
2265 btcoexist
->btc_write_1byte(btcoexist
, 0x974, 0xff);
2266 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x944, 0x3, 0x3);
2267 btcoexist
->btc_write_1byte(btcoexist
, 0x930, 0x77);
2269 /* BT calibration check */
2270 while (cnt_bt_cal_chk
<= 20) {
2271 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x49d);
2273 if (u32tmp
& BIT(0)) {
2274 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
2275 "[BTCoex], ########### BT calibration(cnt =%d) ###########\n",
2279 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
2280 "[BTCoex], ********** BT NOT calibration (cnt =%d)**********\n",
2286 /* 0x790[5:0] = 0x5 */
2287 u8tmp
= btcoexist
->btc_read_1byte(btcoexist
, 0x790);
2290 btcoexist
->btc_write_1byte(btcoexist
, 0x790, u8tmp
);
2292 /* Enable counter statistics */
2293 /*0x76e[3] = 1, WLAN_Act control by PTA */
2294 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
2295 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x1);
2296 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
2299 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_PTA
, true, false);
2301 coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
2304 static void halbtc8723b1ant_wifi_off_hw_cfg(struct btc_coexist
*btcoexist
)
2306 /* set wlan_act to low */
2307 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
2310 /**************************************************************
2311 * work around function start with wa_halbtc8723b1ant_
2312 **************************************************************/
2313 /**************************************************************
2314 * extern function start with EXhalbtc8723b1ant_
2315 **************************************************************/
2317 void ex_halbtc8723b1ant_init_hwconfig(struct btc_coexist
*btcoexist
)
2319 init_hw_config(btcoexist
, true);
2322 void ex_halbtc8723b1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2324 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
2325 "[BTCoex], Coex Mechanism Init!!\n");
2327 btcoexist
->stop_coex_dm
= false;
2329 halbtc8723b1ant_init_coex_dm(btcoexist
);
2331 halbtc8723b1ant_query_bt_info(btcoexist
);
2334 void ex_halbtc8723b1ant_display_coex_info(struct btc_coexist
*btcoexist
)
2336 struct btc_board_info
*brd_info
= &btcoexist
->board_info
;
2337 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2338 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2339 u8
*cli_buf
= btcoexist
->cli_buf
;
2340 u8 u8tmp
[4], i
, bt_info_ext
, stdmacase
= 0;
2343 bool roam
= false, scan
= false;
2344 bool link
= false, wifi_under_5g
= false;
2345 bool bt_hs_on
= false, wifi_busy
= false;
2346 s32 wifi_rssi
= 0, bt_hs_rssi
= 0;
2347 u32 wifi_bw
, wifi_traffic_dir
, fa_ofdm
, fa_cck
, wifi_link_status
;
2348 u8 wifi_dot11_chnl
, wifi_hs_chnl
;
2349 u32 fw_ver
= 0, bt_patch_ver
= 0;
2351 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2352 "\r\n ============[BT Coexist info] ============");
2355 if (btcoexist
->manual_control
) {
2356 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2357 "\r\n ============[Under Manual Control] ==========");
2359 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2360 "\r\n ==========================================");
2363 if (btcoexist
->stop_coex_dm
) {
2364 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2365 "\r\n ============[Coex is STOPPED] ============");
2367 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2368 "\r\n ==========================================");
2372 if (!brd_info
->bt_exist
) {
2373 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n BT not exists !!!");
2378 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d/ %d",
2379 "Ant PG Num/ Ant Mech/ Ant Pos: ",
2380 brd_info
->pg_ant_num
, brd_info
->btdm_ant_num
,
2381 brd_info
->btdm_ant_pos
);
2384 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s / %d",
2385 "BT stack/ hci ext ver",
2386 ((stack_info
->profile_notified
) ? "Yes" : "No"),
2387 stack_info
->hci_version
);
2390 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
2391 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2392 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2393 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2394 "CoexVer/ FwVer/ PatchVer",
2395 glcoex_ver_date_8723b_1ant
, glcoex_ver_8723b_1ant
,
2396 fw_ver
, bt_patch_ver
, bt_patch_ver
);
2399 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2400 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
,
2402 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
2403 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d / %d(%d)",
2404 "Dot11 channel / HsChnl(HsMode)",
2405 wifi_dot11_chnl
, wifi_hs_chnl
, bt_hs_on
);
2408 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %02x %02x %02x ",
2409 "H2C Wifi inform bt chnl Info",
2410 coex_dm
->wifi_chnl_info
[0], coex_dm
->wifi_chnl_info
[1],
2411 coex_dm
->wifi_chnl_info
[2]);
2414 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
2415 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
2416 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d",
2417 "Wifi rssi/ HS rssi", wifi_rssi
, bt_hs_rssi
);
2420 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2421 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2422 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2423 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d/ %d ",
2424 "Wifi link/ roam/ scan", link
, roam
, scan
);
2427 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
,
2429 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2430 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2431 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
,
2434 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s / %s/ %s ",
2435 "Wifi status", (wifi_under_5g
? "5G" : "2.4G"),
2436 ((BTC_WIFI_BW_LEGACY
== wifi_bw
) ? "Legacy" :
2437 (((BTC_WIFI_BW_HT40
== wifi_bw
) ? "HT40" : "HT20"))),
2438 ((!wifi_busy
) ? "idle" :
2439 ((BTC_WIFI_TRAFFIC_TX
== wifi_traffic_dir
) ?
2440 "uplink" : "downlink")));
2443 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2445 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
2446 "sta/vwifi/hs/p2pGo/p2pGc",
2447 ((wifi_link_status
& WIFI_STA_CONNECTED
) ? 1 : 0),
2448 ((wifi_link_status
& WIFI_AP_CONNECTED
) ? 1 : 0),
2449 ((wifi_link_status
& WIFI_HS_CONNECTED
) ? 1 : 0),
2450 ((wifi_link_status
& WIFI_P2P_GO_CONNECTED
) ? 1 : 0),
2451 ((wifi_link_status
& WIFI_P2P_GC_CONNECTED
) ? 1 : 0));
2454 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = [%s/ %d/ %d] ",
2455 "BT [status/ rssi/ retryCnt]",
2456 ((btcoexist
->bt_info
.bt_disabled
) ? ("disabled") :
2457 ((coex_sta
->c2h_bt_inquiry_page
) ? ("inquiry/page scan") :
2458 ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
== coex_dm
->bt_status
) ?
2459 "non-connected idle" :
2460 ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
== coex_dm
->bt_status
) ?
2461 "connected-idle" : "busy")))),
2462 coex_sta
->bt_rssi
, coex_sta
->bt_retry_cnt
);
2465 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d / %d / %d / %d",
2466 "SCO/HID/PAN/A2DP", bt_link_info
->sco_exist
,
2467 bt_link_info
->hid_exist
, bt_link_info
->pan_exist
,
2468 bt_link_info
->a2dp_exist
);
2470 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_BT_LINK_INFO
);
2472 bt_info_ext
= coex_sta
->bt_info_ext
;
2473 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s",
2474 "BT Info A2DP rate",
2475 (bt_info_ext
& BIT(0)) ? "Basic rate" : "EDR rate");
2478 for (i
= 0; i
< BT_INFO_SRC_8723B_1ANT_MAX
; i
++) {
2479 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
2480 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2481 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2482 glb_infosrc8723b1ant
[i
],
2483 coex_sta
->bt_info_c2h
[i
][0],
2484 coex_sta
->bt_info_c2h
[i
][1],
2485 coex_sta
->bt_info_c2h
[i
][2],
2486 coex_sta
->bt_info_c2h
[i
][3],
2487 coex_sta
->bt_info_c2h
[i
][4],
2488 coex_sta
->bt_info_c2h
[i
][5],
2489 coex_sta
->bt_info_c2h
[i
][6],
2490 coex_sta
->bt_info_c2h_cnt
[i
]);
2494 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2495 "\r\n %-35s = %s/%s, (0x%x/0x%x)",
2496 "PS state, IPS/LPS, (lps/rpwm)",
2497 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
2498 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")),
2499 btcoexist
->bt_info
.lps_val
,
2500 btcoexist
->bt_info
.rpwm_val
);
2502 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
);
2504 if (!btcoexist
->manual_control
) {
2506 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s",
2507 "============[Sw mechanism] ============");
2510 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/",
2511 "SM[LowPenaltyRA]", coex_dm
->cur_low_penalty_ra
);
2514 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s/ %s/ %d ",
2515 "DelBA/ BtCtrlAgg/ AggSize",
2516 (btcoexist
->bt_info
.reject_agg_pkt
? "Yes" : "No"),
2517 (btcoexist
->bt_info
.b_bt_ctrl_buf_size
? "Yes" : "No"),
2518 btcoexist
->bt_info
.agg_buf_size
);
2521 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x ",
2522 "Rate Mask", btcoexist
->bt_info
.ra_mask
);
2526 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s",
2527 "============[Fw mechanism] ============");
2530 stdmacase
= coex_dm
->cur_ps_tdma
;
2531 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2532 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2533 "PS TDMA", coex_dm
->ps_tdma_para
[0],
2534 coex_dm
->ps_tdma_para
[1], coex_dm
->ps_tdma_para
[2],
2535 coex_dm
->ps_tdma_para
[3], coex_dm
->ps_tdma_para
[4],
2536 stdmacase
, coex_dm
->auto_tdma_adjust
);
2539 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d ",
2540 "IgnWlanAct", coex_dm
->cur_ignore_wlan_act
);
2543 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x ",
2544 "Latest error condition(should be 0)",
2545 coex_dm
->error_condition
);
2550 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s",
2551 "============[Hw setting] ============");
2554 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2555 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm
->backup_arfr_cnt1
,
2556 coex_dm
->backup_arfr_cnt2
, coex_dm
->backup_retry_limit
,
2557 coex_dm
->backup_ampdu_max_time
);
2560 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2561 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2562 u16tmp
[0] = btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2563 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2564 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2565 "0x430/0x434/0x42a/0x456",
2566 u32tmp
[0], u32tmp
[1], u16tmp
[0], u8tmp
[0]);
2569 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
2570 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6cc);
2571 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x880);
2572 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2573 "0x778/0x6cc/0x880[29:25]", u8tmp
[0], u32tmp
[0],
2574 (u32tmp
[1] & 0x3e000000) >> 25);
2577 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2578 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2579 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2580 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2581 "0x948/ 0x67[5] / 0x765",
2582 u32tmp
[0], ((u8tmp
[0] & 0x20) >> 5), u8tmp
[1]);
2585 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x92c);
2586 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x930);
2587 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x944);
2588 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2589 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
2590 u32tmp
[0] & 0x3, u32tmp
[1] & 0xff, u32tmp
[2] & 0x3);
2593 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x39);
2594 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
2595 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
2596 u8tmp
[2] = btcoexist
->btc_read_1byte(btcoexist
, 0x64);
2597 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
,
2598 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2599 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
2600 ((u8tmp
[0] & 0x8)>>3), u8tmp
[1],
2601 ((u32tmp
[0] & 0x01800000) >> 23), u8tmp
[2] & 0x1);
2604 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
2605 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
2606 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x",
2607 "0x550(bcn ctrl)/0x522", u32tmp
[0], u8tmp
[0]);
2610 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
2611 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x49c);
2612 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x",
2613 "0xc50(dig)/0x49c(null-drop)", u32tmp
[0] & 0xff, u8tmp
[0]);
2616 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xda0);
2617 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0xda4);
2618 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0xda8);
2619 u32tmp
[3] = btcoexist
->btc_read_4byte(btcoexist
, 0xcf0);
2621 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
2622 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
2624 fa_ofdm
= ((u32tmp
[0] & 0xffff0000) >> 16) +
2625 ((u32tmp
[1] & 0xffff0000) >> 16) +
2626 (u32tmp
[1] & 0xffff) +
2627 (u32tmp
[2] & 0xffff) +
2628 ((u32tmp
[3] & 0xffff0000) >> 16) +
2629 (u32tmp
[3] & 0xffff);
2630 fa_cck
= (u8tmp
[0] << 8) + u8tmp
[1];
2632 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2633 "OFDM-CCA/OFDM-FA/CCK-FA",
2634 u32tmp
[0] & 0xffff, fa_ofdm
, fa_cck
);
2637 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
2638 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
2639 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
2640 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2641 "0x6c0/0x6c4/0x6c8(coexTable)",
2642 u32tmp
[0], u32tmp
[1], u32tmp
[2]);
2645 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d",
2646 "0x770(high-pri rx/tx)", coex_sta
->high_priority_rx
,
2647 coex_sta
->high_priority_tx
);
2649 CL_SPRINTF(cli_buf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d",
2650 "0x774(low-pri rx/tx)", coex_sta
->low_priority_rx
,
2651 coex_sta
->low_priority_tx
);
2653 #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)
2654 halbtc8723b1ant_monitor_bt_ctr(btcoexist
);
2656 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
);
2659 void ex_halbtc8723b1ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
2661 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2664 if (BTC_IPS_ENTER
== type
) {
2665 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2666 "[BTCoex], IPS ENTER notify\n");
2667 coex_sta
->under_ips
= true;
2669 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_BT
,
2671 /* set PTA control */
2672 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2673 coex_table_with_type(btcoexist
,
2675 halbtc8723b1ant_wifi_off_hw_cfg(btcoexist
);
2676 } else if (BTC_IPS_LEAVE
== type
) {
2677 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2678 "[BTCoex], IPS LEAVE notify\n");
2679 coex_sta
->under_ips
= false;
2681 init_hw_config(btcoexist
, false);
2682 halbtc8723b1ant_init_coex_dm(btcoexist
);
2683 halbtc8723b1ant_query_bt_info(btcoexist
);
2687 void ex_halbtc8723b1ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
2689 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2692 if (BTC_LPS_ENABLE
== type
) {
2693 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2694 "[BTCoex], LPS ENABLE notify\n");
2695 coex_sta
->under_lps
= true;
2696 } else if (BTC_LPS_DISABLE
== type
) {
2697 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2698 "[BTCoex], LPS DISABLE notify\n");
2699 coex_sta
->under_lps
= false;
2703 void ex_halbtc8723b1ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
2705 bool wifi_connected
= false, bt_hs_on
= false;
2706 u32 wifi_link_status
= 0;
2707 u32 num_of_wifi_link
= 0;
2708 bool bt_ctrl_agg_buf_size
= false;
2709 u8 agg_buf_size
= 5;
2711 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2712 btcoexist
->bt_info
.bt_disabled
)
2715 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2716 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2719 halbtc8723b1ant_query_bt_info(btcoexist
);
2721 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2723 num_of_wifi_link
= wifi_link_status
>> 16;
2724 if (num_of_wifi_link
>= 2) {
2725 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2726 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2727 bt_ctrl_agg_buf_size
, agg_buf_size
);
2728 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2732 if (coex_sta
->c2h_bt_inquiry_page
) {
2733 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2735 } else if (bt_hs_on
) {
2736 halbtc8723b1ant_action_hs(btcoexist
);
2740 if (BTC_SCAN_START
== type
) {
2741 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2742 "[BTCoex], SCAN START notify\n");
2743 if (!wifi_connected
) /* non-connected scan */
2744 action_wifi_not_connected_scan(btcoexist
);
2745 else /* wifi is connected */
2746 action_wifi_connected_scan(btcoexist
);
2747 } else if (BTC_SCAN_FINISH
== type
) {
2748 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2749 "[BTCoex], SCAN FINISH notify\n");
2750 if (!wifi_connected
) /* non-connected scan */
2751 action_wifi_not_connected(btcoexist
);
2753 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2757 void ex_halbtc8723b1ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
2759 bool wifi_connected
= false, bt_hs_on
= false;
2760 u32 wifi_link_status
= 0;
2761 u32 num_of_wifi_link
= 0;
2762 bool bt_ctrl_agg_buf_size
= false;
2763 u8 agg_buf_size
= 5;
2765 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2766 btcoexist
->bt_info
.bt_disabled
)
2769 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2771 num_of_wifi_link
= wifi_link_status
>>16;
2772 if (num_of_wifi_link
>= 2) {
2773 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2774 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2775 bt_ctrl_agg_buf_size
, agg_buf_size
);
2776 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2780 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2781 if (coex_sta
->c2h_bt_inquiry_page
) {
2782 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2784 } else if (bt_hs_on
) {
2785 halbtc8723b1ant_action_hs(btcoexist
);
2789 if (BTC_ASSOCIATE_START
== type
) {
2790 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2791 "[BTCoex], CONNECT START notify\n");
2792 action_wifi_not_connected_asso_auth(btcoexist
);
2793 } else if (BTC_ASSOCIATE_FINISH
== type
) {
2794 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2795 "[BTCoex], CONNECT FINISH notify\n");
2797 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2799 if (!wifi_connected
) /* non-connected scan */
2800 action_wifi_not_connected(btcoexist
);
2802 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2806 void ex_halbtc8723b1ant_media_status_notify(struct btc_coexist
*btcoexist
,
2809 u8 h2c_parameter
[3] = {0};
2813 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2814 btcoexist
->bt_info
.bt_disabled
)
2817 if (BTC_MEDIA_CONNECT
== type
)
2818 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2819 "[BTCoex], MEDIA connect notify\n");
2821 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2822 "[BTCoex], MEDIA disconnect notify\n");
2824 /* only 2.4G we need to inform bt the chnl mask */
2825 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_CENTRAL_CHNL
,
2828 if ((BTC_MEDIA_CONNECT
== type
) &&
2829 (wificentralchnl
<= 14)) {
2830 h2c_parameter
[0] = 0x0;
2831 h2c_parameter
[1] = wificentralchnl
;
2832 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2833 if (BTC_WIFI_BW_HT40
== wifi_bw
)
2834 h2c_parameter
[2] = 0x30;
2836 h2c_parameter
[2] = 0x20;
2839 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
2840 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
2841 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
2843 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
,
2844 "[BTCoex], FW write 0x66 = 0x%x\n",
2845 h2c_parameter
[0] << 16 | h2c_parameter
[1] << 8 |
2848 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
2851 void ex_halbtc8723b1ant_special_packet_notify(struct btc_coexist
*btcoexist
,
2854 bool bt_hs_on
= false;
2855 u32 wifi_link_status
= 0;
2856 u32 num_of_wifi_link
= 0;
2857 bool bt_ctrl_agg_buf_size
= false;
2858 u8 agg_buf_size
= 5;
2860 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2861 btcoexist
->bt_info
.bt_disabled
)
2864 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2866 num_of_wifi_link
= wifi_link_status
>> 16;
2867 if (num_of_wifi_link
>= 2) {
2868 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2869 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2870 bt_ctrl_agg_buf_size
, agg_buf_size
);
2871 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2875 coex_sta
->special_pkt_period_cnt
= 0;
2877 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2878 if (coex_sta
->c2h_bt_inquiry_page
) {
2879 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2881 } else if (bt_hs_on
) {
2882 halbtc8723b1ant_action_hs(btcoexist
);
2886 if (BTC_PACKET_DHCP
== type
||
2887 BTC_PACKET_EAPOL
== type
) {
2888 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2889 "[BTCoex], special Packet(%d) notify\n", type
);
2890 action_wifi_connected_special_packet(btcoexist
);
2894 void ex_halbtc8723b1ant_bt_info_notify(struct btc_coexist
*btcoexist
,
2895 u8
*tmp_buf
, u8 length
)
2898 u8 i
, rsp_source
= 0;
2899 bool wifi_connected
= false;
2900 bool bt_busy
= false;
2902 coex_sta
->c2h_bt_info_req_sent
= false;
2904 rsp_source
= tmp_buf
[0] & 0xf;
2905 if (rsp_source
>= BT_INFO_SRC_8723B_1ANT_MAX
)
2906 rsp_source
= BT_INFO_SRC_8723B_1ANT_WIFI_FW
;
2907 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
2909 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2910 "[BTCoex], Bt info[%d], length =%d, hex data =[",
2911 rsp_source
, length
);
2912 for (i
= 0; i
< length
; i
++) {
2913 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmp_buf
[i
];
2915 bt_info
= tmp_buf
[i
];
2916 if (i
== length
- 1)
2917 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2918 "0x%02x]\n", tmp_buf
[i
]);
2920 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
2921 "0x%02x, ", tmp_buf
[i
]);
2924 if (BT_INFO_SRC_8723B_1ANT_WIFI_FW
!= rsp_source
) {
2925 coex_sta
->bt_retry_cnt
= /* [3:0] */
2926 coex_sta
->bt_info_c2h
[rsp_source
][2] & 0xf;
2929 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 + 10;
2931 coex_sta
->bt_info_ext
=
2932 coex_sta
->bt_info_c2h
[rsp_source
][4];
2934 /* Here we need to resend some wifi info to BT
2935 * because bt is reset and loss of the info.*/
2936 if (coex_sta
->bt_info_ext
& BIT(1)) {
2937 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2938 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
2939 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2942 ex_halbtc8723b1ant_media_status_notify(btcoexist
,
2945 ex_halbtc8723b1ant_media_status_notify(btcoexist
,
2946 BTC_MEDIA_DISCONNECT
);
2949 if (coex_sta
->bt_info_ext
& BIT(3)) {
2950 if (!btcoexist
->manual_control
&&
2951 !btcoexist
->stop_coex_dm
) {
2952 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
2953 "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
2954 halbtc8723b1ant_ignore_wlan_act(btcoexist
,
2959 /* BT already NOT ignore Wlan active, do nothing here.*/
2961 #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
2962 if (coex_sta
->bt_info_ext
& BIT(4)) {
2963 /* BT auto report already enabled, do nothing */
2965 halbtc8723b1ant_bt_auto_report(btcoexist
, FORCE_EXEC
,
2971 /* check BIT(2) first ==> check if bt is under inquiry or page scan */
2972 if (bt_info
& BT_INFO_8723B_1ANT_B_INQ_PAGE
)
2973 coex_sta
->c2h_bt_inquiry_page
= true;
2975 coex_sta
->c2h_bt_inquiry_page
= false;
2977 /* set link exist status */
2978 if (!(bt_info
& BT_INFO_8723B_1ANT_B_CONNECTION
)) {
2979 coex_sta
->bt_link_exist
= false;
2980 coex_sta
->pan_exist
= false;
2981 coex_sta
->a2dp_exist
= false;
2982 coex_sta
->hid_exist
= false;
2983 coex_sta
->sco_exist
= false;
2984 } else { /* connection exists */
2985 coex_sta
->bt_link_exist
= true;
2986 if (bt_info
& BT_INFO_8723B_1ANT_B_FTP
)
2987 coex_sta
->pan_exist
= true;
2989 coex_sta
->pan_exist
= false;
2990 if (bt_info
& BT_INFO_8723B_1ANT_B_A2DP
)
2991 coex_sta
->a2dp_exist
= true;
2993 coex_sta
->a2dp_exist
= false;
2994 if (bt_info
& BT_INFO_8723B_1ANT_B_HID
)
2995 coex_sta
->hid_exist
= true;
2997 coex_sta
->hid_exist
= false;
2998 if (bt_info
& BT_INFO_8723B_1ANT_B_SCO_ESCO
)
2999 coex_sta
->sco_exist
= true;
3001 coex_sta
->sco_exist
= false;
3004 halbtc8723b1ant_update_bt_link_info(btcoexist
);
3006 if (!(bt_info
&BT_INFO_8723B_1ANT_B_CONNECTION
)) {
3007 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
;
3008 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3009 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
3010 /* connection exists but no busy */
3011 } else if (bt_info
== BT_INFO_8723B_1ANT_B_CONNECTION
) {
3012 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
;
3013 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3014 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3015 } else if ((bt_info
& BT_INFO_8723B_1ANT_B_SCO_ESCO
) ||
3016 (bt_info
& BT_INFO_8723B_1ANT_B_SCO_BUSY
)) {
3017 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_SCO_BUSY
;
3018 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3019 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3020 } else if (bt_info
& BT_INFO_8723B_1ANT_B_ACL_BUSY
) {
3021 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
!= coex_dm
->bt_status
)
3022 coex_dm
->auto_tdma_adjust
= false;
3024 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_ACL_BUSY
;
3025 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3026 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3028 coex_dm
->bt_status
=
3029 BT_8723B_1ANT_BT_STATUS_MAX
;
3030 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3031 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
3034 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
3035 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
3036 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
))
3040 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
3042 halbtc8723b1ant_run_coexist_mechanism(btcoexist
);
3045 void ex_halbtc8723b1ant_halt_notify(struct btc_coexist
*btcoexist
)
3047 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, "[BTCoex], Halt notify\n");
3049 btcoexist
->stop_coex_dm
= true;
3051 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_BT
, false, true);
3053 halbtc8723b1ant_wifi_off_hw_cfg(btcoexist
);
3054 halbtc8723b1ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3056 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3058 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 0);
3060 ex_halbtc8723b1ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
3063 void ex_halbtc8723b1ant_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
3065 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, "[BTCoex], Pnp notify\n");
3067 if (BTC_WIFI_PNP_SLEEP
== pnp_state
) {
3068 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
3069 "[BTCoex], Pnp notify to SLEEP\n");
3070 btcoexist
->stop_coex_dm
= true;
3071 halbtc8723b1ant_setantpath(btcoexist
, BTC_ANT_PATH_BT
, false,
3073 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3075 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
3076 coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
3077 halbtc8723b1ant_wifi_off_hw_cfg(btcoexist
);
3078 } else if (BTC_WIFI_PNP_WAKE_UP
== pnp_state
) {
3079 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
,
3080 "[BTCoex], Pnp notify to WAKE UP\n");
3081 btcoexist
->stop_coex_dm
= false;
3082 init_hw_config(btcoexist
, false);
3083 halbtc8723b1ant_init_coex_dm(btcoexist
);
3084 halbtc8723b1ant_query_bt_info(btcoexist
);
3088 void ex_halbtc8723b1ant_coex_dm_reset(struct btc_coexist
*btcoexist
)
3090 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3091 "[BTCoex], *****************Coex DM Reset****************\n");
3093 init_hw_config(btcoexist
, false);
3094 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3095 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x2, 0xfffff, 0x0);
3096 halbtc8723b1ant_init_coex_dm(btcoexist
);
3099 void ex_halbtc8723b1ant_periodical(struct btc_coexist
*btcoexist
)
3101 struct btc_board_info
*brd_info
= &btcoexist
->board_info
;
3102 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
3103 static u8 dis_ver_info_cnt
;
3104 u32 fw_ver
= 0, bt_patch_ver
= 0;
3106 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
,
3107 "[BTCoex], ========================== Periodical ===========================\n");
3109 if (dis_ver_info_cnt
<= 5) {
3110 dis_ver_info_cnt
+= 1;
3111 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
3112 "[BTCoex], ****************************************************************\n");
3113 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
3114 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
3115 brd_info
->pg_ant_num
, brd_info
->btdm_ant_num
,
3116 brd_info
->btdm_ant_pos
);
3117 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
3118 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
3119 ((stack_info
->profile_notified
) ? "Yes" : "No"),
3120 stack_info
->hci_version
);
3121 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
,
3123 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3124 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
3125 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
3126 glcoex_ver_date_8723b_1ant
,
3127 glcoex_ver_8723b_1ant
, fw_ver
,
3128 bt_patch_ver
, bt_patch_ver
);
3129 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
,
3130 "[BTCoex], ****************************************************************\n");
3133 #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
3134 halbtc8723b1ant_query_bt_info(btcoexist
);
3135 halbtc8723b1ant_monitor_bt_ctr(btcoexist
);
3136 halbtc8723b1ant_monitor_bt_enable_disable(btcoexist
);
3138 if (is_wifi_status_changed(btcoexist
) ||
3139 coex_dm
->auto_tdma_adjust
) {
3140 halbtc8723b1ant_run_coexist_mechanism(btcoexist
);
3143 coex_sta
->special_pkt_period_cnt
++;