net: mt7628-eth: add support to isolate LAN/WAN ports
[oweals/u-boot.git] / drivers / mmc / msm_sdhci.c
index 64bbf0cd2507fe57062017031c6419d4a756bec0..cae42ec4acebb75f192f977dc314510dc86337df 100644 (file)
@@ -1,11 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Qualcomm SDHCI driver - SD/eMMC controller
  *
  * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
  *
  * Based on Linux driver
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 /* Non standard (?) SDHCI register */
 #define SDHCI_VENDOR_SPEC_CAPABILITIES0  0x11c
 
+struct msm_sdhc_plat {
+       struct mmc_config cfg;
+       struct mmc mmc;
+};
+
 struct msm_sdhc {
        struct sdhci_host host;
        void *base;
@@ -45,16 +49,16 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static int msm_sdc_clk_init(struct udevice *dev)
 {
-       uint clk_rate = fdtdec_get_uint(gd->fdt_blob, dev->of_offset,
-                                       "clock-frequency", 400000);
+       int node = dev_of_offset(dev);
+       uint clk_rate = fdtdec_get_uint(gd->fdt_blob, node, "clock-frequency",
+                                       400000);
        uint clkd[2]; /* clk_id and clk_no */
        int clk_offset;
        struct udevice *clk_dev;
        struct clk clk;
        int ret;
 
-       ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset, "clock", clkd,
-                                  2);
+       ret = fdtdec_get_int_array(gd->fdt_blob, node, "clock", clkd, 2);
        if (ret)
                return ret;
 
@@ -81,13 +85,18 @@ static int msm_sdc_clk_init(struct udevice *dev)
 
 static int msm_sdc_probe(struct udevice *dev)
 {
+       struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+       struct msm_sdhc_plat *plat = dev_get_platdata(dev);
        struct msm_sdhc *prv = dev_get_priv(dev);
        struct sdhci_host *host = &prv->host;
        u32 core_version, core_minor, core_major;
+       u32 caps;
        int ret;
 
        host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_BROKEN_R1B;
 
+       host->max_clk = 0;
+
        /* Init clocks */
        ret = msm_sdc_clk_init(dev);
        if (ret)
@@ -99,15 +108,15 @@ static int msm_sdc_probe(struct udevice *dev)
 
 
        /* Wait for reset to be written to register */
-       if (wait_for_bit(__func__, prv->base + SDCC_MCI_STATUS2,
-                        SDCC_MCI_STATUS2_MCI_ACT, false, 10, false)) {
+       if (wait_for_bit_le32(prv->base + SDCC_MCI_STATUS2,
+                             SDCC_MCI_STATUS2_MCI_ACT, false, 10, false)) {
                printf("msm_sdhci: reset request failed\n");
                return -EIO;
        }
 
        /* SW reset can take upto 10HCLK + 15MCLK cycles. (min 40us) */
-       if (wait_for_bit(__func__, prv->base + SDCC_MCI_POWER,
-                        SDCC_MCI_POWER_SW_RST, false, 2, false)) {
+       if (wait_for_bit_le32(prv->base + SDCC_MCI_POWER,
+                             SDCC_MCI_POWER_SW_RST, false, 2, false)) {
                printf("msm_sdhci: stuck in reset\n");
                return -ETIMEDOUT;
        }
@@ -127,16 +136,20 @@ static int msm_sdc_probe(struct udevice *dev)
         * controller versions and must be explicitly enabled.
         */
        if (core_major >= 1 && core_minor != 0x11 && core_minor != 0x12) {
-               u32 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
+               caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
                caps |= SDHCI_CAN_VDD_300 | SDHCI_CAN_DO_8BIT;
                writel(caps, host->ioaddr + SDHCI_VENDOR_SPEC_CAPABILITIES0);
        }
 
-       /* Set host controller version */
-       host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
+       host->mmc = &plat->mmc;
+       host->mmc->dev = dev;
+       ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
+       if (ret)
+               return ret;
+       host->mmc->priv = &prv->host;
+       upriv->mmc = host->mmc;
 
-       /* automatically detect max and min speed */
-       return add_sdhci(host, 0, 0);
+       return sdhci_probe(dev);
 }
 
 static int msm_sdc_remove(struct udevice *dev)
@@ -154,16 +167,14 @@ static int msm_ofdata_to_platdata(struct udevice *dev)
        struct udevice *parent = dev->parent;
        struct msm_sdhc *priv = dev_get_priv(dev);
        struct sdhci_host *host = &priv->host;
+       int node = dev_of_offset(dev);
 
        host->name = strdup(dev->name);
-       host->ioaddr = (void *)dev_get_addr(dev);
-       host->bus_width = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-                                        "bus-width", 4);
-       host->index = fdtdec_get_uint(gd->fdt_blob, dev->of_offset, "index", 0);
+       host->ioaddr = (void *)devfdt_get_addr(dev);
+       host->bus_width = fdtdec_get_int(gd->fdt_blob, node, "bus-width", 4);
+       host->index = fdtdec_get_uint(gd->fdt_blob, node, "index", 0);
        priv->base = (void *)fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
-                                                             parent->of_offset,
-                                                             dev->of_offset,
-                                                             "reg", 1, NULL);
+                       dev_of_offset(parent), node, "reg", 1, NULL, false);
        if (priv->base == (void *)FDT_ADDR_T_NONE ||
            host->ioaddr == (void *)FDT_ADDR_T_NONE)
                return -EINVAL;
@@ -171,6 +182,13 @@ static int msm_ofdata_to_platdata(struct udevice *dev)
        return 0;
 }
 
+static int msm_sdc_bind(struct udevice *dev)
+{
+       struct msm_sdhc_plat *plat = dev_get_platdata(dev);
+
+       return sdhci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
 static const struct udevice_id msm_mmc_ids[] = {
        { .compatible = "qcom,sdhci-msm-v4" },
        { }
@@ -181,7 +199,10 @@ U_BOOT_DRIVER(msm_sdc_drv) = {
        .id             = UCLASS_MMC,
        .of_match       = msm_mmc_ids,
        .ofdata_to_platdata = msm_ofdata_to_platdata,
+       .ops            = &sdhci_ops,
+       .bind           = msm_sdc_bind,
        .probe          = msm_sdc_probe,
        .remove         = msm_sdc_remove,
        .priv_auto_alloc_size = sizeof(struct msm_sdhc),
+       .platdata_auto_alloc_size = sizeof(struct msm_sdhc_plat),
 };