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 *****************************************************************************/
26 /*============================================================
29 * This file is for RTL8821A Co-exist mechanism
32 * 2012/08/22 Cosa first check in.
33 * 2012/11/14 Cosa Revise for 8821A 2Ant out sourcing.
35 *============================================================
38 /*============================================================
40 *============================================================
42 #include "halbt_precomp.h"
43 /*============================================================
44 * Global variables, these are static variables
45 *============================================================
47 static struct coex_dm_8821a_2ant glcoex_dm_8821a_2ant;
48 static struct coex_dm_8821a_2ant *coex_dm = &glcoex_dm_8821a_2ant;
49 static struct coex_sta_8821a_2ant glcoex_sta_8821a_2ant;
50 static struct coex_sta_8821a_2ant *coex_sta = &glcoex_sta_8821a_2ant;
52 static const char *const glbt_info_src_8821a_2ant[] = {
55 "BT Info[bt auto report]",
58 static u32 glcoex_ver_date_8821a_2ant = 20130618;
59 static u32 glcoex_ver_8821a_2ant = 0x5050;
61 /*============================================================
62 * local function proto type if needed
63 *============================================================
64 *============================================================
65 * local function start with halbtc8821a2ant_
66 *============================================================
68 static u8 halbtc8821a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh,
72 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
74 bt_rssi = coex_sta->bt_rssi;
77 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
78 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
79 long tmp = rssi_thresh +
80 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT;
82 bt_rssi_state = BTC_RSSI_STATE_HIGH;
83 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
84 "[BTCoex], BT Rssi state switch to High\n");
86 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
87 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
88 "[BTCoex], BT Rssi state stay at Low\n");
91 if (bt_rssi < rssi_thresh) {
92 bt_rssi_state = BTC_RSSI_STATE_LOW;
93 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
94 "[BTCoex], BT Rssi state switch to Low\n");
96 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
97 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
98 "[BTCoex], BT Rssi state stay at High\n");
101 } else if (level_num == 3) {
102 if (rssi_thresh > rssi_thresh1) {
103 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
104 "[BTCoex], BT Rssi thresh error!!\n");
105 return coex_sta->pre_bt_rssi_state;
108 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
109 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
111 (rssi_thresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
112 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
113 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
114 "[BTCoex], BT Rssi state switch to Medium\n");
116 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
117 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
118 "[BTCoex], BT Rssi state stay at Low\n");
120 } else if ((coex_sta->pre_bt_rssi_state ==
121 BTC_RSSI_STATE_MEDIUM) ||
122 (coex_sta->pre_bt_rssi_state ==
123 BTC_RSSI_STATE_STAY_MEDIUM)) {
126 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
127 bt_rssi_state = BTC_RSSI_STATE_HIGH;
128 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
129 "[BTCoex], BT Rssi state switch to High\n");
130 } else if (bt_rssi < rssi_thresh) {
131 bt_rssi_state = BTC_RSSI_STATE_LOW;
132 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
133 "[BTCoex], BT Rssi state switch to Low\n");
135 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
136 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
137 "[BTCoex], BT Rssi state stay at Medium\n");
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 switch to Medium\n");
145 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
146 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
147 "[BTCoex], BT Rssi state stay at High\n");
152 coex_sta->pre_bt_rssi_state = bt_rssi_state;
154 return bt_rssi_state;
157 static u8 halbtc8821a2ant_wifi_rssi_state(struct btc_coexist *btcoexist,
158 u8 index, u8 level_num,
159 u8 rssi_thresh, u8 rssi_thresh1)
162 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
164 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
166 if (level_num == 2) {
167 if ((coex_sta->pre_wifi_rssi_state[index] ==
168 BTC_RSSI_STATE_LOW) ||
169 (coex_sta->pre_wifi_rssi_state[index] ==
170 BTC_RSSI_STATE_STAY_LOW)) {
172 (rssi_thresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
173 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
174 BTC_PRINT(BTC_MSG_ALGORITHM,
175 ALGO_WIFI_RSSI_STATE,
176 "[BTCoex], wifi RSSI state switch to High\n");
178 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
179 BTC_PRINT(BTC_MSG_ALGORITHM,
180 ALGO_WIFI_RSSI_STATE,
181 "[BTCoex], wifi RSSI state stay at Low\n");
184 if (wifi_rssi < rssi_thresh) {
185 wifi_rssi_state = BTC_RSSI_STATE_LOW;
186 BTC_PRINT(BTC_MSG_ALGORITHM,
187 ALGO_WIFI_RSSI_STATE,
188 "[BTCoex], wifi RSSI state switch to Low\n");
190 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
191 BTC_PRINT(BTC_MSG_ALGORITHM,
192 ALGO_WIFI_RSSI_STATE,
193 "[BTCoex], wifi RSSI state stay at High\n");
196 } else if (level_num == 3) {
197 if (rssi_thresh > rssi_thresh1) {
198 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE,
199 "[BTCoex], wifi RSSI thresh error!!\n");
200 return coex_sta->pre_wifi_rssi_state[index];
203 if ((coex_sta->pre_wifi_rssi_state[index] ==
204 BTC_RSSI_STATE_LOW) ||
205 (coex_sta->pre_wifi_rssi_state[index] ==
206 BTC_RSSI_STATE_STAY_LOW)) {
208 (rssi_thresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
209 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
210 BTC_PRINT(BTC_MSG_ALGORITHM,
211 ALGO_WIFI_RSSI_STATE,
212 "[BTCoex], wifi RSSI state switch to Medium\n");
214 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
215 BTC_PRINT(BTC_MSG_ALGORITHM,
216 ALGO_WIFI_RSSI_STATE,
217 "[BTCoex], wifi RSSI state stay at Low\n");
219 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
220 BTC_RSSI_STATE_MEDIUM) ||
221 (coex_sta->pre_wifi_rssi_state[index] ==
222 BTC_RSSI_STATE_STAY_MEDIUM)) {
223 if (wifi_rssi >= (rssi_thresh1 +
224 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
225 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
226 BTC_PRINT(BTC_MSG_ALGORITHM,
227 ALGO_WIFI_RSSI_STATE,
228 "[BTCoex], wifi RSSI state switch to High\n");
229 } else if (wifi_rssi < rssi_thresh) {
230 wifi_rssi_state = BTC_RSSI_STATE_LOW;
231 BTC_PRINT(BTC_MSG_ALGORITHM,
232 ALGO_WIFI_RSSI_STATE,
233 "[BTCoex], wifi RSSI state switch to Low\n");
235 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
236 BTC_PRINT(BTC_MSG_ALGORITHM,
237 ALGO_WIFI_RSSI_STATE,
238 "[BTCoex], wifi RSSI state stay at Medium\n");
241 if (wifi_rssi < rssi_thresh1) {
242 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
243 BTC_PRINT(BTC_MSG_ALGORITHM,
244 ALGO_WIFI_RSSI_STATE,
245 "[BTCoex], wifi RSSI state switch to Medium\n");
247 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
248 BTC_PRINT(BTC_MSG_ALGORITHM,
249 ALGO_WIFI_RSSI_STATE,
250 "[BTCoex], wifi RSSI state stay at High\n");
254 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
256 return wifi_rssi_state;
259 static void btc8821a2ant_mon_bt_en_dis(struct btc_coexist *btcoexist)
261 static bool pre_bt_disabled;
262 static u32 bt_disable_cnt;
263 bool bt_active = true, bt_disabled = false;
265 /* This function check if bt is disabled*/
267 if (coex_sta->high_priority_tx == 0 &&
268 coex_sta->high_priority_rx == 0 &&
269 coex_sta->low_priority_tx == 0 &&
270 coex_sta->low_priority_rx == 0)
272 if (coex_sta->high_priority_tx == 0xffff &&
273 coex_sta->high_priority_rx == 0xffff &&
274 coex_sta->low_priority_tx == 0xffff &&
275 coex_sta->low_priority_rx == 0xffff)
280 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
282 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
283 "[BTCoex], BT is enabled !!\n");
286 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
287 "[BTCoex], bt all counters = 0, %d times!!\n",
289 if (bt_disable_cnt >= 2) {
291 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
293 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
294 "[BTCoex], BT is disabled !!\n");
297 if (pre_bt_disabled != bt_disabled) {
298 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
299 "[BTCoex], BT is from %s to %s!!\n",
300 (pre_bt_disabled ? "disabled" : "enabled"),
301 (bt_disabled ? "disabled" : "enabled"));
302 pre_bt_disabled = bt_disabled;
306 static void halbtc8821a2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
308 u32 reg_hp_txrx, reg_lp_txrx, u4tmp;
309 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
314 u4tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
315 reg_hp_tx = u4tmp & MASKLWORD;
316 reg_hp_rx = (u4tmp & MASKHWORD)>>16;
318 u4tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
319 reg_lp_tx = u4tmp & MASKLWORD;
320 reg_lp_rx = (u4tmp & MASKHWORD)>>16;
322 coex_sta->high_priority_tx = reg_hp_tx;
323 coex_sta->high_priority_rx = reg_hp_rx;
324 coex_sta->low_priority_tx = reg_lp_tx;
325 coex_sta->low_priority_rx = reg_lp_rx;
327 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
328 "[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
329 reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
330 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
331 "[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
332 reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
335 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
338 static void halbtc8821a2ant_query_bt_info(struct btc_coexist *btcoexist)
340 u8 h2c_parameter[1] = {0};
342 coex_sta->c2h_bt_info_req_sent = true;
344 h2c_parameter[0] |= BIT0; /* trigger */
346 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
347 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
350 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
353 static u8 halbtc8821a2ant_action_algorithm(struct btc_coexist *btcoexist)
355 struct btc_stack_info *stack_info = &btcoexist->stack_info;
356 bool bt_hs_on = false;
357 u8 algorithm = BT_8821A_2ANT_COEX_ALGO_UNDEFINED;
358 u8 num_of_diff_profile = 0;
360 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
362 /*for win-8 stack HID report error*/
363 /* sync BTInfo with BT firmware and stack */
364 if (!stack_info->hid_exist)
365 stack_info->hid_exist = coex_sta->hid_exist;
366 /* when stack HID report error, here we use the info from bt fw. */
367 if (!stack_info->bt_link_exist)
368 stack_info->bt_link_exist = coex_sta->bt_link_exist;
370 if (!coex_sta->bt_link_exist) {
371 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
372 "[BTCoex], No profile exists!!!\n");
376 if (coex_sta->sco_exist)
377 num_of_diff_profile++;
378 if (coex_sta->hid_exist)
379 num_of_diff_profile++;
380 if (coex_sta->pan_exist)
381 num_of_diff_profile++;
382 if (coex_sta->a2dp_exist)
383 num_of_diff_profile++;
385 if (num_of_diff_profile == 1) {
386 if (coex_sta->sco_exist) {
387 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
388 "[BTCoex], SCO only\n");
389 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
391 if (coex_sta->hid_exist) {
392 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
393 "[BTCoex], HID only\n");
394 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
395 } else if (coex_sta->a2dp_exist) {
396 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
397 "[BTCoex], A2DP only\n");
398 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;
399 } else if (coex_sta->pan_exist) {
401 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
402 "[BTCoex], PAN(HS) only\n");
403 algorithm = BT_8821A_2ANT_COEX_ALGO_PANHS;
405 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
406 "[BTCoex], PAN(EDR) only\n");
407 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR;
411 } else if (num_of_diff_profile == 2) {
412 if (coex_sta->sco_exist) {
413 if (coex_sta->hid_exist) {
414 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
415 "[BTCoex], SCO + HID\n");
416 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
417 } else if (coex_sta->a2dp_exist) {
418 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
419 "[BTCoex], SCO + A2DP ==> SCO\n");
420 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
421 } else if (coex_sta->pan_exist) {
423 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
424 "[BTCoex], SCO + PAN(HS)\n");
425 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
427 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
428 "[BTCoex], SCO + PAN(EDR)\n");
429 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
433 if (coex_sta->hid_exist &&
434 coex_sta->a2dp_exist) {
435 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
436 "[BTCoex], HID + A2DP\n");
437 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
438 } else if (coex_sta->hid_exist &&
439 coex_sta->pan_exist) {
441 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
442 "[BTCoex], HID + PAN(HS)\n");
443 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
445 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
446 "[BTCoex], HID + PAN(EDR)\n");
447 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
449 } else if (coex_sta->pan_exist &&
450 coex_sta->a2dp_exist) {
452 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
453 "[BTCoex], A2DP + PAN(HS)\n");
454 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;
456 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
457 "[BTCoex], A2DP + PAN(EDR)\n");
458 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;
462 } else if (num_of_diff_profile == 3) {
463 if (coex_sta->sco_exist) {
464 if (coex_sta->hid_exist &&
465 coex_sta->a2dp_exist) {
466 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
467 "[BTCoex], SCO + HID + A2DP ==> HID\n");
468 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
469 } else if (coex_sta->hid_exist &&
470 coex_sta->pan_exist) {
472 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
473 "[BTCoex], SCO + HID + PAN(HS)\n");
474 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
476 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
477 "[BTCoex], SCO + HID + PAN(EDR)\n");
478 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
480 } else if (coex_sta->pan_exist &&
481 coex_sta->a2dp_exist) {
483 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
484 "[BTCoex], SCO + A2DP + PAN(HS)\n");
485 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
487 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
488 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
489 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
493 if (coex_sta->hid_exist &&
494 coex_sta->pan_exist &&
495 coex_sta->a2dp_exist) {
497 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
498 "[BTCoex], HID + A2DP + PAN(HS)\n");
499 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
501 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
502 "[BTCoex], HID + A2DP + PAN(EDR)\n");
503 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
507 } else if (num_of_diff_profile >= 3) {
508 if (coex_sta->sco_exist) {
509 if (coex_sta->hid_exist &&
510 coex_sta->pan_exist &&
511 coex_sta->a2dp_exist) {
513 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
514 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
517 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
518 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
519 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
527 static bool halbtc8821a2ant_need_to_dec_bt_pwr(struct btc_coexist *btcoexist)
530 bool bt_hs_on = false, wifi_connected = false;
534 if (!btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on))
536 if (!btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
539 if (!btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi))
542 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
544 if (wifi_connected) {
546 if (bt_hs_rssi > 37) {
547 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
548 "[BTCoex], Need to decrease bt power for HS mode!!\n");
552 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
553 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
554 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
555 "[BTCoex], Need to decrease bt power for Wifi is connected!!\n");
563 static void btc8821a2ant_set_fw_dac_swing_lev(struct btc_coexist *btcoexist,
566 u8 h2c_parameter[1] = {0};
568 /* There are several type of dacswing
569 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
571 h2c_parameter[0] = dac_swing_lvl;
573 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
574 "[BTCoex], Set Dac Swing Level = 0x%x\n", dac_swing_lvl);
575 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
576 "[BTCoex], FW write 0x64 = 0x%x\n", h2c_parameter[0]);
578 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
581 static void halbtc8821a2ant_set_fw_dec_bt_pwr(struct btc_coexist *btcoexist,
584 u8 h2c_parameter[1] = {0};
586 h2c_parameter[0] = 0;
589 h2c_parameter[0] |= BIT1;
591 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
592 "[BTCoex], decrease Bt Power : %s, FW write 0x62 = 0x%x\n",
593 (dec_bt_pwr ? "Yes!!" : "No!!"), h2c_parameter[0]);
595 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
598 static void halbtc8821a2ant_dec_bt_pwr(struct btc_coexist *btcoexist,
599 bool force_exec, bool dec_bt_pwr)
601 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
602 "[BTCoex], %s Dec BT power = %s\n",
603 (force_exec ? "force to" : ""),
604 ((dec_bt_pwr) ? "ON" : "OFF"));
605 coex_dm->cur_dec_bt_pwr = dec_bt_pwr;
608 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
609 "[BTCoex], pre_dec_bt_pwr = %d, cur_dec_bt_pwr = %d\n",
610 coex_dm->pre_dec_bt_pwr, coex_dm->cur_dec_bt_pwr);
612 if (coex_dm->pre_dec_bt_pwr == coex_dm->cur_dec_bt_pwr)
615 halbtc8821a2ant_set_fw_dec_bt_pwr(btcoexist, coex_dm->cur_dec_bt_pwr);
617 coex_dm->pre_dec_bt_pwr = coex_dm->cur_dec_bt_pwr;
620 static void btc8821a2ant_set_fw_bt_lna_constr(struct btc_coexist *btcoexist,
623 u8 h2c_parameter[2] = {0};
625 h2c_parameter[0] = 0x3; /* opCode, 0x3 = BT_SET_LNA_CONSTRAIN */
628 h2c_parameter[1] |= BIT0;
630 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
631 "[BTCoex], set BT LNA Constrain: %s, FW write 0x69 = 0x%x\n",
632 (bt_lna_cons_on ? "ON!!" : "OFF!!"),
633 h2c_parameter[0]<<8|h2c_parameter[1]);
635 btcoexist->btc_fill_h2c(btcoexist, 0x69, 2, h2c_parameter);
638 static void btc8821a2_set_bt_lna_const(struct btc_coexist *btcoexist,
639 bool force_exec, bool bt_lna_cons_on)
641 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
642 "[BTCoex], %s BT Constrain = %s\n",
643 (force_exec ? "force" : ""),
644 ((bt_lna_cons_on) ? "ON" : "OFF"));
645 coex_dm->cur_bt_lna_constrain = bt_lna_cons_on;
648 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
649 "[BTCoex], pre_bt_lna_constrain = %d,cur_bt_lna_constrain = %d\n",
650 coex_dm->pre_bt_lna_constrain,
651 coex_dm->cur_bt_lna_constrain);
653 if (coex_dm->pre_bt_lna_constrain ==
654 coex_dm->cur_bt_lna_constrain)
657 btc8821a2ant_set_fw_bt_lna_constr(btcoexist,
658 coex_dm->cur_bt_lna_constrain);
660 coex_dm->pre_bt_lna_constrain = coex_dm->cur_bt_lna_constrain;
663 static void halbtc8821a2ant_set_fw_bt_psd_mode(struct btc_coexist *btcoexist,
666 u8 h2c_parameter[2] = {0};
668 h2c_parameter[0] = 0x2; /* opCode, 0x2 = BT_SET_PSD_MODE */
670 h2c_parameter[1] = bt_psd_mode;
672 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
673 "[BTCoex], set BT PSD mode = 0x%x, FW write 0x69 = 0x%x\n",
675 h2c_parameter[0]<<8|h2c_parameter[1]);
677 btcoexist->btc_fill_h2c(btcoexist, 0x69, 2, h2c_parameter);
680 static void halbtc8821a2ant_set_bt_psd_mode(struct btc_coexist *btcoexist,
681 bool force_exec, u8 bt_psd_mode)
683 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
684 "[BTCoex], %s BT PSD mode = 0x%x\n",
685 (force_exec ? "force" : ""), bt_psd_mode);
686 coex_dm->cur_bt_psd_mode = bt_psd_mode;
689 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
690 "[BTCoex], pre_bt_psd_mode = 0x%x, cur_bt_psd_mode = 0x%x\n",
691 coex_dm->pre_bt_psd_mode, coex_dm->cur_bt_psd_mode);
693 if (coex_dm->pre_bt_psd_mode == coex_dm->cur_bt_psd_mode)
696 halbtc8821a2ant_set_fw_bt_psd_mode(btcoexist,
697 coex_dm->cur_bt_psd_mode);
699 coex_dm->pre_bt_psd_mode = coex_dm->cur_bt_psd_mode;
702 static void halbtc8821a2ant_set_bt_auto_report(struct btc_coexist *btcoexist,
703 bool enable_auto_report)
705 u8 h2c_parameter[1] = {0};
707 h2c_parameter[0] = 0;
709 if (enable_auto_report)
710 h2c_parameter[0] |= BIT0;
712 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
713 "[BTCoex], BT FW auto report : %s, FW write 0x68 = 0x%x\n",
714 (enable_auto_report ? "Enabled!!" : "Disabled!!"),
717 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
720 static void halbtc8821a2ant_bt_auto_report(struct btc_coexist *btcoexist,
722 bool enable_auto_report)
724 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
725 "[BTCoex], %s BT Auto report = %s\n",
726 (force_exec ? "force to" : ""),
727 ((enable_auto_report) ? "Enabled" : "Disabled"));
728 coex_dm->cur_bt_auto_report = enable_auto_report;
731 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
732 "[BTCoex], pre_bt_auto_report = %d, cur_bt_auto_report = %d\n",
733 coex_dm->pre_bt_auto_report,
734 coex_dm->cur_bt_auto_report);
736 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
739 halbtc8821a2ant_set_bt_auto_report(btcoexist,
740 coex_dm->cur_bt_auto_report);
742 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
745 static void halbtc8821a2ant_fw_dac_swing_lvl(struct btc_coexist *btcoexist,
749 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
750 "[BTCoex], %s set FW Dac Swing level = %d\n",
751 (force_exec ? "force to" : ""), fw_dac_swing_lvl);
752 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
755 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
756 "[BTCoex], pre_fw_dac_swing_lvl = %d, cur_fw_dac_swing_lvl = %d\n",
757 coex_dm->pre_fw_dac_swing_lvl,
758 coex_dm->cur_fw_dac_swing_lvl);
760 if (coex_dm->pre_fw_dac_swing_lvl ==
761 coex_dm->cur_fw_dac_swing_lvl)
765 btc8821a2ant_set_fw_dac_swing_lev(btcoexist,
766 coex_dm->cur_fw_dac_swing_lvl);
768 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
771 static void btc8821a2ant_set_sw_rf_rx_lpf_corner(struct btc_coexist *btcoexist,
772 bool rx_rf_shrink_on)
774 if (rx_rf_shrink_on) {
775 /* Shrink RF Rx LPF corner */
776 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
777 "[BTCoex], Shrink RF Rx LPF corner!!\n");
778 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
781 /* Resume RF Rx LPF corner
782 * After initialized, we can use coex_dm->bt_rf0x1e_backup
784 if (btcoexist->initilized) {
785 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
786 "[BTCoex], Resume RF Rx LPF corner!!\n");
787 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
789 coex_dm->bt_rf0x1e_backup);
794 static void halbtc8821a2ant_RfShrink(struct btc_coexist *btcoexist,
795 bool force_exec, bool rx_rf_shrink_on)
797 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
798 "[BTCoex], %s turn Rx RF Shrink = %s\n",
799 (force_exec ? "force to" : ""),
800 ((rx_rf_shrink_on) ? "ON" : "OFF"));
801 coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
804 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
805 "[BTCoex], pre_rf_rx_lpf_shrink = %d, cur_rf_rx_lpf_shrink = %d\n",
806 coex_dm->pre_rf_rx_lpf_shrink,
807 coex_dm->cur_rf_rx_lpf_shrink);
809 if (coex_dm->pre_rf_rx_lpf_shrink ==
810 coex_dm->cur_rf_rx_lpf_shrink)
813 btc8821a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
814 coex_dm->cur_rf_rx_lpf_shrink);
816 coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
819 static void btc8821a2ant_SetSwPenTxRateAdapt(struct btc_coexist *btcoexist,
822 u8 h2c_parameter[6] = {0};
824 h2c_parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
826 if (low_penalty_ra) {
827 h2c_parameter[1] |= BIT0;
828 /*normal rate except MCS7/6/5, OFDM54/48/36 */
829 h2c_parameter[2] = 0x00;
831 h2c_parameter[3] = 0xf7;
833 h2c_parameter[4] = 0xf8;
835 h2c_parameter[5] = 0xf9;
838 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
839 "[BTCoex], set WiFi Low-Penalty Retry: %s",
840 (low_penalty_ra ? "ON!!" : "OFF!!"));
842 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
845 static void halbtc8821a2ant_low_penalty_ra(struct btc_coexist *btcoexist,
846 bool force_exec, bool low_penalty_ra)
849 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
850 "[BTCoex], %s turn LowPenaltyRA = %s\n",
851 (force_exec ? "force to" : ""),
852 ((low_penalty_ra) ? "ON" : "OFF"));
853 coex_dm->cur_low_penalty_ra = low_penalty_ra;
856 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
857 "[BTCoex], pre_low_penalty_ra = %d, cur_low_penalty_ra = %d\n",
858 coex_dm->pre_low_penalty_ra,
859 coex_dm->cur_low_penalty_ra);
861 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
864 btc8821a2ant_SetSwPenTxRateAdapt(btcoexist,
865 coex_dm->cur_low_penalty_ra);
867 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
870 static void halbtc8821a2ant_set_dac_swing_reg(struct btc_coexist *btcoexist,
875 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
876 "[BTCoex], Write SwDacSwing = 0x%x\n", level);
877 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
880 static void btc8821a2ant_set_sw_full_dac_swing(struct btc_coexist *btcoexist,
881 bool sw_dac_swing_on,
882 u32 sw_dac_swing_lvl)
885 halbtc8821a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
887 halbtc8821a2ant_set_dac_swing_reg(btcoexist, 0x18);
890 static void halbtc8821a2ant_dac_swing(struct btc_coexist *btcoexist,
891 bool force_exec, bool dac_swing_on,
894 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
895 "[BTCoex], %s turn DacSwing = %s, dac_swing_lvl = 0x%x\n",
896 (force_exec ? "force to" : ""),
897 ((dac_swing_on) ? "ON" : "OFF"),
899 coex_dm->cur_dac_swing_on = dac_swing_on;
900 coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
903 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
904 "[BTCoex], pre_dac_swing_on = %d, pre_dac_swing_lvl = 0x%x, cur_dac_swing_on = %d, cur_dac_swing_lvl = 0x%x\n",
905 coex_dm->pre_dac_swing_on,
906 coex_dm->pre_dac_swing_lvl,
907 coex_dm->cur_dac_swing_on,
908 coex_dm->cur_dac_swing_lvl);
910 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
911 (coex_dm->pre_dac_swing_lvl ==
912 coex_dm->cur_dac_swing_lvl))
916 btc8821a2ant_set_sw_full_dac_swing(btcoexist, dac_swing_on,
919 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
920 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
923 static void halbtc8821a2ant_set_adc_back_off(struct btc_coexist *btcoexist,
927 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
928 "[BTCoex], BB BackOff Level On!\n");
929 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
931 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
932 "[BTCoex], BB BackOff Level Off!\n");
933 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
937 static void halbtc8821a2ant_adc_back_off(struct btc_coexist *btcoexist,
938 bool force_exec, bool adc_back_off)
940 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
941 "[BTCoex], %s turn AdcBackOff = %s\n",
942 (force_exec ? "force to" : ""),
943 ((adc_back_off) ? "ON" : "OFF"));
944 coex_dm->cur_adc_back_off = adc_back_off;
947 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
948 "[BTCoex], pre_adc_back_off = %d, cur_adc_back_off = %d\n",
949 coex_dm->pre_adc_back_off, coex_dm->cur_adc_back_off);
951 if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
954 halbtc8821a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
956 coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
959 static void halbtc8821a2ant_set_coex_table(struct btc_coexist *btcoexist,
960 u32 val0x6c0, u32 val0x6c4,
961 u32 val0x6c8, u8 val0x6cc)
963 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
964 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
965 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
967 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
968 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
969 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
971 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
972 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
973 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
975 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
976 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
977 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
980 static void halbtc8821a2ant_coex_table(struct btc_coexist *btcoexist,
981 bool force_exec, u32 val0x6c0,
982 u32 val0x6c4, u32 val0x6c8, u8 val0x6cc)
984 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
985 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
986 (force_exec ? "force to" : ""),
987 val0x6c0, val0x6c4, val0x6c8, val0x6cc);
988 coex_dm->cur_val0x6c0 = val0x6c0;
989 coex_dm->cur_val0x6c4 = val0x6c4;
990 coex_dm->cur_val0x6c8 = val0x6c8;
991 coex_dm->cur_val0x6cc = val0x6cc;
994 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
995 "[BTCoex], pre_val0x6c0 = 0x%x, pre_val0x6c4 = 0x%x, pre_val0x6c8 = 0x%x, pre_val0x6cc = 0x%x !!\n",
996 coex_dm->pre_val0x6c0,
997 coex_dm->pre_val0x6c4,
998 coex_dm->pre_val0x6c8,
999 coex_dm->pre_val0x6cc);
1000 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL,
1001 "[BTCoex], cur_val0x6c0 = 0x%x, cur_val0x6c4 = 0x%x, cur_val0x6c8 = 0x%x, cur_val0x6cc = 0x%x !!\n",
1002 coex_dm->cur_val0x6c0,
1003 coex_dm->cur_val0x6c4,
1004 coex_dm->cur_val0x6c8,
1005 coex_dm->cur_val0x6cc);
1007 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1008 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1009 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1010 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1013 halbtc8821a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1016 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1017 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1018 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1019 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1022 static void halbtc8821a2ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoex,
1025 u8 h2c_parameter[1] = {0};
1028 h2c_parameter[0] |= BIT0;/* function enable */
1030 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
1031 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
1034 btcoex->btc_fill_h2c(btcoex, 0x63, 1, h2c_parameter);
1037 static void halbtc8821a2ant_ignore_wlan_act(struct btc_coexist *btcoexist,
1038 bool force_exec, bool enable)
1040 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
1041 "[BTCoex], %s turn Ignore WlanAct %s\n",
1042 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
1043 coex_dm->cur_ignore_wlan_act = enable;
1046 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1047 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
1048 coex_dm->pre_ignore_wlan_act,
1049 coex_dm->cur_ignore_wlan_act);
1051 if (coex_dm->pre_ignore_wlan_act ==
1052 coex_dm->cur_ignore_wlan_act)
1055 halbtc8821a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1057 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1060 static void halbtc8821a2ant_set_fw_pstdma(struct btc_coexist *btcoexist,
1061 u8 byte1, u8 byte2, u8 byte3,
1064 u8 h2c_parameter[5];
1066 h2c_parameter[0] = byte1;
1067 h2c_parameter[1] = byte2;
1068 h2c_parameter[2] = byte3;
1069 h2c_parameter[3] = byte4;
1070 h2c_parameter[4] = byte5;
1072 coex_dm->ps_tdma_para[0] = byte1;
1073 coex_dm->ps_tdma_para[1] = byte2;
1074 coex_dm->ps_tdma_para[2] = byte3;
1075 coex_dm->ps_tdma_para[3] = byte4;
1076 coex_dm->ps_tdma_para[4] = byte5;
1078 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
1079 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1081 h2c_parameter[1]<<24|
1082 h2c_parameter[2]<<16|
1083 h2c_parameter[3]<<8|
1086 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1089 static void btc8821a2ant_sw_mech1(struct btc_coexist *btcoexist,
1091 bool low_penalty_ra, bool limited_dig,
1092 bool bt_lna_constrain)
1096 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
1098 if (BTC_WIFI_BW_HT40 != wifi_bw) {
1099 /*only shrink RF Rx LPF for HT40*/
1101 shrink_rx_lpf = false;
1104 halbtc8821a2ant_RfShrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
1105 halbtc8821a2ant_low_penalty_ra(btcoexist,
1106 NORMAL_EXEC, low_penalty_ra);
1109 * btc8821a2_set_bt_lna_const(btcoexist,
1110 NORMAL_EXEC, bBTLNAConstrain);
1114 static void btc8821a2ant_sw_mech2(struct btc_coexist *btcoexist,
1115 bool agc_table_shift,
1116 bool adc_back_off, bool sw_dac_swing,
1119 /* halbtc8821a2ant_AgcTable(btcoexist, NORMAL_EXEC, bAGCTableShift); */
1120 halbtc8821a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off);
1121 halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1125 static void halbtc8821a2ant_set_ant_path(struct btc_coexist *btcoexist,
1126 u8 ant_pos_type, bool init_hw_cfg,
1129 struct btc_board_info *board_info = &btcoexist->board_info;
1131 u8 h2c_parameter[2] = {0};
1134 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
1135 u4tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1138 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4tmp);
1140 btcoexist->btc_write_4byte(btcoexist, 0x974, 0x3ff);
1141 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
1143 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
1144 /* tell firmware "antenna inverse" ==>
1145 * WRONG firmware antenna control code.
1148 h2c_parameter[0] = 1;
1149 h2c_parameter[1] = 1;
1150 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1153 /* tell firmware "no antenna inverse"
1154 * ==> WRONG firmware antenna control code.
1157 h2c_parameter[0] = 0;
1158 h2c_parameter[1] = 1;
1159 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1164 /* ext switch setting */
1165 switch (ant_pos_type) {
1166 case BTC_ANT_WIFI_AT_MAIN:
1167 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, 0x1);
1169 case BTC_ANT_WIFI_AT_AUX:
1170 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, 0x2);
1175 static void halbtc8821a2ant_ps_tdma(struct btc_coexist *btcoexist,
1176 bool force_exec, bool turn_on, u8 type)
1178 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
1179 "[BTCoex], %s turn %s PS TDMA, type = %d\n",
1180 (force_exec ? "force to" : ""), (turn_on ? "ON" : "OFF"),
1182 coex_dm->cur_ps_tdma_on = turn_on;
1183 coex_dm->cur_ps_tdma = type;
1186 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1187 "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n",
1188 coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on);
1189 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1190 "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n",
1191 coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma);
1193 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1194 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1201 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1205 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12,
1209 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1c,
1213 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x10,
1217 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1221 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12,
1225 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1c,
1229 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3, 0x10,
1233 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1237 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12,
1241 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa,
1245 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5,
1249 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1253 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1254 0x12, 0x12, 0x60, 0x90);
1257 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa,
1261 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5,
1265 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3, 0x2f,
1269 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5,
1273 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x25,
1277 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x25,
1281 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x15,
1285 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1290 /* disable PS tdma */
1293 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1297 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1301 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1307 /* update pre state */
1308 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1309 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1312 static void halbtc8821a2ant_coex_all_off(struct btc_coexist *btcoexist)
1315 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1316 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1317 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1320 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1321 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1324 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC,
1325 0x55555555, 0x55555555, 0xffff, 0x3);
1328 static void halbtc8821a2ant_coex_under_5g(struct btc_coexist *btcoexist)
1330 halbtc8821a2ant_coex_all_off(btcoexist);
1333 static void halbtc8821a2ant_init_coex_dm(struct btc_coexist *btcoexist)
1335 /* force to reset coex mechanism */
1336 halbtc8821a2ant_coex_table(btcoexist, FORCE_EXEC, 0x55555555,
1337 0x55555555, 0xffff, 0x3);
1339 halbtc8821a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1340 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1341 halbtc8821a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, false);
1343 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1344 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1347 static void halbtc8821a2ant_bt_inquiry_page(struct btc_coexist *btcoexist)
1349 bool low_pwr_disable = true;
1351 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1354 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
1355 0x5afa5afa, 0xffff, 0x3);
1356 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1359 static bool halbtc8821a2ant_is_common_action(struct btc_coexist *btcoexist)
1361 bool common = false, wifi_connected = false, wifi_busy = false;
1362 bool low_pwr_disable = false;
1364 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1366 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1368 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
1369 0x5afa5afa, 0xffff, 0x3);
1371 if (!wifi_connected &&
1372 BT_8821A_2ANT_BT_STATUS_IDLE == coex_dm->bt_status) {
1373 low_pwr_disable = false;
1374 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1377 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1378 "[BTCoex], Wifi IPS + BT IPS!!\n");
1380 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1381 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1382 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1384 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1385 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1388 } else if (wifi_connected &&
1389 (BT_8821A_2ANT_BT_STATUS_IDLE == coex_dm->bt_status)) {
1390 low_pwr_disable = false;
1391 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1395 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1396 "[BTCoex], Wifi Busy + BT IPS!!\n");
1397 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1400 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1401 "[BTCoex], Wifi LPS + BT IPS!!\n");
1402 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1406 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1407 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1409 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1410 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1413 } else if (!wifi_connected &&
1414 (BT_8821A_2ANT_BT_STATUS_CON_IDLE == coex_dm->bt_status)) {
1415 low_pwr_disable = true;
1416 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1419 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1420 "[BTCoex], Wifi IPS + BT LPS!!\n");
1422 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1423 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1424 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1426 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1427 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1429 } else if (wifi_connected &&
1430 (BT_8821A_2ANT_BT_STATUS_CON_IDLE == coex_dm->bt_status)) {
1431 low_pwr_disable = true;
1432 btcoexist->btc_set(btcoexist,
1433 BTC_SET_ACT_DISABLE_LOW_POWER, &low_pwr_disable);
1436 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1437 "[BTCoex], Wifi Busy + BT LPS!!\n");
1438 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1441 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1442 "[BTCoex], Wifi LPS + BT LPS!!\n");
1443 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1447 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1448 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1450 btc8821a2ant_sw_mech1(btcoexist, true, true, true, true);
1451 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1454 } else if (!wifi_connected &&
1455 (BT_8821A_2ANT_BT_STATUS_NON_IDLE ==
1456 coex_dm->bt_status)) {
1457 low_pwr_disable = false;
1458 btcoexist->btc_set(btcoexist,
1459 BTC_SET_ACT_DISABLE_LOW_POWER, &low_pwr_disable);
1461 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1462 "[BTCoex], Wifi IPS + BT Busy!!\n");
1464 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1465 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1466 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1468 btc8821a2ant_sw_mech1(btcoexist, false, false,
1470 btc8821a2ant_sw_mech2(btcoexist, false, false,
1475 low_pwr_disable = true;
1476 btcoexist->btc_set(btcoexist,
1477 BTC_SET_ACT_DISABLE_LOW_POWER,
1481 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1482 "[BTCoex], Wifi Busy + BT Busy!!\n");
1485 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
1486 "[BTCoex], Wifi LPS + BT Busy!!\n");
1487 halbtc8821a2ant_ps_tdma(btcoexist,
1488 NORMAL_EXEC, true, 21);
1490 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
1491 halbtc8821a2ant_dec_bt_pwr(btcoexist,
1494 halbtc8821a2ant_dec_bt_pwr(btcoexist,
1495 NORMAL_EXEC, false);
1499 btc8821a2ant_sw_mech1(btcoexist, true, true, true, true);
1504 static void btc8821a2_int1(struct btc_coexist *btcoexist, bool tx_pause,
1508 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1509 "[BTCoex], TxPause = 1\n");
1511 if (coex_dm->cur_ps_tdma == 71) {
1512 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1514 coex_dm->tdma_adj_type = 5;
1515 } else if (coex_dm->cur_ps_tdma == 1) {
1516 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1518 coex_dm->tdma_adj_type = 5;
1519 } else if (coex_dm->cur_ps_tdma == 2) {
1520 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1522 coex_dm->tdma_adj_type = 6;
1523 } else if (coex_dm->cur_ps_tdma == 3) {
1524 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1526 coex_dm->tdma_adj_type = 7;
1527 } else if (coex_dm->cur_ps_tdma == 4) {
1528 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1530 coex_dm->tdma_adj_type = 8;
1532 if (coex_dm->cur_ps_tdma == 9) {
1533 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1535 coex_dm->tdma_adj_type = 13;
1536 } else if (coex_dm->cur_ps_tdma == 10) {
1537 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1539 coex_dm->tdma_adj_type = 14;
1540 } else if (coex_dm->cur_ps_tdma == 11) {
1541 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1543 coex_dm->tdma_adj_type = 15;
1544 } else if (coex_dm->cur_ps_tdma == 12) {
1545 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1547 coex_dm->tdma_adj_type = 16;
1551 if (coex_dm->cur_ps_tdma == 5) {
1552 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1554 coex_dm->tdma_adj_type = 6;
1555 } else if (coex_dm->cur_ps_tdma == 6) {
1556 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1558 coex_dm->tdma_adj_type = 7;
1559 } else if (coex_dm->cur_ps_tdma == 7) {
1560 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1562 coex_dm->tdma_adj_type = 8;
1563 } else if (coex_dm->cur_ps_tdma == 13) {
1564 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1566 coex_dm->tdma_adj_type = 14;
1567 } else if (coex_dm->cur_ps_tdma == 14) {
1568 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1570 coex_dm->tdma_adj_type = 15;
1571 } else if (coex_dm->cur_ps_tdma == 15) {
1572 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1574 coex_dm->tdma_adj_type = 16;
1576 } else if (result == 1) {
1577 if (coex_dm->cur_ps_tdma == 8) {
1578 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1580 coex_dm->tdma_adj_type = 7;
1581 } else if (coex_dm->cur_ps_tdma == 7) {
1582 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1584 coex_dm->tdma_adj_type = 6;
1585 } else if (coex_dm->cur_ps_tdma == 6) {
1586 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1588 coex_dm->tdma_adj_type = 5;
1589 } else if (coex_dm->cur_ps_tdma == 16) {
1590 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1592 coex_dm->tdma_adj_type = 15;
1593 } else if (coex_dm->cur_ps_tdma == 15) {
1594 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1596 coex_dm->tdma_adj_type = 14;
1597 } else if (coex_dm->cur_ps_tdma == 14) {
1598 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1600 coex_dm->tdma_adj_type = 13;
1604 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1605 "[BTCoex], TxPause = 0\n");
1606 if (coex_dm->cur_ps_tdma == 5) {
1607 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1609 coex_dm->tdma_adj_type = 71;
1610 } else if (coex_dm->cur_ps_tdma == 6) {
1611 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1613 coex_dm->tdma_adj_type = 2;
1614 } else if (coex_dm->cur_ps_tdma == 7) {
1615 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1617 coex_dm->tdma_adj_type = 3;
1618 } else if (coex_dm->cur_ps_tdma == 8) {
1619 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1621 coex_dm->tdma_adj_type = 4;
1623 if (coex_dm->cur_ps_tdma == 13) {
1624 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1626 coex_dm->tdma_adj_type = 9;
1627 } else if (coex_dm->cur_ps_tdma == 14) {
1628 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1630 coex_dm->tdma_adj_type = 10;
1631 } else if (coex_dm->cur_ps_tdma == 15) {
1632 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1634 coex_dm->tdma_adj_type = 11;
1635 } else if (coex_dm->cur_ps_tdma == 16) {
1636 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1638 coex_dm->tdma_adj_type = 12;
1642 if (coex_dm->cur_ps_tdma == 71) {
1643 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1645 coex_dm->tdma_adj_type = 1;
1646 } else if (coex_dm->cur_ps_tdma == 1) {
1647 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1649 coex_dm->tdma_adj_type = 2;
1650 } else if (coex_dm->cur_ps_tdma == 2) {
1651 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1653 coex_dm->tdma_adj_type = 3;
1654 } else if (coex_dm->cur_ps_tdma == 3) {
1655 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1657 coex_dm->tdma_adj_type = 4;
1658 } else if (coex_dm->cur_ps_tdma == 9) {
1659 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1661 coex_dm->tdma_adj_type = 10;
1662 } else if (coex_dm->cur_ps_tdma == 10) {
1663 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1665 coex_dm->tdma_adj_type = 11;
1666 } else if (coex_dm->cur_ps_tdma == 11) {
1667 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1669 coex_dm->tdma_adj_type = 12;
1671 } else if (result == 1) {
1672 if (coex_dm->cur_ps_tdma == 4) {
1673 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1675 coex_dm->tdma_adj_type = 3;
1676 } else if (coex_dm->cur_ps_tdma == 3) {
1677 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1679 coex_dm->tdma_adj_type = 2;
1680 } else if (coex_dm->cur_ps_tdma == 2) {
1681 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1683 coex_dm->tdma_adj_type = 1;
1684 } else if (coex_dm->cur_ps_tdma == 1) {
1685 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1687 coex_dm->tdma_adj_type = 71;
1688 } else if (coex_dm->cur_ps_tdma == 12) {
1689 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1691 coex_dm->tdma_adj_type = 11;
1692 } else if (coex_dm->cur_ps_tdma == 11) {
1693 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1695 coex_dm->tdma_adj_type = 10;
1696 } else if (coex_dm->cur_ps_tdma == 10) {
1697 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1699 coex_dm->tdma_adj_type = 9;
1705 static void btc8821a2_int2(struct btc_coexist *btcoexist, bool tx_pause,
1709 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1710 "[BTCoex], TxPause = 1\n");
1711 if (coex_dm->cur_ps_tdma == 1) {
1712 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1714 coex_dm->tdma_adj_type = 6;
1715 } else if (coex_dm->cur_ps_tdma == 2) {
1716 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1718 coex_dm->tdma_adj_type = 6;
1719 } else if (coex_dm->cur_ps_tdma == 3) {
1720 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1722 coex_dm->tdma_adj_type = 7;
1723 } else if (coex_dm->cur_ps_tdma == 4) {
1724 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1726 coex_dm->tdma_adj_type = 8;
1728 if (coex_dm->cur_ps_tdma == 9) {
1729 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1731 coex_dm->tdma_adj_type = 14;
1732 } else if (coex_dm->cur_ps_tdma == 10) {
1733 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1735 coex_dm->tdma_adj_type = 14;
1736 } else if (coex_dm->cur_ps_tdma == 11) {
1737 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1739 coex_dm->tdma_adj_type = 15;
1740 } else if (coex_dm->cur_ps_tdma == 12) {
1741 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1743 coex_dm->tdma_adj_type = 16;
1746 if (coex_dm->cur_ps_tdma == 5) {
1747 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1749 coex_dm->tdma_adj_type = 6;
1750 } else if (coex_dm->cur_ps_tdma == 6) {
1751 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1753 coex_dm->tdma_adj_type = 7;
1754 } else if (coex_dm->cur_ps_tdma == 7) {
1755 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1757 coex_dm->tdma_adj_type = 8;
1758 } else if (coex_dm->cur_ps_tdma == 13) {
1759 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1761 coex_dm->tdma_adj_type = 14;
1762 } else if (coex_dm->cur_ps_tdma == 14) {
1763 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1765 coex_dm->tdma_adj_type = 15;
1766 } else if (coex_dm->cur_ps_tdma == 15) {
1767 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1769 coex_dm->tdma_adj_type = 16;
1771 } else if (result == 1) {
1772 if (coex_dm->cur_ps_tdma == 8) {
1773 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1775 coex_dm->tdma_adj_type = 7;
1776 } else if (coex_dm->cur_ps_tdma == 7) {
1777 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1779 coex_dm->tdma_adj_type = 6;
1780 } else if (coex_dm->cur_ps_tdma == 6) {
1781 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1783 coex_dm->tdma_adj_type = 6;
1784 } else if (coex_dm->cur_ps_tdma == 16) {
1785 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1787 coex_dm->tdma_adj_type = 15;
1788 } else if (coex_dm->cur_ps_tdma == 15) {
1789 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1791 coex_dm->tdma_adj_type = 14;
1792 } else if (coex_dm->cur_ps_tdma == 14) {
1793 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1795 coex_dm->tdma_adj_type = 14;
1799 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1800 "[BTCoex], TxPause = 0\n");
1801 if (coex_dm->cur_ps_tdma == 5) {
1802 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1804 coex_dm->tdma_adj_type = 2;
1805 } else if (coex_dm->cur_ps_tdma == 6) {
1806 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1808 coex_dm->tdma_adj_type = 2;
1809 } else if (coex_dm->cur_ps_tdma == 7) {
1810 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1812 coex_dm->tdma_adj_type = 3;
1813 } else if (coex_dm->cur_ps_tdma == 8) {
1814 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1816 coex_dm->tdma_adj_type = 4;
1818 if (coex_dm->cur_ps_tdma == 13) {
1819 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1821 coex_dm->tdma_adj_type = 10;
1822 } else if (coex_dm->cur_ps_tdma == 14) {
1823 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1825 coex_dm->tdma_adj_type = 10;
1826 } else if (coex_dm->cur_ps_tdma == 15) {
1827 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1829 coex_dm->tdma_adj_type = 11;
1830 } else if (coex_dm->cur_ps_tdma == 16) {
1831 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1833 coex_dm->tdma_adj_type = 12;
1836 if (coex_dm->cur_ps_tdma == 1) {
1837 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1839 coex_dm->tdma_adj_type = 2;
1840 } else if (coex_dm->cur_ps_tdma == 2) {
1841 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1843 coex_dm->tdma_adj_type = 3;
1844 } else if (coex_dm->cur_ps_tdma == 3) {
1845 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1847 coex_dm->tdma_adj_type = 4;
1848 } else if (coex_dm->cur_ps_tdma == 9) {
1849 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1851 coex_dm->tdma_adj_type = 10;
1852 } else if (coex_dm->cur_ps_tdma == 10) {
1853 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1855 coex_dm->tdma_adj_type = 11;
1856 } else if (coex_dm->cur_ps_tdma == 11) {
1857 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1859 coex_dm->tdma_adj_type = 12;
1861 } else if (result == 1) {
1862 if (coex_dm->cur_ps_tdma == 4) {
1863 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1865 coex_dm->tdma_adj_type = 3;
1866 } else if (coex_dm->cur_ps_tdma == 3) {
1867 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1869 coex_dm->tdma_adj_type = 2;
1870 } else if (coex_dm->cur_ps_tdma == 2) {
1871 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1873 coex_dm->tdma_adj_type = 2;
1874 } else if (coex_dm->cur_ps_tdma == 12) {
1875 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1877 coex_dm->tdma_adj_type = 11;
1878 } else if (coex_dm->cur_ps_tdma == 11) {
1879 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1881 coex_dm->tdma_adj_type = 10;
1882 } else if (coex_dm->cur_ps_tdma == 10) {
1883 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1885 coex_dm->tdma_adj_type = 10;
1891 static void btc8821a2_int3(struct btc_coexist *btcoexist, bool tx_pause,
1895 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1896 "[BTCoex], TxPause = 1\n");
1897 if (coex_dm->cur_ps_tdma == 1) {
1898 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1900 coex_dm->tdma_adj_type = 7;
1901 } else if (coex_dm->cur_ps_tdma == 2) {
1902 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1904 coex_dm->tdma_adj_type = 7;
1905 } else if (coex_dm->cur_ps_tdma == 3) {
1906 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1908 coex_dm->tdma_adj_type = 7;
1909 } else if (coex_dm->cur_ps_tdma == 4) {
1910 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1912 coex_dm->tdma_adj_type = 8;
1914 if (coex_dm->cur_ps_tdma == 9) {
1915 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1917 coex_dm->tdma_adj_type = 15;
1918 } else if (coex_dm->cur_ps_tdma == 10) {
1919 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1921 coex_dm->tdma_adj_type = 15;
1922 } else if (coex_dm->cur_ps_tdma == 11) {
1923 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1925 coex_dm->tdma_adj_type = 15;
1926 } else if (coex_dm->cur_ps_tdma == 12) {
1927 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1929 coex_dm->tdma_adj_type = 16;
1932 if (coex_dm->cur_ps_tdma == 5) {
1933 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1935 coex_dm->tdma_adj_type = 7;
1936 } else if (coex_dm->cur_ps_tdma == 6) {
1937 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1939 coex_dm->tdma_adj_type = 7;
1940 } else if (coex_dm->cur_ps_tdma == 7) {
1941 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1943 coex_dm->tdma_adj_type = 8;
1944 } else if (coex_dm->cur_ps_tdma == 13) {
1945 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1947 coex_dm->tdma_adj_type = 15;
1948 } else if (coex_dm->cur_ps_tdma == 14) {
1949 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1951 coex_dm->tdma_adj_type = 15;
1952 } else if (coex_dm->cur_ps_tdma == 15) {
1953 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1955 coex_dm->tdma_adj_type = 16;
1957 } else if (result == 1) {
1958 if (coex_dm->cur_ps_tdma == 8) {
1959 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1961 coex_dm->tdma_adj_type = 7;
1962 } else if (coex_dm->cur_ps_tdma == 7) {
1963 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1965 coex_dm->tdma_adj_type = 7;
1966 } else if (coex_dm->cur_ps_tdma == 6) {
1967 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1969 coex_dm->tdma_adj_type = 7;
1970 } else if (coex_dm->cur_ps_tdma == 16) {
1971 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1973 coex_dm->tdma_adj_type = 15;
1974 } else if (coex_dm->cur_ps_tdma == 15) {
1975 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1977 coex_dm->tdma_adj_type = 15;
1978 } else if (coex_dm->cur_ps_tdma == 14) {
1979 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1981 coex_dm->tdma_adj_type = 15;
1985 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
1986 "[BTCoex], TxPause = 0\n");
1987 if (coex_dm->cur_ps_tdma == 5) {
1988 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1990 coex_dm->tdma_adj_type = 3;
1991 } else if (coex_dm->cur_ps_tdma == 6) {
1992 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1994 coex_dm->tdma_adj_type = 3;
1995 } else if (coex_dm->cur_ps_tdma == 7) {
1996 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1998 coex_dm->tdma_adj_type = 3;
1999 } else if (coex_dm->cur_ps_tdma == 8) {
2000 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2002 coex_dm->tdma_adj_type = 4;
2004 if (coex_dm->cur_ps_tdma == 13) {
2005 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2007 coex_dm->tdma_adj_type = 11;
2008 } else if (coex_dm->cur_ps_tdma == 14) {
2009 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2011 coex_dm->tdma_adj_type = 11;
2012 } else if (coex_dm->cur_ps_tdma == 15) {
2013 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2015 coex_dm->tdma_adj_type = 11;
2016 } else if (coex_dm->cur_ps_tdma == 16) {
2017 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2019 coex_dm->tdma_adj_type = 12;
2022 if (coex_dm->cur_ps_tdma == 1) {
2023 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2025 coex_dm->tdma_adj_type = 3;
2026 } else if (coex_dm->cur_ps_tdma == 2) {
2027 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2029 coex_dm->tdma_adj_type = 3;
2030 } else if (coex_dm->cur_ps_tdma == 3) {
2031 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2033 coex_dm->tdma_adj_type = 4;
2034 } else if (coex_dm->cur_ps_tdma == 9) {
2035 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2037 coex_dm->tdma_adj_type = 11;
2038 } else if (coex_dm->cur_ps_tdma == 10) {
2039 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2041 coex_dm->tdma_adj_type = 11;
2042 } else if (coex_dm->cur_ps_tdma == 11) {
2043 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2045 coex_dm->tdma_adj_type = 12;
2047 } else if (result == 1) {
2048 if (coex_dm->cur_ps_tdma == 4) {
2049 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2051 coex_dm->tdma_adj_type = 3;
2052 } else if (coex_dm->cur_ps_tdma == 3) {
2053 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2055 coex_dm->tdma_adj_type = 3;
2056 } else if (coex_dm->cur_ps_tdma == 2) {
2057 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2059 coex_dm->tdma_adj_type = 3;
2060 } else if (coex_dm->cur_ps_tdma == 12) {
2061 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2063 coex_dm->tdma_adj_type = 11;
2064 } else if (coex_dm->cur_ps_tdma == 11) {
2065 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2067 coex_dm->tdma_adj_type = 11;
2068 } else if (coex_dm->cur_ps_tdma == 10) {
2069 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2071 coex_dm->tdma_adj_type = 11;
2077 static void btc8821a2ant_tdma_dur_adj(struct btc_coexist *btcoexist,
2078 bool sco_hid, bool tx_pause,
2081 static long up, dn, m, n, wait_count;
2082 /* 0: no change, +1: increase WiFi duration,
2083 * -1: decrease WiFi duration
2088 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
2089 "[BTCoex], TdmaDurationAdjust()\n");
2091 if (coex_dm->reset_tdma_adjust) {
2092 coex_dm->reset_tdma_adjust = false;
2093 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2094 "[BTCoex], first run TdmaDurationAdjust()!!\n");
2097 if (max_interval == 1) {
2098 halbtc8821a2ant_ps_tdma(btcoexist,
2101 coex_dm->tdma_adj_type = 13;
2102 } else if (max_interval == 2) {
2103 halbtc8821a2ant_ps_tdma(btcoexist,
2106 coex_dm->tdma_adj_type = 14;
2107 } else if (max_interval == 3) {
2108 halbtc8821a2ant_ps_tdma(btcoexist,
2111 coex_dm->tdma_adj_type = 15;
2113 halbtc8821a2ant_ps_tdma(btcoexist,
2116 coex_dm->tdma_adj_type = 15;
2119 if (max_interval == 1) {
2120 halbtc8821a2ant_ps_tdma(btcoexist,
2123 coex_dm->tdma_adj_type = 9;
2124 } else if (max_interval == 2) {
2125 halbtc8821a2ant_ps_tdma(btcoexist,
2128 coex_dm->tdma_adj_type = 10;
2129 } else if (max_interval == 3) {
2130 halbtc8821a2ant_ps_tdma(btcoexist,
2133 coex_dm->tdma_adj_type = 11;
2135 halbtc8821a2ant_ps_tdma(btcoexist,
2138 coex_dm->tdma_adj_type = 11;
2143 if (max_interval == 1) {
2144 halbtc8821a2ant_ps_tdma(btcoexist,
2147 coex_dm->tdma_adj_type = 5;
2148 } else if (max_interval == 2) {
2149 halbtc8821a2ant_ps_tdma(btcoexist,
2152 coex_dm->tdma_adj_type = 6;
2153 } else if (max_interval == 3) {
2154 halbtc8821a2ant_ps_tdma(btcoexist,
2157 coex_dm->tdma_adj_type = 7;
2159 halbtc8821a2ant_ps_tdma(btcoexist,
2162 coex_dm->tdma_adj_type = 7;
2165 if (max_interval == 1) {
2166 halbtc8821a2ant_ps_tdma(btcoexist,
2169 coex_dm->tdma_adj_type = 1;
2170 } else if (max_interval == 2) {
2171 halbtc8821a2ant_ps_tdma(btcoexist,
2174 coex_dm->tdma_adj_type = 2;
2175 } else if (max_interval == 3) {
2176 halbtc8821a2ant_ps_tdma(btcoexist,
2179 coex_dm->tdma_adj_type = 3;
2181 halbtc8821a2ant_ps_tdma(btcoexist,
2184 coex_dm->tdma_adj_type = 3;
2196 /* accquire the BT TRx retry count from BT_Info byte2 */
2197 retry_count = coex_sta->bt_retry_cnt;
2198 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2199 "[BTCoex], retry_count = %d\n", retry_count);
2200 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2201 "[BTCoex], up = %d, dn = %d, m = %d, n = %d, wait_count = %d\n",
2202 (int)up, (int)dn, (int)m, (int)n, (int)wait_count);
2206 if (retry_count == 0) {
2207 /* no retry in the last 2-second duration */
2215 /* if (retry count == 0) for 2*n seconds,
2216 * make WiFi duration wider
2223 BTC_PRINT(BTC_MSG_ALGORITHM,
2224 ALGO_TRACE_FW_DETAIL,
2225 "[BTCoex], Increase wifi duration!!\n");
2227 } else if (retry_count <= 3) {
2228 /* <=3 retry in the last 2-second duration */
2236 /* if retry count< 3 for 2*2 seconds,
2237 * shrink wifi duration
2239 if (wait_count <= 2)
2240 m++; /* avoid bounce in two levels */
2243 /* m max value is 20, max time is 120 second,
2244 * recheck if adjust WiFi duration.
2254 BTC_PRINT(BTC_MSG_ALGORITHM,
2255 ALGO_TRACE_FW_DETAIL,
2256 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
2259 /* retry count > 3, if retry count > 3 happens once,
2260 * shrink WiFi duration
2262 if (wait_count == 1)
2263 m++; /* avoid bounce in two levels */
2266 /* m max value is 20, max time is 120 second,
2267 * recheck if adjust WiFi duration.
2277 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2278 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
2281 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2282 "[BTCoex], max Interval = %d\n", max_interval);
2283 if (max_interval == 1)
2284 btc8821a2_int1(btcoexist, tx_pause, result);
2285 else if (max_interval == 2)
2286 btc8821a2_int2(btcoexist, tx_pause, result);
2287 else if (max_interval == 3)
2288 btc8821a2_int3(btcoexist, tx_pause, result);
2291 /* if current PsTdma not match with the recorded one
2292 * (when scan, dhcp...), then we have to adjust it back to
2293 * the previous recorded one.
2295 if (coex_dm->cur_ps_tdma != coex_dm->tdma_adj_type) {
2296 bool scan = false, link = false, roam = false;
2298 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2299 "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma = %d, recordPsTdma = %d\n",
2300 coex_dm->cur_ps_tdma, coex_dm->tdma_adj_type);
2302 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2303 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2304 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2306 if (!scan && !link && !roam) {
2307 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2308 coex_dm->tdma_adj_type);
2310 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
2311 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2315 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6);
2318 /* SCO only or SCO+PAN(HS)*/
2319 static void halbtc8821a2ant_action_sco(struct btc_coexist *btcoexist)
2321 u8 wifi_rssi_state, bt_rssi_state;
2324 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2326 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2328 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
2330 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2331 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2333 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2335 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2337 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2338 /* for SCO quality at 11b/g mode */
2339 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC,
2340 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);
2342 /* for SCO quality & wifi performance balance at 11n mode */
2343 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC,
2344 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3);
2347 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2349 * halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2352 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2353 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2354 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2355 false, 0); /*for voice quality*/
2357 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2358 false, 0); /*for voice quality*/
2362 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2363 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2364 btc8821a2ant_sw_mech1(btcoexist, true, true,
2366 btc8821a2ant_sw_mech2(btcoexist, true, false,
2369 btc8821a2ant_sw_mech1(btcoexist, true, true,
2371 btc8821a2ant_sw_mech2(btcoexist, false, false,
2376 * halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2378 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2379 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2380 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2381 false, 0); /*for voice quality*/
2383 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2384 false, 0); /*for voice quality*/
2388 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2389 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2390 btc8821a2ant_sw_mech1(btcoexist, false, true,
2392 btc8821a2ant_sw_mech2(btcoexist, true, false,
2395 btc8821a2ant_sw_mech1(btcoexist, false, true,
2397 btc8821a2ant_sw_mech2(btcoexist, false, false,
2403 static void halbtc8821a2ant_action_hid(struct btc_coexist *btcoexist)
2405 u8 wifi_rssi_state, bt_rssi_state;
2408 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist,
2410 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2412 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2414 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2415 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2417 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2419 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2421 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2422 /* for HID at 11b/g mode */
2423 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2424 0x5a5a5a5a, 0xffff, 0x3);
2426 /* for HID quality & wifi performance balance at 11n mode */
2427 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2428 0x5aea5aea, 0xffff, 0x3);
2431 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2433 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2434 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2435 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2438 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2443 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2444 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2445 btc8821a2ant_sw_mech1(btcoexist, true, true,
2447 btc8821a2ant_sw_mech2(btcoexist, true, false,
2450 btc8821a2ant_sw_mech1(btcoexist, true, true,
2452 btc8821a2ant_sw_mech2(btcoexist, false, false,
2457 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2458 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2459 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2462 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2467 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2468 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2469 btc8821a2ant_sw_mech1(btcoexist, false, true,
2471 btc8821a2ant_sw_mech2(btcoexist, true, false,
2474 btc8821a2ant_sw_mech1(btcoexist, false, true,
2476 btc8821a2ant_sw_mech2(btcoexist, false, false,
2482 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2483 static void halbtc8821a2ant_action_a2dp(struct btc_coexist *btcoexist)
2485 u8 wifi_rssi_state, bt_rssi_state;
2488 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2490 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2492 /* fw dac swing is called in btc8821a2ant_tdma_dur_adj()
2493 * halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2496 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2497 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2499 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2501 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2503 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2505 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2506 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2507 btc8821a2ant_tdma_dur_adj(btcoexist, false, false, 1);
2509 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2513 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2514 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2515 btc8821a2ant_sw_mech1(btcoexist, true, false,
2517 btc8821a2ant_sw_mech2(btcoexist, true, false,
2520 btc8821a2ant_sw_mech1(btcoexist, true, false,
2522 btc8821a2ant_sw_mech2(btcoexist, false, false,
2527 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2528 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2529 btc8821a2ant_tdma_dur_adj(btcoexist, false, false, 1);
2531 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2535 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2536 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2537 btc8821a2ant_sw_mech1(btcoexist, false, false,
2539 btc8821a2ant_sw_mech2(btcoexist, true, false,
2542 btc8821a2ant_sw_mech1(btcoexist, false, false,
2544 btc8821a2ant_sw_mech2(btcoexist, false, false,
2550 static void halbtc8821a2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2552 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
2555 bt_info_ext = coex_sta->bt_info_ext;
2556 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2558 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2560 /*fw dac swing is called in btc8821a2ant_tdma_dur_adj()
2561 *halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2564 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2565 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2567 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2569 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2571 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2573 if (bt_info_ext&BIT0) {
2575 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 2);
2578 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2582 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2583 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2584 btc8821a2ant_sw_mech1(btcoexist, true, false,
2586 btc8821a2ant_sw_mech2(btcoexist, true, false,
2589 btc8821a2ant_sw_mech1(btcoexist, true, false,
2591 btc8821a2ant_sw_mech2(btcoexist, false, false,
2596 if (bt_info_ext&BIT0) {
2597 /* a2dp basic rate */
2598 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 2);
2601 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2605 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2606 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2607 btc8821a2ant_sw_mech1(btcoexist, false, false,
2609 btc8821a2ant_sw_mech2(btcoexist, true, false,
2612 btc8821a2ant_sw_mech1(btcoexist, false, false,
2614 btc8821a2ant_sw_mech2(btcoexist, false, false,
2620 static void halbtc8821a2ant_action_pan_edr(struct btc_coexist *btcoexist)
2622 u8 wifi_rssi_state, bt_rssi_state;
2625 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2627 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2629 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2631 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2632 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2634 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2636 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2638 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2639 /* for HID at 11b/g mode */
2640 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2641 0x5aff5aff, 0xffff, 0x3);
2643 /* for HID quality & wifi performance balance at 11n mode */
2644 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2645 0x5aff5aff, 0xffff, 0x3);
2648 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2650 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2651 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2652 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2655 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2660 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2661 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2662 btc8821a2ant_sw_mech1(btcoexist, true, false,
2664 btc8821a2ant_sw_mech2(btcoexist, true, false,
2667 btc8821a2ant_sw_mech1(btcoexist, true, false,
2669 btc8821a2ant_sw_mech2(btcoexist, false, false,
2674 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2675 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2676 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2679 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2684 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2685 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2686 btc8821a2ant_sw_mech1(btcoexist, false, false,
2688 btc8821a2ant_sw_mech2(btcoexist, true, false,
2691 btc8821a2ant_sw_mech1(btcoexist, false, false,
2693 btc8821a2ant_sw_mech2(btcoexist, false, false,
2700 static void halbtc8821a2ant_action_pan_hs(struct btc_coexist *btcoexist)
2702 u8 wifi_rssi_state, bt_rssi_state;
2705 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist,
2707 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2709 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2711 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2713 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2715 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2716 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2717 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
2720 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
2723 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
2726 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2727 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2728 btc8821a2ant_sw_mech1(btcoexist, true, false,
2730 btc8821a2ant_sw_mech2(btcoexist, true, false,
2733 btc8821a2ant_sw_mech1(btcoexist, true, false,
2735 btc8821a2ant_sw_mech2(btcoexist, false, false,
2740 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2741 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2742 halbtc8821a2ant_dec_bt_pwr(btcoexist,
2745 halbtc8821a2ant_dec_bt_pwr(btcoexist,
2746 NORMAL_EXEC, false);
2749 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2750 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2751 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2754 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2759 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2760 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2761 btc8821a2ant_sw_mech1(btcoexist, false, false,
2763 btc8821a2ant_sw_mech2(btcoexist, true, false,
2766 btc8821a2ant_sw_mech1(btcoexist, false, false,
2768 btc8821a2ant_sw_mech2(btcoexist, false, false,
2775 static void halbtc8821a2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
2777 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
2780 bt_info_ext = coex_sta->bt_info_ext;
2781 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2783 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2785 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2787 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2788 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2790 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2792 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2794 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2795 /* for HID at 11b/g mode */
2796 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2797 0x5afa5afa, 0xffff, 0x3);
2799 /* for HID quality & wifi performance balance at 11n mode */
2800 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2801 0x5afa5afa, 0xffff, 0x3);
2804 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2806 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2807 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2808 if (bt_info_ext&BIT0) {
2809 /* a2dp basic rate */
2810 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2814 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2818 if (bt_info_ext&BIT0) {
2819 /* a2dp basic rate */
2820 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2824 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2830 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2831 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2832 btc8821a2ant_sw_mech1(btcoexist, true, false,
2834 btc8821a2ant_sw_mech2(btcoexist, true, false,
2837 btc8821a2ant_sw_mech1(btcoexist, true, false,
2839 btc8821a2ant_sw_mech2(btcoexist, false, false,
2844 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2845 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2846 if (bt_info_ext&BIT0) {
2847 /* a2dp basic rate */
2848 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2852 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2856 if (bt_info_ext&BIT0) {
2857 /* a2dp basic rate */
2858 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2862 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2868 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2869 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2870 btc8821a2ant_sw_mech1(btcoexist, false, false,
2872 btc8821a2ant_sw_mech2(btcoexist, true, false,
2875 btc8821a2ant_sw_mech1(btcoexist, false, false,
2877 btc8821a2ant_sw_mech2(btcoexist, false, false,
2883 static void halbtc8821a2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
2885 u8 wifi_rssi_state, bt_rssi_state;
2888 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2890 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2892 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2894 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2895 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2897 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2899 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2901 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2902 /* for HID at 11b/g mode */
2903 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2904 0x5a5f5a5f, 0xffff, 0x3);
2906 /* for HID quality & wifi performance balance at 11n mode */
2907 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2908 0x5a5f5a5f, 0xffff, 0x3);
2911 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2912 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 3);
2914 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2915 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2916 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2919 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2924 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2925 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2926 btc8821a2ant_sw_mech1(btcoexist, true, true,
2928 btc8821a2ant_sw_mech2(btcoexist, true, false,
2931 btc8821a2ant_sw_mech1(btcoexist, true, true,
2933 btc8821a2ant_sw_mech2(btcoexist, false, false,
2937 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2939 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2940 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2941 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2944 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2949 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2950 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2951 btc8821a2ant_sw_mech1(btcoexist, false, true,
2953 btc8821a2ant_sw_mech2(btcoexist, true, false,
2956 btc8821a2ant_sw_mech1(btcoexist, false, true,
2958 btc8821a2ant_sw_mech2(btcoexist, false, false,
2964 /* HID+A2DP+PAN(EDR) */
2965 static void btc8821a2ant_act_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
2967 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
2970 bt_info_ext = coex_sta->bt_info_ext;
2971 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist,
2973 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2975 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2977 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2978 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2980 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2982 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2984 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2985 /* for HID at 11b/g mode */
2986 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2987 0x5a5a5a5a, 0xffff, 0x3);
2989 /* for HID quality & wifi performance balance at 11n mode */
2990 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2991 0x5a5a5a5a, 0xffff, 0x3);
2994 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2996 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2997 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2998 if (bt_info_ext&BIT0) {
2999 /* a2dp basic rate */
3000 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3004 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3008 if (bt_info_ext&BIT0) {
3009 /* a2dp basic rate */
3010 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3014 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3020 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3021 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3022 btc8821a2ant_sw_mech1(btcoexist, true, true,
3024 btc8821a2ant_sw_mech2(btcoexist, true, false,
3027 btc8821a2ant_sw_mech1(btcoexist, true, true,
3029 btc8821a2ant_sw_mech2(btcoexist, false, false,
3034 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3035 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3036 if (bt_info_ext&BIT0) {
3037 /* a2dp basic rate */
3038 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3042 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3046 if (bt_info_ext&BIT0) {
3047 /* a2dp basic rate */
3048 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3052 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3058 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3059 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3060 btc8821a2ant_sw_mech1(btcoexist, false, true,
3062 btc8821a2ant_sw_mech2(btcoexist, true, false,
3065 btc8821a2ant_sw_mech1(btcoexist, false, true,
3067 btc8821a2ant_sw_mech2(btcoexist, false, false,
3073 static void halbtc8821a2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
3075 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
3078 bt_info_ext = coex_sta->bt_info_ext;
3079 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
3081 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
3083 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
3084 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
3086 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
3088 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3090 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
3091 /* for HID at 11b/g mode */
3092 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3093 0x5f5b5f5b, 0xffffff, 0x3);
3095 /*for HID quality & wifi performance balance at 11n mode*/
3096 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3097 0x5f5b5f5b, 0xffffff, 0x3);
3100 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3102 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3103 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3104 if (bt_info_ext&BIT0) {
3105 /* a2dp basic rate */
3106 btc8821a2ant_tdma_dur_adj(btcoexist,
3110 btc8821a2ant_tdma_dur_adj(btcoexist,
3114 if (bt_info_ext&BIT0) {
3115 /* a2dp basic rate */
3116 btc8821a2ant_tdma_dur_adj(btcoexist,
3120 btc8821a2ant_tdma_dur_adj(btcoexist,
3126 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3127 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3128 btc8821a2ant_sw_mech1(btcoexist, true, true,
3130 btc8821a2ant_sw_mech2(btcoexist, true, false,
3133 btc8821a2ant_sw_mech1(btcoexist, true, true,
3135 btc8821a2ant_sw_mech2(btcoexist, false, false,
3140 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3141 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3142 if (bt_info_ext&BIT0) {
3143 /* a2dp basic rate */
3144 btc8821a2ant_tdma_dur_adj(btcoexist,
3149 btc8821a2ant_tdma_dur_adj(btcoexist,
3153 if (bt_info_ext&BIT0) {
3155 btc8821a2ant_tdma_dur_adj(btcoexist,
3159 btc8821a2ant_tdma_dur_adj(btcoexist,
3165 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3166 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3167 btc8821a2ant_sw_mech1(btcoexist, false, true,
3169 btc8821a2ant_sw_mech2(btcoexist, true, false,
3172 btc8821a2ant_sw_mech1(btcoexist, false, true,
3174 btc8821a2ant_sw_mech2(btcoexist, false, false,
3180 static void halbtc8821a2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3182 bool wifi_under_5g = false;
3185 if (btcoexist->manual_control) {
3186 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3187 "[BTCoex], Manual control!!!\n");
3191 btcoexist->btc_get(btcoexist,
3192 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3194 if (wifi_under_5g) {
3195 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3196 "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3197 halbtc8821a2ant_coex_under_5g(btcoexist);
3201 algorithm = halbtc8821a2ant_action_algorithm(btcoexist);
3202 if (coex_sta->c2h_bt_inquiry_page &&
3203 (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3204 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3205 "[BTCoex], BT is under inquiry/page scan !!\n");
3206 halbtc8821a2ant_bt_inquiry_page(btcoexist);
3210 coex_dm->cur_algorithm = algorithm;
3211 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3212 "[BTCoex], Algorithm = %d\n", coex_dm->cur_algorithm);
3214 if (halbtc8821a2ant_is_common_action(btcoexist)) {
3215 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3216 "[BTCoex], Action 2-Ant common.\n");
3217 coex_dm->reset_tdma_adjust = true;
3219 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3220 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3221 "[BTCoex], pre_algorithm = %d, cur_algorithm = %d\n",
3222 coex_dm->pre_algorithm, coex_dm->cur_algorithm);
3223 coex_dm->reset_tdma_adjust = true;
3225 switch (coex_dm->cur_algorithm) {
3226 case BT_8821A_2ANT_COEX_ALGO_SCO:
3227 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3228 "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
3229 halbtc8821a2ant_action_sco(btcoexist);
3231 case BT_8821A_2ANT_COEX_ALGO_HID:
3232 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3233 "[BTCoex], Action 2-Ant, algorithm = HID.\n");
3234 halbtc8821a2ant_action_hid(btcoexist);
3236 case BT_8821A_2ANT_COEX_ALGO_A2DP:
3237 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3238 "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
3239 halbtc8821a2ant_action_a2dp(btcoexist);
3241 case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
3242 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3243 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
3244 halbtc8821a2ant_action_a2dp_pan_hs(btcoexist);
3246 case BT_8821A_2ANT_COEX_ALGO_PANEDR:
3247 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3248 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
3249 halbtc8821a2ant_action_pan_edr(btcoexist);
3251 case BT_8821A_2ANT_COEX_ALGO_PANHS:
3252 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3253 "[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
3254 halbtc8821a2ant_action_pan_hs(btcoexist);
3256 case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
3257 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3258 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
3259 halbtc8821a2ant_action_pan_edr_a2dp(btcoexist);
3261 case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
3262 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3263 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
3264 halbtc8821a2ant_action_pan_edr_hid(btcoexist);
3266 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3267 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3268 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
3269 btc8821a2ant_act_hid_a2dp_pan_edr(btcoexist);
3271 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
3272 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3273 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
3274 halbtc8821a2ant_action_hid_a2dp(btcoexist);
3277 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3278 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3279 halbtc8821a2ant_coex_all_off(btcoexist);
3282 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3286 /*============================================================
3287 *work around function start with wa_halbtc8821a2ant_
3288 *============================================================
3289 *============================================================
3290 * extern function start with EXhalbtc8821a2ant_
3291 *============================================================
3293 void ex_halbtc8821a2ant_init_hwconfig(struct btc_coexist *btcoexist)
3297 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3298 "[BTCoex], 2Ant Init HW Config!!\n");
3300 /* backup rf 0x1e value */
3301 coex_dm->bt_rf0x1e_backup =
3302 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
3304 /* 0x790[5:0] = 0x5 */
3305 u1tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3308 btcoexist->btc_write_1byte(btcoexist, 0x790, u1tmp);
3311 halbtc8821a2ant_set_ant_path(btcoexist,
3312 BTC_ANT_WIFI_AT_MAIN, true, false);
3315 halbtc8821a2ant_coex_table(btcoexist,
3316 FORCE_EXEC, 0x55555555, 0x55555555,
3319 /* Enable counter statistics */
3320 /*0x76e[3] = 1, WLAN_Act control by PTA*/
3321 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
3322 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3323 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3327 ex_halbtc8821a2ant_init_coex_dm(
3328 struct btc_coexist *btcoexist
3331 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3332 "[BTCoex], Coex Mechanism Init!!\n");
3334 halbtc8821a2ant_init_coex_dm(btcoexist);
3338 ex_halbtc8821a2ant_display_coex_info(
3339 struct btc_coexist *btcoexist
3342 struct btc_board_info *board_info = &btcoexist->board_info;
3343 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3344 struct rtl_priv *rtlpriv = btcoexist->adapter;
3345 u8 u1tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3347 bool roam = false, scan = false, link = false, wifi_under_5g = false;
3348 bool bt_hs_on = false, wifi_busy = false;
3349 long wifi_rssi = 0, bt_hs_rssi = 0;
3350 u32 wifi_bw, wifi_traffic_dir;
3351 u8 wifi_dot_11_chnl, wifi_hs_chnl;
3352 u32 fw_ver = 0, bt_patch_ver = 0;
3354 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3355 "\r\n ============[BT Coexist info]============");
3357 if (!board_info->bt_exist) {
3358 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
3362 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3363 "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
3364 board_info->pg_ant_num, board_info->btdm_ant_num);
3366 if (btcoexist->manual_control) {
3367 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3368 "\r\n %-35s", "[Action Manual control]!!");
3371 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3372 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
3373 ((stack_info->profile_notified) ? "Yes" : "No"),
3374 stack_info->hci_version);
3376 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3377 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3378 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3379 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
3380 "CoexVer/ FwVer/ PatchVer",
3381 glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
3382 fw_ver, bt_patch_ver, bt_patch_ver);
3384 btcoexist->btc_get(btcoexist,
3385 BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3386 btcoexist->btc_get(btcoexist,
3387 BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_dot_11_chnl);
3388 btcoexist->btc_get(btcoexist,
3389 BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
3390 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3391 "\r\n %-35s = %d / %d(%d)",
3392 "Dot11 channel / HsMode(HsChnl)",
3393 wifi_dot_11_chnl, bt_hs_on, wifi_hs_chnl);
3395 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3396 "\r\n %-35s = %02x %02x %02x ",
3397 "H2C Wifi inform bt chnl Info",
3398 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
3399 coex_dm->wifi_chnl_info[2]);
3401 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
3402 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
3403 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3404 "\r\n %-35s = %ld/ %ld", "Wifi rssi/ HS rssi",
3405 wifi_rssi, bt_hs_rssi);
3407 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3408 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3409 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3410 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3411 "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
3414 btcoexist->btc_get(btcoexist,
3415 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3416 btcoexist->btc_get(btcoexist,
3417 BTC_GET_U4_WIFI_BW, &wifi_bw);
3418 btcoexist->btc_get(btcoexist,
3419 BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3420 btcoexist->btc_get(btcoexist,
3421 BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifi_traffic_dir);
3422 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3423 "\r\n %-35s = %s / %s/ %s ", "Wifi status",
3424 (wifi_under_5g ? "5G" : "2.4G"),
3425 ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
3426 (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
3427 ((!wifi_busy) ? "idle" :
3428 ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
3429 "uplink" : "downlink")));
3431 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3432 "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]",
3433 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
3434 ((BT_8821A_2ANT_BT_STATUS_IDLE == coex_dm->bt_status)
3435 ? "idle" : ((BT_8821A_2ANT_BT_STATUS_CON_IDLE ==
3436 coex_dm->bt_status) ? "connected-idle" : "busy"))),
3437 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
3439 if (stack_info->profile_notified) {
3440 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3441 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
3442 stack_info->sco_exist, stack_info->hid_exist,
3443 stack_info->pan_exist, stack_info->a2dp_exist);
3445 btcoexist->btc_disp_dbg_msg(btcoexist,
3446 BTC_DBG_DISP_BT_LINK_INFO);
3449 bt_info_ext = coex_sta->bt_info_ext;
3450 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
3451 "BT Info A2DP rate",
3452 (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
3454 for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) {
3455 if (coex_sta->bt_info_c2h_cnt[i]) {
3456 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3457 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
3458 glbt_info_src_8821a_2ant[i],
3459 coex_sta->bt_info_c2h[i][0],
3460 coex_sta->bt_info_c2h[i][1],
3461 coex_sta->bt_info_c2h[i][2],
3462 coex_sta->bt_info_c2h[i][3],
3463 coex_sta->bt_info_c2h[i][4],
3464 coex_sta->bt_info_c2h[i][5],
3465 coex_sta->bt_info_c2h[i][6],
3466 coex_sta->bt_info_c2h_cnt[i]);
3470 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/%s",
3471 "PS state, IPS/LPS",
3472 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
3473 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
3474 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3477 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3478 "============[Sw mechanism]============");
3479 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3480 "\r\n %-35s = %d/ %d/ %d/ %d ",
3481 "SM1[ShRf/ LpRA/ LimDig/ btLna]",
3482 coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
3483 coex_dm->limited_dig, coex_dm->cur_bt_lna_constrain);
3484 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3485 "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3486 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3487 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
3488 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
3491 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3492 "============[Fw mechanism]============");
3494 if (!btcoexist->manual_control) {
3495 ps_tdma_case = coex_dm->cur_ps_tdma;
3496 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3497 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d",
3499 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
3500 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
3501 coex_dm->ps_tdma_para[4], ps_tdma_case);
3503 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3504 "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct",
3505 coex_dm->cur_dec_bt_pwr,
3506 coex_dm->cur_ignore_wlan_act);
3510 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3511 "\r\n %-35s", "============[Hw setting]============");
3513 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3514 "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal",
3515 coex_dm->bt_rf0x1e_backup);
3517 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
3518 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
3519 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x ",
3520 "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
3521 u1tmp[0], u1tmp[1]);
3523 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
3524 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
3525 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3526 "0x8db(ADC)/0xc5b[29:25](DAC)",
3527 ((u1tmp[0]&0x60)>>5), ((u1tmp[1]&0x3e)>>1));
3529 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3530 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3531 "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
3532 u4tmp[0]&0xff, ((u4tmp[0]&0x30000000)>>28));
3534 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
3535 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
3536 u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
3537 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3538 "0x40/ 0x4c[24:23]/ 0x974",
3539 u1tmp[0], ((u4tmp[0]&0x01800000)>>23), u4tmp[1]);
3541 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
3542 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
3543 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3544 "0x550(bcn ctrl)/0x522",
3545 u4tmp[0], u1tmp[0]);
3547 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
3548 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
3549 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3550 "0xc50(DIG)/0xa0a(CCK-TH)",
3551 u4tmp[0], u1tmp[0]);
3553 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
3554 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
3555 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
3556 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3558 u4tmp[0], (u1tmp[0]<<8) + u1tmp[1]);
3560 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
3561 u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
3562 u4tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
3563 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3564 "0x6c0/0x6c4/0x6c8",
3565 u4tmp[0], u4tmp[1], u4tmp[2]);
3567 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3568 "0x770 (hi-pri Rx/Tx)",
3569 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
3570 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3571 "0x774(low-pri Rx/Tx)",
3572 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
3574 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang*/
3575 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x41b);
3576 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x",
3577 "0x41b (mgntQ hang chk == 0xf)",
3580 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
3583 void ex_halbtc8821a2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
3585 if (BTC_IPS_ENTER == type) {
3586 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3587 "[BTCoex], IPS ENTER notify\n");
3588 coex_sta->under_ips = true;
3589 halbtc8821a2ant_coex_all_off(btcoexist);
3590 } else if (BTC_IPS_LEAVE == type) {
3591 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3592 "[BTCoex], IPS LEAVE notify\n");
3593 coex_sta->under_ips = false;
3594 /*halbtc8821a2ant_init_coex_dm(btcoexist);*/
3598 void ex_halbtc8821a2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
3600 if (BTC_LPS_ENABLE == type) {
3601 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3602 "[BTCoex], LPS ENABLE notify\n");
3603 coex_sta->under_lps = true;
3604 } else if (BTC_LPS_DISABLE == type) {
3605 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3606 "[BTCoex], LPS DISABLE notify\n");
3607 coex_sta->under_lps = false;
3611 void ex_halbtc8821a2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
3613 if (BTC_SCAN_START == type) {
3614 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3615 "[BTCoex], SCAN START notify\n");
3616 } else if (BTC_SCAN_FINISH == type) {
3617 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3618 "[BTCoex], SCAN FINISH notify\n");
3622 void ex_halbtc8821a2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
3624 if (BTC_ASSOCIATE_START == type) {
3625 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3626 "[BTCoex], CONNECT START notify\n");
3627 } else if (BTC_ASSOCIATE_FINISH == type) {
3628 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3629 "[BTCoex], CONNECT FINISH notify\n");
3633 void ex_halbtc8821a2ant_media_status_notify(struct btc_coexist *btcoexist,
3636 u8 h2c_parameter[3] = {0};
3638 u8 wifi_central_chnl;
3640 if (BTC_MEDIA_CONNECT == type) {
3641 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3642 "[BTCoex], MEDIA connect notify\n");
3644 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3645 "[BTCoex], MEDIA disconnect notify\n");
3648 /* only 2.4G we need to inform bt the chnl mask*/
3649 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
3650 &wifi_central_chnl);
3651 if ((BTC_MEDIA_CONNECT == type) &&
3652 (wifi_central_chnl <= 14)) {
3653 h2c_parameter[0] = 0x1;
3654 h2c_parameter[1] = wifi_central_chnl;
3655 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3656 if (BTC_WIFI_BW_HT40 == wifi_bw)
3657 h2c_parameter[2] = 0x30;
3659 h2c_parameter[2] = 0x20;
3662 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3663 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3664 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3666 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
3667 "[BTCoex], FW write 0x66 = 0x%x\n",
3668 h2c_parameter[0]<<16|h2c_parameter[1]<<8|h2c_parameter[2]);
3670 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3673 void ex_halbtc8821a2ant_special_packet_notify(struct btc_coexist *btcoexist,
3675 if (type == BTC_PACKET_DHCP) {
3676 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3677 "[BTCoex], DHCP Packet notify\n");
3681 void ex_halbtc8821a2ant_bt_info_notify(struct btc_coexist *btcoexist,
3682 u8 *tmp_buf, u8 length)
3685 u8 i, rsp_source = 0;
3686 static u32 set_bt_lna_cnt, set_bt_psd_mode;
3687 bool bt_busy = false, limited_dig = false;
3688 bool wifi_connected = false, bt_hs_on = false;
3690 coex_sta->c2h_bt_info_req_sent = false;
3692 rsp_source = tmp_buf[0]&0xf;
3693 if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX)
3694 rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
3695 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3697 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3698 "[BTCoex], Bt info[%d], length = %d, hex data = [",
3699 rsp_source, length);
3700 for (i = 0; i < length; i++) {
3701 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3703 bt_info = tmp_buf[i];
3704 if (i == length-1) {
3705 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3706 "0x%02x]\n", tmp_buf[i]);
3708 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3709 "0x%02x, ", tmp_buf[i]);
3713 if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) {
3714 coex_sta->bt_retry_cnt = /* [3:0]*/
3715 coex_sta->bt_info_c2h[rsp_source][2]&0xf;
3718 coex_sta->bt_info_c2h[rsp_source][3]*2+10;
3720 coex_sta->bt_info_ext =
3721 coex_sta->bt_info_c2h[rsp_source][4];
3723 /* Here we need to resend some wifi info to BT*/
3724 /* because bt is reset and loss of the info.*/
3725 if ((coex_sta->bt_info_ext & BIT1)) {
3726 btcoexist->btc_get(btcoexist,
3727 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3728 if (wifi_connected) {
3729 ex_halbtc8821a2ant_media_status_notify(btcoexist,
3732 ex_halbtc8821a2ant_media_status_notify(btcoexist,
3733 BTC_MEDIA_DISCONNECT);
3736 set_bt_psd_mode = 0;
3738 if (set_bt_psd_mode <= 3) {
3739 halbtc8821a2ant_set_bt_psd_mode(btcoexist, FORCE_EXEC,
3740 0x0); /*fix CH-BW mode*/
3744 if (coex_dm->cur_bt_lna_constrain) {
3745 if (!(coex_sta->bt_info_ext & BIT2)) {
3746 if (set_bt_lna_cnt <= 3) {
3747 btc8821a2_set_bt_lna_const(btcoexist,
3757 if ((coex_sta->bt_info_ext & BIT3)) {
3758 halbtc8821a2ant_ignore_wlan_act(btcoexist,
3761 /* BT already NOT ignore Wlan active, do nothing here.*/
3764 if ((coex_sta->bt_info_ext & BIT4)) {
3765 /* BT auto report already enabled, do nothing*/
3767 halbtc8821a2ant_bt_auto_report(btcoexist,
3772 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3773 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
3774 if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE) {
3775 coex_sta->c2h_bt_inquiry_page = true;
3776 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_IDLE;
3778 coex_sta->c2h_bt_inquiry_page = false;
3779 if (bt_info == 0x1) {
3780 /* connection exists but not busy*/
3781 coex_sta->bt_link_exist = true;
3782 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CON_IDLE;
3783 } else if (bt_info & BT_INFO_8821A_2ANT_B_CONNECTION) {
3784 /* connection exists and some link is busy*/
3785 coex_sta->bt_link_exist = true;
3786 if (bt_info & BT_INFO_8821A_2ANT_B_FTP)
3787 coex_sta->pan_exist = true;
3789 coex_sta->pan_exist = false;
3790 if (bt_info & BT_INFO_8821A_2ANT_B_A2DP)
3791 coex_sta->a2dp_exist = true;
3793 coex_sta->a2dp_exist = false;
3794 if (bt_info & BT_INFO_8821A_2ANT_B_HID)
3795 coex_sta->hid_exist = true;
3797 coex_sta->hid_exist = false;
3798 if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO)
3799 coex_sta->sco_exist = true;
3801 coex_sta->sco_exist = false;
3802 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_IDLE;
3804 coex_sta->bt_link_exist = false;
3805 coex_sta->pan_exist = false;
3806 coex_sta->a2dp_exist = false;
3807 coex_sta->hid_exist = false;
3808 coex_sta->sco_exist = false;
3809 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_IDLE;
3813 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_IDLE;
3816 if (BT_8821A_2ANT_BT_STATUS_NON_IDLE == coex_dm->bt_status)
3820 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3822 if (BT_8821A_2ANT_BT_STATUS_IDLE != coex_dm->bt_status)
3825 limited_dig = false;
3826 coex_dm->limited_dig = limited_dig;
3827 btcoexist->btc_set(btcoexist,
3828 BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
3830 halbtc8821a2ant_run_coexist_mechanism(btcoexist);
3833 void ex_halbtc8821a2ant_halt_notify(struct btc_coexist *btcoexist)
3835 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
3836 "[BTCoex], Halt notify\n");
3838 halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3839 ex_halbtc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3842 void ex_halbtc8821a2ant_periodical(struct btc_coexist *btcoexist)
3844 static u8 dis_ver_info_cnt;
3845 u32 fw_ver = 0, bt_patch_ver = 0;
3846 struct btc_board_info *board_info = &btcoexist->board_info;
3847 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3849 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
3850 "[BTCoex], ==========================Periodical===========================\n");
3852 if (dis_ver_info_cnt <= 5) {
3853 dis_ver_info_cnt += 1;
3854 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3855 "[BTCoex], ****************************************************************\n");
3856 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3857 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
3858 board_info->pg_ant_num,
3859 board_info->btdm_ant_num,
3860 board_info->btdm_ant_pos);
3861 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3862 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
3863 ((stack_info->profile_notified) ? "Yes" : "No"),
3864 stack_info->hci_version);
3865 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
3867 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3868 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3869 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
3870 glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
3871 fw_ver, bt_patch_ver, bt_patch_ver);
3872 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
3873 "[BTCoex], ****************************************************************\n");
3876 halbtc8821a2ant_query_bt_info(btcoexist);
3877 halbtc8821a2ant_monitor_bt_ctr(btcoexist);
3878 btc8821a2ant_mon_bt_en_dis(btcoexist);