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