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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
21 #include "halbt_precomp.h"
23 /*#if(BT_30_SUPPORT == 1)*/
25 /***********************************************
27 ***********************************************/
28 const char *const bt_profile_string[]={
36 const char *const bt_spec_string[]={
46 const char *const bt_link_role_string[]={
51 const char *const h2c_state_string[]={
58 const char *const io_state_string[]={
60 "IO_STATUS_FAIL_CANNOT_IO",
61 "IO_STATUS_FAIL_RF_OFF",
62 "IO_STATUS_FAIL_FW_READ_CLEAR_TIMEOUT",
63 "IO_STATUS_FAIL_WAIT_IO_EVENT_TIMEOUT",
64 "IO_STATUS_INVALID_LEN",
65 "IO_STATUS_IO_IDLE_QUEUE_EMPTY",
66 "IO_STATUS_IO_INSERT_WAIT_QUEUE_FAIL",
67 "IO_STATUS_UNKNOWN_FAIL",
68 "IO_STATUS_WRONG_LEVEL",
69 "IO_STATUS_H2C_STOPPED",
72 struct btc_coexist gl_bt_coexist;
74 u32 btc_dbg_type[BTC_MSG_MAX];
77 /***************************************************
78 * Debug related function
79 ***************************************************/
80 bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
82 if (!btcoexist->binded || NULL == btcoexist->adapter)
88 bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
91 if (rtlpriv->link_info.b_busytraffic)
98 void halbtc_dbg_init(void)
102 for (i = 0; i < BTC_MSG_MAX; i++)
105 btc_dbg_type[BTC_MSG_INTERFACE] = \
110 btc_dbg_type[BTC_MSG_ALGORITHM] = \
111 // ALGO_BT_RSSI_STATE |
112 // ALGO_WIFI_RSSI_STATE |
116 // ALGO_TRACE_FW_DETAIL |
117 // ALGO_TRACE_FW_EXEC |
119 // ALGO_TRACE_SW_DETAIL |
120 // ALGO_TRACE_SW_EXEC |
124 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
129 bool halbtc_is_bt40(struct rtl_priv *adapter)
131 struct rtl_priv *rtlpriv = adapter;
132 struct rtl_phy *rtlphy = &(rtlpriv->phy);
134 enum ht_channel_width bw = rtlphy->current_chan_bw;
137 if (bw == HT_CHANNEL_WIDTH_20)
139 else if (bw == HT_CHANNEL_WIDTH_20_40)
145 bool halbtc_legacy(struct rtl_priv *adapter)
147 struct rtl_priv *rtlpriv = adapter;
148 struct rtl_mac *mac = rtl_mac(rtlpriv);
150 bool is_legacy = false;
152 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_B))
158 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
160 struct rtl_priv *rtlpriv = adapter;
162 if (rtlpriv->link_info.b_tx_busy_traffic)
168 u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
170 struct rtl_priv *rtlpriv =
171 (struct rtl_priv *)btcoexist->adapter;
172 u32 wifi_bw = BTC_WIFI_BW_HT20;
174 if (halbtc_is_bt40(rtlpriv)){
175 wifi_bw = BTC_WIFI_BW_HT40;
177 if(halbtc_legacy(rtlpriv))
178 wifi_bw = BTC_WIFI_BW_LEGACY;
180 wifi_bw = BTC_WIFI_BW_HT20;
185 u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
187 struct rtl_priv *rtlpriv = btcoexist->adapter;
188 struct rtl_phy *rtlphy = &(rtlpriv->phy);
192 if (rtlphy->current_channel != 0)
193 chnl = rtlphy->current_channel;
194 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
195 "halbtc_get_wifi_central_chnl:%d\n",chnl);
199 void halbtc_leave_lps(struct btc_coexist *btcoexist)
201 struct rtl_priv *rtlpriv;
202 struct rtl_ps_ctl *ppsc;
203 bool ap_enable = false;
205 rtlpriv = btcoexist->adapter;
206 ppsc = rtl_psc(rtlpriv);
208 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
212 printk("halbtc_leave_lps()<--dont leave lps under AP mode\n");
216 btcoexist->bt_info.bt_ctrl_lps = true;
217 btcoexist->bt_info.bt_lps_on = false;
220 void halbtc_enter_lps(struct btc_coexist *btcoexist)
222 struct rtl_priv *rtlpriv;
223 struct rtl_ps_ctl *ppsc;
224 bool ap_enable = false;
226 rtlpriv = btcoexist->adapter;
227 ppsc = rtl_psc(rtlpriv);
229 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
233 printk("halbtc_enter_lps()<--dont enter lps under AP mode\n");
237 btcoexist->bt_info.bt_ctrl_lps = true;
238 btcoexist->bt_info.bt_lps_on = false;
241 void halbtc_normal_lps(struct btc_coexist *btcoexist)
243 if (btcoexist->bt_info.bt_ctrl_lps) {
244 btcoexist->bt_info.bt_lps_on = false;
245 btcoexist->bt_info.bt_ctrl_lps = false;
250 void halbtc_leave_low_power(void)
254 void halbtc_nomal_low_power(void)
258 void halbtc_disable_low_power(void)
262 void halbtc_aggregation_check(void)
267 u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
272 s32 halbtc_get_wifi_rssi(struct rtl_priv *adapter)
274 struct rtl_priv *rtlpriv = adapter;
275 s32 undecorated_smoothed_pwdb = 0;
277 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
278 undecorated_smoothed_pwdb =
279 rtlpriv->dm.undecorated_smoothed_pwdb;
280 else /* associated entry pwdb */
281 undecorated_smoothed_pwdb =
282 rtlpriv->dm.undecorated_smoothed_pwdb;
283 return undecorated_smoothed_pwdb;
286 bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
288 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
289 struct rtl_priv *rtlpriv = btcoexist->adapter;
290 struct rtl_phy *rtlphy = &(rtlpriv->phy);
291 struct rtl_mac *mac = rtl_mac(rtlpriv);
292 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
293 bool *bool_tmp = (bool*)out_buf;
294 int *s32_tmp = (int*)out_buf;
295 u32 *u32_tmp = (u32*)out_buf;
296 u8 *u8_tmp = (u8*)out_buf;
300 if (!halbtc_is_bt_coexist_available(btcoexist))
305 case BTC_GET_BL_HS_OPERATION:
308 case BTC_GET_BL_HS_CONNECTING:
311 case BTC_GET_BL_WIFI_CONNECTED:
312 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
317 case BTC_GET_BL_WIFI_BUSY:
318 if(halbtc_is_wifi_busy(rtlpriv))
323 case BTC_GET_BL_WIFI_SCAN:
324 if (mac->act_scanning == true)
329 case BTC_GET_BL_WIFI_LINK:
330 if (mac->link_state == MAC80211_LINKING)
335 case BTC_GET_BL_WIFI_ROAM: /*TODO*/
336 if (mac->link_state == MAC80211_LINKING)
341 case BTC_GET_BL_WIFI_4_WAY_PROGRESS: /*TODO*/
345 case BTC_GET_BL_WIFI_UNDER_5G:
346 *bool_tmp = false; /*TODO*/
348 case BTC_GET_BL_WIFI_DHCP: /*TODO*/
350 case BTC_GET_BL_WIFI_SOFTAP_IDLE:
353 case BTC_GET_BL_WIFI_SOFTAP_LINKING:
356 case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND:
359 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
362 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
363 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
368 case BTC_GET_BL_WIFI_UNDER_B_MODE:
369 *bool_tmp = false; /*TODO*/
371 case BTC_GET_BL_EXT_SWITCH:
374 case BTC_GET_S4_WIFI_RSSI:
375 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
377 case BTC_GET_S4_HS_RSSI: /*TODO*/
378 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
380 case BTC_GET_U4_WIFI_BW:
381 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
383 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
384 if (halbtc_is_wifi_uplink(rtlpriv))
385 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
387 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
389 case BTC_GET_U4_WIFI_FW_VER:
390 *u32_tmp = rtlhal->fw_version;
392 case BTC_GET_U4_BT_PATCH_VER:
393 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
395 case BTC_GET_U1_WIFI_DOT11_CHNL:
396 *u8_tmp = rtlphy->current_channel;
398 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
399 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
401 case BTC_GET_U1_WIFI_HS_CHNL:
402 *u8_tmp = 1;/* BT_OperateChnl(rtlpriv); */
404 case BTC_GET_U1_MAC_PHY_MODE:
405 *u8_tmp = BTC_MP_UNKNOWN;
407 case BTC_GET_U1_AP_NUM:
408 /* driver don't know AP num in Linux,
409 * So, the return value here is not right */
410 *u8_tmp = 1;/* pDefMgntInfo->NumBssDesc4Query; */
413 /************* 1Ant **************/
414 case BTC_GET_U1_LPS_MODE:
415 *u8_tmp = btcoexist->pwr_mode_val[0];
425 bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
427 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
428 bool *bool_tmp = (bool *)in_buf;
429 u8 *u8_tmp = (u8 *)in_buf;
430 u32 *u32_tmp = (u32 *)in_buf;
433 if (!halbtc_is_bt_coexist_available(btcoexist))
437 /* set some bool type variables. */
438 case BTC_SET_BL_BT_DISABLE:
439 btcoexist->bt_info.bt_disabled = *bool_tmp;
441 case BTC_SET_BL_BT_TRAFFIC_BUSY:
442 btcoexist->bt_info.bt_busy = *bool_tmp;
444 case BTC_SET_BL_BT_LIMITED_DIG:
445 btcoexist->bt_info.limited_dig = *bool_tmp;
447 case BTC_SET_BL_FORCE_TO_ROAM:
448 btcoexist->bt_info.force_to_roam = *bool_tmp;
450 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
451 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
453 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
454 btcoexist->bt_info.b_bt_ctrl_buf_size = *bool_tmp;
456 case BTC_SET_BL_INC_SCAN_DEV_NUM:
457 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
459 /* set some u1Byte type variables. */
460 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
461 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
463 case BTC_SET_U1_AGG_BUF_SIZE:
464 btcoexist->bt_info.agg_buf_size = *u8_tmp;
466 /* the following are some action which will be triggered */
467 case BTC_SET_ACT_GET_BT_RSSI:
468 /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/
470 case BTC_SET_ACT_AGGREGATE_CTRL:
471 halbtc_aggregation_check();
475 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
476 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
478 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
479 /* rtlpriv->mlmepriv.scan_compensation = *u8_tmp; */
481 case BTC_SET_U1_1ANT_LPS:
482 btcoexist->bt_info.lps_1ant = *u8_tmp;
484 case BTC_SET_U1_1ANT_RPWM:
485 btcoexist->bt_info.rpwm_1ant = *u8_tmp;
487 /* the following are some action which will be triggered */
488 case BTC_SET_ACT_LEAVE_LPS:
489 halbtc_leave_lps(btcoexist);
491 case BTC_SET_ACT_ENTER_LPS:
492 halbtc_enter_lps(btcoexist);
494 case BTC_SET_ACT_NORMAL_LPS:
495 halbtc_normal_lps(btcoexist);
497 case BTC_SET_ACT_DISABLE_LOW_POWER:
498 halbtc_disable_low_power();
500 case BTC_SET_ACT_UPDATE_ra_mask:
501 btcoexist->bt_info.ra_mask = *u32_tmp;
503 case BTC_SET_ACT_SEND_MIMO_PS:
505 case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT:
506 btcoexist->bt_info.force_exec_pwr_cmd_cnt++;
508 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
510 case BTC_SET_ACT_CTRL_BT_COEX:
519 void halbtc_display_coex_statistics(struct btc_coexist *btcoexist)
523 void halbtc_display_bt_link_info(struct btc_coexist *btcoexist)
527 void halbtc_display_bt_fw_info(struct btc_coexist *btcoexist)
531 void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist *btcoexist)
535 /************************************************************
536 * IO related function
537 ************************************************************/
538 u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
540 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
541 struct rtl_priv *rtlpriv = btcoexist->adapter;
543 return rtl_read_byte(rtlpriv, reg_addr);
547 u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
549 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
550 struct rtl_priv *rtlpriv = btcoexist->adapter;
552 return rtl_read_word(rtlpriv, reg_addr);
556 u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
558 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
559 struct rtl_priv *rtlpriv = btcoexist->adapter;
561 return rtl_read_dword(rtlpriv, reg_addr);
565 void halbtc_write_1byte(void *bt_context, u32 reg_addr, u8 data)
567 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
568 struct rtl_priv *rtlpriv = btcoexist->adapter;
570 rtl_write_byte(rtlpriv, reg_addr, data);
573 void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
574 u8 bit_mask, u8 data)
576 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
577 struct rtl_priv *rtlpriv = btcoexist->adapter;
578 u8 original_value, bit_shift = 0;
581 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
582 original_value = rtl_read_byte(rtlpriv, reg_addr);
583 for (i=0; i<=7; i++) {
584 if((bit_mask>>i)&0x1)
588 data = (original_value & (~bit_mask)) |
589 ((data << bit_shift) & bit_mask);
591 rtl_write_byte(rtlpriv, reg_addr, data);
595 void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
597 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
598 struct rtl_priv *rtlpriv = btcoexist->adapter;
600 rtl_write_word(rtlpriv, reg_addr, data);
604 void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
606 struct btc_coexist *btcoexist =
607 (struct btc_coexist *)bt_context;
608 struct rtl_priv *rtlpriv = btcoexist->adapter;
610 rtl_write_dword(rtlpriv, reg_addr, data);
614 void halbtc_set_macreg(void *bt_context, u32 reg_addr, u32 bit_mask, u32 data)
616 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
617 struct rtl_priv *rtlpriv = btcoexist->adapter;
619 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
623 u32 halbtc_get_macreg(void *bt_context, u32 reg_addr, u32 bit_mask)
625 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
626 struct rtl_priv *rtlpriv = btcoexist->adapter;
628 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
632 void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask, u32 data)
634 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
635 struct rtl_priv *rtlpriv = btcoexist->adapter;
637 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
641 u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
643 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
644 struct rtl_priv *rtlpriv = btcoexist->adapter;
646 return rtl_get_bbreg(rtlpriv->mac80211.hw,reg_addr, bit_mask);
650 void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
651 u32 bit_mask, u32 data)
653 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
654 struct rtl_priv *rtlpriv = btcoexist->adapter;
656 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
660 u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, u32 bit_mask)
662 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
663 struct rtl_priv *rtlpriv = btcoexist->adapter;
665 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
669 void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
670 u32 cmd_len, u8 *cmd_buf)
672 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
673 struct rtl_priv *rtlpriv = btcoexist->adapter;
675 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
679 void halbtc_display_dbg_msg(void *bt_context, u8 disp_type)
681 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
683 case BTC_DBG_DISP_COEX_STATISTICS:
684 halbtc_display_coex_statistics(btcoexist);
686 case BTC_DBG_DISP_BT_LINK_INFO:
687 halbtc_display_bt_link_info(btcoexist);
689 case BTC_DBG_DISP_BT_FW_VER:
690 halbtc_display_bt_fw_info(btcoexist);
692 case BTC_DBG_DISP_FW_PWR_MODE_CMD:
693 halbtc_display_fw_pwr_mode_cmd(btcoexist);
700 bool halbtc_under_ips(struct btc_coexist *btcoexist)
702 struct rtl_priv *rtlpriv = btcoexist->adapter;
703 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
704 enum rf_pwrstate rtstate;
706 if (ppsc->b_inactiveps) {
707 rtstate = ppsc->rfpwr_state;
709 if (rtstate != ERFON &&
710 ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
719 /*****************************************************************
720 * Extern functions called by other module
721 *****************************************************************/
722 bool exhalbtc_initlize_variables(struct rtl_priv *adapter)
724 struct btc_coexist *btcoexist = &gl_bt_coexist;
726 btcoexist->statistics.cnt_bind++;
730 if (btcoexist->binded)
733 btcoexist->binded = true;
735 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
737 if (NULL == btcoexist->adapter)
738 btcoexist->adapter = adapter;
740 btcoexist->stack_info.profile_notified = false;
742 btcoexist->btc_read_1byte = halbtc_read_1byte;
743 btcoexist->btc_write_1byte = halbtc_write_1byte;
744 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
745 btcoexist->btc_read_2byte = halbtc_read_2byte;
746 btcoexist->btc_write_2byte = halbtc_write_2byte;
747 btcoexist->btc_read_4byte = halbtc_read_4byte;
748 btcoexist->btc_write_4byte = halbtc_write_4byte;
750 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
751 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
753 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
754 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
756 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
757 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
759 btcoexist->btc_get = halbtc_get;
760 btcoexist->btc_set = halbtc_set;
762 btcoexist->cli_buf = &btc_dbg_buf[0];
764 btcoexist->bt_info.b_bt_ctrl_buf_size = false;
765 btcoexist->bt_info.agg_buf_size = 5;
767 btcoexist->bt_info.increase_scan_dev_num = false;
771 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist)
773 struct rtl_priv *rtlpriv = btcoexist->adapter;
774 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
776 if (!halbtc_is_bt_coexist_available(btcoexist))
779 btcoexist->statistics.cnt_init_hw_config++;
781 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
782 if (btcoexist->board_info.btdm_ant_num == 2)
783 ex_halbtc8723b2ant_init_hwconfig(btcoexist);
784 else if(btcoexist->board_info.btdm_ant_num == 1)
785 ex_halbtc8723b1ant_init_hwconfig(btcoexist);
786 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
787 ex_halbtc8192e2ant_init_hwconfig(btcoexist);
792 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
794 struct rtl_priv *rtlpriv = btcoexist->adapter;
795 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
797 if (!halbtc_is_bt_coexist_available(btcoexist))
800 btcoexist->statistics.cnt_init_coex_dm++;
802 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
803 if (btcoexist->board_info.btdm_ant_num == 2)
804 ex_halbtc8723b2ant_init_coex_dm(btcoexist);
805 else if(btcoexist->board_info.btdm_ant_num == 1)
806 ex_halbtc8723b1ant_init_coex_dm(btcoexist);
807 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
808 ex_halbtc8192e2ant_init_coex_dm(btcoexist);
811 btcoexist->initilized = true;
814 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
816 struct rtl_priv *rtlpriv = btcoexist->adapter;
817 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
820 if (!halbtc_is_bt_coexist_available(btcoexist))
822 btcoexist->statistics.cnt_ips_notify++;
823 if (btcoexist->manual_control)
827 ips_type = BTC_IPS_ENTER;
829 ips_type = BTC_IPS_LEAVE;
831 halbtc_leave_low_power();
833 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
834 if (btcoexist->board_info.btdm_ant_num == 2)
835 ex_halbtc8723b2ant_ips_notify(btcoexist, ips_type);
836 else if(btcoexist->board_info.btdm_ant_num == 1)
837 ex_halbtc8723b1ant_ips_notify(btcoexist, ips_type);
838 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
839 ex_halbtc8192e2ant_ips_notify(btcoexist, ips_type);
842 halbtc_nomal_low_power();
845 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
847 struct rtl_priv *rtlpriv = btcoexist->adapter;
848 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
851 if (!halbtc_is_bt_coexist_available(btcoexist))
853 btcoexist->statistics.cnt_lps_notify++;
854 if (btcoexist->manual_control)
858 lps_type = BTC_LPS_DISABLE;
860 lps_type = BTC_LPS_ENABLE;
862 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
863 if (btcoexist->board_info.btdm_ant_num == 2)
864 ex_halbtc8723b2ant_lps_notify(btcoexist, lps_type);
865 else if(btcoexist->board_info.btdm_ant_num == 1)
866 ex_halbtc8723b1ant_lps_notify(btcoexist, lps_type);
867 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
868 ex_halbtc8192e2ant_lps_notify(btcoexist, lps_type);
872 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
874 struct rtl_priv *rtlpriv = btcoexist->adapter;
875 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
878 if (!halbtc_is_bt_coexist_available(btcoexist))
880 btcoexist->statistics.cnt_scan_notify++;
881 if (btcoexist->manual_control)
885 scan_type = BTC_SCAN_START;
887 scan_type = BTC_SCAN_FINISH;
889 halbtc_leave_low_power();
891 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
892 if (btcoexist->board_info.btdm_ant_num == 2)
893 ex_halbtc8723b2ant_scan_notify(btcoexist, scan_type);
894 else if(btcoexist->board_info.btdm_ant_num == 1)
895 ex_halbtc8723b1ant_scan_notify(btcoexist, scan_type);
896 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
897 ex_halbtc8192e2ant_scan_notify(btcoexist, scan_type);
900 halbtc_nomal_low_power();
903 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
905 struct rtl_priv *rtlpriv = btcoexist->adapter;
906 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
909 if (!halbtc_is_bt_coexist_available(btcoexist))
911 btcoexist->statistics.cnt_connect_notify++;
912 if (btcoexist->manual_control)
916 asso_type = BTC_ASSOCIATE_START;
918 asso_type = BTC_ASSOCIATE_FINISH;
920 halbtc_leave_low_power();
922 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
923 if (btcoexist->board_info.btdm_ant_num == 2)
924 ex_halbtc8723b2ant_connect_notify(btcoexist, asso_type);
925 else if(btcoexist->board_info.btdm_ant_num == 1)
926 ex_halbtc8723b1ant_connect_notify(btcoexist, asso_type);
927 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
928 ex_halbtc8192e2ant_connect_notify(btcoexist, asso_type);
931 halbtc_nomal_low_power();
934 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
935 enum rt_media_status media_status)
937 struct rtl_priv *rtlpriv = btcoexist->adapter;
938 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
941 if (!halbtc_is_bt_coexist_available(btcoexist))
943 btcoexist->statistics.cnt_media_status_notify++;
944 if (btcoexist->manual_control)
947 if (RT_MEDIA_CONNECT == media_status)
948 status = BTC_MEDIA_CONNECT;
950 status = BTC_MEDIA_DISCONNECT;
952 halbtc_leave_low_power();
954 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
955 if (btcoexist->board_info.btdm_ant_num == 2)
956 ex_halbtc8723b2ant_media_status_notify(btcoexist, status);
957 else if(btcoexist->board_info.btdm_ant_num == 1)
958 ex_halbtc8723b1ant_media_status_notify(btcoexist, status);
959 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
960 ex_halbtc8192e2ant_media_status_notify(btcoexist, status);
963 halbtc_nomal_low_power();
966 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
970 if (!halbtc_is_bt_coexist_available(btcoexist))
972 btcoexist->statistics.cnt_special_packet_notify++;
973 if (btcoexist->manual_control)
976 /*if(PACKET_DHCP == pkt_type)*/
977 packet_type = BTC_PACKET_DHCP;
978 /*else if(PACKET_EAPOL == pkt_type)
979 packet_type = BTC_PACKET_EAPOL;
981 packet_type = BTC_PACKET_UNKNOWN;*/
983 halbtc_leave_low_power();
985 if (btcoexist->board_info.btdm_ant_num == 2)
986 ex_halbtc8723b2ant_special_packet_notify(btcoexist,
988 else if (btcoexist->board_info.btdm_ant_num == 1)
989 ex_halbtc8723b1ant_special_packet_notify(btcoexist,
992 halbtc_nomal_low_power();
995 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
996 u8 *tmp_buf, u8 length)
998 struct rtl_priv *rtlpriv = btcoexist->adapter;
999 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1000 if (!halbtc_is_bt_coexist_available(btcoexist))
1002 btcoexist->statistics.cnt_bt_info_notify++;
1004 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1005 if (btcoexist->board_info.btdm_ant_num == 2)
1006 ex_halbtc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length);
1007 else if(btcoexist->board_info.btdm_ant_num == 1)
1008 ex_halbtc8723b1ant_bt_info_notify(btcoexist, tmp_buf, length);
1009 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1010 // ex_halbtc8192e2ant_bt_info_notify(btcoexist, tmp_buf, length);
1014 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1018 if (!halbtc_is_bt_coexist_available(btcoexist))
1020 btcoexist->statistics.cnt_stack_operation_notify++;
1021 if (btcoexist->manual_control)
1024 stack_op_type = BTC_STACK_OP_NONE;
1027 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1029 struct rtl_priv *rtlpriv = btcoexist->adapter;
1030 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1031 if (!halbtc_is_bt_coexist_available(btcoexist))
1034 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1035 if (btcoexist->board_info.btdm_ant_num == 2)
1036 ex_halbtc8723b2ant_halt_notify(btcoexist);
1037 else if(btcoexist->board_info.btdm_ant_num == 1)
1038 ex_halbtc8723b1ant_halt_notify(btcoexist);
1039 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1040 ex_halbtc8192e2ant_halt_notify(btcoexist);
1044 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1046 if (!halbtc_is_bt_coexist_available(btcoexist))
1050 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1052 struct rtl_priv *rtlpriv = btcoexist->adapter;
1053 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1054 if (!halbtc_is_bt_coexist_available(btcoexist))
1056 btcoexist->statistics.cnt_periodical++;
1058 halbtc_leave_low_power();
1060 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1061 if (btcoexist->board_info.btdm_ant_num == 2)
1062 ex_halbtc8723b2ant_periodical(btcoexist);
1063 else if(btcoexist->board_info.btdm_ant_num == 1)
1064 ex_halbtc8723b1ant_periodical(btcoexist);
1065 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1066 ex_halbtc8192e2ant_periodical(btcoexist);
1069 halbtc_nomal_low_power();
1072 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1073 u8 code, u8 len, u8 *data)
1075 if (!halbtc_is_bt_coexist_available(btcoexist))
1077 btcoexist->statistics.cnt_dbg_ctrl++;
1080 void exhalbtc_stack_update_profile_info()
1084 void exhalbtc_update_min_bt_rssi(char bt_rssi)
1086 struct btc_coexist *btcoexist = &gl_bt_coexist;
1088 if (!halbtc_is_bt_coexist_available(btcoexist))
1091 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1095 void exhalbtc_set_hci_version(u16 hci_version)
1097 struct btc_coexist *btcoexist = &gl_bt_coexist;
1099 if (!halbtc_is_bt_coexist_available(btcoexist))
1102 btcoexist->stack_info.hci_version = hci_version;
1105 void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version)
1107 struct btc_coexist *btcoexist = &gl_bt_coexist;
1109 if (!halbtc_is_bt_coexist_available(btcoexist))
1112 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1113 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1116 void exhalbtc_set_bt_exist(bool bt_exist)
1118 gl_bt_coexist.board_info.bt_exist = bt_exist;
1121 void exhalbtc_set_chip_type(u8 chip_type)
1123 switch (chip_type) {
1129 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
1132 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1135 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1138 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1141 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
1144 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1149 void exhalbtc_set_ant_num(u8 type, u8 ant_num)
1151 if (BT_COEX_ANT_TYPE_PG == type) {
1152 gl_bt_coexist.board_info.pg_ant_num = ant_num;
1153 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1154 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1155 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1159 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
1161 if (!halbtc_is_bt_coexist_available(btcoexist))
1164 if (btcoexist->board_info.btdm_ant_num == 2)
1165 ex_halbtc8723b2ant_display_coex_info(btcoexist);
1166 else if (btcoexist->board_info.btdm_ant_num == 1)
1167 ex_halbtc8723b1ant_display_coex_info(btcoexist);