Commit 4e36c0f2 authored by Wolfram Sang's avatar Wolfram Sang Committed by Andi Shyti

i2c: rcar: bring hardware to known state when probing

When probing, the hardware is not brought into a known state. This may
be a problem when a hypervisor restarts Linux without resetting the
hardware, leaving an old state running. Make sure the hardware gets
initialized, especially interrupts should be cleared and disabled.
Reported-by: default avatarDirk Behme <dirk.behme@de.bosch.com>
Reported-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Closes: https://lore.kernel.org/r/20240702045535.2000393-1-dirk.behme@de.bosch.com
Fixes: 6ccbe607 ("i2c: add Renesas R-Car I2C driver")
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: default avatarAndi Shyti <andi.shyti@kernel.org>
parent 256abd8e
...@@ -257,6 +257,14 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv) ...@@ -257,6 +257,14 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv)
} }
} }
static void rcar_i2c_reset_slave(struct rcar_i2c_priv *priv)
{
rcar_i2c_write(priv, ICSIER, 0);
rcar_i2c_write(priv, ICSSR, 0);
rcar_i2c_write(priv, ICSCR, SDBS);
rcar_i2c_write(priv, ICSAR, 0); /* Gen2: must be 0 if not using slave */
}
static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv)
{ {
int ret; int ret;
...@@ -1033,11 +1041,8 @@ static int rcar_unreg_slave(struct i2c_client *slave) ...@@ -1033,11 +1041,8 @@ static int rcar_unreg_slave(struct i2c_client *slave)
/* ensure no irq is running before clearing ptr */ /* ensure no irq is running before clearing ptr */
disable_irq(priv->irq); disable_irq(priv->irq);
rcar_i2c_write(priv, ICSIER, 0); rcar_i2c_reset_slave(priv);
rcar_i2c_write(priv, ICSSR, 0);
enable_irq(priv->irq); enable_irq(priv->irq);
rcar_i2c_write(priv, ICSCR, SDBS);
rcar_i2c_write(priv, ICSAR, 0); /* Gen2: must be 0 if not using slave */
priv->slave = NULL; priv->slave = NULL;
...@@ -1152,7 +1157,9 @@ static int rcar_i2c_probe(struct platform_device *pdev) ...@@ -1152,7 +1157,9 @@ static int rcar_i2c_probe(struct platform_device *pdev)
goto out_pm_disable; goto out_pm_disable;
} }
rcar_i2c_write(priv, ICSAR, 0); /* Gen2: must be 0 if not using slave */ /* Bring hardware to known state */
rcar_i2c_init(priv);
rcar_i2c_reset_slave(priv);
if (priv->devtype < I2C_RCAR_GEN3) { if (priv->devtype < I2C_RCAR_GEN3) {
irqflags |= IRQF_NO_THREAD; irqflags |= IRQF_NO_THREAD;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment