1 /******************************************************************************
3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
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 ******************************************************************************/
26 #include "halbt_precomp.h"
28 /***********************************************
30 ***********************************************/
32 struct btc_coexist gl_bt_coexist;
34 u32 btc_dbg_type[BTC_MSG_MAX];
36 /***************************************************
37 * Debug related function
38 ***************************************************/
40 const char *const gl_btc_wifi_bw_string[] = {
48 const char *const gl_btc_wifi_freq_string[] = {
53 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
55 if (!btcoexist->binded || NULL == btcoexist->adapter)
61 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
63 if (rtlpriv->link_info.busytraffic)
69 static void halbtc_dbg_init(void)
73 /***************************************************
75 ***************************************************/
76 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
78 struct rtl_priv *rtlpriv = btcoexist->adapter;
79 struct rtl_mac *mac = rtl_mac(rtlpriv);
80 struct rtl_sta_info *drv_priv;
83 if (mac->opmode == NL80211_IFTYPE_ADHOC ||
84 mac->opmode == NL80211_IFTYPE_MESH_POINT ||
85 mac->opmode == NL80211_IFTYPE_AP) {
86 if (in_interrupt() > 0) {
87 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
92 spin_lock_bh(&rtlpriv->locks.entry_list_lock);
93 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
97 spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
106 static bool halbtc_is_bt40(struct rtl_priv *adapter)
108 struct rtl_priv *rtlpriv = adapter;
109 struct rtl_phy *rtlphy = &(rtlpriv->phy);
111 enum ht_channel_width bw = rtlphy->current_chan_bw;
113 if (bw == HT_CHANNEL_WIDTH_20)
115 else if (bw == HT_CHANNEL_WIDTH_20_40)
121 static bool halbtc_legacy(struct rtl_priv *adapter)
123 struct rtl_priv *rtlpriv = adapter;
124 struct rtl_mac *mac = rtl_mac(rtlpriv);
126 bool is_legacy = false;
128 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
134 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
136 struct rtl_priv *rtlpriv = adapter;
138 if (rtlpriv->link_info.tx_busy_traffic)
144 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
146 struct rtl_priv *rtlpriv =
147 (struct rtl_priv *)btcoexist->adapter;
148 u32 wifi_bw = BTC_WIFI_BW_HT20;
150 if (halbtc_is_bt40(rtlpriv)) {
151 wifi_bw = BTC_WIFI_BW_HT40;
153 if (halbtc_legacy(rtlpriv))
154 wifi_bw = BTC_WIFI_BW_LEGACY;
156 wifi_bw = BTC_WIFI_BW_HT20;
161 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
163 struct rtl_priv *rtlpriv = btcoexist->adapter;
164 struct rtl_phy *rtlphy = &(rtlpriv->phy);
167 if (rtlphy->current_channel != 0)
168 chnl = rtlphy->current_channel;
169 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
170 "static halbtc_get_wifi_central_chnl:%d\n", chnl);
174 u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
176 return rtlpriv->btcoexist.btc_info.single_ant_path;
179 u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
181 return rtlpriv->btcoexist.btc_info.bt_type;
184 u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
188 if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
196 u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
198 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
200 return rtlhal->package_type;
203 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
205 struct rtl_priv *rtlpriv;
206 struct rtl_ps_ctl *ppsc;
207 bool ap_enable = false;
209 rtlpriv = btcoexist->adapter;
210 ppsc = rtl_psc(rtlpriv);
212 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
216 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
217 "%s()<--dont leave lps under AP mode\n", __func__);
221 btcoexist->bt_info.bt_ctrl_lps = true;
222 btcoexist->bt_info.bt_lps_on = false;
223 rtl_lps_leave(rtlpriv->mac80211.hw);
226 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
228 struct rtl_priv *rtlpriv;
229 struct rtl_ps_ctl *ppsc;
230 bool ap_enable = false;
232 rtlpriv = btcoexist->adapter;
233 ppsc = rtl_psc(rtlpriv);
235 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
239 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
240 "%s()<--dont enter lps under AP mode\n", __func__);
244 btcoexist->bt_info.bt_ctrl_lps = true;
245 btcoexist->bt_info.bt_lps_on = true;
246 rtl_lps_enter(rtlpriv->mac80211.hw);
249 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
251 struct rtl_priv *rtlpriv;
253 rtlpriv = btcoexist->adapter;
255 if (btcoexist->bt_info.bt_ctrl_lps) {
256 btcoexist->bt_info.bt_lps_on = false;
257 rtl_lps_leave(rtlpriv->mac80211.hw);
258 btcoexist->bt_info.bt_ctrl_lps = false;
262 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
266 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
270 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
271 bool low_pwr_disable)
273 /* TODO: original/leave 32k low power */
274 btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
277 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
279 bool need_to_act = false;
280 static unsigned long pre_time;
281 unsigned long cur_time = 0;
282 struct rtl_priv *rtlpriv = btcoexist->adapter;
284 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
285 * This function is not allowed to continuous called
286 * It can only be called after 8 seconds
290 if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
291 /* over 8 seconds you can execute this function again. */
296 if (btcoexist->bt_info.reject_agg_pkt) {
298 btcoexist->bt_info.pre_reject_agg_pkt =
299 btcoexist->bt_info.reject_agg_pkt;
301 if (btcoexist->bt_info.pre_reject_agg_pkt) {
303 btcoexist->bt_info.pre_reject_agg_pkt =
304 btcoexist->bt_info.reject_agg_pkt;
307 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
308 btcoexist->bt_info.bt_ctrl_agg_buf_size) {
310 btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
311 btcoexist->bt_info.bt_ctrl_agg_buf_size;
314 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
315 if (btcoexist->bt_info.pre_agg_buf_size !=
316 btcoexist->bt_info.agg_buf_size) {
319 btcoexist->bt_info.pre_agg_buf_size =
320 btcoexist->bt_info.agg_buf_size;
324 rtl_rx_ampdu_apply(rtlpriv);
328 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
330 struct rtl_priv *rtlpriv = btcoexist->adapter;
331 u8 cmd_buffer[4] = {0};
335 if (btcoexist->bt_info.bt_real_fw_ver)
338 cmd_buffer[0] |= (oper_ver & 0x0f); /* Set OperVer */
339 cmd_buffer[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
340 cmd_buffer[1] = 0; /* BT_OP_GET_BT_VERSION = 0 */
341 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4,
345 return btcoexist->bt_info.bt_real_fw_ver;
348 u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
351 * [31:16] => connected port number
352 * [15:0] => port connected bit define
354 struct rtl_priv *rtlpriv = btcoexist->adapter;
355 struct rtl_mac *mac = rtl_mac(rtlpriv);
357 u32 port_connected_status = 0, num_of_connected_port = 0;
359 if (mac->opmode == NL80211_IFTYPE_STATION &&
360 mac->link_state >= MAC80211_LINKED) {
361 port_connected_status |= WIFI_STA_CONNECTED;
362 num_of_connected_port++;
364 /* AP & ADHOC & MESH */
365 if (is_any_client_connect_to_ap(btcoexist)) {
366 port_connected_status |= WIFI_AP_CONNECTED;
367 num_of_connected_port++;
369 /* TODO: P2P Connected Status */
371 ret_val = (num_of_connected_port << 16) | port_connected_status;
376 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
378 int undec_sm_pwdb = 0;
380 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
381 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
382 else /* associated entry pwdb */
383 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
384 return undec_sm_pwdb;
387 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
389 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
390 struct rtl_priv *rtlpriv = btcoexist->adapter;
391 struct rtl_phy *rtlphy = &(rtlpriv->phy);
392 struct rtl_mac *mac = rtl_mac(rtlpriv);
393 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
394 bool *bool_tmp = (bool *)out_buf;
395 int *s32_tmp = (int *)out_buf;
396 u32 *u32_tmp = (u32 *)out_buf;
397 u8 *u8_tmp = (u8 *)out_buf;
401 if (!halbtc_is_bt_coexist_available(btcoexist))
405 case BTC_GET_BL_HS_OPERATION:
409 case BTC_GET_BL_HS_CONNECTING:
413 case BTC_GET_BL_WIFI_CONNECTED:
414 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
415 rtlpriv->mac80211.link_state >= MAC80211_LINKED)
417 if (is_any_client_connect_to_ap(btcoexist))
421 case BTC_GET_BL_WIFI_BUSY:
422 if (halbtc_is_wifi_busy(rtlpriv))
427 case BTC_GET_BL_WIFI_SCAN:
428 if (mac->act_scanning)
433 case BTC_GET_BL_WIFI_LINK:
434 if (mac->link_state == MAC80211_LINKING)
439 case BTC_GET_BL_WIFI_ROAM:
440 if (mac->link_state == MAC80211_LINKING)
445 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
446 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
448 case BTC_GET_BL_WIFI_UNDER_5G:
449 if (rtlhal->current_bandtype == BAND_ON_5G)
454 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
455 if (mac->opmode == NL80211_IFTYPE_AP)
460 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
461 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
466 case BTC_GET_BL_WIFI_UNDER_B_MODE:
467 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
472 case BTC_GET_BL_EXT_SWITCH:
475 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
478 case BTC_GET_BL_IS_ASUS_8723B:
481 case BTC_GET_S4_WIFI_RSSI:
482 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
484 case BTC_GET_S4_HS_RSSI:
488 case BTC_GET_U4_WIFI_BW:
489 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
491 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
492 if (halbtc_is_wifi_uplink(rtlpriv))
493 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
495 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
497 case BTC_GET_U4_WIFI_FW_VER:
498 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
500 case BTC_GET_U4_WIFI_LINK_STATUS:
501 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
503 case BTC_GET_U4_BT_PATCH_VER:
504 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
506 case BTC_GET_U4_VENDOR:
507 *u32_tmp = BTC_VENDOR_OTHER;
509 case BTC_GET_U1_WIFI_DOT11_CHNL:
510 *u8_tmp = rtlphy->current_channel;
512 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
513 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
515 case BTC_GET_U1_WIFI_HS_CHNL:
519 case BTC_GET_U1_AP_NUM:
520 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
522 case BTC_GET_U1_ANT_TYPE:
523 *u8_tmp = (u8)BTC_ANT_TYPE_0;
525 case BTC_GET_U1_IOT_PEER:
529 /************* 1Ant **************/
530 case BTC_GET_U1_LPS_MODE:
531 *u8_tmp = btcoexist->pwr_mode_val[0];
542 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
544 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
545 bool *bool_tmp = (bool *)in_buf;
546 u8 *u8_tmp = (u8 *)in_buf;
547 u32 *u32_tmp = (u32 *)in_buf;
550 if (!halbtc_is_bt_coexist_available(btcoexist))
554 /* set some bool type variables. */
555 case BTC_SET_BL_BT_DISABLE:
556 btcoexist->bt_info.bt_disabled = *bool_tmp;
558 case BTC_SET_BL_BT_TRAFFIC_BUSY:
559 btcoexist->bt_info.bt_busy = *bool_tmp;
561 case BTC_SET_BL_BT_LIMITED_DIG:
562 btcoexist->bt_info.limited_dig = *bool_tmp;
564 case BTC_SET_BL_FORCE_TO_ROAM:
565 btcoexist->bt_info.force_to_roam = *bool_tmp;
567 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
568 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
570 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
571 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
573 case BTC_SET_BL_INC_SCAN_DEV_NUM:
574 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
576 case BTC_SET_BL_BT_TX_RX_MASK:
577 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
579 case BTC_SET_BL_MIRACAST_PLUS_BT:
580 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
582 /* set some u1Byte type variables. */
583 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
584 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
586 case BTC_SET_U1_AGG_BUF_SIZE:
587 btcoexist->bt_info.agg_buf_size = *u8_tmp;
590 /* the following are some action which will be triggered */
591 case BTC_SET_ACT_GET_BT_RSSI:
594 case BTC_SET_ACT_AGGREGATE_CTRL:
595 halbtc_aggregation_check(btcoexist);
599 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
600 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
602 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
604 case BTC_SET_U1_LPS_VAL:
605 btcoexist->bt_info.lps_val = *u8_tmp;
607 case BTC_SET_U1_RPWM_VAL:
608 btcoexist->bt_info.rpwm_val = *u8_tmp;
610 /* the following are some action which will be triggered */
611 case BTC_SET_ACT_LEAVE_LPS:
612 halbtc_leave_lps(btcoexist);
614 case BTC_SET_ACT_ENTER_LPS:
615 halbtc_enter_lps(btcoexist);
617 case BTC_SET_ACT_NORMAL_LPS:
618 halbtc_normal_lps(btcoexist);
620 case BTC_SET_ACT_DISABLE_LOW_POWER:
621 halbtc_disable_low_power(btcoexist, *bool_tmp);
623 case BTC_SET_ACT_UPDATE_RAMASK:
624 btcoexist->bt_info.ra_mask = *u32_tmp;
626 case BTC_SET_ACT_SEND_MIMO_PS:
628 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
630 case BTC_SET_ACT_CTRL_BT_COEX:
632 case BTC_SET_ACT_CTRL_8723B_ANT:
641 /************************************************************
642 * IO related function
643 ************************************************************/
644 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
646 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
647 struct rtl_priv *rtlpriv = btcoexist->adapter;
649 return rtl_read_byte(rtlpriv, reg_addr);
652 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
654 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
655 struct rtl_priv *rtlpriv = btcoexist->adapter;
657 return rtl_read_word(rtlpriv, reg_addr);
660 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
662 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
663 struct rtl_priv *rtlpriv = btcoexist->adapter;
665 return rtl_read_dword(rtlpriv, reg_addr);
668 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
670 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
671 struct rtl_priv *rtlpriv = btcoexist->adapter;
673 rtl_write_byte(rtlpriv, reg_addr, data);
676 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
677 u32 bit_mask, u8 data)
679 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
680 struct rtl_priv *rtlpriv = btcoexist->adapter;
681 u8 original_value, bit_shift = 0;
684 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
685 original_value = rtl_read_byte(rtlpriv, reg_addr);
686 for (i = 0; i <= 7; i++) {
687 if ((bit_mask>>i) & 0x1)
691 data = (original_value & (~bit_mask)) |
692 ((data << bit_shift) & bit_mask);
694 rtl_write_byte(rtlpriv, reg_addr, data);
697 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
699 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
700 struct rtl_priv *rtlpriv = btcoexist->adapter;
702 rtl_write_word(rtlpriv, reg_addr, data);
705 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
707 struct btc_coexist *btcoexist =
708 (struct btc_coexist *)bt_context;
709 struct rtl_priv *rtlpriv = btcoexist->adapter;
711 rtl_write_dword(rtlpriv, reg_addr, data);
714 void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr, u8 data)
716 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
717 struct rtl_priv *rtlpriv = btcoexist->adapter;
719 if (btcoexist->chip_interface == BTC_INTF_SDIO)
721 else if (btcoexist->chip_interface == BTC_INTF_PCI)
722 rtl_write_byte(rtlpriv, reg_addr, data);
723 else if (btcoexist->chip_interface == BTC_INTF_USB)
724 rtl_write_byte(rtlpriv, reg_addr, data);
727 void halbtc_set_macreg(void *btc_context, u32 reg_addr, u32 bit_mask, u32 data)
729 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
730 struct rtl_priv *rtlpriv = btcoexist->adapter;
732 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
735 u32 halbtc_get_macreg(void *btc_context, u32 reg_addr, u32 bit_mask)
737 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
738 struct rtl_priv *rtlpriv = btcoexist->adapter;
740 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
743 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
746 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
747 struct rtl_priv *rtlpriv = btcoexist->adapter;
749 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
752 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
754 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
755 struct rtl_priv *rtlpriv = btcoexist->adapter;
757 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
760 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
761 u32 bit_mask, u32 data)
763 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
764 struct rtl_priv *rtlpriv = btcoexist->adapter;
766 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
769 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
772 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
773 struct rtl_priv *rtlpriv = btcoexist->adapter;
775 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
778 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
779 u32 cmd_len, u8 *cmd_buf)
781 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
782 struct rtl_priv *rtlpriv = btcoexist->adapter;
784 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
788 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
790 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
791 struct rtl_priv *rtlpriv = btcoexist->adapter;
792 u8 cmd_buffer1[4] = {0};
793 u8 cmd_buffer2[4] = {0};
794 u8 *addr_to_set = (u8 *)&offset;
795 u8 *value_to_set = (u8 *)&set_val;
799 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
800 cmd_buffer1[0] |= (oper_ver & 0x0f); /* Set OperVer */
801 cmd_buffer1[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
802 cmd_buffer1[1] = 0x0d; /* OpCode: BT_LO_OP_WRITE_REG_VALUE */
803 cmd_buffer1[2] = value_to_set[0]; /* Set WriteRegValue */
804 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4,
810 cmd_buffer2[0] |= (oper_ver & 0x0f); /* Set OperVer */
811 cmd_buffer2[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
812 cmd_buffer2[1] = 0x0c; /* OpCode: BT_LO_OP_WRITE_REG_ADDR */
813 cmd_buffer2[3] = addr_to_set[0]; /* Set WriteRegAddr */
814 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4,
819 bool halbtc_under_ips(struct btc_coexist *btcoexist)
821 struct rtl_priv *rtlpriv = btcoexist->adapter;
822 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
823 enum rf_pwrstate rtstate;
825 if (ppsc->inactiveps) {
826 rtstate = ppsc->rfpwr_state;
828 if (rtstate != ERFON &&
829 ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
837 /*****************************************************************
838 * Extern functions called by other module
839 *****************************************************************/
840 bool exhalbtc_initlize_variables(void)
842 struct btc_coexist *btcoexist = &gl_bt_coexist;
846 btcoexist->btc_read_1byte = halbtc_read_1byte;
847 btcoexist->btc_write_1byte = halbtc_write_1byte;
848 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
849 btcoexist->btc_read_2byte = halbtc_read_2byte;
850 btcoexist->btc_write_2byte = halbtc_write_2byte;
851 btcoexist->btc_read_4byte = halbtc_read_4byte;
852 btcoexist->btc_write_4byte = halbtc_write_4byte;
853 btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
855 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
856 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
858 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
859 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
861 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
863 btcoexist->btc_get = halbtc_get;
864 btcoexist->btc_set = halbtc_set;
865 btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
868 btcoexist->bt_info.bt_ctrl_buf_size = false;
869 btcoexist->bt_info.agg_buf_size = 5;
871 btcoexist->bt_info.increase_scan_dev_num = false;
875 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
877 struct btc_coexist *btcoexist = &gl_bt_coexist;
878 struct rtl_priv *rtlpriv = adapter;
879 u8 ant_num = 2, chip_type;
881 if (btcoexist->binded)
884 switch (rtlpriv->rtlhal.interface) {
886 btcoexist->chip_interface = BTC_INTF_PCI;
889 btcoexist->chip_interface = BTC_INTF_USB;
892 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
896 btcoexist->binded = true;
897 btcoexist->statistics.cnt_bind++;
899 btcoexist->adapter = adapter;
901 btcoexist->stack_info.profile_notified = false;
903 btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
904 btcoexist->bt_info.agg_buf_size = 5;
906 btcoexist->bt_info.increase_scan_dev_num = false;
907 btcoexist->bt_info.miracast_plus_bt = false;
909 chip_type = rtl_get_hwpg_bt_type(rtlpriv);
910 exhalbtc_set_chip_type(chip_type);
911 ant_num = rtl_get_hwpg_ant_num(rtlpriv);
912 exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
914 if (rtl_get_hwpg_package_type(rtlpriv) == 0)
915 btcoexist->board_info.tfbga_package = false;
916 else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
917 btcoexist->board_info.tfbga_package = false;
919 btcoexist->board_info.tfbga_package = true;
921 if (btcoexist->board_info.tfbga_package)
922 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
923 "[BTCoex], Package Type = TFBGA\n");
925 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
926 "[BTCoex], Package Type = Non-TFBGA\n");
931 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
933 if (!halbtc_is_bt_coexist_available(btcoexist))
936 btcoexist->statistics.cnt_power_on++;
938 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
939 if (btcoexist->board_info.btdm_ant_num == 2)
940 ex_btc8723b2ant_power_on_setting(btcoexist);
941 else if (btcoexist->board_info.btdm_ant_num == 1)
942 ex_btc8723b1ant_power_on_setting(btcoexist);
946 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
948 if (!halbtc_is_bt_coexist_available(btcoexist))
951 btcoexist->statistics.cnt_pre_load_firmware++;
953 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
954 if (btcoexist->board_info.btdm_ant_num == 2)
955 ex_btc8723b2ant_pre_load_firmware(btcoexist);
959 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
961 if (!halbtc_is_bt_coexist_available(btcoexist))
964 btcoexist->statistics.cnt_init_hw_config++;
966 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
967 if (btcoexist->board_info.btdm_ant_num == 2)
968 ex_btc8821a2ant_init_hwconfig(btcoexist);
969 else if (btcoexist->board_info.btdm_ant_num == 1)
970 ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
971 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
972 if (btcoexist->board_info.btdm_ant_num == 2)
973 ex_btc8723b2ant_init_hwconfig(btcoexist);
974 else if (btcoexist->board_info.btdm_ant_num == 1)
975 ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
976 } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
977 /* 8723A has no this function */
978 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
979 if (btcoexist->board_info.btdm_ant_num == 2)
980 ex_btc8192e2ant_init_hwconfig(btcoexist);
984 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
986 if (!halbtc_is_bt_coexist_available(btcoexist))
989 btcoexist->statistics.cnt_init_coex_dm++;
991 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
992 if (btcoexist->board_info.btdm_ant_num == 2)
993 ex_btc8821a2ant_init_coex_dm(btcoexist);
994 else if (btcoexist->board_info.btdm_ant_num == 1)
995 ex_btc8821a1ant_init_coex_dm(btcoexist);
996 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
997 if (btcoexist->board_info.btdm_ant_num == 2)
998 ex_btc8723b2ant_init_coex_dm(btcoexist);
999 else if (btcoexist->board_info.btdm_ant_num == 1)
1000 ex_btc8723b1ant_init_coex_dm(btcoexist);
1001 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1002 if (btcoexist->board_info.btdm_ant_num == 2)
1003 ex_btc8192e2ant_init_coex_dm(btcoexist);
1006 btcoexist->initilized = true;
1009 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1013 if (!halbtc_is_bt_coexist_available(btcoexist))
1015 btcoexist->statistics.cnt_ips_notify++;
1016 if (btcoexist->manual_control)
1020 ips_type = BTC_IPS_ENTER;
1022 ips_type = BTC_IPS_LEAVE;
1024 halbtc_leave_low_power(btcoexist);
1026 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1027 if (btcoexist->board_info.btdm_ant_num == 2)
1028 ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
1029 else if (btcoexist->board_info.btdm_ant_num == 1)
1030 ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
1031 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1032 if (btcoexist->board_info.btdm_ant_num == 2)
1033 ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
1034 else if (btcoexist->board_info.btdm_ant_num == 1)
1035 ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
1036 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1037 if (btcoexist->board_info.btdm_ant_num == 2)
1038 ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
1041 halbtc_normal_low_power(btcoexist);
1044 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1048 if (!halbtc_is_bt_coexist_available(btcoexist))
1050 btcoexist->statistics.cnt_lps_notify++;
1051 if (btcoexist->manual_control)
1054 if (EACTIVE == type)
1055 lps_type = BTC_LPS_DISABLE;
1057 lps_type = BTC_LPS_ENABLE;
1059 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1060 if (btcoexist->board_info.btdm_ant_num == 2)
1061 ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
1062 else if (btcoexist->board_info.btdm_ant_num == 1)
1063 ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
1064 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1065 if (btcoexist->board_info.btdm_ant_num == 2)
1066 ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
1067 else if (btcoexist->board_info.btdm_ant_num == 1)
1068 ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
1069 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1070 if (btcoexist->board_info.btdm_ant_num == 2)
1071 ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
1075 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1079 if (!halbtc_is_bt_coexist_available(btcoexist))
1081 btcoexist->statistics.cnt_scan_notify++;
1082 if (btcoexist->manual_control)
1086 scan_type = BTC_SCAN_START;
1088 scan_type = BTC_SCAN_FINISH;
1090 halbtc_leave_low_power(btcoexist);
1092 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1093 if (btcoexist->board_info.btdm_ant_num == 2)
1094 ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
1095 else if (btcoexist->board_info.btdm_ant_num == 1)
1096 ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
1097 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1098 if (btcoexist->board_info.btdm_ant_num == 2)
1099 ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
1100 else if (btcoexist->board_info.btdm_ant_num == 1)
1101 ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
1102 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1103 if (btcoexist->board_info.btdm_ant_num == 2)
1104 ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
1107 halbtc_normal_low_power(btcoexist);
1110 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1114 if (!halbtc_is_bt_coexist_available(btcoexist))
1116 btcoexist->statistics.cnt_connect_notify++;
1117 if (btcoexist->manual_control)
1121 asso_type = BTC_ASSOCIATE_START;
1123 asso_type = BTC_ASSOCIATE_FINISH;
1125 halbtc_leave_low_power(btcoexist);
1127 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1128 if (btcoexist->board_info.btdm_ant_num == 2)
1129 ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
1130 else if (btcoexist->board_info.btdm_ant_num == 1)
1131 ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
1132 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1133 if (btcoexist->board_info.btdm_ant_num == 2)
1134 ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
1135 else if (btcoexist->board_info.btdm_ant_num == 1)
1136 ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
1137 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1138 if (btcoexist->board_info.btdm_ant_num == 2)
1139 ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
1142 halbtc_normal_low_power(btcoexist);
1145 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1146 enum rt_media_status media_status)
1150 if (!halbtc_is_bt_coexist_available(btcoexist))
1152 btcoexist->statistics.cnt_media_status_notify++;
1153 if (btcoexist->manual_control)
1156 if (RT_MEDIA_CONNECT == media_status)
1157 status = BTC_MEDIA_CONNECT;
1159 status = BTC_MEDIA_DISCONNECT;
1161 halbtc_leave_low_power(btcoexist);
1163 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1164 if (btcoexist->board_info.btdm_ant_num == 2)
1165 ex_btc8821a2ant_media_status_notify(btcoexist, status);
1166 else if (btcoexist->board_info.btdm_ant_num == 1)
1167 ex_btc8821a1ant_media_status_notify(btcoexist, status);
1168 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1169 if (btcoexist->board_info.btdm_ant_num == 2)
1170 ex_btc8723b2ant_media_status_notify(btcoexist, status);
1171 else if (btcoexist->board_info.btdm_ant_num == 1)
1172 ex_btc8723b1ant_media_status_notify(btcoexist, status);
1173 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1174 if (btcoexist->board_info.btdm_ant_num == 2)
1175 ex_btc8192e2ant_media_status_notify(btcoexist, status);
1178 halbtc_normal_low_power(btcoexist);
1181 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1185 if (!halbtc_is_bt_coexist_available(btcoexist))
1187 btcoexist->statistics.cnt_special_packet_notify++;
1188 if (btcoexist->manual_control)
1191 if (pkt_type == PACKET_DHCP) {
1192 packet_type = BTC_PACKET_DHCP;
1193 } else if (pkt_type == PACKET_EAPOL) {
1194 packet_type = BTC_PACKET_EAPOL;
1195 } else if (pkt_type == PACKET_ARP) {
1196 packet_type = BTC_PACKET_ARP;
1198 packet_type = BTC_PACKET_UNKNOWN;
1202 halbtc_leave_low_power(btcoexist);
1204 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1205 if (btcoexist->board_info.btdm_ant_num == 2)
1206 ex_btc8821a2ant_special_packet_notify(btcoexist,
1208 else if (btcoexist->board_info.btdm_ant_num == 1)
1209 ex_btc8821a1ant_special_packet_notify(btcoexist,
1211 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1212 if (btcoexist->board_info.btdm_ant_num == 2)
1213 ex_btc8723b2ant_special_packet_notify(btcoexist,
1215 else if (btcoexist->board_info.btdm_ant_num == 1)
1216 ex_btc8723b1ant_special_packet_notify(btcoexist,
1218 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1219 if (btcoexist->board_info.btdm_ant_num == 2)
1220 ex_btc8192e2ant_special_packet_notify(btcoexist,
1224 halbtc_normal_low_power(btcoexist);
1227 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1228 u8 *tmp_buf, u8 length)
1230 if (!halbtc_is_bt_coexist_available(btcoexist))
1232 btcoexist->statistics.cnt_bt_info_notify++;
1234 halbtc_leave_low_power(btcoexist);
1236 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1237 if (btcoexist->board_info.btdm_ant_num == 2)
1238 ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
1240 else if (btcoexist->board_info.btdm_ant_num == 1)
1241 ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
1243 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1244 if (btcoexist->board_info.btdm_ant_num == 2)
1245 ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
1247 else if (btcoexist->board_info.btdm_ant_num == 1)
1248 ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
1250 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1251 if (btcoexist->board_info.btdm_ant_num == 2)
1252 ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
1256 halbtc_normal_low_power(btcoexist);
1259 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1261 if (!halbtc_is_bt_coexist_available(btcoexist))
1264 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1265 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1266 if (btcoexist->board_info.btdm_ant_num == 1)
1267 ex_btc8723b1ant_rf_status_notify(btcoexist, type);
1268 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1272 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1276 if (!halbtc_is_bt_coexist_available(btcoexist))
1278 btcoexist->statistics.cnt_stack_operation_notify++;
1279 if (btcoexist->manual_control)
1282 if ((type == HCI_BT_OP_INQUIRY_START) ||
1283 (type == HCI_BT_OP_PAGING_START) ||
1284 (type == HCI_BT_OP_PAIRING_START)) {
1285 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
1286 } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
1287 (type == HCI_BT_OP_PAGING_SUCCESS) ||
1288 (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
1289 (type == HCI_BT_OP_PAIRING_FINISH)) {
1290 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
1292 stack_op_type = BTC_STACK_OP_NONE;
1296 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1298 if (!halbtc_is_bt_coexist_available(btcoexist))
1301 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1302 if (btcoexist->board_info.btdm_ant_num == 2)
1303 ex_btc8821a2ant_halt_notify(btcoexist);
1304 else if (btcoexist->board_info.btdm_ant_num == 1)
1305 ex_btc8821a1ant_halt_notify(btcoexist);
1306 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1307 if (btcoexist->board_info.btdm_ant_num == 2)
1308 ex_btc8723b2ant_halt_notify(btcoexist);
1309 else if (btcoexist->board_info.btdm_ant_num == 1)
1310 ex_btc8723b1ant_halt_notify(btcoexist);
1311 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1312 if (btcoexist->board_info.btdm_ant_num == 2)
1313 ex_btc8192e2ant_halt_notify(btcoexist);
1316 btcoexist->binded = false;
1319 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1321 if (!halbtc_is_bt_coexist_available(btcoexist))
1324 /* currently only 1ant we have to do the notification,
1325 * once pnp is notified to sleep state, we have to leave LPS that
1326 * we can sleep normally.
1329 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1330 if (btcoexist->board_info.btdm_ant_num == 1)
1331 ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
1332 else if (btcoexist->board_info.btdm_ant_num == 2)
1333 ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
1334 } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1335 if (btcoexist->board_info.btdm_ant_num == 1)
1336 ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
1337 else if (btcoexist->board_info.btdm_ant_num == 2)
1338 ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
1339 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1343 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1345 struct rtl_priv *rtlpriv = btcoexist->adapter;
1347 if (!halbtc_is_bt_coexist_available(btcoexist))
1349 btcoexist->statistics.cnt_coex_dm_switch++;
1351 halbtc_leave_low_power(btcoexist);
1353 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1354 if (btcoexist->board_info.btdm_ant_num == 1) {
1355 btcoexist->stop_coex_dm = true;
1356 ex_btc8723b1ant_coex_dm_reset(btcoexist);
1357 exhalbtc_set_ant_num(rtlpriv,
1358 BT_COEX_ANT_TYPE_DETECTED, 2);
1359 ex_btc8723b2ant_init_hwconfig(btcoexist);
1360 ex_btc8723b2ant_init_coex_dm(btcoexist);
1361 btcoexist->stop_coex_dm = false;
1365 halbtc_normal_low_power(btcoexist);
1368 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1370 if (!halbtc_is_bt_coexist_available(btcoexist))
1372 btcoexist->statistics.cnt_periodical++;
1374 halbtc_leave_low_power(btcoexist);
1376 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1377 if (btcoexist->board_info.btdm_ant_num == 2)
1378 ex_btc8821a2ant_periodical(btcoexist);
1379 else if (btcoexist->board_info.btdm_ant_num == 1)
1380 if (!halbtc_under_ips(btcoexist))
1381 ex_btc8821a1ant_periodical(btcoexist);
1382 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1383 if (btcoexist->board_info.btdm_ant_num == 2)
1384 ex_btc8723b2ant_periodical(btcoexist);
1385 else if (btcoexist->board_info.btdm_ant_num == 1)
1386 ex_btc8723b1ant_periodical(btcoexist);
1387 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1388 if (btcoexist->board_info.btdm_ant_num == 2)
1389 ex_btc8192e2ant_periodical(btcoexist);
1392 halbtc_normal_low_power(btcoexist);
1395 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1396 u8 code, u8 len, u8 *data)
1398 if (!halbtc_is_bt_coexist_available(btcoexist))
1400 btcoexist->statistics.cnt_dbg_ctrl++;
1402 halbtc_leave_low_power(btcoexist);
1404 halbtc_normal_low_power(btcoexist);
1407 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1408 u32 offset, u32 span, u32 seconds)
1410 if (!halbtc_is_bt_coexist_available(btcoexist))
1414 void exhalbtc_stack_update_profile_info(void)
1418 void exhalbtc_update_min_bt_rssi(s8 bt_rssi)
1420 struct btc_coexist *btcoexist = &gl_bt_coexist;
1422 if (!halbtc_is_bt_coexist_available(btcoexist))
1425 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1428 void exhalbtc_set_hci_version(u16 hci_version)
1430 struct btc_coexist *btcoexist = &gl_bt_coexist;
1432 if (!halbtc_is_bt_coexist_available(btcoexist))
1435 btcoexist->stack_info.hci_version = hci_version;
1438 void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version)
1440 struct btc_coexist *btcoexist = &gl_bt_coexist;
1442 if (!halbtc_is_bt_coexist_available(btcoexist))
1445 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1446 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1449 void exhalbtc_set_chip_type(u8 chip_type)
1451 switch (chip_type) {
1457 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
1460 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1463 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1466 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1469 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
1472 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1477 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1479 if (BT_COEX_ANT_TYPE_PG == type) {
1480 gl_bt_coexist.board_info.pg_ant_num = ant_num;
1481 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1482 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1483 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1484 } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1485 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1486 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1487 gl_bt_coexist.board_info.btdm_ant_pos =
1488 BTC_ANTENNA_AT_AUX_PORT;
1490 gl_bt_coexist.board_info.btdm_ant_pos =
1491 BTC_ANTENNA_AT_MAIN_PORT;
1495 /* Currently used by 8723b only, S0 or S1 */
1496 void exhalbtc_set_single_ant_path(u8 single_ant_path)
1498 gl_bt_coexist.board_info.single_ant_path = single_ant_path;
1501 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
1503 if (!halbtc_is_bt_coexist_available(btcoexist))
1506 halbtc_leave_low_power(btcoexist);
1508 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1509 if (btcoexist->board_info.btdm_ant_num == 2)
1510 ex_btc8821a2ant_display_coex_info(btcoexist);
1511 else if (btcoexist->board_info.btdm_ant_num == 1)
1512 ex_btc8821a1ant_display_coex_info(btcoexist);
1513 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1514 if (btcoexist->board_info.btdm_ant_num == 2)
1515 ex_btc8723b2ant_display_coex_info(btcoexist);
1516 else if (btcoexist->board_info.btdm_ant_num == 1)
1517 ex_btc8723b1ant_display_coex_info(btcoexist);
1518 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1519 if (btcoexist->board_info.btdm_ant_num == 2)
1520 ex_btc8192e2ant_display_coex_info(btcoexist);
1523 halbtc_normal_low_power(btcoexist);