[PATCH v2 2/5] mmc: mmci: stm32: release the delay block before enabling it

From: Mateusz Nowicki

Date: Wed Nov 04 2026 - 10:34:10 EST


From: Christophe Kerello <christophe.kerello@xxxxxxxxxxx>

The delay block must be locked on the last frequency set. To avoid it
staying locked on a frequency used before, disable it first and wait for
the lock to drop before enabling it again.

Fixes: b5c3eb385797 ("mmc: mmci: stm32: add delay block support for STM32MP25")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Christophe Kerello <christophe.kerello@xxxxxxxxxxx>
[Mateusz: reworded the commit message, added Fixes and Cc stable]
Signed-off-by: Mateusz Nowicki <mateusz.nowicki@xxxxxxxxxx>
---

Notes:
On the STM32MP257F-DK eMMC in HS200 at 150 MHz, switching from DDR52 to
HS200 made the tuning pick a wrong phase in 9 of 18 tries without this
change, the phase was right in all 12 tries with it.

drivers/mmc/host/mmci_stm32_sdmmc.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c
index 9dc51859c2e5..bb058e0910ad 100644
--- a/drivers/mmc/host/mmci_stm32_sdmmc.c
+++ b/drivers/mmc/host/mmci_stm32_sdmmc.c
@@ -537,10 +537,20 @@ static int sdmmc_dlyb_mp15_prepare(struct mmci_host *host)
static int sdmmc_dlyb_mp25_enable(struct sdmmc_dlyb *dlyb)
{
u32 cr, sr;
+ int ret;

cr = readl_relaxed(dlyb->base + SYSCFG_DLYBSD_CR);
- cr |= DLYBSD_CR_EN;

+ cr &= ~DLYBSD_CR_EN;
+ writel_relaxed(cr, dlyb->base + SYSCFG_DLYBSD_CR);
+
+ ret = readl_relaxed_poll_timeout(dlyb->base + SYSCFG_DLYBSD_SR,
+ sr, !(sr & DLYBSD_SR_LOCK), 1,
+ DLYBSD_TIMEOUT_1S_IN_US);
+ if (ret)
+ return ret;
+
+ cr |= DLYBSD_CR_EN;
writel_relaxed(cr, dlyb->base + SYSCFG_DLYBSD_CR);

return readl_relaxed_poll_timeout(dlyb->base + SYSCFG_DLYBSD_SR,
--
2.56.0