Merge https://gitlab.denx.de/u-boot/custodians/u-boot-spi into next
[platform/kernel/u-boot.git] / drivers / mmc / fsl_esdhc_imx.c
index 3416e9b..f42e018 100644 (file)
 #include <cpu_func.h>
 #include <errno.h>
 #include <hwconfig.h>
+#include <log.h>
 #include <mmc.h>
 #include <part.h>
+#include <asm/cache.h>
+#include <dm/device_compat.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/err.h>
 #include <power/regulator.h>
 #include <malloc.h>
 #include <fsl_esdhc_imx.h>
@@ -78,7 +84,7 @@ struct fsl_esdhc {
        uint    vendorspec;
        uint    mmcboot;
        uint    vendorspec2;
-       uint    tuning_ctrl;    /* on i.MX6/7/8 */
+       uint    tuning_ctrl;    /* on i.MX6/7/8/RT */
        char    reserved5[44];
        uint    hostver;        /* Host controller version register */
        char    reserved6[4];   /* reserved */
@@ -661,35 +667,6 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
        priv->clock = clock;
 }
 
-#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
-static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
-{
-       struct fsl_esdhc *regs = priv->esdhc_regs;
-       u32 value;
-       u32 time_out;
-
-       value = esdhc_read32(&regs->sysctl);
-
-       if (enable)
-               value |= SYSCTL_CKEN;
-       else
-               value &= ~SYSCTL_CKEN;
-
-       esdhc_write32(&regs->sysctl, value);
-
-       time_out = 20;
-       value = PRSSTAT_SDSTB;
-       while (!(esdhc_read32(&regs->prsstat) & value)) {
-               if (time_out == 0) {
-                       printf("fsl_esdhc: Internal clock never stabilised.\n");
-                       break;
-               }
-               time_out--;
-               mdelay(1);
-       }
-}
-#endif
-
 #ifdef MMC_SUPPORTS_TUNING
 static int esdhc_change_pinstate(struct udevice *dev)
 {
@@ -770,7 +747,6 @@ static int esdhc_set_timing(struct mmc *mmc)
 
        switch (mmc->selected_mode) {
        case MMC_LEGACY:
-       case SD_LEGACY:
                esdhc_reset_tuning(mmc);
                writel(mixctrl, &regs->mixctrl);
                break;
@@ -815,7 +791,7 @@ static int esdhc_set_voltage(struct mmc *mmc)
        switch (mmc->signal_voltage) {
        case MMC_SIGNAL_VOLTAGE_330:
                if (priv->vs18_enable)
-                       return -EIO;
+                       return -ENOTSUPP;
 #if CONFIG_IS_ENABLED(DM_REGULATOR)
                if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
                        ret = regulator_set_value(priv->vqmmc_dev, 3300000);
@@ -961,12 +937,6 @@ static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
        int ret __maybe_unused;
        u32 clock;
 
-#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
-       /* Select to use peripheral clock */
-       esdhc_clock_control(priv, false);
-       esdhc_setbits32(&regs->scr, ESDHCCTL_PCS);
-       esdhc_clock_control(priv, true);
-#endif
        /* Set the clock speed */
        clock = mmc->clock;
        if (clock < mmc->cfg->f_min)
@@ -1002,7 +972,8 @@ static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
        if (priv->signal_voltage != mmc->signal_voltage) {
                ret = esdhc_set_voltage(mmc);
                if (ret) {
-                       printf("esdhc_set_voltage error %d\n", ret);
+                       if (ret != -ENOTSUPP)
+                               printf("esdhc_set_voltage error %d\n", ret);
                        return ret;
                }
        }
@@ -1394,13 +1365,8 @@ void fdt_fixup_esdhc(void *blob, bd_t *bd)
        if (esdhc_status_fixup(blob, compat))
                return;
 
-#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
-       do_fixup_by_compat_u32(blob, compat, "peripheral-frequency",
-                              gd->arch.sdhc_clk, 1);
-#else
        do_fixup_by_compat_u32(blob, compat, "clock-frequency",
                               gd->arch.sdhc_clk, 1);
-#endif
 }
 #endif
 
@@ -1490,6 +1456,7 @@ static int fsl_esdhc_probe(struct udevice *dev)
        if (ret) {
                dev_dbg(dev, "no vqmmc-supply\n");
        } else {
+               priv->vqmmc_dev = vqmmc_dev;
                ret = regulator_set_enable(vqmmc_dev, true);
                if (ret) {
                        dev_err(dev, "fail to enable vqmmc-supply\n");
@@ -1660,6 +1627,7 @@ static const struct udevice_id fsl_esdhc_ids[] = {
        { .compatible = "fsl,imx8mm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
        { .compatible = "fsl,imx8mn-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
        { .compatible = "fsl,imx8mq-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
+       { .compatible = "fsl,imxrt-usdhc", },
        { .compatible = "fsl,esdhc", },
        { /* sentinel */ }
 };