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