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