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>
12 #ifdef CONFIG_MACH_RK_FAC
13 #include <plat/config.h>
16 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
17 static ssize_t wifi_chip_read(struct class *cls, struct class_attribute *attr, char *_buf)
19 static ssize_t wifi_chip_read(struct class *cls, char *_buf)
24 #ifdef CONFIG_MACH_RK_FAC
25 if(wifi_type==WIFI_TYPE_RTL8188CU) {
26 count = sprintf(_buf, "%s", "RTL8188CU");
27 printk("Current WiFi chip is RTL8188CU.\n");
29 } else if(wifi_type==WIFI_TYPE_RTL8188EU) {
30 count = sprintf(_buf, "%s", "RTL8188EU");
31 printk("Current WiFi chip is RTL8188EU.\n");
33 } else if(wifi_type==WIFI_TYPE_MT7601) {
34 count = sprintf(_buf, "%s", "MT7601");
35 printk("Current WiFi chip is MT7601.\n");
37 } else if(wifi_type==WIFI_TYPE_RTL8188ETV) {
38 count = sprintf(_buf, "%s", "RTL8188ETV");
39 printk("Current WiFi chip is RTL8188ETV.\n");
41 } else if(wifi_type==WIFI_TYPE_MT5370) {
42 count = sprintf(_buf, "%s", "MT5370");
43 printk("Current WiFi chip is MT5370.\n");
46 //printk("NOT surpport type %d\n",wifi_type);
51 count = sprintf(_buf, "%s", "BCM4329");
52 printk("Current WiFi chip is BCM4329.\n");
55 #ifdef CONFIG_RTL8192CU
56 count = sprintf(_buf, "%s", "RTL8188CU");
57 printk("Current WiFi chip is RTL8188CU.\n");
60 #ifdef CONFIG_RTL8188EU
61 count = sprintf(_buf, "%s", "RTL8188EU");
62 printk("Current WiFi chip is RTL8188EU.\n");
65 #ifdef CONFIG_RTL8723AU
66 count = sprintf(_buf, "%s", "RTL8723AU");
67 printk("Current WiFi chip is RTL8723AU.\n");
70 #ifdef CONFIG_RTL8189ES
71 count = sprintf(_buf, "%s", "RTL8189ES");
72 printk("Current WiFi chip is RTL8189ES.\n");
76 count = sprintf(_buf, "%s", "BCM4330");
77 printk("Current WiFi chip is BCM4330.\n");
81 #ifdef CONFIG_BCM_OOB_ENABLED
82 count = sprintf(_buf, "%s", "OOB_RK901");
83 printk("Current WiFi chip is RK901(OOB)\n");
85 count = sprintf(_buf, "%s", "RK901");
86 printk("Current WiFi chip is RK901.\n");
91 #ifdef CONFIG_BCM_OOB_ENABLED
92 count = sprintf(_buf, "%s", "OOB_RK903");
93 printk("Current WiFi chip is RK903(OOB)\n");
95 count = sprintf(_buf, "%s", "RK903");
96 printk("Current WiFi chip is RK903.\n");
101 #ifdef CONFIG_BCM_OOB_ENABLED
102 count = sprintf(_buf, "%s", "OOB_RK901");
103 printk("Current WiFi chip is AP6181(OOB)\n");
105 count = sprintf(_buf, "%s", "RK901");
106 printk("Current WiFi chip is AP6181.\n");
111 #ifdef CONFIG_BCM_OOB_ENABLED
112 count = sprintf(_buf, "%s", "OOB_RK901");
113 printk("Current WiFi chip is AP6210(OOB)\n");
115 count = sprintf(_buf, "%s", "RK901");
116 printk("Current WiFi chip is AP6210.\n");
121 #ifdef CONFIG_BCM_OOB_ENABLED
122 count = sprintf(_buf, "%s", "OOB_RK903");
123 printk("Current WiFi chip is AP6330(OOB)\n");
125 count = sprintf(_buf, "%s", "RK903");
126 printk("Current WiFi chip is AP6330.\n");
131 #ifdef CONFIG_BCM_OOB_ENABLED
132 count = sprintf(_buf, "%s", "OOB_RK901");
133 printk("Current WiFi chip is AP6476(OOB)\n");
135 count = sprintf(_buf, "%s", "RK901");
136 printk("Current WiFi chip is AP6476.\n");
141 #ifdef CONFIG_BCM_OOB_ENABLED
142 count = sprintf(_buf, "%s", "OOB_RK903");
143 printk("Current WiFi chip is AP6493(OOB)\n");
145 count = sprintf(_buf, "%s", "RK903");
146 printk("Current WiFi chip is AP6493.\n");
150 #ifdef CONFIG_GB86302I
151 #ifdef CONFIG_BCM_OOB_ENABLED
152 count = sprintf(_buf, "%s", "OOB_RK903");
153 printk("Current WiFi chip is GB86302I(OOB)\n");
155 count = sprintf(_buf, "%s", "RK903");
156 printk("Current WiFi chip is GB86302I.\n");
160 #ifdef CONFIG_MTK_COMBO
161 count = sprintf(_buf, "%s", "MT6620");
162 printk("Current WiFi chip is MT6620.\n");
166 count = sprintf(_buf, "%s", "RT5370");
167 printk("Current WiFi chip is RT5370.\n");
171 count = sprintf(_buf, "%s", "MT5931");
172 printk("Current WiFi chip is MT5931.\n");
175 #ifdef CONFIG_MT5931_MT6622
176 count = sprintf(_buf, "%s", "MT5931");
177 printk("Current WiFi chip is MT5931.\n");
181 count = sprintf(_buf, "%s", "MT7601");
182 printk("Current WiFi chip is MT7601.\n");
186 #ifdef CONFIG_RTL8723AS
187 count = sprintf(_buf, "%s", "RTL8723AS");
188 printk("Current WiFi chip is RTL8723AS.\n");
191 #ifdef CONFIG_ESP8089
192 count = sprintf(_buf, "%s", "ESP8089");
193 printk("Current WiFi chip is ESP8089.\n");
200 static ssize_t wifi_channel_write(struct class *cls, const char *_buf, size_t _count)
204 if (wifi_enabled == 0)
206 printk("WiFi is disabled.\n");
210 channel = simple_strtol(_buf, NULL, 10);
212 ret = wifi_emi_set_channel(channel);
215 //printk("Set channel=%d fail.\n", channel);
219 //printk("Set channel=%d successfully.\n", channel);
220 wifi_channel = channel;
227 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
228 static ssize_t wifi_p2p_read(struct class *cls, struct class_attribute *attr, char *_buf)
230 static ssize_t wifi_p2p_read(struct class *cls, char *_buf)
235 #ifdef CONFIG_BCM4329
236 count = sprintf(_buf, "%s", "false");
237 printk("Current WiFi chip BCM4329 doesn't support direct.(%s)\n", _buf);
240 #ifdef CONFIG_RTL8192CU
241 count = sprintf(_buf, "%s", "false");
242 printk("Current WiFi chip RTL8188 support direct.(%s)\n", _buf);
246 count = sprintf(_buf, "%s", "true");
247 printk("Current WiFi chip RK903 support direct.(%s)\n", _buf);
250 #ifdef CONFIG_BCM4330
251 count = sprintf(_buf, "%s", "true");
252 printk("Current WiFi chip BCM4330 support direct.(%s)\n", _buf);
258 int wifi_pcba_test = 0;
260 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
261 static ssize_t wifi_pcba_read(struct class *cls, struct class_attribute *attr, char *_buf)
263 static ssize_t wifi_pcba_read(struct class *cls, char *_buf)
268 count = sprintf(_buf, "%d", wifi_pcba_test);
272 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
273 static ssize_t wifi_pcba_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
275 static ssize_t wifi_pcba_write(struct class *cls, char *_buf, size_t _count)
278 wifi_pcba_test = simple_strtol(_buf, NULL, 10);
279 if(wifi_pcba_test > 0) {
286 int check_wifi_type_from_id(int id, char * _buf) {
291 count = sprintf(_buf, "%s", "RTL8188EU");
292 printk("Current WiFi chip is RTL8188EU.\n");
295 count = sprintf(_buf, "%s", "RTL8188EU");
296 printk("Current WiFi chip is RTL8188ETV.\n");
299 count = sprintf(_buf, "%s", "RT5370");
300 printk("Current WiFi chip is RT5370.\n");
303 count = sprintf(_buf, "%s", "RTL8723AU");
304 printk("Current WiFi chip is RTL8723AU.\n");
307 count = sprintf(_buf, "%s", "RTL8188CU");
308 printk("Current WiFi chip is RTL8188CU.\n");
311 count = sprintf(_buf, "%s", "RTL8188CU");
312 printk("Current WiFi chip is RTL8188CTV.\n");
315 printk("Unsupported usb wifi.............\n");
320 extern int rk29sdk_wifi_power(int on);
321 extern int wifi_activate_usb(void);
322 extern int wifi_deactivate_usb(void);
323 #define USB_IDP_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idProduct"
324 #define USB_IDP_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idProduct"
325 #define USB_IDV_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idVendor"
326 #define USB_IDV_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idVendor"
327 #define USB_PRODUCT_SYS_PATCH "/sys/bus/usb/devices/1-1/product"
329 //8723 802.11n WLAN Adapter
331 //8188cu 802.11n WLAN Adapter
332 char aidc_type[20] = {0};
334 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
335 static ssize_t wifi_aidc_read(struct class *cls, struct class_attribute *attr, char *_buf)
337 static ssize_t wifi_aidc_read(struct class *cls, char *_buf)
340 int count = 0, retry = 10, idP = 0;// idV = 0;
343 char usbid[20] = {0};
344 struct file *file = NULL;
347 sprintf(_buf, "%s", "UNKNOW");
353 file = filp_open(USB_IDP_SYS_PATCH_2, O_RDONLY, 0);
355 printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_2, retry);
356 file = filp_open(USB_IDP_SYS_PATCH_1, O_RDONLY, 0);
358 printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_1, retry);
369 nread = vfs_read(file, (char __user *)usbid, sizeof(usbid), &pos);
371 filp_close(file, NULL);
372 wifi_deactivate_usb();
373 idP = simple_strtol(usbid, NULL, 16);
374 printk("Get usb wifi idProduct = 0X%04X\n", idP);
375 count = check_wifi_type_from_id(idP, _buf);
381 static struct class *rkwifi_class = NULL;
382 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
383 static CLASS_ATTR(p2p, 0664, wifi_p2p_read, NULL);
384 static CLASS_ATTR(pcba, 0664, wifi_pcba_read, wifi_pcba_write);
386 static CLASS_ATTR(aidc, 0664, wifi_aidc_read, NULL);
389 int rkwifi_sysif_init(void)
393 printk("Rockchip WiFi SYS interface (V1.00) ... \n");
397 rkwifi_class = class_create(THIS_MODULE, "rkwifi");
398 if (IS_ERR(rkwifi_class))
400 printk("Create class rkwifi_class failed.\n");
404 ret = class_create_file(rkwifi_class, &class_attr_chip);
405 ret = class_create_file(rkwifi_class, &class_attr_p2p);
406 ret = class_create_file(rkwifi_class, &class_attr_pcba);
408 ret = class_create_file(rkwifi_class, &class_attr_aidc);
414 void rkwifi_sysif_exit(void)
416 // need to remove the sys files and class
417 class_remove_file(rkwifi_class, &class_attr_chip);
418 class_remove_file(rkwifi_class, &class_attr_p2p);
419 class_remove_file(rkwifi_class, &class_attr_pcba);
421 class_remove_file(rkwifi_class, &class_attr_aidc);
423 class_destroy(rkwifi_class);
428 module_init(rkwifi_sysif_init);
429 module_exit(rkwifi_sysif_exit);
431 MODULE_AUTHOR("Yongle Lai");
432 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
433 MODULE_LICENSE("GPL");