support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / net / rfkill / rfkill-wlan.c
index 2253ad87d7ffcc64867451f5d068bd38e5dcd707..ff5dd1620ee66677546b6740888d6edcf82a4ca2 100755 (executable)
@@ -23,8 +23,8 @@
 #include <asm/gpio.h>
 #include <linux/regulator/consumer.h>
 #include <linux/delay.h>
-#include <linux/rfkill-rk.h>
 #include <linux/rfkill-wlan.h>
+#include <linux/rfkill-bt.h>
 #include <linux/wakelock.h>
 #include <linux/interrupt.h>
 #include <asm/irq.h>
 #include <linux/proc_fs.h>
 #include <linux/uaccess.h>
 #include <linux/gpio.h>
+#include <linux/rockchip/iomap.h>
+#include <dt-bindings/gpio/gpio.h>
+#include <linux/skbuff.h>
+#include <linux/rockchip/cpu.h>
+#include <linux/fb.h>
 #ifdef CONFIG_OF
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -52,6 +57,7 @@ struct rfkill_wlan_data {
 };
 
 static struct rfkill_wlan_data *g_rfkill = NULL;
+static int power_set_time = 0;
 
 static const char wlan_name[] = 
 #if defined (CONFIG_BCM4330)
@@ -87,61 +93,126 @@ static const char wlan_name[] =
 #endif
 ;
 
+static char wifi_chip_type_string[64];
+int get_wifi_chip_type(void)
+{
+    int type;
+    if (strcmp(wifi_chip_type_string, "ap6210") == 0) {
+        type = WIFI_AP6210;
+    } else if (strcmp(wifi_chip_type_string, "rk901") == 0) {
+        type = WIFI_RK901;    
+    } else if (strcmp(wifi_chip_type_string, "rk903") == 0) {
+        type = WIFI_RK903;  
+    } else if (strcmp(wifi_chip_type_string, "ap6181") == 0) {
+        type = WIFI_AP6181;
+    } else if (strcmp(wifi_chip_type_string, "ap6234") == 0) {
+        type = WIFI_AP6234;                            
+    } else if (strcmp(wifi_chip_type_string, "ap6330") == 0) {
+        type = WIFI_AP6330;
+    } else if (strcmp(wifi_chip_type_string, "ap6335") == 0) {
+        type = WIFI_AP6335;
+    } else if (strcmp(wifi_chip_type_string, "ap6441") == 0) {
+        type = WIFI_AP6441;
+    } else if (strcmp(wifi_chip_type_string, "ap6476") == 0) {
+        type = WIFI_AP6476;    
+    } else if (strcmp(wifi_chip_type_string, "ap6493") == 0) {
+        type = WIFI_AP6493;                    
+    } else if (strcmp(wifi_chip_type_string, "rtl8188eu") == 0) {
+        type = WIFI_RTL8188EU;
+    } else if (strcmp(wifi_chip_type_string, "rtl8192du") == 0) {
+        type = WIFI_RTL8192DU;
+    } else if (strcmp(wifi_chip_type_string, "rtl8723as") == 0) {
+        type = WIFI_RTL8723AS;        
+    } else if (strcmp(wifi_chip_type_string, "rtl8723bs_vq0") == 0) {
+        type = WIFI_RTL8723BS_VQ0;        
+    } else if (strcmp(wifi_chip_type_string, "rtl8723bs") == 0) {
+        type = WIFI_RTL8723BS;
+    } else if (strcmp(wifi_chip_type_string, "rtl8723au") == 0) {
+        type = WIFI_RTL8723AU;        
+    } else if (strcmp(wifi_chip_type_string, "rtl8723bu") == 0) {
+        type = WIFI_RTL8723BU;
+    } else if (strcmp(wifi_chip_type_string, "rtl8189es") == 0) {
+        type = WIFI_RTL8189ES;
+    } else if (strcmp(wifi_chip_type_string, "rtl8812au") == 0) {
+        type = WIFI_RTL8812AU;                        
+    } else if (strcmp(wifi_chip_type_string, "esp8089") == 0) {
+        type = WIFI_ESP8089;
+    } else {
+        type = WIFI_AP6210;
+    }
+    return type;
+}
+EXPORT_SYMBOL(get_wifi_chip_type);
+
 /***********************************************************
  * 
  * Broadcom Wifi Static Memory
  * 
  **********************************************************/
+#if 0//def CONFIG_RKWIFI
+#define BCM_STATIC_MEMORY_SUPPORT 1
+#else
 #define BCM_STATIC_MEMORY_SUPPORT 0
+#endif
 //===========================
 #if BCM_STATIC_MEMORY_SUPPORT
 #define PREALLOC_WLAN_SEC_NUM           4
 #define PREALLOC_WLAN_BUF_NUM           160
-#define PREALLOC_WLAN_SECTION_HEADER    24
+#define PREALLOC_WLAN_SECTION_HEADER    0
 #define WLAN_SKB_BUF_NUM        16
 
-#define WLAN_SECTION_SIZE_0     (PREALLOC_WLAN_BUF_NUM * 128)
-#define WLAN_SECTION_SIZE_1     (PREALLOC_WLAN_BUF_NUM * 128)
-#define WLAN_SECTION_SIZE_2     (PREALLOC_WLAN_BUF_NUM * 512)
-#define WLAN_SECTION_SIZE_3     (PREALLOC_WLAN_BUF_NUM * 1024)
-#define WLAN_SECTION_SIZE_5     (PREALLOC_WLAN_BUF_NUM * 512)
+#define WLAN_SECTION_SIZE_0     (12 * 1024)
+#define WLAN_SECTION_SIZE_1     (12 * 1024)
+#define WLAN_SECTION_SIZE_2     (32 * 1024)
+#define WLAN_SECTION_SIZE_3     (136* 1024)
+#define WLAN_SECTION_SIZE_4     (4  * 1024)
+#define WLAN_SECTION_SIZE_5     (64 * 1024)
+#define WLAN_SECTION_SIZE_6     (4  * 1024)
+#define WLAN_SECTION_SIZE_7     (4  * 1024)
 
-static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
+static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM+1];
 
 struct wifi_mem_prealloc {
     void *mem_ptr;
     unsigned long size;
 };
 
-static struct wifi_mem_prealloc wifi_mem_array[5] = {
-    {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
-    {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
-    {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
-    {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)},
-    {NULL, (WLAN_SECTION_SIZE_5 + PREALLOC_WLAN_SECTION_HEADER)}
+static struct wifi_mem_prealloc wifi_mem_array[8] = {
+    {NULL, (WLAN_SECTION_SIZE_0)},
+    {NULL, (WLAN_SECTION_SIZE_1)},
+    {NULL, (WLAN_SECTION_SIZE_2)},
+    {NULL, (WLAN_SECTION_SIZE_3)},
+    {NULL, (WLAN_SECTION_SIZE_4)},
+    {NULL, (WLAN_SECTION_SIZE_5)},
+    {NULL, (WLAN_SECTION_SIZE_6)},
+    {NULL, (WLAN_SECTION_SIZE_7)}
 };
 
-static int __init rk29sdk_init_wifi_mem(void)
+static int rockchip_init_wifi_mem(void)
 {
     int i;
     int j;
 
     for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
         wlan_static_skb[i] = dev_alloc_skb(
-               ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
+               ((i < (WLAN_SKB_BUF_NUM / 2)) ? (PAGE_SIZE*1) : (PAGE_SIZE*2)));
 
         if (!wlan_static_skb[i])
             goto err_skb_alloc;
     }
 
-    for (i = 0 ; i < 5; i++) {
+    wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE*4));
+    if (!wlan_static_skb[i])
+        goto err_skb_alloc;
+
+    for (i = 0 ; i <= 7; i++) {
         wifi_mem_array[i].mem_ptr =
                kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
 
         if (!wifi_mem_array[i].mem_ptr)
             goto err_mem_alloc;
-        }
-        return 0;
+    }
+    return 0;
 
 err_mem_alloc:
     pr_err("Failed to mem_alloc for WLAN\n");
@@ -152,30 +223,145 @@ err_skb_alloc:
     pr_err("Failed to skb_alloc for WLAN\n");
     for (j = 0 ; j < i ; j++)
         dev_kfree_skb(wlan_static_skb[j]);
+    dev_kfree_skb(wlan_static_skb[j]);
 
     return -ENOMEM;
 }
 
-void *rk29sdk_mem_prealloc(int section, unsigned long size)
+void *rockchip_mem_prealloc(int section, unsigned long size)
 {
+    //printk("rockchip_mem_prealloc: section = %d, size = %d\n", section, size);
     if (section == PREALLOC_WLAN_SEC_NUM)
         return wlan_static_skb;
 
-    if ((section < 0) || (section > 5))
+    if ((section < 0) || (section > 7))
         return NULL;
 
-    if (section == 5)
-        return wifi_mem_array[4].mem_ptr;
-
     if (wifi_mem_array[section].size < size)
         return NULL;
 
     return wifi_mem_array[section].mem_ptr;
 }
 #else
-void *rk29sdk_mem_prealloc(int section, unsigned long size) { return NULL;}
+void *rockchip_mem_prealloc(int section, unsigned long size) { return NULL;}
 #endif
-EXPORT_SYMBOL(rk29sdk_mem_prealloc);
+EXPORT_SYMBOL(rockchip_mem_prealloc);
+
+/**************************************************************************
+ *
+ * get wifi power state Func
+ *
+ *************************************************************************/
+static int wifi_power_state = 0;
+int rfkill_get_wifi_power_state(int *power, int *vref_ctrl_enable)
+{
+    struct rfkill_wlan_data *mrfkill = g_rfkill;
+
+    if (mrfkill == NULL) {
+        LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
+        return -1;
+    }
+
+    if (mrfkill->pdata->vref_ctrl_enble)
+        *vref_ctrl_enable = 1;
+    *power = wifi_power_state;
+
+    return 0;
+}
+
+/**************************************************************************
+ *
+ * wifi reference voltage control Func
+ *
+ *************************************************************************/
+int rockchip_wifi_ref_voltage(int on)
+{
+    struct rfkill_wlan_data *mrfkill = g_rfkill;
+    struct rksdmmc_gpio *vddio;
+    struct regulator *ldo = NULL;
+    int power = 0;
+    bool toggle = false;
+
+    LOG("%s: %d\n", __func__, on);
+
+    if (mrfkill == NULL) {
+        LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
+        return -1;
+    }
+
+    if (!mrfkill->pdata->vref_ctrl_enble) {
+        LOG("%s: wifi io reference voltage control is disabled.\n", __func__);
+        return 0;
+    }
+
+    if (!rfkill_get_bt_power_state(&power, &toggle)) {
+        if (power == 1) {
+            LOG("%s: wifi shouldn't control io reference voltage, BT is running!\n", __func__);
+            return 0;
+        }
+    }
+
+    if (mrfkill->pdata->ioregulator.power_ctrl_by_pmu) {
+        int ret = -1;
+        char *ldostr;
+        int level = mrfkill->pdata->ioregulator.enable;
+               int voltage = 1000 * mrfkill->pdata->sdio_vol;
+
+        ldostr = mrfkill->pdata->ioregulator.pmu_regulator;
+        if (ldostr == NULL) {
+            LOG("%s: wifi io reference voltage set to be controled by pmic, but which one?\n", __func__);
+            return -1;
+        }
+        ldo = regulator_get(NULL, ldostr);
+        if (ldo == NULL || IS_ERR(ldo)) {
+            LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
+            return -1;
+        } else {
+            if (on == level) {
+               if(cpu_is_rk3036() || cpu_is_rk312x())
+               {
+                                       /*regulator_set_voltage(ldo, voltage, voltage);
+                                       LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
+                                       ret = regulator_enable(ldo);
+                                       LOG("wifi turn on io reference voltage.\n");*/
+               }else{
+                                       regulator_set_voltage(ldo, voltage, voltage);
+                                       LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
+                                       ret = regulator_enable(ldo);
+                                       LOG("wifi turn on io reference voltage.\n");
+               }
+            } else {
+                LOG("%s: %s disabled\n", __func__, ldostr);
+                while (regulator_is_enabled(ldo) > 0) {
+                    ret = regulator_disable(ldo);
+                }
+                LOG("wifi shut off io reference voltage.\n");
+            }
+            regulator_put(ldo);
+            msleep(100);
+        }
+    } else {
+        vddio = &mrfkill->pdata->power_n;
+
+        if (on){
+            if (gpio_is_valid(vddio->io)) {
+                gpio_set_value(vddio->io, vddio->enable);
+                msleep(100);
+            }
+
+            LOG("wifi turn on io reference voltage.\n");
+        }else{
+            if (gpio_is_valid(vddio->io)) {
+                gpio_set_value(vddio->io, !(vddio->enable));
+                msleep(100);
+            }
+
+            LOG("wifi shut off io reference voltage.\n");
+        }
+    }
+
+       return 0;
+}
 
 /**************************************************************************
  *
@@ -184,11 +370,13 @@ EXPORT_SYMBOL(rk29sdk_mem_prealloc);
  * 1 -> power on
  *
  *************************************************************************/
-int rk29sdk_wifi_power(int on)
+int rockchip_wifi_power(int on)
 {
        struct rfkill_wlan_data *mrfkill = g_rfkill;
     struct rksdmmc_gpio *poweron, *reset;
     struct regulator *ldo = NULL;
+    int power = 0;
+    bool toggle = false;
 
     LOG("%s: %d\n", __func__, on);
 
@@ -197,9 +385,24 @@ int rk29sdk_wifi_power(int on)
         return -1;
     }
 
+    if (mrfkill->pdata->wifi_power_remain && power_set_time) {
+        LOG("%s: wifi power is setted to be remain on. skip anything to the power control", __func__);
+        return 0;
+    } else power_set_time++;
+
+    if (!rfkill_get_bt_power_state(&power, &toggle)) {
+        if (toggle == true && power == 1) {
+            LOG("%s: wifi shouldn't control the power, it was enabled by BT!\n", __func__);
+            return 0;
+        }
+    }
+    
+    if (on)
+        rockchip_wifi_ref_voltage(1);
+
     if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
-        char *ldostr;
         int ret = -1;
+        char *ldostr;
         int level = mrfkill->pdata->mregulator.enable;
 
         ldostr = mrfkill->pdata->mregulator.pmu_regulator;
@@ -208,27 +411,26 @@ int rk29sdk_wifi_power(int on)
             return -1;
         }
         ldo = regulator_get(NULL, ldostr);
-        if (ldo == NULL) {
+        if (ldo == NULL || IS_ERR(ldo)) {
             LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
+            return -1;
         } else {
                        if (on == level) {
                                regulator_set_voltage(ldo, 3000000, 3000000);
                            LOG("%s: %s enabled\n", __func__, ldostr);
                                ret = regulator_enable(ldo);
-                               if(ret != 0){
-                                   LOG("%s: faild to enable %s\n", __func__, ldostr);
-                               }
+                wifi_power_state = 1;
                            LOG("wifi turn on power.\n");
             } else {
-                           LOG("wifi shut off power.\n");
                                LOG("%s: %s disabled\n", __func__, ldostr);
-                               ret = regulator_disable(ldo);
-                               if(ret != 0){
-                                       LOG("%s: faild to disable %s\n", __func__, ldostr);
-                               }
+                while (regulator_is_enabled(ldo) > 0) {
+                                   ret = regulator_disable(ldo);
+                }
+                wifi_power_state = 0;
+                           LOG("wifi shut off power.\n");
                        }
                        regulator_put(ldo);
-                       mdelay(100);
+                       msleep(100);
                }
     } else {
                poweron = &mrfkill->pdata->power_n;
@@ -236,43 +438,101 @@ int rk29sdk_wifi_power(int on)
 
                if (on){
                        if (gpio_is_valid(poweron->io)) {
-                               gpio_set_value(poweron->io, !(poweron->enable));
+                               gpio_set_value(poweron->io, poweron->enable);
+                               msleep(100);
                        }
-                       mdelay(100);
 
                        if (gpio_is_valid(reset->io)) {
-                               gpio_set_value(reset->io, !(reset->enable));
+                               gpio_set_value(reset->io, reset->enable);
+                               msleep(100);
                        }
-                       mdelay(100);
+
+            wifi_power_state = 1;
                        LOG("wifi turn on power. %d\n", poweron->io);
                }else{
                        if (gpio_is_valid(poweron->io)) {
-                               gpio_set_value(poweron->io, poweron->enable);
+                               gpio_set_value(poweron->io, !(poweron->enable));
+                               msleep(100);
                        }
 
-                       mdelay(100);
                        if (gpio_is_valid(reset->io)) {
-                               gpio_set_value(reset->io, reset->enable);
+                               gpio_set_value(reset->io, !(reset->enable));
                        }
 
+            wifi_power_state = 0;
                        LOG("wifi shut off power.\n");
                }
     }
 
+    if (!on)
+        rockchip_wifi_ref_voltage(0);
+
     return 0;
 }
-EXPORT_SYMBOL(rk29sdk_wifi_power);
+EXPORT_SYMBOL(rockchip_wifi_power);
+
+/**************************************************************************
+ *
+ * Wifi Sdio Detect Func
+ *
+ *************************************************************************/
+#include <linux/mmc/host.h>
+extern int mmc_host_rescan(struct mmc_host *host, int val, int irq_type);
+int rockchip_wifi_set_carddetect(int val)
+{
+       int chip, irq_type;
+       chip = get_wifi_chip_type();
+
+       /*  irq_type : 0, oob; 1, cap-sdio-irq */
+       if (!strncmp(wifi_chip_type_string, "ap", 2) ||
+               !strncmp(wifi_chip_type_string, "rk", 2))
+               irq_type = 0;
+       else
+               irq_type = 1;
+
+       return mmc_host_rescan(NULL, val, irq_type);//NULL => SDIO host
+}
+EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
+
+/**************************************************************************
+ *
+ * Wifi Get Interrupt irq Func
+ *
+ *************************************************************************/
+int rockchip_wifi_get_oob_irq(void)
+{
+    struct rfkill_wlan_data *mrfkill = g_rfkill;
+    struct rksdmmc_gpio *wifi_int_irq;
+
+    LOG("%s: Enter\n", __func__);
+
+    if (mrfkill == NULL) {
+        LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
+        return -1;
+    }
+    
+    wifi_int_irq = &mrfkill->pdata->wifi_int_b;
+    if (gpio_is_valid(wifi_int_irq->io)) {
+        return gpio_to_irq(wifi_int_irq->io);
+        //return wifi_int_irq->io;
+    } else {
+        LOG("%s: wifi OOB pin isn't defined.\n", __func__);
+    }
+    
+    return -1;
+}
+EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
 
 /**************************************************************************
  *
  * Wifi Reset Func
  *
  *************************************************************************/
-int rk29sdk_wifi_reset(int on)
+int rockchip_wifi_reset(int on)
 {
     return 0;
 }
-EXPORT_SYMBOL(rk29sdk_wifi_reset);
+EXPORT_SYMBOL(rockchip_wifi_reset);
 
 /**************************************************************************
  *
@@ -282,7 +542,7 @@ EXPORT_SYMBOL(rk29sdk_wifi_reset);
 #include <linux/etherdevice.h>
 u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
 extern char GetSNSectorInfo(char * pbuf);
-int rk29sdk_wifi_mac_addr(unsigned char *buf)
+int rockchip_wifi_mac_addr(unsigned char *buf)
 {
     char mac_buf[20] = {0};
     LOG("%s: enter.\n", __func__);
@@ -293,8 +553,8 @@ int rk29sdk_wifi_mac_addr(unsigned char *buf)
         char *tempBuf = kmalloc(512, GFP_KERNEL);
         if(tempBuf) {
             GetSNSectorInfo(tempBuf);
-            for (i = 506; i <= 511; i++)
-                wifi_custom_mac_addr[i-506] = tempBuf[i];
+            for (i = 445; i <= 450; i++)
+                wifi_custom_mac_addr[i-445] = tempBuf[i];
             kfree(tempBuf);
         } else {
             return -1;
@@ -315,14 +575,11 @@ int rk29sdk_wifi_mac_addr(unsigned char *buf)
         return -1;
     }
 
-#if defined(CONFIG_RKWIFI)
     memcpy(buf, wifi_custom_mac_addr, 6);
-#else
-    memcpy(buf, mac_buf, strlen(mac_buf));//realtek's wifi use this branch
-#endif
+
     return 0;
 }
-EXPORT_SYMBOL(rk29sdk_wifi_mac_addr);
+EXPORT_SYMBOL(rockchip_wifi_mac_addr);
 
 /**************************************************************************
  *
@@ -337,7 +594,7 @@ struct cntry_locales_custom {
 
 static struct cntry_locales_custom country_cloc;
 
-void *rk29sdk_wifi_country_code(char *ccode)
+void *rockchip_wifi_country_code(char *ccode)
 {
     struct cntry_locales_custom *mcloc;
 
@@ -348,8 +605,33 @@ void *rk29sdk_wifi_country_code(char *ccode)
 
     return mcloc;
 }
+EXPORT_SYMBOL(rockchip_wifi_country_code);
 /**************************************************************************/
 
+static int rockchip_wifi_voltage_select(void)
+{
+    struct rfkill_wlan_data *mrfkill = g_rfkill;
+    int voltage = 0;
+
+    if (mrfkill == NULL) {
+        LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
+        return -1;
+    }
+    voltage = mrfkill->pdata->sdio_vol;
+    if (voltage > 2700 && voltage < 3500) {
+        writel_relaxed(0x00100000, RK_GRF_VIRT+0x380); //3.3
+        LOG("%s: wifi & sdio reference voltage: 3.3V\n", __func__);
+    } else if (voltage  > 1500 && voltage < 1950) {
+        writel_relaxed(0x00100010, RK_GRF_VIRT+0x380); //1.8
+        LOG("%s: wifi & sdio reference voltage: 1.8V\n", __func__);
+    } else {
+        LOG("%s: unsupport wifi & sdio reference voltage!\n", __func__);
+        return -1;
+    }
+
+    return 0;
+}
+
 static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char* prefix, const char* name)
 {
     if (gpio_is_valid(gpio->io)) {
@@ -370,8 +652,7 @@ static int wlan_platdata_parse_dt(struct device *dev,
                   struct rksdmmc_gpio_wifi_moudle *data)
 {
     struct device_node *node = dev->of_node;
-    struct device_node *childnode, *grandchildnode;
-    const char *pin_funcs, *strings;
+    const char *strings;
     u32 value;
     int gpio,ret;
     enum of_gpio_flags flags;
@@ -381,78 +662,120 @@ static int wlan_platdata_parse_dt(struct device *dev,
 
     memset(data, 0, sizeof(*data));
 
-    ret = of_property_read_u32(node, "sdio_vref", &value);
-    if (ret < 0)
-        LOG("%s: Can't get sdio vref.", __func__);
-
-    data->sdio_vol = value;
+    ret = of_property_read_string(node, "wifi_chip_type", &strings);
+    if (ret) {
+        LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n", __func__);
+        strcpy(wifi_chip_type_string, "rkwifi");
+    } else {
+        strcpy(wifi_chip_type_string, strings);
+    }
+    LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
 
-    childnode = of_get_child_by_name(node, "wlan_ctrl_pmic");
-       if (!childnode) {
-               LOG("%s: Can not get child => wlan_ctrl_pmic.\n", __func__);
-       } else {
-               ret = of_property_read_string(childnode, "power_ctrl_by_pmu", &strings);
-               if (ret) {
-                       LOG("%s: Can not read property: power_ctrl_by_pmu.\n", __func__);
-                       data->mregulator.power_ctrl_by_pmu = false;
+       if(cpu_is_rk3036() || cpu_is_rk312x()){
+               /* ret = of_property_read_u32(node, "sdio_vref", &value);
+               if (ret < 0) {
+                       LOG("%s: Can't get sdio vref.", __func__);
+                       return -1;
                }
-               if (0 == strcmp(strings, "true")) {
-                       data->mregulator.power_ctrl_by_pmu = true;
-                       ret = of_property_read_string(childnode, "pmu_regulator", &strings);
-                       if (ret) {
-                               LOG("%s: Can not read property: pmu_regulator.\n", __func__);
-                               data->mregulator.power_ctrl_by_pmu = false;
-                       } else {
-                               LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
-                sprintf(data->mregulator.pmu_regulator, "%s", strings);
-                       }
-                       ret = of_property_read_u32(childnode, "pmu_enable_level", &value);
-                       if (ret) {
-                               LOG("%s: Can not read property: pmu_enable_level.\n", __func__);
-                               data->mregulator.power_ctrl_by_pmu = false;
-                       } else {
-                               LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
-                data->mregulator.enable = value;
-                       }
-               } else {
-                       data->mregulator.power_ctrl_by_pmu = false;
-                       LOG("%s: wifi power controled by gpio.\n", __func__);
+               data->sdio_vol = value;*/
+       }else{
+               ret = of_property_read_u32(node, "sdio_vref", &value);
+               if (ret < 0) {
+                       LOG("%s: Can't get sdio vref.", __func__);
+                       return -1;
                }
-    }
-
-    childnode = of_get_child_by_name(node, "wlan_ctrl_gpios");
-       if (!childnode) {
-               LOG("%s: Can not get child => wlan_ctrl_gpios.\n", __func__);
-               return -EINVAL;
+               data->sdio_vol = value;
        }
 
-    for_each_child_of_node(childnode, grandchildnode) {
-        ret = of_property_read_string(grandchildnode, "pin-func", &pin_funcs);
-               if (ret) {
-                       LOG("%s: Can not read property: pin-func.\n", __func__);
-            continue;
-               }
-        gpio = of_get_named_gpio_flags(grandchildnode, "gpios", 0, &flags);
-        if (!gpio_is_valid(gpio)){
-            LOG("%s: Can not read property: %s->gpios.\n", __func__, pin_funcs);
-            continue;
+    if (of_find_property(node, "keep_wifi_power_on", NULL)) {
+        data->wifi_power_remain = true;
+        LOG("%s: wifi power will enabled while kernel starting and keep on.\n", __func__);
+    } else {
+        data->wifi_power_remain = false;
+        LOG("%s: enable wifi power control.\n", __func__);
+    }
+       
+    if (of_find_property(node, "vref_ctrl_enable", NULL)) {
+        LOG("%s: enable wifi io reference voltage control.\n", __func__);
+        data->vref_ctrl_enble = true;
+        if (of_find_property(node, "vref_ctrl_gpio", NULL)) {
+            gpio = of_get_named_gpio_flags(node, "vref_ctrl_gpio", 0, &flags);
+            if (gpio_is_valid(gpio)){
+                data->vddio.io = gpio;
+                data->vddio.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
+                data->ioregulator.power_ctrl_by_pmu = false;
+                LOG("%s: get property: vref_ctrl_gpio = %d, flags = %d.\n", __func__, gpio, flags);
+            } else {
+                data->vddio.io = -1;
+                data->vref_ctrl_enble = false;
+                LOG("%s: vref_ctrl_gpio defined invalid, disable wifi io reference voltage control.\n", __func__);
+            }
+        } else {
+            data->ioregulator.power_ctrl_by_pmu = true;
+            ret = of_property_read_string(node, "vref_pmu_regulator", &strings);
+            if (ret) {
+                LOG("%s: Can not read property: vref_pmu_regulator.\n", __func__);
+                data->vref_ctrl_enble = false;
+                data->ioregulator.power_ctrl_by_pmu = false;
+            } else {
+                LOG("%s: wifi io reference voltage controled by pmu(%s).\n", __func__, strings);
+                sprintf(data->ioregulator.pmu_regulator, "%s", strings);
+            }
+            ret = of_property_read_u32(node, "vref_pmu_enable_level", &value);
+            if (ret) {
+                LOG("%s: Can not read property: vref_pmu_enable_level.\n", __func__);
+                data->vref_ctrl_enble = false;
+                data->ioregulator.power_ctrl_by_pmu = false;
+            } else {
+                LOG("%s: wifi io reference voltage controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
+                data->ioregulator.enable = value;
+            }
         }
+    } else {
+        data->vref_ctrl_enble = false;
+        LOG("%s: disable wifi io reference voltage control.\n", __func__);
+    }
 
-        if (0 == strcmp(pin_funcs, "wlan_poweren")) {
-            data->power_n.io = gpio;
-            data->power_n.enable = flags;
-                   LOG("pin_funcs = %s, gpio = %d, flags = %d", pin_funcs, gpio, flags);
-        } else if (0 == strcmp(pin_funcs, "wlan_reset")) {
-            data->reset_n.io = gpio;
-            data->reset_n.enable = flags;
-                   LOG("pin_funcs = %s, gpio = %d, flags = %d", pin_funcs, gpio, flags);
-        } else if (0 == strcmp(pin_funcs, "wlan_wake_host_irq")) {
-            data->wifi_int_b.io = gpio;
-            data->wifi_int_b.enable = flags;
-                   LOG("pin_funcs = %s, gpio = %d, flags = %d", pin_funcs, gpio, flags);
+    if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
+        data->mregulator.power_ctrl_by_pmu = true;
+        ret = of_property_read_string(node, "power_pmu_regulator", &strings);
+        if (ret) {
+            LOG("%s: Can not read property: power_pmu_regulator.\n", __func__);
+            data->mregulator.power_ctrl_by_pmu = false;
+        } else {
+            LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
+            sprintf(data->mregulator.pmu_regulator, "%s", strings);
         }
-
-    }
+        ret = of_property_read_u32(node, "power_pmu_enable_level", &value);
+        if (ret) {
+            LOG("%s: Can not read property: power_pmu_enable_level.\n", __func__);
+            data->mregulator.power_ctrl_by_pmu = false;
+        } else {
+            LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
+            data->mregulator.enable = value;
+        }
+       } else {
+               data->mregulator.power_ctrl_by_pmu = false;
+               LOG("%s: wifi power controled by gpio.\n", __func__);
+        gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
+        if (gpio_is_valid(gpio)){
+                       data->power_n.io = gpio;
+                       data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
+                       LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
+        } else data->power_n.io = -1;
+        gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
+        if (gpio_is_valid(gpio)){
+                       data->reset_n.io = gpio;
+                       data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
+                       LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
+        } else data->reset_n.io = -1;
+        gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
+        if (gpio_is_valid(gpio)){
+                       data->wifi_int_b.io = gpio;
+                       data->wifi_int_b.enable = flags;
+                       LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
+        } else data->wifi_int_b.io = -1;
+       }
 
     return 0;
 }
@@ -482,6 +805,47 @@ struct early_suspend wlan_early_suspend {
 }
 #endif
 
+static void rfkill_wlan_early_suspend(void)
+{
+    //LOG("%s :enter\n", __func__);
+
+    return;
+}
+
+static void rfkill_wlan_later_resume(void)
+{
+    //LOG("%s :enter\n", __func__);
+
+    return;
+}
+
+static int rfkill_wlan_fb_event_notify(struct notifier_block *self,
+                       unsigned long action, void *data)
+{
+
+    struct fb_event *event = data;
+    int blank_mode = *((int *)event->data);
+
+    switch (blank_mode) {
+    case FB_BLANK_UNBLANK:
+        rfkill_wlan_later_resume();
+        break;
+    case FB_BLANK_NORMAL:
+        rfkill_wlan_early_suspend();
+        break;
+    default:
+        rfkill_wlan_early_suspend();
+        break;
+    }
+
+    return 0;
+}
+
+static struct notifier_block rfkill_wlan_fb_notifier = {
+    .notifier_call = rfkill_wlan_fb_event_notify,
+};
+
+
 static int rfkill_wlan_probe(struct platform_device *pdev)
 {
        struct rfkill_wlan_data *rfkill;
@@ -515,45 +879,38 @@ static int rfkill_wlan_probe(struct platform_device *pdev)
 
     LOG("%s: init gpio\n", __func__);
 
-    ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
-    if (ret) goto fail_alloc;
-
-    ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
-    if (ret) goto fail_alloc;
-/*
-       ret = rfkill_rk_setup_gpio(&pdata->vddio, IOMUX_FGPIO, wlan_name, "wlan-vddio");
-       if (ret) goto fail_alloc;
+    if (!pdata->mregulator.power_ctrl_by_pmu) {
+        ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
+        if (ret) goto fail_alloc;
 
-       ret = rfkill_rk_setup_gpio(&pdata->bgf_int_b, IOMUX_FGPIO, wlan_name, "bgf_int_b");
-       if (ret) goto fail_alloc;
-
-    ret = rfkill_rk_setup_gpio(&pdata->gps_sync, IOMUX_FGPIO, wlan_name, "gps_sync");
-    if (ret) goto fail_alloc;
-
-       ret = rfkill_rk_setup_gpio(&pdata->ANTSEL2, IOMUX_FGPIO, wlan_name, "ANTSEL2");
-       if (ret) goto fail_alloc;
-
-       ret = rfkill_rk_setup_gpio(&pdata->ANTSEL3, IOMUX_FGPIO, wlan_name, "ANTSEL3");
-       if (ret) goto fail_alloc;
+        ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
+        if (ret) goto fail_alloc;
+    }
 
-       ret = rfkill_rk_setup_gpio(&pdata->GPS_LAN, IOMUX_FGPIO, wlan_name, "GPS_LAN");
-       if (ret) goto fail_alloc;
-*/
     wake_lock_init(&(rfkill->wlan_irq_wl), WAKE_LOCK_SUSPEND, "rfkill_wlan_wake");
 
     // Turn off wifi power as default
     if (gpio_is_valid(pdata->power_n.io))
     {
-        gpio_direction_output(pdata->power_n.io, pdata->power_n.enable);
+        gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable);
     }
 
+    if (pdata->wifi_power_remain)
+    {
+        rockchip_wifi_power(1);
+    }
+
+    rockchip_wifi_voltage_select();
+
 #if BCM_STATIC_MEMORY_SUPPORT
-    rk29sdk_init_wifi_mem();
+    rockchip_init_wifi_mem();
 #endif
 
 #if defined(CONFIG_HAS_EARLYSUSPEND)
     register_early_suspend(wlan_early_suspend);
 #endif
+    
+    fb_register_client(&rfkill_wlan_fb_notifier);
 
     LOG("Exit %s\n", __func__);
 
@@ -576,6 +933,8 @@ static int rfkill_wlan_remove(struct platform_device *pdev)
     LOG("Enter %s\n", __func__);
 
     wake_lock_destroy(&rfkill->wlan_irq_wl);
+
+    fb_unregister_client(&rfkill_wlan_fb_notifier);
     
     if (gpio_is_valid(rfkill->pdata->power_n.io))
         gpio_free(rfkill->pdata->power_n.io);
@@ -620,11 +979,11 @@ static int rfkill_wlan_resume(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_OF
-static struct of_device_id pwm_backlight_of_match[] = {
+static struct of_device_id wlan_platdata_of_match[] = {
     { .compatible = "wlan-platdata" },
     { }
 };
-MODULE_DEVICE_TABLE(of, pwm_backlight_of_match);
+MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
 #endif //CONFIG_OF
 
 static struct platform_driver rfkill_wlan_driver = {
@@ -635,7 +994,7 @@ static struct platform_driver rfkill_wlan_driver = {
        .driver = {
                .name = "wlan-platdata",
                .owner = THIS_MODULE,
-        .of_match_table = of_match_ptr(pwm_backlight_of_match),
+        .of_match_table = of_match_ptr(wlan_platdata_of_match),
        },
 };