add new function of automatic identifi USB Wifi Type.
authorgwl <gwl@rock-chips.com>
Fri, 26 Apr 2013 03:55:41 +0000 (11:55 +0800)
committergwl <gwl@rock-chips.com>
Fri, 26 Apr 2013 03:55:52 +0000 (11:55 +0800)
drivers/net/wireless/Kconfig
drivers/net/wireless/wifi_sys/rkwifi_sys_iface.c

index 703c3b7bd3d640bca81bdcab534b6a41a87dae17..80035535f87f643cc2a4133731150d8f9846d843 100755 (executable)
@@ -26,6 +26,12 @@ config WLAN_80211
          This option does not affect the kernel build, it only
          lets you choose drivers.
 
+config AIDC
+    bool "Enable WIFI AIDS(Automatic Identification USB Wifi Type)"
+       depends on RTL8188EU || RTL8192CU || RTL8723AU || RT5370
+       default n
+       ---help---
+
 choice
        prompt "WiFi device driver support"
        default WIFI_NONE
index 52df660620d2ebb852016fd81cce441c1d56bfcc..e3c9832fc8477f2410431c1bcfa9aa29a01ad72b 100755 (executable)
@@ -1,11 +1,13 @@
-\r
-\r
 
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/delay.h>
+#include <linux/syscalls.h>
+#include <linux/fs.h>
+#include <asm/uaccess.h>
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
 static ssize_t wifi_chip_read(struct class *cls, struct class_attribute *attr, char *_buf)
@@ -189,10 +191,109 @@ static ssize_t wifi_pcba_write(struct class *cls, char *_buf, size_t _count)
         return _count;
 }
 
+#ifdef CONFIG_AIDC
+int check_wifi_type_from_id(int id, char * _buf) {
+       int count = 0;
+
+       switch(id) {
+               case 0x8179:
+                       count = sprintf(_buf, "%s", "RTL8188EU");
+               printk("Current WiFi chip is RTL8188EU.\n");
+                       break;
+               case 0x0179:
+                       count = sprintf(_buf, "%s", "RTL8188EU");
+               printk("Current WiFi chip is RTL8188ETV.\n");
+                       break;
+               case 0x5370:
+                       count = sprintf(_buf, "%s", "RT5370");
+               printk("Current WiFi chip is RT5370.\n");
+                       break;
+               case 0x0724:
+                       count = sprintf(_buf, "%s", "RTL8723AU");
+               printk("Current WiFi chip is RTL8723AU.\n");
+                       break;
+               case 0x8176:
+                       count = sprintf(_buf, "%s", "RTL8188CU");
+               printk("Current WiFi chip is RTL8188CU.\n");
+                       break;
+               case 0x018A:
+                       count = sprintf(_buf, "%s", "RTL8188CU");
+               printk("Current WiFi chip is RTL8188CTV.\n");
+                       break;
+               default:
+               printk("Unsupported usb wifi.............\n");
+       }       
+       return count;   
+}
+
+extern int rk29sdk_wifi_power(int on);
+extern int wifi_activate_usb(void);
+extern int wifi_deactivate_usb(void);
+#define USB_IDP_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idProduct"
+#define USB_IDP_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idProduct"
+#define USB_IDV_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idVendor"
+#define USB_IDV_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idVendor"
+#define USB_PRODUCT_SYS_PATCH "/sys/bus/usb/devices/1-1/product"
+//5370 802.11 n WLAN
+//8723 802.11n WLAN Adapter
+//8188eu 802.11n NIC
+//8188cu 802.11n WLAN Adapter
+char aidc_type[20] = {0};
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
+static ssize_t wifi_aidc_read(struct class *cls, struct class_attribute *attr, char *_buf)
+#else
+static ssize_t wifi_aidc_read(struct class *cls, char *_buf)
+#endif
+{
+        int count = 0, retry = 10, idP = 0;// idV = 0;
+               ssize_t nread;
+               loff_t pos = 0;
+               char usbid[20] = {0};
+               struct file *file = NULL;
+               mm_segment_t old_fs;
+                
+               sprintf(_buf, "%s", "UNKNOW");
+               wifi_activate_usb();
+               msleep(2000);
+               old_fs = get_fs();
+               set_fs(KERNEL_DS);
+               while(retry--) {
+                       file = filp_open(USB_IDP_SYS_PATCH_2, O_RDONLY, 0);
+                       if (IS_ERR(file)) {
+                               printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_2, retry);
+                               file = filp_open(USB_IDP_SYS_PATCH_1, O_RDONLY, 0);
+                               if (IS_ERR(file)) {
+                               printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_1, retry);
+                                       msleep(500);
+                                       continue;
+                               }
+                       }
+                       break;
+       }
+               if(retry <= 0) {
+                       set_fs(old_fs);
+                       return count;
+               }
+               nread = vfs_read(file, (char __user *)usbid, sizeof(usbid), &pos);
+               set_fs(old_fs);
+               filp_close(file, NULL);
+               wifi_deactivate_usb();
+               idP = simple_strtol(usbid, NULL, 16);
+               printk("Get usb wifi idProduct = 0X%04X\n", idP);
+               count = check_wifi_type_from_id(idP, _buf);
+
+        return count;
+}
+#endif //CONFIG_AIDC
+
 static struct class *rkwifi_class = NULL;
 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
 static CLASS_ATTR(p2p, 0664, wifi_p2p_read, NULL);
 static CLASS_ATTR(pcba, 0664, wifi_pcba_read, wifi_pcba_write);
+#ifdef CONFIG_AIDC
+static CLASS_ATTR(aidc, 0664, wifi_aidc_read, NULL);
+#endif
 
 int rkwifi_sysif_init(void)
 {
@@ -212,6 +313,9 @@ int rkwifi_sysif_init(void)
     ret =  class_create_file(rkwifi_class, &class_attr_chip);
     ret =  class_create_file(rkwifi_class, &class_attr_p2p);
     ret =  class_create_file(rkwifi_class, &class_attr_pcba);
+#ifdef CONFIG_AIDC
+    ret =  class_create_file(rkwifi_class, &class_attr_aidc);
+#endif
     
     return 0;
 }
@@ -222,6 +326,9 @@ void rkwifi_sysif_exit(void)
     class_remove_file(rkwifi_class, &class_attr_chip);
     class_remove_file(rkwifi_class, &class_attr_p2p);
     class_remove_file(rkwifi_class, &class_attr_pcba);
+#ifdef CONFIG_AIDC
+    class_remove_file(rkwifi_class, &class_attr_aidc);
+#endif
     class_destroy(rkwifi_class);
     
     rkwifi_class = NULL;