1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include "halbt_precomp.h"
29
30
31
32
33static struct coex_dm_8822b_1ant glcoex_dm_8822b_1ant;
34static struct coex_dm_8822b_1ant *coex_dm = &glcoex_dm_8822b_1ant;
35static struct coex_sta_8822b_1ant glcoex_sta_8822b_1ant;
36static struct coex_sta_8822b_1ant *coex_sta = &glcoex_sta_8822b_1ant;
37static struct psdscan_sta_8822b_1ant gl_psd_scan_8822b_1ant;
38static struct psdscan_sta_8822b_1ant *psd_scan = &gl_psd_scan_8822b_1ant;
39static struct rfe_type_8822b_1ant gl_rfe_type_8822b_1ant;
40static struct rfe_type_8822b_1ant *rfe_type = &gl_rfe_type_8822b_1ant;
41
42static const char *const glbt_info_src_8822b_1ant[] = {
43 "BT Info[wifi fw]", "BT Info[bt rsp]", "BT Info[bt auto report]",
44};
45
46static u32 glcoex_ver_date_8822b_1ant = 20170327;
47static u32 glcoex_ver_8822b_1ant = 0x44;
48static u32 glcoex_ver_btdesired_8822b_1ant = 0x42;
49
50
51
52
53
54
55
56
57static u8 halbtc8822b1ant_wifi_rssi_state(struct btc_coexist *btcoexist,
58 u8 index, u8 level_num,
59 u8 rssi_thresh, u8 rssi_thresh1)
60{
61 struct rtl_priv *rtlpriv = btcoexist->adapter;
62 s32 wifi_rssi = 0;
63 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
64
65 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
66
67 if (level_num == 2) {
68 if ((coex_sta->pre_wifi_rssi_state[index] ==
69 BTC_RSSI_STATE_LOW) ||
70 (coex_sta->pre_wifi_rssi_state[index] ==
71 BTC_RSSI_STATE_STAY_LOW)) {
72 if (wifi_rssi >=
73 (rssi_thresh + BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
74 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
75 else
76 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
77 } else {
78 if (wifi_rssi < rssi_thresh)
79 wifi_rssi_state = BTC_RSSI_STATE_LOW;
80 else
81 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
82 }
83 } else if (level_num == 3) {
84 if (rssi_thresh > rssi_thresh1) {
85 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
86 "[BTCoex], wifi RSSI thresh error!!\n");
87 return coex_sta->pre_wifi_rssi_state[index];
88 }
89
90 if ((coex_sta->pre_wifi_rssi_state[index] ==
91 BTC_RSSI_STATE_LOW) ||
92 (coex_sta->pre_wifi_rssi_state[index] ==
93 BTC_RSSI_STATE_STAY_LOW)) {
94 if (wifi_rssi >=
95 (rssi_thresh + BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
96 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
97 else
98 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
99 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
100 BTC_RSSI_STATE_MEDIUM) ||
101 (coex_sta->pre_wifi_rssi_state[index] ==
102 BTC_RSSI_STATE_STAY_MEDIUM)) {
103 if (wifi_rssi >= (rssi_thresh1 +
104 BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
105 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
106 else if (wifi_rssi < rssi_thresh)
107 wifi_rssi_state = BTC_RSSI_STATE_LOW;
108 else
109 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
110 } else {
111 if (wifi_rssi < rssi_thresh1)
112 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
113 else
114 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
115 }
116 }
117
118 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
119
120 return wifi_rssi_state;
121}
122
123static void halbtc8822b1ant_update_ra_mask(struct btc_coexist *btcoexist,
124 bool force_exec, u32 dis_rate_mask)
125{
126 coex_dm->cur_ra_mask = dis_rate_mask;
127
128 if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
129 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
130 &coex_dm->cur_ra_mask);
131 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
132}
133
134static void
135halbtc8822b1ant_auto_rate_fallback_retry(struct btc_coexist *btcoexist,
136 bool force_exec, u8 type)
137{
138 bool wifi_under_b_mode = false;
139
140 coex_dm->cur_arfr_type = type;
141
142 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
143 switch (coex_dm->cur_arfr_type) {
144 case 0:
145 btcoexist->btc_write_4byte(btcoexist, 0x430,
146 coex_dm->backup_arfr_cnt1);
147 btcoexist->btc_write_4byte(btcoexist, 0x434,
148 coex_dm->backup_arfr_cnt2);
149 break;
150 case 1:
151 btcoexist->btc_get(btcoexist,
152 BTC_GET_BL_WIFI_UNDER_B_MODE,
153 &wifi_under_b_mode);
154 if (wifi_under_b_mode) {
155 btcoexist->btc_write_4byte(btcoexist, 0x430,
156 0x0);
157 btcoexist->btc_write_4byte(btcoexist, 0x434,
158 0x01010101);
159 } else {
160 btcoexist->btc_write_4byte(btcoexist, 0x430,
161 0x0);
162 btcoexist->btc_write_4byte(btcoexist, 0x434,
163 0x04030201);
164 }
165 break;
166 default:
167 break;
168 }
169 }
170
171 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
172}
173
174static void halbtc8822b1ant_retry_limit(struct btc_coexist *btcoexist,
175 bool force_exec, u8 type)
176{
177 coex_dm->cur_retry_limit_type = type;
178
179 if (force_exec ||
180 (coex_dm->pre_retry_limit_type != coex_dm->cur_retry_limit_type)) {
181 switch (coex_dm->cur_retry_limit_type) {
182 case 0:
183 btcoexist->btc_write_2byte(btcoexist, 0x42a,
184 coex_dm->backup_retry_limit);
185 break;
186 case 1:
187 btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
188 break;
189 default:
190 break;
191 }
192 }
193
194 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
195}
196
197static void halbtc8822b1ant_ampdu_max_time(struct btc_coexist *btcoexist,
198 bool force_exec, u8 type)
199{
200 coex_dm->cur_ampdu_time_type = type;
201
202 if (force_exec ||
203 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
204 switch (coex_dm->cur_ampdu_time_type) {
205 case 0:
206 btcoexist->btc_write_1byte(
207 btcoexist, 0x456,
208 coex_dm->backup_ampdu_max_time);
209 break;
210 case 1:
211 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
212 break;
213 default:
214 break;
215 }
216 }
217
218 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
219}
220
221static void halbtc8822b1ant_limited_tx(struct btc_coexist *btcoexist,
222 bool force_exec, u8 ra_mask_type,
223 u8 arfr_type, u8 retry_limit_type,
224 u8 ampdu_time_type)
225{
226 switch (ra_mask_type) {
227 case 0:
228 halbtc8822b1ant_update_ra_mask(btcoexist, force_exec, 0x0);
229 break;
230 case 1:
231 halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
232 0x00000003);
233 break;
234 case 2:
235 halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
236 0x0001f1f7);
237 break;
238 default:
239 break;
240 }
241
242 halbtc8822b1ant_auto_rate_fallback_retry(btcoexist, force_exec,
243 arfr_type);
244 halbtc8822b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
245 halbtc8822b1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
246}
247
248
249
250
251
252
253
254
255static void halbtc8822b1ant_limited_rx(struct btc_coexist *btcoexist,
256 bool force_exec, bool rej_ap_agg_pkt,
257 bool bt_ctrl_agg_buf_size,
258 u8 agg_buf_size)
259{
260 bool reject_rx_agg = rej_ap_agg_pkt;
261 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
262 u8 rx_agg_size = agg_buf_size;
263
264
265
266
267 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
268 &reject_rx_agg);
269
270 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
271 &bt_ctrl_rx_agg_size);
272
273 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
274
275 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
276}
277
278static void halbtc8822b1ant_query_bt_info(struct btc_coexist *btcoexist)
279{
280 struct rtl_priv *rtlpriv = btcoexist->adapter;
281 u8 h2c_parameter[1] = {0};
282
283 if (coex_sta->bt_disabled) {
284 RT_TRACE(
285 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
286 "[BTCoex], No query BT info because BT is disabled!\n");
287 return;
288 }
289
290 h2c_parameter[0] |= BIT(0);
291
292 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
293
294 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
295 "[BTCoex], WL query BT info!!\n");
296}
297
298static void halbtc8822b1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
299{
300 struct rtl_priv *rtlpriv = btcoexist->adapter;
301 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
302 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
303 static u8 num_of_bt_counter_chk, cnt_slave, cnt_autoslot_hang;
304 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
305
306 reg_hp_txrx = 0x770;
307 reg_lp_txrx = 0x774;
308
309 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
310 reg_hp_tx = u32tmp & MASKLWORD;
311 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
312
313 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
314 reg_lp_tx = u32tmp & MASKLWORD;
315 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
316
317 coex_sta->high_priority_tx = reg_hp_tx;
318 coex_sta->high_priority_rx = reg_hp_rx;
319 coex_sta->low_priority_tx = reg_lp_tx;
320 coex_sta->low_priority_rx = reg_lp_rx;
321
322 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
323 "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
324 reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
325
326
327 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
328
329 if ((coex_sta->low_priority_tx > 1150) &&
330 (!coex_sta->c2h_bt_inquiry_page))
331 coex_sta->pop_event_cnt++;
332
333 if ((coex_sta->low_priority_rx >= 1150) &&
334 (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) &&
335 (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) &&
336 (coex_sta->bt_link_exist)) {
337 if (cnt_slave >= 3) {
338 bt_link_info->slave_role = true;
339 cnt_slave = 3;
340 } else {
341 cnt_slave++;
342 }
343 } else {
344 if (cnt_slave == 0) {
345 bt_link_info->slave_role = false;
346 cnt_slave = 0;
347 } else {
348 cnt_slave--;
349 }
350 }
351
352 if (coex_sta->is_tdma_btautoslot) {
353 if ((coex_sta->low_priority_tx >= 1300) &&
354 (coex_sta->low_priority_rx <= 150)) {
355 if (cnt_autoslot_hang >= 2) {
356 coex_sta->is_tdma_btautoslot_hang = true;
357 cnt_autoslot_hang = 2;
358 } else {
359 cnt_autoslot_hang++;
360 }
361 } else {
362 if (cnt_autoslot_hang == 0) {
363 coex_sta->is_tdma_btautoslot_hang = false;
364 cnt_autoslot_hang = 0;
365 } else {
366 cnt_autoslot_hang--;
367 }
368 }
369 }
370
371 if (bt_link_info->hid_only) {
372 if (coex_sta->low_priority_rx > 50)
373 coex_sta->is_hid_low_pri_tx_overhead = true;
374 else
375 coex_sta->is_hid_low_pri_tx_overhead = false;
376 }
377
378 if ((coex_sta->high_priority_tx == 0) &&
379 (coex_sta->high_priority_rx == 0) &&
380 (coex_sta->low_priority_tx == 0) &&
381 (coex_sta->low_priority_rx == 0)) {
382 num_of_bt_counter_chk++;
383
384 if (num_of_bt_counter_chk >= 3) {
385 halbtc8822b1ant_query_bt_info(btcoexist);
386 num_of_bt_counter_chk = 0;
387 }
388 }
389}
390
391static void halbtc8822b1ant_monitor_wifi_ctr(struct btc_coexist *btcoexist)
392{
393 s32 wifi_rssi = 0;
394 bool wifi_busy = false, wifi_under_b_mode = false, wifi_scan = false;
395 static u8 cck_lock_counter, wl_noisy_count0, wl_noisy_count1 = 3,
396 wl_noisy_count2;
397 u32 total_cnt, cck_cnt;
398
399 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
400 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
401 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
402 &wifi_under_b_mode);
403
404 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
405
406 coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_phy_counter(
407 btcoexist, "PHYDM_INFO_CRC32_OK_CCK");
408 coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_phy_counter(
409 btcoexist, "PHYDM_INFO_CRC32_OK_LEGACY");
410 coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_phy_counter(
411 btcoexist, "PHYDM_INFO_CRC32_OK_HT");
412 coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_phy_counter(
413 btcoexist, "PHYDM_INFO_CRC32_OK_VHT");
414
415 coex_sta->crc_err_cck = btcoexist->btc_phydm_query_phy_counter(
416 btcoexist, "PHYDM_INFO_CRC32_ERROR_CCK");
417 coex_sta->crc_err_11g = btcoexist->btc_phydm_query_phy_counter(
418 btcoexist, "PHYDM_INFO_CRC32_ERROR_LEGACY");
419 coex_sta->crc_err_11n = btcoexist->btc_phydm_query_phy_counter(
420 btcoexist, "PHYDM_INFO_CRC32_ERROR_HT");
421 coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_phy_counter(
422 btcoexist, "PHYDM_INFO_CRC32_ERROR_VHT");
423
424 cck_cnt = coex_sta->crc_ok_cck + coex_sta->crc_err_cck;
425
426 if (cck_cnt > 250) {
427 if (wl_noisy_count2 < 3)
428 wl_noisy_count2++;
429
430 if (wl_noisy_count2 == 3) {
431 wl_noisy_count0 = 0;
432 wl_noisy_count1 = 0;
433 }
434
435 } else if (cck_cnt < 50) {
436 if (wl_noisy_count0 < 3)
437 wl_noisy_count0++;
438
439 if (wl_noisy_count0 == 3) {
440 wl_noisy_count1 = 0;
441 wl_noisy_count2 = 0;
442 }
443
444 } else {
445 if (wl_noisy_count1 < 3)
446 wl_noisy_count1++;
447
448 if (wl_noisy_count1 == 3) {
449 wl_noisy_count0 = 0;
450 wl_noisy_count2 = 0;
451 }
452 }
453
454 if (wl_noisy_count2 == 3)
455 coex_sta->wl_noisy_level = 2;
456 else if (wl_noisy_count1 == 3)
457 coex_sta->wl_noisy_level = 1;
458 else
459 coex_sta->wl_noisy_level = 0;
460
461 if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
462 total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g +
463 coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_vht;
464
465 if ((coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) ||
466 (coex_dm->bt_status ==
467 BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
468 (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_SCO_BUSY)) {
469 if (coex_sta->crc_ok_cck >
470 (total_cnt - coex_sta->crc_ok_cck)) {
471 if (cck_lock_counter < 3)
472 cck_lock_counter++;
473 } else {
474 if (cck_lock_counter > 0)
475 cck_lock_counter--;
476 }
477
478 } else {
479 if (cck_lock_counter > 0)
480 cck_lock_counter--;
481 }
482 } else {
483 if (cck_lock_counter > 0)
484 cck_lock_counter--;
485 }
486
487 if (!coex_sta->pre_ccklock) {
488 if (cck_lock_counter >= 3)
489 coex_sta->cck_lock = true;
490 else
491 coex_sta->cck_lock = false;
492 } else {
493 if (cck_lock_counter == 0)
494 coex_sta->cck_lock = false;
495 else
496 coex_sta->cck_lock = true;
497 }
498
499 if (coex_sta->cck_lock)
500 coex_sta->cck_ever_lock = true;
501
502 coex_sta->pre_ccklock = coex_sta->cck_lock;
503}
504
505static bool
506halbtc8822b1ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
507{
508 struct rtl_priv *rtlpriv = btcoexist->adapter;
509 static bool pre_wifi_busy, pre_under_4way, pre_bt_hs_on,
510 pre_rf4ce_enabled, pre_bt_off, pre_bt_slave,
511 pre_hid_low_pri_tx_overhead, pre_wifi_under_lps,
512 pre_bt_setup_link;
513 static u8 pre_hid_busy_num, pre_wl_noisy_level;
514 bool wifi_busy = false, under_4way = false, bt_hs_on = false,
515 rf4ce_enabled = false;
516 bool wifi_connected = false;
517 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
518
519 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
520 &wifi_connected);
521 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
522 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
523 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
524 &under_4way);
525
526 if (coex_sta->bt_disabled != pre_bt_off) {
527 pre_bt_off = coex_sta->bt_disabled;
528
529 if (coex_sta->bt_disabled)
530 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
531 "[BTCoex], BT is disabled !!\n");
532 else
533 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
534 "[BTCoex], BT is enabled !!\n");
535
536 coex_sta->bt_coex_supported_feature = 0;
537 coex_sta->bt_coex_supported_version = 0;
538 return true;
539 }
540 btcoexist->btc_get(btcoexist, BTC_GET_BL_RF4CE_CONNECTED,
541 &rf4ce_enabled);
542
543 if (rf4ce_enabled != pre_rf4ce_enabled) {
544 pre_rf4ce_enabled = rf4ce_enabled;
545
546 if (rf4ce_enabled)
547 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
548 "[BTCoex], rf4ce is enabled !!\n");
549 else
550 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
551 "[BTCoex], rf4ce is disabled !!\n");
552
553 return true;
554 }
555
556 if (wifi_connected) {
557 if (wifi_busy != pre_wifi_busy) {
558 pre_wifi_busy = wifi_busy;
559 return true;
560 }
561 if (under_4way != pre_under_4way) {
562 pre_under_4way = under_4way;
563 return true;
564 }
565 if (bt_hs_on != pre_bt_hs_on) {
566 pre_bt_hs_on = bt_hs_on;
567 return true;
568 }
569 if (coex_sta->wl_noisy_level != pre_wl_noisy_level) {
570 pre_wl_noisy_level = coex_sta->wl_noisy_level;
571 return true;
572 }
573 if (coex_sta->under_lps != pre_wifi_under_lps) {
574 pre_wifi_under_lps = coex_sta->under_lps;
575 if (coex_sta->under_lps)
576 return true;
577 }
578 }
579
580 if (!coex_sta->bt_disabled) {
581 if (coex_sta->hid_busy_num != pre_hid_busy_num) {
582 pre_hid_busy_num = coex_sta->hid_busy_num;
583 return true;
584 }
585
586 if (bt_link_info->slave_role != pre_bt_slave) {
587 pre_bt_slave = bt_link_info->slave_role;
588 return true;
589 }
590
591 if (pre_hid_low_pri_tx_overhead !=
592 coex_sta->is_hid_low_pri_tx_overhead) {
593 pre_hid_low_pri_tx_overhead =
594 coex_sta->is_hid_low_pri_tx_overhead;
595 return true;
596 }
597
598 if (pre_bt_setup_link != coex_sta->is_setup_link) {
599 pre_bt_setup_link = coex_sta->is_setup_link;
600 return true;
601 }
602 }
603
604 return false;
605}
606
607static void halbtc8822b1ant_update_bt_link_info(struct btc_coexist *btcoexist)
608{
609 struct rtl_priv *rtlpriv = btcoexist->adapter;
610 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
611 bool bt_hs_on = false;
612 bool bt_busy = false;
613
614 coex_sta->num_of_profile = 0;
615
616
617 if (!(coex_sta->bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
618 coex_sta->bt_link_exist = false;
619 coex_sta->pan_exist = false;
620 coex_sta->a2dp_exist = false;
621 coex_sta->hid_exist = false;
622 coex_sta->sco_exist = false;
623 } else {
624 coex_sta->bt_link_exist = true;
625 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_FTP) {
626 coex_sta->pan_exist = true;
627 coex_sta->num_of_profile++;
628 } else {
629 coex_sta->pan_exist = false;
630 }
631
632 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_A2DP) {
633 coex_sta->a2dp_exist = true;
634 coex_sta->num_of_profile++;
635 } else {
636 coex_sta->a2dp_exist = false;
637 }
638
639 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_HID) {
640 coex_sta->hid_exist = true;
641 coex_sta->num_of_profile++;
642 } else {
643 coex_sta->hid_exist = false;
644 }
645
646 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) {
647 coex_sta->sco_exist = true;
648 coex_sta->num_of_profile++;
649 } else {
650 coex_sta->sco_exist = false;
651 }
652 }
653
654 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
655
656 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
657 bt_link_info->sco_exist = coex_sta->sco_exist;
658 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
659 bt_link_info->pan_exist = coex_sta->pan_exist;
660 bt_link_info->hid_exist = coex_sta->hid_exist;
661 bt_link_info->acl_busy = coex_sta->acl_busy;
662
663
664 if (bt_hs_on) {
665 bt_link_info->pan_exist = true;
666 bt_link_info->bt_link_exist = true;
667 }
668
669
670 if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
671 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
672 bt_link_info->sco_only = true;
673 else
674 bt_link_info->sco_only = false;
675
676
677 if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
678 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
679 bt_link_info->a2dp_only = true;
680 else
681 bt_link_info->a2dp_only = false;
682
683
684 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
685 bt_link_info->pan_exist && !bt_link_info->hid_exist)
686 bt_link_info->pan_only = true;
687 else
688 bt_link_info->pan_only = false;
689
690
691 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
692 !bt_link_info->pan_exist && bt_link_info->hid_exist)
693 bt_link_info->hid_only = true;
694 else
695 bt_link_info->hid_only = false;
696
697 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_INQ_PAGE) {
698 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_INQ_PAGE;
699 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
700 "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n");
701 } else if (!(coex_sta->bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
702 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
703 RT_TRACE(
704 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
705 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
706 } else if (coex_sta->bt_info == BT_INFO_8822B_1ANT_B_CONNECTION) {
707
708 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE;
709 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
710 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
711 } else if (((coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) ||
712 (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_BUSY)) &&
713 (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_ACL_BUSY)) {
714 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY;
715 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
716 "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
717 } else if ((coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) ||
718 (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_BUSY)) {
719 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_SCO_BUSY;
720 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
721 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
722 } else if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_ACL_BUSY) {
723 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_ACL_BUSY;
724 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
725 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
726 } else {
727 coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_MAX;
728 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
729 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
730 }
731
732 if ((coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) ||
733 (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_SCO_BUSY) ||
734 (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY))
735 bt_busy = true;
736 else
737 bt_busy = false;
738
739 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
740}
741
742static void halbtc8822b1ant_update_wifi_ch_info(struct btc_coexist *btcoexist,
743 u8 type)
744{
745 u8 h2c_parameter[3] = {0};
746 u32 wifi_bw;
747 u8 wifi_central_chnl;
748
749
750 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
751 &wifi_central_chnl);
752 if ((type == BTC_MEDIA_CONNECT) && (wifi_central_chnl <= 14)) {
753
754
755
756 h2c_parameter[0] = 0x1;
757 h2c_parameter[1] = wifi_central_chnl;
758
759 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
760
761 if (wifi_bw == BTC_WIFI_BW_HT40)
762 h2c_parameter[2] = 0x30;
763 else
764 h2c_parameter[2] = 0x20;
765 }
766
767 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
768 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
769 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
770
771 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
772}
773
774static u8 halbtc8822b1ant_action_algorithm(struct btc_coexist *btcoexist)
775{
776 struct rtl_priv *rtlpriv = btcoexist->adapter;
777 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
778 bool bt_hs_on = false;
779 u8 algorithm = BT_8822B_1ANT_COEX_ALGO_UNDEFINED;
780 u8 num_of_diff_profile = 0;
781
782 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
783
784 if (!bt_link_info->bt_link_exist) {
785 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
786 "[BTCoex], No BT link exists!!!\n");
787 return algorithm;
788 }
789
790 if (bt_link_info->sco_exist)
791 num_of_diff_profile++;
792 if (bt_link_info->hid_exist)
793 num_of_diff_profile++;
794 if (bt_link_info->pan_exist)
795 num_of_diff_profile++;
796 if (bt_link_info->a2dp_exist)
797 num_of_diff_profile++;
798
799 if (num_of_diff_profile == 1) {
800 if (bt_link_info->sco_exist) {
801 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
802 "[BTCoex], BT Profile = SCO only\n");
803 algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
804 } else {
805 if (bt_link_info->hid_exist) {
806 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
807 "[BTCoex], BT Profile = HID only\n");
808 algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
809 } else if (bt_link_info->a2dp_exist) {
810 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
811 "[BTCoex], BT Profile = A2DP only\n");
812 algorithm = BT_8822B_1ANT_COEX_ALGO_A2DP;
813 } else if (bt_link_info->pan_exist) {
814 if (bt_hs_on) {
815 RT_TRACE(
816 rtlpriv, COMP_BT_COEXIST,
817 DBG_LOUD,
818 "[BTCoex], BT Profile = PAN(HS) only\n");
819 algorithm =
820 BT_8822B_1ANT_COEX_ALGO_PANHS;
821 } else {
822 RT_TRACE(
823 rtlpriv, COMP_BT_COEXIST,
824 DBG_LOUD,
825 "[BTCoex], BT Profile = PAN(EDR) only\n");
826 algorithm =
827 BT_8822B_1ANT_COEX_ALGO_PANEDR;
828 }
829 }
830 }
831 } else if (num_of_diff_profile == 2) {
832 if (bt_link_info->sco_exist) {
833 if (bt_link_info->hid_exist) {
834 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
835 "[BTCoex], BT Profile = SCO + HID\n");
836 algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
837 } else if (bt_link_info->a2dp_exist) {
838 RT_TRACE(
839 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
840 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
841 algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
842 } else if (bt_link_info->pan_exist) {
843 if (bt_hs_on) {
844 RT_TRACE(
845 rtlpriv, COMP_BT_COEXIST,
846 DBG_LOUD,
847 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
848 algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
849 } else {
850 RT_TRACE(
851 rtlpriv, COMP_BT_COEXIST,
852 DBG_LOUD,
853 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
854 algorithm =
855 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
856 }
857 }
858 } else {
859 if (bt_link_info->hid_exist &&
860 bt_link_info->a2dp_exist) {
861 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
862 "[BTCoex], BT Profile = HID + A2DP\n");
863 algorithm = BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
864 } else if (bt_link_info->hid_exist &&
865 bt_link_info->pan_exist) {
866 if (bt_hs_on) {
867 RT_TRACE(
868 rtlpriv, COMP_BT_COEXIST,
869 DBG_LOUD,
870 "[BTCoex], BT Profile = HID + PAN(HS)\n");
871 algorithm =
872 BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
873 } else {
874 RT_TRACE(
875 rtlpriv, COMP_BT_COEXIST,
876 DBG_LOUD,
877 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
878 algorithm =
879 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
880 }
881 } else if (bt_link_info->pan_exist &&
882 bt_link_info->a2dp_exist) {
883 if (bt_hs_on) {
884 RT_TRACE(
885 rtlpriv, COMP_BT_COEXIST,
886 DBG_LOUD,
887 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
888 algorithm =
889 BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS;
890 } else {
891 RT_TRACE(
892 rtlpriv, COMP_BT_COEXIST,
893 DBG_LOUD,
894 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
895 algorithm =
896 BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP;
897 }
898 }
899 }
900 } else if (num_of_diff_profile == 3) {
901 if (bt_link_info->sco_exist) {
902 if (bt_link_info->hid_exist &&
903 bt_link_info->a2dp_exist) {
904 RT_TRACE(
905 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
906 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
907 algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
908 } else if (bt_link_info->hid_exist &&
909 bt_link_info->pan_exist) {
910 if (bt_hs_on) {
911 RT_TRACE(
912 rtlpriv, COMP_BT_COEXIST,
913 DBG_LOUD,
914 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
915 algorithm =
916 BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
917 } else {
918 RT_TRACE(
919 rtlpriv, COMP_BT_COEXIST,
920 DBG_LOUD,
921 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
922 algorithm =
923 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
924 }
925 } else if (bt_link_info->pan_exist &&
926 bt_link_info->a2dp_exist) {
927 if (bt_hs_on) {
928 RT_TRACE(
929 rtlpriv, COMP_BT_COEXIST,
930 DBG_LOUD,
931 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
932 algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
933 } else {
934 RT_TRACE(
935 rtlpriv, COMP_BT_COEXIST,
936 DBG_LOUD,
937 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
938 algorithm =
939 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
940 }
941 }
942 } else {
943 if (bt_link_info->hid_exist &&
944 bt_link_info->pan_exist &&
945 bt_link_info->a2dp_exist) {
946 if (bt_hs_on) {
947 RT_TRACE(
948 rtlpriv, COMP_BT_COEXIST,
949 DBG_LOUD,
950 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
951 algorithm =
952 BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
953 } else {
954 RT_TRACE(
955 rtlpriv, COMP_BT_COEXIST,
956 DBG_LOUD,
957 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
958 algorithm =
959 BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
960 }
961 }
962 }
963 } else if (num_of_diff_profile >= 3) {
964 if (bt_link_info->sco_exist) {
965 if (bt_link_info->hid_exist &&
966 bt_link_info->pan_exist &&
967 bt_link_info->a2dp_exist) {
968 if (bt_hs_on) {
969 RT_TRACE(
970 rtlpriv, COMP_BT_COEXIST,
971 DBG_LOUD,
972 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
973
974 } else {
975 RT_TRACE(
976 rtlpriv, COMP_BT_COEXIST,
977 DBG_LOUD,
978 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
979 algorithm =
980 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
981 }
982 }
983 }
984 }
985
986 return algorithm;
987}
988
989static void halbtc8822b1ant_low_penalty_ra(struct btc_coexist *btcoexist,
990 bool force_exec, bool low_penalty_ra)
991{
992 coex_dm->cur_low_penalty_ra = low_penalty_ra;
993
994 if (!force_exec) {
995 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
996 return;
997 }
998
999 if (low_penalty_ra)
1000 btcoexist->btc_phydm_modify_ra_pcr_threshold(btcoexist, 0, 25);
1001 else
1002 btcoexist->btc_phydm_modify_ra_pcr_threshold(btcoexist, 0, 0);
1003
1004 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
1005}
1006
1007static void halbtc8822b1ant_write_score_board(struct btc_coexist *btcoexist,
1008 u16 bitpos, bool state)
1009{
1010 static u16 originalval = 0x8002;
1011
1012 if (state)
1013 originalval = originalval | bitpos;
1014 else
1015 originalval = originalval & (~bitpos);
1016
1017 btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
1018}
1019
1020static void halbtc8822b1ant_read_score_board(struct btc_coexist *btcoexist,
1021 u16 *score_board_val)
1022{
1023 *score_board_val =
1024 (btcoexist->btc_read_2byte(btcoexist, 0xaa)) & 0x7fff;
1025}
1026
1027static void halbtc8822b1ant_post_state_to_bt(struct btc_coexist *btcoexist,
1028 u16 type, bool state)
1029{
1030 halbtc8822b1ant_write_score_board(btcoexist, (u16)type, state);
1031}
1032
1033static void
1034halbtc8822b1ant_monitor_bt_enable_disable(struct btc_coexist *btcoexist)
1035{
1036 struct rtl_priv *rtlpriv = btcoexist->adapter;
1037 static u32 bt_disable_cnt;
1038 bool bt_active = true, bt_disabled = false, wifi_under_5g = false;
1039 u16 u16tmp;
1040
1041
1042
1043
1044
1045
1046 halbtc8822b1ant_read_score_board(btcoexist, &u16tmp);
1047
1048 bt_active = u16tmp & BIT(1);
1049
1050 if (bt_active) {
1051 bt_disable_cnt = 0;
1052 bt_disabled = false;
1053 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1054 &bt_disabled);
1055 } else {
1056 bt_disable_cnt++;
1057 if (bt_disable_cnt >= 2) {
1058 bt_disabled = true;
1059 bt_disable_cnt = 2;
1060 }
1061
1062 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1063 &bt_disabled);
1064 }
1065
1066 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1067
1068 if ((wifi_under_5g) || (bt_disabled))
1069 halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
1070 else
1071 halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true);
1072
1073 if (coex_sta->bt_disabled != bt_disabled) {
1074 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1075 "[BTCoex], BT is from %s to %s!!\n",
1076 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1077 (bt_disabled ? "disabled" : "enabled"));
1078 coex_sta->bt_disabled = bt_disabled;
1079 }
1080}
1081
1082static void halbtc8822b1ant_enable_gnt_to_gpio(struct btc_coexist *btcoexist,
1083 bool isenable)
1084{
1085 static u8 bit_val[5] = {0, 0, 0, 0, 0};
1086 static bool state;
1087
1088 if (!btcoexist->dbg_mode_1ant)
1089 return;
1090
1091 if (state == isenable)
1092 return;
1093
1094 state = isenable;
1095
1096 if (isenable) {
1097
1098 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
1099
1100
1101 bit_val[0] =
1102 (btcoexist->btc_read_1byte(btcoexist, 0x66) & BIT(4)) >>
1103 4;
1104 bit_val[1] = (btcoexist->btc_read_1byte(btcoexist, 0x67) &
1105 BIT(0));
1106 bit_val[2] =
1107 (btcoexist->btc_read_1byte(btcoexist, 0x42) & BIT(3)) >>
1108 3;
1109 bit_val[3] =
1110 (btcoexist->btc_read_1byte(btcoexist, 0x65) & BIT(7)) >>
1111 7;
1112 bit_val[4] =
1113 (btcoexist->btc_read_1byte(btcoexist, 0x72) & BIT(2)) >>
1114 2;
1115
1116
1117 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1118 0x0);
1119 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1120 0x0);
1121 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1122 0x0);
1123 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1124 0x0);
1125 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1126 0x0);
1127
1128 } else {
1129 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
1130
1131
1132
1133 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1134 bit_val[0]);
1135 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1136 bit_val[1]);
1137 btcoexist->btc_write_1byte_bitmask(
1138 btcoexist, 0x42, BIT(3), bit_val[2]);
1139 btcoexist->btc_write_1byte_bitmask(
1140 btcoexist, 0x65, BIT(7), bit_val[3]);
1141 btcoexist->btc_write_1byte_bitmask(
1142 btcoexist, 0x72, BIT(2), bit_val[4]);
1143 }
1144}
1145
1146static u32
1147halbtc8822b1ant_ltecoex_indirect_read_reg(struct btc_coexist *btcoexist,
1148 u16 reg_addr)
1149{
1150 u32 delay_count = 0;
1151
1152
1153 while (1) {
1154 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703) & BIT(5)) ==
1155 0) {
1156 mdelay(50);
1157 delay_count++;
1158 if (delay_count >= 10) {
1159 delay_count = 0;
1160 break;
1161 }
1162 } else {
1163 break;
1164 }
1165 }
1166
1167 btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
1168
1169 return btcoexist->btc_read_4byte(btcoexist, 0x1708);
1170}
1171
1172static void
1173halbtc8822b1ant_ltecoex_indirect_write_reg(struct btc_coexist *btcoexist,
1174 u16 reg_addr, u32 bit_mask,
1175 u32 reg_value)
1176{
1177 u32 val, i = 0, bitpos = 0, delay_count = 0;
1178
1179 if (bit_mask == 0x0)
1180 return;
1181
1182 if (bit_mask == 0xffffffff) {
1183
1184 while (1) {
1185 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703) &
1186 BIT(5)) == 0) {
1187 mdelay(50);
1188 delay_count++;
1189 if (delay_count >= 10) {
1190 delay_count = 0;
1191 break;
1192 }
1193 } else {
1194 break;
1195 }
1196 }
1197
1198 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1199 reg_value);
1200
1201 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1202 0xc00F0000 | reg_addr);
1203 } else {
1204 for (i = 0; i <= 31; i++) {
1205 if (((bit_mask >> i) & 0x1) == 0x1) {
1206 bitpos = i;
1207 break;
1208 }
1209 }
1210
1211
1212 val = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
1213 reg_addr);
1214 val = (val & (~bit_mask)) | (reg_value << bitpos);
1215
1216
1217 while (1) {
1218 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703) &
1219 BIT(5)) == 0) {
1220 mdelay(50);
1221 delay_count++;
1222 if (delay_count >= 10) {
1223 delay_count = 0;
1224 break;
1225 }
1226 } else {
1227 break;
1228 }
1229 }
1230
1231 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1232 val);
1233
1234 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1235 0xc00F0000 | reg_addr);
1236 }
1237}
1238
1239static void halbtc8822b1ant_ltecoex_enable(struct btc_coexist *btcoexist,
1240 bool enable)
1241{
1242 u8 val;
1243
1244 val = (enable) ? 1 : 0;
1245
1246 halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, val);
1247}
1248
1249static void
1250halbtc8822b1ant_ltecoex_pathcontrol_owner(struct btc_coexist *btcoexist,
1251 bool wifi_control)
1252{
1253 u8 val;
1254
1255 val = (wifi_control) ? 1 : 0;
1256
1257 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, val);
1258}
1259
1260static void halbtc8822b1ant_ltecoex_set_gnt_bt(struct btc_coexist *btcoexist,
1261 u8 control_block,
1262 bool sw_control, u8 state)
1263{
1264 u32 val = 0, bit_mask;
1265
1266 state = state & 0x1;
1267
1268
1269
1270
1271 val = (sw_control) ? ((state << 1) | 0x1) : 0;
1272
1273 switch (control_block) {
1274 case BT_8822B_1ANT_GNT_BLOCK_RFC_BB:
1275 default:
1276 bit_mask = 0xc000;
1277 halbtc8822b1ant_ltecoex_indirect_write_reg(
1278 btcoexist, 0x38, bit_mask, val);
1279 bit_mask = 0x0c00;
1280 halbtc8822b1ant_ltecoex_indirect_write_reg(
1281 btcoexist, 0x38, bit_mask, val);
1282 break;
1283 case BT_8822B_1ANT_GNT_BLOCK_RFC:
1284 bit_mask = 0xc000;
1285 halbtc8822b1ant_ltecoex_indirect_write_reg(
1286 btcoexist, 0x38, bit_mask, val);
1287 break;
1288 case BT_8822B_1ANT_GNT_BLOCK_BB:
1289 bit_mask = 0x0c00;
1290 halbtc8822b1ant_ltecoex_indirect_write_reg(
1291 btcoexist, 0x38, bit_mask, val);
1292 break;
1293 }
1294}
1295
1296static void halbtc8822b1ant_ltecoex_set_gnt_wl(struct btc_coexist *btcoexist,
1297 u8 control_block,
1298 bool sw_control, u8 state)
1299{
1300 u32 val = 0, bit_mask;
1301
1302
1303
1304
1305
1306 state = state & 0x1;
1307 val = (sw_control) ? ((state << 1) | 0x1) : 0;
1308
1309 switch (control_block) {
1310 case BT_8822B_1ANT_GNT_BLOCK_RFC_BB:
1311 default:
1312 bit_mask = 0x3000;
1313 halbtc8822b1ant_ltecoex_indirect_write_reg(
1314 btcoexist, 0x38, bit_mask, val);
1315 bit_mask = 0x0300;
1316 halbtc8822b1ant_ltecoex_indirect_write_reg(
1317 btcoexist, 0x38, bit_mask, val);
1318 break;
1319 case BT_8822B_1ANT_GNT_BLOCK_RFC:
1320 bit_mask = 0x3000;
1321 halbtc8822b1ant_ltecoex_indirect_write_reg(
1322 btcoexist, 0x38, bit_mask, val);
1323 break;
1324 case BT_8822B_1ANT_GNT_BLOCK_BB:
1325 bit_mask = 0x0300;
1326 halbtc8822b1ant_ltecoex_indirect_write_reg(
1327 btcoexist, 0x38, bit_mask, val);
1328 break;
1329 }
1330}
1331
1332static void
1333halbtc8822b1ant_ltecoex_set_coex_table(struct btc_coexist *btcoexist,
1334 u8 table_type, u16 table_content)
1335{
1336 u16 reg_addr = 0x0000;
1337
1338 switch (table_type) {
1339 case BT_8822B_1ANT_CTT_WL_VS_LTE:
1340 reg_addr = 0xa0;
1341 break;
1342 case BT_8822B_1ANT_CTT_BT_VS_LTE:
1343 reg_addr = 0xa4;
1344 break;
1345 }
1346
1347 if (reg_addr != 0x0000)
1348 halbtc8822b1ant_ltecoex_indirect_write_reg(
1349 btcoexist, reg_addr, 0xffff,
1350 table_content);
1351}
1352
1353static void halbtc8822b1ant_set_wltoggle_coex_table(
1354 struct btc_coexist *btcoexist, bool force_exec, u8 interval,
1355 u8 val0x6c4_b0, u8 val0x6c4_b1, u8 val0x6c4_b2, u8 val0x6c4_b3)
1356{
1357 static u8 pre_h2c_parameter[6] = {0};
1358 u8 cur_h2c_parameter[6] = {0};
1359 u8 i, match_cnt = 0;
1360
1361 cur_h2c_parameter[0] = 0x7;
1362
1363 cur_h2c_parameter[1] = interval;
1364 cur_h2c_parameter[2] = val0x6c4_b0;
1365 cur_h2c_parameter[3] = val0x6c4_b1;
1366 cur_h2c_parameter[4] = val0x6c4_b2;
1367 cur_h2c_parameter[5] = val0x6c4_b3;
1368
1369 if (!force_exec) {
1370 for (i = 1; i <= 5; i++) {
1371 if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
1372 break;
1373
1374 match_cnt++;
1375 }
1376
1377 if (match_cnt == 5)
1378 return;
1379 }
1380
1381 for (i = 1; i <= 5; i++)
1382 pre_h2c_parameter[i] = cur_h2c_parameter[i];
1383
1384 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter);
1385}
1386
1387static void halbtc8822b1ant_set_coex_table(struct btc_coexist *btcoexist,
1388 u32 val0x6c0, u32 val0x6c4,
1389 u32 val0x6c8, u8 val0x6cc)
1390{
1391 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1392
1393 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1394
1395 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1396
1397 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1398}
1399
1400static void halbtc8822b1ant_coex_table(struct btc_coexist *btcoexist,
1401 bool force_exec, u32 val0x6c0,
1402 u32 val0x6c4, u32 val0x6c8, u8 val0x6cc)
1403{
1404 coex_dm->cur_val0x6c0 = val0x6c0;
1405 coex_dm->cur_val0x6c4 = val0x6c4;
1406 coex_dm->cur_val0x6c8 = val0x6c8;
1407 coex_dm->cur_val0x6cc = val0x6cc;
1408
1409 if (!force_exec) {
1410 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1411 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1412 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1413 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1414 return;
1415 }
1416 halbtc8822b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1417 val0x6cc);
1418
1419 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1420 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1421 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1422 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1423}
1424
1425static void halbtc8822b1ant_coex_table_with_type(struct btc_coexist *btcoexist,
1426 bool force_exec, u8 type)
1427{
1428 u32 break_table;
1429 u8 select_table;
1430
1431 coex_sta->coex_table_type = type;
1432
1433 if (coex_sta->concurrent_rx_mode_on) {
1434 break_table = 0xf0ffffff;
1435 select_table = 0x3;
1436
1437
1438 } else {
1439 break_table = 0xffffff;
1440 select_table = 0x3;
1441 }
1442
1443 switch (type) {
1444 case 0:
1445 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1446 0x55555555, break_table,
1447 select_table);
1448 break;
1449 case 1:
1450 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1451 0x5a5a5a5a, break_table,
1452 select_table);
1453 break;
1454 case 2:
1455 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaa5a5a5a,
1456 0xaa5a5a5a, break_table,
1457 select_table);
1458 break;
1459 case 3:
1460 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1461 0xaa5a5a5a, break_table,
1462 select_table);
1463 break;
1464 case 4:
1465 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaa555555,
1466 0xaa5a5a5a, break_table,
1467 select_table);
1468 break;
1469 case 5:
1470 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
1471 0x5a5a5a5a, break_table,
1472 select_table);
1473 break;
1474 case 6:
1475 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1476 0xaaaaaaaa, break_table,
1477 select_table);
1478 break;
1479 case 7:
1480 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
1481 0xaaaaaaaa, break_table,
1482 select_table);
1483 break;
1484 case 8:
1485 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xffffffff,
1486 0xffffffff, break_table,
1487 select_table);
1488 break;
1489 case 9:
1490 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x5a5a5555,
1491 0xaaaa5a5a, break_table,
1492 select_table);
1493 break;
1494 case 10:
1495 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaaaa5aaa,
1496 0xaaaa5aaa, break_table,
1497 select_table);
1498 break;
1499 case 11:
1500 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaaaaa5aa,
1501 0xaaaaaaaa, break_table,
1502 select_table);
1503 break;
1504 case 12:
1505 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaaaaa5aa,
1506 0xaaaaa5aa, break_table,
1507 select_table);
1508 break;
1509 case 13:
1510 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1511 0xaaaa5a5a, break_table,
1512 select_table);
1513 break;
1514 case 14:
1515 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x5a5a555a,
1516 0xaaaa5a5a, break_table,
1517 select_table);
1518 break;
1519 case 15:
1520 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1521 0xaaaa55aa, break_table,
1522 select_table);
1523 break;
1524 case 16:
1525 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x5a5a555a,
1526 0x5a5a555a, break_table,
1527 select_table);
1528 break;
1529 case 17:
1530 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xaaaa55aa,
1531 0xaaaa55aa, break_table,
1532 select_table);
1533 break;
1534 case 18:
1535 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1536 0x5aaa5a5a, break_table,
1537 select_table);
1538 break;
1539 case 19:
1540 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0xa5555555,
1541 0xaaaa5aaa, break_table,
1542 select_table);
1543 break;
1544 case 20:
1545 halbtc8822b1ant_coex_table(btcoexist, force_exec, 0x55555555,
1546 0xaaaa5aaa, break_table,
1547 select_table);
1548 break;
1549 default:
1550 break;
1551 }
1552}
1553
1554static void
1555halbtc8822b1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
1556 bool enable)
1557{
1558 u8 h2c_parameter[1] = {0};
1559
1560 if (enable)
1561 h2c_parameter[0] |= BIT(0);
1562
1563 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1564}
1565
1566static void halbtc8822b1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
1567 bool force_exec, bool enable)
1568{
1569 coex_dm->cur_ignore_wlan_act = enable;
1570
1571 if (!force_exec) {
1572 if (coex_dm->pre_ignore_wlan_act ==
1573 coex_dm->cur_ignore_wlan_act) {
1574 coex_dm->pre_ignore_wlan_act =
1575 coex_dm->cur_ignore_wlan_act;
1576 return;
1577 }
1578 }
1579
1580 halbtc8822b1ant_set_fw_ignore_wlan_act(btcoexist, enable);
1581
1582 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1583}
1584
1585static void halbtc8822b1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
1586 u8 lps_val, u8 rpwm_val)
1587{
1588 u8 lps = lps_val;
1589 u8 rpwm = rpwm_val;
1590
1591 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1592 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1593}
1594
1595static void halbtc8822b1ant_lps_rpwm(struct btc_coexist *btcoexist,
1596 bool force_exec, u8 lps_val, u8 rpwm_val)
1597{
1598 coex_dm->cur_lps = lps_val;
1599 coex_dm->cur_rpwm = rpwm_val;
1600
1601 if (!force_exec) {
1602 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1603 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1604 return;
1605 }
1606 halbtc8822b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1607
1608 coex_dm->pre_lps = coex_dm->cur_lps;
1609 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1610}
1611
1612static void halbtc8822b1ant_ps_tdma_check_for_power_save_state(
1613 struct btc_coexist *btcoexist, bool new_ps_state)
1614{
1615 u8 lps_mode = 0x0;
1616 u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
1617
1618 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1619
1620 if (lps_mode) {
1621 if (new_ps_state) {
1622
1623 } else {
1624
1625
1626 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1627 h2c_parameter);
1628 }
1629 } else {
1630 if (new_ps_state) {
1631
1632
1633 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1634 h2c_parameter);
1635 } else {
1636
1637 }
1638 }
1639}
1640
1641static bool halbtc8822b1ant_power_save_state(struct btc_coexist *btcoexist,
1642 u8 ps_type, u8 lps_val,
1643 u8 rpwm_val)
1644{
1645 bool low_pwr_disable = false, result = true;
1646
1647 switch (ps_type) {
1648 case BTC_PS_WIFI_NATIVE:
1649
1650 coex_sta->force_lps_ctrl = false;
1651 low_pwr_disable = false;
1652 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1653 &low_pwr_disable);
1654 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1655 break;
1656 case BTC_PS_LPS_ON:
1657
1658 coex_sta->force_lps_ctrl = true;
1659 halbtc8822b1ant_ps_tdma_check_for_power_save_state(btcoexist,
1660 true);
1661 halbtc8822b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
1662 rpwm_val);
1663
1664 low_pwr_disable = true;
1665 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1666 &low_pwr_disable);
1667
1668 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1669
1670 break;
1671 case BTC_PS_LPS_OFF:
1672
1673 coex_sta->force_lps_ctrl = true;
1674 halbtc8822b1ant_ps_tdma_check_for_power_save_state(btcoexist,
1675 false);
1676 result = btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1677 NULL);
1678
1679 break;
1680 default:
1681 break;
1682 }
1683
1684 return result;
1685}
1686
1687static void halbtc8822b1ant_set_fw_pstdma(struct btc_coexist *btcoexist,
1688 u8 byte1, u8 byte2, u8 byte3,
1689 u8 byte4, u8 byte5)
1690{
1691 struct rtl_priv *rtlpriv = btcoexist->adapter;
1692 u8 h2c_parameter[5] = {0};
1693 u8 real_byte1 = byte1, real_byte5 = byte5;
1694 bool ap_enable = false, result = false;
1695 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1696
1697 if (byte5 & BIT(2))
1698 coex_sta->is_tdma_btautoslot = true;
1699 else
1700 coex_sta->is_tdma_btautoslot = false;
1701
1702
1703 if (coex_sta->is_tdma_btautoslot)
1704 if ((coex_sta->is_tdma_btautoslot_hang) ||
1705 (bt_link_info->slave_role))
1706 byte5 = byte5 & 0xfb;
1707
1708 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1709 &ap_enable);
1710
1711 if ((ap_enable) && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
1712 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1713 "[BTCoex], %s == FW for 1Ant AP mode\n", __func__);
1714
1715 real_byte1 &= ~BIT(4);
1716 real_byte1 |= BIT(5);
1717
1718 real_byte5 |= BIT(5);
1719 real_byte5 &= ~BIT(6);
1720
1721 halbtc8822b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1722 0x0, 0x0);
1723
1724 } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1725 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1726 "[BTCoex], %s == Force LPS (byte1 = 0x%x)\n",
1727 __func__, byte1);
1728 if (!halbtc8822b1ant_power_save_state(btcoexist, BTC_PS_LPS_OFF,
1729 0x50, 0x4))
1730 result = true;
1731 } else {
1732 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1733 "[BTCoex], %s == native power save (byte1 = 0x%x)\n",
1734 __func__, byte1);
1735 halbtc8822b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1736 0x0, 0x0);
1737 }
1738
1739 coex_sta->is_set_ps_state_fail = result;
1740
1741 if (!coex_sta->is_set_ps_state_fail) {
1742 h2c_parameter[0] = real_byte1;
1743 h2c_parameter[1] = byte2;
1744 h2c_parameter[2] = byte3;
1745 h2c_parameter[3] = byte4;
1746 h2c_parameter[4] = real_byte5;
1747
1748 coex_dm->ps_tdma_para[0] = real_byte1;
1749 coex_dm->ps_tdma_para[1] = byte2;
1750 coex_dm->ps_tdma_para[2] = byte3;
1751 coex_dm->ps_tdma_para[3] = byte4;
1752 coex_dm->ps_tdma_para[4] = real_byte5;
1753
1754 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1755
1756 } else {
1757 coex_sta->cnt_set_ps_state_fail++;
1758 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1759 "[BTCoex], %s == Force Leave LPS Fail (cnt = %d)\n",
1760 __func__, coex_sta->cnt_set_ps_state_fail);
1761 }
1762}
1763
1764static void halbtc8822b1ant_ps_tdma(struct btc_coexist *btcoexist,
1765 bool force_exec, bool turn_on, u8 type)
1766{
1767 struct rtl_priv *rtlpriv = btcoexist->adapter;
1768 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1769 bool wifi_busy = false;
1770 static u8 ps_tdma_byte4_modify, pre_ps_tdma_byte4_modify;
1771 static bool pre_wifi_busy;
1772
1773 coex_dm->cur_ps_tdma_on = turn_on;
1774 coex_dm->cur_ps_tdma = type;
1775
1776 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1777
1778 if (wifi_busy != pre_wifi_busy) {
1779 force_exec = true;
1780 pre_wifi_busy = wifi_busy;
1781 }
1782
1783
1784 if (bt_link_info->slave_role)
1785 ps_tdma_byte4_modify = 0x1;
1786 else
1787 ps_tdma_byte4_modify = 0x0;
1788
1789 if (pre_ps_tdma_byte4_modify != ps_tdma_byte4_modify) {
1790 force_exec = true;
1791 pre_ps_tdma_byte4_modify = ps_tdma_byte4_modify;
1792 }
1793
1794 if (!force_exec) {
1795 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1796 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) {
1797 RT_TRACE(
1798 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1799 "[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
1800 (coex_dm->cur_ps_tdma_on ? "on" : "off"),
1801 coex_dm->cur_ps_tdma);
1802 return;
1803 }
1804 }
1805
1806 if (coex_dm->cur_ps_tdma_on) {
1807 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1808 "[BTCoex], ********** TDMA(on, %d) **********\n",
1809 coex_dm->cur_ps_tdma);
1810
1811 btcoexist->btc_write_1byte_bitmask(
1812 btcoexist, 0x550, 0x8, 0x1);
1813 } else {
1814 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1815 "[BTCoex], ********** TDMA(off, %d) **********\n",
1816 coex_dm->cur_ps_tdma);
1817 }
1818
1819 if (turn_on) {
1820
1821 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, 0x1);
1822
1823 switch (type) {
1824 default:
1825 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x35,
1826 0x03, 0x11, 0x11);
1827 break;
1828 case 1:
1829 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x3a,
1830 0x03, 0x11, 0x10);
1831 break;
1832 case 3:
1833 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x30,
1834 0x03, 0x10, 0x50);
1835 break;
1836 case 4:
1837 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x21,
1838 0x03, 0x10, 0x50);
1839 break;
1840 case 5:
1841 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x15,
1842 0x3, 0x11, 0x11);
1843 break;
1844 case 6:
1845 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x20,
1846 0x3, 0x11, 0x10);
1847 break;
1848 case 7:
1849 halbtc8822b1ant_set_fw_pstdma(
1850 btcoexist, 0x51, 0x10, 0x03, 0x10,
1851 0x54 | ps_tdma_byte4_modify);
1852 break;
1853 case 8:
1854 halbtc8822b1ant_set_fw_pstdma(
1855 btcoexist, 0x51, 0x10, 0x03, 0x10,
1856 0x14 | ps_tdma_byte4_modify);
1857 break;
1858 case 11:
1859 halbtc8822b1ant_set_fw_pstdma(
1860 btcoexist, 0x61, 0x25, 0x03, 0x11,
1861 0x10 | ps_tdma_byte4_modify);
1862 break;
1863 case 12:
1864 halbtc8822b1ant_set_fw_pstdma(
1865 btcoexist, 0x51, 0x30, 0x03, 0x10,
1866 0x50 | ps_tdma_byte4_modify);
1867 break;
1868 case 13:
1869 halbtc8822b1ant_set_fw_pstdma(
1870 btcoexist, 0x51, 0x10, 0x07, 0x10,
1871 0x54 | ps_tdma_byte4_modify);
1872 break;
1873 case 14:
1874 halbtc8822b1ant_set_fw_pstdma(
1875 btcoexist, 0x51, 0x15, 0x03, 0x10,
1876 0x50 | ps_tdma_byte4_modify);
1877 break;
1878 case 15:
1879 halbtc8822b1ant_set_fw_pstdma(
1880 btcoexist, 0x51, 0x20, 0x03, 0x10,
1881 0x10 | ps_tdma_byte4_modify);
1882 break;
1883 case 17:
1884 halbtc8822b1ant_set_fw_pstdma(
1885 btcoexist, 0x61, 0x10, 0x03, 0x11,
1886 0x14 | ps_tdma_byte4_modify);
1887 break;
1888 case 18:
1889 halbtc8822b1ant_set_fw_pstdma(
1890 btcoexist, 0x51, 0x10, 0x03, 0x10,
1891 0x50 | ps_tdma_byte4_modify);
1892 break;
1893
1894 case 20:
1895 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x30,
1896 0x03, 0x11, 0x10);
1897 break;
1898 case 22:
1899 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x25,
1900 0x03, 0x11, 0x10);
1901 break;
1902 case 27:
1903 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x10,
1904 0x03, 0x11, 0x15);
1905 break;
1906 case 32:
1907 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x35,
1908 0x3, 0x11, 0x11);
1909 break;
1910 case 33:
1911 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x35,
1912 0x03, 0x11, 0x10);
1913 break;
1914 case 41:
1915 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x45,
1916 0x3, 0x11, 0x11);
1917 break;
1918 case 42:
1919 halbtc8822b1ant_set_fw_pstdma(
1920 btcoexist, 0x51, 0x1e, 0x3, 0x10,
1921 0x14 | ps_tdma_byte4_modify);
1922 break;
1923 case 43:
1924 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x45,
1925 0x3, 0x10, 0x14);
1926 break;
1927 case 44:
1928 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x25,
1929 0x3, 0x10, 0x10);
1930 break;
1931 case 45:
1932 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x29,
1933 0x3, 0x10, 0x10);
1934 break;
1935 case 46:
1936 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x1a,
1937 0x3, 0x10, 0x10);
1938 break;
1939 case 47:
1940 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x32,
1941 0x3, 0x10, 0x10);
1942 break;
1943 case 48:
1944 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x29,
1945 0x3, 0x10, 0x10);
1946 break;
1947 case 49:
1948 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x55, 0x10,
1949 0x3, 0x10, 0x54);
1950 break;
1951 case 50:
1952 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x51, 0x4a,
1953 0x3, 0x10, 0x10);
1954 break;
1955 case 51:
1956 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x61, 0x35,
1957 0x3, 0x10, 0x11);
1958 break;
1959 }
1960 } else {
1961 switch (type) {
1962 case 0:
1963 default:
1964 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1965 0x0, 0x0);
1966 break;
1967 case 8:
1968 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x8, 0x0, 0x0,
1969 0x0, 0x0);
1970 break;
1971 case 9:
1972 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1973 0x0, 0x0);
1974 break;
1975 case 10:
1976 halbtc8822b1ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1977 0x0, 0x0);
1978
1979 break;
1980 }
1981 }
1982
1983 if (!coex_sta->is_set_ps_state_fail) {
1984
1985 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1986 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1987 }
1988}
1989
1990static void halbtc8822b1ant_sw_mechanism(struct btc_coexist *btcoexist,
1991 bool low_penalty_ra)
1992{
1993 halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
1994}
1995
1996
1997
1998
1999
2000static void halbtc8822b1ant_set_rfe_type(struct btc_coexist *btcoexist)
2001{
2002 struct btc_board_info *board_info = &btcoexist->board_info;
2003
2004
2005 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2006 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2007 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2008
2009
2010 rfe_type->rfe_module_type = board_info->rfe_type;
2011
2012 rfe_type->ext_ant_switch_ctrl_polarity = 0;
2013
2014 switch (rfe_type->rfe_module_type) {
2015 case 0:
2016 default:
2017 rfe_type->ext_ant_switch_exist = true;
2018 rfe_type->ext_ant_switch_type =
2019 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2020 break;
2021 case 1:
2022 rfe_type->ext_ant_switch_exist = true;
2023 rfe_type->ext_ant_switch_type =
2024 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2025 break;
2026 case 2:
2027 rfe_type->ext_ant_switch_exist = true;
2028 rfe_type->ext_ant_switch_type =
2029 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2030 break;
2031 case 3:
2032 rfe_type->ext_ant_switch_exist = true;
2033 rfe_type->ext_ant_switch_type =
2034 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2035 break;
2036 case 4:
2037 rfe_type->ext_ant_switch_exist = true;
2038 rfe_type->ext_ant_switch_type =
2039 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2040 break;
2041 case 5:
2042 rfe_type->ext_ant_switch_exist = true;
2043 rfe_type->ext_ant_switch_type =
2044 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2045 break;
2046 case 6:
2047 rfe_type->ext_ant_switch_exist = true;
2048 rfe_type->ext_ant_switch_type =
2049 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2050 break;
2051 case 7:
2052 rfe_type->ext_ant_switch_exist = true;
2053 rfe_type->ext_ant_switch_type =
2054 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
2055 break;
2056 }
2057}
2058
2059
2060
2061static void halbtc8822b1ant_set_ext_ant_switch(struct btc_coexist *btcoexist,
2062 bool force_exec, u8 ctrl_type,
2063 u8 pos_type)
2064{
2065 struct rtl_priv *rtlpriv = btcoexist->adapter;
2066 bool switch_polatiry_inverse = false;
2067 u8 regval_0xcbd = 0, regval_0x64;
2068 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
2069
2070
2071 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2072 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2073 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2074
2075 if (!rfe_type->ext_ant_switch_exist)
2076 return;
2077
2078 coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
2079
2080 if (!force_exec) {
2081 if (coex_dm->pre_ext_ant_switch_status ==
2082 coex_dm->cur_ext_ant_switch_status)
2083 return;
2084 }
2085
2086 coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
2087
2088
2089
2090
2091
2092
2093 switch_polatiry_inverse = rfe_type->ext_ant_switch_ctrl_polarity == 1;
2094
2095 switch (pos_type) {
2096 default:
2097 case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT:
2098 case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE:
2099
2100 break;
2101 case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG:
2102 break;
2103 case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA:
2104 break;
2105 }
2106
2107 if (rfe_type->ext_ant_switch_type ==
2108 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT) {
2109 switch (ctrl_type) {
2110 default:
2111 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
2112
2113 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2114 0x80, 0x0);
2115
2116 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2117 0x01, 0x1);
2118
2119 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2120 0xff, 0x77);
2121
2122
2123
2124
2125 regval_0xcbd = (!switch_polatiry_inverse ? 0x1 : 0x2);
2126 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
2127 0x3, regval_0xcbd);
2128
2129 break;
2130 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
2131
2132 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2133 0x80, 0x0);
2134
2135 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2136 0x01, 0x1);
2137
2138 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2139 0xff, 0x66);
2140
2141
2142
2143
2144 regval_0xcbd = (!switch_polatiry_inverse ? 0x2 : 0x1);
2145 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
2146 0x3, regval_0xcbd);
2147
2148 break;
2149 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
2150
2151 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2152 0x80, 0x0);
2153
2154 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2155 0x01, 0x1);
2156 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2157 0xff, 0x88);
2158
2159
2160
2161
2162
2163 break;
2164 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
2165
2166 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2167 0x80, 0x1);
2168
2169
2170
2171
2172 regval_0x64 = (!switch_polatiry_inverse ? 0x0 : 0x1);
2173 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
2174 regval_0x64);
2175 break;
2176 case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
2177
2178 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2179 0x80, 0x0);
2180
2181 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2182 0x01, 0x0);
2183
2184
2185
2186
2187 break;
2188 }
2189 }
2190
2191 u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcbc);
2192 u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2193 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
2194
2195 RT_TRACE(
2196 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2197 "[BTCoex], ********** (After Ext Ant switch setup) 0xcbc = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x**********\n",
2198 u32tmp1, u32tmp2, u32tmp3);
2199}
2200
2201
2202
2203
2204
2205
2206static void halbtc8822b1ant_set_ant_path(struct btc_coexist *btcoexist,
2207 u8 ant_pos_type, bool force_exec,
2208 u8 phase)
2209
2210{
2211 struct rtl_priv *rtlpriv = btcoexist->adapter;
2212 u8 u8tmp = 0;
2213 u32 u32tmp1 = 0;
2214 u32 u32tmp2 = 0, u32tmp3 = 0;
2215
2216 u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
2217
2218
2219 if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) {
2220 force_exec = true;
2221 coex_sta->gnt_error_cnt++;
2222
2223 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2224 "[BTCoex],(Before Ant Setup) 0x38= 0x%x\n", u32tmp1);
2225 }
2226
2227
2228 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2229 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2230 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2231
2232 coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
2233
2234 if (!force_exec) {
2235 if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type)
2236 return;
2237 }
2238
2239 coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
2240
2241 if (btcoexist->dbg_mode_1ant) {
2242 u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
2243 0x38);
2244 u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
2245 0x54);
2246 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2247
2248 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
2249
2250 RT_TRACE(
2251 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2252 "[BTCoex], ********** (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
2253 u32tmp3, u8tmp, u32tmp1, u32tmp2);
2254 }
2255
2256 switch (phase) {
2257 case BT_8822B_1ANT_PHASE_COEX_INIT:
2258 RT_TRACE(
2259 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2260 "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_COEX_INIT) **********\n");
2261
2262
2263
2264
2265 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2266
2267
2268
2269
2270 halbtc8822b1ant_ltecoex_set_coex_table(
2271 btcoexist, BT_8822B_1ANT_CTT_WL_VS_LTE, 0xffff);
2272
2273
2274
2275
2276 halbtc8822b1ant_ltecoex_set_coex_table(
2277 btcoexist, BT_8822B_1ANT_CTT_BT_VS_LTE, 0xffff);
2278
2279
2280 halbtc8822b1ant_ltecoex_set_gnt_bt(
2281 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2282 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2283 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2284
2285
2286 halbtc8822b1ant_ltecoex_set_gnt_wl(
2287 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2288 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2289 BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
2290
2291
2292 halbtc8822b1ant_ltecoex_pathcontrol_owner(
2293 btcoexist, BT_8822B_1ANT_PCO_WLSIDE);
2294
2295 coex_sta->run_time_state = false;
2296
2297
2298 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2299 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2300 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2301
2302 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2303 ant_pos_type = BTC_ANT_PATH_BT;
2304
2305 break;
2306 case BT_8822B_1ANT_PHASE_WLANONLY_INIT:
2307 RT_TRACE(
2308 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2309 "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLANONLY_INIT) **********\n");
2310
2311
2312
2313
2314 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2315
2316
2317
2318
2319 halbtc8822b1ant_ltecoex_set_coex_table(
2320 btcoexist, BT_8822B_1ANT_CTT_WL_VS_LTE, 0xffff);
2321
2322
2323
2324
2325 halbtc8822b1ant_ltecoex_set_coex_table(
2326 btcoexist, BT_8822B_1ANT_CTT_BT_VS_LTE, 0xffff);
2327
2328
2329 halbtc8822b1ant_ltecoex_set_gnt_bt(
2330 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2331 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2332 BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
2333
2334
2335 halbtc8822b1ant_ltecoex_set_gnt_wl(
2336 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2337 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2338 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2339
2340
2341 halbtc8822b1ant_ltecoex_pathcontrol_owner(
2342 btcoexist, BT_8822B_1ANT_PCO_WLSIDE);
2343
2344 coex_sta->run_time_state = false;
2345
2346
2347 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
2348 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
2349 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
2350
2351 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2352 ant_pos_type = BTC_ANT_PATH_WIFI;
2353
2354 break;
2355 case BT_8822B_1ANT_PHASE_WLAN_OFF:
2356 RT_TRACE(
2357 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2358 "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLAN_OFF) **********\n");
2359
2360
2361 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2362
2363
2364 halbtc8822b1ant_ltecoex_pathcontrol_owner(
2365 btcoexist, BT_8822B_1ANT_PCO_BTSIDE);
2366
2367
2368 halbtc8822b1ant_set_ext_ant_switch(
2369 btcoexist, FORCE_EXEC,
2370 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
2371 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
2372
2373 coex_sta->run_time_state = false;
2374
2375 break;
2376 case BT_8822B_1ANT_PHASE_2G_RUNTIME:
2377 RT_TRACE(
2378 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2379 "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_2G_RUNTIME) **********\n");
2380
2381
2382 halbtc8822b1ant_ltecoex_set_gnt_bt(
2383 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2384 BT_8822B_1ANT_GNT_CTRL_BY_PTA,
2385 BT_8822B_1ANT_SIG_STA_SET_BY_HW);
2386
2387
2388 halbtc8822b1ant_ltecoex_set_gnt_wl(
2389 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2390 BT_8822B_1ANT_GNT_CTRL_BY_PTA,
2391 BT_8822B_1ANT_SIG_STA_SET_BY_HW);
2392
2393
2394 halbtc8822b1ant_ltecoex_pathcontrol_owner(
2395 btcoexist, BT_8822B_1ANT_PCO_WLSIDE);
2396
2397 coex_sta->run_time_state = true;
2398
2399 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2400 ant_pos_type = BTC_ANT_PATH_PTA;
2401
2402 break;
2403 case BT_8822B_1ANT_PHASE_5G_RUNTIME:
2404 RT_TRACE(
2405 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2406 "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_5G_RUNTIME) **********\n");
2407
2408
2409 halbtc8822b1ant_ltecoex_set_gnt_bt(
2410 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2411 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2412 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2413
2414
2415 halbtc8822b1ant_ltecoex_set_gnt_wl(
2416 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2417 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2418 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2419
2420
2421 halbtc8822b1ant_ltecoex_pathcontrol_owner(
2422 btcoexist, BT_8822B_1ANT_PCO_WLSIDE);
2423
2424 coex_sta->run_time_state = true;
2425
2426 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2427 ant_pos_type = BTC_ANT_PATH_WIFI5G;
2428
2429 break;
2430 case BT_8822B_1ANT_PHASE_BTMPMODE:
2431 RT_TRACE(
2432 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2433 "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_BTMPMODE) **********\n");
2434
2435
2436 halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
2437
2438
2439 halbtc8822b1ant_ltecoex_set_gnt_bt(
2440 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2441 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2442 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
2443
2444
2445 halbtc8822b1ant_ltecoex_set_gnt_wl(
2446 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
2447 BT_8822B_1ANT_GNT_CTRL_BY_SW,
2448 BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
2449
2450
2451 halbtc8822b1ant_ltecoex_pathcontrol_owner(
2452 btcoexist, BT_8822B_1ANT_PCO_WLSIDE);
2453
2454 coex_sta->run_time_state = false;
2455
2456
2457 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2458 ant_pos_type = BTC_ANT_PATH_BT;
2459
2460 break;
2461 }
2462
2463 if (phase != BT_8822B_1ANT_PHASE_WLAN_OFF) {
2464 switch (ant_pos_type) {
2465 case BTC_ANT_PATH_WIFI:
2466 halbtc8822b1ant_set_ext_ant_switch(
2467 btcoexist, force_exec,
2468 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2469 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG);
2470 break;
2471 case BTC_ANT_PATH_WIFI5G:
2472 halbtc8822b1ant_set_ext_ant_switch(
2473 btcoexist, force_exec,
2474 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2475 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA);
2476 break;
2477 case BTC_ANT_PATH_BT:
2478 halbtc8822b1ant_set_ext_ant_switch(
2479 btcoexist, force_exec,
2480 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2481 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT);
2482 break;
2483 default:
2484 case BTC_ANT_PATH_PTA:
2485 halbtc8822b1ant_set_ext_ant_switch(
2486 btcoexist, force_exec,
2487 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA,
2488 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
2489 break;
2490 }
2491 }
2492
2493 if (btcoexist->dbg_mode_1ant) {
2494 u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
2495 0x38);
2496 u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
2497 0x54);
2498 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2499
2500 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
2501
2502 RT_TRACE(
2503 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2504 "[BTCoex], ********** (After Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
2505 u32tmp3, u8tmp, u32tmp1, u32tmp2);
2506 }
2507}
2508
2509static bool halbtc8822b1ant_is_common_action(struct btc_coexist *btcoexist)
2510{
2511 struct rtl_priv *rtlpriv = btcoexist->adapter;
2512 bool common = false, wifi_connected = false, wifi_busy = false;
2513
2514 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2515 &wifi_connected);
2516 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2517
2518 if (!wifi_connected &&
2519 coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE) {
2520 RT_TRACE(
2521 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2522 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
2523
2524
2525
2526 common = true;
2527 } else if (wifi_connected &&
2528 (coex_dm->bt_status ==
2529 BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE)) {
2530 RT_TRACE(
2531 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2532 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
2533
2534
2535
2536 common = true;
2537 } else if (!wifi_connected && (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE ==
2538 coex_dm->bt_status)) {
2539 RT_TRACE(
2540 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2541 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
2542
2543
2544
2545 common = true;
2546 } else if (wifi_connected && (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE ==
2547 coex_dm->bt_status)) {
2548 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2549 "[BTCoex], Wifi connected + BT connected-idle!!\n");
2550
2551
2552
2553 common = true;
2554 } else if (!wifi_connected && (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE !=
2555 coex_dm->bt_status)) {
2556 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2557 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
2558
2559
2560
2561 common = true;
2562 } else {
2563 if (wifi_busy) {
2564 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2565 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
2566 } else {
2567 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2568 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
2569 }
2570
2571 common = false;
2572 }
2573
2574 return common;
2575}
2576
2577static void halbtc8822b1ant_action_wifi_under5g(struct btc_coexist *btcoexist)
2578{
2579 struct rtl_priv *rtlpriv = btcoexist->adapter;
2580
2581 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2582 "[BTCoex], under 5g start\n");
2583
2584
2585 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
2586 BT_8822B_1ANT_PHASE_5G_RUNTIME);
2587
2588 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2589 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2590 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 1);
2591}
2592
2593static void halbtc8822b1ant_action_wifi_only(struct btc_coexist *btcoexist)
2594{
2595 struct rtl_priv *rtlpriv = btcoexist->adapter;
2596 bool wifi_under_5g = false, rf4ce_enabled = false;
2597
2598 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2599 if (wifi_under_5g) {
2600 halbtc8822b1ant_action_wifi_under5g(btcoexist);
2601
2602 RT_TRACE(
2603 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2604 "[BTCoex], ********** (wlan only -- under 5g ) **********\n");
2605 return;
2606 }
2607
2608 if (rf4ce_enabled) {
2609 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
2610
2611 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 50);
2612
2613 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2614 return;
2615 }
2616 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2617 halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2618
2619 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
2620 BT_8822B_1ANT_PHASE_2G_RUNTIME);
2621
2622 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2623 "[BTCoex], ********** (wlan only -- under 2g ) **********\n");
2624}
2625
2626static void
2627halbtc8822b1ant_action_wifi_native_lps(struct btc_coexist *btcoexist)
2628{
2629 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2630
2631 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2632}
2633
2634
2635
2636
2637
2638
2639
2640static void halbtc8822b1ant_action_bt_whck_test(struct btc_coexist *btcoexist)
2641{
2642 struct rtl_priv *rtlpriv = btcoexist->adapter;
2643
2644 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2645 "[BTCoex],action_bt_whck_test\n");
2646
2647 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2648
2649 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
2650 BT_8822B_1ANT_PHASE_2G_RUNTIME);
2651
2652 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2653}
2654
2655static void
2656halbtc8822b1ant_action_wifi_multi_port(struct btc_coexist *btcoexist)
2657{
2658 struct rtl_priv *rtlpriv = btcoexist->adapter;
2659
2660 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2661 "[BTCoex],action_wifi_multi_port\n");
2662
2663 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2664
2665 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
2666 BT_8822B_1ANT_PHASE_2G_RUNTIME);
2667
2668 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2669}
2670
2671static void halbtc8822b1ant_action_hs(struct btc_coexist *btcoexist)
2672{
2673 struct rtl_priv *rtlpriv = btcoexist->adapter;
2674
2675 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], action_hs\n");
2676
2677 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2678
2679 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
2680 BT_8822B_1ANT_PHASE_2G_RUNTIME);
2681
2682 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2683}
2684
2685static void halbtc8822b1ant_action_bt_relink(struct btc_coexist *btcoexist)
2686{
2687 struct rtl_priv *rtlpriv = btcoexist->adapter;
2688
2689 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2690 "[BTCoex], run bt multi link function\n");
2691
2692 if (coex_sta->is_bt_multi_link)
2693 return;
2694 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2695 "[BTCoex], run bt_re-link function\n");
2696
2697 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2698 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2699}
2700
2701
2702
2703static void halbtc8822b1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
2704{
2705 struct rtl_priv *rtlpriv = btcoexist->adapter;
2706 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2707 bool wifi_connected = false, ap_enable = false, wifi_busy = false,
2708 bt_busy = false, rf4ce_enabled = false;
2709
2710 bool wifi_scan = false, link = false, roam = false;
2711
2712 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2713 "[BTCoex], ********** (bt inquiry) **********\n");
2714 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2715 &ap_enable);
2716 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2717 &wifi_connected);
2718 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2719 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
2720
2721 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
2722 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2723 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2724
2725 RT_TRACE(
2726 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2727 "[BTCoex], ********** scan = %d, link =%d, roam = %d**********\n",
2728 wifi_scan, link, roam);
2729
2730 if ((link) || (roam) || (coex_sta->wifi_is_high_pri_task)) {
2731 RT_TRACE(
2732 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2733 "[BTCoex], ********** (bt inquiry wifi connect or scan ) **********\n");
2734
2735 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
2736
2737 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2738
2739 } else if ((wifi_scan) && (coex_sta->bt_create_connection)) {
2740 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2741 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2742
2743 } else if ((!wifi_connected) && (!wifi_scan)) {
2744 RT_TRACE(
2745 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2746 "[BTCoex], ********** (bt inquiry wifi non connect) **********\n");
2747
2748 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2749
2750 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2751
2752 } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) {
2753 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2754 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2755 } else if (bt_link_info->a2dp_exist) {
2756 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2757
2758 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
2759 } else if (wifi_scan) {
2760 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
2761
2762 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2763 } else if (wifi_busy) {
2764
2765 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2766
2767 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2768 15);
2769 if (rf4ce_enabled) {
2770 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e,
2771 0x8, 0x1);
2772
2773 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2774 50);
2775
2776 halbtc8822b1ant_coex_table_with_type(btcoexist,
2777 NORMAL_EXEC, 0);
2778 }
2779 } else {
2780 RT_TRACE(
2781 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2782 "[BTCoex], ********** (bt inquiry wifi connect) **********\n");
2783
2784 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2785
2786 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
2787 NORMAL_EXEC,
2788 BT_8822B_1ANT_PHASE_2G_RUNTIME);
2789
2790 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2791 }
2792}
2793
2794static void
2795halbtc8822b1ant_action_bt_sco_hid_only_busy(struct btc_coexist *btcoexist)
2796{
2797 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2798 bool wifi_connected = false, wifi_busy = false;
2799 u32 wifi_bw = 1;
2800
2801 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2802 &wifi_connected);
2803
2804 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2805
2806 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2807
2808 if (bt_link_info->sco_exist) {
2809 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2810 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2811 } else {
2812 if (coex_sta->is_hid_low_pri_tx_overhead) {
2813 halbtc8822b1ant_coex_table_with_type(btcoexist,
2814 NORMAL_EXEC, 6);
2815 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2816 18);
2817 } else if (wifi_bw == 0) {
2818
2819 if (coex_sta->is_bt_multi_link) {
2820 halbtc8822b1ant_coex_table_with_type(
2821 btcoexist, NORMAL_EXEC, 11);
2822 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2823 true, 11);
2824 } else {
2825 halbtc8822b1ant_coex_table_with_type(
2826 btcoexist, NORMAL_EXEC, 6);
2827 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2828 true, 11);
2829 }
2830 } else {
2831 halbtc8822b1ant_coex_table_with_type(btcoexist,
2832 NORMAL_EXEC, 6);
2833 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2834 11);
2835 }
2836 }
2837}
2838
2839static void
2840halbtc8822b1ant_action_wifi_connected_bt_acl_busy(struct btc_coexist *btcoexist)
2841{
2842 struct rtl_priv *rtlpriv = btcoexist->adapter;
2843 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2844 bool wifi_busy = false, wifi_turbo = false;
2845 u32 wifi_bw = 1;
2846
2847 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2848
2849 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2850 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2851 &coex_sta->scan_ap_num);
2852 RT_TRACE(
2853 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2854 "############# [BTCoex], scan_ap_num = %d, wl_noisy_level = %d\n",
2855 coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
2856
2857 if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
2858 wifi_turbo = true;
2859
2860 if ((coex_sta->bt_relink_downcount != 0) &&
2861 (!bt_link_info->pan_exist) && (wifi_busy)) {
2862 RT_TRACE(
2863 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2864 "############# [BTCoex], BT Re-Link + A2DP + WL busy\n");
2865
2866 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2867 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2868
2869 } else if ((bt_link_info->a2dp_exist) && (coex_sta->is_bt_a2dp_sink)) {
2870 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
2871 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
2872 } else if (bt_link_info->a2dp_only) {
2873
2874 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
2875
2876 if (wifi_turbo)
2877 halbtc8822b1ant_coex_table_with_type(btcoexist,
2878 NORMAL_EXEC, 19);
2879 else
2880 halbtc8822b1ant_coex_table_with_type(btcoexist,
2881 NORMAL_EXEC, 4);
2882 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
2883 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
2884 bt_link_info->pan_exist)) {
2885
2886
2887 if (wifi_busy)
2888 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2889 13);
2890 else
2891 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2892 14);
2893
2894 if (bt_link_info->hid_exist)
2895 halbtc8822b1ant_coex_table_with_type(btcoexist,
2896 NORMAL_EXEC, 1);
2897 else if (wifi_turbo)
2898 halbtc8822b1ant_coex_table_with_type(btcoexist,
2899 NORMAL_EXEC, 19);
2900 else
2901 halbtc8822b1ant_coex_table_with_type(btcoexist,
2902 NORMAL_EXEC, 4);
2903 } else if (bt_link_info->hid_exist &&
2904 bt_link_info->a2dp_exist) {
2905
2906 if (wifi_bw == 0) {
2907 halbtc8822b1ant_coex_table_with_type(btcoexist,
2908 NORMAL_EXEC, 1);
2909 halbtc8822b1ant_set_wltoggle_coex_table(
2910 btcoexist, NORMAL_EXEC, 1, 0xaa, 0x5a, 0xaa,
2911 0xaa);
2912 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2913 49);
2914 } else {
2915 halbtc8822b1ant_coex_table_with_type(btcoexist,
2916 NORMAL_EXEC, 1);
2917 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC,
2918 false, true, 8);
2919 halbtc8822b1ant_set_wltoggle_coex_table(
2920 btcoexist, NORMAL_EXEC, 1, 0xaa, 0x5a, 0xaa,
2921 0xaa);
2922 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2923 49);
2924 }
2925
2926
2927 } else if ((bt_link_info->pan_only) ||
2928 (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
2929 if (!wifi_busy)
2930 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2931 4);
2932 else
2933 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2934 3);
2935
2936 if (bt_link_info->hid_exist)
2937 halbtc8822b1ant_coex_table_with_type(btcoexist,
2938 NORMAL_EXEC, 1);
2939 else if (wifi_turbo)
2940 halbtc8822b1ant_coex_table_with_type(btcoexist,
2941 NORMAL_EXEC, 19);
2942 else
2943 halbtc8822b1ant_coex_table_with_type(btcoexist,
2944 NORMAL_EXEC, 4);
2945 } else {
2946
2947 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
2948 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2949 }
2950}
2951
2952
2953
2954static void
2955halbtc8822b1ant_action_wifi_not_connected(struct btc_coexist *btcoexist)
2956{
2957 struct rtl_priv *rtlpriv = btcoexist->adapter;
2958 bool rf4ce_enabled = false;
2959
2960 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2961 "[BTCoex], ********** (wifi not connect) **********\n");
2962
2963
2964 if (rf4ce_enabled) {
2965 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
2966
2967 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 50);
2968
2969 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2970 return;
2971 }
2972 halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2973
2974 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
2975 BT_8822B_1ANT_PHASE_2G_RUNTIME);
2976
2977 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2978}
2979
2980
2981static void
2982halbtc8822b1ant_action_wifi_not_connected_scan(struct btc_coexist *btcoexist)
2983{
2984 struct rtl_priv *rtlpriv = btcoexist->adapter;
2985 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2986 bool bt_hs_on = false;
2987 u32 wifi_link_status = 0;
2988 u32 num_of_wifi_link = 0;
2989 bool bt_ctrl_agg_buf_size = false;
2990 u8 agg_buf_size = 5;
2991
2992 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2993 "[BTCoex], ********** (wifi non connect scan) **********\n");
2994
2995 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2996 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2997 &wifi_link_status);
2998
2999 num_of_wifi_link = wifi_link_status >> 16;
3000
3001 if (num_of_wifi_link >= 2) {
3002 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3003 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3004 bt_ctrl_agg_buf_size, agg_buf_size);
3005
3006 if (coex_sta->c2h_bt_inquiry_page) {
3007 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3008 "############# [BTCoex], BT Is Inquirying\n");
3009 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3010 } else {
3011 halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3012 }
3013 return;
3014 }
3015
3016 if (coex_sta->c2h_bt_inquiry_page) {
3017 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3018 return;
3019 } else if (bt_hs_on) {
3020 halbtc8822b1ant_action_hs(btcoexist);
3021 return;
3022 }
3023
3024
3025 if (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) {
3026 if (bt_link_info->a2dp_exist) {
3027 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3028 32);
3029 halbtc8822b1ant_coex_table_with_type(btcoexist,
3030 NORMAL_EXEC, 1);
3031 } else if (bt_link_info->a2dp_exist &&
3032 bt_link_info->pan_exist) {
3033 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3034 22);
3035 halbtc8822b1ant_coex_table_with_type(btcoexist,
3036 NORMAL_EXEC, 1);
3037 } else {
3038 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3039 20);
3040 halbtc8822b1ant_coex_table_with_type(btcoexist,
3041 NORMAL_EXEC, 1);
3042 }
3043 } else if ((coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_SCO_BUSY) ||
3044 (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3045 coex_dm->bt_status)) {
3046 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist);
3047 } else {
3048 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3049
3050 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3051 NORMAL_EXEC,
3052 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3053
3054 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3055 }
3056}
3057
3058
3059
3060static void halbtc8822b1ant_action_wifi_not_connected_asso_auth(
3061 struct btc_coexist *btcoexist)
3062{
3063 struct rtl_priv *rtlpriv = btcoexist->adapter;
3064 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3065 bool bt_hs_on = false;
3066 u32 wifi_link_status = 0;
3067 u32 num_of_wifi_link = 0;
3068 bool bt_ctrl_agg_buf_size = false;
3069 u8 agg_buf_size = 5;
3070
3071 RT_TRACE(
3072 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3073 "[BTCoex], ********** (wifi non connect asso_auth) **********\n");
3074
3075 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3076 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3077 &wifi_link_status);
3078
3079 num_of_wifi_link = wifi_link_status >> 16;
3080
3081 if (num_of_wifi_link >= 2) {
3082 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3083 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3084 bt_ctrl_agg_buf_size, agg_buf_size);
3085
3086 if (coex_sta->c2h_bt_inquiry_page) {
3087 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3088 "############# [BTCoex], BT Is Inquirying\n");
3089 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3090 } else {
3091 halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3092 }
3093 return;
3094 }
3095
3096 if (coex_sta->c2h_bt_inquiry_page) {
3097 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3098 return;
3099 } else if (bt_hs_on) {
3100 halbtc8822b1ant_action_hs(btcoexist);
3101 return;
3102 }
3103
3104
3105 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
3106 (bt_link_info->a2dp_exist)) {
3107 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
3108 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
3109 } else if (bt_link_info->pan_exist) {
3110 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
3111 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
3112 } else {
3113 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3114
3115 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3116 NORMAL_EXEC,
3117 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3118
3119 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
3120 }
3121}
3122
3123
3124
3125static void
3126halbtc8822b1ant_action_wifi_connected_scan(struct btc_coexist *btcoexist)
3127{
3128 struct rtl_priv *rtlpriv = btcoexist->adapter;
3129 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3130 bool bt_hs_on = false;
3131 u32 wifi_link_status = 0;
3132 u32 num_of_wifi_link = 0;
3133 bool bt_ctrl_agg_buf_size = false;
3134 u8 agg_buf_size = 5;
3135
3136 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3137 "[BTCoex], ********** (wifi connect scan) **********\n");
3138
3139 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3140 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3141 &wifi_link_status);
3142
3143 num_of_wifi_link = wifi_link_status >> 16;
3144
3145 if (num_of_wifi_link >= 2) {
3146 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3147 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3148 bt_ctrl_agg_buf_size, agg_buf_size);
3149
3150 if (coex_sta->c2h_bt_inquiry_page) {
3151 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3152 "############# [BTCoex], BT Is Inquirying\n");
3153 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3154 } else {
3155 halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3156 }
3157 return;
3158 }
3159
3160 if (coex_sta->c2h_bt_inquiry_page) {
3161 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3162 return;
3163 } else if (bt_hs_on) {
3164 halbtc8822b1ant_action_hs(btcoexist);
3165 return;
3166 }
3167
3168
3169 if (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) {
3170 if (bt_link_info->a2dp_exist) {
3171 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3172 32);
3173 halbtc8822b1ant_coex_table_with_type(btcoexist,
3174 NORMAL_EXEC, 1);
3175 } else if (bt_link_info->a2dp_exist &&
3176 bt_link_info->pan_exist) {
3177 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3178 22);
3179 halbtc8822b1ant_coex_table_with_type(btcoexist,
3180 NORMAL_EXEC, 1);
3181 } else {
3182 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3183 20);
3184 halbtc8822b1ant_coex_table_with_type(btcoexist,
3185 NORMAL_EXEC, 1);
3186 }
3187 } else if ((coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_SCO_BUSY) ||
3188 (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3189 coex_dm->bt_status)) {
3190 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist);
3191 } else {
3192 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3193
3194 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3195 NORMAL_EXEC,
3196 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3197
3198 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
3199 }
3200}
3201
3202
3203
3204static void halbtc8822b1ant_action_wifi_connected_specific_packet(
3205 struct btc_coexist *btcoexist)
3206{
3207 struct rtl_priv *rtlpriv = btcoexist->adapter;
3208 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3209 bool bt_hs_on = false;
3210 u32 wifi_link_status = 0;
3211 u32 num_of_wifi_link = 0;
3212 bool bt_ctrl_agg_buf_size = false;
3213 u8 agg_buf_size = 5;
3214 bool wifi_busy = false;
3215
3216 RT_TRACE(
3217 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3218 "[BTCoex], ********** (wifi connect specific packet) **********\n");
3219
3220 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3221 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3222 &wifi_link_status);
3223
3224 num_of_wifi_link = wifi_link_status >> 16;
3225
3226 if (num_of_wifi_link >= 2) {
3227 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3228 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3229 bt_ctrl_agg_buf_size, agg_buf_size);
3230
3231 if (coex_sta->c2h_bt_inquiry_page) {
3232 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3233 "############# [BTCoex], BT Is Inquirying\n");
3234 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3235 } else {
3236 halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3237 }
3238 return;
3239 }
3240
3241 if (coex_sta->c2h_bt_inquiry_page) {
3242 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3243 return;
3244 } else if (bt_hs_on) {
3245 halbtc8822b1ant_action_hs(btcoexist);
3246 return;
3247 }
3248
3249 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3250
3251
3252 if ((wifi_busy) &&
3253 ((bt_link_info->pan_exist) || (coex_sta->num_of_profile >= 2)))
3254 return;
3255
3256
3257 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
3258 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
3259 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3260 } else if (bt_link_info->a2dp_exist) {
3261 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
3262
3263 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3264 15);
3265 } else if (bt_link_info->pan_exist) {
3266 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
3267 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3268 } else {
3269 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
3270
3271 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3272 NORMAL_EXEC,
3273 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3274
3275 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3276 }
3277}
3278
3279
3280
3281
3282
3283static void halbtc8822b1ant_action_wifi_connected(struct btc_coexist *btcoexist)
3284{
3285 struct rtl_priv *rtlpriv = btcoexist->adapter;
3286 bool wifi_busy = false, rf4ce_enabled = false;
3287 bool scan = false, link = false, roam = false;
3288 bool under_4way = false, ap_enable = false, wifi_under_5g = false;
3289 u8 wifi_rssi_state;
3290
3291 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3292 "[BTCoex], CoexForWifiConnect()===>\n");
3293
3294 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3295
3296 if (wifi_under_5g) {
3297 RT_TRACE(
3298 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3299 "[BTCoex], CoexForWifiConnect(), return for wifi is under 5g<===\n");
3300
3301 halbtc8822b1ant_action_wifi_under5g(btcoexist);
3302
3303 return;
3304 }
3305
3306 RT_TRACE(
3307 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3308 "[BTCoex], CoexForWifiConnect(), return for wifi is under 2g<===\n");
3309
3310 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3311 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3312
3313 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
3314 &under_4way);
3315
3316 if (under_4way) {
3317 halbtc8822b1ant_action_wifi_connected_specific_packet(
3318 btcoexist);
3319 RT_TRACE(
3320 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3321 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
3322 return;
3323 }
3324
3325 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3326 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3327 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3328 if (scan || link || roam) {
3329 if (scan)
3330 halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
3331 else
3332 halbtc8822b1ant_action_wifi_connected_specific_packet(
3333 btcoexist);
3334 RT_TRACE(
3335 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3336 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
3337 return;
3338 }
3339
3340 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3341 &ap_enable);
3342 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3343
3344
3345 if (!wifi_busy) {
3346 if (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) {
3347 halbtc8822b1ant_action_wifi_connected_bt_acl_busy(
3348 btcoexist);
3349 } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY ==
3350 coex_dm->bt_status) ||
3351 (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3352 coex_dm->bt_status)) {
3353 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist);
3354 } else {
3355 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3356 8);
3357
3358 halbtc8822b1ant_set_ant_path(
3359 btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3360 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3361
3362 if ((coex_sta->high_priority_tx) +
3363 (coex_sta->high_priority_rx) <=
3364 60)
3365
3366 halbtc8822b1ant_coex_table_with_type(
3367 btcoexist, NORMAL_EXEC, 1);
3368 else
3369 halbtc8822b1ant_coex_table_with_type(
3370 btcoexist, NORMAL_EXEC, 1);
3371 }
3372 } else {
3373 if (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) {
3374 halbtc8822b1ant_action_wifi_connected_bt_acl_busy(
3375 btcoexist);
3376 } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY ==
3377 coex_dm->bt_status) ||
3378 (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
3379 coex_dm->bt_status)) {
3380 halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist);
3381 } else {
3382 if (rf4ce_enabled) {
3383 btcoexist->btc_write_1byte_bitmask(
3384 btcoexist, 0x45e, 0x8, 0x1);
3385
3386 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
3387 true, 50);
3388
3389 halbtc8822b1ant_coex_table_with_type(
3390 btcoexist, NORMAL_EXEC, 1);
3391 return;
3392 }
3393
3394 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3395 8);
3396
3397 halbtc8822b1ant_set_ant_path(
3398 btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3399 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3400
3401 wifi_rssi_state = halbtc8822b1ant_wifi_rssi_state(
3402 btcoexist, 1, 2, 25, 0);
3403
3404 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3405 "[BTCoex], ********** before **********\n");
3406 if (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3407 coex_dm->bt_status) {
3408 if (rf4ce_enabled) {
3409 btcoexist->btc_write_1byte_bitmask(
3410 btcoexist, 0x45e, 0x8, 0x1);
3411
3412 halbtc8822b1ant_ps_tdma(btcoexist,
3413 NORMAL_EXEC,
3414 true, 50);
3415
3416 halbtc8822b1ant_coex_table_with_type(
3417 btcoexist, NORMAL_EXEC, 1);
3418 return;
3419 }
3420
3421 halbtc8822b1ant_coex_table_with_type(
3422 btcoexist, NORMAL_EXEC, 1);
3423 } else {
3424 halbtc8822b1ant_coex_table_with_type(
3425 btcoexist, NORMAL_EXEC, 1);
3426 }
3427 }
3428 }
3429}
3430
3431static void
3432halbtc8822b1ant_run_sw_coexist_mechanism(struct btc_coexist *btcoexist)
3433{
3434 struct rtl_priv *rtlpriv = btcoexist->adapter;
3435 u8 algorithm = 0;
3436
3437 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3438 "[BTCoex], ********** (run sw coexmech) **********\n");
3439 algorithm = halbtc8822b1ant_action_algorithm(btcoexist);
3440 coex_dm->cur_algorithm = algorithm;
3441
3442 if (halbtc8822b1ant_is_common_action(btcoexist)) {
3443 } else {
3444 switch (coex_dm->cur_algorithm) {
3445 case BT_8822B_1ANT_COEX_ALGO_SCO:
3446 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3447 "[BTCoex], Action algorithm = SCO.\n");
3448 break;
3449 case BT_8822B_1ANT_COEX_ALGO_HID:
3450 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3451 "[BTCoex], Action algorithm = HID.\n");
3452 break;
3453 case BT_8822B_1ANT_COEX_ALGO_A2DP:
3454 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3455 "[BTCoex], Action algorithm = A2DP.\n");
3456 break;
3457 case BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS:
3458 RT_TRACE(
3459 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3460 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
3461 break;
3462 case BT_8822B_1ANT_COEX_ALGO_PANEDR:
3463 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3464 "[BTCoex], Action algorithm = PAN(EDR).\n");
3465 break;
3466 case BT_8822B_1ANT_COEX_ALGO_PANHS:
3467 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3468 "[BTCoex], Action algorithm = HS mode.\n");
3469 break;
3470 case BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP:
3471 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3472 "[BTCoex], Action algorithm = PAN+A2DP.\n");
3473 break;
3474 case BT_8822B_1ANT_COEX_ALGO_PANEDR_HID:
3475 RT_TRACE(
3476 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3477 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
3478 break;
3479 case BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
3480 RT_TRACE(
3481 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3482 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
3483 break;
3484 case BT_8822B_1ANT_COEX_ALGO_HID_A2DP:
3485 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3486 "[BTCoex], Action algorithm = HID+A2DP.\n");
3487 break;
3488 default:
3489 RT_TRACE(
3490 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3491 "[BTCoex], Action algorithm = coexist All Off!!\n");
3492 break;
3493 }
3494 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3495 }
3496}
3497
3498static void halbtc8822b1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3499{
3500 struct rtl_priv *rtlpriv = btcoexist->adapter;
3501 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3502 bool wifi_connected = false, bt_hs_on = false;
3503 bool increase_scan_dev_num = false;
3504 bool bt_ctrl_agg_buf_size = false;
3505 bool miracast_plus_bt = false;
3506 u8 agg_buf_size = 5;
3507 u32 wifi_link_status = 0;
3508 u32 num_of_wifi_link = 0, wifi_bw;
3509 u8 iot_peer = BTC_IOT_PEER_UNKNOWN;
3510 bool wifi_under_5g = false;
3511
3512 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3513 "[BTCoex], RunCoexistMechanism()===>\n");
3514
3515 if (btcoexist->manual_control) {
3516 RT_TRACE(
3517 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3518 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3519 return;
3520 }
3521
3522 if (btcoexist->stop_coex_dm) {
3523 RT_TRACE(
3524 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3525 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3526 return;
3527 }
3528
3529 if (coex_sta->under_ips) {
3530 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3531 "[BTCoex], wifi is under IPS !!!\n");
3532 return;
3533 }
3534
3535 if ((coex_sta->under_lps) &&
3536 (coex_dm->bt_status != BT_8822B_1ANT_BT_STATUS_ACL_BUSY)) {
3537 RT_TRACE(
3538 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3539 "[BTCoex], RunCoexistMechanism(), wifi is under LPS !!!\n");
3540 halbtc8822b1ant_action_wifi_native_lps(btcoexist);
3541 return;
3542 }
3543
3544 if (!coex_sta->run_time_state) {
3545 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3546 "[BTCoex], return for run_time_state = false !!!\n");
3547 return;
3548 }
3549
3550 if (coex_sta->freeze_coexrun_by_btinfo) {
3551 RT_TRACE(
3552 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3553 "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n");
3554 return;
3555 }
3556
3557 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3558 if (wifi_under_5g) {
3559 halbtc8822b1ant_action_wifi_under5g(btcoexist);
3560
3561 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3562 "[BTCoex], WiFi is under 5G!!!\n");
3563 return;
3564 }
3565
3566 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3567 "[BTCoex], WiFi is under 2G!!!\n");
3568
3569 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3570 BT_8822B_1ANT_PHASE_2G_RUNTIME);
3571
3572 if (coex_sta->bt_whck_test) {
3573 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3574 "[BTCoex], BT is under WHCK TEST!!!\n");
3575 halbtc8822b1ant_action_bt_whck_test(btcoexist);
3576 return;
3577 }
3578
3579 if (coex_sta->bt_disabled) {
3580 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3581 "[BTCoex], BT is disabled !!!\n");
3582 halbtc8822b1ant_action_wifi_only(btcoexist);
3583 return;
3584 }
3585
3586 if (coex_sta->is_setup_link) {
3587 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3588 "[BTCoex], BT is re-link !!!\n");
3589 halbtc8822b1ant_action_bt_relink(btcoexist);
3590 return;
3591 }
3592
3593 if ((coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) ||
3594 (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_SCO_BUSY) ||
3595 (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY))
3596 increase_scan_dev_num = true;
3597
3598 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
3599 &increase_scan_dev_num);
3600 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3601 &wifi_connected);
3602
3603 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3604 &wifi_link_status);
3605 num_of_wifi_link = wifi_link_status >> 16;
3606
3607 if ((num_of_wifi_link >= 2) ||
3608 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3609 RT_TRACE(
3610 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3611 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3612 num_of_wifi_link, wifi_link_status);
3613
3614 if (bt_link_info->bt_link_exist) {
3615 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
3616 0, 1);
3617 miracast_plus_bt = true;
3618 } else {
3619 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
3620 0, 0);
3621 miracast_plus_bt = false;
3622 }
3623 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3624 &miracast_plus_bt);
3625 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3626 bt_ctrl_agg_buf_size, agg_buf_size);
3627
3628 if ((bt_link_info->a2dp_exist) &&
3629 (coex_sta->c2h_bt_inquiry_page)) {
3630 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3631 "############# [BTCoex], BT Is Inquirying\n");
3632 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3633 } else {
3634 halbtc8822b1ant_action_wifi_multi_port(btcoexist);
3635 }
3636
3637 return;
3638 }
3639
3640 miracast_plus_bt = false;
3641 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3642 &miracast_plus_bt);
3643
3644 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3645
3646 if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
3647 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
3648
3649 btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
3650
3651 if (iot_peer != BTC_IOT_PEER_CISCO) {
3652 if (bt_link_info->sco_exist)
3653 halbtc8822b1ant_limited_rx(btcoexist,
3654 NORMAL_EXEC, true,
3655 false, 0x5);
3656 else
3657 halbtc8822b1ant_limited_rx(btcoexist,
3658 NORMAL_EXEC, false,
3659 false, 0x5);
3660 } else {
3661 if (bt_link_info->sco_exist) {
3662 halbtc8822b1ant_limited_rx(btcoexist,
3663 NORMAL_EXEC, true,
3664 false, 0x5);
3665 } else {
3666 if (wifi_bw == BTC_WIFI_BW_HT40)
3667 halbtc8822b1ant_limited_rx(
3668 btcoexist, NORMAL_EXEC, false,
3669 true, 0x10);
3670 else
3671 halbtc8822b1ant_limited_rx(
3672 btcoexist, NORMAL_EXEC, false,
3673 true, 0x8);
3674 }
3675 }
3676
3677 halbtc8822b1ant_sw_mechanism(btcoexist, true);
3678 halbtc8822b1ant_run_sw_coexist_mechanism(
3679 btcoexist);
3680 } else {
3681 halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3682
3683 halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3684 0x5);
3685
3686 halbtc8822b1ant_sw_mechanism(btcoexist, false);
3687 halbtc8822b1ant_run_sw_coexist_mechanism(
3688 btcoexist);
3689 }
3690
3691 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3692 if (coex_sta->c2h_bt_inquiry_page) {
3693 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3694 "############# [BTCoex], BT Is Inquirying\n");
3695 halbtc8822b1ant_action_bt_inquiry(btcoexist);
3696 return;
3697 } else if (bt_hs_on) {
3698 halbtc8822b1ant_action_hs(btcoexist);
3699 return;
3700 }
3701
3702 if (!wifi_connected) {
3703 bool scan = false, link = false, roam = false;
3704
3705 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3706 "[BTCoex], wifi is non connected-idle !!!\n");
3707
3708 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3709 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3710 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3711
3712 if (scan)
3713 halbtc8822b1ant_action_wifi_not_connected_scan(
3714 btcoexist);
3715 else if (link || roam)
3716 halbtc8822b1ant_action_wifi_not_connected_asso_auth(
3717 btcoexist);
3718 else
3719 halbtc8822b1ant_action_wifi_not_connected(btcoexist);
3720 } else {
3721 halbtc8822b1ant_action_wifi_connected(btcoexist);
3722 }
3723}
3724
3725static void halbtc8822b1ant_init_coex_dm(struct btc_coexist *btcoexist)
3726{
3727
3728
3729 halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
3730
3731
3732 halbtc8822b1ant_sw_mechanism(btcoexist, false);
3733
3734 coex_sta->pop_event_cnt = 0;
3735}
3736
3737static void halbtc8822b1ant_init_hw_config(struct btc_coexist *btcoexist,
3738 bool back_up, bool wifi_only)
3739{
3740 struct rtl_priv *rtlpriv = btcoexist->adapter;
3741 u8 u8tmp = 0, i = 0;
3742 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
3743
3744 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3745 u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
3746 u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
3747
3748 RT_TRACE(
3749 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3750 "[BTCoex], ********** (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
3751 u32tmp3, u32tmp1, u32tmp2);
3752
3753 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3754 "[BTCoex], 1Ant Init HW Config!!\n");
3755
3756 coex_sta->bt_coex_supported_feature = 0;
3757 coex_sta->bt_coex_supported_version = 0;
3758 coex_sta->bt_ble_scan_type = 0;
3759 coex_sta->bt_ble_scan_para[0] = 0;
3760 coex_sta->bt_ble_scan_para[1] = 0;
3761 coex_sta->bt_ble_scan_para[2] = 0;
3762 coex_sta->bt_reg_vendor_ac = 0xffff;
3763 coex_sta->bt_reg_vendor_ae = 0xffff;
3764 coex_sta->isolation_btween_wb = BT_8822B_1ANT_DEFAULT_ISOLATION;
3765 coex_sta->gnt_error_cnt = 0;
3766 coex_sta->bt_relink_downcount = 0;
3767 coex_sta->is_set_ps_state_fail = false;
3768 coex_sta->cnt_set_ps_state_fail = 0;
3769
3770 for (i = 0; i <= 9; i++)
3771 coex_sta->bt_afh_map[i] = 0;
3772
3773
3774 halbtc8822b1ant_set_rfe_type(btcoexist);
3775
3776
3777 coex_sta->cut_version =
3778 (btcoexist->btc_read_1byte(btcoexist, 0xf1) & 0xf0) >> 4;
3779
3780 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
3781 0x1);
3782
3783
3784
3785 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3786 u8tmp &= 0xc0;
3787 u8tmp |= 0x5;
3788 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
3789
3790
3791 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
3792
3793
3794 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3795 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
3796
3797
3798 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
3799
3800 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
3801
3802
3803 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0);
3804 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0);
3805
3806 if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)
3807 halbtc8822b1ant_post_state_to_bt(
3808 btcoexist, BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
3809
3810
3811 if (coex_sta->is_rf_state_off) {
3812 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3813 FORCE_EXEC,
3814 BT_8822B_1ANT_PHASE_WLAN_OFF);
3815
3816 btcoexist->stop_coex_dm = true;
3817
3818 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3819 "[BTCoex], ********** %s (RF Off)**********\n",
3820 __func__);
3821 } else if (wifi_only) {
3822 coex_sta->concurrent_rx_mode_on = false;
3823 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
3824 FORCE_EXEC,
3825 BT_8822B_1ANT_PHASE_WLANONLY_INIT);
3826 } else {
3827 coex_sta->concurrent_rx_mode_on = true;
3828
3829 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3830 FORCE_EXEC,
3831 BT_8822B_1ANT_PHASE_COEX_INIT);
3832 }
3833
3834
3835 halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
3836
3837 halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true);
3838}
3839
3840void ex_btc8822b1ant_power_on_setting(struct btc_coexist *btcoexist)
3841{
3842 struct rtl_priv *rtlpriv = btcoexist->adapter;
3843 struct btc_board_info *board_info = &btcoexist->board_info;
3844 u8 u8tmp = 0x0;
3845 u16 u16tmp = 0x0;
3846
3847 RT_TRACE(
3848 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3849 "xxxxxxxxxxxxxxxx Execute 8822b 1-Ant PowerOn Setting!! xxxxxxxxxxxxxxxx\n");
3850
3851 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3852 "Ant Det Finish = %s, Ant Det Number = %d\n",
3853 board_info->btdm_ant_det_finish ? "Yes" : "No",
3854 board_info->btdm_ant_num_by_ant_det);
3855
3856 btcoexist->dbg_mode_1ant = false;
3857 btcoexist->stop_coex_dm = true;
3858
3859
3860 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
3861 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
3862
3863
3864 halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
3865 BT_8822B_1ANT_PCO_WLSIDE);
3866
3867
3868 halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
3869 BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
3870 BT_8822B_1ANT_GNT_CTRL_BY_SW,
3871 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
3872
3873 halbtc8822b1ant_ltecoex_set_gnt_wl(
3874 btcoexist, BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
3875 BT_8822B_1ANT_GNT_CTRL_BY_SW, BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
3876
3877
3878
3879
3880
3881 btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0);
3882
3883 halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true);
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897 u8tmp = 0;
3898 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3899
3900 if (btcoexist->chip_interface == BTC_INTF_USB)
3901 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
3902 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
3903 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
3904}
3905
3906void ex_btc8822b1ant_pre_load_firmware(struct btc_coexist *btcoexist) {}
3907
3908void ex_btc8822b1ant_init_hw_config(struct btc_coexist *btcoexist,
3909 bool wifi_only)
3910{
3911 struct rtl_priv *rtlpriv = btcoexist->adapter;
3912
3913 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3914 "[BTCoex], ********** (ini hw config) **********\n");
3915
3916 halbtc8822b1ant_init_hw_config(btcoexist, true, wifi_only);
3917 btcoexist->stop_coex_dm = false;
3918 btcoexist->auto_report_1ant = true;
3919}
3920
3921void ex_btc8822b1ant_init_coex_dm(struct btc_coexist *btcoexist)
3922{
3923 struct rtl_priv *rtlpriv = btcoexist->adapter;
3924
3925 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3926 "[BTCoex], Coex Mechanism Init!!\n");
3927
3928 btcoexist->stop_coex_dm = false;
3929
3930 halbtc8822b1ant_init_coex_dm(btcoexist);
3931
3932 halbtc8822b1ant_query_bt_info(btcoexist);
3933}
3934
3935void ex_btc8822b1ant_display_coex_info(struct btc_coexist *btcoexist,
3936 struct seq_file *m)
3937{
3938 struct btc_board_info *board_info = &btcoexist->board_info;
3939 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3940
3941 u8 u8tmp[4], i, ps_tdma_case = 0;
3942 u16 u16tmp[4];
3943 u32 u32tmp[4];
3944 u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
3945 u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
3946 static u8 pop_report_in_10s;
3947 u32 phyver = 0;
3948 bool lte_coex_on = false;
3949 static u8 cnt;
3950
3951 seq_puts(m, "\r\n ============[BT Coexist info]============");
3952
3953 if (btcoexist->manual_control) {
3954 seq_puts(m,
3955 "\r\n ============[Under Manual Control]============");
3956 seq_puts(m, "\r\n ==========================================");
3957 }
3958 if (btcoexist->stop_coex_dm) {
3959 seq_puts(m, "\r\n ============[Coex is STOPPED]============");
3960 seq_puts(m, "\r\n ==========================================");
3961 }
3962
3963 if (!coex_sta->bt_disabled) {
3964 if (coex_sta->bt_coex_supported_feature == 0)
3965 btcoexist->btc_get(
3966 btcoexist, BTC_GET_U4_SUPPORTED_FEATURE,
3967 &coex_sta->bt_coex_supported_feature);
3968
3969 if ((coex_sta->bt_coex_supported_version == 0) ||
3970 (coex_sta->bt_coex_supported_version == 0xffff))
3971 btcoexist->btc_get(
3972 btcoexist, BTC_GET_U4_SUPPORTED_VERSION,
3973 &coex_sta->bt_coex_supported_version);
3974
3975 if (coex_sta->bt_reg_vendor_ac == 0xffff)
3976 coex_sta->bt_reg_vendor_ac = (u16)(
3977 btcoexist->btc_get_bt_reg(btcoexist, 3, 0xac) &
3978 0xffff);
3979
3980 if (coex_sta->bt_reg_vendor_ae == 0xffff)
3981 coex_sta->bt_reg_vendor_ae = (u16)(
3982 btcoexist->btc_get_bt_reg(btcoexist, 3, 0xae) &
3983 0xffff);
3984
3985 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
3986 &bt_patch_ver);
3987 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
3988
3989 if (coex_sta->num_of_profile > 0) {
3990 cnt++;
3991
3992 if (cnt >= 3) {
3993 btcoexist->btc_get_bt_afh_map_from_bt(
3994 btcoexist, 0, &coex_sta->bt_afh_map[0]);
3995 cnt = 0;
3996 }
3997 }
3998 }
3999
4000 if (psd_scan->ant_det_try_count == 0) {
4001 seq_printf(
4002 m, "\r\n %-35s = %d/ %d/ %s / %d",
4003 "Ant PG Num/ Mech/ Pos/ RFE", board_info->pg_ant_num,
4004 board_info->btdm_ant_num,
4005 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT ?
4006 "Main" :
4007 "Aux"),
4008 rfe_type->rfe_module_type);
4009 } else {
4010 seq_printf(
4011 m, "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)",
4012 "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4013 board_info->pg_ant_num,
4014 board_info->btdm_ant_num_by_ant_det,
4015 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT ?
4016 "Main" :
4017 "Aux"),
4018 rfe_type->rfe_module_type, psd_scan->ant_det_try_count,
4019 psd_scan->ant_det_fail_count, psd_scan->ant_det_result);
4020
4021 if (board_info->btdm_ant_det_finish) {
4022 if (psd_scan->ant_det_result != 12)
4023 seq_printf(m, "\r\n %-35s = %s",
4024 "Ant Det PSD Value",
4025 psd_scan->ant_det_peak_val);
4026 else
4027 seq_printf(m, "\r\n %-35s = %d",
4028 "Ant Det PSD Value",
4029 psd_scan->ant_det_psd_scan_peak_val /
4030 100);
4031 }
4032 }
4033
4034 bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
4035 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4036 phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
4037
4038 bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
4039
4040 seq_printf(
4041 m, "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4042 "CoexVer WL/ BT_Desired/ BT_Report",
4043 glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant,
4044 glcoex_ver_btdesired_8822b_1ant, bt_coex_ver,
4045 (bt_coex_ver == 0xff ?
4046 "Unknown" :
4047 (coex_sta->bt_disabled ? "BT-disable" :
4048 (bt_coex_ver >= glcoex_ver_btdesired_8822b_1ant ?
4049 "Match" :
4050 "Mis-Match"))));
4051
4052 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", "W_FW/ B_FW/ Phy/ Kt",
4053 fw_ver, bt_patch_ver, phyver, coex_sta->cut_version + 65);
4054
4055 seq_printf(m, "\r\n %-35s = %02x %02x %02x ", "AFH Map to BT",
4056 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4057 coex_dm->wifi_chnl_info[2]);
4058
4059
4060 seq_printf(m, "\r\n %-35s", "============[Wifi Status]============");
4061 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS, m);
4062
4063 seq_printf(m, "\r\n %-35s", "============[BT Status]============");
4064
4065 pop_report_in_10s++;
4066 seq_printf(
4067 m, "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ",
4068 "BT [status/ rssi/ retryCnt/ popCnt]",
4069 ((coex_sta->bt_disabled) ?
4070 ("disabled") :
4071 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") :
4072 ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4073 coex_dm->bt_status) ?
4074 "non-connected idle" :
4075 ((coex_dm->bt_status ==
4076 BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE) ?
4077 "connected-idle" :
4078 "busy")))),
4079 coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
4080 coex_sta->pop_event_cnt);
4081
4082 if (pop_report_in_10s >= 5) {
4083 coex_sta->pop_event_cnt = 0;
4084 pop_report_in_10s = 0;
4085 }
4086
4087 if (coex_sta->num_of_profile != 0)
4088 seq_printf(
4089 m, "\r\n %-35s = %s%s%s%s%s", "Profiles",
4090 ((bt_link_info->a2dp_exist) ?
4091 ((coex_sta->is_bt_a2dp_sink) ? "A2DP sink," :
4092 "A2DP,") :
4093 ""),
4094 ((bt_link_info->sco_exist) ? "HFP," : ""),
4095 ((bt_link_info->hid_exist) ?
4096 ((coex_sta->hid_busy_num >= 2) ?
4097 "HID(4/18)," :
4098 "HID(2/18),") :
4099 ""),
4100 ((bt_link_info->pan_exist) ? "PAN," : ""),
4101 ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
4102 else
4103 seq_printf(m, "\r\n %-35s = None", "Profiles");
4104
4105 if (bt_link_info->a2dp_exist) {
4106 seq_printf(m, "\r\n %-35s = %s/ %d/ %s",
4107 "A2DP Rate/Bitpool/Auto_Slot",
4108 ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
4109 coex_sta->a2dp_bit_pool,
4110 ((coex_sta->is_autoslot) ? "On" : "Off"));
4111 }
4112
4113 if (bt_link_info->hid_exist) {
4114 seq_printf(m, "\r\n %-35s = %d/ %d", "HID PairNum/Forbid_Slot",
4115 coex_sta->hid_pair_cnt, coex_sta->forbidden_slot);
4116 }
4117
4118 seq_printf(m, "\r\n %-35s = %s/ %d/ %s/ 0x%x",
4119 "Role/RoleSwCnt/IgnWlact/Feature",
4120 ((bt_link_info->slave_role) ? "Slave" : "Master"),
4121 coex_sta->cnt_role_switch,
4122 ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"),
4123 coex_sta->bt_coex_supported_feature);
4124
4125 if ((coex_sta->bt_ble_scan_type & 0x7) != 0x0) {
4126 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4127 "BLEScan Type/TV/Init/Ble",
4128 coex_sta->bt_ble_scan_type,
4129 (coex_sta->bt_ble_scan_type & 0x1 ?
4130 coex_sta->bt_ble_scan_para[0] :
4131 0x0),
4132 (coex_sta->bt_ble_scan_type & 0x2 ?
4133 coex_sta->bt_ble_scan_para[1] :
4134 0x0),
4135 (coex_sta->bt_ble_scan_type & 0x4 ?
4136 coex_sta->bt_ble_scan_para[2] :
4137 0x0));
4138 }
4139
4140 seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4141 "ReInit/ReLink/IgnWlact/Page/NameReq", coex_sta->cnt_reinit,
4142 coex_sta->cnt_setup_link, coex_sta->cnt_ign_wlan_act,
4143 coex_sta->cnt_page, coex_sta->cnt_remote_name_req);
4144
4145 halbtc8822b1ant_read_score_board(btcoexist, &u16tmp[0]);
4146
4147 if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
4148 (coex_sta->bt_reg_vendor_ac == 0xffff))
4149 seq_printf(m, "\r\n %-35s = x/ x/ %04x",
4150 "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]);
4151 else
4152 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ %04x",
4153 "0xae[4]/0xac[1:0]/Scoreboard",
4154 (int)((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
4155 coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
4156
4157 if (coex_sta->num_of_profile > 0) {
4158 seq_printf(
4159 m,
4160 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
4161 "AFH MAP", coex_sta->bt_afh_map[0],
4162 coex_sta->bt_afh_map[1], coex_sta->bt_afh_map[2],
4163 coex_sta->bt_afh_map[3], coex_sta->bt_afh_map[4],
4164 coex_sta->bt_afh_map[5], coex_sta->bt_afh_map[6],
4165 coex_sta->bt_afh_map[7], coex_sta->bt_afh_map[8],
4166 coex_sta->bt_afh_map[9]);
4167 }
4168
4169 for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) {
4170 if (coex_sta->bt_info_c2h_cnt[i]) {
4171 seq_printf(
4172 m,
4173 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
4174 glbt_info_src_8822b_1ant[i],
4175 coex_sta->bt_info_c2h[i][0],
4176 coex_sta->bt_info_c2h[i][1],
4177 coex_sta->bt_info_c2h[i][2],
4178 coex_sta->bt_info_c2h[i][3],
4179 coex_sta->bt_info_c2h[i][4],
4180 coex_sta->bt_info_c2h[i][5],
4181 coex_sta->bt_info_c2h[i][6],
4182 coex_sta->bt_info_c2h_cnt[i]);
4183 }
4184 }
4185
4186 if (btcoexist->manual_control)
4187 seq_printf(
4188 m, "\r\n %-35s",
4189 "============[mechanisms] (before Manual)============");
4190 else
4191 seq_printf(m, "\r\n %-35s",
4192 "============[Mechanisms]============");
4193
4194 ps_tdma_case = coex_dm->cur_ps_tdma;
4195 seq_printf(m, "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s)",
4196 "TDMA", coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4197 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4198 coex_dm->ps_tdma_para[4], ps_tdma_case,
4199 (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"));
4200
4201 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4202 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4203 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4204 seq_printf(m, "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
4205 "Table/0x6c0/0x6c4/0x6c8", coex_sta->coex_table_type,
4206 u32tmp[0], u32tmp[1], u32tmp[2]);
4207
4208 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4209 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
4210 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x", "0x778/0x6cc", u8tmp[0],
4211 u32tmp[0]);
4212
4213 seq_printf(m, "\r\n %-35s = %s/ %s/ %s/ %d",
4214 "AntDiv/BtCtrlLPS/LPRA/PsFail",
4215 ((board_info->ant_div_cfg) ? "On" : "Off"),
4216 ((coex_sta->force_lps_ctrl) ? "On" : "Off"),
4217 ((coex_dm->cur_low_penalty_ra) ? "On" : "Off"),
4218 coex_sta->cnt_set_ps_state_fail);
4219
4220 u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4221 lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false;
4222
4223 if (lte_coex_on) {
4224 u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
4225 0xa0);
4226 u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
4227 0xa4);
4228
4229 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x",
4230 "LTE Coex Table W_L/B_L", u32tmp[0] & 0xffff,
4231 u32tmp[1] & 0xffff);
4232
4233 u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
4234 0xa8);
4235 u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
4236 0xac);
4237 u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
4238 0xb0);
4239 u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
4240 0xb4);
4241
4242 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4243 "LTE Break Table W_L/B_L/L_W/L_B",
4244 u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
4245 u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
4246 }
4247
4248
4249 seq_printf(m, "\r\n %-35s", "============[Hw setting]============");
4250
4251 u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4252 u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
4253 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
4254
4255 seq_printf(m, "\r\n %-35s = %s/ %s", "LTE Coex/Path Owner",
4256 ((lte_coex_on) ? "On" : "Off"),
4257 ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
4258
4259 if (lte_coex_on) {
4260 seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d",
4261 "LTE 3Wire/OPMode/UART/UARTMode",
4262 (int)((u32tmp[0] & BIT(6)) >> 6),
4263 (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
4264 (int)((u32tmp[0] & BIT(3)) >> 3),
4265 (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
4266
4267 seq_printf(m, "\r\n %-35s = %d/ %d", "LTE_Busy/UART_Busy",
4268 (int)((u32tmp[1] & BIT(1)) >> 1),
4269 (int)(u32tmp[1] & BIT(0)));
4270 }
4271 seq_printf(m, "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d",
4272 "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
4273 ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
4274 ((u32tmp[0] & BIT(8)) ? "SW" : "HW"),
4275 ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
4276 ((u32tmp[0] & BIT(10)) ? "SW" : "HW"),
4277 ((u8tmp[0] & BIT(3)) ? "On" : "Off"),
4278 coex_sta->gnt_error_cnt);
4279
4280 seq_printf(m, "\r\n %-35s = %d/ %d", "GNT_WL/GNT_BT",
4281 (int)((u32tmp[1] & BIT(2)) >> 2),
4282 (int)((u32tmp[1] & BIT(3)) >> 3));
4283
4284 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
4285 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
4286 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba);
4287
4288 seq_printf(m, "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s",
4289 "0xcb0/0xcb4/0xcb8[23:16]", u32tmp[0], u32tmp[1], u8tmp[0],
4290 ((u8tmp[0] & 0x1) == 0x1 ? "(BTG)" : "(WL_A+G)"));
4291
4292 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4293 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
4294 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
4295 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4296
4297 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4298 "4c[24:23]/64[0]/4c6[4]/40[5]",
4299 (int)((u32tmp[0] & (BIT(24) | BIT(23))) >> 23),
4300 u8tmp[2] & 0x1, (int)((u8tmp[0] & BIT(4)) >> 4),
4301 (int)((u8tmp[1] & BIT(5)) >> 5));
4302
4303 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4304 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4305 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
4306 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
4307
4308 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
4309 "0x550/0x522/4-RxAGC/0xc50", u32tmp[0], u8tmp[0],
4310 (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
4311
4312 fa_ofdm = btcoexist->btc_phydm_query_phy_counter(btcoexist,
4313 "PHYDM_INFO_FA_OFDM");
4314 fa_cck = btcoexist->btc_phydm_query_phy_counter(btcoexist,
4315 "PHYDM_INFO_FA_CCK");
4316 cca_ofdm = btcoexist->btc_phydm_query_phy_counter(
4317 btcoexist, "PHYDM_INFO_CCA_OFDM");
4318 cca_cck = btcoexist->btc_phydm_query_phy_counter(btcoexist,
4319 "PHYDM_INFO_CCA_CCK");
4320
4321 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4322 "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", cca_cck, fa_cck, cca_ofdm,
4323 fa_ofdm);
4324
4325 seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11ac",
4326 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
4327 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
4328
4329 seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11ac",
4330 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
4331 coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
4332
4333 seq_printf(m, "\r\n %-35s = %s/ %s/ %s/ %d",
4334 "WlHiPri/ Locking/ Locked/ Noisy",
4335 (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
4336 (coex_sta->cck_lock ? "Yes" : "No"),
4337 (coex_sta->cck_ever_lock ? "Yes" : "No"),
4338 coex_sta->wl_noisy_level);
4339
4340 seq_printf(m, "\r\n %-35s = %d/ %d", "0x770(Hi-pri rx/tx)",
4341 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4342
4343 seq_printf(m, "\r\n %-35s = %d/ %d %s", "0x774(Lo-pri rx/tx)",
4344 coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4345 (bt_link_info->slave_role ?
4346 "(Slave!!)" :
4347 (coex_sta->is_tdma_btautoslot_hang ?
4348 "(auto-slot hang!!)" :
4349 "")));
4350
4351 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS, m);
4352}
4353
4354void ex_btc8822b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
4355{
4356 struct rtl_priv *rtlpriv = btcoexist->adapter;
4357
4358 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4359 return;
4360
4361 if (type == BTC_IPS_ENTER) {
4362 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4363 "[BTCoex], IPS ENTER notify\n");
4364 coex_sta->under_ips = true;
4365
4366
4367 halbtc8822b1ant_post_state_to_bt(
4368 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
4369
4370 halbtc8822b1ant_post_state_to_bt(
4371 btcoexist, BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
4372
4373 halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
4374
4375 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4376 FORCE_EXEC,
4377 BT_8822B_1ANT_PHASE_WLAN_OFF);
4378
4379 halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
4380 } else if (type == BTC_IPS_LEAVE) {
4381 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4382 "[BTCoex], IPS LEAVE notify\n");
4383 halbtc8822b1ant_post_state_to_bt(
4384 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
4385
4386 halbtc8822b1ant_post_state_to_bt(
4387 btcoexist, BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
4388
4389
4390 halbtc8822b1ant_init_hw_config(btcoexist, false, false);
4391
4392 halbtc8822b1ant_init_coex_dm(btcoexist);
4393
4394 halbtc8822b1ant_query_bt_info(btcoexist);
4395
4396 coex_sta->under_ips = false;
4397 }
4398}
4399
4400void ex_btc8822b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
4401{
4402 struct rtl_priv *rtlpriv = btcoexist->adapter;
4403 static bool pre_force_lps_on;
4404
4405 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4406 return;
4407
4408 if (type == BTC_LPS_ENABLE) {
4409 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4410 "[BTCoex], LPS ENABLE notify\n");
4411 coex_sta->under_lps = true;
4412
4413 if (coex_sta->force_lps_ctrl) {
4414
4415 pre_force_lps_on = true;
4416 halbtc8822b1ant_post_state_to_bt(
4417 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE,
4418 true);
4419 } else {
4420
4421
4422
4423
4424 pre_force_lps_on = false;
4425 halbtc8822b1ant_post_state_to_bt(
4426 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE,
4427 false);
4428 }
4429 } else if (type == BTC_LPS_DISABLE) {
4430 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4431 "[BTCoex], LPS DISABLE notify\n");
4432 coex_sta->under_lps = false;
4433
4434
4435 halbtc8822b1ant_post_state_to_bt(
4436 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
4437
4438 if ((!pre_force_lps_on) && (!coex_sta->force_lps_ctrl))
4439 halbtc8822b1ant_query_bt_info(btcoexist);
4440 }
4441}
4442
4443void ex_btc8822b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
4444{
4445 struct rtl_priv *rtlpriv = btcoexist->adapter;
4446 bool wifi_connected = false;
4447 bool wifi_under_5g = false;
4448
4449 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4450 return;
4451
4452 coex_sta->freeze_coexrun_by_btinfo = false;
4453
4454 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4455 &wifi_connected);
4456
4457 if (wifi_connected)
4458 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4459 "[BTCoex], ********** WL connected before SCAN\n");
4460 else
4461 RT_TRACE(
4462 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4463 "[BTCoex], ********** WL is not connected before SCAN\n");
4464
4465 halbtc8822b1ant_query_bt_info(btcoexist);
4466
4467
4468 if (type == BTC_SCAN_START) {
4469 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
4470 &wifi_under_5g);
4471
4472
4473 if (wifi_under_5g) {
4474 RT_TRACE(
4475 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4476 "[BTCoex], ********** (scan_notify_5g_scan_start) **********\n");
4477 halbtc8822b1ant_action_wifi_under5g(btcoexist);
4478 return;
4479 }
4480
4481
4482 coex_sta->wifi_is_high_pri_task = true;
4483
4484 RT_TRACE(
4485 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4486 "[BTCoex], ********** (scan_notify_2g_scan_start) **********\n");
4487
4488 if (!wifi_connected) {
4489 RT_TRACE(
4490 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4491 "[BTCoex], ********** wifi is not connected scan **********\n");
4492 halbtc8822b1ant_action_wifi_not_connected_scan(
4493 btcoexist);
4494 } else {
4495 RT_TRACE(
4496 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4497 "[BTCoex], ********** wifi is connected scan **********\n");
4498 halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
4499 }
4500
4501 return;
4502 }
4503
4504 if (type == BTC_SCAN_START_2G) {
4505 coex_sta->wifi_is_high_pri_task = true;
4506
4507 RT_TRACE(
4508 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4509 "[BTCoex], ********** (scan_notify_2g_sacn_start_for_switch_band_used) **********\n");
4510
4511 if (!wifi_connected) {
4512 RT_TRACE(
4513 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4514 "[BTCoex], ********** wifi is not connected **********\n");
4515
4516 halbtc8822b1ant_action_wifi_not_connected_scan(
4517 btcoexist);
4518 } else {
4519 RT_TRACE(
4520 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4521 "[BTCoex], ********** wifi is connected **********\n");
4522 halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
4523 }
4524 } else {
4525 coex_sta->wifi_is_high_pri_task = false;
4526
4527
4528
4529 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
4530 &coex_sta->scan_ap_num);
4531
4532 RT_TRACE(
4533 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4534 "[BTCoex], ********** (scan_finish_notify) **********\n");
4535
4536 if (!wifi_connected) {
4537 halbtc8822b1ant_action_wifi_not_connected(btcoexist);
4538 } else {
4539 RT_TRACE(
4540 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4541 "[BTCoex], ********** scan_finish_notify wifi is connected **********\n");
4542 halbtc8822b1ant_action_wifi_connected(btcoexist);
4543 }
4544 }
4545}
4546
4547void ex_btc8822b1ant_scan_notify_without_bt(struct btc_coexist *btcoexist,
4548 u8 type)
4549{
4550 bool wifi_under_5g = false;
4551
4552 if (type == BTC_SCAN_START) {
4553 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
4554 &wifi_under_5g);
4555
4556 if (wifi_under_5g) {
4557 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
4558 0x3, 1);
4559 return;
4560 }
4561
4562
4563 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2);
4564 return;
4565 }
4566 if (type == BTC_SCAN_START_2G)
4567 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2);
4568}
4569
4570void ex_btc8822b1ant_switchband_notify(struct btc_coexist *btcoexist, u8 type)
4571{
4572 struct rtl_priv *rtlpriv = btcoexist->adapter;
4573
4574 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4575 "[BTCoex], ********** (switchband_notify) **********\n");
4576
4577 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4578 return;
4579
4580 coex_sta->switch_band_notify_to = type;
4581
4582 if (type == BTC_SWITCH_TO_5G) {
4583 RT_TRACE(
4584 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4585 "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_5G) **********\n");
4586
4587 halbtc8822b1ant_action_wifi_under5g(btcoexist);
4588 return;
4589 } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
4590 RT_TRACE(
4591 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4592 "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G (no for scan)) **********\n");
4593
4594 halbtc8822b1ant_run_coexist_mechanism(btcoexist);
4595
4596
4597 } else {
4598 RT_TRACE(
4599 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4600 "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G) **********\n");
4601
4602 ex_btc8822b1ant_scan_notify(btcoexist, BTC_SCAN_START_2G);
4603 }
4604 coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
4605}
4606
4607void ex_btc8822b1ant_switchband_notify_without_bt(struct btc_coexist *btcoexist,
4608 u8 type)
4609{
4610 bool wifi_under_5g = false;
4611
4612 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4613
4614 if (type == BTC_SWITCH_TO_5G) {
4615 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 1);
4616 return;
4617 } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
4618 if (wifi_under_5g)
4619
4620 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
4621 0x3, 1);
4622
4623 else
4624 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
4625 0x3, 2);
4626 } else {
4627 ex_btc8822b1ant_scan_notify_without_bt(btcoexist,
4628 BTC_SCAN_START_2G);
4629 }
4630}
4631
4632void ex_btc8822b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
4633{
4634 struct rtl_priv *rtlpriv = btcoexist->adapter;
4635 bool wifi_connected = false;
4636
4637 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4638 "[BTCoex], ********** (connect notify) **********\n");
4639
4640 halbtc8822b1ant_post_state_to_bt(btcoexist,
4641 BT_8822B_1ANT_SCOREBOARD_SCAN, true);
4642
4643 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4644 return;
4645
4646 if ((type == BTC_ASSOCIATE_5G_START) ||
4647 (type == BTC_ASSOCIATE_5G_FINISH)) {
4648 if (type == BTC_ASSOCIATE_5G_START) {
4649 RT_TRACE(
4650 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4651 "[BTCoex], ********** (5G associate start notify) **********\n");
4652
4653 halbtc8822b1ant_action_wifi_under5g(btcoexist);
4654
4655 } else if (type == BTC_ASSOCIATE_5G_FINISH) {
4656 RT_TRACE(
4657 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4658 "[BTCoex], ********** (5G associate finish notify) **********\n");
4659 }
4660
4661 return;
4662 }
4663
4664 if (type == BTC_ASSOCIATE_START) {
4665 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4666 "[BTCoex], 2G CONNECT START notify\n");
4667
4668 coex_sta->wifi_is_high_pri_task = true;
4669
4670 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4671 FORCE_EXEC,
4672 BT_8822B_1ANT_PHASE_2G_RUNTIME);
4673
4674 coex_dm->arp_cnt = 0;
4675
4676 halbtc8822b1ant_action_wifi_not_connected_asso_auth(btcoexist);
4677
4678 coex_sta->freeze_coexrun_by_btinfo = true;
4679
4680 } else {
4681 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4682 "[BTCoex], 2G CONNECT Finish notify\n");
4683 coex_sta->wifi_is_high_pri_task = false;
4684 coex_sta->freeze_coexrun_by_btinfo = false;
4685
4686 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4687 &wifi_connected);
4688
4689 if (!wifi_connected)
4690 halbtc8822b1ant_action_wifi_not_connected(btcoexist);
4691 else
4692 halbtc8822b1ant_action_wifi_connected(btcoexist);
4693 }
4694}
4695
4696void ex_btc8822b1ant_media_status_notify(struct btc_coexist *btcoexist, u8 type)
4697{
4698 struct rtl_priv *rtlpriv = btcoexist->adapter;
4699 bool wifi_under_b_mode = false;
4700 bool wifi_under_5g = false;
4701
4702 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4703 return;
4704
4705 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4706
4707 if (type == BTC_MEDIA_CONNECT) {
4708 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4709 "[BTCoex], 2g media connect notify");
4710
4711 halbtc8822b1ant_post_state_to_bt(
4712 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
4713
4714 if (wifi_under_5g) {
4715 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4716 "[BTCoex], 5g media notify\n");
4717
4718 halbtc8822b1ant_action_wifi_under5g(btcoexist);
4719 return;
4720 }
4721
4722 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4723 FORCE_EXEC,
4724 BT_8822B_1ANT_PHASE_2G_RUNTIME);
4725
4726 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
4727 &wifi_under_b_mode);
4728
4729
4730 if (wifi_under_b_mode) {
4731 RT_TRACE(
4732 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4733 "[BTCoex], ********** (media status notity under b mode) **********\n");
4734 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
4735 0x00);
4736 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
4737 0x00);
4738 } else {
4739 RT_TRACE(
4740 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4741 "[BTCoex], ********** (media status notity not under b mode) **********\n");
4742 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
4743 0x00);
4744 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
4745 0x10);
4746 }
4747
4748 coex_dm->backup_arfr_cnt1 =
4749 btcoexist->btc_read_4byte(btcoexist, 0x430);
4750 coex_dm->backup_arfr_cnt2 =
4751 btcoexist->btc_read_4byte(btcoexist, 0x434);
4752 coex_dm->backup_retry_limit =
4753 btcoexist->btc_read_2byte(btcoexist, 0x42a);
4754 coex_dm->backup_ampdu_max_time =
4755 btcoexist->btc_read_1byte(btcoexist, 0x456);
4756 } else {
4757 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4758 "[BTCoex], 2g media disconnect notify\n");
4759 coex_dm->arp_cnt = 0;
4760
4761 halbtc8822b1ant_post_state_to_bt(
4762 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
4763
4764 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0);
4765 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0);
4766
4767 coex_sta->cck_ever_lock = false;
4768 }
4769
4770 halbtc8822b1ant_update_wifi_ch_info(btcoexist, type);
4771}
4772
4773void ex_btc8822b1ant_specific_packet_notify(struct btc_coexist *btcoexist,
4774 u8 type)
4775{
4776 struct rtl_priv *rtlpriv = btcoexist->adapter;
4777 bool under_4way = false, wifi_under_5g = false;
4778
4779 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4780 return;
4781
4782 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4783 if (wifi_under_5g) {
4784 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4785 "[BTCoex], 5g special packet notify\n");
4786
4787 halbtc8822b1ant_action_wifi_under5g(btcoexist);
4788 return;
4789 }
4790
4791 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
4792 &under_4way);
4793
4794 if (under_4way) {
4795 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4796 "[BTCoex], specific Packet ---- under_4way!!\n");
4797
4798 coex_sta->wifi_is_high_pri_task = true;
4799 coex_sta->specific_pkt_period_cnt = 2;
4800 } else if (type == BTC_PACKET_ARP) {
4801 coex_dm->arp_cnt++;
4802
4803 if (coex_sta->wifi_is_high_pri_task) {
4804 RT_TRACE(
4805 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4806 "[BTCoex], specific Packet ARP notify -cnt = %d\n",
4807 coex_dm->arp_cnt);
4808 }
4809
4810 } else {
4811 RT_TRACE(
4812 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4813 "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
4814 type);
4815
4816 coex_sta->wifi_is_high_pri_task = true;
4817 coex_sta->specific_pkt_period_cnt = 2;
4818 }
4819
4820 if (coex_sta->wifi_is_high_pri_task)
4821 halbtc8822b1ant_action_wifi_connected_specific_packet(
4822 btcoexist);
4823}
4824
4825void ex_btc8822b1ant_bt_info_notify(struct btc_coexist *btcoexist, u8 *tmp_buf,
4826 u8 length)
4827{
4828 struct rtl_priv *rtlpriv = btcoexist->adapter;
4829 u8 i, rsp_source = 0;
4830 bool wifi_connected = false;
4831 bool wifi_scan = false, wifi_link = false, wifi_roam = false,
4832 wifi_busy = false;
4833 static bool is_scoreboard_scan;
4834
4835 if (psd_scan->is_ant_det_running) {
4836 RT_TRACE(
4837 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4838 "[BTCoex], bt_info_notify return for AntDet is running\n");
4839 return;
4840 }
4841
4842 rsp_source = tmp_buf[0] & 0xf;
4843 if (rsp_source >= BT_INFO_SRC_8822B_1ANT_MAX)
4844 rsp_source = BT_INFO_SRC_8822B_1ANT_WIFI_FW;
4845 coex_sta->bt_info_c2h_cnt[rsp_source]++;
4846
4847 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4848 "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, length);
4849
4850 for (i = 0; i < length; i++) {
4851 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
4852
4853 if (i == length - 1) {
4854
4855 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4856 "0x%02x]\n", tmp_buf[i]);
4857 } else {
4858
4859 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "0x%02x, ",
4860 tmp_buf[i]);
4861 }
4862 }
4863
4864 coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1];
4865 coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
4866 coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5];
4867
4868 if (rsp_source != BT_INFO_SRC_8822B_1ANT_WIFI_FW) {
4869
4870 coex_sta->bt_whck_test =
4871 ((coex_sta->bt_info == 0xff) ? true : false);
4872
4873 coex_sta->bt_create_connection =
4874 ((coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true :
4875 false);
4876
4877
4878 coex_sta->bt_rssi =
4879 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4880
4881 coex_sta->c2h_bt_remote_name_req =
4882 ((coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true :
4883 false);
4884
4885 coex_sta->is_A2DP_3M =
4886 ((coex_sta->bt_info_c2h[rsp_source][2] & 0x10) ? true :
4887 false);
4888
4889 coex_sta->acl_busy =
4890 ((coex_sta->bt_info_c2h[rsp_source][1] & 0x9) ? true :
4891 false);
4892
4893 coex_sta->voice_over_HOGP =
4894 ((coex_sta->bt_info_ext & 0x10) ? true : false);
4895
4896 coex_sta->c2h_bt_inquiry_page =
4897 ((coex_sta->bt_info & BT_INFO_8822B_1ANT_B_INQ_PAGE) ?
4898 true :
4899 false);
4900
4901 coex_sta->a2dp_bit_pool =
4902 (((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) ==
4903 0x49) ?
4904 (coex_sta->bt_info_c2h[rsp_source][6] & 0x7f) :
4905 0);
4906
4907 coex_sta->is_bt_a2dp_sink =
4908 (coex_sta->bt_info_c2h[rsp_source][6] & 0x80) ? true :
4909 false;
4910
4911 coex_sta->bt_retry_cnt =
4912 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
4913
4914 coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8;
4915
4916 coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7;
4917
4918 coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4;
4919
4920 coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6;
4921 if (coex_sta->bt_retry_cnt >= 1)
4922 coex_sta->pop_event_cnt++;
4923
4924 if (coex_sta->c2h_bt_remote_name_req)
4925 coex_sta->cnt_remote_name_req++;
4926
4927 if (coex_sta->bt_info_ext & BIT(1))
4928 coex_sta->cnt_reinit++;
4929
4930 if (coex_sta->bt_info_ext & BIT(2)) {
4931 coex_sta->cnt_setup_link++;
4932 coex_sta->is_setup_link = true;
4933 coex_sta->bt_relink_downcount = 2;
4934 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4935 "[BTCoex], Re-Link start in BT info!!\n");
4936 } else {
4937 coex_sta->is_setup_link = false;
4938 coex_sta->bt_relink_downcount = 0;
4939 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4940 "[BTCoex], Re-Link stop in BT info!!\n");
4941 }
4942
4943 if (coex_sta->bt_info_ext & BIT(3))
4944 coex_sta->cnt_ign_wlan_act++;
4945
4946 if (coex_sta->bt_info_ext & BIT(6))
4947 coex_sta->cnt_role_switch++;
4948
4949 if (coex_sta->bt_info_ext & BIT(7))
4950 coex_sta->is_bt_multi_link = true;
4951 else
4952 coex_sta->is_bt_multi_link = false;
4953
4954 if (coex_sta->bt_create_connection) {
4955 coex_sta->cnt_page++;
4956
4957 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY,
4958 &wifi_busy);
4959
4960 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN,
4961 &wifi_scan);
4962 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK,
4963 &wifi_link);
4964 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM,
4965 &wifi_roam);
4966
4967 if ((wifi_link) || (wifi_roam) || (wifi_scan) ||
4968 (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) {
4969 is_scoreboard_scan = true;
4970 halbtc8822b1ant_post_state_to_bt(
4971 btcoexist,
4972 BT_8822B_1ANT_SCOREBOARD_SCAN, true);
4973
4974 } else {
4975 halbtc8822b1ant_post_state_to_bt(
4976 btcoexist,
4977 BT_8822B_1ANT_SCOREBOARD_SCAN, false);
4978 }
4979 } else {
4980 if (is_scoreboard_scan) {
4981 halbtc8822b1ant_post_state_to_bt(
4982 btcoexist,
4983 BT_8822B_1ANT_SCOREBOARD_SCAN, false);
4984 is_scoreboard_scan = false;
4985 }
4986 }
4987
4988
4989
4990
4991 if ((!btcoexist->manual_control) &&
4992 (!btcoexist->stop_coex_dm)) {
4993 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4994 &wifi_connected);
4995
4996
4997 if ((coex_sta->bt_info_ext & BIT(1))) {
4998 RT_TRACE(
4999 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5000 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
5001 if (wifi_connected)
5002 halbtc8822b1ant_update_wifi_ch_info(
5003 btcoexist, BTC_MEDIA_CONNECT);
5004 else
5005 halbtc8822b1ant_update_wifi_ch_info(
5006 btcoexist,
5007 BTC_MEDIA_DISCONNECT);
5008 }
5009
5010
5011 if ((coex_sta->bt_info_ext & BIT(3)) &&
5012 (!(coex_sta->bt_info_ext & BIT(2)))) {
5013 RT_TRACE(
5014 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5015 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
5016 halbtc8822b1ant_ignore_wlan_act(
5017 btcoexist, FORCE_EXEC, false);
5018 }
5019 }
5020 }
5021
5022 if ((coex_sta->bt_info_ext & BIT(5))) {
5023 RT_TRACE(
5024 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5025 "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n");
5026 coex_sta->bt_ble_scan_type =
5027 btcoexist->btc_get_ble_scan_type_from_bt(btcoexist);
5028
5029 if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1)
5030 coex_sta->bt_ble_scan_para[0] =
5031 btcoexist->btc_get_ble_scan_para_from_bt(
5032 btcoexist, 0x1);
5033 if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2)
5034 coex_sta->bt_ble_scan_para[1] =
5035 btcoexist->btc_get_ble_scan_para_from_bt(
5036 btcoexist, 0x2);
5037 if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4)
5038 coex_sta->bt_ble_scan_para[2] =
5039 btcoexist->btc_get_ble_scan_para_from_bt(
5040 btcoexist, 0x4);
5041 }
5042
5043 halbtc8822b1ant_update_bt_link_info(btcoexist);
5044
5045 halbtc8822b1ant_run_coexist_mechanism(btcoexist);
5046}
5047
5048void ex_btc8822b1ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
5049{
5050 struct rtl_priv *rtlpriv = btcoexist->adapter;
5051
5052 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5053 "[BTCoex], RF Status notify\n");
5054
5055 if (type == BTC_RF_ON) {
5056 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5057 "[BTCoex], RF is turned ON!!\n");
5058 btcoexist->stop_coex_dm = false;
5059
5060 halbtc8822b1ant_post_state_to_bt(
5061 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
5062 halbtc8822b1ant_post_state_to_bt(
5063 btcoexist, BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
5064
5065 } else if (type == BTC_RF_OFF) {
5066 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5067 "[BTCoex], RF is turned OFF!!\n");
5068
5069 halbtc8822b1ant_post_state_to_bt(
5070 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
5071 halbtc8822b1ant_post_state_to_bt(
5072 btcoexist, BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
5073 halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
5074
5075 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5076 FORCE_EXEC,
5077 BT_8822B_1ANT_PHASE_WLAN_OFF);
5078
5079
5080 halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
5081
5082 btcoexist->stop_coex_dm = true;
5083 }
5084}
5085
5086void ex_btc8822b1ant_halt_notify(struct btc_coexist *btcoexist)
5087{
5088 struct rtl_priv *rtlpriv = btcoexist->adapter;
5089
5090 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n");
5091
5092 halbtc8822b1ant_post_state_to_bt(
5093 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
5094 halbtc8822b1ant_post_state_to_bt(btcoexist,
5095 BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
5096
5097 halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
5098
5099 halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
5100 BT_8822B_1ANT_PHASE_WLAN_OFF);
5101
5102
5103 halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
5104
5105 ex_btc8822b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
5106 btcoexist->stop_coex_dm = true;
5107}
5108
5109void ex_btc8822b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
5110{
5111 struct rtl_priv *rtlpriv = btcoexist->adapter;
5112 bool wifi_under_5g = false;
5113
5114 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
5115
5116 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5117
5118 if ((pnp_state == BTC_WIFI_PNP_SLEEP) ||
5119 (pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT)) {
5120 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5121 "[BTCoex], Pnp notify to SLEEP\n");
5122
5123 halbtc8822b1ant_post_state_to_bt(
5124 btcoexist, BT_8822B_1ANT_SCOREBOARD_ACTIVE |
5125 BT_8822B_1ANT_SCOREBOARD_ONOFF |
5126 BT_8822B_1ANT_SCOREBOARD_SCAN |
5127 BT_8822B_1ANT_SCOREBOARD_UNDERTEST,
5128 false);
5129
5130 if (pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT) {
5131 if (wifi_under_5g)
5132 halbtc8822b1ant_set_ant_path(
5133 btcoexist, BTC_ANT_PATH_AUTO,
5134 FORCE_EXEC,
5135 BT_8822B_1ANT_PHASE_5G_RUNTIME);
5136 else
5137 halbtc8822b1ant_set_ant_path(
5138 btcoexist, BTC_ANT_PATH_AUTO,
5139 FORCE_EXEC,
5140 BT_8822B_1ANT_PHASE_2G_RUNTIME);
5141 } else {
5142 halbtc8822b1ant_set_ant_path(
5143 btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
5144 BT_8822B_1ANT_PHASE_WLAN_OFF);
5145 }
5146
5147 btcoexist->stop_coex_dm = true;
5148 } else if (pnp_state == BTC_WIFI_PNP_WAKE_UP) {
5149 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5150 "[BTCoex], Pnp notify to WAKE UP\n");
5151 btcoexist->stop_coex_dm = false;
5152 }
5153}
5154
5155void ex_btc8822b1ant_coex_dm_reset(struct btc_coexist *btcoexist)
5156{
5157 struct rtl_priv *rtlpriv = btcoexist->adapter;
5158
5159 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5160 "[BTCoex], *****************Coex DM Reset*****************\n");
5161
5162 halbtc8822b1ant_init_hw_config(btcoexist, false, false);
5163 halbtc8822b1ant_init_coex_dm(btcoexist);
5164}
5165
5166void ex_btc8822b1ant_periodical(struct btc_coexist *btcoexist)
5167{
5168 struct rtl_priv *rtlpriv = btcoexist->adapter;
5169 bool bt_relink_finish = false;
5170
5171 RT_TRACE(
5172 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5173 "[BTCoex], ==========================Periodical===========================\n");
5174
5175 if (!btcoexist->auto_report_1ant)
5176 halbtc8822b1ant_query_bt_info(btcoexist);
5177
5178 halbtc8822b1ant_monitor_bt_ctr(btcoexist);
5179 halbtc8822b1ant_monitor_wifi_ctr(btcoexist);
5180
5181 halbtc8822b1ant_monitor_bt_enable_disable(btcoexist);
5182
5183 if (coex_sta->bt_relink_downcount != 0) {
5184 coex_sta->bt_relink_downcount--;
5185
5186 if (coex_sta->bt_relink_downcount == 0) {
5187 coex_sta->is_setup_link = false;
5188 bt_relink_finish = true;
5189 }
5190 }
5191
5192
5193 if (coex_sta->specific_pkt_period_cnt > 0) {
5194 coex_sta->specific_pkt_period_cnt--;
5195
5196 if ((coex_sta->specific_pkt_period_cnt == 0) &&
5197 (coex_sta->wifi_is_high_pri_task))
5198 coex_sta->wifi_is_high_pri_task = false;
5199
5200 RT_TRACE(
5201 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5202 "[BTCoex], ***************** Hi-Pri Task = %s*****************\n",
5203 (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"));
5204 }
5205
5206 if (halbtc8822b1ant_is_wifi_status_changed(btcoexist) ||
5207 (bt_relink_finish) || (coex_sta->is_set_ps_state_fail))
5208 halbtc8822b1ant_run_coexist_mechanism(btcoexist);
5209}
5210
5211void ex_btc8822b1ant_antenna_detection(struct btc_coexist *btcoexist,
5212 u32 cent_freq, u32 offset, u32 span,
5213 u32 seconds)
5214{
5215}
5216
5217void ex_btc8822b1ant_antenna_isolation(struct btc_coexist *btcoexist,
5218 u32 cent_freq, u32 offset, u32 span,
5219 u32 seconds)
5220{
5221}
5222
5223void ex_btc8822b1ant_psd_scan(struct btc_coexist *btcoexist, u32 cent_freq,
5224 u32 offset, u32 span, u32 seconds)
5225{
5226}
5227
5228void ex_btc8822b1ant_display_ant_detection(struct btc_coexist *btcoexist) {}
5229
5230void ex_btc8822b1ant_dbg_control(struct btc_coexist *btcoexist, u8 op_code,
5231 u8 op_len, u8 *pdata)
5232{
5233}
5234