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 <linux/semaphore.h>
26 #include <asm/io.h>
27 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
28 #include <linux/printk.h>
29 #include <linux/err.h>
30 #else
31 #include <config/printk.h>
32 #endif
33 extern void sdio_reinit(void);
34 extern void extern_wifi_set_enable(int is_on);
35 extern int ssv6xxx_get_dev_status(void);
36 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
37 extern int wifi_setup_dt(void);
38 #endif
39 #define GPIO_REG_WRITEL(val,reg) \
40 do { \
41 __raw_writel(val, CTL_PIN_BASE + (reg)); \
42 } while (0)
43 struct semaphore icomm_chipup_sem;
44 static int g_wifidev_registered = 0;
45 char ssvcabrio_fw_name[50] = "ssv6051-sw.bin";
46 extern int ssvdevice_init(void);
47 extern void ssvdevice_exit(void);
48 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
49 extern int aes_init(void);
50 extern void aes_fini(void);
51 extern int sha1_mod_init(void);
52 extern void sha1_mod_fini(void);
53 #endif
ssv_wifi_power(void)54 void ssv_wifi_power(void)
55 {
56 extern_wifi_set_enable(0);
57 mdelay(150);
58 extern_wifi_set_enable(1);
59 mdelay(150);
60 sdio_reinit();
61 mdelay(150);
62 }
initWlan(void)63 int initWlan(void)
64 {
65 int ret = 0;
66 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
67 if (wifi_setup_dt()) {
68 printk("wifi_dt : fail to setup dt\n");
69 goto fail;
70 }
71 #endif
72 ssv_wifi_power();
73 g_wifidev_registered = 1;
74 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
75 fail:
76 #endif
77 up(&icomm_chipup_sem);
78 return ret;
79 }
exitWlan(void)80 void exitWlan(void)
81 {
82 if (g_wifidev_registered) {
83 ssvdevice_exit();
84 extern_wifi_set_enable(0);
85 g_wifidev_registered = 0;
86 mdelay(150);
87 }
88 return;
89 }
generic_wifi_init_module(void)90 static __init int generic_wifi_init_module(void)
91 {
92 int ret, time = 5;
93 printk("%s\n", __func__);
94 sema_init(&icomm_chipup_sem, 0);
95 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
96 sha1_mod_init();
97 aes_init();
98 #endif
99 ret = initWlan();
100 if (down_timeout(&icomm_chipup_sem, msecs_to_jiffies(1000)) != 0) {
101 ret = -EINVAL;
102 printk(KERN_ALERT "%s: platform_driver_register timeout\n",
103 __FUNCTION__);
104 goto out;
105 }
106 ret = ssvdevice_init();
107 while(time-- > 0){
108 mdelay(500);
109 if(ssv6xxx_get_dev_status() == 1)
110 break;
111 printk("%s : Retry to carddetect\n",__func__);
112 ssv_wifi_power();
113 }
114 out:
115 printk("generic_wifi_init finished\n");
116 return ret;
117 }
generic_wifi_exit_module(void)118 static __exit void generic_wifi_exit_module(void)
119 {
120 printk("%s\n", __func__);
121 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
122 aes_fini();
123 sha1_mod_fini();
124 #endif
125 exitWlan();
126 }
127 EXPORT_SYMBOL(generic_wifi_init_module);
128 EXPORT_SYMBOL(generic_wifi_exit_module);
129 module_init(generic_wifi_init_module);
130 module_exit(generic_wifi_exit_module);
131 MODULE_LICENSE("Dual BSD/GPL");
132