2 * Copyright (C) 2012 ROCKCHIP, Inc.
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.
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.
14 /* Rock-chips rfkill driver for wifi
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>
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>
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 #include <linux/skbuff.h>
38 #include <linux/rockchip/cpu.h>
41 #include <linux/of_device.h>
42 #include <linux/of_gpio.h>
46 #define DBG(x...) printk(KERN_INFO "[WLAN_RFKILL]: "x)
51 #define LOG(x...) printk(KERN_INFO "[WLAN_RFKILL]: "x)
53 struct rfkill_wlan_data {
54 struct rksdmmc_gpio_wifi_moudle *pdata;
55 struct wake_lock wlan_irq_wl;
58 static struct rfkill_wlan_data *g_rfkill = NULL;
59 static int power_set_time = 0;
61 static const char wlan_name[] =
62 #if defined (CONFIG_BCM4330)
63 #if defined (CONFIG_BT_MODULE_NH660)
68 #elif defined (CONFIG_RK903)
69 #if defined(CONFIG_RKWIFI_26M)
74 #elif defined(CONFIG_BCM4329)
76 #elif defined(CONFIG_MV8787)
78 #elif defined(CONFIG_AP6210)
79 #if defined(CONFIG_RKWIFI_26M)
84 #elif defined(CONFIG_AP6330)
86 #elif defined(CONFIG_AP6476)
88 #elif defined(CONFIG_AP6493)
95 static char wifi_chip_type_string[64];
96 int get_wifi_chip_type(void)
99 if (strcmp(wifi_chip_type_string, "bcmwifi") == 0) {
101 } else if (strcmp(wifi_chip_type_string, "rtkwifi") == 0) {
103 } else if (strcmp(wifi_chip_type_string, "esp8089") == 0) {
110 EXPORT_SYMBOL(get_wifi_chip_type);
112 /***********************************************************
114 * Broadcom Wifi Static Memory
116 **********************************************************/
118 #define BCM_STATIC_MEMORY_SUPPORT 1
120 #define BCM_STATIC_MEMORY_SUPPORT 0
122 //===========================
123 #if BCM_STATIC_MEMORY_SUPPORT
124 #define PREALLOC_WLAN_SEC_NUM 4
125 #define PREALLOC_WLAN_BUF_NUM 160
126 #define PREALLOC_WLAN_SECTION_HEADER 0
127 #define WLAN_SKB_BUF_NUM 16
129 #define WLAN_SECTION_SIZE_0 (12 * 1024)
130 #define WLAN_SECTION_SIZE_1 (12 * 1024)
131 #define WLAN_SECTION_SIZE_2 (32 * 1024)
132 #define WLAN_SECTION_SIZE_3 (136* 1024)
133 #define WLAN_SECTION_SIZE_4 (4 * 1024)
134 #define WLAN_SECTION_SIZE_5 (64 * 1024)
135 #define WLAN_SECTION_SIZE_6 (4 * 1024)
136 #define WLAN_SECTION_SIZE_7 (4 * 1024)
138 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM+1];
140 struct wifi_mem_prealloc {
145 static struct wifi_mem_prealloc wifi_mem_array[8] = {
146 {NULL, (WLAN_SECTION_SIZE_0)},
147 {NULL, (WLAN_SECTION_SIZE_1)},
148 {NULL, (WLAN_SECTION_SIZE_2)},
149 {NULL, (WLAN_SECTION_SIZE_3)},
150 {NULL, (WLAN_SECTION_SIZE_4)},
151 {NULL, (WLAN_SECTION_SIZE_5)},
152 {NULL, (WLAN_SECTION_SIZE_6)},
153 {NULL, (WLAN_SECTION_SIZE_7)}
156 static int rockchip_init_wifi_mem(void)
161 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
162 wlan_static_skb[i] = dev_alloc_skb(
163 ((i < (WLAN_SKB_BUF_NUM / 2)) ? (PAGE_SIZE*1) : (PAGE_SIZE*2)));
165 if (!wlan_static_skb[i])
169 wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE*4));
170 if (!wlan_static_skb[i])
173 for (i = 0 ; i <= 7; i++) {
174 wifi_mem_array[i].mem_ptr =
175 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
177 if (!wifi_mem_array[i].mem_ptr)
183 pr_err("Failed to mem_alloc for WLAN\n");
184 for (j = 0 ; j < i ; j++)
185 kfree(wifi_mem_array[j].mem_ptr);
186 i = WLAN_SKB_BUF_NUM;
188 pr_err("Failed to skb_alloc for WLAN\n");
189 for (j = 0 ; j < i ; j++)
190 dev_kfree_skb(wlan_static_skb[j]);
191 dev_kfree_skb(wlan_static_skb[j]);
196 void *rockchip_mem_prealloc(int section, unsigned long size)
198 //printk("rockchip_mem_prealloc: section = %d, size = %d\n", section, size);
199 if (section == PREALLOC_WLAN_SEC_NUM)
200 return wlan_static_skb;
202 if ((section < 0) || (section > 7))
205 if (wifi_mem_array[section].size < size)
208 return wifi_mem_array[section].mem_ptr;
211 void *rockchip_mem_prealloc(int section, unsigned long size) { return NULL;}
213 EXPORT_SYMBOL(rockchip_mem_prealloc);
215 /**************************************************************************
217 * get wifi power state Func
219 *************************************************************************/
220 static int wifi_power_state = 0;
221 int rfkill_get_wifi_power_state(int *power, int *vref_ctrl_enable)
223 struct rfkill_wlan_data *mrfkill = g_rfkill;
225 if (mrfkill == NULL) {
226 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
230 if (mrfkill->pdata->vref_ctrl_enble)
231 *vref_ctrl_enable = 1;
232 *power = wifi_power_state;
237 /**************************************************************************
239 * wifi reference voltage control Func
241 *************************************************************************/
242 int rockchip_wifi_ref_voltage(int on)
244 struct rfkill_wlan_data *mrfkill = g_rfkill;
245 struct rksdmmc_gpio *vddio;
246 struct regulator *ldo = NULL;
250 LOG("%s: %d\n", __func__, on);
252 if (mrfkill == NULL) {
253 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
257 if (!mrfkill->pdata->vref_ctrl_enble) {
258 LOG("%s: wifi io reference voltage control is disabled.\n", __func__);
262 if (!rfkill_get_bt_power_state(&power, &toggle)) {
264 LOG("%s: wifi shouldn't control io reference voltage, BT is running!\n", __func__);
269 if (mrfkill->pdata->ioregulator.power_ctrl_by_pmu) {
272 int level = mrfkill->pdata->ioregulator.enable;
273 int voltage = 1000 * mrfkill->pdata->sdio_vol;
275 ldostr = mrfkill->pdata->ioregulator.pmu_regulator;
276 if (ldostr == NULL) {
277 LOG("%s: wifi io reference voltage set to be controled by pmic, but which one?\n", __func__);
280 ldo = regulator_get(NULL, ldostr);
281 if (ldo == NULL || IS_ERR(ldo)) {
282 LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
286 if(cpu_is_rk3036() || cpu_is_rk312x())
288 /*regulator_set_voltage(ldo, voltage, voltage);
289 LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
290 ret = regulator_enable(ldo);
291 LOG("wifi turn on io reference voltage.\n");*/
293 regulator_set_voltage(ldo, voltage, voltage);
294 LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
295 ret = regulator_enable(ldo);
296 LOG("wifi turn on io reference voltage.\n");
299 LOG("%s: %s disabled\n", __func__, ldostr);
300 while (regulator_is_enabled(ldo) > 0) {
301 ret = regulator_disable(ldo);
303 LOG("wifi shut off io reference voltage.\n");
309 vddio = &mrfkill->pdata->power_n;
312 if (gpio_is_valid(vddio->io)) {
313 gpio_set_value(vddio->io, vddio->enable);
317 LOG("wifi turn on io reference voltage.\n");
319 if (gpio_is_valid(vddio->io)) {
320 gpio_set_value(vddio->io, !(vddio->enable));
324 LOG("wifi shut off io reference voltage.\n");
331 /**************************************************************************
333 * Wifi Power Control Func
337 *************************************************************************/
338 int rockchip_wifi_power(int on)
340 struct rfkill_wlan_data *mrfkill = g_rfkill;
341 struct rksdmmc_gpio *poweron, *reset;
342 struct regulator *ldo = NULL;
346 LOG("%s: %d\n", __func__, on);
348 if (mrfkill == NULL) {
349 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
353 if (mrfkill->pdata->wifi_power_remain && power_set_time) {
354 LOG("%s: wifi power is setted to be remain on. skip anything to the power control", __func__);
356 } else power_set_time++;
358 if (!rfkill_get_bt_power_state(&power, &toggle)) {
359 if (toggle == true && power == 1) {
360 LOG("%s: wifi shouldn't control the power, it was enabled by BT!\n", __func__);
366 rockchip_wifi_ref_voltage(1);
368 if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
371 int level = mrfkill->pdata->mregulator.enable;
373 ldostr = mrfkill->pdata->mregulator.pmu_regulator;
374 if (ldostr == NULL) {
375 LOG("%s: wifi power set to be controled by pmic, but which one?\n", __func__);
378 ldo = regulator_get(NULL, ldostr);
379 if (ldo == NULL || IS_ERR(ldo)) {
380 LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
384 regulator_set_voltage(ldo, 3000000, 3000000);
385 LOG("%s: %s enabled\n", __func__, ldostr);
386 ret = regulator_enable(ldo);
387 wifi_power_state = 1;
388 LOG("wifi turn on power.\n");
390 LOG("%s: %s disabled\n", __func__, ldostr);
391 while (regulator_is_enabled(ldo) > 0) {
392 ret = regulator_disable(ldo);
394 wifi_power_state = 0;
395 LOG("wifi shut off power.\n");
401 poweron = &mrfkill->pdata->power_n;
402 reset = &mrfkill->pdata->reset_n;
405 if (gpio_is_valid(poweron->io)) {
406 gpio_set_value(poweron->io, poweron->enable);
410 if (gpio_is_valid(reset->io)) {
411 gpio_set_value(reset->io, reset->enable);
415 wifi_power_state = 1;
416 LOG("wifi turn on power. %d\n", poweron->io);
418 if (gpio_is_valid(poweron->io)) {
419 gpio_set_value(poweron->io, !(poweron->enable));
423 if (gpio_is_valid(reset->io)) {
424 gpio_set_value(reset->io, !(reset->enable));
427 wifi_power_state = 0;
428 LOG("wifi shut off power.\n");
433 rockchip_wifi_ref_voltage(0);
437 EXPORT_SYMBOL(rockchip_wifi_power);
439 /**************************************************************************
441 * Wifi Sdio Detect Func
443 *************************************************************************/
444 #include <linux/mmc/host.h>
445 extern int mmc_host_rescan(struct mmc_host *host, int val, int irq_type);
446 int rockchip_wifi_set_carddetect(int val)
449 chip = get_wifi_chip_type();
451 /* irq_type : 0, oob; 1, cap-sdio-irq */
452 if (chip == WIFI_BCMWIFI)
457 return mmc_host_rescan(NULL, val, irq_type);//NULL => SDIO host
459 EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
461 /**************************************************************************
463 * Wifi Get Interrupt irq Func
465 *************************************************************************/
466 int rockchip_wifi_get_oob_irq(void)
468 struct rfkill_wlan_data *mrfkill = g_rfkill;
469 struct rksdmmc_gpio *wifi_int_irq;
471 LOG("%s: Enter\n", __func__);
473 if (mrfkill == NULL) {
474 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
478 wifi_int_irq = &mrfkill->pdata->wifi_int_b;
479 if (gpio_is_valid(wifi_int_irq->io)) {
480 return gpio_to_irq(wifi_int_irq->io);
481 //return wifi_int_irq->io;
483 LOG("%s: wifi OOB pin isn't defined.\n", __func__);
488 EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
490 /**************************************************************************
494 *************************************************************************/
495 int rockchip_wifi_reset(int on)
499 EXPORT_SYMBOL(rockchip_wifi_reset);
501 /**************************************************************************
503 * Wifi MAC custom Func
505 *************************************************************************/
506 #include <linux/etherdevice.h>
507 u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
508 extern char GetSNSectorInfo(char * pbuf);
509 int rockchip_wifi_mac_addr(unsigned char *buf)
511 char mac_buf[20] = {0};
512 LOG("%s: enter.\n", __func__);
515 if(is_zero_ether_addr(wifi_custom_mac_addr)) {
517 char *tempBuf = kmalloc(512, GFP_KERNEL);
519 GetSNSectorInfo(tempBuf);
520 for (i = 506; i <= 511; i++)
521 wifi_custom_mac_addr[i-506] = tempBuf[i];
528 sprintf(mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x",wifi_custom_mac_addr[0],wifi_custom_mac_addr[1],
529 wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
530 LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
532 if (is_valid_ether_addr(wifi_custom_mac_addr)) {
533 if (2 == (wifi_custom_mac_addr[0] & 0x0F)) {
534 LOG("This mac address come into conflict with the address of direct, ignored...\n");
538 LOG("This mac address is not valid, ignored...\n");
542 memcpy(buf, wifi_custom_mac_addr, 6);
546 EXPORT_SYMBOL(rockchip_wifi_mac_addr);
548 /**************************************************************************
550 * wifi get country code func
552 *************************************************************************/
553 struct cntry_locales_custom {
554 char iso_abbrev[4]; /* ISO 3166-1 country abbreviation */
555 char custom_locale[4]; /* Custom firmware locale */
556 int custom_locale_rev; /* Custom local revisin default -1 */
559 static struct cntry_locales_custom country_cloc;
561 void *rockchip_wifi_country_code(char *ccode)
563 struct cntry_locales_custom *mcloc;
565 LOG("%s: set country code [%s]\n", __func__, ccode);
566 mcloc = &country_cloc;
567 memcpy(mcloc->custom_locale, ccode, 4);
568 mcloc->custom_locale_rev = 0;
572 EXPORT_SYMBOL(rockchip_wifi_country_code);
573 /**************************************************************************/
575 static int rockchip_wifi_voltage_select(void)
577 struct rfkill_wlan_data *mrfkill = g_rfkill;
580 if (mrfkill == NULL) {
581 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
584 voltage = mrfkill->pdata->sdio_vol;
585 if (voltage > 2700 && voltage < 3500) {
586 writel_relaxed(0x00100000, RK_GRF_VIRT+0x380); //3.3
587 LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
588 } else if (voltage > 1500 && voltage < 1950) {
589 writel_relaxed(0x00100010, RK_GRF_VIRT+0x380); //1.8
590 LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
592 LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
599 static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char* prefix, const char* name)
601 if (gpio_is_valid(gpio->io)) {
603 sprintf(gpio->name, "%s_%s", prefix, name);
604 ret = gpio_request(gpio->io, gpio->name);
606 LOG("Failed to get %s gpio.\n", gpio->name);
615 static int wlan_platdata_parse_dt(struct device *dev,
616 struct rksdmmc_gpio_wifi_moudle *data)
618 struct device_node *node = dev->of_node;
622 enum of_gpio_flags flags;
627 memset(data, 0, sizeof(*data));
629 ret = of_property_read_string(node, "wifi_chip_type", &strings);
631 LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n", __func__);
632 strcpy(wifi_chip_type_string, "rkwifi");
634 strcpy(wifi_chip_type_string, strings);
635 LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
637 if(cpu_is_rk3036() || cpu_is_rk312x()){
638 /* ret = of_property_read_u32(node, "sdio_vref", &value);
640 LOG("%s: Can't get sdio vref.", __func__);
643 data->sdio_vol = value;*/
645 ret = of_property_read_u32(node, "sdio_vref", &value);
647 LOG("%s: Can't get sdio vref.", __func__);
650 data->sdio_vol = value;
653 if (of_find_property(node, "keep_wifi_power_on", NULL)) {
654 data->wifi_power_remain = true;
655 LOG("%s: wifi power will enabled while kernel starting and keep on.\n", __func__);
657 data->wifi_power_remain = false;
658 LOG("%s: enable wifi power control.\n", __func__);
661 if (of_find_property(node, "vref_ctrl_enable", NULL)) {
662 LOG("%s: enable wifi io reference voltage control.\n", __func__);
663 data->vref_ctrl_enble = true;
664 if (of_find_property(node, "vref_ctrl_gpio", NULL)) {
665 gpio = of_get_named_gpio_flags(node, "vref_ctrl_gpio", 0, &flags);
666 if (gpio_is_valid(gpio)){
667 data->vddio.io = gpio;
668 data->vddio.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
669 data->ioregulator.power_ctrl_by_pmu = false;
670 LOG("%s: get property: vref_ctrl_gpio = %d, flags = %d.\n", __func__, gpio, flags);
673 data->vref_ctrl_enble = false;
674 LOG("%s: vref_ctrl_gpio defined invalid, disable wifi io reference voltage control.\n", __func__);
677 data->ioregulator.power_ctrl_by_pmu = true;
678 ret = of_property_read_string(node, "vref_pmu_regulator", &strings);
680 LOG("%s: Can not read property: vref_pmu_regulator.\n", __func__);
681 data->vref_ctrl_enble = false;
682 data->ioregulator.power_ctrl_by_pmu = false;
684 LOG("%s: wifi io reference voltage controled by pmu(%s).\n", __func__, strings);
685 sprintf(data->ioregulator.pmu_regulator, "%s", strings);
687 ret = of_property_read_u32(node, "vref_pmu_enable_level", &value);
689 LOG("%s: Can not read property: vref_pmu_enable_level.\n", __func__);
690 data->vref_ctrl_enble = false;
691 data->ioregulator.power_ctrl_by_pmu = false;
693 LOG("%s: wifi io reference voltage controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
694 data->ioregulator.enable = value;
698 data->vref_ctrl_enble = false;
699 LOG("%s: disable wifi io reference voltage control.\n", __func__);
702 if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
703 data->mregulator.power_ctrl_by_pmu = true;
704 ret = of_property_read_string(node, "power_pmu_regulator", &strings);
706 LOG("%s: Can not read property: power_pmu_regulator.\n", __func__);
707 data->mregulator.power_ctrl_by_pmu = false;
709 LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
710 sprintf(data->mregulator.pmu_regulator, "%s", strings);
712 ret = of_property_read_u32(node, "power_pmu_enable_level", &value);
714 LOG("%s: Can not read property: power_pmu_enable_level.\n", __func__);
715 data->mregulator.power_ctrl_by_pmu = false;
717 LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
718 data->mregulator.enable = value;
721 data->mregulator.power_ctrl_by_pmu = false;
722 LOG("%s: wifi power controled by gpio.\n", __func__);
723 gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
724 if (gpio_is_valid(gpio)){
725 data->power_n.io = gpio;
726 data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
727 LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
728 } else data->power_n.io = -1;
729 gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
730 if (gpio_is_valid(gpio)){
731 data->reset_n.io = gpio;
732 data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
733 LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
734 } else data->reset_n.io = -1;
735 gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
736 if (gpio_is_valid(gpio)){
737 data->wifi_int_b.io = gpio;
738 data->wifi_int_b.enable = flags;
739 LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
740 } else data->wifi_int_b.io = -1;
747 #if defined(CONFIG_HAS_EARLYSUSPEND)
748 #include <linux/earlysuspend.h>
750 static void wlan_early_suspend(struct early_suspend *h)
752 LOG("%s :enter\n", __func__);
757 static void wlan_late_resume(struct early_suspend *h)
759 LOG("%s :enter\n", __func__);
764 struct early_suspend wlan_early_suspend {
765 .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
766 .suspend = wlan_early_suspend;
767 .resume = wlan_late_resume;
771 static int rfkill_wlan_probe(struct platform_device *pdev)
773 struct rfkill_wlan_data *rfkill;
774 struct rksdmmc_gpio_wifi_moudle *pdata = pdev->dev.platform_data;
777 LOG("Enter %s\n", __func__);
781 pdata = kzalloc(sizeof(struct rksdmmc_gpio_wifi_moudle), GFP_KERNEL);
785 ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
788 LOG("%s: No platform data specified\n", __func__);
795 rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
797 goto rfkill_alloc_fail;
799 rfkill->pdata = pdata;
802 LOG("%s: init gpio\n", __func__);
804 if (!pdata->mregulator.power_ctrl_by_pmu) {
805 ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
806 if (ret) goto fail_alloc;
808 ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
809 if (ret) goto fail_alloc;
812 wake_lock_init(&(rfkill->wlan_irq_wl), WAKE_LOCK_SUSPEND, "rfkill_wlan_wake");
814 // Turn off wifi power as default
815 if (gpio_is_valid(pdata->power_n.io))
817 gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable);
820 if (pdata->wifi_power_remain)
822 rockchip_wifi_power(1);
825 rockchip_wifi_voltage_select();
827 #if BCM_STATIC_MEMORY_SUPPORT
828 rockchip_init_wifi_mem();
831 #if defined(CONFIG_HAS_EARLYSUSPEND)
832 register_early_suspend(wlan_early_suspend);
835 LOG("Exit %s\n", __func__);
849 static int rfkill_wlan_remove(struct platform_device *pdev)
851 struct rfkill_wlan_data *rfkill = platform_get_drvdata(pdev);
853 LOG("Enter %s\n", __func__);
855 wake_lock_destroy(&rfkill->wlan_irq_wl);
857 if (gpio_is_valid(rfkill->pdata->power_n.io))
858 gpio_free(rfkill->pdata->power_n.io);
860 if (gpio_is_valid(rfkill->pdata->reset_n.io))
861 gpio_free(rfkill->pdata->reset_n.io);
863 // if (gpio_is_valid(rfkill->pdata->vddio.io))
864 // gpio_free(rfkill->pdata->vddio.io);
866 // if (gpio_is_valid(rfkill->pdata->bgf_int_b.io))
867 // gpio_free(rfkill->pdata->bgf_int_b.io);
869 // if (gpio_is_valid(rfkill->pdata->gps_sync.io))
870 // gpio_free(rfkill->pdata->gps_sync.io);
872 // if (gpio_is_valid(rfkill->pdata->ANTSEL2.io))
873 // gpio_free(rfkill->pdata->ANTSEL2.io);
875 // if (gpio_is_valid(rfkill->pdata->ANTSEL3.io))
876 // gpio_free(rfkill->pdata->ANTSEL3.io);
878 // if (gpio_is_valid(rfkill->pdata->GPS_LAN.io))
879 // gpio_free(rfkill->pdata->GPS_LAN.io);
887 static int rfkill_wlan_suspend(struct platform_device *pdev, pm_message_t state)
889 LOG("Enter %s\n", __func__);
893 static int rfkill_wlan_resume(struct platform_device *pdev)
895 LOG("Enter %s\n", __func__);
900 static struct of_device_id wlan_platdata_of_match[] = {
901 { .compatible = "wlan-platdata" },
904 MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
907 static struct platform_driver rfkill_wlan_driver = {
908 .probe = rfkill_wlan_probe,
909 .remove = rfkill_wlan_remove,
910 .suspend = rfkill_wlan_suspend,
911 .resume = rfkill_wlan_resume,
913 .name = "wlan-platdata",
914 .owner = THIS_MODULE,
915 .of_match_table = of_match_ptr(wlan_platdata_of_match),
919 static int __init rfkill_wlan_init(void)
921 LOG("Enter %s\n", __func__);
922 return platform_driver_register(&rfkill_wlan_driver);
925 static void __exit rfkill_wlan_exit(void)
927 LOG("Enter %s\n", __func__);
928 platform_driver_unregister(&rfkill_wlan_driver);
931 module_init(rfkill_wlan_init);
932 module_exit(rfkill_wlan_exit);
934 MODULE_DESCRIPTION("rock-chips rfkill for wifi v0.1");
935 MODULE_AUTHOR("gwl@rock-chips.com");
936 MODULE_LICENSE("GPL");