mmc: add a reinit() API
authorYangbo Lu <yangbo.lu@nxp.com>
Tue, 1 Sep 2020 08:57:59 +0000 (16:57 +0800)
committerPeng Fan <peng.fan@nxp.com>
Mon, 12 Oct 2020 07:45:39 +0000 (15:45 +0800)
For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/mmc/mmc-uclass.c
drivers/mmc/mmc.c
include/mmc.h

index 90690c8..b90e1ee 100644 (file)
@@ -171,6 +171,21 @@ int mmc_deferred_probe(struct mmc *mmc)
        return dm_mmc_deferred_probe(mmc->dev);
 }
 
+int dm_mmc_reinit(struct udevice *dev)
+{
+       struct dm_mmc_ops *ops = mmc_get_ops(dev);
+
+       if (ops->reinit)
+               return ops->reinit(dev);
+
+       return 0;
+}
+
+int mmc_reinit(struct mmc *mmc)
+{
+       return dm_mmc_reinit(mmc->dev);
+}
+
 int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
 {
        int val;
index d79cdef..0727505 100644 (file)
@@ -2816,13 +2816,17 @@ int mmc_get_op_cond(struct mmc *mmc)
                return err;
 
 #if CONFIG_IS_ENABLED(DM_MMC)
-       /* The device has already been probed ready for use */
+       /*
+        * Re-initialization is needed to clear old configuration for
+        * mmc rescan.
+        */
+       err = mmc_reinit(mmc);
 #else
        /* made sure it's not NULL earlier */
        err = mmc->cfg->ops->init(mmc);
+#endif
        if (err)
                return err;
-#endif
        mmc->ddr_mode = 0;
 
 retry:
index 75bcaaf..93494d9 100644 (file)
@@ -422,6 +422,14 @@ struct dm_mmc_ops {
         */
        int (*deferred_probe)(struct udevice *dev);
        /**
+        * reinit() - Re-initialization to clear old configuration for
+        * mmc rescan.
+        *
+        * @dev:        Device to reinit
+        * @return 0 if Ok, -ve if error
+        */
+       int (*reinit)(struct udevice *dev);
+       /**
         * send_cmd() - Send a command to the MMC device
         *
         * @dev:        Device to receive the command
@@ -518,6 +526,7 @@ int dm_mmc_execute_tuning(struct udevice *dev, uint opcode);
 int dm_mmc_wait_dat0(struct udevice *dev, int state, int timeout_us);
 int dm_mmc_host_power_cycle(struct udevice *dev);
 int dm_mmc_deferred_probe(struct udevice *dev);
+int dm_mmc_reinit(struct udevice *dev);
 int dm_mmc_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt);
 
 /* Transition functions for compatibility */
@@ -529,6 +538,7 @@ int mmc_wait_dat0(struct mmc *mmc, int state, int timeout_us);
 int mmc_set_enhanced_strobe(struct mmc *mmc);
 int mmc_host_power_cycle(struct mmc *mmc);
 int mmc_deferred_probe(struct mmc *mmc);
+int mmc_reinit(struct mmc *mmc);
 int mmc_get_b_max(struct mmc *mmc, void *dst, lbaint_t blkcnt);
 
 #else