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