net: wireless: bcmdhd: Add card detect for DT
Mohan Thadikamalla [Thu, 19 May 2016 05:06:56 +0000 (10:06 +0530)]
- Implement set_carddetect platform call back for DT
- Remove TEGRA_PREPOWER_WIFI config check for adapter power up
and use pwr_retry_cnt DT parameter for no of retries
- Add sdhci_host and pwr_retry_cnt DT parameter support
- Request wifi power and reset gpio's

Bug 200166355

Change-Id: Ib3aced1d60f7e5242bfcff7b26cbf99610faca5a
Signed-off-by: Mohan Thadikamalla <mohant@nvidia.com>
(cherry picked from commit 81349e483d9526a9730ff56332c86fc9498f5baa)
Reviewed-on: http://git-master/r/1128873
Reviewed-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>

drivers/net/wireless/bcmdhd/bcmsdh_sdmmc_linux.c
drivers/net/wireless/bcmdhd/dhd_linux.h
drivers/net/wireless/bcmdhd/dhd_linux_platdev.c

index 83f40c3..31c1150 100644 (file)
@@ -89,6 +89,7 @@ extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd);
 extern void* bcmsdh_probe(osl_t *osh, void *dev, void *sdioh, void *adapter_info, uint bus_type,
        uint bus_num, uint slot_num);
 extern int bcmsdh_remove(bcmsdh_info_t *bcmsdh);
+extern int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present);
 
 int sdio_function_init(void);
 void sdio_function_cleanup(void);
@@ -124,19 +125,9 @@ static int sdioh_probe(struct sdio_func *func)
        if (adapter  != NULL) {
                sd_err(("found adapter info '%s'\n", adapter->name));
 #if defined(CONFIG_WIFI_CONTROL_FUNC)
-               if (adapter->wifi_plat_data) {
-                       plat_data = adapter->wifi_plat_data;
-                       /* sdio card detection is completed,
-                        * so stop card detection here */
-                       if (plat_data->set_carddetect) {
-                               sd_debug(("stopping card detection\n"));
-                               plat_data->set_carddetect(0);
-                       }
-                       else
-                               sd_err(("set_carddetect is not registered\n"));
-               }
-               else
-                       sd_err(("platform data is NULL\n"));
+               /* sdio card detection is completed,
+               * so stop card detection here */
+               wifi_platform_bus_enumerate(adapter, 0);
 #endif
        } else
                sd_err(("can't find adapter info for this chip\n"));
index ef9a063..3e8080e 100644 (file)
@@ -56,9 +56,11 @@ typedef struct wifi_adapter_info {
        uint            intr_flags;
        int             wlan_pwr;
        int             wlan_rst;
+       int             pwr_retry_cnt;
        const char      *edp_name;
        const char      *fw_path;
        const char      *nv_path;
+       struct device_node *sdhci_host;
        void            *wifi_plat_data;        /* wifi ctrl func, for backward compatibility */
        uint            bus_type;
        uint            bus_num;
index 7fc2693..0142340 100644 (file)
 #include <linux/of_net.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
+#include <linux/of_platform.h>
 #include <linux/irq.h>
 #include <mach/nct.h>
 #include <linux/gpio.h>
+#include <linux/mmc/host.h>
+#include <linux/mmc/sdhci.h>
 #ifdef CONFIG_BCMDHD_CUSTOM_SYSFS_TEGRA
 #include "dhd_custom_sysfs_tegra.h"
 #endif
@@ -184,9 +187,9 @@ int wifi_platform_set_power(wifi_adapter_info_t *adapter, bool on, unsigned long
                err = plat_data->set_power(on);
        else {
                if (gpio_is_valid(adapter->wlan_pwr))
-                       gpio_set_value_cansleep(adapter->wlan_pwr, on);
+                       gpio_direction_output(adapter->wlan_pwr, on);
                if (gpio_is_valid(adapter->wlan_rst))
-                       gpio_set_value_cansleep(adapter->wlan_rst, on);
+                       gpio_direction_output(adapter->wlan_rst, on);
        }
 
        if (!on)
@@ -203,6 +206,34 @@ int wifi_platform_set_power(wifi_adapter_info_t *adapter, bool on, unsigned long
        return err;
 }
 
+int wifi_dts_set_carddetect(wifi_adapter_info_t *adapter, bool device_present)
+{
+       struct platform_device *pdev = NULL;
+       struct sdhci_host *host =  NULL;
+
+       if (adapter->sdhci_host == NULL)
+               return -EINVAL;
+
+       pdev = of_find_device_by_node(adapter->sdhci_host);
+       if (pdev == NULL)
+               return -EINVAL;
+
+       host = platform_get_drvdata(pdev);
+       if (host == NULL)
+               return -EINVAL;
+
+       DHD_INFO(("%s Calling %s card detect\n", __func__, mmc_hostname(host->mmc)));
+       if (device_present == 1) {
+               host->mmc->rescan_disable = 0;
+               mmc_detect_change(host->mmc, 0);
+       } else {
+               host->mmc->detect_change = 0;
+               host->mmc->rescan_disable = 1;
+       }
+
+       return 0;
+}
+
 int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present)
 {
        int err = 0;
@@ -215,9 +246,11 @@ int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_presen
        DHD_ERROR(("%s device present %d\n", __FUNCTION__, device_present));
        if (plat_data && plat_data->set_carddetect) {
                err = plat_data->set_carddetect(device_present);
+       } else {
+               err = wifi_dts_set_carddetect(adapter, device_present);
        }
-       return err;
 
+       return err;
 }
 
 static int wifi_get_mac_addr(unsigned char *buf)
@@ -389,11 +422,19 @@ static int wifi_plat_dev_drv_probe(struct platform_device *pdev)
                adapter->wlan_rst = of_get_named_gpio(node, "wlan-rst-gpio", 0);
                adapter->fw_path = of_get_property(node, "fw_path", NULL);
                adapter->nv_path = of_get_property(node, "nv_path", NULL);
+               adapter->sdhci_host = of_parse_phandle(node, "sdhci-host", 0);
+               of_property_read_u32(node, "pwr-retry-cnt", &adapter->pwr_retry_cnt);
 
                if (is_antenna_tuned())
                        adapter->nv_path = of_get_property(node,
                                                "tuned_nv_path", NULL);
 
+               if (gpio_is_valid(adapter->wlan_pwr))
+                       gpio_request(adapter->wlan_pwr, "wlan_pwr");
+
+               if (gpio_is_valid(adapter->wlan_rst))
+                       gpio_request(adapter->wlan_rst, "wlan_rst");
+
                /* This is to get the irq for the OOB */
                adapter->irq_num = platform_get_irq(pdev, 0);
                if (adapter->irq_num > -1) {
@@ -830,7 +871,7 @@ static int dhd_wifi_platform_load_sdio(void)
 #if defined(BCMLXSDMMC)
        sema_init(&dhd_registration_sem, 0);
 #endif
-#if defined(BCMLXSDMMC) && !defined(CONFIG_TEGRA_PREPOWER_WIFI)
+#if defined(BCMLXSDMMC)
        if (dhd_wifi_platdata == NULL) {
                DHD_ERROR(("DHD wifi platform data is required for Android build\n"));
                return -EINVAL;
@@ -839,11 +880,12 @@ static int dhd_wifi_platform_load_sdio(void)
        /* power up all adapters */
        for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
                bool chip_up = FALSE;
-               int retry = POWERUP_MAX_RETRY;
+               int retry;
                struct semaphore dhd_chipup_sem;
 
                adapter = &dhd_wifi_platdata->adapters[i];
 
+               retry = adapter->pwr_retry_cnt;
                DHD_ERROR(("Power-up adapter '%s'\n", adapter->name));
                DHD_INFO((" - irq %d [flags %d], firmware: %s, nvram: %s\n",
                        adapter->irq_num, adapter->intr_flags, adapter->fw_path, adapter->nv_path));