1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* ************************************************************
3 * Description:
4 *
5 * This file is for RTL8821A Co-exist mechanism
6 *
7 * History
8 * 2012/11/15 Cosa first check in.
9 *
10 * ************************************************************ */
11
12 /* ************************************************************
13 * include files
14 * ************************************************************ */
15 #include "Mp_Precomp.h"
16
17 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
18
19 #if (RTL8821A_SUPPORT == 1)
20 /* ************************************************************
21 * Global variables, these are static variables
22 * ************************************************************ */
23 static u8 *trace_buf = &gl_btc_trace_buf[0];
24 static struct coex_dm_8821a_2ant glcoex_dm_8821a_2ant;
25 static struct coex_dm_8821a_2ant *coex_dm = &glcoex_dm_8821a_2ant;
26 static struct coex_sta_8821a_2ant glcoex_sta_8821a_2ant;
27 static struct coex_sta_8821a_2ant *coex_sta = &glcoex_sta_8821a_2ant;
28
29 const char *const glbt_info_src_8821a_2ant[] = {
30 "BT Info[wifi fw]",
31 "BT Info[bt rsp]",
32 "BT Info[bt auto report]",
33 };
34
35 u32 glcoex_ver_date_8821a_2ant = 20150921;
36 u32 glcoex_ver_8821a_2ant = 0x58;
37 /* modify 20140903v43 a2dpandhid tdmaonoff a2dp glitch _ tdma off 778=3(case1)->778=1(case0)
38 * and to improve tp while a2dphid case23->case25 , case123->case125 for asus spec
39 * and modify for asus bt WHQL test _ tdma off_ 778=3->1_
40 * ************************************************************
41 * local function proto type if needed
42 * ************************************************************
43 * ************************************************************
44 * local function start with halbtc8821a2ant_
45 * ************************************************************ */
halbtc8821a2ant_bt_rssi_state(u8 level_num,u8 rssi_thresh,u8 rssi_thresh1)46 u8 halbtc8821a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
47 {
48 s32 bt_rssi = 0;
49 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
50
51 bt_rssi = coex_sta->bt_rssi;
52
53 if (level_num == 2) {
54 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
55 (coex_sta->pre_bt_rssi_state ==
56 BTC_RSSI_STATE_STAY_LOW)) {
57 if (bt_rssi >= (rssi_thresh +
58 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
59 bt_rssi_state = BTC_RSSI_STATE_HIGH;
60 else
61 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
62 } else {
63 if (bt_rssi < rssi_thresh)
64 bt_rssi_state = BTC_RSSI_STATE_LOW;
65 else
66 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
67 }
68 } else if (level_num == 3) {
69 if (rssi_thresh > rssi_thresh1) {
70 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
71 "[BTCoex], BT Rssi thresh error!!\n");
72 BTC_TRACE(trace_buf);
73 return coex_sta->pre_bt_rssi_state;
74 }
75
76 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
77 (coex_sta->pre_bt_rssi_state ==
78 BTC_RSSI_STATE_STAY_LOW)) {
79 if (bt_rssi >= (rssi_thresh +
80 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
81 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
82 else
83 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
84 } else if ((coex_sta->pre_bt_rssi_state ==
85 BTC_RSSI_STATE_MEDIUM) ||
86 (coex_sta->pre_bt_rssi_state ==
87 BTC_RSSI_STATE_STAY_MEDIUM)) {
88 if (bt_rssi >= (rssi_thresh1 +
89 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
90 bt_rssi_state = BTC_RSSI_STATE_HIGH;
91 else if (bt_rssi < rssi_thresh)
92 bt_rssi_state = BTC_RSSI_STATE_LOW;
93 else
94 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
95 } else {
96 if (bt_rssi < rssi_thresh1)
97 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
98 else
99 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
100 }
101 }
102
103 coex_sta->pre_bt_rssi_state = bt_rssi_state;
104
105 return bt_rssi_state;
106 }
107
halbtc8821a2ant_wifi_rssi_state(IN struct btc_coexist * btcoexist,IN u8 index,IN u8 level_num,IN u8 rssi_thresh,IN u8 rssi_thresh1)108 u8 halbtc8821a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
109 IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
110 {
111 s32 wifi_rssi = 0;
112 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
113
114 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
115
116 if (level_num == 2) {
117 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
118 ||
119 (coex_sta->pre_wifi_rssi_state[index] ==
120 BTC_RSSI_STATE_STAY_LOW)) {
121 if (wifi_rssi >= (rssi_thresh +
122 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
123 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
124 else
125 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
126 } else {
127 if (wifi_rssi < rssi_thresh)
128 wifi_rssi_state = BTC_RSSI_STATE_LOW;
129 else
130 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
131 }
132 } else if (level_num == 3) {
133 if (rssi_thresh > rssi_thresh1) {
134 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
135 "[BTCoex], wifi RSSI thresh error!!\n");
136 BTC_TRACE(trace_buf);
137 return coex_sta->pre_wifi_rssi_state[index];
138 }
139
140 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
141 ||
142 (coex_sta->pre_wifi_rssi_state[index] ==
143 BTC_RSSI_STATE_STAY_LOW)) {
144 if (wifi_rssi >= (rssi_thresh +
145 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
146 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
147 else
148 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
149 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
150 BTC_RSSI_STATE_MEDIUM) ||
151 (coex_sta->pre_wifi_rssi_state[index] ==
152 BTC_RSSI_STATE_STAY_MEDIUM)) {
153 if (wifi_rssi >= (rssi_thresh1 +
154 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
155 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
156 else if (wifi_rssi < rssi_thresh)
157 wifi_rssi_state = BTC_RSSI_STATE_LOW;
158 else
159 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
160 } else {
161 if (wifi_rssi < rssi_thresh1)
162 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
163 else
164 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
165 }
166 }
167
168 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
169
170 return wifi_rssi_state;
171 }
172
halbtc8821a2ant_monitor_bt_enable_disable(IN struct btc_coexist * btcoexist)173 void halbtc8821a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
174 {
175 static u32 bt_disable_cnt = 0;
176 boolean bt_active = true, bt_disabled = false;
177
178 /* This function check if bt is disabled */
179
180 if (coex_sta->high_priority_tx == 0 &&
181 coex_sta->high_priority_rx == 0 &&
182 coex_sta->low_priority_tx == 0 &&
183 coex_sta->low_priority_rx == 0)
184 bt_active = false;
185 if (coex_sta->high_priority_tx == 0xffff &&
186 coex_sta->high_priority_rx == 0xffff &&
187 coex_sta->low_priority_tx == 0xffff &&
188 coex_sta->low_priority_rx == 0xffff)
189 bt_active = false;
190 if (bt_active) {
191 bt_disable_cnt = 0;
192 bt_disabled = false;
193 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
194 &bt_disabled);
195 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
196 "[BTCoex], BT is enabled !!\n");
197 BTC_TRACE(trace_buf);
198 } else {
199 bt_disable_cnt++;
200 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
201 "[BTCoex], bt all counters=0, %d times!!\n",
202 bt_disable_cnt);
203 BTC_TRACE(trace_buf);
204 if (bt_disable_cnt >= 2) {
205 bt_disabled = true;
206 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
207 &bt_disabled);
208 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
209 "[BTCoex], BT is disabled !!\n");
210 BTC_TRACE(trace_buf);
211 }
212 }
213 if (coex_sta->bt_disabled != bt_disabled) {
214 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
215 "[BTCoex], BT is from %s to %s!!\n",
216 (coex_sta->bt_disabled ? "disabled" : "enabled"),
217 (bt_disabled ? "disabled" : "enabled"));
218 BTC_TRACE(trace_buf);
219 coex_sta->bt_disabled = bt_disabled;
220 if (!bt_disabled) {
221 } else {
222 }
223 }
224 }
225
halbtc8821a2ant_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)226 void halbtc8821a2ant_limited_rx(IN struct btc_coexist *btcoexist,
227 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
228 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
229 {
230 boolean reject_rx_agg = rej_ap_agg_pkt;
231 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
232 u8 rx_agg_size = agg_buf_size;
233
234 /* ============================================ */
235 /* Rx Aggregation related setting */
236 /* ============================================ */
237 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
238 &reject_rx_agg);
239 /* decide BT control aggregation buf size or not */
240 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
241 &bt_ctrl_rx_agg_size);
242 /* aggregation buf size, only work when BT control Rx aggregation size. */
243 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
244 /* real update aggregation setting */
245 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
246 }
247
halbtc8821a2ant_monitor_bt_ctr(IN struct btc_coexist * btcoexist)248 void halbtc8821a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
249 {
250 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
251 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
252
253 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
254
255 reg_hp_txrx = 0x770;
256 reg_lp_txrx = 0x774;
257
258 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
259 reg_hp_tx = u32tmp & MASKLWORD;
260 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
261
262 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
263 reg_lp_tx = u32tmp & MASKLWORD;
264 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
265
266 coex_sta->high_priority_tx = reg_hp_tx;
267 coex_sta->high_priority_rx = reg_hp_rx;
268 coex_sta->low_priority_tx = reg_lp_tx;
269 coex_sta->low_priority_rx = reg_lp_rx;
270
271 if ((coex_sta->low_priority_rx >= 950) &&
272 (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) &&
273 (!coex_sta->under_ips))
274 bt_link_info->slave_role = true;
275 else
276 bt_link_info->slave_role = false;
277
278 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
279 "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
280 reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
281 BTC_TRACE(trace_buf);
282 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
283 "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
284 reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
285 BTC_TRACE(trace_buf);
286
287 /* reset counter */
288 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
289 }
290
halbtc8821a2ant_monitor_wifi_ctr(IN struct btc_coexist * btcoexist)291 void halbtc8821a2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
292 {
293 if (coex_sta->under_ips) {
294 coex_sta->crc_ok_cck = 0;
295 coex_sta->crc_ok_11g = 0;
296 coex_sta->crc_ok_11n = 0;
297 coex_sta->crc_ok_11n_agg = 0;
298
299 coex_sta->crc_err_cck = 0;
300 coex_sta->crc_err_11g = 0;
301 coex_sta->crc_err_11n = 0;
302 coex_sta->crc_err_11n_agg = 0;
303 } else {
304 coex_sta->crc_ok_cck = btcoexist->btc_read_4byte(btcoexist,
305 0xf88);
306 coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist,
307 0xf94);
308 coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist,
309 0xf90);
310 coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
311 0xfb8);
312
313 coex_sta->crc_err_cck = btcoexist->btc_read_4byte(btcoexist,
314 0xf84);
315 coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist,
316 0xf96);
317 coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist,
318 0xf92);
319 coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
320 0xfba);
321 }
322
323 /* reset counter */
324 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1);
325 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0);
326 }
327
halbtc8821a2ant_query_bt_info(IN struct btc_coexist * btcoexist)328 void halbtc8821a2ant_query_bt_info(IN struct btc_coexist *btcoexist)
329 {
330 u8 h2c_parameter[1] = {0};
331
332 coex_sta->c2h_bt_info_req_sent = true;
333
334 h2c_parameter[0] |= BIT(0); /* trigger */
335
336 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
337 }
338
halbtc8821a2ant_is_wifi_status_changed(IN struct btc_coexist * btcoexist)339 boolean halbtc8821a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
340 {
341 static boolean pre_wifi_busy = false, pre_under_4way = false,
342 pre_bt_hs_on = false;
343 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
344 boolean wifi_connected = false;
345 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
346
347
348 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
349 &wifi_connected);
350 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
351 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
352 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
353 &under_4way);
354
355 if (wifi_connected) {
356 if (wifi_busy != pre_wifi_busy) {
357 pre_wifi_busy = wifi_busy;
358 return true;
359 }
360 if (under_4way != pre_under_4way) {
361 pre_under_4way = under_4way;
362 return true;
363 }
364 if (bt_hs_on != pre_bt_hs_on) {
365 pre_bt_hs_on = bt_hs_on;
366 return true;
367 }
368
369
370 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 3,
371 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
372
373 if ((BTC_RSSI_STATE_HIGH == wifi_rssi_state) ||
374 (BTC_RSSI_STATE_LOW == wifi_rssi_state))
375 return true;
376
377 }
378
379 return false;
380 }
381
halbtc8821a2ant_update_bt_link_info(IN struct btc_coexist * btcoexist)382 void halbtc8821a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
383 {
384 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
385 boolean bt_hs_on = false;
386
387 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
388
389 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
390 bt_link_info->sco_exist = coex_sta->sco_exist;
391 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
392 bt_link_info->pan_exist = coex_sta->pan_exist;
393 bt_link_info->hid_exist = coex_sta->hid_exist;
394
395 /* work around for HS mode. */
396 if (bt_hs_on) {
397 bt_link_info->pan_exist = true;
398 bt_link_info->bt_link_exist = true;
399 }
400
401 /* check if Sco only */
402 if (bt_link_info->sco_exist &&
403 !bt_link_info->a2dp_exist &&
404 !bt_link_info->pan_exist &&
405 !bt_link_info->hid_exist)
406 bt_link_info->sco_only = true;
407 else
408 bt_link_info->sco_only = false;
409
410 /* check if A2dp only */
411 if (!bt_link_info->sco_exist &&
412 bt_link_info->a2dp_exist &&
413 !bt_link_info->pan_exist &&
414 !bt_link_info->hid_exist)
415 bt_link_info->a2dp_only = true;
416 else
417 bt_link_info->a2dp_only = false;
418
419 /* check if Pan only */
420 if (!bt_link_info->sco_exist &&
421 !bt_link_info->a2dp_exist &&
422 bt_link_info->pan_exist &&
423 !bt_link_info->hid_exist)
424 bt_link_info->pan_only = true;
425 else
426 bt_link_info->pan_only = false;
427
428 /* check if Hid only */
429 if (!bt_link_info->sco_exist &&
430 !bt_link_info->a2dp_exist &&
431 !bt_link_info->pan_exist &&
432 bt_link_info->hid_exist)
433 bt_link_info->hid_only = true;
434 else
435 bt_link_info->hid_only = false;
436 }
437
halbtc8821a2ant_action_algorithm(IN struct btc_coexist * btcoexist)438 u8 halbtc8821a2ant_action_algorithm(IN struct btc_coexist *btcoexist)
439 {
440 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
441 boolean bt_hs_on = false;
442 u8 algorithm = BT_8821A_2ANT_COEX_ALGO_UNDEFINED;
443 u8 num_of_diff_profile = 0;
444
445 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
446
447 if (!bt_link_info->bt_link_exist) {
448 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
449 "[BTCoex], No BT link exists!!!\n");
450 BTC_TRACE(trace_buf);
451 return algorithm;
452 }
453
454 if (bt_link_info->sco_exist)
455 num_of_diff_profile++;
456 if (bt_link_info->hid_exist)
457 num_of_diff_profile++;
458 if (bt_link_info->pan_exist)
459 num_of_diff_profile++;
460 if (bt_link_info->a2dp_exist)
461 num_of_diff_profile++;
462
463 if (num_of_diff_profile == 1) {
464 if (bt_link_info->sco_exist) {
465 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
466 "[BTCoex], SCO only\n");
467 BTC_TRACE(trace_buf);
468 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
469 } else {
470 if (bt_link_info->hid_exist) {
471 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
472 "[BTCoex], HID only\n");
473 BTC_TRACE(trace_buf);
474 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
475 } else if (bt_link_info->a2dp_exist) {
476 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
477 "[BTCoex], A2DP only\n");
478 BTC_TRACE(trace_buf);
479 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;
480 } else if (bt_link_info->pan_exist) {
481 if (bt_hs_on) {
482 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
483 "[BTCoex], PAN(HS) only\n");
484 BTC_TRACE(trace_buf);
485 algorithm =
486 BT_8821A_2ANT_COEX_ALGO_PANHS;
487 } else {
488 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
489 "[BTCoex], PAN(EDR) only\n");
490 BTC_TRACE(trace_buf);
491 algorithm =
492 BT_8821A_2ANT_COEX_ALGO_PANEDR;
493 }
494 }
495 }
496 } else if (num_of_diff_profile == 2) {
497 if (bt_link_info->sco_exist) {
498 if (bt_link_info->hid_exist) {
499 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
500 "[BTCoex], SCO + HID\n");
501 BTC_TRACE(trace_buf);
502 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
503 } else if (bt_link_info->a2dp_exist) {
504 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
505 "[BTCoex], SCO + A2DP ==> SCO\n");
506 BTC_TRACE(trace_buf);
507 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
508 } else if (bt_link_info->pan_exist) {
509 if (bt_hs_on) {
510 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
511 "[BTCoex], SCO + PAN(HS)\n");
512 BTC_TRACE(trace_buf);
513 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
514 } else {
515 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
516 "[BTCoex], SCO + PAN(EDR)\n");
517 BTC_TRACE(trace_buf);
518 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
519 }
520 }
521 } else {
522 if (bt_link_info->hid_exist &&
523 bt_link_info->a2dp_exist) {
524 {
525 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
526 "[BTCoex], HID + A2DP\n");
527 BTC_TRACE(trace_buf);
528 algorithm =
529 BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
530 }
531 } else if (bt_link_info->hid_exist &&
532 bt_link_info->pan_exist) {
533 if (bt_hs_on) {
534 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
535 "[BTCoex], HID + PAN(HS)\n");
536 BTC_TRACE(trace_buf);
537 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
538 } else {
539 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
540 "[BTCoex], HID + PAN(EDR)\n");
541 BTC_TRACE(trace_buf);
542 algorithm =
543 BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
544 }
545 } else if (bt_link_info->pan_exist &&
546 bt_link_info->a2dp_exist) {
547 if (bt_hs_on) {
548 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
549 "[BTCoex], A2DP + PAN(HS)\n");
550 BTC_TRACE(trace_buf);
551 algorithm =
552 BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;
553 } else {
554 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
555 "[BTCoex], A2DP + PAN(EDR)\n");
556 BTC_TRACE(trace_buf);
557 algorithm =
558 BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;
559 }
560 }
561 }
562 } else if (num_of_diff_profile == 3) {
563 if (bt_link_info->sco_exist) {
564 if (bt_link_info->hid_exist &&
565 bt_link_info->a2dp_exist) {
566 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
567 "[BTCoex], SCO + HID + A2DP ==> SCO\n");
568 BTC_TRACE(trace_buf);
569 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
570 } else if (bt_link_info->hid_exist &&
571 bt_link_info->pan_exist) {
572 if (bt_hs_on) {
573 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
574 "[BTCoex], SCO + HID + PAN(HS) ==> SCO\n");
575 BTC_TRACE(trace_buf);
576 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
577 } else {
578 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
579 "[BTCoex], SCO + HID + PAN(EDR) ==> SCO\n");
580 BTC_TRACE(trace_buf);
581 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
582 }
583 } else if (bt_link_info->pan_exist &&
584 bt_link_info->a2dp_exist) {
585 if (bt_hs_on) {
586 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
587 "[BTCoex], SCO + A2DP + PAN(HS)\n");
588 BTC_TRACE(trace_buf);
589 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
590 } else {
591 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
592 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
593 BTC_TRACE(trace_buf);
594 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
595 }
596 }
597 } else {
598 if (bt_link_info->hid_exist &&
599 bt_link_info->pan_exist &&
600 bt_link_info->a2dp_exist) {
601 if (bt_hs_on) {
602 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
603 "[BTCoex], HID + A2DP + PAN(HS)\n");
604 BTC_TRACE(trace_buf);
605 algorithm =
606 BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
607 } else {
608 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
609 "[BTCoex], HID + A2DP + PAN(EDR)\n");
610 BTC_TRACE(trace_buf);
611 algorithm =
612 BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
613 }
614 }
615 }
616 } else if (num_of_diff_profile >= 3) {
617 if (bt_link_info->sco_exist) {
618 if (bt_link_info->hid_exist &&
619 bt_link_info->pan_exist &&
620 bt_link_info->a2dp_exist) {
621 if (bt_hs_on) {
622 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
623 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
624 BTC_TRACE(trace_buf);
625
626 } else {
627 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
628 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
629 BTC_TRACE(trace_buf);
630 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
631 }
632 }
633 }
634 }
635
636 return algorithm;
637 }
638
halbtc8821a2ant_set_fw_dac_swing_level(IN struct btc_coexist * btcoexist,IN u8 dac_swing_lvl)639 void halbtc8821a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist,
640 IN u8 dac_swing_lvl)
641 {
642 u8 h2c_parameter[1] = {0};
643
644 /* There are several type of dacswing */
645 /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
646 h2c_parameter[0] = dac_swing_lvl;
647
648 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
649 }
650
halbtc8821a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist * btcoexist,IN u8 dec_bt_pwr_lvl)651 void halbtc8821a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist,
652 IN u8 dec_bt_pwr_lvl)
653 {
654 u8 h2c_parameter[1] = {0};
655
656 h2c_parameter[0] = dec_bt_pwr_lvl;
657
658 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
659 }
660
halbtc8821a2ant_dec_bt_pwr(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 dec_bt_pwr_lvl)661 void halbtc8821a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist,
662 IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
663 {
664 coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
665
666 if (!force_exec) {
667 if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
668 return;
669 }
670 halbtc8821a2ant_set_fw_dec_bt_pwr(btcoexist,
671 coex_dm->cur_bt_dec_pwr_lvl);
672
673 coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
674 }
675
halbtc8821a2ant_set_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean enable_auto_report)676 void halbtc8821a2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
677 IN boolean enable_auto_report)
678 {
679 u8 h2c_parameter[1] = {0};
680
681 h2c_parameter[0] = 0;
682
683 if (enable_auto_report)
684 h2c_parameter[0] |= BIT(0);
685
686 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
687 }
688
halbtc8821a2ant_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable_auto_report)689 void halbtc8821a2ant_bt_auto_report(IN struct btc_coexist *btcoexist,
690 IN boolean force_exec, IN boolean enable_auto_report)
691 {
692 coex_dm->cur_bt_auto_report = enable_auto_report;
693
694 if (!force_exec) {
695 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
696 return;
697 }
698 halbtc8821a2ant_set_bt_auto_report(btcoexist,
699 coex_dm->cur_bt_auto_report);
700
701 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
702 }
703
halbtc8821a2ant_fw_dac_swing_lvl(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 fw_dac_swing_lvl)704 void halbtc8821a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist,
705 IN boolean force_exec, IN u8 fw_dac_swing_lvl)
706 {
707 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
708
709 if (!force_exec) {
710 if (coex_dm->pre_fw_dac_swing_lvl ==
711 coex_dm->cur_fw_dac_swing_lvl)
712 return;
713 }
714
715 halbtc8821a2ant_set_fw_dac_swing_level(btcoexist,
716 coex_dm->cur_fw_dac_swing_lvl);
717
718 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
719 }
720
halbtc8821a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist * btcoexist,IN boolean rx_rf_shrink_on)721 void halbtc8821a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist,
722 IN boolean rx_rf_shrink_on)
723 {
724 if (rx_rf_shrink_on) {
725 /* Shrink RF Rx LPF corner */
726 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
727 "[BTCoex], Shrink RF Rx LPF corner!!\n");
728 BTC_TRACE(trace_buf);
729 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff,
730 0xffffc);
731 } else {
732 /* Resume RF Rx LPF corner */
733 /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */
734 if (btcoexist->initilized) {
735 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
736 "[BTCoex], Resume RF Rx LPF corner!!\n");
737 BTC_TRACE(trace_buf);
738 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
739 0xfffff, coex_dm->bt_rf_0x1e_backup);
740 }
741 }
742 }
743
halbtc8821a2ant_rf_shrink(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean rx_rf_shrink_on)744 void halbtc8821a2ant_rf_shrink(IN struct btc_coexist *btcoexist,
745 IN boolean force_exec, IN boolean rx_rf_shrink_on)
746 {
747 coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
748
749 if (!force_exec) {
750 if (coex_dm->pre_rf_rx_lpf_shrink ==
751 coex_dm->cur_rf_rx_lpf_shrink)
752 return;
753 }
754 halbtc8821a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
755 coex_dm->cur_rf_rx_lpf_shrink);
756
757 coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
758 }
759
halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist * btcoexist,IN boolean low_penalty_ra)760 void halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
761 *btcoexist, IN boolean low_penalty_ra)
762 {
763 u8 h2c_parameter[6] = {0};
764
765 h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
766
767 if (low_penalty_ra) {
768 h2c_parameter[1] |= BIT(0);
769 h2c_parameter[2] =
770 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
771 h2c_parameter[3] = 0xf5; /* MCS7 or OFDM54 */
772 h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */
773 h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */
774 /* h2c_parameter[3] = 0xf7; //MCS7 or OFDM54 */
775 /* h2c_parameter[4] = 0xf8; //MCS6 or OFDM48 */
776 /* h2c_parameter[5] = 0xf9; //MCS5 or OFDM36 */
777 }
778
779 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
780 }
781
halbtc8821a2ant_low_penalty_ra(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean low_penalty_ra)782 void halbtc8821a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
783 IN boolean force_exec, IN boolean low_penalty_ra)
784 {
785 coex_dm->cur_low_penalty_ra = low_penalty_ra;
786
787 if (!force_exec) {
788 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
789 return;
790 }
791 halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
792 coex_dm->cur_low_penalty_ra);
793
794 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
795 }
796
halbtc8821a2ant_set_dac_swing_reg(IN struct btc_coexist * btcoexist,IN u32 level)797 void halbtc8821a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist,
798 IN u32 level)
799 {
800 u8 val = (u8)level;
801
802 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
803 "[BTCoex], Write SwDacSwing = 0x%x\n", level);
804 BTC_TRACE(trace_buf);
805 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
806 }
807
halbtc8821a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist * btcoexist,IN boolean sw_dac_swing_on,IN u32 sw_dac_swing_lvl)808 void halbtc8821a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist
809 *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl)
810 {
811 if (sw_dac_swing_on)
812 halbtc8821a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
813 else
814 halbtc8821a2ant_set_dac_swing_reg(btcoexist, 0x18);
815 }
816
817
halbtc8821a2ant_dac_swing(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean dac_swing_on,IN u32 dac_swing_lvl)818 void halbtc8821a2ant_dac_swing(IN struct btc_coexist *btcoexist,
819 IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl)
820 {
821 coex_dm->cur_dac_swing_on = dac_swing_on;
822 coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
823
824 if (!force_exec) {
825 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
826 (coex_dm->pre_dac_swing_lvl ==
827 coex_dm->cur_dac_swing_lvl))
828 return;
829 }
830 delay_ms(30);
831 halbtc8821a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on,
832 dac_swing_lvl);
833
834 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
835 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
836 }
837
halbtc8821a2ant_set_adc_back_off(IN struct btc_coexist * btcoexist,IN boolean adc_back_off)838 void halbtc8821a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist,
839 IN boolean adc_back_off)
840 {
841 if (adc_back_off) {
842 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
843 "[BTCoex], BB BackOff Level On!\n");
844 BTC_TRACE(trace_buf);
845 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
846 } else {
847 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
848 "[BTCoex], BB BackOff Level Off!\n");
849 BTC_TRACE(trace_buf);
850 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
851 }
852 }
853
halbtc8821a2ant_adc_back_off(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean adc_back_off)854 void halbtc8821a2ant_adc_back_off(IN struct btc_coexist *btcoexist,
855 IN boolean force_exec, IN boolean adc_back_off)
856 {
857 coex_dm->cur_adc_back_off = adc_back_off;
858
859 if (!force_exec) {
860 if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
861 return;
862 }
863 halbtc8821a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
864
865 coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
866 }
867
halbtc8821a2ant_set_agc_table(IN struct btc_coexist * btcoexist,IN boolean agc_table_en)868 void halbtc8821a2ant_set_agc_table(IN struct btc_coexist *btcoexist,
869 IN boolean agc_table_en)
870 {
871 u8 rssi_adjust_val = 0;
872
873 /* =================BB AGC Gain Table */
874 if (agc_table_en) {
875 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
876 "[BTCoex], BB Agc Table On!\n");
877 BTC_TRACE(trace_buf);
878 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6e1A0001);
879 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6d1B0001);
880 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6c1C0001);
881 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6b1D0001);
882 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6a1E0001);
883 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x691F0001);
884 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x68200001);
885 } else {
886 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
887 "[BTCoex], BB Agc Table Off!\n");
888 BTC_TRACE(trace_buf);
889 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001);
890 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001);
891 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001);
892 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001);
893 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001);
894 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001);
895 btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa4200001);
896 }
897
898
899 /* =================RF Gain */
900 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
901 if (agc_table_en) {
902 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
903 "[BTCoex], Agc Table On!\n");
904 BTC_TRACE(trace_buf);
905 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
906 0x38fff);
907 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
908 0x38ffe);
909 } else {
910 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
911 "[BTCoex], Agc Table Off!\n");
912 BTC_TRACE(trace_buf);
913 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
914 0x380c3);
915 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
916 0x28ce6);
917 }
918 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
919
920 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
921 if (agc_table_en) {
922 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
923 "[BTCoex], Agc Table On!\n");
924 BTC_TRACE(trace_buf);
925 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
926 0x38fff);
927 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
928 0x38ffe);
929 } else {
930 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
931 "[BTCoex], Agc Table Off!\n");
932 BTC_TRACE(trace_buf);
933 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
934 0x380c3);
935 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
936 0x28ce6);
937 }
938 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
939
940 /* set rssi_adjust_val for wifi module. */
941 if (agc_table_en)
942 rssi_adjust_val = 8;
943 btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
944 &rssi_adjust_val);
945 }
946
halbtc8821a2ant_agc_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean agc_table_en)947 void halbtc8821a2ant_agc_table(IN struct btc_coexist *btcoexist,
948 IN boolean force_exec, IN boolean agc_table_en)
949 {
950 coex_dm->cur_agc_table_en = agc_table_en;
951
952 if (!force_exec) {
953 if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
954 return;
955 }
956 halbtc8821a2ant_set_agc_table(btcoexist, agc_table_en);
957
958 coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
959 }
960
halbtc8821a2ant_set_coex_table(IN struct btc_coexist * btcoexist,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)961 void halbtc8821a2ant_set_coex_table(IN struct btc_coexist *btcoexist,
962 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
963 {
964 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
965
966 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
967
968 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
969
970 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
971 }
972
halbtc8821a2ant_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)973 void halbtc8821a2ant_coex_table(IN struct btc_coexist *btcoexist,
974 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
975 IN u32 val0x6c8, IN u8 val0x6cc)
976 {
977 coex_dm->cur_val0x6c0 = val0x6c0;
978 coex_dm->cur_val0x6c4 = val0x6c4;
979 coex_dm->cur_val0x6c8 = val0x6c8;
980 coex_dm->cur_val0x6cc = val0x6cc;
981
982 if (!force_exec) {
983 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
984 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
985 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
986 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
987 return;
988 }
989 halbtc8821a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
990 val0x6cc);
991
992 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
993 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
994 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
995 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
996 }
997
halbtc8821a2ant_coex_table_with_type(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)998 void halbtc8821a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
999 IN boolean force_exec, IN u8 type)
1000 {
1001 coex_sta->coex_table_type = type;
1002
1003 switch (type) {
1004 case 0:
1005 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1006 0x55555555, 0x55555555, 0xffffff, 0x3);
1007 break;
1008 case 1:
1009 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1010 0x55555555, 0x5afa5afa, 0xffffff, 0x3);
1011 break;
1012 case 2:
1013 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1014 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3);
1015 break;
1016 case 3:
1017 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1018 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
1019 break;
1020 case 4:
1021 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1022 0xffffffff, 0xffffffff, 0xffffff, 0x3);
1023 break;
1024 case 5:
1025 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1026 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3);
1027 break;
1028 case 6:
1029 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1030 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3);
1031 break;
1032 case 7:
1033 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1034 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1035 break;
1036 case 8:
1037 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1038 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1039 break;
1040 case 9:
1041 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1042 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1043 break;
1044 case 10:
1045 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1046 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1047 break;
1048 case 11:
1049 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1050 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1051 break;
1052 case 12:
1053 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1054 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1055 break;
1056 case 13:
1057 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1058 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3);
1059 break;
1060 case 14:
1061 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1062 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3);
1063 break;
1064 case 15:
1065 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1066 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3);
1067 break;
1068 case 16:
1069 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1070 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
1071 break;
1072 case 17:
1073 halbtc8821a2ant_coex_table(btcoexist, force_exec,
1074 0xfafafafa, 0xfafafafa, 0xffffff, 0x3);
1075 break;
1076 default:
1077 break;
1078 }
1079 }
1080
halbtc8821a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean enable)1081 void halbtc8821a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1082 IN boolean enable)
1083 {
1084 u8 h2c_parameter[1] = {0};
1085
1086 if (enable) {
1087 h2c_parameter[0] |= BIT(0); /* function enable */
1088 }
1089
1090 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1091 }
1092
halbtc8821a2ant_set_lps_rpwm(IN struct btc_coexist * btcoexist,IN u8 lps_val,IN u8 rpwm_val)1093 void halbtc8821a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
1094 IN u8 lps_val, IN u8 rpwm_val)
1095 {
1096 u8 lps = lps_val;
1097 u8 rpwm = rpwm_val;
1098
1099 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1100 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1101 }
1102
halbtc8821a2ant_lps_rpwm(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 lps_val,IN u8 rpwm_val)1103 void halbtc8821a2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
1104 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
1105 {
1106 coex_dm->cur_lps = lps_val;
1107 coex_dm->cur_rpwm = rpwm_val;
1108
1109 if (!force_exec) {
1110 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1111 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1112 return;
1113 }
1114 halbtc8821a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1115
1116 coex_dm->pre_lps = coex_dm->cur_lps;
1117 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1118 }
1119
halbtc8821a2ant_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable)1120 void halbtc8821a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1121 IN boolean force_exec, IN boolean enable)
1122 {
1123 coex_dm->cur_ignore_wlan_act = enable;
1124
1125 if (!force_exec) {
1126 if (coex_dm->pre_ignore_wlan_act ==
1127 coex_dm->cur_ignore_wlan_act)
1128 return;
1129 }
1130 halbtc8821a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1131
1132 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1133 }
1134
halbtc8821a2ant_set_fw_pstdma(IN struct btc_coexist * btcoexist,IN u8 byte1,IN u8 byte2,IN u8 byte3,IN u8 byte4,IN u8 byte5)1135 void halbtc8821a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1136 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1137 {
1138 u8 h2c_parameter[5] = {0};
1139
1140 h2c_parameter[0] = byte1;
1141 h2c_parameter[1] = byte2;
1142 h2c_parameter[2] = byte3;
1143 h2c_parameter[3] = byte4;
1144 h2c_parameter[4] = byte5;
1145
1146 coex_dm->ps_tdma_para[0] = byte1;
1147 coex_dm->ps_tdma_para[1] = byte2;
1148 coex_dm->ps_tdma_para[2] = byte3;
1149 coex_dm->ps_tdma_para[3] = byte4;
1150 coex_dm->ps_tdma_para[4] = byte5;
1151
1152 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1153 }
1154
halbtc8821a2ant_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)1155 void halbtc8821a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist,
1156 IN boolean shrink_rx_lpf, IN boolean low_penalty_ra,
1157 IN boolean limited_dig, IN boolean bt_lna_constrain)
1158 {
1159 /*
1160 u32 wifi_bw;
1161
1162 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
1163
1164 if(BTC_WIFI_BW_HT40 != wifi_bw)
1165 {
1166 if (shrink_rx_lpf)
1167 shrink_rx_lpf = false;
1168 }
1169 */
1170
1171 /* halbtc8821a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf); */
1172 halbtc8821a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
1173 }
1174
halbtc8821a2ant_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)1175 void halbtc8821a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist,
1176 IN boolean agc_table_shift, IN boolean adc_back_off,
1177 IN boolean sw_dac_swing, IN u32 dac_swing_lvl)
1178 {
1179 /* halbtc8821a2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */
1180 /* halbtc8821a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off); */
1181 halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1182 dac_swing_lvl);
1183 }
1184
halbtc8821a2ant_set_ant_path(IN struct btc_coexist * btcoexist,IN u8 ant_pos_type,IN boolean init_hwcfg,IN boolean wifi_off)1185 void halbtc8821a2ant_set_ant_path(IN struct btc_coexist *btcoexist,
1186 IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
1187 {
1188 struct btc_board_info *board_info = &btcoexist->board_info;
1189 u32 u32tmp = 0;
1190 u8 h2c_parameter[2] = {0};
1191
1192 if (init_hwcfg) {
1193 /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
1194 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1195 u32tmp &= ~BIT(23);
1196 u32tmp |= BIT(24);
1197 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
1198
1199 btcoexist->btc_write_4byte(btcoexist, 0x974, 0x3ff);
1200 /* btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); */
1201
1202 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
1203 /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
1204 h2c_parameter[0] = 1;
1205 h2c_parameter[1] = 1;
1206 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1207 h2c_parameter);
1208 } else {
1209 /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
1210 h2c_parameter[0] = 0;
1211 h2c_parameter[1] = 1;
1212 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1213 h2c_parameter);
1214 }
1215 }
1216
1217 /* ext switch setting */
1218 switch (ant_pos_type) {
1219 case BTC_ANT_WIFI_AT_MAIN:
1220 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
1221 0x30, 0x1);
1222 break;
1223 case BTC_ANT_WIFI_AT_AUX:
1224 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
1225 0x30, 0x2);
1226 break;
1227 }
1228 }
1229
halbtc8821a2ant_ps_tdma(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean turn_on,IN u8 type)1230 void halbtc8821a2ant_ps_tdma(IN struct btc_coexist *btcoexist,
1231 IN boolean force_exec, IN boolean turn_on, IN u8 type)
1232 {
1233 u8 wifi_rssi_state1, bt_rssi_state;
1234
1235
1236 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1237 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1238 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
1239 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1240
1241 if (!(BTC_RSSI_HIGH(wifi_rssi_state1) &&
1242 BTC_RSSI_HIGH(bt_rssi_state)) && turn_on) {
1243 type = type + 100; /* for WiFi RSSI low or BT RSSI low */
1244 }
1245
1246 coex_dm->cur_ps_tdma_on = turn_on;
1247 coex_dm->cur_ps_tdma = type;
1248
1249 if (!force_exec) {
1250 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1251 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1252 return;
1253 }
1254 if (turn_on) {
1255 switch (type) {
1256 case 1:
1257 default:
1258 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */
1259 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1260 0x3c, 0x03, 0xf1, 0x90);
1261 break;
1262 case 2:
1263 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); */
1264 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1265 0x2d, 0x03, 0xf1, 0x90);
1266 break;
1267 case 3:
1268 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1269 0x1c, 0x3, 0xf1, 0x90);
1270 break;
1271 case 4:
1272 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1273 0x10, 0x03, 0xf1, 0x90);
1274 break;
1275 case 5:
1276 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); */
1277 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1278 0x3c, 0x3, 0x70, 0x90);
1279 break;
1280 case 6:
1281 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); */
1282 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1283 0x2d, 0x3, 0x70, 0x90);
1284 break;
1285 case 7:
1286 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1287 0x1c, 0x3, 0x70, 0x90);
1288 break;
1289 case 8:
1290 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3,
1291 0x10, 0x3, 0x70, 0x90);
1292 break;
1293 case 9:
1294 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */
1295 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1296 0x3c, 0x03, 0xf1, 0x90);
1297 break;
1298 case 10:
1299 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); */
1300 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1301 0x2d, 0x03, 0xf1, 0x90);
1302 break;
1303 case 11:
1304 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90); */
1305 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1306 0x1c, 0x3, 0xf1, 0x90);
1307 break;
1308 case 12:
1309 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90); */
1310 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1311 0x10, 0x3, 0xf1, 0x90);
1312 break;
1313 case 13:
1314 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); */
1315 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1316 0x3c, 0x3, 0x70, 0x90);
1317 break;
1318 case 14:
1319 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); */
1320 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1321 0x2d, 0x3, 0x70, 0x90);
1322 break;
1323 case 15:
1324 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa, 0xa, 0x60, 0x90); */
1325 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1326 0x1c, 0x3, 0x70, 0x90);
1327 break;
1328 case 16:
1329 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, 0x60, 0x90); */
1330 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1331 0x10, 0x3, 0x70, 0x90);
1332 break;
1333 case 17:
1334 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3,
1335 0x2f, 0x2f, 0x60, 0x90);
1336 break;
1337 case 18:
1338 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1339 0x5, 0x5, 0xe1, 0x90);
1340 break;
1341 case 19:
1342 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1343 0x25, 0x25, 0xe1, 0x90);
1344 break;
1345 case 20:
1346 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1347 0x25, 0x25, 0x60, 0x90);
1348 break;
1349 case 21:
1350 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1351 0x15, 0x03, 0x70, 0x90);
1352 break;
1353 case 23:
1354 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1355 0x1e, 0x03, 0xf0, 0x14);
1356 break;
1357 case 24:
1358 case 124:
1359 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1360 0x3c, 0x03, 0x70, 0x50);
1361 break;
1362 /* case25/case125 : for lenovo bt pan tp degrade<30% while wifi downlink */
1363 case 25:
1364 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1365 0x14, 0x03, 0xf1, 0x90);
1366 break;
1367 case 26:
1368 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1369 0x30, 0x03, 0xf1, 0x90);
1370 break;
1371 case 71:
1372 /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */
1373
1374 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1375 0x3c, 0x03, 0xf1, 0x90);
1376 break;
1377 case 101:
1378 case 105:
1379 case 171:
1380 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1381 0x3a, 0x03, 0x70, 0x50);
1382 break;
1383 case 102:
1384 case 106:
1385 case 110:
1386 case 114:
1387 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1388 0x2d, 0x03, 0x70, 0x50);
1389 break;
1390 case 103:
1391 case 107:
1392 case 111:
1393 case 115:
1394 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1395 0x1c, 0x03, 0x70, 0x50);
1396 break;
1397 case 104:
1398 case 108:
1399 case 112:
1400 case 116:
1401 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1402 0x10, 0x03, 0x70, 0x50);
1403 break;
1404 case 109:
1405 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1406 0x3c, 0x03, 0xf1, 0x90);
1407 break;
1408 case 113:
1409 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1410 0x3c, 0x03, 0x70, 0x90);
1411 break;
1412 case 121:
1413 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1414 0x15, 0x03, 0x70, 0x90);
1415 break;
1416 case 22:
1417 case 122:
1418 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
1419 0x35, 0x03, 0x71, 0x11);
1420 break;
1421 case 123:
1422 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1423 0x1c, 0x03, 0x70, 0x54);
1424 break;
1425 /* case25/case125 : for lenovo bt pan tp degrade<30% while wifi downlink */
1426 case 125:
1427 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1428 0x14, 0x03, 0x70, 0x50);
1429 break;
1430 case 126:
1431 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
1432 0x30, 0x03, 0x70, 0x50);
1433 break;
1434 }
1435 } else {
1436 /* disable PS tdma */
1437 switch (type) {
1438 case 0:
1439 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0,
1440 0x0, 0x0, 0x40, 0x0);
1441 break;
1442 case 1:
1443 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0,
1444 0x0, 0x0, 0x48, 0x0);
1445 break;
1446 default:
1447 halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0,
1448 0x0, 0x0, 0x40, 0x0);
1449 break;
1450 }
1451 }
1452
1453 /* update pre state */
1454 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1455 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1456 }
1457
halbtc8821a2ant_ps_tdma_check_for_power_save_state(IN struct btc_coexist * btcoexist,IN boolean new_ps_state)1458 void halbtc8821a2ant_ps_tdma_check_for_power_save_state(
1459 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1460 {
1461 u8 lps_mode = 0x0;
1462
1463 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1464
1465 if (lps_mode) { /* already under LPS state */
1466 if (new_ps_state) {
1467 /* keep state under LPS, do nothing. */
1468 } else {
1469 /* will leave LPS state, turn off psTdma first */
1470 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1471 1);
1472 }
1473 } else { /* NO PS state */
1474 if (new_ps_state) {
1475 /* will enter LPS state, turn off psTdma first */
1476 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1477 1);
1478 } else {
1479 /* keep state under NO PS state, do nothing. */
1480 }
1481 }
1482 }
1483
halbtc8821a2ant_power_save_state(IN struct btc_coexist * btcoexist,IN u8 ps_type,IN u8 lps_val,IN u8 rpwm_val)1484 void halbtc8821a2ant_power_save_state(IN struct btc_coexist *btcoexist,
1485 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1486 {
1487 boolean low_pwr_disable = false;
1488
1489 switch (ps_type) {
1490 case BTC_PS_WIFI_NATIVE:
1491 /* recover to original 32k low power setting */
1492 low_pwr_disable = false;
1493 btcoexist->btc_set(btcoexist,
1494 BTC_SET_ACT_DISABLE_LOW_POWER,
1495 &low_pwr_disable);
1496 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1497 NULL);
1498 coex_sta->force_lps_on = false;
1499 break;
1500 case BTC_PS_LPS_ON:
1501 halbtc8821a2ant_ps_tdma_check_for_power_save_state(
1502 btcoexist, true);
1503 halbtc8821a2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1504 lps_val, rpwm_val);
1505 /* when coex force to enter LPS, do not enter 32k low power. */
1506 low_pwr_disable = true;
1507 btcoexist->btc_set(btcoexist,
1508 BTC_SET_ACT_DISABLE_LOW_POWER,
1509 &low_pwr_disable);
1510 /* power save must executed before psTdma. */
1511 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1512 NULL);
1513 coex_sta->force_lps_on = true;
1514 break;
1515 case BTC_PS_LPS_OFF:
1516 halbtc8821a2ant_ps_tdma_check_for_power_save_state(
1517 btcoexist, false);
1518 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1519 NULL);
1520 coex_sta->force_lps_on = false;
1521 break;
1522 default:
1523 break;
1524 }
1525 }
1526
1527
halbtc8821a2ant_coex_all_off(IN struct btc_coexist * btcoexist)1528 void halbtc8821a2ant_coex_all_off(IN struct btc_coexist *btcoexist)
1529 {
1530 /* fw all off */
1531 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1532 0x0);
1533 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1534 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1535 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1536
1537 /* sw all off */
1538 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1539 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1540
1541 /* hw all off */
1542 /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
1543 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1544 }
1545
halbtc8821a2ant_coex_under_5g(IN struct btc_coexist * btcoexist)1546 void halbtc8821a2ant_coex_under_5g(IN struct btc_coexist *btcoexist)
1547 {
1548 halbtc8821a2ant_coex_all_off(btcoexist);
1549
1550 halbtc8821a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
1551 }
1552
halbtc8821a2ant_init_coex_dm(IN struct btc_coexist * btcoexist)1553 void halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
1554 {
1555 /* force to reset coex mechanism */
1556 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1557
1558 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1559 0x0);
1560 halbtc8821a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1561 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1562 halbtc8821a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0);
1563
1564 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1565 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1566 }
1567
halbtc8821a2ant_action_bt_inquiry(IN struct btc_coexist * btcoexist)1568 void halbtc8821a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1569 {
1570 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
1571 boolean wifi_connected = false;
1572 boolean low_pwr_disable = true;
1573 boolean scan = false, link = false, roam = false;
1574
1575
1576 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
1577 0);
1578 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1579 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1580 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
1581 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1582
1583 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1584 &low_pwr_disable);
1585 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1586 &wifi_connected);
1587
1588 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1589 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1590 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1591
1592
1593 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1594 0x0);
1595
1596 if (scan || link || roam) {
1597 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1598 "[BTCoex], Wifi link process + BT Inq/Page!!\n");
1599 BTC_TRACE(trace_buf);
1600 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
1601 15);
1602 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1603 } else if (wifi_connected) {
1604 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1605 "[BTCoex], Wifi connected + BT Inq/Page!!\n");
1606 BTC_TRACE(trace_buf);
1607 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
1608 15);
1609 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1610 } else {
1611 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1612 "[BTCoex], Wifi no-link + BT Inq/Page!!\n");
1613 BTC_TRACE(trace_buf);
1614 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1615 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1616 }
1617
1618 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1619 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1620
1621 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1622 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1623
1624 }
1625
1626
halbtc8821a2ant_action_wifi_link_process(IN struct btc_coexist * btcoexist)1627 void halbtc8821a2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist)
1628 {
1629 u8 u8tmpa, u8tmpb;
1630
1631 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1632 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1633
1634 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1635 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1636
1637
1638
1639 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
1640 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
1641
1642 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1643 "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa,
1644 u8tmpb);
1645 BTC_TRACE(trace_buf);
1646 }
1647
halbtc8821a2ant_action_wifi_idle_process(IN struct btc_coexist * btcoexist)1648 boolean halbtc8821a2ant_action_wifi_idle_process(IN struct btc_coexist
1649 *btcoexist)
1650 {
1651 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
1652 u8 ap_num = 0;
1653
1654 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
1655 0);
1656 /* wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); */
1657 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1658 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 20, 0);
1659 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
1660 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1661
1662 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
1663
1664 /* define the office environment */
1665 if (BTC_RSSI_HIGH(wifi_rssi_state1) &&
1666 (coex_sta->hid_exist == true) &&
1667 (coex_sta->a2dp_exist == true)) {
1668
1669 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1670 "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n");
1671 BTC_TRACE(trace_buf);
1672
1673 halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
1674 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1675
1676 /* sw all off */
1677 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1678 false);
1679 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1680 0x18);
1681
1682 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1683
1684 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1685 0x0, 0x0);
1686 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1687
1688 return true;
1689 }
1690
1691 /* */
1692 else if (coex_sta->pan_exist == true) {
1693
1694 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1695 "[BTCoex], Wifi idle process for BT PAN exist!!\n");
1696 BTC_TRACE(trace_buf);
1697
1698 halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
1699 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1700
1701 /* sw all off */
1702 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1703 false);
1704 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1705 0x18);
1706
1707 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1708
1709 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1710 0x0, 0x0);
1711 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1712
1713 return true;
1714 }
1715
1716 else {
1717 halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18);
1718 return false;
1719 }
1720
1721
1722 }
1723
1724
1725
halbtc8821a2ant_is_common_action(IN struct btc_coexist * btcoexist)1726 boolean halbtc8821a2ant_is_common_action(IN struct btc_coexist *btcoexist)
1727 {
1728 boolean common = false, wifi_connected = false, wifi_busy = false;
1729 boolean bt_hs_on = false, low_pwr_disable = false;
1730
1731 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1732 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1733 &wifi_connected);
1734 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1735
1736 if (!wifi_connected) {
1737 low_pwr_disable = false;
1738 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1739 &low_pwr_disable);
1740 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
1741 0x8);
1742
1743 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1744 "[BTCoex], Wifi non-connected idle!!\n");
1745 BTC_TRACE(trace_buf);
1746
1747 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
1748 0x0);
1749 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1750
1751 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1752 0x0, 0x0);
1753 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1754 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1755 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1756
1757 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1758 false);
1759 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1760 0x18);
1761
1762 common = true;
1763 } else {
1764 if (BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1765 coex_dm->bt_status) {
1766 low_pwr_disable = false;
1767 btcoexist->btc_set(btcoexist,
1768 BTC_SET_ACT_DISABLE_LOW_POWER,
1769 &low_pwr_disable);
1770 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1771 false, false, 0x8);
1772
1773 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1774 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1775 BTC_TRACE(trace_buf);
1776
1777 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1778 0xfffff, 0x0);
1779 halbtc8821a2ant_coex_table_with_type(btcoexist,
1780 NORMAL_EXEC, 0);
1781
1782 halbtc8821a2ant_power_save_state(btcoexist,
1783 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1784 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1785 1);
1786 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1787 0xb);
1788 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1789
1790 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1791 false);
1792 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
1793 false, 0x18);
1794
1795 common = true;
1796 } else if (BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE ==
1797 coex_dm->bt_status) {
1798 low_pwr_disable = true;
1799 btcoexist->btc_set(btcoexist,
1800 BTC_SET_ACT_DISABLE_LOW_POWER,
1801 &low_pwr_disable);
1802
1803 if (bt_hs_on)
1804 return false;
1805 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1806 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1807 BTC_TRACE(trace_buf);
1808 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1809 false, false, 0x8);
1810
1811 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1812 0xfffff, 0x0);
1813 halbtc8821a2ant_coex_table_with_type(btcoexist,
1814 NORMAL_EXEC, 0);
1815
1816 halbtc8821a2ant_power_save_state(btcoexist,
1817 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1818 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1819 1);
1820 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1821 0xb);
1822 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1823
1824 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
1825 false, false);
1826 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
1827 false, 0x18);
1828
1829 common = true;
1830 } else {
1831 low_pwr_disable = true;
1832 btcoexist->btc_set(btcoexist,
1833 BTC_SET_ACT_DISABLE_LOW_POWER,
1834 &low_pwr_disable);
1835
1836 if (wifi_busy) {
1837 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1838 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1839 BTC_TRACE(trace_buf);
1840 common = false;
1841 /* common = halbtc8821a2ant_action_wifi_idle_process(btcoexist); */
1842 } else {
1843 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1844 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1845 BTC_TRACE(trace_buf);
1846 /* common = false; */
1847 common = halbtc8821a2ant_action_wifi_idle_process(
1848 btcoexist);
1849 }
1850 }
1851 }
1852
1853 return common;
1854 }
halbtc8821a2ant_tdma_duration_adjust(IN struct btc_coexist * btcoexist,IN boolean sco_hid,IN boolean tx_pause,IN u8 max_interval)1855 void halbtc8821a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist,
1856 IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval)
1857 {
1858 static s32 up, dn, m, n, wait_count;
1859 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1860 u8 retry_count = 0;
1861
1862 if (!coex_dm->auto_tdma_adjust) {
1863 coex_dm->auto_tdma_adjust = true;
1864 {
1865 if (sco_hid) {
1866 if (tx_pause) {
1867 if (max_interval == 1) {
1868 halbtc8821a2ant_ps_tdma(
1869 btcoexist, NORMAL_EXEC,
1870 true, 13);
1871 coex_dm->ps_tdma_du_adj_type =
1872 13;
1873 } else if (max_interval == 2) {
1874 halbtc8821a2ant_ps_tdma(
1875 btcoexist, NORMAL_EXEC,
1876 true, 14);
1877 coex_dm->ps_tdma_du_adj_type =
1878 14;
1879 } else if (max_interval == 3) {
1880 halbtc8821a2ant_ps_tdma(
1881 btcoexist, NORMAL_EXEC,
1882 true, 15);
1883 coex_dm->ps_tdma_du_adj_type =
1884 15;
1885 } else {
1886 halbtc8821a2ant_ps_tdma(
1887 btcoexist, NORMAL_EXEC,
1888 true, 15);
1889 coex_dm->ps_tdma_du_adj_type =
1890 15;
1891 }
1892 } else {
1893 if (max_interval == 1) {
1894 halbtc8821a2ant_ps_tdma(
1895 btcoexist, NORMAL_EXEC,
1896 true, 9);
1897 coex_dm->ps_tdma_du_adj_type =
1898 9;
1899 } else if (max_interval == 2) {
1900 halbtc8821a2ant_ps_tdma(
1901 btcoexist, NORMAL_EXEC,
1902 true, 10);
1903 coex_dm->ps_tdma_du_adj_type =
1904 10;
1905 } else if (max_interval == 3) {
1906 halbtc8821a2ant_ps_tdma(
1907 btcoexist, NORMAL_EXEC,
1908 true, 11);
1909 coex_dm->ps_tdma_du_adj_type =
1910 11;
1911 } else {
1912 halbtc8821a2ant_ps_tdma(
1913 btcoexist, NORMAL_EXEC,
1914 true, 11);
1915 coex_dm->ps_tdma_du_adj_type =
1916 11;
1917 }
1918 }
1919 } else {
1920 if (tx_pause) {
1921 if (max_interval == 1) {
1922 halbtc8821a2ant_ps_tdma(
1923 btcoexist, NORMAL_EXEC,
1924 true, 5);
1925 coex_dm->ps_tdma_du_adj_type =
1926 5;
1927 } else if (max_interval == 2) {
1928 halbtc8821a2ant_ps_tdma(
1929 btcoexist, NORMAL_EXEC,
1930 true, 6);
1931 coex_dm->ps_tdma_du_adj_type =
1932 6;
1933 } else if (max_interval == 3) {
1934 halbtc8821a2ant_ps_tdma(
1935 btcoexist, NORMAL_EXEC,
1936 true, 7);
1937 coex_dm->ps_tdma_du_adj_type =
1938 7;
1939 } else {
1940 halbtc8821a2ant_ps_tdma(
1941 btcoexist, NORMAL_EXEC,
1942 true, 7);
1943 coex_dm->ps_tdma_du_adj_type =
1944 7;
1945 }
1946 } else {
1947 if (max_interval == 1) {
1948 halbtc8821a2ant_ps_tdma(
1949 btcoexist, NORMAL_EXEC,
1950 true, 1);
1951 coex_dm->ps_tdma_du_adj_type =
1952 1;
1953 } else if (max_interval == 2) {
1954 halbtc8821a2ant_ps_tdma(
1955 btcoexist, NORMAL_EXEC,
1956 true, 2);
1957 coex_dm->ps_tdma_du_adj_type =
1958 2;
1959 } else if (max_interval == 3) {
1960 halbtc8821a2ant_ps_tdma(
1961 btcoexist, NORMAL_EXEC,
1962 true, 3);
1963 coex_dm->ps_tdma_du_adj_type =
1964 3;
1965 } else {
1966 halbtc8821a2ant_ps_tdma(
1967 btcoexist, NORMAL_EXEC,
1968 true, 3);
1969 coex_dm->ps_tdma_du_adj_type =
1970 3;
1971 }
1972 }
1973 }
1974 }
1975 /* ============ */
1976 up = 0;
1977 dn = 0;
1978 m = 1;
1979 n = 3;
1980 result = 0;
1981 wait_count = 0;
1982 } else {
1983 /* accquire the BT TRx retry count from BT_Info byte2 */
1984 retry_count = coex_sta->bt_retry_cnt;
1985 result = 0;
1986 wait_count++;
1987
1988 if (retry_count ==
1989 0) { /* no retry in the last 2-second duration */
1990 up++;
1991 dn--;
1992
1993 if (dn <= 0)
1994 dn = 0;
1995
1996 if (up >= n) { /* if �s�� n ��2�� retry count��0, �h�ռeWiFi duration */
1997 wait_count = 0;
1998 n = 3;
1999 up = 0;
2000 dn = 0;
2001 result = 1;
2002 }
2003 } else if (retry_count <=
2004 3) { /* <=3 retry in the last 2-second duration */
2005 up--;
2006 dn++;
2007
2008 if (up <= 0)
2009 up = 0;
2010
2011 if (dn == 2) { /* if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration */
2012 if (wait_count <= 2)
2013 m++; /* �קK�@���b���level���Ӧ^ */
2014 else
2015 m = 1;
2016
2017 if (m >= 20) /* m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration. */
2018 m = 20;
2019
2020 n = 3 * m;
2021 up = 0;
2022 dn = 0;
2023 wait_count = 0;
2024 result = -1;
2025 }
2026 } else { /* retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration */
2027 if (wait_count == 1)
2028 m++; /* �קK�@���b���level���Ӧ^ */
2029 else
2030 m = 1;
2031
2032 if (m >= 20) /* m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration. */
2033 m = 20;
2034
2035 n = 3 * m;
2036 up = 0;
2037 dn = 0;
2038 wait_count = 0;
2039 result = -1;
2040 }
2041
2042 if (max_interval == 1) {
2043 if (tx_pause) {
2044 if (coex_dm->cur_ps_tdma == 71) {
2045 halbtc8821a2ant_ps_tdma(btcoexist,
2046 NORMAL_EXEC, true, 5);
2047 coex_dm->ps_tdma_du_adj_type = 5;
2048 } else if (coex_dm->cur_ps_tdma == 1) {
2049 halbtc8821a2ant_ps_tdma(btcoexist,
2050 NORMAL_EXEC, true, 5);
2051 coex_dm->ps_tdma_du_adj_type = 5;
2052 } else if (coex_dm->cur_ps_tdma == 2) {
2053 halbtc8821a2ant_ps_tdma(btcoexist,
2054 NORMAL_EXEC, true, 6);
2055 coex_dm->ps_tdma_du_adj_type = 6;
2056 } else if (coex_dm->cur_ps_tdma == 3) {
2057 halbtc8821a2ant_ps_tdma(btcoexist,
2058 NORMAL_EXEC, true, 7);
2059 coex_dm->ps_tdma_du_adj_type = 7;
2060 } else if (coex_dm->cur_ps_tdma == 4) {
2061 halbtc8821a2ant_ps_tdma(btcoexist,
2062 NORMAL_EXEC, true, 8);
2063 coex_dm->ps_tdma_du_adj_type = 8;
2064 }
2065 if (coex_dm->cur_ps_tdma == 9) {
2066 halbtc8821a2ant_ps_tdma(btcoexist,
2067 NORMAL_EXEC, true, 13);
2068 coex_dm->ps_tdma_du_adj_type = 13;
2069 } else if (coex_dm->cur_ps_tdma == 10) {
2070 halbtc8821a2ant_ps_tdma(btcoexist,
2071 NORMAL_EXEC, true, 14);
2072 coex_dm->ps_tdma_du_adj_type = 14;
2073 } else if (coex_dm->cur_ps_tdma == 11) {
2074 halbtc8821a2ant_ps_tdma(btcoexist,
2075 NORMAL_EXEC, true, 15);
2076 coex_dm->ps_tdma_du_adj_type = 15;
2077 } else if (coex_dm->cur_ps_tdma == 12) {
2078 halbtc8821a2ant_ps_tdma(btcoexist,
2079 NORMAL_EXEC, true, 16);
2080 coex_dm->ps_tdma_du_adj_type = 16;
2081 }
2082
2083 if (result == -1) {
2084 if (coex_dm->cur_ps_tdma == 5) {
2085 halbtc8821a2ant_ps_tdma(
2086 btcoexist, NORMAL_EXEC,
2087 true, 6);
2088 coex_dm->ps_tdma_du_adj_type =
2089 6;
2090 } else if (coex_dm->cur_ps_tdma == 6) {
2091 halbtc8821a2ant_ps_tdma(
2092 btcoexist, NORMAL_EXEC,
2093 true, 7);
2094 coex_dm->ps_tdma_du_adj_type =
2095 7;
2096 } else if (coex_dm->cur_ps_tdma == 7) {
2097 halbtc8821a2ant_ps_tdma(
2098 btcoexist, NORMAL_EXEC,
2099 true, 8);
2100 coex_dm->ps_tdma_du_adj_type =
2101 8;
2102 } else if (coex_dm->cur_ps_tdma == 13) {
2103 halbtc8821a2ant_ps_tdma(
2104 btcoexist, NORMAL_EXEC,
2105 true, 14);
2106 coex_dm->ps_tdma_du_adj_type =
2107 14;
2108 } else if (coex_dm->cur_ps_tdma == 14) {
2109 halbtc8821a2ant_ps_tdma(
2110 btcoexist, NORMAL_EXEC,
2111 true, 15);
2112 coex_dm->ps_tdma_du_adj_type =
2113 15;
2114 } else if (coex_dm->cur_ps_tdma == 15) {
2115 halbtc8821a2ant_ps_tdma(
2116 btcoexist, NORMAL_EXEC,
2117 true, 16);
2118 coex_dm->ps_tdma_du_adj_type =
2119 16;
2120 }
2121 } else if (result == 1) {
2122 if (coex_dm->cur_ps_tdma == 8) {
2123 halbtc8821a2ant_ps_tdma(
2124 btcoexist, NORMAL_EXEC,
2125 true, 7);
2126 coex_dm->ps_tdma_du_adj_type =
2127 7;
2128 } else if (coex_dm->cur_ps_tdma == 7) {
2129 halbtc8821a2ant_ps_tdma(
2130 btcoexist, NORMAL_EXEC,
2131 true, 6);
2132 coex_dm->ps_tdma_du_adj_type =
2133 6;
2134 } else if (coex_dm->cur_ps_tdma == 6) {
2135 halbtc8821a2ant_ps_tdma(
2136 btcoexist, NORMAL_EXEC,
2137 true, 5);
2138 coex_dm->ps_tdma_du_adj_type =
2139 5;
2140 } else if (coex_dm->cur_ps_tdma == 16) {
2141 halbtc8821a2ant_ps_tdma(
2142 btcoexist, NORMAL_EXEC,
2143 true, 15);
2144 coex_dm->ps_tdma_du_adj_type =
2145 15;
2146 } else if (coex_dm->cur_ps_tdma == 15) {
2147 halbtc8821a2ant_ps_tdma(
2148 btcoexist, NORMAL_EXEC,
2149 true, 14);
2150 coex_dm->ps_tdma_du_adj_type =
2151 14;
2152 } else if (coex_dm->cur_ps_tdma == 14) {
2153 halbtc8821a2ant_ps_tdma(
2154 btcoexist, NORMAL_EXEC,
2155 true, 13);
2156 coex_dm->ps_tdma_du_adj_type =
2157 13;
2158 }
2159 }
2160 } else {
2161 if (coex_dm->cur_ps_tdma == 5) {
2162 halbtc8821a2ant_ps_tdma(btcoexist,
2163 NORMAL_EXEC, true, 71);
2164 coex_dm->ps_tdma_du_adj_type = 71;
2165 } else if (coex_dm->cur_ps_tdma == 6) {
2166 halbtc8821a2ant_ps_tdma(btcoexist,
2167 NORMAL_EXEC, true, 2);
2168 coex_dm->ps_tdma_du_adj_type = 2;
2169 } else if (coex_dm->cur_ps_tdma == 7) {
2170 halbtc8821a2ant_ps_tdma(btcoexist,
2171 NORMAL_EXEC, true, 3);
2172 coex_dm->ps_tdma_du_adj_type = 3;
2173 } else if (coex_dm->cur_ps_tdma == 8) {
2174 halbtc8821a2ant_ps_tdma(btcoexist,
2175 NORMAL_EXEC, true, 4);
2176 coex_dm->ps_tdma_du_adj_type = 4;
2177 }
2178 if (coex_dm->cur_ps_tdma == 13) {
2179 halbtc8821a2ant_ps_tdma(btcoexist,
2180 NORMAL_EXEC, true, 9);
2181 coex_dm->ps_tdma_du_adj_type = 9;
2182 } else if (coex_dm->cur_ps_tdma == 14) {
2183 halbtc8821a2ant_ps_tdma(btcoexist,
2184 NORMAL_EXEC, true, 10);
2185 coex_dm->ps_tdma_du_adj_type = 10;
2186 } else if (coex_dm->cur_ps_tdma == 15) {
2187 halbtc8821a2ant_ps_tdma(btcoexist,
2188 NORMAL_EXEC, true, 11);
2189 coex_dm->ps_tdma_du_adj_type = 11;
2190 } else if (coex_dm->cur_ps_tdma == 16) {
2191 halbtc8821a2ant_ps_tdma(btcoexist,
2192 NORMAL_EXEC, true, 12);
2193 coex_dm->ps_tdma_du_adj_type = 12;
2194 }
2195
2196 if (result == -1) {
2197 if (coex_dm->cur_ps_tdma == 71) {
2198 halbtc8821a2ant_ps_tdma(
2199 btcoexist, NORMAL_EXEC,
2200 true, 1);
2201 coex_dm->ps_tdma_du_adj_type =
2202 1;
2203 } else if (coex_dm->cur_ps_tdma == 1) {
2204 halbtc8821a2ant_ps_tdma(
2205 btcoexist, NORMAL_EXEC,
2206 true, 2);
2207 coex_dm->ps_tdma_du_adj_type =
2208 2;
2209 } else if (coex_dm->cur_ps_tdma == 2) {
2210 halbtc8821a2ant_ps_tdma(
2211 btcoexist, NORMAL_EXEC,
2212 true, 3);
2213 coex_dm->ps_tdma_du_adj_type =
2214 3;
2215 } else if (coex_dm->cur_ps_tdma == 3) {
2216 halbtc8821a2ant_ps_tdma(
2217 btcoexist, NORMAL_EXEC,
2218 true, 4);
2219 coex_dm->ps_tdma_du_adj_type =
2220 4;
2221 } else if (coex_dm->cur_ps_tdma == 9) {
2222 halbtc8821a2ant_ps_tdma(
2223 btcoexist, NORMAL_EXEC,
2224 true, 10);
2225 coex_dm->ps_tdma_du_adj_type =
2226 10;
2227 } else if (coex_dm->cur_ps_tdma == 10) {
2228 halbtc8821a2ant_ps_tdma(
2229 btcoexist, NORMAL_EXEC,
2230 true, 11);
2231 coex_dm->ps_tdma_du_adj_type =
2232 11;
2233 } else if (coex_dm->cur_ps_tdma == 11) {
2234 halbtc8821a2ant_ps_tdma(
2235 btcoexist, NORMAL_EXEC,
2236 true, 12);
2237 coex_dm->ps_tdma_du_adj_type =
2238 12;
2239 }
2240 } else if (result == 1) {
2241 if (coex_dm->cur_ps_tdma == 4) {
2242 halbtc8821a2ant_ps_tdma(
2243 btcoexist, NORMAL_EXEC,
2244 true, 3);
2245 coex_dm->ps_tdma_du_adj_type =
2246 3;
2247 } else if (coex_dm->cur_ps_tdma == 3) {
2248 halbtc8821a2ant_ps_tdma(
2249 btcoexist, NORMAL_EXEC,
2250 true, 2);
2251 coex_dm->ps_tdma_du_adj_type =
2252 2;
2253 } else if (coex_dm->cur_ps_tdma == 2) {
2254 halbtc8821a2ant_ps_tdma(
2255 btcoexist, NORMAL_EXEC,
2256 true, 1);
2257 coex_dm->ps_tdma_du_adj_type =
2258 1;
2259 } else if (coex_dm->cur_ps_tdma == 1) {
2260 halbtc8821a2ant_ps_tdma(
2261 btcoexist, NORMAL_EXEC,
2262 true, 71);
2263 coex_dm->ps_tdma_du_adj_type =
2264 71;
2265 } else if (coex_dm->cur_ps_tdma == 12) {
2266 halbtc8821a2ant_ps_tdma(
2267 btcoexist, NORMAL_EXEC,
2268 true, 11);
2269 coex_dm->ps_tdma_du_adj_type =
2270 11;
2271 } else if (coex_dm->cur_ps_tdma == 11) {
2272 halbtc8821a2ant_ps_tdma(
2273 btcoexist, NORMAL_EXEC,
2274 true, 10);
2275 coex_dm->ps_tdma_du_adj_type =
2276 10;
2277 } else if (coex_dm->cur_ps_tdma == 10) {
2278 halbtc8821a2ant_ps_tdma(
2279 btcoexist, NORMAL_EXEC,
2280 true, 9);
2281 coex_dm->ps_tdma_du_adj_type =
2282 9;
2283 }
2284 }
2285 }
2286 } else if (max_interval == 2) {
2287 if (tx_pause) {
2288 if (coex_dm->cur_ps_tdma == 1) {
2289 halbtc8821a2ant_ps_tdma(btcoexist,
2290 NORMAL_EXEC, true, 6);
2291 coex_dm->ps_tdma_du_adj_type = 6;
2292 } else if (coex_dm->cur_ps_tdma == 2) {
2293 halbtc8821a2ant_ps_tdma(btcoexist,
2294 NORMAL_EXEC, true, 6);
2295 coex_dm->ps_tdma_du_adj_type = 6;
2296 } else if (coex_dm->cur_ps_tdma == 3) {
2297 halbtc8821a2ant_ps_tdma(btcoexist,
2298 NORMAL_EXEC, true, 7);
2299 coex_dm->ps_tdma_du_adj_type = 7;
2300 } else if (coex_dm->cur_ps_tdma == 4) {
2301 halbtc8821a2ant_ps_tdma(btcoexist,
2302 NORMAL_EXEC, true, 8);
2303 coex_dm->ps_tdma_du_adj_type = 8;
2304 }
2305 if (coex_dm->cur_ps_tdma == 9) {
2306 halbtc8821a2ant_ps_tdma(btcoexist,
2307 NORMAL_EXEC, true, 14);
2308 coex_dm->ps_tdma_du_adj_type = 14;
2309 } else if (coex_dm->cur_ps_tdma == 10) {
2310 halbtc8821a2ant_ps_tdma(btcoexist,
2311 NORMAL_EXEC, true, 14);
2312 coex_dm->ps_tdma_du_adj_type = 14;
2313 } else if (coex_dm->cur_ps_tdma == 11) {
2314 halbtc8821a2ant_ps_tdma(btcoexist,
2315 NORMAL_EXEC, true, 15);
2316 coex_dm->ps_tdma_du_adj_type = 15;
2317 } else if (coex_dm->cur_ps_tdma == 12) {
2318 halbtc8821a2ant_ps_tdma(btcoexist,
2319 NORMAL_EXEC, true, 16);
2320 coex_dm->ps_tdma_du_adj_type = 16;
2321 }
2322 if (result == -1) {
2323 if (coex_dm->cur_ps_tdma == 5) {
2324 halbtc8821a2ant_ps_tdma(
2325 btcoexist, NORMAL_EXEC,
2326 true, 6);
2327 coex_dm->ps_tdma_du_adj_type =
2328 6;
2329 } else if (coex_dm->cur_ps_tdma == 6) {
2330 halbtc8821a2ant_ps_tdma(
2331 btcoexist, NORMAL_EXEC,
2332 true, 7);
2333 coex_dm->ps_tdma_du_adj_type =
2334 7;
2335 } else if (coex_dm->cur_ps_tdma == 7) {
2336 halbtc8821a2ant_ps_tdma(
2337 btcoexist, NORMAL_EXEC,
2338 true, 8);
2339 coex_dm->ps_tdma_du_adj_type =
2340 8;
2341 } else if (coex_dm->cur_ps_tdma == 13) {
2342 halbtc8821a2ant_ps_tdma(
2343 btcoexist, NORMAL_EXEC,
2344 true, 14);
2345 coex_dm->ps_tdma_du_adj_type =
2346 14;
2347 } else if (coex_dm->cur_ps_tdma == 14) {
2348 halbtc8821a2ant_ps_tdma(
2349 btcoexist, NORMAL_EXEC,
2350 true, 15);
2351 coex_dm->ps_tdma_du_adj_type =
2352 15;
2353 } else if (coex_dm->cur_ps_tdma == 15) {
2354 halbtc8821a2ant_ps_tdma(
2355 btcoexist, NORMAL_EXEC,
2356 true, 16);
2357 coex_dm->ps_tdma_du_adj_type =
2358 16;
2359 }
2360 } else if (result == 1) {
2361 if (coex_dm->cur_ps_tdma == 8) {
2362 halbtc8821a2ant_ps_tdma(
2363 btcoexist, NORMAL_EXEC,
2364 true, 7);
2365 coex_dm->ps_tdma_du_adj_type =
2366 7;
2367 } else if (coex_dm->cur_ps_tdma == 7) {
2368 halbtc8821a2ant_ps_tdma(
2369 btcoexist, NORMAL_EXEC,
2370 true, 6);
2371 coex_dm->ps_tdma_du_adj_type =
2372 6;
2373 } else if (coex_dm->cur_ps_tdma == 6) {
2374 halbtc8821a2ant_ps_tdma(
2375 btcoexist, NORMAL_EXEC,
2376 true, 6);
2377 coex_dm->ps_tdma_du_adj_type =
2378 6;
2379 } else if (coex_dm->cur_ps_tdma == 16) {
2380 halbtc8821a2ant_ps_tdma(
2381 btcoexist, NORMAL_EXEC,
2382 true, 15);
2383 coex_dm->ps_tdma_du_adj_type =
2384 15;
2385 } else if (coex_dm->cur_ps_tdma == 15) {
2386 halbtc8821a2ant_ps_tdma(
2387 btcoexist, NORMAL_EXEC,
2388 true, 14);
2389 coex_dm->ps_tdma_du_adj_type =
2390 14;
2391 } else if (coex_dm->cur_ps_tdma == 14) {
2392 halbtc8821a2ant_ps_tdma(
2393 btcoexist, NORMAL_EXEC,
2394 true, 14);
2395 coex_dm->ps_tdma_du_adj_type =
2396 14;
2397 }
2398 }
2399 } else {
2400 if (coex_dm->cur_ps_tdma == 5) {
2401 halbtc8821a2ant_ps_tdma(btcoexist,
2402 NORMAL_EXEC, true, 2);
2403 coex_dm->ps_tdma_du_adj_type = 2;
2404 } else if (coex_dm->cur_ps_tdma == 6) {
2405 halbtc8821a2ant_ps_tdma(btcoexist,
2406 NORMAL_EXEC, true, 2);
2407 coex_dm->ps_tdma_du_adj_type = 2;
2408 } else if (coex_dm->cur_ps_tdma == 7) {
2409 halbtc8821a2ant_ps_tdma(btcoexist,
2410 NORMAL_EXEC, true, 3);
2411 coex_dm->ps_tdma_du_adj_type = 3;
2412 } else if (coex_dm->cur_ps_tdma == 8) {
2413 halbtc8821a2ant_ps_tdma(btcoexist,
2414 NORMAL_EXEC, true, 4);
2415 coex_dm->ps_tdma_du_adj_type = 4;
2416 }
2417 if (coex_dm->cur_ps_tdma == 13) {
2418 halbtc8821a2ant_ps_tdma(btcoexist,
2419 NORMAL_EXEC, true, 10);
2420 coex_dm->ps_tdma_du_adj_type = 10;
2421 } else if (coex_dm->cur_ps_tdma == 14) {
2422 halbtc8821a2ant_ps_tdma(btcoexist,
2423 NORMAL_EXEC, true, 10);
2424 coex_dm->ps_tdma_du_adj_type = 10;
2425 } else if (coex_dm->cur_ps_tdma == 15) {
2426 halbtc8821a2ant_ps_tdma(btcoexist,
2427 NORMAL_EXEC, true, 11);
2428 coex_dm->ps_tdma_du_adj_type = 11;
2429 } else if (coex_dm->cur_ps_tdma == 16) {
2430 halbtc8821a2ant_ps_tdma(btcoexist,
2431 NORMAL_EXEC, true, 12);
2432 coex_dm->ps_tdma_du_adj_type = 12;
2433 }
2434 if (result == -1) {
2435 if (coex_dm->cur_ps_tdma == 1) {
2436 halbtc8821a2ant_ps_tdma(
2437 btcoexist, NORMAL_EXEC,
2438 true, 2);
2439 coex_dm->ps_tdma_du_adj_type =
2440 2;
2441 } else if (coex_dm->cur_ps_tdma == 2) {
2442 halbtc8821a2ant_ps_tdma(
2443 btcoexist, NORMAL_EXEC,
2444 true, 3);
2445 coex_dm->ps_tdma_du_adj_type =
2446 3;
2447 } else if (coex_dm->cur_ps_tdma == 3) {
2448 halbtc8821a2ant_ps_tdma(
2449 btcoexist, NORMAL_EXEC,
2450 true, 4);
2451 coex_dm->ps_tdma_du_adj_type =
2452 4;
2453 } else if (coex_dm->cur_ps_tdma == 9) {
2454 halbtc8821a2ant_ps_tdma(
2455 btcoexist, NORMAL_EXEC,
2456 true, 10);
2457 coex_dm->ps_tdma_du_adj_type =
2458 10;
2459 } else if (coex_dm->cur_ps_tdma == 10) {
2460 halbtc8821a2ant_ps_tdma(
2461 btcoexist, NORMAL_EXEC,
2462 true, 11);
2463 coex_dm->ps_tdma_du_adj_type =
2464 11;
2465 } else if (coex_dm->cur_ps_tdma == 11) {
2466 halbtc8821a2ant_ps_tdma(
2467 btcoexist, NORMAL_EXEC,
2468 true, 12);
2469 coex_dm->ps_tdma_du_adj_type =
2470 12;
2471 }
2472 } else if (result == 1) {
2473 if (coex_dm->cur_ps_tdma == 4) {
2474 halbtc8821a2ant_ps_tdma(
2475 btcoexist, NORMAL_EXEC,
2476 true, 3);
2477 coex_dm->ps_tdma_du_adj_type =
2478 3;
2479 } else if (coex_dm->cur_ps_tdma == 3) {
2480 halbtc8821a2ant_ps_tdma(
2481 btcoexist, NORMAL_EXEC,
2482 true, 2);
2483 coex_dm->ps_tdma_du_adj_type =
2484 2;
2485 } else if (coex_dm->cur_ps_tdma == 2) {
2486 halbtc8821a2ant_ps_tdma(
2487 btcoexist, NORMAL_EXEC,
2488 true, 2);
2489 coex_dm->ps_tdma_du_adj_type =
2490 2;
2491 } else if (coex_dm->cur_ps_tdma == 12) {
2492 halbtc8821a2ant_ps_tdma(
2493 btcoexist, NORMAL_EXEC,
2494 true, 11);
2495 coex_dm->ps_tdma_du_adj_type =
2496 11;
2497 } else if (coex_dm->cur_ps_tdma == 11) {
2498 halbtc8821a2ant_ps_tdma(
2499 btcoexist, NORMAL_EXEC,
2500 true, 10);
2501 coex_dm->ps_tdma_du_adj_type =
2502 10;
2503 } else if (coex_dm->cur_ps_tdma == 10) {
2504 halbtc8821a2ant_ps_tdma(
2505 btcoexist, NORMAL_EXEC,
2506 true, 10);
2507 coex_dm->ps_tdma_du_adj_type =
2508 10;
2509 }
2510 }
2511 }
2512 } else if (max_interval == 3) {
2513 if (tx_pause) {
2514 if (coex_dm->cur_ps_tdma == 1) {
2515 halbtc8821a2ant_ps_tdma(btcoexist,
2516 NORMAL_EXEC, true, 7);
2517 coex_dm->ps_tdma_du_adj_type = 7;
2518 } else if (coex_dm->cur_ps_tdma == 2) {
2519 halbtc8821a2ant_ps_tdma(btcoexist,
2520 NORMAL_EXEC, true, 7);
2521 coex_dm->ps_tdma_du_adj_type = 7;
2522 } else if (coex_dm->cur_ps_tdma == 3) {
2523 halbtc8821a2ant_ps_tdma(btcoexist,
2524 NORMAL_EXEC, true, 7);
2525 coex_dm->ps_tdma_du_adj_type = 7;
2526 } else if (coex_dm->cur_ps_tdma == 4) {
2527 halbtc8821a2ant_ps_tdma(btcoexist,
2528 NORMAL_EXEC, true, 8);
2529 coex_dm->ps_tdma_du_adj_type = 8;
2530 }
2531 if (coex_dm->cur_ps_tdma == 9) {
2532 halbtc8821a2ant_ps_tdma(btcoexist,
2533 NORMAL_EXEC, true, 15);
2534 coex_dm->ps_tdma_du_adj_type = 15;
2535 } else if (coex_dm->cur_ps_tdma == 10) {
2536 halbtc8821a2ant_ps_tdma(btcoexist,
2537 NORMAL_EXEC, true, 15);
2538 coex_dm->ps_tdma_du_adj_type = 15;
2539 } else if (coex_dm->cur_ps_tdma == 11) {
2540 halbtc8821a2ant_ps_tdma(btcoexist,
2541 NORMAL_EXEC, true, 15);
2542 coex_dm->ps_tdma_du_adj_type = 15;
2543 } else if (coex_dm->cur_ps_tdma == 12) {
2544 halbtc8821a2ant_ps_tdma(btcoexist,
2545 NORMAL_EXEC, true, 16);
2546 coex_dm->ps_tdma_du_adj_type = 16;
2547 }
2548 if (result == -1) {
2549 if (coex_dm->cur_ps_tdma == 5) {
2550 halbtc8821a2ant_ps_tdma(
2551 btcoexist, NORMAL_EXEC,
2552 true, 7);
2553 coex_dm->ps_tdma_du_adj_type =
2554 7;
2555 } else if (coex_dm->cur_ps_tdma == 6) {
2556 halbtc8821a2ant_ps_tdma(
2557 btcoexist, NORMAL_EXEC,
2558 true, 7);
2559 coex_dm->ps_tdma_du_adj_type =
2560 7;
2561 } else if (coex_dm->cur_ps_tdma == 7) {
2562 halbtc8821a2ant_ps_tdma(
2563 btcoexist, NORMAL_EXEC,
2564 true, 8);
2565 coex_dm->ps_tdma_du_adj_type =
2566 8;
2567 } else if (coex_dm->cur_ps_tdma == 13) {
2568 halbtc8821a2ant_ps_tdma(
2569 btcoexist, NORMAL_EXEC,
2570 true, 15);
2571 coex_dm->ps_tdma_du_adj_type =
2572 15;
2573 } else if (coex_dm->cur_ps_tdma == 14) {
2574 halbtc8821a2ant_ps_tdma(
2575 btcoexist, NORMAL_EXEC,
2576 true, 15);
2577 coex_dm->ps_tdma_du_adj_type =
2578 15;
2579 } else if (coex_dm->cur_ps_tdma == 15) {
2580 halbtc8821a2ant_ps_tdma(
2581 btcoexist, NORMAL_EXEC,
2582 true, 16);
2583 coex_dm->ps_tdma_du_adj_type =
2584 16;
2585 }
2586 } else if (result == 1) {
2587 if (coex_dm->cur_ps_tdma == 8) {
2588 halbtc8821a2ant_ps_tdma(
2589 btcoexist, NORMAL_EXEC,
2590 true, 7);
2591 coex_dm->ps_tdma_du_adj_type =
2592 7;
2593 } else if (coex_dm->cur_ps_tdma == 7) {
2594 halbtc8821a2ant_ps_tdma(
2595 btcoexist, NORMAL_EXEC,
2596 true, 7);
2597 coex_dm->ps_tdma_du_adj_type =
2598 7;
2599 } else if (coex_dm->cur_ps_tdma == 6) {
2600 halbtc8821a2ant_ps_tdma(
2601 btcoexist, NORMAL_EXEC,
2602 true, 7);
2603 coex_dm->ps_tdma_du_adj_type =
2604 7;
2605 } else if (coex_dm->cur_ps_tdma == 16) {
2606 halbtc8821a2ant_ps_tdma(
2607 btcoexist, NORMAL_EXEC,
2608 true, 15);
2609 coex_dm->ps_tdma_du_adj_type =
2610 15;
2611 } else if (coex_dm->cur_ps_tdma == 15) {
2612 halbtc8821a2ant_ps_tdma(
2613 btcoexist, NORMAL_EXEC,
2614 true, 15);
2615 coex_dm->ps_tdma_du_adj_type =
2616 15;
2617 } else if (coex_dm->cur_ps_tdma == 14) {
2618 halbtc8821a2ant_ps_tdma(
2619 btcoexist, NORMAL_EXEC,
2620 true, 15);
2621 coex_dm->ps_tdma_du_adj_type =
2622 15;
2623 }
2624 }
2625 } else {
2626 if (coex_dm->cur_ps_tdma == 5) {
2627 halbtc8821a2ant_ps_tdma(btcoexist,
2628 NORMAL_EXEC, true, 3);
2629 coex_dm->ps_tdma_du_adj_type = 3;
2630 } else if (coex_dm->cur_ps_tdma == 6) {
2631 halbtc8821a2ant_ps_tdma(btcoexist,
2632 NORMAL_EXEC, true, 3);
2633 coex_dm->ps_tdma_du_adj_type = 3;
2634 } else if (coex_dm->cur_ps_tdma == 7) {
2635 halbtc8821a2ant_ps_tdma(btcoexist,
2636 NORMAL_EXEC, true, 3);
2637 coex_dm->ps_tdma_du_adj_type = 3;
2638 } else if (coex_dm->cur_ps_tdma == 8) {
2639 halbtc8821a2ant_ps_tdma(btcoexist,
2640 NORMAL_EXEC, true, 4);
2641 coex_dm->ps_tdma_du_adj_type = 4;
2642 }
2643 if (coex_dm->cur_ps_tdma == 13) {
2644 halbtc8821a2ant_ps_tdma(btcoexist,
2645 NORMAL_EXEC, true, 11);
2646 coex_dm->ps_tdma_du_adj_type = 11;
2647 } else if (coex_dm->cur_ps_tdma == 14) {
2648 halbtc8821a2ant_ps_tdma(btcoexist,
2649 NORMAL_EXEC, true, 11);
2650 coex_dm->ps_tdma_du_adj_type = 11;
2651 } else if (coex_dm->cur_ps_tdma == 15) {
2652 halbtc8821a2ant_ps_tdma(btcoexist,
2653 NORMAL_EXEC, true, 11);
2654 coex_dm->ps_tdma_du_adj_type = 11;
2655 } else if (coex_dm->cur_ps_tdma == 16) {
2656 halbtc8821a2ant_ps_tdma(btcoexist,
2657 NORMAL_EXEC, true, 12);
2658 coex_dm->ps_tdma_du_adj_type = 12;
2659 }
2660 if (result == -1) {
2661 if (coex_dm->cur_ps_tdma == 1) {
2662 halbtc8821a2ant_ps_tdma(
2663 btcoexist, NORMAL_EXEC,
2664 true, 3);
2665 coex_dm->ps_tdma_du_adj_type =
2666 3;
2667 } else if (coex_dm->cur_ps_tdma == 2) {
2668 halbtc8821a2ant_ps_tdma(
2669 btcoexist, NORMAL_EXEC,
2670 true, 3);
2671 coex_dm->ps_tdma_du_adj_type =
2672 3;
2673 } else if (coex_dm->cur_ps_tdma == 3) {
2674 halbtc8821a2ant_ps_tdma(
2675 btcoexist, NORMAL_EXEC,
2676 true, 4);
2677 coex_dm->ps_tdma_du_adj_type =
2678 4;
2679 } else if (coex_dm->cur_ps_tdma == 9) {
2680 halbtc8821a2ant_ps_tdma(
2681 btcoexist, NORMAL_EXEC,
2682 true, 11);
2683 coex_dm->ps_tdma_du_adj_type =
2684 11;
2685 } else if (coex_dm->cur_ps_tdma == 10) {
2686 halbtc8821a2ant_ps_tdma(
2687 btcoexist, NORMAL_EXEC,
2688 true, 11);
2689 coex_dm->ps_tdma_du_adj_type =
2690 11;
2691 } else if (coex_dm->cur_ps_tdma == 11) {
2692 halbtc8821a2ant_ps_tdma(
2693 btcoexist, NORMAL_EXEC,
2694 true, 12);
2695 coex_dm->ps_tdma_du_adj_type =
2696 12;
2697 }
2698 } else if (result == 1) {
2699 if (coex_dm->cur_ps_tdma == 4) {
2700 halbtc8821a2ant_ps_tdma(
2701 btcoexist, NORMAL_EXEC,
2702 true, 3);
2703 coex_dm->ps_tdma_du_adj_type =
2704 3;
2705 } else if (coex_dm->cur_ps_tdma == 3) {
2706 halbtc8821a2ant_ps_tdma(
2707 btcoexist, NORMAL_EXEC,
2708 true, 3);
2709 coex_dm->ps_tdma_du_adj_type =
2710 3;
2711 } else if (coex_dm->cur_ps_tdma == 2) {
2712 halbtc8821a2ant_ps_tdma(
2713 btcoexist, NORMAL_EXEC,
2714 true, 3);
2715 coex_dm->ps_tdma_du_adj_type =
2716 3;
2717 } else if (coex_dm->cur_ps_tdma == 12) {
2718 halbtc8821a2ant_ps_tdma(
2719 btcoexist, NORMAL_EXEC,
2720 true, 11);
2721 coex_dm->ps_tdma_du_adj_type =
2722 11;
2723 } else if (coex_dm->cur_ps_tdma == 11) {
2724 halbtc8821a2ant_ps_tdma(
2725 btcoexist, NORMAL_EXEC,
2726 true, 11);
2727 coex_dm->ps_tdma_du_adj_type =
2728 11;
2729 } else if (coex_dm->cur_ps_tdma == 10) {
2730 halbtc8821a2ant_ps_tdma(
2731 btcoexist, NORMAL_EXEC,
2732 true, 11);
2733 coex_dm->ps_tdma_du_adj_type =
2734 11;
2735 }
2736 }
2737 }
2738 }
2739 }
2740
2741 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
2742 /* then we have to adjust it back to the previous record one. */
2743 if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
2744 boolean scan = false, link = false, roam = false;
2745 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2746 "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n",
2747 coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
2748 BTC_TRACE(trace_buf);
2749
2750 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2751 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2752 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2753
2754 if (!scan && !link && !roam)
2755 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2756 coex_dm->ps_tdma_du_adj_type);
2757 else {
2758 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2759 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2760 BTC_TRACE(trace_buf);
2761 }
2762 }
2763 }
2764
2765 /* SCO only or SCO+PAN(HS) */
halbtc8821a2ant_action_sco(IN struct btc_coexist * btcoexist)2766 void halbtc8821a2ant_action_sco(IN struct btc_coexist *btcoexist)
2767 {
2768 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2769 u8 wifi_rssi_state, bt_rssi_state;
2770 u32 wifi_bw;
2771
2772 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
2773 0);
2774 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
2775 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2776
2777 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2778
2779 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2780
2781 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
2782
2783 if (BTC_RSSI_HIGH(bt_rssi_state))
2784 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2785 else
2786 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2787
2788 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2789
2790 if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for SCO quality at 11b/g mode */
2791 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2792 else { /* for SCO quality & wifi performance balance at 11n mode */
2793 if (BTC_WIFI_BW_HT40 == wifi_bw)
2794 halbtc8821a2ant_coex_table_with_type(btcoexist,
2795 NORMAL_EXEC, 8);
2796 else {
2797 if (bt_link_info->sco_only)
2798 halbtc8821a2ant_coex_table_with_type(btcoexist,
2799 NORMAL_EXEC, 17);
2800 else
2801 halbtc8821a2ant_coex_table_with_type(btcoexist,
2802 NORMAL_EXEC, 12);
2803 }
2804 }
2805
2806 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
2807 0x0);
2808 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2809 0); /* for voice quality */
2810
2811 /* sw mechanism */
2812 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2813 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2814 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2815 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
2816 false, false);
2817 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2818 true, 0x18);
2819 } else {
2820 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
2821 false, false);
2822 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
2823 true, 0x18);
2824 }
2825 } else {
2826 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2827 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2828 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
2829 false, false);
2830 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2831 true, 0x18);
2832 } else {
2833 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
2834 false, false);
2835 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
2836 true, 0x18);
2837 }
2838 }
2839 }
2840
2841
halbtc8821a2ant_action_hid(IN struct btc_coexist * btcoexist)2842 void halbtc8821a2ant_action_hid(IN struct btc_coexist *btcoexist)
2843 {
2844 u8 wifi_rssi_state, bt_rssi_state;
2845 u32 wifi_bw;
2846
2847 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
2848 0);
2849 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
2850 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2851
2852 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2853
2854 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2855
2856 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2857
2858 if (BTC_RSSI_HIGH(bt_rssi_state))
2859 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2860 else
2861 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2862
2863 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2864
2865 if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for HID at 11b/g mode */
2866 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2867 else /* for HID quality & wifi performance balance at 11n mode */
2868 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2869
2870 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
2871 0x0);
2872
2873 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 24);
2874
2875 /* sw mechanism */
2876 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2877 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2878 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2879 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
2880 false, false);
2881 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2882 false, 0x18);
2883 } else {
2884 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
2885 false, false);
2886 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
2887 false, 0x18);
2888 }
2889 } else {
2890 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2891 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2892 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
2893 false, false);
2894 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2895 false, 0x18);
2896 } else {
2897 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
2898 false, false);
2899 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
2900 false, 0x18);
2901 }
2902 }
2903 }
2904
2905 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
halbtc8821a2ant_action_a2dp(IN struct btc_coexist * btcoexist)2906 void halbtc8821a2ant_action_a2dp(IN struct btc_coexist *btcoexist)
2907 {
2908 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2909 u32 wifi_bw;
2910 u8 ap_num = 0;
2911
2912 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
2913 0);
2914 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2915 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2916 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
2917 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2918
2919 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
2920
2921 /* define the office environment */
2922 if ((ap_num >= 10) && BTC_RSSI_HIGH(wifi_rssi_state1) &&
2923 BTC_RSSI_HIGH(bt_rssi_state)) {
2924 /* dbg_print(" AP#>10(%d)\n", ap_num); */
2925 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2926 0x0, 0x0);
2927
2928 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
2929 0x0);
2930 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2931 0x8);
2932 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2933 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2934
2935 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2936
2937 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2938 0x0, 0x0);
2939 /* halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); */
2940 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2941
2942 /* sw mechanism */
2943 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2944 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2945 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
2946 false, false);
2947 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2948 true, 0x6);
2949 } else {
2950 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
2951 false, false);
2952 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2953 true, 0x6);
2954 }
2955 return;
2956
2957 }
2958
2959 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2960 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2961
2962 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2963
2964 if (BTC_RSSI_HIGH(bt_rssi_state))
2965 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2966 else
2967 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2968
2969
2970 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2971 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2972 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2973 0x0, 0x0);
2974 } else {
2975 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2976 13);
2977 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2978 0x4);
2979 }
2980
2981
2982 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2983 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2984 /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, false, 1); */
2985 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2986 } else {
2987 /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 1); */
2988 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2989 }
2990
2991 /* sw mechanism */
2992 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2993 if (BTC_WIFI_BW_HT40 == wifi_bw) {
2994 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2995 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2996 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
2997 false, false);
2998 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
2999 false, 0x18);
3000 } else {
3001 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3002 false, false);
3003 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3004 false, 0x18);
3005 }
3006 } else {
3007 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3008 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3009 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3010 false, false);
3011 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3012 false, 0x18);
3013 } else {
3014 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3015 false, false);
3016 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3017 false, 0x18);
3018 }
3019 }
3020 }
3021
halbtc8821a2ant_action_a2dp_pan_hs(IN struct btc_coexist * btcoexist)3022 void halbtc8821a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
3023 {
3024 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3025 u32 wifi_bw;
3026
3027 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3028 0);
3029 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3030 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3031 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
3032 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3033
3034 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3035
3036 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3037
3038 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3039
3040 if (BTC_RSSI_HIGH(bt_rssi_state))
3041 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3042 else
3043 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3044
3045 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3046 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3047 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3048 0x0, 0x0);
3049 } else {
3050 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3051 13);
3052 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3053 0x4);
3054 }
3055
3056 halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
3057
3058 /* sw mechanism */
3059 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3060 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3061 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3062 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3063 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3064 false, false);
3065 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3066 false, 0x18);
3067 } else {
3068 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3069 false, false);
3070 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3071 false, 0x18);
3072 }
3073 } else {
3074 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3075 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3076 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3077 false, false);
3078 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3079 false, 0x18);
3080 } else {
3081 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3082 false, false);
3083 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3084 false, 0x18);
3085 }
3086 }
3087 }
3088
halbtc8821a2ant_action_pan_edr(IN struct btc_coexist * btcoexist)3089 void halbtc8821a2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
3090 {
3091 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3092 u32 wifi_bw;
3093
3094 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3095 0);
3096 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3097 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3098 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
3099 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3100
3101 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3102
3103 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3104
3105 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3106
3107 if (BTC_RSSI_HIGH(bt_rssi_state))
3108 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3109 else
3110 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3111
3112 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3113 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3114 10);
3115 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3116 0x0, 0x0);
3117 } else {
3118 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3119 13);
3120 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3121 0x4);
3122 }
3123
3124 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3125 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
3126 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
3127 else
3128 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
3129
3130 /* sw mechanism */
3131 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3132 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3133 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3134 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3135 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3136 false, false);
3137 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3138 false, 0x18);
3139 } else {
3140 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3141 false, false);
3142 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3143 false, 0x18);
3144 }
3145 } else {
3146 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3147 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3148 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3149 false, false);
3150 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3151 false, 0x18);
3152 } else {
3153 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3154 false, false);
3155 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3156 false, 0x18);
3157 }
3158 }
3159 }
3160
3161
3162 /* PAN(HS) only */
halbtc8821a2ant_action_pan_hs(IN struct btc_coexist * btcoexist)3163 void halbtc8821a2ant_action_pan_hs(IN struct btc_coexist *btcoexist)
3164 {
3165 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3166 u32 wifi_bw;
3167
3168 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3169 0);
3170 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3171 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3172 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
3173 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3174
3175 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3176
3177 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3178
3179 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3180
3181 if (BTC_RSSI_HIGH(bt_rssi_state))
3182 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3183 else
3184 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3185
3186 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3187
3188 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3189 0x0);
3190 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3191
3192 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3193 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3194 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3195 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3196 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3197 false, false);
3198 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3199 false, 0x18);
3200 } else {
3201 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3202 false, false);
3203 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3204 false, 0x18);
3205 }
3206 } else {
3207 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3208 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3209 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3210 false, false);
3211 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3212 false, 0x18);
3213 } else {
3214 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3215 false, false);
3216 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3217 false, 0x18);
3218 }
3219 }
3220 }
3221
3222 /* PAN(EDR)+A2DP */
halbtc8821a2ant_action_pan_edr_a2dp(IN struct btc_coexist * btcoexist)3223 void halbtc8821a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
3224 {
3225 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3226 u32 wifi_bw;
3227
3228 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3229 0);
3230 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3231 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3232 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
3233 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3234
3235 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3236
3237 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3238
3239 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3240
3241 if (BTC_RSSI_HIGH(bt_rssi_state))
3242 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3243 else
3244 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3245
3246 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state))
3247 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3248 0x0, 0x0);
3249 else
3250 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3251 0x4);
3252
3253 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3254
3255 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3256 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3257 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3258 12);
3259
3260 if (BTC_WIFI_BW_HT40 == wifi_bw)
3261 halbtc8821a2ant_tdma_duration_adjust(btcoexist, false,
3262 true, 3);
3263 else
3264 halbtc8821a2ant_tdma_duration_adjust(btcoexist, false,
3265 false, 3);
3266 } else {
3267 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3268 13);
3269 halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 3);
3270 }
3271
3272 /* sw mechanism */
3273 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3274 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3275 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3276 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3277 false, false);
3278 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3279 false, 0x18);
3280 } else {
3281 halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
3282 false, false);
3283 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3284 false, 0x18);
3285 }
3286 } else {
3287 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3288 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3289 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3290 false, false);
3291 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3292 false, 0x18);
3293 } else {
3294 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
3295 false, false);
3296 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3297 false, 0x18);
3298 }
3299 }
3300 }
3301
halbtc8821a2ant_action_pan_edr_hid(IN struct btc_coexist * btcoexist)3302 void halbtc8821a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
3303 {
3304 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3305 u32 wifi_bw;
3306
3307 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3308 0);
3309 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3310 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3311 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
3312 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3313 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3314
3315 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3316
3317 if (BTC_RSSI_HIGH(bt_rssi_state))
3318 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3319 else
3320 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3321
3322 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3323 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3324 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3325 0x0, 0x0);
3326 } else {
3327 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3328 14);
3329 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3330 0x4);
3331 }
3332
3333 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3334 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3335 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3336 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
3337 3);
3338 /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 11); */
3339 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
3340 0xfffff, 0x780);
3341 } else {
3342 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
3343 6);
3344 /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); */
3345 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
3346 0xfffff, 0x0);
3347 }
3348 halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3349 } else {
3350 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3351 /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); */
3352 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
3353 0x0);
3354 halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3355 }
3356
3357 /* sw mechanism */
3358 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3359 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3360 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3361 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
3362 false, false);
3363 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3364 false, 0x18);
3365 } else {
3366 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
3367 false, false);
3368 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3369 false, 0x18);
3370 }
3371 } else {
3372 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3373 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3374 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
3375 false, false);
3376 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3377 false, 0x18);
3378 } else {
3379 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
3380 false, false);
3381 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3382 false, 0x18);
3383 }
3384 }
3385 }
3386
3387 /* HID+A2DP+PAN(EDR) */
halbtc8821a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist * btcoexist)3388 void halbtc8821a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
3389 {
3390 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3391 u32 wifi_bw;
3392
3393 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3394 0);
3395 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3396 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3397 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
3398 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3399
3400 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3401
3402 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3403
3404 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3405
3406 if (BTC_RSSI_HIGH(bt_rssi_state))
3407 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3408 else
3409 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3410
3411 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3412 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3413 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3414 0x0, 0x0);
3415 } else {
3416 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3417 14);
3418 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3419 0x4);
3420 }
3421
3422 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3423
3424 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3425 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3426 if (BTC_WIFI_BW_HT40 == wifi_bw)
3427 halbtc8821a2ant_tdma_duration_adjust(btcoexist, true,
3428 true, 3);
3429 else
3430 halbtc8821a2ant_tdma_duration_adjust(btcoexist, true,
3431 false, 3);
3432 } else
3433 halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
3434
3435 /* sw mechanism */
3436 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3437 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3438 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3439 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
3440 false, false);
3441 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3442 false, 0x18);
3443 } else {
3444 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
3445 false, false);
3446 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3447 false, 0x18);
3448 }
3449 } else {
3450 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3451 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3452 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
3453 false, false);
3454 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3455 false, 0x18);
3456 } else {
3457 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
3458 false, false);
3459 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3460 false, 0x18);
3461 }
3462 }
3463 }
3464
halbtc8821a2ant_action_hid_a2dp(IN struct btc_coexist * btcoexist)3465 void halbtc8821a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
3466 {
3467 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3468 u32 wifi_bw;
3469 u8 ap_num = 0;
3470
3471 wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
3472 0);
3473 /* bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 29, 0); */
3474 wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3475 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3476 bt_rssi_state = halbtc8821a2ant_bt_rssi_state(3,
3477 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);
3478
3479 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3480
3481 halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x5);
3482
3483 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3484
3485 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3486 if (BTC_WIFI_BW_LEGACY == wifi_bw) {
3487 if (BTC_RSSI_HIGH(bt_rssi_state))
3488 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3489 else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3490 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3491 else
3492 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3493 } else {
3494 /* only 802.11N mode we have to dec bt power to 4 degree */
3495 if (BTC_RSSI_HIGH(bt_rssi_state)) {
3496 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3497 &ap_num);
3498 /* need to check ap Number of Not */
3499 if (ap_num < 10)
3500 halbtc8821a2ant_dec_bt_pwr(btcoexist,
3501 NORMAL_EXEC, 4);
3502 else
3503 halbtc8821a2ant_dec_bt_pwr(btcoexist,
3504 NORMAL_EXEC, 2);
3505 } else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3506 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3507 else
3508 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3509 }
3510
3511 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3512 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3513 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3514 0x0, 0x0);
3515 } else {
3516 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
3517 14);
3518 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3519 0x4);
3520 }
3521
3522 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3523 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3524 /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, false, 3); */
3525 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
3526 } else {
3527 /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3); */
3528 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
3529 }
3530
3531 /* sw mechanism */
3532 if (BTC_WIFI_BW_HT40 == wifi_bw) {
3533 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3534 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3535 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
3536 false, false);
3537 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3538 false, 0x18);
3539 } else {
3540 halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
3541 false, false);
3542 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3543 false, 0x18);
3544 }
3545 } else {
3546 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3547 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3548 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
3549 false, false);
3550 halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
3551 false, 0x18);
3552 } else {
3553 halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
3554 false, false);
3555 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
3556 false, 0x18);
3557 }
3558 }
3559 }
3560
halbtc8821a2ant_action_bt_whck_test(IN struct btc_coexist * btcoexist)3561 void halbtc8821a2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
3562 {
3563 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3564
3565 /* sw all off */
3566 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
3567 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
3568
3569 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3570 0x0);
3571
3572 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3573 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3574 }
3575
halbtc8821a2ant_action_wifi_multi_port(IN struct btc_coexist * btcoexist)3576 void halbtc8821a2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
3577 {
3578 halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3579 halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3580
3581 /* sw all off */
3582 halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
3583 halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
3584
3585 /* hw all off */
3586 /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
3587 halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3588
3589 halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3590 0x0);
3591 halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3592 }
3593
halbtc8821a2ant_run_coexist_mechanism(IN struct btc_coexist * btcoexist)3594 void halbtc8821a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
3595 {
3596 boolean wifi_under_5g = false;
3597 u8 algorithm = 0;
3598 u32 num_of_wifi_link = 0;
3599 u32 wifi_link_status = 0;
3600 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3601 boolean miracast_plus_bt = false;
3602 boolean scan = false, link = false, roam = false;
3603
3604 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3605 "[BTCoex], RunCoexistMechanism()===>\n");
3606 BTC_TRACE(trace_buf);
3607
3608 if (btcoexist->manual_control) {
3609 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3610 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3611 BTC_TRACE(trace_buf);
3612 return;
3613 }
3614
3615 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3616 if (wifi_under_5g) {
3617 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3618 "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3619 BTC_TRACE(trace_buf);
3620 halbtc8821a2ant_coex_under_5g(btcoexist);
3621 return;
3622 }
3623
3624 if (coex_sta->under_ips) {
3625 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3626 "[BTCoex], wifi is under IPS !!!\n");
3627 BTC_TRACE(trace_buf);
3628 return;
3629 }
3630
3631 if (coex_sta->bt_whck_test) {
3632 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3633 "[BTCoex], BT is under WHCK TEST!!!\n");
3634 BTC_TRACE(trace_buf);
3635 halbtc8821a2ant_action_bt_whck_test(btcoexist);
3636 return;
3637 }
3638
3639 algorithm = halbtc8821a2ant_action_algorithm(btcoexist);
3640 if (coex_sta->c2h_bt_inquiry_page &&
3641 (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3642 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3643 "[BTCoex], BT is under inquiry/page scan !!\n");
3644 BTC_TRACE(trace_buf);
3645 halbtc8821a2ant_action_bt_inquiry(btcoexist);
3646 return;
3647 } else {
3648
3649 }
3650
3651 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3652 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3653 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3654
3655 if (scan || link || roam) {
3656 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3657 "[BTCoex], WiFi is under Link Process !!\n");
3658 BTC_TRACE(trace_buf);
3659 halbtc8821a2ant_action_wifi_link_process(btcoexist);
3660 return;
3661 }
3662
3663 /* for P2P */
3664
3665 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3666 &wifi_link_status);
3667 num_of_wifi_link = wifi_link_status >> 16;
3668
3669 if ((num_of_wifi_link >= 2) ||
3670 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3671 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3672 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3673 num_of_wifi_link, wifi_link_status);
3674 BTC_TRACE(trace_buf);
3675
3676 if (bt_link_info->bt_link_exist)
3677 miracast_plus_bt = true;
3678 else
3679 miracast_plus_bt = false;
3680
3681 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3682 &miracast_plus_bt);
3683 halbtc8821a2ant_action_wifi_multi_port(btcoexist);
3684
3685 return;
3686 } else {
3687 miracast_plus_bt = false;
3688 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3689 &miracast_plus_bt);
3690 }
3691
3692 coex_dm->cur_algorithm = algorithm;
3693 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
3694 coex_dm->cur_algorithm);
3695 BTC_TRACE(trace_buf);
3696
3697 if (halbtc8821a2ant_is_common_action(btcoexist)) {
3698 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3699 "[BTCoex], Action 2-Ant common.\n");
3700 BTC_TRACE(trace_buf);
3701 coex_dm->auto_tdma_adjust = false;
3702 } else {
3703 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3704 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3705 "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n",
3706 coex_dm->pre_algorithm, coex_dm->cur_algorithm);
3707 BTC_TRACE(trace_buf);
3708 coex_dm->auto_tdma_adjust = false;
3709 }
3710 switch (coex_dm->cur_algorithm) {
3711 case BT_8821A_2ANT_COEX_ALGO_SCO:
3712 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3713 "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
3714 BTC_TRACE(trace_buf);
3715 halbtc8821a2ant_action_sco(btcoexist);
3716 break;
3717 case BT_8821A_2ANT_COEX_ALGO_HID:
3718 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3719 "[BTCoex], Action 2-Ant, algorithm = HID.\n");
3720 BTC_TRACE(trace_buf);
3721 halbtc8821a2ant_action_hid(btcoexist);
3722 break;
3723 case BT_8821A_2ANT_COEX_ALGO_A2DP:
3724 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3725 "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
3726 BTC_TRACE(trace_buf);
3727 halbtc8821a2ant_action_a2dp(btcoexist);
3728 break;
3729 case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
3730 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3731 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
3732 BTC_TRACE(trace_buf);
3733 halbtc8821a2ant_action_a2dp_pan_hs(btcoexist);
3734 break;
3735 case BT_8821A_2ANT_COEX_ALGO_PANEDR:
3736 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3737 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
3738 BTC_TRACE(trace_buf);
3739 halbtc8821a2ant_action_pan_edr(btcoexist);
3740 break;
3741 case BT_8821A_2ANT_COEX_ALGO_PANHS:
3742 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3743 "[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
3744 BTC_TRACE(trace_buf);
3745 halbtc8821a2ant_action_pan_hs(btcoexist);
3746 break;
3747 case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
3748 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3749 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
3750 BTC_TRACE(trace_buf);
3751 halbtc8821a2ant_action_pan_edr_a2dp(btcoexist);
3752 break;
3753 case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
3754 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3755 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
3756 BTC_TRACE(trace_buf);
3757 halbtc8821a2ant_action_pan_edr_hid(btcoexist);
3758 break;
3759 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3760 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3761 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
3762 BTC_TRACE(trace_buf);
3763 halbtc8821a2ant_action_hid_a2dp_pan_edr(
3764 btcoexist);
3765 break;
3766 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
3767 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3768 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
3769 BTC_TRACE(trace_buf);
3770 halbtc8821a2ant_action_hid_a2dp(btcoexist);
3771 break;
3772 default:
3773 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3774 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3775 BTC_TRACE(trace_buf);
3776 halbtc8821a2ant_coex_all_off(btcoexist);
3777 break;
3778 }
3779 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3780 }
3781 }
3782
halbtc8821a2ant_wifi_off_hw_cfg(IN struct btc_coexist * btcoexist)3783 void halbtc8821a2ant_wifi_off_hw_cfg(IN struct btc_coexist *btcoexist)
3784 {
3785 u8 h2c_parameter[2] = {0};
3786 u32 fw_ver = 0;
3787
3788 /* set wlan_act to low */
3789 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
3790
3791 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
3792 0x780); /* WiFi goto standby while GNT_BT 0-->1 */
3793 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3794 if (fw_ver >= 0x180000) {
3795 /* Use H2C to set GNT_BT to HIGH */
3796 h2c_parameter[0] = 1;
3797 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter);
3798 } else
3799 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
3800 }
3801
halbtc8821a2ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean back_up)3802 void halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
3803 IN boolean back_up)
3804 {
3805 u8 u8tmp = 0;
3806
3807
3808 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3809 "[BTCoex], 2Ant Init HW Config!!\n");
3810 BTC_TRACE(trace_buf);
3811
3812 /* backup rf 0x1e value */
3813 coex_dm->bt_rf_0x1e_backup =
3814 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
3815
3816 /* 0x790[5:0]=0x5 */
3817 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3818 u8tmp &= 0xc0;
3819 u8tmp |= 0x5;
3820 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
3821
3822 /* Antenna config */
3823 halbtc8821a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, true,
3824 false);
3825 coex_sta->dis_ver_info_cnt = 0;
3826
3827 /* PTA parameter */
3828 halbtc8821a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
3829
3830 /* Enable counter statistics */
3831 btcoexist->btc_write_1byte(btcoexist, 0x76e,
3832 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */
3833 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3834 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3835 }
3836
3837 /* ************************************************************
3838 * work around function start with wa_halbtc8821a2ant_
3839 * ************************************************************
3840 * ************************************************************
3841 * extern function start with ex_halbtc8821a2ant_
3842 * ************************************************************ */
ex_halbtc8821a2ant_power_on_setting(IN struct btc_coexist * btcoexist)3843 void ex_halbtc8821a2ant_power_on_setting(IN struct btc_coexist *btcoexist)
3844 {
3845
3846 }
3847
ex_halbtc8821a2ant_pre_load_firmware(IN struct btc_coexist * btcoexist)3848 void ex_halbtc8821a2ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
3849 {
3850 struct btc_board_info *board_info = &btcoexist->board_info;
3851 u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
3852
3853 /* */
3854 /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
3855 /* Local setting bit define */
3856 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
3857 /* BIT1: "0" for internal switch; "1" for external switch */
3858 /* BIT2: "0" for one antenna; "1" for two antenna */
3859 /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
3860 if (btcoexist->chip_interface == BTC_INTF_USB) {
3861 /* fixed at S0 for USB interface */
3862 u8tmp |= 0x1; /* antenna inverse */
3863 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
3864 } else {
3865 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
3866 if (board_info->single_ant_path == 0) {
3867 } else if (board_info->single_ant_path == 1) {
3868 /* set to S0 */
3869 u8tmp |= 0x1; /* antenna inverse */
3870 }
3871
3872 if (btcoexist->chip_interface == BTC_INTF_PCI)
3873 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
3874 u8tmp);
3875 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
3876 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
3877 u8tmp);
3878 }
3879 }
3880
ex_halbtc8821a2ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)3881 void ex_halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
3882 IN boolean wifi_only)
3883 {
3884 halbtc8821a2ant_init_hw_config(btcoexist, true);
3885 }
3886
ex_halbtc8821a2ant_init_coex_dm(IN struct btc_coexist * btcoexist)3887 void ex_halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
3888 {
3889 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3890 "[BTCoex], Coex Mechanism Init!!\n");
3891 BTC_TRACE(trace_buf);
3892
3893 halbtc8821a2ant_init_coex_dm(btcoexist);
3894 }
3895
ex_halbtc8821a2ant_display_coex_info(IN struct btc_coexist * btcoexist)3896 void ex_halbtc8821a2ant_display_coex_info(IN struct btc_coexist *btcoexist)
3897 {
3898 struct btc_board_info *board_info = &btcoexist->board_info;
3899 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3900 u8 *cli_buf = btcoexist->cli_buf;
3901 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3902 u32 u32tmp[4];
3903 u32 fa_of_dm, fa_cck;
3904 u32 fw_ver = 0, bt_patch_ver = 0;
3905
3906 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3907 "\r\n ============[BT Coexist info]============");
3908 CL_PRINTF(cli_buf);
3909
3910 if (btcoexist->manual_control) {
3911 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3912 "\r\n ============[Under Manual Control]============");
3913 CL_PRINTF(cli_buf);
3914 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3915 "\r\n ==========================================");
3916 CL_PRINTF(cli_buf);
3917 }
3918
3919 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
3920 "Ant PG number/ Ant mechanism:",
3921 board_info->pg_ant_num, board_info->btdm_ant_num);
3922 CL_PRINTF(cli_buf);
3923
3924 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3925 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3926 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3927 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
3928 "CoexVer/ FwVer/ PatchVer",
3929 glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant, fw_ver,
3930 bt_patch_ver, bt_patch_ver);
3931 CL_PRINTF(cli_buf);
3932
3933 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
3934 "Wifi channel informed to BT",
3935 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
3936 coex_dm->wifi_chnl_info[2]);
3937 CL_PRINTF(cli_buf);
3938
3939 /* wifi status */
3940 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
3941 "============[Wifi Status]============");
3942 CL_PRINTF(cli_buf);
3943 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
3944
3945 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
3946 "============[BT Status]============");
3947 CL_PRINTF(cli_buf);
3948
3949 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %ddBm/ %d] ",
3950 "BT [status/ rssi/ retryCnt]",
3951 ((coex_sta->bt_disabled) ? ("disabled") : ((
3952 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
3953 : ((BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3954 coex_dm->bt_status) ? "non-connected idle" :
3955 ((BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
3956 ? "connected-idle" : "busy")))),
3957 coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt);
3958 CL_PRINTF(cli_buf);
3959
3960 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
3961 "SCO/HID/PAN/A2DP",
3962 bt_link_info->sco_exist, bt_link_info->hid_exist,
3963 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
3964 CL_PRINTF(cli_buf);
3965
3966 {
3967 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
3968 "BT Role",
3969 (bt_link_info->slave_role) ? "Slave" : "Master");
3970 CL_PRINTF(cli_buf);
3971 }
3972
3973 bt_info_ext = coex_sta->bt_info_ext;
3974 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
3975 "BT Info A2DP rate",
3976 (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
3977 CL_PRINTF(cli_buf);
3978
3979 for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) {
3980 if (coex_sta->bt_info_c2h_cnt[i]) {
3981 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3982 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
3983 glbt_info_src_8821a_2ant[i],
3984 coex_sta->bt_info_c2h[i][0],
3985 coex_sta->bt_info_c2h[i][1],
3986 coex_sta->bt_info_c2h[i][2],
3987 coex_sta->bt_info_c2h[i][3],
3988 coex_sta->bt_info_c2h[i][4],
3989 coex_sta->bt_info_c2h[i][5],
3990 coex_sta->bt_info_c2h[i][6],
3991 coex_sta->bt_info_c2h_cnt[i]);
3992 CL_PRINTF(cli_buf);
3993 }
3994 }
3995
3996 /* Sw mechanism */
3997 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
3998 "============[Sw mechanism]============");
3999 CL_PRINTF(cli_buf);
4000 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
4001 "SM1[ShRf/ LpRA/ LimDig]",
4002 coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
4003 coex_dm->limited_dig);
4004 CL_PRINTF(cli_buf);
4005 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
4006 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
4007 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
4008 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
4009 CL_PRINTF(cli_buf);
4010
4011 /* Fw mechanism */
4012 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4013 "============[Fw mechanism]============");
4014 CL_PRINTF(cli_buf);
4015
4016 ps_tdma_case = coex_dm->cur_ps_tdma;
4017 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4018 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
4019 "PS TDMA",
4020 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4021 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4022 coex_dm->ps_tdma_para[4], ps_tdma_case,
4023 coex_dm->auto_tdma_adjust);
4024 CL_PRINTF(cli_buf);
4025
4026 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
4027 "Coex Table Type",
4028 coex_sta->coex_table_type);
4029 CL_PRINTF(cli_buf);
4030
4031 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
4032 "DecBtPwr/ IgnWlanAct",
4033 coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act);
4034 CL_PRINTF(cli_buf);
4035
4036 /* Hw setting */
4037 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4038 "============[Hw setting]============");
4039 CL_PRINTF(cli_buf);
4040
4041 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x",
4042 "RF-A, 0x1e initVal",
4043 coex_dm->bt_rf_0x1e_backup);
4044 CL_PRINTF(cli_buf);
4045
4046 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4047 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
4048 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880);
4049 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
4050 "0x778/0x880[29:25]/0xc58[29:25]",
4051 u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25,
4052 ((u8tmp[1] & 0x3e) >> 1));
4053 CL_PRINTF(cli_buf);
4054
4055 u32tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x764);
4056 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x76e);
4057 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
4058 "0x764/ 0x765/ 0x76e",
4059 (u32tmp[0] & 0xff), (u32tmp[0] & 0xff00) >> 8, u8tmp[0]);
4060 CL_PRINTF(cli_buf);
4061
4062 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
4063 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4064 "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
4065 u32tmp[0] & 0xff, ((u32tmp[0] & 0x30000000) >> 28));
4066 CL_PRINTF(cli_buf);
4067
4068 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4069 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4070 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
4071 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
4072 "0x40/ 0x4c[24:23]/ 0x974",
4073 u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]);
4074 CL_PRINTF(cli_buf);
4075
4076 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4077 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4078 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4079 "0x550(bcn ctrl)/0x522",
4080 u32tmp[0], u8tmp[0]);
4081 CL_PRINTF(cli_buf);
4082
4083 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
4084 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
4085 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4086 "0xc50(dig)/0x49c(null-drop)",
4087 u32tmp[0] & 0xff, u8tmp[0]);
4088 CL_PRINTF(cli_buf);
4089
4090 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
4091 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
4092 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
4093 u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
4094
4095 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
4096 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
4097
4098 fa_of_dm = ((u32tmp[0] & 0xffff0000) >> 16) + ((u32tmp[1] & 0xffff0000)
4099 >> 16) + (u32tmp[1] & 0xffff) + (u32tmp[2] & 0xffff) + \
4100 ((u32tmp[3] & 0xffff0000) >> 16) + (u32tmp[3] &
4101 0xffff) ;
4102 fa_cck = (u8tmp[0] << 8) + u8tmp[1];
4103
4104 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
4105 "OFDM-CCA/OFDM-FA/CCK-FA",
4106 u32tmp[0] & 0xffff, fa_of_dm, fa_cck);
4107 CL_PRINTF(cli_buf);
4108
4109 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
4110 "CRC_OK CCK/11g/11n/11n-Agg",
4111 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
4112 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_agg);
4113 CL_PRINTF(cli_buf);
4114
4115 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
4116 "CRC_Err CCK/11g/11n/11n-Agg",
4117 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
4118 coex_sta->crc_err_11n, coex_sta->crc_err_11n_agg);
4119 CL_PRINTF(cli_buf);
4120
4121 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4122 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4123 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4124 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
4125 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4126 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4127 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
4128 u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
4129 CL_PRINTF(cli_buf);
4130
4131 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4132 "0x770(high-pri rx/tx)",
4133 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4134 CL_PRINTF(cli_buf);
4135 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4136 "0x774(low-pri rx/tx)",
4137 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
4138 CL_PRINTF(cli_buf);
4139 #if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 1)
4140 /* halbtc8821a2ant_monitor_bt_ctr(btcoexist); */
4141 #endif
4142 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
4143 }
4144
4145
ex_halbtc8821a2ant_ips_notify(IN struct btc_coexist * btcoexist,IN u8 type)4146 void ex_halbtc8821a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4147 {
4148 if (BTC_IPS_ENTER == type) {
4149 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4150 "[BTCoex], IPS ENTER notify\n");
4151 BTC_TRACE(trace_buf);
4152 coex_sta->under_ips = true;
4153 halbtc8821a2ant_wifi_off_hw_cfg(btcoexist);
4154 halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4155 halbtc8821a2ant_coex_all_off(btcoexist);
4156 } else if (BTC_IPS_LEAVE == type) {
4157 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4158 "[BTCoex], IPS LEAVE notify\n");
4159 BTC_TRACE(trace_buf);
4160 coex_sta->under_ips = false;
4161 halbtc8821a2ant_init_hw_config(btcoexist, false);
4162 halbtc8821a2ant_init_coex_dm(btcoexist);
4163 halbtc8821a2ant_query_bt_info(btcoexist);
4164 }
4165 }
4166
ex_halbtc8821a2ant_lps_notify(IN struct btc_coexist * btcoexist,IN u8 type)4167 void ex_halbtc8821a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4168 {
4169 if (BTC_LPS_ENABLE == type) {
4170 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4171 "[BTCoex], LPS ENABLE notify\n");
4172 BTC_TRACE(trace_buf);
4173 coex_sta->under_lps = true;
4174 } else if (BTC_LPS_DISABLE == type) {
4175 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4176 "[BTCoex], LPS DISABLE notify\n");
4177 BTC_TRACE(trace_buf);
4178 coex_sta->under_lps = false;
4179 }
4180 }
4181
ex_halbtc8821a2ant_scan_notify(IN struct btc_coexist * btcoexist,IN u8 type)4182 void ex_halbtc8821a2ant_scan_notify(IN struct btc_coexist *btcoexist,
4183 IN u8 type)
4184 {
4185 u8 u8tmpa, u8tmpb;
4186
4187 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
4188 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
4189
4190 if (BTC_SCAN_START == type) {
4191 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4192 "[BTCoex], SCAN START notify\n");
4193 BTC_TRACE(trace_buf);
4194 } else if (BTC_SCAN_FINISH == type) {
4195 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4196 "[BTCoex], SCAN FINISH notify\n");
4197 BTC_TRACE(trace_buf);
4198 }
4199
4200 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4201 "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa,
4202 u8tmpb);
4203 BTC_TRACE(trace_buf);
4204 }
4205
ex_halbtc8821a2ant_connect_notify(IN struct btc_coexist * btcoexist,IN u8 type)4206 void ex_halbtc8821a2ant_connect_notify(IN struct btc_coexist *btcoexist,
4207 IN u8 type)
4208 {
4209 if (BTC_ASSOCIATE_START == type) {
4210 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4211 "[BTCoex], CONNECT START notify\n");
4212 BTC_TRACE(trace_buf);
4213 } else if (BTC_ASSOCIATE_FINISH == type) {
4214 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4215 "[BTCoex], CONNECT FINISH notify\n");
4216 BTC_TRACE(trace_buf);
4217 }
4218 }
4219
ex_halbtc8821a2ant_media_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)4220 void ex_halbtc8821a2ant_media_status_notify(IN struct btc_coexist *btcoexist,
4221 IN u8 type)
4222 {
4223 u8 h2c_parameter[3] = {0};
4224 u32 wifi_bw;
4225 u8 wifi_central_chnl;
4226 u8 ap_num = 0;
4227
4228 if (BTC_MEDIA_CONNECT == type) {
4229 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4230 "[BTCoex], MEDIA connect notify\n");
4231 BTC_TRACE(trace_buf);
4232 } else {
4233 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4234 "[BTCoex], MEDIA disconnect notify\n");
4235 BTC_TRACE(trace_buf);
4236 }
4237
4238 /* only 2.4G we need to inform bt the chnl mask */
4239 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
4240 &wifi_central_chnl);
4241 if ((BTC_MEDIA_CONNECT == type) &&
4242 (wifi_central_chnl <= 14)) {
4243 h2c_parameter[0] = 0x1;
4244 h2c_parameter[1] = wifi_central_chnl;
4245 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
4246 if (BTC_WIFI_BW_HT40 == wifi_bw)
4247 h2c_parameter[2] = 0x30;
4248 else {
4249 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
4250 &ap_num);
4251 if (ap_num < 10)
4252 h2c_parameter[2] = 0x30;
4253 else
4254 h2c_parameter[2] = 0x20;
4255 }
4256 }
4257
4258 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
4259 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
4260 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
4261
4262 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
4263 }
4264
ex_halbtc8821a2ant_specific_packet_notify(IN struct btc_coexist * btcoexist,IN u8 type)4265 void ex_halbtc8821a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
4266 IN u8 type)
4267 {
4268 if (type == BTC_PACKET_DHCP) {
4269 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4270 "[BTCoex], DHCP Packet notify\n");
4271 BTC_TRACE(trace_buf);
4272 }
4273 }
4274
ex_halbtc8821a2ant_bt_info_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)4275 void ex_halbtc8821a2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
4276 IN u8 *tmp_buf, IN u8 length)
4277 {
4278 u8 bt_info = 0;
4279 u8 i, rsp_source = 0;
4280 boolean bt_busy = false, limited_dig = false;
4281 boolean wifi_connected = false, wifi_under_5g = false;
4282
4283 coex_sta->c2h_bt_info_req_sent = false;
4284 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4285 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4286 &wifi_connected);
4287
4288 rsp_source = tmp_buf[0] & 0xf;
4289 if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX)
4290 rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
4291 coex_sta->bt_info_c2h_cnt[rsp_source]++;
4292
4293 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4294 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
4295 length);
4296 BTC_TRACE(trace_buf);
4297 for (i = 0; i < length; i++) {
4298 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
4299 if (i == 1)
4300 bt_info = tmp_buf[i];
4301 if (i == length - 1) {
4302 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
4303 tmp_buf[i]);
4304 BTC_TRACE(trace_buf);
4305 } else {
4306 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
4307 tmp_buf[i]);
4308 BTC_TRACE(trace_buf);
4309 }
4310 }
4311
4312 if (btcoexist->manual_control) {
4313 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4314 "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
4315 BTC_TRACE(trace_buf);
4316 return;
4317 }
4318
4319 /* if 0xff, it means BT is under WHCK test */
4320 if (bt_info == 0xff)
4321 coex_sta->bt_whck_test = true;
4322 else
4323 coex_sta->bt_whck_test = false;
4324
4325 if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) {
4326 coex_sta->bt_retry_cnt = /* [3:0] */
4327 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
4328
4329 coex_sta->bt_rssi =
4330 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4331
4332 coex_sta->bt_info_ext =
4333 coex_sta->bt_info_c2h[rsp_source][4];
4334
4335 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
4336 & 0x40);
4337 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
4338 &coex_sta->bt_tx_rx_mask);
4339 if (coex_sta->bt_tx_rx_mask) {
4340 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */
4341 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4342 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n");
4343 BTC_TRACE(trace_buf);
4344 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
4345 0x3c, 0x01);
4346 }
4347
4348 /* Here we need to resend some wifi info to BT */
4349 /* because bt is reset and loss of the info. */
4350 if ((coex_sta->bt_info_ext & BIT(1))) {
4351 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4352 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
4353 BTC_TRACE(trace_buf);
4354 if (wifi_connected)
4355 ex_halbtc8821a2ant_media_status_notify(
4356 btcoexist, BTC_MEDIA_CONNECT);
4357 else
4358 ex_halbtc8821a2ant_media_status_notify(
4359 btcoexist, BTC_MEDIA_DISCONNECT);
4360 }
4361
4362
4363 if (!btcoexist->manual_control && !wifi_under_5g) {
4364 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4365 "[BTCoex], BT ext info = 0x%x!!\n",
4366 coex_sta->bt_info_ext);
4367 BTC_TRACE(trace_buf);
4368 if ((coex_sta->bt_info_ext & BIT(3))) {
4369 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4370 "[BTCoex], BT ext info bit3=1, wifi_connected=%d\n",
4371 wifi_connected);
4372 BTC_TRACE(trace_buf);
4373 if (wifi_connected) {
4374 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4375 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4376 BTC_TRACE(trace_buf);
4377 halbtc8821a2ant_ignore_wlan_act(
4378 btcoexist, FORCE_EXEC, false);
4379 }
4380 } else {
4381 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4382 "[BTCoex], BT ext info bit3=0, wifi_connected=%d\n",
4383 wifi_connected);
4384 BTC_TRACE(trace_buf);
4385 /* BT already NOT ignore Wlan active, do nothing here. */
4386 if (!wifi_connected) {
4387 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4388 "[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n");
4389 BTC_TRACE(trace_buf);
4390 halbtc8821a2ant_ignore_wlan_act(
4391 btcoexist, FORCE_EXEC, true);
4392 }
4393 }
4394 }
4395
4396 #if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)
4397 if ((coex_sta->bt_info_ext & BIT(4))) {
4398 /* BT auto report already enabled, do nothing */
4399 } else
4400 halbtc8821a2ant_bt_auto_report(btcoexist, FORCE_EXEC,
4401 true);
4402 #endif
4403 }
4404
4405 /* check BIT2 first ==> check if bt is under inquiry or page scan */
4406 if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE)
4407 coex_sta->c2h_bt_inquiry_page = true;
4408 else
4409 coex_sta->c2h_bt_inquiry_page = false;
4410
4411 /* set link exist status */
4412 if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
4413 coex_sta->bt_link_exist = false;
4414 coex_sta->pan_exist = false;
4415 coex_sta->a2dp_exist = false;
4416 coex_sta->hid_exist = false;
4417 coex_sta->sco_exist = false;
4418 } else { /* connection exists */
4419 coex_sta->bt_link_exist = true;
4420 if (bt_info & BT_INFO_8821A_2ANT_B_FTP)
4421 coex_sta->pan_exist = true;
4422 else
4423 coex_sta->pan_exist = false;
4424 if (bt_info & BT_INFO_8821A_2ANT_B_A2DP)
4425 coex_sta->a2dp_exist = true;
4426 else
4427 coex_sta->a2dp_exist = false;
4428 if (bt_info & BT_INFO_8821A_2ANT_B_HID)
4429 coex_sta->hid_exist = true;
4430 else
4431 coex_sta->hid_exist = false;
4432 if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO)
4433 coex_sta->sco_exist = true;
4434 else
4435 coex_sta->sco_exist = false;
4436
4437 if ((coex_sta->hid_exist == false) &&
4438 (coex_sta->c2h_bt_inquiry_page == false) &&
4439 (coex_sta->sco_exist == false)) {
4440 if (coex_sta->high_priority_tx +
4441 coex_sta->high_priority_rx >= 160)
4442 coex_sta->hid_exist = true;
4443 }
4444 }
4445
4446 halbtc8821a2ant_update_bt_link_info(btcoexist);
4447
4448 if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
4449 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
4450 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4451 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4452 BTC_TRACE(trace_buf);
4453 } else if (bt_info ==
4454 BT_INFO_8821A_2ANT_B_CONNECTION) { /* connection exists but no busy */
4455 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE;
4456 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4457 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4458 BTC_TRACE(trace_buf);
4459 } else if ((bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO) ||
4460 (bt_info & BT_INFO_8821A_2ANT_B_SCO_BUSY)) {
4461 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_SCO_BUSY;
4462 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4463 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4464 BTC_TRACE(trace_buf);
4465 } else if (bt_info & BT_INFO_8821A_2ANT_B_ACL_BUSY) {
4466 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_ACL_BUSY;
4467 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4468 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4469 BTC_TRACE(trace_buf);
4470 } else {
4471 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_MAX;
4472 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4473 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4474 BTC_TRACE(trace_buf);
4475 }
4476
4477 if ((BT_8821A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
4478 (BT_8821A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
4479 (BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
4480 bt_busy = true;
4481 limited_dig = true;
4482 } else {
4483 bt_busy = false;
4484 limited_dig = false;
4485 }
4486
4487 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
4488
4489 coex_dm->limited_dig = limited_dig;
4490 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
4491
4492 halbtc8821a2ant_run_coexist_mechanism(btcoexist);
4493 }
4494
ex_halbtc8821a2ant_halt_notify(IN struct btc_coexist * btcoexist)4495 void ex_halbtc8821a2ant_halt_notify(IN struct btc_coexist *btcoexist)
4496 {
4497 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
4498 BTC_TRACE(trace_buf);
4499
4500 halbtc8821a2ant_wifi_off_hw_cfg(btcoexist);
4501 /* remove due to interrupt is disabled that polling c2h will fail and delay 100ms. */
4502 /* btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0 */
4503 halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4504
4505 ex_halbtc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
4506 }
4507
ex_halbtc8821a2ant_pnp_notify(IN struct btc_coexist * btcoexist,IN u8 pnp_state)4508 void ex_halbtc8821a2ant_pnp_notify(IN struct btc_coexist *btcoexist,
4509 IN u8 pnp_state)
4510 {
4511 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
4512 BTC_TRACE(trace_buf);
4513
4514 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
4515 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4516 "[BTCoex], Pnp notify to SLEEP\n");
4517 BTC_TRACE(trace_buf);
4518 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
4519 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4520 "[BTCoex], Pnp notify to WAKE UP\n");
4521 BTC_TRACE(trace_buf);
4522 halbtc8821a2ant_init_hw_config(btcoexist, false);
4523 halbtc8821a2ant_init_coex_dm(btcoexist);
4524 halbtc8821a2ant_query_bt_info(btcoexist);
4525 }
4526 }
4527
ex_halbtc8821a2ant_periodical(IN struct btc_coexist * btcoexist)4528 void ex_halbtc8821a2ant_periodical(IN struct btc_coexist *btcoexist)
4529 {
4530 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4531 "[BTCoex], ==========================Periodical===========================\n");
4532 BTC_TRACE(trace_buf);
4533
4534 if (coex_sta->dis_ver_info_cnt <= 5) {
4535 coex_sta->dis_ver_info_cnt += 1;
4536 if (coex_sta->dis_ver_info_cnt == 3) {
4537 /* Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial */
4538 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4539 "[BTCoex], Set GNT_BT control by PTA\n");
4540 BTC_TRACE(trace_buf);
4541 halbtc8821a2ant_set_ant_path(btcoexist,
4542 BTC_ANT_WIFI_AT_MAIN, false, false);
4543 }
4544 }
4545
4546 #if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)
4547 halbtc8821a2ant_query_bt_info(btcoexist);
4548 halbtc8821a2ant_monitor_bt_enable_disable(btcoexist);
4549 #else
4550 halbtc8821a2ant_monitor_bt_ctr(btcoexist);
4551 halbtc8821a2ant_monitor_wifi_ctr(btcoexist);
4552
4553 if (halbtc8821a2ant_is_wifi_status_changed(btcoexist) ||
4554 coex_dm->auto_tdma_adjust)
4555 halbtc8821a2ant_run_coexist_mechanism(btcoexist);
4556 #endif
4557 }
4558
4559 #endif
4560
4561 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */