]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
i2c: npcm: Add clock toggle recovery
authorTali Perry <tali.perry1@gmail.com>
Fri, 28 Mar 2025 19:32:50 +0000 (19:32 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:05:31 +0000 (11:05 +0100)
[ Upstream commit 38010591a0fc3203f1cee45b01ab358b72dd9ab2 ]

During init of the bus, the module checks that the bus is idle.
If one of the lines are stuck try to recover them first before failing.
Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

Signed-off-by: Tali Perry <tali.perry1@gmail.com>
Signed-off-by: Mohammed Elbadry <mohammed.0.elbadry@gmail.com>
Reviewed-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
Link: https://lore.kernel.org/r/20250328193252.1570811-1-mohammed.0.elbadry@gmail.com
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/i2c/busses/i2c-npcm7xx.c

index d97694ac29ca90ea566099940c1dc5fbdc66d9db..3f30c3cff7201d2197fdbb6a1938c06ca00f42df 100644 (file)
@@ -1950,10 +1950,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
        /* check HW is OK: SDA and SCL should be high at this point. */
        if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-               dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-               dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-                       npcm_i2c_get_SCL(&bus->adap));
-               return -ENXIO;
+               dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,
+                                npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+               if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+                       dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+                               bus->num, npcm_i2c_get_SDA(&bus->adap),
+                               npcm_i2c_get_SCL(&bus->adap));
+                       return -ENXIO;
+               }
        }
 
        npcm_i2c_int_enable(bus, true);