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