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>
23 #include <linux/regulator/consumer.h>
24 #include <linux/delay.h>
25 #include <linux/rfkill-wlan.h>
26 #include <linux/rfkill-bt.h>
27 #include <linux/wakelock.h>
28 #include <linux/interrupt.h>
30 #include <linux/suspend.h>
31 #include <linux/proc_fs.h>
32 #include <linux/uaccess.h>
33 #include <linux/gpio.h>
34 #include <linux/rockchip/iomap.h>
35 #include <dt-bindings/gpio/gpio.h>
36 #include <linux/skbuff.h>
37 #include <linux/rockchip/cpu.h>
39 #include <linux/rockchip/grf.h>
40 #include <linux/rockchip/common.h>
41 #include <linux/regmap.h>
42 #include <linux/mfd/syscon.h>
45 #include <linux/of_device.h>
46 #include <linux/of_gpio.h>
50 #define DBG(x...) printk(KERN_INFO "[WLAN_RFKILL]: "x)
55 #define LOG(x...) printk(KERN_INFO "[WLAN_RFKILL]: "x)
57 struct rfkill_wlan_data {
58 struct rksdmmc_gpio_wifi_moudle *pdata;
59 struct wake_lock wlan_irq_wl;
62 static struct rfkill_wlan_data *g_rfkill = NULL;
63 static int power_set_time = 0;
65 static const char wlan_name[] =
66 #if defined (CONFIG_BCM4330)
67 #if defined (CONFIG_BT_MODULE_NH660)
72 #elif defined (CONFIG_RK903)
73 #if defined(CONFIG_RKWIFI_26M)
78 #elif defined(CONFIG_BCM4329)
80 #elif defined(CONFIG_MV8787)
82 #elif defined(CONFIG_AP6210)
83 #if defined(CONFIG_RKWIFI_26M)
88 #elif defined(CONFIG_AP6330)
90 #elif defined(CONFIG_AP6476)
92 #elif defined(CONFIG_AP6493)
99 static char wifi_chip_type_string[64];
100 int get_wifi_chip_type(void)
103 if (strcmp(wifi_chip_type_string, "ap6210") == 0) {
105 } else if (strcmp(wifi_chip_type_string, "ap6212") == 0) {
107 } else if (strcmp(wifi_chip_type_string, "rk901") == 0) {
109 } else if (strcmp(wifi_chip_type_string, "rk903") == 0) {
111 } else if (strcmp(wifi_chip_type_string, "ap6181") == 0) {
113 } else if (strcmp(wifi_chip_type_string, "ap6234") == 0) {
115 } else if (strcmp(wifi_chip_type_string, "ap6330") == 0) {
117 } else if (strcmp(wifi_chip_type_string, "ap6335") == 0) {
119 } else if (strcmp(wifi_chip_type_string, "ap6354") == 0) {
121 } else if (strcmp(wifi_chip_type_string, "ap6441") == 0) {
123 } else if (strcmp(wifi_chip_type_string, "ap6476") == 0) {
125 } else if (strcmp(wifi_chip_type_string, "ap6493") == 0) {
127 } else if (strcmp(wifi_chip_type_string, "rtl8188eu") == 0) {
128 type = WIFI_RTL8188EU;
129 } else if (strcmp(wifi_chip_type_string, "rtl8192du") == 0) {
130 type = WIFI_RTL8192DU;
131 } else if (strcmp(wifi_chip_type_string, "rtl8723as") == 0) {
132 type = WIFI_RTL8723AS;
133 } else if (strcmp(wifi_chip_type_string, "rtl8723bs_vq0") == 0) {
134 type = WIFI_RTL8723BS_VQ0;
135 } else if (strcmp(wifi_chip_type_string, "rtl8723bs") == 0) {
136 type = WIFI_RTL8723BS;
137 } else if (strcmp(wifi_chip_type_string, "rtl8723au") == 0) {
138 type = WIFI_RTL8723AU;
139 } else if (strcmp(wifi_chip_type_string, "rtl8723bu") == 0) {
140 type = WIFI_RTL8723BU;
141 } else if (strcmp(wifi_chip_type_string, "rtl8189es") == 0) {
142 type = WIFI_RTL8189ES;
143 } else if (strcmp(wifi_chip_type_string, "rtl8812au") == 0) {
144 type = WIFI_RTL8812AU;
145 } else if (strcmp(wifi_chip_type_string, "esp8089") == 0) {
152 EXPORT_SYMBOL(get_wifi_chip_type);
154 /***********************************************************
156 * Broadcom Wifi Static Memory
158 **********************************************************/
160 #define BCM_STATIC_MEMORY_SUPPORT 0
162 #define BCM_STATIC_MEMORY_SUPPORT 0
164 //===========================
165 #if BCM_STATIC_MEMORY_SUPPORT
166 #define PREALLOC_WLAN_SEC_NUM 4
167 #define PREALLOC_WLAN_BUF_NUM 160
168 #define PREALLOC_WLAN_SECTION_HEADER 0
169 #define WLAN_SKB_BUF_NUM 16
171 #define WLAN_SECTION_SIZE_0 (12 * 1024)
172 #define WLAN_SECTION_SIZE_1 (12 * 1024)
173 #define WLAN_SECTION_SIZE_2 (32 * 1024)
174 #define WLAN_SECTION_SIZE_3 (136* 1024)
175 #define WLAN_SECTION_SIZE_4 (4 * 1024)
176 #define WLAN_SECTION_SIZE_5 (64 * 1024)
177 #define WLAN_SECTION_SIZE_6 (4 * 1024)
178 #define WLAN_SECTION_SIZE_7 (4 * 1024)
180 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM+1];
182 struct wifi_mem_prealloc {
187 static struct wifi_mem_prealloc wifi_mem_array[8] = {
188 {NULL, (WLAN_SECTION_SIZE_0)},
189 {NULL, (WLAN_SECTION_SIZE_1)},
190 {NULL, (WLAN_SECTION_SIZE_2)},
191 {NULL, (WLAN_SECTION_SIZE_3)},
192 {NULL, (WLAN_SECTION_SIZE_4)},
193 {NULL, (WLAN_SECTION_SIZE_5)},
194 {NULL, (WLAN_SECTION_SIZE_6)},
195 {NULL, (WLAN_SECTION_SIZE_7)}
198 static int rockchip_init_wifi_mem(void)
203 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
204 wlan_static_skb[i] = dev_alloc_skb(
205 ((i < (WLAN_SKB_BUF_NUM / 2)) ? (PAGE_SIZE*1) : (PAGE_SIZE*2)));
207 if (!wlan_static_skb[i])
211 wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE*4));
212 if (!wlan_static_skb[i])
215 for (i = 0 ; i <= 7; i++) {
216 wifi_mem_array[i].mem_ptr =
217 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
219 if (!wifi_mem_array[i].mem_ptr)
225 pr_err("Failed to mem_alloc for WLAN\n");
226 for (j = 0 ; j < i ; j++)
227 kfree(wifi_mem_array[j].mem_ptr);
228 i = WLAN_SKB_BUF_NUM;
230 pr_err("Failed to skb_alloc for WLAN\n");
231 for (j = 0 ; j < i ; j++)
232 dev_kfree_skb(wlan_static_skb[j]);
233 dev_kfree_skb(wlan_static_skb[j]);
238 void *rockchip_mem_prealloc(int section, unsigned long size)
240 //printk("rockchip_mem_prealloc: section = %d, size = %d\n", section, size);
241 if (section == PREALLOC_WLAN_SEC_NUM)
242 return wlan_static_skb;
244 if ((section < 0) || (section > 7))
247 if (wifi_mem_array[section].size < size)
250 return wifi_mem_array[section].mem_ptr;
253 void *rockchip_mem_prealloc(int section, unsigned long size) { return NULL;}
255 EXPORT_SYMBOL(rockchip_mem_prealloc);
257 /**************************************************************************
259 * get wifi power state Func
261 *************************************************************************/
262 static int wifi_power_state = 0;
263 int rfkill_get_wifi_power_state(int *power, int *vref_ctrl_enable)
265 struct rfkill_wlan_data *mrfkill = g_rfkill;
267 if (mrfkill == NULL) {
268 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
272 if (mrfkill->pdata->vref_ctrl_enble)
273 *vref_ctrl_enable = 1;
274 *power = wifi_power_state;
279 /**************************************************************************
281 * wifi reference voltage control Func
283 *************************************************************************/
284 int rockchip_wifi_ref_voltage(int on)
286 struct rfkill_wlan_data *mrfkill = g_rfkill;
287 struct rksdmmc_gpio *vddio;
288 struct regulator *ldo = NULL;
292 LOG("%s: %d\n", __func__, on);
294 if (mrfkill == NULL) {
295 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
299 if (!mrfkill->pdata->vref_ctrl_enble) {
300 LOG("%s: wifi io reference voltage control is disabled.\n", __func__);
304 if (!rfkill_get_bt_power_state(&power, &toggle)) {
306 LOG("%s: wifi shouldn't control io reference voltage, BT is running!\n", __func__);
311 if (mrfkill->pdata->ioregulator.power_ctrl_by_pmu) {
314 int level = mrfkill->pdata->ioregulator.enable;
315 int voltage = 1000 * mrfkill->pdata->sdio_vol;
317 ldostr = mrfkill->pdata->ioregulator.pmu_regulator;
318 if (ldostr == NULL) {
319 LOG("%s: wifi io reference voltage set to be controled by pmic, but which one?\n", __func__);
322 ldo = regulator_get(NULL, ldostr);
323 if (ldo == NULL || IS_ERR(ldo)) {
324 LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
328 if(cpu_is_rk3036() || cpu_is_rk312x())
330 /*regulator_set_voltage(ldo, voltage, voltage);
331 LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
332 ret = regulator_enable(ldo);
333 LOG("wifi turn on io reference voltage.\n");*/
335 regulator_set_voltage(ldo, voltage, voltage);
336 LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
337 ret = regulator_enable(ldo);
338 LOG("wifi turn on io reference voltage.\n");
341 LOG("%s: %s disabled\n", __func__, ldostr);
342 while (regulator_is_enabled(ldo) > 0) {
343 ret = regulator_disable(ldo);
345 LOG("wifi shut off io reference voltage.\n");
351 vddio = &mrfkill->pdata->power_n;
354 if (gpio_is_valid(vddio->io)) {
355 gpio_set_value(vddio->io, vddio->enable);
359 LOG("wifi turn on io reference voltage.\n");
361 if (gpio_is_valid(vddio->io)) {
362 gpio_set_value(vddio->io, !(vddio->enable));
366 LOG("wifi shut off io reference voltage.\n");
373 /**************************************************************************
375 * Wifi Power Control Func
379 *************************************************************************/
380 int rockchip_wifi_power(int on)
382 struct rfkill_wlan_data *mrfkill = g_rfkill;
383 struct rksdmmc_gpio *poweron, *reset;
384 struct regulator *ldo = NULL;
388 LOG("%s: %d\n", __func__, on);
390 if (mrfkill == NULL) {
391 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
395 if (mrfkill->pdata->wifi_power_remain && power_set_time) {
396 LOG("%s: wifi power is setted to be remain on. skip anything to the power control", __func__);
398 } else power_set_time++;
400 if (!rfkill_get_bt_power_state(&power, &toggle)) {
401 if (toggle == true && power == 1) {
402 LOG("%s: wifi shouldn't control the power, it was enabled by BT!\n", __func__);
408 rockchip_wifi_ref_voltage(1);
410 if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
413 int level = mrfkill->pdata->mregulator.enable;
415 ldostr = mrfkill->pdata->mregulator.pmu_regulator;
416 if (ldostr == NULL) {
417 LOG("%s: wifi power set to be controled by pmic, but which one?\n", __func__);
420 ldo = regulator_get(NULL, ldostr);
421 if (ldo == NULL || IS_ERR(ldo)) {
422 LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
426 regulator_set_voltage(ldo, 3000000, 3000000);
427 LOG("%s: %s enabled\n", __func__, ldostr);
428 ret = regulator_enable(ldo);
429 wifi_power_state = 1;
430 LOG("wifi turn on power.\n");
432 LOG("%s: %s disabled\n", __func__, ldostr);
433 while (regulator_is_enabled(ldo) > 0) {
434 ret = regulator_disable(ldo);
436 wifi_power_state = 0;
437 LOG("wifi shut off power.\n");
443 poweron = &mrfkill->pdata->power_n;
444 reset = &mrfkill->pdata->reset_n;
447 if (gpio_is_valid(poweron->io)) {
448 gpio_set_value(poweron->io, poweron->enable);
452 if (gpio_is_valid(reset->io)) {
453 gpio_set_value(reset->io, reset->enable);
457 wifi_power_state = 1;
458 LOG("wifi turn on power. %d\n", poweron->io);
460 if (gpio_is_valid(poweron->io)) {
461 gpio_set_value(poweron->io, !(poweron->enable));
465 if (gpio_is_valid(reset->io)) {
466 gpio_set_value(reset->io, !(reset->enable));
469 wifi_power_state = 0;
470 LOG("wifi shut off power.\n");
475 rockchip_wifi_ref_voltage(0);
479 EXPORT_SYMBOL(rockchip_wifi_power);
481 /**************************************************************************
483 * Wifi Sdio Detect Func
485 *************************************************************************/
486 #include <linux/mmc/host.h>
487 extern int mmc_host_rescan(struct mmc_host *host, int val, int irq_type);
488 int rockchip_wifi_set_carddetect(int val)
491 chip = get_wifi_chip_type();
493 /* irq_type : 0, oob; 1, cap-sdio-irq */
494 if (!strncmp(wifi_chip_type_string, "ap", 2) ||
495 !strncmp(wifi_chip_type_string, "rk", 2))
500 return mmc_host_rescan(NULL, val, irq_type);//NULL => SDIO host
502 EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
504 /**************************************************************************
506 * Wifi Get Interrupt irq Func
508 *************************************************************************/
509 int rockchip_wifi_get_oob_irq(void)
511 struct rfkill_wlan_data *mrfkill = g_rfkill;
512 struct rksdmmc_gpio *wifi_int_irq;
514 LOG("%s: Enter\n", __func__);
516 if (mrfkill == NULL) {
517 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
521 wifi_int_irq = &mrfkill->pdata->wifi_int_b;
522 if (gpio_is_valid(wifi_int_irq->io)) {
523 return gpio_to_irq(wifi_int_irq->io);
524 //return wifi_int_irq->io;
526 LOG("%s: wifi OOB pin isn't defined.\n", __func__);
531 EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
533 /**************************************************************************
537 *************************************************************************/
538 int rockchip_wifi_reset(int on)
542 EXPORT_SYMBOL(rockchip_wifi_reset);
544 /**************************************************************************
546 * Wifi MAC custom Func
548 *************************************************************************/
549 #include <linux/etherdevice.h>
550 u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
551 extern char GetSNSectorInfo(char * pbuf);
552 int rockchip_wifi_mac_addr(unsigned char *buf)
554 char mac_buf[20] = {0};
555 LOG("%s: enter.\n", __func__);
558 if(is_zero_ether_addr(wifi_custom_mac_addr)) {
560 char *tempBuf = kmalloc(512, GFP_KERNEL);
562 GetSNSectorInfo(tempBuf);
563 for (i = 445; i <= 450; i++)
564 wifi_custom_mac_addr[i-445] = tempBuf[i];
571 sprintf(mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x",wifi_custom_mac_addr[0],wifi_custom_mac_addr[1],
572 wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
573 LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
575 if (is_valid_ether_addr(wifi_custom_mac_addr)) {
576 if (2 == (wifi_custom_mac_addr[0] & 0x0F)) {
577 LOG("This mac address come into conflict with the address of direct, ignored...\n");
581 LOG("This mac address is not valid, ignored...\n");
585 memcpy(buf, wifi_custom_mac_addr, 6);
589 EXPORT_SYMBOL(rockchip_wifi_mac_addr);
591 /**************************************************************************
593 * wifi get country code func
595 *************************************************************************/
596 struct cntry_locales_custom {
597 char iso_abbrev[4]; /* ISO 3166-1 country abbreviation */
598 char custom_locale[4]; /* Custom firmware locale */
599 int custom_locale_rev; /* Custom local revisin default -1 */
602 static struct cntry_locales_custom country_cloc;
604 void *rockchip_wifi_country_code(char *ccode)
606 struct cntry_locales_custom *mcloc;
608 LOG("%s: set country code [%s]\n", __func__, ccode);
609 mcloc = &country_cloc;
610 memcpy(mcloc->custom_locale, ccode, 4);
611 mcloc->custom_locale_rev = 0;
615 EXPORT_SYMBOL(rockchip_wifi_country_code);
616 /**************************************************************************/
618 #define RK3368_GRF_IO_VSEL 0x900
619 static int rockchip_wifi_voltage_select(void)
621 struct rfkill_wlan_data *mrfkill = g_rfkill;
624 if (mrfkill == NULL) {
625 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
629 voltage = mrfkill->pdata->sdio_vol;
630 if (cpu_is_rk3288()) {
631 if (voltage > 2700 && voltage < 3500) {
632 writel_relaxed(0x00100000, RK_GRF_VIRT+0x380); //3.3
633 LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
634 } else if (voltage > 1500 && voltage < 1950) {
635 writel_relaxed(0x00100010, RK_GRF_VIRT+0x380); //1.8
636 LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
638 LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
641 } else if(cpu_is_rk3036() || cpu_is_rk312x()) {
643 #ifdef CONFIG_MFD_SYSCON
644 if (voltage > 2700 && voltage < 3500) {
645 regmap_write(mrfkill->pdata->grf, RK3368_GRF_IO_VSEL, ((1<<3)<<16)|(0<<3)); //3.3
646 LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
647 } else if (voltage > 1500 && voltage < 1950) {
648 regmap_write(mrfkill->pdata->grf, RK3368_GRF_IO_VSEL, ((1<<3)<<16)|(1<<3)); //1.8
649 LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
653 LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
661 static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char* prefix, const char* name)
663 if (gpio_is_valid(gpio->io)) {
665 sprintf(gpio->name, "%s_%s", prefix, name);
666 ret = gpio_request(gpio->io, gpio->name);
668 LOG("Failed to get %s gpio.\n", gpio->name);
677 static int wlan_platdata_parse_dt(struct device *dev,
678 struct rksdmmc_gpio_wifi_moudle *data)
680 struct device_node *node = dev->of_node;
684 enum of_gpio_flags flags;
689 memset(data, 0, sizeof(*data));
691 #ifdef CONFIG_MFD_SYSCON
692 data->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");
693 if (IS_ERR(data->grf)) {
694 LOG("can't find rockchip,grf property\n");
699 ret = of_property_read_string(node, "wifi_chip_type", &strings);
701 LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n", __func__);
702 strcpy(wifi_chip_type_string, "rkwifi");
704 strcpy(wifi_chip_type_string, strings);
706 LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
708 if(cpu_is_rk3036() || cpu_is_rk312x()){
709 /* ret = of_property_read_u32(node, "sdio_vref", &value);
711 LOG("%s: Can't get sdio vref.", __func__);
714 data->sdio_vol = value;*/
716 ret = of_property_read_u32(node, "sdio_vref", &value);
718 LOG("%s: Can't get sdio vref.", __func__);
721 data->sdio_vol = value;
724 if (of_find_property(node, "keep_wifi_power_on", NULL)) {
725 data->wifi_power_remain = true;
726 LOG("%s: wifi power will enabled while kernel starting and keep on.\n", __func__);
728 data->wifi_power_remain = false;
729 LOG("%s: enable wifi power control.\n", __func__);
732 if (of_find_property(node, "vref_ctrl_enable", NULL)) {
733 LOG("%s: enable wifi io reference voltage control.\n", __func__);
734 data->vref_ctrl_enble = true;
735 if (of_find_property(node, "vref_ctrl_gpio", NULL)) {
736 gpio = of_get_named_gpio_flags(node, "vref_ctrl_gpio", 0, &flags);
737 if (gpio_is_valid(gpio)){
738 data->vddio.io = gpio;
739 data->vddio.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
740 data->ioregulator.power_ctrl_by_pmu = false;
741 LOG("%s: get property: vref_ctrl_gpio = %d, flags = %d.\n", __func__, gpio, flags);
744 data->vref_ctrl_enble = false;
745 LOG("%s: vref_ctrl_gpio defined invalid, disable wifi io reference voltage control.\n", __func__);
748 data->ioregulator.power_ctrl_by_pmu = true;
749 ret = of_property_read_string(node, "vref_pmu_regulator", &strings);
751 LOG("%s: Can not read property: vref_pmu_regulator.\n", __func__);
752 data->vref_ctrl_enble = false;
753 data->ioregulator.power_ctrl_by_pmu = false;
755 LOG("%s: wifi io reference voltage controled by pmu(%s).\n", __func__, strings);
756 sprintf(data->ioregulator.pmu_regulator, "%s", strings);
758 ret = of_property_read_u32(node, "vref_pmu_enable_level", &value);
760 LOG("%s: Can not read property: vref_pmu_enable_level.\n", __func__);
761 data->vref_ctrl_enble = false;
762 data->ioregulator.power_ctrl_by_pmu = false;
764 LOG("%s: wifi io reference voltage controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
765 data->ioregulator.enable = value;
769 data->vref_ctrl_enble = false;
770 LOG("%s: disable wifi io reference voltage control.\n", __func__);
773 if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
774 data->mregulator.power_ctrl_by_pmu = true;
775 ret = of_property_read_string(node, "power_pmu_regulator", &strings);
777 LOG("%s: Can not read property: power_pmu_regulator.\n", __func__);
778 data->mregulator.power_ctrl_by_pmu = false;
780 LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
781 sprintf(data->mregulator.pmu_regulator, "%s", strings);
783 ret = of_property_read_u32(node, "power_pmu_enable_level", &value);
785 LOG("%s: Can not read property: power_pmu_enable_level.\n", __func__);
786 data->mregulator.power_ctrl_by_pmu = false;
788 LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
789 data->mregulator.enable = value;
792 data->mregulator.power_ctrl_by_pmu = false;
793 LOG("%s: wifi power controled by gpio.\n", __func__);
794 gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
795 if (gpio_is_valid(gpio)){
796 data->power_n.io = gpio;
797 data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
798 LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
799 } else data->power_n.io = -1;
800 gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
801 if (gpio_is_valid(gpio)){
802 data->reset_n.io = gpio;
803 data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
804 LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
805 } else data->reset_n.io = -1;
806 gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
807 if (gpio_is_valid(gpio)){
808 data->wifi_int_b.io = gpio;
809 data->wifi_int_b.enable = flags;
810 LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
811 } else data->wifi_int_b.io = -1;
818 #if defined(CONFIG_HAS_EARLYSUSPEND)
819 #include <linux/earlysuspend.h>
821 static void wlan_early_suspend(struct early_suspend *h)
823 LOG("%s :enter\n", __func__);
828 static void wlan_late_resume(struct early_suspend *h)
830 LOG("%s :enter\n", __func__);
835 struct early_suspend wlan_early_suspend {
836 .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
837 .suspend = wlan_early_suspend;
838 .resume = wlan_late_resume;
842 static void rfkill_wlan_early_suspend(void)
844 //LOG("%s :enter\n", __func__);
849 static void rfkill_wlan_later_resume(void)
851 //LOG("%s :enter\n", __func__);
856 static int rfkill_wlan_fb_event_notify(struct notifier_block *self,
857 unsigned long action, void *data)
860 struct fb_event *event = data;
861 int blank_mode = *((int *)event->data);
863 switch (blank_mode) {
864 case FB_BLANK_UNBLANK:
865 rfkill_wlan_later_resume();
867 case FB_BLANK_NORMAL:
868 rfkill_wlan_early_suspend();
871 rfkill_wlan_early_suspend();
878 static struct notifier_block rfkill_wlan_fb_notifier = {
879 .notifier_call = rfkill_wlan_fb_event_notify,
883 static int rfkill_wlan_probe(struct platform_device *pdev)
885 struct rfkill_wlan_data *rfkill;
886 struct rksdmmc_gpio_wifi_moudle *pdata = pdev->dev.platform_data;
889 LOG("Enter %s\n", __func__);
893 pdata = kzalloc(sizeof(struct rksdmmc_gpio_wifi_moudle), GFP_KERNEL);
897 ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
900 LOG("%s: No platform data specified\n", __func__);
907 rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
909 goto rfkill_alloc_fail;
911 rfkill->pdata = pdata;
914 LOG("%s: init gpio\n", __func__);
916 if (!pdata->mregulator.power_ctrl_by_pmu) {
917 ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
918 if (ret) goto fail_alloc;
920 ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
921 if (ret) goto fail_alloc;
924 wake_lock_init(&(rfkill->wlan_irq_wl), WAKE_LOCK_SUSPEND, "rfkill_wlan_wake");
926 // Turn off wifi power as default
927 if (gpio_is_valid(pdata->power_n.io))
929 gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable);
932 if (pdata->wifi_power_remain)
934 rockchip_wifi_power(1);
937 rockchip_wifi_voltage_select();
939 #if BCM_STATIC_MEMORY_SUPPORT
940 rockchip_init_wifi_mem();
943 #if defined(CONFIG_HAS_EARLYSUSPEND)
944 register_early_suspend(wlan_early_suspend);
947 fb_register_client(&rfkill_wlan_fb_notifier);
949 LOG("Exit %s\n", __func__);
963 static int rfkill_wlan_remove(struct platform_device *pdev)
965 struct rfkill_wlan_data *rfkill = platform_get_drvdata(pdev);
967 LOG("Enter %s\n", __func__);
969 wake_lock_destroy(&rfkill->wlan_irq_wl);
971 fb_unregister_client(&rfkill_wlan_fb_notifier);
973 if (gpio_is_valid(rfkill->pdata->power_n.io))
974 gpio_free(rfkill->pdata->power_n.io);
976 if (gpio_is_valid(rfkill->pdata->reset_n.io))
977 gpio_free(rfkill->pdata->reset_n.io);
979 // if (gpio_is_valid(rfkill->pdata->vddio.io))
980 // gpio_free(rfkill->pdata->vddio.io);
982 // if (gpio_is_valid(rfkill->pdata->bgf_int_b.io))
983 // gpio_free(rfkill->pdata->bgf_int_b.io);
985 // if (gpio_is_valid(rfkill->pdata->gps_sync.io))
986 // gpio_free(rfkill->pdata->gps_sync.io);
988 // if (gpio_is_valid(rfkill->pdata->ANTSEL2.io))
989 // gpio_free(rfkill->pdata->ANTSEL2.io);
991 // if (gpio_is_valid(rfkill->pdata->ANTSEL3.io))
992 // gpio_free(rfkill->pdata->ANTSEL3.io);
994 // if (gpio_is_valid(rfkill->pdata->GPS_LAN.io))
995 // gpio_free(rfkill->pdata->GPS_LAN.io);
1003 static int rfkill_wlan_suspend(struct platform_device *pdev, pm_message_t state)
1005 LOG("Enter %s\n", __func__);
1009 static int rfkill_wlan_resume(struct platform_device *pdev)
1011 LOG("Enter %s\n", __func__);
1016 static struct of_device_id wlan_platdata_of_match[] = {
1017 { .compatible = "wlan-platdata" },
1020 MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
1023 static struct platform_driver rfkill_wlan_driver = {
1024 .probe = rfkill_wlan_probe,
1025 .remove = rfkill_wlan_remove,
1026 .suspend = rfkill_wlan_suspend,
1027 .resume = rfkill_wlan_resume,
1029 .name = "wlan-platdata",
1030 .owner = THIS_MODULE,
1031 .of_match_table = of_match_ptr(wlan_platdata_of_match),
1035 static int __init rfkill_wlan_init(void)
1037 LOG("Enter %s\n", __func__);
1038 return platform_driver_register(&rfkill_wlan_driver);
1041 static void __exit rfkill_wlan_exit(void)
1043 LOG("Enter %s\n", __func__);
1044 platform_driver_unregister(&rfkill_wlan_driver);
1047 module_init(rfkill_wlan_init);
1048 module_exit(rfkill_wlan_exit);
1050 MODULE_DESCRIPTION("rock-chips rfkill for wifi v0.1");
1051 MODULE_AUTHOR("gwl@rock-chips.com");
1052 MODULE_LICENSE("GPL");