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 #ifdef CONFIG_RTL8192CU
21 count = sprintf(_buf, "%s", "RTL8188CU");
22 printk("Current WiFi chip is RTL8188CU.\n");
25 #ifdef CONFIG_RTL8192DU
26 count = sprintf(_buf, "%s", "RTL8192DU");
27 printk("Current WiFi chip is RTL8192DU.\n");
30 if(type == WIFI_RTL8188EU) {
31 #ifdef CONFIG_RTL8188EU
32 count = sprintf(_buf, "%s", "RTL8188EU");
33 printk("Current WiFi chip is RTL8188EU.\n");
37 #ifdef CONFIG_RTL8723AU
38 count = sprintf(_buf, "%s", "RTL8723AU");
39 printk("Current WiFi chip is RTL8723AU.\n");
42 #ifdef CONFIG_RTL8723BS
43 count = sprintf(_buf, "%s", "RTL8723BS");
44 printk("Current WiFi chip is RTL8723BS.\n");
47 if(type == WIFI_RKWIFI) {
49 count = sprintf(_buf, "%s", "BCM4330");
50 printk("Current WiFi chip is BCM4330.\n");
54 count = sprintf(_buf, "%s", "RK901");
55 printk("Current WiFi chip is RK901.\n");
59 count = sprintf(_buf, "%s", "RK903");
60 printk("Current WiFi chip is RK903.\n");
64 count = sprintf(_buf, "%s", "RK901");
65 printk("Current WiFi chip is AP6181.\n");
69 count = sprintf(_buf, "%s", "RK901");
70 printk("Current WiFi chip is AP6210.\n");
74 count = sprintf(_buf, "%s", "AP6234");
75 printk("Current WiFi chip is AP6234.\n");
79 count = sprintf(_buf, "%s", "RK903");
80 printk("Current WiFi chip is AP6330.\n");
84 count = sprintf(_buf, "%s", "AP6335");
85 printk("Current WiFi chip is AP6335.\n");
89 count = sprintf(_buf, "%s", "AP6441");
90 printk("Current WiFi chip is AP6441.\n");
94 count = sprintf(_buf, "%s", "RK901");
95 printk("Current WiFi chip is AP6476.\n");
99 count = sprintf(_buf, "%s", "RK903");
100 printk("Current WiFi chip is AP6493.\n");
103 #ifdef CONFIG_GB86302I
104 count = sprintf(_buf, "%s", "RK903");
105 printk("Current WiFi chip is GB86302I.\n");
109 #ifdef CONFIG_MTK_COMBO
110 count = sprintf(_buf, "%s", "MT6620");
111 printk("Current WiFi chip is MT6620.\n");
115 count = sprintf(_buf, "%s", "MT5931");
116 printk("Current WiFi chip is MT5931.\n");
119 #ifdef CONFIG_MT5931_MT6622
120 count = sprintf(_buf, "%s", "MT5931");
121 printk("Current WiFi chip is MT5931.\n");
124 #ifdef CONFIG_MTK_MT5931
125 count = sprintf(_buf, "%s", "MT5931");
126 printk("Current WiFi chip is MT5931.\n");
130 count = sprintf(_buf, "%s", "MT7601");
131 printk("Current WiFi chip is MT7601.\n");
134 if(type == WIFI_ESP8089) {
135 #ifdef CONFIG_ESP8089
136 count = sprintf(_buf, "%s", "ESP8089");
137 printk("Current WiFi chip is ESP8089.\n");
144 static ssize_t wifi_power_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
147 poweren = simple_strtol(_buf, NULL, 10);
148 printk("%s: poweren = %d\n", __func__, poweren);
150 rockchip_wifi_power(1);
152 rockchip_wifi_power(0);
158 #ifdef CONFIG_WIFI_NONE
159 int rockchip_wifi_init_module(void) {return 0;}
160 void rockchip_wifi_exit_module(void) {return;}
162 extern int rockchip_wifi_init_module(void);
163 extern void rockchip_wifi_exit_module(void);
164 extern int rockchip_wifi_init_module_rkwifi(void);
165 extern void rockchip_wifi_exit_module_rkwifi(void);
166 extern int rockchip_wifi_init_module_rtl8188eu(void);
167 extern void rockchip_wifi_exit_module_rtl8188eu(void);
168 extern int rockchip_wifi_init_module_esp8089(void);
169 extern void rockchip_wifi_exit_module_esp8089(void);
171 static struct semaphore driver_sem;
172 static int wifi_driver_insmod = 0;
174 static int wifi_init_exit_module(int enable)
177 int type = get_wifi_chip_type();
179 if (type == WIFI_RKWIFI) {
181 ret = rockchip_wifi_init_module_rkwifi();
183 rockchip_wifi_exit_module_rkwifi();
187 #ifdef CONFIG_RTL8188EU
188 if (type == WIFI_RTL8188EU) {
190 ret = rockchip_wifi_init_module_rtl8188eu();
192 rockchip_wifi_exit_module_rtl8188eu();
196 #ifdef CONFIG_ESP8089
197 if (type == WIFI_ESP8089) {
199 ret = rockchip_wifi_init_module_esp8089();
201 rockchip_wifi_exit_module_esp8089();
206 #if !defined(CONFIG_RKWIFI) && !defined(CONFIG_RTL8188EU) && !defined(CONFIG_ESP8089)
209 ret = rockchip_wifi_init_module();
211 rockchip_wifi_exit_module();
218 static ssize_t wifi_driver_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
220 int enable = 0, ret = 0;
223 enable = simple_strtol(_buf, NULL, 10);
224 //printk("%s: enable = %d\n", __func__, enable);
225 if (wifi_driver_insmod == enable) {
226 printk("%s: wifi driver already %s\n", __func__, enable? "insmod":"rmmod");
231 ret = wifi_init_exit_module(enable);
233 wifi_driver_insmod = enable;
235 wifi_init_exit_module(enable);
236 wifi_driver_insmod = enable;
240 //printk("%s: ret = %d\n", __func__, ret);
244 static struct class *rkwifi_class = NULL;
245 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
246 static CLASS_ATTR(power, 0660, NULL, wifi_power_write);
247 static CLASS_ATTR(driver, 0660, NULL, wifi_driver_write);
249 int rkwifi_sysif_init(void)
253 printk("Rockchip WiFi SYS interface (V1.00) ... \n");
257 rkwifi_class = class_create(THIS_MODULE, "rkwifi");
258 if (IS_ERR(rkwifi_class))
260 printk("Create class rkwifi_class failed.\n");
264 ret = class_create_file(rkwifi_class, &class_attr_chip);
265 ret = class_create_file(rkwifi_class, &class_attr_power);
266 ret = class_create_file(rkwifi_class, &class_attr_driver);
267 sema_init(&driver_sem, 1);
272 void rkwifi_sysif_exit(void)
274 // need to remove the sys files and class
275 class_remove_file(rkwifi_class, &class_attr_chip);
276 class_remove_file(rkwifi_class, &class_attr_power);
277 class_remove_file(rkwifi_class, &class_attr_driver);
278 class_destroy(rkwifi_class);
283 module_init(rkwifi_sysif_init);
284 module_exit(rkwifi_sysif_exit);
286 MODULE_AUTHOR("Yongle Lai & gwl");
287 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
288 MODULE_LICENSE("GPL");