1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2013  Realtek Corporation.
4  *
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.
8  *
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
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25 #include "../wifi.h"
26 #include <linux/vmalloc.h>
27 #include <linux/module.h>
28 
29 #include "rtl_btc.h"
30 #include "halbt_precomp.h"
31 
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_init_hw_config = rtl_btc_init_hw_config,
36 	.btc_ips_notify = rtl_btc_ips_notify,
37 	.btc_lps_notify = rtl_btc_lps_notify,
38 	.btc_scan_notify = rtl_btc_scan_notify,
39 	.btc_connect_notify = rtl_btc_connect_notify,
40 	.btc_mediastatus_notify = rtl_btc_mediastatus_notify,
41 	.btc_periodical = rtl_btc_periodical,
42 	.btc_halt_notify = rtl_btc_halt_notify,
43 	.btc_btinfo_notify = rtl_btc_btinfo_notify,
44 	.btc_is_limited_dig = rtl_btc_is_limited_dig,
45 	.btc_is_disable_edca_turbo = rtl_btc_is_disable_edca_turbo,
46 	.btc_is_bt_disabled = rtl_btc_is_bt_disabled,
47 	.btc_special_packet_notify = rtl_btc_special_packet_notify,
48 	.btc_record_pwr_mode = rtl_btc_record_pwr_mode,
49 };
50 
51 void rtl_btc_record_pwr_mode(struct rtl_priv *rtlpriv, u8 *buf, u8 len)
52 {
53 	u8 safe_len;
54 
55 	safe_len = sizeof(gl_bt_coexist.pwr_mode_val);
56 
57 	if (safe_len > len)
58 		safe_len = len;
59 
60 	memcpy(gl_bt_coexist.pwr_mode_val, buf, safe_len);
61 }
62 
63 void rtl_btc_init_variables(struct rtl_priv *rtlpriv)
64 {
65 	exhalbtc_initlize_variables();
66 	exhalbtc_bind_bt_coex_withadapter(rtlpriv);
67 }
68 
69 void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv)
70 {
71 	/* move ant_num, bt_type and single_ant_path to
72 	 * exhalbtc_bind_bt_coex_withadapter()
73 	 */
74 }
75 
76 void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv)
77 {
78 	u8 bt_exist;
79 
80 	bt_exist = rtl_get_hwpg_bt_exist(rtlpriv);
81 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
82 		"%s, bt_exist is %d\n", __func__, bt_exist);
83 
84 	exhalbtc_init_hw_config(&gl_bt_coexist, !bt_exist);
85 	exhalbtc_init_coex_dm(&gl_bt_coexist);
86 }
87 
88 void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
89 {
90 	exhalbtc_ips_notify(&gl_bt_coexist, type);
91 }
92 
93 void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type)
94 {
95 	exhalbtc_lps_notify(&gl_bt_coexist, type);
96 }
97 
98 void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
99 {
100 	exhalbtc_scan_notify(&gl_bt_coexist, scantype);
101 }
102 
103 void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
104 {
105 	exhalbtc_connect_notify(&gl_bt_coexist, action);
106 }
107 
108 void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
109 				enum rt_media_status mstatus)
110 {
111 	exhalbtc_mediastatus_notify(&gl_bt_coexist, mstatus);
112 }
113 
114 void rtl_btc_periodical(struct rtl_priv *rtlpriv)
115 {
116 	/*rtl_bt_dm_monitor();*/
117 	exhalbtc_periodical(&gl_bt_coexist);
118 }
119 
120 void rtl_btc_halt_notify(void)
121 {
122 	struct btc_coexist *btcoexist = &gl_bt_coexist;
123 
124 	exhalbtc_halt_notify(btcoexist);
125 }
126 
127 void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
128 {
129 	exhalbtc_bt_info_notify(&gl_bt_coexist, tmp_buf, length);
130 }
131 
132 bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv)
133 {
134 	return gl_bt_coexist.bt_info.limited_dig;
135 }
136 
137 bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
138 {
139 	bool bt_change_edca = false;
140 	u32 cur_edca_val;
141 	u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
142 	u32 edca_hs;
143 	u32 edca_addr = 0x504;
144 
145 	cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
146 	if (halbtc_is_wifi_uplink(rtlpriv)) {
147 		if (cur_edca_val != edca_bt_hs_uplink) {
148 			edca_hs = edca_bt_hs_uplink;
149 			bt_change_edca = true;
150 		}
151 	} else {
152 		if (cur_edca_val != edca_bt_hs_downlink) {
153 			edca_hs = edca_bt_hs_downlink;
154 			bt_change_edca = true;
155 		}
156 	}
157 
158 	if (bt_change_edca)
159 		rtl_write_dword(rtlpriv, edca_addr, edca_hs);
160 
161 	return true;
162 }
163 
164 bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
165 {
166 	/* It seems 'bt_disabled' is never be initialized or set. */
167 	if (gl_bt_coexist.bt_info.bt_disabled)
168 		return true;
169 	else
170 		return false;
171 }
172 
173 void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type)
174 {
175 	return exhalbtc_special_packet_notify(&gl_bt_coexist, pkt_type);
176 }
177 
178 struct rtl_btc_ops *rtl_btc_get_ops_pointer(void)
179 {
180 	return &rtl_btc_operation;
181 }
182 EXPORT_SYMBOL(rtl_btc_get_ops_pointer);
183 
184 
185 enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw)
186 {
187 	struct rtl_priv *rtlpriv = rtl_priv(hw);
188 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
189 	enum rt_media_status    m_status = RT_MEDIA_DISCONNECT;
190 
191 	u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
192 
193 	if (bibss || rtlpriv->mac80211.link_state >= MAC80211_LINKED)
194 		m_status = RT_MEDIA_CONNECT;
195 
196 	return m_status;
197 }
198 
199 u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
200 {
201 	return rtlpriv->btcoexist.btc_info.btcoexist;
202 }
203 
204 MODULE_AUTHOR("Page He	<page_he@realsil.com.cn>");
205 MODULE_AUTHOR("Realtek WlanFAE	<wlanfae@realtek.com>");
206 MODULE_AUTHOR("Larry Finger	<Larry.FInger@lwfinger.net>");
207 MODULE_LICENSE("GPL");
208 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
209 
210 static int __init rtl_btcoexist_module_init(void)
211 {
212 	return 0;
213 }
214 
215 static void __exit rtl_btcoexist_module_exit(void)
216 {
217 	return;
218 }
219 
220 module_init(rtl_btcoexist_module_init);
221 module_exit(rtl_btcoexist_module_exit);
222