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 <mach/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)
23 #ifdef CONFIG_MACH_RK_CONFIG
24 if(wifi_type==WIFI_TYPE_RTL8188CU)
26 count = sprintf(_buf, "%s", "RTL8188CU");
27 printk("Current WiFi chip is RTL8188CU.\n");
28 }else if(wifi_type==WIFI_TYPE_RTL8188EU){
29 count = sprintf(_buf, "%s", "RTL8188EU");
30 printk("Current WiFi chip is RTL8188EU.\n");
31 }else if(wifi_type==WIFI_TYPE_MT7601){
32 count = sprintf(_buf, "%s", "MT7601");
33 printk("Current WiFi chip is MT7601.\n");
34 }else if(wifi_type==WIFI_TYPE_RTL8188ETV)
36 count = sprintf(_buf, "%s", "RTL8188ETV");
37 printk("Current WiFi chip is RTL8188ETV.\n");
38 }else if(wifi_type==WIFI_TYPE_MT5370)
40 count = sprintf(_buf, "%s", "MT5370");
41 printk("Current WiFi chip is MT5370.\n");
45 printk("NOT surpport type %d\n",wifi_type);
50 count = sprintf(_buf, "%s", "BCM4329");
51 printk("Current WiFi chip is BCM4329.\n");
54 #ifdef CONFIG_RTL8192CU
55 count = sprintf(_buf, "%s", "RTL8188CU");
56 printk("Current WiFi chip is RTL8188CU.\n");
59 #ifdef CONFIG_RTL8188EU
60 count = sprintf(_buf, "%s", "RTL8188EU");
61 printk("Current WiFi chip is RTL8188EU.\n");
64 #ifdef CONFIG_RTL8723AU
65 count = sprintf(_buf, "%s", "RTL8723AU");
66 printk("Current WiFi chip is RTL8723AU.\n");
69 #ifdef CONFIG_RTL8189ES
70 count = sprintf(_buf, "%s", "RTL8189ES");
71 printk("Current WiFi chip is RTL8189ES.\n");
75 count = sprintf(_buf, "%s", "BCM4330");
76 printk("Current WiFi chip is BCM4330.\n");
80 count = sprintf(_buf, "%s", "RK901");
81 printk("Current WiFi chip is RK901.\n");
85 count = sprintf(_buf, "%s", "RK903");
86 printk("Current WiFi chip is RK903.\n");
90 count = sprintf(_buf, "%s", "RK901");
91 printk("Current WiFi chip is AP6181.\n");
95 count = sprintf(_buf, "%s", "RK901");
96 printk("Current WiFi chip is AP6210.\n");
100 count = sprintf(_buf, "%s", "RK903");
101 printk("Current WiFi chip is AP6330.\n");
105 count = sprintf(_buf, "%s", "RK901");
106 printk("Current WiFi chip is AP6476.\n");
110 count = sprintf(_buf, "%s", "RK903");
111 printk("Current WiFi chip is AP6493.\n");
114 #ifdef CONFIG_GB86302I
115 count = sprintf(_buf, "%s", "RK903");
116 printk("Current WiFi chip is GB86302I.\n");
119 #ifdef CONFIG_MTK_COMBO
120 count = sprintf(_buf, "%s", "MT6620");
121 printk("Current WiFi chip is MT6620.\n");
125 count = sprintf(_buf, "%s", "RT5370");
126 printk("Current WiFi chip is RT5370.\n");
130 count = sprintf(_buf, "%s", "MT5931");
131 printk("Current WiFi chip is MT5931.\n");
134 #ifdef CONFIG_MT5931_MT6622
135 count = sprintf(_buf, "%s", "MT5931");
136 printk("Current WiFi chip is MT5931.\n");
140 count = sprintf(_buf, "%s", "MT7601");
141 printk("Current WiFi chip is MT7601.\n");
145 #ifdef CONFIG_RTL8723AS
146 count = sprintf(_buf, "%s", "RTL8723AS");
147 printk("Current WiFi chip is RTL8723AS.\n");
154 static ssize_t wifi_channel_write(struct class *cls, const char *_buf, size_t _count)
158 if (wifi_enabled == 0)
160 printk("WiFi is disabled.\n");
164 channel = simple_strtol(_buf, NULL, 10);
166 ret = wifi_emi_set_channel(channel);
169 //printk("Set channel=%d fail.\n", channel);
173 //printk("Set channel=%d successfully.\n", channel);
174 wifi_channel = channel;
181 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
182 static ssize_t wifi_p2p_read(struct class *cls, struct class_attribute *attr, char *_buf)
184 static ssize_t wifi_p2p_read(struct class *cls, char *_buf)
189 #ifdef CONFIG_BCM4329
190 count = sprintf(_buf, "%s", "false");
191 printk("Current WiFi chip BCM4329 doesn't support direct.(%s)\n", _buf);
194 #ifdef CONFIG_RTL8192CU
195 count = sprintf(_buf, "%s", "false");
196 printk("Current WiFi chip RTL8188 support direct.(%s)\n", _buf);
200 count = sprintf(_buf, "%s", "true");
201 printk("Current WiFi chip RK903 support direct.(%s)\n", _buf);
204 #ifdef CONFIG_BCM4330
205 count = sprintf(_buf, "%s", "true");
206 printk("Current WiFi chip BCM4330 support direct.(%s)\n", _buf);
212 int wifi_pcba_test = 0;
214 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
215 static ssize_t wifi_pcba_read(struct class *cls, struct class_attribute *attr, char *_buf)
217 static ssize_t wifi_pcba_read(struct class *cls, char *_buf)
222 count = sprintf(_buf, "%d", wifi_pcba_test);
226 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
227 static ssize_t wifi_pcba_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
229 static ssize_t wifi_pcba_write(struct class *cls, char *_buf, size_t _count)
232 wifi_pcba_test = simple_strtol(_buf, NULL, 10);
233 if(wifi_pcba_test > 0) {
240 int check_wifi_type_from_id(int id, char * _buf) {
245 count = sprintf(_buf, "%s", "RTL8188EU");
246 printk("Current WiFi chip is RTL8188EU.\n");
249 count = sprintf(_buf, "%s", "RTL8188EU");
250 printk("Current WiFi chip is RTL8188ETV.\n");
253 count = sprintf(_buf, "%s", "RT5370");
254 printk("Current WiFi chip is RT5370.\n");
257 count = sprintf(_buf, "%s", "RTL8723AU");
258 printk("Current WiFi chip is RTL8723AU.\n");
261 count = sprintf(_buf, "%s", "RTL8188CU");
262 printk("Current WiFi chip is RTL8188CU.\n");
265 count = sprintf(_buf, "%s", "RTL8188CU");
266 printk("Current WiFi chip is RTL8188CTV.\n");
269 printk("Unsupported usb wifi.............\n");
274 extern int rk29sdk_wifi_power(int on);
275 extern int wifi_activate_usb(void);
276 extern int wifi_deactivate_usb(void);
277 #define USB_IDP_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idProduct"
278 #define USB_IDP_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idProduct"
279 #define USB_IDV_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idVendor"
280 #define USB_IDV_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idVendor"
281 #define USB_PRODUCT_SYS_PATCH "/sys/bus/usb/devices/1-1/product"
283 //8723 802.11n WLAN Adapter
285 //8188cu 802.11n WLAN Adapter
286 char aidc_type[20] = {0};
288 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
289 static ssize_t wifi_aidc_read(struct class *cls, struct class_attribute *attr, char *_buf)
291 static ssize_t wifi_aidc_read(struct class *cls, char *_buf)
294 int count = 0, retry = 10, idP = 0;// idV = 0;
297 char usbid[20] = {0};
298 struct file *file = NULL;
301 sprintf(_buf, "%s", "UNKNOW");
307 file = filp_open(USB_IDP_SYS_PATCH_2, O_RDONLY, 0);
309 printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_2, retry);
310 file = filp_open(USB_IDP_SYS_PATCH_1, O_RDONLY, 0);
312 printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_1, retry);
323 nread = vfs_read(file, (char __user *)usbid, sizeof(usbid), &pos);
325 filp_close(file, NULL);
326 wifi_deactivate_usb();
327 idP = simple_strtol(usbid, NULL, 16);
328 printk("Get usb wifi idProduct = 0X%04X\n", idP);
329 count = check_wifi_type_from_id(idP, _buf);
335 static struct class *rkwifi_class = NULL;
336 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
337 static CLASS_ATTR(p2p, 0664, wifi_p2p_read, NULL);
338 static CLASS_ATTR(pcba, 0664, wifi_pcba_read, wifi_pcba_write);
340 static CLASS_ATTR(aidc, 0664, wifi_aidc_read, NULL);
343 int rkwifi_sysif_init(void)
347 printk("Rockchip WiFi SYS interface (V1.00) ... \n");
351 rkwifi_class = class_create(THIS_MODULE, "rkwifi");
352 if (IS_ERR(rkwifi_class))
354 printk("Create class rkwifi_class failed.\n");
358 ret = class_create_file(rkwifi_class, &class_attr_chip);
359 ret = class_create_file(rkwifi_class, &class_attr_p2p);
360 ret = class_create_file(rkwifi_class, &class_attr_pcba);
362 ret = class_create_file(rkwifi_class, &class_attr_aidc);
368 void rkwifi_sysif_exit(void)
370 // need to remove the sys files and class
371 class_remove_file(rkwifi_class, &class_attr_chip);
372 class_remove_file(rkwifi_class, &class_attr_p2p);
373 class_remove_file(rkwifi_class, &class_attr_pcba);
375 class_remove_file(rkwifi_class, &class_attr_aidc);
377 class_destroy(rkwifi_class);
382 module_init(rkwifi_sysif_init);
383 module_exit(rkwifi_sysif_exit);
385 MODULE_AUTHOR("Yongle Lai");
386 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
387 MODULE_LICENSE("GPL");