]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
i2c: npcm: fix consecutive dm_i2c_read/write error
authorStanley Chu <yschu@nuvoton.com>
Thu, 7 Aug 2025 05:32:20 +0000 (13:32 +0800)
committerTom Rini <trini@konsulko.com>
Mon, 18 Aug 2025 22:40:23 +0000 (16:40 -0600)
When doing a dm_i2c_read followed by a dm_i2c_write, the subsequent
transaction may get npcm_i2c_check_sda error because the module is
still busy in STOP condition in previous dm_i2c_read.
Always check and wait for module to be out of busy before starting
an i2c transaction.

Signed-off-by: Stanley Chu <yschu@nuvoton.com>
Signed-off-by: Jim Liu <JJLIU0@nuvoton.com>
drivers/i2c/npcm_i2c.c

index c64752e1467e9e80c93a074b2319bf2e76bfe025..bff0d04f1a5ae2c261657a5776b38e4ab6ad4d28 100644 (file)
@@ -34,6 +34,7 @@
 #define SMBCTL3_SDA_LVL                BIT(6)
 
 /* SMBCST */
+#define SMBCST_BUSY            BIT(0)
 #define SMBCST_BB              BIT(1)
 #define SMBCST_TGSCL           BIT(5)
 
@@ -479,11 +480,17 @@ static int npcm_i2c_xfer(struct udevice *dev,
        struct npcm_i2c_bus *bus = dev_get_priv(dev);
        struct npcm_i2c_regs *reg = bus->reg;
        int ret = 0, err = 0;
+       u8 val;
 
        if (nmsgs < 1 || nmsgs > 2) {
                printf("%s: commands not support\n", __func__);
                return -EREMOTEIO;
        }
+
+       /* Wait for module out of busy */
+       if (readb_poll_timeout(&reg->cst, val, !(val & SMBCST_BUSY), 1000))
+               return -EBUSY;
+
        /* clear ST register */
        writeb(0xFF, &reg->st);