1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2016 - 2017 Realtek Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 *****************************************************************************/
16
17
18 /* ************************************************************
19 * Description:
20 *
21 * This file is for RTL8822B Co-exist mechanism
22 *
23 * History
24 * 2012/11/15 Cosa first check in.
25 *
26 * ************************************************************ */
27
28 /* ************************************************************
29 * include files
30 * ************************************************************ */
31 #include "mp_precomp.h"
32
33 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
34
35 #if (RTL8822B_SUPPORT == 1)
36 /* ************************************************************
37 * Global variables, these are static variables
38 * ************************************************************ */
39 static u8 *trace_buf = &gl_btc_trace_buf[0];
40 static struct coex_dm_8822b_2ant glcoex_dm_8822b_2ant;
41 static struct coex_dm_8822b_2ant *coex_dm = &glcoex_dm_8822b_2ant;
42 static struct coex_sta_8822b_2ant glcoex_sta_8822b_2ant;
43 static struct coex_sta_8822b_2ant *coex_sta = &glcoex_sta_8822b_2ant;
44 static struct psdscan_sta_8822b_2ant gl_psd_scan_8822b_2ant;
45 static struct psdscan_sta_8822b_2ant *psd_scan = &gl_psd_scan_8822b_2ant;
46 static struct rfe_type_8822b_2ant gl_rfe_type_8822b_2ant;
47 static struct rfe_type_8822b_2ant *rfe_type = &gl_rfe_type_8822b_2ant;
48
49 static const char *const glbt_info_src_8822b_2ant[] = {
50 "BT Info[wifi fw]",
51 "BT Info[bt rsp]",
52 "BT Info[bt auto report]",
53 };
54
55 static u32 glcoex_ver_date_8822b_2ant = 20170815;
56 static u32 glcoex_ver_8822b_2ant = 0x4a;
57 static u32 glcoex_ver_btdesired_8822b_2ant = 0x42;
58
59
60 /* ************************************************************
61 * local function proto type if needed
62 * ************************************************************
63 * ************************************************************
64 * local function start with halbtc8822b2ant_
65 * ************************************************************ */
66 static
halbtc8822b2ant_bt_rssi_state(IN struct btc_coexist * btcoexist,u8 * ppre_bt_rssi_state,u8 level_num,u8 rssi_thresh,u8 rssi_thresh1)67 u8 halbtc8822b2ant_bt_rssi_state(IN struct btc_coexist *btcoexist,
68 u8 *ppre_bt_rssi_state, u8 level_num,
69 u8 rssi_thresh, u8 rssi_thresh1)
70 {
71 s32 bt_rssi = 0;
72 u8 bt_rssi_state = *ppre_bt_rssi_state;
73
74 bt_rssi = coex_sta->bt_rssi;
75
76 if (level_num == 2) {
77 if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
78 (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
79 if (bt_rssi >= (rssi_thresh +
80 BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
81 bt_rssi_state = BTC_RSSI_STATE_HIGH;
82 else
83 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
84 } else {
85 if (bt_rssi < rssi_thresh)
86 bt_rssi_state = BTC_RSSI_STATE_LOW;
87 else
88 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
89 }
90 } else if (level_num == 3) {
91 if (rssi_thresh > rssi_thresh1) {
92 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
93 "[BTCoex], BT Rssi thresh error!!\n");
94 BTC_TRACE(trace_buf);
95 return *ppre_bt_rssi_state;
96 }
97
98 if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
99 (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
100 if (bt_rssi >= (rssi_thresh +
101 BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
102 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
103 else
104 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
105 } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) ||
106 (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
107 if (bt_rssi >= (rssi_thresh1 +
108 BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
109 bt_rssi_state = BTC_RSSI_STATE_HIGH;
110 else if (bt_rssi < rssi_thresh)
111 bt_rssi_state = BTC_RSSI_STATE_LOW;
112 else
113 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
114 } else {
115 if (bt_rssi < rssi_thresh1)
116 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
117 else
118 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
119 }
120 }
121
122 *ppre_bt_rssi_state = bt_rssi_state;
123
124 return bt_rssi_state;
125 }
126
127
128 static
halbtc8822b2ant_wifi_rssi_state(IN struct btc_coexist * btcoexist,IN u8 * pprewifi_rssi_state,IN u8 level_num,IN u8 rssi_thresh,IN u8 rssi_thresh1)129 u8 halbtc8822b2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
130 IN u8 *pprewifi_rssi_state, IN u8 level_num, IN u8 rssi_thresh,
131 IN u8 rssi_thresh1)
132 {
133 s32 wifi_rssi = 0;
134 u8 wifi_rssi_state = *pprewifi_rssi_state;
135
136 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
137
138 if (level_num == 2) {
139 if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) ||
140 (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
141 if (wifi_rssi >= (rssi_thresh +
142 BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
143 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
144 else
145 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
146 } else {
147 if (wifi_rssi < rssi_thresh)
148 wifi_rssi_state = BTC_RSSI_STATE_LOW;
149 else
150 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
151 }
152 } else if (level_num == 3) {
153 if (rssi_thresh > rssi_thresh1) {
154 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
155 "[BTCoex], wifi RSSI thresh error!!\n");
156 BTC_TRACE(trace_buf);
157 return *pprewifi_rssi_state;
158 }
159
160 if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) ||
161 (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
162 if (wifi_rssi >= (rssi_thresh +
163 BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
164 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
165 else
166 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
167 } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) ||
168 (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
169 if (wifi_rssi >= (rssi_thresh1 +
170 BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
171 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
172 else if (wifi_rssi < rssi_thresh)
173 wifi_rssi_state = BTC_RSSI_STATE_LOW;
174 else
175 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
176 } else {
177 if (wifi_rssi < rssi_thresh1)
178 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
179 else
180 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
181 }
182 }
183
184 *pprewifi_rssi_state = wifi_rssi_state;
185
186 return wifi_rssi_state;
187 }
188
189
190 static
halbtc8822b2ant_coex_switch_threshold(IN struct btc_coexist * btcoexist,IN u8 isolation_measuared)191 void halbtc8822b2ant_coex_switch_threshold(IN struct btc_coexist *btcoexist,
192 IN u8 isolation_measuared)
193 {
194 s8 interference_wl_tx = 0, interference_bt_tx = 0;
195
196
197 interference_wl_tx = BT_8822B_2ANT_WIFI_MAX_TX_POWER -
198 isolation_measuared;
199 interference_bt_tx = BT_8822B_2ANT_BT_MAX_TX_POWER -
200 isolation_measuared;
201
202 /* coex_sta->isolation_btween_wb default = 25dB, should be from config file */
203 if (coex_sta->isolation_btween_wb > 20) {
204
205 coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1;
206 coex_sta->wifi_coex_thres2 = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES2;
207
208 coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1;
209 coex_sta->bt_coex_thres2 = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES2;
210 } else {
211
212 coex_sta->wifi_coex_thres = 90;
213 coex_sta->wifi_coex_thres2 = 90;
214
215 coex_sta->bt_coex_thres = 90;
216 coex_sta->bt_coex_thres2 = 90;
217 }
218
219 #if 0
220 coex_sta->wifi_coex_thres = interference_wl_tx + BT_8822B_2ANT_WIFI_SIR_THRES1;
221 coex_sta->wifi_coex_thres2 = interference_wl_tx + BT_8822B_2ANT_WIFI_SIR_THRES2;
222
223 coex_sta->bt_coex_thres = interference_bt_tx + BT_8822B_2ANT_BT_SIR_THRES1;
224 coex_sta->bt_coex_thres2 = interference_bt_tx + BT_8822B_2ANT_BT_SIR_THRES2;
225 #endif
226
227
228 #if 0
229 if (BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 < (isolation_measuared -
230 BT_8822B_2ANT_DEFAULT_ISOLATION))
231 coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1;
232 else
233 coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 - (isolation_measuared -
234 BT_8822B_2ANT_DEFAULT_ISOLATION);
235
236 if (BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 < (isolation_measuared -
237 BT_8822B_2ANT_DEFAULT_ISOLATION))
238 coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1;
239 else
240 coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 - (isolation_measuared -
241 BT_8822B_2ANT_DEFAULT_ISOLATION);
242
243 #endif
244 }
245
246 static
halbtc8822b2ant_query_bt_info(IN struct btc_coexist * btcoexist)247 void halbtc8822b2ant_query_bt_info(IN struct btc_coexist *btcoexist)
248 {
249 u8 h2c_parameter[1] = {0};
250
251 if (coex_sta->bt_disabled) {
252 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
253 "[BTCoex], No query BT info because BT is disabled!\n");
254 BTC_TRACE(trace_buf);
255 return;
256 }
257
258
259 h2c_parameter[0] |= BIT(0); /* trigger */
260
261 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
262 }
263
264
265 static
halbtc8822b2ant_monitor_bt_ctr(IN struct btc_coexist * btcoexist)266 void halbtc8822b2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
267 {
268 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
269 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
270 static u8 num_of_bt_counter_chk = 0, cnt_slave = 0, cnt_autoslot_hang = 0;
271
272 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
273
274 reg_hp_txrx = 0x770;
275 reg_lp_txrx = 0x774;
276
277 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
278 reg_hp_tx = u32tmp & MASKLWORD;
279 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
280
281 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
282 reg_lp_tx = u32tmp & MASKLWORD;
283 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
284
285 coex_sta->high_priority_tx = reg_hp_tx;
286 coex_sta->high_priority_rx = reg_hp_rx;
287 coex_sta->low_priority_tx = reg_lp_tx;
288 coex_sta->low_priority_rx = reg_lp_rx;
289
290
291 /* reset counter */
292 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
293
294 if ((coex_sta->low_priority_tx > 1050) &&
295 (!coex_sta->c2h_bt_inquiry_page))
296 coex_sta->pop_event_cnt++;
297
298 if ((coex_sta->low_priority_rx >= 950) &&
299 (coex_sta->low_priority_rx >= coex_sta->low_priority_tx)
300 && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) &&
301 (coex_sta->bt_link_exist)) {
302 if (cnt_slave >= 2) {
303 bt_link_info->slave_role = TRUE;
304 cnt_slave = 2;
305 } else {
306 cnt_slave++;
307 }
308 } else {
309 if (cnt_slave == 0) {
310 bt_link_info->slave_role = FALSE;
311 cnt_slave = 0;
312 } else {
313 cnt_slave--;
314 }
315
316 }
317
318 if (coex_sta->is_tdma_btautoslot) {
319 if ((coex_sta->low_priority_tx >= 1300) &&
320 (coex_sta->low_priority_rx <= 150)) {
321 if (cnt_autoslot_hang >= 2) {
322 coex_sta->is_tdma_btautoslot_hang = TRUE;
323 cnt_autoslot_hang = 2;
324 } else {
325 cnt_autoslot_hang++;
326 }
327 } else {
328 if (cnt_autoslot_hang == 0) {
329 coex_sta->is_tdma_btautoslot_hang = FALSE;
330 cnt_autoslot_hang = 0;
331 } else {
332 cnt_autoslot_hang--;
333 }
334 }
335 }
336
337 if (coex_sta->sco_exist) {
338 if ((coex_sta->high_priority_tx >= 400) &&
339 (coex_sta->high_priority_rx >= 400))
340 coex_sta->is_eSCO_mode = FALSE;
341 else
342 coex_sta->is_eSCO_mode = TRUE;
343 }
344
345 if (bt_link_info->hid_only) {
346 if (coex_sta->low_priority_rx > 50)
347 coex_sta->is_hid_low_pri_tx_overhead = true;
348 else
349 coex_sta->is_hid_low_pri_tx_overhead = false;
350 }
351
352 if ((coex_sta->high_priority_tx == 0) &&
353 (coex_sta->high_priority_rx == 0) &&
354 (coex_sta->low_priority_tx == 0) &&
355 (coex_sta->low_priority_rx == 0)) {
356 num_of_bt_counter_chk++;
357 if (num_of_bt_counter_chk >= 3) {
358 halbtc8822b2ant_query_bt_info(btcoexist);
359 num_of_bt_counter_chk = 0;
360 }
361 }
362
363 }
364
365 static
halbtc8822b2ant_monitor_wifi_ctr(IN struct btc_coexist * btcoexist)366 void halbtc8822b2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
367 {
368 s32 wifi_rssi = 0;
369 boolean wifi_busy = FALSE, wifi_under_b_mode = FALSE,
370 wifi_scan = FALSE;
371 boolean bt_idle = FALSE;
372 static u8 cck_lock_counter = 0, wl_noisy_count0 = 0,
373 wl_noisy_count1 = 3, wl_noisy_count2 = 0;
374 u32 total_cnt, cnt_cck;
375 u32 cnt_crcok = 0, cnt_crcerr = 0;
376 static u8 cnt = 0, cnt_ccklocking = 0;
377 u8 h2c_parameter[1] = {0};
378 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
379
380 /* Only enable for windows becaus 8821cu H2C 0x69 unknown fail @ linux */
381 if (btcoexist->chip_interface != BTC_INTF_USB) {
382 /*send h2c to query WL FW dbg info */
383 if (((coex_dm->cur_ps_tdma_on) && (coex_sta->force_lps_ctrl)) ||
384 ((coex_sta->acl_busy) && (bt_link_info->a2dp_exist))) {
385 h2c_parameter[0] = 0x8;
386 btcoexist->btc_fill_h2c(btcoexist, 0x69, 1, h2c_parameter);
387 }
388 }
389
390 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
391 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
392 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
393 &wifi_under_b_mode);
394
395 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
396
397 coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(
398 btcoexist,
399 PHYDM_INFO_CRC32_OK_CCK);
400 coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(
401 btcoexist,
402 PHYDM_INFO_CRC32_OK_LEGACY);
403 coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(
404 btcoexist,
405 PHYDM_INFO_CRC32_OK_HT);
406 coex_sta->crc_ok_11n_vht =
407 btcoexist->btc_phydm_query_PHY_counter(
408 btcoexist,
409 PHYDM_INFO_CRC32_OK_VHT);
410
411 coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter(
412 btcoexist, PHYDM_INFO_CRC32_ERROR_CCK);
413 coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter(
414 btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY);
415 coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter(
416 btcoexist, PHYDM_INFO_CRC32_ERROR_HT);
417 coex_sta->crc_err_11n_vht =
418 btcoexist->btc_phydm_query_PHY_counter(
419 btcoexist,
420 PHYDM_INFO_CRC32_ERROR_VHT);
421
422 cnt_crcok = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g
423 + coex_sta->crc_ok_11n
424 + coex_sta->crc_ok_11n_vht;
425
426 cnt_crcerr = coex_sta->crc_err_cck + coex_sta->crc_err_11g
427 + coex_sta->crc_err_11n
428 + coex_sta->crc_err_11n_vht;
429
430 if ((wifi_busy) && (cnt_crcerr != 0)) {
431
432 coex_sta->now_crc_ratio = cnt_crcok/cnt_crcerr;
433
434 if (cnt == 0)
435 coex_sta->acc_crc_ratio = coex_sta->now_crc_ratio;
436 else
437 coex_sta->acc_crc_ratio = (coex_sta->acc_crc_ratio * 7 +
438 coex_sta->now_crc_ratio * 3)/10;
439
440 if (cnt >= 10)
441 cnt = 0;
442 else
443 cnt++;
444 }
445
446
447 /* CCK lock identification */
448 if (coex_sta->cck_lock)
449 cnt_ccklocking++;
450 else if (cnt_ccklocking != 0)
451 cnt_ccklocking--;
452
453 if (cnt_ccklocking >= 3) {
454 cnt_ccklocking = 3;
455 coex_sta->cck_lock_ever = TRUE;
456 }
457
458 /* WiFi environment noisy identification */
459 cnt_cck = coex_sta->crc_ok_cck + coex_sta->crc_err_cck;
460
461 if ((!wifi_busy) && (!coex_sta->cck_lock)) {
462 if (cnt_cck > 250) {
463 if (wl_noisy_count2 < 3)
464 wl_noisy_count2++;
465
466 if (wl_noisy_count2 == 3) {
467 wl_noisy_count0 = 0;
468 wl_noisy_count1 = 0;
469 }
470
471 } else if (cnt_cck < 50) {
472 if (wl_noisy_count0 < 3)
473 wl_noisy_count0++;
474
475 if (wl_noisy_count0 == 3) {
476 wl_noisy_count1 = 0;
477 wl_noisy_count2 = 0;
478 }
479
480 } else {
481 if (wl_noisy_count1 < 3)
482 wl_noisy_count1++;
483
484 if (wl_noisy_count1 == 3) {
485 wl_noisy_count0 = 0;
486 wl_noisy_count2 = 0;
487 }
488 }
489
490 if (wl_noisy_count2 == 3)
491 coex_sta->wl_noisy_level = 2;
492 else if (wl_noisy_count1 == 3)
493 coex_sta->wl_noisy_level = 1;
494 else
495 coex_sta->wl_noisy_level = 0;
496 }
497 }
498
499
500 static
halbtc8822b2ant_is_wifibt_status_changed(IN struct btc_coexist * btcoexist)501 boolean halbtc8822b2ant_is_wifibt_status_changed(IN struct btc_coexist
502 *btcoexist)
503 {
504 static boolean pre_wifi_busy = FALSE, pre_under_4way = FALSE,
505 pre_bt_hs_on = FALSE, pre_bt_off = FALSE,
506 pre_bt_slave = FALSE, pre_hid_low_pri_tx_overhead = FALSE,
507 pre_wifi_under_lps = FALSE, pre_bt_setup_link = FALSE;
508 static u8 pre_hid_busy_num = 0, pre_wl_noisy_level = 0;
509 boolean wifi_busy = FALSE, under_4way = FALSE, bt_hs_on = FALSE;
510 boolean wifi_connected = FALSE;
511 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
512
513 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
514 &wifi_connected);
515 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
516 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
517 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
518 &under_4way);
519
520 if (coex_sta->bt_disabled != pre_bt_off) {
521 pre_bt_off = coex_sta->bt_disabled;
522
523 if (coex_sta->bt_disabled)
524 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
525 "[BTCoex], BT is disabled !!\n");
526 else
527 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
528 "[BTCoex], BT is enabled !!\n");
529
530 BTC_TRACE(trace_buf);
531
532 coex_sta->bt_coex_supported_feature = 0;
533 coex_sta->bt_coex_supported_version = 0;
534 coex_sta->bt_ble_scan_type = 0;
535 coex_sta->bt_ble_scan_para[0] = 0;
536 coex_sta->bt_ble_scan_para[1] = 0;
537 coex_sta->bt_ble_scan_para[2] = 0;
538 coex_sta->bt_reg_vendor_ac = 0xffff;
539 coex_sta->bt_reg_vendor_ae = 0xffff;
540 return TRUE;
541 }
542
543
544 if (wifi_connected) {
545 if (wifi_busy != pre_wifi_busy) {
546 pre_wifi_busy = wifi_busy;
547 return TRUE;
548 }
549 if (under_4way != pre_under_4way) {
550 pre_under_4way = under_4way;
551 return TRUE;
552 }
553 if (bt_hs_on != pre_bt_hs_on) {
554 pre_bt_hs_on = bt_hs_on;
555 return TRUE;
556 }
557 if (coex_sta->wl_noisy_level != pre_wl_noisy_level) {
558 pre_wl_noisy_level = coex_sta->wl_noisy_level;
559 return TRUE;
560 }
561 if (coex_sta->under_lps != pre_wifi_under_lps) {
562 pre_wifi_under_lps = coex_sta->under_lps;
563 if (coex_sta->under_lps)
564 return TRUE;
565 }
566 }
567
568 if (!coex_sta->bt_disabled) {
569 if (coex_sta->hid_busy_num != pre_hid_busy_num) {
570 pre_hid_busy_num = coex_sta->hid_busy_num;
571 return TRUE;
572 }
573
574 if (bt_link_info->slave_role != pre_bt_slave) {
575 pre_bt_slave = bt_link_info->slave_role;
576 return TRUE;
577 }
578
579 if (pre_hid_low_pri_tx_overhead != coex_sta->is_hid_low_pri_tx_overhead) {
580 pre_hid_low_pri_tx_overhead = coex_sta->is_hid_low_pri_tx_overhead;
581 return TRUE;
582 }
583
584 if (pre_bt_setup_link != coex_sta->is_setupLink) {
585 pre_bt_setup_link = coex_sta->is_setupLink;
586 return TRUE;
587 }
588 }
589
590 return FALSE;
591 }
592
593
594 static
halbtc8822b2ant_update_bt_link_info(IN struct btc_coexist * btcoexist)595 void halbtc8822b2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
596 {
597
598 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
599 boolean bt_hs_on = FALSE;
600 boolean bt_busy = FALSE;
601
602 coex_sta->num_of_profile = 0;
603
604 /* set link exist status */
605 if (!(coex_sta->bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
606 coex_sta->bt_link_exist = FALSE;
607 coex_sta->pan_exist = FALSE;
608 coex_sta->a2dp_exist = FALSE;
609 coex_sta->hid_exist = FALSE;
610 coex_sta->sco_exist = FALSE;
611 } else { /* connection exists */
612 coex_sta->bt_link_exist = TRUE;
613 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_FTP) {
614 coex_sta->pan_exist = TRUE;
615 coex_sta->num_of_profile++;
616 } else {
617 coex_sta->pan_exist = FALSE;
618 }
619
620 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_A2DP) {
621 coex_sta->a2dp_exist = TRUE;
622 coex_sta->num_of_profile++;
623 } else {
624 coex_sta->a2dp_exist = FALSE;
625 }
626
627 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_HID) {
628 coex_sta->hid_exist = TRUE;
629 coex_sta->num_of_profile++;
630 } else {
631 coex_sta->hid_exist = FALSE;
632 }
633
634 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) {
635 coex_sta->sco_exist = TRUE;
636 coex_sta->num_of_profile++;
637 } else {
638 coex_sta->sco_exist = FALSE;
639 }
640
641 }
642
643
644 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
645
646 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
647 bt_link_info->sco_exist = coex_sta->sco_exist;
648 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
649 bt_link_info->pan_exist = coex_sta->pan_exist;
650 bt_link_info->hid_exist = coex_sta->hid_exist;
651 bt_link_info->acl_busy = coex_sta->acl_busy;
652
653 /* work around for HS mode. */
654 if (bt_hs_on) {
655 bt_link_info->pan_exist = TRUE;
656 bt_link_info->bt_link_exist = TRUE;
657 }
658
659 /* check if Sco only */
660 if (bt_link_info->sco_exist &&
661 !bt_link_info->a2dp_exist &&
662 !bt_link_info->pan_exist &&
663 !bt_link_info->hid_exist)
664 bt_link_info->sco_only = TRUE;
665 else
666 bt_link_info->sco_only = FALSE;
667
668 /* check if A2dp only */
669 if (!bt_link_info->sco_exist &&
670 bt_link_info->a2dp_exist &&
671 !bt_link_info->pan_exist &&
672 !bt_link_info->hid_exist)
673 bt_link_info->a2dp_only = TRUE;
674 else
675 bt_link_info->a2dp_only = FALSE;
676
677 /* check if Pan only */
678 if (!bt_link_info->sco_exist &&
679 !bt_link_info->a2dp_exist &&
680 bt_link_info->pan_exist &&
681 !bt_link_info->hid_exist)
682 bt_link_info->pan_only = TRUE;
683 else
684 bt_link_info->pan_only = FALSE;
685
686 /* check if Hid only */
687 if (!bt_link_info->sco_exist &&
688 !bt_link_info->a2dp_exist &&
689 !bt_link_info->pan_exist &&
690 bt_link_info->hid_exist)
691 bt_link_info->hid_only = TRUE;
692 else
693 bt_link_info->hid_only = FALSE;
694
695 if (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_INQ_PAGE) {
696 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_INQ_PAGE;
697 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
698 "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n");
699 } else if (!(coex_sta->bt_info & BT_INFO_8822B_2ANT_B_CONNECTION)) {
700 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
701 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
702 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
703 } else if (coex_sta->bt_info == BT_INFO_8822B_2ANT_B_CONNECTION) {
704 /* connection exists but no busy */
705 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE;
706 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
707 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
708 } else if (((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) ||
709 (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) &&
710 (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY)) {
711 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY;
712 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
713 "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
714 } else if ((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) ||
715 (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) {
716 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_SCO_BUSY;
717 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
718 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
719 } else if (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY) {
720 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_BUSY;
721 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
722 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
723 } else {
724 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_MAX;
725 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
726 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
727 }
728
729 BTC_TRACE(trace_buf);
730
731 if ((BT_8822B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
732 (BT_8822B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
733 (BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
734 bt_busy = TRUE;
735 else
736 bt_busy = FALSE;
737
738 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
739 }
740
741
742 static
halbtc8822b2ant_update_wifi_channel_info(IN struct btc_coexist * btcoexist,IN u8 type)743 void halbtc8822b2ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist,
744 IN u8 type)
745 {
746 u8 h2c_parameter[3] = {0}, i;
747 u32 wifi_bw;
748 u8 wifi_central_chnl = 0;
749 u8 wifi_5g_chnl[19] = {120, 124, 128, 132, 136, 140, 144, 149, 153, 157, 118, 126, 134, 142, 151, 159, 122, 138, 155};
750 u8 bt_skip_cneter_chanl[19] = {2, 8, 17, 26, 34, 42, 51, 62, 71, 77, 2, 12, 29, 46, 66, 76, 10, 37, 68};
751 u8 bt_skip_span[19] = {4, 8, 8, 10, 8, 10, 8, 8, 10, 4, 4, 16, 16, 16, 16, 4, 20, 34, 20};
752 boolean wifi_under_5g = FALSE;
753
754
755 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
756 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
757
758 if (type == BTC_MEDIA_CONNECT) {
759
760 if (!wifi_under_5g) {
761
762 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
763 &wifi_central_chnl);
764
765 h2c_parameter[0] = 0x1;
766 h2c_parameter[1] = wifi_central_chnl;
767
768 if (wifi_bw == BTC_WIFI_BW_HT40)
769 h2c_parameter[2] = 0x30;
770 else
771 h2c_parameter[2] = 0x30;
772 } else { /* for 5G */
773
774 wifi_central_chnl =
775 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x18, 0xfffff) & 0xff;
776
777 for (i = 0; i <= 18; i++) {
778 if (wifi_central_chnl == wifi_5g_chnl[i])
779 break;
780 }
781
782 if (i <= 18) {
783 h2c_parameter[0] = 0x3;
784 h2c_parameter[1] = bt_skip_cneter_chanl[i];
785 h2c_parameter[2] = bt_skip_span[i];
786 }
787
788 }
789 }
790
791 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
792 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
793 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
794 coex_sta->wl_center_channel = wifi_central_chnl;
795
796 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
797
798 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
799 "[BTCoex], para[0:2] = 0x%x 0x%x 0x%x\n",
800 h2c_parameter[0], h2c_parameter[1], h2c_parameter[2]);
801 BTC_TRACE(trace_buf);
802
803 }
804
805
806
807 static
halbtc8822b2ant_low_penalty_ra(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean low_penalty_ra)808 void halbtc8822b2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
809 IN boolean force_exec, IN boolean low_penalty_ra)
810 {
811
812 #if 1
813 coex_dm->cur_low_penalty_ra = low_penalty_ra;
814
815 if (!force_exec) {
816 if (coex_dm->pre_low_penalty_ra ==
817 coex_dm->cur_low_penalty_ra)
818 return;
819 }
820
821 if (low_penalty_ra)
822 btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 10);
823 else
824 btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0);
825
826 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
827
828 #endif
829
830 }
831
832 static
halbtc8822b2ant_write_score_board(IN struct btc_coexist * btcoexist,IN u16 bitpos,IN boolean state)833 void halbtc8822b2ant_write_score_board(
834 IN struct btc_coexist *btcoexist,
835 IN u16 bitpos,
836 IN boolean state
837 )
838 {
839
840 static u16 originalval = 0x8002, preval = 0x0;
841
842 if (state)
843 originalval = originalval | bitpos;
844 else
845 originalval = originalval & (~bitpos);
846
847 coex_sta->score_board_WB = originalval;
848
849 if (originalval != preval) {
850
851 preval = originalval;
852 btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
853 } else {
854 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
855 "[BTCoex], halbtc8822b2ant_write_score_board: return for nochange\n");
856 BTC_TRACE(trace_buf);
857 }
858 }
859
860
861 static
halbtc8822b2ant_read_score_board(IN struct btc_coexist * btcoexist,IN u16 * score_board_val)862 void halbtc8822b2ant_read_score_board(
863 IN struct btc_coexist *btcoexist,
864 IN u16 *score_board_val
865 )
866 {
867
868 *score_board_val = (btcoexist->btc_read_2byte(btcoexist,
869 0xaa)) & 0x7fff;
870 }
871
872 static
halbtc8822b2ant_post_state_to_bt(IN struct btc_coexist * btcoexist,IN u16 type,IN BOOLEAN state)873 void halbtc8822b2ant_post_state_to_bt(
874 IN struct btc_coexist *btcoexist,
875 IN u16 type,
876 IN BOOLEAN state
877 )
878 {
879
880 halbtc8822b2ant_write_score_board(btcoexist, (u16) type, state);
881
882 }
883
884 static
halbtc8822b2ant_adjust_wl_tx_power(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 fw_dac_swing_lvl)885 void halbtc8822b2ant_adjust_wl_tx_power(IN struct btc_coexist *btcoexist,
886 IN boolean force_exec, IN u8 fw_dac_swing_lvl)
887 {
888
889 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
890
891 if (!force_exec) {
892 if (coex_dm->pre_fw_dac_swing_lvl ==
893 coex_dm->cur_fw_dac_swing_lvl)
894 return;
895 }
896
897 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0xff, fw_dac_swing_lvl);
898 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xe5b, 0xff, fw_dac_swing_lvl);
899
900 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
901 }
902
903 static
halbtc8822b2ant_adjust_bt_tx_power(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 dec_bt_pwr_lvl)904 void halbtc8822b2ant_adjust_bt_tx_power(IN struct btc_coexist *btcoexist,
905 IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
906 {
907 u8 h2c_parameter[1] = {0};
908
909 coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
910
911 if (!force_exec) {
912 if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
913 return;
914 }
915
916 h2c_parameter[0] = 0 - dec_bt_pwr_lvl;
917
918 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
919
920 coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
921 }
922
923 static
halbtc8822b2ant_adjust_wl_rx_gain(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean agc_table_en)924 void halbtc8822b2ant_adjust_wl_rx_gain(IN struct btc_coexist *btcoexist,
925 IN boolean force_exec, IN boolean agc_table_en)
926 {u32 rx_gain_value_enable[] = {0xff000003, 0xea240003, 0xe9260003,
927 0xe8280003, 0xe72a0003, 0xe62c0003, 0xaf2e0003, 0xae300003,
928 0xad320003, 0xac340003, 0xab360003, 0x8d380003, 0x8c3a0003,
929 0x8b3c0003, 0x8a3e0003, 0x6e400003, 0x6d420003, 0x6c440003,
930 0x6b460003, 0x6a480003, 0x694a0003, 0x684c0003, 0x674e0003,
931 0x66500003, 0x65520003, 0x64540003, 0x64560003, 0x007e0403};
932 u32 rx_gain_value_disable[] = {0xff000003, 0xeb240003, 0xea260003,
933 0xe9280003, 0xe82a0003, 0xe72c0003, 0xe62e0003, 0xe5300003,
934 0xc8320003, 0xc7340003, 0xc6360003, 0xc5380003, 0xc43a0003,
935 0xc33c0003, 0xc23e0003, 0xc1400003, 0xc0420003, 0xa5440003,
936 0xa4460003, 0xa3480003, 0xa24a0003, 0xa14c0003, 0x834e0003,
937 0x82500003, 0x81520003, 0x80540003, 0x65560003, 0x007e0403};
938
939 u8 i;
940
941 coex_dm->cur_agc_table_en = agc_table_en;
942
943 if (!force_exec) {
944 if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
945 return;
946 }
947
948 if (agc_table_en) {
949 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
950 "[BTCoex], BB Agc Table On!\n");
951 BTC_TRACE(trace_buf);
952
953 for (i = 0; i <= 100; i++) {
954 btcoexist->btc_write_4byte(btcoexist,
955 0x81c, rx_gain_value_enable[i]);
956
957 if (rx_gain_value_enable[i] == 0x007e0403)
958 break;
959 }
960
961 } else {
962 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
963 "[BTCoex], BB Agc Table Off!\n");
964 BTC_TRACE(trace_buf);
965
966 for (i = 0; i <= 100; i++) {
967 btcoexist->btc_write_4byte(btcoexist,
968 0x81c, rx_gain_value_disable[i]);
969
970 if (rx_gain_value_disable[i] == 0x007e0403)
971 break;
972 }
973 }
974
975
976 coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
977 }
978
979 static
halbtc8822b2ant_adjust_bt_rx_gain(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean rx_gain_en)980 void halbtc8822b2ant_adjust_bt_rx_gain(IN struct btc_coexist *btcoexist,
981 IN boolean force_exec, IN boolean rx_gain_en)
982 {
983
984 /* use scoreboard[4] to notify BT Rx gain table change */
985 halbtc8822b2ant_post_state_to_bt(btcoexist,
986 BT_8822B_2ANT_SCOREBOARD_RXGAIN,
987 rx_gain_en);
988 }
989
990
991 static
halbtc8822b2ant_monitor_bt_enable_disable(IN struct btc_coexist * btcoexist)992 void halbtc8822b2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
993 {
994 static u32 bt_disable_cnt = 0;
995 boolean bt_active = TRUE, bt_disabled = FALSE, wifi_under_5g = FALSE;
996 u16 u16tmp;
997
998 /* This function check if bt is disabled */
999 #if 0
1000 if (coex_sta->high_priority_tx == 0 &&
1001 coex_sta->high_priority_rx == 0 &&
1002 coex_sta->low_priority_tx == 0 &&
1003 coex_sta->low_priority_rx == 0)
1004 bt_active = FALSE;
1005 if (coex_sta->high_priority_tx == 0xffff &&
1006 coex_sta->high_priority_rx == 0xffff &&
1007 coex_sta->low_priority_tx == 0xffff &&
1008 coex_sta->low_priority_rx == 0xffff)
1009 bt_active = FALSE;
1010
1011
1012 #else
1013
1014 /* Read BT on/off status from scoreboard[1],
1015 * enable this only if BT patch support this feature
1016 */
1017 halbtc8822b2ant_read_score_board(btcoexist, &u16tmp);
1018
1019 bt_active = u16tmp & BIT(1);
1020
1021
1022 #endif
1023
1024 if (bt_active) {
1025 bt_disable_cnt = 0;
1026 bt_disabled = FALSE;
1027 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1028 &bt_disabled);
1029 } else {
1030
1031 bt_disable_cnt++;
1032 if (bt_disable_cnt >= 10) {
1033 bt_disabled = TRUE;
1034 bt_disable_cnt = 10;
1035 }
1036
1037 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1038 &bt_disabled);
1039 }
1040
1041 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1042
1043 if ((wifi_under_5g) || (bt_disabled))
1044 halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, FALSE);
1045 else
1046 halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, TRUE);
1047
1048
1049 if (coex_sta->bt_disabled != bt_disabled) {
1050 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1051 "[BTCoex], BT is from %s to %s!!\n",
1052 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1053 (bt_disabled ? "disabled" : "enabled"));
1054 BTC_TRACE(trace_buf);
1055 coex_sta->bt_disabled = bt_disabled;
1056 }
1057
1058 }
1059
1060 static
halbtc8822b2ant_enable_gnt_to_gpio(IN struct btc_coexist * btcoexist,boolean isenable)1061 void halbtc8822b2ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist,
1062 boolean isenable)
1063 {
1064 #if BT_8822B_2ANT_COEX_DBG
1065 static u8 bitVal[5] = {0, 0, 0, 0, 0};
1066 #if 0
1067 static boolean state = FALSE;
1068
1069 if (state == isenable)
1070 return;
1071
1072 state = isenable;
1073 #endif
1074
1075 if (isenable) {
1076
1077 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1078 "[BTCoex], enable_gnt_to_gpio!!\n");
1079 BTC_TRACE(trace_buf);
1080
1081 /* enable GNT_WL, GNT_BT to GPIO for debug */
1082 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
1083
1084 /* store original value */
1085 bitVal[0] = (btcoexist->btc_read_1byte(btcoexist,
1086 0x66) & BIT(4)) >> 4; /*0x66[4] */
1087 bitVal[1] = (btcoexist->btc_read_1byte(btcoexist,
1088 0x67) & BIT(0)); /*0x66[8] */
1089 bitVal[2] = (btcoexist->btc_read_1byte(btcoexist,
1090 0x42) & BIT(3)) >> 3; /*0x40[19] */
1091 bitVal[3] = (btcoexist->btc_read_1byte(btcoexist,
1092 0x65) & BIT(7)) >> 7; /*0x64[15] */
1093 bitVal[4] = (btcoexist->btc_read_1byte(btcoexist,
1094 0x72) & BIT(2)) >> 2; /*0x70[18] */
1095
1096 /* switch GPIO Mux */
1097 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1098 0x0); /*0x66[4] = 0 */
1099 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1100 0x0); /*0x66[8] = 0 */
1101 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1102 0x0); /*0x40[19] = 0 */
1103 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1104 0x0); /*0x64[15] = 0 */
1105 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1106 0x0); /*0x70[18] = 0 */
1107
1108
1109 } else {
1110 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1111 "[BTCoex], disable_gnt_to_gpio!!\n");
1112 BTC_TRACE(trace_buf);
1113
1114 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
1115
1116 /* Restore original value */
1117 /* switch GPIO Mux */
1118 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1119 bitVal[0]); /*0x66[4] = 0 */
1120 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1121 bitVal[1]); /*0x66[8] = 0 */
1122 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1123 bitVal[2]); /*0x40[19] = 0 */
1124 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1125 bitVal[3]); /*0x64[15] = 0 */
1126 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1127 bitVal[4]); /*0x70[18] = 0 */
1128 }
1129
1130 #endif
1131 }
1132
1133
1134 static
halbtc8822b2ant_ltecoex_indirect_read_reg(IN struct btc_coexist * btcoexist,IN u16 reg_addr)1135 u32 halbtc8822b2ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist,
1136 IN u16 reg_addr)
1137 {
1138 u32 delay_count = 0;
1139
1140 while (1) {
1141 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
1142 delay_ms(50);
1143 delay_count++;
1144 if (delay_count >= 10) {
1145 delay_count = 0;
1146 break;
1147 }
1148 } else {
1149 break;
1150 }
1151 }
1152
1153 /* wait for ready bit before access 0x1700 */
1154 btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
1155
1156 return btcoexist->btc_read_4byte(btcoexist,
1157 0x1708); /* get read data */
1158
1159 }
1160
1161
1162 static
halbtc8822b2ant_ltecoex_indirect_write_reg(IN struct btc_coexist * btcoexist,IN u16 reg_addr,IN u32 bit_mask,IN u32 reg_value)1163 void halbtc8822b2ant_ltecoex_indirect_write_reg(IN struct btc_coexist
1164 *btcoexist,
1165 IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value)
1166 {
1167 u32 val, i = 0, bitpos = 0, delay_count = 0;
1168
1169
1170 if (bit_mask == 0x0)
1171 return;
1172 if (bit_mask == 0xffffffff) {
1173 /* wait for ready bit before access 0x1700/0x1704 */
1174 while (1) {
1175 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
1176 delay_ms(50);
1177 delay_count++;
1178 if (delay_count >= 10) {
1179 delay_count = 0;
1180 break;
1181 }
1182 } else {
1183 break;
1184 }
1185 }
1186
1187 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1188 reg_value); /* put write data */
1189
1190 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1191 0xc00F0000 | reg_addr);
1192 } else {
1193 for (i = 0; i <= 31; i++) {
1194 if (((bit_mask >> i) & 0x1) == 0x1) {
1195 bitpos = i;
1196 break;
1197 }
1198 }
1199
1200 /* read back register value before write */
1201 val = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
1202 reg_addr);
1203 val = (val & (~bit_mask)) | (reg_value << bitpos);
1204
1205 /* wait for ready bit before access 0x1700/0x1704 */
1206 while (1) {
1207 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
1208 delay_ms(50);
1209 delay_count++;
1210 if (delay_count >= 10) {
1211 delay_count = 0;
1212 break;
1213 }
1214 } else {
1215 break;
1216 }
1217 }
1218
1219 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1220 val); /* put write data */
1221
1222 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1223 0xc00F0000 | reg_addr);
1224 }
1225
1226 }
1227
1228
1229 static
halbtc8822b2ant_ltecoex_enable(IN struct btc_coexist * btcoexist,IN boolean enable)1230 void halbtc8822b2ant_ltecoex_enable(IN struct btc_coexist *btcoexist,
1231 IN boolean enable)
1232 {
1233 u8 val;
1234
1235 val = (enable) ? 1 : 0;
1236 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
1237 val); /* 0x38[7] */
1238
1239 }
1240
1241 static
halbtc8822b2ant_ltecoex_pathcontrol_owner(IN struct btc_coexist * btcoexist,IN boolean wifi_control)1242 void halbtc8822b2ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist,
1243 IN boolean wifi_control)
1244 {
1245 u8 val;
1246
1247 val = (wifi_control) ? 1 : 0;
1248 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
1249 val); /* 0x70[26] */
1250
1251 }
1252
1253 static
halbtc8822b2ant_ltecoex_set_gnt_bt(IN struct btc_coexist * btcoexist,IN u8 control_block,IN boolean sw_control,IN u8 state)1254 void halbtc8822b2ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist,
1255 IN u8 control_block, IN boolean sw_control, IN u8 state)
1256 {
1257 u32 val = 0, bit_mask;
1258
1259 state = state & 0x1;
1260 val = (sw_control) ? ((state << 1) | 0x1) : 0;
1261
1262 switch (control_block) {
1263 case BT_8822B_2ANT_GNT_BLOCK_RFC_BB:
1264 default:
1265 bit_mask = 0xc000;
1266 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1267 0x38, bit_mask, val); /* 0x38[15:14] */
1268 bit_mask = 0x0c00;
1269 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1270 0x38, bit_mask, val); /* 0x38[11:10] */
1271 break;
1272 case BT_8822B_2ANT_GNT_BLOCK_RFC:
1273 bit_mask = 0xc000;
1274 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1275 0x38, bit_mask, val); /* 0x38[15:14] */
1276 break;
1277 case BT_8822B_2ANT_GNT_BLOCK_BB:
1278 bit_mask = 0x0c00;
1279 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1280 0x38, bit_mask, val); /* 0x38[11:10] */
1281 break;
1282
1283 }
1284
1285 }
1286
1287 static
halbtc8822b2ant_ltecoex_set_gnt_wl(IN struct btc_coexist * btcoexist,IN u8 control_block,IN boolean sw_control,IN u8 state)1288 void halbtc8822b2ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist,
1289 IN u8 control_block, IN boolean sw_control, IN u8 state)
1290 {
1291 u32 val = 0, bit_mask;
1292
1293 state = state & 0x1;
1294 val = (sw_control) ? ((state << 1) | 0x1) : 0;
1295
1296 switch (control_block) {
1297 case BT_8822B_2ANT_GNT_BLOCK_RFC_BB:
1298 default:
1299 bit_mask = 0x3000;
1300 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1301 0x38, bit_mask, val); /* 0x38[13:12] */
1302 bit_mask = 0x0300;
1303 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1304 0x38, bit_mask, val); /* 0x38[9:8] */
1305 break;
1306 case BT_8822B_2ANT_GNT_BLOCK_RFC:
1307 bit_mask = 0x3000;
1308 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1309 0x38, bit_mask, val); /* 0x38[13:12] */
1310 break;
1311 case BT_8822B_2ANT_GNT_BLOCK_BB:
1312 bit_mask = 0x0300;
1313 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
1314 0x38, bit_mask, val); /* 0x38[9:8] */
1315 break;
1316
1317 }
1318
1319 }
1320
1321 static
halbtc8822b2ant_ltecoex_set_coex_table(IN struct btc_coexist * btcoexist,IN u8 table_type,IN u16 table_content)1322 void halbtc8822b2ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist,
1323 IN u8 table_type, IN u16 table_content)
1324 {
1325 u16 reg_addr = 0x0000;
1326
1327 switch (table_type) {
1328 case BT_8822B_2ANT_CTT_WL_VS_LTE:
1329 reg_addr = 0xa0;
1330 break;
1331 case BT_8822B_2ANT_CTT_BT_VS_LTE:
1332 reg_addr = 0xa4;
1333 break;
1334 }
1335
1336 if (reg_addr != 0x0000)
1337 halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
1338 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */
1339
1340
1341 }
1342
1343
1344 static
halbtc8822b2ant_set_wltoggle_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 interval,IN u8 val0x6c4_b0,IN u8 val0x6c4_b1,IN u8 val0x6c4_b2,IN u8 val0x6c4_b3)1345 void halbtc8822b2ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist,
1346 IN boolean force_exec, IN u8 interval,
1347 IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2,
1348 IN u8 val0x6c4_b3)
1349 {
1350 static u8 pre_h2c_parameter[6] = {0};
1351 u8 cur_h2c_parameter[6] = {0};
1352 u8 i, match_cnt = 0;
1353
1354 cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/
1355
1356 cur_h2c_parameter[1] = interval;
1357 cur_h2c_parameter[2] = val0x6c4_b0;
1358 cur_h2c_parameter[3] = val0x6c4_b1;
1359 cur_h2c_parameter[4] = val0x6c4_b2;
1360 cur_h2c_parameter[5] = val0x6c4_b3;
1361
1362 if (!force_exec) {
1363 for (i = 1; i <= 5; i++) {
1364 if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
1365 break;
1366
1367 match_cnt++;
1368 }
1369
1370 if (match_cnt == 5)
1371 return;
1372 }
1373
1374 for (i = 1; i <= 5; i++)
1375 pre_h2c_parameter[i] = cur_h2c_parameter[i];
1376
1377 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter);
1378 }
1379
1380 static
halbtc8822b2ant_set_coex_table(IN struct btc_coexist * btcoexist,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)1381 void halbtc8822b2ant_set_coex_table(IN struct btc_coexist *btcoexist,
1382 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
1383 {
1384 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1385
1386 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1387
1388 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1389
1390 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1391 }
1392
1393 static
halbtc8822b2ant_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)1394 void halbtc8822b2ant_coex_table(IN struct btc_coexist *btcoexist,
1395 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
1396 IN u32 val0x6c8, IN u8 val0x6cc)
1397 {
1398 coex_dm->cur_val0x6c0 = val0x6c0;
1399 coex_dm->cur_val0x6c4 = val0x6c4;
1400 coex_dm->cur_val0x6c8 = val0x6c8;
1401 coex_dm->cur_val0x6cc = val0x6cc;
1402
1403 if (!force_exec) {
1404 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1405 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1406 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1407 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1408 return;
1409 }
1410 halbtc8822b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1411 val0x6cc);
1412
1413 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1414 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1415 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1416 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1417 }
1418
1419 static
halbtc8822b2ant_coex_table_with_type(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)1420 void halbtc8822b2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
1421 IN boolean force_exec, IN u8 type)
1422 {
1423 u32 break_table;
1424 u8 select_table;
1425
1426 coex_sta->coex_table_type = type;
1427
1428 if (coex_sta->concurrent_rx_mode_on) {
1429 break_table = 0xf0ffffff; /* set WL hi-pri can break BT */
1430 /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
1431 select_table = 0xb;
1432 } else {
1433 break_table = 0xffffff;
1434 select_table = 0x3;
1435 }
1436
1437 switch (type) {
1438 case 0:
1439 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1440 0xffffffff, 0xffffffff, break_table, select_table);
1441 break;
1442 case 1:
1443 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1444 0x55555555, 0x5a5a5a5a, break_table, select_table);
1445 break;
1446 case 2:
1447 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1448 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table);
1449 break;
1450 case 3:
1451 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1452 0x55555555, 0x5a5a5a5a, break_table, select_table);
1453 break;
1454 case 4:
1455 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1456 0x55555555, 0x5a5a5a5a, break_table, select_table);
1457 break;
1458 case 5:
1459 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1460 0x55555555, 0x55555555, break_table, select_table);
1461 break;
1462 case 6:
1463 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1464 0xa5555555, 0xfafafafa, break_table, select_table);
1465 break;
1466 case 7:
1467 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1468 0xa5555555, 0xaa5a5a5a, break_table, select_table);
1469 break;
1470 case 8:
1471 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1472 0xa5555555, 0xfafafafa, break_table, select_table);
1473 break;
1474 case 9:
1475 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1476 0x5a5a5a5a, 0xaaaa5aaa, break_table, select_table);
1477 break;
1478 case 10:
1479 halbtc8822b2ant_coex_table(btcoexist, force_exec,
1480 0x55555555, 0x5a5a555a, break_table, select_table);
1481 break;
1482 default:
1483 break;
1484 }
1485 }
1486
1487 static
halbtc8822b2ant_set_fw_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean enable)1488 void halbtc8822b2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1489 IN boolean enable)
1490 {
1491 u8 h2c_parameter[1] = {0};
1492 u32 RTL97F_8822B = 0;
1493
1494 if (RTL97F_8822B)
1495 return;
1496
1497 if (enable)
1498 h2c_parameter[0] |= BIT(0); /* function enable */
1499
1500 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1501 }
1502
1503 static
halbtc8822b2ant_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable)1504 void halbtc8822b2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1505 IN boolean force_exec, IN boolean enable)
1506 {
1507 coex_dm->cur_ignore_wlan_act = enable;
1508
1509 if (!force_exec) {
1510 if (coex_dm->pre_ignore_wlan_act ==
1511 coex_dm->cur_ignore_wlan_act)
1512 return;
1513 }
1514 halbtc8822b2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1515
1516 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1517 }
1518
1519 static
halbtc8822b2ant_set_lps_rpwm(IN struct btc_coexist * btcoexist,IN u8 lps_val,IN u8 rpwm_val)1520 void halbtc8822b2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
1521 IN u8 lps_val, IN u8 rpwm_val)
1522 {
1523 u8 lps = lps_val;
1524 u8 rpwm = rpwm_val;
1525
1526 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1527 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1528 }
1529
1530 static
halbtc8822b2ant_lps_rpwm(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 lps_val,IN u8 rpwm_val)1531 void halbtc8822b2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
1532 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
1533 {
1534 coex_dm->cur_lps = lps_val;
1535 coex_dm->cur_rpwm = rpwm_val;
1536
1537 if (!force_exec) {
1538 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1539 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1540 return;
1541 }
1542 halbtc8822b2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1543
1544 coex_dm->pre_lps = coex_dm->cur_lps;
1545 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1546 }
1547
1548
1549 static
halbtc8822b2ant_ps_tdma_check_for_power_save_state(IN struct btc_coexist * btcoexist,IN boolean new_ps_state)1550 void halbtc8822b2ant_ps_tdma_check_for_power_save_state(
1551 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1552 {
1553 u8 lps_mode = 0x0;
1554 u8 h2c_parameter[5] = {0, 0, 0, 0x40, 0};
1555 u32 RTL97F_8822B = 0;
1556
1557 if (RTL97F_8822B)
1558 return;
1559
1560 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1561
1562 if (lps_mode) { /* already under LPS state */
1563 if (new_ps_state) {
1564 /* keep state under LPS, do nothing. */
1565 } else {
1566 /* will leave LPS state, turn off psTdma first */
1567 #if 0
1568 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE,
1569 8);
1570 #endif
1571 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1572 h2c_parameter);
1573 }
1574 } else { /* NO PS state */
1575 if (new_ps_state) {
1576 /* will enter LPS state, turn off psTdma first */
1577 #if 0
1578 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE,
1579 8);
1580 #endif
1581 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1582 h2c_parameter);
1583 } else {
1584 /* keep state under NO PS state, do nothing. */
1585 }
1586 }
1587 }
1588
1589
1590 static
halbtc8822b2ant_power_save_state(IN struct btc_coexist * btcoexist,IN u8 ps_type,IN u8 lps_val,IN u8 rpwm_val)1591 boolean halbtc8822b2ant_power_save_state(IN struct btc_coexist *btcoexist,
1592 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1593 {
1594 boolean low_pwr_disable = FALSE, result = TRUE;
1595
1596 switch (ps_type) {
1597 case BTC_PS_WIFI_NATIVE:
1598 coex_sta->force_lps_ctrl = FALSE;
1599 /* recover to original 32k low power setting */
1600 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1601 "[BTCoex], halbtc8822b2ant_power_save_state == BTC_PS_WIFI_NATIVE\n");
1602 BTC_TRACE(trace_buf);
1603
1604 low_pwr_disable = FALSE;
1605 /* btcoexist->btc_set(btcoexist,
1606 over to original 32k low power setting */
1607
1608 btcoexist->btc_set(btcoexist, BTC_SET_ACT_PRE_NORMAL_LPS,
1609 NULL);
1610 break;
1611 case BTC_PS_LPS_ON:
1612 coex_sta->force_lps_ctrl = TRUE;
1613 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1614 "[BTCoex], halbtc8822b2ant_power_save_state == BTC_PS_LPS_ON\n");
1615 BTC_TRACE(trace_buf);
1616
1617 halbtc8822b2ant_ps_tdma_check_for_power_save_state(
1618 btcoexist, TRUE);
1619 halbtc8822b2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1620 lps_val, rpwm_val);
1621 /* when coex force to enter LPS, do not enter 32k low power. */
1622 low_pwr_disable = TRUE;
1623 btcoexist->btc_set(btcoexist,
1624 BTC_SET_ACT_DISABLE_LOW_POWER,
1625 &low_pwr_disable);
1626 /* power save must executed before psTdma. */
1627 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1628 NULL);
1629 break;
1630 case BTC_PS_LPS_OFF:
1631 coex_sta->force_lps_ctrl = TRUE;
1632 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1633 "[BTCoex], halbtc8822b2ant_power_save_state == BTC_PS_LPS_OFF\n");
1634 BTC_TRACE(trace_buf);
1635
1636 halbtc8822b2ant_ps_tdma_check_for_power_save_state(
1637 btcoexist, FALSE);
1638 result = btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1639 NULL);
1640 break;
1641 default:
1642 break;
1643 }
1644
1645 return result;
1646 }
1647
1648
1649
1650
1651 static
halbtc8822b2ant_set_fw_pstdma(IN struct btc_coexist * btcoexist,IN u8 byte1,IN u8 byte2,IN u8 byte3,IN u8 byte4,IN u8 byte5)1652 void halbtc8822b2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1653 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1654 {
1655 u8 h2c_parameter[5] = {0};
1656 u8 real_byte1 = byte1, real_byte5 = byte5;
1657 boolean ap_enable = FALSE, result = FALSE;
1658 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1659 u8 ps_type = BTC_PS_WIFI_NATIVE;
1660
1661 if (byte5 & BIT(2))
1662 coex_sta->is_tdma_btautoslot = TRUE;
1663 else
1664 coex_sta->is_tdma_btautoslot = FALSE;
1665
1666 /* release bt-auto slot for auto-slot hang is detected!! */
1667 if (coex_sta->is_tdma_btautoslot)
1668 if ((coex_sta->is_tdma_btautoslot_hang) ||
1669 (bt_link_info->slave_role))
1670 byte5 = byte5 & 0xfb;
1671
1672 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1673 &ap_enable);
1674
1675 if ((ap_enable) && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
1676 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1677 "[BTCoex], halbtc8822b2ant_set_fw_pstdma == FW for AP mode\n");
1678 BTC_TRACE(trace_buf);
1679
1680 real_byte1 &= ~BIT(4);
1681 real_byte1 |= BIT(5);
1682
1683 real_byte5 |= BIT(5);
1684 real_byte5 &= ~BIT(6);
1685
1686 ps_type = BTC_PS_WIFI_NATIVE;
1687 halbtc8822b2ant_power_save_state(btcoexist,
1688 ps_type, 0x0, 0x0);
1689 } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1690 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1691 "[BTCoex], halbtc8822b2ant_set_fw_pstdma == Force LPS (byte1 = 0x%x)\n", byte1);
1692 BTC_TRACE(trace_buf);
1693
1694 #if 0
1695 halbtc8822b2ant_power_save_state(
1696 btcoexist, BTC_PS_LPS_ON, 0x50,
1697 0x4);
1698 #endif
1699 ps_type = BTC_PS_LPS_OFF;
1700 if (!halbtc8822b2ant_power_save_state(btcoexist, ps_type, 0x50, 0x4))
1701 result = TRUE;
1702
1703 } else {
1704 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1705 "[BTCoex], halbtc8822b2ant_set_fw_pstdma == Native LPS (byte1 = 0x%x)\n", byte1);
1706 BTC_TRACE(trace_buf);
1707
1708 ps_type = BTC_PS_WIFI_NATIVE;
1709 halbtc8822b2ant_power_save_state(btcoexist, ps_type, 0x0, 0x0);
1710 }
1711
1712
1713 coex_sta->is_set_ps_state_fail = result;
1714
1715 if (!coex_sta->is_set_ps_state_fail) {
1716 h2c_parameter[0] = real_byte1;
1717 h2c_parameter[1] = byte2;
1718 h2c_parameter[2] = byte3;
1719 h2c_parameter[3] = byte4;
1720 h2c_parameter[4] = real_byte5;
1721
1722 coex_dm->ps_tdma_para[0] = real_byte1;
1723 coex_dm->ps_tdma_para[1] = byte2;
1724 coex_dm->ps_tdma_para[2] = byte3;
1725 coex_dm->ps_tdma_para[3] = byte4;
1726 coex_dm->ps_tdma_para[4] = real_byte5;
1727
1728 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1729
1730 } else {
1731 coex_sta->cnt_set_ps_state_fail++;
1732 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1733 "[BTCoex], halbtc8822b2ant_set_fw_pstdma == Force Leave LPS Fail (cnt = %d)\n",
1734 coex_sta->cnt_set_ps_state_fail);
1735 BTC_TRACE(trace_buf);
1736 }
1737
1738 if (ps_type == BTC_PS_WIFI_NATIVE)
1739 btcoexist->btc_set(btcoexist, BTC_SET_ACT_POST_NORMAL_LPS, NULL);
1740 }
1741
1742
1743 static
halbtc8822b2ant_ps_tdma(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean turn_on,IN u8 type)1744 void halbtc8822b2ant_ps_tdma(IN struct btc_coexist *btcoexist,
1745 IN boolean force_exec, IN boolean turn_on, IN u8 type)
1746 {
1747 static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0;
1748 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1749
1750 coex_dm->cur_ps_tdma_on = turn_on;
1751 coex_dm->cur_ps_tdma = type;
1752
1753 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1754 if (bt_link_info->slave_role)
1755 psTdmaByte4Modify = 0x1;
1756 else
1757 psTdmaByte4Modify = 0x0;
1758
1759 if (pre_psTdmaByte4Modify != psTdmaByte4Modify) {
1760 force_exec = TRUE;
1761 pre_psTdmaByte4Modify = psTdmaByte4Modify;
1762 }
1763
1764 if (!force_exec) {
1765 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1766 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) {
1767 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1768 "[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
1769 (coex_dm->cur_ps_tdma_on ? "on" : "off"),
1770 coex_dm->cur_ps_tdma);
1771 BTC_TRACE(trace_buf);
1772 return;
1773 }
1774 }
1775
1776 if (coex_dm->cur_ps_tdma_on) {
1777 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1778 "[BTCoex], ********** TDMA(on, %d) **********\n",
1779 coex_dm->cur_ps_tdma);
1780 BTC_TRACE(trace_buf);
1781
1782 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
1783 0x1); /* enable TBTT nterrupt */
1784 } else {
1785 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1786 "[BTCoex], ********** TDMA(off, %d) **********\n",
1787 coex_dm->cur_ps_tdma);
1788 BTC_TRACE(trace_buf);
1789 }
1790
1791
1792 if (turn_on) {
1793 switch (type) {
1794 case 1:
1795 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1796 0x10, 0x03, 0x91,
1797 0x54 | psTdmaByte4Modify);
1798 break;
1799 case 2:
1800 default:
1801 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1802 0x35, 0x03, 0x11,
1803 0x11 | psTdmaByte4Modify);
1804 break;
1805 case 3:
1806 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1807 0x3a, 0x3, 0x91,
1808 0x10 | psTdmaByte4Modify);
1809 break;
1810 case 4:
1811 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1812 0x21, 0x3, 0x91,
1813 0x10 | psTdmaByte4Modify);
1814 break;
1815 case 5:
1816 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1817 0x25, 0x3, 0x91,
1818 0x10 | psTdmaByte4Modify);
1819 break;
1820 case 6:
1821 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1822 0x10, 0x3, 0x91,
1823 0x10 | psTdmaByte4Modify);
1824 break;
1825 case 7:
1826 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1827 0x20, 0x3, 0x91,
1828 0x10 | psTdmaByte4Modify);
1829 break;
1830 case 8:
1831 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1832 0x15, 0x03, 0x11,
1833 0x11);
1834 break;
1835 case 10:
1836 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1837 0x30, 0x03, 0x11,
1838 0x10);
1839 break;
1840 case 11:
1841 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1842 0x35, 0x03, 0x11,
1843 0x10 | psTdmaByte4Modify);
1844 break;
1845 case 12:
1846 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1847 0x35, 0x03, 0x11, 0x11);
1848 break;
1849 case 13:
1850 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1851 0x1c, 0x03, 0x11,
1852 0x10 | psTdmaByte4Modify);
1853 break;
1854 case 14:
1855 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1856 0x20, 0x03, 0x11,
1857 0x11);
1858 break;
1859 case 15:
1860 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1861 0x10, 0x03, 0x11,
1862 0x14);
1863 break;
1864 case 16:
1865 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1866 0x10, 0x03, 0x11,
1867 0x15);
1868 break;
1869 case 21:
1870 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1871 0x30, 0x03, 0x11,
1872 0x10);
1873 break;
1874 case 22:
1875 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1876 0x25, 0x03, 0x11,
1877 0x10);
1878 break;
1879 case 23:
1880 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1881 0x10, 0x03, 0x11,
1882 0x10);
1883 break;
1884 case 51:
1885 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1886 0x10, 0x03, 0x91,
1887 0x10 | psTdmaByte4Modify);
1888 break;
1889 case 101:
1890 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1891 0x25, 0x03, 0x11,
1892 0x11 | psTdmaByte4Modify);
1893 break;
1894 case 102:
1895 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1896 0x35, 0x03, 0x11,
1897 0x11 | psTdmaByte4Modify);
1898 break;
1899 case 103:
1900 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1901 0x3a, 0x3, 0x10,
1902 0x50 | psTdmaByte4Modify);
1903 break;
1904 case 104:
1905 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1906 0x21, 0x3, 0x10,
1907 0x50 | psTdmaByte4Modify);
1908 break;
1909 case 105:
1910 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1911 0x30, 0x3, 0x10,
1912 0x50 | psTdmaByte4Modify);
1913 break;
1914 case 106:
1915 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1916 0x10, 0x3, 0x10,
1917 0x50 | psTdmaByte4Modify);
1918 break;
1919 case 107:
1920 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1921 0x10, 0x7, 0x10,
1922 0x54 | psTdmaByte4Modify);
1923 break;
1924 case 108:
1925 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1926 0x30, 0x3, 0x10,
1927 0x50 | psTdmaByte4Modify);
1928 break;
1929 case 109:
1930 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1931 0x10, 0x03, 0x10,
1932 0x54 | psTdmaByte4Modify);
1933 break;
1934 case 110:
1935 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x55,
1936 0x30, 0x03, 0x10,
1937 0x50 | psTdmaByte4Modify);
1938 break;
1939 case 111:
1940 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61,
1941 0x25, 0x03, 0x11,
1942 0x11 | psTdmaByte4Modify);
1943 break;
1944 case 151:
1945 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x51,
1946 0x10, 0x03, 0x10,
1947 0x50 | psTdmaByte4Modify);
1948 break;
1949 }
1950 } else {
1951 /* disable PS tdma */
1952 switch (type) {
1953
1954 case 0:
1955 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0,
1956 0x0, 0x0, 0x40, 0x0);
1957 break;
1958 default:
1959 halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0,
1960 0x0, 0x0, 0x40, 0x0);
1961 break;
1962 }
1963 }
1964
1965 if (!coex_sta->is_set_ps_state_fail) {
1966 /* update pre state */
1967 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1968 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1969 }
1970 }
1971
1972 /*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
1973 static
halbtc8822b2ant_set_ext_ant_switch(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 ctrl_type,IN u8 pos_type)1974 void halbtc8822b2ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist,
1975 IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type)
1976 {
1977
1978 boolean switch_polatiry_inverse = FALSE;
1979 u8 regval_0xcbc = 0, regval_0x64;
1980 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
1981
1982 if (!rfe_type->ext_ant_switch_exist)
1983 return;
1984
1985 coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
1986
1987 if (!force_exec) {
1988 if (coex_dm->pre_ext_ant_switch_status ==
1989 coex_dm->cur_ext_ant_switch_status)
1990 return;
1991 }
1992 coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
1993
1994
1995 /* Ext switch buffer mux */
1996 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
1997 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
1998 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
1999
2000 switch (ctrl_type) {
2001 default:
2002 case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
2003 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2004 0x80, 0x0); /* 0x4c[23] = 0 */
2005 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2006 0x01, 0x1); /* 0x4c[24] = 1 */
2007 /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
2008 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2009 0xff, 0x77);
2010
2011 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
2012 0x03, 0x1);
2013
2014 break;
2015 case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
2016 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2017 0x80, 0x0); /* 0x4c[23] = 0 */
2018 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2019 0x01, 0x1); /* 0x4c[24] = 1 */
2020 /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
2021 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2022 0xff, 0x66);
2023
2024 /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse,
2025 * DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1
2026 */
2027 regval_0xcbc = (!switch_polatiry_inverse ? 0x2 : 0x1);
2028 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbc,
2029 0x03, regval_0xcbc);
2030
2031 break;
2032 case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
2033 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2034 0x80, 0x0); /* 0x4c[23] = 0 */
2035 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2036 0x01, 0x1);/* 0x4c[24] = 1 */
2037 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x88);
2038 break;
2039 case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
2040 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2041 0x80, 0x1); /* 0x4c[23] = 1 */
2042
2043 /* 0x64[0] = 1b'0 for no switch_polatiry_inverse,
2044 * DPDT_SEL_N =1, DPDT_SEL_P =0
2045 */
2046 regval_0x64 = (!switch_polatiry_inverse ? 0x0 : 0x1);
2047 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
2048 regval_0x64);
2049 break;
2050 case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
2051 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2052 0x80, 0x0); /* 0x4c[23] = 0 */
2053 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2054 0x01, 0x0); /* 0x4c[24] = 0 */
2055
2056 /* no setup required, because antenna switch control value by
2057 * BT vendor 0x1c[1:0]
2058 */
2059 break;
2060 }
2061
2062 /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue*/
2063 if (ctrl_type == BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT) {
2064 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20,
2065 0x0); /* PAPE 0x64[29] = 0 */
2066 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10,
2067 0x0); /* LNA_ON 0x64[28] = 0 */
2068 } else {
2069 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20,
2070 0x1); /* PAPE 0x64[29] = 1 */
2071 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10,
2072 0x1); /* LNA_ON 0x64[28] = 1 */
2073 }
2074
2075 #if BT_8822B_2ANT_COEX_DBG
2076
2077 u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcbc);
2078 u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2079 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
2080
2081 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2082 "[BTCoex], (After Ext Ant switch setup) 0xcbc = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n",
2083 u32tmp1, u32tmp2, u32tmp3);
2084 BTC_TRACE(trace_buf);
2085 #endif
2086
2087
2088 }
2089
2090 /* rf4 type by efuse, and for ant at main aux inverse use,
2091 * because is 2x2, and control types are the same, does not need
2092 */
2093 static
halbtc8822b2ant_set_rfe_type(IN struct btc_coexist * btcoexist)2094 void halbtc8822b2ant_set_rfe_type(IN struct btc_coexist *btcoexist)
2095 {
2096
2097 struct btc_board_info *board_info = &btcoexist->board_info;
2098
2099
2100 rfe_type->ext_band_switch_exist = FALSE;
2101 rfe_type->ext_band_switch_type =
2102 BT_8822B_2ANT_EXT_BAND_SWITCH_USE_SPDT; /* SPDT; */
2103 rfe_type->ext_band_switch_ctrl_polarity = 0;
2104 /* Ext switch buffer mux */
2105 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2106 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2107 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2108
2109 if (rfe_type->ext_band_switch_exist) {
2110
2111 /* band switch use RFE_ctrl1 (pin name: PAPE_A) and
2112 * RFE_ctrl3 (pin name: LNAON_A)
2113 */
2114
2115 /* set RFE_ctrl1 as software control */
2116 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7);
2117
2118 /* set RFE_ctrl3 as software control */
2119 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7);
2120
2121 }
2122
2123
2124 /* the following setup should be got from Efuse in the future */
2125 rfe_type->rfe_module_type = board_info->rfe_type;
2126 rfe_type->ext_ant_switch_ctrl_polarity = 0;
2127 rfe_type->ext_ant_switch_exist = TRUE;
2128 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2129
2130 #if 0
2131 switch (rfe_type->rfe_module_type) {
2132 case 0:
2133 default:
2134 rfe_type->ext_ant_switch_exist = TRUE;
2135 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2136 break;
2137 case 1:
2138 rfe_type->ext_ant_switch_exist = TRUE;
2139 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2140 break;
2141 case 2:
2142 rfe_type->ext_ant_switch_exist = TRUE;
2143 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2144 break;
2145 case 3:
2146 rfe_type->ext_ant_switch_exist = TRUE;
2147 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2148 break;
2149 case 4:
2150 rfe_type->ext_ant_switch_exist = TRUE;
2151 rfe_type->ext_ant_switch_type =
2152 BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2153 break;
2154 case 5:
2155 rfe_type->ext_ant_switch_exist = TRUE;
2156 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2157 break;
2158 case 6:
2159 rfe_type->ext_ant_switch_exist = TRUE;
2160 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2161 break;
2162 case 7:
2163 rfe_type->ext_ant_switch_exist = TRUE;
2164 rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
2165 break;
2166 }
2167 #endif
2168
2169 #if 0
2170
2171 if (rfe_type->wlg_Locate_at_btg)
2172 halbtc8822b2ant_set_int_block(btcoexist, FORCE_EXEC,
2173 BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG);
2174 else
2175 halbtc8822b2ant_set_int_block(btcoexist, FORCE_EXEC,
2176 BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
2177 #endif
2178
2179 }
2180
2181 /* set gnt_wl gnt_bt control by sw high low, or hwpta while in
2182 * power on, ini, wlan off, wlan only, wl2g non-currrent, wl2g current, wl5g
2183 */
2184 static
halbtc8822b2ant_set_ant_path(IN struct btc_coexist * btcoexist,IN u8 ant_pos_type,IN boolean force_exec,IN u8 phase)2185 void halbtc8822b2ant_set_ant_path(IN struct btc_coexist *btcoexist,
2186 IN u8 ant_pos_type, IN boolean force_exec,
2187 IN u8 phase)
2188 {
2189
2190 u8 u8tmp = 0;
2191 u32 u32tmp1 = 0;
2192 u32 u32tmp2 = 0, u32tmp3 = 0;
2193
2194 u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
2195 0x38);
2196
2197 /* To avoid indirect access fail */
2198 if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) {
2199 force_exec = TRUE;
2200 coex_sta->gnt_error_cnt++;
2201 }
2202
2203 /* Ext switch buffer mux */
2204 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2205 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2206 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2207 /* 0x4c[23] = 0 */
2208 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, 0x0);
2209 /* 0x4c[24] = 1 */
2210 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01, 0x1);
2211
2212 coex_sta->is_2g_freerun = ((phase == BT_8822B_2ANT_PHASE_2G_FREERUN) ? TRUE : FALSE);
2213
2214 coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
2215
2216 if (!force_exec) {
2217 if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type)
2218 return;
2219 }
2220
2221 coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
2222
2223 #if BT_8822B_2ANT_COEX_DBG
2224 u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
2225 0x38);
2226 u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
2227 0x54);
2228 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
2229
2230 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2231
2232 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2233 "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
2234 u32tmp3, u8tmp, u32tmp1, u32tmp2);
2235 BTC_TRACE(trace_buf);
2236 #endif
2237
2238 switch (phase) {
2239 case BT_8822B_2ANT_PHASE_COEX_POWERON:
2240
2241 /* set Path control owner to WL at initial step */
2242 halbtc8822b2ant_ltecoex_pathcontrol_owner(btcoexist,
2243 BT_8822B_2ANT_PCO_BTSIDE);
2244
2245 /* set GNT_BT to SW high */
2246 halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
2247 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2248 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2249 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2250 /* Set GNT_WL to SW high */
2251 halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
2252 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2253 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2254 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2255
2256 coex_sta->run_time_state = FALSE;
2257
2258 break;
2259 case BT_8822B_2ANT_PHASE_COEX_INIT:
2260 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2261 0x80, 0x0); /* 0x4c[23] = 0 */
2262 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2263 0x01, 0x1); /* 0x4c[24] = 1 */
2264 /* Disable LTE Coex Function in WiFi side
2265 * (this should be on if LTE coex is required)
2266 */
2267 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2268
2269 /* GNT_WL_LTE always = 1
2270 * (this should be config if LTE coex is required)
2271 */
2272 halbtc8822b2ant_ltecoex_set_coex_table(
2273 btcoexist,
2274 BT_8822B_2ANT_CTT_WL_VS_LTE,
2275 0xffff);
2276
2277 /* GNT_BT_LTE always = 1
2278 * (this should be config if LTE coex is required)
2279 */
2280 halbtc8822b2ant_ltecoex_set_coex_table(
2281 btcoexist,
2282 BT_8822B_2ANT_CTT_BT_VS_LTE,
2283 0xffff);
2284
2285 /* set Path control owner to WL at initial step */
2286 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2287 btcoexist,
2288 BT_8822B_2ANT_PCO_WLSIDE);
2289
2290 /* set GNT_BT to SW high */
2291 halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
2292 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2293 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2294 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2295 /* Set GNT_WL to SW high */
2296 halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
2297 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2298 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2299 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2300
2301 coex_sta->run_time_state = FALSE;
2302
2303 break;
2304 case BT_8822B_2ANT_PHASE_WLANONLY_INIT:
2305 /* Disable LTE Coex Function in WiFi side
2306 * (this should be on if LTE coex is required)
2307 */
2308 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2309
2310 /* GNT_WL_LTE always = 1
2311 * (this should be config if LTE coex is required)
2312 */
2313 halbtc8822b2ant_ltecoex_set_coex_table(
2314 btcoexist,
2315 BT_8822B_2ANT_CTT_WL_VS_LTE,
2316 0xffff);
2317
2318 /* GNT_BT_LTE always = 1
2319 * (this should be config if LTE coex is required)
2320 */
2321 halbtc8822b2ant_ltecoex_set_coex_table(
2322 btcoexist,
2323 BT_8822B_2ANT_CTT_BT_VS_LTE,
2324 0xffff);
2325
2326 /* set Path control owner to WL at initial step */
2327 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2328 btcoexist,
2329 BT_8822B_2ANT_PCO_WLSIDE);
2330
2331 /* set GNT_BT to SW Low */
2332 halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
2333 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2334 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2335 BT_8822B_2ANT_SIG_STA_SET_TO_LOW);
2336 /* Set GNT_WL to SW high */
2337 halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
2338 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2339 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2340 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2341
2342 coex_sta->run_time_state = FALSE;
2343
2344
2345 break;
2346 case BT_8822B_2ANT_PHASE_WLAN_OFF:
2347 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2348 0x80, 0x0); /* 0x4c[23] = 0 */
2349 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2350 0x01, 0x0); /* 0x4c[24] = 0 */
2351 /* Disable LTE Coex Function in WiFi side */
2352 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2353
2354 /* set Path control owner to BT */
2355 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2356 btcoexist,
2357 BT_8822B_2ANT_PCO_BTSIDE);
2358
2359 /* Set Ext Ant Switch to BT control at wifi off step */
2360 halbtc8822b2ant_set_ext_ant_switch(btcoexist,
2361 FORCE_EXEC,
2362 BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
2363 BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE);
2364 coex_sta->run_time_state = FALSE;
2365 break;
2366 case BT_8822B_2ANT_PHASE_2G_RUNTIME:
2367 case BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT:
2368
2369 /* set Path control owner to WL at runtime step */
2370 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2371 btcoexist,
2372 BT_8822B_2ANT_PCO_WLSIDE);
2373 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x66);
2374 if (phase ==
2375 BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT) {
2376 /* set GNT_BT to PTA */
2377 halbtc8822b2ant_ltecoex_set_gnt_bt(
2378 btcoexist,
2379 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2380 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
2381 BT_8822B_2ANT_SIG_STA_SET_BY_HW);
2382
2383 /* Set GNT_WL to SW High */
2384 halbtc8822b2ant_ltecoex_set_gnt_wl(
2385 btcoexist,
2386 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2387 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2388 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2389 } else {
2390 /* set GNT_BT to PTA */
2391 halbtc8822b2ant_ltecoex_set_gnt_bt(
2392 btcoexist,
2393 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2394 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
2395 BT_8822B_2ANT_SIG_STA_SET_BY_HW);
2396
2397 /* Set GNT_WL to PTA */
2398 halbtc8822b2ant_ltecoex_set_gnt_wl(
2399 btcoexist,
2400 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2401 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
2402 BT_8822B_2ANT_SIG_STA_SET_BY_HW);
2403 }
2404
2405 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2406 "[BTCoex], ************* under2g 0xcbd setting =2 *************\n");
2407 BTC_TRACE(trace_buf);
2408
2409 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 02);
2410 break;
2411
2412 case BT_8822B_2ANT_PHASE_5G_RUNTIME:
2413 case BT_8822B_2ANT_PHASE_2G_FREERUN:
2414
2415 /* set Path control owner to WL at runtime step */
2416 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2417 btcoexist,
2418 BT_8822B_2ANT_PCO_WLSIDE);
2419
2420 /* set GNT_BT to SW Hi */
2421 halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
2422 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2423 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2424 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2425 /* Set GNT_WL to SW Hi */
2426 halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
2427 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2428 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2429 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2430 coex_sta->run_time_state = TRUE;
2431
2432 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2433 "[BTCoex], ************* under5g 0xcbd setting =1 *************\n");
2434 BTC_TRACE(trace_buf);
2435
2436 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 01);
2437
2438 break;
2439 case BT_8822B_2ANT_PHASE_BTMPMODE:
2440 /* Disable LTE Coex Function in WiFi side */
2441 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2442
2443 /* set Path control owner to WL */
2444 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2445 btcoexist,
2446 BT_8822B_2ANT_PCO_WLSIDE);
2447
2448 /* set GNT_BT to SW Hi */
2449 halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
2450 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2451 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2452 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2453
2454 /* Set GNT_WL to SW Lo */
2455 halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
2456 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2457 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2458 BT_8822B_2ANT_SIG_STA_SET_TO_LOW);
2459
2460 coex_sta->run_time_state = FALSE;
2461 break;
2462 }
2463 #if BT_8822B_2ANT_COEX_DBG
2464 u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
2465 u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
2466 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2467 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
2468
2469 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2470 "[BTCoex], (After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
2471 phase, u32tmp3, u8tmp, u32tmp1, u32tmp2);
2472
2473 BTC_TRACE(trace_buf);
2474 #endif
2475
2476 }
2477
2478
2479 static
halbtc8822b2ant_action_algorithm(IN struct btc_coexist * btcoexist)2480 u8 halbtc8822b2ant_action_algorithm(IN struct btc_coexist *btcoexist)
2481 {
2482 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2483 boolean bt_hs_on = FALSE;
2484 u8 algorithm = BT_8822B_2ANT_COEX_ALGO_UNDEFINED;
2485 u8 num_of_diff_profile = 0;
2486
2487 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2488
2489 if (!bt_link_info->bt_link_exist) {
2490 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2491 "[BTCoex], No BT link exists!!!\n");
2492 BTC_TRACE(trace_buf);
2493 return algorithm;
2494 }
2495
2496 if (bt_link_info->sco_exist)
2497 num_of_diff_profile++;
2498 if (bt_link_info->hid_exist)
2499 num_of_diff_profile++;
2500 if (bt_link_info->pan_exist)
2501 num_of_diff_profile++;
2502 if (bt_link_info->a2dp_exist)
2503 num_of_diff_profile++;
2504
2505 if (num_of_diff_profile == 0) {
2506
2507 if (bt_link_info->acl_busy) {
2508 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2509 "[BTCoex], No-Profile busy\n");
2510 BTC_TRACE(trace_buf);
2511 algorithm = BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY;
2512 }
2513 } else if ((bt_link_info->a2dp_exist) && (coex_sta->is_bt_a2dp_sink)) {
2514 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2515 "[BTCoex], A2DP Sink\n");
2516 BTC_TRACE(trace_buf);
2517 algorithm = BT_8822B_2ANT_COEX_ALGO_A2DPSINK;
2518 } else if (num_of_diff_profile == 1) {
2519 if (bt_link_info->sco_exist) {
2520 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2521 "[BTCoex], SCO only\n");
2522 BTC_TRACE(trace_buf);
2523 algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
2524 } else {
2525 if (bt_link_info->hid_exist) {
2526 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2527 "[BTCoex], HID only\n");
2528 BTC_TRACE(trace_buf);
2529 algorithm = BT_8822B_2ANT_COEX_ALGO_HID;
2530 } else if (bt_link_info->a2dp_exist) {
2531 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2532 "[BTCoex], A2DP only\n");
2533 BTC_TRACE(trace_buf);
2534 algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP;
2535 } else if (bt_link_info->pan_exist) {
2536 if (bt_hs_on) {
2537 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2538 "[BTCoex], PAN(HS) only\n");
2539 BTC_TRACE(trace_buf);
2540 algorithm =
2541 BT_8822B_2ANT_COEX_ALGO_PANHS;
2542 } else {
2543 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2544 "[BTCoex], PAN(EDR) only\n");
2545 BTC_TRACE(trace_buf);
2546 algorithm =
2547 BT_8822B_2ANT_COEX_ALGO_PANEDR;
2548 }
2549 }
2550 }
2551 } else if (num_of_diff_profile == 2) {
2552 if (bt_link_info->sco_exist) {
2553 if (bt_link_info->hid_exist) {
2554 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2555 "[BTCoex], SCO + HID\n");
2556 BTC_TRACE(trace_buf);
2557 algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
2558 } else if (bt_link_info->a2dp_exist) {
2559 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2560 "[BTCoex], SCO + A2DP ==> A2DP\n");
2561 BTC_TRACE(trace_buf);
2562 algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP;
2563 } else if (bt_link_info->pan_exist) {
2564 if (bt_hs_on) {
2565 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2566 "[BTCoex], SCO + PAN(HS)\n");
2567 BTC_TRACE(trace_buf);
2568 algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
2569 } else {
2570 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2571 "[BTCoex], SCO + PAN(EDR)\n");
2572 BTC_TRACE(trace_buf);
2573 algorithm =
2574 BT_8822B_2ANT_COEX_ALGO_PANEDR;
2575 }
2576 }
2577 } else {
2578 if (bt_link_info->hid_exist &&
2579 bt_link_info->a2dp_exist) {
2580 {
2581 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2582 "[BTCoex], HID + A2DP\n");
2583 BTC_TRACE(trace_buf);
2584 algorithm =
2585 BT_8822B_2ANT_COEX_ALGO_HID_A2DP;
2586 }
2587 } else if (bt_link_info->hid_exist &&
2588 bt_link_info->pan_exist) {
2589 if (bt_hs_on) {
2590 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2591 "[BTCoex], HID + PAN(HS)\n");
2592 BTC_TRACE(trace_buf);
2593 algorithm = BT_8822B_2ANT_COEX_ALGO_HID;
2594 } else {
2595 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2596 "[BTCoex], HID + PAN(EDR)\n");
2597 BTC_TRACE(trace_buf);
2598 algorithm =
2599 BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
2600 }
2601 } else if (bt_link_info->pan_exist &&
2602 bt_link_info->a2dp_exist) {
2603 if (bt_hs_on) {
2604 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2605 "[BTCoex], A2DP + PAN(HS)\n");
2606 BTC_TRACE(trace_buf);
2607 algorithm =
2608 BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS;
2609 } else {
2610 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2611 "[BTCoex], A2DP + PAN(EDR)\n");
2612 BTC_TRACE(trace_buf);
2613 algorithm =
2614 BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
2615 }
2616 }
2617 }
2618 } else if (num_of_diff_profile == 3) {
2619 if (bt_link_info->sco_exist) {
2620 if (bt_link_info->hid_exist &&
2621 bt_link_info->a2dp_exist) {
2622 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2623 "[BTCoex], SCO + HID + A2DP ==> HID + A2DP\n");
2624 BTC_TRACE(trace_buf);
2625 algorithm = BT_8822B_2ANT_COEX_ALGO_HID_A2DP;
2626 } else if (bt_link_info->hid_exist &&
2627 bt_link_info->pan_exist) {
2628 if (bt_hs_on) {
2629 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2630 "[BTCoex], SCO + HID + PAN(HS)\n");
2631 BTC_TRACE(trace_buf);
2632 algorithm =
2633 BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
2634 } else {
2635 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2636 "[BTCoex], SCO + HID + PAN(EDR)\n");
2637 BTC_TRACE(trace_buf);
2638 algorithm =
2639 BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
2640 }
2641 } else if (bt_link_info->pan_exist &&
2642 bt_link_info->a2dp_exist) {
2643 if (bt_hs_on) {
2644 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2645 "[BTCoex], SCO + A2DP + PAN(HS)\n");
2646 BTC_TRACE(trace_buf);
2647 algorithm =
2648 BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
2649 } else {
2650 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2651 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
2652 BTC_TRACE(trace_buf);
2653 algorithm =
2654 BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
2655 }
2656 }
2657 } else {
2658 if (bt_link_info->hid_exist &&
2659 bt_link_info->pan_exist &&
2660 bt_link_info->a2dp_exist) {
2661 if (bt_hs_on) {
2662 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2663 "[BTCoex], HID + A2DP + PAN(HS)\n");
2664 BTC_TRACE(trace_buf);
2665 algorithm =
2666 BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2667 } else {
2668 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2669 "[BTCoex], HID + A2DP + PAN(EDR)\n");
2670 BTC_TRACE(trace_buf);
2671 algorithm =
2672 BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2673 }
2674 }
2675 }
2676 } else if (num_of_diff_profile >= 3) {
2677 if (bt_link_info->sco_exist) {
2678 if (bt_link_info->hid_exist &&
2679 bt_link_info->pan_exist &&
2680 bt_link_info->a2dp_exist) {
2681 if (bt_hs_on) {
2682 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2683 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
2684 BTC_TRACE(trace_buf);
2685 algorithm =
2686 BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2687 } else {
2688 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2689 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
2690 BTC_TRACE(trace_buf);
2691 algorithm =
2692 BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2693 }
2694 }
2695 }
2696 }
2697
2698 return algorithm;
2699 }
2700
2701
2702 static
halbtc8822b2ant_action_wifi_freerun(IN struct btc_coexist * btcoexist)2703 void halbtc8822b2ant_action_wifi_freerun(IN struct btc_coexist *btcoexist)
2704 {
2705 boolean wifi_busy = FALSE;
2706
2707 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2708
2709 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], wifi_freerun!!\n");
2710 BTC_TRACE(trace_buf);
2711
2712
2713 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd0);
2714 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 21);
2715 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, TRUE);
2716
2717 /* just for GNT_WL = 1 && GNT_BT = 1, not for antenna control */
2718 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
2719 BT_8822B_2ANT_PHASE_2G_FREERUN);
2720
2721 if (wifi_busy)
2722 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, TRUE);
2723 else
2724 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2725
2726 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2727 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2728 }
2729
2730
2731 static
halbtc8822b2ant_action_coex_all_off(IN struct btc_coexist * btcoexist)2732 void halbtc8822b2ant_action_coex_all_off(IN struct btc_coexist *btcoexist)
2733 {
2734
2735 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2736 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2737 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2738 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2739
2740 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2741 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2742 }
2743
2744 static
halbtc8822b2ant_action_bt_whql_test(IN struct btc_coexist * btcoexist)2745 void halbtc8822b2ant_action_bt_whql_test(IN struct btc_coexist *btcoexist)
2746 {
2747 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2748 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2749 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2750 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2751
2752 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2753 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2754 }
2755
2756 static
halbtc8822b2ant_action_bt_hs(IN struct btc_coexist * btcoexist)2757 void halbtc8822b2ant_action_bt_hs(IN struct btc_coexist *btcoexist)
2758 {
2759 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2760 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2761 u8 wifi_rssi_state, bt_rssi_state;
2762
2763 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2764 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2765 u8 wifi_rssi_state2, bt_rssi_state2;
2766 boolean wifi_busy = FALSE, wifi_turbo = FALSE;
2767
2768
2769 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2770 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2771 &coex_sta->scan_ap_num);
2772 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2773 "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n",
2774 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
2775 BTC_TRACE(trace_buf);
2776
2777 #if 1
2778 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
2779 wifi_turbo = TRUE;
2780 #endif
2781
2782
2783 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
2784 &prewifi_rssi_state, 2,
2785 coex_sta->wifi_coex_thres, 0);
2786
2787 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
2788 &prewifi_rssi_state2, 2,
2789 coex_sta->wifi_coex_thres2, 0);
2790
2791 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
2792 &pre_bt_rssi_state, 2,
2793 coex_sta->bt_coex_thres, 0);
2794
2795 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
2796 &pre_bt_rssi_state2, 2,
2797 coex_sta->bt_coex_thres2, 0);
2798
2799 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
2800 BTC_RSSI_HIGH(bt_rssi_state)) {
2801
2802 halbtc8822b2ant_action_wifi_freerun(btcoexist);
2803 } else {
2804
2805 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2806 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2807 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2808 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2809
2810 coex_dm->is_switch_to_1dot5_ant = TRUE;
2811
2812 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2813
2814 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2815 }
2816
2817 }
2818
2819 static
halbtc8822b2ant_action_bt_relink(IN struct btc_coexist * btcoexist)2820 void halbtc8822b2ant_action_bt_relink(IN struct btc_coexist *btcoexist)
2821 {
2822 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2823 "[BTCoex], run bt multi link function\n");
2824 BTC_TRACE(trace_buf);
2825
2826 if (coex_sta->is_bt_multi_link)
2827 return;
2828 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2829 "[BTCoex], run bt re-link function\n");
2830 BTC_TRACE(trace_buf);
2831
2832 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2833 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2834 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2835 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2836
2837 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2838 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2839 }
2840
2841 static
halbtc8822b2ant_action_bt_idle(IN struct btc_coexist * btcoexist)2842 void halbtc8822b2ant_action_bt_idle(IN struct btc_coexist *btcoexist)
2843 {
2844
2845 boolean wifi_busy = FALSE;
2846
2847 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2848 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2849 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2850 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2851
2852 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2853
2854 if (!wifi_busy) {
2855
2856 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2857
2858 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 14);
2859 } else { /* if wl busy */
2860
2861 if (BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2862 coex_dm->bt_status) {
2863 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2864
2865 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2866 } else {
2867 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2868 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 12);
2869 }
2870 }
2871
2872 }
2873
2874 static
halbtc8822b2ant_action_bt_inquiry(IN struct btc_coexist * btcoexist)2875 void halbtc8822b2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
2876 {
2877
2878 boolean wifi_connected = FALSE;
2879 boolean wifi_scan = FALSE, wifi_link = FALSE, wifi_roam = FALSE;
2880 boolean wifi_busy = FALSE;
2881 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2882
2883
2884 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2885 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
2886
2887 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
2888 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link);
2889 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam);
2890
2891 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2892 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2893 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2894 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2895
2896 if ((coex_sta->bt_create_connection) && ((wifi_link) || (wifi_roam)
2897 || (wifi_scan) || (wifi_busy) || (coex_sta->wifi_is_high_pri_task))) {
2898
2899 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2900 "[BTCoex], Wifi link/roam/Scan/busy/hi-pri-task + BT Inq/Page!!\n");
2901 BTC_TRACE(trace_buf);
2902
2903 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2904
2905 if ((bt_link_info->a2dp_exist) && (!bt_link_info->pan_exist))
2906 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 15);
2907 else
2908 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 11);
2909 } else if ((!wifi_connected) && (!wifi_scan)) {
2910
2911 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2912 "[BTCoex], Wifi no-link + no-scan + BT Inq/Page!!\n");
2913 BTC_TRACE(trace_buf);
2914
2915 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2916
2917 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
2918 } else if (bt_link_info->pan_exist) {
2919 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2920
2921 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 22);
2922
2923
2924 } else if (bt_link_info->a2dp_exist) {
2925
2926 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10);
2927
2928 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 8);
2929
2930 } else {
2931
2932 if ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy)
2933 || (coex_sta->wifi_is_high_pri_task))
2934 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 21);
2935 else
2936 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 23);
2937
2938 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2939 }
2940
2941 }
2942
2943
2944 /* SCO only or SCO+PAN(HS) */
2945 static
halbtc8822b2ant_action_sco(IN struct btc_coexist * btcoexist)2946 void halbtc8822b2ant_action_sco(IN struct btc_coexist *btcoexist)
2947 {
2948 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2949 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2950 u8 wifi_rssi_state, bt_rssi_state;
2951
2952 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2953 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2954 u8 wifi_rssi_state2, bt_rssi_state2;
2955 boolean wifi_busy = FALSE;
2956 u32 wifi_bw = 1;
2957
2958 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
2959 &wifi_bw);
2960
2961 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2962
2963 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
2964 &prewifi_rssi_state, 2,
2965 coex_sta->wifi_coex_thres , 0);
2966
2967 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
2968 &prewifi_rssi_state2, 2,
2969 coex_sta->wifi_coex_thres2, 0);
2970
2971 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
2972 &pre_bt_rssi_state, 2,
2973 coex_sta->bt_coex_thres, 0);
2974
2975 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
2976 &pre_bt_rssi_state2, 2,
2977 coex_sta->bt_coex_thres2, 0);
2978
2979
2980 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
2981 BTC_RSSI_HIGH(bt_rssi_state)) {
2982
2983 halbtc8822b2ant_action_wifi_freerun(btcoexist);
2984 } else {
2985
2986 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
2987 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
2988 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2989 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
2990
2991 coex_dm->is_switch_to_1dot5_ant = FALSE;
2992
2993 if (coex_sta->is_eSCO_mode)
2994 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2995 else /* 2-Ant free run if SCO mode */
2996 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2997
2998 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 8);
2999 }
3000
3001 }
3002
3003
3004 static
halbtc8822b2ant_action_hid(IN struct btc_coexist * btcoexist)3005 void halbtc8822b2ant_action_hid(IN struct btc_coexist *btcoexist)
3006 {
3007 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3008 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3009 u8 wifi_rssi_state, bt_rssi_state;
3010
3011 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3012 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3013 u8 wifi_rssi_state2, bt_rssi_state2;
3014 boolean wifi_busy = FALSE;
3015 u32 wifi_bw = 1;
3016
3017
3018 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3019 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3020
3021 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3022 &prewifi_rssi_state, 2,
3023 coex_sta->wifi_coex_thres, 0);
3024
3025 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3026 &prewifi_rssi_state2, 2,
3027 coex_sta->wifi_coex_thres2, 0);
3028
3029 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3030 &pre_bt_rssi_state, 2,
3031 coex_sta->bt_coex_thres, 0);
3032
3033 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3034 &pre_bt_rssi_state2, 2,
3035 coex_sta->bt_coex_thres2, 0);
3036
3037
3038 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3039 BTC_RSSI_HIGH(bt_rssi_state)) {
3040
3041 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3042 } else {
3043
3044 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3045 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3046 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3047 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3048
3049 coex_dm->is_switch_to_1dot5_ant = FALSE;
3050
3051 if (coex_sta->is_hid_low_pri_tx_overhead) {
3052
3053 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3054 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 108);
3055 } else if (wifi_bw == 0) { /* if 11bg mode */
3056
3057 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3058 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 111);
3059 } else {
3060
3061 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3062 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE,
3063 111);
3064 }
3065 }
3066
3067 }
3068
3069
3070 static
halbtc8822b2ant_action_a2dpsink(IN struct btc_coexist * btcoexist)3071 void halbtc8822b2ant_action_a2dpsink(IN struct btc_coexist *btcoexist)
3072 {
3073 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3074 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3075 u8 wifi_rssi_state, bt_rssi_state;
3076
3077 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3078 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3079 u8 wifi_rssi_state2, bt_rssi_state2;
3080 boolean wifi_busy = FALSE, wifi_turbo = FALSE;
3081
3082 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3083 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3084 &coex_sta->scan_ap_num);
3085 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3086 "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n",
3087 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3088 BTC_TRACE(trace_buf);
3089
3090 #if 1
3091 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3092 wifi_turbo = TRUE;
3093 #endif
3094
3095 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3096 &prewifi_rssi_state, 2,
3097 coex_sta->wifi_coex_thres, 0);
3098
3099 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3100 &prewifi_rssi_state2, 2,
3101 coex_sta->wifi_coex_thres2, 0);
3102
3103 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3104 &pre_bt_rssi_state, 2,
3105 coex_sta->bt_coex_thres, 0);
3106
3107 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3108 &pre_bt_rssi_state2, 2,
3109 coex_sta->bt_coex_thres2, 0);
3110
3111
3112 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3113 BTC_RSSI_HIGH(bt_rssi_state)) {
3114
3115 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3116 } else {
3117
3118 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3119 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3120 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3121 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3122
3123 coex_dm->is_switch_to_1dot5_ant = TRUE;
3124
3125 if ((coex_sta->bt_relink_downcount != 0)
3126 && (wifi_busy)) {
3127
3128 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3129 "############# [BTCoex], BT Re-Link + A2DP + WL busy\n");
3130 BTC_TRACE(trace_buf);
3131
3132 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3133 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
3134
3135 } else {
3136 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3137 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 105);
3138 }
3139
3140 }
3141
3142 }
3143
3144 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
3145 static
halbtc8822b2ant_action_a2dp(IN struct btc_coexist * btcoexist)3146 void halbtc8822b2ant_action_a2dp(IN struct btc_coexist *btcoexist)
3147 {
3148 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3149 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3150 u8 wifi_rssi_state, bt_rssi_state;
3151
3152 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3153 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3154 u8 wifi_rssi_state2, bt_rssi_state2;
3155 boolean wifi_busy = FALSE, wifi_turbo = FALSE;
3156
3157
3158 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3159 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3160 &coex_sta->scan_ap_num);
3161 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3162 "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n",
3163 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3164 BTC_TRACE(trace_buf);
3165
3166
3167 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3168 wifi_turbo = TRUE;
3169
3170 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3171 &prewifi_rssi_state, 2,
3172 coex_sta->wifi_coex_thres, 0);
3173
3174 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3175 &prewifi_rssi_state2, 2,
3176 coex_sta->wifi_coex_thres2, 0);
3177
3178 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3179 &pre_bt_rssi_state, 2,
3180 coex_sta->bt_coex_thres, 0);
3181
3182 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3183 &pre_bt_rssi_state2, 2,
3184 coex_sta->bt_coex_thres2, 0);
3185
3186 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3187 BTC_RSSI_HIGH(bt_rssi_state)) {
3188
3189 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3190 } else {
3191
3192 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3193 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3194 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3195 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3196
3197 coex_dm->is_switch_to_1dot5_ant = TRUE;
3198
3199 if ((coex_sta->bt_relink_downcount != 0)
3200 && (wifi_busy)) {
3201
3202 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3203 "############# [BTCoex], BT Re-Link + A2DP + WL busy\n");
3204 BTC_TRACE(trace_buf);
3205
3206 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3207 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
3208
3209 } else {
3210
3211 if (wifi_turbo)
3212 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10);
3213 else
3214 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10);
3215
3216 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3217 TRUE, 109);
3218 }
3219
3220 }
3221
3222 }
3223
3224
3225 static
halbtc8822b2ant_action_pan_edr(IN struct btc_coexist * btcoexist)3226 void halbtc8822b2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
3227 {
3228 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3229 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3230 u8 wifi_rssi_state, bt_rssi_state;
3231
3232 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3233 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3234 u8 wifi_rssi_state2, bt_rssi_state2;
3235 boolean wifi_busy = FALSE, wifi_turbo = FALSE;
3236
3237
3238 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3239 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3240 &coex_sta->scan_ap_num);
3241 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3242 "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n",
3243 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3244 BTC_TRACE(trace_buf);
3245
3246 #if 1
3247 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3248 wifi_turbo = TRUE;
3249 #endif
3250
3251 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3252 &prewifi_rssi_state, 2,
3253 coex_sta->wifi_coex_thres, 0);
3254
3255 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3256 &prewifi_rssi_state2, 2,
3257 coex_sta->wifi_coex_thres2, 0);
3258
3259 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3260 &pre_bt_rssi_state, 2,
3261 coex_sta->bt_coex_thres, 0);
3262
3263 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3264 &pre_bt_rssi_state2, 2,
3265 coex_sta->bt_coex_thres2, 0);
3266
3267
3268 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3269 BTC_RSSI_HIGH(bt_rssi_state)) {
3270
3271 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3272 } else {
3273
3274 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3275 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3276 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3277 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3278
3279 coex_dm->is_switch_to_1dot5_ant = TRUE;
3280
3281 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3282
3283 if (wifi_busy)
3284 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 103);
3285 else
3286 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 104);
3287 }
3288
3289 }
3290
3291 static
halbtc8822b2ant_action_hid_a2dp(IN struct btc_coexist * btcoexist)3292 void halbtc8822b2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
3293 {
3294 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3295 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3296 u8 wifi_rssi_state, bt_rssi_state;
3297
3298 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3299 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3300 u8 wifi_rssi_state2, bt_rssi_state2;
3301 boolean wifi_busy = FALSE;
3302 u32 wifi_bw = 1;
3303
3304 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
3305 &wifi_bw);
3306
3307
3308 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3309
3310 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3311 &prewifi_rssi_state, 2,
3312 coex_sta->wifi_coex_thres, 0);
3313
3314 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3315 &prewifi_rssi_state2, 2,
3316 coex_sta->wifi_coex_thres2, 0);
3317
3318 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3319 &pre_bt_rssi_state, 2,
3320 coex_sta->bt_coex_thres, 0);
3321
3322 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3323 &pre_bt_rssi_state2, 2,
3324 coex_sta->bt_coex_thres2, 0);
3325
3326
3327 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3328 BTC_RSSI_HIGH(bt_rssi_state)) {
3329
3330 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3331 } else {
3332
3333 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3334 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3335 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3336 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3337
3338 coex_dm->is_switch_to_1dot5_ant = TRUE;
3339
3340 if ((coex_sta->bt_relink_downcount != 0)
3341 && (wifi_busy)) {
3342
3343 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3344 "############# [BTCoex], BT Re-Link + A2DP + WL busy\n");
3345 BTC_TRACE(trace_buf);
3346
3347 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
3348 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3349 } else {
3350 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3351 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 109);
3352 }
3353 }
3354
3355 }
3356
3357 static
halbtc8822b2ant_action_a2dp_pan_hs(IN struct btc_coexist * btcoexist)3358 void halbtc8822b2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
3359 {
3360 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3361 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3362 u8 wifi_rssi_state, bt_rssi_state;
3363
3364 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3365 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3366 u8 wifi_rssi_state2, bt_rssi_state2;
3367 boolean wifi_busy = FALSE, wifi_turbo = FALSE;
3368
3369
3370 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3371 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3372 &coex_sta->scan_ap_num);
3373 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3374 "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n",
3375 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3376 BTC_TRACE(trace_buf);
3377
3378 #if 1
3379 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3380 wifi_turbo = TRUE;
3381 #endif
3382
3383
3384 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3385 &prewifi_rssi_state, 2,
3386 coex_sta->wifi_coex_thres, 0);
3387
3388 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3389 &prewifi_rssi_state2, 2,
3390 coex_sta->wifi_coex_thres2, 0);
3391
3392 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3393 &pre_bt_rssi_state, 2,
3394 coex_sta->bt_coex_thres, 0);
3395
3396 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3397 &pre_bt_rssi_state2, 2,
3398 coex_sta->bt_coex_thres2, 0);
3399
3400
3401 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3402 BTC_RSSI_HIGH(bt_rssi_state)) {
3403
3404 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3405 } else {
3406
3407 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3408 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3409 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3410 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3411
3412 coex_dm->is_switch_to_1dot5_ant = TRUE;
3413
3414 if (wifi_turbo)
3415 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
3416 else
3417 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3418
3419 if (wifi_busy) {
3420
3421 if ((coex_sta->a2dp_bit_pool > 40) &&
3422 (coex_sta->a2dp_bit_pool < 255))
3423 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 107);
3424 else
3425 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 105);
3426 } else
3427 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 106);
3428
3429 }
3430
3431 }
3432
3433
3434
3435
3436 /* PAN(EDR)+A2DP */
3437 static
halbtc8822b2ant_action_pan_edr_a2dp(IN struct btc_coexist * btcoexist)3438 void halbtc8822b2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
3439 {
3440 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3441 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3442 u8 wifi_rssi_state, bt_rssi_state;
3443
3444 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3445 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3446 u8 wifi_rssi_state2, bt_rssi_state2;
3447 boolean wifi_busy = FALSE, wifi_turbo = FALSE;
3448
3449
3450 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3451 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3452 &coex_sta->scan_ap_num);
3453 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3454 "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n",
3455 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3456 BTC_TRACE(trace_buf);
3457
3458 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3459 wifi_turbo = TRUE;
3460
3461 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3462 &prewifi_rssi_state, 2,
3463 coex_sta->wifi_coex_thres, 0);
3464
3465 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3466 &prewifi_rssi_state2, 2,
3467 coex_sta->wifi_coex_thres2, 0);
3468
3469 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3470 &pre_bt_rssi_state, 2,
3471 coex_sta->bt_coex_thres, 0);
3472
3473 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3474 &pre_bt_rssi_state2, 2,
3475 coex_sta->bt_coex_thres2, 0);
3476
3477 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3478 BTC_RSSI_HIGH(bt_rssi_state)) {
3479
3480 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3481 } else {
3482
3483 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3484 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3485 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3486 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3487
3488 coex_dm->is_switch_to_1dot5_ant = TRUE;
3489
3490 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3491 if (wifi_busy)
3492 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 107);
3493 else
3494 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 106);
3495 }
3496
3497 }
3498
3499
3500 static
halbtc8822b2ant_action_pan_edr_hid(IN struct btc_coexist * btcoexist)3501 void halbtc8822b2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
3502 {
3503 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3504 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3505 u8 wifi_rssi_state, bt_rssi_state;
3506
3507 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3508 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3509 u8 wifi_rssi_state2, bt_rssi_state2;
3510 boolean wifi_busy = FALSE;
3511 u32 wifi_bw = 1;
3512
3513 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
3514 &wifi_bw);
3515
3516 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3517
3518 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3519 &prewifi_rssi_state, 2,
3520 coex_sta->wifi_coex_thres, 0);
3521
3522 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3523 &prewifi_rssi_state2, 2,
3524 coex_sta->wifi_coex_thres2, 0);
3525
3526 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3527 &pre_bt_rssi_state, 2,
3528 coex_sta->bt_coex_thres, 0);
3529
3530 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3531 &pre_bt_rssi_state2, 2,
3532 coex_sta->bt_coex_thres2, 0);
3533
3534
3535 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3536 BTC_RSSI_HIGH(bt_rssi_state)) {
3537
3538 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3539 } else {
3540
3541 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3542 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3543 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3544 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3545
3546 coex_dm->is_switch_to_1dot5_ant = TRUE;
3547
3548 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3549
3550 if (wifi_busy)
3551 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 103);
3552 else
3553 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 104);
3554 }
3555
3556 }
3557
3558
3559 /* HID+A2DP+PAN(EDR) */
3560 static
halbtc8822b2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist * btcoexist)3561 void halbtc8822b2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
3562 {
3563 static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3564 static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3565 u8 wifi_rssi_state, bt_rssi_state;
3566
3567 static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3568 static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3569 u8 wifi_rssi_state2, bt_rssi_state2;
3570 boolean wifi_busy = FALSE;
3571 u32 wifi_bw = 1;
3572
3573 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
3574 &wifi_bw);
3575
3576 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3577
3578 wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3579 &prewifi_rssi_state, 2,
3580 coex_sta->wifi_coex_thres, 0);
3581
3582 wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
3583 &prewifi_rssi_state2, 2,
3584 coex_sta->wifi_coex_thres2, 0);
3585
3586 bt_rssi_state = halbtc8822b2ant_bt_rssi_state(btcoexist,
3587 &pre_bt_rssi_state, 2,
3588 coex_sta->bt_coex_thres, 0);
3589
3590 bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(btcoexist,
3591 &pre_bt_rssi_state2, 2,
3592 coex_sta->bt_coex_thres2, 0);
3593
3594
3595 if (BTC_RSSI_HIGH(wifi_rssi_state) &&
3596 BTC_RSSI_HIGH(bt_rssi_state)) {
3597
3598 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3599 } else {
3600
3601 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3602 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3603 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3604 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3605
3606 coex_dm->is_switch_to_1dot5_ant = TRUE;
3607
3608 if (coex_sta->hid_busy_num >= 2) {
3609 halbtc8822b2ant_coex_table_with_type(btcoexist,
3610 NORMAL_EXEC, 8);
3611
3612 if (wifi_bw == 0) {
3613 halbtc8822b2ant_set_wltoggle_coex_table(
3614 btcoexist,
3615 NORMAL_EXEC,
3616 0x1, 0xaa,
3617 0x5a, 0xaa,
3618 0xaa);
3619 }
3620 else
3621 halbtc8822b2ant_set_wltoggle_coex_table(
3622 btcoexist,
3623 NORMAL_EXEC,
3624 0x2, 0xaa,
3625 0x5a, 0xaa,
3626 0xaa);
3627
3628 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 110);
3629 } else {
3630 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3631
3632 if (wifi_busy) {
3633
3634 if ((coex_sta->a2dp_bit_pool > 40) &&
3635 (coex_sta->a2dp_bit_pool < 255))
3636 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 107);
3637 else
3638 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 105);
3639 } else
3640 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 106);
3641 }
3642 }
3643
3644 }
3645
3646 static
halbtc8822b2ant_action_wifi_under5g(IN struct btc_coexist * btcoexist)3647 void halbtc8822b2ant_action_wifi_under5g(IN struct btc_coexist *btcoexist)
3648 {
3649
3650 /* fw all off */
3651 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3652 "[BTCoex], ************* under5g *************\n");
3653 BTC_TRACE(trace_buf);
3654
3655 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3656 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3657 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3658 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3659
3660 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
3661 BT_8822B_2ANT_PHASE_5G_RUNTIME);
3662
3663 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3664 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
3665
3666 }
3667
3668 static
halbtc8822b2ant_action_wifi_native_lps(IN struct btc_coexist * btcoexist)3669 void halbtc8822b2ant_action_wifi_native_lps(IN struct btc_coexist *btcoexist)
3670 {
3671 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3672 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3673 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3674 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3675
3676 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3677 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
3678
3679 }
3680
3681 static
halbtc8822b2ant_action_wifi_link_process(IN struct btc_coexist * btcoexist)3682 void halbtc8822b2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist)
3683 {
3684 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3685
3686 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3687 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3688 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3689 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3690
3691 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3692
3693 if (bt_link_info->pan_exist) {
3694 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3695
3696 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 22);
3697
3698 } else if (bt_link_info->a2dp_exist) {
3699 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3700
3701 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 16);
3702
3703 } else {
3704 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3705
3706 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 21);
3707
3708 }
3709
3710 }
3711
3712 static
halbtc8822b2ant_action_wifi_not_connected(IN struct btc_coexist * btcoexist)3713 void halbtc8822b2ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
3714 {
3715 halbtc8822b2ant_adjust_wl_tx_power(btcoexist, NORMAL_EXEC, 0xd8);
3716 halbtc8822b2ant_adjust_bt_tx_power(btcoexist, NORMAL_EXEC, 0);
3717 halbtc8822b2ant_adjust_wl_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3718 halbtc8822b2ant_adjust_bt_rx_gain(btcoexist, NORMAL_EXEC, FALSE);
3719
3720 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3721 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
3722 }
3723
3724
3725 static
halbtc8822b2ant_action_wifi_multi_port(IN struct btc_coexist * btcoexist)3726 void halbtc8822b2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
3727 {
3728 halbtc8822b2ant_action_wifi_freerun(btcoexist);
3729 }
3730
3731 static
halbtc8822b2ant_action_wifi_connected(IN struct btc_coexist * btcoexist)3732 void halbtc8822b2ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
3733 {
3734 switch (coex_dm->cur_algorithm) {
3735
3736 case BT_8822B_2ANT_COEX_ALGO_SCO:
3737 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3738 "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
3739 BTC_TRACE(trace_buf);
3740 halbtc8822b2ant_action_sco(btcoexist);
3741 break;
3742 case BT_8822B_2ANT_COEX_ALGO_HID:
3743 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3744 "[BTCoex], Action 2-Ant, algorithm = HID.\n");
3745 BTC_TRACE(trace_buf);
3746 halbtc8822b2ant_action_hid(btcoexist);
3747 break;
3748 case BT_8822B_2ANT_COEX_ALGO_A2DP:
3749 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3750 "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
3751 BTC_TRACE(trace_buf);
3752 halbtc8822b2ant_action_a2dp(btcoexist);
3753 break;
3754 case BT_8822B_2ANT_COEX_ALGO_A2DPSINK:
3755 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3756 "[BTCoex], Action 2-Ant, algorithm = A2DP Sink.\n");
3757 BTC_TRACE(trace_buf);
3758 halbtc8822b2ant_action_a2dpsink(btcoexist);
3759 break;
3760 case BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS:
3761 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3762 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
3763 BTC_TRACE(trace_buf);
3764 halbtc8822b2ant_action_a2dp_pan_hs(btcoexist);
3765 break;
3766 case BT_8822B_2ANT_COEX_ALGO_PANEDR:
3767 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3768 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
3769 BTC_TRACE(trace_buf);
3770 halbtc8822b2ant_action_pan_edr(btcoexist);
3771 break;
3772 case BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP:
3773 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3774 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
3775 BTC_TRACE(trace_buf);
3776 halbtc8822b2ant_action_pan_edr_a2dp(btcoexist);
3777 break;
3778 case BT_8822B_2ANT_COEX_ALGO_PANEDR_HID:
3779 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3780 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
3781 BTC_TRACE(trace_buf);
3782 halbtc8822b2ant_action_pan_edr_hid(btcoexist);
3783 break;
3784 case BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3785 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3786 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
3787 BTC_TRACE(trace_buf);
3788 halbtc8822b2ant_action_hid_a2dp_pan_edr(
3789 btcoexist);
3790 break;
3791 case BT_8822B_2ANT_COEX_ALGO_HID_A2DP:
3792 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3793 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
3794 BTC_TRACE(trace_buf);
3795 halbtc8822b2ant_action_hid_a2dp(btcoexist);
3796 break;
3797 case BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY:
3798 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3799 "[BTCoex], Action 2-Ant, algorithm = No-Profile busy.\n");
3800 BTC_TRACE(trace_buf);
3801 halbtc8822b2ant_action_bt_idle(btcoexist);
3802 break;
3803 default:
3804 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3805 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3806 BTC_TRACE(trace_buf);
3807 halbtc8822b2ant_action_coex_all_off(btcoexist);
3808 break;
3809 }
3810
3811 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3812
3813 }
3814
3815 static
halbtc8822b2ant_run_coexist_mechanism(IN struct btc_coexist * btcoexist)3816 void halbtc8822b2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
3817 {
3818 u8 algorithm = 0;
3819 u32 num_of_wifi_link = 0;
3820 u32 wifi_link_status = 0;
3821 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3822 boolean miracast_plus_bt = FALSE;
3823 boolean scan = FALSE, link = FALSE, roam = FALSE,
3824 under_4way = FALSE, wifi_connected = FALSE,
3825 wifi_under_5g = FALSE, bt_hs_on = FALSE;
3826
3827 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3828 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3829 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3830 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
3831 &under_4way);
3832
3833 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3834 "[BTCoex], RunCoexistMechanism()===>\n");
3835 BTC_TRACE(trace_buf);
3836
3837 if (btcoexist->manual_control) {
3838 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3839 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3840 BTC_TRACE(trace_buf);
3841 return;
3842 }
3843
3844 if (btcoexist->stop_coex_dm) {
3845 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3846 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3847 BTC_TRACE(trace_buf);
3848 return;
3849 }
3850
3851 if (coex_sta->under_ips) {
3852 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3853 "[BTCoex], wifi is under IPS !!!\n");
3854 BTC_TRACE(trace_buf);
3855 return;
3856 }
3857
3858 if (!coex_sta->run_time_state) {
3859 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3860 "[BTCoex], return for run_time_state = FALSE !!!\n");
3861 BTC_TRACE(trace_buf);
3862 return;
3863 }
3864
3865 if (coex_sta->freeze_coexrun_by_btinfo) {
3866 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3867 "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n");
3868 BTC_TRACE(trace_buf);
3869 return;
3870 }
3871
3872 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3873
3874 if ((wifi_under_5g) &&
3875 (coex_sta->switch_band_notify_to != BTC_SWITCH_TO_24G) &&
3876 (coex_sta->switch_band_notify_to != BTC_SWITCH_TO_24G_NOFORSCAN)) {
3877
3878 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3879 "[BTCoex], WiFi is under 5G!!!\n");
3880 BTC_TRACE(trace_buf);
3881 halbtc8822b2ant_action_wifi_under5g(btcoexist);
3882 return;
3883 } else {
3884
3885 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3886 "[BTCoex], WiFi is under 2G!!!\n");
3887 BTC_TRACE(trace_buf);
3888
3889 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3890 NORMAL_EXEC,
3891 BT_8822B_2ANT_PHASE_2G_RUNTIME);
3892 }
3893
3894 if ((coex_sta->under_lps) && (!coex_sta->force_lps_ctrl) &&
3895 (!coex_sta->acl_busy)) {
3896 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3897 "[BTCoex], RunCoexistMechanism(), wifi is under LPS !!!\n");
3898 BTC_TRACE(trace_buf);
3899 halbtc8822b2ant_action_wifi_native_lps(btcoexist);
3900 return;
3901 }
3902
3903 if (coex_sta->bt_whck_test) {
3904 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3905 "[BTCoex], BT is under WHCK TEST!!!\n");
3906 BTC_TRACE(trace_buf);
3907 halbtc8822b2ant_action_bt_whql_test(btcoexist);
3908 return;
3909 }
3910
3911 if (coex_sta->bt_disabled) {
3912 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3913 "[BTCoex], BT is disabled!!!\n");
3914 BTC_TRACE(trace_buf);
3915 halbtc8822b2ant_action_coex_all_off(btcoexist);
3916 return;
3917 }
3918
3919 if (coex_sta->c2h_bt_inquiry_page) {
3920 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3921 "[BTCoex], BT is under inquiry/page scan !!\n");
3922 BTC_TRACE(trace_buf);
3923 halbtc8822b2ant_action_bt_inquiry(btcoexist);
3924 return;
3925 }
3926
3927 if ((coex_sta->is_setupLink) && (!coex_sta->is_2g_freerun)) {
3928 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3929 "[BTCoex], BT is re-link !!!\n");
3930 BTC_TRACE(trace_buf);
3931 halbtc8822b2ant_action_bt_relink(btcoexist);
3932 return;
3933 }
3934
3935 /* for P2P */
3936 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3937 &wifi_link_status);
3938 num_of_wifi_link = wifi_link_status >> 16;
3939
3940 if ((num_of_wifi_link >= 2) ||
3941 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3942 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3943 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3944 num_of_wifi_link, wifi_link_status);
3945 BTC_TRACE(trace_buf);
3946
3947 if (bt_link_info->bt_link_exist)
3948 miracast_plus_bt = TRUE;
3949 else
3950 miracast_plus_bt = FALSE;
3951
3952 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3953 &miracast_plus_bt);
3954
3955 if (scan || link || roam || under_4way) {
3956 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3957 "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n",
3958 scan, link, roam, under_4way);
3959 BTC_TRACE(trace_buf);
3960
3961 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3962 "[BTCoex], wifi is under linkscan process + Multi-Port !!\n");
3963 BTC_TRACE(trace_buf);
3964
3965 halbtc8822b2ant_action_wifi_link_process(btcoexist);
3966 } else {
3967 halbtc8822b2ant_action_wifi_multi_port(btcoexist);
3968 }
3969
3970 return;
3971 }
3972
3973 miracast_plus_bt = FALSE;
3974 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3975 &miracast_plus_bt);
3976
3977
3978 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3979
3980 if (bt_hs_on) {
3981 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3982 "############# [BTCoex], BT Is hs\n");
3983 BTC_TRACE(trace_buf);
3984 halbtc8822b2ant_action_bt_hs(btcoexist);
3985 return;
3986 }
3987
3988 if ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3989 coex_dm->bt_status) ||
3990 (BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE ==
3991 coex_dm->bt_status)) {
3992
3993 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3994 "[BTCoex], Action 2-Ant, bt idle!!.\n");
3995 BTC_TRACE(trace_buf);
3996
3997 halbtc8822b2ant_action_bt_idle(btcoexist);
3998 return;
3999 }
4000
4001 algorithm = halbtc8822b2ant_action_algorithm(btcoexist);
4002 coex_dm->cur_algorithm = algorithm;
4003 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
4004 coex_dm->cur_algorithm);
4005 BTC_TRACE(trace_buf);
4006
4007 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
4008
4009 if (scan || link || roam || under_4way) {
4010 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4011 "[BTCoex], WiFi is under Link Process !!\n");
4012 BTC_TRACE(trace_buf);
4013 halbtc8822b2ant_action_wifi_link_process(btcoexist);
4014 } else if (wifi_connected) {
4015
4016 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4017 "[BTCoex], Action 2-Ant, wifi connected!!.\n");
4018 BTC_TRACE(trace_buf);
4019 halbtc8822b2ant_action_wifi_connected(btcoexist);
4020
4021 } else {
4022
4023 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4024 "[BTCoex], Action 2-Ant, wifi not-connected!!.\n");
4025 BTC_TRACE(trace_buf);
4026 halbtc8822b2ant_action_wifi_not_connected(btcoexist);
4027 }
4028 }
4029
4030 static
halbtc8822b2ant_init_coex_dm(IN struct btc_coexist * btcoexist)4031 void halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
4032 {
4033 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4034 "[BTCoex], Coex Mechanism Init!!\n");
4035 BTC_TRACE(trace_buf);
4036
4037 halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, FALSE);
4038
4039 coex_sta->pop_event_cnt = 0;
4040 coex_sta->cnt_RemoteNameReq = 0;
4041 coex_sta->cnt_ReInit = 0;
4042 coex_sta->cnt_setupLink = 0;
4043 coex_sta->cnt_IgnWlanAct = 0;
4044 coex_sta->cnt_Page = 0;
4045 coex_sta->cnt_RoleSwitch = 0;
4046 coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
4047
4048 halbtc8822b2ant_query_bt_info(btcoexist);
4049 }
4050
4051
4052 static
halbtc8822b2ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)4053 void halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist,
4054 IN boolean wifi_only)
4055 {
4056 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
4057 u32 RTL97F_8822B = 0;
4058 u8 i = 0;
4059
4060
4061 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
4062 u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4063 u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
4064
4065 if (RTL97F_8822B) {
4066 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, 0x04, 0x0);
4067 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x0);
4068
4069 /* set GNT_BT to SW high */
4070 halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
4071 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
4072 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
4073 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
4074 /* Set GNT_WL to SW high */
4075 halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
4076 BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
4077 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
4078 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
4079 return;
4080 }
4081
4082 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4083 "[BTCoex], (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
4084 u32tmp3, u32tmp1, u32tmp2);
4085 BTC_TRACE(trace_buf);
4086
4087 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4088 "[BTCoex], 2Ant Init HW Config!!\n");
4089 BTC_TRACE(trace_buf);
4090
4091 coex_sta->bt_coex_supported_feature = 0;
4092 coex_sta->bt_coex_supported_version = 0;
4093 coex_sta->bt_ble_scan_type = 0;
4094 coex_sta->bt_ble_scan_para[0] = 0;
4095 coex_sta->bt_ble_scan_para[1] = 0;
4096 coex_sta->bt_ble_scan_para[2] = 0;
4097 coex_sta->bt_reg_vendor_ac = 0xffff;
4098 coex_sta->bt_reg_vendor_ae = 0xffff;
4099 coex_sta->isolation_btween_wb = BT_8822B_2ANT_DEFAULT_ISOLATION;
4100 coex_sta->gnt_error_cnt = 0;
4101 coex_sta->bt_relink_downcount = 0;
4102 coex_sta->is_set_ps_state_fail = FALSE;
4103 coex_sta->cnt_set_ps_state_fail = 0;
4104
4105 for (i = 0; i <= 9; i++)
4106 coex_sta->bt_afh_map[i] = 0;
4107
4108 /* 0xf0[15:12] --> Chip Cut information */
4109 coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
4110 0xf1) & 0xf0) >> 4;
4111
4112 coex_sta->dis_ver_info_cnt = 0;
4113
4114 halbtc8822b2ant_coex_switch_threshold(btcoexist,
4115 coex_sta->isolation_btween_wb);
4116
4117 /* enable TBTT nterrupt */
4118 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, 0x1);
4119
4120 /* BT report packet sample rate */
4121 btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5);
4122
4123 /* Init 0x778 = 0x1 for 2-Ant */
4124 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
4125
4126 /* Enable PTA (3-wire function form BT side) */
4127 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
4128 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
4129
4130 /* Enable PTA (tx/rx signal form WiFi side) */
4131 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
4132
4133 halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, TRUE);
4134
4135 /*GNT_BT=1 while select both */
4136 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
4137
4138
4139 /* Enable counter statistics */ /* 0x76e[3] =1, WLAN_Act control by PTA */
4140 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
4141
4142 halbtc8822b2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 5);
4143
4144 halbtc8822b2ant_ps_tdma(btcoexist, FORCE_EXEC, FALSE, 0);
4145
4146 psd_scan->ant_det_is_ant_det_available = TRUE;
4147
4148 if (coex_sta->is_rf_state_off) {
4149
4150 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4151 FORCE_EXEC,
4152 BT_8822B_2ANT_PHASE_WLAN_OFF);
4153
4154 btcoexist->stop_coex_dm = TRUE;
4155
4156 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4157 "[BTCoex], ********** halbtc8822b2ant_init_hw_config (RF Off)**********\n");
4158 BTC_TRACE(trace_buf);
4159 } else if (wifi_only) {
4160 coex_sta->concurrent_rx_mode_on = FALSE;
4161 /* Path config */
4162 /* Set Antenna Path */
4163 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4164 FORCE_EXEC,
4165 BT_8822B_2ANT_PHASE_WLANONLY_INIT);
4166
4167 btcoexist->stop_coex_dm = TRUE;
4168 } else {
4169 /* Set BT polluted packet on for Tx rate adaptive not including
4170 * Tx retry break by PTA, 0x45c[19] =1
4171 */
4172 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
4173
4174 coex_sta->concurrent_rx_mode_on = TRUE;
4175
4176 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0);
4177
4178 /* Set Antenna Path */
4179 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4180 FORCE_EXEC,
4181 BT_8822B_2ANT_PHASE_COEX_INIT);
4182
4183 btcoexist->stop_coex_dm = FALSE;
4184 }
4185 }
4186
4187
4188
4189 /* ************************************************************
4190 * work around function start with wa_halbtc8822b2ant_
4191 * ************************************************************
4192 * ************************************************************
4193 * extern function start with ex_halbtc8822b2ant_
4194 * ************************************************************ */
ex_halbtc8822b2ant_power_on_setting(IN struct btc_coexist * btcoexist)4195 void ex_halbtc8822b2ant_power_on_setting(IN struct btc_coexist *btcoexist)
4196 {
4197 struct btc_board_info *board_info = &btcoexist->board_info;
4198 u8 u8tmp = 0x0;
4199 u16 u16tmp = 0x0;
4200
4201 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4202 "xxxxxxxxxxxxxxxx Execute 8822b 2-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
4203 BTC_TRACE(trace_buf);
4204
4205 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4206 "Ant Det Finish = %s, Ant Det Number = %d\n",
4207 (board_info->btdm_ant_det_finish ? "Yes" : "No"),
4208 board_info->btdm_ant_num_by_ant_det);
4209 BTC_TRACE(trace_buf);
4210
4211
4212 btcoexist->stop_coex_dm = TRUE;
4213 coex_sta->is_rf_state_off = FALSE;
4214 psd_scan->ant_det_is_ant_det_available = FALSE;
4215
4216 /* enable BB, REG_SYS_FUNC_EN such that we can write BB Reg correctly */
4217 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
4218 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
4219
4220
4221 /* Local setting bit define */
4222 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
4223 /* BIT1: "0" for internal switch; "1" for external switch */
4224 /* BIT2: "0" for one antenna; "1" for two antenna */
4225 /* NOTE: here default all internal switch and 1-antenna ==>
4226 * BIT1=0 and BIT2=0
4227 */
4228
4229 /* Check efuse 0xc3[6] for Single Antenna Path */
4230 #if 0
4231 if (board_info->single_ant_path == 0) {
4232 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4233 "[BTCoex], ********** Single Antenna, Antenna at Aux Port\n");
4234 BTC_TRACE(trace_buf);
4235
4236 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
4237
4238 u8tmp = 7;
4239 } else if (board_info->single_ant_path == 1) {
4240 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4241 "[BTCoex], ********** Single Antenna, Antenna at Main Port\n");
4242 BTC_TRACE(trace_buf);
4243
4244 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
4245
4246 u8tmp = 6;
4247 }
4248
4249 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4250 "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d\n",
4251 board_info->single_ant_path , board_info->btdm_ant_pos);
4252 BTC_TRACE(trace_buf);
4253 #endif
4254
4255 /* Setup RF front end type */
4256 halbtc8822b2ant_set_rfe_type(btcoexist);
4257
4258 /* Set Antenna Path to BT side */
4259 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
4260 BT_8822B_2ANT_PHASE_COEX_POWERON);
4261
4262 /* Save"single antenna position" info in Local register setting for
4263 * FW reading, because FW may not ready at power on
4264 */
4265 if (btcoexist->chip_interface == BTC_INTF_PCI)
4266 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp);
4267 else if (btcoexist->chip_interface == BTC_INTF_USB)
4268 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
4269 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
4270 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
4271
4272 /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
4273 halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, TRUE);
4274
4275 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4276 "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n",
4277 halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38));
4278 BTC_TRACE(trace_buf);
4279
4280 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4281 "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0xcbc (Power-On) = 0x%x / 0x%x\n",
4282 btcoexist->btc_read_4byte(btcoexist, 0x70),
4283 btcoexist->btc_read_4byte(btcoexist, 0xcbc));
4284 BTC_TRACE(trace_buf);
4285
4286 }
4287
ex_halbtc8822b2ant_pre_load_firmware(IN struct btc_coexist * btcoexist)4288 void ex_halbtc8822b2ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
4289 {
4290 struct btc_board_info *board_info = &btcoexist->board_info;
4291 u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
4292
4293 /* */
4294 /* S0 or S1 setting and Local register setting
4295 * (By the setting fw can get ant number, S0/S1, ... info)
4296 */
4297 /* Local setting bit define */
4298 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
4299 /* BIT1: "0" for internal switch; "1" for external switch */
4300 /* BIT2: "0" for one antenna; "1" for two antenna */
4301 /* NOTE: here default all internal switch and 1-antenna ==>
4302 * BIT1=0 and BIT2=0
4303 */
4304 if (btcoexist->chip_interface == BTC_INTF_USB) {
4305 /* fixed at S0 for USB interface */
4306 u8tmp |= 0x1; /* antenna inverse */
4307 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
4308 } else {
4309 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
4310 if (board_info->single_ant_path == 0) {
4311 } else if (board_info->single_ant_path == 1) {
4312 /* set to S0 */
4313 u8tmp |= 0x1; /* antenna inverse */
4314 }
4315
4316 if (btcoexist->chip_interface == BTC_INTF_PCI)
4317 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0,
4318 u8tmp);
4319 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
4320 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
4321 u8tmp);
4322 }
4323 }
4324
ex_halbtc8822b2ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)4325 void ex_halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist,
4326 IN boolean wifi_only)
4327 {
4328 halbtc8822b2ant_init_hw_config(btcoexist, wifi_only);
4329 }
4330
ex_halbtc8822b2ant_init_coex_dm(IN struct btc_coexist * btcoexist)4331 void ex_halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
4332 {
4333
4334 halbtc8822b2ant_init_coex_dm(btcoexist);
4335 }
4336
4337
ex_halbtc8822b2ant_display_simple_coex_info(IN struct btc_coexist * btcoexist)4338 void ex_halbtc8822b2ant_display_simple_coex_info(IN struct btc_coexist *btcoexist)
4339 {
4340 struct btc_board_info *board_info = &btcoexist->board_info;
4341 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
4342
4343 u8 *cli_buf = btcoexist->cli_buf;
4344 u32 bt_patch_ver = 0, bt_coex_ver = 0;
4345 static u8 cnt = 0;
4346
4347 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4348 "\r\n _____[BT Coexist info]____");
4349 CL_PRINTF(cli_buf);
4350
4351 if (btcoexist->manual_control) {
4352 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4353 "\r\n __[Under Manual Control]_");
4354 CL_PRINTF(cli_buf);
4355 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4356 "\r\n _________________________");
4357 CL_PRINTF(cli_buf);
4358 }
4359
4360 if (!coex_sta->bt_disabled) {
4361 if (coex_sta->bt_coex_supported_feature == 0)
4362 btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE,
4363 &coex_sta->bt_coex_supported_feature);
4364
4365 if ((coex_sta->bt_coex_supported_version == 0) ||
4366 (coex_sta->bt_coex_supported_version == 0xffff))
4367 btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION,
4368 &coex_sta->bt_coex_supported_version);
4369
4370 if (coex_sta->bt_reg_vendor_ac == 0xffff)
4371 coex_sta->bt_reg_vendor_ac = (u16)(
4372 btcoexist->btc_get_bt_reg(btcoexist, 3,
4373 0xac) & 0xffff);
4374
4375 if (coex_sta->bt_reg_vendor_ae == 0xffff)
4376 coex_sta->bt_reg_vendor_ae = (u16)(
4377 btcoexist->btc_get_bt_reg(btcoexist, 3,
4378 0xae) & 0xffff);
4379
4380 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
4381 &bt_patch_ver);
4382 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
4383
4384 if (coex_sta->num_of_profile > 0) {
4385 cnt++;
4386
4387 if (cnt >= 3) {
4388 btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0,
4389 &coex_sta->bt_afh_map[0]);
4390 cnt = 0;
4391 }
4392 }
4393 }
4394
4395 // BT coex. info.
4396 if (psd_scan->ant_det_try_count == 0) {
4397 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4398 "\r\n %-35s = %d/ %d/ %s / %d",
4399 "Ant PG Num/ Mech/ Pos/ RFE",
4400 board_info->pg_ant_num, board_info->btdm_ant_num,
4401 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4402 ? "Main" : "Aux"),
4403 rfe_type->rfe_module_type);
4404 CL_PRINTF(cli_buf);
4405 } else {
4406 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4407 "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)",
4408 "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4409 board_info->pg_ant_num,
4410 board_info->btdm_ant_num_by_ant_det,
4411 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4412 ? "Main" : "Aux"),
4413 rfe_type->rfe_module_type,
4414 psd_scan->ant_det_try_count,
4415 psd_scan->ant_det_fail_count,
4416 psd_scan->ant_det_result);
4417 CL_PRINTF(cli_buf);
4418
4419
4420 if (board_info->btdm_ant_det_finish) {
4421
4422 if (psd_scan->ant_det_result != 12)
4423 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4424 "\r\n %-35s = %s",
4425 "Ant Det PSD Value",
4426 psd_scan->ant_det_peak_val);
4427 else
4428 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4429 "\r\n %-35s = %d",
4430 "Ant Det PSD Value",
4431 psd_scan->ant_det_psd_scan_peak_val
4432 / 100);
4433 CL_PRINTF(cli_buf);
4434 }
4435 }
4436
4437 bt_coex_ver = (coex_sta->bt_coex_supported_version & 0xff);
4438
4439 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4440 "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4441 "CoexVer WL/ BT_Desired/ BT_Report",
4442 glcoex_ver_date_8822b_2ant, glcoex_ver_8822b_2ant,
4443 glcoex_ver_btdesired_8822b_2ant,
4444 bt_coex_ver,
4445 (bt_coex_ver == 0xff ? "Unknown" :
4446 (coex_sta->bt_disabled ? "BT-disable" :
4447 (bt_coex_ver >= glcoex_ver_btdesired_8822b_2ant ?
4448 "Match" : "Mis-Match"))));
4449 CL_PRINTF(cli_buf);
4450
4451 // BT status
4452 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4453 "\r\n %-35s = %s",
4454 "BT status",
4455 ((coex_sta->bt_disabled) ? ("disabled") : ((
4456 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
4457 : ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4458 coex_dm->bt_status) ? "non-connected idle" :
4459 ((coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE)
4460 ? "connected-idle" : "busy")))));
4461 CL_PRINTF(cli_buf);
4462
4463 // HW Settings
4464 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4465 "0x770(Hi-pri rx/tx)",
4466 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4467 CL_PRINTF(cli_buf);
4468
4469 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
4470 "0x774(Lo-pri rx/tx)",
4471 coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4472 (bt_link_info->slave_role ? "(Slave!!)" : (
4473 coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : "")));
4474 CL_PRINTF(cli_buf);
4475
4476 }
4477
4478
ex_halbtc8822b2ant_display_coex_info(IN struct btc_coexist * btcoexist)4479 void ex_halbtc8822b2ant_display_coex_info(IN struct btc_coexist *btcoexist)
4480 {
4481 struct btc_board_info *board_info = &btcoexist->board_info;
4482 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
4483
4484 u8 *cli_buf = btcoexist->cli_buf;
4485 u8 u8tmp[4], i, ps_tdma_case = 0;
4486 u32 u32tmp[4];
4487 u16 u16tmp[4];
4488 u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck, ratio_ofdm;
4489 u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
4490 static u8 pop_report_in_10s = 0;
4491 u32 phyver = 0;
4492 boolean lte_coex_on = FALSE;
4493 static u8 cnt = 0;
4494
4495 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4496 "\r\n ============[BT Coexist info]============");
4497 CL_PRINTF(cli_buf);
4498
4499 if (btcoexist->manual_control) {
4500 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4501 "\r\n ============[Under Manual Control]============");
4502 CL_PRINTF(cli_buf);
4503 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4504 "\r\n ==========================================");
4505 CL_PRINTF(cli_buf);
4506 }
4507
4508 if (!coex_sta->bt_disabled) {
4509 if (coex_sta->bt_coex_supported_feature == 0)
4510 btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE,
4511 &coex_sta->bt_coex_supported_feature);
4512
4513 if ((coex_sta->bt_coex_supported_version == 0) ||
4514 (coex_sta->bt_coex_supported_version == 0xffff))
4515 btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION,
4516 &coex_sta->bt_coex_supported_version);
4517
4518 if (coex_sta->bt_reg_vendor_ac == 0xffff)
4519 coex_sta->bt_reg_vendor_ac = (u16)(
4520 btcoexist->btc_get_bt_reg(btcoexist, 3,
4521 0xac) & 0xffff);
4522
4523 if (coex_sta->bt_reg_vendor_ae == 0xffff)
4524 coex_sta->bt_reg_vendor_ae = (u16)(
4525 btcoexist->btc_get_bt_reg(btcoexist, 3,
4526 0xae) & 0xffff);
4527
4528 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
4529 &bt_patch_ver);
4530 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
4531
4532 if (coex_sta->num_of_profile > 0) {
4533 cnt++;
4534
4535 if (cnt >= 3) {
4536 btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0,
4537 &coex_sta->bt_afh_map[0]);
4538 cnt = 0;
4539 }
4540 }
4541 }
4542
4543 if (psd_scan->ant_det_try_count == 0) {
4544 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4545 "\r\n %-35s = %d/ %d/ %s / %d",
4546 "Ant PG Num/ Mech/ Pos/ RFE",
4547 board_info->pg_ant_num, board_info->btdm_ant_num,
4548 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4549 ? "Main" : "Aux"),
4550 rfe_type->rfe_module_type);
4551 CL_PRINTF(cli_buf);
4552 } else {
4553 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4554 "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)",
4555 "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4556 board_info->pg_ant_num,
4557 board_info->btdm_ant_num_by_ant_det,
4558 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4559 ? "Main" : "Aux"),
4560 rfe_type->rfe_module_type,
4561 psd_scan->ant_det_try_count,
4562 psd_scan->ant_det_fail_count,
4563 psd_scan->ant_det_result);
4564 CL_PRINTF(cli_buf);
4565
4566
4567 if (board_info->btdm_ant_det_finish) {
4568
4569 if (psd_scan->ant_det_result != 12)
4570 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4571 "\r\n %-35s = %s",
4572 "Ant Det PSD Value",
4573 psd_scan->ant_det_peak_val);
4574 else
4575 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4576 "\r\n %-35s = %d",
4577 "Ant Det PSD Value",
4578 psd_scan->ant_det_psd_scan_peak_val
4579 / 100);
4580 CL_PRINTF(cli_buf);
4581 }
4582 }
4583
4584
4585 bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
4586 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4587 phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
4588
4589 bt_coex_ver = (coex_sta->bt_coex_supported_version & 0xff);
4590
4591 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4592 "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4593 "CoexVer WL/ BT_Desired/ BT_Report",
4594 glcoex_ver_date_8822b_2ant, glcoex_ver_8822b_2ant,
4595 glcoex_ver_btdesired_8822b_2ant,
4596 bt_coex_ver,
4597 (bt_coex_ver == 0xff ? "Unknown" :
4598 (coex_sta->bt_disabled ? "BT-disable" :
4599 (bt_coex_ver >= glcoex_ver_btdesired_8822b_2ant ?
4600 "Match" : "Mis-Match"))));
4601 CL_PRINTF(cli_buf);
4602
4603 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4604 "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
4605 "W_FW/ B_FW/ Phy/ Kt",
4606 fw_ver, bt_patch_ver, phyver,
4607 coex_sta->cut_version + 65);
4608 CL_PRINTF(cli_buf);
4609
4610 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x (RF-Ch = %d)",
4611 "AFH Map to BT",
4612 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4613 coex_dm->wifi_chnl_info[2], coex_sta->wl_center_channel);
4614 CL_PRINTF(cli_buf);
4615
4616 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d ",
4617 "Isolation/WL_Thres/BT_Thres",
4618 coex_sta->isolation_btween_wb,
4619 coex_sta->wifi_coex_thres,
4620 coex_sta->bt_coex_thres);
4621 CL_PRINTF(cli_buf);
4622
4623 /* wifi status */
4624 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4625 "============[Wifi Status]============");
4626 CL_PRINTF(cli_buf);
4627 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
4628
4629 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4630 "============[BT Status]============");
4631 CL_PRINTF(cli_buf);
4632
4633 pop_report_in_10s++;
4634 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4635 "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ",
4636 "BT [status/ rssi/ retryCnt/ popCnt]",
4637 ((coex_sta->bt_disabled) ? ("disabled") : ((
4638 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
4639 : ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4640 coex_dm->bt_status) ? "non-connected idle" :
4641 ((coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE)
4642 ? "connected-idle" : "busy")))),
4643 coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
4644 coex_sta->pop_event_cnt);
4645 CL_PRINTF(cli_buf);
4646
4647 if (pop_report_in_10s >= 5) {
4648 coex_sta->pop_event_cnt = 0;
4649 pop_report_in_10s = 0;
4650 }
4651
4652
4653 if (coex_sta->num_of_profile != 0)
4654 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4655 "\r\n %-35s = %s%s%s%s%s",
4656 "Profiles",
4657 ((bt_link_info->a2dp_exist) ?
4658 ((coex_sta->is_bt_a2dp_sink) ? "A2DP sink," :
4659 "A2DP,") : ""),
4660 ((bt_link_info->sco_exist) ? "HFP," : ""),
4661 ((bt_link_info->hid_exist) ?
4662 ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," :
4663 "HID(2/18),") : ""),
4664 ((bt_link_info->pan_exist) ? "PAN," : ""),
4665 ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
4666 else
4667 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4668 "\r\n %-35s = None", "Profiles");
4669
4670 CL_PRINTF(cli_buf);
4671
4672
4673 if (bt_link_info->a2dp_exist) {
4674 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s",
4675 "A2DP Rate/Bitpool/Auto_Slot",
4676 ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
4677 coex_sta->a2dp_bit_pool,
4678 ((coex_sta->is_autoslot) ? "On" : "Off")
4679 );
4680 CL_PRINTF(cli_buf);
4681 }
4682
4683 if (bt_link_info->hid_exist) {
4684 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4685 "HID PairNum/Forbid_Slot",
4686 coex_sta->hid_pair_cnt,
4687 coex_sta->forbidden_slot
4688 );
4689 CL_PRINTF(cli_buf);
4690 }
4691
4692 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s/ 0x%x",
4693 "Role/RoleSwCnt/IgnWlact/Feature",
4694 ((bt_link_info->slave_role) ? "Slave" : "Master"),
4695 coex_sta->cnt_RoleSwitch,
4696 ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"),
4697 coex_sta->bt_coex_supported_feature);
4698 CL_PRINTF(cli_buf);
4699
4700 if ((coex_sta->bt_ble_scan_type & 0x7) != 0x0) {
4701 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4702 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4703 "BLEScan Type/TV/Init/Ble",
4704 coex_sta->bt_ble_scan_type,
4705 (coex_sta->bt_ble_scan_type & 0x1 ?
4706 coex_sta->bt_ble_scan_para[0] : 0x0),
4707 (coex_sta->bt_ble_scan_type & 0x2 ?
4708 coex_sta->bt_ble_scan_para[1] : 0x0),
4709 (coex_sta->bt_ble_scan_type & 0x4 ?
4710 coex_sta->bt_ble_scan_para[2] : 0x0));
4711 CL_PRINTF(cli_buf);
4712 }
4713
4714 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4715 "ReInit/ReLink/IgnWlact/Page/NameReq",
4716 coex_sta->cnt_ReInit,
4717 coex_sta->cnt_setupLink,
4718 coex_sta->cnt_IgnWlanAct,
4719 coex_sta->cnt_Page,
4720 coex_sta->cnt_RemoteNameReq
4721 );
4722 CL_PRINTF(cli_buf);
4723
4724 halbtc8822b2ant_read_score_board(btcoexist, &u16tmp[0]);
4725
4726 if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
4727 (coex_sta->bt_reg_vendor_ac == 0xffff))
4728 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x",
4729 "0xae[4]/0xac[1:0]/Scoreboard(B->W)", u16tmp[0]);
4730 else
4731 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4732 "\r\n %-35s = 0x%x/ 0x%x/ %04x",
4733 "0xae[4]/0xac[1:0]/Scoreboard",
4734 (int)((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
4735 coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
4736 CL_PRINTF(cli_buf);
4737
4738 if (coex_sta->num_of_profile > 0) {
4739 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4740 "\r\n %-35s = %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x",
4741 "AFH MAP",
4742 coex_sta->bt_afh_map[0],
4743 coex_sta->bt_afh_map[1],
4744 coex_sta->bt_afh_map[2],
4745 coex_sta->bt_afh_map[3],
4746 coex_sta->bt_afh_map[4],
4747 coex_sta->bt_afh_map[5],
4748 coex_sta->bt_afh_map[6],
4749 coex_sta->bt_afh_map[7],
4750 coex_sta->bt_afh_map[8],
4751 coex_sta->bt_afh_map[9]
4752 );
4753 CL_PRINTF(cli_buf);
4754 }
4755
4756 for (i = 0; i < BT_INFO_SRC_8822B_2ANT_MAX; i++) {
4757 if (coex_sta->bt_info_c2h_cnt[i]) {
4758 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4759 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
4760 glbt_info_src_8822b_2ant[i],
4761 coex_sta->bt_info_c2h[i][0],
4762 coex_sta->bt_info_c2h[i][1],
4763 coex_sta->bt_info_c2h[i][2],
4764 coex_sta->bt_info_c2h[i][3],
4765 coex_sta->bt_info_c2h[i][4],
4766 coex_sta->bt_info_c2h[i][5],
4767 coex_sta->bt_info_c2h[i][6],
4768 coex_sta->bt_info_c2h_cnt[i]);
4769 CL_PRINTF(cli_buf);
4770 }
4771 }
4772
4773 /* Sw mechanism */
4774 if (btcoexist->manual_control)
4775 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4776 "============[mechanism] (before Manual)============");
4777 else
4778 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4779 "============[Mechanism]============");
4780
4781 CL_PRINTF(cli_buf);
4782
4783
4784 ps_tdma_case = coex_dm->cur_ps_tdma;
4785
4786 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4787 "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, %s)",
4788 "TDMA",
4789 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4790 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4791 coex_dm->ps_tdma_para[4], ps_tdma_case,
4792 (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"),
4793 (coex_dm->is_switch_to_1dot5_ant ? "1.5Ant" : "2Ant"));
4794 CL_PRINTF(cli_buf);
4795
4796 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4797 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4798 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4799 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4800 "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
4801 "Table/0x6c0/0x6c4/0x6c8",
4802 coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]);
4803 CL_PRINTF(cli_buf);
4804
4805 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4806 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
4807 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4808 "\r\n %-35s = 0x%x/ 0x%x/ %04x",
4809 "0x778/0x6cc/Scoreboard(W->B)",
4810 u8tmp[0], u32tmp[0], coex_sta->score_board_WB);
4811 CL_PRINTF(cli_buf);
4812
4813 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d",
4814 "AntDiv/BtCtrlLPS/LPRA/PsFail",
4815 ((board_info->ant_div_cfg) ? "On" : "Off"),
4816 ((coex_sta->force_lps_ctrl) ? "On" : "Off"),
4817 ((coex_dm->cur_low_penalty_ra) ? "On" : "Off"),
4818 coex_sta->cnt_set_ps_state_fail);
4819 CL_PRINTF(cli_buf);
4820
4821 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4822 "Null All/Retry/Ack/BT_Empty/BT_Late",
4823 coex_sta->wl_fw_dbg_info[1],
4824 coex_sta->wl_fw_dbg_info[2],
4825 coex_sta->wl_fw_dbg_info[3],
4826 coex_sta->wl_fw_dbg_info[4],
4827 coex_sta->wl_fw_dbg_info[5]);
4828 CL_PRINTF(cli_buf);
4829
4830 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4831 "WL_DACSwing/ BT_Dec_Pwr", coex_dm->cur_fw_dac_swing_lvl,
4832 coex_dm->cur_bt_dec_pwr_lvl);
4833 CL_PRINTF(cli_buf);
4834
4835 u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4836 lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? TRUE : FALSE;
4837
4838 if (lte_coex_on) {
4839
4840 u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4841 0xa0);
4842 u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4843 0xa4);
4844 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4845 "LTE Coex Table W_L/B_L",
4846 u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
4847 CL_PRINTF(cli_buf);
4848
4849
4850 u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4851 0xa8);
4852 u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4853 0xac);
4854 u32tmp[2] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4855 0xb0);
4856 u32tmp[3] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4857 0xb4);
4858 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4859 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4860 "LTE Break Table W_L/B_L/L_W/L_B",
4861 u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
4862 u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
4863 CL_PRINTF(cli_buf);
4864
4865 }
4866
4867 /* Hw setting */
4868 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4869 "============[Hw setting]============");
4870 CL_PRINTF(cli_buf);
4871
4872 u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4873 u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
4874 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
4875
4876 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s",
4877 "LTE Coex/Path Owner",
4878 ((lte_coex_on) ? "On" : "Off"),
4879 ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
4880 CL_PRINTF(cli_buf);
4881
4882 if (lte_coex_on) {
4883 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4884 "\r\n %-35s = %d/ %d/ %d/ %d",
4885 "LTE 3Wire/OPMode/UART/UARTMode",
4886 (int)((u32tmp[0] & BIT(6)) >> 6),
4887 (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
4888 (int)((u32tmp[0] & BIT(3)) >> 3),
4889 (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
4890 CL_PRINTF(cli_buf);
4891
4892 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4893 "LTE_Busy/UART_Busy",
4894 (int)((u32tmp[1] & BIT(1)) >> 1),
4895 (int)(u32tmp[1] & BIT(0)));
4896 CL_PRINTF(cli_buf);
4897 }
4898 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4899 "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d",
4900 "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
4901 ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
4902 ((u32tmp[0] & BIT(8)) ? "SW" : "HW"),
4903 ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
4904 ((u32tmp[0] & BIT(10)) ? "SW" : "HW"),
4905 ((u8tmp[0] & BIT(3)) ? "On" : "Off"),
4906 coex_sta->gnt_error_cnt);
4907 CL_PRINTF(cli_buf);
4908
4909 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4910 "GNT_WL/GNT_BT",
4911 (int)((u32tmp[1] & BIT(2)) >> 2),
4912 (int)((u32tmp[1] & BIT(3)) >> 3));
4913 CL_PRINTF(cli_buf);
4914
4915
4916 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
4917 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
4918 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba);
4919 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcbd);
4920 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc58);
4921
4922 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4923 "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x/ 0x%02x 0x%02x %s",
4924 "0xcb0/0xcb4/0xcb8[23:16]/0xcbd/0xc58",
4925 u32tmp[0], u32tmp[1], u8tmp[0], u8tmp[1], u8tmp[2],
4926 ((u8tmp[1] & 0x1) == 0x1 ? "(BT_WL5G)" : "(WL2G)"));
4927 CL_PRINTF(cli_buf);
4928
4929 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4930 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
4931 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
4932 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4933
4934 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4935 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4936 "4c[24:23]/64[0]/4c6[4]/40[5]",
4937 (int)(u32tmp[0] & (BIT(24) | BIT(23))) >> 23, u8tmp[2] & 0x1,
4938 (int)((u8tmp[0] & BIT(4)) >> 4),
4939 (int)((u8tmp[1] & BIT(5)) >> 5));
4940 CL_PRINTF(cli_buf);
4941
4942 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4943 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4944 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
4945 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
4946
4947 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4948 "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
4949 "0x550/0x522/4-RxAGC/0xc50",
4950 u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
4951 CL_PRINTF(cli_buf);
4952
4953 fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4954 PHYDM_INFO_FA_OFDM);
4955 fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4956 PHYDM_INFO_FA_CCK);
4957 cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4958 PHYDM_INFO_CCA_OFDM);
4959 cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4960 PHYDM_INFO_CCA_CCK);
4961
4962 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4963 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4964 "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
4965 cca_cck, fa_cck, cca_ofdm, fa_ofdm);
4966 CL_PRINTF(cli_buf);
4967
4968 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d (Rx_rate Data/RTS= %d/%d)",
4969 "CRC_OK CCK/11g/11n/11ac",
4970 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
4971 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht,
4972 coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate);
4973 CL_PRINTF(cli_buf);
4974
4975 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
4976 "CRC_Err CCK/11g/11n/11ac",
4977 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
4978 coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
4979 CL_PRINTF(cli_buf);
4980
4981 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %s/ %d",
4982 "HiPr/ Locking/ warn/ Locked/ Noisy",
4983 (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
4984 (coex_sta->cck_lock ? "Yes" : "No"),
4985 (coex_sta->cck_lock_warn ? "Yes" : "No"),
4986 (coex_sta->cck_lock_ever ? "Yes" : "No"),
4987 coex_sta->wl_noisy_level);
4988 CL_PRINTF(cli_buf);
4989
4990 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4991 "0x770(Hi-pri rx/tx)",
4992 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4993 CL_PRINTF(cli_buf);
4994
4995 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
4996 "0x774(Lo-pri rx/tx)",
4997 coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4998 (bt_link_info->slave_role ? "(Slave!!)" : (
4999 coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : "")));
5000 CL_PRINTF(cli_buf);
5001
5002 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
5003 }
5004
5005
ex_halbtc8822b2ant_ips_notify(IN struct btc_coexist * btcoexist,IN u8 type)5006 void ex_halbtc8822b2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
5007 {
5008 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
5009 return;
5010
5011 if (BTC_IPS_ENTER == type) {
5012 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5013 "[BTCoex], IPS ENTER notify\n");
5014 BTC_TRACE(trace_buf);
5015 coex_sta->under_ips = TRUE;
5016 coex_sta->under_lps = FALSE;
5017
5018 halbtc8822b2ant_post_state_to_bt(btcoexist,
5019 BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5020 BT_8822B_2ANT_SCOREBOARD_ONOFF |
5021 BT_8822B_2ANT_SCOREBOARD_SCAN |
5022 BT_8822B_2ANT_SCOREBOARD_UNDERTEST |
5023 BT_8822B_2ANT_SCOREBOARD_RXGAIN,
5024 FALSE);
5025
5026 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5027 FORCE_EXEC,
5028 BT_8822B_2ANT_PHASE_WLAN_OFF);
5029
5030 halbtc8822b2ant_action_coex_all_off(btcoexist);
5031 } else if (BTC_IPS_LEAVE == type) {
5032 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5033 "[BTCoex], IPS LEAVE notify\n");
5034 BTC_TRACE(trace_buf);
5035 coex_sta->under_ips = FALSE;
5036
5037 halbtc8822b2ant_init_hw_config(btcoexist, FALSE);
5038 halbtc8822b2ant_init_coex_dm(btcoexist);
5039 halbtc8822b2ant_query_bt_info(btcoexist);
5040 }
5041 }
5042
5043
5044
ex_halbtc8822b2ant_lps_notify(IN struct btc_coexist * btcoexist,IN u8 type)5045 void ex_halbtc8822b2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
5046 {
5047 static boolean pre_force_lps_on = FALSE;
5048
5049 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
5050 return;
5051
5052 if (BTC_LPS_ENABLE == type) {
5053 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5054 "[BTCoex], LPS ENABLE notify\n");
5055 BTC_TRACE(trace_buf);
5056 coex_sta->under_lps = TRUE;
5057 coex_sta->under_ips = FALSE;
5058
5059 if (coex_sta->force_lps_ctrl) { /* LPS No-32K */
5060 /* Write WL "Active" in Score-board for PS-TDMA */
5061 pre_force_lps_on = TRUE;
5062 halbtc8822b2ant_post_state_to_bt(btcoexist,
5063 BT_8822B_2ANT_SCOREBOARD_ACTIVE, TRUE);
5064
5065 } else {
5066 /* Write WL "Non-Active" in Score-board for Native-PS */
5067 pre_force_lps_on = FALSE;
5068 halbtc8822b2ant_post_state_to_bt(btcoexist,
5069 BT_8822B_2ANT_SCOREBOARD_ACTIVE, FALSE);
5070 halbtc8822b2ant_action_wifi_native_lps(btcoexist);
5071 }
5072
5073 } else if (BTC_LPS_DISABLE == type) {
5074 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5075 "[BTCoex], LPS DISABLE notify\n");
5076 BTC_TRACE(trace_buf);
5077 coex_sta->under_lps = FALSE;
5078
5079 halbtc8822b2ant_post_state_to_bt(btcoexist,
5080 BT_8822B_2ANT_SCOREBOARD_ACTIVE, TRUE);
5081
5082 if ((!pre_force_lps_on) && (!coex_sta->force_lps_ctrl))
5083 halbtc8822b2ant_query_bt_info(btcoexist);
5084 }
5085 }
5086
ex_halbtc8822b2ant_scan_notify(IN struct btc_coexist * btcoexist,IN u8 type)5087 void ex_halbtc8822b2ant_scan_notify(IN struct btc_coexist *btcoexist,
5088 IN u8 type)
5089 {
5090 boolean wifi_connected = FALSE;
5091 boolean wifi_under_5g = FALSE;
5092
5093
5094 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5095 "[BTCoex], SCAN notify()\n");
5096 BTC_TRACE(trace_buf);
5097
5098 if (btcoexist->manual_control ||
5099 btcoexist->stop_coex_dm)
5100 return;
5101
5102 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
5103
5104 /* this can't be removed for RF off_on event, or BT would dis-connect */
5105 if ((type == BTC_SCAN_START) || (type == BTC_SCAN_START_2G)) {
5106
5107 halbtc8822b2ant_post_state_to_bt(btcoexist,
5108 BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5109 BT_8822B_2ANT_SCOREBOARD_SCAN |
5110 BT_8822B_2ANT_SCOREBOARD_ONOFF,
5111 TRUE);
5112
5113 halbtc8822b2ant_query_bt_info(btcoexist);
5114 }
5115
5116 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5117
5118 if ((type == BTC_SCAN_START) && (wifi_under_5g)) {
5119
5120 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5121 "[BTCoex], SCAN START notify (5G)\n");
5122 BTC_TRACE(trace_buf);
5123
5124 halbtc8822b2ant_action_wifi_under5g(btcoexist);
5125 } else if ((type == BTC_SCAN_START_2G) || (type == BTC_SCAN_START)) {
5126
5127 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5128 "[BTCoex], SCAN START notify (2G)\n");
5129 BTC_TRACE(trace_buf);
5130
5131 if (!wifi_connected)
5132 coex_sta->wifi_is_high_pri_task = TRUE;
5133
5134 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5135 FORCE_EXEC,
5136 BT_8822B_2ANT_PHASE_2G_RUNTIME);
5137
5138 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5139
5140 } else if (BTC_SCAN_FINISH == type) {
5141
5142 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
5143 &coex_sta->scan_ap_num);
5144
5145 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5146 "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n",
5147 coex_sta->scan_ap_num);
5148 BTC_TRACE(trace_buf);
5149
5150 coex_sta->wifi_is_high_pri_task = FALSE;
5151
5152 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5153 }
5154
5155 }
5156
5157
ex_halbtc8822b2ant_switchband_notify(IN struct btc_coexist * btcoexist,IN u8 type)5158 void ex_halbtc8822b2ant_switchband_notify(IN struct btc_coexist *btcoexist,
5159 IN u8 type)
5160 {
5161 if (btcoexist->manual_control ||
5162 btcoexist->stop_coex_dm)
5163 return;
5164 coex_sta->switch_band_notify_to = type;
5165
5166 if (type == BTC_SWITCH_TO_5G) {
5167
5168 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5169 "[BTCoex], switchband_notify --- switch to 5G\n");
5170 BTC_TRACE(trace_buf);
5171
5172 halbtc8822b2ant_action_wifi_under5g(btcoexist);
5173
5174 } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
5175 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5176 "[BTCoex], ********** switchband_notify --- BTC_SWITCH_TO_2G (no for scan)\n");
5177 BTC_TRACE(trace_buf);
5178
5179 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5180
5181 } else {
5182
5183 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5184 "[BTCoex], switchband_notify --- switch to 2G\n");
5185 BTC_TRACE(trace_buf);
5186
5187 ex_halbtc8822b2ant_scan_notify(btcoexist,
5188 BTC_SCAN_START_2G);
5189 }
5190 coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
5191 }
5192
5193
ex_halbtc8822b2ant_connect_notify(IN struct btc_coexist * btcoexist,IN u8 type)5194 void ex_halbtc8822b2ant_connect_notify(IN struct btc_coexist *btcoexist,
5195 IN u8 type)
5196 {
5197
5198 if (btcoexist->manual_control ||
5199 btcoexist->stop_coex_dm)
5200 return;
5201
5202 halbtc8822b2ant_post_state_to_bt(btcoexist,
5203 BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5204 BT_8822B_2ANT_SCOREBOARD_SCAN |
5205 BT_8822B_2ANT_SCOREBOARD_ONOFF,
5206 TRUE);
5207
5208 if ((BTC_ASSOCIATE_5G_START == type) ||
5209 (BTC_ASSOCIATE_5G_FINISH == type)) {
5210
5211 if (BTC_ASSOCIATE_5G_START == type)
5212 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5213 "[BTCoex], connect_notify --- 5G start\n");
5214 else
5215 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5216 "[BTCoex], connect_notify --- 5G finish\n");
5217
5218 BTC_TRACE(trace_buf);
5219
5220 halbtc8822b2ant_action_wifi_under5g(btcoexist);
5221 } else if (type == BTC_ASSOCIATE_START) {
5222
5223 coex_sta->wifi_is_high_pri_task = TRUE;
5224
5225 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5226 "[BTCoex], CONNECT START notify (2G)\n");
5227 BTC_TRACE(trace_buf);
5228
5229 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5230 FORCE_EXEC,
5231 BT_8822B_2ANT_PHASE_2G_RUNTIME);
5232
5233 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5234
5235 /* To keep TDMA case during connect process,
5236 * to avoid changed by Btinfo and runcoexmechanism
5237 */
5238 coex_sta->freeze_coexrun_by_btinfo = TRUE;
5239
5240 coex_dm->arp_cnt = 0;
5241
5242 } else if (BTC_ASSOCIATE_FINISH == type) {
5243
5244 coex_sta->wifi_is_high_pri_task = FALSE;
5245 coex_sta->freeze_coexrun_by_btinfo = FALSE;
5246
5247 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5248 "[BTCoex], CONNECT FINISH notify (2G)\n");
5249 BTC_TRACE(trace_buf);
5250
5251 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5252 }
5253 }
5254
ex_halbtc8822b2ant_media_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)5255 void ex_halbtc8822b2ant_media_status_notify(IN struct btc_coexist *btcoexist,
5256 IN u8 type)
5257 {
5258 boolean wifi_under_b_mode = FALSE, wifi_under_5g = FALSE;
5259
5260
5261 if (btcoexist->manual_control ||
5262 btcoexist->stop_coex_dm)
5263 return;
5264
5265 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5266
5267 if (BTC_MEDIA_CONNECT == type) {
5268
5269 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5270 "[BTCoex], MEDIA connect notify\n");
5271 BTC_TRACE(trace_buf);
5272
5273 halbtc8822b2ant_post_state_to_bt(btcoexist,
5274 BT_8822B_2ANT_SCOREBOARD_ACTIVE, TRUE);
5275
5276 if (wifi_under_5g) {
5277
5278 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5279 "[BTCoex], WiFi is under 5G!!!\n");
5280 BTC_TRACE(trace_buf);
5281
5282 halbtc8822b2ant_action_wifi_under5g(btcoexist);
5283 } else {
5284
5285 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5286 FORCE_EXEC,
5287 BT_8822B_2ANT_PHASE_2G_RUNTIME);
5288
5289 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
5290 &wifi_under_b_mode);
5291
5292 /* Set CCK Tx/Rx high Pri except 11b mode */
5293 if (wifi_under_b_mode) {
5294 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x00); /* CCK Tx */
5295 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x00); /* CCK Rx */
5296 } else {
5297
5298 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x00); /* CCK Tx */
5299 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); /* CCK Rx */
5300 }
5301 }
5302 } else {
5303 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5304 "[BTCoex], MEDIA disconnect notify\n");
5305 BTC_TRACE(trace_buf);
5306
5307 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
5308 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
5309
5310 halbtc8822b2ant_post_state_to_bt(btcoexist,
5311 BT_8822B_2ANT_SCOREBOARD_ACTIVE, FALSE);
5312
5313 coex_sta->cck_lock_ever = FALSE;
5314 coex_sta->cck_lock_warn = FALSE;
5315 coex_sta->cck_lock = FALSE;
5316 }
5317
5318
5319 halbtc8822b2ant_update_wifi_channel_info(btcoexist, type);
5320 }
5321
ex_halbtc8822b2ant_specific_packet_notify(IN struct btc_coexist * btcoexist,IN u8 type)5322 void ex_halbtc8822b2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
5323 IN u8 type)
5324 {
5325 boolean under_4way = FALSE, wifi_under_5g = FALSE;
5326
5327 if (btcoexist->manual_control ||
5328 btcoexist->stop_coex_dm)
5329 return;
5330
5331 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5332
5333 if (wifi_under_5g) {
5334
5335 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5336 "[BTCoex], WiFi is under 5G!!!\n");
5337 BTC_TRACE(trace_buf);
5338
5339 halbtc8822b2ant_action_wifi_under5g(btcoexist);
5340 return;
5341 }
5342
5343 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
5344 &under_4way);
5345
5346 if (under_4way) {
5347
5348 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5349 "[BTCoex], specific Packet ---- under_4way!!\n");
5350 BTC_TRACE(trace_buf);
5351
5352 coex_sta->wifi_is_high_pri_task = TRUE;
5353 coex_sta->specific_pkt_period_cnt = 2;
5354
5355 } else if (BTC_PACKET_ARP == type) {
5356
5357 coex_dm->arp_cnt++;
5358 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5359 "[BTCoex], specific Packet ARP notify -cnt = %d\n",
5360 coex_dm->arp_cnt);
5361 BTC_TRACE(trace_buf);
5362
5363 } else {
5364
5365 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5366 "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
5367 type);
5368 BTC_TRACE(trace_buf);
5369
5370 coex_sta->wifi_is_high_pri_task = TRUE;
5371 coex_sta->specific_pkt_period_cnt = 2;
5372 }
5373
5374 if (coex_sta->wifi_is_high_pri_task) {
5375 halbtc8822b2ant_post_state_to_bt(btcoexist,
5376 BT_8822B_2ANT_SCOREBOARD_SCAN, TRUE);
5377 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5378 }
5379
5380 }
5381
5382
ex_halbtc8822b2ant_bt_info_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)5383 void ex_halbtc8822b2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
5384 IN u8 *tmp_buf, IN u8 length)
5385 {
5386 u8 i, rsp_source = 0;
5387 boolean wifi_connected = FALSE;
5388 boolean wifi_scan = FALSE, wifi_link = FALSE, wifi_roam = FALSE,
5389 wifi_busy = FALSE;
5390 static boolean is_scoreboard_scan = FALSE;
5391
5392
5393 rsp_source = tmp_buf[0] & 0xf;
5394 if (rsp_source >= BT_INFO_SRC_8822B_2ANT_MAX)
5395 rsp_source = BT_INFO_SRC_8822B_2ANT_WIFI_FW;
5396 coex_sta->bt_info_c2h_cnt[rsp_source]++;
5397
5398 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5399 "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source,
5400 length);
5401 BTC_TRACE(trace_buf);
5402
5403 for (i = 0; i < length; i++) {
5404 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
5405
5406 if (i == length - 1) {
5407 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
5408 tmp_buf[i]);
5409 BTC_TRACE(trace_buf);
5410 } else {
5411 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
5412 tmp_buf[i]);
5413 BTC_TRACE(trace_buf);
5414 }
5415 }
5416
5417 coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1];
5418 coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
5419 coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5];
5420
5421 if (BT_INFO_SRC_8822B_2ANT_WIFI_FW != rsp_source) {
5422
5423 /* if 0xff, it means BT is under WHCK test */
5424 coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? TRUE :
5425 FALSE);
5426
5427 coex_sta->bt_create_connection = ((
5428 coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? TRUE :
5429 FALSE);
5430
5431 /* unit: %, value-100 to translate to unit: dBm */
5432 coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 +
5433 10;
5434
5435 coex_sta->c2h_bt_remote_name_req = ((
5436 coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? TRUE :
5437 FALSE);
5438
5439 coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] &
5440 0x10) ? TRUE : FALSE);
5441
5442 coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] &
5443 0x9) ? TRUE : FALSE);
5444
5445 coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ?
5446 TRUE : FALSE);
5447
5448 coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info &
5449 BT_INFO_8822B_2ANT_B_INQ_PAGE) ? TRUE : FALSE);
5450
5451 coex_sta->a2dp_bit_pool = (((
5452 coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ?
5453 (coex_sta->bt_info_c2h[rsp_source][6] & 0x7f) : 0);
5454
5455 coex_sta->is_bt_a2dp_sink = (coex_sta->bt_info_c2h[rsp_source][6] & 0x80) ?
5456 TRUE : FALSE;
5457
5458 coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] &
5459 0xf;
5460
5461 coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8;
5462
5463 coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7;
5464
5465 coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4;
5466
5467 coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6;
5468
5469 if (coex_sta->bt_retry_cnt >= 1)
5470 coex_sta->pop_event_cnt++;
5471
5472 if (coex_sta->c2h_bt_remote_name_req)
5473 coex_sta->cnt_RemoteNameReq++;
5474
5475 if (coex_sta->bt_info_ext & BIT(1))
5476 coex_sta->cnt_ReInit++;
5477
5478 if (coex_sta->bt_info_ext & BIT(2)) {
5479 coex_sta->cnt_setupLink++;
5480 coex_sta->is_setupLink = TRUE;
5481 coex_sta->bt_relink_downcount = 2;
5482 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5483 "[BTCoex], Re-Link start in BT info!!\n");
5484 BTC_TRACE(trace_buf);
5485 } else {
5486 coex_sta->is_setupLink = FALSE;
5487 coex_sta->bt_relink_downcount = 0;
5488 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5489 "[BTCoex], Re-Link stop in BT info!!\n");
5490 BTC_TRACE(trace_buf);
5491 }
5492
5493
5494 if (coex_sta->bt_info_ext & BIT(3))
5495 coex_sta->cnt_IgnWlanAct++;
5496
5497 if (coex_sta->bt_info_ext & BIT(6))
5498 coex_sta->cnt_RoleSwitch++;
5499
5500 if (coex_sta->bt_info_ext & BIT(7))
5501 coex_sta->is_bt_multi_link = TRUE;
5502 else
5503 coex_sta->is_bt_multi_link = FALSE;
5504
5505 if (coex_sta->bt_create_connection) {
5506 coex_sta->cnt_Page++;
5507
5508 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY,
5509 &wifi_busy);
5510
5511 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
5512 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link);
5513 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam);
5514
5515 if ((wifi_link) || (wifi_roam) || (wifi_scan) ||
5516 (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) {
5517
5518 is_scoreboard_scan = TRUE;
5519 halbtc8822b2ant_post_state_to_bt(btcoexist,
5520 BT_8822B_2ANT_SCOREBOARD_SCAN, TRUE);
5521
5522 } else
5523 halbtc8822b2ant_post_state_to_bt(btcoexist,
5524 BT_8822B_2ANT_SCOREBOARD_SCAN, FALSE);
5525
5526 } else {
5527 if (is_scoreboard_scan) {
5528 halbtc8822b2ant_post_state_to_bt(btcoexist,
5529 BT_8822B_2ANT_SCOREBOARD_SCAN, FALSE);
5530 is_scoreboard_scan = FALSE;
5531 }
5532 }
5533
5534 /* Here we need to resend some wifi info to BT */
5535 /* because bt is reset and loss of the info. */
5536
5537 if ((!btcoexist->manual_control) &&
5538 (!btcoexist->stop_coex_dm)) {
5539
5540 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
5541 &wifi_connected);
5542
5543 /* Re-Init */
5544 if ((coex_sta->bt_info_ext & BIT(1))) {
5545 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5546 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
5547 BTC_TRACE(trace_buf);
5548 if (wifi_connected)
5549 halbtc8822b2ant_update_wifi_channel_info(
5550 btcoexist, BTC_MEDIA_CONNECT);
5551 else
5552 halbtc8822b2ant_update_wifi_channel_info(
5553 btcoexist,
5554 BTC_MEDIA_DISCONNECT);
5555 }
5556
5557
5558 /* If Ignore_WLanAct && not SetUp_Link */
5559 if ((coex_sta->bt_info_ext & BIT(3)) &&
5560 (!(coex_sta->bt_info_ext & BIT(2))) &&
5561 (!(coex_sta->bt_info_ext & BIT(6)))) {
5562
5563 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5564 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
5565 BTC_TRACE(trace_buf);
5566 halbtc8822b2ant_ignore_wlan_act(btcoexist,
5567 FORCE_EXEC, FALSE);
5568 } else {
5569 if (coex_sta->bt_info_ext & BIT(2)) {
5570 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5571 "[BTCoex], BT ignore Wlan active because Re-link!!\n");
5572 BTC_TRACE(trace_buf);
5573 } else if (coex_sta->bt_info_ext & BIT(6)) {
5574 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5575 "[BTCoex], BT ignore Wlan active because Role-Switch!!\n");
5576 BTC_TRACE(trace_buf);
5577 }
5578 }
5579 }
5580
5581 }
5582
5583 if ((coex_sta->bt_info_ext & BIT(5))) {
5584 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5585 "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n");
5586 BTC_TRACE(trace_buf);
5587 coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(
5588 btcoexist);
5589
5590 if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1)
5591 coex_sta->bt_ble_scan_para[0] =
5592 btcoexist->btc_get_ble_scan_para_from_bt(btcoexist,
5593 0x1);
5594 if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2)
5595 coex_sta->bt_ble_scan_para[1] =
5596 btcoexist->btc_get_ble_scan_para_from_bt(btcoexist,
5597 0x2);
5598 if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4)
5599 coex_sta->bt_ble_scan_para[2] =
5600 btcoexist->btc_get_ble_scan_para_from_bt(btcoexist,
5601 0x4);
5602 }
5603
5604 halbtc8822b2ant_update_bt_link_info(btcoexist);
5605
5606 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5607 }
5608
ex_halbtc8822b2ant_wl_fwdbginfo_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)5609 void ex_halbtc8822b2ant_wl_fwdbginfo_notify(IN struct btc_coexist *btcoexist,
5610 IN u8 *tmp_buf, IN u8 length)
5611 {
5612 u8 i = 0;
5613 static u8 tmp_buf_pre[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
5614
5615 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5616 "[BTCoex], WiFi Fw Dbg info = %d %d %d %d %d %d (len = %d)\n",
5617 tmp_buf[0], tmp_buf[1],
5618 tmp_buf[2], tmp_buf[3],
5619 tmp_buf[4], tmp_buf[5], length);
5620 BTC_TRACE(trace_buf);
5621
5622 if (tmp_buf[0] == 0x8) {
5623 for (i = 1; i <= 5; i++) {
5624 coex_sta->wl_fw_dbg_info[i] =
5625 (tmp_buf[i] >= tmp_buf_pre[i]) ?
5626 (tmp_buf[i] - tmp_buf_pre[i]) :
5627 (255 - tmp_buf_pre[i] + tmp_buf[i]);
5628
5629 tmp_buf_pre[i] = tmp_buf[i];
5630 }
5631 }
5632 }
5633
5634
ex_halbtc8822b2ant_rx_rate_change_notify(IN struct btc_coexist * btcoexist,IN BOOLEAN is_data_frame,IN u8 btc_rate_id)5635 void ex_halbtc8822b2ant_rx_rate_change_notify(IN struct btc_coexist *btcoexist,
5636 IN BOOLEAN is_data_frame, IN u8 btc_rate_id)
5637 {
5638 BOOLEAN wifi_connected = FALSE;
5639
5640 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
5641 &wifi_connected);
5642
5643 if (is_data_frame) {
5644 coex_sta->wl_rx_rate = btc_rate_id;
5645
5646 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5647 "[BTCoex], rx_rate_change_notify data rate id = %d, RTS_Rate = %d\n",
5648 coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate);
5649 BTC_TRACE(trace_buf);
5650 } else {
5651 coex_sta->wl_rts_rx_rate = btc_rate_id;
5652
5653 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5654 "[BTCoex], rts_rate_change_notify RTS rate id = %d, RTS_Rate = %d\n",
5655 coex_sta->wl_rts_rx_rate, coex_sta->wl_rts_rx_rate);
5656 BTC_TRACE(trace_buf);
5657 }
5658
5659 if ((wifi_connected) &&
5660 ((coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_ACL_BUSY) ||
5661 (coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY) ||
5662 (coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_SCO_BUSY))) {
5663
5664 if ((coex_sta->wl_rx_rate == BTC_CCK_5_5) ||
5665 (coex_sta->wl_rx_rate == BTC_OFDM_6) ||
5666 (coex_sta->wl_rx_rate == BTC_MCS_0)) {
5667
5668 coex_sta->cck_lock_warn = TRUE;
5669
5670 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5671 "[BTCoex], cck lock warning...\n");
5672 BTC_TRACE(trace_buf);
5673 } else if ((coex_sta->wl_rx_rate == BTC_CCK_1) ||
5674 (coex_sta->wl_rx_rate == BTC_CCK_2) ||
5675 (coex_sta->wl_rts_rx_rate == BTC_CCK_1) ||
5676 (coex_sta->wl_rts_rx_rate == BTC_CCK_2)) {
5677
5678 coex_sta->cck_lock = TRUE;
5679
5680 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5681 "[BTCoex], cck locking...\n");
5682 BTC_TRACE(trace_buf);
5683 } else {
5684 coex_sta->cck_lock_warn = FALSE;
5685 coex_sta->cck_lock = FALSE;
5686
5687 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5688 "[BTCoex], cck unlock...\n");
5689 BTC_TRACE(trace_buf);
5690 }
5691 } else {
5692 if ((coex_dm->bt_status ==
5693 BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE) ||
5694 (coex_dm->bt_status ==
5695 BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE)) {
5696 coex_sta->cck_lock_warn = FALSE;
5697 coex_sta->cck_lock = FALSE;
5698 }
5699 }
5700
5701 }
5702
5703
ex_halbtc8822b2ant_rf_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)5704 void ex_halbtc8822b2ant_rf_status_notify(IN struct btc_coexist *btcoexist,
5705 IN u8 type)
5706 {
5707 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
5708 BTC_TRACE(trace_buf);
5709
5710 if (BTC_RF_ON == type) {
5711 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5712 "[BTCoex], RF is turned ON!!\n");
5713 BTC_TRACE(trace_buf);
5714
5715 btcoexist->stop_coex_dm = FALSE;
5716 coex_sta->is_rf_state_off = FALSE;
5717 #if 0
5718 halbtc8822b2ant_post_state_to_bt(btcoexist,
5719 BT_8822B_2ANT_SCOREBOARD_ACTIVE, TRUE);
5720 halbtc8822b2ant_post_state_to_bt(btcoexist,
5721 BT_8822B_2ANT_SCOREBOARD_ONOFF, TRUE);
5722 #endif
5723 } else if (BTC_RF_OFF == type) {
5724 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5725 "[BTCoex], RF is turned OFF!!\n");
5726 BTC_TRACE(trace_buf);
5727
5728 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5729 FORCE_EXEC,
5730 BT_8822B_2ANT_PHASE_WLAN_OFF);
5731
5732 halbtc8822b2ant_action_coex_all_off(btcoexist);
5733
5734 halbtc8822b2ant_post_state_to_bt(btcoexist,
5735 BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5736 BT_8822B_2ANT_SCOREBOARD_ONOFF |
5737 BT_8822B_2ANT_SCOREBOARD_SCAN |
5738 BT_8822B_2ANT_SCOREBOARD_UNDERTEST |
5739 BT_8822B_2ANT_SCOREBOARD_RXGAIN,
5740 FALSE);
5741
5742 btcoexist->stop_coex_dm = TRUE;
5743 coex_sta->is_rf_state_off = TRUE;
5744 }
5745 }
5746
ex_halbtc8822b2ant_halt_notify(IN struct btc_coexist * btcoexist)5747 void ex_halbtc8822b2ant_halt_notify(IN struct btc_coexist *btcoexist)
5748 {
5749 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
5750 BTC_TRACE(trace_buf);
5751
5752 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
5753 BT_8822B_2ANT_PHASE_WLAN_OFF);
5754
5755 ex_halbtc8822b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
5756
5757 halbtc8822b2ant_post_state_to_bt(btcoexist,
5758 BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5759 BT_8822B_2ANT_SCOREBOARD_ONOFF |
5760 BT_8822B_2ANT_SCOREBOARD_SCAN |
5761 BT_8822B_2ANT_SCOREBOARD_UNDERTEST |
5762 BT_8822B_2ANT_SCOREBOARD_RXGAIN,
5763 FALSE);
5764 }
5765
ex_halbtc8822b2ant_pnp_notify(IN struct btc_coexist * btcoexist,IN u8 pnp_state)5766 void ex_halbtc8822b2ant_pnp_notify(IN struct btc_coexist *btcoexist,
5767 IN u8 pnp_state)
5768 {
5769 boolean wifi_under_5g = FALSE;
5770
5771 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
5772 BTC_TRACE(trace_buf);
5773
5774 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5775
5776 if ((BTC_WIFI_PNP_SLEEP == pnp_state) ||
5777 (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) {
5778 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5779 "[BTCoex], Pnp notify to SLEEP\n");
5780 BTC_TRACE(trace_buf);
5781
5782 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to
5783 * speed up sleep time.
5784 * Driver do not leave IPS/LPS when driver is going to sleep,
5785 * so BTCoexistence think wifi is still under IPS/LPS.
5786 * BT should clear UnderIPS/UnderLPS state to avoid mismatch
5787 * state after wakeup.
5788 */
5789 coex_sta->under_ips = FALSE;
5790 coex_sta->under_lps = FALSE;
5791
5792 halbtc8822b2ant_post_state_to_bt(btcoexist,
5793 BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5794 BT_8822B_2ANT_SCOREBOARD_ONOFF |
5795 BT_8822B_2ANT_SCOREBOARD_SCAN |
5796 BT_8822B_2ANT_SCOREBOARD_UNDERTEST |
5797 BT_8822B_2ANT_SCOREBOARD_RXGAIN,
5798 FALSE);
5799
5800 if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) {
5801
5802 if (wifi_under_5g)
5803 halbtc8822b2ant_set_ant_path(btcoexist,
5804 BTC_ANT_PATH_AUTO, FORCE_EXEC,
5805 BT_8822B_2ANT_PHASE_5G_RUNTIME);
5806 else
5807 halbtc8822b2ant_set_ant_path(btcoexist,
5808 BTC_ANT_PATH_AUTO, FORCE_EXEC,
5809 BT_8822B_2ANT_PHASE_2G_RUNTIME);
5810 } else {
5811
5812 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5813 FORCE_EXEC,
5814 BT_8822B_2ANT_PHASE_WLAN_OFF);
5815 }
5816 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
5817 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5818 "[BTCoex], Pnp notify to WAKE UP\n");
5819 BTC_TRACE(trace_buf);
5820 #if 0
5821 halbtc8822b2ant_post_state_to_bt(btcoexist,
5822 BT_8822B_2ANT_SCOREBOARD_ACTIVE, TRUE);
5823 halbtc8822b2ant_post_state_to_bt(btcoexist,
5824 BT_8822B_2ANT_SCOREBOARD_ONOFF, TRUE);
5825 #endif
5826 }
5827 }
5828
ex_halbtc8822b2ant_periodical(IN struct btc_coexist * btcoexist)5829 void ex_halbtc8822b2ant_periodical(IN struct btc_coexist *btcoexist)
5830 {
5831 boolean wifi_busy = FALSE;
5832 u16 bt_scoreboard_val = 0;
5833 boolean bt_relink_finish = FALSE;
5834
5835 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5836 "[BTCoex], ************* Periodical *************\n");
5837 BTC_TRACE(trace_buf);
5838
5839 #if (BT_AUTO_REPORT_ONLY_8822B_2ANT == 0)
5840 halbtc8822b2ant_query_bt_info(btcoexist);
5841 #endif
5842
5843 halbtc8822b2ant_monitor_bt_ctr(btcoexist);
5844 halbtc8822b2ant_monitor_wifi_ctr(btcoexist);
5845 halbtc8822b2ant_monitor_bt_enable_disable(btcoexist);
5846
5847 #if 0
5848 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
5849 halbtc8822b2ant_read_score_board(btcoexist, &bt_scoreboard_val);
5850
5851 if (wifi_busy) {
5852 halbtc8822b2ant_post_state_to_bt(btcoexist,
5853 BT_8822B_2ANT_SCOREBOARD_UNDERTEST, TRUE);
5854 /*for bt lps32 clock offset*/
5855 if (bt_scoreboard_val & BIT(6))
5856 halbtc8822b2ant_query_bt_info(btcoexist);
5857 } else {
5858 halbtc8822b2ant_post_state_to_bt(btcoexist,
5859 BT_8822B_2ANT_SCOREBOARD_UNDERTEST, FALSE);
5860 #if 0
5861 halbtc8822b2ant_post_state_to_bt(btcoexist,
5862 BT_8822B_2ANT_SCOREBOARD_WLBUSY,
5863 FALSE);
5864 #endif
5865 }
5866 #endif
5867
5868 if (coex_sta->bt_relink_downcount != 0) {
5869 coex_sta->bt_relink_downcount--;
5870
5871 if (coex_sta->bt_relink_downcount == 0) {
5872 coex_sta->is_setupLink = FALSE;
5873 bt_relink_finish = TRUE;
5874 }
5875 }
5876
5877 /* for 4-way, DHCP, EAPOL packet */
5878 if (coex_sta->specific_pkt_period_cnt > 0) {
5879
5880 coex_sta->specific_pkt_period_cnt--;
5881
5882 if ((coex_sta->specific_pkt_period_cnt == 0) &&
5883 (coex_sta->wifi_is_high_pri_task))
5884 coex_sta->wifi_is_high_pri_task = FALSE;
5885
5886 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5887 "[BTCoex], ***************** Hi-Pri Task = %s*****************\n",
5888 (coex_sta->wifi_is_high_pri_task ? "Yes" :
5889 "No"));
5890 BTC_TRACE(trace_buf);
5891
5892 }
5893
5894 if (halbtc8822b2ant_is_wifibt_status_changed(btcoexist) || (bt_relink_finish)
5895 || (coex_sta->is_set_ps_state_fail))
5896 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5897 }
5898
ex_halbtc8822b2ant_antenna_detection(IN struct btc_coexist * btcoexist,IN u32 cent_freq,IN u32 offset,IN u32 span,IN u32 seconds)5899 void ex_halbtc8822b2ant_antenna_detection(IN struct btc_coexist *btcoexist,
5900 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
5901 {
5902
5903 }
5904
5905
ex_halbtc8822b2ant_display_ant_detection(IN struct btc_coexist * btcoexist)5906 void ex_halbtc8822b2ant_display_ant_detection(IN struct btc_coexist *btcoexist)
5907 {
5908 }
5909
5910
5911 #endif
5912
5913 #endif /* #if (RTL8822B_SUPPORT == 1) */
5914