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_RTKWIFI) {
21 #ifdef CONFIG_RTL8192CU
22 count = sprintf(_buf, "%s", "RTL8188CU");
23 printk("Current WiFi chip is RTL8188CU.\n");
26 #ifdef CONFIG_RTL8192DU
27 count = sprintf(_buf, "%s", "RTL8192DU");
28 printk("Current WiFi chip is RTL8192DU.\n");
31 #ifdef CONFIG_RTL8188EU
32 count = sprintf(_buf, "%s", "RTL8188EU");
33 printk("Current WiFi chip is RTL8188EU.\n");
36 #ifdef CONFIG_RTL8723AU
37 count = sprintf(_buf, "%s", "RTL8723AU");
38 printk("Current WiFi chip is RTL8723AU.\n");
41 #ifdef CONFIG_RTL8723BU
42 count = sprintf(_buf, "%s", "RTL8723BU");
43 printk("Current WiFi chip is RTL8723BU.\n");
46 #ifdef CONFIG_RTL8723BS
47 count = sprintf(_buf, "%s", "RTL8723BS");
48 printk("Current WiFi chip is RTL8723BS.\n");
51 #ifdef CONFIG_RTL8723BS_VQ0
52 count = sprintf(_buf, "%s", "RTL8723BS");
53 printk("Current WiFi chip is RTL8723BS.\n");
56 #ifdef CONFIG_RTL8189ES
57 count = sprintf(_buf, "%s", "RTL8189ES");
58 printk("Current WiFi chip is RTL8189ES.\n");
61 #ifdef CONFIG_RTL8812AU
62 count = sprintf(_buf, "%s", "RTL8812AU");
63 printk("Current WiFi chip is RTL8812AU.\n");
69 if(type == WIFI_BCMWIFI) {
71 count = sprintf(_buf, "%s", "BCM4330");
72 printk("Current WiFi chip is BCM4330.\n");
76 count = sprintf(_buf, "%s", "RK901");
77 printk("Current WiFi chip is RK901.\n");
81 count = sprintf(_buf, "%s", "RK903");
82 printk("Current WiFi chip is RK903.\n");
86 count = sprintf(_buf, "%s", "RK901");
87 printk("Current WiFi chip is AP6181.\n");
91 count = sprintf(_buf, "%s", "RK901");
92 printk("Current WiFi chip is AP6210.\n");
96 count = sprintf(_buf, "%s", "AP6234");
97 printk("Current WiFi chip is AP6234.\n");
101 count = sprintf(_buf, "%s", "RK903");
102 printk("Current WiFi chip is AP6330.\n");
106 count = sprintf(_buf, "%s", "AP6335");
107 printk("Current WiFi chip is AP6335.\n");
111 count = sprintf(_buf, "%s", "AP6441");
112 printk("Current WiFi chip is AP6441.\n");
116 count = sprintf(_buf, "%s", "RK901");
117 printk("Current WiFi chip is AP6476.\n");
121 count = sprintf(_buf, "%s", "RK903");
122 printk("Current WiFi chip is AP6493.\n");
125 #ifdef CONFIG_GB86302I
126 count = sprintf(_buf, "%s", "RK903");
127 printk("Current WiFi chip is GB86302I.\n");
131 #ifdef CONFIG_MTK_COMBO
132 count = sprintf(_buf, "%s", "MT6620");
133 printk("Current WiFi chip is MT6620.\n");
137 count = sprintf(_buf, "%s", "MT5931");
138 printk("Current WiFi chip is MT5931.\n");
141 #ifdef CONFIG_MT5931_MT6622
142 count = sprintf(_buf, "%s", "MT5931");
143 printk("Current WiFi chip is MT5931.\n");
146 #ifdef CONFIG_MTK_MT5931
147 count = sprintf(_buf, "%s", "MT5931");
148 printk("Current WiFi chip is MT5931.\n");
152 count = sprintf(_buf, "%s", "MT7601");
153 printk("Current WiFi chip is MT7601.\n");
156 if(type == WIFI_ESP8089) {
157 #ifdef CONFIG_ESP8089
158 count = sprintf(_buf, "%s", "ESP8089");
159 printk("Current WiFi chip is ESP8089.\n");
166 static ssize_t wifi_power_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
169 poweren = simple_strtol(_buf, NULL, 10);
170 printk("%s: poweren = %d\n", __func__, poweren);
172 rockchip_wifi_power(1);
174 rockchip_wifi_power(0);
180 #ifdef CONFIG_WIFI_NONE
181 int rockchip_wifi_init_module(void) {return 0;}
182 void rockchip_wifi_exit_module(void) {return;}
184 extern int rockchip_wifi_init_module(void);
185 extern void rockchip_wifi_exit_module(void);
186 extern int rockchip_wifi_init_module_rkwifi(void);
187 extern void rockchip_wifi_exit_module_rkwifi(void);
188 extern int rockchip_wifi_init_module_rtkwifi(void);
189 extern void rockchip_wifi_exit_module_rtkwifi(void);
190 extern int rockchip_wifi_init_module_esp8089(void);
191 extern void rockchip_wifi_exit_module_esp8089(void);
193 static struct semaphore driver_sem;
194 static int wifi_driver_insmod = 0;
196 static int wifi_init_exit_module(int enable)
199 int type = get_wifi_chip_type();
201 if (type == WIFI_BCMWIFI) {
203 ret = rockchip_wifi_init_module_rkwifi();
205 rockchip_wifi_exit_module_rkwifi();
209 #ifdef CONFIG_RTL_WIRELESS_SOLUTION
210 if (type == WIFI_RTKWIFI) {
212 ret = rockchip_wifi_init_module_rtkwifi();
214 rockchip_wifi_exit_module_rtkwifi();
218 #ifdef CONFIG_ESP8089
219 if (type == WIFI_ESP8089) {
221 ret = rockchip_wifi_init_module_esp8089();
223 rockchip_wifi_exit_module_esp8089();
228 #if !defined(CONFIG_RKWIFI) && !defined(CONFIG_RTL_WIRELESS_SOLUTION) && !defined(CONFIG_ESP8089)
231 ret = rockchip_wifi_init_module();
233 rockchip_wifi_exit_module();
240 static ssize_t wifi_driver_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
242 int enable = 0, ret = 0;
245 enable = simple_strtol(_buf, NULL, 10);
246 //printk("%s: enable = %d\n", __func__, enable);
247 if (wifi_driver_insmod == enable) {
248 printk("%s: wifi driver already %s\n", __func__, enable? "insmod":"rmmod");
253 ret = wifi_init_exit_module(enable);
255 wifi_driver_insmod = enable;
257 wifi_init_exit_module(enable);
258 wifi_driver_insmod = enable;
262 //printk("%s: ret = %d\n", __func__, ret);
266 static struct class *rkwifi_class = NULL;
267 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
268 static CLASS_ATTR(power, 0660, NULL, wifi_power_write);
269 static CLASS_ATTR(driver, 0660, NULL, wifi_driver_write);
271 int rkwifi_sysif_init(void)
275 printk("Rockchip WiFi SYS interface (V1.00) ... \n");
279 rkwifi_class = class_create(THIS_MODULE, "rkwifi");
280 if (IS_ERR(rkwifi_class))
282 printk("Create class rkwifi_class failed.\n");
286 ret = class_create_file(rkwifi_class, &class_attr_chip);
287 ret = class_create_file(rkwifi_class, &class_attr_power);
288 ret = class_create_file(rkwifi_class, &class_attr_driver);
289 sema_init(&driver_sem, 1);
294 void rkwifi_sysif_exit(void)
296 // need to remove the sys files and class
297 class_remove_file(rkwifi_class, &class_attr_chip);
298 class_remove_file(rkwifi_class, &class_attr_power);
299 class_remove_file(rkwifi_class, &class_attr_driver);
300 class_destroy(rkwifi_class);
305 module_init(rkwifi_sysif_init);
306 module_exit(rkwifi_sysif_exit);
308 MODULE_AUTHOR("Yongle Lai & gwl");
309 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
310 MODULE_LICENSE("GPL");