From 2a8db47d13ccab9d8b5477e2f51e7302d74bac3b Mon Sep 17 00:00:00 2001 From: Shawn Lin Date: Thu, 20 Jul 2023 09:20:45 +0800 Subject: [PATCH] mmc: dw_mmc: Add some safe delay for releasing power leak Add some delay for some broken card which need long time to release the remain power leak. 200ms is very safe, no need to bother device tree property, as it depends on card not board. Fixes: 60c9e5240f35 ("mmc: dw_mmc: Add normal and idle pinctrl control") Change-Id: I5437945cd860674be860d246200e15eed9d91e03 Signed-off-by: Shawn Lin Signed-off-by: Yifeng Zhao --- drivers/mmc/host/dw_mmc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index fde49464a637..a88d9b908d97 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1468,7 +1468,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) { struct dw_mci_slot *slot = mmc_priv(mmc); const struct dw_mci_drv_data *drv_data = slot->host->drv_data; - u32 regs; + u32 regs, power_off_delay; int ret; switch (ios->bus_width) { @@ -1507,8 +1507,14 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) switch (ios->power_mode) { case MMC_POWER_UP: - if (!IS_ERR_OR_NULL(slot->host->pinctrl)) - pinctrl_select_state(slot->host->pinctrl, slot->host->idle_state); + if (dw_mci_get_cd(mmc) && !IS_ERR_OR_NULL(slot->host->pinctrl)) { + if (!pinctrl_select_state(slot->host->pinctrl, slot->host->idle_state)) { + if (device_property_read_u32(slot->host->dev, "power-off-delay-ms", + &power_off_delay)) + power_off_delay = 200; + msleep(power_off_delay); + } + } if (!IS_ERR(mmc->supply.vmmc)) { ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,