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