xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/ssv6xxx/platforms/aml-s905-generic-wlan.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 #include <linux/cpufreq.h>
28 #include <linux/notifier.h>
29 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
30 #include <linux/printk.h>
31 #include <linux/err.h>
32 #else
33 #include <config/printk.h>
34 #endif
35 #include <linux/amlogic/aml_thermal_hw.h>
36 extern void sdio_reinit(void);
37 extern void extern_wifi_set_enable(int is_on);
38 extern int ssv6xxx_get_dev_status(void);
39 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
40 extern int wifi_setup_dt(void);
41 #endif
42 #define GPIO_REG_WRITEL(val,reg) \
43  do { \
44   __raw_writel(val, CTL_PIN_BASE + (reg)); \
45  } while (0)
46 struct semaphore icomm_chipup_sem;
47 static int g_wifidev_registered = 0;
48 char ssvcabrio_fw_name[50] = "ssv6051-sw.bin";
49 extern int ssvdevice_init(void);
50 extern void ssvdevice_exit(void);
51 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
52 extern int aes_init(void);
53 extern void aes_fini(void);
54 extern int sha1_mod_init(void);
55 extern void sha1_mod_fini(void);
56 #endif
57 extern int max_aggr_num;
aml_cpufreq_notifier(struct notifier_block * nb,unsigned long event,void * data)58 static int aml_cpufreq_notifier(struct notifier_block *nb,
59                                          unsigned long event, void *data)
60 {
61         struct cpufreq_freqs *frq = data;
62  int cpu_temp;
63  if((int)frq->cpu != 0 || (int)event == CPUFREQ_TRANSITION_NOTIFIER)
64   return 0;
65  cpu_temp = get_cpu_temp();
66  if(cpu_temp >= 85 && max_aggr_num != 3 )
67   max_aggr_num = 3;
68  else if(cpu_temp <= 83 && max_aggr_num != 24 )
69   max_aggr_num = 24;
70  printk(KERN_INFO "SSV set max_aggr_num : %d\n",max_aggr_num);
71  printk(KERN_INFO "SSV get temp : cur_temp = %d\n",cpu_temp);
72  printk(KERN_INFO "event=%d, cpu=%d, old =%d, new = %d\n", (int)event, (int)frq->cpu, (int)frq->old, (int)frq->new);
73         return 0;
74 }
75 static struct notifier_block aml_cpufreq_notifier_block = {
76         .notifier_call = aml_cpufreq_notifier,
77 };
ssv_wifi_power(void)78 void ssv_wifi_power(void)
79 {
80  extern_wifi_set_enable(0);
81  mdelay(150);
82  extern_wifi_set_enable(1);
83  mdelay(150);
84  sdio_reinit();
85  mdelay(150);
86 }
initWlan(void)87 int initWlan(void)
88 {
89  int ret = 0;
90 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
91  if (wifi_setup_dt()) {
92   printk("wifi_dt : fail to setup dt\n");
93   goto fail;
94  }
95 #endif
96  ssv_wifi_power();
97  g_wifidev_registered = 1;
98 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
99 fail:
100 #endif
101  up(&icomm_chipup_sem);
102  return ret;
103 }
exitWlan(void)104 void exitWlan(void)
105 {
106  if (g_wifidev_registered) {
107   ssvdevice_exit();
108   extern_wifi_set_enable(0);
109   g_wifidev_registered = 0;
110   mdelay(150);
111  }
112  return;
113 }
generic_wifi_init_module(void)114 static __init int generic_wifi_init_module(void)
115 {
116  int ret, time = 5;
117  printk("%s\n", __func__);
118  sema_init(&icomm_chipup_sem, 0);
119 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
120  sha1_mod_init();
121  aes_init();
122 #endif
123  ret = initWlan();
124  if (down_timeout(&icomm_chipup_sem, msecs_to_jiffies(1000)) != 0) {
125   ret = -EINVAL;
126   printk(KERN_ALERT "%s: platform_driver_register timeout\n",
127          __FUNCTION__);
128   goto out;
129  }
130  ret = ssvdevice_init();
131  while(time-- > 0){
132   mdelay(500);
133   if(ssv6xxx_get_dev_status() == 1)
134    break;
135   printk("%s : Retry to carddetect\n",__func__);
136   ssv_wifi_power();
137  }
138     cpufreq_register_notifier(&aml_cpufreq_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
139 out:
140  printk("generic_wifi_init finished\n");
141  return ret;
142 }
generic_wifi_exit_module(void)143 static __exit void generic_wifi_exit_module(void)
144 {
145  printk("%s\n", __func__);
146 #ifdef CONFIG_SSV_SUPPORT_AES_ASM
147  aes_fini();
148  sha1_mod_fini();
149 #endif
150  exitWlan();
151     cpufreq_unregister_notifier(&aml_cpufreq_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
152 }
153 EXPORT_SYMBOL(generic_wifi_init_module);
154 EXPORT_SYMBOL(generic_wifi_exit_module);
155 module_init(generic_wifi_init_module);
156 module_exit(generic_wifi_exit_module);
157 MODULE_LICENSE("Dual BSD/GPL");
158