iommu/rockchip: don't do power domain enable on probe
[firefly-linux-kernel-4.4.55.git] / net / rfkill / rfkill-wlan.c
index 5a13d02a5984945e97463bb643a4034cb13ccd18..070ef05ca15cba7fa8f93f1608c0eb6f7e7713c0 100644 (file)
 #include <linux/rockchip/common.h>
 #include <linux/regmap.h>
 #include <linux/mfd/syscon.h>
+#include <linux/mmc/host.h>
 #ifdef CONFIG_OF
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_gpio.h>
 #endif
+#include <linux/soc/rockchip/rk_vendor_storage.h>
 
 #if 0
 #define DBG(x...)   printk(KERN_INFO "[WLAN_RFKILL]: "x)
@@ -53,6 +55,9 @@
 
 #define LOG(x...)   printk(KERN_INFO "[WLAN_RFKILL]: "x)
 
+extern struct mmc_host *primary_sdio_host;
+extern void mmc_pwrseq_power_off(struct mmc_host *host);
+
 struct rfkill_wlan_data {
        struct rksdmmc_gpio_wifi_moudle *pdata;
     struct wake_lock            wlan_irq_wl;
@@ -290,6 +295,9 @@ int rockchip_wifi_power(int on)
 
     LOG("%s: %d\n", __func__, on);
 
+       if (!on && primary_sdio_host)
+               mmc_pwrseq_power_off(primary_sdio_host);
+
     if (mrfkill == NULL) {
         LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
         return -1;
@@ -380,7 +388,6 @@ 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)
 {
@@ -437,91 +444,70 @@ EXPORT_SYMBOL(rockchip_wifi_reset);
 #include <linux/errno.h>
 u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
 
-static void rockchip_wifi_get_sn(char *buf)
-{
-       memset(buf, 0, 512);
-       //GetSNSectorInfo(char * pbuf);
-
-       return ;
-}
-
-//#define ENABLE_WIFI_RAND_MAC
-#ifdef ENABLE_WIFI_RAND_MAC
-#define WIFI_RAND_MAC_FILE "/data/misc/wifi_rand_mac"
-
-static int rockchip_wifi_rand_mac_addr(unsigned char *buf)
+//#define RANDOM_ADDRESS_SAVE
+static int get_wifi_addr_vendor(unsigned char *addr)
 {
-    struct file *fp; 
-    loff_t pos;
-    mm_segment_t fs;
-    char mac_buf[20] = {0};
-
-    LOG("%s\n", __func__);
-    fp = filp_open(WIFI_RAND_MAC_FILE, O_RDONLY, 0);
-    if (fp == NULL || IS_ERR(fp)) {
-        fp = filp_open(WIFI_RAND_MAC_FILE, O_RDWR | O_CREAT, 0644);
-        if (fp == NULL || IS_ERR(fp)) {
-            LOG("%s: create %s failed.\n", __func__, WIFI_RAND_MAC_FILE);
-            return -1;
-        }
-        fs = get_fs();
-        set_fs(KERNEL_DS);
-        random_ether_addr(wifi_custom_mac_addr);
-        pos = 0;
-        vfs_write(fp, wifi_custom_mac_addr, 6, &pos);
-        filp_close(fp, NULL);  
-    } else {
-        fs = get_fs();
-        set_fs(KERNEL_DS);
-        pos = 0;
-        vfs_read(fp, wifi_custom_mac_addr, 6, &pos);
-        filp_close(fp, NULL); 
-    }
-    sprintf(mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x",wifi_custom_mac_addr[0],wifi_custom_mac_addr[1],
-    wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
-    LOG("random wifi_custom_mac_addr=[%s]\n", mac_buf);    
-    return 0;
-}
+       int ret;
+
+       ret = rk_vendor_read(WIFI_MAC_ID, addr, 6);
+       if (ret != 6 || is_zero_ether_addr(addr)) {
+               LOG("%s: rk_vendor_read wifi mac address failed (%d)\n",
+                   __func__, ret);
+#ifdef RANDOM_ADDRESS_SAVE
+               random_ether_addr(addr);
+               LOG("%s: generate random wifi mac address: "
+                   "%02x:%02x:%02x:%02x:%02x:%02x\n",
+                   __func__, addr[0], addr[1], addr[2],
+                   addr[3], addr[4], addr[5]);
+               ret = rk_vendor_write(WIFI_MAC_ID, addr, 6);
+               if (ret != 0) {
+                       LOG("%s: rk_vendor_write"
+                               " wifi mac address failed (%d)\n",
+                               __func__, ret);
+                       memset(addr, 0, 6);
+                       return -1;
+               }
+#else
+               return -1;
 #endif
+       } else {
+               LOG("%s: rk_vendor_read wifi mac address: "
+                   "%02x:%02x:%02x:%02x:%02x:%02x\n",
+                   __func__, addr[0], addr[1], addr[2],
+                   addr[3], addr[4], addr[5]);
+       }
+       return 0;
+}
 
 int rockchip_wifi_mac_addr(unsigned char *buf)
 {
-    char mac_buf[20] = {0};
-    LOG("%s: enter.\n", __func__);
-
-    // from vflash
-    if(is_zero_ether_addr(wifi_custom_mac_addr)) {
-        int i;
-        char *tempBuf = kmalloc(512, GFP_KERNEL);
-        if(tempBuf) {
-            rockchip_wifi_get_sn(tempBuf);
-            for (i = 445; i <= 450; i++)
-                wifi_custom_mac_addr[i-445] = tempBuf[i];
-            kfree(tempBuf);
-        } else {
-            return -1;
-        }
-    }
+       char mac_buf[20] = {0};
 
-    sprintf(mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x",wifi_custom_mac_addr[0],wifi_custom_mac_addr[1],
-    wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
-    LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
+       LOG("%s: enter.\n", __func__);
 
-#ifdef ENABLE_WIFI_RAND_MAC
-    rockchip_wifi_rand_mac_addr(buf);
-#endif
+       // from vendor storage
+       if (is_zero_ether_addr(wifi_custom_mac_addr)) {
+               if (get_wifi_addr_vendor(wifi_custom_mac_addr) != 0)
+                       return -1;
+       }
 
-    if (is_valid_ether_addr(wifi_custom_mac_addr)) {
-        if (!strncmp(wifi_chip_type_string, "rtl", 3))
-            wifi_custom_mac_addr[0] &= ~0x2; // for p2p
-    } else {
-        LOG("This mac address is not valid, ignored...\n");
-        return -1;
-    }
+       sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x",
+               wifi_custom_mac_addr[0], wifi_custom_mac_addr[1],
+               wifi_custom_mac_addr[2], wifi_custom_mac_addr[3],
+               wifi_custom_mac_addr[4], wifi_custom_mac_addr[5]);
+       LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
+
+       if (is_valid_ether_addr(wifi_custom_mac_addr)) {
+               if (!strncmp(wifi_chip_type_string, "rtl", 3))
+                       wifi_custom_mac_addr[0] &= ~0x2; // for p2p
+       } else {
+               LOG("This mac address is not valid, ignored...\n");
+               return -1;
+       }
 
-    memcpy(buf, wifi_custom_mac_addr, 6);
+       memcpy(buf, wifi_custom_mac_addr, 6);
 
-    return 0;
+       return 0;
 }
 EXPORT_SYMBOL(rockchip_wifi_mac_addr);