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 = 20130731;
53 static u32 glcoex_ver_8723b_2ant = 0x3b;
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_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
76 "[BTCoex], BT Rssi state "
79 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
80 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
81 "[BTCoex], BT Rssi state "
85 if (bt_rssi < rssi_thresh) {
86 bt_rssi_state = BTC_RSSI_STATE_LOW;
87 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
88 "[BTCoex], BT Rssi state "
91 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
92 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
93 "[BTCoex], BT Rssi state "
97 } else if (level_num == 3) {
98 if (rssi_thresh > rssi_thresh1) {
99 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
100 "[BTCoex], BT Rssi thresh error!!\n");
101 return coex_sta->pre_bt_rssi_state;
104 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
105 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
106 if (bt_rssi >= rssi_thresh +
107 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) {
108 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
109 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
110 "[BTCoex], BT Rssi state "
111 "switch to Medium\n");
113 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
114 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
115 "[BTCoex], BT Rssi state "
118 } else if ((coex_sta->pre_bt_rssi_state ==
119 BTC_RSSI_STATE_MEDIUM) ||
120 (coex_sta->pre_bt_rssi_state ==
121 BTC_RSSI_STATE_STAY_MEDIUM)) {
122 if (bt_rssi >= rssi_thresh1 +
123 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) {
124 bt_rssi_state = BTC_RSSI_STATE_HIGH;
125 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
126 "[BTCoex], BT Rssi state "
128 } else if (bt_rssi < rssi_thresh) {
129 bt_rssi_state = BTC_RSSI_STATE_LOW;
130 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
131 "[BTCoex], BT Rssi state "
134 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
135 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
136 "[BTCoex], BT Rssi state "
140 if (bt_rssi < rssi_thresh1) {
141 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
142 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
143 "[BTCoex], BT Rssi state "
144 "switch to Medium\n");
146 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
147 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
148 "[BTCoex], BT Rssi state "
154 coex_sta->pre_bt_rssi_state = bt_rssi_state;
156 return bt_rssi_state;
159 static u8 btc8723b2ant_wifi_rssi_state(struct btc_coexist *btcoexist,
160 u8 index, u8 level_num,
161 u8 rssi_thresh, u8 rssi_thresh1)
164 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
166 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
168 if (level_num == 2) {
169 if ((coex_sta->pre_wifi_rssi_state[index] ==
170 BTC_RSSI_STATE_LOW) ||
171 (coex_sta->pre_wifi_rssi_state[index] ==
172 BTC_RSSI_STATE_STAY_LOW)) {
173 if (wifi_rssi >= rssi_thresh +
174 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) {
175 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
176 BTC_PRINT(BTC_MSG_ALGORITHM,
177 ALGO_WIFI_RSSI_STATE,
178 "[BTCoex], wifi RSSI state "
181 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
182 BTC_PRINT(BTC_MSG_ALGORITHM,
183 ALGO_WIFI_RSSI_STATE,
184 "[BTCoex], wifi RSSI state "
188 if (wifi_rssi < rssi_thresh) {
189 wifi_rssi_state = BTC_RSSI_STATE_LOW;
190 BTC_PRINT(BTC_MSG_ALGORITHM,
191 ALGO_WIFI_RSSI_STATE,
192 "[BTCoex], wifi RSSI state "
195 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
196 BTC_PRINT(BTC_MSG_ALGORITHM,
197 ALGO_WIFI_RSSI_STATE,
198 "[BTCoex], wifi RSSI state "
202 } else if (level_num == 3) {
203 if (rssi_thresh > rssi_thresh1) {
204 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE,
205 "[BTCoex], wifi RSSI thresh error!!\n");
206 return coex_sta->pre_wifi_rssi_state[index];
209 if ((coex_sta->pre_wifi_rssi_state[index] ==
210 BTC_RSSI_STATE_LOW) ||
211 (coex_sta->pre_wifi_rssi_state[index] ==
212 BTC_RSSI_STATE_STAY_LOW)) {
213 if (wifi_rssi >= rssi_thresh +
214 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) {
215 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
216 BTC_PRINT(BTC_MSG_ALGORITHM,
217 ALGO_WIFI_RSSI_STATE,
218 "[BTCoex], wifi RSSI state "
219 "switch to Medium\n");
221 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
222 BTC_PRINT(BTC_MSG_ALGORITHM,
223 ALGO_WIFI_RSSI_STATE,
224 "[BTCoex], wifi RSSI state "
227 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
228 BTC_RSSI_STATE_MEDIUM) ||
229 (coex_sta->pre_wifi_rssi_state[index] ==
230 BTC_RSSI_STATE_STAY_MEDIUM)) {
231 if (wifi_rssi >= rssi_thresh1 +
232 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) {
233 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
234 BTC_PRINT(BTC_MSG_ALGORITHM,
235 ALGO_WIFI_RSSI_STATE,
236 "[BTCoex], wifi RSSI state "
238 } else if (wifi_rssi < rssi_thresh) {
239 wifi_rssi_state = BTC_RSSI_STATE_LOW;
240 BTC_PRINT(BTC_MSG_ALGORITHM,
241 ALGO_WIFI_RSSI_STATE,
242 "[BTCoex], wifi RSSI state "
245 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
246 BTC_PRINT(BTC_MSG_ALGORITHM,
247 ALGO_WIFI_RSSI_STATE,
248 "[BTCoex], wifi RSSI state "
252 if (wifi_rssi < rssi_thresh1) {
253 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
254 BTC_PRINT(BTC_MSG_ALGORITHM,
255 ALGO_WIFI_RSSI_STATE,
256 "[BTCoex], wifi RSSI state "
257 "switch to Medium\n");
259 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
260 BTC_PRINT(BTC_MSG_ALGORITHM,
261 ALGO_WIFI_RSSI_STATE,
262 "[BTCoex], wifi RSSI state "
268 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
270 return wifi_rssi_state;
273 static void btc8723b2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
275 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
276 u32 reg_hp_tx = 0, reg_hp_rx = 0;
277 u32 reg_lp_tx = 0, reg_lp_rx = 0;
282 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
283 reg_hp_tx = u32tmp & MASKLWORD;
284 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
286 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
287 reg_lp_tx = u32tmp & MASKLWORD;
288 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
290 coex_sta->high_priority_tx = reg_hp_tx;
291 coex_sta->high_priority_rx = reg_hp_rx;
292 coex_sta->low_priority_tx = reg_lp_tx;
293 coex_sta->low_priority_rx = reg_lp_rx;
295 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
296 "[BTCoex], High Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
297 reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
298 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
299 "[BTCoex], Low Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
300 reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
303 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
306 static bool btc8723b2ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
308 static bool pre_wifi_busy;
309 static bool pre_under_4way;
310 static bool pre_bt_hs_on;
311 bool wifi_busy = false, under_4way = false, bt_hs_on = false;
312 bool wifi_connected = false;
314 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
316 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
317 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
318 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
321 if (wifi_connected) {
322 if (wifi_busy != pre_wifi_busy) {
323 pre_wifi_busy = wifi_busy;
327 if (under_4way != pre_under_4way) {
328 pre_under_4way = under_4way;
332 if (bt_hs_on != pre_bt_hs_on) {
333 pre_bt_hs_on = bt_hs_on;
341 static void btc8723b2ant_update_bt_link_info(struct btc_coexist *btcoexist)
343 /*struct btc_stack_info *stack_info = &btcoexist->stack_info;*/
344 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
345 bool bt_hs_on = false;
347 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 1) /* profile from bt patch */
348 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
350 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
351 bt_link_info->sco_exist = coex_sta->sco_exist;
352 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
353 bt_link_info->pan_exist = coex_sta->pan_exist;
354 bt_link_info->hid_exist = coex_sta->hid_exist;
356 /* work around for HS mode. */
358 bt_link_info->pan_exist = true;
359 bt_link_info->bt_link_exist = true;
361 #else /* profile from bt stack */
362 bt_link_info->bt_link_exist = stack_info->bt_link_exist;
363 bt_link_info->sco_exist = stack_info->sco_exist;
364 bt_link_info->a2dp_exist = stack_info->a2dp_exist;
365 bt_link_info->pan_exist = stack_info->pan_exist;
366 bt_link_info->hid_exist = stack_info->hid_exist;
368 /*for win-8 stack HID report error*/
369 if (!stack_info->hid_exist)
370 stack_info->hid_exist = coex_sta->hid_exist;
371 /*sync BTInfo with BT firmware and stack*/
372 /* when stack HID report error, here we use the info from bt fw.*/
373 if (!stack_info->bt_link_exist)
374 stack_info->bt_link_exist = coex_sta->bt_link_exist;
376 /* check if Sco only */
377 if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
378 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
379 bt_link_info->sco_only = true;
381 bt_link_info->sco_only = false;
383 /* check if A2dp only */
384 if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
385 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
386 bt_link_info->a2dp_only = true;
388 bt_link_info->a2dp_only = false;
390 /* check if Pan only */
391 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
392 bt_link_info->pan_exist && !bt_link_info->hid_exist)
393 bt_link_info->pan_only = true;
395 bt_link_info->pan_only = false;
397 /* check if Hid only */
398 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
399 !bt_link_info->pan_exist && bt_link_info->hid_exist)
400 bt_link_info->hid_only = true;
402 bt_link_info->hid_only = false;
405 static u8 btc8723b2ant_action_algorithm(struct btc_coexist *btcoexist)
407 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
408 bool bt_hs_on = false;
409 u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED;
410 u8 num_of_diff_profile = 0;
412 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
414 if (!bt_link_info->bt_link_exist) {
415 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
416 "[BTCoex], No BT link exists!!!\n");
420 if (bt_link_info->sco_exist)
421 num_of_diff_profile++;
422 if (bt_link_info->hid_exist)
423 num_of_diff_profile++;
424 if (bt_link_info->pan_exist)
425 num_of_diff_profile++;
426 if (bt_link_info->a2dp_exist)
427 num_of_diff_profile++;
429 if (num_of_diff_profile == 1) {
430 if (bt_link_info->sco_exist) {
431 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
432 "[BTCoex], SCO only\n");
433 algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
435 if (bt_link_info->hid_exist) {
436 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
437 "[BTCoex], HID only\n");
438 algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
439 } else if (bt_link_info->a2dp_exist) {
440 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
441 "[BTCoex], A2DP only\n");
442 algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP;
443 } else if (bt_link_info->pan_exist) {
445 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
446 "[BTCoex], PAN(HS) only\n");
448 BT_8723B_2ANT_COEX_ALGO_PANHS;
450 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
451 "[BTCoex], PAN(EDR) only\n");
453 BT_8723B_2ANT_COEX_ALGO_PANEDR;
457 } else if (num_of_diff_profile == 2) {
458 if (bt_link_info->sco_exist) {
459 if (bt_link_info->hid_exist) {
460 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
461 "[BTCoex], SCO + HID\n");
462 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
463 } else if (bt_link_info->a2dp_exist) {
464 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
465 "[BTCoex], SCO + A2DP ==> SCO\n");
466 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
467 } else if (bt_link_info->pan_exist) {
469 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
470 "[BTCoex], SCO + PAN(HS)\n");
471 algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
473 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
474 "[BTCoex], SCO + PAN(EDR)\n");
476 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
480 if (bt_link_info->hid_exist &&
481 bt_link_info->a2dp_exist) {
482 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
483 "[BTCoex], HID + A2DP\n");
484 algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
485 } else if (bt_link_info->hid_exist &&
486 bt_link_info->pan_exist) {
488 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
489 "[BTCoex], HID + PAN(HS)\n");
490 algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
492 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
493 "[BTCoex], HID + PAN(EDR)\n");
495 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
497 } else if (bt_link_info->pan_exist &&
498 bt_link_info->a2dp_exist) {
500 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
501 "[BTCoex], A2DP + PAN(HS)\n");
503 BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS;
505 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
506 "[BTCoex],A2DP + PAN(EDR)\n");
508 BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP;
512 } else if (num_of_diff_profile == 3) {
513 if (bt_link_info->sco_exist) {
514 if (bt_link_info->hid_exist &&
515 bt_link_info->a2dp_exist) {
516 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
517 "[BTCoex], SCO + HID + A2DP"
519 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
520 } else if (bt_link_info->hid_exist &&
521 bt_link_info->pan_exist) {
523 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
524 "[BTCoex], SCO + HID + "
527 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
529 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
530 "[BTCoex], SCO + HID + "
533 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
535 } else if (bt_link_info->pan_exist &&
536 bt_link_info->a2dp_exist) {
538 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
539 "[BTCoex], SCO + A2DP + "
542 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
544 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
545 "[BTCoex], SCO + A2DP + "
546 "PAN(EDR) ==> HID\n");
548 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
552 if (bt_link_info->hid_exist &&
553 bt_link_info->pan_exist &&
554 bt_link_info->a2dp_exist) {
556 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
557 "[BTCoex], HID + A2DP + "
560 BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
562 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
563 "[BTCoex], HID + A2DP + "
566 BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
570 } else if (num_of_diff_profile >= 3) {
571 if (bt_link_info->sco_exist) {
572 if (bt_link_info->hid_exist &&
573 bt_link_info->pan_exist &&
574 bt_link_info->a2dp_exist) {
576 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
577 "[BTCoex], Error!!! SCO + HID"
578 " + A2DP + PAN(HS)\n");
580 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
581 "[BTCoex], SCO + HID + A2DP +"
582 " PAN(EDR)==>PAN(EDR)+HID\n");
584 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
592 static bool btc8723b_need_dec_pwr(struct btc_coexist *btcoexist)
595 bool bt_hs_on = false, wifi_connected = false;
599 if (!btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on))
601 if (!btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
604 if (!btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi))
607 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
609 if (wifi_connected) {
611 if (bt_hs_rssi > 37) {
612 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
613 "[BTCoex], Need to decrease bt "
614 "power for HS mode!!\n");
618 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
619 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
620 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
621 "[BTCoex], Need to decrease bt "
622 "power for Wifi is connected!!\n");
631 static void btc8723b2ant_set_fw_dac_swing_level(struct btc_coexist *btcoexist,
634 u8 h2c_parameter[1] = {0};
636 /* There are several type of dacswing
637 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
639 h2c_parameter[0] = dac_swing_lvl;
641 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
642 "[BTCoex], Set Dac Swing Level=0x%x\n", dac_swing_lvl);
643 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
644 "[BTCoex], FW write 0x64=0x%x\n", h2c_parameter[0]);
646 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
649 static void btc8723b2ant_set_fw_dec_bt_pwr(struct btc_coexist *btcoexist,
652 u8 h2c_parameter[1] = {0};
654 h2c_parameter[0] = 0;
657 h2c_parameter[0] |= BIT1;
659 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
660 "[BTCoex], decrease Bt Power : %s, FW write 0x62=0x%x\n",
661 (dec_bt_pwr ? "Yes!!" : "No!!"), h2c_parameter[0]);
663 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
666 static void btc8723b2ant_dec_bt_pwr(struct btc_coexist *btcoexist,
667 bool force_exec, bool dec_bt_pwr)
669 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
670 "[BTCoex], %s Dec BT power = %s\n",
671 (force_exec ? "force to" : ""), (dec_bt_pwr ? "ON" : "OFF"));
672 coex_dm->cur_dec_bt_pwr = dec_bt_pwr;
675 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
676 "[BTCoex], bPreDecBtPwr=%d, bCurDecBtPwr=%d\n",
677 coex_dm->pre_dec_bt_pwr, coex_dm->cur_dec_bt_pwr);
679 if (coex_dm->pre_dec_bt_pwr == coex_dm->cur_dec_bt_pwr)
682 btc8723b2ant_set_fw_dec_bt_pwr(btcoexist, coex_dm->cur_dec_bt_pwr);
684 coex_dm->pre_dec_bt_pwr = coex_dm->cur_dec_bt_pwr;
687 static void btc8723b2ant_fw_dac_swing_lvl(struct btc_coexist *btcoexist,
688 bool force_exec, u8 fw_dac_swing_lvl)
690 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
691 "[BTCoex], %s set FW Dac Swing level = %d\n",
692 (force_exec ? "force to" : ""), fw_dac_swing_lvl);
693 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
696 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
697 "[BTCoex], preFwDacSwingLvl=%d, "
698 "curFwDacSwingLvl=%d\n",
699 coex_dm->pre_fw_dac_swing_lvl,
700 coex_dm->cur_fw_dac_swing_lvl);
702 if (coex_dm->pre_fw_dac_swing_lvl ==
703 coex_dm->cur_fw_dac_swing_lvl)
707 btc8723b2ant_set_fw_dac_swing_level(btcoexist,
708 coex_dm->cur_fw_dac_swing_lvl);
709 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
712 static void btc8723b2ant_set_sw_rf_rx_lpf_corner(struct btc_coexist *btcoexist,
713 bool rx_rf_shrink_on)
715 if (rx_rf_shrink_on) {
716 /* Shrink RF Rx LPF corner */
717 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
718 "[BTCoex], Shrink RF Rx LPF corner!!\n");
719 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
722 /* Resume RF Rx LPF corner */
723 /* After initialized, we can use coex_dm->btRf0x1eBackup */
724 if (btcoexist->initilized) {
725 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
726 "[BTCoex], Resume RF Rx LPF corner!!\n");
727 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
729 coex_dm->bt_rf0x1e_backup);
734 static void btc8723b2ant_rf_shrink(struct btc_coexist *btcoexist,
735 bool force_exec, bool rx_rf_shrink_on)
737 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
738 "[BTCoex], %s turn Rx RF Shrink = %s\n",
739 (force_exec ? "force to" : ""), (rx_rf_shrink_on ?
741 coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
744 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
745 "[BTCoex], bPreRfRxLpfShrink=%d, "
746 "bCurRfRxLpfShrink=%d\n",
747 coex_dm->pre_rf_rx_lpf_shrink,
748 coex_dm->cur_rf_rx_lpf_shrink);
750 if (coex_dm->pre_rf_rx_lpf_shrink ==
751 coex_dm->cur_rf_rx_lpf_shrink)
754 btc8723b2ant_set_sw_rf_rx_lpf_corner(btcoexist,
755 coex_dm->cur_rf_rx_lpf_shrink);
757 coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
760 static void btc8723b_set_penalty_txrate(struct btc_coexist *btcoexist,
763 u8 h2c_parameter[6] = {0};
765 h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty*/
767 if (low_penalty_ra) {
768 h2c_parameter[1] |= BIT0;
769 /*normal rate except MCS7/6/5, OFDM54/48/36*/
770 h2c_parameter[2] = 0x00;
771 h2c_parameter[3] = 0xf7; /*MCS7 or OFDM54*/
772 h2c_parameter[4] = 0xf8; /*MCS6 or OFDM48*/
773 h2c_parameter[5] = 0xf9; /*MCS5 or OFDM36*/
776 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
777 "[BTCoex], set WiFi Low-Penalty Retry: %s",
778 (low_penalty_ra ? "ON!!" : "OFF!!"));
780 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
783 static void btc8723b2ant_low_penalty_ra(struct btc_coexist *btcoexist,
784 bool force_exec, bool low_penalty_ra)
787 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
788 "[BTCoex], %s turn LowPenaltyRA = %s\n",
789 (force_exec ? "force to" : ""), (low_penalty_ra ?
791 coex_dm->cur_low_penalty_ra = low_penalty_ra;
794 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
795 "[BTCoex], bPreLowPenaltyRa=%d, "
796 "bCurLowPenaltyRa=%d\n",
797 coex_dm->pre_low_penalty_ra,
798 coex_dm->cur_low_penalty_ra);
800 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
803 btc8723b_set_penalty_txrate(btcoexist, coex_dm->cur_low_penalty_ra);
805 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
808 static void btc8723b2ant_set_dac_swing_reg(struct btc_coexist *btcoexist,
812 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
813 "[BTCoex], Write SwDacSwing = 0x%x\n", level);
814 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x883, 0x3e, val);
817 static void btc8723b2ant_set_sw_fulltime_dac_swing(struct btc_coexist *btcoex,
818 bool sw_dac_swing_on,
819 u32 sw_dac_swing_lvl)
822 btc8723b2ant_set_dac_swing_reg(btcoex, sw_dac_swing_lvl);
824 btc8723b2ant_set_dac_swing_reg(btcoex, 0x18);
828 static void btc8723b2ant_dac_swing(struct btc_coexist *btcoexist,
829 bool force_exec, bool dac_swing_on,
832 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
833 "[BTCoex], %s turn DacSwing=%s, dac_swing_lvl=0x%x\n",
834 (force_exec ? "force to" : ""),
835 (dac_swing_on ? "ON" : "OFF"), dac_swing_lvl);
836 coex_dm->cur_dac_swing_on = dac_swing_on;
837 coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
840 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
841 "[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x,"
842 " bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n",
843 coex_dm->pre_dac_swing_on, coex_dm->pre_dac_swing_lvl,
844 coex_dm->cur_dac_swing_on,
845 coex_dm->cur_dac_swing_lvl);
847 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
848 (coex_dm->pre_dac_swing_lvl == coex_dm->cur_dac_swing_lvl))
852 btc8723b2ant_set_sw_fulltime_dac_swing(btcoexist, dac_swing_on,
855 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
856 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
859 static void btc8723b2ant_set_agc_table(struct btc_coexist *btcoexist,
862 u8 rssi_adjust_val = 0;
864 /* BB AGC Gain Table */
866 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
867 "[BTCoex], BB Agc Table On!\n");
868 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6e1A0001);
869 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6d1B0001);
870 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6c1C0001);
871 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6b1D0001);
872 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6a1E0001);
873 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x691F0001);
874 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x68200001);
876 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
877 "[BTCoex], BB Agc Table Off!\n");
878 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001);
879 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001);
880 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001);
881 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001);
882 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001);
883 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001);
884 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa4200001);
889 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
891 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
892 "[BTCoex], Agc Table On!\n");
893 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b,
895 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b,
898 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
899 "[BTCoex], Agc Table Off!\n");
900 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b,
902 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b,
905 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
907 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
910 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
911 "[BTCoex], Agc Table On!\n");
912 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40,
914 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40,
917 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
918 "[BTCoex], Agc Table Off!\n");
919 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40,
921 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40,
924 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
926 /* set rssiAdjustVal for wifi module. */
929 btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
933 static void btc8723b2ant_agc_table(struct btc_coexist *btcoexist,
934 bool force_exec, bool agc_table_en)
936 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
937 "[BTCoex], %s %s Agc Table\n",
938 (force_exec ? "force to" : ""),
939 (agc_table_en ? "Enable" : "Disable"));
940 coex_dm->cur_agc_table_en = agc_table_en;
943 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
944 "[BTCoex], bPreAgcTableEn=%d, bCurAgcTableEn=%d\n",
945 coex_dm->pre_agc_table_en, coex_dm->cur_agc_table_en);
947 if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
950 btc8723b2ant_set_agc_table(btcoexist, agc_table_en);
952 coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
955 static void btc8723b2ant_set_coex_table(struct btc_coexist *btcoexist,
956 u32 val0x6c0, u32 val0x6c4,
957 u32 val0x6c8, u8 val0x6cc)
959 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
960 "[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0);
961 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
963 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
964 "[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4);
965 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
967 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
968 "[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8);
969 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
971 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
972 "[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc);
973 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
976 static void btc8723b2ant_coex_table(struct btc_coexist *btcoexist,
977 bool force_exec, u32 val0x6c0,
978 u32 val0x6c4, u32 val0x6c8,
981 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
982 "[BTCoex], %s write Coex Table 0x6c0=0x%x,"
983 " 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
984 (force_exec ? "force to" : ""), val0x6c0,
985 val0x6c4, val0x6c8, val0x6cc);
986 coex_dm->cur_val0x6c0 = val0x6c0;
987 coex_dm->cur_val0x6c4 = val0x6c4;
988 coex_dm->cur_val0x6c8 = val0x6c8;
989 coex_dm->cur_val0x6cc = val0x6cc;
992 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
993 "[BTCoex], preVal0x6c0=0x%x, "
994 "preVal0x6c4=0x%x, preVal0x6c8=0x%x, "
995 "preVal0x6cc=0x%x !!\n",
996 coex_dm->pre_val0x6c0, coex_dm->pre_val0x6c4,
997 coex_dm->pre_val0x6c8, coex_dm->pre_val0x6cc);
998 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
999 "[BTCoex], curVal0x6c0=0x%x, "
1000 "curVal0x6c4=0x%x, curVal0x6c8=0x%x, "
1001 "curVal0x6cc=0x%x !!\n",
1002 coex_dm->cur_val0x6c0, coex_dm->cur_val0x6c4,
1003 coex_dm->cur_val0x6c8, coex_dm->cur_val0x6cc);
1005 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1006 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1007 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1008 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1011 btc8723b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
1012 val0x6c8, val0x6cc);
1014 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1015 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1016 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1017 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1020 static void btc8723b_coex_tbl_type(struct btc_coexist *btcoexist,
1021 bool force_exec, u8 type)
1025 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1026 0x55555555, 0xffff, 0x3);
1029 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1030 0x5afa5afa, 0xffff, 0x3);
1033 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
1034 0x5a5a5a5a, 0xffff, 0x3);
1037 btc8723b2ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
1038 0xaaaaaaaa, 0xffff, 0x3);
1041 btc8723b2ant_coex_table(btcoexist, force_exec, 0xffffffff,
1042 0xffffffff, 0xffff, 0x3);
1045 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5fff5fff,
1046 0x5fff5fff, 0xffff, 0x3);
1049 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
1050 0x5a5a5a5a, 0xffff, 0x3);
1053 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
1054 0x5afa5afa, 0xffff, 0x3);
1057 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5aea5aea,
1058 0x5aea5aea, 0xffff, 0x3);
1061 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
1062 0x5aea5aea, 0xffff, 0x3);
1065 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
1066 0x5aff5aff, 0xffff, 0x3);
1069 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
1070 0x5a5f5a5f, 0xffff, 0x3);
1073 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
1074 0x5f5f5f5f, 0xffff, 0x3);
1081 static void btc8723b2ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
1084 u8 h2c_parameter[1] = {0};
1087 h2c_parameter[0] |= BIT0;/* function enable*/
1089 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
1090 "[BTCoex], set FW for BT Ignore Wlan_Act, "
1091 "FW write 0x63=0x%x\n", h2c_parameter[0]);
1093 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1096 static void btc8723b2ant_ignore_wlan_act(struct btc_coexist *btcoexist,
1097 bool force_exec, bool enable)
1099 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
1100 "[BTCoex], %s turn Ignore WlanAct %s\n",
1101 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
1102 coex_dm->cur_ignore_wlan_act = enable;
1105 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1106 "[BTCoex], bPreIgnoreWlanAct = %d, "
1107 "bCurIgnoreWlanAct = %d!!\n",
1108 coex_dm->pre_ignore_wlan_act,
1109 coex_dm->cur_ignore_wlan_act);
1111 if (coex_dm->pre_ignore_wlan_act ==
1112 coex_dm->cur_ignore_wlan_act)
1115 btc8723b2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1117 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1120 static void btc8723b2ant_set_fw_ps_tdma(struct btc_coexist *btcoexist, u8 byte1,
1121 u8 byte2, u8 byte3, u8 byte4, u8 byte5)
1123 u8 h2c_parameter[5];
1125 h2c_parameter[0] = byte1;
1126 h2c_parameter[1] = byte2;
1127 h2c_parameter[2] = byte3;
1128 h2c_parameter[3] = byte4;
1129 h2c_parameter[4] = byte5;
1131 coex_dm->ps_tdma_para[0] = byte1;
1132 coex_dm->ps_tdma_para[1] = byte2;
1133 coex_dm->ps_tdma_para[2] = byte3;
1134 coex_dm->ps_tdma_para[3] = byte4;
1135 coex_dm->ps_tdma_para[4] = byte5;
1137 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
1138 "[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n",
1140 h2c_parameter[1] << 24 | h2c_parameter[2] << 16 |
1141 h2c_parameter[3] << 8 | h2c_parameter[4]);
1143 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1146 static void btc8723b2ant_sw_mechanism1(struct btc_coexist *btcoexist,
1147 bool shrink_rx_lpf, bool low_penalty_ra,
1148 bool limited_dig, bool bt_lna_constrain)
1150 btc8723b2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
1151 btc8723b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
1154 static void btc8723b2ant_sw_mechanism2(struct btc_coexist *btcoexist,
1155 bool agc_table_shift, bool adc_backoff,
1156 bool sw_dac_swing, u32 dac_swing_lvl)
1158 btc8723b2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift);
1159 btc8723b2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1163 static void btc8723b2ant_ps_tdma(struct btc_coexist *btcoexist, bool force_exec,
1164 bool turn_on, u8 type)
1166 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
1167 "[BTCoex], %s turn %s PS TDMA, type=%d\n",
1168 (force_exec ? "force to" : ""),
1169 (turn_on ? "ON" : "OFF"), type);
1170 coex_dm->cur_ps_tdma_on = turn_on;
1171 coex_dm->cur_ps_tdma = type;
1174 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1175 "[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1176 coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on);
1177 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1178 "[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1179 coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma);
1181 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1182 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1189 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
1193 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
1197 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1201 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10,
1205 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
1209 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
1213 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1217 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x10,
1221 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
1225 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
1229 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
1233 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5,
1237 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
1241 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
1245 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
1249 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5,
1253 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x2f,
1257 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5,
1261 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1265 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1269 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
1273 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
1278 /* disable PS tdma */
1281 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1285 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1289 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1295 /* update pre state */
1296 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1297 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1300 static void btc8723b2ant_coex_alloff(struct btc_coexist *btcoexist)
1303 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1304 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1305 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1308 btc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false);
1309 btc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1312 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1313 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
1316 static void btc8723b2ant_init_coex_dm(struct btc_coexist *btcoexist)
1318 /* force to reset coex mechanism*/
1320 btc8723b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1321 btc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1322 btc8723b2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, false);
1324 btc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false);
1325 btc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1328 static void btc8723b2ant_action_bt_inquiry(struct btc_coexist *btcoexist)
1330 bool wifi_connected = false;
1331 bool low_pwr_disable = true;
1333 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1335 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1338 if (wifi_connected) {
1339 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
1340 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1342 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
1343 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1345 btc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1346 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1348 btc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false);
1349 btc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1351 coex_dm->need_recover_0x948 = true;
1352 coex_dm->backup_0x948 = btcoexist->btc_read_2byte(btcoexist, 0x948);
1354 btcoexist->btc_write_2byte(btcoexist, 0x948, 0x280);
1357 static bool btc8723b2ant_is_common_action(struct btc_coexist *btcoexist)
1359 bool common = false, wifi_connected = false;
1360 bool wifi_busy = false;
1361 bool bt_hs_on = false, low_pwr_disable = false;
1363 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1364 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1366 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1368 if (!wifi_connected) {
1369 low_pwr_disable = false;
1370 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1373 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1374 "[BTCoex], Wifi non-connected idle!!\n");
1376 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
1378 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
1379 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1380 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1381 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1383 btc8723b2ant_sw_mechanism1(btcoexist, false, false, false,
1385 btc8723b2ant_sw_mechanism2(btcoexist, false, false, false,
1390 if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1391 coex_dm->bt_status) {
1392 low_pwr_disable = false;
1393 btcoexist->btc_set(btcoexist,
1394 BTC_SET_ACT_DISABLE_LOW_POWER,
1397 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1398 "[BTCoex], Wifi connected + "
1399 "BT non connected-idle!!\n");
1401 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1403 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
1404 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1405 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1407 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
1410 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
1412 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
1416 } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE ==
1417 coex_dm->bt_status) {
1418 low_pwr_disable = true;
1419 btcoexist->btc_set(btcoexist,
1420 BTC_SET_ACT_DISABLE_LOW_POWER,
1425 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1426 "[BTCoex], Wifi connected + "
1427 "BT connected-idle!!\n");
1429 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1431 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
1432 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1433 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1435 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
1438 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
1440 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
1445 low_pwr_disable = true;
1446 btcoexist->btc_set(btcoexist,
1447 BTC_SET_ACT_DISABLE_LOW_POWER,
1451 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1452 "[BTCoex], Wifi Connected-Busy + "
1459 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1460 "[BTCoex], Wifi Connected-Idle + "
1463 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
1465 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC,
1467 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1469 btc8723b2ant_fw_dac_swing_lvl(btcoexist,
1472 if (btc8723b_need_dec_pwr(btcoexist))
1473 btc8723b2ant_dec_bt_pwr(btcoexist,
1477 btc8723b2ant_dec_bt_pwr(btcoexist,
1480 btc8723b2ant_sw_mechanism1(btcoexist, false,
1483 btc8723b2ant_sw_mechanism2(btcoexist, false,
1494 static void set_tdma_int1(struct btc_coexist *btcoexist, bool tx_pause,
1497 /* Set PS TDMA for max interval == 1 */
1499 BTC_PRINT(BTC_MSG_ALGORITHM,
1500 ALGO_TRACE_FW_DETAIL,
1501 "[BTCoex], TxPause = 1\n");
1503 if (coex_dm->cur_ps_tdma == 71) {
1504 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1506 coex_dm->tdma_adj_type = 5;
1507 } else if (coex_dm->cur_ps_tdma == 1) {
1508 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1510 coex_dm->tdma_adj_type = 5;
1511 } else if (coex_dm->cur_ps_tdma == 2) {
1512 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1514 coex_dm->tdma_adj_type = 6;
1515 } else if (coex_dm->cur_ps_tdma == 3) {
1516 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1518 coex_dm->tdma_adj_type = 7;
1519 } else if (coex_dm->cur_ps_tdma == 4) {
1520 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1522 coex_dm->tdma_adj_type = 8;
1523 } else if (coex_dm->cur_ps_tdma == 9) {
1524 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1526 coex_dm->tdma_adj_type = 13;
1527 } else if (coex_dm->cur_ps_tdma == 10) {
1528 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1530 coex_dm->tdma_adj_type = 14;
1531 } else if (coex_dm->cur_ps_tdma == 11) {
1532 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1534 coex_dm->tdma_adj_type = 15;
1535 } else if (coex_dm->cur_ps_tdma == 12) {
1536 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1538 coex_dm->tdma_adj_type = 16;
1542 if (coex_dm->cur_ps_tdma == 5) {
1543 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1545 coex_dm->tdma_adj_type = 6;
1546 } else if (coex_dm->cur_ps_tdma == 6) {
1547 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1549 coex_dm->tdma_adj_type = 7;
1550 } else if (coex_dm->cur_ps_tdma == 7) {
1551 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1553 coex_dm->tdma_adj_type = 8;
1554 } else if (coex_dm->cur_ps_tdma == 13) {
1555 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1557 coex_dm->tdma_adj_type = 14;
1558 } else if (coex_dm->cur_ps_tdma == 14) {
1559 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1561 coex_dm->tdma_adj_type = 15;
1562 } else if (coex_dm->cur_ps_tdma == 15) {
1563 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1565 coex_dm->tdma_adj_type = 16;
1567 } else if (result == 1) {
1568 if (coex_dm->cur_ps_tdma == 8) {
1569 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1571 coex_dm->tdma_adj_type = 7;
1572 } else if (coex_dm->cur_ps_tdma == 7) {
1573 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1575 coex_dm->tdma_adj_type = 6;
1576 } else if (coex_dm->cur_ps_tdma == 6) {
1577 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1579 coex_dm->tdma_adj_type = 5;
1580 } else if (coex_dm->cur_ps_tdma == 16) {
1581 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1583 coex_dm->tdma_adj_type = 15;
1584 } else if (coex_dm->cur_ps_tdma == 15) {
1585 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1587 coex_dm->tdma_adj_type = 14;
1588 } else if (coex_dm->cur_ps_tdma == 14) {
1589 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1591 coex_dm->tdma_adj_type = 13;
1595 BTC_PRINT(BTC_MSG_ALGORITHM,
1596 ALGO_TRACE_FW_DETAIL,
1597 "[BTCoex], TxPause = 0\n");
1598 if (coex_dm->cur_ps_tdma == 5) {
1599 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 71);
1600 coex_dm->tdma_adj_type = 71;
1601 } else if (coex_dm->cur_ps_tdma == 6) {
1602 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1603 coex_dm->tdma_adj_type = 2;
1604 } else if (coex_dm->cur_ps_tdma == 7) {
1605 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1606 coex_dm->tdma_adj_type = 3;
1607 } else if (coex_dm->cur_ps_tdma == 8) {
1608 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4);
1609 coex_dm->tdma_adj_type = 4;
1610 } else if (coex_dm->cur_ps_tdma == 13) {
1611 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
1612 coex_dm->tdma_adj_type = 9;
1613 } else if (coex_dm->cur_ps_tdma == 14) {
1614 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
1615 coex_dm->tdma_adj_type = 10;
1616 } else if (coex_dm->cur_ps_tdma == 15) {
1617 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1618 coex_dm->tdma_adj_type = 11;
1619 } else if (coex_dm->cur_ps_tdma == 16) {
1620 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
1621 coex_dm->tdma_adj_type = 12;
1625 if (coex_dm->cur_ps_tdma == 71) {
1626 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1628 coex_dm->tdma_adj_type = 1;
1629 } else if (coex_dm->cur_ps_tdma == 1) {
1630 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1632 coex_dm->tdma_adj_type = 2;
1633 } else if (coex_dm->cur_ps_tdma == 2) {
1634 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1636 coex_dm->tdma_adj_type = 3;
1637 } else if (coex_dm->cur_ps_tdma == 3) {
1638 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1640 coex_dm->tdma_adj_type = 4;
1641 } else if (coex_dm->cur_ps_tdma == 9) {
1642 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1644 coex_dm->tdma_adj_type = 10;
1645 } else if (coex_dm->cur_ps_tdma == 10) {
1646 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1648 coex_dm->tdma_adj_type = 11;
1649 } else if (coex_dm->cur_ps_tdma == 11) {
1650 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1652 coex_dm->tdma_adj_type = 12;
1654 } else if (result == 1) {
1655 int tmp = coex_dm->cur_ps_tdma;
1663 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1665 coex_dm->tdma_adj_type = tmp - 1;
1668 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1670 coex_dm->tdma_adj_type = 71;
1677 static void set_tdma_int2(struct btc_coexist *btcoexist, bool tx_pause,
1680 /* Set PS TDMA for max interval == 2 */
1682 BTC_PRINT(BTC_MSG_ALGORITHM,
1683 ALGO_TRACE_FW_DETAIL,
1684 "[BTCoex], TxPause = 1\n");
1685 if (coex_dm->cur_ps_tdma == 1) {
1686 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1687 coex_dm->tdma_adj_type = 6;
1688 } else if (coex_dm->cur_ps_tdma == 2) {
1689 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1690 coex_dm->tdma_adj_type = 6;
1691 } else if (coex_dm->cur_ps_tdma == 3) {
1692 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
1693 coex_dm->tdma_adj_type = 7;
1694 } else if (coex_dm->cur_ps_tdma == 4) {
1695 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
1696 coex_dm->tdma_adj_type = 8;
1697 } else if (coex_dm->cur_ps_tdma == 9) {
1698 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1699 coex_dm->tdma_adj_type = 14;
1700 } else if (coex_dm->cur_ps_tdma == 10) {
1701 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1702 coex_dm->tdma_adj_type = 14;
1703 } else if (coex_dm->cur_ps_tdma == 11) {
1704 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
1705 coex_dm->tdma_adj_type = 15;
1706 } else if (coex_dm->cur_ps_tdma == 12) {
1707 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16);
1708 coex_dm->tdma_adj_type = 16;
1711 if (coex_dm->cur_ps_tdma == 5) {
1712 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1714 coex_dm->tdma_adj_type = 6;
1715 } else if (coex_dm->cur_ps_tdma == 6) {
1716 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1718 coex_dm->tdma_adj_type = 7;
1719 } else if (coex_dm->cur_ps_tdma == 7) {
1720 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1722 coex_dm->tdma_adj_type = 8;
1723 } else if (coex_dm->cur_ps_tdma == 13) {
1724 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1726 coex_dm->tdma_adj_type = 14;
1727 } else if (coex_dm->cur_ps_tdma == 14) {
1728 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1730 coex_dm->tdma_adj_type = 15;
1731 } else if (coex_dm->cur_ps_tdma == 15) {
1732 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1734 coex_dm->tdma_adj_type = 16;
1736 } else if (result == 1) {
1737 if (coex_dm->cur_ps_tdma == 8) {
1738 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1740 coex_dm->tdma_adj_type = 7;
1741 } else if (coex_dm->cur_ps_tdma == 7) {
1742 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1744 coex_dm->tdma_adj_type = 6;
1745 } else if (coex_dm->cur_ps_tdma == 6) {
1746 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1748 coex_dm->tdma_adj_type = 6;
1749 } else if (coex_dm->cur_ps_tdma == 16) {
1750 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1752 coex_dm->tdma_adj_type = 15;
1753 } else if (coex_dm->cur_ps_tdma == 15) {
1754 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1756 coex_dm->tdma_adj_type = 14;
1757 } else if (coex_dm->cur_ps_tdma == 14) {
1758 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1760 coex_dm->tdma_adj_type = 14;
1764 BTC_PRINT(BTC_MSG_ALGORITHM,
1765 ALGO_TRACE_FW_DETAIL,
1766 "[BTCoex], TxPause = 0\n");
1767 if (coex_dm->cur_ps_tdma == 5) {
1768 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1769 coex_dm->tdma_adj_type = 2;
1770 } else if (coex_dm->cur_ps_tdma == 6) {
1771 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1772 coex_dm->tdma_adj_type = 2;
1773 } else if (coex_dm->cur_ps_tdma == 7) {
1774 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1775 coex_dm->tdma_adj_type = 3;
1776 } else if (coex_dm->cur_ps_tdma == 8) {
1777 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4);
1778 coex_dm->tdma_adj_type = 4;
1779 } else if (coex_dm->cur_ps_tdma == 13) {
1780 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
1781 coex_dm->tdma_adj_type = 10;
1782 } else if (coex_dm->cur_ps_tdma == 14) {
1783 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
1784 coex_dm->tdma_adj_type = 10;
1785 } else if (coex_dm->cur_ps_tdma == 15) {
1786 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1787 coex_dm->tdma_adj_type = 11;
1788 } else if (coex_dm->cur_ps_tdma == 16) {
1789 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
1790 coex_dm->tdma_adj_type = 12;
1793 if (coex_dm->cur_ps_tdma == 1) {
1794 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1796 coex_dm->tdma_adj_type = 2;
1797 } else if (coex_dm->cur_ps_tdma == 2) {
1798 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1800 coex_dm->tdma_adj_type = 3;
1801 } else if (coex_dm->cur_ps_tdma == 3) {
1802 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1804 coex_dm->tdma_adj_type = 4;
1805 } else if (coex_dm->cur_ps_tdma == 9) {
1806 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1808 coex_dm->tdma_adj_type = 10;
1809 } else if (coex_dm->cur_ps_tdma == 10) {
1810 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1812 coex_dm->tdma_adj_type = 11;
1813 } else if (coex_dm->cur_ps_tdma == 11) {
1814 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1816 coex_dm->tdma_adj_type = 12;
1818 } else if (result == 1) {
1819 if (coex_dm->cur_ps_tdma == 4) {
1820 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1822 coex_dm->tdma_adj_type = 3;
1823 } else if (coex_dm->cur_ps_tdma == 3) {
1824 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1826 coex_dm->tdma_adj_type = 2;
1827 } else if (coex_dm->cur_ps_tdma == 2) {
1828 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1830 coex_dm->tdma_adj_type = 2;
1831 } else if (coex_dm->cur_ps_tdma == 12) {
1832 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1834 coex_dm->tdma_adj_type = 11;
1835 } else if (coex_dm->cur_ps_tdma == 11) {
1836 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1838 coex_dm->tdma_adj_type = 10;
1839 } else if (coex_dm->cur_ps_tdma == 10) {
1840 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1842 coex_dm->tdma_adj_type = 10;
1848 static void set_tdma_int3(struct btc_coexist *btcoexist, bool tx_pause,
1851 /* Set PS TDMA for max interval == 3 */
1853 BTC_PRINT(BTC_MSG_ALGORITHM,
1854 ALGO_TRACE_FW_DETAIL,
1855 "[BTCoex], TxPause = 1\n");
1856 if (coex_dm->cur_ps_tdma == 1) {
1857 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
1858 coex_dm->tdma_adj_type = 7;
1859 } else if (coex_dm->cur_ps_tdma == 2) {
1860 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
1861 coex_dm->tdma_adj_type = 7;
1862 } else if (coex_dm->cur_ps_tdma == 3) {
1863 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
1864 coex_dm->tdma_adj_type = 7;
1865 } else if (coex_dm->cur_ps_tdma == 4) {
1866 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
1867 coex_dm->tdma_adj_type = 8;
1868 } else if (coex_dm->cur_ps_tdma == 9) {
1869 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
1870 coex_dm->tdma_adj_type = 15;
1871 } else if (coex_dm->cur_ps_tdma == 10) {
1872 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
1873 coex_dm->tdma_adj_type = 15;
1874 } else if (coex_dm->cur_ps_tdma == 11) {
1875 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
1876 coex_dm->tdma_adj_type = 15;
1877 } else if (coex_dm->cur_ps_tdma == 12) {
1878 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16);
1879 coex_dm->tdma_adj_type = 16;
1882 if (coex_dm->cur_ps_tdma == 5) {
1883 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1885 coex_dm->tdma_adj_type = 7;
1886 } else if (coex_dm->cur_ps_tdma == 6) {
1887 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1889 coex_dm->tdma_adj_type = 7;
1890 } else if (coex_dm->cur_ps_tdma == 7) {
1891 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1893 coex_dm->tdma_adj_type = 8;
1894 } else if (coex_dm->cur_ps_tdma == 13) {
1895 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1897 coex_dm->tdma_adj_type = 15;
1898 } else if (coex_dm->cur_ps_tdma == 14) {
1899 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1901 coex_dm->tdma_adj_type = 15;
1902 } else if (coex_dm->cur_ps_tdma == 15) {
1903 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1905 coex_dm->tdma_adj_type = 16;
1907 } else if (result == 1) {
1908 if (coex_dm->cur_ps_tdma == 8) {
1909 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1911 coex_dm->tdma_adj_type = 7;
1912 } else if (coex_dm->cur_ps_tdma == 7) {
1913 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1915 coex_dm->tdma_adj_type = 7;
1916 } else if (coex_dm->cur_ps_tdma == 6) {
1917 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1919 coex_dm->tdma_adj_type = 7;
1920 } else if (coex_dm->cur_ps_tdma == 16) {
1921 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1923 coex_dm->tdma_adj_type = 15;
1924 } else if (coex_dm->cur_ps_tdma == 15) {
1925 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1927 coex_dm->tdma_adj_type = 15;
1928 } else if (coex_dm->cur_ps_tdma == 14) {
1929 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1931 coex_dm->tdma_adj_type = 15;
1935 BTC_PRINT(BTC_MSG_ALGORITHM,
1936 ALGO_TRACE_FW_DETAIL,
1937 "[BTCoex], TxPause = 0\n");
1938 switch (coex_dm->cur_ps_tdma) {
1940 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1941 coex_dm->tdma_adj_type = 3;
1944 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1945 coex_dm->tdma_adj_type = 3;
1948 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1949 coex_dm->tdma_adj_type = 3;
1952 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4);
1953 coex_dm->tdma_adj_type = 4;
1956 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1957 coex_dm->tdma_adj_type = 11;
1960 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1961 coex_dm->tdma_adj_type = 11;
1964 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1965 coex_dm->tdma_adj_type = 11;
1968 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
1969 coex_dm->tdma_adj_type = 12;
1973 switch (coex_dm->cur_ps_tdma) {
1975 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1977 coex_dm->tdma_adj_type = 3;
1980 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1982 coex_dm->tdma_adj_type = 3;
1985 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1987 coex_dm->tdma_adj_type = 4;
1990 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1992 coex_dm->tdma_adj_type = 11;
1995 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1997 coex_dm->tdma_adj_type = 11;
2000 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2002 coex_dm->tdma_adj_type = 12;
2005 } else if (result == 1) {
2006 switch (coex_dm->cur_ps_tdma) {
2008 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2010 coex_dm->tdma_adj_type = 3;
2013 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2015 coex_dm->tdma_adj_type = 3;
2018 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2020 coex_dm->tdma_adj_type = 3;
2023 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2025 coex_dm->tdma_adj_type = 11;
2028 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2030 coex_dm->tdma_adj_type = 11;
2033 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2035 coex_dm->tdma_adj_type = 11;
2041 static void btc8723b2ant_tdma_duration_adjust(struct btc_coexist *btcoexist,
2042 bool sco_hid, bool tx_pause,
2045 static s32 up, dn, m, n, wait_count;
2046 /*0: no change, +1: increase WiFi duration, -1: decrease WiFi duration*/
2050 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
2051 "[BTCoex], TdmaDurationAdjust()\n");
2053 if (!coex_dm->auto_tdma_adjust) {
2054 coex_dm->auto_tdma_adjust = true;
2055 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2056 "[BTCoex], first run TdmaDurationAdjust()!!\n");
2059 if (max_interval == 1) {
2060 btc8723b2ant_ps_tdma(btcoexist,
2063 coex_dm->tdma_adj_type = 13;
2064 } else if (max_interval == 2) {
2065 btc8723b2ant_ps_tdma(btcoexist,
2068 coex_dm->tdma_adj_type = 14;
2069 } else if (max_interval == 3) {
2070 btc8723b2ant_ps_tdma(btcoexist,
2073 coex_dm->tdma_adj_type = 15;
2075 btc8723b2ant_ps_tdma(btcoexist,
2078 coex_dm->tdma_adj_type = 15;
2081 if (max_interval == 1) {
2082 btc8723b2ant_ps_tdma(btcoexist,
2085 coex_dm->tdma_adj_type = 9;
2086 } else if (max_interval == 2) {
2087 btc8723b2ant_ps_tdma(btcoexist,
2090 coex_dm->tdma_adj_type = 10;
2091 } else if (max_interval == 3) {
2092 btc8723b2ant_ps_tdma(btcoexist,
2095 coex_dm->tdma_adj_type = 11;
2097 btc8723b2ant_ps_tdma(btcoexist,
2100 coex_dm->tdma_adj_type = 11;
2105 if (max_interval == 1) {
2106 btc8723b2ant_ps_tdma(btcoexist,
2109 coex_dm->tdma_adj_type = 5;
2110 } else if (max_interval == 2) {
2111 btc8723b2ant_ps_tdma(btcoexist,
2114 coex_dm->tdma_adj_type = 6;
2115 } else if (max_interval == 3) {
2116 btc8723b2ant_ps_tdma(btcoexist,
2119 coex_dm->tdma_adj_type = 7;
2121 btc8723b2ant_ps_tdma(btcoexist,
2124 coex_dm->tdma_adj_type = 7;
2127 if (max_interval == 1) {
2128 btc8723b2ant_ps_tdma(btcoexist,
2131 coex_dm->tdma_adj_type = 1;
2132 } else if (max_interval == 2) {
2133 btc8723b2ant_ps_tdma(btcoexist,
2136 coex_dm->tdma_adj_type = 2;
2137 } else if (max_interval == 3) {
2138 btc8723b2ant_ps_tdma(btcoexist,
2141 coex_dm->tdma_adj_type = 3;
2143 btc8723b2ant_ps_tdma(btcoexist,
2146 coex_dm->tdma_adj_type = 3;
2158 /*accquire the BT TRx retry count from BT_Info byte2*/
2159 retry_count = coex_sta->bt_retry_cnt;
2160 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2161 "[BTCoex], retry_count = %d\n", retry_count);
2162 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2163 "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n",
2164 up, dn, m, n, wait_count);
2167 /* no retry in the last 2-second duration*/
2168 if (retry_count == 0) {
2181 BTC_PRINT(BTC_MSG_ALGORITHM,
2182 ALGO_TRACE_FW_DETAIL,
2183 "[BTCoex], Increase wifi "
2185 } /* <=3 retry in the last 2-second duration*/
2186 } else if (retry_count <= 3) {
2194 if (wait_count <= 2)
2207 BTC_PRINT(BTC_MSG_ALGORITHM,
2208 ALGO_TRACE_FW_DETAIL,
2209 "[BTCoex], Decrease wifi duration "
2210 "for retry_counter<3!!\n");
2213 if (wait_count == 1)
2226 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2227 "[BTCoex], Decrease wifi duration "
2228 "for retry_counter>3!!\n");
2231 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2232 "[BTCoex], max Interval = %d\n", max_interval);
2233 if (max_interval == 1)
2234 set_tdma_int1(btcoexist, tx_pause, result);
2235 else if (max_interval == 2)
2236 set_tdma_int2(btcoexist, tx_pause, result);
2237 else if (max_interval == 3)
2238 set_tdma_int3(btcoexist, tx_pause, result);
2241 /*if current PsTdma not match with the recorded one (when scan, dhcp..),
2242 *then we have to adjust it back to the previous recorded one.
2244 if (coex_dm->cur_ps_tdma != coex_dm->tdma_adj_type) {
2245 bool scan = false, link = false, roam = false;
2246 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2247 "[BTCoex], PsTdma type dismatch!!!, "
2248 "curPsTdma=%d, recordPsTdma=%d\n",
2249 coex_dm->cur_ps_tdma, coex_dm->tdma_adj_type);
2251 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2252 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2253 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2255 if (!scan && !link && !roam)
2256 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2257 coex_dm->tdma_adj_type);
2259 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2260 "[BTCoex], roaming/link/scan is under"
2261 " progress, will adjust next time!!!\n");
2265 /* SCO only or SCO+PAN(HS) */
2266 static void btc8723b2ant_action_sco(struct btc_coexist *btcoexist)
2271 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2274 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2276 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
2278 if (btc8723b_need_dec_pwr(btcoexist))
2279 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2281 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2283 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2285 /*for SCO quality at 11b/g mode*/
2286 if (BTC_WIFI_BW_LEGACY == wifi_bw)
2287 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 2);
2288 else /*for SCO quality & wifi performance balance at 11n mode*/
2289 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 8);
2291 /*for voice quality */
2292 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2295 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2296 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2297 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2298 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2300 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2303 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2305 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2309 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2310 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2311 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2313 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2316 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2318 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2324 static void btc8723b2ant_action_hid(struct btc_coexist *btcoexist)
2326 u8 wifi_rssi_state, bt_rssi_state;
2329 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2331 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2333 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2335 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2337 if (btc8723b_need_dec_pwr(btcoexist))
2338 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2340 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2342 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2344 if (BTC_WIFI_BW_LEGACY == wifi_bw) /*/for HID at 11b/g mode*/
2345 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2346 else /*for HID quality & wifi performance balance at 11n mode*/
2347 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 9);
2349 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2350 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2351 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2353 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2356 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2357 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2358 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2359 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2361 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2364 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2366 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2370 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2371 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2372 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2374 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2377 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2379 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2385 /*A2DP only / PAN(EDR) only/ A2DP+PAN(HS)*/
2386 static void btc8723b2ant_action_a2dp(struct btc_coexist *btcoexist)
2388 u8 wifi_rssi_state, bt_rssi_state;
2391 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2393 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2395 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2397 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2399 if (btc8723b_need_dec_pwr(btcoexist))
2400 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2402 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2404 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2406 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2407 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2408 btc8723b2ant_tdma_duration_adjust(btcoexist, false,
2411 btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 1);
2414 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2415 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2416 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2417 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2418 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2420 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2423 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2425 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2429 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2430 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2431 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2433 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2436 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2438 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2444 static void btc8723b2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2449 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2452 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2454 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2456 if (btc8723b_need_dec_pwr(btcoexist))
2457 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2459 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2461 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2463 btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 2);
2466 btcoexist->btc_get(btcoexist,
2467 BTC_GET_U4_WIFI_BW, &wifi_bw);
2468 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2469 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2470 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2471 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2473 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2476 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2478 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2482 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2483 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2484 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2486 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2489 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2491 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2497 static void btc8723b2ant_action_pan_edr(struct btc_coexist *btcoexist)
2499 u8 wifi_rssi_state, bt_rssi_state;
2502 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2504 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2506 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2508 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2510 if (btc8723b_need_dec_pwr(btcoexist))
2511 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2513 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2515 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 10);
2517 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2518 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2519 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
2521 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2524 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2525 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2526 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2527 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2528 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2530 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2533 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2535 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2539 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2540 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2541 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2543 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2546 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2548 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2555 static void btc8723b2ant_action_pan_hs(struct btc_coexist *btcoexist)
2560 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2563 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2565 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2567 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2568 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2569 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2571 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2573 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2575 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
2577 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2578 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2579 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2580 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2581 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2583 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2586 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2588 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2592 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2593 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2594 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2596 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2599 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2601 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2608 static void btc8723b2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
2610 u8 wifi_rssi_state, bt_rssi_state;
2613 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2615 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2617 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2619 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2621 if (btc8723b_need_dec_pwr(btcoexist))
2622 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2624 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2626 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2628 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2629 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2630 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 12);
2631 if (BTC_WIFI_BW_HT40 == wifi_bw)
2632 btc8723b2ant_tdma_duration_adjust(btcoexist, false,
2635 btc8723b2ant_tdma_duration_adjust(btcoexist, false,
2638 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2639 btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 3);
2643 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2644 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2645 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2646 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2648 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2651 btc8723b2ant_sw_mechanism1(btcoexist, true, false,
2653 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2657 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2658 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2659 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2661 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2664 btc8723b2ant_sw_mechanism1(btcoexist, false, false,
2666 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2672 static void btc8723b2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
2674 u8 wifi_rssi_state, bt_rssi_state;
2677 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2679 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2680 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2682 if (btc8723b_need_dec_pwr(btcoexist))
2683 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2685 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2687 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2688 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2689 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2690 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
2692 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 11);
2693 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
2696 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
2698 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2699 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
2702 btc8723b2ant_tdma_duration_adjust(btcoexist, true, false, 2);
2704 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2705 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 11);
2706 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
2708 btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 2);
2712 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2713 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2714 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2715 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2717 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2720 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2722 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2726 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2727 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2728 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2730 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2733 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2735 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2741 /* HID+A2DP+PAN(EDR) */
2742 static void btc8723b2ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
2744 u8 wifi_rssi_state, bt_rssi_state;
2747 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2749 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2751 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2753 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2755 if (btc8723b_need_dec_pwr(btcoexist))
2756 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2758 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2760 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2762 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2764 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2765 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2766 if (BTC_WIFI_BW_HT40 == wifi_bw)
2767 btc8723b2ant_tdma_duration_adjust(btcoexist, true,
2770 btc8723b2ant_tdma_duration_adjust(btcoexist, true,
2773 btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 3);
2777 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2778 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2779 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2780 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2782 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2785 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2787 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2791 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2792 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2793 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2795 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2798 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2800 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2806 static void btc8723b2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
2808 u8 wifi_rssi_state, bt_rssi_state;
2811 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
2813 bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 35, 0);
2815 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2817 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2819 if (btc8723b_need_dec_pwr(btcoexist))
2820 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2822 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2824 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2826 btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
2828 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2829 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2830 btc8723b2ant_tdma_duration_adjust(btcoexist, true, false, 2);
2832 btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 2);
2835 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2836 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2837 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2838 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2840 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2843 btc8723b2ant_sw_mechanism1(btcoexist, true, true,
2845 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2849 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2850 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2851 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2853 btc8723b2ant_sw_mechanism2(btcoexist, true, false,
2856 btc8723b2ant_sw_mechanism1(btcoexist, false, true,
2858 btc8723b2ant_sw_mechanism2(btcoexist, false, false,
2864 static void btc8723b2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
2868 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2869 "[BTCoex], RunCoexistMechanism()===>\n");
2871 if (btcoexist->manual_control) {
2872 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2873 "[BTCoex], RunCoexistMechanism(), "
2874 "return for Manual CTRL <===\n");
2878 if (coex_sta->under_ips) {
2879 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2880 "[BTCoex], wifi is under IPS !!!\n");
2884 algorithm = btc8723b2ant_action_algorithm(btcoexist);
2885 if (coex_sta->c2h_bt_inquiry_page &&
2886 (BT_8723B_2ANT_COEX_ALGO_PANHS != algorithm)) {
2887 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2888 "[BTCoex], BT is under inquiry/page scan !!\n");
2889 btc8723b2ant_action_bt_inquiry(btcoexist);
2892 if (coex_dm->need_recover_0x948) {
2893 coex_dm->need_recover_0x948 = false;
2894 btcoexist->btc_write_2byte(btcoexist, 0x948,
2895 coex_dm->backup_0x948);
2899 coex_dm->cur_algorithm = algorithm;
2900 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, "[BTCoex], Algorithm = %d\n",
2901 coex_dm->cur_algorithm);
2903 if (btc8723b2ant_is_common_action(btcoexist)) {
2904 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2905 "[BTCoex], Action 2-Ant common.\n");
2906 coex_dm->auto_tdma_adjust = false;
2908 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
2909 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2910 "[BTCoex], preAlgorithm=%d, "
2911 "curAlgorithm=%d\n", coex_dm->pre_algorithm,
2912 coex_dm->cur_algorithm);
2913 coex_dm->auto_tdma_adjust = false;
2915 switch (coex_dm->cur_algorithm) {
2916 case BT_8723B_2ANT_COEX_ALGO_SCO:
2917 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2918 "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
2919 btc8723b2ant_action_sco(btcoexist);
2921 case BT_8723B_2ANT_COEX_ALGO_HID:
2922 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2923 "[BTCoex], Action 2-Ant, algorithm = HID.\n");
2924 btc8723b2ant_action_hid(btcoexist);
2926 case BT_8723B_2ANT_COEX_ALGO_A2DP:
2927 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2928 "[BTCoex], Action 2-Ant, "
2929 "algorithm = A2DP.\n");
2930 btc8723b2ant_action_a2dp(btcoexist);
2932 case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS:
2933 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2934 "[BTCoex], Action 2-Ant, "
2935 "algorithm = A2DP+PAN(HS).\n");
2936 btc8723b2ant_action_a2dp_pan_hs(btcoexist);
2938 case BT_8723B_2ANT_COEX_ALGO_PANEDR:
2939 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2940 "[BTCoex], Action 2-Ant, "
2941 "algorithm = PAN(EDR).\n");
2942 btc8723b2ant_action_pan_edr(btcoexist);
2944 case BT_8723B_2ANT_COEX_ALGO_PANHS:
2945 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2946 "[BTCoex], Action 2-Ant, "
2947 "algorithm = HS mode.\n");
2948 btc8723b2ant_action_pan_hs(btcoexist);
2950 case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP:
2951 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2952 "[BTCoex], Action 2-Ant, "
2953 "algorithm = PAN+A2DP.\n");
2954 btc8723b2ant_action_pan_edr_a2dp(btcoexist);
2956 case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID:
2957 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2958 "[BTCoex], Action 2-Ant, "
2959 "algorithm = PAN(EDR)+HID.\n");
2960 btc8723b2ant_action_pan_edr_hid(btcoexist);
2962 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
2963 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2964 "[BTCoex], Action 2-Ant, "
2965 "algorithm = HID+A2DP+PAN.\n");
2966 btc8723b2ant_action_hid_a2dp_pan_edr(btcoexist);
2968 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP:
2969 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2970 "[BTCoex], Action 2-Ant, "
2971 "algorithm = HID+A2DP.\n");
2972 btc8723b2ant_action_hid_a2dp(btcoexist);
2975 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
2976 "[BTCoex], Action 2-Ant, "
2977 "algorithm = coexist All Off!!\n");
2978 btc8723b2ant_coex_alloff(btcoexist);
2981 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2987 /*********************************************************************
2988 * work around function start with wa_btc8723b2ant_
2989 *********************************************************************/
2990 /*********************************************************************
2991 * extern function start with EXbtc8723b2ant_
2992 *********************************************************************/
2993 void ex_halbtc8723b2ant_init_hwconfig(struct btc_coexist *btcoexist)
2995 struct btc_board_info *board_info = &btcoexist->board_info;
2996 u32 u32tmp = 0, fw_ver;
2998 u8 h2c_parameter[2] = {0};
3001 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3002 "[BTCoex], 2Ant Init HW Config!!\n");
3004 /* backup rf 0x1e value */
3005 coex_dm->bt_rf0x1e_backup = btcoexist->btc_get_rf_reg(btcoexist,
3009 /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
3010 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
3013 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
3015 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
3016 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3);
3017 btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77);
3018 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1);
3020 /* Antenna switch control parameter */
3021 /* btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555);*/
3023 /*Force GNT_BT to low*/
3024 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
3025 btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0);
3027 /* 0x790[5:0]=0x5 */
3028 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3031 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
3035 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3037 /*ext switch for fw ver < 0xc */
3038 if (fw_ver < 0xc00) {
3039 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
3040 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
3042 /*Main Ant to BT for IPS case 0x4c[23]=1*/
3043 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
3046 /*tell firmware "no antenna inverse"*/
3047 h2c_parameter[0] = 0;
3048 h2c_parameter[1] = 1; /* ext switch type */
3049 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
3052 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
3054 /*Aux Ant to BT for IPS case 0x4c[23]=1*/
3055 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
3058 /*tell firmware "antenna inverse"*/
3059 h2c_parameter[0] = 1;
3060 h2c_parameter[1] = 1; /*ext switch type*/
3061 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
3065 /*ext switch always at s1 (if exist) */
3066 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c, 0x3, 0x1);
3067 /*Main Ant to BT for IPS case 0x4c[23]=1*/
3068 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1);
3070 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
3071 /*tell firmware "no antenna inverse"*/
3072 h2c_parameter[0] = 0;
3073 h2c_parameter[1] = 0; /*ext switch type*/
3074 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
3077 /*tell firmware "antenna inverse"*/
3078 h2c_parameter[0] = 1;
3079 h2c_parameter[1] = 0; /*ext switch type*/
3080 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
3086 btc8723b_coex_tbl_type(btcoexist, FORCE_EXEC, 0);
3088 /* Enable counter statistics */
3089 /*0x76e[3] =1, WLAN_Act control by PTA*/
3090 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
3091 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3092 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3095 void ex_halbtc8723b2ant_init_coex_dm(struct btc_coexist *btcoexist)
3097 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3098 "[BTCoex], Coex Mechanism Init!!\n");
3099 btc8723b2ant_init_coex_dm(btcoexist);
3102 void ex_halbtc8723b2ant_display_coex_info(struct btc_coexist *btcoexist)
3104 struct btc_board_info *board_info = &btcoexist->board_info;
3105 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3106 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3107 u8 *cli_buf = btcoexist->cli_buf;
3108 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3110 bool roam = false, scan = false;
3111 bool link = false, wifi_under_5g = false;
3112 bool bt_hs_on = false, wifi_busy = false;
3113 s32 wifi_rssi = 0, bt_hs_rssi = 0;
3114 u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck;
3115 u8 wifi_dot11_chnl, wifi_hs_chnl;
3116 u32 fw_ver = 0, bt_patch_ver = 0;
3118 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3119 "\r\n ============[BT Coexist info]============");
3122 if (btcoexist->manual_control) {
3123 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3124 "\r\n ==========[Under Manual Control]============");
3126 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3127 "\r\n ==========================================");
3131 if (!board_info->bt_exist) {
3132 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
3137 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
3138 "Ant PG number/ Ant mechanism:",
3139 board_info->pg_ant_num, board_info->btdm_ant_num);
3142 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d",
3143 "BT stack/ hci ext ver",
3144 ((stack_info->profile_notified) ? "Yes" : "No"),
3145 stack_info->hci_version);
3148 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3149 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3150 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3151 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
3152 "CoexVer/ FwVer/ PatchVer",
3153 glcoex_ver_date_8723b_2ant, glcoex_ver_8723b_2ant,
3154 fw_ver, bt_patch_ver, bt_patch_ver);
3157 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3158 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
3160 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
3162 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)",
3163 "Dot11 channel / HsChnl(HsMode)",
3164 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
3167 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
3168 "H2C Wifi inform bt chnl Info", coex_dm->wifi_chnl_info[0],
3169 coex_dm->wifi_chnl_info[1], coex_dm->wifi_chnl_info[2]);
3172 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
3173 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
3174 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
3175 "Wifi rssi/ HS rssi", wifi_rssi, bt_hs_rssi);
3178 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3179 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3180 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3181 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
3182 "Wifi link/ roam/ scan", link, roam, scan);
3185 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3186 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3187 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3188 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
3190 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s ",
3191 "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
3192 ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
3193 (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
3194 ((!wifi_busy) ? "idle" :
3195 ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
3196 "uplink" : "downlink")));
3201 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
3203 bt_link_info->sco_exist, bt_link_info->hid_exist,
3204 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
3206 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
3208 bt_info_ext = coex_sta->bt_info_ext;
3209 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
3210 "BT Info A2DP rate",
3211 (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
3214 for (i = 0; i < BT_INFO_SRC_8723B_2ANT_MAX; i++) {
3215 if (coex_sta->bt_info_c2h_cnt[i]) {
3216 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3217 "\r\n %-35s = %02x %02x %02x "
3218 "%02x %02x %02x %02x(%d)",
3219 glbt_info_src_8723b_2ant[i],
3220 coex_sta->bt_info_c2h[i][0],
3221 coex_sta->bt_info_c2h[i][1],
3222 coex_sta->bt_info_c2h[i][2],
3223 coex_sta->bt_info_c2h[i][3],
3224 coex_sta->bt_info_c2h[i][4],
3225 coex_sta->bt_info_c2h[i][5],
3226 coex_sta->bt_info_c2h[i][6],
3227 coex_sta->bt_info_c2h_cnt[i]);
3232 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/%s",
3233 "PS state, IPS/LPS",
3234 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
3235 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
3237 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3240 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3241 "\r\n %-35s", "============[Sw mechanism]============");
3243 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
3244 "SM1[ShRf/ LpRA/ LimDig]", coex_dm->cur_rf_rx_lpf_shrink,
3245 coex_dm->cur_low_penalty_ra, coex_dm->limited_dig);
3247 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3248 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3249 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
3250 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
3254 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
3255 "============[Fw mechanism]============");
3258 ps_tdma_case = coex_dm->cur_ps_tdma;
3259 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3260 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
3261 "PS TDMA", coex_dm->ps_tdma_para[0],
3262 coex_dm->ps_tdma_para[1], coex_dm->ps_tdma_para[2],
3263 coex_dm->ps_tdma_para[3], coex_dm->ps_tdma_para[4],
3264 ps_tdma_case, coex_dm->auto_tdma_adjust);
3267 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
3268 "DecBtPwr/ IgnWlanAct", coex_dm->cur_dec_bt_pwr,
3269 coex_dm->cur_ignore_wlan_act);
3273 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
3274 "============[Hw setting]============");
3277 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x",
3278 "RF-A, 0x1e initVal", coex_dm->bt_rf0x1e_backup);
3281 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
3282 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880);
3283 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
3284 "0x778/0x880[29:25]", u8tmp[0],
3285 (u32tmp[0]&0x3e000000) >> 25);
3288 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948);
3289 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67);
3290 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765);
3291 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3292 "0x948/ 0x67[5] / 0x765",
3293 u32tmp[0], ((u8tmp[0]&0x20) >> 5), u8tmp[1]);
3296 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c);
3297 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930);
3298 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944);
3299 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3300 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
3301 u32tmp[0]&0x3, u32tmp[1]&0xff, u32tmp[2]&0x3);
3305 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39);
3306 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
3307 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
3308 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
3309 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3310 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3311 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
3312 ((u8tmp[0] & 0x8)>>3), u8tmp[1],
3313 ((u32tmp[0]&0x01800000)>>23), u8tmp[2]&0x1);
3316 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
3317 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
3318 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
3319 "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
3322 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
3323 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
3324 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
3325 "0xc50(dig)/0x49c(null-drop)", u32tmp[0]&0xff, u8tmp[0]);
3328 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
3329 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
3330 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
3331 u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
3333 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
3334 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
3336 fa_ofdm = ((u32tmp[0]&0xffff0000) >> 16) +
3337 ((u32tmp[1]&0xffff0000) >> 16) +
3338 (u32tmp[1] & 0xffff) +
3339 (u32tmp[2] & 0xffff) +
3340 ((u32tmp[3]&0xffff0000) >> 16) +
3341 (u32tmp[3] & 0xffff);
3342 fa_cck = (u8tmp[0] << 8) + u8tmp[1];
3344 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3345 "OFDM-CCA/OFDM-FA/CCK-FA",
3346 u32tmp[0]&0xffff, fa_ofdm, fa_cck);
3349 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
3350 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
3351 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
3352 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
3353 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3354 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3355 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
3356 u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
3359 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
3360 "0x770(high-pri rx/tx)",
3361 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
3363 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
3364 "0x774(low-pri rx/tx)", coex_sta->low_priority_rx,
3365 coex_sta->low_priority_tx);
3367 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 1)
3368 btc8723b2ant_monitor_bt_ctr(btcoexist);
3370 btcoexist->btc_disp_dbg_msg(btcoexist,
3371 BTC_DBG_DISP_COEX_STATISTICS);
3375 void ex_halbtc8723b2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
3377 if (BTC_IPS_ENTER == type) {
3378 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3379 "[BTCoex], IPS ENTER notify\n");
3380 coex_sta->under_ips = true;
3381 btc8723b2ant_coex_alloff(btcoexist);
3382 } else if (BTC_IPS_LEAVE == type) {
3383 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3384 "[BTCoex], IPS LEAVE notify\n");
3385 coex_sta->under_ips = false;
3389 void ex_halbtc8723b2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
3391 if (BTC_LPS_ENABLE == type) {
3392 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3393 "[BTCoex], LPS ENABLE notify\n");
3394 coex_sta->under_lps = true;
3395 } else if (BTC_LPS_DISABLE == type) {
3396 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3397 "[BTCoex], LPS DISABLE notify\n");
3398 coex_sta->under_lps = false;
3402 void ex_halbtc8723b2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
3404 if (BTC_SCAN_START == type)
3405 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3406 "[BTCoex], SCAN START notify\n");
3407 else if (BTC_SCAN_FINISH == type)
3408 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3409 "[BTCoex], SCAN FINISH notify\n");
3412 void ex_halbtc8723b2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
3414 if (BTC_ASSOCIATE_START == type)
3415 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3416 "[BTCoex], CONNECT START notify\n");
3417 else if (BTC_ASSOCIATE_FINISH == type)
3418 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3419 "[BTCoex], CONNECT FINISH notify\n");
3422 void btc8723b_med_stat_notify(struct btc_coexist *btcoexist,
3425 u8 h2c_parameter[3] = {0};
3427 u8 wifi_central_chnl;
3429 if (BTC_MEDIA_CONNECT == type)
3430 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3431 "[BTCoex], MEDIA connect notify\n");
3433 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3434 "[BTCoex], MEDIA disconnect notify\n");
3436 /* only 2.4G we need to inform bt the chnl mask */
3437 btcoexist->btc_get(btcoexist,
3438 BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifi_central_chnl);
3439 if ((BTC_MEDIA_CONNECT == type) &&
3440 (wifi_central_chnl <= 14)) {
3441 h2c_parameter[0] = 0x1;
3442 h2c_parameter[1] = wifi_central_chnl;
3443 btcoexist->btc_get(btcoexist,
3444 BTC_GET_U4_WIFI_BW, &wifi_bw);
3445 if (BTC_WIFI_BW_HT40 == wifi_bw)
3446 h2c_parameter[2] = 0x30;
3448 h2c_parameter[2] = 0x20;
3451 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3452 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3453 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3455 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
3456 "[BTCoex], FW write 0x66=0x%x\n",
3457 h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
3460 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3463 void ex_halbtc8723b2ant_special_packet_notify(struct btc_coexist *btcoexist,
3466 if (type == BTC_PACKET_DHCP)
3467 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3468 "[BTCoex], DHCP Packet notify\n");
3471 void ex_halbtc8723b2ant_bt_info_notify(struct btc_coexist *btcoexist,
3472 u8 *tmpbuf, u8 length)
3475 u8 i, rsp_source = 0;
3476 bool bt_busy = false, limited_dig = false;
3477 bool wifi_connected = false;
3479 coex_sta->c2h_bt_info_req_sent = false;
3481 rsp_source = tmpbuf[0]&0xf;
3482 if (rsp_source >= BT_INFO_SRC_8723B_2ANT_MAX)
3483 rsp_source = BT_INFO_SRC_8723B_2ANT_WIFI_FW;
3484 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3486 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3487 "[BTCoex], Bt info[%d], length=%d, hex data=[",
3488 rsp_source, length);
3489 for (i = 0; i < length; i++) {
3490 coex_sta->bt_info_c2h[rsp_source][i] = tmpbuf[i];
3492 bt_info = tmpbuf[i];
3494 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3495 "0x%02x]\n", tmpbuf[i]);
3497 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3498 "0x%02x, ", tmpbuf[i]);
3501 if (btcoexist->manual_control) {
3502 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3503 "[BTCoex], BtInfoNotify(), "
3504 "return for Manual CTRL<===\n");
3508 if (BT_INFO_SRC_8723B_2ANT_WIFI_FW != rsp_source) {
3509 coex_sta->bt_retry_cnt = /* [3:0]*/
3510 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3513 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
3515 coex_sta->bt_info_ext =
3516 coex_sta->bt_info_c2h[rsp_source][4];
3518 /* Here we need to resend some wifi info to BT
3519 * because bt is reset and loss of the info.
3521 if ((coex_sta->bt_info_ext & BIT1)) {
3522 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3523 "[BTCoex], BT ext info bit1 check,"
3524 " send wifi BW&Chnl to BT!!\n");
3525 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3528 btc8723b_med_stat_notify(btcoexist,
3531 btc8723b_med_stat_notify(btcoexist,
3532 BTC_MEDIA_DISCONNECT);
3535 if ((coex_sta->bt_info_ext & BIT3)) {
3536 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3537 "[BTCoex], BT ext info bit3 check, "
3538 "set BT NOT to ignore Wlan active!!\n");
3539 btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC,
3542 /* BT already NOT ignore Wlan active, do nothing here.*/
3544 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0)
3545 if ((coex_sta->bt_info_ext & BIT4)) {
3546 /* BT auto report already enabled, do nothing*/
3548 btc8723b2ant_bt_auto_report(btcoexist, FORCE_EXEC,
3554 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
3555 if (bt_info & BT_INFO_8723B_2ANT_B_INQ_PAGE)
3556 coex_sta->c2h_bt_inquiry_page = true;
3558 coex_sta->c2h_bt_inquiry_page = false;
3560 /* set link exist status*/
3561 if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) {
3562 coex_sta->bt_link_exist = false;
3563 coex_sta->pan_exist = false;
3564 coex_sta->a2dp_exist = false;
3565 coex_sta->hid_exist = false;
3566 coex_sta->sco_exist = false;
3567 } else { /* connection exists */
3568 coex_sta->bt_link_exist = true;
3569 if (bt_info & BT_INFO_8723B_2ANT_B_FTP)
3570 coex_sta->pan_exist = true;
3572 coex_sta->pan_exist = false;
3573 if (bt_info & BT_INFO_8723B_2ANT_B_A2DP)
3574 coex_sta->a2dp_exist = true;
3576 coex_sta->a2dp_exist = false;
3577 if (bt_info & BT_INFO_8723B_2ANT_B_HID)
3578 coex_sta->hid_exist = true;
3580 coex_sta->hid_exist = false;
3581 if (bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO)
3582 coex_sta->sco_exist = true;
3584 coex_sta->sco_exist = false;
3587 btc8723b2ant_update_bt_link_info(btcoexist);
3589 if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) {
3590 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
3591 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3592 "[BTCoex], BtInfoNotify(), "
3593 "BT Non-Connected idle!!!\n");
3594 /* connection exists but no busy */
3595 } else if (bt_info == BT_INFO_8723B_2ANT_B_CONNECTION) {
3596 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE;
3597 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3598 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3599 } else if ((bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO) ||
3600 (bt_info & BT_INFO_8723B_2ANT_B_SCO_BUSY)) {
3601 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_SCO_BUSY;
3602 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3603 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3604 } else if (bt_info & BT_INFO_8723B_2ANT_B_ACL_BUSY) {
3605 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_ACL_BUSY;
3606 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3607 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3609 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_MAX;
3610 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3611 "[BTCoex], BtInfoNotify(), "
3612 "BT Non-Defined state!!!\n");
3615 if ((BT_8723B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3616 (BT_8723B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3617 (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
3622 limited_dig = false;
3625 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3627 coex_dm->limited_dig = limited_dig;
3628 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
3630 btc8723b2ant_run_coexist_mechanism(btcoexist);
3633 void ex_halbtc8723b2ant_stack_operation_notify(struct btc_coexist *btcoexist,
3636 if (BTC_STACK_OP_INQ_PAGE_PAIR_START == type)
3637 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3638 "[BTCoex],StackOP Inquiry/page/pair start notify\n");
3639 else if (BTC_STACK_OP_INQ_PAGE_PAIR_FINISH == type)
3640 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3641 "[BTCoex],StackOP Inquiry/page/pair finish notify\n");
3644 void ex_halbtc8723b2ant_halt_notify(struct btc_coexist *btcoexist)
3646 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, "[BTCoex], Halt notify\n");
3648 btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3649 btc8723b_med_stat_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3652 void ex_halbtc8723b2ant_periodical(struct btc_coexist *btcoexist)
3654 struct btc_board_info *board_info = &btcoexist->board_info;
3655 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3656 static u8 dis_ver_info_cnt;
3657 u32 fw_ver = 0, bt_patch_ver = 0;
3659 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3660 "[BTCoex], =========================="
3661 "Periodical===========================\n");
3663 if (dis_ver_info_cnt <= 5) {
3664 dis_ver_info_cnt += 1;
3665 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3666 "[BTCoex], ****************************"
3667 "************************************\n");
3668 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3669 "[BTCoex], Ant PG Num/ Ant Mech/ "
3670 "Ant Pos = %d/ %d/ %d\n", board_info->pg_ant_num,
3671 board_info->btdm_ant_num, board_info->btdm_ant_pos);
3672 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3673 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
3674 ((stack_info->profile_notified) ? "Yes" : "No"),
3675 stack_info->hci_version);
3676 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
3678 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3679 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3680 "[BTCoex], CoexVer/ FwVer/ PatchVer = "
3681 "%d_%x/ 0x%x/ 0x%x(%d)\n",
3682 glcoex_ver_date_8723b_2ant, glcoex_ver_8723b_2ant,
3683 fw_ver, bt_patch_ver, bt_patch_ver);
3684 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3685 "[BTCoex], *****************************"
3686 "***********************************\n");
3689 #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0)
3690 btc8723b2ant_query_bt_info(btcoexist);
3691 btc8723b2ant_monitor_bt_ctr(btcoexist);
3692 btc8723b2ant_monitor_bt_enable_disable(btcoexist);
3694 if (btc8723b2ant_is_wifi_status_changed(btcoexist) ||
3695 coex_dm->auto_tdma_adjust)
3696 btc8723b2ant_run_coexist_mechanism(btcoexist);