]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/mmc.c
Merge branch 'master' of git://git.denx.de/u-boot-mmc
[u-boot] / drivers / mmc / mmc.c
index 0312da91af7736db2ee2845cbfea7cfbdb115dd0..3648950cf5a3fc39cb736b01eafa1b82308ff14c 100644 (file)
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <mmc.h>
 #include <part.h>
+#include <power/regulator.h>
 #include <malloc.h>
 #include <memalign.h>
 #include <linux/list.h>
@@ -29,6 +30,29 @@ static const unsigned int sd_au_size[] = {
        SZ_16M / 512,   (SZ_16M + SZ_8M) / 512, SZ_32M / 512,   SZ_64M / 512,
 };
 
+#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
+
 #ifndef CONFIG_DM_MMC_OPS
 __weak int board_mmc_getwp(struct mmc *mmc)
 {
@@ -258,7 +282,11 @@ ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
        if (!mmc)
                return 0;
 
-       err = blk_dselect_hwpart(block_dev, block_dev->hwpart);
+       if (CONFIG_IS_ENABLED(MMC_TINY))
+               err = mmc_switch_part(mmc, block_dev->hwpart);
+       else
+               err = blk_dselect_hwpart(block_dev, block_dev->hwpart);
+
        if (err < 0)
                return 0;
 
@@ -493,6 +521,7 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
 {
        struct mmc_cmd cmd;
        int timeout = 1000;
+       int retries = 3;
        int ret;
 
        cmd.cmdidx = MMC_CMD_SWITCH;
@@ -501,11 +530,17 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
                                 (index << 16) |
                                 (value << 8);
 
-       ret = mmc_send_cmd(mmc, &cmd, NULL);
+       while (retries > 0) {
+               ret = mmc_send_cmd(mmc, &cmd, NULL);
 
-       /* Waiting for the ready status */
-       if (!ret)
-               ret = mmc_send_status(mmc, timeout);
+               /* Waiting for the ready status */
+               if (!ret) {
+                       ret = mmc_send_status(mmc, timeout);
+                       return ret;
+               }
+
+               retries--;
+       }
 
        return ret;
 
@@ -1582,6 +1617,31 @@ __weak void board_mmc_power_init(void)
 {
 }
 
+static int mmc_power_init(struct mmc *mmc)
+{
+       board_mmc_power_init();
+
+#if defined(CONFIG_DM_MMC) && defined(CONFIG_DM_REGULATOR) && \
+       !defined(CONFIG_SPL_BUILD)
+       struct udevice *vmmc_supply;
+       int ret;
+
+       ret = device_get_supply_regulator(mmc->dev, "vmmc-supply",
+                                         &vmmc_supply);
+       if (ret) {
+               debug("%s: No vmmc supply\n", mmc->dev->name);
+               return 0;
+       }
+
+       ret = regulator_set_enable(vmmc_supply, true);
+       if (ret) {
+               puts("Error enabling VMMC supply\n");
+               return ret;
+       }
+#endif
+       return 0;
+}
+
 int mmc_start_init(struct mmc *mmc)
 {
        bool no_card;
@@ -1606,7 +1666,9 @@ int mmc_start_init(struct mmc *mmc)
 #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
        mmc_adapter_card_type_ident();
 #endif
-       board_mmc_power_init();
+       err = mmc_power_init(mmc);
+       if (err)
+               return err;
 
 #ifdef CONFIG_DM_MMC_OPS
        /* The device has already been probed ready for use */
@@ -1673,7 +1735,7 @@ static int mmc_complete_init(struct mmc *mmc)
 int mmc_init(struct mmc *mmc)
 {
        int err = 0;
-       unsigned start;
+       __maybe_unused unsigned start;
 #ifdef CONFIG_DM_MMC
        struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc->dev);
 
@@ -1689,7 +1751,9 @@ int mmc_init(struct mmc *mmc)
 
        if (!err)
                err = mmc_complete_init(mmc);
-       debug("%s: %d, time %lu\n", __func__, err, get_timer(start));
+       if (err)
+               printf("%s: %d, time %lu\n", __func__, err, get_timer(start));
+
        return err;
 }
 
@@ -1769,7 +1833,9 @@ int mmc_initialize(bd_t *bis)
        initialized = 1;
 
 #ifndef CONFIG_BLK
+#if !CONFIG_IS_ENABLED(MMC_TINY)
        mmc_list_init();
+#endif
 #endif
        ret = mmc_probe(bis);
        if (ret)
@@ -1782,3 +1848,37 @@ int mmc_initialize(bd_t *bis)
        mmc_do_preinit();
        return 0;
 }
+
+#ifdef CONFIG_CMD_BKOPS_ENABLE
+int mmc_set_bkops_enable(struct mmc *mmc)
+{
+       int err;
+       ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+
+       err = mmc_send_ext_csd(mmc, ext_csd);
+       if (err) {
+               puts("Could not get ext_csd register values\n");
+               return err;
+       }
+
+       if (!(ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1)) {
+               puts("Background operations not supported on device\n");
+               return -EMEDIUMTYPE;
+       }
+
+       if (ext_csd[EXT_CSD_BKOPS_EN] & 0x1) {
+               puts("Background operations already enabled\n");
+               return 0;
+       }
+
+       err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BKOPS_EN, 1);
+       if (err) {
+               puts("Failed to enable manual background operations\n");
+               return err;
+       }
+
+       puts("Enabled manual background operations\n");
+
+       return 0;
+}
+#endif