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 * Description:
18 *
19 * This file is for 8821A_1ANT Co-exist mechanism
20 *
21 * History
22 * 2012/11/15 Cosa first check in.
23 *
24 * ************************************************************
25 * SY modify 2015/04/27
26 * ************************************************************
27 * include files
28 * ************************************************************ */
29 #include "mp_precomp.h"
30
31 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
32
33 #if (RTL8821A_SUPPORT == 1)
34 /* ************************************************************
35 * Global variables, these are static variables
36 * ************************************************************ */
37 static u8 *trace_buf = &gl_btc_trace_buf[0];
38 static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant;
39 static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant;
40 static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant;
41 static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant;
42
43 const char *const glbt_info_src_8821a_1ant[] = {
44 "BT Info[wifi fw]",
45 "BT Info[bt rsp]",
46 "BT Info[bt auto report]",
47 };
48
49 u32 glcoex_ver_date_8821a_1ant = 20170206;
50 u32 glcoex_ver_8821a_1ant = 0x67;
51 u32 glcoex_ver_btdesired_8821a_1ant = 0x62;
52
53 /* ************************************************************
54 * local function proto type if needed
55 * ************************************************************
56 * ************************************************************
57 * local function start with halbtc8821a1ant_
58 * ************************************************************ */
halbtc8821a1ant_bt_rssi_state(u8 level_num,u8 rssi_thresh,u8 rssi_thresh1)59 u8 halbtc8821a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
60 {
61 s32 bt_rssi = 0;
62 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
63
64 bt_rssi = coex_sta->bt_rssi;
65
66 if (level_num == 2) {
67 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
68 (coex_sta->pre_bt_rssi_state ==
69 BTC_RSSI_STATE_STAY_LOW)) {
70 if (bt_rssi >= (rssi_thresh +
71 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
72 bt_rssi_state = BTC_RSSI_STATE_HIGH;
73 else
74 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
75 } else {
76 if (bt_rssi < rssi_thresh)
77 bt_rssi_state = BTC_RSSI_STATE_LOW;
78 else
79 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
80 }
81 } else if (level_num == 3) {
82 if (rssi_thresh > rssi_thresh1) {
83 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
84 "[BTCoex], BT Rssi thresh error!!\n");
85 BTC_TRACE(trace_buf);
86 return coex_sta->pre_bt_rssi_state;
87 }
88
89 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
90 (coex_sta->pre_bt_rssi_state ==
91 BTC_RSSI_STATE_STAY_LOW)) {
92 if (bt_rssi >= (rssi_thresh +
93 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
94 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
95 else
96 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
97 } else if ((coex_sta->pre_bt_rssi_state ==
98 BTC_RSSI_STATE_MEDIUM) ||
99 (coex_sta->pre_bt_rssi_state ==
100 BTC_RSSI_STATE_STAY_MEDIUM)) {
101 if (bt_rssi >= (rssi_thresh1 +
102 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
103 bt_rssi_state = BTC_RSSI_STATE_HIGH;
104 else if (bt_rssi < rssi_thresh)
105 bt_rssi_state = BTC_RSSI_STATE_LOW;
106 else
107 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
108 } else {
109 if (bt_rssi < rssi_thresh1)
110 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
111 else
112 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
113 }
114 }
115
116 coex_sta->pre_bt_rssi_state = bt_rssi_state;
117
118 return bt_rssi_state;
119 }
120
halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist * btcoexist,IN u8 index,IN u8 level_num,IN u8 rssi_thresh,IN u8 rssi_thresh1)121 u8 halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
122 IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
123 {
124 s32 wifi_rssi = 0;
125 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
126
127 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
128
129 if (level_num == 2) {
130 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
131 ||
132 (coex_sta->pre_wifi_rssi_state[index] ==
133 BTC_RSSI_STATE_STAY_LOW)) {
134 if (wifi_rssi >= (rssi_thresh +
135 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
136 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
137 else
138 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
139 } else {
140 if (wifi_rssi < rssi_thresh)
141 wifi_rssi_state = BTC_RSSI_STATE_LOW;
142 else
143 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
144 }
145 } else if (level_num == 3) {
146 if (rssi_thresh > rssi_thresh1) {
147 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
148 "[BTCoex], wifi RSSI thresh error!!\n");
149 BTC_TRACE(trace_buf);
150 return coex_sta->pre_wifi_rssi_state[index];
151 }
152
153 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
154 ||
155 (coex_sta->pre_wifi_rssi_state[index] ==
156 BTC_RSSI_STATE_STAY_LOW)) {
157 if (wifi_rssi >= (rssi_thresh +
158 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
159 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
160 else
161 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
162 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
163 BTC_RSSI_STATE_MEDIUM) ||
164 (coex_sta->pre_wifi_rssi_state[index] ==
165 BTC_RSSI_STATE_STAY_MEDIUM)) {
166 if (wifi_rssi >= (rssi_thresh1 +
167 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
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 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
182
183 return wifi_rssi_state;
184 }
185
halbtc8821a1ant_update_ra_mask(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 dis_rate_mask)186 void halbtc8821a1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
187 IN boolean force_exec, IN u32 dis_rate_mask)
188 {
189 coex_dm->cur_ra_mask = dis_rate_mask;
190
191 if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
192 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
193 &coex_dm->cur_ra_mask);
194 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
195 }
196
halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)197 void halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
198 IN boolean force_exec, IN u8 type)
199 {
200 boolean wifi_under_b_mode = false;
201
202 coex_dm->cur_arfr_type = type;
203
204 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
205 switch (coex_dm->cur_arfr_type) {
206 case 0: /* normal mode */
207 btcoexist->btc_write_4byte(btcoexist, 0x430,
208 coex_dm->backup_arfr_cnt1);
209 btcoexist->btc_write_4byte(btcoexist, 0x434,
210 coex_dm->backup_arfr_cnt2);
211 break;
212 case 1:
213 btcoexist->btc_get(btcoexist,
214 BTC_GET_BL_WIFI_UNDER_B_MODE,
215 &wifi_under_b_mode);
216 if (wifi_under_b_mode) {
217 btcoexist->btc_write_4byte(btcoexist,
218 0x430, 0x0);
219 btcoexist->btc_write_4byte(btcoexist,
220 0x434, 0x01010101);
221 } else {
222 btcoexist->btc_write_4byte(btcoexist,
223 0x430, 0x0);
224 btcoexist->btc_write_4byte(btcoexist,
225 0x434, 0x04030201);
226 }
227 break;
228 default:
229 break;
230 }
231 }
232
233 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
234 }
235
halbtc8821a1ant_retry_limit(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)236 void halbtc8821a1ant_retry_limit(IN struct btc_coexist *btcoexist,
237 IN boolean force_exec, IN u8 type)
238 {
239 coex_dm->cur_retry_limit_type = type;
240
241 if (force_exec ||
242 (coex_dm->pre_retry_limit_type !=
243 coex_dm->cur_retry_limit_type)) {
244 switch (coex_dm->cur_retry_limit_type) {
245 case 0: /* normal mode */
246 btcoexist->btc_write_2byte(btcoexist, 0x42a,
247 coex_dm->backup_retry_limit);
248 break;
249 case 1: /* retry limit=8 */
250 btcoexist->btc_write_2byte(btcoexist, 0x42a,
251 0x0808);
252 break;
253 default:
254 break;
255 }
256 }
257
258 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
259 }
260
halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)261 void halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
262 IN boolean force_exec, IN u8 type)
263 {
264 coex_dm->cur_ampdu_time_type = type;
265
266 if (force_exec ||
267 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
268 switch (coex_dm->cur_ampdu_time_type) {
269 case 0: /* normal mode */
270 btcoexist->btc_write_1byte(btcoexist, 0x456,
271 coex_dm->backup_ampdu_max_time);
272 break;
273 case 1: /* AMPDU timw = 0x38 * 32us */
274 btcoexist->btc_write_1byte(btcoexist, 0x456,
275 0x38);
276 break;
277 default:
278 break;
279 }
280 }
281
282 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
283 }
284
halbtc8821a1ant_limited_tx(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 ra_mask_type,IN u8 arfr_type,IN u8 retry_limit_type,IN u8 ampdu_time_type)285 void halbtc8821a1ant_limited_tx(IN struct btc_coexist *btcoexist,
286 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
287 IN u8 retry_limit_type, IN u8 ampdu_time_type)
288 {
289 switch (ra_mask_type) {
290 case 0: /* normal mode */
291 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
292 0x0);
293 break;
294 case 1: /* disable cck 1/2 */
295 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
296 0x00000003);
297 break;
298 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
299 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
300 0x0001f1f7);
301 break;
302 default:
303 break;
304 }
305
306 halbtc8821a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
307 arfr_type);
308 halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
309 halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
310 }
311
312
313 /* true/xxxx/x:1
314 * false/false/x: 64
315 * false/true/x:x */
halbtc8821a1ant_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)316 void halbtc8821a1ant_limited_rx(IN struct btc_coexist *btcoexist,
317 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
318 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
319 {
320 boolean reject_rx_agg = rej_ap_agg_pkt;
321 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
322 u8 rx_agg_size = agg_buf_size;
323
324 /* ============================================ */
325 /* Rx Aggregation related setting */
326 /* ============================================ */
327 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
328 &reject_rx_agg);
329 /* decide BT control aggregation buf size or not */
330 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
331 &bt_ctrl_rx_agg_size);
332 /* aggregation buf size, only work when BT control Rx aggregation size. */
333 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
334 /* real update aggregation setting */
335 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
336
337
338 }
339
halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist * btcoexist)340 void halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
341 {
342 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
343 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
344 #if 0
345 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
346 if (!(btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8)) {
347 coex_sta->high_priority_tx = 65535;
348 coex_sta->high_priority_rx = 65535;
349 coex_sta->low_priority_tx = 65535;
350 coex_sta->low_priority_rx = 65535;
351 return;
352 }
353 #endif
354 reg_hp_txrx = 0x770;
355 reg_lp_txrx = 0x774;
356
357 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
358 reg_hp_tx = u32tmp & MASKLWORD;
359 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
360
361 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
362 reg_lp_tx = u32tmp & MASKLWORD;
363 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
364
365 coex_sta->high_priority_tx = reg_hp_tx;
366 coex_sta->high_priority_rx = reg_hp_rx;
367 coex_sta->low_priority_tx = reg_lp_tx;
368 coex_sta->low_priority_rx = reg_lp_rx;
369
370 /* reset counter */
371 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
372 }
373
halbtc8821a1ant_monitor_wifi_ctr(IN struct btc_coexist * btcoexist)374 void halbtc8821a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
375 {
376 #if 1
377
378 coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(
379 btcoexist,
380 PHYDM_INFO_CRC32_OK_CCK);
381 coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(
382 btcoexist,
383 PHYDM_INFO_CRC32_OK_LEGACY);
384 coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(
385 btcoexist,
386 PHYDM_INFO_CRC32_OK_HT);
387 coex_sta->crc_ok_11n_vht =
388 btcoexist->btc_phydm_query_PHY_counter(
389 btcoexist,
390 PHYDM_INFO_CRC32_OK_VHT);
391
392 coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter(
393 btcoexist,
394 PHYDM_INFO_CRC32_ERROR_CCK);
395 coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter(
396 btcoexist,
397 PHYDM_INFO_CRC32_ERROR_LEGACY);
398 coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter(
399 btcoexist,
400 PHYDM_INFO_CRC32_ERROR_HT);
401 coex_sta->crc_err_11n_vht =
402 btcoexist->btc_phydm_query_PHY_counter(
403 btcoexist,
404 PHYDM_INFO_CRC32_ERROR_VHT);
405
406 #endif
407 }
408
409
halbtc8821a1ant_query_bt_info(IN struct btc_coexist * btcoexist)410 void halbtc8821a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
411 {
412 u8 h2c_parameter[1] = {0};
413
414 coex_sta->c2h_bt_info_req_sent = true;
415
416 h2c_parameter[0] |= BIT(0); /* trigger */
417
418 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
419 }
420
halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist * btcoexist)421 boolean halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
422 {
423 static boolean pre_wifi_busy = false, pre_under_4way = false,
424 pre_bt_hs_on = false;
425 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
426 boolean wifi_connected = false;
427
428 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
429 &wifi_connected);
430 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
431 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
432 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
433 &under_4way);
434
435 if (wifi_connected) {
436 if (wifi_busy != pre_wifi_busy) {
437 pre_wifi_busy = wifi_busy;
438 return true;
439 }
440 if (under_4way != pre_under_4way) {
441 pre_under_4way = under_4way;
442 return true;
443 }
444 if (bt_hs_on != pre_bt_hs_on) {
445 pre_bt_hs_on = bt_hs_on;
446 return true;
447 }
448 }
449
450 return false;
451 }
452
halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist * btcoexist)453 void halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
454 {
455 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
456 boolean bt_hs_on = false;
457
458 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
459
460 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
461 bt_link_info->sco_exist = coex_sta->sco_exist;
462 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
463 bt_link_info->pan_exist = coex_sta->pan_exist;
464 bt_link_info->hid_exist = coex_sta->hid_exist;
465
466 /* work around for HS mode. */
467 if (bt_hs_on) {
468 bt_link_info->pan_exist = true;
469 bt_link_info->bt_link_exist = true;
470 }
471
472 /* check if Sco only */
473 if (bt_link_info->sco_exist &&
474 !bt_link_info->a2dp_exist &&
475 !bt_link_info->pan_exist &&
476 !bt_link_info->hid_exist)
477 bt_link_info->sco_only = true;
478 else
479 bt_link_info->sco_only = false;
480
481 /* check if A2dp only */
482 if (!bt_link_info->sco_exist &&
483 bt_link_info->a2dp_exist &&
484 !bt_link_info->pan_exist &&
485 !bt_link_info->hid_exist)
486 bt_link_info->a2dp_only = true;
487 else
488 bt_link_info->a2dp_only = false;
489
490 /* check if Pan only */
491 if (!bt_link_info->sco_exist &&
492 !bt_link_info->a2dp_exist &&
493 bt_link_info->pan_exist &&
494 !bt_link_info->hid_exist)
495 bt_link_info->pan_only = true;
496 else
497 bt_link_info->pan_only = false;
498
499 /* check if Hid only */
500 if (!bt_link_info->sco_exist &&
501 !bt_link_info->a2dp_exist &&
502 !bt_link_info->pan_exist &&
503 bt_link_info->hid_exist)
504 bt_link_info->hid_only = true;
505 else
506 bt_link_info->hid_only = false;
507 }
508
halbtc8821a1ant_action_algorithm(IN struct btc_coexist * btcoexist)509 u8 halbtc8821a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
510 {
511 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
512 boolean bt_hs_on = false;
513 u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
514 u8 num_of_diff_profile = 0;
515
516 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
517
518 if (!bt_link_info->bt_link_exist) {
519 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
520 "[BTCoex], No BT link exists!!!\n");
521 BTC_TRACE(trace_buf);
522 return algorithm;
523 }
524
525 if (bt_link_info->sco_exist)
526 num_of_diff_profile++;
527 if (bt_link_info->hid_exist)
528 num_of_diff_profile++;
529 if (bt_link_info->pan_exist)
530 num_of_diff_profile++;
531 if (bt_link_info->a2dp_exist)
532 num_of_diff_profile++;
533
534 if (num_of_diff_profile == 1) {
535 if (bt_link_info->sco_exist) {
536 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
537 "[BTCoex], BT Profile = SCO only\n");
538 BTC_TRACE(trace_buf);
539 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
540 } else {
541 if (bt_link_info->hid_exist) {
542 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
543 "[BTCoex], BT Profile = HID only\n");
544 BTC_TRACE(trace_buf);
545 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
546 } else if (bt_link_info->a2dp_exist) {
547 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
548 "[BTCoex], BT Profile = A2DP only\n");
549 BTC_TRACE(trace_buf);
550 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
551 } else if (bt_link_info->pan_exist) {
552 if (bt_hs_on) {
553 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
554 "[BTCoex], BT Profile = PAN(HS) only\n");
555 BTC_TRACE(trace_buf);
556 algorithm =
557 BT_8821A_1ANT_COEX_ALGO_PANHS;
558 } else {
559 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
560 "[BTCoex], BT Profile = PAN(EDR) only\n");
561 BTC_TRACE(trace_buf);
562 algorithm =
563 BT_8821A_1ANT_COEX_ALGO_PANEDR;
564 }
565 }
566 }
567 } else if (num_of_diff_profile == 2) {
568 if (bt_link_info->sco_exist) {
569 if (bt_link_info->hid_exist) {
570 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
571 "[BTCoex], BT Profile = SCO + HID\n");
572 BTC_TRACE(trace_buf);
573 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
574 } else if (bt_link_info->a2dp_exist) {
575 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
576 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
577 BTC_TRACE(trace_buf);
578 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
579 } else if (bt_link_info->pan_exist) {
580 if (bt_hs_on) {
581 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
582 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
583 BTC_TRACE(trace_buf);
584 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
585 } else {
586 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
587 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
588 BTC_TRACE(trace_buf);
589 algorithm =
590 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
591 }
592 }
593 } else {
594 if (bt_link_info->hid_exist &&
595 bt_link_info->a2dp_exist) {
596 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
597 "[BTCoex], BT Profile = HID + A2DP\n");
598 BTC_TRACE(trace_buf);
599 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
600 } else if (bt_link_info->hid_exist &&
601 bt_link_info->pan_exist) {
602 if (bt_hs_on) {
603 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
604 "[BTCoex], BT Profile = HID + PAN(HS)\n");
605 BTC_TRACE(trace_buf);
606 algorithm =
607 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
608 } else {
609 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
610 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
611 BTC_TRACE(trace_buf);
612 algorithm =
613 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
614 }
615 } else if (bt_link_info->pan_exist &&
616 bt_link_info->a2dp_exist) {
617 if (bt_hs_on) {
618 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
619 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
620 BTC_TRACE(trace_buf);
621 algorithm =
622 BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
623 } else {
624 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
625 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
626 BTC_TRACE(trace_buf);
627 algorithm =
628 BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
629 }
630 }
631 }
632 } else if (num_of_diff_profile == 3) {
633 if (bt_link_info->sco_exist) {
634 if (bt_link_info->hid_exist &&
635 bt_link_info->a2dp_exist) {
636 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
637 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
638 BTC_TRACE(trace_buf);
639 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
640 } else if (bt_link_info->hid_exist &&
641 bt_link_info->pan_exist) {
642 if (bt_hs_on) {
643 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
644 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
645 BTC_TRACE(trace_buf);
646 algorithm =
647 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
648 } else {
649 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
650 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
651 BTC_TRACE(trace_buf);
652 algorithm =
653 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
654 }
655 } else if (bt_link_info->pan_exist &&
656 bt_link_info->a2dp_exist) {
657 if (bt_hs_on) {
658 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
659 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
660 BTC_TRACE(trace_buf);
661 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
662 } else {
663 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
664 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
665 BTC_TRACE(trace_buf);
666 algorithm =
667 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
668 }
669 }
670 } else {
671 if (bt_link_info->hid_exist &&
672 bt_link_info->pan_exist &&
673 bt_link_info->a2dp_exist) {
674 if (bt_hs_on) {
675 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
676 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
677 BTC_TRACE(trace_buf);
678 algorithm =
679 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
680 } else {
681 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
682 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
683 BTC_TRACE(trace_buf);
684 algorithm =
685 BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
686 }
687 }
688 }
689 } else if (num_of_diff_profile >= 3) {
690 if (bt_link_info->sco_exist) {
691 if (bt_link_info->hid_exist &&
692 bt_link_info->pan_exist &&
693 bt_link_info->a2dp_exist) {
694 if (bt_hs_on) {
695 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
696 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
697 BTC_TRACE(trace_buf);
698
699 } else {
700 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
701 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
702 BTC_TRACE(trace_buf);
703 algorithm =
704 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
705 }
706 }
707 }
708 }
709
710 return algorithm;
711 }
712
halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean enable_auto_report)713 void halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
714 IN boolean enable_auto_report)
715 {
716 u8 h2c_parameter[1] = {0};
717
718 h2c_parameter[0] = 0;
719
720 if (enable_auto_report)
721 h2c_parameter[0] |= BIT(0);
722
723 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
724 }
725
halbtc8821a1ant_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable_auto_report)726 void halbtc8821a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
727 IN boolean force_exec, IN boolean enable_auto_report)
728 {
729 coex_dm->cur_bt_auto_report = enable_auto_report;
730
731 if (!force_exec) {
732 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
733 return;
734 }
735 halbtc8821a1ant_set_bt_auto_report(btcoexist,
736 coex_dm->cur_bt_auto_report);
737
738 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
739 }
740
halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist * btcoexist,IN boolean low_penalty_ra)741 void halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
742 *btcoexist, IN boolean low_penalty_ra)
743 {
744 u8 h2c_parameter[6] = {0};
745
746 h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
747
748 if (low_penalty_ra) {
749 h2c_parameter[1] |= BIT(0);
750 h2c_parameter[2] =
751 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
752 h2c_parameter[3] = 0xf5; /* MCS7 or OFDM54 */
753 h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */
754 h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */
755 }
756
757 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
758 }
759
halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean low_penalty_ra)760 void halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
761 IN boolean force_exec, IN boolean low_penalty_ra)
762 {
763 coex_dm->cur_low_penalty_ra = low_penalty_ra;
764
765 if (!force_exec) {
766 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
767 return;
768 }
769 halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
770 coex_dm->cur_low_penalty_ra);
771
772 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
773 }
774
halbtc8821a1ant_sw_mechanism(IN struct btc_coexist * btcoexist,IN boolean low_penalty_ra)775 void halbtc8821a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
776 IN boolean low_penalty_ra)
777 {
778 halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
779 }
780
halbtc8821a1ant_set_coex_table(IN struct btc_coexist * btcoexist,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)781 void halbtc8821a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
782 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
783 {
784 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
785
786 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
787
788 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
789
790 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
791 }
792
halbtc8821a1ant_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)793 void halbtc8821a1ant_coex_table(IN struct btc_coexist *btcoexist,
794 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
795 IN u32 val0x6c8, IN u8 val0x6cc)
796 {
797 coex_dm->cur_val0x6c0 = val0x6c0;
798 coex_dm->cur_val0x6c4 = val0x6c4;
799 coex_dm->cur_val0x6c8 = val0x6c8;
800 coex_dm->cur_val0x6cc = val0x6cc;
801
802 if (!force_exec) {
803 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
804 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
805 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
806 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
807 return;
808 }
809 halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
810 val0x6cc);
811
812 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
813 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
814 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
815 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
816 }
817
halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)818 void halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
819 IN boolean force_exec, IN u8 type)
820 {
821 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
822 "[BTCoex], ********** CoexTable(%d) **********\n", type);
823 BTC_TRACE(trace_buf);
824
825 switch (type) {
826 case 0:
827 halbtc8821a1ant_coex_table(btcoexist, force_exec,
828 0x55555555, 0x55555555, 0xffffff, 0x3);
829 break;
830 case 1:
831 halbtc8821a1ant_coex_table(btcoexist, force_exec,
832 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
833 break;
834 case 2:
835 halbtc8821a1ant_coex_table(btcoexist, force_exec,
836 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
837 break;
838 case 3:
839 halbtc8821a1ant_coex_table(btcoexist, force_exec,
840 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);
841 break;
842 case 4:
843 halbtc8821a1ant_coex_table(btcoexist, force_exec,
844 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
845 break;
846 case 5:
847 halbtc8821a1ant_coex_table(btcoexist, force_exec,
848 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
849 break;
850 case 6:
851 halbtc8821a1ant_coex_table(btcoexist, force_exec,
852 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
853 break;
854 case 7:
855 halbtc8821a1ant_coex_table(btcoexist, force_exec,
856 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
857 break;
858 default:
859 break;
860 }
861 }
862
halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean enable)863 void halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
864 IN boolean enable)
865 {
866 u8 h2c_parameter[1] = {0};
867
868 if (enable)
869 h2c_parameter[0] |= BIT(0); /* function enable */
870
871 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
872 }
873
halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable)874 void halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
875 IN boolean force_exec, IN boolean enable)
876 {
877 coex_dm->cur_ignore_wlan_act = enable;
878
879 if (!force_exec) {
880 if (coex_dm->pre_ignore_wlan_act ==
881 coex_dm->cur_ignore_wlan_act)
882 return;
883 }
884 halbtc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
885
886 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
887 }
888
halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist * btcoexist,IN u8 lps_val,IN u8 rpwm_val)889 void halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
890 IN u8 lps_val, IN u8 rpwm_val)
891 {
892 u8 lps = lps_val;
893 u8 rpwm = rpwm_val;
894
895 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
896 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
897 }
898
halbtc8821a1ant_lps_rpwm(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 lps_val,IN u8 rpwm_val)899 void halbtc8821a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
900 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
901 {
902 coex_dm->cur_lps = lps_val;
903 coex_dm->cur_rpwm = rpwm_val;
904
905 if (!force_exec) {
906 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
907 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
908 return;
909 }
910 halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
911
912 coex_dm->pre_lps = coex_dm->cur_lps;
913 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
914 }
915
halbtc8821a1ant_set_ant_path(IN struct btc_coexist * btcoexist,IN u8 ant_pos_type,IN boolean init_hwcfg,IN boolean wifi_off)916 void halbtc8821a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
917 IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
918 {
919 struct btc_board_info *board_info = &btcoexist->board_info;
920 u32 u32tmp = 0;
921 u8 h2c_parameter[2] = {0};
922
923 if (init_hwcfg) {
924
925 /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
926 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
927 u32tmp &= ~BIT(23);
928 u32tmp |= BIT(24);
929 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
930
931 /* 0x765 = 0x18 */
932 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
933
934 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
935 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
936 "[BTCoex], 1\n");
937 BTC_TRACE(trace_buf);
938 /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
939 h2c_parameter[0] = 1;
940 h2c_parameter[1] = 1;
941 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
942 h2c_parameter);
943
944 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1); */ /*Main Ant to BT for IPS case 0x4c[23]=1 */
945 } else {
946 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
947 "[BTCoex], 2\n");
948 BTC_TRACE(trace_buf);
949 /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
950 h2c_parameter[0] = 0;
951 h2c_parameter[1] = 1;
952 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
953 h2c_parameter);
954
955 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); */ /*Aux Ant to BT for IPS case 0x4c[23]=1 */
956 }
957 } else if (wifi_off) {
958 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
959 "[BTCoex], 3\n");
960 BTC_TRACE(trace_buf);
961 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002 */
962 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
963 u32tmp &= ~BIT(23);
964 u32tmp &= ~BIT(24);
965 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
966
967 /* 0x765 = 0x18 */
968 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
969 } else {
970 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
971 "[BTCoex], 4\n");
972 BTC_TRACE(trace_buf);
973 /* 0x765 = 0x0 */
974 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
975 }
976
977 /* ext switch setting */
978 switch (ant_pos_type) {
979 case BTC_ANT_PATH_WIFI:
980 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
981 if (board_info->btdm_ant_pos ==
982 BTC_ANTENNA_AT_MAIN_PORT)
983 btcoexist->btc_write_1byte_bitmask(btcoexist,
984 0xcb7, 0x30, 0x1);
985 else
986 btcoexist->btc_write_1byte_bitmask(btcoexist,
987 0xcb7, 0x30, 0x2);
988 break;
989 case BTC_ANT_PATH_BT:
990 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
991 if (board_info->btdm_ant_pos ==
992 BTC_ANTENNA_AT_MAIN_PORT)
993 btcoexist->btc_write_1byte_bitmask(btcoexist,
994 0xcb7, 0x30, 0x2);
995 else
996 btcoexist->btc_write_1byte_bitmask(btcoexist,
997 0xcb7, 0x30, 0x1);
998 break;
999 default:
1000 case BTC_ANT_PATH_PTA:
1001 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66);
1002 if (board_info->btdm_ant_pos ==
1003 BTC_ANTENNA_AT_MAIN_PORT)
1004 btcoexist->btc_write_1byte_bitmask(btcoexist,
1005 0xcb7, 0x30, 0x1);
1006 else
1007 btcoexist->btc_write_1byte_bitmask(btcoexist,
1008 0xcb7, 0x30, 0x2);
1009 break;
1010 }
1011 }
1012
1013
halbtc8821a1ant_ps_tdma_check_for_power_save_state(IN struct btc_coexist * btcoexist,IN boolean new_ps_state)1014 void halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1015 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1016 {
1017 u8 lps_mode = 0x0;
1018 u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
1019
1020 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1021
1022 if (lps_mode) { /* already under LPS state */
1023 if (new_ps_state) {
1024 /* keep state under LPS, do nothing. */
1025 } else {
1026 /* will leave LPS state, turn off psTdma first */
1027 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,8); */
1028 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1029 h2c_parameter);
1030 }
1031 } else { /* NO PS state */
1032 if (new_ps_state) {
1033 /* will enter LPS state, turn off psTdma first */
1034 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,8); */
1035 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1036 h2c_parameter);
1037 } else {
1038 /* keep state under NO PS state, do nothing. */
1039 }
1040 }
1041 }
1042
halbtc8821a1ant_power_save_state(IN struct btc_coexist * btcoexist,IN u8 ps_type,IN u8 lps_val,IN u8 rpwm_val)1043 void halbtc8821a1ant_power_save_state(IN struct btc_coexist *btcoexist,
1044 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1045 {
1046 boolean low_pwr_disable = false;
1047
1048 switch (ps_type) {
1049 case BTC_PS_WIFI_NATIVE:
1050 /* recover to original 32k low power setting */
1051 low_pwr_disable = false;
1052 btcoexist->btc_set(btcoexist,
1053 BTC_SET_ACT_DISABLE_LOW_POWER,
1054 &low_pwr_disable);
1055 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1056 NULL);
1057 break;
1058 case BTC_PS_LPS_ON:
1059 halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1060 btcoexist, true);
1061 halbtc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1062 lps_val, rpwm_val);
1063 /* when coex force to enter LPS, do not enter 32k low power. */
1064 low_pwr_disable = true;
1065 btcoexist->btc_set(btcoexist,
1066 BTC_SET_ACT_DISABLE_LOW_POWER,
1067 &low_pwr_disable);
1068 /* power save must executed before psTdma. */
1069 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1070 NULL);
1071 break;
1072 case BTC_PS_LPS_OFF:
1073 halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1074 btcoexist, false);
1075 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1076 NULL);
1077 break;
1078 default:
1079 break;
1080 }
1081 }
1082
halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist * btcoexist,IN u8 byte1,IN u8 byte2,IN u8 byte3,IN u8 byte4,IN u8 byte5)1083 void halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1084 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1085 {
1086 u8 h2c_parameter[5] = {0};
1087 u8 real_byte1 = byte1, real_byte5 = byte5;
1088 boolean ap_enable = false;
1089
1090 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1091 &ap_enable);
1092
1093 if (ap_enable) {
1094 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1095 real_byte1 &= ~BIT(4);
1096 real_byte1 |= BIT(5);
1097
1098 real_byte5 |= BIT(5);
1099 real_byte5 &= ~BIT(6);
1100
1101 halbtc8821a1ant_power_save_state(btcoexist,
1102 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1103 }
1104 } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1105 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4);
1106
1107 } else {
1108 halbtc8821a1ant_power_save_state(btcoexist,
1109 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1110 }
1111
1112 h2c_parameter[0] = real_byte1;
1113 h2c_parameter[1] = byte2;
1114 h2c_parameter[2] = byte3;
1115 h2c_parameter[3] = byte4;
1116 h2c_parameter[4] = real_byte5;
1117
1118 coex_dm->ps_tdma_para[0] = real_byte1;
1119 coex_dm->ps_tdma_para[1] = byte2;
1120 coex_dm->ps_tdma_para[2] = byte3;
1121 coex_dm->ps_tdma_para[3] = byte4;
1122 coex_dm->ps_tdma_para[4] = real_byte5;
1123
1124 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1125 }
1126
halbtc8821a1ant_ps_tdma(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean turn_on,IN u8 type)1127 void halbtc8821a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1128 IN boolean force_exec, IN boolean turn_on, IN u8 type)
1129 {
1130 u8 rssi_adjust_val = 0;
1131 /* u32 fw_ver=0; */
1132
1133 coex_dm->cur_ps_tdma_on = turn_on;
1134 coex_dm->cur_ps_tdma = type;
1135
1136 if (coex_dm->cur_ps_tdma_on) {
1137 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1138 "[BTCoex], ********** TDMA(on, %d) **********\n",
1139 coex_dm->cur_ps_tdma);
1140 BTC_TRACE(trace_buf);
1141 } else {
1142 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1143 "[BTCoex], ********** TDMA(off, %d) **********\n",
1144 coex_dm->cur_ps_tdma);
1145 BTC_TRACE(trace_buf);
1146 }
1147
1148 if (!force_exec) {
1149 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1150 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1151 return;
1152 }
1153 if (turn_on) {
1154 switch (type) {
1155 default:
1156 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1157 0x1a, 0x1a, 0x0, 0x50);
1158 break;
1159 case 1:
1160 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1161 0x3a, 0x03, 0x10, 0x50);
1162 rssi_adjust_val = 11;
1163 break;
1164 case 2:
1165 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1166 0x2b, 0x03, 0x10, 0x50);
1167 rssi_adjust_val = 14;
1168 break;
1169 case 3:
1170 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1171 0x1d, 0x1d, 0x0, 0x52);
1172 break;
1173 case 4:
1174 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1175 0x15, 0x3, 0x14, 0x0);
1176 rssi_adjust_val = 17;
1177 break;
1178 case 5:
1179 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1180 0x15, 0x3, 0x11, 0x10);
1181 break;
1182 case 6:
1183 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1184 0x20, 0x3, 0x11, 0x13);
1185 break;
1186 case 7:
1187 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1188 0xc, 0x5, 0x0, 0x0);
1189 break;
1190 case 8:
1191 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1192 0x25, 0x3, 0x10, 0x0);
1193 break;
1194 case 9:
1195 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1196 0x21, 0x3, 0x10, 0x50);
1197 rssi_adjust_val = 18;
1198 break;
1199 case 10:
1200 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1201 0xa, 0xa, 0x0, 0x40);
1202 break;
1203 case 11:
1204 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1205 0x15, 0x03, 0x10, 0x50);
1206 rssi_adjust_val = 20;
1207 break;
1208 case 12:
1209 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1210 0x0a, 0x0a, 0x0, 0x50);
1211 break;
1212 case 13:
1213
1214 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1215 0x40, 0x3, 0x10, 0x50);
1216
1217 break;
1218 case 14:
1219
1220 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1221 0x1e, 0x3, 0x10, 0x14);
1222 break;
1223 case 15:
1224 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1225 0xa, 0x3, 0x8, 0x0);
1226 break;
1227 case 16:
1228 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1229 0x15, 0x3, 0x10, 0x0);
1230 rssi_adjust_val = 18;
1231 break;
1232 case 18:
1233 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1234 0x25, 0x3, 0x10, 0x0);
1235 rssi_adjust_val = 14;
1236 break;
1237 case 20:
1238 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1239 0x35, 0x03, 0x11, 0x10);
1240 break;
1241 case 21:
1242 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1243 0x25, 0x03, 0x11, 0x11);
1244 break;
1245 case 22:
1246 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1247 0x25, 0x03, 0x11, 0x10);
1248 break;
1249 case 23:
1250 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1251 0x25, 0x3, 0x31, 0x18);
1252 rssi_adjust_val = 22;
1253 break;
1254 case 24:
1255 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1256 0x15, 0x3, 0x31, 0x18);
1257 rssi_adjust_val = 22;
1258 break;
1259 case 25:
1260 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1261 0xa, 0x3, 0x31, 0x18);
1262 rssi_adjust_val = 22;
1263 break;
1264 case 26:
1265 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1266 0xa, 0x3, 0x31, 0x18);
1267 rssi_adjust_val = 22;
1268 break;
1269 case 27:
1270 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1271 0x25, 0x3, 0x31, 0x98);
1272 rssi_adjust_val = 22;
1273 break;
1274 case 28:
1275 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69,
1276 0x25, 0x3, 0x31, 0x0);
1277 break;
1278 case 29:
1279 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab,
1280 0x1a, 0x1a, 0x1, 0x10);
1281 break;
1282 case 30:
1283 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1284 0x30, 0x3, 0x10, 0x10);
1285 break;
1286 case 31:
1287 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1288 0x1a, 0x1a, 0, 0x58);
1289 break;
1290 case 32:
1291 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1292 0x35, 0x3, 0x11, 0x11);
1293 break;
1294 case 33:
1295 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3,
1296 0x25, 0x3, 0x30, 0x90);
1297 break;
1298 case 34:
1299 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53,
1300 0x1a, 0x1a, 0x0, 0x10);
1301 break;
1302 case 35:
1303 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63,
1304 0x1a, 0x1a, 0x0, 0x10);
1305 break;
1306 case 36:
1307 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1308 0x12, 0x3, 0x14, 0x50);
1309 break;
1310 case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1311 /* here softap mode screen off will cost 70-80mA for phone */
1312 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x23,
1313 0x18, 0x00, 0x10, 0x24);
1314 break;
1315 case 41:
1316 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1317 0x15, 0x3, 0x11, 0x11);
1318 break;
1319 case 42:
1320 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1321 0x20, 0x3, 0x11, 0x11);
1322 break;
1323 case 43:
1324 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1325 0x30, 0x3, 0x10, 0x11);
1326 break;
1327 case 44:
1328 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1329 0x20, 0x3, 0x10, 0x14);
1330 case 45:
1331 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1332 0x25, 0x3, 0x10, 0x10);
1333 break;
1334 case 46:
1335 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1336 0x35, 0x3, 0x10, 0x10);
1337 break;
1338 }
1339 } else {
1340 /* disable PS tdma */
1341 switch (type) {
1342 case 8: /* PTA Control */
1343 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8,
1344 0x0, 0x0, 0x0, 0x0);
1345 halbtc8821a1ant_set_ant_path(btcoexist,
1346 BTC_ANT_PATH_PTA, false, false);
1347 break;
1348 case 0:
1349 default: /* Software control, Antenna at BT side */
1350 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1351 0x0, 0x0, 0x0, 0x0);
1352 halbtc8821a1ant_set_ant_path(btcoexist,
1353 BTC_ANT_PATH_BT, false, false);
1354 break;
1355 case 9: /* Software control, Antenna at WiFi side */
1356 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1357 0x0, 0x0, 0x0, 0x0);
1358 halbtc8821a1ant_set_ant_path(btcoexist,
1359 BTC_ANT_PATH_WIFI, false, false);
1360 break;
1361 case 10: /* under 5G */
1362 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1363 0x0, 0x0, 0x8, 0x0);
1364 halbtc8821a1ant_set_ant_path(btcoexist,
1365 BTC_ANT_PATH_BT, false, false);
1366 break;
1367 }
1368 }
1369 rssi_adjust_val = 0;
1370 btcoexist->btc_set(btcoexist,
1371 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1372
1373 /* update pre state */
1374 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1375 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1376 }
1377
halbtc8821a1ant_coex_all_off(IN struct btc_coexist * btcoexist)1378 void halbtc8821a1ant_coex_all_off(IN struct btc_coexist *btcoexist)
1379 {
1380 /* sw all off */
1381 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1382
1383 /* hw all off */
1384 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1385 }
1386
halbtc8821a1ant_is_common_action(IN struct btc_coexist * btcoexist)1387 boolean halbtc8821a1ant_is_common_action(IN struct btc_coexist *btcoexist)
1388 {
1389 boolean common = false, wifi_connected = false, wifi_busy = false;
1390
1391 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1392 &wifi_connected);
1393 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1394
1395 if (!wifi_connected &&
1396 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1397 coex_dm->bt_status) {
1398 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1399 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1400 BTC_TRACE(trace_buf);
1401 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1402
1403 common = true;
1404 } else if (wifi_connected &&
1405 (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1406 coex_dm->bt_status)) {
1407 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1408 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1409 BTC_TRACE(trace_buf);
1410 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1411
1412 common = true;
1413 } else if (!wifi_connected &&
1414 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
1415 coex_dm->bt_status)) {
1416 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1417 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1418 BTC_TRACE(trace_buf);
1419 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1420
1421 common = true;
1422 } else if (wifi_connected &&
1423 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
1424 coex_dm->bt_status)) {
1425 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1426 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1427 BTC_TRACE(trace_buf);
1428 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1429
1430 common = true;
1431 } else if (!wifi_connected &&
1432 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE !=
1433 coex_dm->bt_status)) {
1434 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1435 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1436 BTC_TRACE(trace_buf);
1437 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1438
1439 common = true;
1440 } else {
1441 if (wifi_busy) {
1442 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1443 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1444 BTC_TRACE(trace_buf);
1445 } else {
1446 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1447 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1448 BTC_TRACE(trace_buf);
1449 }
1450
1451 common = false;
1452 }
1453
1454 return common;
1455 }
1456
1457 /* *********************************************
1458 *
1459 * Software Coex Mechanism start
1460 *
1461 * ********************************************* */
1462
halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist * btcoexist)1463 void halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
1464 {
1465
1466 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1467 /* halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); */
1468 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, false, false);
1469 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1470 }
1471 /* SCO only or SCO+PAN(HS) */
halbtc8821a1ant_action_sco(IN struct btc_coexist * btcoexist)1472 void halbtc8821a1ant_action_sco(IN struct btc_coexist *btcoexist)
1473 {
1474 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1475
1476 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
1477
1478 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1479 }
1480
halbtc8821a1ant_action_hid(IN struct btc_coexist * btcoexist)1481 void halbtc8821a1ant_action_hid(IN struct btc_coexist *btcoexist)
1482 {
1483 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1484
1485 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
1486
1487 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1488 }
1489
1490 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
halbtc8821a1ant_action_a2dp(IN struct btc_coexist * btcoexist)1491 void halbtc8821a1ant_action_a2dp(IN struct btc_coexist *btcoexist)
1492 {
1493 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1494
1495 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 44);
1496
1497 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1498 }
1499
halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist * btcoexist)1500 void halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
1501 {
1502 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1503
1504 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1505
1506 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1507 }
1508
halbtc8821a1ant_action_pan_edr(IN struct btc_coexist * btcoexist)1509 void halbtc8821a1ant_action_pan_edr(IN struct btc_coexist *btcoexist)
1510 {
1511 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1512
1513 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1514
1515 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1516 }
1517
1518 /* PAN(HS) only */
halbtc8821a1ant_action_pan_hs(IN struct btc_coexist * btcoexist)1519 void halbtc8821a1ant_action_pan_hs(IN struct btc_coexist *btcoexist)
1520 {
1521 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1522
1523 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1524
1525 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1526 }
1527
1528 /* PAN(EDR)+A2DP */
halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist * btcoexist)1529 void halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
1530 {
1531 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1532
1533 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1534
1535 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1536 }
1537
halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist * btcoexist)1538 void halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
1539 {
1540 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1541
1542 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1543
1544 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1545 }
1546
1547 /* HID+A2DP+PAN(EDR) */
halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist * btcoexist)1548 void halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
1549 {
1550 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1551
1552 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1553
1554 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1555 }
1556
halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist * btcoexist)1557 void halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
1558 {
1559 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 44);
1560 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1561
1562 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1563 }
1564
1565 /* *********************************************
1566 *
1567 * Non-Software Coex Mechanism start
1568 *
1569 * ********************************************* */
halbtc8821a1ant_action_hs(IN struct btc_coexist * btcoexist)1570 void halbtc8821a1ant_action_hs(IN struct btc_coexist *btcoexist)
1571 {
1572 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 45);
1573 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1574 }
1575
halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist * btcoexist)1576 void halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1577 {
1578 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1579 boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
1580 bt_busy = false;
1581
1582 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1583 &ap_enable);
1584 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1585 &wifi_connected);
1586 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1587 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1588
1589 if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1590 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1591
1592 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1593 }
1594
1595
1596 else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1597 (bt_link_info->a2dp_exist)) {
1598 /* SCO/HID/A2DP busy */
1599
1600 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1601
1602 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1603 }
1604
1605
1606
1607 else if ((bt_link_info->a2dp_exist) &&
1608 (bt_link_info->hid_exist)) {
1609 /* A2DP+HID busy */
1610
1611 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1612 14);
1613
1614 halbtc8821a1ant_coex_table_with_type(btcoexist,
1615 NORMAL_EXEC, 1);
1616 }
1617
1618
1619 else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1620 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1621
1622 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1623 } else {
1624 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1625
1626 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1627 }
1628 }
1629
halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist * btcoexist,IN u8 wifi_status)1630 void halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1631 *btcoexist, IN u8 wifi_status)
1632 {
1633 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1634 boolean wifi_connected = false;
1635
1636 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1637 &wifi_connected);
1638
1639 /* tdma and coex table */
1640
1641 if (bt_link_info->sco_exist) {
1642 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1643 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1644 } else { /* HID */
1645 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1646 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1647 }
1648 }
1649
halbtc8821a1ant_coex_under_5g(IN struct btc_coexist * btcoexist)1650 void halbtc8821a1ant_coex_under_5g(IN struct btc_coexist *btcoexist)
1651 {
1652
1653 halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
1654
1655 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
1656
1657 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1658
1659 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1660
1661 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
1662 }
1663
halbtc8821a1ant_action_wifi_only(IN struct btc_coexist * btcoexist)1664 void halbtc8821a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1665 {
1666 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1667 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
1668 }
1669
halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist * btcoexist)1670 void halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1671 {
1672 static u32 bt_disable_cnt = 0;
1673 boolean bt_active = true, bt_disabled = false;
1674
1675 /* This function check if bt is disabled */
1676
1677 if (coex_sta->high_priority_tx == 0 &&
1678 coex_sta->high_priority_rx == 0 &&
1679 coex_sta->low_priority_tx == 0 &&
1680 coex_sta->low_priority_rx == 0)
1681 bt_active = false;
1682 if (coex_sta->high_priority_tx == 0xffff &&
1683 coex_sta->high_priority_rx == 0xffff &&
1684 coex_sta->low_priority_tx == 0xffff &&
1685 coex_sta->low_priority_rx == 0xffff)
1686 bt_active = false;
1687 if (bt_active) {
1688 bt_disable_cnt = 0;
1689 bt_disabled = false;
1690 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1691 &bt_disabled);
1692 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1693 "[BTCoex], BT is enabled !!\n");
1694 BTC_TRACE(trace_buf);
1695 } else {
1696 bt_disable_cnt++;
1697 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1698 "[BTCoex], bt all counters=0, %d times!!\n",
1699 bt_disable_cnt);
1700 BTC_TRACE(trace_buf);
1701 if (bt_disable_cnt >= 10) {
1702 bt_disabled = true;
1703 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1704 &bt_disabled);
1705 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1706 "[BTCoex], BT is disabled !!\n");
1707 BTC_TRACE(trace_buf);
1708 halbtc8821a1ant_action_wifi_only(btcoexist);
1709 }
1710 }
1711 if (coex_sta->bt_disabled != bt_disabled) {
1712 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1713 "[BTCoex], BT is from %s to %s!!\n",
1714 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1715 (bt_disabled ? "disabled" : "enabled"));
1716 BTC_TRACE(trace_buf);
1717 coex_sta->bt_disabled = bt_disabled;
1718 if (!bt_disabled) {
1719 } else {
1720 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1721 NULL);
1722 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1723 NULL);
1724 }
1725 }
1726 }
1727
halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist * btcoexist)1728 void halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1729 {
1730
1731 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1732 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1733 }
1734
1735
halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist * btcoexist,IN u8 wifi_status)1736 void halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1737 *btcoexist, IN u8 wifi_status)
1738 {
1739 u8 bt_rssi_state;
1740
1741 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1742
1743 bt_rssi_state = halbtc8821a1ant_bt_rssi_state(2, 28, 0);
1744
1745 if (bt_link_info->hid_only) { /* HID */
1746 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1747 wifi_status);
1748 coex_dm->auto_tdma_adjust = false;
1749 return;
1750 } else if (bt_link_info->a2dp_only) { /* A2DP */
1751 if (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1752 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); */
1753 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); */
1754 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1755 32);
1756 halbtc8821a1ant_coex_table_with_type(btcoexist,
1757 NORMAL_EXEC, 1);
1758 coex_dm->auto_tdma_adjust = false;
1759 } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1760 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1761 /* halbtc8821a1ant_tdma_duration_adjust_for_acl(btcoexist, wifi_status); */
1762 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1763 14);
1764 halbtc8821a1ant_coex_table_with_type(btcoexist,
1765 NORMAL_EXEC, 1);
1766 } else { /* for low BT RSSI */
1767 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1768 14);
1769 halbtc8821a1ant_coex_table_with_type(btcoexist,
1770 NORMAL_EXEC, 1);
1771 coex_dm->auto_tdma_adjust = false;
1772 }
1773 } else if (bt_link_info->hid_exist &&
1774 bt_link_info->a2dp_exist) { /* HID+A2DP */
1775 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1776 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1777 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1778 14);
1779 coex_dm->auto_tdma_adjust = false;
1780 } else { /* for low BT RSSI */
1781 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1782 14);
1783 coex_dm->auto_tdma_adjust = false;
1784 }
1785
1786 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1787 } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1788 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
1789 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1790 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1791 coex_dm->auto_tdma_adjust = false;
1792 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1793 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1794 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1795 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 46);
1796 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1797 coex_dm->auto_tdma_adjust = false;
1798 } else {
1799 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1800 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1801 coex_dm->auto_tdma_adjust = false;
1802 }
1803 }
1804
halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist * btcoexist)1805 void halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1806 {
1807
1808 /* tdma and coex table */
1809 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1810 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1811 }
1812
halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist * btcoexist)1813 void halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1814 *btcoexist)
1815 {
1816 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1817
1818
1819 /* tdma and coex table */
1820 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1821 if (bt_link_info->a2dp_exist) {
1822
1823 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1824 14);
1825 halbtc8821a1ant_coex_table_with_type(btcoexist,
1826 NORMAL_EXEC, 1);
1827 } else if (bt_link_info->a2dp_exist &&
1828 bt_link_info->pan_exist) {
1829 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1830 22);
1831 halbtc8821a1ant_coex_table_with_type(btcoexist,
1832 NORMAL_EXEC, 4);
1833 } else {
1834 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1835 20);
1836 halbtc8821a1ant_coex_table_with_type(btcoexist,
1837 NORMAL_EXEC, 4);
1838 }
1839 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1840 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1841 coex_dm->bt_status)) {
1842 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1843 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1844 } else {
1845 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1846 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1847
1848 /* Bryant Add */
1849 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1850 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1851 }
1852 }
1853
halbtc8821a1ant_action_wifi_not_connected_asso_auth(IN struct btc_coexist * btcoexist)1854 void halbtc8821a1ant_action_wifi_not_connected_asso_auth(
1855 IN struct btc_coexist *btcoexist)
1856 {
1857 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1858
1859 /* tdma and coex table */
1860 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
1861 /* sy modify */
1862 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1863 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1864 } else if ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist)) {
1865 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1866 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1867 } else {
1868 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1869 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1870 }
1871 }
1872
halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist * btcoexist)1873 void halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist
1874 *btcoexist)
1875 {
1876 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1877
1878 /* tdma and coex table */
1879 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1880 if (bt_link_info->a2dp_exist) {
1881 /* sy modify */
1882 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1883 14);
1884 halbtc8821a1ant_coex_table_with_type(btcoexist,
1885 NORMAL_EXEC, 1);
1886 } else if (bt_link_info->a2dp_exist &&
1887 bt_link_info->pan_exist) {
1888 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1889 22);
1890 halbtc8821a1ant_coex_table_with_type(btcoexist,
1891 NORMAL_EXEC, 4);
1892 } else {
1893 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1894 20);
1895 halbtc8821a1ant_coex_table_with_type(btcoexist,
1896 NORMAL_EXEC, 4);
1897 }
1898 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1899 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1900 coex_dm->bt_status)) {
1901 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1902 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1903 } else {
1904 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1905 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1906
1907 /* Bryant Add */
1908 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1909 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1910 }
1911 }
1912
halbtc8821a1ant_action_wifi_connected_specific_packet(IN struct btc_coexist * btcoexist)1913 void halbtc8821a1ant_action_wifi_connected_specific_packet(
1914 IN struct btc_coexist *btcoexist)
1915 {
1916 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1917
1918 /* tdma and coex table */
1919 /* sy modify */
1920 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1921 (bt_link_info->a2dp_exist)) {
1922 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1923 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1924 }
1925
1926 if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist)) {
1927 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1928 14);
1929 halbtc8821a1ant_coex_table_with_type(btcoexist,
1930 NORMAL_EXEC, 1);
1931 }
1932
1933
1934 else if (bt_link_info->pan_exist) {
1935 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1936 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1937 } else {
1938 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1939 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1940 }
1941 }
1942
halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist * btcoexist)1943 void halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
1944 {
1945 boolean wifi_busy = false;
1946 boolean scan = false, link = false, roam = false;
1947 boolean under_4way = false, ap_enable = false;
1948
1949 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1950 "[BTCoex], CoexForWifiConnect()===>\n");
1951 BTC_TRACE(trace_buf);
1952
1953 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1954 &under_4way);
1955 if (under_4way) {
1956 halbtc8821a1ant_action_wifi_connected_specific_packet(
1957 btcoexist);
1958 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1959 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1960 BTC_TRACE(trace_buf);
1961 return;
1962 }
1963
1964 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1965 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1966 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1967 if (scan || link || roam) {
1968 if (scan)
1969 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
1970 else
1971 halbtc8821a1ant_action_wifi_connected_specific_packet(
1972 btcoexist);
1973 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1974 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1975 BTC_TRACE(trace_buf);
1976 return;
1977 }
1978
1979 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1980 &ap_enable);
1981 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1982
1983 /* tdma and coex table */
1984 if (!wifi_busy) {
1985 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1986 halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1987 btcoexist,
1988 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1989 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1990 coex_dm->bt_status) ||
1991 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1992 coex_dm->bt_status)) {
1993 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1994 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1995 } else {
1996 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1997 8);
1998 halbtc8821a1ant_coex_table_with_type(btcoexist,
1999 NORMAL_EXEC, 2);
2000 }
2001 } else {
2002 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2003 halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
2004 btcoexist,
2005 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2006 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
2007 coex_dm->bt_status) ||
2008 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2009 coex_dm->bt_status)) {
2010 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
2011 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2012 } else {
2013 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2014 8);
2015 halbtc8821a1ant_coex_table_with_type(btcoexist,
2016 NORMAL_EXEC, 2);
2017 }
2018 }
2019 }
2020
halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist * btcoexist)2021 void halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
2022 {
2023 u8 algorithm = 0;
2024
2025 algorithm = halbtc8821a1ant_action_algorithm(btcoexist);
2026 coex_dm->cur_algorithm = algorithm;
2027
2028 if (halbtc8821a1ant_is_common_action(btcoexist)) {
2029
2030 } else {
2031 switch (coex_dm->cur_algorithm) {
2032 case BT_8821A_1ANT_COEX_ALGO_SCO:
2033 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2034 "[BTCoex], Action algorithm = SCO.\n");
2035 BTC_TRACE(trace_buf);
2036 halbtc8821a1ant_action_sco(btcoexist);
2037 break;
2038 case BT_8821A_1ANT_COEX_ALGO_HID:
2039 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2040 "[BTCoex], Action algorithm = HID.\n");
2041 BTC_TRACE(trace_buf);
2042 halbtc8821a1ant_action_hid(btcoexist);
2043 break;
2044 case BT_8821A_1ANT_COEX_ALGO_A2DP:
2045 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2046 "[BTCoex], Action algorithm = A2DP.\n");
2047 BTC_TRACE(trace_buf);
2048 halbtc8821a1ant_action_a2dp(btcoexist);
2049 break;
2050 case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
2051 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2052 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
2053 BTC_TRACE(trace_buf);
2054 halbtc8821a1ant_action_a2dp_pan_hs(btcoexist);
2055 break;
2056 case BT_8821A_1ANT_COEX_ALGO_PANEDR:
2057 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2058 "[BTCoex], Action algorithm = PAN(EDR).\n");
2059 BTC_TRACE(trace_buf);
2060 halbtc8821a1ant_action_pan_edr(btcoexist);
2061 break;
2062 case BT_8821A_1ANT_COEX_ALGO_PANHS:
2063 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2064 "[BTCoex], Action algorithm = HS mode.\n");
2065 BTC_TRACE(trace_buf);
2066 halbtc8821a1ant_action_pan_hs(btcoexist);
2067 break;
2068 case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
2069 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2070 "[BTCoex], Action algorithm = PAN+A2DP.\n");
2071 BTC_TRACE(trace_buf);
2072 halbtc8821a1ant_action_pan_edr_a2dp(btcoexist);
2073 break;
2074 case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
2075 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2076 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
2077 BTC_TRACE(trace_buf);
2078 halbtc8821a1ant_action_pan_edr_hid(btcoexist);
2079 break;
2080 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2081 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2082 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
2083 BTC_TRACE(trace_buf);
2084 halbtc8821a1ant_action_hid_a2dp_pan_edr(
2085 btcoexist);
2086 break;
2087 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
2088 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2089 "[BTCoex], Action algorithm = HID+A2DP.\n");
2090 BTC_TRACE(trace_buf);
2091 halbtc8821a1ant_action_hid_a2dp(btcoexist);
2092 break;
2093 default:
2094 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2095 "[BTCoex], Action algorithm = coexist All Off!!\n");
2096 BTC_TRACE(trace_buf);
2097 /* halbtc8821a1ant_coex_all_off(btcoexist); */
2098 break;
2099 }
2100 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2101 }
2102 }
2103
halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist * btcoexist)2104 void halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2105 {
2106 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2107 boolean wifi_connected = false, bt_hs_on = false;
2108 boolean increase_scan_dev_num = false;
2109 boolean bt_ctrl_agg_buf_size = false;
2110 u8 agg_buf_size = 5;
2111 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
2112 u32 wifi_link_status = 0;
2113 u32 num_of_wifi_link = 0;
2114 boolean wifi_under_5g = false;
2115
2116 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2117 "[BTCoex], RunCoexistMechanism()===>\n");
2118 BTC_TRACE(trace_buf);
2119
2120 if (btcoexist->manual_control) {
2121 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2122 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2123 BTC_TRACE(trace_buf);
2124 return;
2125 }
2126
2127 if (btcoexist->stop_coex_dm) {
2128 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2129 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2130 BTC_TRACE(trace_buf);
2131 return;
2132 }
2133
2134 if (coex_sta->under_ips) {
2135 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2136 "[BTCoex], wifi is under IPS !!!\n");
2137 BTC_TRACE(trace_buf);
2138 return;
2139 }
2140
2141 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2142 if (wifi_under_5g) {
2143 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2144 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2145 BTC_TRACE(trace_buf);
2146 halbtc8821a1ant_coex_under_5g(btcoexist);
2147 return;
2148 }
2149 if (coex_sta->bt_whck_test) {
2150 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2151 "[BTCoex], BT is under WHCK TEST!!!\n");
2152 BTC_TRACE(trace_buf);
2153 halbtc8821a1ant_action_bt_whck_test(btcoexist);
2154 return;
2155 }
2156
2157 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2158 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2159 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2160 increase_scan_dev_num = true;
2161
2162 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2163 &increase_scan_dev_num);
2164 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2165 &wifi_connected);
2166
2167 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2168 &wifi_link_status);
2169 num_of_wifi_link = wifi_link_status >> 16;
2170 if ((num_of_wifi_link >= 2) ||
2171 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2172 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2173 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2174 bt_ctrl_agg_buf_size, agg_buf_size);
2175 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2176 return;
2177 }
2178
2179 if (!bt_link_info->sco_exist && !bt_link_info->hid_exist)
2180 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2181 else {
2182 if (wifi_connected) {
2183 wifi_rssi_state = halbtc8821a1ant_wifi_rssi_state(
2184 btcoexist, 1, 2, 30, 0);
2185 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2186 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2187 /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2188 halbtc8821a1ant_limited_tx(btcoexist,
2189 NORMAL_EXEC, 1, 1, 0, 1);
2190 } else {
2191 /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2192 halbtc8821a1ant_limited_tx(btcoexist,
2193 NORMAL_EXEC, 1, 1, 0, 1);
2194 }
2195 } else
2196 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2197 0, 0);
2198
2199 }
2200
2201 if (bt_link_info->sco_exist) {
2202 bt_ctrl_agg_buf_size = true;
2203 agg_buf_size = 0x3;
2204 } else if (bt_link_info->hid_exist) {
2205 bt_ctrl_agg_buf_size = true;
2206 agg_buf_size = 0x5;
2207 } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
2208 bt_ctrl_agg_buf_size = true;
2209 agg_buf_size = 0x8;
2210 }
2211 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2212 bt_ctrl_agg_buf_size, agg_buf_size);
2213
2214 halbtc8821a1ant_run_sw_coexist_mechanism(btcoexist);
2215
2216 /* low pelnaty ra in pcr ra */
2217 btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
2218
2219 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2220 if (coex_sta->c2h_bt_inquiry_page) {
2221 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2222 return;
2223 } else if (bt_hs_on) {
2224 halbtc8821a1ant_action_hs(btcoexist);
2225 return;
2226 }
2227
2228
2229 if (!wifi_connected) {
2230 boolean scan = false, link = false, roam = false;
2231
2232 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2233 "[BTCoex], wifi is non connected-idle !!!\n");
2234 BTC_TRACE(trace_buf);
2235
2236 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2237 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2238 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2239
2240 if (scan || link || roam) {
2241 if (scan)
2242 halbtc8821a1ant_action_wifi_not_connected_scan(
2243 btcoexist);
2244 else
2245 halbtc8821a1ant_action_wifi_not_connected_asso_auth(
2246 btcoexist);
2247 } else
2248 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2249 } else /* wifi LPS/Busy */
2250 halbtc8821a1ant_action_wifi_connected(btcoexist);
2251 }
2252
halbtc8821a1ant_init_coex_dm(IN struct btc_coexist * btcoexist)2253 void halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2254 {
2255 /* force to reset coex mechanism */
2256 /* sw all off */
2257 halbtc8821a1ant_sw_mechanism(btcoexist, false);
2258
2259 /* halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2260 halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2261 }
2262
halbtc8821a1ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean back_up,IN boolean wifi_only)2263 void halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2264 IN boolean back_up, IN boolean wifi_only)
2265 {
2266 u8 u8tmp = 0;
2267 boolean wifi_under_5g = false;
2268
2269
2270 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2271 "[BTCoex], 1Ant Init HW Config!!\n");
2272 BTC_TRACE(trace_buf);
2273
2274 if (wifi_only)
2275 return;
2276
2277 if (back_up) {
2278 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2279 0x430);
2280 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2281 0x434);
2282 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2283 btcoexist, 0x42a);
2284 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2285 btcoexist, 0x456);
2286 }
2287
2288 /* 0x790[5:0]=0x5 */
2289 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2290 u8tmp &= 0xc0;
2291 u8tmp |= 0x5;
2292 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2293
2294 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2295
2296 /* Give bt_coex_supported_version the default value */
2297 coex_sta->bt_coex_supported_version = 0;
2298
2299 /* 0xf0[15:12] --> Chip Cut information */
2300 coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
2301 0xf1) & 0xf0) >> 4;
2302
2303 /* Antenna config */
2304 if (wifi_under_5g)
2305 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true,
2306 false);
2307 else
2308 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true,
2309 false);
2310
2311 /* PTA parameter */
2312 halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2313
2314 /* Enable counter statistics */
2315 btcoexist->btc_write_1byte(btcoexist, 0x76e,
2316 0xc); /* 0x76e[3] =1, WLAN_Act control by PTA */
2317 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
2318 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
2319 }
2320
2321 /* ************************************************************
2322 * work around function start with wa_halbtc8821a1ant_
2323 * ************************************************************
2324 * ************************************************************
2325 * extern function start with ex_halbtc8821a1ant_
2326 * ************************************************************ */
ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist * btcoexist)2327 void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2328 {
2329 struct btc_board_info *board_info = &btcoexist->board_info;
2330
2331 if (board_info->single_ant_path == 0) {
2332 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2333 } else if (board_info->single_ant_path == 1) {
2334 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2335 }
2336
2337 }
2338
ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)2339 void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2340 IN boolean wifi_only)
2341 {
2342 halbtc8821a1ant_init_hw_config(btcoexist, true, wifi_only);
2343 }
2344
ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist * btcoexist)2345 void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2346 {
2347 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2348 "[BTCoex], Coex Mechanism Init!!\n");
2349 BTC_TRACE(trace_buf);
2350
2351 btcoexist->stop_coex_dm = false;
2352
2353 halbtc8821a1ant_init_coex_dm(btcoexist);
2354
2355 halbtc8821a1ant_query_bt_info(btcoexist);
2356 }
2357
ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist * btcoexist)2358 void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2359 {
2360 struct btc_board_info *board_info = &btcoexist->board_info;
2361 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2362 u8 *cli_buf = btcoexist->cli_buf;
2363 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2364 u16 u16tmp[4];
2365 u32 u32tmp[4];
2366 u32 fw_ver = 0, bt_patch_ver = 0;
2367 u32 bt_coex_ver = 0;
2368 u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
2369 u32 phyver = 0;
2370
2371 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2372 "\r\n ============[BT Coexist info]============");
2373 CL_PRINTF(cli_buf);
2374
2375 if (btcoexist->manual_control) {
2376 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2377 "\r\n ============[Under Manual Control]============");
2378 CL_PRINTF(cli_buf);
2379 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2380 "\r\n ==========================================");
2381 CL_PRINTF(cli_buf);
2382 }
2383 if (btcoexist->stop_coex_dm) {
2384 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2385 "\r\n ============[Coex is STOPPED]============");
2386 CL_PRINTF(cli_buf);
2387 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2388 "\r\n ==========================================");
2389 CL_PRINTF(cli_buf);
2390 }
2391
2392 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d",
2393 "Ant PG Num/ Ant Mech/ Ant Pos:",
2394 board_info->pg_ant_num, board_info->btdm_ant_num,
2395 board_info->btdm_ant_pos);
2396 CL_PRINTF(cli_buf);
2397
2398 /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */
2399 bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
2400 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2401 phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
2402 bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
2403
2404 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2405 "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
2406 "CoexVer WL/ BT_Desired/ BT_Report",
2407 glcoex_ver_date_8821a_1ant, glcoex_ver_8821a_1ant,
2408 glcoex_ver_btdesired_8821a_1ant,
2409 bt_coex_ver,
2410 (bt_coex_ver == 0xff ? "Unknown" :
2411 (bt_coex_ver >= glcoex_ver_btdesired_8821a_1ant ?
2412 "Match" : "Mis-Match")));
2413 CL_PRINTF(cli_buf);
2414
2415 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2416 "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
2417 "W_FW/ B_FW/ Phy/ Kt",
2418 fw_ver, bt_patch_ver, phyver,
2419 coex_sta->cut_version + 65);
2420 CL_PRINTF(cli_buf);
2421
2422 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2423 "Wifi channel informed to BT",
2424 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2425 coex_dm->wifi_chnl_info[2]);
2426 CL_PRINTF(cli_buf);
2427
2428 /* wifi status */
2429 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2430 "============[Wifi Status]============");
2431 CL_PRINTF(cli_buf);
2432 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2433
2434 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2435 "============[BT Status]============");
2436 CL_PRINTF(cli_buf);
2437
2438 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2439 "BT [status/ rssi/ retryCnt]",
2440 ((coex_sta->bt_disabled) ? ("disabled") : ((
2441 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2442 : ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2443 coex_dm->bt_status) ? "non-connected idle" :
2444 ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2445 ? "connected-idle" : "busy")))),
2446 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2447 CL_PRINTF(cli_buf);
2448
2449 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2450 "SCO/HID/PAN/A2DP",
2451 bt_link_info->sco_exist, bt_link_info->hid_exist,
2452 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2453 CL_PRINTF(cli_buf);
2454 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2455
2456 bt_info_ext = coex_sta->bt_info_ext;
2457 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2458 "BT Info A2DP rate",
2459 (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2460 CL_PRINTF(cli_buf);
2461
2462 for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
2463 if (coex_sta->bt_info_c2h_cnt[i]) {
2464 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2465 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2466 glbt_info_src_8821a_1ant[i],
2467 coex_sta->bt_info_c2h[i][0],
2468 coex_sta->bt_info_c2h[i][1],
2469 coex_sta->bt_info_c2h[i][2],
2470 coex_sta->bt_info_c2h[i][3],
2471 coex_sta->bt_info_c2h[i][4],
2472 coex_sta->bt_info_c2h[i][5],
2473 coex_sta->bt_info_c2h[i][6],
2474 coex_sta->bt_info_c2h_cnt[i]);
2475 CL_PRINTF(cli_buf);
2476 }
2477 }
2478
2479 if (!btcoexist->manual_control) {
2480 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
2481 "SM[LowPenaltyRA]",
2482 coex_dm->cur_low_penalty_ra);
2483 CL_PRINTF(cli_buf);
2484
2485 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2486 "============[mechanisms]============");
2487 CL_PRINTF(cli_buf);
2488
2489 ps_tdma_case = coex_dm->cur_ps_tdma;
2490 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2491 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2492 "PS TDMA",
2493 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2494 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2495 coex_dm->ps_tdma_para[4], ps_tdma_case,
2496 coex_dm->auto_tdma_adjust);
2497 CL_PRINTF(cli_buf);
2498
2499 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2500 "IgnWlanAct",
2501 coex_dm->cur_ignore_wlan_act);
2502 CL_PRINTF(cli_buf);
2503
2504 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2505 "Latest error condition(should be 0)",
2506 coex_dm->error_condition);
2507 CL_PRINTF(cli_buf);
2508 }
2509
2510 /* Hw setting */
2511 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2512 "============[Hw setting]============");
2513 CL_PRINTF(cli_buf);
2514
2515 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2516 "backup ARFR1/ARFR2/RL/AMaxTime",
2517 coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
2518 coex_dm->backup_retry_limit,
2519 coex_dm->backup_ampdu_max_time);
2520 CL_PRINTF(cli_buf);
2521
2522 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
2523 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
2524 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
2525 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
2526 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2527 "0x430/0x434/0x42a/0x456",
2528 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
2529 CL_PRINTF(cli_buf);
2530
2531 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2532 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
2533 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2534 "0x778/ 0xc58[29:25]",
2535 u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25);
2536 CL_PRINTF(cli_buf);
2537
2538 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
2539 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]",
2540 ((u8tmp[0] & 0x60) >> 5));
2541 CL_PRINTF(cli_buf);
2542
2543 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
2544 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2545 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2546 "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
2547 (u32tmp[0] & 0x30000000) >> 28, u32tmp[0] & 0xff,
2548 u8tmp[0] & 0x3);
2549 CL_PRINTF(cli_buf);
2550
2551
2552 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2553 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2554 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
2555 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2556 "0x40/0x4c[24:23]/0x64[0]",
2557 u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u8tmp[1] & 0x1);
2558 CL_PRINTF(cli_buf);
2559
2560 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2561 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2562 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2563 "0x550(bcn ctrl)/0x522",
2564 u32tmp[0], u8tmp[0]);
2565 CL_PRINTF(cli_buf);
2566
2567 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2568 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2569 u32tmp[0] & 0xff);
2570 CL_PRINTF(cli_buf);
2571
2572 fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2573 PHYDM_INFO_FA_OFDM);
2574 fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2575 PHYDM_INFO_FA_CCK);
2576 cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2577 PHYDM_INFO_CCA_OFDM);
2578 cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2579 PHYDM_INFO_CCA_CCK);
2580
2581 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2582 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2583 "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
2584 cca_cck, fa_cck, cca_ofdm, fa_ofdm);
2585 CL_PRINTF(cli_buf);
2586
2587 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
2588 "CRC_OK CCK/11g/11n/11n-agg",
2589 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
2590 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
2591 CL_PRINTF(cli_buf);
2592
2593 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
2594 "CRC_Err CCK/11g/11n/11n-agg",
2595 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
2596 coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
2597 CL_PRINTF(cli_buf);
2598
2599
2600 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2601 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2602 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2603 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2604 "0x6c0/0x6c4/0x6c8(coexTable)",
2605 u32tmp[0], u32tmp[1], u32tmp[2]);
2606 CL_PRINTF(cli_buf);
2607
2608 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2609 "0x770(high-pri rx/tx)",
2610 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2611 CL_PRINTF(cli_buf);
2612 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2613 "0x774(low-pri rx/tx)",
2614 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2615 CL_PRINTF(cli_buf);
2616 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
2617 halbtc8821a1ant_monitor_bt_ctr(btcoexist);
2618 #endif
2619 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2620 }
2621
2622
ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist * btcoexist,IN u8 type)2623 void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2624 {
2625 boolean wifi_under_5g = false;
2626
2627 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2628 return;
2629 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
2630 &wifi_under_5g);
2631 if (wifi_under_5g) {
2632 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2633 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2634 BTC_TRACE(trace_buf);
2635 halbtc8821a1ant_coex_under_5g(btcoexist);
2636 return;
2637 }
2638
2639 if (BTC_IPS_ENTER == type) {
2640 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2641 "[BTCoex], IPS ENTER notify\n");
2642 BTC_TRACE(trace_buf);
2643 coex_sta->under_ips = true;
2644
2645 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2646 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2647 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2648 true);
2649 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
2650 } else if (BTC_IPS_LEAVE == type) {
2651 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2652 "[BTCoex], IPS LEAVE notify\n");
2653 BTC_TRACE(trace_buf);
2654 coex_sta->under_ips = false;
2655
2656 halbtc8821a1ant_init_hw_config(btcoexist, false, false);
2657 halbtc8821a1ant_init_coex_dm(btcoexist);
2658 halbtc8821a1ant_query_bt_info(btcoexist);
2659 }
2660 }
2661
ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist * btcoexist,IN u8 type)2662 void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2663 {
2664
2665
2666 if (BTC_LPS_ENABLE == type) {
2667 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2668 "[BTCoex], LPS ENABLE notify\n");
2669 BTC_TRACE(trace_buf);
2670 coex_sta->under_lps = true;
2671 } else if (BTC_LPS_DISABLE == type) {
2672 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2673 "[BTCoex], LPS DISABLE notify\n");
2674 BTC_TRACE(trace_buf);
2675 coex_sta->under_lps = false;
2676 }
2677 }
2678
ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist * btcoexist,IN u8 type)2679 void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist,
2680 IN u8 type)
2681 {
2682 boolean wifi_connected = false, bt_hs_on = false;
2683 u32 wifi_link_status = 0;
2684 u32 num_of_wifi_link = 0;
2685 boolean bt_ctrl_agg_buf_size = false;
2686 u8 agg_buf_size = 5;
2687 boolean wifi_under_5g = false;
2688
2689 if (btcoexist->manual_control ||
2690 btcoexist->stop_coex_dm)
2691 return;
2692 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2693 if (wifi_under_5g) {
2694 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2695 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2696 BTC_TRACE(trace_buf);
2697 halbtc8821a1ant_coex_under_5g(btcoexist);
2698 return;
2699 }
2700
2701 if (BTC_SCAN_START == type) {
2702 coex_sta->wifi_is_high_pri_task = true;
2703 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2704 "[BTCoex], SCAN START notify\n");
2705 BTC_TRACE(trace_buf);
2706
2707 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2708 8); /* Force antenna setup for no scan result issue */
2709 } else {
2710 coex_sta->wifi_is_high_pri_task = false;
2711 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2712 "[BTCoex], SCAN FINISH notify\n");
2713 BTC_TRACE(trace_buf);
2714 }
2715
2716 if (coex_sta->bt_disabled)
2717 return;
2718
2719 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2720 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2721 &wifi_connected);
2722
2723 halbtc8821a1ant_query_bt_info(btcoexist);
2724
2725 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2726 &wifi_link_status);
2727 num_of_wifi_link = wifi_link_status >> 16;
2728 if (num_of_wifi_link >= 2) {
2729 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2730 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2731 bt_ctrl_agg_buf_size, agg_buf_size);
2732 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2733 return;
2734 }
2735
2736 if (coex_sta->c2h_bt_inquiry_page) {
2737 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2738 return;
2739 } else if (bt_hs_on) {
2740 halbtc8821a1ant_action_hs(btcoexist);
2741 return;
2742 }
2743
2744 if (BTC_SCAN_START == type) {
2745 if (!wifi_connected) /* non-connected scan */
2746 halbtc8821a1ant_action_wifi_not_connected_scan(
2747 btcoexist);
2748 else /* wifi is connected */
2749 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
2750 } else if (BTC_SCAN_FINISH == type) {
2751 if (!wifi_connected) /* non-connected scan */
2752 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2753 else
2754 halbtc8821a1ant_action_wifi_connected(btcoexist);
2755 }
2756 }
2757
2758 /* copy scan notify content to switch band notify */
ex_halbtc8821a1ant_switchband_notify(IN struct btc_coexist * btcoexist,IN u8 type)2759 void ex_halbtc8821a1ant_switchband_notify(IN struct btc_coexist *btcoexist,
2760 IN u8 type)
2761 {
2762 boolean wifi_connected = false, bt_hs_on = false;
2763 u32 wifi_link_status = 0;
2764 u32 num_of_wifi_link = 0;
2765 boolean bt_ctrl_agg_buf_size = false;
2766 u8 agg_buf_size = 5;
2767 boolean wifi_under_5g = false;
2768
2769 if (btcoexist->manual_control ||
2770 btcoexist->stop_coex_dm)
2771 return;
2772 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2773 if (wifi_under_5g) {
2774 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2775 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2776 BTC_TRACE(trace_buf);
2777 halbtc8821a1ant_coex_under_5g(btcoexist);
2778 return;
2779 }
2780
2781 if (BTC_SCAN_START == type) {
2782 coex_sta->wifi_is_high_pri_task = true;
2783 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2784 "[BTCoex], SCAN START notify\n");
2785 BTC_TRACE(trace_buf);
2786
2787 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2788 8); /* Force antenna setup for no scan result issue */
2789 } else {
2790 coex_sta->wifi_is_high_pri_task = false;
2791 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2792 "[BTCoex], SCAN FINISH notify\n");
2793 BTC_TRACE(trace_buf);
2794 }
2795
2796 if (coex_sta->bt_disabled)
2797 return;
2798
2799 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2800 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2801 &wifi_connected);
2802
2803 halbtc8821a1ant_query_bt_info(btcoexist);
2804
2805 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2806 &wifi_link_status);
2807 num_of_wifi_link = wifi_link_status >> 16;
2808 if (num_of_wifi_link >= 2) {
2809 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2810 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2811 bt_ctrl_agg_buf_size, agg_buf_size);
2812 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2813 return;
2814 }
2815
2816 if (coex_sta->c2h_bt_inquiry_page) {
2817 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2818 return;
2819 } else if (bt_hs_on) {
2820 halbtc8821a1ant_action_hs(btcoexist);
2821 return;
2822 }
2823
2824 if (BTC_SCAN_START == type) {
2825 if (!wifi_connected) /* non-connected scan */
2826 halbtc8821a1ant_action_wifi_not_connected_scan(
2827 btcoexist);
2828 else /* wifi is connected */
2829 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
2830 } else if (BTC_SCAN_FINISH == type) {
2831 if (!wifi_connected) /* non-connected scan */
2832 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2833 else
2834 halbtc8821a1ant_action_wifi_connected(btcoexist);
2835 }
2836 }
ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist * btcoexist,IN u8 type)2837 void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist,
2838 IN u8 type)
2839 {
2840 boolean wifi_connected = false, bt_hs_on = false;
2841 u32 wifi_link_status = 0;
2842 u32 num_of_wifi_link = 0;
2843 boolean bt_ctrl_agg_buf_size = false;
2844 u8 agg_buf_size = 5;
2845 boolean wifi_under_5g = false;
2846
2847 if (btcoexist->manual_control ||
2848 btcoexist->stop_coex_dm ||
2849 coex_sta->bt_disabled)
2850 return;
2851 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2852 if (wifi_under_5g) {
2853 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2854 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2855 BTC_TRACE(trace_buf);
2856 halbtc8821a1ant_coex_under_5g(btcoexist);
2857 return;
2858 }
2859
2860 if (BTC_ASSOCIATE_START == type) {
2861 coex_sta->wifi_is_high_pri_task = true;
2862 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2863 "[BTCoex], CONNECT START notify\n");
2864 BTC_TRACE(trace_buf);
2865 coex_dm->arp_cnt = 0;
2866 } else {
2867 coex_sta->wifi_is_high_pri_task = false;
2868 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2869 "[BTCoex], CONNECT FINISH notify\n");
2870 BTC_TRACE(trace_buf);
2871 coex_dm->arp_cnt = 0;
2872 }
2873
2874 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2875 &wifi_link_status);
2876 num_of_wifi_link = wifi_link_status >> 16;
2877 if (num_of_wifi_link >= 2) {
2878 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2879 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2880 bt_ctrl_agg_buf_size, agg_buf_size);
2881 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2882 return;
2883 }
2884
2885 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2886 if (coex_sta->c2h_bt_inquiry_page) {
2887 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2888 return;
2889 } else if (bt_hs_on) {
2890 halbtc8821a1ant_action_hs(btcoexist);
2891 return;
2892 }
2893
2894 if (BTC_ASSOCIATE_START == type)
2895 halbtc8821a1ant_action_wifi_not_connected_asso_auth(btcoexist);
2896 else if (BTC_ASSOCIATE_FINISH == type) {
2897 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2898 &wifi_connected);
2899 if (!wifi_connected) /* non-connected scan */
2900 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2901 else
2902 halbtc8821a1ant_action_wifi_connected(btcoexist);
2903 }
2904 }
2905
ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)2906 void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2907 IN u8 type)
2908 {
2909 u8 h2c_parameter[3] = {0};
2910 u32 wifi_bw;
2911 u8 wifi_central_chnl;
2912 boolean wifi_under_5g = false;
2913
2914 if (btcoexist->manual_control ||
2915 btcoexist->stop_coex_dm ||
2916 coex_sta->bt_disabled)
2917 return;
2918 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2919 if (wifi_under_5g) {
2920 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2921 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2922 BTC_TRACE(trace_buf);
2923 halbtc8821a1ant_coex_under_5g(btcoexist);
2924 return;
2925 }
2926
2927 if (BTC_MEDIA_CONNECT == type) {
2928 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2929 "[BTCoex], MEDIA connect notify\n");
2930 BTC_TRACE(trace_buf);
2931 } else {
2932 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2933 "[BTCoex], MEDIA disconnect notify\n");
2934 BTC_TRACE(trace_buf);
2935 coex_dm->arp_cnt = 0;
2936 }
2937
2938 /* only 2.4G we need to inform bt the chnl mask */
2939 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2940 &wifi_central_chnl);
2941
2942 if ((wifi_central_chnl <= 14) && (type == BTC_MEDIA_CONNECT)) {
2943
2944 h2c_parameter[0] = 0x1;
2945 /*h2c_parameter[0] = 0x0;*/
2946 h2c_parameter[1] = wifi_central_chnl;
2947 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2948 if (BTC_WIFI_BW_HT40 == wifi_bw)
2949 h2c_parameter[2] = 0x30;
2950 else
2951 h2c_parameter[2] = 0x20;
2952 }
2953
2954 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2955 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2956 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2957
2958 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2959 }
2960
ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist * btcoexist,IN u8 type)2961 void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
2962 IN u8 type)
2963 {
2964 boolean bt_hs_on = false;
2965 u32 wifi_link_status = 0;
2966 u32 num_of_wifi_link = 0;
2967 boolean bt_ctrl_agg_buf_size = false;
2968 u8 agg_buf_size = 5;
2969 boolean wifi_under_5g = false;
2970
2971 if (btcoexist->manual_control ||
2972 btcoexist->stop_coex_dm ||
2973 coex_sta->bt_disabled)
2974 return;
2975 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2976 if (wifi_under_5g) {
2977 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2978 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2979 BTC_TRACE(trace_buf);
2980 halbtc8821a1ant_coex_under_5g(btcoexist);
2981 return;
2982 }
2983
2984 if (BTC_PACKET_DHCP == type ||
2985 BTC_PACKET_EAPOL == type ||
2986 BTC_PACKET_ARP == type) {
2987 coex_sta->wifi_is_high_pri_task = true;
2988
2989 if (BTC_PACKET_ARP == type) {
2990 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2991 "[BTCoex], specific Packet ARP notify\n");
2992 BTC_TRACE(trace_buf);
2993 } else {
2994 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2995 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
2996 BTC_TRACE(trace_buf);
2997 }
2998 } else {
2999 coex_sta->wifi_is_high_pri_task = false;
3000 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3001 "[BTCoex], specific Packet [Type = %d] notify\n", type);
3002 BTC_TRACE(trace_buf);
3003 }
3004
3005 coex_sta->specific_pkt_period_cnt = 0;
3006
3007 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3008 &wifi_link_status);
3009 num_of_wifi_link = wifi_link_status >> 16;
3010 if (num_of_wifi_link >= 2) {
3011 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3012 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3013 bt_ctrl_agg_buf_size, agg_buf_size);
3014 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
3015 return;
3016 }
3017
3018 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3019 if (coex_sta->c2h_bt_inquiry_page) {
3020 halbtc8821a1ant_action_bt_inquiry(btcoexist);
3021 return;
3022 } else if (bt_hs_on) {
3023 halbtc8821a1ant_action_hs(btcoexist);
3024 return;
3025 }
3026
3027 if (BTC_PACKET_DHCP == type ||
3028 BTC_PACKET_EAPOL == type ||
3029 BTC_PACKET_ARP == type) {
3030 if (BTC_PACKET_ARP == type) {
3031 coex_dm->arp_cnt++;
3032 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3033 "[BTCoex], ARP Packet Count = %d\n",
3034 coex_dm->arp_cnt);
3035 BTC_TRACE(trace_buf);
3036 if (coex_dm->arp_cnt >=
3037 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
3038 return;
3039 }
3040
3041 halbtc8821a1ant_action_wifi_connected_specific_packet(
3042 btcoexist);
3043 }
3044 }
3045
ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)3046 void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
3047 IN u8 *tmp_buf, IN u8 length)
3048 {
3049 u8 bt_info = 0;
3050 u8 i, rsp_source = 0;
3051 boolean wifi_connected = false;
3052 boolean bt_busy = false;
3053 boolean wifi_under_5g = false;
3054
3055
3056 coex_sta->c2h_bt_info_req_sent = false;
3057
3058 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3059
3060 rsp_source = tmp_buf[0] & 0xf;
3061 if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
3062 rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
3063 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3064
3065 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3066 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
3067 length);
3068 BTC_TRACE(trace_buf);
3069 for (i = 0; i < length; i++) {
3070 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3071 if (i == 1)
3072 bt_info = tmp_buf[i];
3073 if (i == length - 1) {
3074 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
3075 tmp_buf[i]);
3076 BTC_TRACE(trace_buf);
3077 } else {
3078 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
3079 tmp_buf[i]);
3080 BTC_TRACE(trace_buf);
3081 }
3082 }
3083 /* if 0xff, it means BT is under WHCK test */
3084 if (bt_info == 0xff)
3085 coex_sta->bt_whck_test = true;
3086 else
3087 coex_sta->bt_whck_test = false;
3088
3089 if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
3090 coex_sta->bt_retry_cnt = /* [3:0] */
3091 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3092
3093 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
3094 coex_sta->c2h_bt_page = true;
3095 else
3096 coex_sta->c2h_bt_page = false;
3097
3098 coex_sta->bt_rssi =
3099 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
3100
3101 coex_sta->bt_info_ext =
3102 coex_sta->bt_info_c2h[rsp_source][4];
3103
3104 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
3105 & 0x40);
3106 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
3107 &coex_sta->bt_tx_rx_mask);
3108 if (!coex_sta->bt_tx_rx_mask) {
3109 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
3110 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3111 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3112 BTC_TRACE(trace_buf);
3113 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3114 0x3c, 0x15);
3115 }
3116
3117 /* Here we need to resend some wifi info to BT */
3118 /* because bt is reset and loss of the info. */
3119 if (coex_sta->bt_info_ext & BIT(1)) {
3120 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3121 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3122 BTC_TRACE(trace_buf);
3123 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3124 &wifi_connected);
3125 if (wifi_connected)
3126 ex_halbtc8821a1ant_media_status_notify(
3127 btcoexist, BTC_MEDIA_CONNECT);
3128 else
3129 ex_halbtc8821a1ant_media_status_notify(
3130 btcoexist, BTC_MEDIA_DISCONNECT);
3131 }
3132
3133 if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
3134 if (!btcoexist->manual_control &&
3135 !btcoexist->stop_coex_dm) {
3136 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3137 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
3138 BTC_TRACE(trace_buf);
3139 halbtc8821a1ant_ignore_wlan_act(btcoexist,
3140 FORCE_EXEC, false);
3141 }
3142 } else {
3143 /* BT already NOT ignore Wlan active, do nothing here. */
3144 }
3145 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
3146 if ((coex_sta->bt_info_ext & BIT(4))) {
3147 /* BT auto report already enabled, do nothing */
3148 } else
3149 halbtc8821a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
3150 true);
3151 #endif
3152 }
3153
3154 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3155 if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
3156 coex_sta->c2h_bt_inquiry_page = true;
3157 else
3158 coex_sta->c2h_bt_inquiry_page = false;
3159
3160 /* set link exist status */
3161 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
3162 coex_sta->bt_link_exist = false;
3163 coex_sta->pan_exist = false;
3164 coex_sta->a2dp_exist = false;
3165 coex_sta->hid_exist = false;
3166 coex_sta->sco_exist = false;
3167 } else { /* connection exists */
3168 coex_sta->bt_link_exist = true;
3169 if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
3170 coex_sta->pan_exist = true;
3171 else
3172 coex_sta->pan_exist = false;
3173 if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
3174 coex_sta->a2dp_exist = true;
3175 else
3176 coex_sta->a2dp_exist = false;
3177 if (bt_info & BT_INFO_8821A_1ANT_B_HID)
3178 coex_sta->hid_exist = true;
3179 else
3180 coex_sta->hid_exist = false;
3181 if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
3182 coex_sta->sco_exist = true;
3183 else
3184 coex_sta->sco_exist = false;
3185 }
3186
3187 halbtc8821a1ant_update_bt_link_info(btcoexist);
3188
3189 bt_info = bt_info &
3190 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
3191
3192 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
3193 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3194 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3195 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
3196 BTC_TRACE(trace_buf);
3197 } else if (bt_info ==
3198 BT_INFO_8821A_1ANT_B_CONNECTION) { /* connection exists but no busy */
3199 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
3200 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3201 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3202 BTC_TRACE(trace_buf);
3203 } else if ((bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
3204 (bt_info & BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
3205 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
3206 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3207 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3208 BTC_TRACE(trace_buf);
3209 } else if (bt_info & BT_INFO_8821A_1ANT_B_ACL_BUSY) {
3210 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
3211 coex_dm->auto_tdma_adjust = false;
3212 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
3213 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3214 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3215 BTC_TRACE(trace_buf);
3216 } else {
3217 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
3218 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3219 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
3220 BTC_TRACE(trace_buf);
3221 }
3222
3223 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3224 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3225 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3226 bt_busy = true;
3227 else
3228 bt_busy = false;
3229 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3230
3231 halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3232 }
3233
ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist * btcoexist)3234 void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist)
3235 {
3236 boolean wifi_under_5g = false;
3237 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3238 if (wifi_under_5g) {
3239 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3240 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3241 BTC_TRACE(trace_buf);
3242 halbtc8821a1ant_coex_under_5g(btcoexist);
3243 return;
3244 }
3245
3246 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3247 BTC_TRACE(trace_buf);
3248
3249 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3250 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
3251 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3252
3253 halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3254
3255 ex_halbtc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3256
3257 btcoexist->stop_coex_dm = true;
3258 }
3259
ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist * btcoexist,IN u8 pnp_state)3260 void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3261 IN u8 pnp_state)
3262 {
3263 boolean wifi_under_5g = false;
3264
3265 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3266 if (wifi_under_5g) {
3267 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3268 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3269 BTC_TRACE(trace_buf);
3270 halbtc8821a1ant_coex_under_5g(btcoexist);
3271 return;
3272 }
3273 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3274 BTC_TRACE(trace_buf);
3275
3276 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3277 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3278 "[BTCoex], Pnp notify to SLEEP\n");
3279 BTC_TRACE(trace_buf);
3280
3281 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3282 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3283 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3284 true);
3285 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3286
3287 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3288 /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3289 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3290 coex_sta->under_ips = false;
3291 coex_sta->under_lps = false;
3292 btcoexist->stop_coex_dm = true;
3293 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3294 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3295 "[BTCoex], Pnp notify to WAKE UP\n");
3296 BTC_TRACE(trace_buf);
3297 btcoexist->stop_coex_dm = false;
3298 halbtc8821a1ant_init_hw_config(btcoexist, false, false);
3299 halbtc8821a1ant_init_coex_dm(btcoexist);
3300 halbtc8821a1ant_query_bt_info(btcoexist);
3301 }
3302 }
3303
ex_halbtc8821a1ant_periodical(IN struct btc_coexist * btcoexist)3304 void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist)
3305 {
3306 u32 bt_patch_ver;
3307
3308 if (((coex_sta->bt_coex_supported_version == 0) ||
3309 (coex_sta->bt_coex_supported_version == 0xffff)) && (!coex_sta->bt_disabled))
3310 btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
3311
3312 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3313 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
3314
3315 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
3316 halbtc8821a1ant_query_bt_info(btcoexist);
3317 halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
3318 #else
3319 halbtc8821a1ant_monitor_bt_ctr(btcoexist);
3320 halbtc8821a1ant_monitor_wifi_ctr(btcoexist);
3321 halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
3322 if (halbtc8821a1ant_is_wifi_status_changed(btcoexist) ||
3323 coex_dm->auto_tdma_adjust) {
3324 /* if(coex_sta->specific_pkt_period_cnt > 2) */
3325 /* { */
3326 halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3327 /* } */
3328 }
3329
3330 coex_sta->specific_pkt_period_cnt++;
3331 #endif
3332 }
3333
3334 #endif
3335
3336 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */
3337
3338
3339