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