add rk3288 pinctrl dts code
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8723bs / os_dep / linux / custom_gpio_linux.c
1 /******************************************************************************
2  * Customer code to add GPIO control during WLAN start/stop
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18  *
19  *
20  ******************************************************************************/
21 #include "drv_types.h"
22
23 #ifdef CONFIG_PLATFORM_SPRD
24
25 //gspi func & GPIO define
26 #include <mach/gpio.h>//0915
27 #include <mach/board.h>
28
29 #if !(defined ANDROID_2X)
30
31 #ifdef CONFIG_RTL8188E
32 #include <mach/regulator.h>
33 #include <linux/regulator/consumer.h>
34 #endif // CONFIG_RTL8188E
35
36 #ifndef GPIO_WIFI_POWER
37 #define GPIO_WIFI_POWER -1
38 #endif // !GPIO_WIFI_POWER
39
40 #ifndef GPIO_WIFI_RESET
41 #define GPIO_WIFI_RESET -1
42 #endif // !GPIO_WIFI_RESET
43
44 #ifndef GPIO_WIFI_PWDN
45 #define GPIO_WIFI_PWDN -1
46 #endif // !GPIO_WIFI_RESET
47 #ifdef CONFIG_GSPI_HCI
48 extern unsigned int oob_irq;
49 #endif // CONFIG_GSPI_HCI
50
51 #ifdef CONFIG_SDIO_HCI
52 extern int rtw_mp_mode;
53 #else // !CONFIG_SDIO_HCI
54 #endif // !CONFIG_SDIO_HCI
55
56 int rtw_wifi_gpio_init(void)
57 {
58 #ifdef CONFIG_GSPI_HCI
59         if (GPIO_WIFI_IRQ > 0) {
60                 gpio_request(GPIO_WIFI_IRQ, "oob_irq");
61                 gpio_direction_input(GPIO_WIFI_IRQ);
62
63                 oob_irq = gpio_to_irq(GPIO_WIFI_IRQ);
64
65                 DBG_8192C("%s oob_irq:%d\n", __func__, oob_irq);
66         }
67 #endif
68         if (GPIO_WIFI_RESET > 0)
69                 gpio_request(GPIO_WIFI_RESET , "wifi_rst");
70         if (GPIO_WIFI_POWER > 0)
71                 gpio_request(GPIO_WIFI_POWER, "wifi_power");
72
73 #ifdef CONFIG_SDIO_HCI
74 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1) 
75         if(rtw_mp_mode==1){
76                 DBG_871X("%s GPIO_BT_RESET pin special for mp_test\n", __func__);       
77                 if (GPIO_BT_RESET > 0)
78                         gpio_request(GPIO_BT_RESET , "bt_rst");
79         }
80 #endif
81 #endif
82         return 0;
83 }
84
85 int rtw_wifi_gpio_deinit(void)
86 {
87 #ifdef CONFIG_GSPI_HCI
88         if (GPIO_WIFI_IRQ > 0)
89                 gpio_free(GPIO_WIFI_IRQ);
90 #endif
91         if (GPIO_WIFI_RESET > 0)
92                 gpio_free(GPIO_WIFI_RESET );
93         if (GPIO_WIFI_POWER > 0)
94                 gpio_free(GPIO_WIFI_POWER);
95
96 #ifdef CONFIG_SDIO_HCI
97 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1) 
98         if(rtw_mp_mode==1){
99                 DBG_871X("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
100                 if (GPIO_BT_RESET > 0)
101                         gpio_free(GPIO_BT_RESET);
102         }
103 #endif
104 #endif
105         return 0;
106 }
107
108 /* Customer function to control hw specific wlan gpios */
109 void rtw_wifi_gpio_wlan_ctrl(int onoff)
110 {
111         switch (onoff)
112         {
113                 case WLAN_PWDN_OFF:
114                         DBG_8192C("%s: call customer specific GPIO(%d) to set wifi power down pin to 0\n",
115                                 __FUNCTION__, GPIO_WIFI_RESET);
116
117 #ifndef CONFIG_DONT_BUS_SCAN
118                         if (GPIO_WIFI_RESET > 0)
119                                 gpio_direction_output(GPIO_WIFI_RESET , 0);
120 #endif
121                 break;
122
123                 case WLAN_PWDN_ON:
124                         DBG_8192C("%s: callc customer specific GPIO(%d) to set wifi power down pin to 1\n",
125                                 __FUNCTION__, GPIO_WIFI_RESET);
126
127                         if (GPIO_WIFI_RESET > 0)
128                                 gpio_direction_output(GPIO_WIFI_RESET , 1);
129                 break;
130
131                 case WLAN_POWER_OFF:
132                 break;
133
134                 case WLAN_POWER_ON:
135                 break;
136 #ifdef CONFIG_SDIO_HCI
137 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1) 
138                 case WLAN_BT_PWDN_OFF:
139                 if(rtw_mp_mode==1)
140                 {
141                         DBG_871X("%s: call customer specific GPIO to set wifi power down pin to 0\n",
142                                         __FUNCTION__);
143                         if (GPIO_BT_RESET > 0)
144                                 gpio_direction_output(GPIO_BT_RESET , 0);
145                 }
146                 break;
147
148                 case WLAN_BT_PWDN_ON:
149                 if(rtw_mp_mode==1)
150                 {
151                         DBG_871X("%s: callc customer specific GPIO to set wifi power down pin to 1 %x\n",
152                                         __FUNCTION__, GPIO_BT_RESET);
153
154                         if (GPIO_BT_RESET > 0)
155                                 gpio_direction_output(GPIO_BT_RESET , 1);
156                 }
157                 break;
158 #endif
159 #endif
160         }
161 }
162
163 #else //ANDROID_2X
164
165 #include <mach/ldo.h>
166
167 #ifdef CONFIG_RTL8188E
168 extern int sprd_3rdparty_gpio_wifi_power;
169 #endif
170 extern int sprd_3rdparty_gpio_wifi_pwd;
171 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
172 extern int sprd_3rdparty_gpio_bt_reset;
173 #endif
174
175 int rtw_wifi_gpio_init(void)
176 {
177 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
178         if (sprd_3rdparty_gpio_bt_reset > 0)
179                 gpio_direction_output(sprd_3rdparty_gpio_bt_reset, 1);
180 #endif
181
182         return 0;
183 }
184
185 int rtw_wifi_gpio_deinit(void)
186 {
187         return 0;
188 }
189
190 /* Customer function to control hw specific wlan gpios */
191 void rtw_wifi_gpio_wlan_ctrl(int onoff)
192 {
193         switch (onoff)
194         {
195                 case WLAN_PWDN_OFF:
196                         DBG_8192C("%s: call customer specific GPIO to set wifi power down pin to 0\n",
197                                 __FUNCTION__);
198                         if (sprd_3rdparty_gpio_wifi_pwd > 0)
199                         {
200                                 gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 0);
201                         }
202
203                         if (sprd_3rdparty_gpio_wifi_pwd == 60) {
204                                 DBG_8192C("%s: turn off VSIM2 2.8V\n", __func__);
205                                 LDO_TurnOffLDO(LDO_LDO_SIM2);
206                         }
207                 break;
208
209                 case WLAN_PWDN_ON:
210                         DBG_8192C("%s: callc customer specific GPIO to set wifi power down pin to 1\n",
211                                 __FUNCTION__);
212                         if (sprd_3rdparty_gpio_wifi_pwd == 60) {
213                                 DBG_8192C("%s: turn on VSIM2 2.8V\n", __func__);
214                                 LDO_SetVoltLevel(LDO_LDO_SIM2, LDO_VOLT_LEVEL0);
215                                 LDO_TurnOnLDO(LDO_LDO_SIM2);
216                         }
217                         if (sprd_3rdparty_gpio_wifi_pwd > 0)
218                         {
219                                 gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 1);
220                         }
221                 break;
222
223                 case WLAN_POWER_OFF:
224 #ifdef CONFIG_RTL8188E
225 #ifdef CONFIG_WIF1_LDO
226                         DBG_8192C("%s: turn off VDD-WIFI0 1.2V\n", __FUNCTION__);
227                         LDO_TurnOffLDO(LDO_LDO_WIF1);
228 #endif //CONFIG_WIF1_LDO
229
230                         DBG_8192C("%s: turn off VDD-WIFI0 3.3V\n", __FUNCTION__);
231                         LDO_TurnOffLDO(LDO_LDO_WIF0);
232
233                         DBG_8192C("%s: call customer specific GPIO(%d) to turn off wifi power\n",
234                                 __FUNCTION__, sprd_3rdparty_gpio_wifi_power);
235                         if (sprd_3rdparty_gpio_wifi_power != 65535)
236                                 gpio_set_value(sprd_3rdparty_gpio_wifi_power, 0);
237 #endif
238                 break;
239
240                 case WLAN_POWER_ON:
241 #ifdef CONFIG_RTL8188E
242                         DBG_8192C("%s: call customer specific GPIO(%d) to turn on wifi power\n",
243                                 __FUNCTION__, sprd_3rdparty_gpio_wifi_power);
244                         if (sprd_3rdparty_gpio_wifi_power != 65535)
245                                 gpio_set_value(sprd_3rdparty_gpio_wifi_power, 1);
246
247                         DBG_8192C("%s: turn on VDD-WIFI0 3.3V\n", __FUNCTION__);
248                         LDO_TurnOnLDO(LDO_LDO_WIF0);
249                         LDO_SetVoltLevel(LDO_LDO_WIF0,LDO_VOLT_LEVEL1);
250
251 #ifdef CONFIG_WIF1_LDO
252                         DBG_8192C("%s: turn on VDD-WIFI1 1.2V\n", __func__);
253                         LDO_TurnOnLDO(LDO_LDO_WIF1);
254                         LDO_SetVoltLevel(LDO_LDO_WIF1,LDO_VOLT_LEVEL3);
255 #endif //CONFIG_WIF1_LDO
256 #endif
257                 break;
258
259                 case WLAN_BT_PWDN_OFF:
260                         DBG_8192C("%s: call customer specific GPIO to set bt power down pin to 0\n",
261                                 __FUNCTION__);
262 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
263                         if (sprd_3rdparty_gpio_bt_reset > 0)
264                                 gpio_set_value(sprd_3rdparty_gpio_bt_reset, 0);
265 #endif
266                 break;
267
268                 case WLAN_BT_PWDN_ON:
269                         DBG_8192C("%s: callc customer specific GPIO to set bt power down pin to 1\n",
270                                 __FUNCTION__);
271 #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
272                         if (sprd_3rdparty_gpio_bt_reset > 0)
273                                 gpio_set_value(sprd_3rdparty_gpio_bt_reset, 1);
274 #endif
275                 break;
276         }
277 }
278 #endif //ANDROID_2X
279
280 #else // !CONFIG_PLATFORM_SPRD
281
282 int rtw_wifi_gpio_init(void)
283 {
284         return 0;
285 }
286
287 void rtw_wifi_gpio_wlan_ctrl(int onoff)
288 {
289 }
290 #endif //CONFIG_PLATFORM_SPRD