1 /******************************************************************************
3 * Copyright(c) 2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
25 /***************************************************************
28 * This file is for RTL8723B Co-exist mechanism
31 * 2012/11/15 Cosa first check in.
33 **************************************************************/
34 /**************************************************************
36 **************************************************************/
37 #include "halbt_precomp.h"
38 /**************************************************************
39 * Global variables, these are static variables
40 **************************************************************/
41 static struct coex_dm_8723b_2ant glcoex_dm_8723b_2ant
;
42 static struct coex_dm_8723b_2ant
*coex_dm
= &glcoex_dm_8723b_2ant
;
43 static struct coex_sta_8723b_2ant glcoex_sta_8723b_2ant
;
44 static struct coex_sta_8723b_2ant
*coex_sta
= &glcoex_sta_8723b_2ant
;
46 static const char *const glbt_info_src_8723b_2ant
[] = {
49 "BT Info[bt auto report]",
52 static u32 glcoex_ver_date_8723b_2ant
= 20131113;
53 static u32 glcoex_ver_8723b_2ant
= 0x3f;
55 /**************************************************************
56 * local function proto type if needed
57 **************************************************************/
58 /**************************************************************
59 * local function start with btc8723b2ant_
60 **************************************************************/
61 static u8
btc8723b2ant_bt_rssi_state(u8 level_num
, u8 rssi_thresh
,
65 u8 bt_rssi_state
= coex_sta
->pre_bt_rssi_state
;
67 bt_rssi
= coex_sta
->bt_rssi
;
70 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
71 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
72 if (bt_rssi
>= rssi_thresh
+
73 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
74 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
75 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
76 "[BTCoex], BT Rssi state switch to High\n");
78 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
79 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
80 "[BTCoex], BT Rssi state stay at Low\n");
83 if (bt_rssi
< rssi_thresh
) {
84 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
85 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
86 "[BTCoex], BT Rssi state switch to Low\n");
88 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
89 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
90 "[BTCoex], BT Rssi state stay at High\n");
93 } else if (level_num
== 3) {
94 if (rssi_thresh
> rssi_thresh1
) {
95 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
96 "[BTCoex], BT Rssi thresh error!!\n");
97 return coex_sta
->pre_bt_rssi_state
;
100 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
101 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
102 if (bt_rssi
>= rssi_thresh
+
103 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
104 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
105 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
106 "[BTCoex], BT Rssi state switch to Medium\n");
108 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
109 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
110 "[BTCoex], BT Rssi state stay at Low\n");
112 } else if ((coex_sta
->pre_bt_rssi_state
==
113 BTC_RSSI_STATE_MEDIUM
) ||
114 (coex_sta
->pre_bt_rssi_state
==
115 BTC_RSSI_STATE_STAY_MEDIUM
)) {
116 if (bt_rssi
>= rssi_thresh1
+
117 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
118 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
119 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
120 "[BTCoex], BT Rssi state switch to High\n");
121 } else if (bt_rssi
< rssi_thresh
) {
122 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
123 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
124 "[BTCoex], BT Rssi state switch to Low\n");
126 bt_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
127 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
128 "[BTCoex], BT Rssi state stay at Medium\n");
131 if (bt_rssi
< rssi_thresh1
) {
132 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
133 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
134 "[BTCoex], BT Rssi state switch to Medium\n");
136 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
137 btc_alg_dbg(ALGO_BT_RSSI_STATE
,
138 "[BTCoex], BT Rssi state stay at High\n");
143 coex_sta
->pre_bt_rssi_state
= bt_rssi_state
;
145 return bt_rssi_state
;
148 static u8
btc8723b2ant_wifi_rssi_state(struct btc_coexist
*btcoexist
,
149 u8 index
, u8 level_num
,
150 u8 rssi_thresh
, u8 rssi_thresh1
)
153 u8 wifi_rssi_state
= coex_sta
->pre_wifi_rssi_state
[index
];
155 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
157 if (level_num
== 2) {
158 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
159 BTC_RSSI_STATE_LOW
) ||
160 (coex_sta
->pre_wifi_rssi_state
[index
] ==
161 BTC_RSSI_STATE_STAY_LOW
)) {
162 if (wifi_rssi
>= rssi_thresh
+
163 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
164 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
165 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
166 "[BTCoex], wifi RSSI state switch to High\n");
168 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
169 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
170 "[BTCoex], wifi RSSI state stay at Low\n");
173 if (wifi_rssi
< rssi_thresh
) {
174 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
175 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
176 "[BTCoex], wifi RSSI state switch to Low\n");
178 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
179 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
180 "[BTCoex], wifi RSSI state stay at High\n");
183 } else if (level_num
== 3) {
184 if (rssi_thresh
> rssi_thresh1
) {
185 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
186 "[BTCoex], wifi RSSI thresh error!!\n");
187 return coex_sta
->pre_wifi_rssi_state
[index
];
190 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
191 BTC_RSSI_STATE_LOW
) ||
192 (coex_sta
->pre_wifi_rssi_state
[index
] ==
193 BTC_RSSI_STATE_STAY_LOW
)) {
194 if (wifi_rssi
>= rssi_thresh
+
195 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
196 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
197 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
198 "[BTCoex], wifi RSSI state switch to Medium\n");
200 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
201 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
202 "[BTCoex], wifi RSSI state stay at Low\n");
204 } else if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
205 BTC_RSSI_STATE_MEDIUM
) ||
206 (coex_sta
->pre_wifi_rssi_state
[index
] ==
207 BTC_RSSI_STATE_STAY_MEDIUM
)) {
208 if (wifi_rssi
>= rssi_thresh1
+
209 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
210 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
211 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
212 "[BTCoex], wifi RSSI state switch to High\n");
213 } else if (wifi_rssi
< rssi_thresh
) {
214 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
215 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
216 "[BTCoex], wifi RSSI state switch to Low\n");
218 wifi_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
219 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
220 "[BTCoex], wifi RSSI state stay at Medium\n");
223 if (wifi_rssi
< rssi_thresh1
) {
224 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
225 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
226 "[BTCoex], wifi RSSI state switch to Medium\n");
228 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
229 btc_alg_dbg(ALGO_WIFI_RSSI_STATE
,
230 "[BTCoex], wifi RSSI state stay at High\n");
235 coex_sta
->pre_wifi_rssi_state
[index
] = wifi_rssi_state
;
237 return wifi_rssi_state
;
240 static void btc8723b2ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
242 u32 reg_hp_txrx
, reg_lp_txrx
, u32tmp
;
243 u32 reg_hp_tx
= 0, reg_hp_rx
= 0;
244 u32 reg_lp_tx
= 0, reg_lp_rx
= 0;
249 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
250 reg_hp_tx
= u32tmp
& MASKLWORD
;
251 reg_hp_rx
= (u32tmp
& MASKHWORD
) >> 16;
253 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
254 reg_lp_tx
= u32tmp
& MASKLWORD
;
255 reg_lp_rx
= (u32tmp
& MASKHWORD
) >> 16;
257 coex_sta
->high_priority_tx
= reg_hp_tx
;
258 coex_sta
->high_priority_rx
= reg_hp_rx
;
259 coex_sta
->low_priority_tx
= reg_lp_tx
;
260 coex_sta
->low_priority_rx
= reg_lp_rx
;
262 btc_alg_dbg(ALGO_BT_MONITOR
,
263 "[BTCoex], High Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
264 reg_hp_txrx
, reg_hp_tx
, reg_hp_tx
, reg_hp_rx
, reg_hp_rx
);
265 btc_alg_dbg(ALGO_BT_MONITOR
,
266 "[BTCoex], Low Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
267 reg_lp_txrx
, reg_lp_tx
, reg_lp_tx
, reg_lp_rx
, reg_lp_rx
);
270 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
273 static void btc8723b2ant_query_bt_info(struct btc_coexist
*btcoexist
)
275 u8 h2c_parameter
[1] = {0};
277 coex_sta
->c2h_bt_info_req_sent
= true;
279 h2c_parameter
[0] |= BIT0
; /* trigger */
281 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
282 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
285 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
288 static bool btc8723b2ant_is_wifi_status_changed(struct btc_coexist
*btcoexist
)
290 static bool pre_wifi_busy
;
291 static bool pre_under_4way
;
292 static bool pre_bt_hs_on
;
293 bool wifi_busy
= false, under_4way
= false, bt_hs_on
= false;
294 bool wifi_connected
= false;
296 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
298 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
299 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
300 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
303 if (wifi_connected
) {
304 if (wifi_busy
!= pre_wifi_busy
) {
305 pre_wifi_busy
= wifi_busy
;
309 if (under_4way
!= pre_under_4way
) {
310 pre_under_4way
= under_4way
;
314 if (bt_hs_on
!= pre_bt_hs_on
) {
315 pre_bt_hs_on
= bt_hs_on
;
323 static void btc8723b2ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
325 /*struct btc_stack_info *stack_info = &btcoexist->stack_info;*/
326 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
327 bool bt_hs_on
= false;
329 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 1) /* profile from bt patch */
330 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
332 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
333 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
334 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
335 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
336 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
338 /* work around for HS mode. */
340 bt_link_info
->pan_exist
= true;
341 bt_link_info
->bt_link_exist
= true;
343 #else /* profile from bt stack */
344 bt_link_info
->bt_link_exist
= stack_info
->bt_link_exist
;
345 bt_link_info
->sco_exist
= stack_info
->sco_exist
;
346 bt_link_info
->a2dp_exist
= stack_info
->a2dp_exist
;
347 bt_link_info
->pan_exist
= stack_info
->pan_exist
;
348 bt_link_info
->hid_exist
= stack_info
->hid_exist
;
350 /*for win-8 stack HID report error*/
351 if (!stack_info
->hid_exist
)
352 stack_info
->hid_exist
= coex_sta
->hid_exist
;
353 /*sync BTInfo with BT firmware and stack*/
354 /* when stack HID report error, here we use the info from bt fw.*/
355 if (!stack_info
->bt_link_exist
)
356 stack_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
358 /* check if Sco only */
359 if (bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
360 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
361 bt_link_info
->sco_only
= true;
363 bt_link_info
->sco_only
= false;
365 /* check if A2dp only */
366 if (!bt_link_info
->sco_exist
&& bt_link_info
->a2dp_exist
&&
367 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
368 bt_link_info
->a2dp_only
= true;
370 bt_link_info
->a2dp_only
= false;
372 /* check if Pan only */
373 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
374 bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
375 bt_link_info
->pan_only
= true;
377 bt_link_info
->pan_only
= false;
379 /* check if Hid only */
380 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
381 !bt_link_info
->pan_exist
&& bt_link_info
->hid_exist
)
382 bt_link_info
->hid_only
= true;
384 bt_link_info
->hid_only
= false;
387 static u8
btc8723b2ant_action_algorithm(struct btc_coexist
*btcoexist
)
389 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
390 bool bt_hs_on
= false;
391 u8 algorithm
= BT_8723B_2ANT_COEX_ALGO_UNDEFINED
;
392 u8 num_of_diff_profile
= 0;
394 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
396 if (!bt_link_info
->bt_link_exist
) {
397 btc_alg_dbg(ALGO_TRACE
,
398 "[BTCoex], No BT link exists!!!\n");
402 if (bt_link_info
->sco_exist
)
403 num_of_diff_profile
++;
404 if (bt_link_info
->hid_exist
)
405 num_of_diff_profile
++;
406 if (bt_link_info
->pan_exist
)
407 num_of_diff_profile
++;
408 if (bt_link_info
->a2dp_exist
)
409 num_of_diff_profile
++;
411 if (num_of_diff_profile
== 1) {
412 if (bt_link_info
->sco_exist
) {
413 btc_alg_dbg(ALGO_TRACE
,
414 "[BTCoex], SCO only\n");
415 algorithm
= BT_8723B_2ANT_COEX_ALGO_SCO
;
417 if (bt_link_info
->hid_exist
) {
418 btc_alg_dbg(ALGO_TRACE
,
419 "[BTCoex], HID only\n");
420 algorithm
= BT_8723B_2ANT_COEX_ALGO_HID
;
421 } else if (bt_link_info
->a2dp_exist
) {
422 btc_alg_dbg(ALGO_TRACE
,
423 "[BTCoex], A2DP only\n");
424 algorithm
= BT_8723B_2ANT_COEX_ALGO_A2DP
;
425 } else if (bt_link_info
->pan_exist
) {
427 btc_alg_dbg(ALGO_TRACE
,
428 "[BTCoex], PAN(HS) only\n");
430 BT_8723B_2ANT_COEX_ALGO_PANHS
;
432 btc_alg_dbg(ALGO_TRACE
,
433 "[BTCoex], PAN(EDR) only\n");
435 BT_8723B_2ANT_COEX_ALGO_PANEDR
;
439 } else if (num_of_diff_profile
== 2) {
440 if (bt_link_info
->sco_exist
) {
441 if (bt_link_info
->hid_exist
) {
442 btc_alg_dbg(ALGO_TRACE
,
443 "[BTCoex], SCO + HID\n");
444 algorithm
= BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
445 } else if (bt_link_info
->a2dp_exist
) {
446 btc_alg_dbg(ALGO_TRACE
,
447 "[BTCoex], SCO + A2DP ==> SCO\n");
448 algorithm
= BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
449 } else if (bt_link_info
->pan_exist
) {
451 btc_alg_dbg(ALGO_TRACE
,
452 "[BTCoex], SCO + PAN(HS)\n");
453 algorithm
= BT_8723B_2ANT_COEX_ALGO_SCO
;
455 btc_alg_dbg(ALGO_TRACE
,
456 "[BTCoex], SCO + PAN(EDR)\n");
458 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
462 if (bt_link_info
->hid_exist
&&
463 bt_link_info
->a2dp_exist
) {
464 btc_alg_dbg(ALGO_TRACE
,
465 "[BTCoex], HID + A2DP\n");
466 algorithm
= BT_8723B_2ANT_COEX_ALGO_HID_A2DP
;
467 } else if (bt_link_info
->hid_exist
&&
468 bt_link_info
->pan_exist
) {
470 btc_alg_dbg(ALGO_TRACE
,
471 "[BTCoex], HID + PAN(HS)\n");
472 algorithm
= BT_8723B_2ANT_COEX_ALGO_HID
;
474 btc_alg_dbg(ALGO_TRACE
,
475 "[BTCoex], HID + PAN(EDR)\n");
477 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
479 } else if (bt_link_info
->pan_exist
&&
480 bt_link_info
->a2dp_exist
) {
482 btc_alg_dbg(ALGO_TRACE
,
483 "[BTCoex], A2DP + PAN(HS)\n");
485 BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS
;
487 btc_alg_dbg(ALGO_TRACE
,
488 "[BTCoex],A2DP + PAN(EDR)\n");
490 BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP
;
494 } else if (num_of_diff_profile
== 3) {
495 if (bt_link_info
->sco_exist
) {
496 if (bt_link_info
->hid_exist
&&
497 bt_link_info
->a2dp_exist
) {
498 btc_alg_dbg(ALGO_TRACE
,
499 "[BTCoex], SCO + HID + A2DP ==> HID\n");
500 algorithm
= BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
501 } else if (bt_link_info
->hid_exist
&&
502 bt_link_info
->pan_exist
) {
504 btc_alg_dbg(ALGO_TRACE
,
505 "[BTCoex], SCO + HID + PAN(HS)\n");
507 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
509 btc_alg_dbg(ALGO_TRACE
,
510 "[BTCoex], SCO + HID + PAN(EDR)\n");
512 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
514 } else if (bt_link_info
->pan_exist
&&
515 bt_link_info
->a2dp_exist
) {
517 btc_alg_dbg(ALGO_TRACE
,
518 "[BTCoex], SCO + A2DP + PAN(HS)\n");
520 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
522 btc_alg_dbg(ALGO_TRACE
,
523 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
525 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
529 if (bt_link_info
->hid_exist
&&
530 bt_link_info
->pan_exist
&&
531 bt_link_info
->a2dp_exist
) {
533 btc_alg_dbg(ALGO_TRACE
,
534 "[BTCoex], HID + A2DP + PAN(HS)\n");
536 BT_8723B_2ANT_COEX_ALGO_HID_A2DP
;
538 btc_alg_dbg(ALGO_TRACE
,
539 "[BTCoex], HID + A2DP + PAN(EDR)\n");
541 BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR
;
545 } else if (num_of_diff_profile
>= 3) {
546 if (bt_link_info
->sco_exist
) {
547 if (bt_link_info
->hid_exist
&&
548 bt_link_info
->pan_exist
&&
549 bt_link_info
->a2dp_exist
) {
551 btc_alg_dbg(ALGO_TRACE
,
552 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
554 btc_alg_dbg(ALGO_TRACE
,
555 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
557 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
565 static bool btc8723b_need_dec_pwr(struct btc_coexist
*btcoexist
)
568 bool bt_hs_on
= false, wifi_connected
= false;
572 if (!btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
))
574 if (!btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
577 if (!btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
))
580 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
582 if (wifi_connected
) {
584 if (bt_hs_rssi
> 37) {
585 btc_alg_dbg(ALGO_TRACE_FW
,
586 "[BTCoex], Need to decrease bt power for HS mode!!\n");
590 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
591 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
592 btc_alg_dbg(ALGO_TRACE_FW
,
593 "[BTCoex], Need to decrease bt power for Wifi is connected!!\n");
602 static void btc8723b2ant_set_fw_dac_swing_level(struct btc_coexist
*btcoexist
,
605 u8 h2c_parameter
[1] = {0};
607 /* There are several type of dacswing
608 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
610 h2c_parameter
[0] = dac_swing_lvl
;
612 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
613 "[BTCoex], Set Dac Swing Level=0x%x\n", dac_swing_lvl
);
614 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
615 "[BTCoex], FW write 0x64=0x%x\n", h2c_parameter
[0]);
617 btcoexist
->btc_fill_h2c(btcoexist
, 0x64, 1, h2c_parameter
);
620 static void btc8723b2ant_set_fw_dec_bt_pwr(struct btc_coexist
*btcoexist
,
623 u8 h2c_parameter
[1] = {0};
625 h2c_parameter
[0] = 0;
628 h2c_parameter
[0] |= BIT1
;
630 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
631 "[BTCoex], decrease Bt Power : %s, FW write 0x62=0x%x\n",
632 (dec_bt_pwr
? "Yes!!" : "No!!"), h2c_parameter
[0]);
634 btcoexist
->btc_fill_h2c(btcoexist
, 0x62, 1, h2c_parameter
);
637 static void btc8723b2ant_dec_bt_pwr(struct btc_coexist
*btcoexist
,
638 bool force_exec
, bool dec_bt_pwr
)
640 btc_alg_dbg(ALGO_TRACE_FW
,
641 "[BTCoex], %s Dec BT power = %s\n",
642 force_exec
? "force to" : "", dec_bt_pwr
? "ON" : "OFF");
643 coex_dm
->cur_dec_bt_pwr
= dec_bt_pwr
;
646 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
647 "[BTCoex], bPreDecBtPwr=%d, bCurDecBtPwr=%d\n",
648 coex_dm
->pre_dec_bt_pwr
, coex_dm
->cur_dec_bt_pwr
);
650 if (coex_dm
->pre_dec_bt_pwr
== coex_dm
->cur_dec_bt_pwr
)
653 btc8723b2ant_set_fw_dec_bt_pwr(btcoexist
, coex_dm
->cur_dec_bt_pwr
);
655 coex_dm
->pre_dec_bt_pwr
= coex_dm
->cur_dec_bt_pwr
;
658 static void btc8723b2ant_fw_dac_swing_lvl(struct btc_coexist
*btcoexist
,
659 bool force_exec
, u8 fw_dac_swing_lvl
)
661 btc_alg_dbg(ALGO_TRACE_FW
,
662 "[BTCoex], %s set FW Dac Swing level = %d\n",
663 (force_exec
? "force to" : ""), fw_dac_swing_lvl
);
664 coex_dm
->cur_fw_dac_swing_lvl
= fw_dac_swing_lvl
;
667 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
668 "[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n",
669 coex_dm
->pre_fw_dac_swing_lvl
,
670 coex_dm
->cur_fw_dac_swing_lvl
);
672 if (coex_dm
->pre_fw_dac_swing_lvl
==
673 coex_dm
->cur_fw_dac_swing_lvl
)
677 btc8723b2ant_set_fw_dac_swing_level(btcoexist
,
678 coex_dm
->cur_fw_dac_swing_lvl
);
679 coex_dm
->pre_fw_dac_swing_lvl
= coex_dm
->cur_fw_dac_swing_lvl
;
682 static void btc8723b2ant_set_sw_rf_rx_lpf_corner(struct btc_coexist
*btcoexist
,
683 bool rx_rf_shrink_on
)
685 if (rx_rf_shrink_on
) {
686 /* Shrink RF Rx LPF corner */
687 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
688 "[BTCoex], Shrink RF Rx LPF corner!!\n");
689 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1e,
692 /* Resume RF Rx LPF corner */
693 /* After initialized, we can use coex_dm->btRf0x1eBackup */
694 if (btcoexist
->initilized
) {
695 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
696 "[BTCoex], Resume RF Rx LPF corner!!\n");
697 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1e,
699 coex_dm
->bt_rf0x1e_backup
);
704 static void btc8723b2ant_rf_shrink(struct btc_coexist
*btcoexist
,
705 bool force_exec
, bool rx_rf_shrink_on
)
707 btc_alg_dbg(ALGO_TRACE_SW
,
708 "[BTCoex], %s turn Rx RF Shrink = %s\n",
709 (force_exec
? "force to" : ""), (rx_rf_shrink_on
?
711 coex_dm
->cur_rf_rx_lpf_shrink
= rx_rf_shrink_on
;
714 btc_alg_dbg(ALGO_TRACE_SW_DETAIL
,
715 "[BTCoex], bPreRfRxLpfShrink=%d, bCurRfRxLpfShrink=%d\n",
716 coex_dm
->pre_rf_rx_lpf_shrink
,
717 coex_dm
->cur_rf_rx_lpf_shrink
);
719 if (coex_dm
->pre_rf_rx_lpf_shrink
==
720 coex_dm
->cur_rf_rx_lpf_shrink
)
723 btc8723b2ant_set_sw_rf_rx_lpf_corner(btcoexist
,
724 coex_dm
->cur_rf_rx_lpf_shrink
);
726 coex_dm
->pre_rf_rx_lpf_shrink
= coex_dm
->cur_rf_rx_lpf_shrink
;
729 static void btc8723b_set_penalty_txrate(struct btc_coexist
*btcoexist
,
732 u8 h2c_parameter
[6] = {0};
734 h2c_parameter
[0] = 0x6; /* opCode, 0x6= Retry_Penalty*/
736 if (low_penalty_ra
) {
737 h2c_parameter
[1] |= BIT0
;
738 /*normal rate except MCS7/6/5, OFDM54/48/36*/
739 h2c_parameter
[2] = 0x00;
740 h2c_parameter
[3] = 0xf7; /*MCS7 or OFDM54*/
741 h2c_parameter
[4] = 0xf8; /*MCS6 or OFDM48*/
742 h2c_parameter
[5] = 0xf9; /*MCS5 or OFDM36*/
745 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
746 "[BTCoex], set WiFi Low-Penalty Retry: %s",
747 (low_penalty_ra
? "ON!!" : "OFF!!"));
749 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
752 static void btc8723b2ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
753 bool force_exec
, bool low_penalty_ra
)
756 btc_alg_dbg(ALGO_TRACE_SW
,
757 "[BTCoex], %s turn LowPenaltyRA = %s\n",
758 (force_exec
? "force to" : ""), (low_penalty_ra
?
760 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
763 btc_alg_dbg(ALGO_TRACE_SW_DETAIL
,
764 "[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n",
765 coex_dm
->pre_low_penalty_ra
,
766 coex_dm
->cur_low_penalty_ra
);
768 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
771 btc8723b_set_penalty_txrate(btcoexist
, coex_dm
->cur_low_penalty_ra
);
773 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
776 static void btc8723b2ant_set_dac_swing_reg(struct btc_coexist
*btcoexist
,
780 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
781 "[BTCoex], Write SwDacSwing = 0x%x\n", level
);
782 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x883, 0x3e, val
);
785 static void btc8723b2ant_set_sw_fulltime_dac_swing(struct btc_coexist
*btcoex
,
786 bool sw_dac_swing_on
,
787 u32 sw_dac_swing_lvl
)
790 btc8723b2ant_set_dac_swing_reg(btcoex
, sw_dac_swing_lvl
);
792 btc8723b2ant_set_dac_swing_reg(btcoex
, 0x18);
795 static void btc8723b2ant_dac_swing(struct btc_coexist
*btcoexist
,
796 bool force_exec
, bool dac_swing_on
,
799 btc_alg_dbg(ALGO_TRACE_SW
,
800 "[BTCoex], %s turn DacSwing=%s, dac_swing_lvl=0x%x\n",
801 (force_exec
? "force to" : ""),
802 (dac_swing_on
? "ON" : "OFF"), dac_swing_lvl
);
803 coex_dm
->cur_dac_swing_on
= dac_swing_on
;
804 coex_dm
->cur_dac_swing_lvl
= dac_swing_lvl
;
807 btc_alg_dbg(ALGO_TRACE_SW_DETAIL
,
808 "[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n",
809 coex_dm
->pre_dac_swing_on
,
810 coex_dm
->pre_dac_swing_lvl
,
811 coex_dm
->cur_dac_swing_on
,
812 coex_dm
->cur_dac_swing_lvl
);
814 if ((coex_dm
->pre_dac_swing_on
== coex_dm
->cur_dac_swing_on
) &&
815 (coex_dm
->pre_dac_swing_lvl
== coex_dm
->cur_dac_swing_lvl
))
819 btc8723b2ant_set_sw_fulltime_dac_swing(btcoexist
, dac_swing_on
,
822 coex_dm
->pre_dac_swing_on
= coex_dm
->cur_dac_swing_on
;
823 coex_dm
->pre_dac_swing_lvl
= coex_dm
->cur_dac_swing_lvl
;
826 static void btc8723b2ant_set_agc_table(struct btc_coexist
*btcoexist
,
829 u8 rssi_adjust_val
= 0;
831 /* BB AGC Gain Table */
833 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
834 "[BTCoex], BB Agc Table On!\n");
835 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x6e1A0001);
836 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x6d1B0001);
837 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x6c1C0001);
838 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x6b1D0001);
839 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x6a1E0001);
840 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x691F0001);
841 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0x68200001);
843 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
844 "[BTCoex], BB Agc Table Off!\n");
845 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xaa1A0001);
846 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xa91B0001);
847 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xa81C0001);
848 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xa71D0001);
849 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xa61E0001);
850 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xa51F0001);
851 btcoexist
->btc_write_4byte(btcoexist
, 0xc78, 0xa4200001);
855 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0xef, 0xfffff, 0x02000);
857 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
858 "[BTCoex], Agc Table On!\n");
859 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x3b,
861 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x3b,
864 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
865 "[BTCoex], Agc Table Off!\n");
866 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x3b,
868 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x3b,
871 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0xef, 0xfffff, 0x0);
873 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0xed, 0xfffff, 0x1);
876 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
877 "[BTCoex], Agc Table On!\n");
878 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x40,
880 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x40,
883 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
884 "[BTCoex], Agc Table Off!\n");
885 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x40,
887 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x40,
890 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0xed, 0xfffff, 0x0);
892 /* set rssiAdjustVal for wifi module. */
895 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON
,
899 static void btc8723b2ant_agc_table(struct btc_coexist
*btcoexist
,
900 bool force_exec
, bool agc_table_en
)
902 btc_alg_dbg(ALGO_TRACE_SW
,
903 "[BTCoex], %s %s Agc Table\n",
904 (force_exec
? "force to" : ""),
905 (agc_table_en
? "Enable" : "Disable"));
906 coex_dm
->cur_agc_table_en
= agc_table_en
;
909 btc_alg_dbg(ALGO_TRACE_SW_DETAIL
,
910 "[BTCoex], bPreAgcTableEn=%d, bCurAgcTableEn=%d\n",
911 coex_dm
->pre_agc_table_en
,
912 coex_dm
->cur_agc_table_en
);
914 if (coex_dm
->pre_agc_table_en
== coex_dm
->cur_agc_table_en
)
917 btc8723b2ant_set_agc_table(btcoexist
, agc_table_en
);
919 coex_dm
->pre_agc_table_en
= coex_dm
->cur_agc_table_en
;
922 static void btc8723b2ant_set_coex_table(struct btc_coexist
*btcoexist
,
923 u32 val0x6c0
, u32 val0x6c4
,
924 u32 val0x6c8
, u8 val0x6cc
)
926 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
927 "[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0
);
928 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
930 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
931 "[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4
);
932 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
934 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
935 "[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8
);
936 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
938 btc_alg_dbg(ALGO_TRACE_SW_EXEC
,
939 "[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc
);
940 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
943 static void btc8723b2ant_coex_table(struct btc_coexist
*btcoexist
,
944 bool force_exec
, u32 val0x6c0
,
945 u32 val0x6c4
, u32 val0x6c8
,
948 btc_alg_dbg(ALGO_TRACE_SW
,
949 "[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
950 force_exec
? "force to" : "",
951 val0x6c0
, val0x6c4
, val0x6c8
, val0x6cc
);
952 coex_dm
->cur_val0x6c0
= val0x6c0
;
953 coex_dm
->cur_val0x6c4
= val0x6c4
;
954 coex_dm
->cur_val0x6c8
= val0x6c8
;
955 coex_dm
->cur_val0x6cc
= val0x6cc
;
958 btc_alg_dbg(ALGO_TRACE_SW_DETAIL
,
959 "[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n",
960 coex_dm
->pre_val0x6c0
, coex_dm
->pre_val0x6c4
,
961 coex_dm
->pre_val0x6c8
, coex_dm
->pre_val0x6cc
);
962 btc_alg_dbg(ALGO_TRACE_SW_DETAIL
,
963 "[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n",
964 coex_dm
->cur_val0x6c0
, coex_dm
->cur_val0x6c4
,
965 coex_dm
->cur_val0x6c8
, coex_dm
->cur_val0x6cc
);
967 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
968 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
969 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
970 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
973 btc8723b2ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
,
976 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
977 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
978 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
979 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
982 static void btc8723b_coex_tbl_type(struct btc_coexist
*btcoexist
,
983 bool force_exec
, u8 type
)
987 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55555555,
988 0x55555555, 0xffff, 0x3);
991 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55555555,
992 0x5afa5afa, 0xffff, 0x3);
995 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
996 0x5a5a5a5a, 0xffff, 0x3);
999 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
1000 0xaaaaaaaa, 0xffff, 0x3);
1003 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0xffffffff,
1004 0xffffffff, 0xffff, 0x3);
1007 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
1008 0x5fff5fff, 0xffff, 0x3);
1011 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
1012 0x5a5a5a5a, 0xffff, 0x3);
1015 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
1016 0x5afa5afa, 0xffff, 0x3);
1019 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5aea5aea,
1020 0x5aea5aea, 0xffff, 0x3);
1023 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
1024 0x5aea5aea, 0xffff, 0x3);
1027 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
1028 0x5aff5aff, 0xffff, 0x3);
1031 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
1032 0x5a5f5a5f, 0xffff, 0x3);
1035 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
1036 0x5f5f5f5f, 0xffff, 0x3);
1043 static void btc8723b2ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoexist
,
1046 u8 h2c_parameter
[1] = {0};
1049 h2c_parameter
[0] |= BIT0
;/* function enable*/
1051 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
1052 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n",
1055 btcoexist
->btc_fill_h2c(btcoexist
, 0x63, 1, h2c_parameter
);
1058 static void btc8723b2ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
1059 bool force_exec
, bool enable
)
1061 btc_alg_dbg(ALGO_TRACE_FW
,
1062 "[BTCoex], %s turn Ignore WlanAct %s\n",
1063 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
1064 coex_dm
->cur_ignore_wlan_act
= enable
;
1067 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1068 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
1069 coex_dm
->pre_ignore_wlan_act
,
1070 coex_dm
->cur_ignore_wlan_act
);
1072 if (coex_dm
->pre_ignore_wlan_act
==
1073 coex_dm
->cur_ignore_wlan_act
)
1076 btc8723b2ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
1078 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
1081 static void btc8723b2ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
, u8 byte1
,
1082 u8 byte2
, u8 byte3
, u8 byte4
, u8 byte5
)
1084 u8 h2c_parameter
[5];
1086 h2c_parameter
[0] = byte1
;
1087 h2c_parameter
[1] = byte2
;
1088 h2c_parameter
[2] = byte3
;
1089 h2c_parameter
[3] = byte4
;
1090 h2c_parameter
[4] = byte5
;
1092 coex_dm
->ps_tdma_para
[0] = byte1
;
1093 coex_dm
->ps_tdma_para
[1] = byte2
;
1094 coex_dm
->ps_tdma_para
[2] = byte3
;
1095 coex_dm
->ps_tdma_para
[3] = byte4
;
1096 coex_dm
->ps_tdma_para
[4] = byte5
;
1098 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
1099 "[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n",
1101 h2c_parameter
[1] << 24 | h2c_parameter
[2] << 16 |
1102 h2c_parameter
[3] << 8 | h2c_parameter
[4]);
1104 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
1107 static void btc8723b2ant_sw_mechanism1(struct btc_coexist
*btcoexist
,
1108 bool shrink_rx_lpf
, bool low_penalty_ra
,
1109 bool limited_dig
, bool bt_lna_constrain
)
1111 btc8723b2ant_rf_shrink(btcoexist
, NORMAL_EXEC
, shrink_rx_lpf
);
1112 btc8723b2ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
1115 static void btc8723b2ant_sw_mechanism2(struct btc_coexist
*btcoexist
,
1116 bool agc_table_shift
, bool adc_backoff
,
1117 bool sw_dac_swing
, u32 dac_swing_lvl
)
1119 btc8723b2ant_agc_table(btcoexist
, NORMAL_EXEC
, agc_table_shift
);
1120 btc8723b2ant_dac_swing(btcoexist
, NORMAL_EXEC
, sw_dac_swing
,
1124 static void btc8723b2ant_set_ant_path(struct btc_coexist
*btcoexist
,
1125 u8 antpos_type
, bool init_hwcfg
,
1128 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
1129 u32 fw_ver
= 0, u32tmp
= 0;
1130 bool pg_ext_switch
= false;
1131 bool use_ext_switch
= false;
1132 u8 h2c_parameter
[2] = {0};
1134 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_EXT_SWITCH
, &pg_ext_switch
);
1135 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
1137 if ((fw_ver
< 0xc0000) || pg_ext_switch
)
1138 use_ext_switch
= true;
1141 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
1142 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
1145 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
1147 btcoexist
->btc_write_1byte(btcoexist
, 0x974, 0xff);
1148 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x944, 0x3, 0x3);
1149 btcoexist
->btc_write_1byte(btcoexist
, 0x930, 0x77);
1150 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x1);
1152 /* Force GNT_BT to low */
1153 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x765, 0x18, 0x0);
1155 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
) {
1156 /* tell firmware "no antenna inverse" */
1157 h2c_parameter
[0] = 0;
1158 h2c_parameter
[1] = 1; /* ext switch type */
1159 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1161 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x0);
1163 /* tell firmware "antenna inverse" */
1164 h2c_parameter
[0] = 1;
1165 h2c_parameter
[1] = 1; /* ext switch type */
1166 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1168 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x280);
1172 /* ext switch setting */
1173 if (use_ext_switch
) {
1174 /* fixed internal switch S1->WiFi, S0->BT */
1175 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1176 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x0);
1178 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x280);
1180 switch (antpos_type
) {
1181 case BTC_ANT_WIFI_AT_MAIN
:
1182 /* ext switch main at wifi */
1183 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x92c,
1186 case BTC_ANT_WIFI_AT_AUX
:
1187 /* ext switch aux at wifi */
1188 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1192 } else { /* internal switch */
1193 /* fixed ext switch */
1194 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x92c, 0x3, 0x1);
1195 switch (antpos_type
) {
1196 case BTC_ANT_WIFI_AT_MAIN
:
1197 /* fixed internal switch S1->WiFi, S0->BT */
1198 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x0);
1200 case BTC_ANT_WIFI_AT_AUX
:
1201 /* fixed internal switch S0->WiFi, S1->BT */
1202 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x280);
1208 static void btc8723b2ant_ps_tdma(struct btc_coexist
*btcoexist
, bool force_exec
,
1209 bool turn_on
, u8 type
)
1211 btc_alg_dbg(ALGO_TRACE_FW
,
1212 "[BTCoex], %s turn %s PS TDMA, type=%d\n",
1213 (force_exec
? "force to" : ""),
1214 (turn_on
? "ON" : "OFF"), type
);
1215 coex_dm
->cur_ps_tdma_on
= turn_on
;
1216 coex_dm
->cur_ps_tdma
= type
;
1219 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1220 "[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1221 coex_dm
->pre_ps_tdma_on
, coex_dm
->cur_ps_tdma_on
);
1222 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1223 "[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1224 coex_dm
->pre_ps_tdma
, coex_dm
->cur_ps_tdma
);
1226 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1227 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1234 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1238 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
1242 /* This call breaks BT when wireless is active -
1243 * comment it out for now until a better fix is found:
1244 * btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1249 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1253 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1257 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
1261 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1265 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x10,
1269 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1273 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
1277 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1281 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5,
1285 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1289 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
1293 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1297 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5,
1301 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x2f,
1305 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5,
1309 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1313 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1317 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1321 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1326 /* disable PS tdma */
1329 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1333 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1337 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1343 /* update pre state */
1344 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1345 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1348 static void btc8723b2ant_coex_alloff(struct btc_coexist
*btcoexist
)
1351 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1352 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1353 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1356 btc8723b2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1357 btc8723b2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1360 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
1361 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 0);
1364 static void btc8723b2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
1366 /* force to reset coex mechanism*/
1368 btc8723b2ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 1);
1369 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1370 btc8723b2ant_dec_bt_pwr(btcoexist
, FORCE_EXEC
, false);
1372 btc8723b2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1373 btc8723b2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1376 static void btc8723b2ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1378 bool wifi_connected
= false;
1379 bool low_pwr_disable
= true;
1381 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1383 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1386 if (wifi_connected
) {
1387 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
1388 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1390 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 0);
1391 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1393 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1394 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1396 btc8723b2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1397 btc8723b2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1399 coex_dm
->need_recover_0x948
= true;
1400 coex_dm
->backup_0x948
= btcoexist
->btc_read_2byte(btcoexist
, 0x948);
1402 btc8723b2ant_set_ant_path(btcoexist
, BTC_ANT_WIFI_AT_AUX
,
1406 static bool btc8723b2ant_is_common_action(struct btc_coexist
*btcoexist
)
1408 bool common
= false, wifi_connected
= false;
1409 bool wifi_busy
= false;
1410 bool bt_hs_on
= false, low_pwr_disable
= false;
1412 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
1413 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1415 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1417 if (!wifi_connected
) {
1418 low_pwr_disable
= false;
1419 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1422 btc_alg_dbg(ALGO_TRACE
,
1423 "[BTCoex], Wifi non-connected idle!!\n");
1425 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
1427 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 0);
1428 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1429 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1430 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1432 btc8723b2ant_sw_mechanism1(btcoexist
, false, false, false,
1434 btc8723b2ant_sw_mechanism2(btcoexist
, false, false, false,
1439 if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE
==
1440 coex_dm
->bt_status
) {
1441 low_pwr_disable
= false;
1442 btcoexist
->btc_set(btcoexist
,
1443 BTC_SET_ACT_DISABLE_LOW_POWER
,
1446 btc_alg_dbg(ALGO_TRACE
,
1447 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1449 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
1451 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 0);
1452 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1453 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
1455 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
,
1458 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
1460 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
1464 } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE
==
1465 coex_dm
->bt_status
) {
1466 low_pwr_disable
= true;
1467 btcoexist
->btc_set(btcoexist
,
1468 BTC_SET_ACT_DISABLE_LOW_POWER
,
1473 btc_alg_dbg(ALGO_TRACE
,
1474 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1476 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
1478 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 0);
1479 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1480 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
1482 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
,
1485 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
1487 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
1492 low_pwr_disable
= true;
1493 btcoexist
->btc_set(btcoexist
,
1494 BTC_SET_ACT_DISABLE_LOW_POWER
,
1498 btc_alg_dbg(ALGO_TRACE
,
1499 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1505 btc_alg_dbg(ALGO_TRACE
,
1506 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1508 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
,
1510 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
,
1512 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1514 btc8723b2ant_fw_dac_swing_lvl(btcoexist
,
1517 if (btc8723b_need_dec_pwr(btcoexist
))
1518 btc8723b2ant_dec_bt_pwr(btcoexist
,
1522 btc8723b2ant_dec_bt_pwr(btcoexist
,
1525 btc8723b2ant_sw_mechanism1(btcoexist
, false,
1528 btc8723b2ant_sw_mechanism2(btcoexist
, false,
1539 static void set_tdma_int1(struct btc_coexist
*btcoexist
, bool tx_pause
,
1542 /* Set PS TDMA for max interval == 1 */
1544 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1545 "[BTCoex], TxPause = 1\n");
1547 if (coex_dm
->cur_ps_tdma
== 71) {
1548 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1550 coex_dm
->tdma_adj_type
= 5;
1551 } else if (coex_dm
->cur_ps_tdma
== 1) {
1552 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1554 coex_dm
->tdma_adj_type
= 5;
1555 } else if (coex_dm
->cur_ps_tdma
== 2) {
1556 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1558 coex_dm
->tdma_adj_type
= 6;
1559 } else if (coex_dm
->cur_ps_tdma
== 3) {
1560 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1562 coex_dm
->tdma_adj_type
= 7;
1563 } else if (coex_dm
->cur_ps_tdma
== 4) {
1564 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1566 coex_dm
->tdma_adj_type
= 8;
1569 if (coex_dm
->cur_ps_tdma
== 9) {
1570 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1572 coex_dm
->tdma_adj_type
= 13;
1573 } else if (coex_dm
->cur_ps_tdma
== 10) {
1574 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1576 coex_dm
->tdma_adj_type
= 14;
1577 } else if (coex_dm
->cur_ps_tdma
== 11) {
1578 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1580 coex_dm
->tdma_adj_type
= 15;
1581 } else if (coex_dm
->cur_ps_tdma
== 12) {
1582 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1584 coex_dm
->tdma_adj_type
= 16;
1588 if (coex_dm
->cur_ps_tdma
== 5) {
1589 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1591 coex_dm
->tdma_adj_type
= 6;
1592 } else if (coex_dm
->cur_ps_tdma
== 6) {
1593 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1595 coex_dm
->tdma_adj_type
= 7;
1596 } else if (coex_dm
->cur_ps_tdma
== 7) {
1597 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1599 coex_dm
->tdma_adj_type
= 8;
1600 } else if (coex_dm
->cur_ps_tdma
== 13) {
1601 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1603 coex_dm
->tdma_adj_type
= 14;
1604 } else if (coex_dm
->cur_ps_tdma
== 14) {
1605 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1607 coex_dm
->tdma_adj_type
= 15;
1608 } else if (coex_dm
->cur_ps_tdma
== 15) {
1609 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1611 coex_dm
->tdma_adj_type
= 16;
1613 } else if (result
== 1) {
1614 if (coex_dm
->cur_ps_tdma
== 8) {
1615 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1617 coex_dm
->tdma_adj_type
= 7;
1618 } else if (coex_dm
->cur_ps_tdma
== 7) {
1619 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1621 coex_dm
->tdma_adj_type
= 6;
1622 } else if (coex_dm
->cur_ps_tdma
== 6) {
1623 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1625 coex_dm
->tdma_adj_type
= 5;
1626 } else if (coex_dm
->cur_ps_tdma
== 16) {
1627 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1629 coex_dm
->tdma_adj_type
= 15;
1630 } else if (coex_dm
->cur_ps_tdma
== 15) {
1631 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1633 coex_dm
->tdma_adj_type
= 14;
1634 } else if (coex_dm
->cur_ps_tdma
== 14) {
1635 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1637 coex_dm
->tdma_adj_type
= 13;
1641 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1642 "[BTCoex], TxPause = 0\n");
1643 if (coex_dm
->cur_ps_tdma
== 5) {
1644 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 71);
1645 coex_dm
->tdma_adj_type
= 71;
1646 } else if (coex_dm
->cur_ps_tdma
== 6) {
1647 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 2);
1648 coex_dm
->tdma_adj_type
= 2;
1649 } else if (coex_dm
->cur_ps_tdma
== 7) {
1650 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1651 coex_dm
->tdma_adj_type
= 3;
1652 } else if (coex_dm
->cur_ps_tdma
== 8) {
1653 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 4);
1654 coex_dm
->tdma_adj_type
= 4;
1657 if (coex_dm
->cur_ps_tdma
== 13) {
1658 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 9);
1659 coex_dm
->tdma_adj_type
= 9;
1660 } else if (coex_dm
->cur_ps_tdma
== 14) {
1661 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 10);
1662 coex_dm
->tdma_adj_type
= 10;
1663 } else if (coex_dm
->cur_ps_tdma
== 15) {
1664 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
1665 coex_dm
->tdma_adj_type
= 11;
1666 } else if (coex_dm
->cur_ps_tdma
== 16) {
1667 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 12);
1668 coex_dm
->tdma_adj_type
= 12;
1672 if (coex_dm
->cur_ps_tdma
== 71) {
1673 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1675 coex_dm
->tdma_adj_type
= 1;
1676 } else if (coex_dm
->cur_ps_tdma
== 1) {
1677 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1679 coex_dm
->tdma_adj_type
= 2;
1680 } else if (coex_dm
->cur_ps_tdma
== 2) {
1681 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1683 coex_dm
->tdma_adj_type
= 3;
1684 } else if (coex_dm
->cur_ps_tdma
== 3) {
1685 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1687 coex_dm
->tdma_adj_type
= 4;
1688 } else if (coex_dm
->cur_ps_tdma
== 9) {
1689 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1691 coex_dm
->tdma_adj_type
= 10;
1692 } else if (coex_dm
->cur_ps_tdma
== 10) {
1693 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1695 coex_dm
->tdma_adj_type
= 11;
1696 } else if (coex_dm
->cur_ps_tdma
== 11) {
1697 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1699 coex_dm
->tdma_adj_type
= 12;
1701 } else if (result
== 1) {
1702 if (coex_dm
->cur_ps_tdma
== 4) {
1703 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1705 coex_dm
->tdma_adj_type
= 3;
1706 } else if (coex_dm
->cur_ps_tdma
== 3) {
1707 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1709 coex_dm
->tdma_adj_type
= 2;
1710 } else if (coex_dm
->cur_ps_tdma
== 2) {
1711 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1713 coex_dm
->tdma_adj_type
= 1;
1714 } else if (coex_dm
->cur_ps_tdma
== 1) {
1715 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1717 coex_dm
->tdma_adj_type
= 71;
1718 } else if (coex_dm
->cur_ps_tdma
== 12) {
1719 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1721 coex_dm
->tdma_adj_type
= 11;
1722 } else if (coex_dm
->cur_ps_tdma
== 11) {
1723 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1725 coex_dm
->tdma_adj_type
= 10;
1726 } else if (coex_dm
->cur_ps_tdma
== 10) {
1727 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1729 coex_dm
->tdma_adj_type
= 9;
1735 static void set_tdma_int2(struct btc_coexist
*btcoexist
, bool tx_pause
,
1738 /* Set PS TDMA for max interval == 2 */
1740 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1741 "[BTCoex], TxPause = 1\n");
1742 if (coex_dm
->cur_ps_tdma
== 1) {
1743 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 6);
1744 coex_dm
->tdma_adj_type
= 6;
1745 } else if (coex_dm
->cur_ps_tdma
== 2) {
1746 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 6);
1747 coex_dm
->tdma_adj_type
= 6;
1748 } else if (coex_dm
->cur_ps_tdma
== 3) {
1749 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 7);
1750 coex_dm
->tdma_adj_type
= 7;
1751 } else if (coex_dm
->cur_ps_tdma
== 4) {
1752 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 8);
1753 coex_dm
->tdma_adj_type
= 8;
1755 if (coex_dm
->cur_ps_tdma
== 9) {
1756 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1757 coex_dm
->tdma_adj_type
= 14;
1758 } else if (coex_dm
->cur_ps_tdma
== 10) {
1759 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1760 coex_dm
->tdma_adj_type
= 14;
1761 } else if (coex_dm
->cur_ps_tdma
== 11) {
1762 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 15);
1763 coex_dm
->tdma_adj_type
= 15;
1764 } else if (coex_dm
->cur_ps_tdma
== 12) {
1765 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 16);
1766 coex_dm
->tdma_adj_type
= 16;
1769 if (coex_dm
->cur_ps_tdma
== 5) {
1770 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1772 coex_dm
->tdma_adj_type
= 6;
1773 } else if (coex_dm
->cur_ps_tdma
== 6) {
1774 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1776 coex_dm
->tdma_adj_type
= 7;
1777 } else if (coex_dm
->cur_ps_tdma
== 7) {
1778 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1780 coex_dm
->tdma_adj_type
= 8;
1781 } else if (coex_dm
->cur_ps_tdma
== 13) {
1782 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1784 coex_dm
->tdma_adj_type
= 14;
1785 } else if (coex_dm
->cur_ps_tdma
== 14) {
1786 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1788 coex_dm
->tdma_adj_type
= 15;
1789 } else if (coex_dm
->cur_ps_tdma
== 15) {
1790 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1792 coex_dm
->tdma_adj_type
= 16;
1794 } else if (result
== 1) {
1795 if (coex_dm
->cur_ps_tdma
== 8) {
1796 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1798 coex_dm
->tdma_adj_type
= 7;
1799 } else if (coex_dm
->cur_ps_tdma
== 7) {
1800 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1802 coex_dm
->tdma_adj_type
= 6;
1803 } else if (coex_dm
->cur_ps_tdma
== 6) {
1804 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1806 coex_dm
->tdma_adj_type
= 6;
1807 } else if (coex_dm
->cur_ps_tdma
== 16) {
1808 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1810 coex_dm
->tdma_adj_type
= 15;
1811 } else if (coex_dm
->cur_ps_tdma
== 15) {
1812 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1814 coex_dm
->tdma_adj_type
= 14;
1815 } else if (coex_dm
->cur_ps_tdma
== 14) {
1816 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1818 coex_dm
->tdma_adj_type
= 14;
1822 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1823 "[BTCoex], TxPause = 0\n");
1824 if (coex_dm
->cur_ps_tdma
== 5) {
1825 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 2);
1826 coex_dm
->tdma_adj_type
= 2;
1827 } else if (coex_dm
->cur_ps_tdma
== 6) {
1828 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 2);
1829 coex_dm
->tdma_adj_type
= 2;
1830 } else if (coex_dm
->cur_ps_tdma
== 7) {
1831 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1832 coex_dm
->tdma_adj_type
= 3;
1833 } else if (coex_dm
->cur_ps_tdma
== 8) {
1834 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 4);
1835 coex_dm
->tdma_adj_type
= 4;
1837 if (coex_dm
->cur_ps_tdma
== 13) {
1838 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 10);
1839 coex_dm
->tdma_adj_type
= 10;
1840 } else if (coex_dm
->cur_ps_tdma
== 14) {
1841 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 10);
1842 coex_dm
->tdma_adj_type
= 10;
1843 } else if (coex_dm
->cur_ps_tdma
== 15) {
1844 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
1845 coex_dm
->tdma_adj_type
= 11;
1846 } else if (coex_dm
->cur_ps_tdma
== 16) {
1847 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 12);
1848 coex_dm
->tdma_adj_type
= 12;
1851 if (coex_dm
->cur_ps_tdma
== 1) {
1852 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1854 coex_dm
->tdma_adj_type
= 2;
1855 } else if (coex_dm
->cur_ps_tdma
== 2) {
1856 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1858 coex_dm
->tdma_adj_type
= 3;
1859 } else if (coex_dm
->cur_ps_tdma
== 3) {
1860 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1862 coex_dm
->tdma_adj_type
= 4;
1863 } else if (coex_dm
->cur_ps_tdma
== 9) {
1864 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1866 coex_dm
->tdma_adj_type
= 10;
1867 } else if (coex_dm
->cur_ps_tdma
== 10) {
1868 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1870 coex_dm
->tdma_adj_type
= 11;
1871 } else if (coex_dm
->cur_ps_tdma
== 11) {
1872 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1874 coex_dm
->tdma_adj_type
= 12;
1876 } else if (result
== 1) {
1877 if (coex_dm
->cur_ps_tdma
== 4) {
1878 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1880 coex_dm
->tdma_adj_type
= 3;
1881 } else if (coex_dm
->cur_ps_tdma
== 3) {
1882 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1884 coex_dm
->tdma_adj_type
= 2;
1885 } else if (coex_dm
->cur_ps_tdma
== 2) {
1886 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1888 coex_dm
->tdma_adj_type
= 2;
1889 } else if (coex_dm
->cur_ps_tdma
== 12) {
1890 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1892 coex_dm
->tdma_adj_type
= 11;
1893 } else if (coex_dm
->cur_ps_tdma
== 11) {
1894 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1896 coex_dm
->tdma_adj_type
= 10;
1897 } else if (coex_dm
->cur_ps_tdma
== 10) {
1898 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1900 coex_dm
->tdma_adj_type
= 10;
1906 static void set_tdma_int3(struct btc_coexist
*btcoexist
, bool tx_pause
,
1909 /* Set PS TDMA for max interval == 3 */
1911 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1912 "[BTCoex], TxPause = 1\n");
1913 if (coex_dm
->cur_ps_tdma
== 1) {
1914 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 7);
1915 coex_dm
->tdma_adj_type
= 7;
1916 } else if (coex_dm
->cur_ps_tdma
== 2) {
1917 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 7);
1918 coex_dm
->tdma_adj_type
= 7;
1919 } else if (coex_dm
->cur_ps_tdma
== 3) {
1920 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 7);
1921 coex_dm
->tdma_adj_type
= 7;
1922 } else if (coex_dm
->cur_ps_tdma
== 4) {
1923 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 8);
1924 coex_dm
->tdma_adj_type
= 8;
1926 if (coex_dm
->cur_ps_tdma
== 9) {
1927 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 15);
1928 coex_dm
->tdma_adj_type
= 15;
1929 } else if (coex_dm
->cur_ps_tdma
== 10) {
1930 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 15);
1931 coex_dm
->tdma_adj_type
= 15;
1932 } else if (coex_dm
->cur_ps_tdma
== 11) {
1933 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 15);
1934 coex_dm
->tdma_adj_type
= 15;
1935 } else if (coex_dm
->cur_ps_tdma
== 12) {
1936 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 16);
1937 coex_dm
->tdma_adj_type
= 16;
1940 if (coex_dm
->cur_ps_tdma
== 5) {
1941 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1943 coex_dm
->tdma_adj_type
= 7;
1944 } else if (coex_dm
->cur_ps_tdma
== 6) {
1945 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1947 coex_dm
->tdma_adj_type
= 7;
1948 } else if (coex_dm
->cur_ps_tdma
== 7) {
1949 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1951 coex_dm
->tdma_adj_type
= 8;
1952 } else if (coex_dm
->cur_ps_tdma
== 13) {
1953 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1955 coex_dm
->tdma_adj_type
= 15;
1956 } else if (coex_dm
->cur_ps_tdma
== 14) {
1957 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1959 coex_dm
->tdma_adj_type
= 15;
1960 } else if (coex_dm
->cur_ps_tdma
== 15) {
1961 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1963 coex_dm
->tdma_adj_type
= 16;
1965 } else if (result
== 1) {
1966 if (coex_dm
->cur_ps_tdma
== 8) {
1967 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1969 coex_dm
->tdma_adj_type
= 7;
1970 } else if (coex_dm
->cur_ps_tdma
== 7) {
1971 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1973 coex_dm
->tdma_adj_type
= 7;
1974 } else if (coex_dm
->cur_ps_tdma
== 6) {
1975 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1977 coex_dm
->tdma_adj_type
= 7;
1978 } else if (coex_dm
->cur_ps_tdma
== 16) {
1979 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1981 coex_dm
->tdma_adj_type
= 15;
1982 } else if (coex_dm
->cur_ps_tdma
== 15) {
1983 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1985 coex_dm
->tdma_adj_type
= 15;
1986 } else if (coex_dm
->cur_ps_tdma
== 14) {
1987 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1989 coex_dm
->tdma_adj_type
= 15;
1993 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
1994 "[BTCoex], TxPause = 0\n");
1995 if (coex_dm
->cur_ps_tdma
== 5) {
1996 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1997 coex_dm
->tdma_adj_type
= 3;
1998 } else if (coex_dm
->cur_ps_tdma
== 6) {
1999 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
2000 coex_dm
->tdma_adj_type
= 3;
2001 } else if (coex_dm
->cur_ps_tdma
== 7) {
2002 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
2003 coex_dm
->tdma_adj_type
= 3;
2004 } else if (coex_dm
->cur_ps_tdma
== 8) {
2005 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 4);
2006 coex_dm
->tdma_adj_type
= 4;
2008 if (coex_dm
->cur_ps_tdma
== 13) {
2009 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
2010 coex_dm
->tdma_adj_type
= 11;
2011 } else if (coex_dm
->cur_ps_tdma
== 14) {
2012 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
2013 coex_dm
->tdma_adj_type
= 11;
2014 } else if (coex_dm
->cur_ps_tdma
== 15) {
2015 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
2016 coex_dm
->tdma_adj_type
= 11;
2017 } else if (coex_dm
->cur_ps_tdma
== 16) {
2018 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 12);
2019 coex_dm
->tdma_adj_type
= 12;
2022 if (coex_dm
->cur_ps_tdma
== 1) {
2023 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2025 coex_dm
->tdma_adj_type
= 3;
2026 } else if (coex_dm
->cur_ps_tdma
== 2) {
2027 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2029 coex_dm
->tdma_adj_type
= 3;
2030 } else if (coex_dm
->cur_ps_tdma
== 3) {
2031 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2033 coex_dm
->tdma_adj_type
= 4;
2034 } else if (coex_dm
->cur_ps_tdma
== 9) {
2035 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2037 coex_dm
->tdma_adj_type
= 11;
2038 } else if (coex_dm
->cur_ps_tdma
== 10) {
2039 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2041 coex_dm
->tdma_adj_type
= 11;
2042 } else if (coex_dm
->cur_ps_tdma
== 11) {
2043 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2045 coex_dm
->tdma_adj_type
= 12;
2047 } else if (result
== 1) {
2048 if (coex_dm
->cur_ps_tdma
== 4) {
2049 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2051 coex_dm
->tdma_adj_type
= 3;
2052 } else if (coex_dm
->cur_ps_tdma
== 3) {
2053 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2055 coex_dm
->tdma_adj_type
= 3;
2056 } else if (coex_dm
->cur_ps_tdma
== 2) {
2057 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2059 coex_dm
->tdma_adj_type
= 3;
2060 } else if (coex_dm
->cur_ps_tdma
== 12) {
2061 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2063 coex_dm
->tdma_adj_type
= 11;
2064 } else if (coex_dm
->cur_ps_tdma
== 11) {
2065 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2067 coex_dm
->tdma_adj_type
= 11;
2068 } else if (coex_dm
->cur_ps_tdma
== 10) {
2069 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2071 coex_dm
->tdma_adj_type
= 11;
2077 static void btc8723b2ant_tdma_duration_adjust(struct btc_coexist
*btcoexist
,
2078 bool sco_hid
, bool tx_pause
,
2081 static s32 up
, dn
, m
, n
, wait_count
;
2082 /*0: no change, +1: increase WiFi duration, -1: decrease WiFi duration*/
2086 btc_alg_dbg(ALGO_TRACE_FW
,
2087 "[BTCoex], TdmaDurationAdjust()\n");
2089 if (!coex_dm
->auto_tdma_adjust
) {
2090 coex_dm
->auto_tdma_adjust
= true;
2091 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2092 "[BTCoex], first run TdmaDurationAdjust()!!\n");
2095 if (max_interval
== 1) {
2096 btc8723b2ant_ps_tdma(btcoexist
,
2099 coex_dm
->tdma_adj_type
= 13;
2100 } else if (max_interval
== 2) {
2101 btc8723b2ant_ps_tdma(btcoexist
,
2104 coex_dm
->tdma_adj_type
= 14;
2105 } else if (max_interval
== 3) {
2106 btc8723b2ant_ps_tdma(btcoexist
,
2109 coex_dm
->tdma_adj_type
= 15;
2111 btc8723b2ant_ps_tdma(btcoexist
,
2114 coex_dm
->tdma_adj_type
= 15;
2117 if (max_interval
== 1) {
2118 btc8723b2ant_ps_tdma(btcoexist
,
2121 coex_dm
->tdma_adj_type
= 9;
2122 } else if (max_interval
== 2) {
2123 btc8723b2ant_ps_tdma(btcoexist
,
2126 coex_dm
->tdma_adj_type
= 10;
2127 } else if (max_interval
== 3) {
2128 btc8723b2ant_ps_tdma(btcoexist
,
2131 coex_dm
->tdma_adj_type
= 11;
2133 btc8723b2ant_ps_tdma(btcoexist
,
2136 coex_dm
->tdma_adj_type
= 11;
2141 if (max_interval
== 1) {
2142 btc8723b2ant_ps_tdma(btcoexist
,
2145 coex_dm
->tdma_adj_type
= 5;
2146 } else if (max_interval
== 2) {
2147 btc8723b2ant_ps_tdma(btcoexist
,
2150 coex_dm
->tdma_adj_type
= 6;
2151 } else if (max_interval
== 3) {
2152 btc8723b2ant_ps_tdma(btcoexist
,
2155 coex_dm
->tdma_adj_type
= 7;
2157 btc8723b2ant_ps_tdma(btcoexist
,
2160 coex_dm
->tdma_adj_type
= 7;
2163 if (max_interval
== 1) {
2164 btc8723b2ant_ps_tdma(btcoexist
,
2167 coex_dm
->tdma_adj_type
= 1;
2168 } else if (max_interval
== 2) {
2169 btc8723b2ant_ps_tdma(btcoexist
,
2172 coex_dm
->tdma_adj_type
= 2;
2173 } else if (max_interval
== 3) {
2174 btc8723b2ant_ps_tdma(btcoexist
,
2177 coex_dm
->tdma_adj_type
= 3;
2179 btc8723b2ant_ps_tdma(btcoexist
,
2182 coex_dm
->tdma_adj_type
= 3;
2194 /*accquire the BT TRx retry count from BT_Info byte2*/
2195 retry_count
= coex_sta
->bt_retry_cnt
;
2196 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2197 "[BTCoex], retry_count = %d\n", retry_count
);
2198 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2199 "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n",
2200 up
, dn
, m
, n
, wait_count
);
2203 /* no retry in the last 2-second duration*/
2204 if (retry_count
== 0) {
2217 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2218 "[BTCoex], Increase wifi duration!!\n");
2219 } /* <=3 retry in the last 2-second duration*/
2220 } else if (retry_count
<= 3) {
2228 if (wait_count
<= 2)
2241 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2242 "[BTCoex], Decrease wifi duration for retry_counter<3!!\n");
2245 if (wait_count
== 1)
2258 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2259 "[BTCoex], Decrease wifi duration for retry_counter>3!!\n");
2262 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2263 "[BTCoex], max Interval = %d\n", max_interval
);
2264 if (max_interval
== 1)
2265 set_tdma_int1(btcoexist
, tx_pause
, result
);
2266 else if (max_interval
== 2)
2267 set_tdma_int2(btcoexist
, tx_pause
, result
);
2268 else if (max_interval
== 3)
2269 set_tdma_int3(btcoexist
, tx_pause
, result
);
2272 /*if current PsTdma not match with the recorded one (when scan, dhcp..),
2273 *then we have to adjust it back to the previous recorded one.
2275 if (coex_dm
->cur_ps_tdma
!= coex_dm
->tdma_adj_type
) {
2276 bool scan
= false, link
= false, roam
= false;
2277 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2278 "[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n",
2279 coex_dm
->cur_ps_tdma
, coex_dm
->tdma_adj_type
);
2281 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2282 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2283 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2285 if (!scan
&& !link
&& !roam
)
2286 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
2287 coex_dm
->tdma_adj_type
);
2289 btc_alg_dbg(ALGO_TRACE_FW_DETAIL
,
2290 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2294 /* SCO only or SCO+PAN(HS) */
2295 static void btc8723b2ant_action_sco(struct btc_coexist
*btcoexist
)
2300 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2303 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2305 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 4);
2307 if (btc8723b_need_dec_pwr(btcoexist
))
2308 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2310 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2312 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2314 /*for SCO quality at 11b/g mode*/
2315 if (BTC_WIFI_BW_LEGACY
== wifi_bw
)
2316 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 2);
2317 else /*for SCO quality & wifi performance balance at 11n mode*/
2318 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 8);
2320 /*for voice quality */
2321 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2324 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2325 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2326 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2327 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2329 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2332 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2334 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2338 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2339 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2340 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2342 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2345 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2347 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2353 static void btc8723b2ant_action_hid(struct btc_coexist
*btcoexist
)
2355 u8 wifi_rssi_state
, bt_rssi_state
;
2358 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2360 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2362 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2364 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2366 if (btc8723b_need_dec_pwr(btcoexist
))
2367 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2369 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2371 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2373 if (BTC_WIFI_BW_LEGACY
== wifi_bw
) /*/for HID at 11b/g mode*/
2374 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2375 else /*for HID quality & wifi performance balance at 11n mode*/
2376 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 9);
2378 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2379 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2380 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 9);
2382 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 13);
2385 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2386 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2387 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2388 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2390 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2393 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2395 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2399 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2400 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2401 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2403 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2406 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2408 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2414 /*A2DP only / PAN(EDR) only/ A2DP+PAN(HS)*/
2415 static void btc8723b2ant_action_a2dp(struct btc_coexist
*btcoexist
)
2417 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2421 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2423 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2425 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2427 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
, &ap_num
);
2429 /* define the office environment */
2430 /* driver don't know AP num in Linux, so we will never enter this if */
2431 if (ap_num
>= 10 && BTC_RSSI_HIGH(wifi_rssi_state1
)) {
2432 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
2434 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2435 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2436 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 0);
2437 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
2440 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2441 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2442 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2444 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2447 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2449 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2455 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2457 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2459 if (btc8723b_need_dec_pwr(btcoexist
))
2460 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2462 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2464 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2466 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2467 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2468 btc8723b2ant_tdma_duration_adjust(btcoexist
, false,
2471 btc8723b2ant_tdma_duration_adjust(btcoexist
, false, true, 1);
2474 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2475 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2476 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2477 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2478 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2480 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2483 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2485 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2489 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2490 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2491 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2493 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2496 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2498 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2504 static void btc8723b2ant_action_a2dp_pan_hs(struct btc_coexist
*btcoexist
)
2509 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2512 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2514 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2516 if (btc8723b_need_dec_pwr(btcoexist
))
2517 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2519 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2521 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2523 btc8723b2ant_tdma_duration_adjust(btcoexist
, false, true, 2);
2526 btcoexist
->btc_get(btcoexist
,
2527 BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2528 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2529 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2530 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2531 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2533 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2536 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2538 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2542 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2543 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2544 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2546 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2549 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2551 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2557 static void btc8723b2ant_action_pan_edr(struct btc_coexist
*btcoexist
)
2559 u8 wifi_rssi_state
, bt_rssi_state
;
2562 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2564 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2566 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2568 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2570 if (btc8723b_need_dec_pwr(btcoexist
))
2571 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2573 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2575 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 10);
2577 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2578 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2579 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 1);
2581 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
2584 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2585 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2586 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2587 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2588 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2590 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2593 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2595 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2599 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2600 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2601 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2603 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2606 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2608 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2615 static void btc8723b2ant_action_pan_hs(struct btc_coexist
*btcoexist
)
2620 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2623 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2625 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2627 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2628 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2629 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2631 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2633 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2635 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
2637 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2638 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2639 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2640 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2641 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2643 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2646 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2648 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2652 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2653 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2654 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2656 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2659 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2661 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2668 static void btc8723b2ant_action_pan_edr_a2dp(struct btc_coexist
*btcoexist
)
2670 u8 wifi_rssi_state
, bt_rssi_state
;
2673 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2675 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2677 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2679 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2681 if (btc8723b_need_dec_pwr(btcoexist
))
2682 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2684 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2686 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2688 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2689 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2690 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 12);
2691 if (BTC_WIFI_BW_HT40
== wifi_bw
)
2692 btc8723b2ant_tdma_duration_adjust(btcoexist
, false,
2695 btc8723b2ant_tdma_duration_adjust(btcoexist
, false,
2698 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2699 btc8723b2ant_tdma_duration_adjust(btcoexist
, false, true, 3);
2703 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2704 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2705 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2706 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2708 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2711 btc8723b2ant_sw_mechanism1(btcoexist
, true, false,
2713 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2717 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2718 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2719 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2721 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2724 btc8723b2ant_sw_mechanism1(btcoexist
, false, false,
2726 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2732 static void btc8723b2ant_action_pan_edr_hid(struct btc_coexist
*btcoexist
)
2734 u8 wifi_rssi_state
, bt_rssi_state
;
2737 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2739 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2740 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2742 if (btc8723b_need_dec_pwr(btcoexist
))
2743 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2745 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2747 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2748 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2749 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2750 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
2752 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 11);
2753 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
2756 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
2758 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2759 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
2762 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, false, 2);
2764 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2765 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 11);
2766 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
2768 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, true, 2);
2772 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2773 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2774 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2775 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2777 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2780 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2782 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2786 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2787 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2788 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2790 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2793 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2795 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2801 /* HID+A2DP+PAN(EDR) */
2802 static void btc8723b2ant_action_hid_a2dp_pan_edr(struct btc_coexist
*btcoexist
)
2804 u8 wifi_rssi_state
, bt_rssi_state
;
2807 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2809 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2811 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2813 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2815 if (btc8723b_need_dec_pwr(btcoexist
))
2816 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2818 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2820 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2822 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2824 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2825 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2826 if (BTC_WIFI_BW_HT40
== wifi_bw
)
2827 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
2830 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
2833 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, true, 3);
2837 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2838 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2839 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2840 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2842 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2845 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2847 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2851 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2852 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2853 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2855 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2858 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2860 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2866 static void btc8723b2ant_action_hid_a2dp(struct btc_coexist
*btcoexist
)
2868 u8 wifi_rssi_state
, bt_rssi_state
;
2871 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
,
2873 bt_rssi_state
= btc8723b2ant_bt_rssi_state(2, 29, 0);
2875 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2877 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2879 if (btc8723b_need_dec_pwr(btcoexist
))
2880 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2882 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2884 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2886 btc8723b_coex_tbl_type(btcoexist
, NORMAL_EXEC
, 7);
2888 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2889 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2890 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, false, 2);
2892 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, true, 2);
2895 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2896 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2897 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2898 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2900 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2903 btc8723b2ant_sw_mechanism1(btcoexist
, true, true,
2905 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2909 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2910 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2911 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2913 btc8723b2ant_sw_mechanism2(btcoexist
, true, false,
2916 btc8723b2ant_sw_mechanism1(btcoexist
, false, true,
2918 btc8723b2ant_sw_mechanism2(btcoexist
, false, false,
2924 static void btc8723b2ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
2928 btc_alg_dbg(ALGO_TRACE
,
2929 "[BTCoex], RunCoexistMechanism()===>\n");
2931 if (btcoexist
->manual_control
) {
2932 btc_alg_dbg(ALGO_TRACE
,
2933 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2937 if (coex_sta
->under_ips
) {
2938 btc_alg_dbg(ALGO_TRACE
,
2939 "[BTCoex], wifi is under IPS !!!\n");
2943 algorithm
= btc8723b2ant_action_algorithm(btcoexist
);
2944 if (coex_sta
->c2h_bt_inquiry_page
&&
2945 (BT_8723B_2ANT_COEX_ALGO_PANHS
!= algorithm
)) {
2946 btc_alg_dbg(ALGO_TRACE
,
2947 "[BTCoex], BT is under inquiry/page scan !!\n");
2948 btc8723b2ant_action_bt_inquiry(btcoexist
);
2951 if (coex_dm
->need_recover_0x948
) {
2952 coex_dm
->need_recover_0x948
= false;
2953 btcoexist
->btc_write_2byte(btcoexist
, 0x948,
2954 coex_dm
->backup_0x948
);
2958 coex_dm
->cur_algorithm
= algorithm
;
2959 btc_alg_dbg(ALGO_TRACE
, "[BTCoex], Algorithm = %d\n",
2960 coex_dm
->cur_algorithm
);
2962 if (btc8723b2ant_is_common_action(btcoexist
)) {
2963 btc_alg_dbg(ALGO_TRACE
,
2964 "[BTCoex], Action 2-Ant common\n");
2965 coex_dm
->auto_tdma_adjust
= false;
2967 if (coex_dm
->cur_algorithm
!= coex_dm
->pre_algorithm
) {
2968 btc_alg_dbg(ALGO_TRACE
,
2969 "[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n",
2970 coex_dm
->pre_algorithm
,
2971 coex_dm
->cur_algorithm
);
2972 coex_dm
->auto_tdma_adjust
= false;
2974 switch (coex_dm
->cur_algorithm
) {
2975 case BT_8723B_2ANT_COEX_ALGO_SCO
:
2976 btc_alg_dbg(ALGO_TRACE
,
2977 "[BTCoex], Action 2-Ant, algorithm = SCO\n");
2978 btc8723b2ant_action_sco(btcoexist
);
2980 case BT_8723B_2ANT_COEX_ALGO_HID
:
2981 btc_alg_dbg(ALGO_TRACE
,
2982 "[BTCoex], Action 2-Ant, algorithm = HID\n");
2983 btc8723b2ant_action_hid(btcoexist
);
2985 case BT_8723B_2ANT_COEX_ALGO_A2DP
:
2986 btc_alg_dbg(ALGO_TRACE
,
2987 "[BTCoex], Action 2-Ant, algorithm = A2DP\n");
2988 btc8723b2ant_action_a2dp(btcoexist
);
2990 case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS
:
2991 btc_alg_dbg(ALGO_TRACE
,
2992 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
2993 btc8723b2ant_action_a2dp_pan_hs(btcoexist
);
2995 case BT_8723B_2ANT_COEX_ALGO_PANEDR
:
2996 btc_alg_dbg(ALGO_TRACE
,
2997 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
2998 btc8723b2ant_action_pan_edr(btcoexist
);
3000 case BT_8723B_2ANT_COEX_ALGO_PANHS
:
3001 btc_alg_dbg(ALGO_TRACE
,
3002 "[BTCoex], Action 2-Ant, algorithm = HS mode\n");
3003 btc8723b2ant_action_pan_hs(btcoexist
);
3005 case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP
:
3006 btc_alg_dbg(ALGO_TRACE
,
3007 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
3008 btc8723b2ant_action_pan_edr_a2dp(btcoexist
);
3010 case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
:
3011 btc_alg_dbg(ALGO_TRACE
,
3012 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3013 btc8723b2ant_action_pan_edr_hid(btcoexist
);
3015 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR
:
3016 btc_alg_dbg(ALGO_TRACE
,
3017 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3018 btc8723b2ant_action_hid_a2dp_pan_edr(btcoexist
);
3020 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP
:
3021 btc_alg_dbg(ALGO_TRACE
,
3022 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
3023 btc8723b2ant_action_hid_a2dp(btcoexist
);
3026 btc_alg_dbg(ALGO_TRACE
,
3027 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3028 btc8723b2ant_coex_alloff(btcoexist
);
3031 coex_dm
->pre_algorithm
= coex_dm
->cur_algorithm
;
3035 static void btc8723b2ant_wifioff_hwcfg(struct btc_coexist
*btcoexist
)
3037 /* set wlan_act to low */
3038 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
3039 /* Force GNT_BT to High */
3040 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x765, 0x18, 0x3);
3041 /* BT select s0/s1 is controlled by BT */
3042 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x0);
3045 /*********************************************************************
3046 * work around function start with wa_btc8723b2ant_
3047 *********************************************************************/
3048 /*********************************************************************
3049 * extern function start with EXbtc8723b2ant_
3050 *********************************************************************/
3051 void ex_btc8723b2ant_init_hwconfig(struct btc_coexist
*btcoexist
)
3055 btc_iface_dbg(INTF_INIT
,
3056 "[BTCoex], 2Ant Init HW Config!!\n");
3057 coex_dm
->bt_rf0x1e_backup
=
3058 btcoexist
->btc_get_rf_reg(btcoexist
, BTC_RF_A
, 0x1e, 0xfffff);
3060 /* 0x790[5:0] = 0x5 */
3061 u8tmp
= btcoexist
->btc_read_1byte(btcoexist
, 0x790);
3064 btcoexist
->btc_write_1byte(btcoexist
, 0x790, u8tmp
);
3067 btc8723b2ant_set_ant_path(btcoexist
, BTC_ANT_WIFI_AT_MAIN
,
3070 btc8723b_coex_tbl_type(btcoexist
, FORCE_EXEC
, 0);
3072 /* Enable counter statistics */
3073 /*0x76e[3] =1, WLAN_Act control by PTA*/
3074 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
3075 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x3);
3076 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
3079 void ex_btc8723b2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
3081 btc_iface_dbg(INTF_INIT
,
3082 "[BTCoex], Coex Mechanism Init!!\n");
3083 btc8723b2ant_init_coex_dm(btcoexist
);
3086 void ex_btc8723b2ant_display_coex_info(struct btc_coexist
*btcoexist
)
3088 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3089 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
3090 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
3091 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3092 u8 u8tmp
[4], i
, bt_info_ext
, ps_tdma_case
= 0;
3094 bool roam
= false, scan
= false;
3095 bool link
= false, wifi_under_5g
= false;
3096 bool bt_hs_on
= false, wifi_busy
= false;
3097 s32 wifi_rssi
= 0, bt_hs_rssi
= 0;
3098 u32 wifi_bw
, wifi_traffic_dir
, fa_ofdm
, fa_cck
;
3099 u8 wifi_dot11_chnl
, wifi_hs_chnl
;
3100 u32 fw_ver
= 0, bt_patch_ver
= 0;
3103 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3104 "\r\n ============[BT Coexist info]============");
3106 if (btcoexist
->manual_control
) {
3107 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3108 "\r\n ==========[Under Manual Control]============");
3109 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3110 "\r\n ==========================================");
3113 if (!board_info
->bt_exist
) {
3114 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n BT not exists !!!");
3118 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d ",
3119 "Ant PG number/ Ant mechanism:",
3120 board_info
->pg_ant_num
, board_info
->btdm_ant_num
);
3122 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s / %d",
3123 "BT stack/ hci ext ver",
3124 ((stack_info
->profile_notified
) ? "Yes" : "No"),
3125 stack_info
->hci_version
);
3127 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
3128 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3129 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3130 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
3131 "CoexVer/ FwVer/ PatchVer",
3132 glcoex_ver_date_8723b_2ant
, glcoex_ver_8723b_2ant
,
3133 fw_ver
, bt_patch_ver
, bt_patch_ver
);
3135 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
3136 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
,
3138 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
3140 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d / %d(%d)",
3141 "Dot11 channel / HsChnl(HsMode)",
3142 wifi_dot11_chnl
, wifi_hs_chnl
, bt_hs_on
);
3144 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %3ph ",
3145 "H2C Wifi inform bt chnl Info", coex_dm
->wifi_chnl_info
);
3147 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
3148 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
3149 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
, &ap_num
);
3150 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d",
3151 "Wifi rssi/ HS rssi/ AP#", wifi_rssi
, bt_hs_rssi
, ap_num
);
3153 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
3154 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
3155 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
3156 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d ",
3157 "Wifi link/ roam/ scan", link
, roam
, scan
);
3159 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
3160 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3161 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
3162 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
,
3164 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s / %s/ %s ",
3165 "Wifi status", (wifi_under_5g
? "5G" : "2.4G"),
3166 ((BTC_WIFI_BW_LEGACY
== wifi_bw
) ? "Legacy" :
3167 (((BTC_WIFI_BW_HT40
== wifi_bw
) ? "HT40" : "HT20"))),
3168 ((!wifi_busy
) ? "idle" :
3169 ((BTC_WIFI_TRAFFIC_TX
== wifi_traffic_dir
) ?
3170 "uplink" : "downlink")));
3173 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d / %d / %d / %d",
3175 bt_link_info
->sco_exist
, bt_link_info
->hid_exist
,
3176 bt_link_info
->pan_exist
, bt_link_info
->a2dp_exist
);
3177 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_BT_LINK_INFO
);
3179 bt_info_ext
= coex_sta
->bt_info_ext
;
3180 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s",
3181 "BT Info A2DP rate",
3182 (bt_info_ext
&BIT0
) ? "Basic rate" : "EDR rate");
3184 for (i
= 0; i
< BT_INFO_SRC_8723B_2ANT_MAX
; i
++) {
3185 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
3186 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3187 "\r\n %-35s = %7ph(%d)",
3188 glbt_info_src_8723b_2ant
[i
],
3189 coex_sta
->bt_info_c2h
[i
],
3190 coex_sta
->bt_info_c2h_cnt
[i
]);
3194 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s/%s",
3195 "PS state, IPS/LPS",
3196 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
3197 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")));
3198 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
);
3201 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3202 "\r\n %-35s", "============[Sw mechanism]============");
3203 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d ",
3204 "SM1[ShRf/ LpRA/ LimDig]", coex_dm
->cur_rf_rx_lpf_shrink
,
3205 coex_dm
->cur_low_penalty_ra
, coex_dm
->limited_dig
);
3206 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3207 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3208 coex_dm
->cur_agc_table_en
, coex_dm
->cur_adc_back_off
,
3209 coex_dm
->cur_dac_swing_on
, coex_dm
->cur_dac_swing_lvl
);
3212 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
3213 "============[Fw mechanism]============");
3215 ps_tdma_case
= coex_dm
->cur_ps_tdma
;
3216 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3217 "\r\n %-35s = %5ph case-%d (auto:%d)",
3218 "PS TDMA", coex_dm
->ps_tdma_para
,
3219 ps_tdma_case
, coex_dm
->auto_tdma_adjust
);
3221 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d ",
3222 "DecBtPwr/ IgnWlanAct", coex_dm
->cur_dec_bt_pwr
,
3223 coex_dm
->cur_ignore_wlan_act
);
3226 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
3227 "============[Hw setting]============");
3229 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x",
3230 "RF-A, 0x1e initVal", coex_dm
->bt_rf0x1e_backup
);
3232 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
3233 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x880);
3234 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
3235 "0x778/0x880[29:25]", u8tmp
[0],
3236 (u32tmp
[0]&0x3e000000) >> 25);
3238 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x948);
3239 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x67);
3240 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x765);
3241 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3242 "0x948/ 0x67[5] / 0x765",
3243 u32tmp
[0], ((u8tmp
[0]&0x20) >> 5), u8tmp
[1]);
3245 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x92c);
3246 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x930);
3247 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x944);
3248 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3249 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
3250 u32tmp
[0]&0x3, u32tmp
[1]&0xff, u32tmp
[2]&0x3);
3252 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x39);
3253 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
3254 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
3255 u8tmp
[2] = btcoexist
->btc_read_1byte(btcoexist
, 0x64);
3256 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3257 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3258 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
3259 ((u8tmp
[0] & 0x8)>>3), u8tmp
[1],
3260 ((u32tmp
[0]&0x01800000)>>23), u8tmp
[2]&0x1);
3262 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
3263 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
3264 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
3265 "0x550(bcn ctrl)/0x522", u32tmp
[0], u8tmp
[0]);
3267 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
3268 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x49c);
3269 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
3270 "0xc50(dig)/0x49c(null-drop)", u32tmp
[0]&0xff, u8tmp
[0]);
3272 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xda0);
3273 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0xda4);
3274 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0xda8);
3275 u32tmp
[3] = btcoexist
->btc_read_4byte(btcoexist
, 0xcf0);
3277 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
3278 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
3280 fa_ofdm
= ((u32tmp
[0]&0xffff0000) >> 16) +
3281 ((u32tmp
[1]&0xffff0000) >> 16) +
3282 (u32tmp
[1] & 0xffff) +
3283 (u32tmp
[2] & 0xffff) +
3284 ((u32tmp
[3]&0xffff0000) >> 16) +
3285 (u32tmp
[3] & 0xffff);
3286 fa_cck
= (u8tmp
[0] << 8) + u8tmp
[1];
3288 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3289 "OFDM-CCA/OFDM-FA/CCK-FA",
3290 u32tmp
[0]&0xffff, fa_ofdm
, fa_cck
);
3292 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
3293 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
3294 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
3295 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x6cc);
3296 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3297 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3298 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
3299 u32tmp
[0], u32tmp
[1], u32tmp
[2], u8tmp
[0]);
3301 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
3302 "0x770(high-pri rx/tx)",
3303 coex_sta
->high_priority_rx
, coex_sta
->high_priority_tx
);
3304 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
3305 "0x774(low-pri rx/tx)", coex_sta
->low_priority_rx
,
3306 coex_sta
->low_priority_tx
);
3307 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 1)
3308 btc8723b2ant_monitor_bt_ctr(btcoexist
);
3310 btcoexist
->btc_disp_dbg_msg(btcoexist
,
3311 BTC_DBG_DISP_COEX_STATISTICS
);
3314 void ex_btc8723b2ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
3316 if (BTC_IPS_ENTER
== type
) {
3317 btc_iface_dbg(INTF_NOTIFY
,
3318 "[BTCoex], IPS ENTER notify\n");
3319 coex_sta
->under_ips
= true;
3320 btc8723b2ant_wifioff_hwcfg(btcoexist
);
3321 btc8723b2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3322 btc8723b2ant_coex_alloff(btcoexist
);
3323 } else if (BTC_IPS_LEAVE
== type
) {
3324 btc_iface_dbg(INTF_NOTIFY
,
3325 "[BTCoex], IPS LEAVE notify\n");
3326 coex_sta
->under_ips
= false;
3327 ex_btc8723b2ant_init_hwconfig(btcoexist
);
3328 btc8723b2ant_init_coex_dm(btcoexist
);
3329 btc8723b2ant_query_bt_info(btcoexist
);
3333 void ex_btc8723b2ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
3335 if (BTC_LPS_ENABLE
== type
) {
3336 btc_iface_dbg(INTF_NOTIFY
,
3337 "[BTCoex], LPS ENABLE notify\n");
3338 coex_sta
->under_lps
= true;
3339 } else if (BTC_LPS_DISABLE
== type
) {
3340 btc_iface_dbg(INTF_NOTIFY
,
3341 "[BTCoex], LPS DISABLE notify\n");
3342 coex_sta
->under_lps
= false;
3346 void ex_btc8723b2ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
3348 if (BTC_SCAN_START
== type
)
3349 btc_iface_dbg(INTF_NOTIFY
,
3350 "[BTCoex], SCAN START notify\n");
3351 else if (BTC_SCAN_FINISH
== type
)
3352 btc_iface_dbg(INTF_NOTIFY
,
3353 "[BTCoex], SCAN FINISH notify\n");
3356 void ex_btc8723b2ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
3358 if (BTC_ASSOCIATE_START
== type
)
3359 btc_iface_dbg(INTF_NOTIFY
,
3360 "[BTCoex], CONNECT START notify\n");
3361 else if (BTC_ASSOCIATE_FINISH
== type
)
3362 btc_iface_dbg(INTF_NOTIFY
,
3363 "[BTCoex], CONNECT FINISH notify\n");
3366 void ex_btc8723b2ant_media_status_notify(struct btc_coexist
*btcoexist
,
3369 u8 h2c_parameter
[3] = {0};
3371 u8 wifi_central_chnl
;
3373 if (BTC_MEDIA_CONNECT
== type
)
3374 btc_iface_dbg(INTF_NOTIFY
,
3375 "[BTCoex], MEDIA connect notify\n");
3377 btc_iface_dbg(INTF_NOTIFY
,
3378 "[BTCoex], MEDIA disconnect notify\n");
3380 /* only 2.4G we need to inform bt the chnl mask */
3381 btcoexist
->btc_get(btcoexist
,
3382 BTC_GET_U1_WIFI_CENTRAL_CHNL
, &wifi_central_chnl
);
3383 if ((BTC_MEDIA_CONNECT
== type
) &&
3384 (wifi_central_chnl
<= 14)) {
3385 h2c_parameter
[0] = 0x1;
3386 h2c_parameter
[1] = wifi_central_chnl
;
3387 btcoexist
->btc_get(btcoexist
,
3388 BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3389 if (BTC_WIFI_BW_HT40
== wifi_bw
)
3390 h2c_parameter
[2] = 0x30;
3392 h2c_parameter
[2] = 0x20;
3395 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
3396 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
3397 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
3399 btc_alg_dbg(ALGO_TRACE_FW_EXEC
,
3400 "[BTCoex], FW write 0x66=0x%x\n",
3401 h2c_parameter
[0] << 16 | h2c_parameter
[1] << 8 |
3404 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
3407 void ex_btc8723b2ant_special_packet_notify(struct btc_coexist
*btcoexist
,
3410 if (type
== BTC_PACKET_DHCP
)
3411 btc_iface_dbg(INTF_NOTIFY
,
3412 "[BTCoex], DHCP Packet notify\n");
3415 void ex_btc8723b2ant_bt_info_notify(struct btc_coexist
*btcoexist
,
3416 u8
*tmpbuf
, u8 length
)
3419 u8 i
, rsp_source
= 0;
3420 bool bt_busy
= false, limited_dig
= false;
3421 bool wifi_connected
= false;
3423 coex_sta
->c2h_bt_info_req_sent
= false;
3425 rsp_source
= tmpbuf
[0]&0xf;
3426 if (rsp_source
>= BT_INFO_SRC_8723B_2ANT_MAX
)
3427 rsp_source
= BT_INFO_SRC_8723B_2ANT_WIFI_FW
;
3428 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
3430 btc_iface_dbg(INTF_NOTIFY
,
3431 "[BTCoex], Bt info[%d], length=%d, hex data=[",
3432 rsp_source
, length
);
3433 for (i
= 0; i
< length
; i
++) {
3434 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmpbuf
[i
];
3436 bt_info
= tmpbuf
[i
];
3438 btc_iface_dbg(INTF_NOTIFY
,
3439 "0x%02x]\n", tmpbuf
[i
]);
3441 btc_iface_dbg(INTF_NOTIFY
,
3442 "0x%02x, ", tmpbuf
[i
]);
3445 if (btcoexist
->manual_control
) {
3446 btc_alg_dbg(ALGO_TRACE
,
3447 "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
3451 if (BT_INFO_SRC_8723B_2ANT_WIFI_FW
!= rsp_source
) {
3452 coex_sta
->bt_retry_cnt
= /* [3:0]*/
3453 coex_sta
->bt_info_c2h
[rsp_source
][2] & 0xf;
3456 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 + 10;
3458 coex_sta
->bt_info_ext
=
3459 coex_sta
->bt_info_c2h
[rsp_source
][4];
3461 /* Here we need to resend some wifi info to BT
3462 because bt is reset and loss of the info.
3464 if ((coex_sta
->bt_info_ext
& BIT1
)) {
3465 btc_alg_dbg(ALGO_TRACE
,
3466 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3467 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
3470 ex_btc8723b2ant_media_status_notify(
3474 ex_btc8723b2ant_media_status_notify(
3476 BTC_MEDIA_DISCONNECT
);
3479 if ((coex_sta
->bt_info_ext
& BIT3
)) {
3480 btc_alg_dbg(ALGO_TRACE
,
3481 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
3482 btc8723b2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
,
3485 /* BT already NOT ignore Wlan active, do nothing here.*/
3487 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0)
3488 if ((coex_sta
->bt_info_ext
& BIT4
)) {
3489 /* BT auto report already enabled, do nothing*/
3491 btc8723b2ant_bt_auto_report(btcoexist
, FORCE_EXEC
,
3497 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
3498 if (bt_info
& BT_INFO_8723B_2ANT_B_INQ_PAGE
)
3499 coex_sta
->c2h_bt_inquiry_page
= true;
3501 coex_sta
->c2h_bt_inquiry_page
= false;
3503 /* set link exist status*/
3504 if (!(bt_info
& BT_INFO_8723B_2ANT_B_CONNECTION
)) {
3505 coex_sta
->bt_link_exist
= false;
3506 coex_sta
->pan_exist
= false;
3507 coex_sta
->a2dp_exist
= false;
3508 coex_sta
->hid_exist
= false;
3509 coex_sta
->sco_exist
= false;
3510 } else { /* connection exists */
3511 coex_sta
->bt_link_exist
= true;
3512 if (bt_info
& BT_INFO_8723B_2ANT_B_FTP
)
3513 coex_sta
->pan_exist
= true;
3515 coex_sta
->pan_exist
= false;
3516 if (bt_info
& BT_INFO_8723B_2ANT_B_A2DP
)
3517 coex_sta
->a2dp_exist
= true;
3519 coex_sta
->a2dp_exist
= false;
3520 if (bt_info
& BT_INFO_8723B_2ANT_B_HID
)
3521 coex_sta
->hid_exist
= true;
3523 coex_sta
->hid_exist
= false;
3524 if (bt_info
& BT_INFO_8723B_2ANT_B_SCO_ESCO
)
3525 coex_sta
->sco_exist
= true;
3527 coex_sta
->sco_exist
= false;
3530 btc8723b2ant_update_bt_link_info(btcoexist
);
3532 if (!(bt_info
& BT_INFO_8723B_2ANT_B_CONNECTION
)) {
3533 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE
;
3534 btc_alg_dbg(ALGO_TRACE
,
3535 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
3536 /* connection exists but no busy */
3537 } else if (bt_info
== BT_INFO_8723B_2ANT_B_CONNECTION
) {
3538 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE
;
3539 btc_alg_dbg(ALGO_TRACE
,
3540 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3541 } else if ((bt_info
& BT_INFO_8723B_2ANT_B_SCO_ESCO
) ||
3542 (bt_info
& BT_INFO_8723B_2ANT_B_SCO_BUSY
)) {
3543 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_SCO_BUSY
;
3544 btc_alg_dbg(ALGO_TRACE
,
3545 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3546 } else if (bt_info
&BT_INFO_8723B_2ANT_B_ACL_BUSY
) {
3547 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_ACL_BUSY
;
3548 btc_alg_dbg(ALGO_TRACE
,
3549 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3551 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_MAX
;
3552 btc_alg_dbg(ALGO_TRACE
,
3553 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
3556 if ((BT_8723B_2ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
3557 (BT_8723B_2ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
3558 (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
)) {
3563 limited_dig
= false;
3566 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
3568 coex_dm
->limited_dig
= limited_dig
;
3569 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_LIMITED_DIG
, &limited_dig
);
3571 btc8723b2ant_run_coexist_mechanism(btcoexist
);
3574 void ex_btc8723b2ant_halt_notify(struct btc_coexist
*btcoexist
)
3576 btc_iface_dbg(INTF_NOTIFY
, "[BTCoex], Halt notify\n");
3578 btc8723b2ant_wifioff_hwcfg(btcoexist
);
3579 btc8723b2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3580 ex_btc8723b2ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
3583 void ex_btc8723b2ant_periodical(struct btc_coexist
*btcoexist
)
3585 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3586 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
3587 static u8 dis_ver_info_cnt
;
3588 u32 fw_ver
= 0, bt_patch_ver
= 0;
3590 btc_alg_dbg(ALGO_TRACE
,
3591 "[BTCoex], ==========================Periodical===========================\n");
3593 if (dis_ver_info_cnt
<= 5) {
3594 dis_ver_info_cnt
+= 1;
3595 btc_iface_dbg(INTF_INIT
,
3596 "[BTCoex], ****************************************************************\n");
3597 btc_iface_dbg(INTF_INIT
,
3598 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
3599 board_info
->pg_ant_num
,
3600 board_info
->btdm_ant_num
,
3601 board_info
->btdm_ant_pos
);
3602 btc_iface_dbg(INTF_INIT
,
3603 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
3604 stack_info
->profile_notified
? "Yes" : "No",
3605 stack_info
->hci_version
);
3606 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
,
3608 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3609 btc_iface_dbg(INTF_INIT
,
3610 "[BTCoex], CoexVer/ fw_ver/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
3611 glcoex_ver_date_8723b_2ant
, glcoex_ver_8723b_2ant
,
3612 fw_ver
, bt_patch_ver
, bt_patch_ver
);
3613 btc_iface_dbg(INTF_INIT
,
3614 "[BTCoex], ****************************************************************\n");
3617 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0)
3618 btc8723b2ant_query_bt_info(btcoexist
);
3619 btc8723b2ant_monitor_bt_ctr(btcoexist
);
3620 btc8723b2ant_monitor_bt_enable_disable(btcoexist
);
3622 if (btc8723b2ant_is_wifi_status_changed(btcoexist
) ||
3623 coex_dm
->auto_tdma_adjust
)
3624 btc8723b2ant_run_coexist_mechanism(btcoexist
);