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