]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/mmc.c
mtd: nand: mxs_nand: move structs into header file
[u-boot] / drivers / mmc / mmc.c
index c93089330030f07a42bd38502c4a536ffec75447..f7827f527aa5cac1a4c651422d1c2edcb2dc1324 100644 (file)
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2008, Freescale Semiconductor, Inc
  * Andy Fleming
  *
  * Based vaguely on the Linux code
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <config.h>
 
 static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage);
 static int mmc_power_cycle(struct mmc *mmc);
+#if !CONFIG_IS_ENABLED(MMC_TINY)
 static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps);
-
-#if CONFIG_IS_ENABLED(MMC_TINY)
-static struct mmc mmc_static;
-struct mmc *find_mmc_device(int dev_num)
-{
-       return &mmc_static;
-}
-
-void mmc_do_preinit(void)
-{
-       struct mmc *m = &mmc_static;
-#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
-       mmc_set_preinit(m, 1);
-#endif
-       if (m->preinit)
-               mmc_start_init(m);
-}
-
-struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
-{
-       return &mmc->block_dev;
-}
 #endif
 
 #if !CONFIG_IS_ENABLED(DM_MMC)
@@ -530,7 +508,7 @@ static int mmc_switch_voltage(struct mmc *mmc, int signal_voltage)
         * During a signal voltage level switch, the clock must be gated
         * for 5 ms according to the SD spec
         */
-       mmc_set_clock(mmc, mmc->clock, true);
+       mmc_set_clock(mmc, mmc->clock, MMC_CLK_DISABLE);
 
        err = mmc_set_signal_voltage(mmc, signal_voltage);
        if (err)
@@ -538,7 +516,7 @@ static int mmc_switch_voltage(struct mmc *mmc, int signal_voltage)
 
        /* Keep clock gated for at least 10 ms, though spec only says 5 ms */
        mdelay(10);
-       mmc_set_clock(mmc, mmc->clock, false);
+       mmc_set_clock(mmc, mmc->clock, MMC_CLK_ENABLE);
 
        /*
         * Failure to switch is indicated by the card holding
@@ -680,7 +658,7 @@ static int mmc_complete_op_cond(struct mmc *mmc)
 {
        struct mmc_cmd cmd;
        int timeout = 1000;
-       uint start;
+       ulong start;
        int err;
 
        mmc->op_cond_pending = 0;
@@ -773,6 +751,7 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
 
 }
 
+#if !CONFIG_IS_ENABLED(MMC_TINY)
 static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode)
 {
        int err;
@@ -856,6 +835,7 @@ static int mmc_get_capabilities(struct mmc *mmc)
 
        return 0;
 }
+#endif
 
 static int mmc_set_capacity(struct mmc *mmc, int part_num)
 {
@@ -1155,6 +1135,7 @@ int mmc_getcd(struct mmc *mmc)
 }
 #endif
 
+#if !CONFIG_IS_ENABLED(MMC_TINY)
 static int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp)
 {
        struct mmc_cmd cmd;
@@ -1175,7 +1156,6 @@ static int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp)
        return mmc_send_cmd(mmc, &cmd, &data);
 }
 
-
 static int sd_get_capabilities(struct mmc *mmc)
 {
        int err;
@@ -1334,7 +1314,7 @@ static int sd_set_card_speed(struct mmc *mmc, enum bus_mode mode)
        return 0;
 }
 
-int sd_select_bus_width(struct mmc *mmc, int w)
+static int sd_select_bus_width(struct mmc *mmc, int w)
 {
        int err;
        struct mmc_cmd cmd;
@@ -1362,6 +1342,7 @@ int sd_select_bus_width(struct mmc *mmc, int w)
 
        return 0;
 }
+#endif
 
 #if CONFIG_IS_ENABLED(MMC_WRITE)
 static int sd_read_ssr(struct mmc *mmc)
@@ -1507,6 +1488,8 @@ int mmc_set_clock(struct mmc *mmc, uint clock, bool disable)
        mmc->clock = clock;
        mmc->clk_disable = disable;
 
+       debug("clock is %s (%dHz)\n", disable ? "disabled" : "enabled", clock);
+
        return mmc_set_ios(mmc);
 }
 
@@ -1583,6 +1566,7 @@ static inline int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage)
 }
 #endif
 
+#if !CONFIG_IS_ENABLED(MMC_TINY)
 static const struct mode_width_tuning sd_modes_by_pref[] = {
 #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
 #ifdef MMC_SUPPORTS_TUNING
@@ -1673,7 +1657,8 @@ static int sd_select_mode_and_width(struct mmc *mmc, uint card_caps)
 
                                /* configure the bus mode (host) */
                                mmc_select_mode(mmc, mwt->mode);
-                               mmc_set_clock(mmc, mmc->tran_speed, false);
+                               mmc_set_clock(mmc, mmc->tran_speed,
+                                               MMC_CLK_ENABLE);
 
 #ifdef MMC_SUPPORTS_TUNING
                                /* execute tuning if needed */
@@ -1689,7 +1674,7 @@ static int sd_select_mode_and_width(struct mmc *mmc, uint card_caps)
 
 #if CONFIG_IS_ENABLED(MMC_WRITE)
                                err = sd_read_ssr(mmc);
-                               if (!err)
+                               if (err)
                                        pr_warn("unable to read ssr\n");
 #endif
                                if (!err)
@@ -1698,7 +1683,8 @@ static int sd_select_mode_and_width(struct mmc *mmc, uint card_caps)
 error:
                                /* revert to a safer bus speed */
                                mmc_select_mode(mmc, SD_LEGACY);
-                               mmc_set_clock(mmc, mmc->tran_speed, false);
+                               mmc_set_clock(mmc, mmc->tran_speed,
+                                               MMC_CLK_ENABLE);
                        }
                }
        }
@@ -1859,7 +1845,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)
                return -ENOTSUPP;
        }
 
-       mmc_set_clock(mmc, mmc->legacy_speed, false);
+       mmc_set_clock(mmc, mmc->legacy_speed, MMC_CLK_ENABLE);
 
        for_each_mmc_mode_by_pref(card_caps, mwt) {
                for_each_supported_width(card_caps & mwt->widths,
@@ -1902,7 +1888,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)
 
                        /* configure the bus mode (host) */
                        mmc_select_mode(mmc, mwt->mode);
-                       mmc_set_clock(mmc, mmc->tran_speed, false);
+                       mmc_set_clock(mmc, mmc->tran_speed, MMC_CLK_ENABLE);
 #ifdef MMC_SUPPORTS_TUNING
 
                        /* execute tuning if needed */
@@ -1933,6 +1919,11 @@ error:
 
        return -ENOTSUPP;
 }
+#endif
+
+#if CONFIG_IS_ENABLED(MMC_TINY)
+DEFINE_CACHE_ALIGN_BUFFER(u8, ext_csd_bkup, MMC_MAX_BLOCK_LEN);
+#endif
 
 static int mmc_startup_v4(struct mmc *mmc)
 {
@@ -1952,6 +1943,23 @@ static int mmc_startup_v4(struct mmc *mmc)
                MMC_VERSION_5_1
        };
 
+#if CONFIG_IS_ENABLED(MMC_TINY)
+       u8 *ext_csd = ext_csd_bkup;
+
+       if (IS_SD(mmc) || mmc->version < MMC_VERSION_4)
+               return 0;
+
+       if (!mmc->ext_csd)
+               memset(ext_csd_bkup, 0, sizeof(ext_csd_bkup));
+
+       err = mmc_send_ext_csd(mmc, ext_csd);
+       if (err)
+               goto error;
+
+       /* store the ext csd for future reference */
+       if (!mmc->ext_csd)
+               mmc->ext_csd = ext_csd;
+#else
        ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
 
        if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
@@ -1968,7 +1976,7 @@ static int mmc_startup_v4(struct mmc *mmc)
        if (!mmc->ext_csd)
                return -ENOMEM;
        memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN);
-
+#endif
        if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions))
                return -EINVAL;
 
@@ -2107,7 +2115,9 @@ static int mmc_startup_v4(struct mmc *mmc)
        return 0;
 error:
        if (mmc->ext_csd) {
+#if !CONFIG_IS_ENABLED(MMC_TINY)
                free(mmc->ext_csd);
+#endif
                mmc->ext_csd = NULL;
        }
        return err;
@@ -2296,6 +2306,11 @@ static int mmc_startup(struct mmc *mmc)
        if (err)
                return err;
 
+#if CONFIG_IS_ENABLED(MMC_TINY)
+       mmc_set_clock(mmc, mmc->legacy_speed, false);
+       mmc_select_mode(mmc, IS_SD(mmc) ? SD_LEGACY : MMC_LEGACY);
+       mmc_set_bus_width(mmc, 1);
+#else
        if (IS_SD(mmc)) {
                err = sd_get_capabilities(mmc);
                if (err)
@@ -2307,7 +2322,7 @@ static int mmc_startup(struct mmc *mmc)
                        return err;
                mmc_select_mode_and_width(mmc, mmc->card_caps);
        }
-
+#endif
        if (err)
                return err;
 
@@ -2427,7 +2442,7 @@ static void mmc_set_initial_state(struct mmc *mmc)
 
        mmc_select_mode(mmc, MMC_LEGACY);
        mmc_set_bus_width(mmc, 1);
-       mmc_set_clock(mmc, 0, false);
+       mmc_set_clock(mmc, 0, MMC_CLK_ENABLE);
 }
 
 static int mmc_power_on(struct mmc *mmc)
@@ -2447,7 +2462,7 @@ static int mmc_power_on(struct mmc *mmc)
 
 static int mmc_power_off(struct mmc *mmc)
 {
-       mmc_set_clock(mmc, 0, true);
+       mmc_set_clock(mmc, 0, MMC_CLK_DISABLE);
 #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)
        if (mmc->vmmc_supply) {
                int ret = regulator_set_enable(mmc->vmmc_supply, false);
@@ -2608,7 +2623,7 @@ static int mmc_complete_init(struct mmc *mmc)
 int mmc_init(struct mmc *mmc)
 {
        int err = 0;
-       __maybe_unused unsigned start;
+       __maybe_unused ulong start;
 #if CONFIG_IS_ENABLED(DM_MMC)
        struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc->dev);