1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
31 #include "../rtl8723com/phy_common.h"
33 static struct bt_coexist_8723 hal_coex_8723
;
35 void rtl8723e_dm_bt_turn_off_bt_coexist_before_enter_lps(struct ieee80211_hw
*hw
)
37 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
38 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
40 if (!rtlpriv
->btcoexist
.bt_coexistence
)
43 if (ppsc
->inactiveps
) {
44 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
45 "[BT][DM], Before enter IPS, turn off all Coexist DM\n");
46 rtlpriv
->btcoexist
.cstate
= 0;
47 rtlpriv
->btcoexist
.previous_state
= 0;
48 rtlpriv
->btcoexist
.cstate_h
= 0;
49 rtlpriv
->btcoexist
.previous_state_h
= 0;
50 rtl8723e_btdm_coex_all_off(hw
);
54 static enum rt_media_status
mgnt_link_status_query(struct ieee80211_hw
*hw
)
56 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
57 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
58 enum rt_media_status m_status
= RT_MEDIA_DISCONNECT
;
59 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
60 if (bibss
|| rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
)
61 m_status
= RT_MEDIA_CONNECT
;
66 void rtl_8723e_bt_wifi_media_status_notify(struct ieee80211_hw
*hw
,
69 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
70 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
71 u8 h2c_parameter
[3] = {0};
74 if (!rtlpriv
->btcoexist
.bt_coexistence
)
77 if (RT_MEDIA_CONNECT
== mstatus
)
78 h2c_parameter
[0] = 0x1; /* 0: disconnected, 1:connected */
80 h2c_parameter
[0] = 0x0;
82 if (mgnt_link_status_query(hw
)) {
83 chnl
= rtlphy
->current_channel
;
84 h2c_parameter
[1] = chnl
;
87 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
)
88 h2c_parameter
[2] = 0x30;
90 h2c_parameter
[2] = 0x20;
92 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
93 "[BTCoex], FW write 0x19=0x%x\n",
94 h2c_parameter
[0]<<16|h2c_parameter
[1]<<8|h2c_parameter
[2]);
96 rtl8723e_fill_h2c_cmd(hw
, 0x19, 3, h2c_parameter
);
99 static bool rtl8723e_dm_bt_is_wifi_busy(struct ieee80211_hw
*hw
)
101 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
102 if (rtlpriv
->link_info
.busytraffic
||
103 rtlpriv
->link_info
.rx_busy_traffic
||
104 rtlpriv
->link_info
.tx_busy_traffic
)
110 static void rtl8723e_dm_bt_set_fw_3a(struct ieee80211_hw
*hw
,
111 u8 byte1
, u8 byte2
, u8 byte3
, u8 byte4
,
114 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
117 h2c_parameter
[0] = byte1
;
118 h2c_parameter
[1] = byte2
;
119 h2c_parameter
[2] = byte3
;
120 h2c_parameter
[3] = byte4
;
121 h2c_parameter
[4] = byte5
;
122 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
123 "[BTCoex], FW write 0x3a(4bytes)=0x%x%8x\n",
124 h2c_parameter
[0], h2c_parameter
[1]<<24 |
125 h2c_parameter
[2]<<16 | h2c_parameter
[3]<<8 |
127 rtl8723e_fill_h2c_cmd(hw
, 0x3a, 5, h2c_parameter
);
130 static bool rtl8723e_dm_bt_need_to_dec_bt_pwr(struct ieee80211_hw
*hw
)
132 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
134 if (mgnt_link_status_query(hw
) == RT_MEDIA_CONNECT
) {
135 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
136 "Need to decrease bt power\n");
137 rtlpriv
->btcoexist
.cstate
|=
138 BT_COEX_STATE_DEC_BT_POWER
;
142 rtlpriv
->btcoexist
.cstate
&= ~BT_COEX_STATE_DEC_BT_POWER
;
146 static bool rtl8723e_dm_bt_is_same_coexist_state(struct ieee80211_hw
*hw
)
148 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
150 if ((rtlpriv
->btcoexist
.previous_state
==
151 rtlpriv
->btcoexist
.cstate
) &&
152 (rtlpriv
->btcoexist
.previous_state_h
==
153 rtlpriv
->btcoexist
.cstate_h
)) {
154 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
155 "[DM][BT], Coexist state do not chang!!\n");
158 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
159 "[DM][BT], Coexist state changed!!\n");
164 static void rtl8723e_dm_bt_set_coex_table(struct ieee80211_hw
*hw
,
165 u32 val_0x6c0
, u32 val_0x6c8
,
168 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
170 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
171 "set coex table, set 0x6c0=0x%x\n", val_0x6c0
);
172 rtl_write_dword(rtlpriv
, 0x6c0, val_0x6c0
);
174 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
175 "set coex table, set 0x6c8=0x%x\n", val_0x6c8
);
176 rtl_write_dword(rtlpriv
, 0x6c8, val_0x6c8
);
178 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
179 "set coex table, set 0x6cc=0x%x\n", val_0x6cc
);
180 rtl_write_byte(rtlpriv
, 0x6cc, val_0x6cc
);
183 static void rtl8723e_dm_bt_set_hw_pta_mode(struct ieee80211_hw
*hw
, bool b_mode
)
185 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
187 if (BT_PTA_MODE_ON
== b_mode
) {
188 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
, "PTA mode on, ");
189 /* Enable GPIO 0/1/2/3/8 pins for bt */
190 rtl_write_byte(rtlpriv
, 0x40, 0x20);
191 rtlpriv
->btcoexist
.hw_coexist_all_off
= false;
193 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
, "PTA mode off\n");
194 rtl_write_byte(rtlpriv
, 0x40, 0x0);
198 static void rtl8723e_dm_bt_set_sw_rf_rx_lpf_corner(struct ieee80211_hw
*hw
,
201 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
203 if (BT_RF_RX_LPF_CORNER_SHRINK
== type
) {
204 /* Shrink RF Rx LPF corner, 0x1e[7:4]=1111 ==> [11:4] */
205 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
206 "Shrink RF Rx LPF corner!!\n");
207 rtl8723e_phy_set_rf_reg(hw
, RF90_PATH_A
, 0x1e,
209 rtlpriv
->btcoexist
.sw_coexist_all_off
= false;
210 } else if (BT_RF_RX_LPF_CORNER_RESUME
== type
) {
211 /*Resume RF Rx LPF corner*/
212 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
213 "Resume RF Rx LPF corner!!\n");
214 rtl8723e_phy_set_rf_reg(hw
, RF90_PATH_A
, 0x1e, 0xfffff,
215 rtlpriv
->btcoexist
.bt_rfreg_origin_1e
);
219 static void dm_bt_set_sw_penalty_tx_rate_adapt(struct ieee80211_hw
*hw
,
222 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
225 tmp_u1
= rtl_read_byte(rtlpriv
, 0x4fd);
227 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY
== ra_type
) {
228 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
229 "Tx rate adaptive, set low penalty!!\n");
231 rtlpriv
->btcoexist
.sw_coexist_all_off
= false;
232 } else if (BT_TX_RATE_ADAPTIVE_NORMAL
== ra_type
) {
233 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
234 "Tx rate adaptive, set normal!!\n");
238 rtl_write_byte(rtlpriv
, 0x4fd, tmp_u1
);
241 static void rtl8723e_dm_bt_btdm_structure_reload(struct ieee80211_hw
*hw
,
242 struct btdm_8723
*btdm
)
244 btdm
->all_off
= false;
245 btdm
->agc_table_en
= false;
246 btdm
->adc_back_off_on
= false;
247 btdm
->b2_ant_hid_en
= false;
248 btdm
->low_penalty_rate_adaptive
= false;
249 btdm
->rf_rx_lpf_shrink
= false;
250 btdm
->reject_aggre_pkt
= false;
252 btdm
->tdma_on
= false;
253 btdm
->tdma_ant
= TDMA_2ANT
;
254 btdm
->tdma_nav
= TDMA_NAV_OFF
;
255 btdm
->tdma_dac_swing
= TDMA_DAC_SWING_OFF
;
256 btdm
->fw_dac_swing_lvl
= 0x20;
258 btdm
->tra_tdma_on
= false;
259 btdm
->tra_tdma_ant
= TDMA_2ANT
;
260 btdm
->tra_tdma_nav
= TDMA_NAV_OFF
;
261 btdm
->ignore_wlan_act
= false;
263 btdm
->ps_tdma_on
= false;
264 btdm
->ps_tdma_byte
[0] = 0x0;
265 btdm
->ps_tdma_byte
[1] = 0x0;
266 btdm
->ps_tdma_byte
[2] = 0x0;
267 btdm
->ps_tdma_byte
[3] = 0x8;
268 btdm
->ps_tdma_byte
[4] = 0x0;
271 btdm
->val_0x6c0
= 0x5a5aaaaa;
272 btdm
->val_0x6c8
= 0xcc;
273 btdm
->val_0x6cc
= 0x3;
275 btdm
->sw_dac_swing_on
= false;
276 btdm
->sw_dac_swing_lvl
= 0xc0;
277 btdm
->wlan_act_hi
= 0x20;
278 btdm
->wlan_act_lo
= 0x10;
279 btdm
->bt_retry_index
= 2;
281 btdm
->dec_bt_pwr
= false;
284 static void rtl8723e_dm_bt_btdm_structure_reload_all_off(struct ieee80211_hw
*hw
,
285 struct btdm_8723
*btdm
)
287 rtl8723e_dm_bt_btdm_structure_reload(hw
, btdm
);
288 btdm
->all_off
= true;
289 btdm
->pta_on
= false;
290 btdm
->wlan_act_hi
= 0x10;
293 static bool rtl8723e_dm_bt_is_2_ant_common_action(struct ieee80211_hw
*hw
)
295 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
296 struct btdm_8723 btdm8723
;
297 bool b_common
= false;
299 rtl8723e_dm_bt_btdm_structure_reload(hw
, &btdm8723
);
301 if (!rtl8723e_dm_bt_is_wifi_busy(hw
) &&
302 !rtlpriv
->btcoexist
.bt_busy
) {
303 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
304 "Wifi idle + Bt idle, bt coex mechanism always off!!\n");
305 rtl8723e_dm_bt_btdm_structure_reload_all_off(hw
, &btdm8723
);
307 } else if (rtl8723e_dm_bt_is_wifi_busy(hw
) &&
308 !rtlpriv
->btcoexist
.bt_busy
) {
309 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
310 "Wifi non-idle + Bt disabled/idle!!\n");
311 btdm8723
.low_penalty_rate_adaptive
= true;
312 btdm8723
.rf_rx_lpf_shrink
= false;
313 btdm8723
.reject_aggre_pkt
= false;
316 btdm8723
.agc_table_en
= false;
317 btdm8723
.adc_back_off_on
= false;
318 btdm8723
.sw_dac_swing_on
= false;
320 btdm8723
.pta_on
= true;
321 btdm8723
.val_0x6c0
= 0x5a5aaaaa;
322 btdm8723
.val_0x6c8
= 0xcccc;
323 btdm8723
.val_0x6cc
= 0x3;
325 btdm8723
.tdma_on
= false;
326 btdm8723
.tdma_dac_swing
= TDMA_DAC_SWING_OFF
;
327 btdm8723
.b2_ant_hid_en
= false;
330 } else if (rtlpriv
->btcoexist
.bt_busy
) {
331 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
333 if (mgnt_link_status_query(hw
) == RT_MEDIA_CONNECT
) {
334 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
335 "Wifi connection exist\n");
338 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
339 "No Wifi connection!\n");
340 btdm8723
.rf_rx_lpf_shrink
= true;
341 btdm8723
.low_penalty_rate_adaptive
= false;
342 btdm8723
.reject_aggre_pkt
= false;
345 btdm8723
.agc_table_en
= false;
346 btdm8723
.adc_back_off_on
= false;
347 btdm8723
.sw_dac_swing_on
= false;
349 btdm8723
.pta_on
= true;
350 btdm8723
.val_0x6c0
= 0x55555555;
351 btdm8723
.val_0x6c8
= 0x0000ffff;
352 btdm8723
.val_0x6cc
= 0x3;
354 btdm8723
.tdma_on
= false;
355 btdm8723
.tdma_dac_swing
= TDMA_DAC_SWING_OFF
;
356 btdm8723
.b2_ant_hid_en
= false;
362 if (rtl8723e_dm_bt_need_to_dec_bt_pwr(hw
))
363 btdm8723
.dec_bt_pwr
= true;
366 rtlpriv
->btcoexist
.cstate
|=
367 BT_COEX_STATE_BTINFO_COMMON
;
369 if (b_common
&& rtl8723e_dm_bt_is_coexist_state_changed(hw
))
370 rtl8723e_dm_bt_set_bt_dm(hw
, &btdm8723
);
375 static void rtl8723e_dm_bt_set_sw_full_time_dac_swing(
376 struct ieee80211_hw
*hw
,
377 bool sw_dac_swing_on
,
378 u32 sw_dac_swing_lvl
)
380 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
382 if (sw_dac_swing_on
) {
383 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
384 "[BTCoex], SwDacSwing = 0x%x\n", sw_dac_swing_lvl
);
385 rtl8723_phy_set_bb_reg(hw
, 0x880, 0xff000000,
387 rtlpriv
->btcoexist
.sw_coexist_all_off
= false;
389 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
390 "[BTCoex], SwDacSwing Off!\n");
391 rtl8723_phy_set_bb_reg(hw
, 0x880, 0xff000000, 0xc0);
395 static void rtl8723e_dm_bt_set_fw_dec_bt_pwr(
396 struct ieee80211_hw
*hw
, bool dec_bt_pwr
)
398 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
399 u8 h2c_parameter
[1] = {0};
401 h2c_parameter
[0] = 0;
404 h2c_parameter
[0] |= BIT(1);
405 rtlpriv
->btcoexist
.fw_coexist_all_off
= false;
408 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
409 "[BTCoex], decrease Bt Power : %s, write 0x21=0x%x\n",
410 (dec_bt_pwr
? "Yes!!" : "No!!"), h2c_parameter
[0]);
412 rtl8723e_fill_h2c_cmd(hw
, 0x21, 1, h2c_parameter
);
415 static void rtl8723e_dm_bt_set_fw_2_ant_hid(struct ieee80211_hw
*hw
,
416 bool b_enable
, bool b_dac_swing_on
)
418 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
419 u8 h2c_parameter
[1] = {0};
422 h2c_parameter
[0] |= BIT(0);
423 rtlpriv
->btcoexist
.fw_coexist_all_off
= false;
426 h2c_parameter
[0] |= BIT(1); /* Dac Swing default enable */
428 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
429 "[BTCoex], turn 2-Ant+HID mode %s, DACSwing:%s, write 0x15=0x%x\n",
430 (b_enable
? "ON!!" : "OFF!!"), (b_dac_swing_on
? "ON" : "OFF"),
433 rtl8723e_fill_h2c_cmd(hw
, 0x15, 1, h2c_parameter
);
436 static void rtl8723e_dm_bt_set_fw_tdma_ctrl(struct ieee80211_hw
*hw
,
437 bool b_enable
, u8 ant_num
,
438 u8 nav_en
, u8 dac_swing_en
)
440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
441 u8 h2c_parameter
[1] = {0};
442 u8 h2c_parameter1
[1] = {0};
444 h2c_parameter
[0] = 0;
445 h2c_parameter1
[0] = 0;
448 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
449 "[BTCoex], set BT PTA update manager to trigger update!!\n");
450 h2c_parameter1
[0] |= BIT(0);
452 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
453 "[BTCoex], turn TDMA mode ON!!\n");
454 h2c_parameter
[0] |= BIT(0); /* function enable */
455 if (TDMA_1ANT
== ant_num
) {
456 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
457 "[BTCoex], TDMA_1ANT\n");
458 h2c_parameter
[0] |= BIT(1);
459 } else if (TDMA_2ANT
== ant_num
) {
460 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
461 "[BTCoex], TDMA_2ANT\n");
463 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
464 "[BTCoex], Unknown Ant\n");
467 if (TDMA_NAV_OFF
== nav_en
) {
468 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
469 "[BTCoex], TDMA_NAV_OFF\n");
470 } else if (TDMA_NAV_ON
== nav_en
) {
471 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
472 "[BTCoex], TDMA_NAV_ON\n");
473 h2c_parameter
[0] |= BIT(2);
476 if (TDMA_DAC_SWING_OFF
== dac_swing_en
) {
477 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
478 "[BTCoex], TDMA_DAC_SWING_OFF\n");
479 } else if (TDMA_DAC_SWING_ON
== dac_swing_en
) {
480 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
481 "[BTCoex], TDMA_DAC_SWING_ON\n");
482 h2c_parameter
[0] |= BIT(4);
484 rtlpriv
->btcoexist
.fw_coexist_all_off
= false;
486 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
487 "[BTCoex], set BT PTA update manager to no update!!\n");
488 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
489 "[BTCoex], turn TDMA mode OFF!!\n");
492 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
493 "[BTCoex], FW2AntTDMA, write 0x26=0x%x\n",
495 rtl8723e_fill_h2c_cmd(hw
, 0x26, 1, h2c_parameter1
);
497 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
498 "[BTCoex], FW2AntTDMA, write 0x14=0x%x\n",
500 rtl8723e_fill_h2c_cmd(hw
, 0x14, 1, h2c_parameter
);
503 static void rtl8723e_dm_bt_set_fw_ignore_wlan_act(struct ieee80211_hw
*hw
,
506 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
507 u8 h2c_parameter
[1] = {0};
510 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
511 "[BTCoex], BT Ignore Wlan_Act !!\n");
512 h2c_parameter
[0] |= BIT(0); /* function enable */
513 rtlpriv
->btcoexist
.fw_coexist_all_off
= false;
515 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
516 "[BTCoex], BT don't ignore Wlan_Act !!\n");
519 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
520 "[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25=0x%x\n",
523 rtl8723e_fill_h2c_cmd(hw
, 0x25, 1, h2c_parameter
);
526 static void rtl8723e_dm_bt_set_fw_tra_tdma_ctrl(struct ieee80211_hw
*hw
,
527 bool b_enable
, u8 ant_num
,
530 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
531 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
533 u8 h2c_parameter
[2] = {0};
535 /* Only 8723 B cut should do this */
536 if (IS_VENDOR_8723_A_CUT(rtlhal
->version
)) {
537 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
538 "[BTCoex], not 8723B cut, don't set Traditional TDMA!!\n");
543 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
544 "[BTCoex], turn TTDMA mode ON!!\n");
545 h2c_parameter
[0] |= BIT(0); /* function enable */
546 if (TDMA_1ANT
== ant_num
) {
547 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
548 "[BTCoex], TTDMA_1ANT\n");
549 h2c_parameter
[0] |= BIT(1);
550 } else if (TDMA_2ANT
== ant_num
) {
551 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
552 "[BTCoex], TTDMA_2ANT\n");
554 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
555 "[BTCoex], Unknown Ant\n");
558 if (TDMA_NAV_OFF
== nav_en
) {
559 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
560 "[BTCoex], TTDMA_NAV_OFF\n");
561 } else if (TDMA_NAV_ON
== nav_en
) {
562 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
563 "[BTCoex], TTDMA_NAV_ON\n");
564 h2c_parameter
[1] |= BIT(0);
567 rtlpriv
->btcoexist
.fw_coexist_all_off
= false;
569 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
570 "[BTCoex], turn TTDMA mode OFF!!\n");
573 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
574 "[BTCoex], FW Traditional TDMA, write 0x33=0x%x\n",
575 h2c_parameter
[0] << 8 | h2c_parameter
[1]);
577 rtl8723e_fill_h2c_cmd(hw
, 0x33, 2, h2c_parameter
);
580 static void rtl8723e_dm_bt_set_fw_dac_swing_level(struct ieee80211_hw
*hw
,
583 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
584 u8 h2c_parameter
[1] = {0};
585 h2c_parameter
[0] = dac_swing_lvl
;
587 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
588 "[BTCoex], Set Dac Swing Level=0x%x\n", dac_swing_lvl
);
589 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
590 "[BTCoex], write 0x29=0x%x\n", h2c_parameter
[0]);
592 rtl8723e_fill_h2c_cmd(hw
, 0x29, 1, h2c_parameter
);
595 static void rtl8723e_dm_bt_set_fw_bt_hid_info(struct ieee80211_hw
*hw
,
598 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
599 u8 h2c_parameter
[1] = {0};
600 h2c_parameter
[0] = 0;
603 h2c_parameter
[0] |= BIT(0);
604 rtlpriv
->btcoexist
.fw_coexist_all_off
= false;
606 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
607 "[BTCoex], Set BT HID information=0x%x\n", b_enable
);
608 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
609 "[BTCoex], write 0x24=0x%x\n", h2c_parameter
[0]);
611 rtl8723e_fill_h2c_cmd(hw
, 0x24, 1, h2c_parameter
);
614 static void rtl8723e_dm_bt_set_fw_bt_retry_index(struct ieee80211_hw
*hw
,
617 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
618 u8 h2c_parameter
[1] = {0};
619 h2c_parameter
[0] = retry_index
;
621 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
622 "[BTCoex], Set BT Retry Index=%d\n", retry_index
);
623 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
624 "[BTCoex], write 0x23=0x%x\n", h2c_parameter
[0]);
626 rtl8723e_fill_h2c_cmd(hw
, 0x23, 1, h2c_parameter
);
629 static void rtl8723e_dm_bt_set_fw_wlan_act(struct ieee80211_hw
*hw
,
630 u8 wlan_act_hi
, u8 wlan_act_lo
)
632 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
633 u8 h2c_parameter_hi
[1] = {0};
634 u8 h2c_parameter_lo
[1] = {0};
635 h2c_parameter_hi
[0] = wlan_act_hi
;
636 h2c_parameter_lo
[0] = wlan_act_lo
;
638 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
639 "[BTCoex], Set WLAN_ACT Hi:Lo=0x%x/0x%x\n",
640 wlan_act_hi
, wlan_act_lo
);
641 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
642 "[BTCoex], write 0x22=0x%x\n", h2c_parameter_hi
[0]);
643 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
644 "[BTCoex], write 0x11=0x%x\n", h2c_parameter_lo
[0]);
646 /* WLAN_ACT = High duration, unit:ms */
647 rtl8723e_fill_h2c_cmd(hw
, 0x22, 1, h2c_parameter_hi
);
648 /* WLAN_ACT = Low duration, unit:3*625us */
649 rtl8723e_fill_h2c_cmd(hw
, 0x11, 1, h2c_parameter_lo
);
652 void rtl8723e_dm_bt_set_bt_dm(struct ieee80211_hw
*hw
,
653 struct btdm_8723
*btdm
)
655 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
656 struct btdm_8723
*btdm_8723
= &hal_coex_8723
.btdm
;
659 bool fw_current_inpsmode
= false;
660 bool fw_ps_awake
= true;
662 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
663 (u8
*)(&fw_current_inpsmode
));
664 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_FWLPS_RF_ON
,
665 (u8
*)(&fw_ps_awake
));
667 /* check new setting is different with the old one, */
668 /* if all the same, don't do the setting again. */
669 if (memcmp(btdm_8723
, btdm
, sizeof(struct btdm_8723
)) == 0) {
670 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
671 "[BTCoex], the same coexist setting, return!!\n");
673 } else { /* save the new coexist setting */
674 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
675 "[BTCoex], UPDATE TO NEW COEX SETTING!!\n");
676 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
677 "[BTCoex], original/new bAllOff=0x%x/ 0x%x\n",
678 btdm_8723
->all_off
, btdm
->all_off
);
679 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
680 "[BTCoex], original/new agc_table_en=0x%x/ 0x%x\n",
681 btdm_8723
->agc_table_en
, btdm
->agc_table_en
);
682 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
683 "[BTCoex], original/new adc_back_off_on=0x%x/ 0x%x\n",
684 btdm_8723
->adc_back_off_on
,
685 btdm
->adc_back_off_on
);
686 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
687 "[BTCoex], original/new b2_ant_hid_en=0x%x/ 0x%x\n",
688 btdm_8723
->b2_ant_hid_en
, btdm
->b2_ant_hid_en
);
689 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
690 "[BTCoex], original/new bLowPenaltyRateAdaptive=0x%x/ 0x%x\n",
691 btdm_8723
->low_penalty_rate_adaptive
,
692 btdm
->low_penalty_rate_adaptive
);
693 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
694 "[BTCoex], original/new bRfRxLpfShrink=0x%x/ 0x%x\n",
695 btdm_8723
->rf_rx_lpf_shrink
,
696 btdm
->rf_rx_lpf_shrink
);
697 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
698 "[BTCoex], original/new bRejectAggrePkt=0x%x/ 0x%x\n",
699 btdm_8723
->reject_aggre_pkt
,
700 btdm
->reject_aggre_pkt
);
701 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
702 "[BTCoex], original/new tdma_on=0x%x/ 0x%x\n",
703 btdm_8723
->tdma_on
, btdm
->tdma_on
);
704 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
705 "[BTCoex], original/new tdmaAnt=0x%x/ 0x%x\n",
706 btdm_8723
->tdma_ant
, btdm
->tdma_ant
);
707 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
708 "[BTCoex], original/new tdmaNav=0x%x/ 0x%x\n",
709 btdm_8723
->tdma_nav
, btdm
->tdma_nav
);
710 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
711 "[BTCoex], original/new tdma_dac_swing=0x%x/ 0x%x\n",
712 btdm_8723
->tdma_dac_swing
, btdm
->tdma_dac_swing
);
713 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
714 "[BTCoex], original/new fw_dac_swing_lvl=0x%x/ 0x%x\n",
715 btdm_8723
->fw_dac_swing_lvl
,
716 btdm
->fw_dac_swing_lvl
);
718 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
719 "[BTCoex], original/new bTraTdmaOn=0x%x/ 0x%x\n",
720 btdm_8723
->tra_tdma_on
, btdm
->tra_tdma_on
);
721 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
722 "[BTCoex], original/new traTdmaAnt=0x%x/ 0x%x\n",
723 btdm_8723
->tra_tdma_ant
, btdm
->tra_tdma_ant
);
724 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
725 "[BTCoex], original/new traTdmaNav=0x%x/ 0x%x\n",
726 btdm_8723
->tra_tdma_nav
, btdm
->tra_tdma_nav
);
727 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
728 "[BTCoex], original/new bPsTdmaOn=0x%x/ 0x%x\n",
729 btdm_8723
->ps_tdma_on
, btdm
->ps_tdma_on
);
730 for (i
= 0; i
< 5; i
++) {
731 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
732 "[BTCoex], original/new psTdmaByte[i]=0x%x/ 0x%x\n",
733 btdm_8723
->ps_tdma_byte
[i
],
734 btdm
->ps_tdma_byte
[i
]);
736 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
737 "[BTCoex], original/new bIgnoreWlanAct=0x%x/ 0x%x\n",
738 btdm_8723
->ignore_wlan_act
,
739 btdm
->ignore_wlan_act
);
742 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
743 "[BTCoex], original/new bPtaOn=0x%x/ 0x%x\n",
744 btdm_8723
->pta_on
, btdm
->pta_on
);
745 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
746 "[BTCoex], original/new val_0x6c0=0x%x/ 0x%x\n",
747 btdm_8723
->val_0x6c0
, btdm
->val_0x6c0
);
748 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
749 "[BTCoex], original/new val_0x6c8=0x%x/ 0x%x\n",
750 btdm_8723
->val_0x6c8
, btdm
->val_0x6c8
);
751 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
752 "[BTCoex], original/new val_0x6cc=0x%x/ 0x%x\n",
753 btdm_8723
->val_0x6cc
, btdm
->val_0x6cc
);
754 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
755 "[BTCoex], original/new sw_dac_swing_on=0x%x/ 0x%x\n",
756 btdm_8723
->sw_dac_swing_on
,
757 btdm
->sw_dac_swing_on
);
758 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
759 "[BTCoex], original/new sw_dac_swing_lvl=0x%x/ 0x%x\n",
760 btdm_8723
->sw_dac_swing_lvl
,
761 btdm
->sw_dac_swing_lvl
);
762 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
763 "[BTCoex], original/new wlanActHi=0x%x/ 0x%x\n",
764 btdm_8723
->wlan_act_hi
, btdm
->wlan_act_hi
);
765 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
766 "[BTCoex], original/new wlanActLo=0x%x/ 0x%x\n",
767 btdm_8723
->wlan_act_lo
, btdm
->wlan_act_lo
);
768 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
769 "[BTCoex], original/new btRetryIndex=0x%x/ 0x%x\n",
770 btdm_8723
->bt_retry_index
, btdm
->bt_retry_index
);
772 memcpy(btdm_8723
, btdm
, sizeof(struct btdm_8723
));
774 /* Here we only consider when Bt Operation
775 * inquiry/paging/pairing is ON
776 * we only need to turn off TDMA
779 if (rtlpriv
->btcoexist
.hold_for_bt_operation
) {
780 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
781 "[BTCoex], set to ignore wlanAct for BT OP!!\n");
782 rtl8723e_dm_bt_set_fw_ignore_wlan_act(hw
, true);
787 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
788 "[BTCoex], disable all coexist mechanism !!\n");
789 rtl8723e_btdm_coex_all_off(hw
);
793 rtl8723e_dm_bt_reject_ap_aggregated_packet(hw
, btdm
->reject_aggre_pkt
);
795 if (btdm
->low_penalty_rate_adaptive
)
796 dm_bt_set_sw_penalty_tx_rate_adapt(hw
, BT_TX_RATE_ADAPTIVE_LOW_PENALTY
);
798 dm_bt_set_sw_penalty_tx_rate_adapt(hw
,
799 BT_TX_RATE_ADAPTIVE_NORMAL
);
801 if (btdm
->rf_rx_lpf_shrink
)
802 rtl8723e_dm_bt_set_sw_rf_rx_lpf_corner(hw
,
803 BT_RF_RX_LPF_CORNER_SHRINK
);
805 rtl8723e_dm_bt_set_sw_rf_rx_lpf_corner(hw
,
806 BT_RF_RX_LPF_CORNER_RESUME
);
808 if (btdm
->agc_table_en
)
809 rtl8723e_dm_bt_agc_table(hw
, BT_AGCTABLE_ON
);
811 rtl8723e_dm_bt_agc_table(hw
, BT_AGCTABLE_OFF
);
813 if (btdm
->adc_back_off_on
)
814 rtl8723e_dm_bt_bb_back_off_level(hw
, BT_BB_BACKOFF_ON
);
816 rtl8723e_dm_bt_bb_back_off_level(hw
, BT_BB_BACKOFF_OFF
);
818 rtl8723e_dm_bt_set_fw_bt_retry_index(hw
, btdm
->bt_retry_index
);
820 rtl8723e_dm_bt_set_fw_dac_swing_level(hw
, btdm
->fw_dac_swing_lvl
);
821 rtl8723e_dm_bt_set_fw_wlan_act(hw
, btdm
->wlan_act_hi
,
824 rtl8723e_dm_bt_set_coex_table(hw
, btdm
->val_0x6c0
,
825 btdm
->val_0x6c8
, btdm
->val_0x6cc
);
826 rtl8723e_dm_bt_set_hw_pta_mode(hw
, btdm
->pta_on
);
828 /* Note: There is a constraint between TDMA and 2AntHID
829 * Only one of 2AntHid and tdma can be turn on
830 * We should turn off those mechanisms should be turned off first
831 * and then turn on those mechanisms should be turned on.
833 if (btdm
->b2_ant_hid_en
) {
835 rtl8723e_dm_bt_set_fw_tra_tdma_ctrl(hw
, btdm
->tra_tdma_on
,
838 rtl8723e_dm_bt_set_fw_tdma_ctrl(hw
, false, btdm
->tdma_ant
,
840 btdm
->tdma_dac_swing
);
842 /* turn off Pstdma */
843 rtl8723e_dm_bt_set_fw_ignore_wlan_act(hw
,
844 btdm
->ignore_wlan_act
);
845 /* Antenna control by PTA, 0x870 = 0x300. */
846 rtl8723e_dm_bt_set_fw_3a(hw
, 0x0, 0x0, 0x0, 0x8, 0x0);
848 /* turn on 2AntHid */
849 rtl8723e_dm_bt_set_fw_bt_hid_info(hw
, true);
850 rtl8723e_dm_bt_set_fw_2_ant_hid(hw
, true, true);
851 } else if (btdm
->tdma_on
) {
852 /* turn off 2AntHid */
853 rtl8723e_dm_bt_set_fw_bt_hid_info(hw
, false);
854 rtl8723e_dm_bt_set_fw_2_ant_hid(hw
, false, false);
856 /* turn off pstdma */
857 rtl8723e_dm_bt_set_fw_ignore_wlan_act(hw
,
858 btdm
->ignore_wlan_act
);
859 /* Antenna control by PTA, 0x870 = 0x300. */
860 rtl8723e_dm_bt_set_fw_3a(hw
, 0x0, 0x0, 0x0, 0x8, 0x0);
863 rtl8723e_dm_bt_set_fw_tra_tdma_ctrl(hw
, btdm
->tra_tdma_on
,
866 rtl8723e_dm_bt_set_fw_tdma_ctrl(hw
, true, btdm
->tdma_ant
,
868 btdm
->tdma_dac_swing
);
869 } else if (btdm
->ps_tdma_on
) {
870 /* turn off 2AntHid */
871 rtl8723e_dm_bt_set_fw_bt_hid_info(hw
, false);
872 rtl8723e_dm_bt_set_fw_2_ant_hid(hw
, false, false);
875 rtl8723e_dm_bt_set_fw_tra_tdma_ctrl(hw
, btdm
->tra_tdma_on
,
878 rtl8723e_dm_bt_set_fw_tdma_ctrl(hw
, false, btdm
->tdma_ant
,
880 btdm
->tdma_dac_swing
);
883 rtl8723e_dm_bt_set_fw_ignore_wlan_act(hw
,
884 btdm
->ignore_wlan_act
);
885 rtl8723e_dm_bt_set_fw_3a(hw
, btdm
->ps_tdma_byte
[0],
886 btdm
->ps_tdma_byte
[1],
887 btdm
->ps_tdma_byte
[2],
888 btdm
->ps_tdma_byte
[3],
889 btdm
->ps_tdma_byte
[4]);
891 /* turn off 2AntHid */
892 rtl8723e_dm_bt_set_fw_bt_hid_info(hw
, false);
893 rtl8723e_dm_bt_set_fw_2_ant_hid(hw
, false, false);
896 rtl8723e_dm_bt_set_fw_tra_tdma_ctrl(hw
, btdm
->tra_tdma_on
,
899 rtl8723e_dm_bt_set_fw_tdma_ctrl(hw
, false, btdm
->tdma_ant
,
901 btdm
->tdma_dac_swing
);
903 /* turn off pstdma */
904 rtl8723e_dm_bt_set_fw_ignore_wlan_act(hw
,
905 btdm
->ignore_wlan_act
);
906 /* Antenna control by PTA, 0x870 = 0x300. */
907 rtl8723e_dm_bt_set_fw_3a(hw
, 0x0, 0x0, 0x0, 0x8, 0x0);
911 * We should add delay for making sure
912 * sw DacSwing can be set sucessfully.
913 * because of that rtl8723e_dm_bt_set_fw_2_ant_hid()
914 * and rtl8723e_dm_bt_set_fw_tdma_ctrl()
915 * will overwrite the reg 0x880.
918 rtl8723e_dm_bt_set_sw_full_time_dac_swing(hw
, btdm
->sw_dac_swing_on
,
919 btdm
->sw_dac_swing_lvl
);
920 rtl8723e_dm_bt_set_fw_dec_bt_pwr(hw
, btdm
->dec_bt_pwr
);
923 /* ============================================================ */
924 /* extern function start with BTDM_ */
925 /* ============================================================i
927 static u32
rtl8723e_dm_bt_tx_rx_couter_h(struct ieee80211_hw
*hw
)
931 counters
= hal_coex_8723
.high_priority_tx
+
932 hal_coex_8723
.high_priority_rx
;
936 static u32
rtl8723e_dm_bt_tx_rx_couter_l(struct ieee80211_hw
*hw
)
940 counters
= hal_coex_8723
.low_priority_tx
+
941 hal_coex_8723
.low_priority_rx
;
945 static u8
rtl8723e_dm_bt_bt_tx_rx_counter_level(struct ieee80211_hw
*hw
)
947 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
948 u32 bt_tx_rx_cnt
= 0;
949 u8 bt_tx_rx_cnt_lvl
= 0;
951 bt_tx_rx_cnt
= rtl8723e_dm_bt_tx_rx_couter_h(hw
)
952 + rtl8723e_dm_bt_tx_rx_couter_l(hw
);
953 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
954 "[BTCoex], BT TxRx Counters = %d\n", bt_tx_rx_cnt
);
956 rtlpriv
->btcoexist
.cstate_h
&= ~
957 (BT_COEX_STATE_BT_CNT_LEVEL_0
| BT_COEX_STATE_BT_CNT_LEVEL_1
|
958 BT_COEX_STATE_BT_CNT_LEVEL_2
);
960 if (bt_tx_rx_cnt
>= BT_TXRX_CNT_THRES_3
) {
961 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
962 "[BTCoex], BT TxRx Counters at level 3\n");
963 bt_tx_rx_cnt_lvl
= BT_TXRX_CNT_LEVEL_3
;
964 rtlpriv
->btcoexist
.cstate_h
|=
965 BT_COEX_STATE_BT_CNT_LEVEL_3
;
966 } else if (bt_tx_rx_cnt
>= BT_TXRX_CNT_THRES_2
) {
967 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
968 "[BTCoex], BT TxRx Counters at level 2\n");
969 bt_tx_rx_cnt_lvl
= BT_TXRX_CNT_LEVEL_2
;
970 rtlpriv
->btcoexist
.cstate_h
|=
971 BT_COEX_STATE_BT_CNT_LEVEL_2
;
972 } else if (bt_tx_rx_cnt
>= BT_TXRX_CNT_THRES_1
) {
973 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
974 "[BTCoex], BT TxRx Counters at level 1\n");
975 bt_tx_rx_cnt_lvl
= BT_TXRX_CNT_LEVEL_1
;
976 rtlpriv
->btcoexist
.cstate_h
|=
977 BT_COEX_STATE_BT_CNT_LEVEL_1
;
979 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
980 "[BTCoex], BT TxRx Counters at level 0\n");
981 bt_tx_rx_cnt_lvl
= BT_TXRX_CNT_LEVEL_0
;
982 rtlpriv
->btcoexist
.cstate_h
|=
983 BT_COEX_STATE_BT_CNT_LEVEL_0
;
985 return bt_tx_rx_cnt_lvl
;
988 static void rtl8723e_dm_bt_2_ant_hid_sco_esco(struct ieee80211_hw
*hw
)
990 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
991 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
992 struct btdm_8723 btdm8723
;
993 u8 bt_rssi_state
, bt_rssi_state1
;
994 u8 bt_tx_rx_cnt_lvl
= 0;
996 rtl8723e_dm_bt_btdm_structure_reload(hw
, &btdm8723
);
998 btdm8723
.rf_rx_lpf_shrink
= true;
999 btdm8723
.low_penalty_rate_adaptive
= true;
1000 btdm8723
.reject_aggre_pkt
= false;
1002 bt_tx_rx_cnt_lvl
= rtl8723e_dm_bt_bt_tx_rx_counter_level(hw
);
1003 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1004 "[BTCoex], BT TxRx Counters = %d\n", bt_tx_rx_cnt_lvl
);
1006 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
1007 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
, "HT40\n");
1009 btdm8723
.val_0x6c0
= 0x55555555;
1010 btdm8723
.val_0x6c8
= 0xffff;
1011 btdm8723
.val_0x6cc
= 0x3;
1014 btdm8723
.agc_table_en
= false;
1015 btdm8723
.adc_back_off_on
= false;
1016 btdm8723
.sw_dac_swing_on
= false;
1019 btdm8723
.ps_tdma_on
= true;
1020 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1021 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1022 "[BTCoex], BT TxRx Counters >= 1400\n");
1023 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1024 btdm8723
.ps_tdma_byte
[1] = 0x5;
1025 btdm8723
.ps_tdma_byte
[2] = 0x5;
1026 btdm8723
.ps_tdma_byte
[3] = 0x2;
1027 btdm8723
.ps_tdma_byte
[4] = 0x80;
1028 } else if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_1
) {
1029 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1030 "[BTCoex], BT TxRx Counters >= 1200 && < 1400\n");
1031 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1032 btdm8723
.ps_tdma_byte
[1] = 0xa;
1033 btdm8723
.ps_tdma_byte
[2] = 0xa;
1034 btdm8723
.ps_tdma_byte
[3] = 0x2;
1035 btdm8723
.ps_tdma_byte
[4] = 0x80;
1037 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1038 "[BTCoex], BT TxRx Counters < 1200\n");
1039 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1040 btdm8723
.ps_tdma_byte
[1] = 0xf;
1041 btdm8723
.ps_tdma_byte
[2] = 0xf;
1042 btdm8723
.ps_tdma_byte
[3] = 0x2;
1043 btdm8723
.ps_tdma_byte
[4] = 0x80;
1046 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1047 "HT20 or Legacy\n");
1049 rtl8723e_dm_bt_check_coex_rssi_state(hw
, 2, 47, 0);
1051 rtl8723e_dm_bt_check_coex_rssi_state1(hw
, 2, 27, 0);
1054 btdm8723
.val_0x6c0
= 0x55555555;
1055 btdm8723
.val_0x6c8
= 0xffff;
1056 btdm8723
.val_0x6cc
= 0x3;
1059 if ((bt_rssi_state
== BT_RSSI_STATE_HIGH
) ||
1060 (bt_rssi_state
== BT_RSSI_STATE_STAY_HIGH
)) {
1061 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1062 "Wifi rssi high\n");
1063 btdm8723
.agc_table_en
= true;
1064 btdm8723
.adc_back_off_on
= true;
1065 btdm8723
.sw_dac_swing_on
= false;
1067 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1069 btdm8723
.agc_table_en
= false;
1070 btdm8723
.adc_back_off_on
= false;
1071 btdm8723
.sw_dac_swing_on
= false;
1075 btdm8723
.ps_tdma_on
= true;
1076 if ((bt_rssi_state1
== BT_RSSI_STATE_HIGH
) ||
1077 (bt_rssi_state1
== BT_RSSI_STATE_STAY_HIGH
)) {
1078 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1079 "Wifi rssi-1 high\n");
1080 /* only rssi high we need to do this, */
1081 /* when rssi low, the value will modified by fw */
1082 rtl_write_byte(rtlpriv
, 0x883, 0x40);
1083 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1084 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1085 "[BTCoex], BT TxRx Counters >= 1400\n");
1086 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1087 btdm8723
.ps_tdma_byte
[1] = 0x5;
1088 btdm8723
.ps_tdma_byte
[2] = 0x5;
1089 btdm8723
.ps_tdma_byte
[3] = 0x83;
1090 btdm8723
.ps_tdma_byte
[4] = 0x80;
1091 } else if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_1
) {
1092 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1093 "[BTCoex], BT TxRx Counters>= 1200 && < 1400\n");
1094 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1095 btdm8723
.ps_tdma_byte
[1] = 0xa;
1096 btdm8723
.ps_tdma_byte
[2] = 0xa;
1097 btdm8723
.ps_tdma_byte
[3] = 0x83;
1098 btdm8723
.ps_tdma_byte
[4] = 0x80;
1100 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1101 "[BTCoex], BT TxRx Counters < 1200\n");
1102 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1103 btdm8723
.ps_tdma_byte
[1] = 0xf;
1104 btdm8723
.ps_tdma_byte
[2] = 0xf;
1105 btdm8723
.ps_tdma_byte
[3] = 0x83;
1106 btdm8723
.ps_tdma_byte
[4] = 0x80;
1109 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1110 "Wifi rssi-1 low\n");
1111 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1112 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1113 "[BTCoex], BT TxRx Counters >= 1400\n");
1114 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1115 btdm8723
.ps_tdma_byte
[1] = 0x5;
1116 btdm8723
.ps_tdma_byte
[2] = 0x5;
1117 btdm8723
.ps_tdma_byte
[3] = 0x2;
1118 btdm8723
.ps_tdma_byte
[4] = 0x80;
1119 } else if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_1
) {
1120 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1121 "[BTCoex], BT TxRx Counters >= 1200 && < 1400\n");
1122 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1123 btdm8723
.ps_tdma_byte
[1] = 0xa;
1124 btdm8723
.ps_tdma_byte
[2] = 0xa;
1125 btdm8723
.ps_tdma_byte
[3] = 0x2;
1126 btdm8723
.ps_tdma_byte
[4] = 0x80;
1128 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1129 "[BTCoex], BT TxRx Counters < 1200\n");
1130 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1131 btdm8723
.ps_tdma_byte
[1] = 0xf;
1132 btdm8723
.ps_tdma_byte
[2] = 0xf;
1133 btdm8723
.ps_tdma_byte
[3] = 0x2;
1134 btdm8723
.ps_tdma_byte
[4] = 0x80;
1139 if (rtl8723e_dm_bt_need_to_dec_bt_pwr(hw
))
1140 btdm8723
.dec_bt_pwr
= true;
1142 /* Always ignore WlanAct if bHid|bSCOBusy|bSCOeSCO */
1144 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1145 "[BTCoex], BT btInqPageStartTime = 0x%x, btTxRxCntLvl = %d\n",
1146 hal_coex_8723
.bt_inq_page_start_time
, bt_tx_rx_cnt_lvl
);
1147 if ((hal_coex_8723
.bt_inq_page_start_time
) ||
1148 (BT_TXRX_CNT_LEVEL_3
== bt_tx_rx_cnt_lvl
)) {
1149 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1150 "[BTCoex], Set BT inquiry / page scan 0x3a setting\n");
1151 btdm8723
.ps_tdma_on
= true;
1152 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1153 btdm8723
.ps_tdma_byte
[1] = 0x5;
1154 btdm8723
.ps_tdma_byte
[2] = 0x5;
1155 btdm8723
.ps_tdma_byte
[3] = 0x2;
1156 btdm8723
.ps_tdma_byte
[4] = 0x80;
1159 if (rtl8723e_dm_bt_is_coexist_state_changed(hw
))
1160 rtl8723e_dm_bt_set_bt_dm(hw
, &btdm8723
);
1164 static void rtl8723e_dm_bt_2_ant_ftp_a2dp(struct ieee80211_hw
*hw
)
1166 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1167 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1168 struct btdm_8723 btdm8723
;
1170 u8 bt_rssi_state
, bt_rssi_state1
;
1171 u32 bt_tx_rx_cnt_lvl
= 0;
1173 rtl8723e_dm_bt_btdm_structure_reload(hw
, &btdm8723
);
1175 btdm8723
.rf_rx_lpf_shrink
= true;
1176 btdm8723
.low_penalty_rate_adaptive
= true;
1177 btdm8723
.reject_aggre_pkt
= false;
1179 bt_tx_rx_cnt_lvl
= rtl8723e_dm_bt_bt_tx_rx_counter_level(hw
);
1181 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1182 "[BTCoex], BT TxRx Counters = %d\n", bt_tx_rx_cnt_lvl
);
1184 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
1185 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
, "HT40\n");
1187 rtl8723e_dm_bt_check_coex_rssi_state(hw
, 2, 37, 0);
1190 btdm8723
.val_0x6c0
= 0x55555555;
1191 btdm8723
.val_0x6c8
= 0xffff;
1192 btdm8723
.val_0x6cc
= 0x3;
1195 btdm8723
.agc_table_en
= false;
1196 btdm8723
.adc_back_off_on
= true;
1197 btdm8723
.sw_dac_swing_on
= false;
1200 btdm8723
.ps_tdma_on
= true;
1201 if ((bt_rssi_state
== BT_RSSI_STATE_HIGH
) ||
1202 (bt_rssi_state
== BT_RSSI_STATE_STAY_HIGH
)) {
1203 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1204 "Wifi rssi high\n");
1205 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1206 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1207 "[BTCoex], BT TxRx Counters >= 1400\n");
1208 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1209 btdm8723
.ps_tdma_byte
[1] = 0x5;
1210 btdm8723
.ps_tdma_byte
[2] = 0x5;
1211 btdm8723
.ps_tdma_byte
[3] = 0x81;
1212 btdm8723
.ps_tdma_byte
[4] = 0x80;
1213 } else if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_1
) {
1214 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1215 "[BTCoex], BT TxRx Counters >= 1200 && < 1400\n");
1216 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1217 btdm8723
.ps_tdma_byte
[1] = 0xa;
1218 btdm8723
.ps_tdma_byte
[2] = 0xa;
1219 btdm8723
.ps_tdma_byte
[3] = 0x81;
1220 btdm8723
.ps_tdma_byte
[4] = 0x80;
1222 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1223 "[BTCoex], BT TxRx Counters < 1200\n");
1224 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1225 btdm8723
.ps_tdma_byte
[1] = 0xf;
1226 btdm8723
.ps_tdma_byte
[2] = 0xf;
1227 btdm8723
.ps_tdma_byte
[3] = 0x81;
1228 btdm8723
.ps_tdma_byte
[4] = 0x80;
1231 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1233 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1234 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1235 "[BTCoex], BT TxRx Counters >= 1400\n");
1236 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1237 btdm8723
.ps_tdma_byte
[1] = 0x5;
1238 btdm8723
.ps_tdma_byte
[2] = 0x5;
1239 btdm8723
.ps_tdma_byte
[3] = 0x0;
1240 btdm8723
.ps_tdma_byte
[4] = 0x80;
1241 } else if (bt_tx_rx_cnt_lvl
==
1242 BT_TXRX_CNT_LEVEL_1
) {
1243 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1244 "[BTCoex], BT TxRx Counters >= 1200 && < 1400\n");
1245 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1246 btdm8723
.ps_tdma_byte
[1] = 0xa;
1247 btdm8723
.ps_tdma_byte
[2] = 0xa;
1248 btdm8723
.ps_tdma_byte
[3] = 0x0;
1249 btdm8723
.ps_tdma_byte
[4] = 0x80;
1251 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1252 "[BTCoex], BT TxRx Counters < 1200\n");
1253 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1254 btdm8723
.ps_tdma_byte
[1] = 0xf;
1255 btdm8723
.ps_tdma_byte
[2] = 0xf;
1256 btdm8723
.ps_tdma_byte
[3] = 0x0;
1257 btdm8723
.ps_tdma_byte
[4] = 0x80;
1261 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1262 "HT20 or Legacy\n");
1264 rtl8723e_dm_bt_check_coex_rssi_state(hw
, 2, 47, 0);
1266 rtl8723e_dm_bt_check_coex_rssi_state1(hw
, 2, 27, 0);
1269 btdm8723
.val_0x6c0
= 0x55555555;
1270 btdm8723
.val_0x6c8
= 0xffff;
1271 btdm8723
.val_0x6cc
= 0x3;
1274 if ((bt_rssi_state
== BT_RSSI_STATE_HIGH
) ||
1275 (bt_rssi_state
== BT_RSSI_STATE_STAY_HIGH
)) {
1276 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1277 "Wifi rssi high\n");
1278 btdm8723
.agc_table_en
= true;
1279 btdm8723
.adc_back_off_on
= true;
1280 btdm8723
.sw_dac_swing_on
= false;
1282 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1284 btdm8723
.agc_table_en
= false;
1285 btdm8723
.adc_back_off_on
= false;
1286 btdm8723
.sw_dac_swing_on
= false;
1290 btdm8723
.ps_tdma_on
= true;
1291 if ((bt_rssi_state1
== BT_RSSI_STATE_HIGH
) ||
1292 (bt_rssi_state1
== BT_RSSI_STATE_STAY_HIGH
)) {
1293 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1294 "Wifi rssi-1 high\n");
1295 /* only rssi high we need to do this, */
1296 /* when rssi low, the value will modified by fw */
1297 rtl_write_byte(rtlpriv
, 0x883, 0x40);
1298 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1299 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1300 "[BTCoex], BT TxRx Counters >= 1400\n");
1301 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1302 btdm8723
.ps_tdma_byte
[1] = 0x5;
1303 btdm8723
.ps_tdma_byte
[2] = 0x5;
1304 btdm8723
.ps_tdma_byte
[3] = 0x81;
1305 btdm8723
.ps_tdma_byte
[4] = 0x80;
1306 } else if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_1
) {
1307 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1308 "[BTCoex], BT TxRx Counters >= 1200 && < 1400\n");
1309 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1310 btdm8723
.ps_tdma_byte
[1] = 0xa;
1311 btdm8723
.ps_tdma_byte
[2] = 0xa;
1312 btdm8723
.ps_tdma_byte
[3] = 0x81;
1313 btdm8723
.ps_tdma_byte
[4] = 0x80;
1315 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1316 "[BTCoex], BT TxRx Counters < 1200\n");
1317 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1318 btdm8723
.ps_tdma_byte
[1] = 0xf;
1319 btdm8723
.ps_tdma_byte
[2] = 0xf;
1320 btdm8723
.ps_tdma_byte
[3] = 0x81;
1321 btdm8723
.ps_tdma_byte
[4] = 0x80;
1324 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1325 "Wifi rssi-1 low\n");
1326 if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_2
) {
1327 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1328 "[BTCoex], BT TxRx Counters >= 1400\n");
1329 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1330 btdm8723
.ps_tdma_byte
[1] = 0x5;
1331 btdm8723
.ps_tdma_byte
[2] = 0x5;
1332 btdm8723
.ps_tdma_byte
[3] = 0x0;
1333 btdm8723
.ps_tdma_byte
[4] = 0x80;
1334 } else if (bt_tx_rx_cnt_lvl
== BT_TXRX_CNT_LEVEL_1
) {
1335 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1336 "[BTCoex], BT TxRx Counters >= 1200 && < 1400\n");
1337 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1338 btdm8723
.ps_tdma_byte
[1] = 0xa;
1339 btdm8723
.ps_tdma_byte
[2] = 0xa;
1340 btdm8723
.ps_tdma_byte
[3] = 0x0;
1341 btdm8723
.ps_tdma_byte
[4] = 0x80;
1343 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1344 "[BTCoex], BT TxRx Counters < 1200\n");
1345 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1346 btdm8723
.ps_tdma_byte
[1] = 0xf;
1347 btdm8723
.ps_tdma_byte
[2] = 0xf;
1348 btdm8723
.ps_tdma_byte
[3] = 0x0;
1349 btdm8723
.ps_tdma_byte
[4] = 0x80;
1354 if (rtl8723e_dm_bt_need_to_dec_bt_pwr(hw
))
1355 btdm8723
.dec_bt_pwr
= true;
1357 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1358 "[BTCoex], BT btInqPageStartTime = 0x%x, btTxRxCntLvl = %d\n",
1359 hal_coex_8723
.bt_inq_page_start_time
, bt_tx_rx_cnt_lvl
);
1361 if ((hal_coex_8723
.bt_inq_page_start_time
) ||
1362 (BT_TXRX_CNT_LEVEL_3
== bt_tx_rx_cnt_lvl
)) {
1363 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1364 "[BTCoex], Set BT inquiry / page scan 0x3a setting\n");
1365 btdm8723
.ps_tdma_on
= true;
1366 btdm8723
.ps_tdma_byte
[0] = 0xa3;
1367 btdm8723
.ps_tdma_byte
[1] = 0x5;
1368 btdm8723
.ps_tdma_byte
[2] = 0x5;
1369 btdm8723
.ps_tdma_byte
[3] = 0x83;
1370 btdm8723
.ps_tdma_byte
[4] = 0x80;
1373 if (rtl8723e_dm_bt_is_coexist_state_changed(hw
))
1374 rtl8723e_dm_bt_set_bt_dm(hw
, &btdm8723
);
1378 static void rtl8723e_dm_bt_inq_page_monitor(struct ieee80211_hw
*hw
)
1380 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1384 if (hal_coex_8723
.c2h_bt_inquiry_page
) {
1385 /* bt inquiry or page is started. */
1386 if (hal_coex_8723
.bt_inq_page_start_time
== 0) {
1387 rtlpriv
->btcoexist
.cstate
|=
1388 BT_COEX_STATE_BT_INQ_PAGE
;
1389 hal_coex_8723
.bt_inq_page_start_time
= cur_time
;
1390 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1391 "[BTCoex], BT Inquiry/page is started at time : 0x%x\n",
1392 hal_coex_8723
.bt_inq_page_start_time
);
1395 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1396 "[BTCoex], BT Inquiry/page started time : 0x%x, cur_time : 0x%x\n",
1397 hal_coex_8723
.bt_inq_page_start_time
, cur_time
);
1399 if (hal_coex_8723
.bt_inq_page_start_time
) {
1400 if ((((long)cur_time
-
1401 (long)hal_coex_8723
.bt_inq_page_start_time
) / HZ
)
1403 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1404 "[BTCoex], BT Inquiry/page >= 10sec!!!");
1405 hal_coex_8723
.bt_inq_page_start_time
= 0;
1406 rtlpriv
->btcoexist
.cstate
&=
1407 ~BT_COEX_STATE_BT_INQ_PAGE
;
1412 static void rtl8723e_dm_bt_reset_action_profile_state(struct ieee80211_hw
*hw
)
1414 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1416 rtlpriv
->btcoexist
.cstate
&= ~
1417 (BT_COEX_STATE_PROFILE_HID
| BT_COEX_STATE_PROFILE_A2DP
|
1418 BT_COEX_STATE_PROFILE_PAN
| BT_COEX_STATE_PROFILE_SCO
);
1420 rtlpriv
->btcoexist
.cstate
&= ~
1421 (BT_COEX_STATE_BTINFO_COMMON
|
1422 BT_COEX_STATE_BTINFO_B_HID_SCOESCO
|
1423 BT_COEX_STATE_BTINFO_B_FTP_A2DP
);
1426 static void _rtl8723e_dm_bt_coexist_2_ant(struct ieee80211_hw
*hw
)
1428 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1430 u8 bt_info_original
;
1431 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1432 "[BTCoex] Get bt info by fw!!\n");
1434 _rtl8723_dm_bt_check_wifi_state(hw
);
1436 if (hal_coex_8723
.c2h_bt_info_req_sent
) {
1437 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1438 "[BTCoex] c2h for bt_info not rcvd yet!!\n");
1441 bt_retry_cnt
= hal_coex_8723
.bt_retry_cnt
;
1442 bt_info_original
= hal_coex_8723
.c2h_bt_info_original
;
1444 /* when bt inquiry or page scan, we have to set h2c 0x25 */
1445 /* ignore wlanact for continuous 4x2secs */
1446 rtl8723e_dm_bt_inq_page_monitor(hw
);
1447 rtl8723e_dm_bt_reset_action_profile_state(hw
);
1449 if (rtl8723e_dm_bt_is_2_ant_common_action(hw
)) {
1450 rtlpriv
->btcoexist
.bt_profile_case
= BT_COEX_MECH_COMMON
;
1451 rtlpriv
->btcoexist
.bt_profile_action
= BT_COEX_MECH_COMMON
;
1452 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1453 "Action 2-Ant common.\n");
1455 if ((bt_info_original
& BTINFO_B_HID
) ||
1456 (bt_info_original
& BTINFO_B_SCO_BUSY
) ||
1457 (bt_info_original
& BTINFO_B_SCO_ESCO
)) {
1458 rtlpriv
->btcoexist
.cstate
|=
1459 BT_COEX_STATE_BTINFO_B_HID_SCOESCO
;
1460 rtlpriv
->btcoexist
.bt_profile_case
=
1461 BT_COEX_MECH_HID_SCO_ESCO
;
1462 rtlpriv
->btcoexist
.bt_profile_action
=
1463 BT_COEX_MECH_HID_SCO_ESCO
;
1464 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1465 "[BTCoex], BTInfo: bHid|bSCOBusy|bSCOeSCO\n");
1466 rtl8723e_dm_bt_2_ant_hid_sco_esco(hw
);
1467 } else if ((bt_info_original
& BTINFO_B_FTP
) ||
1468 (bt_info_original
& BTINFO_B_A2DP
)) {
1469 rtlpriv
->btcoexist
.cstate
|=
1470 BT_COEX_STATE_BTINFO_B_FTP_A2DP
;
1471 rtlpriv
->btcoexist
.bt_profile_case
=
1472 BT_COEX_MECH_FTP_A2DP
;
1473 rtlpriv
->btcoexist
.bt_profile_action
=
1474 BT_COEX_MECH_FTP_A2DP
;
1475 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1476 "BTInfo: bFTP|bA2DP\n");
1477 rtl8723e_dm_bt_2_ant_ftp_a2dp(hw
);
1479 rtlpriv
->btcoexist
.cstate
|=
1480 BT_COEX_STATE_BTINFO_B_HID_SCOESCO
;
1481 rtlpriv
->btcoexist
.bt_profile_case
=
1483 rtlpriv
->btcoexist
.bt_profile_action
=
1485 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1486 "[BTCoex], BTInfo: undefined case!!!!\n");
1487 rtl8723e_dm_bt_2_ant_hid_sco_esco(hw
);
1492 static void _rtl8723e_dm_bt_coexist_1_ant(struct ieee80211_hw
*hw
)
1497 void rtl8723e_dm_bt_hw_coex_all_off_8723a(struct ieee80211_hw
*hw
)
1499 rtl8723e_dm_bt_set_coex_table(hw
, 0x5a5aaaaa, 0xcc, 0x3);
1500 rtl8723e_dm_bt_set_hw_pta_mode(hw
, true);
1503 void rtl8723e_dm_bt_fw_coex_all_off_8723a(struct ieee80211_hw
*hw
)
1505 rtl8723e_dm_bt_set_fw_ignore_wlan_act(hw
, false);
1506 rtl8723e_dm_bt_set_fw_3a(hw
, 0x0, 0x0, 0x0, 0x8, 0x0);
1507 rtl8723e_dm_bt_set_fw_2_ant_hid(hw
, false, false);
1508 rtl8723e_dm_bt_set_fw_tra_tdma_ctrl(hw
, false, TDMA_2ANT
,
1510 rtl8723e_dm_bt_set_fw_tdma_ctrl(hw
, false, TDMA_2ANT
, TDMA_NAV_OFF
,
1511 TDMA_DAC_SWING_OFF
);
1512 rtl8723e_dm_bt_set_fw_dac_swing_level(hw
, 0);
1513 rtl8723e_dm_bt_set_fw_bt_hid_info(hw
, false);
1514 rtl8723e_dm_bt_set_fw_bt_retry_index(hw
, 2);
1515 rtl8723e_dm_bt_set_fw_wlan_act(hw
, 0x10, 0x10);
1516 rtl8723e_dm_bt_set_fw_dec_bt_pwr(hw
, false);
1519 void rtl8723e_dm_bt_sw_coex_all_off_8723a(struct ieee80211_hw
*hw
)
1521 rtl8723e_dm_bt_agc_table(hw
, BT_AGCTABLE_OFF
);
1522 rtl8723e_dm_bt_bb_back_off_level(hw
, BT_BB_BACKOFF_OFF
);
1523 rtl8723e_dm_bt_reject_ap_aggregated_packet(hw
, false);
1525 dm_bt_set_sw_penalty_tx_rate_adapt(hw
, BT_TX_RATE_ADAPTIVE_NORMAL
);
1526 rtl8723e_dm_bt_set_sw_rf_rx_lpf_corner(hw
, BT_RF_RX_LPF_CORNER_RESUME
);
1527 rtl8723e_dm_bt_set_sw_full_time_dac_swing(hw
, false, 0xc0);
1530 static void rtl8723e_dm_bt_query_bt_information(struct ieee80211_hw
*hw
)
1532 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1533 u8 h2c_parameter
[1] = {0};
1535 hal_coex_8723
.c2h_bt_info_req_sent
= true;
1537 h2c_parameter
[0] |= BIT(0);
1539 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1540 "Query Bt information, write 0x38=0x%x\n", h2c_parameter
[0]);
1542 rtl8723e_fill_h2c_cmd(hw
, 0x38, 1, h2c_parameter
);
1545 static void rtl8723e_dm_bt_bt_hw_counters_monitor(struct ieee80211_hw
*hw
)
1547 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1548 u32 reg_hp_tx_rx
, reg_lp_tx_rx
, u32_tmp
;
1549 u32 reg_hp_tx
= 0, reg_hp_rx
= 0, reg_lp_tx
= 0, reg_lp_rx
= 0;
1551 reg_hp_tx_rx
= REG_HIGH_PRIORITY_TXRX
;
1552 reg_lp_tx_rx
= REG_LOW_PRIORITY_TXRX
;
1554 u32_tmp
= rtl_read_dword(rtlpriv
, reg_hp_tx_rx
);
1555 reg_hp_tx
= u32_tmp
& MASKLWORD
;
1556 reg_hp_rx
= (u32_tmp
& MASKHWORD
)>>16;
1558 u32_tmp
= rtl_read_dword(rtlpriv
, reg_lp_tx_rx
);
1559 reg_lp_tx
= u32_tmp
& MASKLWORD
;
1560 reg_lp_rx
= (u32_tmp
& MASKHWORD
)>>16;
1562 if (rtlpriv
->btcoexist
.lps_counter
> 1) {
1563 reg_hp_tx
%= rtlpriv
->btcoexist
.lps_counter
;
1564 reg_hp_rx
%= rtlpriv
->btcoexist
.lps_counter
;
1565 reg_lp_tx
%= rtlpriv
->btcoexist
.lps_counter
;
1566 reg_lp_rx
%= rtlpriv
->btcoexist
.lps_counter
;
1569 hal_coex_8723
.high_priority_tx
= reg_hp_tx
;
1570 hal_coex_8723
.high_priority_rx
= reg_hp_rx
;
1571 hal_coex_8723
.low_priority_tx
= reg_lp_tx
;
1572 hal_coex_8723
.low_priority_rx
= reg_lp_rx
;
1574 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1575 "High Priority Tx/Rx (reg 0x%x)=%x(%d)/%x(%d)\n",
1576 reg_hp_tx_rx
, reg_hp_tx
, reg_hp_tx
, reg_hp_rx
, reg_hp_rx
);
1577 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1578 "Low Priority Tx/Rx (reg 0x%x)=%x(%d)/%x(%d)\n",
1579 reg_lp_tx_rx
, reg_lp_tx
, reg_lp_tx
, reg_lp_rx
, reg_lp_rx
);
1580 rtlpriv
->btcoexist
.lps_counter
= 0;
1581 /* rtl_write_byte(rtlpriv, 0x76e, 0xc); */
1584 static void rtl8723e_dm_bt_bt_enable_disable_check(struct ieee80211_hw
*hw
)
1586 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1587 bool bt_alife
= true;
1589 if (hal_coex_8723
.high_priority_tx
== 0 &&
1590 hal_coex_8723
.high_priority_rx
== 0 &&
1591 hal_coex_8723
.low_priority_tx
== 0 &&
1592 hal_coex_8723
.low_priority_rx
== 0) {
1595 if (hal_coex_8723
.high_priority_tx
== 0xeaea &&
1596 hal_coex_8723
.high_priority_rx
== 0xeaea &&
1597 hal_coex_8723
.low_priority_tx
== 0xeaea &&
1598 hal_coex_8723
.low_priority_rx
== 0xeaea) {
1601 if (hal_coex_8723
.high_priority_tx
== 0xffff &&
1602 hal_coex_8723
.high_priority_rx
== 0xffff &&
1603 hal_coex_8723
.low_priority_tx
== 0xffff &&
1604 hal_coex_8723
.low_priority_rx
== 0xffff) {
1608 rtlpriv
->btcoexist
.bt_active_zero_cnt
= 0;
1609 rtlpriv
->btcoexist
.cur_bt_disabled
= false;
1610 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1611 "8723A BT is enabled !!\n");
1613 rtlpriv
->btcoexist
.bt_active_zero_cnt
++;
1614 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1615 "8723A bt all counters=0, %d times!!\n",
1616 rtlpriv
->btcoexist
.bt_active_zero_cnt
);
1617 if (rtlpriv
->btcoexist
.bt_active_zero_cnt
>= 2) {
1618 rtlpriv
->btcoexist
.cur_bt_disabled
= true;
1619 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1620 "8723A BT is disabled !!\n");
1623 if (rtlpriv
->btcoexist
.pre_bt_disabled
!=
1624 rtlpriv
->btcoexist
.cur_bt_disabled
) {
1625 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
1626 DBG_TRACE
, "8723A BT is from %s to %s!!\n",
1627 (rtlpriv
->btcoexist
.pre_bt_disabled
?
1628 "disabled" : "enabled"),
1629 (rtlpriv
->btcoexist
.cur_bt_disabled
?
1630 "disabled" : "enabled"));
1631 rtlpriv
->btcoexist
.pre_bt_disabled
1632 = rtlpriv
->btcoexist
.cur_bt_disabled
;
1637 void rtl8723e_dm_bt_coexist_8723(struct ieee80211_hw
*hw
)
1639 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1641 rtl8723e_dm_bt_query_bt_information(hw
);
1642 rtl8723e_dm_bt_bt_hw_counters_monitor(hw
);
1643 rtl8723e_dm_bt_bt_enable_disable_check(hw
);
1645 if (rtlpriv
->btcoexist
.bt_ant_num
== ANT_X2
) {
1646 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1647 "[BTCoex], 2 Ant mechanism\n");
1648 _rtl8723e_dm_bt_coexist_2_ant(hw
);
1650 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1651 "[BTCoex], 1 Ant mechanism\n");
1652 _rtl8723e_dm_bt_coexist_1_ant(hw
);
1655 if (!rtl8723e_dm_bt_is_same_coexist_state(hw
)) {
1656 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1657 "[BTCoex], Coexist State[bitMap] change from 0x%x%8x to 0x%x%8x\n",
1658 rtlpriv
->btcoexist
.previous_state_h
,
1659 rtlpriv
->btcoexist
.previous_state
,
1660 rtlpriv
->btcoexist
.cstate_h
,
1661 rtlpriv
->btcoexist
.cstate
);
1662 rtlpriv
->btcoexist
.previous_state
1663 = rtlpriv
->btcoexist
.cstate
;
1664 rtlpriv
->btcoexist
.previous_state_h
1665 = rtlpriv
->btcoexist
.cstate_h
;
1669 static void rtl8723e_dm_bt_parse_bt_info(struct ieee80211_hw
*hw
,
1670 u8
*tmp_buf
, u8 len
)
1672 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1676 hal_coex_8723
.c2h_bt_info_req_sent
= false;
1677 hal_coex_8723
.bt_retry_cnt
= 0;
1678 for (i
= 0; i
< len
; i
++) {
1680 hal_coex_8723
.c2h_bt_info_original
= tmp_buf
[i
];
1682 hal_coex_8723
.bt_retry_cnt
= tmp_buf
[i
];
1684 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1685 "0x%2x]", tmp_buf
[i
]);
1687 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
1688 "0x%2x, ", tmp_buf
[i
]);
1691 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1692 "BT info bt_info (Data)= 0x%x\n",
1693 hal_coex_8723
.c2h_bt_info_original
);
1694 bt_info
= hal_coex_8723
.c2h_bt_info_original
;
1696 if (bt_info
& BIT(2))
1697 hal_coex_8723
.c2h_bt_inquiry_page
= true;
1699 hal_coex_8723
.c2h_bt_inquiry_page
= false;
1702 if (bt_info
& BTINFO_B_CONNECTION
) {
1703 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1704 "[BTC2H], BTInfo: bConnect=true\n");
1705 rtlpriv
->btcoexist
.bt_busy
= true;
1706 rtlpriv
->btcoexist
.cstate
&= ~BT_COEX_STATE_BT_IDLE
;
1708 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1709 "[BTC2H], BTInfo: bConnect=false\n");
1710 rtlpriv
->btcoexist
.bt_busy
= false;
1711 rtlpriv
->btcoexist
.cstate
|= BT_COEX_STATE_BT_IDLE
;
1714 void rtl_8723e_c2h_command_handle(struct ieee80211_hw
*hw
)
1716 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1717 struct c2h_evt_hdr c2h_event
;
1718 u8
*ptmp_buf
= NULL
;
1721 memset(&c2h_event
, 0, sizeof(c2h_event
));
1722 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_C2HEVT_MSG_NORMAL
);
1723 RT_TRACE(rtlpriv
, COMP_FW
, DBG_DMESG
,
1724 "&&&&&&: REG_C2HEVT_MSG_NORMAL is 0x%x\n", u1b_tmp
);
1725 c2h_event
.cmd_id
= u1b_tmp
& 0xF;
1726 c2h_event
.cmd_len
= (u1b_tmp
& 0xF0) >> 4;
1727 c2h_event
.cmd_seq
= rtl_read_byte(rtlpriv
, REG_C2HEVT_MSG_NORMAL
+ 1);
1728 RT_TRACE(rtlpriv
, COMP_FW
, DBG_DMESG
,
1729 "cmd_id: %d, cmd_len: %d, cmd_seq: %d\n",
1730 c2h_event
.cmd_id
, c2h_event
.cmd_len
, c2h_event
.cmd_seq
);
1731 u1b_tmp
= rtl_read_byte(rtlpriv
, 0x01AF);
1732 if (u1b_tmp
== C2H_EVT_HOST_CLOSE
) {
1734 } else if (u1b_tmp
!= C2H_EVT_FW_CLOSE
) {
1735 rtl_write_byte(rtlpriv
, 0x1AF, 0x00);
1738 ptmp_buf
= kzalloc(c2h_event
.cmd_len
, GFP_KERNEL
);
1739 if (ptmp_buf
== NULL
) {
1740 RT_TRACE(rtlpriv
, COMP_FW
, DBG_TRACE
,
1741 "malloc cmd buf failed\n");
1745 /* Read the content */
1746 for (index
= 0; index
< c2h_event
.cmd_len
; index
++)
1747 ptmp_buf
[index
] = rtl_read_byte(rtlpriv
,
1748 REG_C2HEVT_MSG_NORMAL
+ 2 + index
);
1751 switch (c2h_event
.cmd_id
) {
1755 case C2H_BT_OP_MODE
:
1759 RT_TRACE(rtlpriv
, COMP_FW
, DBG_TRACE
,
1760 "BT info Byte[0] (ID) is 0x%x\n",
1762 RT_TRACE(rtlpriv
, COMP_FW
, DBG_TRACE
,
1763 "BT info Byte[1] (Seq) is 0x%x\n",
1765 RT_TRACE(rtlpriv
, COMP_FW
, DBG_TRACE
,
1766 "BT info Byte[2] (Data)= 0x%x\n", ptmp_buf
[0]);
1768 rtl8723e_dm_bt_parse_bt_info(hw
, ptmp_buf
, c2h_event
.cmd_len
);
1770 if (rtlpriv
->cfg
->ops
->get_btc_status())
1771 rtlpriv
->btcoexist
.btc_ops
->btc_periodical(rtlpriv
);
1779 rtl_write_byte(rtlpriv
, 0x01AF, C2H_EVT_HOST_CLOSE
);