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