arm: mvebu: remove self assignment
[oweals/u-boot.git] / drivers / mmc / mmc.c
index d6b7e4f510c93c3faadaa6b84646bc7402e68b1b..38e1c800e10c3b7c70d69828413444e34db12d9f 100644 (file)
@@ -30,7 +30,30 @@ static const unsigned int sd_au_size[] = {
        SZ_16M / 512,   (SZ_16M + SZ_8M) / 512, SZ_32M / 512,   SZ_64M / 512,
 };
 
-#ifndef CONFIG_DM_MMC_OPS
+#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_OPS)
 __weak int board_mmc_getwp(struct mmc *mmc)
 {
        return -1;
@@ -126,7 +149,7 @@ void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd)
 }
 #endif
 
-#ifndef CONFIG_DM_MMC_OPS
+#if !CONFIG_IS_ENABLED(DM_MMC_OPS)
 int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 {
        int ret;
@@ -238,14 +261,14 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
        return blkcnt;
 }
 
-#ifdef CONFIG_BLK
+#if CONFIG_IS_ENABLED(BLK)
 ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *dst)
 #else
 ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
                void *dst)
 #endif
 {
-#ifdef CONFIG_BLK
+#if CONFIG_IS_ENABLED(BLK)
        struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 #endif
        int dev_num = block_dev->devnum;
@@ -259,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;
 
@@ -812,7 +839,7 @@ int mmc_hwpart_config(struct mmc *mmc,
        return 0;
 }
 
-#ifndef CONFIG_DM_MMC_OPS
+#if !CONFIG_IS_ENABLED(DM_MMC_OPS)
 int mmc_getcd(struct mmc *mmc)
 {
        int cd;
@@ -1048,7 +1075,7 @@ static const u8 multipliers[] = {
        80,
 };
 
-#ifndef CONFIG_DM_MMC_OPS
+#if !CONFIG_IS_ENABLED(DM_MMC_OPS)
 static void mmc_set_ios(struct mmc *mmc)
 {
        if (mmc->cfg->ops->set_ios)
@@ -1084,7 +1111,6 @@ static int mmc_startup(struct mmc *mmc)
        struct mmc_cmd cmd;
        ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
        ALLOC_CACHE_ALIGN_BUFFER(u8, test_csd, MMC_MAX_BLOCK_LEN);
-       int timeout = 1000;
        bool has_parts = false;
        bool part_completed;
        struct blk_desc *bdesc;
@@ -1140,9 +1166,6 @@ static int mmc_startup(struct mmc *mmc)
 
        err = mmc_send_cmd(mmc, &cmd, NULL);
 
-       /* Waiting for the ready status */
-       mmc_send_status(mmc, timeout);
-
        if (err)
                return err;
 
@@ -1585,17 +1608,17 @@ static int mmc_send_if_cond(struct mmc *mmc)
        return 0;
 }
 
+#if !CONFIG_IS_ENABLED(DM_MMC)
 /* board-specific MMC power initializations. */
 __weak void board_mmc_power_init(void)
 {
 }
+#endif
 
 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)
+#if CONFIG_IS_ENABLED(DM_MMC)
+#if defined(CONFIG_DM_REGULATOR) && !defined(CONFIG_SPL_BUILD)
        struct udevice *vmmc_supply;
        int ret;
 
@@ -1611,6 +1634,13 @@ static int mmc_power_init(struct mmc *mmc)
                puts("Error enabling VMMC supply\n");
                return ret;
        }
+#endif
+#else /* !CONFIG_DM_MMC */
+       /*
+        * Driver model should use a regulator, as above, rather than calling
+        * out to board code.
+        */
+       board_mmc_power_init();
 #endif
        return 0;
 }
@@ -1622,7 +1652,7 @@ int mmc_start_init(struct mmc *mmc)
 
        /* we pretend there's no card when init is NULL */
        no_card = mmc_getcd(mmc) == 0;
-#ifndef CONFIG_DM_MMC_OPS
+#if !CONFIG_IS_ENABLED(DM_MMC_OPS)
        no_card = no_card || (mmc->cfg->ops->init == NULL);
 #endif
        if (no_card) {
@@ -1643,7 +1673,7 @@ int mmc_start_init(struct mmc *mmc)
        if (err)
                return err;
 
-#ifdef CONFIG_DM_MMC_OPS
+#if CONFIG_IS_ENABLED(DM_MMC_OPS)
        /* The device has already been probed ready for use */
 #else
        /* made sure it's not NULL earlier */
@@ -1708,8 +1738,8 @@ static int mmc_complete_init(struct mmc *mmc)
 int mmc_init(struct mmc *mmc)
 {
        int err = 0;
-       unsigned start;
-#ifdef CONFIG_DM_MMC
+       __maybe_unused unsigned start;
+#if CONFIG_IS_ENABLED(DM_MMC)
        struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc->dev);
 
        upriv->mmc = mmc;
@@ -1724,7 +1754,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;
 }
 
@@ -1751,12 +1783,12 @@ void mmc_set_preinit(struct mmc *mmc, int preinit)
        mmc->preinit = preinit;
 }
 
-#if defined(CONFIG_DM_MMC) && defined(CONFIG_SPL_BUILD)
+#if CONFIG_IS_ENABLED(DM_MMC) && defined(CONFIG_SPL_BUILD)
 static int mmc_probe(bd_t *bis)
 {
        return 0;
 }
-#elif defined(CONFIG_DM_MMC)
+#elif CONFIG_IS_ENABLED(DM_MMC)
 static int mmc_probe(bd_t *bis)
 {
        int ret, i;
@@ -1803,8 +1835,10 @@ int mmc_initialize(bd_t *bis)
                return 0;
        initialized = 1;
 
-#ifndef CONFIG_BLK
+#if !CONFIG_IS_ENABLED(BLK)
+#if !CONFIG_IS_ENABLED(MMC_TINY)
        mmc_list_init();
+#endif
 #endif
        ret = mmc_probe(bis);
        if (ret)
@@ -1817,3 +1851,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