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_alg_dbg(ALGO_BT_RSSI_STATE,
84 "[BTCoex], BT Rssi state switch to High\n");
86 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
87 btc_alg_dbg(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_alg_dbg(ALGO_BT_RSSI_STATE,
94 "[BTCoex], BT Rssi state switch to Low\n");
96 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
97 btc_alg_dbg(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_alg_dbg(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_alg_dbg(ALGO_BT_RSSI_STATE,
114 "[BTCoex], BT Rssi state switch to Medium\n");
116 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
117 btc_alg_dbg(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_alg_dbg(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_alg_dbg(ALGO_BT_RSSI_STATE,
133 "[BTCoex], BT Rssi state switch to Low\n");
135 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
136 btc_alg_dbg(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_alg_dbg(ALGO_BT_RSSI_STATE,
143 "[BTCoex], BT Rssi state switch to Medium\n");
145 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
146 btc_alg_dbg(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_alg_dbg(ALGO_WIFI_RSSI_STATE,
175 "[BTCoex], wifi RSSI state switch to High\n");
177 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
178 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
179 "[BTCoex], wifi RSSI state stay at Low\n");
182 if (wifi_rssi < rssi_thresh) {
183 wifi_rssi_state = BTC_RSSI_STATE_LOW;
184 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
185 "[BTCoex], wifi RSSI state switch to Low\n");
187 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
188 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
189 "[BTCoex], wifi RSSI state stay at High\n");
192 } else if (level_num == 3) {
193 if (rssi_thresh > rssi_thresh1) {
194 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
195 "[BTCoex], wifi RSSI thresh error!!\n");
196 return coex_sta->pre_wifi_rssi_state[index];
199 if ((coex_sta->pre_wifi_rssi_state[index] ==
200 BTC_RSSI_STATE_LOW) ||
201 (coex_sta->pre_wifi_rssi_state[index] ==
202 BTC_RSSI_STATE_STAY_LOW)) {
204 (rssi_thresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
205 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
206 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
207 "[BTCoex], wifi RSSI state switch to Medium\n");
209 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
210 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
211 "[BTCoex], wifi RSSI state stay at Low\n");
213 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
214 BTC_RSSI_STATE_MEDIUM) ||
215 (coex_sta->pre_wifi_rssi_state[index] ==
216 BTC_RSSI_STATE_STAY_MEDIUM)) {
217 if (wifi_rssi >= (rssi_thresh1 +
218 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) {
219 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
220 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
221 "[BTCoex], wifi RSSI state switch to High\n");
222 } else if (wifi_rssi < rssi_thresh) {
223 wifi_rssi_state = BTC_RSSI_STATE_LOW;
224 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
225 "[BTCoex], wifi RSSI state switch to Low\n");
227 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
228 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
229 "[BTCoex], wifi RSSI state stay at Medium\n");
232 if (wifi_rssi < rssi_thresh1) {
233 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
234 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
235 "[BTCoex], wifi RSSI state switch to Medium\n");
237 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
238 btc_alg_dbg(ALGO_WIFI_RSSI_STATE,
239 "[BTCoex], wifi RSSI state stay at High\n");
243 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
245 return wifi_rssi_state;
248 static void btc8821a2ant_mon_bt_en_dis(struct btc_coexist *btcoexist)
250 static bool pre_bt_disabled;
251 static u32 bt_disable_cnt;
252 bool bt_active = true, bt_disabled = false;
254 /* This function check if bt is disabled*/
256 if (coex_sta->high_priority_tx == 0 &&
257 coex_sta->high_priority_rx == 0 &&
258 coex_sta->low_priority_tx == 0 &&
259 coex_sta->low_priority_rx == 0)
261 if (coex_sta->high_priority_tx == 0xffff &&
262 coex_sta->high_priority_rx == 0xffff &&
263 coex_sta->low_priority_tx == 0xffff &&
264 coex_sta->low_priority_rx == 0xffff)
269 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
271 btc_alg_dbg(ALGO_BT_MONITOR,
272 "[BTCoex], BT is enabled !!\n");
275 btc_alg_dbg(ALGO_BT_MONITOR,
276 "[BTCoex], bt all counters = 0, %d times!!\n",
278 if (bt_disable_cnt >= 2) {
280 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
282 btc_alg_dbg(ALGO_BT_MONITOR,
283 "[BTCoex], BT is disabled !!\n");
286 if (pre_bt_disabled != bt_disabled) {
287 btc_alg_dbg(ALGO_BT_MONITOR,
288 "[BTCoex], BT is from %s to %s!!\n",
289 (pre_bt_disabled ? "disabled" : "enabled"),
290 (bt_disabled ? "disabled" : "enabled"));
291 pre_bt_disabled = bt_disabled;
295 static void halbtc8821a2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
297 u32 reg_hp_txrx, reg_lp_txrx, u4tmp;
298 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
303 u4tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
304 reg_hp_tx = u4tmp & MASKLWORD;
305 reg_hp_rx = (u4tmp & MASKHWORD)>>16;
307 u4tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
308 reg_lp_tx = u4tmp & MASKLWORD;
309 reg_lp_rx = (u4tmp & MASKHWORD)>>16;
311 coex_sta->high_priority_tx = reg_hp_tx;
312 coex_sta->high_priority_rx = reg_hp_rx;
313 coex_sta->low_priority_tx = reg_lp_tx;
314 coex_sta->low_priority_rx = reg_lp_rx;
316 btc_alg_dbg(ALGO_BT_MONITOR,
317 "[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
318 reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
319 btc_alg_dbg(ALGO_BT_MONITOR,
320 "[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
321 reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
324 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
327 static void halbtc8821a2ant_query_bt_info(struct btc_coexist *btcoexist)
329 u8 h2c_parameter[1] = {0};
331 coex_sta->c2h_bt_info_req_sent = true;
333 h2c_parameter[0] |= BIT0; /* trigger */
335 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
336 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
339 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
342 static u8 halbtc8821a2ant_action_algorithm(struct btc_coexist *btcoexist)
344 struct btc_stack_info *stack_info = &btcoexist->stack_info;
345 bool bt_hs_on = false;
346 u8 algorithm = BT_8821A_2ANT_COEX_ALGO_UNDEFINED;
347 u8 num_of_diff_profile = 0;
349 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
351 /*for win-8 stack HID report error*/
352 /* sync BTInfo with BT firmware and stack */
353 if (!stack_info->hid_exist)
354 stack_info->hid_exist = coex_sta->hid_exist;
355 /* when stack HID report error, here we use the info from bt fw. */
356 if (!stack_info->bt_link_exist)
357 stack_info->bt_link_exist = coex_sta->bt_link_exist;
359 if (!coex_sta->bt_link_exist) {
360 btc_alg_dbg(ALGO_TRACE,
361 "[BTCoex], No profile exists!!!\n");
365 if (coex_sta->sco_exist)
366 num_of_diff_profile++;
367 if (coex_sta->hid_exist)
368 num_of_diff_profile++;
369 if (coex_sta->pan_exist)
370 num_of_diff_profile++;
371 if (coex_sta->a2dp_exist)
372 num_of_diff_profile++;
374 if (num_of_diff_profile == 1) {
375 if (coex_sta->sco_exist) {
376 btc_alg_dbg(ALGO_TRACE,
377 "[BTCoex], SCO only\n");
378 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
380 if (coex_sta->hid_exist) {
381 btc_alg_dbg(ALGO_TRACE,
382 "[BTCoex], HID only\n");
383 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
384 } else if (coex_sta->a2dp_exist) {
385 btc_alg_dbg(ALGO_TRACE,
386 "[BTCoex], A2DP only\n");
387 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;
388 } else if (coex_sta->pan_exist) {
390 btc_alg_dbg(ALGO_TRACE,
391 "[BTCoex], PAN(HS) only\n");
392 algorithm = BT_8821A_2ANT_COEX_ALGO_PANHS;
394 btc_alg_dbg(ALGO_TRACE,
395 "[BTCoex], PAN(EDR) only\n");
396 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR;
400 } else if (num_of_diff_profile == 2) {
401 if (coex_sta->sco_exist) {
402 if (coex_sta->hid_exist) {
403 btc_alg_dbg(ALGO_TRACE,
404 "[BTCoex], SCO + HID\n");
405 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
406 } else if (coex_sta->a2dp_exist) {
407 btc_alg_dbg(ALGO_TRACE,
408 "[BTCoex], SCO + A2DP ==> SCO\n");
409 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
410 } else if (coex_sta->pan_exist) {
412 btc_alg_dbg(ALGO_TRACE,
413 "[BTCoex], SCO + PAN(HS)\n");
414 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
416 btc_alg_dbg(ALGO_TRACE,
417 "[BTCoex], SCO + PAN(EDR)\n");
418 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
422 if (coex_sta->hid_exist &&
423 coex_sta->a2dp_exist) {
424 btc_alg_dbg(ALGO_TRACE,
425 "[BTCoex], HID + A2DP\n");
426 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
427 } else if (coex_sta->hid_exist &&
428 coex_sta->pan_exist) {
430 btc_alg_dbg(ALGO_TRACE,
431 "[BTCoex], HID + PAN(HS)\n");
432 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
434 btc_alg_dbg(ALGO_TRACE,
435 "[BTCoex], HID + PAN(EDR)\n");
436 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
438 } else if (coex_sta->pan_exist &&
439 coex_sta->a2dp_exist) {
441 btc_alg_dbg(ALGO_TRACE,
442 "[BTCoex], A2DP + PAN(HS)\n");
443 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;
445 btc_alg_dbg(ALGO_TRACE,
446 "[BTCoex], A2DP + PAN(EDR)\n");
447 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;
451 } else if (num_of_diff_profile == 3) {
452 if (coex_sta->sco_exist) {
453 if (coex_sta->hid_exist &&
454 coex_sta->a2dp_exist) {
455 btc_alg_dbg(ALGO_TRACE,
456 "[BTCoex], SCO + HID + A2DP ==> HID\n");
457 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
458 } else if (coex_sta->hid_exist &&
459 coex_sta->pan_exist) {
461 btc_alg_dbg(ALGO_TRACE,
462 "[BTCoex], SCO + HID + PAN(HS)\n");
463 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
465 btc_alg_dbg(ALGO_TRACE,
466 "[BTCoex], SCO + HID + PAN(EDR)\n");
467 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
469 } else if (coex_sta->pan_exist &&
470 coex_sta->a2dp_exist) {
472 btc_alg_dbg(ALGO_TRACE,
473 "[BTCoex], SCO + A2DP + PAN(HS)\n");
474 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
476 btc_alg_dbg(ALGO_TRACE,
477 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
478 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
482 if (coex_sta->hid_exist &&
483 coex_sta->pan_exist &&
484 coex_sta->a2dp_exist) {
486 btc_alg_dbg(ALGO_TRACE,
487 "[BTCoex], HID + A2DP + PAN(HS)\n");
488 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
490 btc_alg_dbg(ALGO_TRACE,
491 "[BTCoex], HID + A2DP + PAN(EDR)\n");
492 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
496 } else if (num_of_diff_profile >= 3) {
497 if (coex_sta->sco_exist) {
498 if (coex_sta->hid_exist &&
499 coex_sta->pan_exist &&
500 coex_sta->a2dp_exist) {
502 btc_alg_dbg(ALGO_TRACE,
503 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
506 btc_alg_dbg(ALGO_TRACE,
507 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
508 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
516 static bool halbtc8821a2ant_need_to_dec_bt_pwr(struct btc_coexist *btcoexist)
519 bool bt_hs_on = false, wifi_connected = false;
523 if (!btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on))
525 if (!btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
528 if (!btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi))
531 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
533 if (wifi_connected) {
535 if (bt_hs_rssi > 37) {
536 btc_alg_dbg(ALGO_TRACE_FW,
537 "[BTCoex], Need to decrease bt power for HS mode!!\n");
541 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
542 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
543 btc_alg_dbg(ALGO_TRACE_FW,
544 "[BTCoex], Need to decrease bt power for Wifi is connected!!\n");
552 static void btc8821a2ant_set_fw_dac_swing_lev(struct btc_coexist *btcoexist,
555 u8 h2c_parameter[1] = {0};
557 /* There are several type of dacswing
558 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
560 h2c_parameter[0] = dac_swing_lvl;
562 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
563 "[BTCoex], Set Dac Swing Level = 0x%x\n", dac_swing_lvl);
564 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
565 "[BTCoex], FW write 0x64 = 0x%x\n", h2c_parameter[0]);
567 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
570 static void halbtc8821a2ant_set_fw_dec_bt_pwr(struct btc_coexist *btcoexist,
573 u8 h2c_parameter[1] = {0};
575 h2c_parameter[0] = 0;
578 h2c_parameter[0] |= BIT1;
580 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
581 "[BTCoex], decrease Bt Power : %s, FW write 0x62 = 0x%x\n",
582 (dec_bt_pwr ? "Yes!!" : "No!!"), h2c_parameter[0]);
584 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
587 static void halbtc8821a2ant_dec_bt_pwr(struct btc_coexist *btcoexist,
588 bool force_exec, bool dec_bt_pwr)
590 btc_alg_dbg(ALGO_TRACE_FW,
591 "[BTCoex], %s Dec BT power = %s\n",
592 (force_exec ? "force to" : ""),
593 ((dec_bt_pwr) ? "ON" : "OFF"));
594 coex_dm->cur_dec_bt_pwr = dec_bt_pwr;
597 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
598 "[BTCoex], pre_dec_bt_pwr = %d, cur_dec_bt_pwr = %d\n",
599 coex_dm->pre_dec_bt_pwr, coex_dm->cur_dec_bt_pwr);
601 if (coex_dm->pre_dec_bt_pwr == coex_dm->cur_dec_bt_pwr)
604 halbtc8821a2ant_set_fw_dec_bt_pwr(btcoexist, coex_dm->cur_dec_bt_pwr);
606 coex_dm->pre_dec_bt_pwr = coex_dm->cur_dec_bt_pwr;
609 static void btc8821a2ant_set_fw_bt_lna_constr(struct btc_coexist *btcoexist,
612 u8 h2c_parameter[2] = {0};
614 h2c_parameter[0] = 0x3; /* opCode, 0x3 = BT_SET_LNA_CONSTRAIN */
617 h2c_parameter[1] |= BIT0;
619 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
620 "[BTCoex], set BT LNA Constrain: %s, FW write 0x69 = 0x%x\n",
621 bt_lna_cons_on ? "ON!!" : "OFF!!",
622 h2c_parameter[0] << 8 | h2c_parameter[1]);
624 btcoexist->btc_fill_h2c(btcoexist, 0x69, 2, h2c_parameter);
627 static void btc8821a2_set_bt_lna_const(struct btc_coexist *btcoexist,
628 bool force_exec, bool bt_lna_cons_on)
630 btc_alg_dbg(ALGO_TRACE_FW,
631 "[BTCoex], %s BT Constrain = %s\n",
632 (force_exec ? "force" : ""),
633 ((bt_lna_cons_on) ? "ON" : "OFF"));
634 coex_dm->cur_bt_lna_constrain = bt_lna_cons_on;
637 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
638 "[BTCoex], pre_bt_lna_constrain = %d,cur_bt_lna_constrain = %d\n",
639 coex_dm->pre_bt_lna_constrain,
640 coex_dm->cur_bt_lna_constrain);
642 if (coex_dm->pre_bt_lna_constrain ==
643 coex_dm->cur_bt_lna_constrain)
646 btc8821a2ant_set_fw_bt_lna_constr(btcoexist,
647 coex_dm->cur_bt_lna_constrain);
649 coex_dm->pre_bt_lna_constrain = coex_dm->cur_bt_lna_constrain;
652 static void halbtc8821a2ant_set_fw_bt_psd_mode(struct btc_coexist *btcoexist,
655 u8 h2c_parameter[2] = {0};
657 h2c_parameter[0] = 0x2; /* opCode, 0x2 = BT_SET_PSD_MODE */
659 h2c_parameter[1] = bt_psd_mode;
661 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
662 "[BTCoex], set BT PSD mode = 0x%x, FW write 0x69 = 0x%x\n",
664 h2c_parameter[0] << 8 | h2c_parameter[1]);
666 btcoexist->btc_fill_h2c(btcoexist, 0x69, 2, h2c_parameter);
669 static void halbtc8821a2ant_set_bt_psd_mode(struct btc_coexist *btcoexist,
670 bool force_exec, u8 bt_psd_mode)
672 btc_alg_dbg(ALGO_TRACE_FW,
673 "[BTCoex], %s BT PSD mode = 0x%x\n",
674 (force_exec ? "force" : ""), bt_psd_mode);
675 coex_dm->cur_bt_psd_mode = bt_psd_mode;
678 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
679 "[BTCoex], pre_bt_psd_mode = 0x%x, cur_bt_psd_mode = 0x%x\n",
680 coex_dm->pre_bt_psd_mode, coex_dm->cur_bt_psd_mode);
682 if (coex_dm->pre_bt_psd_mode == coex_dm->cur_bt_psd_mode)
685 halbtc8821a2ant_set_fw_bt_psd_mode(btcoexist,
686 coex_dm->cur_bt_psd_mode);
688 coex_dm->pre_bt_psd_mode = coex_dm->cur_bt_psd_mode;
691 static void halbtc8821a2ant_set_bt_auto_report(struct btc_coexist *btcoexist,
692 bool enable_auto_report)
694 u8 h2c_parameter[1] = {0};
696 h2c_parameter[0] = 0;
698 if (enable_auto_report)
699 h2c_parameter[0] |= BIT0;
701 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
702 "[BTCoex], BT FW auto report : %s, FW write 0x68 = 0x%x\n",
703 (enable_auto_report ? "Enabled!!" : "Disabled!!"),
706 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
709 static void halbtc8821a2ant_bt_auto_report(struct btc_coexist *btcoexist,
711 bool enable_auto_report)
713 btc_alg_dbg(ALGO_TRACE_FW,
714 "[BTCoex], %s BT Auto report = %s\n",
715 (force_exec ? "force to" : ""),
716 ((enable_auto_report) ? "Enabled" : "Disabled"));
717 coex_dm->cur_bt_auto_report = enable_auto_report;
720 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
721 "[BTCoex], pre_bt_auto_report = %d, cur_bt_auto_report = %d\n",
722 coex_dm->pre_bt_auto_report,
723 coex_dm->cur_bt_auto_report);
725 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
728 halbtc8821a2ant_set_bt_auto_report(btcoexist,
729 coex_dm->cur_bt_auto_report);
731 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
734 static void halbtc8821a2ant_fw_dac_swing_lvl(struct btc_coexist *btcoexist,
738 btc_alg_dbg(ALGO_TRACE_FW,
739 "[BTCoex], %s set FW Dac Swing level = %d\n",
740 (force_exec ? "force to" : ""), fw_dac_swing_lvl);
741 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
744 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
745 "[BTCoex], pre_fw_dac_swing_lvl = %d, cur_fw_dac_swing_lvl = %d\n",
746 coex_dm->pre_fw_dac_swing_lvl,
747 coex_dm->cur_fw_dac_swing_lvl);
749 if (coex_dm->pre_fw_dac_swing_lvl ==
750 coex_dm->cur_fw_dac_swing_lvl)
754 btc8821a2ant_set_fw_dac_swing_lev(btcoexist,
755 coex_dm->cur_fw_dac_swing_lvl);
757 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
760 static void btc8821a2ant_set_sw_rf_rx_lpf_corner(struct btc_coexist *btcoexist,
761 bool rx_rf_shrink_on)
763 if (rx_rf_shrink_on) {
764 /* Shrink RF Rx LPF corner */
765 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
766 "[BTCoex], Shrink RF Rx LPF corner!!\n");
767 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
770 /* Resume RF Rx LPF corner
771 * After initialized, we can use coex_dm->bt_rf0x1e_backup
773 if (btcoexist->initilized) {
774 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
775 "[BTCoex], Resume RF Rx LPF corner!!\n");
776 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
778 coex_dm->bt_rf0x1e_backup);
783 static void halbtc8821a2ant_RfShrink(struct btc_coexist *btcoexist,
784 bool force_exec, bool rx_rf_shrink_on)
786 btc_alg_dbg(ALGO_TRACE_SW,
787 "[BTCoex], %s turn Rx RF Shrink = %s\n",
788 (force_exec ? "force to" : ""),
789 ((rx_rf_shrink_on) ? "ON" : "OFF"));
790 coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
793 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
794 "[BTCoex], pre_rf_rx_lpf_shrink = %d, cur_rf_rx_lpf_shrink = %d\n",
795 coex_dm->pre_rf_rx_lpf_shrink,
796 coex_dm->cur_rf_rx_lpf_shrink);
798 if (coex_dm->pre_rf_rx_lpf_shrink ==
799 coex_dm->cur_rf_rx_lpf_shrink)
802 btc8821a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
803 coex_dm->cur_rf_rx_lpf_shrink);
805 coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
808 static void btc8821a2ant_SetSwPenTxRateAdapt(struct btc_coexist *btcoexist,
811 u8 h2c_parameter[6] = {0};
813 h2c_parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
815 if (low_penalty_ra) {
816 h2c_parameter[1] |= BIT0;
817 /*normal rate except MCS7/6/5, OFDM54/48/36 */
818 h2c_parameter[2] = 0x00;
820 h2c_parameter[3] = 0xf7;
822 h2c_parameter[4] = 0xf8;
824 h2c_parameter[5] = 0xf9;
827 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
828 "[BTCoex], set WiFi Low-Penalty Retry: %s",
829 (low_penalty_ra ? "ON!!" : "OFF!!"));
831 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
834 static void halbtc8821a2ant_low_penalty_ra(struct btc_coexist *btcoexist,
835 bool force_exec, bool low_penalty_ra)
838 btc_alg_dbg(ALGO_TRACE_SW,
839 "[BTCoex], %s turn LowPenaltyRA = %s\n",
840 (force_exec ? "force to" : ""),
841 ((low_penalty_ra) ? "ON" : "OFF"));
842 coex_dm->cur_low_penalty_ra = low_penalty_ra;
845 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
846 "[BTCoex], pre_low_penalty_ra = %d, cur_low_penalty_ra = %d\n",
847 coex_dm->pre_low_penalty_ra,
848 coex_dm->cur_low_penalty_ra);
850 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
853 btc8821a2ant_SetSwPenTxRateAdapt(btcoexist,
854 coex_dm->cur_low_penalty_ra);
856 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
859 static void halbtc8821a2ant_set_dac_swing_reg(struct btc_coexist *btcoexist,
864 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
865 "[BTCoex], Write SwDacSwing = 0x%x\n", level);
866 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
869 static void btc8821a2ant_set_sw_full_dac_swing(struct btc_coexist *btcoexist,
870 bool sw_dac_swing_on,
871 u32 sw_dac_swing_lvl)
874 halbtc8821a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
876 halbtc8821a2ant_set_dac_swing_reg(btcoexist, 0x18);
879 static void halbtc8821a2ant_dac_swing(struct btc_coexist *btcoexist,
880 bool force_exec, bool dac_swing_on,
883 btc_alg_dbg(ALGO_TRACE_SW,
884 "[BTCoex], %s turn DacSwing = %s, dac_swing_lvl = 0x%x\n",
885 (force_exec ? "force to" : ""),
886 ((dac_swing_on) ? "ON" : "OFF"),
888 coex_dm->cur_dac_swing_on = dac_swing_on;
889 coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
892 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
893 "[BTCoex], pre_dac_swing_on = %d, pre_dac_swing_lvl = 0x%x, cur_dac_swing_on = %d, cur_dac_swing_lvl = 0x%x\n",
894 coex_dm->pre_dac_swing_on,
895 coex_dm->pre_dac_swing_lvl,
896 coex_dm->cur_dac_swing_on,
897 coex_dm->cur_dac_swing_lvl);
899 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
900 (coex_dm->pre_dac_swing_lvl ==
901 coex_dm->cur_dac_swing_lvl))
905 btc8821a2ant_set_sw_full_dac_swing(btcoexist, dac_swing_on,
908 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
909 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
912 static void halbtc8821a2ant_set_adc_back_off(struct btc_coexist *btcoexist,
916 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
917 "[BTCoex], BB BackOff Level On!\n");
918 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
920 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
921 "[BTCoex], BB BackOff Level Off!\n");
922 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
926 static void halbtc8821a2ant_adc_back_off(struct btc_coexist *btcoexist,
927 bool force_exec, bool adc_back_off)
929 btc_alg_dbg(ALGO_TRACE_SW,
930 "[BTCoex], %s turn AdcBackOff = %s\n",
931 (force_exec ? "force to" : ""),
932 ((adc_back_off) ? "ON" : "OFF"));
933 coex_dm->cur_adc_back_off = adc_back_off;
936 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
937 "[BTCoex], pre_adc_back_off = %d, cur_adc_back_off = %d\n",
938 coex_dm->pre_adc_back_off,
939 coex_dm->cur_adc_back_off);
941 if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
944 halbtc8821a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
946 coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
949 static void halbtc8821a2ant_set_coex_table(struct btc_coexist *btcoexist,
950 u32 val0x6c0, u32 val0x6c4,
951 u32 val0x6c8, u8 val0x6cc)
953 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
954 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
955 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
957 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
958 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
959 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
961 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
962 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
963 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
965 btc_alg_dbg(ALGO_TRACE_SW_EXEC,
966 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
967 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
970 static void halbtc8821a2ant_coex_table(struct btc_coexist *btcoexist,
971 bool force_exec, u32 val0x6c0,
972 u32 val0x6c4, u32 val0x6c8, u8 val0x6cc)
974 btc_alg_dbg(ALGO_TRACE_SW,
975 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
976 (force_exec ? "force to" : ""),
977 val0x6c0, val0x6c4, val0x6c8, val0x6cc);
978 coex_dm->cur_val0x6c0 = val0x6c0;
979 coex_dm->cur_val0x6c4 = val0x6c4;
980 coex_dm->cur_val0x6c8 = val0x6c8;
981 coex_dm->cur_val0x6cc = val0x6cc;
984 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
985 "[BTCoex], pre_val0x6c0 = 0x%x, pre_val0x6c4 = 0x%x, pre_val0x6c8 = 0x%x, pre_val0x6cc = 0x%x !!\n",
986 coex_dm->pre_val0x6c0,
987 coex_dm->pre_val0x6c4,
988 coex_dm->pre_val0x6c8,
989 coex_dm->pre_val0x6cc);
990 btc_alg_dbg(ALGO_TRACE_SW_DETAIL,
991 "[BTCoex], cur_val0x6c0 = 0x%x, cur_val0x6c4 = 0x%x, cur_val0x6c8 = 0x%x, cur_val0x6cc = 0x%x !!\n",
992 coex_dm->cur_val0x6c0,
993 coex_dm->cur_val0x6c4,
994 coex_dm->cur_val0x6c8,
995 coex_dm->cur_val0x6cc);
997 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
998 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
999 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1000 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1003 halbtc8821a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1006 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1007 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1008 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1009 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1012 static void halbtc8821a2ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoex,
1015 u8 h2c_parameter[1] = {0};
1018 h2c_parameter[0] |= BIT0;/* function enable */
1020 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
1021 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
1024 btcoex->btc_fill_h2c(btcoex, 0x63, 1, h2c_parameter);
1027 static void halbtc8821a2ant_ignore_wlan_act(struct btc_coexist *btcoexist,
1028 bool force_exec, bool enable)
1030 btc_alg_dbg(ALGO_TRACE_FW,
1031 "[BTCoex], %s turn Ignore WlanAct %s\n",
1032 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
1033 coex_dm->cur_ignore_wlan_act = enable;
1036 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1037 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
1038 coex_dm->pre_ignore_wlan_act,
1039 coex_dm->cur_ignore_wlan_act);
1041 if (coex_dm->pre_ignore_wlan_act ==
1042 coex_dm->cur_ignore_wlan_act)
1045 halbtc8821a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1047 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1050 static void halbtc8821a2ant_set_fw_pstdma(struct btc_coexist *btcoexist,
1051 u8 byte1, u8 byte2, u8 byte3,
1054 u8 h2c_parameter[5];
1056 h2c_parameter[0] = byte1;
1057 h2c_parameter[1] = byte2;
1058 h2c_parameter[2] = byte3;
1059 h2c_parameter[3] = byte4;
1060 h2c_parameter[4] = byte5;
1062 coex_dm->ps_tdma_para[0] = byte1;
1063 coex_dm->ps_tdma_para[1] = byte2;
1064 coex_dm->ps_tdma_para[2] = byte3;
1065 coex_dm->ps_tdma_para[3] = byte4;
1066 coex_dm->ps_tdma_para[4] = byte5;
1068 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
1069 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1071 h2c_parameter[1] << 24 |
1072 h2c_parameter[2] << 16 |
1073 h2c_parameter[3] << 8 |
1076 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1079 static void btc8821a2ant_sw_mech1(struct btc_coexist *btcoexist,
1081 bool low_penalty_ra, bool limited_dig,
1082 bool bt_lna_constrain)
1086 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
1088 if (BTC_WIFI_BW_HT40 != wifi_bw) {
1089 /*only shrink RF Rx LPF for HT40*/
1091 shrink_rx_lpf = false;
1094 halbtc8821a2ant_RfShrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
1095 halbtc8821a2ant_low_penalty_ra(btcoexist,
1096 NORMAL_EXEC, low_penalty_ra);
1099 * btc8821a2_set_bt_lna_const(btcoexist,
1100 NORMAL_EXEC, bBTLNAConstrain);
1104 static void btc8821a2ant_sw_mech2(struct btc_coexist *btcoexist,
1105 bool agc_table_shift,
1106 bool adc_back_off, bool sw_dac_swing,
1109 /* halbtc8821a2ant_AgcTable(btcoexist, NORMAL_EXEC, bAGCTableShift); */
1110 halbtc8821a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off);
1111 halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1115 static void halbtc8821a2ant_set_ant_path(struct btc_coexist *btcoexist,
1116 u8 ant_pos_type, bool init_hw_cfg,
1119 struct btc_board_info *board_info = &btcoexist->board_info;
1121 u8 h2c_parameter[2] = {0};
1124 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
1125 u4tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1128 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4tmp);
1130 btcoexist->btc_write_4byte(btcoexist, 0x974, 0x3ff);
1131 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
1133 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
1134 /* tell firmware "antenna inverse" ==>
1135 * WRONG firmware antenna control code.
1138 h2c_parameter[0] = 1;
1139 h2c_parameter[1] = 1;
1140 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1143 /* tell firmware "no antenna inverse"
1144 * ==> WRONG firmware antenna control code.
1147 h2c_parameter[0] = 0;
1148 h2c_parameter[1] = 1;
1149 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1154 /* ext switch setting */
1155 switch (ant_pos_type) {
1156 case BTC_ANT_WIFI_AT_MAIN:
1157 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, 0x1);
1159 case BTC_ANT_WIFI_AT_AUX:
1160 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, 0x2);
1165 static void halbtc8821a2ant_ps_tdma(struct btc_coexist *btcoexist,
1166 bool force_exec, bool turn_on, u8 type)
1168 btc_alg_dbg(ALGO_TRACE_FW,
1169 "[BTCoex], %s turn %s PS TDMA, type = %d\n",
1170 (force_exec ? "force to" : ""), (turn_on ? "ON" : "OFF"),
1172 coex_dm->cur_ps_tdma_on = turn_on;
1173 coex_dm->cur_ps_tdma = type;
1176 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1177 "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n",
1178 coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on);
1179 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1180 "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n",
1181 coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma);
1183 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1184 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1191 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1195 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12,
1199 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1c,
1203 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x10,
1207 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1211 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12,
1215 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1c,
1219 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3, 0x10,
1223 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1227 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12,
1231 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa,
1235 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5,
1239 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1243 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1244 0x12, 0x12, 0x60, 0x90);
1247 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa,
1251 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5,
1255 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3, 0x2f,
1259 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5,
1263 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x25,
1267 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x25,
1271 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x15,
1275 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a,
1280 /* disable PS tdma */
1283 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1287 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1291 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1297 /* update pre state */
1298 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1299 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1302 static void halbtc8821a2ant_coex_all_off(struct btc_coexist *btcoexist)
1305 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1306 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1307 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1310 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1311 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1314 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC,
1315 0x55555555, 0x55555555, 0xffff, 0x3);
1318 static void halbtc8821a2ant_coex_under_5g(struct btc_coexist *btcoexist)
1320 halbtc8821a2ant_coex_all_off(btcoexist);
1323 static void halbtc8821a2ant_init_coex_dm(struct btc_coexist *btcoexist)
1325 /* force to reset coex mechanism */
1326 halbtc8821a2ant_coex_table(btcoexist, FORCE_EXEC, 0x55555555,
1327 0x55555555, 0xffff, 0x3);
1329 halbtc8821a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1330 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1331 halbtc8821a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, false);
1333 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1334 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1337 static void halbtc8821a2ant_bt_inquiry_page(struct btc_coexist *btcoexist)
1339 bool low_pwr_disable = true;
1341 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1344 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
1345 0x5afa5afa, 0xffff, 0x3);
1346 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1349 static bool halbtc8821a2ant_is_common_action(struct btc_coexist *btcoexist)
1351 bool common = false, wifi_connected = false, wifi_busy = false;
1352 bool low_pwr_disable = false;
1354 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1356 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1358 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
1359 0x5afa5afa, 0xffff, 0x3);
1361 if (!wifi_connected &&
1362 BT_8821A_2ANT_BT_STATUS_IDLE == coex_dm->bt_status) {
1363 low_pwr_disable = false;
1364 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1367 btc_alg_dbg(ALGO_TRACE,
1368 "[BTCoex], Wifi IPS + BT IPS!!\n");
1370 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1371 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1372 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1374 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1375 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1378 } else if (wifi_connected &&
1379 (BT_8821A_2ANT_BT_STATUS_IDLE == coex_dm->bt_status)) {
1380 low_pwr_disable = false;
1381 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1385 btc_alg_dbg(ALGO_TRACE,
1386 "[BTCoex], Wifi Busy + BT IPS!!\n");
1387 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1390 btc_alg_dbg(ALGO_TRACE,
1391 "[BTCoex], Wifi LPS + BT IPS!!\n");
1392 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1396 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1397 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1399 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1400 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1403 } else if (!wifi_connected &&
1404 (BT_8821A_2ANT_BT_STATUS_CON_IDLE == coex_dm->bt_status)) {
1405 low_pwr_disable = true;
1406 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1409 btc_alg_dbg(ALGO_TRACE,
1410 "[BTCoex], Wifi IPS + BT LPS!!\n");
1412 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1413 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1414 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1416 btc8821a2ant_sw_mech1(btcoexist, false, false, false, false);
1417 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1419 } else if (wifi_connected &&
1420 (BT_8821A_2ANT_BT_STATUS_CON_IDLE == coex_dm->bt_status)) {
1421 low_pwr_disable = true;
1422 btcoexist->btc_set(btcoexist,
1423 BTC_SET_ACT_DISABLE_LOW_POWER, &low_pwr_disable);
1426 btc_alg_dbg(ALGO_TRACE,
1427 "[BTCoex], Wifi Busy + BT LPS!!\n");
1428 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1431 btc_alg_dbg(ALGO_TRACE,
1432 "[BTCoex], Wifi LPS + BT LPS!!\n");
1433 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1437 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1438 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1440 btc8821a2ant_sw_mech1(btcoexist, true, true, true, true);
1441 btc8821a2ant_sw_mech2(btcoexist, false, false, false, 0x18);
1444 } else if (!wifi_connected &&
1445 (BT_8821A_2ANT_BT_STATUS_NON_IDLE ==
1446 coex_dm->bt_status)) {
1447 low_pwr_disable = false;
1448 btcoexist->btc_set(btcoexist,
1449 BTC_SET_ACT_DISABLE_LOW_POWER, &low_pwr_disable);
1451 btc_alg_dbg(ALGO_TRACE,
1452 "[BTCoex], Wifi IPS + BT Busy!!\n");
1454 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1455 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1456 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
1458 btc8821a2ant_sw_mech1(btcoexist, false, false,
1460 btc8821a2ant_sw_mech2(btcoexist, false, false,
1465 low_pwr_disable = true;
1466 btcoexist->btc_set(btcoexist,
1467 BTC_SET_ACT_DISABLE_LOW_POWER,
1471 btc_alg_dbg(ALGO_TRACE,
1472 "[BTCoex], Wifi Busy + BT Busy!!\n");
1475 btc_alg_dbg(ALGO_TRACE,
1476 "[BTCoex], Wifi LPS + BT Busy!!\n");
1477 halbtc8821a2ant_ps_tdma(btcoexist,
1478 NORMAL_EXEC, true, 21);
1480 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
1481 halbtc8821a2ant_dec_bt_pwr(btcoexist,
1484 halbtc8821a2ant_dec_bt_pwr(btcoexist,
1485 NORMAL_EXEC, false);
1489 btc8821a2ant_sw_mech1(btcoexist, true, true, true, true);
1494 static void btc8821a2_int1(struct btc_coexist *btcoexist, bool tx_pause,
1498 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1499 "[BTCoex], TxPause = 1\n");
1501 if (coex_dm->cur_ps_tdma == 71) {
1502 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1504 coex_dm->tdma_adj_type = 5;
1505 } else if (coex_dm->cur_ps_tdma == 1) {
1506 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1508 coex_dm->tdma_adj_type = 5;
1509 } else if (coex_dm->cur_ps_tdma == 2) {
1510 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1512 coex_dm->tdma_adj_type = 6;
1513 } else if (coex_dm->cur_ps_tdma == 3) {
1514 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1516 coex_dm->tdma_adj_type = 7;
1517 } else if (coex_dm->cur_ps_tdma == 4) {
1518 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1520 coex_dm->tdma_adj_type = 8;
1522 if (coex_dm->cur_ps_tdma == 9) {
1523 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1525 coex_dm->tdma_adj_type = 13;
1526 } else if (coex_dm->cur_ps_tdma == 10) {
1527 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1529 coex_dm->tdma_adj_type = 14;
1530 } else if (coex_dm->cur_ps_tdma == 11) {
1531 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1533 coex_dm->tdma_adj_type = 15;
1534 } else if (coex_dm->cur_ps_tdma == 12) {
1535 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1537 coex_dm->tdma_adj_type = 16;
1541 if (coex_dm->cur_ps_tdma == 5) {
1542 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1544 coex_dm->tdma_adj_type = 6;
1545 } else if (coex_dm->cur_ps_tdma == 6) {
1546 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1548 coex_dm->tdma_adj_type = 7;
1549 } else if (coex_dm->cur_ps_tdma == 7) {
1550 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1552 coex_dm->tdma_adj_type = 8;
1553 } else if (coex_dm->cur_ps_tdma == 13) {
1554 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1556 coex_dm->tdma_adj_type = 14;
1557 } else if (coex_dm->cur_ps_tdma == 14) {
1558 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1560 coex_dm->tdma_adj_type = 15;
1561 } else if (coex_dm->cur_ps_tdma == 15) {
1562 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1564 coex_dm->tdma_adj_type = 16;
1566 } else if (result == 1) {
1567 if (coex_dm->cur_ps_tdma == 8) {
1568 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1570 coex_dm->tdma_adj_type = 7;
1571 } else if (coex_dm->cur_ps_tdma == 7) {
1572 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1574 coex_dm->tdma_adj_type = 6;
1575 } else if (coex_dm->cur_ps_tdma == 6) {
1576 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1578 coex_dm->tdma_adj_type = 5;
1579 } else if (coex_dm->cur_ps_tdma == 16) {
1580 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1582 coex_dm->tdma_adj_type = 15;
1583 } else if (coex_dm->cur_ps_tdma == 15) {
1584 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1586 coex_dm->tdma_adj_type = 14;
1587 } else if (coex_dm->cur_ps_tdma == 14) {
1588 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1590 coex_dm->tdma_adj_type = 13;
1594 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1595 "[BTCoex], TxPause = 0\n");
1596 if (coex_dm->cur_ps_tdma == 5) {
1597 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1599 coex_dm->tdma_adj_type = 71;
1600 } else if (coex_dm->cur_ps_tdma == 6) {
1601 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1603 coex_dm->tdma_adj_type = 2;
1604 } else if (coex_dm->cur_ps_tdma == 7) {
1605 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1607 coex_dm->tdma_adj_type = 3;
1608 } else if (coex_dm->cur_ps_tdma == 8) {
1609 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1611 coex_dm->tdma_adj_type = 4;
1613 if (coex_dm->cur_ps_tdma == 13) {
1614 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1616 coex_dm->tdma_adj_type = 9;
1617 } else if (coex_dm->cur_ps_tdma == 14) {
1618 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1620 coex_dm->tdma_adj_type = 10;
1621 } else if (coex_dm->cur_ps_tdma == 15) {
1622 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1624 coex_dm->tdma_adj_type = 11;
1625 } else if (coex_dm->cur_ps_tdma == 16) {
1626 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1628 coex_dm->tdma_adj_type = 12;
1632 if (coex_dm->cur_ps_tdma == 71) {
1633 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1635 coex_dm->tdma_adj_type = 1;
1636 } else if (coex_dm->cur_ps_tdma == 1) {
1637 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1639 coex_dm->tdma_adj_type = 2;
1640 } else if (coex_dm->cur_ps_tdma == 2) {
1641 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1643 coex_dm->tdma_adj_type = 3;
1644 } else if (coex_dm->cur_ps_tdma == 3) {
1645 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1647 coex_dm->tdma_adj_type = 4;
1648 } else if (coex_dm->cur_ps_tdma == 9) {
1649 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1651 coex_dm->tdma_adj_type = 10;
1652 } else if (coex_dm->cur_ps_tdma == 10) {
1653 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1655 coex_dm->tdma_adj_type = 11;
1656 } else if (coex_dm->cur_ps_tdma == 11) {
1657 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1659 coex_dm->tdma_adj_type = 12;
1661 } else if (result == 1) {
1662 if (coex_dm->cur_ps_tdma == 4) {
1663 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1665 coex_dm->tdma_adj_type = 3;
1666 } else if (coex_dm->cur_ps_tdma == 3) {
1667 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1669 coex_dm->tdma_adj_type = 2;
1670 } else if (coex_dm->cur_ps_tdma == 2) {
1671 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1673 coex_dm->tdma_adj_type = 1;
1674 } else if (coex_dm->cur_ps_tdma == 1) {
1675 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1677 coex_dm->tdma_adj_type = 71;
1678 } else if (coex_dm->cur_ps_tdma == 12) {
1679 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1681 coex_dm->tdma_adj_type = 11;
1682 } else if (coex_dm->cur_ps_tdma == 11) {
1683 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1685 coex_dm->tdma_adj_type = 10;
1686 } else if (coex_dm->cur_ps_tdma == 10) {
1687 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1689 coex_dm->tdma_adj_type = 9;
1695 static void btc8821a2_int2(struct btc_coexist *btcoexist, bool tx_pause,
1699 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1700 "[BTCoex], TxPause = 1\n");
1701 if (coex_dm->cur_ps_tdma == 1) {
1702 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1704 coex_dm->tdma_adj_type = 6;
1705 } else if (coex_dm->cur_ps_tdma == 2) {
1706 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1708 coex_dm->tdma_adj_type = 6;
1709 } else if (coex_dm->cur_ps_tdma == 3) {
1710 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1712 coex_dm->tdma_adj_type = 7;
1713 } else if (coex_dm->cur_ps_tdma == 4) {
1714 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1716 coex_dm->tdma_adj_type = 8;
1718 if (coex_dm->cur_ps_tdma == 9) {
1719 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1721 coex_dm->tdma_adj_type = 14;
1722 } else if (coex_dm->cur_ps_tdma == 10) {
1723 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1725 coex_dm->tdma_adj_type = 14;
1726 } else if (coex_dm->cur_ps_tdma == 11) {
1727 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1729 coex_dm->tdma_adj_type = 15;
1730 } else if (coex_dm->cur_ps_tdma == 12) {
1731 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1733 coex_dm->tdma_adj_type = 16;
1736 if (coex_dm->cur_ps_tdma == 5) {
1737 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1739 coex_dm->tdma_adj_type = 6;
1740 } else if (coex_dm->cur_ps_tdma == 6) {
1741 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1743 coex_dm->tdma_adj_type = 7;
1744 } else if (coex_dm->cur_ps_tdma == 7) {
1745 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1747 coex_dm->tdma_adj_type = 8;
1748 } else if (coex_dm->cur_ps_tdma == 13) {
1749 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1751 coex_dm->tdma_adj_type = 14;
1752 } else if (coex_dm->cur_ps_tdma == 14) {
1753 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1755 coex_dm->tdma_adj_type = 15;
1756 } else if (coex_dm->cur_ps_tdma == 15) {
1757 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1759 coex_dm->tdma_adj_type = 16;
1761 } else if (result == 1) {
1762 if (coex_dm->cur_ps_tdma == 8) {
1763 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1765 coex_dm->tdma_adj_type = 7;
1766 } else if (coex_dm->cur_ps_tdma == 7) {
1767 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1769 coex_dm->tdma_adj_type = 6;
1770 } else if (coex_dm->cur_ps_tdma == 6) {
1771 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1773 coex_dm->tdma_adj_type = 6;
1774 } else if (coex_dm->cur_ps_tdma == 16) {
1775 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1777 coex_dm->tdma_adj_type = 15;
1778 } else if (coex_dm->cur_ps_tdma == 15) {
1779 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1781 coex_dm->tdma_adj_type = 14;
1782 } else if (coex_dm->cur_ps_tdma == 14) {
1783 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1785 coex_dm->tdma_adj_type = 14;
1789 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1790 "[BTCoex], TxPause = 0\n");
1791 if (coex_dm->cur_ps_tdma == 5) {
1792 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1794 coex_dm->tdma_adj_type = 2;
1795 } else if (coex_dm->cur_ps_tdma == 6) {
1796 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1798 coex_dm->tdma_adj_type = 2;
1799 } else if (coex_dm->cur_ps_tdma == 7) {
1800 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1802 coex_dm->tdma_adj_type = 3;
1803 } else if (coex_dm->cur_ps_tdma == 8) {
1804 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1806 coex_dm->tdma_adj_type = 4;
1808 if (coex_dm->cur_ps_tdma == 13) {
1809 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1811 coex_dm->tdma_adj_type = 10;
1812 } else if (coex_dm->cur_ps_tdma == 14) {
1813 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1815 coex_dm->tdma_adj_type = 10;
1816 } else if (coex_dm->cur_ps_tdma == 15) {
1817 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1819 coex_dm->tdma_adj_type = 11;
1820 } else if (coex_dm->cur_ps_tdma == 16) {
1821 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1823 coex_dm->tdma_adj_type = 12;
1826 if (coex_dm->cur_ps_tdma == 1) {
1827 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1829 coex_dm->tdma_adj_type = 2;
1830 } else if (coex_dm->cur_ps_tdma == 2) {
1831 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1833 coex_dm->tdma_adj_type = 3;
1834 } else if (coex_dm->cur_ps_tdma == 3) {
1835 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1837 coex_dm->tdma_adj_type = 4;
1838 } else if (coex_dm->cur_ps_tdma == 9) {
1839 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1841 coex_dm->tdma_adj_type = 10;
1842 } else if (coex_dm->cur_ps_tdma == 10) {
1843 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1845 coex_dm->tdma_adj_type = 11;
1846 } else if (coex_dm->cur_ps_tdma == 11) {
1847 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1849 coex_dm->tdma_adj_type = 12;
1851 } else if (result == 1) {
1852 if (coex_dm->cur_ps_tdma == 4) {
1853 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1855 coex_dm->tdma_adj_type = 3;
1856 } else if (coex_dm->cur_ps_tdma == 3) {
1857 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1859 coex_dm->tdma_adj_type = 2;
1860 } else if (coex_dm->cur_ps_tdma == 2) {
1861 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1863 coex_dm->tdma_adj_type = 2;
1864 } else if (coex_dm->cur_ps_tdma == 12) {
1865 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1867 coex_dm->tdma_adj_type = 11;
1868 } else if (coex_dm->cur_ps_tdma == 11) {
1869 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1871 coex_dm->tdma_adj_type = 10;
1872 } else if (coex_dm->cur_ps_tdma == 10) {
1873 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1875 coex_dm->tdma_adj_type = 10;
1881 static void btc8821a2_int3(struct btc_coexist *btcoexist, bool tx_pause,
1885 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1886 "[BTCoex], TxPause = 1\n");
1887 if (coex_dm->cur_ps_tdma == 1) {
1888 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1890 coex_dm->tdma_adj_type = 7;
1891 } else if (coex_dm->cur_ps_tdma == 2) {
1892 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1894 coex_dm->tdma_adj_type = 7;
1895 } else if (coex_dm->cur_ps_tdma == 3) {
1896 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1898 coex_dm->tdma_adj_type = 7;
1899 } else if (coex_dm->cur_ps_tdma == 4) {
1900 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1902 coex_dm->tdma_adj_type = 8;
1904 if (coex_dm->cur_ps_tdma == 9) {
1905 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1907 coex_dm->tdma_adj_type = 15;
1908 } else if (coex_dm->cur_ps_tdma == 10) {
1909 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1911 coex_dm->tdma_adj_type = 15;
1912 } else if (coex_dm->cur_ps_tdma == 11) {
1913 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1915 coex_dm->tdma_adj_type = 15;
1916 } else if (coex_dm->cur_ps_tdma == 12) {
1917 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1919 coex_dm->tdma_adj_type = 16;
1922 if (coex_dm->cur_ps_tdma == 5) {
1923 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1925 coex_dm->tdma_adj_type = 7;
1926 } else if (coex_dm->cur_ps_tdma == 6) {
1927 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1929 coex_dm->tdma_adj_type = 7;
1930 } else if (coex_dm->cur_ps_tdma == 7) {
1931 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1933 coex_dm->tdma_adj_type = 8;
1934 } else if (coex_dm->cur_ps_tdma == 13) {
1935 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1937 coex_dm->tdma_adj_type = 15;
1938 } else if (coex_dm->cur_ps_tdma == 14) {
1939 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1941 coex_dm->tdma_adj_type = 15;
1942 } else if (coex_dm->cur_ps_tdma == 15) {
1943 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1945 coex_dm->tdma_adj_type = 16;
1947 } else if (result == 1) {
1948 if (coex_dm->cur_ps_tdma == 8) {
1949 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1951 coex_dm->tdma_adj_type = 7;
1952 } else if (coex_dm->cur_ps_tdma == 7) {
1953 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1955 coex_dm->tdma_adj_type = 7;
1956 } else if (coex_dm->cur_ps_tdma == 6) {
1957 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1959 coex_dm->tdma_adj_type = 7;
1960 } else if (coex_dm->cur_ps_tdma == 16) {
1961 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1963 coex_dm->tdma_adj_type = 15;
1964 } else if (coex_dm->cur_ps_tdma == 15) {
1965 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1967 coex_dm->tdma_adj_type = 15;
1968 } else if (coex_dm->cur_ps_tdma == 14) {
1969 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1971 coex_dm->tdma_adj_type = 15;
1975 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
1976 "[BTCoex], TxPause = 0\n");
1977 if (coex_dm->cur_ps_tdma == 5) {
1978 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1980 coex_dm->tdma_adj_type = 3;
1981 } else if (coex_dm->cur_ps_tdma == 6) {
1982 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1984 coex_dm->tdma_adj_type = 3;
1985 } else if (coex_dm->cur_ps_tdma == 7) {
1986 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1988 coex_dm->tdma_adj_type = 3;
1989 } else if (coex_dm->cur_ps_tdma == 8) {
1990 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1992 coex_dm->tdma_adj_type = 4;
1994 if (coex_dm->cur_ps_tdma == 13) {
1995 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1997 coex_dm->tdma_adj_type = 11;
1998 } else if (coex_dm->cur_ps_tdma == 14) {
1999 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2001 coex_dm->tdma_adj_type = 11;
2002 } else if (coex_dm->cur_ps_tdma == 15) {
2003 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2005 coex_dm->tdma_adj_type = 11;
2006 } else if (coex_dm->cur_ps_tdma == 16) {
2007 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2009 coex_dm->tdma_adj_type = 12;
2012 if (coex_dm->cur_ps_tdma == 1) {
2013 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2015 coex_dm->tdma_adj_type = 3;
2016 } else if (coex_dm->cur_ps_tdma == 2) {
2017 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2019 coex_dm->tdma_adj_type = 3;
2020 } else if (coex_dm->cur_ps_tdma == 3) {
2021 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2023 coex_dm->tdma_adj_type = 4;
2024 } else if (coex_dm->cur_ps_tdma == 9) {
2025 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2027 coex_dm->tdma_adj_type = 11;
2028 } else if (coex_dm->cur_ps_tdma == 10) {
2029 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2031 coex_dm->tdma_adj_type = 11;
2032 } else if (coex_dm->cur_ps_tdma == 11) {
2033 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2035 coex_dm->tdma_adj_type = 12;
2037 } else if (result == 1) {
2038 if (coex_dm->cur_ps_tdma == 4) {
2039 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2041 coex_dm->tdma_adj_type = 3;
2042 } else if (coex_dm->cur_ps_tdma == 3) {
2043 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2045 coex_dm->tdma_adj_type = 3;
2046 } else if (coex_dm->cur_ps_tdma == 2) {
2047 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2049 coex_dm->tdma_adj_type = 3;
2050 } else if (coex_dm->cur_ps_tdma == 12) {
2051 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2053 coex_dm->tdma_adj_type = 11;
2054 } else if (coex_dm->cur_ps_tdma == 11) {
2055 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2057 coex_dm->tdma_adj_type = 11;
2058 } else if (coex_dm->cur_ps_tdma == 10) {
2059 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2061 coex_dm->tdma_adj_type = 11;
2067 static void btc8821a2ant_tdma_dur_adj(struct btc_coexist *btcoexist,
2068 bool sco_hid, bool tx_pause,
2071 static long up, dn, m, n, wait_count;
2072 /* 0: no change, +1: increase WiFi duration,
2073 * -1: decrease WiFi duration
2078 btc_alg_dbg(ALGO_TRACE_FW,
2079 "[BTCoex], TdmaDurationAdjust()\n");
2081 if (coex_dm->reset_tdma_adjust) {
2082 coex_dm->reset_tdma_adjust = false;
2083 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2084 "[BTCoex], first run TdmaDurationAdjust()!!\n");
2087 if (max_interval == 1) {
2088 halbtc8821a2ant_ps_tdma(btcoexist,
2091 coex_dm->tdma_adj_type = 13;
2092 } else if (max_interval == 2) {
2093 halbtc8821a2ant_ps_tdma(btcoexist,
2096 coex_dm->tdma_adj_type = 14;
2097 } else if (max_interval == 3) {
2098 halbtc8821a2ant_ps_tdma(btcoexist,
2101 coex_dm->tdma_adj_type = 15;
2103 halbtc8821a2ant_ps_tdma(btcoexist,
2106 coex_dm->tdma_adj_type = 15;
2109 if (max_interval == 1) {
2110 halbtc8821a2ant_ps_tdma(btcoexist,
2113 coex_dm->tdma_adj_type = 9;
2114 } else if (max_interval == 2) {
2115 halbtc8821a2ant_ps_tdma(btcoexist,
2118 coex_dm->tdma_adj_type = 10;
2119 } else if (max_interval == 3) {
2120 halbtc8821a2ant_ps_tdma(btcoexist,
2123 coex_dm->tdma_adj_type = 11;
2125 halbtc8821a2ant_ps_tdma(btcoexist,
2128 coex_dm->tdma_adj_type = 11;
2133 if (max_interval == 1) {
2134 halbtc8821a2ant_ps_tdma(btcoexist,
2137 coex_dm->tdma_adj_type = 5;
2138 } else if (max_interval == 2) {
2139 halbtc8821a2ant_ps_tdma(btcoexist,
2142 coex_dm->tdma_adj_type = 6;
2143 } else if (max_interval == 3) {
2144 halbtc8821a2ant_ps_tdma(btcoexist,
2147 coex_dm->tdma_adj_type = 7;
2149 halbtc8821a2ant_ps_tdma(btcoexist,
2152 coex_dm->tdma_adj_type = 7;
2155 if (max_interval == 1) {
2156 halbtc8821a2ant_ps_tdma(btcoexist,
2159 coex_dm->tdma_adj_type = 1;
2160 } else if (max_interval == 2) {
2161 halbtc8821a2ant_ps_tdma(btcoexist,
2164 coex_dm->tdma_adj_type = 2;
2165 } else if (max_interval == 3) {
2166 halbtc8821a2ant_ps_tdma(btcoexist,
2169 coex_dm->tdma_adj_type = 3;
2171 halbtc8821a2ant_ps_tdma(btcoexist,
2174 coex_dm->tdma_adj_type = 3;
2186 /* accquire the BT TRx retry count from BT_Info byte2 */
2187 retry_count = coex_sta->bt_retry_cnt;
2188 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2189 "[BTCoex], retry_count = %d\n", retry_count);
2190 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2191 "[BTCoex], up = %d, dn = %d, m = %d, n = %d, wait_count = %d\n",
2192 (int)up, (int)dn, (int)m, (int)n, (int)wait_count);
2196 if (retry_count == 0) {
2197 /* no retry in the last 2-second duration */
2205 /* if (retry count == 0) for 2*n seconds,
2206 * make WiFi duration wider
2213 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2214 "[BTCoex], Increase wifi duration!!\n");
2216 } else if (retry_count <= 3) {
2217 /* <=3 retry in the last 2-second duration */
2225 /* if retry count< 3 for 2*2 seconds,
2226 * shrink wifi duration
2228 if (wait_count <= 2)
2229 m++; /* avoid bounce in two levels */
2232 /* m max value is 20, max time is 120 second,
2233 * recheck if adjust WiFi duration.
2243 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2244 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
2247 /* retry count > 3, if retry count > 3 happens once,
2248 * shrink WiFi duration
2250 if (wait_count == 1)
2251 m++; /* avoid bounce in two levels */
2254 /* m max value is 20, max time is 120 second,
2255 * recheck if adjust WiFi duration.
2265 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2266 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
2269 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2270 "[BTCoex], max Interval = %d\n", max_interval);
2271 if (max_interval == 1)
2272 btc8821a2_int1(btcoexist, tx_pause, result);
2273 else if (max_interval == 2)
2274 btc8821a2_int2(btcoexist, tx_pause, result);
2275 else if (max_interval == 3)
2276 btc8821a2_int3(btcoexist, tx_pause, result);
2279 /* if current PsTdma not match with the recorded one
2280 * (when scan, dhcp...), then we have to adjust it back to
2281 * the previous recorded one.
2283 if (coex_dm->cur_ps_tdma != coex_dm->tdma_adj_type) {
2284 bool scan = false, link = false, roam = false;
2286 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2287 "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma = %d, recordPsTdma = %d\n",
2288 coex_dm->cur_ps_tdma, coex_dm->tdma_adj_type);
2290 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2291 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2292 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2294 if (!scan && !link && !roam) {
2295 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2296 coex_dm->tdma_adj_type);
2298 btc_alg_dbg(ALGO_TRACE_FW_DETAIL,
2299 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2303 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6);
2306 /* SCO only or SCO+PAN(HS)*/
2307 static void halbtc8821a2ant_action_sco(struct btc_coexist *btcoexist)
2309 u8 wifi_rssi_state, bt_rssi_state;
2312 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2314 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2316 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
2318 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2319 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2321 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2323 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2325 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2326 /* for SCO quality at 11b/g mode */
2327 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC,
2328 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);
2330 /* for SCO quality & wifi performance balance at 11n mode */
2331 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC,
2332 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3);
2335 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2337 * halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2340 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2341 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2342 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2343 false, 0); /*for voice quality*/
2345 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2346 false, 0); /*for voice quality*/
2350 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2351 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2352 btc8821a2ant_sw_mech1(btcoexist, true, true,
2354 btc8821a2ant_sw_mech2(btcoexist, true, false,
2357 btc8821a2ant_sw_mech1(btcoexist, true, true,
2359 btc8821a2ant_sw_mech2(btcoexist, false, false,
2364 * halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2366 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2367 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2368 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2369 false, 0); /*for voice quality*/
2371 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2372 false, 0); /*for voice quality*/
2376 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2377 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2378 btc8821a2ant_sw_mech1(btcoexist, false, true,
2380 btc8821a2ant_sw_mech2(btcoexist, true, false,
2383 btc8821a2ant_sw_mech1(btcoexist, false, true,
2385 btc8821a2ant_sw_mech2(btcoexist, false, false,
2391 static void halbtc8821a2ant_action_hid(struct btc_coexist *btcoexist)
2393 u8 wifi_rssi_state, bt_rssi_state;
2396 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist,
2398 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2400 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2402 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2403 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2405 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2407 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2409 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2410 /* for HID at 11b/g mode */
2411 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2412 0x5a5a5a5a, 0xffff, 0x3);
2414 /* for HID quality & wifi performance balance at 11n mode */
2415 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2416 0x5aea5aea, 0xffff, 0x3);
2419 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2421 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2422 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2423 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2426 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2431 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2432 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2433 btc8821a2ant_sw_mech1(btcoexist, true, true,
2435 btc8821a2ant_sw_mech2(btcoexist, true, false,
2438 btc8821a2ant_sw_mech1(btcoexist, true, true,
2440 btc8821a2ant_sw_mech2(btcoexist, false, false,
2445 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2446 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2447 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2450 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2455 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2456 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2457 btc8821a2ant_sw_mech1(btcoexist, false, true,
2459 btc8821a2ant_sw_mech2(btcoexist, true, false,
2462 btc8821a2ant_sw_mech1(btcoexist, false, true,
2464 btc8821a2ant_sw_mech2(btcoexist, false, false,
2470 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2471 static void halbtc8821a2ant_action_a2dp(struct btc_coexist *btcoexist)
2473 u8 wifi_rssi_state, bt_rssi_state;
2476 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2478 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2480 /* fw dac swing is called in btc8821a2ant_tdma_dur_adj()
2481 * halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2484 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2485 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2487 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2489 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2491 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2493 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2494 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2495 btc8821a2ant_tdma_dur_adj(btcoexist, false, false, 1);
2497 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2501 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2502 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2503 btc8821a2ant_sw_mech1(btcoexist, true, false,
2505 btc8821a2ant_sw_mech2(btcoexist, true, false,
2508 btc8821a2ant_sw_mech1(btcoexist, true, false,
2510 btc8821a2ant_sw_mech2(btcoexist, false, false,
2515 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2516 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2517 btc8821a2ant_tdma_dur_adj(btcoexist, false, false, 1);
2519 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2523 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2524 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2525 btc8821a2ant_sw_mech1(btcoexist, false, false,
2527 btc8821a2ant_sw_mech2(btcoexist, true, false,
2530 btc8821a2ant_sw_mech1(btcoexist, false, false,
2532 btc8821a2ant_sw_mech2(btcoexist, false, false,
2538 static void halbtc8821a2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2540 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
2543 bt_info_ext = coex_sta->bt_info_ext;
2544 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2546 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2548 /*fw dac swing is called in btc8821a2ant_tdma_dur_adj()
2549 *halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2552 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2553 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2555 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2557 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2559 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2561 if (bt_info_ext&BIT0) {
2563 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 2);
2566 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2570 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2571 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2572 btc8821a2ant_sw_mech1(btcoexist, true, false,
2574 btc8821a2ant_sw_mech2(btcoexist, true, false,
2577 btc8821a2ant_sw_mech1(btcoexist, true, false,
2579 btc8821a2ant_sw_mech2(btcoexist, false, false,
2584 if (bt_info_ext&BIT0) {
2585 /* a2dp basic rate */
2586 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 2);
2589 btc8821a2ant_tdma_dur_adj(btcoexist, false, true, 1);
2593 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2594 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2595 btc8821a2ant_sw_mech1(btcoexist, false, false,
2597 btc8821a2ant_sw_mech2(btcoexist, true, false,
2600 btc8821a2ant_sw_mech1(btcoexist, false, false,
2602 btc8821a2ant_sw_mech2(btcoexist, false, false,
2608 static void halbtc8821a2ant_action_pan_edr(struct btc_coexist *btcoexist)
2610 u8 wifi_rssi_state, bt_rssi_state;
2613 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2615 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2617 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2619 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2620 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2622 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2624 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2626 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2627 /* for HID at 11b/g mode */
2628 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2629 0x5aff5aff, 0xffff, 0x3);
2631 /* for HID quality & wifi performance balance at 11n mode */
2632 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2633 0x5aff5aff, 0xffff, 0x3);
2636 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2638 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2639 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2640 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2643 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2648 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2649 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2650 btc8821a2ant_sw_mech1(btcoexist, true, false,
2652 btc8821a2ant_sw_mech2(btcoexist, true, false,
2655 btc8821a2ant_sw_mech1(btcoexist, true, false,
2657 btc8821a2ant_sw_mech2(btcoexist, false, false,
2662 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2663 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2664 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2667 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2672 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2673 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2674 btc8821a2ant_sw_mech1(btcoexist, false, false,
2676 btc8821a2ant_sw_mech2(btcoexist, true, false,
2679 btc8821a2ant_sw_mech1(btcoexist, false, false,
2681 btc8821a2ant_sw_mech2(btcoexist, false, false,
2688 static void halbtc8821a2ant_action_pan_hs(struct btc_coexist *btcoexist)
2690 u8 wifi_rssi_state, bt_rssi_state;
2693 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist,
2695 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2697 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2699 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2701 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2703 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2704 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2705 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
2708 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
2711 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
2714 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2715 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2716 btc8821a2ant_sw_mech1(btcoexist, true, false,
2718 btc8821a2ant_sw_mech2(btcoexist, true, false,
2721 btc8821a2ant_sw_mech1(btcoexist, true, false,
2723 btc8821a2ant_sw_mech2(btcoexist, false, false,
2728 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2729 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2730 halbtc8821a2ant_dec_bt_pwr(btcoexist,
2733 halbtc8821a2ant_dec_bt_pwr(btcoexist,
2734 NORMAL_EXEC, false);
2737 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2738 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2739 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2742 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2747 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2748 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2749 btc8821a2ant_sw_mech1(btcoexist, false, false,
2751 btc8821a2ant_sw_mech2(btcoexist, true, false,
2754 btc8821a2ant_sw_mech1(btcoexist, false, false,
2756 btc8821a2ant_sw_mech2(btcoexist, false, false,
2763 static void halbtc8821a2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
2765 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
2768 bt_info_ext = coex_sta->bt_info_ext;
2769 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2771 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2773 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2775 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2776 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2778 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2780 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2782 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2783 /* for HID at 11b/g mode */
2784 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2785 0x5afa5afa, 0xffff, 0x3);
2787 /* for HID quality & wifi performance balance at 11n mode */
2788 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2789 0x5afa5afa, 0xffff, 0x3);
2792 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2794 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2795 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2796 if (bt_info_ext&BIT0) {
2797 /* a2dp basic rate */
2798 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2802 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2806 if (bt_info_ext&BIT0) {
2807 /* a2dp basic rate */
2808 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2812 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2818 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2819 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2820 btc8821a2ant_sw_mech1(btcoexist, true, false,
2822 btc8821a2ant_sw_mech2(btcoexist, true, false,
2825 btc8821a2ant_sw_mech1(btcoexist, true, false,
2827 btc8821a2ant_sw_mech2(btcoexist, false, false,
2832 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2833 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2834 if (bt_info_ext&BIT0) {
2835 /* a2dp basic rate */
2836 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2840 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2844 if (bt_info_ext&BIT0) {
2845 /* a2dp basic rate */
2846 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2850 btc8821a2ant_tdma_dur_adj(btcoexist, false,
2856 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2857 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2858 btc8821a2ant_sw_mech1(btcoexist, false, false,
2860 btc8821a2ant_sw_mech2(btcoexist, true, false,
2863 btc8821a2ant_sw_mech1(btcoexist, false, false,
2865 btc8821a2ant_sw_mech2(btcoexist, false, false,
2871 static void halbtc8821a2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
2873 u8 wifi_rssi_state, bt_rssi_state;
2876 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
2878 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2880 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2882 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2883 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2885 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2887 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2889 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2890 /* for HID at 11b/g mode */
2891 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2892 0x5a5f5a5f, 0xffff, 0x3);
2894 /* for HID quality & wifi performance balance at 11n mode */
2895 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2896 0x5a5f5a5f, 0xffff, 0x3);
2899 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2900 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 3);
2902 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2903 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2904 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2907 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2912 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2913 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2914 btc8821a2ant_sw_mech1(btcoexist, true, true,
2916 btc8821a2ant_sw_mech2(btcoexist, true, false,
2919 btc8821a2ant_sw_mech1(btcoexist, true, true,
2921 btc8821a2ant_sw_mech2(btcoexist, false, false,
2925 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2927 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2928 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2929 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2932 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2937 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2938 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2939 btc8821a2ant_sw_mech1(btcoexist, false, true,
2941 btc8821a2ant_sw_mech2(btcoexist, true, false,
2944 btc8821a2ant_sw_mech1(btcoexist, false, true,
2946 btc8821a2ant_sw_mech2(btcoexist, false, false,
2952 /* HID+A2DP+PAN(EDR) */
2953 static void btc8821a2ant_act_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
2955 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
2958 bt_info_ext = coex_sta->bt_info_ext;
2959 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist,
2961 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
2963 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2965 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
2966 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2968 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2970 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2972 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
2973 /* for HID at 11b/g mode */
2974 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2975 0x5a5a5a5a, 0xffff, 0x3);
2977 /* for HID quality & wifi performance balance at 11n mode */
2978 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
2979 0x5a5a5a5a, 0xffff, 0x3);
2982 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2984 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2985 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2986 if (bt_info_ext&BIT0) {
2987 /* a2dp basic rate */
2988 btc8821a2ant_tdma_dur_adj(btcoexist, true,
2992 btc8821a2ant_tdma_dur_adj(btcoexist, true,
2996 if (bt_info_ext&BIT0) {
2997 /* a2dp basic rate */
2998 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3002 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3008 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3009 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3010 btc8821a2ant_sw_mech1(btcoexist, true, true,
3012 btc8821a2ant_sw_mech2(btcoexist, true, false,
3015 btc8821a2ant_sw_mech1(btcoexist, true, true,
3017 btc8821a2ant_sw_mech2(btcoexist, false, false,
3022 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3023 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3024 if (bt_info_ext&BIT0) {
3025 /* a2dp basic rate */
3026 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3030 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3034 if (bt_info_ext&BIT0) {
3035 /* a2dp basic rate */
3036 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3040 btc8821a2ant_tdma_dur_adj(btcoexist, true,
3046 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3047 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3048 btc8821a2ant_sw_mech1(btcoexist, false, true,
3050 btc8821a2ant_sw_mech2(btcoexist, true, false,
3053 btc8821a2ant_sw_mech1(btcoexist, false, true,
3055 btc8821a2ant_sw_mech2(btcoexist, false, false,
3061 static void halbtc8821a2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
3063 u8 wifi_rssi_state, bt_rssi_state, bt_info_ext;
3066 bt_info_ext = coex_sta->bt_info_ext;
3067 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2,
3069 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 35, 0);
3071 if (halbtc8821a2ant_need_to_dec_bt_pwr(btcoexist))
3072 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
3074 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
3076 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3078 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
3079 /* for HID at 11b/g mode */
3080 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3081 0x5f5b5f5b, 0xffffff, 0x3);
3083 /*for HID quality & wifi performance balance at 11n mode*/
3084 halbtc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3085 0x5f5b5f5b, 0xffffff, 0x3);
3088 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3090 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3091 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3092 if (bt_info_ext&BIT0) {
3093 /* a2dp basic rate */
3094 btc8821a2ant_tdma_dur_adj(btcoexist,
3098 btc8821a2ant_tdma_dur_adj(btcoexist,
3102 if (bt_info_ext&BIT0) {
3103 /* a2dp basic rate */
3104 btc8821a2ant_tdma_dur_adj(btcoexist,
3108 btc8821a2ant_tdma_dur_adj(btcoexist,
3114 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3115 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3116 btc8821a2ant_sw_mech1(btcoexist, true, true,
3118 btc8821a2ant_sw_mech2(btcoexist, true, false,
3121 btc8821a2ant_sw_mech1(btcoexist, true, true,
3123 btc8821a2ant_sw_mech2(btcoexist, false, false,
3128 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3129 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3130 if (bt_info_ext&BIT0) {
3131 /* a2dp basic rate */
3132 btc8821a2ant_tdma_dur_adj(btcoexist,
3137 btc8821a2ant_tdma_dur_adj(btcoexist,
3141 if (bt_info_ext&BIT0) {
3143 btc8821a2ant_tdma_dur_adj(btcoexist,
3147 btc8821a2ant_tdma_dur_adj(btcoexist,
3153 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3154 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3155 btc8821a2ant_sw_mech1(btcoexist, false, true,
3157 btc8821a2ant_sw_mech2(btcoexist, true, false,
3160 btc8821a2ant_sw_mech1(btcoexist, false, true,
3162 btc8821a2ant_sw_mech2(btcoexist, false, false,
3168 static void halbtc8821a2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3170 bool wifi_under_5g = false;
3173 if (btcoexist->manual_control) {
3174 btc_alg_dbg(ALGO_TRACE,
3175 "[BTCoex], Manual control!!!\n");
3179 btcoexist->btc_get(btcoexist,
3180 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3182 if (wifi_under_5g) {
3183 btc_alg_dbg(ALGO_TRACE,
3184 "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3185 halbtc8821a2ant_coex_under_5g(btcoexist);
3189 algorithm = halbtc8821a2ant_action_algorithm(btcoexist);
3190 if (coex_sta->c2h_bt_inquiry_page &&
3191 (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3192 btc_alg_dbg(ALGO_TRACE,
3193 "[BTCoex], BT is under inquiry/page scan !!\n");
3194 halbtc8821a2ant_bt_inquiry_page(btcoexist);
3198 coex_dm->cur_algorithm = algorithm;
3199 btc_alg_dbg(ALGO_TRACE,
3200 "[BTCoex], Algorithm = %d\n", coex_dm->cur_algorithm);
3202 if (halbtc8821a2ant_is_common_action(btcoexist)) {
3203 btc_alg_dbg(ALGO_TRACE,
3204 "[BTCoex], Action 2-Ant common\n");
3205 coex_dm->reset_tdma_adjust = true;
3207 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3208 btc_alg_dbg(ALGO_TRACE,
3209 "[BTCoex], pre_algorithm = %d, cur_algorithm = %d\n",
3210 coex_dm->pre_algorithm,
3211 coex_dm->cur_algorithm);
3212 coex_dm->reset_tdma_adjust = true;
3214 switch (coex_dm->cur_algorithm) {
3215 case BT_8821A_2ANT_COEX_ALGO_SCO:
3216 btc_alg_dbg(ALGO_TRACE,
3217 "[BTCoex], Action 2-Ant, algorithm = SCO\n");
3218 halbtc8821a2ant_action_sco(btcoexist);
3220 case BT_8821A_2ANT_COEX_ALGO_HID:
3221 btc_alg_dbg(ALGO_TRACE,
3222 "[BTCoex], Action 2-Ant, algorithm = HID\n");
3223 halbtc8821a2ant_action_hid(btcoexist);
3225 case BT_8821A_2ANT_COEX_ALGO_A2DP:
3226 btc_alg_dbg(ALGO_TRACE,
3227 "[BTCoex], Action 2-Ant, algorithm = A2DP\n");
3228 halbtc8821a2ant_action_a2dp(btcoexist);
3230 case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
3231 btc_alg_dbg(ALGO_TRACE,
3232 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
3233 halbtc8821a2ant_action_a2dp_pan_hs(btcoexist);
3235 case BT_8821A_2ANT_COEX_ALGO_PANEDR:
3236 btc_alg_dbg(ALGO_TRACE,
3237 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
3238 halbtc8821a2ant_action_pan_edr(btcoexist);
3240 case BT_8821A_2ANT_COEX_ALGO_PANHS:
3241 btc_alg_dbg(ALGO_TRACE,
3242 "[BTCoex], Action 2-Ant, algorithm = HS mode\n");
3243 halbtc8821a2ant_action_pan_hs(btcoexist);
3245 case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
3246 btc_alg_dbg(ALGO_TRACE,
3247 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
3248 halbtc8821a2ant_action_pan_edr_a2dp(btcoexist);
3250 case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
3251 btc_alg_dbg(ALGO_TRACE,
3252 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3253 halbtc8821a2ant_action_pan_edr_hid(btcoexist);
3255 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3256 btc_alg_dbg(ALGO_TRACE,
3257 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3258 btc8821a2ant_act_hid_a2dp_pan_edr(btcoexist);
3260 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
3261 btc_alg_dbg(ALGO_TRACE,
3262 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
3263 halbtc8821a2ant_action_hid_a2dp(btcoexist);
3266 btc_alg_dbg(ALGO_TRACE,
3267 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3268 halbtc8821a2ant_coex_all_off(btcoexist);
3271 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3275 /*============================================================
3276 *work around function start with wa_halbtc8821a2ant_
3277 *============================================================
3278 *============================================================
3279 * extern function start with EXhalbtc8821a2ant_
3280 *============================================================
3282 void ex_halbtc8821a2ant_init_hwconfig(struct btc_coexist *btcoexist)
3286 btc_iface_dbg(INTF_INIT,
3287 "[BTCoex], 2Ant Init HW Config!!\n");
3289 /* backup rf 0x1e value */
3290 coex_dm->bt_rf0x1e_backup =
3291 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
3293 /* 0x790[5:0] = 0x5 */
3294 u1tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3297 btcoexist->btc_write_1byte(btcoexist, 0x790, u1tmp);
3300 halbtc8821a2ant_set_ant_path(btcoexist,
3301 BTC_ANT_WIFI_AT_MAIN, true, false);
3304 halbtc8821a2ant_coex_table(btcoexist,
3305 FORCE_EXEC, 0x55555555, 0x55555555,
3308 /* Enable counter statistics */
3309 /*0x76e[3] = 1, WLAN_Act control by PTA*/
3310 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
3311 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3312 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3316 ex_halbtc8821a2ant_init_coex_dm(
3317 struct btc_coexist *btcoexist
3320 btc_iface_dbg(INTF_INIT,
3321 "[BTCoex], Coex Mechanism Init!!\n");
3323 halbtc8821a2ant_init_coex_dm(btcoexist);
3327 ex_halbtc8821a2ant_display_coex_info(
3328 struct btc_coexist *btcoexist
3331 struct btc_board_info *board_info = &btcoexist->board_info;
3332 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3333 struct rtl_priv *rtlpriv = btcoexist->adapter;
3334 u8 u1tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3336 bool roam = false, scan = false, link = false, wifi_under_5g = false;
3337 bool bt_hs_on = false, wifi_busy = false;
3338 long wifi_rssi = 0, bt_hs_rssi = 0;
3339 u32 wifi_bw, wifi_traffic_dir;
3340 u8 wifi_dot_11_chnl, wifi_hs_chnl;
3341 u32 fw_ver = 0, bt_patch_ver = 0;
3343 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3344 "\r\n ============[BT Coexist info]============");
3346 if (!board_info->bt_exist) {
3347 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
3351 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3352 "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
3353 board_info->pg_ant_num, board_info->btdm_ant_num);
3355 if (btcoexist->manual_control) {
3356 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3357 "\r\n %-35s", "[Action Manual control]!!");
3360 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3361 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
3362 ((stack_info->profile_notified) ? "Yes" : "No"),
3363 stack_info->hci_version);
3365 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3366 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3367 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3368 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
3369 "CoexVer/ FwVer/ PatchVer",
3370 glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
3371 fw_ver, bt_patch_ver, bt_patch_ver);
3373 btcoexist->btc_get(btcoexist,
3374 BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3375 btcoexist->btc_get(btcoexist,
3376 BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_dot_11_chnl);
3377 btcoexist->btc_get(btcoexist,
3378 BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
3379 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3380 "\r\n %-35s = %d / %d(%d)",
3381 "Dot11 channel / HsMode(HsChnl)",
3382 wifi_dot_11_chnl, bt_hs_on, wifi_hs_chnl);
3384 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3385 "\r\n %-35s = %3ph ",
3386 "H2C Wifi inform bt chnl Info",
3387 coex_dm->wifi_chnl_info);
3389 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
3390 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
3391 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3392 "\r\n %-35s = %ld/ %ld", "Wifi rssi/ HS rssi",
3393 wifi_rssi, bt_hs_rssi);
3395 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3396 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3397 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3398 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3399 "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
3402 btcoexist->btc_get(btcoexist,
3403 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3404 btcoexist->btc_get(btcoexist,
3405 BTC_GET_U4_WIFI_BW, &wifi_bw);
3406 btcoexist->btc_get(btcoexist,
3407 BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3408 btcoexist->btc_get(btcoexist,
3409 BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifi_traffic_dir);
3410 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3411 "\r\n %-35s = %s / %s/ %s ", "Wifi status",
3412 (wifi_under_5g ? "5G" : "2.4G"),
3413 ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
3414 (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
3415 ((!wifi_busy) ? "idle" :
3416 ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
3417 "uplink" : "downlink")));
3419 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3420 "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]",
3421 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
3422 ((BT_8821A_2ANT_BT_STATUS_IDLE == coex_dm->bt_status)
3423 ? "idle" : ((BT_8821A_2ANT_BT_STATUS_CON_IDLE ==
3424 coex_dm->bt_status) ? "connected-idle" : "busy"))),
3425 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
3427 if (stack_info->profile_notified) {
3428 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3429 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
3430 stack_info->sco_exist, stack_info->hid_exist,
3431 stack_info->pan_exist, stack_info->a2dp_exist);
3433 btcoexist->btc_disp_dbg_msg(btcoexist,
3434 BTC_DBG_DISP_BT_LINK_INFO);
3437 bt_info_ext = coex_sta->bt_info_ext;
3438 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
3439 "BT Info A2DP rate",
3440 (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
3442 for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) {
3443 if (coex_sta->bt_info_c2h_cnt[i]) {
3444 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3445 "\r\n %-35s = %7ph(%d)",
3446 glbt_info_src_8821a_2ant[i],
3447 coex_sta->bt_info_c2h[i],
3448 coex_sta->bt_info_c2h_cnt[i]);
3452 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/%s",
3453 "PS state, IPS/LPS",
3454 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
3455 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
3456 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3459 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3460 "============[Sw mechanism]============");
3461 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3462 "\r\n %-35s = %d/ %d/ %d/ %d ",
3463 "SM1[ShRf/ LpRA/ LimDig/ btLna]",
3464 coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
3465 coex_dm->limited_dig, coex_dm->cur_bt_lna_constrain);
3466 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3467 "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3468 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3469 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
3470 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
3473 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3474 "============[Fw mechanism]============");
3476 if (!btcoexist->manual_control) {
3477 ps_tdma_case = coex_dm->cur_ps_tdma;
3478 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3479 "\r\n %-35s = %5ph case-%d",
3481 coex_dm->ps_tdma_para, ps_tdma_case);
3483 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3484 "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct",
3485 coex_dm->cur_dec_bt_pwr,
3486 coex_dm->cur_ignore_wlan_act);
3490 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3491 "\r\n %-35s", "============[Hw setting]============");
3493 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3494 "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal",
3495 coex_dm->bt_rf0x1e_backup);
3497 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
3498 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
3499 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x ",
3500 "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
3501 u1tmp[0], u1tmp[1]);
3503 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
3504 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
3505 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3506 "0x8db(ADC)/0xc5b[29:25](DAC)",
3507 ((u1tmp[0]&0x60)>>5), ((u1tmp[1]&0x3e)>>1));
3509 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3510 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3511 "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
3512 u4tmp[0]&0xff, ((u4tmp[0]&0x30000000)>>28));
3514 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
3515 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
3516 u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
3517 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3518 "0x40/ 0x4c[24:23]/ 0x974",
3519 u1tmp[0], ((u4tmp[0]&0x01800000)>>23), u4tmp[1]);
3521 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
3522 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
3523 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3524 "0x550(bcn ctrl)/0x522",
3525 u4tmp[0], u1tmp[0]);
3527 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
3528 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
3529 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3530 "0xc50(DIG)/0xa0a(CCK-TH)",
3531 u4tmp[0], u1tmp[0]);
3533 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
3534 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
3535 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
3536 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3538 u4tmp[0], (u1tmp[0]<<8) + u1tmp[1]);
3540 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
3541 u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
3542 u4tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
3543 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3544 "0x6c0/0x6c4/0x6c8",
3545 u4tmp[0], u4tmp[1], u4tmp[2]);
3547 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3548 "0x770 (hi-pri Rx/Tx)",
3549 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
3550 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3551 "0x774(low-pri Rx/Tx)",
3552 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
3554 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang*/
3555 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x41b);
3556 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x",
3557 "0x41b (mgntQ hang chk == 0xf)",
3560 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
3563 void ex_halbtc8821a2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
3565 if (BTC_IPS_ENTER == type) {
3566 btc_iface_dbg(INTF_NOTIFY,
3567 "[BTCoex], IPS ENTER notify\n");
3568 coex_sta->under_ips = true;
3569 halbtc8821a2ant_coex_all_off(btcoexist);
3570 } else if (BTC_IPS_LEAVE == type) {
3571 btc_iface_dbg(INTF_NOTIFY,
3572 "[BTCoex], IPS LEAVE notify\n");
3573 coex_sta->under_ips = false;
3574 /*halbtc8821a2ant_init_coex_dm(btcoexist);*/
3578 void ex_halbtc8821a2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
3580 if (BTC_LPS_ENABLE == type) {
3581 btc_iface_dbg(INTF_NOTIFY,
3582 "[BTCoex], LPS ENABLE notify\n");
3583 coex_sta->under_lps = true;
3584 } else if (BTC_LPS_DISABLE == type) {
3585 btc_iface_dbg(INTF_NOTIFY,
3586 "[BTCoex], LPS DISABLE notify\n");
3587 coex_sta->under_lps = false;
3591 void ex_halbtc8821a2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
3593 if (BTC_SCAN_START == type) {
3594 btc_iface_dbg(INTF_NOTIFY,
3595 "[BTCoex], SCAN START notify\n");
3596 } else if (BTC_SCAN_FINISH == type) {
3597 btc_iface_dbg(INTF_NOTIFY,
3598 "[BTCoex], SCAN FINISH notify\n");
3602 void ex_halbtc8821a2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
3604 if (BTC_ASSOCIATE_START == type) {
3605 btc_iface_dbg(INTF_NOTIFY,
3606 "[BTCoex], CONNECT START notify\n");
3607 } else if (BTC_ASSOCIATE_FINISH == type) {
3608 btc_iface_dbg(INTF_NOTIFY,
3609 "[BTCoex], CONNECT FINISH notify\n");
3613 void ex_halbtc8821a2ant_media_status_notify(struct btc_coexist *btcoexist,
3616 u8 h2c_parameter[3] = {0};
3618 u8 wifi_central_chnl;
3620 if (BTC_MEDIA_CONNECT == type) {
3621 btc_iface_dbg(INTF_NOTIFY,
3622 "[BTCoex], MEDIA connect notify\n");
3624 btc_iface_dbg(INTF_NOTIFY,
3625 "[BTCoex], MEDIA disconnect notify\n");
3628 /* only 2.4G we need to inform bt the chnl mask*/
3629 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
3630 &wifi_central_chnl);
3631 if ((BTC_MEDIA_CONNECT == type) &&
3632 (wifi_central_chnl <= 14)) {
3633 h2c_parameter[0] = 0x1;
3634 h2c_parameter[1] = wifi_central_chnl;
3635 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3636 if (BTC_WIFI_BW_HT40 == wifi_bw)
3637 h2c_parameter[2] = 0x30;
3639 h2c_parameter[2] = 0x20;
3642 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3643 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3644 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3646 btc_alg_dbg(ALGO_TRACE_FW_EXEC,
3647 "[BTCoex], FW write 0x66 = 0x%x\n",
3648 h2c_parameter[0] << 16 |
3649 h2c_parameter[1] << 8 |
3652 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3655 void ex_halbtc8821a2ant_special_packet_notify(struct btc_coexist *btcoexist,
3657 if (type == BTC_PACKET_DHCP) {
3658 btc_iface_dbg(INTF_NOTIFY,
3659 "[BTCoex], DHCP Packet notify\n");
3663 void ex_halbtc8821a2ant_bt_info_notify(struct btc_coexist *btcoexist,
3664 u8 *tmp_buf, u8 length)
3667 u8 i, rsp_source = 0;
3668 static u32 set_bt_lna_cnt, set_bt_psd_mode;
3669 bool bt_busy = false, limited_dig = false;
3670 bool wifi_connected = false, bt_hs_on = false;
3672 coex_sta->c2h_bt_info_req_sent = false;
3674 rsp_source = tmp_buf[0]&0xf;
3675 if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX)
3676 rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
3677 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3679 btc_iface_dbg(INTF_NOTIFY,
3680 "[BTCoex], Bt info[%d], length = %d, hex data = [",
3681 rsp_source, length);
3682 for (i = 0; i < length; i++) {
3683 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3685 bt_info = tmp_buf[i];
3686 if (i == length-1) {
3687 btc_iface_dbg(INTF_NOTIFY,
3688 "0x%02x]\n", tmp_buf[i]);
3690 btc_iface_dbg(INTF_NOTIFY,
3691 "0x%02x, ", tmp_buf[i]);
3695 if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) {
3696 coex_sta->bt_retry_cnt = /* [3:0]*/
3697 coex_sta->bt_info_c2h[rsp_source][2]&0xf;
3700 coex_sta->bt_info_c2h[rsp_source][3]*2+10;
3702 coex_sta->bt_info_ext =
3703 coex_sta->bt_info_c2h[rsp_source][4];
3705 /* Here we need to resend some wifi info to BT*/
3706 /* because bt is reset and loss of the info.*/
3707 if ((coex_sta->bt_info_ext & BIT1)) {
3708 btcoexist->btc_get(btcoexist,
3709 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3710 if (wifi_connected) {
3711 ex_halbtc8821a2ant_media_status_notify(btcoexist,
3714 ex_halbtc8821a2ant_media_status_notify(btcoexist,
3715 BTC_MEDIA_DISCONNECT);
3718 set_bt_psd_mode = 0;
3720 if (set_bt_psd_mode <= 3) {
3721 halbtc8821a2ant_set_bt_psd_mode(btcoexist, FORCE_EXEC,
3722 0x0); /*fix CH-BW mode*/
3726 if (coex_dm->cur_bt_lna_constrain) {
3727 if (!(coex_sta->bt_info_ext & BIT2)) {
3728 if (set_bt_lna_cnt <= 3) {
3729 btc8821a2_set_bt_lna_const(btcoexist,
3739 if ((coex_sta->bt_info_ext & BIT3)) {
3740 halbtc8821a2ant_ignore_wlan_act(btcoexist,
3743 /* BT already NOT ignore Wlan active, do nothing here.*/
3746 if ((coex_sta->bt_info_ext & BIT4)) {
3747 /* BT auto report already enabled, do nothing*/
3749 halbtc8821a2ant_bt_auto_report(btcoexist,
3754 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3755 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
3756 if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE) {
3757 coex_sta->c2h_bt_inquiry_page = true;
3758 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_IDLE;
3760 coex_sta->c2h_bt_inquiry_page = false;
3761 if (bt_info == 0x1) {
3762 /* connection exists but not busy*/
3763 coex_sta->bt_link_exist = true;
3764 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CON_IDLE;
3765 } else if (bt_info & BT_INFO_8821A_2ANT_B_CONNECTION) {
3766 /* connection exists and some link is busy*/
3767 coex_sta->bt_link_exist = true;
3768 if (bt_info & BT_INFO_8821A_2ANT_B_FTP)
3769 coex_sta->pan_exist = true;
3771 coex_sta->pan_exist = false;
3772 if (bt_info & BT_INFO_8821A_2ANT_B_A2DP)
3773 coex_sta->a2dp_exist = true;
3775 coex_sta->a2dp_exist = false;
3776 if (bt_info & BT_INFO_8821A_2ANT_B_HID)
3777 coex_sta->hid_exist = true;
3779 coex_sta->hid_exist = false;
3780 if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO)
3781 coex_sta->sco_exist = true;
3783 coex_sta->sco_exist = false;
3784 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_IDLE;
3786 coex_sta->bt_link_exist = false;
3787 coex_sta->pan_exist = false;
3788 coex_sta->a2dp_exist = false;
3789 coex_sta->hid_exist = false;
3790 coex_sta->sco_exist = false;
3791 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_IDLE;
3795 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_IDLE;
3798 if (BT_8821A_2ANT_BT_STATUS_NON_IDLE == coex_dm->bt_status)
3802 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3804 if (BT_8821A_2ANT_BT_STATUS_IDLE != coex_dm->bt_status)
3807 limited_dig = false;
3808 coex_dm->limited_dig = limited_dig;
3809 btcoexist->btc_set(btcoexist,
3810 BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
3812 halbtc8821a2ant_run_coexist_mechanism(btcoexist);
3815 void ex_halbtc8821a2ant_halt_notify(struct btc_coexist *btcoexist)
3817 btc_iface_dbg(INTF_NOTIFY,
3818 "[BTCoex], Halt notify\n");
3820 halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3821 ex_halbtc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3824 void ex_halbtc8821a2ant_periodical(struct btc_coexist *btcoexist)
3826 static u8 dis_ver_info_cnt;
3827 u32 fw_ver = 0, bt_patch_ver = 0;
3828 struct btc_board_info *board_info = &btcoexist->board_info;
3829 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3831 btc_alg_dbg(ALGO_TRACE,
3832 "[BTCoex], ==========================Periodical===========================\n");
3834 if (dis_ver_info_cnt <= 5) {
3835 dis_ver_info_cnt += 1;
3836 btc_iface_dbg(INTF_INIT,
3837 "[BTCoex], ****************************************************************\n");
3838 btc_iface_dbg(INTF_INIT,
3839 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
3840 board_info->pg_ant_num,
3841 board_info->btdm_ant_num,
3842 board_info->btdm_ant_pos);
3843 btc_iface_dbg(INTF_INIT,
3844 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
3845 stack_info->profile_notified ? "Yes" : "No",
3846 stack_info->hci_version);
3847 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
3849 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3850 btc_iface_dbg(INTF_INIT,
3851 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
3852 glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
3853 fw_ver, bt_patch_ver, bt_patch_ver);
3854 btc_iface_dbg(INTF_INIT,
3855 "[BTCoex], ****************************************************************\n");
3858 halbtc8821a2ant_query_bt_info(btcoexist);
3859 halbtc8821a2ant_monitor_bt_ctr(btcoexist);
3860 btc8821a2ant_mon_bt_en_dis(btcoexist);