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
46 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
47 extern int aes_init(void);
48 extern void aes_fini(void);
49 extern int sha1_mod_init(void);
50 extern void sha1_mod_fini(void);
51 #endif
52
ssv_wifi_power(void)53 void ssv_wifi_power(void)
54 {
55 /*
56 rockchip_wifi_set_carddetect(0);
57 msleep(150);
58 rockchip_wifi_power(0);
59 msleep(150);
60 rockchip_wifi_power(1);
61 msleep(150);
62 rockchip_wifi_set_carddetect(1);*/
63 msleep(150);
64 }
65
initWlan(void)66 int initWlan(void)
67 {
68 int ret = 0;
69 int time = 5;
70 ssv_wifi_power();
71 msleep(120);
72 g_wifidev_registered = 1;
73 ret = ssvdevice_init();
74 while(time-- > 0){
75 msleep(500);
76 if(ssv6xxx_get_dev_status() == 1)
77 break;
78 printk("%s : Retry to carddetect\n",__func__);
79 ssv_wifi_power();
80 }
81 #ifdef ROCKCHIP_WIFI_AUTO_SUPPORT
82 if (!ret) {
83 strcpy(wifi_chip_type_string, "ssv6051");
84 printk(KERN_INFO "wifi_chip_type_string : %s\n" ,wifi_chip_type_string);
85 }
86 #endif
87 return ret;
88 }
exitWlan(void)89 void exitWlan(void)
90 {
91 if (g_wifidev_registered)
92 {
93 ssvdevice_exit();
94 msleep(50);
95 #ifndef ROCKCHIP_WIFI_AUTO_SUPPORT
96 rockchip_wifi_set_carddetect(0);
97 #endif
98 rockchip_wifi_power(0);
99 g_wifidev_registered = 0;
100 }
101 return;
102 }
generic_wifi_init_module(void)103 static __init int generic_wifi_init_module(void)
104 {
105 printk("%s\n", __func__);
106 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
107 sha1_mod_init();
108 aes_init();
109 #endif
110 return initWlan();
111 }
generic_wifi_exit_module(void)112 static __exit void generic_wifi_exit_module(void)
113 {
114 printk("%s\n", __func__);
115 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
116 aes_fini();
117 sha1_mod_fini();
118 #endif
119 msleep(100);
120 exitWlan();
121 }
122 EXPORT_SYMBOL(generic_wifi_init_module);
123 EXPORT_SYMBOL(generic_wifi_exit_module);
124 module_init(generic_wifi_init_module);
125 module_exit(generic_wifi_exit_module);
126 MODULE_LICENSE("Dual BSD/GPL");
127