1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 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 *****************************************************************************/
15 #include "drv_types.h"
16
17 #ifdef CONFIG_PLATFORM_SPRD
18
19 /* gspi func & GPIO define */
20 #include <mach/gpio.h>/* 0915 */
21 #include <mach/board.h>
22
23 #if !(defined ANDROID_2X)
24
25 #ifdef CONFIG_RTL8188E
26 #include <mach/regulator.h>
27 #include <linux/regulator/consumer.h>
28 #endif /* CONFIG_RTL8188E */
29
30 #ifndef GPIO_WIFI_POWER
31 #define GPIO_WIFI_POWER -1
32 #endif /* !GPIO_WIFI_POWER */
33
34 #ifndef GPIO_WIFI_RESET
35 #define GPIO_WIFI_RESET -1
36 #endif /* !GPIO_WIFI_RESET */
37
38 #ifndef GPIO_WIFI_PWDN
39 #define GPIO_WIFI_PWDN -1
40 #endif /* !GPIO_WIFI_RESET */
41 #ifdef CONFIG_GSPI_HCI
42 extern unsigned int oob_irq;
43 #endif /* CONFIG_GSPI_HCI */
44
45 #ifdef CONFIG_SDIO_HCI
46 extern int rtw_mp_mode;
47 #else /* !CONFIG_SDIO_HCI */
48 #endif /* !CONFIG_SDIO_HCI */
49
rtw_wifi_gpio_init(void)50 int rtw_wifi_gpio_init(void)
51 {
52 #ifdef CONFIG_GSPI_HCI
53 if (GPIO_WIFI_IRQ > 0) {
54 gpio_request(GPIO_WIFI_IRQ, "oob_irq");
55 gpio_direction_input(GPIO_WIFI_IRQ);
56
57 oob_irq = gpio_to_irq(GPIO_WIFI_IRQ);
58
59 RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq);
60 }
61 #endif
62 if (GPIO_WIFI_RESET > 0)
63 gpio_request(GPIO_WIFI_RESET , "wifi_rst");
64 if (GPIO_WIFI_POWER > 0)
65 gpio_request(GPIO_WIFI_POWER, "wifi_power");
66
67 #ifdef CONFIG_SDIO_HCI
68 #if (defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
69 if (rtw_mp_mode == 1) {
70 RTW_INFO("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
71 if (GPIO_BT_RESET > 0)
72 gpio_request(GPIO_BT_RESET , "bt_rst");
73 }
74 #endif
75 #endif
76 return 0;
77 }
78
rtw_wifi_gpio_deinit(void)79 int rtw_wifi_gpio_deinit(void)
80 {
81 #ifdef CONFIG_GSPI_HCI
82 if (GPIO_WIFI_IRQ > 0)
83 gpio_free(GPIO_WIFI_IRQ);
84 #endif
85 if (GPIO_WIFI_RESET > 0)
86 gpio_free(GPIO_WIFI_RESET);
87 if (GPIO_WIFI_POWER > 0)
88 gpio_free(GPIO_WIFI_POWER);
89
90 #ifdef CONFIG_SDIO_HCI
91 #if (defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
92 if (rtw_mp_mode == 1) {
93 RTW_INFO("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
94 if (GPIO_BT_RESET > 0)
95 gpio_free(GPIO_BT_RESET);
96 }
97 #endif
98 #endif
99 return 0;
100 }
101
102 /* Customer function to control hw specific wlan gpios */
rtw_wifi_gpio_wlan_ctrl(int onoff)103 void rtw_wifi_gpio_wlan_ctrl(int onoff)
104 {
105 switch (onoff) {
106 case WLAN_PWDN_OFF:
107 RTW_INFO("%s: call customer specific GPIO(%d) to set wifi power down pin to 0\n",
108 __FUNCTION__, GPIO_WIFI_RESET);
109
110 #ifndef CONFIG_DONT_BUS_SCAN
111 if (GPIO_WIFI_RESET > 0)
112 gpio_direction_output(GPIO_WIFI_RESET , 0);
113 #endif
114 break;
115
116 case WLAN_PWDN_ON:
117 RTW_INFO("%s: callc customer specific GPIO(%d) to set wifi power down pin to 1\n",
118 __FUNCTION__, GPIO_WIFI_RESET);
119
120 if (GPIO_WIFI_RESET > 0)
121 gpio_direction_output(GPIO_WIFI_RESET , 1);
122 break;
123
124 case WLAN_POWER_OFF:
125 break;
126
127 case WLAN_POWER_ON:
128 break;
129 #ifdef CONFIG_SDIO_HCI
130 #if (defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
131 case WLAN_BT_PWDN_OFF:
132 if (rtw_mp_mode == 1) {
133 RTW_INFO("%s: call customer specific GPIO to set wifi power down pin to 0\n",
134 __FUNCTION__);
135 if (GPIO_BT_RESET > 0)
136 gpio_direction_output(GPIO_BT_RESET , 0);
137 }
138 break;
139
140 case WLAN_BT_PWDN_ON:
141 if (rtw_mp_mode == 1) {
142 RTW_INFO("%s: callc customer specific GPIO to set wifi power down pin to 1 %x\n",
143 __FUNCTION__, GPIO_BT_RESET);
144
145 if (GPIO_BT_RESET > 0)
146 gpio_direction_output(GPIO_BT_RESET , 1);
147 }
148 break;
149 #endif
150 #endif
151 }
152 }
153
154 #else /* ANDROID_2X */
155
156 #include <mach/ldo.h>
157
158 #ifdef CONFIG_RTL8188E
159 extern int sprd_3rdparty_gpio_wifi_power;
160 #endif
161 extern int sprd_3rdparty_gpio_wifi_pwd;
162 #if defined(CONFIG_RTL8723B)
163 extern int sprd_3rdparty_gpio_bt_reset;
164 #endif
165
rtw_wifi_gpio_init(void)166 int rtw_wifi_gpio_init(void)
167 {
168 #if defined(CONFIG_RTL8723B)
169 if (sprd_3rdparty_gpio_bt_reset > 0)
170 gpio_direction_output(sprd_3rdparty_gpio_bt_reset, 1);
171 #endif
172
173 return 0;
174 }
175
rtw_wifi_gpio_deinit(void)176 int rtw_wifi_gpio_deinit(void)
177 {
178 return 0;
179 }
180
181 /* Customer function to control hw specific wlan gpios */
rtw_wifi_gpio_wlan_ctrl(int onoff)182 void rtw_wifi_gpio_wlan_ctrl(int onoff)
183 {
184 switch (onoff) {
185 case WLAN_PWDN_OFF:
186 RTW_INFO("%s: call customer specific GPIO to set wifi power down pin to 0\n",
187 __FUNCTION__);
188 if (sprd_3rdparty_gpio_wifi_pwd > 0)
189 gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 0);
190
191 if (sprd_3rdparty_gpio_wifi_pwd == 60) {
192 RTW_INFO("%s: turn off VSIM2 2.8V\n", __func__);
193 LDO_TurnOffLDO(LDO_LDO_SIM2);
194 }
195 break;
196
197 case WLAN_PWDN_ON:
198 RTW_INFO("%s: callc customer specific GPIO to set wifi power down pin to 1\n",
199 __FUNCTION__);
200 if (sprd_3rdparty_gpio_wifi_pwd == 60) {
201 RTW_INFO("%s: turn on VSIM2 2.8V\n", __func__);
202 LDO_SetVoltLevel(LDO_LDO_SIM2, LDO_VOLT_LEVEL0);
203 LDO_TurnOnLDO(LDO_LDO_SIM2);
204 }
205 if (sprd_3rdparty_gpio_wifi_pwd > 0)
206 gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 1);
207 break;
208
209 case WLAN_POWER_OFF:
210 #ifdef CONFIG_RTL8188E
211 #ifdef CONFIG_WIF1_LDO
212 RTW_INFO("%s: turn off VDD-WIFI0 1.2V\n", __FUNCTION__);
213 LDO_TurnOffLDO(LDO_LDO_WIF1);
214 #endif /* CONFIG_WIF1_LDO */
215
216 RTW_INFO("%s: turn off VDD-WIFI0 3.3V\n", __FUNCTION__);
217 LDO_TurnOffLDO(LDO_LDO_WIF0);
218
219 RTW_INFO("%s: call customer specific GPIO(%d) to turn off wifi power\n",
220 __FUNCTION__, sprd_3rdparty_gpio_wifi_power);
221 if (sprd_3rdparty_gpio_wifi_power != 65535)
222 gpio_set_value(sprd_3rdparty_gpio_wifi_power, 0);
223 #endif
224 break;
225
226 case WLAN_POWER_ON:
227 #ifdef CONFIG_RTL8188E
228 RTW_INFO("%s: call customer specific GPIO(%d) to turn on wifi power\n",
229 __FUNCTION__, sprd_3rdparty_gpio_wifi_power);
230 if (sprd_3rdparty_gpio_wifi_power != 65535)
231 gpio_set_value(sprd_3rdparty_gpio_wifi_power, 1);
232
233 RTW_INFO("%s: turn on VDD-WIFI0 3.3V\n", __FUNCTION__);
234 LDO_TurnOnLDO(LDO_LDO_WIF0);
235 LDO_SetVoltLevel(LDO_LDO_WIF0, LDO_VOLT_LEVEL1);
236
237 #ifdef CONFIG_WIF1_LDO
238 RTW_INFO("%s: turn on VDD-WIFI1 1.2V\n", __func__);
239 LDO_TurnOnLDO(LDO_LDO_WIF1);
240 LDO_SetVoltLevel(LDO_LDO_WIF1, LDO_VOLT_LEVEL3);
241 #endif /* CONFIG_WIF1_LDO */
242 #endif
243 break;
244
245 case WLAN_BT_PWDN_OFF:
246 RTW_INFO("%s: call customer specific GPIO to set bt power down pin to 0\n",
247 __FUNCTION__);
248 #if defined(CONFIG_RTL8723B)
249 if (sprd_3rdparty_gpio_bt_reset > 0)
250 gpio_set_value(sprd_3rdparty_gpio_bt_reset, 0);
251 #endif
252 break;
253
254 case WLAN_BT_PWDN_ON:
255 RTW_INFO("%s: callc customer specific GPIO to set bt power down pin to 1\n",
256 __FUNCTION__);
257 #if defined(CONFIG_RTL8723B)
258 if (sprd_3rdparty_gpio_bt_reset > 0)
259 gpio_set_value(sprd_3rdparty_gpio_bt_reset, 1);
260 #endif
261 break;
262 }
263 }
264 #endif /* ANDROID_2X */
265
266 #elif defined(CONFIG_PLATFORM_ARM_RK3066)
267 #include <mach/iomux.h>
268
269 #define GPIO_WIFI_IRQ RK30_PIN2_PC2
270 extern unsigned int oob_irq;
rtw_wifi_gpio_init(void)271 int rtw_wifi_gpio_init(void)
272 {
273 #ifdef CONFIG_GSPI_HCI
274 if (GPIO_WIFI_IRQ > 0) {
275 rk30_mux_api_set(GPIO2C2_LCDC1DATA18_SMCBLSN1_HSADCDATA5_NAME, GPIO2C_GPIO2C2);/* jacky_test */
276 gpio_request(GPIO_WIFI_IRQ, "oob_irq");
277 gpio_direction_input(GPIO_WIFI_IRQ);
278
279 oob_irq = gpio_to_irq(GPIO_WIFI_IRQ);
280
281 RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq);
282 }
283 #endif
284 return 0;
285 }
286
287
rtw_wifi_gpio_deinit(void)288 int rtw_wifi_gpio_deinit(void)
289 {
290 #ifdef CONFIG_GSPI_HCI
291 if (GPIO_WIFI_IRQ > 0)
292 gpio_free(GPIO_WIFI_IRQ);
293 #endif
294 return 0;
295 }
296
rtw_wifi_gpio_wlan_ctrl(int onoff)297 void rtw_wifi_gpio_wlan_ctrl(int onoff)
298 {
299 }
300
301 #ifdef CONFIG_GPIO_API
302 /* this is a demo for extending GPIO pin[7] as interrupt mode */
303 struct net_device *rtl_net;
304 extern int rtw_register_gpio_interrupt(struct net_device *netdev, int gpio_num, void(*callback)(u8 level));
305 extern int rtw_disable_gpio_interrupt(struct net_device *netdev, int gpio_num);
gpio_int(u8 is_high)306 void gpio_int(u8 is_high)
307 {
308 RTW_INFO("%s level=%d\n", __func__, is_high);
309 }
register_net_gpio_init(void)310 int register_net_gpio_init(void)
311 {
312 rtl_net = dev_get_by_name(&init_net, "wlan0");
313 if (!rtl_net) {
314 RTW_PRINT("rtl_net init fail!\n");
315 return -1;
316 }
317 return rtw_register_gpio_interrupt(rtl_net, 7, gpio_int);
318 }
unregister_net_gpio_init(void)319 int unregister_net_gpio_init(void)
320 {
321 rtl_net = dev_get_by_name(&init_net, "wlan0");
322 if (!rtl_net) {
323 RTW_PRINT("rtl_net init fail!\n");
324 return -1;
325 }
326 return rtw_disable_gpio_interrupt(rtl_net, 7);
327 }
328 #endif
329
330 #else
331
rtw_wifi_gpio_init(void)332 int rtw_wifi_gpio_init(void)
333 {
334 return 0;
335 }
336
rtw_wifi_gpio_wlan_ctrl(int onoff)337 void rtw_wifi_gpio_wlan_ctrl(int onoff)
338 {
339 }
340 #endif /* CONFIG_PLATFORM_SPRD */
341