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