Merge tag 'lsk-v3.10-android-14.12'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / wifi_sys / rkwifi_sys_iface.c
1
2 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/init.h>
5 #include <linux/device.h>
6 #include <linux/err.h>
7 #include <linux/delay.h>
8 #include <linux/syscalls.h>
9 #include <linux/fs.h>
10 #include <asm/uaccess.h>
11 #include <linux/rfkill-wlan.h>
12
13 extern int get_wifi_chip_type(void);
14
15 static ssize_t wifi_chip_read(struct class *cls, struct class_attribute *attr, char *_buf)
16 {
17     int count = 0;
18     int type = get_wifi_chip_type();
19
20 if(type == WIFI_RTKWIFI) {
21 #ifdef CONFIG_RTL8192CU
22     count = sprintf(_buf, "%s", "RTL8188CU");
23     printk("Current WiFi chip is RTL8188CU.\n");
24 #endif
25
26 #ifdef CONFIG_RTL8192DU
27     count = sprintf(_buf, "%s", "RTL8192DU");
28     printk("Current WiFi chip is RTL8192DU.\n");
29 #endif
30
31 #ifdef CONFIG_RTL8188EU
32     count = sprintf(_buf, "%s", "RTL8188EU");
33     printk("Current WiFi chip is RTL8188EU.\n");
34 #endif
35
36 #ifdef CONFIG_RTL8723AU
37     count = sprintf(_buf, "%s", "RTL8723AU");
38     printk("Current WiFi chip is RTL8723AU.\n");
39 #endif
40
41 #ifdef CONFIG_RTL8723BS
42     count = sprintf(_buf, "%s", "RTL8723BS");
43     printk("Current WiFi chip is RTL8723BS.\n");
44 #endif
45
46 #ifdef CONFIG_RTL8189ES
47     count = sprintf(_buf, "%s", "RTL8189ES");
48     printk("Current WiFi chip is RTL8189ES.\n");
49 #endif
50 }
51
52 if(type == WIFI_BCMWIFI) {
53 #ifdef CONFIG_BCM4330
54     count = sprintf(_buf, "%s", "BCM4330");
55     printk("Current WiFi chip is BCM4330.\n");
56 #endif
57
58 #ifdef CONFIG_RK901
59     count = sprintf(_buf, "%s", "RK901");
60     printk("Current WiFi chip is RK901.\n");
61 #endif
62
63 #ifdef CONFIG_RK903
64     count = sprintf(_buf, "%s", "RK903");
65     printk("Current WiFi chip is RK903.\n");
66 #endif
67
68 #ifdef CONFIG_AP6181
69     count = sprintf(_buf, "%s", "RK901");
70     printk("Current WiFi chip is AP6181.\n");
71 #endif
72
73 #ifdef CONFIG_AP6210
74     count = sprintf(_buf, "%s", "RK901");
75     printk("Current WiFi chip is AP6210.\n");
76 #endif
77
78 #ifdef CONFIG_AP6234
79     count = sprintf(_buf, "%s", "AP6234");
80     printk("Current WiFi chip is AP6234.\n");
81 #endif
82
83 #ifdef CONFIG_AP6330
84     count = sprintf(_buf, "%s", "RK903");
85     printk("Current WiFi chip is AP6330.\n");
86 #endif
87
88 #ifdef CONFIG_AP6335
89     count = sprintf(_buf, "%s", "AP6335");
90     printk("Current WiFi chip is AP6335.\n");
91 #endif
92
93 #ifdef CONFIG_AP6441
94     count = sprintf(_buf, "%s", "AP6441");
95     printk("Current WiFi chip is AP6441.\n");
96 #endif
97
98 #ifdef CONFIG_AP6476
99     count = sprintf(_buf, "%s", "RK901");
100     printk("Current WiFi chip is AP6476.\n");
101 #endif
102
103 #ifdef CONFIG_AP6493
104     count = sprintf(_buf, "%s", "RK903");
105     printk("Current WiFi chip is AP6493.\n");
106 #endif
107
108 #ifdef CONFIG_GB86302I
109     count = sprintf(_buf, "%s", "RK903");
110     printk("Current WiFi chip is GB86302I.\n");
111 #endif
112 }
113
114 #ifdef CONFIG_MTK_COMBO
115         count = sprintf(_buf, "%s", "MT6620");
116         printk("Current WiFi chip is MT6620.\n");
117 #endif
118
119 #ifdef CONFIG_MT5931
120     count = sprintf(_buf, "%s", "MT5931");
121     printk("Current WiFi chip is MT5931.\n");
122 #endif
123
124 #ifdef CONFIG_MT5931_MT6622
125     count = sprintf(_buf, "%s", "MT5931");
126     printk("Current WiFi chip is MT5931.\n");
127 #endif
128
129 #ifdef CONFIG_MTK_MT5931
130     count = sprintf(_buf, "%s", "MT5931");
131     printk("Current WiFi chip is MT5931.\n");
132 #endif
133
134 #ifdef CONFIG_MT7601
135     count = sprintf(_buf, "%s", "MT7601");
136     printk("Current WiFi chip is MT7601.\n");
137 #endif
138
139 if(type == WIFI_ESP8089) {
140 #ifdef CONFIG_ESP8089
141     count = sprintf(_buf, "%s", "ESP8089");
142     printk("Current WiFi chip is ESP8089.\n");
143 #endif
144 }
145
146     return count;
147 }
148
149 static ssize_t wifi_power_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
150 {
151     int poweren = 0;
152     poweren = simple_strtol(_buf, NULL, 10);
153     printk("%s: poweren = %d\n", __func__, poweren);
154     if(poweren > 0) {
155         rockchip_wifi_power(1);
156     } else {
157         rockchip_wifi_power(0);
158     }
159
160 return _count;
161 }
162
163 #ifdef CONFIG_WIFI_NONE
164 int rockchip_wifi_init_module(void) {return 0;}
165 void rockchip_wifi_exit_module(void) {return;}
166 #else
167 extern int rockchip_wifi_init_module(void);
168 extern void rockchip_wifi_exit_module(void);
169 extern int rockchip_wifi_init_module_rkwifi(void);
170 extern void rockchip_wifi_exit_module_rkwifi(void);
171 extern int rockchip_wifi_init_module_rtkwifi(void);
172 extern void rockchip_wifi_exit_module_rtkwifi(void);
173 extern int rockchip_wifi_init_module_esp8089(void);
174 extern void rockchip_wifi_exit_module_esp8089(void);
175 #endif
176 static struct semaphore driver_sem;
177 static int wifi_driver_insmod = 0;
178
179 static int wifi_init_exit_module(int enable)
180 {
181     int ret = 0;
182     int type = get_wifi_chip_type();
183 #ifdef CONFIG_RKWIFI
184     if (type == WIFI_BCMWIFI) {
185         if (enable > 0)
186             ret = rockchip_wifi_init_module_rkwifi();
187         else
188             rockchip_wifi_exit_module_rkwifi();
189         return ret;
190     }
191 #endif
192 #ifdef CONFIG_RTL_WIRELESS_SOLUTION
193     if (type == WIFI_RTKWIFI) {
194         if (enable > 0) 
195             ret = rockchip_wifi_init_module_rtkwifi();
196         else
197             rockchip_wifi_exit_module_rtkwifi();
198         return ret;
199     }
200 #endif
201 #ifdef CONFIG_ESP8089
202     if (type == WIFI_ESP8089) {
203         if (enable > 0)  
204             ret = rockchip_wifi_init_module_esp8089();
205         else
206             rockchip_wifi_exit_module_esp8089();
207         return ret;
208     }
209 #endif
210
211 #if !defined(CONFIG_RKWIFI) && !defined(CONFIG_RTL_WIRELESS_SOLUTION) && !defined(CONFIG_ESP8089)
212     if (type >= 0) {
213         if (enable > 0)
214             ret = rockchip_wifi_init_module();
215         else
216             rockchip_wifi_exit_module();
217     }
218 #endif
219
220     return ret;
221 }
222
223 static ssize_t wifi_driver_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
224 {
225     int enable = 0, ret = 0;
226     
227     down(&driver_sem);
228     enable = simple_strtol(_buf, NULL, 10);
229     //printk("%s: enable = %d\n", __func__, enable);
230     if (wifi_driver_insmod == enable) {
231         printk("%s: wifi driver already %s\n", __func__, enable? "insmod":"rmmod");
232         up(&driver_sem);
233         return _count;
234     }
235     if(enable > 0) {
236         ret = wifi_init_exit_module(enable);
237         if (ret >= 0)
238             wifi_driver_insmod = enable;
239     } else {
240         wifi_init_exit_module(enable);
241         wifi_driver_insmod = enable;
242     }   
243
244     up(&driver_sem);
245     //printk("%s: ret = %d\n", __func__, ret);
246     return _count; 
247 }
248
249 static struct class *rkwifi_class = NULL;
250 static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL);
251 static CLASS_ATTR(power, 0660, NULL, wifi_power_write);
252 static CLASS_ATTR(driver, 0660, NULL, wifi_driver_write);
253
254 int rkwifi_sysif_init(void)
255 {
256     int ret;
257     
258     printk("Rockchip WiFi SYS interface (V1.00) ... \n");
259     
260     rkwifi_class = NULL;
261     
262     rkwifi_class = class_create(THIS_MODULE, "rkwifi");
263     if (IS_ERR(rkwifi_class)) 
264     {   
265         printk("Create class rkwifi_class failed.\n");
266         return -ENOMEM;
267     }
268     
269     ret =  class_create_file(rkwifi_class, &class_attr_chip);
270     ret =  class_create_file(rkwifi_class, &class_attr_power);
271     ret =  class_create_file(rkwifi_class, &class_attr_driver);
272     sema_init(&driver_sem, 1);
273     
274     return 0;
275 }
276
277 void rkwifi_sysif_exit(void)
278 {
279     // need to remove the sys files and class
280     class_remove_file(rkwifi_class, &class_attr_chip);
281     class_remove_file(rkwifi_class, &class_attr_power);
282     class_remove_file(rkwifi_class, &class_attr_driver);
283     class_destroy(rkwifi_class);
284     
285     rkwifi_class = NULL;
286 }
287
288 module_init(rkwifi_sysif_init);
289 module_exit(rkwifi_sysif_exit);
290
291 MODULE_AUTHOR("Yongle Lai & gwl");
292 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
293 MODULE_LICENSE("GPL");
294