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, "rk901") == 0) {
107 } else if (strcmp(wifi_chip_type_string, "rk903") == 0) {
109 } else if (strcmp(wifi_chip_type_string, "ap6181") == 0) {
111 } else if (strcmp(wifi_chip_type_string, "ap6234") == 0) {
113 } else if (strcmp(wifi_chip_type_string, "ap6330") == 0) {
115 } else if (strcmp(wifi_chip_type_string, "ap6335") == 0) {
117 } else if (strcmp(wifi_chip_type_string, "ap6441") == 0) {
119 } else if (strcmp(wifi_chip_type_string, "ap6476") == 0) {
121 } else if (strcmp(wifi_chip_type_string, "ap6493") == 0) {
123 } else if (strcmp(wifi_chip_type_string, "rtl8188eu") == 0) {
124 type = WIFI_RTL8188EU;
125 } else if (strcmp(wifi_chip_type_string, "rtl8192du") == 0) {
126 type = WIFI_RTL8192DU;
127 } else if (strcmp(wifi_chip_type_string, "rtl8723as") == 0) {
128 type = WIFI_RTL8723AS;
129 } else if (strcmp(wifi_chip_type_string, "rtl8723bs_vq0") == 0) {
130 type = WIFI_RTL8723BS_VQ0;
131 } else if (strcmp(wifi_chip_type_string, "rtl8723bs") == 0) {
132 type = WIFI_RTL8723BS;
133 } else if (strcmp(wifi_chip_type_string, "rtl8723au") == 0) {
134 type = WIFI_RTL8723AU;
135 } else if (strcmp(wifi_chip_type_string, "rtl8723bu") == 0) {
136 type = WIFI_RTL8723BU;
137 } else if (strcmp(wifi_chip_type_string, "rtl8189es") == 0) {
138 type = WIFI_RTL8189ES;
139 } else if (strcmp(wifi_chip_type_string, "rtl8812au") == 0) {
140 type = WIFI_RTL8812AU;
141 } else if (strcmp(wifi_chip_type_string, "esp8089") == 0) {
148 EXPORT_SYMBOL(get_wifi_chip_type);
150 /***********************************************************
152 * Broadcom Wifi Static Memory
154 **********************************************************/
156 #define BCM_STATIC_MEMORY_SUPPORT 0
158 #define BCM_STATIC_MEMORY_SUPPORT 0
160 //===========================
161 #if BCM_STATIC_MEMORY_SUPPORT
162 #define PREALLOC_WLAN_SEC_NUM 4
163 #define PREALLOC_WLAN_BUF_NUM 160
164 #define PREALLOC_WLAN_SECTION_HEADER 0
165 #define WLAN_SKB_BUF_NUM 16
167 #define WLAN_SECTION_SIZE_0 (12 * 1024)
168 #define WLAN_SECTION_SIZE_1 (12 * 1024)
169 #define WLAN_SECTION_SIZE_2 (32 * 1024)
170 #define WLAN_SECTION_SIZE_3 (136* 1024)
171 #define WLAN_SECTION_SIZE_4 (4 * 1024)
172 #define WLAN_SECTION_SIZE_5 (64 * 1024)
173 #define WLAN_SECTION_SIZE_6 (4 * 1024)
174 #define WLAN_SECTION_SIZE_7 (4 * 1024)
176 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM+1];
178 struct wifi_mem_prealloc {
183 static struct wifi_mem_prealloc wifi_mem_array[8] = {
184 {NULL, (WLAN_SECTION_SIZE_0)},
185 {NULL, (WLAN_SECTION_SIZE_1)},
186 {NULL, (WLAN_SECTION_SIZE_2)},
187 {NULL, (WLAN_SECTION_SIZE_3)},
188 {NULL, (WLAN_SECTION_SIZE_4)},
189 {NULL, (WLAN_SECTION_SIZE_5)},
190 {NULL, (WLAN_SECTION_SIZE_6)},
191 {NULL, (WLAN_SECTION_SIZE_7)}
194 static int rockchip_init_wifi_mem(void)
199 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
200 wlan_static_skb[i] = dev_alloc_skb(
201 ((i < (WLAN_SKB_BUF_NUM / 2)) ? (PAGE_SIZE*1) : (PAGE_SIZE*2)));
203 if (!wlan_static_skb[i])
207 wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE*4));
208 if (!wlan_static_skb[i])
211 for (i = 0 ; i <= 7; i++) {
212 wifi_mem_array[i].mem_ptr =
213 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
215 if (!wifi_mem_array[i].mem_ptr)
221 pr_err("Failed to mem_alloc for WLAN\n");
222 for (j = 0 ; j < i ; j++)
223 kfree(wifi_mem_array[j].mem_ptr);
224 i = WLAN_SKB_BUF_NUM;
226 pr_err("Failed to skb_alloc for WLAN\n");
227 for (j = 0 ; j < i ; j++)
228 dev_kfree_skb(wlan_static_skb[j]);
229 dev_kfree_skb(wlan_static_skb[j]);
234 void *rockchip_mem_prealloc(int section, unsigned long size)
236 //printk("rockchip_mem_prealloc: section = %d, size = %d\n", section, size);
237 if (section == PREALLOC_WLAN_SEC_NUM)
238 return wlan_static_skb;
240 if ((section < 0) || (section > 7))
243 if (wifi_mem_array[section].size < size)
246 return wifi_mem_array[section].mem_ptr;
249 void *rockchip_mem_prealloc(int section, unsigned long size) { return NULL;}
251 EXPORT_SYMBOL(rockchip_mem_prealloc);
253 /**************************************************************************
255 * get wifi power state Func
257 *************************************************************************/
258 static int wifi_power_state = 0;
259 int rfkill_get_wifi_power_state(int *power, int *vref_ctrl_enable)
261 struct rfkill_wlan_data *mrfkill = g_rfkill;
263 if (mrfkill == NULL) {
264 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
268 if (mrfkill->pdata->vref_ctrl_enble)
269 *vref_ctrl_enable = 1;
270 *power = wifi_power_state;
275 /**************************************************************************
277 * wifi reference voltage control Func
279 *************************************************************************/
280 int rockchip_wifi_ref_voltage(int on)
282 struct rfkill_wlan_data *mrfkill = g_rfkill;
283 struct rksdmmc_gpio *vddio;
284 struct regulator *ldo = NULL;
288 LOG("%s: %d\n", __func__, on);
290 if (mrfkill == NULL) {
291 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
295 if (!mrfkill->pdata->vref_ctrl_enble) {
296 LOG("%s: wifi io reference voltage control is disabled.\n", __func__);
300 if (!rfkill_get_bt_power_state(&power, &toggle)) {
302 LOG("%s: wifi shouldn't control io reference voltage, BT is running!\n", __func__);
307 if (mrfkill->pdata->ioregulator.power_ctrl_by_pmu) {
310 int level = mrfkill->pdata->ioregulator.enable;
311 int voltage = 1000 * mrfkill->pdata->sdio_vol;
313 ldostr = mrfkill->pdata->ioregulator.pmu_regulator;
314 if (ldostr == NULL) {
315 LOG("%s: wifi io reference voltage set to be controled by pmic, but which one?\n", __func__);
318 ldo = regulator_get(NULL, ldostr);
319 if (ldo == NULL || IS_ERR(ldo)) {
320 LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
324 if(cpu_is_rk3036() || cpu_is_rk312x())
326 /*regulator_set_voltage(ldo, voltage, voltage);
327 LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
328 ret = regulator_enable(ldo);
329 LOG("wifi turn on io reference voltage.\n");*/
331 regulator_set_voltage(ldo, voltage, voltage);
332 LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
333 ret = regulator_enable(ldo);
334 LOG("wifi turn on io reference voltage.\n");
337 LOG("%s: %s disabled\n", __func__, ldostr);
338 while (regulator_is_enabled(ldo) > 0) {
339 ret = regulator_disable(ldo);
341 LOG("wifi shut off io reference voltage.\n");
347 vddio = &mrfkill->pdata->power_n;
350 if (gpio_is_valid(vddio->io)) {
351 gpio_set_value(vddio->io, vddio->enable);
355 LOG("wifi turn on io reference voltage.\n");
357 if (gpio_is_valid(vddio->io)) {
358 gpio_set_value(vddio->io, !(vddio->enable));
362 LOG("wifi shut off io reference voltage.\n");
369 /**************************************************************************
371 * Wifi Power Control Func
375 *************************************************************************/
376 int rockchip_wifi_power(int on)
378 struct rfkill_wlan_data *mrfkill = g_rfkill;
379 struct rksdmmc_gpio *poweron, *reset;
380 struct regulator *ldo = NULL;
384 LOG("%s: %d\n", __func__, on);
386 if (mrfkill == NULL) {
387 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
391 if (mrfkill->pdata->wifi_power_remain && power_set_time) {
392 LOG("%s: wifi power is setted to be remain on. skip anything to the power control", __func__);
394 } else power_set_time++;
396 if (!rfkill_get_bt_power_state(&power, &toggle)) {
397 if (toggle == true && power == 1) {
398 LOG("%s: wifi shouldn't control the power, it was enabled by BT!\n", __func__);
404 rockchip_wifi_ref_voltage(1);
406 if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
409 int level = mrfkill->pdata->mregulator.enable;
411 ldostr = mrfkill->pdata->mregulator.pmu_regulator;
412 if (ldostr == NULL) {
413 LOG("%s: wifi power set to be controled by pmic, but which one?\n", __func__);
416 ldo = regulator_get(NULL, ldostr);
417 if (ldo == NULL || IS_ERR(ldo)) {
418 LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
422 regulator_set_voltage(ldo, 3000000, 3000000);
423 LOG("%s: %s enabled\n", __func__, ldostr);
424 ret = regulator_enable(ldo);
425 wifi_power_state = 1;
426 LOG("wifi turn on power.\n");
428 LOG("%s: %s disabled\n", __func__, ldostr);
429 while (regulator_is_enabled(ldo) > 0) {
430 ret = regulator_disable(ldo);
432 wifi_power_state = 0;
433 LOG("wifi shut off power.\n");
439 poweron = &mrfkill->pdata->power_n;
440 reset = &mrfkill->pdata->reset_n;
443 if (gpio_is_valid(poweron->io)) {
444 gpio_set_value(poweron->io, poweron->enable);
448 if (gpio_is_valid(reset->io)) {
449 gpio_set_value(reset->io, reset->enable);
453 wifi_power_state = 1;
454 LOG("wifi turn on power. %d\n", poweron->io);
456 if (gpio_is_valid(poweron->io)) {
457 gpio_set_value(poweron->io, !(poweron->enable));
461 if (gpio_is_valid(reset->io)) {
462 gpio_set_value(reset->io, !(reset->enable));
465 wifi_power_state = 0;
466 LOG("wifi shut off power.\n");
471 rockchip_wifi_ref_voltage(0);
475 EXPORT_SYMBOL(rockchip_wifi_power);
477 /**************************************************************************
479 * Wifi Sdio Detect Func
481 *************************************************************************/
482 #include <linux/mmc/host.h>
483 extern int mmc_host_rescan(struct mmc_host *host, int val, int irq_type);
484 int rockchip_wifi_set_carddetect(int val)
487 chip = get_wifi_chip_type();
489 /* irq_type : 0, oob; 1, cap-sdio-irq */
490 if (!strncmp(wifi_chip_type_string, "ap", 2) ||
491 !strncmp(wifi_chip_type_string, "rk", 2))
496 return mmc_host_rescan(NULL, val, irq_type);//NULL => SDIO host
498 EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
500 /**************************************************************************
502 * Wifi Get Interrupt irq Func
504 *************************************************************************/
505 int rockchip_wifi_get_oob_irq(void)
507 struct rfkill_wlan_data *mrfkill = g_rfkill;
508 struct rksdmmc_gpio *wifi_int_irq;
510 LOG("%s: Enter\n", __func__);
512 if (mrfkill == NULL) {
513 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
517 wifi_int_irq = &mrfkill->pdata->wifi_int_b;
518 if (gpio_is_valid(wifi_int_irq->io)) {
519 return gpio_to_irq(wifi_int_irq->io);
520 //return wifi_int_irq->io;
522 LOG("%s: wifi OOB pin isn't defined.\n", __func__);
527 EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
529 /**************************************************************************
533 *************************************************************************/
534 int rockchip_wifi_reset(int on)
538 EXPORT_SYMBOL(rockchip_wifi_reset);
540 /**************************************************************************
542 * Wifi MAC custom Func
544 *************************************************************************/
545 #include <linux/etherdevice.h>
546 u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
547 extern char GetSNSectorInfo(char * pbuf);
548 int rockchip_wifi_mac_addr(unsigned char *buf)
550 char mac_buf[20] = {0};
551 LOG("%s: enter.\n", __func__);
554 if(is_zero_ether_addr(wifi_custom_mac_addr)) {
556 char *tempBuf = kmalloc(512, GFP_KERNEL);
558 GetSNSectorInfo(tempBuf);
559 for (i = 445; i <= 450; i++)
560 wifi_custom_mac_addr[i-445] = tempBuf[i];
567 sprintf(mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x",wifi_custom_mac_addr[0],wifi_custom_mac_addr[1],
568 wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
569 LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
571 if (is_valid_ether_addr(wifi_custom_mac_addr)) {
572 if (2 == (wifi_custom_mac_addr[0] & 0x0F)) {
573 LOG("This mac address come into conflict with the address of direct, ignored...\n");
577 LOG("This mac address is not valid, ignored...\n");
581 memcpy(buf, wifi_custom_mac_addr, 6);
585 EXPORT_SYMBOL(rockchip_wifi_mac_addr);
587 /**************************************************************************
589 * wifi get country code func
591 *************************************************************************/
592 struct cntry_locales_custom {
593 char iso_abbrev[4]; /* ISO 3166-1 country abbreviation */
594 char custom_locale[4]; /* Custom firmware locale */
595 int custom_locale_rev; /* Custom local revisin default -1 */
598 static struct cntry_locales_custom country_cloc;
600 void *rockchip_wifi_country_code(char *ccode)
602 struct cntry_locales_custom *mcloc;
604 LOG("%s: set country code [%s]\n", __func__, ccode);
605 mcloc = &country_cloc;
606 memcpy(mcloc->custom_locale, ccode, 4);
607 mcloc->custom_locale_rev = 0;
611 EXPORT_SYMBOL(rockchip_wifi_country_code);
612 /**************************************************************************/
614 #define RK3368_GRF_IO_VSEL 0x900
615 static int rockchip_wifi_voltage_select(void)
617 struct rfkill_wlan_data *mrfkill = g_rfkill;
620 if (mrfkill == NULL) {
621 LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
625 voltage = mrfkill->pdata->sdio_vol;
626 if (cpu_is_rk3288()) {
627 if (voltage > 2700 && voltage < 3500) {
628 writel_relaxed(0x00100000, RK_GRF_VIRT+0x380); //3.3
629 LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
630 } else if (voltage > 1500 && voltage < 1950) {
631 writel_relaxed(0x00100010, RK_GRF_VIRT+0x380); //1.8
632 LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
634 LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
637 } else if(cpu_is_rk3036() || cpu_is_rk312x()) {
639 #ifdef CONFIG_MFD_SYSCON
640 if (voltage > 2700 && voltage < 3500) {
641 regmap_write(mrfkill->pdata->grf, RK3368_GRF_IO_VSEL, ((1<<3)<<16)|(0<<3)); //3.3
642 LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
643 } else if (voltage > 1500 && voltage < 1950) {
644 regmap_write(mrfkill->pdata->grf, RK3368_GRF_IO_VSEL, ((1<<3)<<16)|(1<<3)); //1.8
645 LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
649 LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
657 static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char* prefix, const char* name)
659 if (gpio_is_valid(gpio->io)) {
661 sprintf(gpio->name, "%s_%s", prefix, name);
662 ret = gpio_request(gpio->io, gpio->name);
664 LOG("Failed to get %s gpio.\n", gpio->name);
673 static int wlan_platdata_parse_dt(struct device *dev,
674 struct rksdmmc_gpio_wifi_moudle *data)
676 struct device_node *node = dev->of_node;
680 enum of_gpio_flags flags;
685 memset(data, 0, sizeof(*data));
687 #ifdef CONFIG_MFD_SYSCON
688 data->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");
689 if (IS_ERR(data->grf)) {
690 LOG("can't find rockchip,grf property\n");
695 ret = of_property_read_string(node, "wifi_chip_type", &strings);
697 LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n", __func__);
698 strcpy(wifi_chip_type_string, "rkwifi");
700 strcpy(wifi_chip_type_string, strings);
702 LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
704 if(cpu_is_rk3036() || cpu_is_rk312x()){
705 /* ret = of_property_read_u32(node, "sdio_vref", &value);
707 LOG("%s: Can't get sdio vref.", __func__);
710 data->sdio_vol = value;*/
712 ret = of_property_read_u32(node, "sdio_vref", &value);
714 LOG("%s: Can't get sdio vref.", __func__);
717 data->sdio_vol = value;
720 if (of_find_property(node, "keep_wifi_power_on", NULL)) {
721 data->wifi_power_remain = true;
722 LOG("%s: wifi power will enabled while kernel starting and keep on.\n", __func__);
724 data->wifi_power_remain = false;
725 LOG("%s: enable wifi power control.\n", __func__);
728 if (of_find_property(node, "vref_ctrl_enable", NULL)) {
729 LOG("%s: enable wifi io reference voltage control.\n", __func__);
730 data->vref_ctrl_enble = true;
731 if (of_find_property(node, "vref_ctrl_gpio", NULL)) {
732 gpio = of_get_named_gpio_flags(node, "vref_ctrl_gpio", 0, &flags);
733 if (gpio_is_valid(gpio)){
734 data->vddio.io = gpio;
735 data->vddio.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
736 data->ioregulator.power_ctrl_by_pmu = false;
737 LOG("%s: get property: vref_ctrl_gpio = %d, flags = %d.\n", __func__, gpio, flags);
740 data->vref_ctrl_enble = false;
741 LOG("%s: vref_ctrl_gpio defined invalid, disable wifi io reference voltage control.\n", __func__);
744 data->ioregulator.power_ctrl_by_pmu = true;
745 ret = of_property_read_string(node, "vref_pmu_regulator", &strings);
747 LOG("%s: Can not read property: vref_pmu_regulator.\n", __func__);
748 data->vref_ctrl_enble = false;
749 data->ioregulator.power_ctrl_by_pmu = false;
751 LOG("%s: wifi io reference voltage controled by pmu(%s).\n", __func__, strings);
752 sprintf(data->ioregulator.pmu_regulator, "%s", strings);
754 ret = of_property_read_u32(node, "vref_pmu_enable_level", &value);
756 LOG("%s: Can not read property: vref_pmu_enable_level.\n", __func__);
757 data->vref_ctrl_enble = false;
758 data->ioregulator.power_ctrl_by_pmu = false;
760 LOG("%s: wifi io reference voltage controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
761 data->ioregulator.enable = value;
765 data->vref_ctrl_enble = false;
766 LOG("%s: disable wifi io reference voltage control.\n", __func__);
769 if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
770 data->mregulator.power_ctrl_by_pmu = true;
771 ret = of_property_read_string(node, "power_pmu_regulator", &strings);
773 LOG("%s: Can not read property: power_pmu_regulator.\n", __func__);
774 data->mregulator.power_ctrl_by_pmu = false;
776 LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
777 sprintf(data->mregulator.pmu_regulator, "%s", strings);
779 ret = of_property_read_u32(node, "power_pmu_enable_level", &value);
781 LOG("%s: Can not read property: power_pmu_enable_level.\n", __func__);
782 data->mregulator.power_ctrl_by_pmu = false;
784 LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
785 data->mregulator.enable = value;
788 data->mregulator.power_ctrl_by_pmu = false;
789 LOG("%s: wifi power controled by gpio.\n", __func__);
790 gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
791 if (gpio_is_valid(gpio)){
792 data->power_n.io = gpio;
793 data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
794 LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
795 } else data->power_n.io = -1;
796 gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
797 if (gpio_is_valid(gpio)){
798 data->reset_n.io = gpio;
799 data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
800 LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
801 } else data->reset_n.io = -1;
802 gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
803 if (gpio_is_valid(gpio)){
804 data->wifi_int_b.io = gpio;
805 data->wifi_int_b.enable = flags;
806 LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
807 } else data->wifi_int_b.io = -1;
814 #if defined(CONFIG_HAS_EARLYSUSPEND)
815 #include <linux/earlysuspend.h>
817 static void wlan_early_suspend(struct early_suspend *h)
819 LOG("%s :enter\n", __func__);
824 static void wlan_late_resume(struct early_suspend *h)
826 LOG("%s :enter\n", __func__);
831 struct early_suspend wlan_early_suspend {
832 .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
833 .suspend = wlan_early_suspend;
834 .resume = wlan_late_resume;
838 static void rfkill_wlan_early_suspend(void)
840 //LOG("%s :enter\n", __func__);
845 static void rfkill_wlan_later_resume(void)
847 //LOG("%s :enter\n", __func__);
852 static int rfkill_wlan_fb_event_notify(struct notifier_block *self,
853 unsigned long action, void *data)
856 struct fb_event *event = data;
857 int blank_mode = *((int *)event->data);
859 switch (blank_mode) {
860 case FB_BLANK_UNBLANK:
861 rfkill_wlan_later_resume();
863 case FB_BLANK_NORMAL:
864 rfkill_wlan_early_suspend();
867 rfkill_wlan_early_suspend();
874 static struct notifier_block rfkill_wlan_fb_notifier = {
875 .notifier_call = rfkill_wlan_fb_event_notify,
879 static int rfkill_wlan_probe(struct platform_device *pdev)
881 struct rfkill_wlan_data *rfkill;
882 struct rksdmmc_gpio_wifi_moudle *pdata = pdev->dev.platform_data;
885 LOG("Enter %s\n", __func__);
889 pdata = kzalloc(sizeof(struct rksdmmc_gpio_wifi_moudle), GFP_KERNEL);
893 ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
896 LOG("%s: No platform data specified\n", __func__);
903 rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
905 goto rfkill_alloc_fail;
907 rfkill->pdata = pdata;
910 LOG("%s: init gpio\n", __func__);
912 if (!pdata->mregulator.power_ctrl_by_pmu) {
913 ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
914 if (ret) goto fail_alloc;
916 ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
917 if (ret) goto fail_alloc;
920 wake_lock_init(&(rfkill->wlan_irq_wl), WAKE_LOCK_SUSPEND, "rfkill_wlan_wake");
922 // Turn off wifi power as default
923 if (gpio_is_valid(pdata->power_n.io))
925 gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable);
928 if (pdata->wifi_power_remain)
930 rockchip_wifi_power(1);
933 rockchip_wifi_voltage_select();
935 #if BCM_STATIC_MEMORY_SUPPORT
936 rockchip_init_wifi_mem();
939 #if defined(CONFIG_HAS_EARLYSUSPEND)
940 register_early_suspend(wlan_early_suspend);
943 fb_register_client(&rfkill_wlan_fb_notifier);
945 LOG("Exit %s\n", __func__);
959 static int rfkill_wlan_remove(struct platform_device *pdev)
961 struct rfkill_wlan_data *rfkill = platform_get_drvdata(pdev);
963 LOG("Enter %s\n", __func__);
965 wake_lock_destroy(&rfkill->wlan_irq_wl);
967 fb_unregister_client(&rfkill_wlan_fb_notifier);
969 if (gpio_is_valid(rfkill->pdata->power_n.io))
970 gpio_free(rfkill->pdata->power_n.io);
972 if (gpio_is_valid(rfkill->pdata->reset_n.io))
973 gpio_free(rfkill->pdata->reset_n.io);
975 // if (gpio_is_valid(rfkill->pdata->vddio.io))
976 // gpio_free(rfkill->pdata->vddio.io);
978 // if (gpio_is_valid(rfkill->pdata->bgf_int_b.io))
979 // gpio_free(rfkill->pdata->bgf_int_b.io);
981 // if (gpio_is_valid(rfkill->pdata->gps_sync.io))
982 // gpio_free(rfkill->pdata->gps_sync.io);
984 // if (gpio_is_valid(rfkill->pdata->ANTSEL2.io))
985 // gpio_free(rfkill->pdata->ANTSEL2.io);
987 // if (gpio_is_valid(rfkill->pdata->ANTSEL3.io))
988 // gpio_free(rfkill->pdata->ANTSEL3.io);
990 // if (gpio_is_valid(rfkill->pdata->GPS_LAN.io))
991 // gpio_free(rfkill->pdata->GPS_LAN.io);
999 static int rfkill_wlan_suspend(struct platform_device *pdev, pm_message_t state)
1001 LOG("Enter %s\n", __func__);
1005 static int rfkill_wlan_resume(struct platform_device *pdev)
1007 LOG("Enter %s\n", __func__);
1012 static struct of_device_id wlan_platdata_of_match[] = {
1013 { .compatible = "wlan-platdata" },
1016 MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
1019 static struct platform_driver rfkill_wlan_driver = {
1020 .probe = rfkill_wlan_probe,
1021 .remove = rfkill_wlan_remove,
1022 .suspend = rfkill_wlan_suspend,
1023 .resume = rfkill_wlan_resume,
1025 .name = "wlan-platdata",
1026 .owner = THIS_MODULE,
1027 .of_match_table = of_match_ptr(wlan_platdata_of_match),
1031 static int __init rfkill_wlan_init(void)
1033 LOG("Enter %s\n", __func__);
1034 return platform_driver_register(&rfkill_wlan_driver);
1037 static void __exit rfkill_wlan_exit(void)
1039 LOG("Enter %s\n", __func__);
1040 platform_driver_unregister(&rfkill_wlan_driver);
1043 module_init(rfkill_wlan_init);
1044 module_exit(rfkill_wlan_exit);
1046 MODULE_DESCRIPTION("rock-chips rfkill for wifi v0.1");
1047 MODULE_AUTHOR("gwl@rock-chips.com");
1048 MODULE_LICENSE("GPL");