From 48aae478a0f0542cd7a528fa7d67bead1704b8e4 Mon Sep 17 00:00:00 2001 From: Valentin Caron Date: Tue, 16 May 2023 18:01:29 +0200 Subject: [PATCH] mfd: stmfx: wait boot time after a regulator enable STMFX has a boot time of 10ms between reset and first register access. But this delay is not yet respected after a regulator_enable, and sometimes register access could failed with -ENXIO. As we cannot get the time since the regulator was enabled, we poll every 1ms the STMFX_REG_FW_VERSION_MSB, to wait the completed boot of chip. A timeout is set to 10ms. Signed-off-by: Valentin Caron Change-Id: I5563eb4d799ab40ca540a008f38518d0b086ca40 Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/306814 Reviewed-by: Antonio Maria BORNEO Reviewed-by: Amelie DELAUNAY ACI: CITOOLS ACI: CIBUILD Domain-Review: Amelie DELAUNAY --- drivers/mfd/stmfx.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c index 30f83efad318..eaf0d29e0258 100644 --- a/drivers/mfd/stmfx.c +++ b/drivers/mfd/stmfx.c @@ -304,6 +304,21 @@ irq_exit: return ret; } +static int stmfx_chip_wait_boot(struct stmfx *stmfx) +{ + unsigned long timeout_ms = 0; + unsigned int val; + int ret; + + while (1) { + ret = regmap_read(stmfx->map, STMFX_REG_FW_VERSION_MSB, &val); + if (ret != -ENXIO || timeout_ms > STMFX_BOOT_TIME_MS) + return ret; + mdelay(1); + timeout_ms++; + } +} + static int stmfx_chip_reset(struct stmfx *stmfx) { int ret; @@ -340,6 +355,11 @@ static int stmfx_chip_init(struct i2c_client *client) return ret; } } + ret = stmfx_chip_wait_boot(stmfx); + if (ret) { + dev_err(stmfx->dev, "Boot chip failed: %d\n", ret); + return ret; + } ret = regmap_read(stmfx->map, STMFX_REG_CHIP_ID, &id); if (ret) { @@ -513,6 +533,11 @@ static int stmfx_resume(struct device *dev) return ret; } } + ret = stmfx_chip_wait_boot(stmfx); + if (ret) { + dev_err(stmfx->dev, "Boot chip failed: %d\n", ret); + return ret; + } /* Reset STMFX - supply has been stopped during suspend */ ret = stmfx_chip_reset(stmfx);