e2e3864c7cb1d411f52a16e58b88d6ca0de82f02
[cascardo/linux.git] / drivers / staging / rtl8192ee / 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  * 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 <linux/vmalloc.h>
26 #include <linux/module.h>
27
28 #include "rtl_btc.h"
29 #include "halbt_precomp.h"
30
31 static struct rtl_btc_ops rtl_btc_operation = {
32         .btc_init_variables = rtl92e_btc_init_variables,
33         .btc_init_hal_vars = rtl92e_btc_init_hal_vars,
34         .btc_init_hw_config = rtl92e_btc_init_hw_config,
35         .btc_ips_notify = rtl92e_btc_ips_notify,
36         .btc_lps_notify = rtl_btc_lps_notify,
37         .btc_scan_notify = rtl92e_btc_scan_notify,
38         .btc_connect_notify = rtl92e_btc_connect_notify,
39         .btc_mediastatus_notify = rtl92e_btc_mediastatus_notify,
40         .btc_periodical = rtl92e_btc_periodical,
41         .btc_halt_notify = rtl92e_btc_halt_notify,
42         .btc_btinfo_notify = rtl92e_btc_btinfo_notify,
43         .btc_is_limited_dig = rtl92e_btc_is_limited_dig,
44         .btc_is_disable_edca_turbo = rtl92e_btc_is_disable_edca_turbo,
45         .btc_is_bt_disabled = rtl92e_btc_is_bt_disabled,
46         .btc_special_packet_notify = rtl_btc_special_packet_notify,
47 };
48
49 void rtl92e_btc_init_variables(struct rtl_priv *rtlpriv)
50 {
51         exhalbtc92e_initlize_variables(rtlpriv);
52 }
53
54 void rtl92e_btc_init_hal_vars(struct rtl_priv *rtlpriv)
55 {
56         u8 ant_num;
57         u8 bt_exist;
58         u8 bt_type;
59         ant_num = rtl92e_get_hwpg_ant_num(rtlpriv);
60         RT_TRACE(COMP_INIT, DBG_DMESG, "antNum is %d\n", ant_num);
61
62         bt_exist = rtl92e_get_hwpg_bt_exist(rtlpriv);
63         RT_TRACE(COMP_INIT, DBG_DMESG, "bt_exist is %d\n", bt_exist);
64         exhalbtc92e_set_bt_exist(bt_exist);
65
66         bt_type = rtl92e_get_hwpg_bt_type(rtlpriv);
67         RT_TRACE(COMP_INIT, DBG_DMESG, "bt_type is %d\n", bt_type);
68         exhalbtc92e_set_chip_type(bt_type);
69
70         exhalbtc92e_set_ant_num(BT_COEX_ANT_TYPE_PG, ant_num);
71 }
72
73 void rtl92e_btc_init_hw_config(struct rtl_priv *rtlpriv)
74 {
75         exhalbtc92e_init_hw_config(&gl92e_bt_coexist);
76         exhalbtc92e_init_coex_dm(&gl92e_bt_coexist);
77 }
78
79 void rtl92e_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
80 {
81         exhalbtc92e_ips_notify(&gl92e_bt_coexist, type);
82 }
83
84 void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type)
85 {
86         exhalbtc92e_lps_notify(&gl92e_bt_coexist, type);
87 }
88
89 void rtl92e_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
90 {
91         exhalbtc92e_scan_notify(&gl92e_bt_coexist, scantype);
92 }
93
94 void rtl92e_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
95 {
96         exhalbtc92e_connect_notify(&gl92e_bt_coexist, action);
97 }
98
99 void rtl92e_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
100                                    enum rt_media_status mstatus)
101 {
102         exhalbtc92e_mediastatus_notify(&gl92e_bt_coexist, mstatus);
103 }
104
105 void rtl92e_btc_periodical(struct rtl_priv *rtlpriv)
106 {
107         exhalbtc92e_periodical(&gl92e_bt_coexist);
108 }
109
110 void rtl92e_btc_halt_notify(void)
111 {
112         exhalbtc92e_halt_notify(&gl92e_bt_coexist);
113 }
114
115 void rtl92e_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
116 {
117         exhalbtc92e_bt_info_notify(&gl92e_bt_coexist, tmp_buf, length);
118 }
119
120 bool rtl92e_btc_is_limited_dig(struct rtl_priv *rtlpriv)
121 {
122         return gl92e_bt_coexist.bt_info.limited_dig;
123 }
124
125 bool rtl92e_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
126 {
127         bool bt_change_edca = false;
128         u32 cur_edca_val;
129         u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
130         u32 edca_hs;
131         u32 edca_addr = 0x504;
132
133         cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
134         if (halbtc92e_is_wifi_uplink(rtlpriv)) {
135                 if (cur_edca_val != edca_bt_hs_uplink) {
136                         edca_hs = edca_bt_hs_uplink;
137                         bt_change_edca = true;
138                 }
139         } else {
140                 if (cur_edca_val != edca_bt_hs_downlink) {
141                         edca_hs = edca_bt_hs_downlink;
142                         bt_change_edca = true;
143                 }
144         }
145
146         if (bt_change_edca)
147                 rtl_write_dword(rtlpriv, edca_addr, edca_hs);
148
149         return true;
150 }
151
152 bool rtl92e_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
153 {
154         /* It seems 'bt_disabled' is never be initialized or set. */
155         if (gl92e_bt_coexist.bt_info.bt_disabled)
156                 return true;
157         else
158                 return false;
159 }
160
161 void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type)
162 {
163         return exhalbtc92e_special_packet_notify(&gl92e_bt_coexist, pkt_type);
164 }
165
166 struct rtl_btc_ops *stg_rtl_btc_get_ops_pointer(void)
167 {
168         return &rtl_btc_operation;
169 }
170 EXPORT_SYMBOL(stg_rtl_btc_get_ops_pointer);
171
172 u8 rtl92e_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
173 {
174         u8 num;
175
176         if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
177                 num = 2;
178         else
179                 num = 1;
180
181         return num;
182 }
183 u8 rtl92e_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
184 {
185         return rtlpriv->btcoexist.btc_info.btcoexist;
186 }
187
188 u8 rtl92e_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
189 {
190         return rtlpriv->btcoexist.btc_info.bt_type;
191 }