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 <valentin.caron@foss.st.com>
Change-Id: I5563eb4d799ab40ca540a008f38518d0b086ca40
Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/306814
Reviewed-by: Antonio Maria BORNEO <antonio.borneo@foss.st.com>
Reviewed-by: Amelie DELAUNAY <amelie.delaunay@foss.st.com>
ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com>
ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
Domain-Review: Amelie DELAUNAY <amelie.delaunay@foss.st.com>
This commit is contained in:
Valentin Caron
2023-05-16 18:01:29 +02:00
committed by Eric Fourmont
parent 0eee85f10b
commit 48aae478a0

View File

@ -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);