Wifi:BT: add power toggle control.
[firefly-linux-kernel-4.4.55.git] / net / rfkill / rfkill-wlan.c
1 /*
2  * Copyright (C) 2012 ROCKCHIP, Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  */
14 /* Rock-chips rfkill driver for wifi
15 */
16
17 #include <linux/kernel.h>
18 #include <linux/platform_device.h>
19 #include <linux/module.h>
20 #include <linux/rfkill.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <asm/gpio.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/delay.h>
26 #include <linux/rfkill-wlan.h>
27 #include <linux/rfkill-bt.h>
28 #include <linux/wakelock.h>
29 #include <linux/interrupt.h>
30 #include <asm/irq.h>
31 #include <linux/suspend.h>
32 #include <linux/proc_fs.h>
33 #include <linux/uaccess.h>
34 #include <linux/gpio.h>
35 #include <linux/rockchip/iomap.h>
36 #include <dt-bindings/gpio/gpio.h>
37 #ifdef CONFIG_OF
38 #include <linux/of.h>
39 #include <linux/of_device.h>
40 #include <linux/of_gpio.h>
41 #endif
42
43 #if 0
44 #define DBG(x...)   printk(KERN_INFO "[WLAN_RFKILL]: "x)
45 #else
46 #define DBG(x...)
47 #endif
48
49 #define LOG(x...)   printk(KERN_INFO "[WLAN_RFKILL]: "x)
50
51 struct rfkill_wlan_data {
52         struct rksdmmc_gpio_wifi_moudle *pdata;
53     struct wake_lock            wlan_irq_wl;
54 };
55
56 static struct rfkill_wlan_data *g_rfkill = NULL;
57
58 static const char wlan_name[] = 
59 #if defined (CONFIG_BCM4330)
60     #if defined (CONFIG_BT_MODULE_NH660)
61         "nh660"
62     #else
63         "bcm4330"
64     #endif
65 #elif defined (CONFIG_RK903)
66     #if defined(CONFIG_RKWIFI_26M)
67         "rk903_26M"
68     #else
69         "rk903"
70     #endif
71 #elif defined(CONFIG_BCM4329)
72         "bcm4329"
73 #elif defined(CONFIG_MV8787)
74         "mv8787"
75 #elif defined(CONFIG_AP6210)
76     #if defined(CONFIG_RKWIFI_26M)
77         "ap6210"
78     #else
79         "ap6210_24M"
80     #endif
81 #elif defined(CONFIG_AP6330)
82                 "ap6330"
83 #elif defined(CONFIG_AP6476)
84                 "ap6476"
85 #elif defined(CONFIG_AP6493)
86                 "ap6493"
87 #else
88         "wlan_default"
89 #endif
90 ;
91
92 /***********************************************************
93  * 
94  * Broadcom Wifi Static Memory
95  * 
96  **********************************************************/
97 #define BCM_STATIC_MEMORY_SUPPORT 0
98 //===========================
99 #if BCM_STATIC_MEMORY_SUPPORT
100 #define PREALLOC_WLAN_SEC_NUM           4
101 #define PREALLOC_WLAN_BUF_NUM           160
102 #define PREALLOC_WLAN_SECTION_HEADER    24
103 #define WLAN_SKB_BUF_NUM        16
104
105 #define WLAN_SECTION_SIZE_0     (PREALLOC_WLAN_BUF_NUM * 128)
106 #define WLAN_SECTION_SIZE_1     (PREALLOC_WLAN_BUF_NUM * 128)
107 #define WLAN_SECTION_SIZE_2     (PREALLOC_WLAN_BUF_NUM * 512)
108 #define WLAN_SECTION_SIZE_3     (PREALLOC_WLAN_BUF_NUM * 1024)
109 #define WLAN_SECTION_SIZE_5     (PREALLOC_WLAN_BUF_NUM * 512)
110
111 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
112
113 struct wifi_mem_prealloc {
114     void *mem_ptr;
115     unsigned long size;
116 };
117
118 static struct wifi_mem_prealloc wifi_mem_array[5] = {
119     {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
120     {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
121     {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
122     {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)},
123     {NULL, (WLAN_SECTION_SIZE_5 + PREALLOC_WLAN_SECTION_HEADER)}
124 };
125
126 static int __init rockchip_init_wifi_mem(void)
127 {
128     int i;
129     int j;
130
131     for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
132         wlan_static_skb[i] = dev_alloc_skb(
133                ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
134
135         if (!wlan_static_skb[i])
136             goto err_skb_alloc;
137     }
138
139     for (i = 0 ; i < 5; i++) {
140         wifi_mem_array[i].mem_ptr =
141                kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
142
143         if (!wifi_mem_array[i].mem_ptr)
144             goto err_mem_alloc;
145         }
146         return 0;
147
148 err_mem_alloc:
149     pr_err("Failed to mem_alloc for WLAN\n");
150     for (j = 0 ; j < i ; j++)
151         kfree(wifi_mem_array[j].mem_ptr);
152     i = WLAN_SKB_BUF_NUM;
153 err_skb_alloc:
154     pr_err("Failed to skb_alloc for WLAN\n");
155     for (j = 0 ; j < i ; j++)
156         dev_kfree_skb(wlan_static_skb[j]);
157
158     return -ENOMEM;
159 }
160
161 void *rockchip_mem_prealloc(int section, unsigned long size)
162 {
163     if (section == PREALLOC_WLAN_SEC_NUM)
164         return wlan_static_skb;
165
166     if ((section < 0) || (section > 5))
167         return NULL;
168
169     if (section == 5)
170         return wifi_mem_array[4].mem_ptr;
171
172     if (wifi_mem_array[section].size < size)
173         return NULL;
174
175     return wifi_mem_array[section].mem_ptr;
176 }
177 #else
178 void *rockchip_mem_prealloc(int section, unsigned long size) { return NULL;}
179 #endif
180 EXPORT_SYMBOL(rockchip_mem_prealloc);
181
182 /**************************************************************************
183  *
184  * get wifi power state Func
185  *
186  *************************************************************************/
187 static int wifi_power_state = 0;
188 int rfkill_get_wifi_power_state(int *power)
189 {
190     struct rfkill_wlan_data *mrfkill = g_rfkill;
191
192     if (mrfkill == NULL) {
193         LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
194         return -1;
195     }
196
197     *power = wifi_power_state;
198
199     return 0;
200 }
201
202 /**************************************************************************
203  *
204  * Wifi Power Control Func
205  * 0 -> power off
206  * 1 -> power on
207  *
208  *************************************************************************/
209 int rockchip_wifi_power(int on)
210 {
211         struct rfkill_wlan_data *mrfkill = g_rfkill;
212     struct rksdmmc_gpio *poweron, *reset;
213     struct regulator *ldo = NULL;
214     int power = 0;
215     bool toggle = false;
216
217     LOG("%s: %d\n", __func__, on);
218
219     if (mrfkill == NULL) {
220         LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
221         return -1;
222     }
223
224     if(!rfkill_get_bt_power_state(&power, &toggle)) {
225         if (toggle == true && power == 1) {
226             LOG("%s: wifi shouldn't control the power, it was enabled by BT!\n", __func__);
227             return 0;
228         }
229     }
230
231     if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
232         char *ldostr;
233         int ret = -1;
234         int level = mrfkill->pdata->mregulator.enable;
235
236         ldostr = mrfkill->pdata->mregulator.pmu_regulator;
237         if (ldostr == NULL) {
238             LOG("%s: wifi power set to be controled by pmic, but which one?\n", __func__);
239             return -1;
240         }
241         ldo = regulator_get(NULL, ldostr);
242         if (ldo == NULL) {
243             LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
244         } else {
245                         if (on == level) {
246                                 regulator_set_voltage(ldo, 3000000, 3000000);
247                             LOG("%s: %s enabled\n", __func__, ldostr);
248                                 ret = regulator_enable(ldo);
249                                 if(ret != 0){
250                                     LOG("%s: faild to enable %s\n", __func__, ldostr);
251                                 } else {
252                     wifi_power_state = 1;
253                                 LOG("wifi turn on power.\n");
254                 }
255             } else {
256                                 LOG("%s: %s disabled\n", __func__, ldostr);
257                                 ret = regulator_disable(ldo);
258                                 if(ret != 0){
259                                         LOG("%s: faild to disable %s\n", __func__, ldostr);
260                                 } else {
261                     wifi_power_state = 0;
262                                 LOG("wifi shut off power.\n");
263                 }
264                         }
265                         regulator_put(ldo);
266                         msleep(100);
267                 }
268     } else {
269                 poweron = &mrfkill->pdata->power_n;
270                 reset = &mrfkill->pdata->reset_n;
271
272                 if (on){
273                         if (gpio_is_valid(poweron->io)) {
274                                 gpio_set_value(poweron->io, poweron->enable);
275                                 msleep(100);
276                         }
277
278                         if (gpio_is_valid(reset->io)) {
279                                 gpio_set_value(reset->io, reset->enable);
280                                 msleep(100);
281                         }
282
283             wifi_power_state = 1;
284                         LOG("wifi turn on power. %d\n", poweron->io);
285                 }else{
286                         if (gpio_is_valid(poweron->io)) {
287                                 gpio_set_value(poweron->io, !(poweron->enable));
288                                 msleep(100);
289                         }
290
291                         if (gpio_is_valid(reset->io)) {
292                                 gpio_set_value(reset->io, !(reset->enable));
293                         }
294
295             wifi_power_state = 0;
296                         LOG("wifi shut off power.\n");
297                 }
298     }
299
300     return 0;
301 }
302 EXPORT_SYMBOL(rockchip_wifi_power);
303
304 /**************************************************************************
305  *
306  * Wifi Sdio Detect Func
307  *
308  *************************************************************************/
309 #include <linux/mmc/host.h>
310 extern int mmc_host_rescan(struct mmc_host *host, int val);
311 int rockchip_wifi_set_carddetect(int val)
312 {
313     return mmc_host_rescan(NULL, val);//NULL => SDIO host
314 }
315 EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
316
317 /**************************************************************************
318  *
319  * Wifi Get Interrupt irq Func
320  *
321  *************************************************************************/
322 int rockchip_wifi_get_oob_irq(void)
323 {
324     struct rfkill_wlan_data *mrfkill = g_rfkill;
325     struct rksdmmc_gpio *wifi_int_irq;
326
327     LOG("%s: Enter\n", __func__);
328
329     if (mrfkill == NULL) {
330         LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
331         return -1;
332     }
333     
334     wifi_int_irq = &mrfkill->pdata->wifi_int_b;
335     if (gpio_is_valid(wifi_int_irq->io)) {
336         return gpio_to_irq(wifi_int_irq->io);
337         //return wifi_int_irq->io;
338     } else {
339         LOG("%s: wifi OOB pin isn't defined.\n", __func__);
340     }
341     
342     return -1;
343 }
344 EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
345
346 /**************************************************************************
347  *
348  * Wifi Reset Func
349  *
350  *************************************************************************/
351 int rockchip_wifi_reset(int on)
352 {
353     return 0;
354 }
355 EXPORT_SYMBOL(rockchip_wifi_reset);
356
357 /**************************************************************************
358  *
359  * Wifi MAC custom Func
360  *
361  *************************************************************************/
362 #include <linux/etherdevice.h>
363 u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
364 extern char GetSNSectorInfo(char * pbuf);
365 int rockchip_wifi_mac_addr(unsigned char *buf)
366 {
367     return -1;
368     char mac_buf[20] = {0};
369     LOG("%s: enter.\n", __func__);
370
371     // from vflash
372     if(is_zero_ether_addr(wifi_custom_mac_addr)) {
373         int i;
374         char *tempBuf = kmalloc(512, GFP_KERNEL);
375         if(tempBuf) {
376             GetSNSectorInfo(tempBuf);
377             for (i = 506; i <= 511; i++)
378                 wifi_custom_mac_addr[i-506] = tempBuf[i];
379             kfree(tempBuf);
380         } else {
381             return -1;
382         }
383     }
384
385     sprintf(mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x",wifi_custom_mac_addr[0],wifi_custom_mac_addr[1],
386     wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
387     LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
388
389     if (is_valid_ether_addr(wifi_custom_mac_addr)) {
390         if (2 == (wifi_custom_mac_addr[0] & 0x0F)) {
391             LOG("This mac address come into conflict with the address of direct, ignored...\n");
392             return -1;
393         }
394     } else {
395         LOG("This mac address is not valid, ignored...\n");
396         return -1;
397     }
398
399 #if defined(CONFIG_RKWIFI)
400     memcpy(buf, wifi_custom_mac_addr, 6);
401 #else
402     memcpy(buf, mac_buf, strlen(mac_buf));//realtek's wifi use this branch
403 #endif
404     return 0;
405 }
406 EXPORT_SYMBOL(rockchip_wifi_mac_addr);
407
408 /**************************************************************************
409  *
410  * wifi get country code func
411  *
412  *************************************************************************/
413 struct cntry_locales_custom {
414     char iso_abbrev[4];  /* ISO 3166-1 country abbreviation */
415     char custom_locale[4];   /* Custom firmware locale */
416     int custom_locale_rev;        /* Custom local revisin default -1 */
417 };
418
419 static struct cntry_locales_custom country_cloc;
420
421 void *rockchip_wifi_country_code(char *ccode)
422 {
423     struct cntry_locales_custom *mcloc;
424
425     LOG("%s: set country code [%s]\n", __func__, ccode);
426     mcloc = &country_cloc;
427     memcpy(mcloc->custom_locale, ccode, 4);
428     mcloc->custom_locale_rev = 0;
429
430     return mcloc;
431 }
432 EXPORT_SYMBOL(rockchip_wifi_country_code);
433 /**************************************************************************/
434
435 static int rockchip_wifi_voltage_select(void)
436 {
437     struct rfkill_wlan_data *mrfkill = g_rfkill;
438     int voltage = 0;
439
440     if (mrfkill == NULL) {
441         LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
442         return -1;
443     }
444     voltage = mrfkill->pdata->sdio_vol;
445     if (voltage > 2700 && voltage < 3500) {
446         writel_relaxed(0x00100000, RK_GRF_VIRT+0x380); //3.3
447         LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
448     } else if (voltage  > 1500 && voltage < 1950) {
449         writel_relaxed(0x00100010, RK_GRF_VIRT+0x380); //1.8
450         LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
451     } else {
452         LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
453         return -1;
454     }
455
456     return 0;
457 }
458
459 static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char* prefix, const char* name)
460 {
461     if (gpio_is_valid(gpio->io)) {
462         int ret=0;
463         sprintf(gpio->name, "%s_%s", prefix, name);
464         ret = gpio_request(gpio->io, gpio->name);
465         if (ret) {
466             LOG("Failed to get %s gpio.\n", gpio->name);
467             return -1;
468         }
469     }
470
471     return 0;
472 }
473
474 #ifdef CONFIG_OF
475 static int wlan_platdata_parse_dt(struct device *dev,
476                   struct rksdmmc_gpio_wifi_moudle *data)
477 {
478     struct device_node *node = dev->of_node;
479     const char *strings;
480     u32 value;
481     int gpio,ret;
482     enum of_gpio_flags flags;
483
484     if (!node)
485         return -ENODEV;
486
487     memset(data, 0, sizeof(*data));
488
489     ret = of_property_read_u32(node, "sdio_vref", &value);
490     if (ret < 0) {
491         LOG("%s: Can't get sdio vref.", __func__);
492         return -1;
493     }
494     data->sdio_vol = value;
495
496     if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
497         data->mregulator.power_ctrl_by_pmu = true;
498         ret = of_property_read_string(node, "pmu_regulator", &strings);
499         if (ret) {
500             LOG("%s: Can not read property: pmu_regulator.\n", __func__);
501             data->mregulator.power_ctrl_by_pmu = false;
502         } else {
503             LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
504             sprintf(data->mregulator.pmu_regulator, "%s", strings);
505         }
506         ret = of_property_read_u32(node, "pmu_enable_level", &value);
507         if (ret) {
508             LOG("%s: Can not read property: pmu_enable_level.\n", __func__);
509             data->mregulator.power_ctrl_by_pmu = false;
510         } else {
511             LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
512             data->mregulator.enable = value;
513         }
514         } else {
515                 data->mregulator.power_ctrl_by_pmu = false;
516                 LOG("%s: wifi power controled by gpio.\n", __func__);
517         gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
518         if (gpio_is_valid(gpio)){
519                         data->power_n.io = gpio;
520                         data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
521                         LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
522         } else data->power_n.io = -1;
523         gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
524         if (gpio_is_valid(gpio)){
525                         data->reset_n.io = gpio;
526                         data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
527                         LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
528         } else data->reset_n.io = -1;
529         gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
530         if (gpio_is_valid(gpio)){
531                         data->wifi_int_b.io = gpio;
532                         data->wifi_int_b.enable = flags;
533                         LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
534         } else data->wifi_int_b.io = -1;
535         }
536
537     return 0;
538 }
539 #endif //CONFIG_OF
540
541 #if defined(CONFIG_HAS_EARLYSUSPEND)
542 #include <linux/earlysuspend.h>
543
544 static void wlan_early_suspend(struct early_suspend *h)
545 {
546     LOG("%s :enter\n", __func__);
547
548     return;
549 }
550
551 static void wlan_late_resume(struct early_suspend *h)
552 {
553     LOG("%s :enter\n", __func__);
554
555     return;
556 }
557
558 struct early_suspend wlan_early_suspend {
559     .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
560     .suspend = wlan_early_suspend;
561     .resume = wlan_late_resume; 
562 }
563 #endif
564
565 static int rfkill_wlan_probe(struct platform_device *pdev)
566 {
567         struct rfkill_wlan_data *rfkill;
568         struct rksdmmc_gpio_wifi_moudle *pdata = pdev->dev.platform_data;
569         int ret = -1;
570
571     LOG("Enter %s\n", __func__);
572
573         if (!pdata) {
574 #ifdef CONFIG_OF
575         pdata = kzalloc(sizeof(struct rksdmmc_gpio_wifi_moudle), GFP_KERNEL);
576         if (!pdata)
577             return -ENOMEM;
578
579         ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
580         if (ret < 0) {
581 #endif
582                     LOG("%s: No platform data specified\n", __func__);
583             return ret;
584 #ifdef CONFIG_OF
585         }
586 #endif
587         }
588
589         rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
590         if (!rfkill)
591         goto rfkill_alloc_fail;
592
593         rfkill->pdata = pdata;
594     g_rfkill = rfkill;
595
596     LOG("%s: init gpio\n", __func__);
597
598     if (!pdata->mregulator.power_ctrl_by_pmu) {
599         ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
600         if (ret) goto fail_alloc;
601
602         ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
603         if (ret) goto fail_alloc;
604     }
605
606     wake_lock_init(&(rfkill->wlan_irq_wl), WAKE_LOCK_SUSPEND, "rfkill_wlan_wake");
607
608     // Turn off wifi power as default
609     if (gpio_is_valid(pdata->power_n.io))
610     {
611         gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable);
612     }
613
614     rockchip_wifi_voltage_select();
615
616 #if BCM_STATIC_MEMORY_SUPPORT
617     rockchip_init_wifi_mem();
618 #endif
619
620 #if defined(CONFIG_HAS_EARLYSUSPEND)
621     register_early_suspend(wlan_early_suspend);
622 #endif
623
624     LOG("Exit %s\n", __func__);
625
626         return 0;
627
628 fail_alloc:
629         kfree(rfkill);
630 rfkill_alloc_fail:
631     kfree(pdata);
632
633     g_rfkill = NULL;
634
635         return ret;
636 }
637
638 static int rfkill_wlan_remove(struct platform_device *pdev)
639 {
640         struct rfkill_wlan_data *rfkill = platform_get_drvdata(pdev);
641
642     LOG("Enter %s\n", __func__);
643
644     wake_lock_destroy(&rfkill->wlan_irq_wl);
645     
646     if (gpio_is_valid(rfkill->pdata->power_n.io))
647         gpio_free(rfkill->pdata->power_n.io);
648     
649     if (gpio_is_valid(rfkill->pdata->reset_n.io))
650         gpio_free(rfkill->pdata->reset_n.io);
651     
652 //    if (gpio_is_valid(rfkill->pdata->vddio.io))
653 //        gpio_free(rfkill->pdata->vddio.io);
654 //
655 //    if (gpio_is_valid(rfkill->pdata->bgf_int_b.io))
656 //        gpio_free(rfkill->pdata->bgf_int_b.io);
657 //    
658 //    if (gpio_is_valid(rfkill->pdata->gps_sync.io))
659 //        gpio_free(rfkill->pdata->gps_sync.io);
660 //    
661 //    if (gpio_is_valid(rfkill->pdata->ANTSEL2.io))
662 //        gpio_free(rfkill->pdata->ANTSEL2.io);
663 //
664 //    if (gpio_is_valid(rfkill->pdata->ANTSEL3.io))
665 //        gpio_free(rfkill->pdata->ANTSEL3.io);
666 //    
667 //    if (gpio_is_valid(rfkill->pdata->GPS_LAN.io))
668 //        gpio_free(rfkill->pdata->GPS_LAN.io);
669
670     kfree(rfkill);
671     g_rfkill = NULL;
672
673         return 0;
674 }
675
676 static int rfkill_wlan_suspend(struct platform_device *pdev, pm_message_t state)
677 {
678     LOG("Enter %s\n", __func__);
679     return 0;
680 }
681
682 static int rfkill_wlan_resume(struct platform_device *pdev)
683 {
684     LOG("Enter %s\n", __func__);
685     return 0;
686 }
687
688 #ifdef CONFIG_OF
689 static struct of_device_id wlan_platdata_of_match[] = {
690     { .compatible = "wlan-platdata" },
691     { }
692 };
693 MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
694 #endif //CONFIG_OF
695
696 static struct platform_driver rfkill_wlan_driver = {
697         .probe = rfkill_wlan_probe,
698         .remove = rfkill_wlan_remove,
699     .suspend = rfkill_wlan_suspend,
700     .resume = rfkill_wlan_resume,
701         .driver = {
702                 .name = "wlan-platdata",
703                 .owner = THIS_MODULE,
704         .of_match_table = of_match_ptr(wlan_platdata_of_match),
705         },
706 };
707
708 static int __init rfkill_wlan_init(void)
709 {
710     LOG("Enter %s\n", __func__);
711         return platform_driver_register(&rfkill_wlan_driver);
712 }
713
714 static void __exit rfkill_wlan_exit(void)
715 {
716     LOG("Enter %s\n", __func__);
717         platform_driver_unregister(&rfkill_wlan_driver);
718 }
719
720 module_init(rfkill_wlan_init);
721 module_exit(rfkill_wlan_exit);
722
723 MODULE_DESCRIPTION("rock-chips rfkill for wifi v0.1");
724 MODULE_AUTHOR("gwl@rock-chips.com");
725 MODULE_LICENSE("GPL");