Merge tag 'nfs-for-3.14-3' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / rtl8821ae / btcoexist / rtl_btc.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2010  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  * 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
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <wlanfae@realtek.com>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <Larry.Finger@lwfinger.net>
27  *
28  *****************************************************************************/
29 #include <linux/vmalloc.h>
30 #include <linux/module.h>
31
32 #include "rtl_btc.h"
33 #include "halbt_precomp.h"
34
35 struct rtl_btc_ops rtl_btc_operation ={
36         .btc_init_variables = rtl_btc_init_variables,
37         .btc_init_hal_vars = rtl_btc_init_hal_vars,
38         .btc_init_hw_config = rtl_btc_init_hw_config,
39         .btc_ips_notify = rtl_btc_ips_notify,
40         .btc_scan_notify = rtl_btc_scan_notify,
41         .btc_connect_notify = rtl_btc_connect_notify,
42         .btc_mediastatus_notify = rtl_btc_mediastatus_notify,
43         .btc_periodical = rtl_btc_periodical,
44         .btc_halt_notify = rtl_btc_halt_notify,
45         .btc_btinfo_notify = rtl_btc_btinfo_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 };
50
51
52 void rtl_btc_init_variables(struct rtl_priv *rtlpriv)
53 {
54
55         exhalbtc_initlize_variables(rtlpriv);
56 }
57
58 void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv)
59 {
60         u8 ant_num;
61         u8 bt_exist;
62         u8 bt_type;
63         ant_num = rtl_get_hwpg_ant_num(rtlpriv);
64         RT_TRACE(COMP_INIT, DBG_DMESG, ("%s, antNum is %d\n", __func__, ant_num));
65
66         bt_exist = rtl_get_hwpg_bt_exist(rtlpriv);
67         RT_TRACE(COMP_INIT, DBG_DMESG, ("%s, bt_exist is %d\n", __func__, bt_exist));
68         exhalbtc_set_bt_exist(bt_exist);
69
70         bt_type = rtl_get_hwpg_bt_type(rtlpriv);
71         RT_TRACE(COMP_INIT, DBG_DMESG, ("%s, bt_type is %d\n", __func__, bt_type));
72         exhalbtc_set_chip_type(bt_type);
73
74         exhalbtc_set_ant_num(BT_COEX_ANT_TYPE_PG, ant_num);
75
76 }
77
78
79 void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv)
80 {
81         exhalbtc_init_hw_config(&gl_bt_coexist);
82         exhalbtc_init_coex_dm(&gl_bt_coexist);
83 }
84
85
86 void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
87 {
88         exhalbtc_ips_notify(&gl_bt_coexist, type);
89 }
90
91
92 void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
93 {
94         exhalbtc_scan_notify(&gl_bt_coexist, scantype);
95 }
96
97
98 void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
99 {
100         exhalbtc_connect_notify(&gl_bt_coexist, action);
101 }
102
103
104 void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv, enum rt_media_status mstatus)
105 {
106         exhalbtc_mediastatus_notify(&gl_bt_coexist, mstatus);
107 }
108
109 void rtl_btc_periodical(struct rtl_priv *rtlpriv)
110 {
111 //      rtl_bt_dm_monitor();
112         exhalbtc_periodical(&gl_bt_coexist);
113 }
114
115 void rtl_btc_halt_notify(void)
116 {
117         exhalbtc_halt_notify(&gl_bt_coexist);
118 }
119
120 void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 * tmp_buf, u8 length)
121 {
122         exhalbtc_bt_info_notify(&gl_bt_coexist, tmp_buf, length);
123 }
124
125 bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv)
126 {
127         return gl_bt_coexist.bt_info.limited_dig;
128 }
129
130 bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
131 {
132         bool bt_change_edca = false;
133         u32 cur_edca_val;
134         u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
135         u32 edca_hs;
136         u32 edca_addr = 0x504;
137
138         cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
139         if (halbtc_is_wifi_uplink(rtlpriv)){
140                 if (cur_edca_val != edca_bt_hs_uplink){
141                         edca_hs = edca_bt_hs_uplink;
142                         bt_change_edca = true;
143                 }
144         }else{
145                 if (cur_edca_val != edca_bt_hs_downlink){
146                         edca_hs = edca_bt_hs_downlink;
147                         bt_change_edca = true;
148                 }
149         }
150
151         if(bt_change_edca)
152                 rtl_write_dword(rtlpriv, edca_addr, edca_hs);
153
154         return true;
155 }
156
157 bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
158 {
159         if (gl_bt_coexist.bt_info.bt_disabled)
160                 return true;
161         else
162                 return false;
163 }
164
165 struct rtl_btc_ops *rtl_btc_get_ops_pointer(void)
166 {
167         return &rtl_btc_operation;
168 }
169 //EXPORT_SYMBOL(rtl_btc_get_ops_pointer);
170
171 u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
172 {
173         u8 num;
174
175         if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
176                 num = 2;
177         else
178                 num = 1;
179
180         return num;
181 }
182
183 #if 0
184 enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw)
185 {
186     struct rtl_priv *rtlpriv = rtl_priv(hw);
187     struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
188     enum rt_media_status    m_status = RT_MEDIA_DISCONNECT;
189
190     u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
191
192     if(bibss || rtlpriv->mac80211.link_state >= MAC80211_LINKED) {
193             m_status = RT_MEDIA_CONNECT;
194     }
195
196     return m_status;
197 }
198 #endif
199
200 u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
201 {
202         return rtlpriv->btcoexist.btc_info.btcoexist;
203 }
204
205 u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
206 {
207         return rtlpriv->btcoexist.btc_info.bt_type;
208 }
209
210
211 #if 0
212
213 MODULE_AUTHOR("Page He  <page_he@realsil.com.cn>");
214 MODULE_AUTHOR("Realtek WlanFAE  <wlanfae@realtek.com>");
215 MODULE_AUTHOR("Larry Finger     <Larry.FInger@lwfinger.net>");
216 MODULE_LICENSE("GPL");
217 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
218
219 static int __init rtl_btcoexist_module_init(void)
220 {
221
222         //printk("%s, rtlpriv->btc_ops.btc_init_variables addr is %p\n", __func__, rtlpriv->btc_ops.btc_init_variables);
223
224         return 0;
225 }
226
227 static void __exit rtl_btcoexist_module_exit(void)
228 {
229         return;
230 }
231
232 module_init(rtl_btcoexist_module_init);
233 module_exit(rtl_btcoexist_module_exit);
234
235 #endif
236