1 /******************************************************************************
3 * Copyright(c) 2009-2013 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 *****************************************************************************/
26 #include <linux/vmalloc.h>
27 #include <linux/module.h>
30 #include "halbt_precomp.h"
32 static struct rtl_btc_ops rtl_btc_operation = {
33 .btc_init_variables = rtl_btc_init_variables,
34 .btc_init_hal_vars = rtl_btc_init_hal_vars,
35 .btc_power_on_setting = rtl_btc_power_on_setting,
36 .btc_init_hw_config = rtl_btc_init_hw_config,
37 .btc_ips_notify = rtl_btc_ips_notify,
38 .btc_lps_notify = rtl_btc_lps_notify,
39 .btc_scan_notify = rtl_btc_scan_notify,
40 .btc_connect_notify = rtl_btc_connect_notify,
41 .btc_mediastatus_notify = rtl_btc_mediastatus_notify,
42 .btc_periodical = rtl_btc_periodical,
43 .btc_halt_notify = rtl_btc_halt_notify,
44 .btc_btinfo_notify = rtl_btc_btinfo_notify,
45 .btc_btmpinfo_notify = rtl_btc_btmpinfo_notify,
46 .btc_is_limited_dig = rtl_btc_is_limited_dig,
47 .btc_is_disable_edca_turbo = rtl_btc_is_disable_edca_turbo,
48 .btc_is_bt_disabled = rtl_btc_is_bt_disabled,
49 .btc_special_packet_notify = rtl_btc_special_packet_notify,
50 .btc_record_pwr_mode = rtl_btc_record_pwr_mode,
51 .btc_get_lps_val = rtl_btc_get_lps_val,
52 .btc_get_rpwm_val = rtl_btc_get_rpwm_val,
53 .btc_is_bt_ctrl_lps = rtl_btc_is_bt_ctrl_lps,
54 .btc_is_bt_lps_on = rtl_btc_is_bt_lps_on,
55 .btc_get_ampdu_cfg = rtl_btc_get_ampdu_cfg,
58 void rtl_btc_record_pwr_mode(struct rtl_priv *rtlpriv, u8 *buf, u8 len)
62 safe_len = sizeof(gl_bt_coexist.pwr_mode_val);
67 memcpy(gl_bt_coexist.pwr_mode_val, buf, safe_len);
70 u8 rtl_btc_get_lps_val(struct rtl_priv *rtlpriv)
72 return gl_bt_coexist.bt_info.lps_val;
75 u8 rtl_btc_get_rpwm_val(struct rtl_priv *rtlpriv)
77 return gl_bt_coexist.bt_info.rpwm_val;
80 bool rtl_btc_is_bt_ctrl_lps(struct rtl_priv *rtlpriv)
82 return gl_bt_coexist.bt_info.bt_ctrl_lps;
85 bool rtl_btc_is_bt_lps_on(struct rtl_priv *rtlpriv)
87 return gl_bt_coexist.bt_info.bt_lps_on;
90 void rtl_btc_get_ampdu_cfg(struct rtl_priv *rtlpriv, u8 *reject_agg,
91 u8 *ctrl_agg_size, u8 *agg_size)
94 *reject_agg = gl_bt_coexist.bt_info.reject_agg_pkt;
96 *ctrl_agg_size = gl_bt_coexist.bt_info.bt_ctrl_agg_buf_size;
98 *agg_size = gl_bt_coexist.bt_info.agg_buf_size;
101 void rtl_btc_init_variables(struct rtl_priv *rtlpriv)
103 exhalbtc_initlize_variables();
104 exhalbtc_bind_bt_coex_withadapter(rtlpriv);
107 void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv)
109 /* move ant_num, bt_type and single_ant_path to
110 * exhalbtc_bind_bt_coex_withadapter()
114 void rtl_btc_power_on_setting(struct rtl_priv *rtlpriv)
116 exhalbtc_power_on_setting(&gl_bt_coexist);
119 void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv)
123 bt_exist = rtl_get_hwpg_bt_exist(rtlpriv);
124 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
125 "%s, bt_exist is %d\n", __func__, bt_exist);
127 exhalbtc_init_hw_config(&gl_bt_coexist, !bt_exist);
128 exhalbtc_init_coex_dm(&gl_bt_coexist);
131 void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
133 exhalbtc_ips_notify(&gl_bt_coexist, type);
136 void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type)
138 exhalbtc_lps_notify(&gl_bt_coexist, type);
141 void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
143 exhalbtc_scan_notify(&gl_bt_coexist, scantype);
146 void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
148 exhalbtc_connect_notify(&gl_bt_coexist, action);
151 void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
152 enum rt_media_status mstatus)
154 exhalbtc_mediastatus_notify(&gl_bt_coexist, mstatus);
157 void rtl_btc_periodical(struct rtl_priv *rtlpriv)
159 /*rtl_bt_dm_monitor();*/
160 exhalbtc_periodical(&gl_bt_coexist);
163 void rtl_btc_halt_notify(void)
165 struct btc_coexist *btcoexist = &gl_bt_coexist;
167 exhalbtc_halt_notify(btcoexist);
170 void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
172 exhalbtc_bt_info_notify(&gl_bt_coexist, tmp_buf, length);
175 void rtl_btc_btmpinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
181 if ((length < 4) || (!tmp_buf))
185 /* not response from BT FW then exit*/
186 if (extid != 1) /* C2H_TRIG_BY_BT_FW = 1 */
189 len = tmp_buf[1] >> 4;
190 seq = tmp_buf[2] >> 4;
192 /* BT Firmware version response */
194 bt_real_fw_ver = tmp_buf[3] | (tmp_buf[4] << 8);
195 bt_fw_ver = tmp_buf[5];
197 gl_bt_coexist.bt_info.bt_real_fw_ver = bt_real_fw_ver;
198 gl_bt_coexist.bt_info.bt_fw_ver = bt_fw_ver;
202 bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv)
204 return gl_bt_coexist.bt_info.limited_dig;
207 bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
209 bool bt_change_edca = false;
211 u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
213 u32 edca_addr = 0x504;
215 cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
216 if (halbtc_is_wifi_uplink(rtlpriv)) {
217 if (cur_edca_val != edca_bt_hs_uplink) {
218 edca_hs = edca_bt_hs_uplink;
219 bt_change_edca = true;
222 if (cur_edca_val != edca_bt_hs_downlink) {
223 edca_hs = edca_bt_hs_downlink;
224 bt_change_edca = true;
229 rtl_write_dword(rtlpriv, edca_addr, edca_hs);
234 bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
236 /* It seems 'bt_disabled' is never be initialized or set. */
237 if (gl_bt_coexist.bt_info.bt_disabled)
243 void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type)
245 return exhalbtc_special_packet_notify(&gl_bt_coexist, pkt_type);
248 struct rtl_btc_ops *rtl_btc_get_ops_pointer(void)
250 return &rtl_btc_operation;
252 EXPORT_SYMBOL(rtl_btc_get_ops_pointer);
255 enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw)
257 struct rtl_priv *rtlpriv = rtl_priv(hw);
258 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
259 enum rt_media_status m_status = RT_MEDIA_DISCONNECT;
261 u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
263 if (bibss || rtlpriv->mac80211.link_state >= MAC80211_LINKED)
264 m_status = RT_MEDIA_CONNECT;
269 u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
271 return rtlpriv->btcoexist.btc_info.btcoexist;
274 MODULE_AUTHOR("Page He <page_he@realsil.com.cn>");
275 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
276 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
277 MODULE_LICENSE("GPL");
278 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
280 static int __init rtl_btcoexist_module_init(void)
285 static void __exit rtl_btcoexist_module_exit(void)
290 module_init(rtl_btcoexist_module_init);
291 module_exit(rtl_btcoexist_module_exit);