Parse power-off-delay-us once in mmc_of_parse() and wait at the end of
mmc_power_off(). The delay was compiled in only with DM_REGULATOR, so a
board that set the property in a build without regulator support never
waited. The default stays 0; mmc_power_cycle() already waits 2 ms
before power-on.

Signed-off-by: Tanmay Kathpalia <[email protected]>
---
 drivers/mmc/mmc-uclass.c | 3 +++
 drivers/mmc/mmc.c        | 9 +++------
 include/mmc.h            | 7 +++++++
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index cd930807802..5f28469f6c5 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -296,6 +296,9 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config 
*cfg)
                                    MMC_MODE_HS400 | MMC_MODE_HS400_ES);
        }
 
+       cfg->power_off_delay_us = dev_read_u32_default(dev,
+                                                      "power-off-delay-us", 0);
+
        return 0;
 }
 
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index a619440fc4c..be41b925bcc 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2910,7 +2910,7 @@ static int mmc_power_on(struct mmc *mmc)
 
 static int mmc_power_off(struct mmc *mmc)
 {
-       __maybe_unused u32 delay_us = 0;
+       unsigned int delay_us = mmc->cfg->power_off_delay_us;
 
        mmc_set_clock(mmc, 0, MMC_CLK_DISABLE);
 #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)
@@ -2933,13 +2933,10 @@ static int mmc_power_off(struct mmc *mmc)
                        return ret;
                }
        }
-
-       if (mmc->dev)
-               dev_read_u32(mmc->dev, "power-off-delay-us", &delay_us);
-
+#endif
        if (delay_us)
                udelay(delay_us);
-#endif
+
        return 0;
 }
 
diff --git a/include/mmc.h b/include/mmc.h
index 9a796e0655f..1e054a228c2 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -628,6 +628,13 @@ struct mmc_config {
 #if CONFIG_IS_ENABLED(MMC_PWRSEQ)
        struct udevice *pwr_dev;
 #endif
+       /*
+        * Extra discharge delay at the end of mmc_power_off(), in
+        * microseconds. Default 0. Boards with slow RC discharge on MMC
+        * VDD set this via "power-off-delay-us". mmc_power_cycle() already
+        * waits 2 ms before power-on, so this is additional time only.
+        */
+       unsigned int power_off_delay_us;
 };
 
 struct sd_ssr {
-- 
2.43.7

Reply via email to