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