2 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/init.h>
5 #include <linux/device.h>
7 #include <linux/delay.h>
8 #include <linux/syscalls.h>
10 #include <asm/uaccess.h>
11 #include <linux/rfkill-wlan.h>
13 extern int get_wifi_chip_type(void);
15 static ssize_t wifi_chip_read(struct class *cls, struct class_attribute *attr, char *_buf)
18 int type = get_wifi_chip_type();
20 if(type == WIFI_RK901) {
21 count = sprintf(_buf, "%s", "APRK901");
22 printk("Current WiFi chip is APRK901.\n");
25 if(type == WIFI_RK903) {
26 count = sprintf(_buf, "%s", "APRK903");
27 printk("Current WiFi chip is APRK903.\n");
30 if(type == WIFI_AP6181) {
31 count = sprintf(_buf, "%s", "AP6181");
32 printk("Current WiFi chip is AP6181.\n");
35 if(type == WIFI_AP6210) {
36 count = sprintf(_buf, "%s", "AP6210");
37 printk("Current WiFi chip is AP6210.\n");
40 if(type == WIFI_AP6212) {
41 count = sprintf(_buf, "%s", "AP6212");
42 printk("Current WiFi chip is AP6212.\n");
45 if(type == WIFI_AP6234) {
46 count = sprintf(_buf, "%s", "AP6234");
47 printk("Current WiFi chip is AP6234.\n");
50 if(type == WIFI_AP6330) {
51 count = sprintf(_buf, "%s", "AP6330");
52 printk("Current WiFi chip is AP6330.\n");
55 if(type == WIFI_AP6335) {
56 count = sprintf(_buf, "%s", "AP6335");
57 printk("Current WiFi chip is AP6335.\n");
60 if(type == WIFI_AP6354) {
61 count = sprintf(_buf, "%s", "AP6354");
62 printk("Current WiFi chip is AP6354.\n");
65 if(type == WIFI_AP6441) {
66 count = sprintf(_buf, "%s", "AP6441");
67 printk("Current WiFi chip is AP6441.\n");
70 if(type == WIFI_AP6476) {
71 count = sprintf(_buf, "%s", "AP6476");
72 printk("Current WiFi chip is AP6476.\n");
75 if(type == WIFI_AP6493) {
76 count = sprintf(_buf, "%s", "AP6493");
77 printk("Current WiFi chip is AP6493.\n");
80 if(type == WIFI_RTL8188EU) {
81 count = sprintf(_buf, "%s", "RTL8188EU");
82 printk("Current WiFi chip is RTL8188EU.\n");
85 if(type == WIFI_RTL8723BS) {
86 count = sprintf(_buf, "%s", "RTL8723BS");
87 printk("Current WiFi chip is RTL8723BS.\n");
90 if(type == WIFI_RTL8723AS) {
91 count = sprintf(_buf, "%s", "RTL8723AS");
92 printk("Current WiFi chip is RTL8723AS.\n");
95 if(type == WIFI_RTL8723BS_VQ0) {
96 count = sprintf(_buf, "%s", "RTL8723BS_VQ0");
97 printk("Current WiFi chip is RTL8723BS_VQ0.\n");
100 if(type == WIFI_RTL8723BU) {
101 count = sprintf(_buf, "%s", "RTL8723BU");
102 printk("Current WiFi chip is RTL8723BU.\n");
105 if(type == WIFI_RTL8723AU) {
106 count = sprintf(_buf, "%s", "RTL8723AU");
107 printk("Current WiFi chip is RTL8723AU.\n");
110 if(type == WIFI_RTL8189ES) {
111 count = sprintf(_buf, "%s", "RTL8189ES");
112 printk("Current WiFi chip is RTL8189ES.\n");
115 if(type == WIFI_ESP8089) {
116 count = sprintf(_buf, "%s", "ESP8089");
117 printk("Current WiFi chip is ESP8089.\n");
123 static ssize_t wifi_power_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
126 poweren = simple_strtol(_buf, NULL, 10);
127 printk("%s: poweren = %d\n", __func__, poweren);
129 rockchip_wifi_power(1);
131 rockchip_wifi_power(0);
137 #ifdef CONFIG_WIFI_NONE
138 int rockchip_wifi_init_module(void) {return 0;}
139 void rockchip_wifi_exit_module(void) {return;}
141 extern int rockchip_wifi_init_module(void);
142 extern void rockchip_wifi_exit_module(void);
143 extern int rockchip_wifi_init_module_rkwifi(void);
144 extern void rockchip_wifi_exit_module_rkwifi(void);
145 extern int rockchip_wifi_init_module_rtkwifi(void);
146 extern void rockchip_wifi_exit_module_rtkwifi(void);
147 extern int rockchip_wifi_init_module_esp8089(void);
148 extern void rockchip_wifi_exit_module_esp8089(void);
150 static struct semaphore driver_sem;
151 static int wifi_driver_insmod = 0;
153 static int wifi_init_exit_module(int enable)
157 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
158 type = get_wifi_chip_type();
160 type = get_wifi_chip_type();
161 //#ifdef CONFIG_RKWIFI
162 if (type < WIFI_AP6XXX_SERIES) {
164 ret = rockchip_wifi_init_module_rkwifi();
166 rockchip_wifi_exit_module_rkwifi();
170 //#ifdef CONFIG_RTL_WIRELESS_SOLUTION
171 if (type < WIFI_RTL_SERIES) {
173 ret = rockchip_wifi_init_module_rtkwifi();
175 rockchip_wifi_exit_module_rtkwifi();
183 static ssize_t wifi_driver_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
185 int enable = 0, ret = 0;
188 enable = simple_strtol(_buf, NULL, 10);
189 //printk("%s: enable = %d\n", __func__, enable);
190 if (wifi_driver_insmod == enable) {
191 printk("%s: wifi driver already %s\n", __func__, enable? "insmod":"rmmod");
196 ret = wifi_init_exit_module(enable);
198 wifi_driver_insmod = enable;
200 wifi_init_exit_module(enable);
201 wifi_driver_insmod = enable;
205 //printk("%s: ret = %d\n", __func__, ret);
209 static struct class *rkwifi_class = NULL;
210 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
211 static CLASS_ATTR(power, 0660, NULL, wifi_power_write);
212 static CLASS_ATTR(driver, 0660, NULL, wifi_driver_write);
213 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
214 static CLASS_ATTR(preload, 0660, NULL, NULL);
217 int rkwifi_sysif_init(void)
221 printk("Rockchip WiFi SYS interface (V1.00) ... \n");
225 rkwifi_class = class_create(THIS_MODULE, "rkwifi");
226 if (IS_ERR(rkwifi_class))
228 printk("Create class rkwifi_class failed.\n");
232 ret = class_create_file(rkwifi_class, &class_attr_chip);
233 ret = class_create_file(rkwifi_class, &class_attr_power);
234 ret = class_create_file(rkwifi_class, &class_attr_driver);
235 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
236 ret = class_create_file(rkwifi_class, &class_attr_preload);
238 sema_init(&driver_sem, 1);
243 void rkwifi_sysif_exit(void)
245 // need to remove the sys files and class
246 class_remove_file(rkwifi_class, &class_attr_chip);
247 class_remove_file(rkwifi_class, &class_attr_power);
248 class_remove_file(rkwifi_class, &class_attr_driver);
249 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
250 class_remove_file(rkwifi_class, &class_attr_preload);
252 class_destroy(rkwifi_class);
257 module_init(rkwifi_sysif_init);
258 module_exit(rkwifi_sysif_exit);
260 MODULE_AUTHOR("Yongle Lai & gwl");
261 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
262 MODULE_LICENSE("GPL");