9465a4f7f1af2258f4145dc6c3fa3a1091868e2d
[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_RTL8723BU
42     count = sprintf(_buf, "%s", "RTL8723BU");
43     printk("Current WiFi chip is RTL8723BU.\n");
44 #endif
45
46 #ifdef CONFIG_RTL8723BS
47     count = sprintf(_buf, "%s", "RTL8723BS");
48     printk("Current WiFi chip is RTL8723BS.\n");
49 #endif
50
51 #ifdef CONFIG_RTL8723BS_VQ0
52     count = sprintf(_buf, "%s", "RTL8723BS");
53     printk("Current WiFi chip is RTL8723BS.\n");
54 #endif
55
56 #ifdef CONFIG_RTL8189ES
57     count = sprintf(_buf, "%s", "RTL8189ES");
58     printk("Current WiFi chip is RTL8189ES.\n");
59 #endif
60
61 #ifdef CONFIG_RTL8812AU
62     count = sprintf(_buf, "%s", "RTL8812AU");
63     printk("Current WiFi chip is RTL8812AU.\n");
64 #endif
65
66
67 }
68
69 if(type == WIFI_BCMWIFI) {
70 #ifdef CONFIG_BCM4330
71     count = sprintf(_buf, "%s", "BCM4330");
72     printk("Current WiFi chip is BCM4330.\n");
73 #endif
74
75 #ifdef CONFIG_RK901
76     count = sprintf(_buf, "%s", "RK901");
77     printk("Current WiFi chip is RK901.\n");
78 #endif
79
80 #ifdef CONFIG_RK903
81     count = sprintf(_buf, "%s", "RK903");
82     printk("Current WiFi chip is RK903.\n");
83 #endif
84
85 #ifdef CONFIG_AP6181
86     count = sprintf(_buf, "%s", "RK901");
87     printk("Current WiFi chip is AP6181.\n");
88 #endif
89
90 #ifdef CONFIG_AP6210
91     count = sprintf(_buf, "%s", "RK901");
92     printk("Current WiFi chip is AP6210.\n");
93 #endif
94
95 #ifdef CONFIG_AP6234
96     count = sprintf(_buf, "%s", "AP6234");
97     printk("Current WiFi chip is AP6234.\n");
98 #endif
99
100 #ifdef CONFIG_AP6330
101     count = sprintf(_buf, "%s", "RK903");
102     printk("Current WiFi chip is AP6330.\n");
103 #endif
104
105 #ifdef CONFIG_AP6335
106     count = sprintf(_buf, "%s", "AP6335");
107     printk("Current WiFi chip is AP6335.\n");
108 #endif
109
110 #ifdef CONFIG_AP6441
111     count = sprintf(_buf, "%s", "AP6441");
112     printk("Current WiFi chip is AP6441.\n");
113 #endif
114
115 #ifdef CONFIG_AP6476
116     count = sprintf(_buf, "%s", "RK901");
117     printk("Current WiFi chip is AP6476.\n");
118 #endif
119
120 #ifdef CONFIG_AP6493
121     count = sprintf(_buf, "%s", "RK903");
122     printk("Current WiFi chip is AP6493.\n");
123 #endif
124
125 #ifdef CONFIG_GB86302I
126     count = sprintf(_buf, "%s", "RK903");
127     printk("Current WiFi chip is GB86302I.\n");
128 #endif
129 }
130
131 #ifdef CONFIG_MTK_COMBO
132         count = sprintf(_buf, "%s", "MT6620");
133         printk("Current WiFi chip is MT6620.\n");
134 #endif
135
136 #ifdef CONFIG_MT5931
137     count = sprintf(_buf, "%s", "MT5931");
138     printk("Current WiFi chip is MT5931.\n");
139 #endif
140
141 #ifdef CONFIG_MT5931_MT6622
142     count = sprintf(_buf, "%s", "MT5931");
143     printk("Current WiFi chip is MT5931.\n");
144 #endif
145
146 #ifdef CONFIG_MTK_MT5931
147     count = sprintf(_buf, "%s", "MT5931");
148     printk("Current WiFi chip is MT5931.\n");
149 #endif
150
151 #ifdef CONFIG_MT7601
152     count = sprintf(_buf, "%s", "MT7601");
153     printk("Current WiFi chip is MT7601.\n");
154 #endif
155
156 if(type == WIFI_ESP8089) {
157 #ifdef CONFIG_ESP8089
158     count = sprintf(_buf, "%s", "ESP8089");
159     printk("Current WiFi chip is ESP8089.\n");
160 #endif
161 }
162
163     return count;
164 }
165
166 static ssize_t wifi_power_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
167 {
168     int poweren = 0;
169     poweren = simple_strtol(_buf, NULL, 10);
170     printk("%s: poweren = %d\n", __func__, poweren);
171     if(poweren > 0) {
172         rockchip_wifi_power(1);
173     } else {
174         rockchip_wifi_power(0);
175     }
176
177 return _count;
178 }
179
180 #ifdef CONFIG_WIFI_NONE
181 int rockchip_wifi_init_module(void) {return 0;}
182 void rockchip_wifi_exit_module(void) {return;}
183 #else
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);
192 #endif
193 static struct semaphore driver_sem;
194 static int wifi_driver_insmod = 0;
195
196 static int wifi_init_exit_module(int enable)
197 {
198     int ret = 0;
199     int type = get_wifi_chip_type();
200 #ifdef CONFIG_RKWIFI
201     if (type == WIFI_BCMWIFI) {
202         if (enable > 0)
203             ret = rockchip_wifi_init_module_rkwifi();
204         else
205             rockchip_wifi_exit_module_rkwifi();
206         return ret;
207     }
208 #endif
209 #ifdef CONFIG_RTL_WIRELESS_SOLUTION
210     if (type == WIFI_RTKWIFI) {
211         if (enable > 0) 
212             ret = rockchip_wifi_init_module_rtkwifi();
213         else
214             rockchip_wifi_exit_module_rtkwifi();
215         return ret;
216     }
217 #endif
218 #ifdef CONFIG_ESP8089
219     if (type == WIFI_ESP8089) {
220         if (enable > 0)  
221             ret = rockchip_wifi_init_module_esp8089();
222         else
223             rockchip_wifi_exit_module_esp8089();
224         return ret;
225     }
226 #endif
227
228 #if !defined(CONFIG_RKWIFI) && !defined(CONFIG_RTL_WIRELESS_SOLUTION) && !defined(CONFIG_ESP8089)
229     if (type >= 0) {
230         if (enable > 0)
231             ret = rockchip_wifi_init_module();
232         else
233             rockchip_wifi_exit_module();
234     }
235 #endif
236
237     return ret;
238 }
239
240 static ssize_t wifi_driver_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
241 {
242     int enable = 0, ret = 0;
243     
244     down(&driver_sem);
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");
249         up(&driver_sem);
250         return _count;
251     }
252     if(enable > 0) {
253         ret = wifi_init_exit_module(enable);
254         if (ret >= 0)
255             wifi_driver_insmod = enable;
256     } else {
257         wifi_init_exit_module(enable);
258         wifi_driver_insmod = enable;
259     }   
260
261     up(&driver_sem);
262     //printk("%s: ret = %d\n", __func__, ret);
263     return _count; 
264 }
265
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);
270
271 int rkwifi_sysif_init(void)
272 {
273     int ret;
274     
275     printk("Rockchip WiFi SYS interface (V1.00) ... \n");
276     
277     rkwifi_class = NULL;
278     
279     rkwifi_class = class_create(THIS_MODULE, "rkwifi");
280     if (IS_ERR(rkwifi_class)) 
281     {   
282         printk("Create class rkwifi_class failed.\n");
283         return -ENOMEM;
284     }
285     
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);
290     
291     return 0;
292 }
293
294 void rkwifi_sysif_exit(void)
295 {
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);
301     
302     rkwifi_class = NULL;
303 }
304
305 module_init(rkwifi_sysif_init);
306 module_exit(rkwifi_sysif_exit);
307
308 MODULE_AUTHOR("Yongle Lai & gwl");
309 MODULE_DESCRIPTION("WiFi SYS @ Rockchip");
310 MODULE_LICENSE("GPL");
311