support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / net / rfkill / rfkill-wlan.c
index 85ea624d7ef487ebb6e50b90635f95b62ecae592..ff5dd1620ee66677546b6740888d6edcf82a4ca2 100755 (executable)
@@ -36,6 +36,7 @@
 #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>
@@ -56,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)
@@ -95,14 +97,48 @@ static char wifi_chip_type_string[64];
 int get_wifi_chip_type(void)
 {
     int type;
-    if (strcmp(wifi_chip_type_string, "rkwifi") == 0) {
-        type = WIFI_BCMWIFI;
-    } else if (strcmp(wifi_chip_type_string, "rtkwifi") == 0) {
-        type = WIFI_RTKWIFI;
+    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_BCMWIFI;
+        type = WIFI_AP6210;
     }
     return type;
 }
@@ -113,7 +149,7 @@ EXPORT_SYMBOL(get_wifi_chip_type);
  * Broadcom Wifi Static Memory
  * 
  **********************************************************/
-#ifdef CONFIG_RKWIFI
+#if 0//def CONFIG_RKWIFI
 #define BCM_STATIC_MEMORY_SUPPORT 1
 #else
 #define BCM_STATIC_MEMORY_SUPPORT 0
@@ -349,6 +385,11 @@ int rockchip_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__);
@@ -443,7 +484,8 @@ int rockchip_wifi_set_carddetect(int val)
        chip = get_wifi_chip_type();
 
        /*  irq_type : 0, oob; 1, cap-sdio-irq */
-       if (chip == WIFI_BCMWIFI)
+       if (!strncmp(wifi_chip_type_string, "ap", 2) ||
+               !strncmp(wifi_chip_type_string, "rk", 2))
                irq_type = 0;
        else
                irq_type = 1;
@@ -502,8 +544,6 @@ u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
 extern char GetSNSectorInfo(char * pbuf);
 int rockchip_wifi_mac_addr(unsigned char *buf)
 {
-    return -1;
-/*
     char mac_buf[20] = {0};
     LOG("%s: enter.\n", __func__);
 
@@ -513,8 +553,8 @@ int rockchip_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;
@@ -535,13 +575,9 @@ int rockchip_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(rockchip_wifi_mac_addr);
 
@@ -630,8 +666,9 @@ static int wlan_platdata_parse_dt(struct device *dev,
     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);
     }
-    strcpy(wifi_chip_type_string, strings);
     LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
 
        if(cpu_is_rk3036() || cpu_is_rk312x()){
@@ -650,6 +687,14 @@ static int wlan_platdata_parse_dt(struct device *dev,
                data->sdio_vol = value;
        }
 
+    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;
@@ -760,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;
@@ -809,6 +895,11 @@ static int rfkill_wlan_probe(struct platform_device *pdev)
         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
@@ -818,6 +909,8 @@ static int rfkill_wlan_probe(struct platform_device *pdev)
 #if defined(CONFIG_HAS_EARLYSUSPEND)
     register_early_suspend(wlan_early_suspend);
 #endif
+    
+    fb_register_client(&rfkill_wlan_fb_notifier);
 
     LOG("Exit %s\n", __func__);
 
@@ -840,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);