1 /*
2 * Copyright (c) 2015 South Silicon Valley Microelectronics Inc.
3 * Copyright (c) 2015 iComm Corporation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <linux/irq.h>
18 #include <linux/version.h>
19 #include <linux/module.h>
20 #include <linux/vmalloc.h>
21 #include <linux/gpio.h>
22 #include <linux/mmc/host.h>
23 #include <linux/delay.h>
24 #include <linux/regulator/consumer.h>
25 #include <asm/io.h>
26 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
27 #include <linux/printk.h>
28 #include <linux/err.h>
29 #else
30 #include <config/printk.h>
31 #endif
32 extern int rockchip_wifi_power(int on);
33 extern int rockchip_wifi_set_carddetect(int val);
34 #ifdef ROCKCHIP_WIFI_AUTO_SUPPORT
35 extern char wifi_chip_type_string[];
36 #endif
37 #define GPIO_REG_WRITEL(val,reg) \
38 do { \
39 __raw_writel(val, CTL_PIN_BASE + (reg)); \
40 } while (0)
41 static int g_wifidev_registered = 0;
42 extern int ssvdevice_init(void);
43 extern void ssvdevice_exit(void);
44 extern int ssv6xxx_get_dev_status(void);
45 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
46 extern int aes_init(void);
47 extern void aes_fini(void);
48 extern int sha1_mod_init(void);
49 extern void sha1_mod_fini(void);
50 #endif
ssv_wifi_power(void)51 void ssv_wifi_power(void)
52 {
53 rockchip_wifi_set_carddetect(0);
54 msleep(150);
55 rockchip_wifi_power(0);
56 msleep(150);
57 rockchip_wifi_power(1);
58 msleep(150);
59 rockchip_wifi_set_carddetect(1);
60 msleep(150);
61 }
initWlan(void)62 int initWlan(void)
63 {
64 int ret = 0;
65 int time = 5;
66 ssv_wifi_power();
67 msleep(120);
68 g_wifidev_registered = 1;
69 ret = ssvdevice_init();
70 while(time-- > 0){
71 msleep(500);
72 if(ssv6xxx_get_dev_status() == 1)
73 break;
74 printk("%s : Retry to carddetect\n",__func__);
75 ssv_wifi_power();
76 }
77 #ifdef ROCKCHIP_WIFI_AUTO_SUPPORT
78 if (!ret) {
79 strcpy(wifi_chip_type_string, "ssv6051");
80 printk(KERN_INFO "wifi_chip_type_string : %s\n" ,wifi_chip_type_string);
81 }
82 #endif
83 return ret;
84 }
exitWlan(void)85 void exitWlan(void)
86 {
87 if (g_wifidev_registered)
88 {
89 ssvdevice_exit();
90 msleep(50);
91 #ifndef ROCKCHIP_WIFI_AUTO_SUPPORT
92 rockchip_wifi_set_carddetect(0);
93 #endif
94 rockchip_wifi_power(0);
95 g_wifidev_registered = 0;
96 }
97 return;
98 }
generic_wifi_init_module(void)99 static __init int generic_wifi_init_module(void)
100 {
101 printk("%s\n", __func__);
102 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
103 sha1_mod_init();
104 aes_init();
105 #endif
106 return initWlan();
107 }
generic_wifi_exit_module(void)108 static __exit void generic_wifi_exit_module(void)
109 {
110 printk("%s\n", __func__);
111 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
112 aes_fini();
113 sha1_mod_fini();
114 #endif
115 msleep(100);
116 exitWlan();
117 }
118 EXPORT_SYMBOL(generic_wifi_init_module);
119 EXPORT_SYMBOL(generic_wifi_exit_module);
120 module_init(generic_wifi_init_module);
121 module_exit(generic_wifi_exit_module);
122 MODULE_LICENSE("Dual BSD/GPL");
123