]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
i2c: imx_lpi2c: Fix MSR status check issue in STOP
authorYe Li <ye.li@nxp.com>
Tue, 28 Apr 2026 08:53:12 +0000 (16:53 +0800)
committerFabio Estevam <festevam@gmail.com>
Fri, 15 May 2026 20:31:39 +0000 (17:31 -0300)
In bus_i2c_stop, the MSR SDF is checked in a loop after stop command
is sent. Meanwhile, some error status in MSR is also checked by
imx_lpci2c_check_clear_error. But the imx_lpci2c_check_clear_error
will clear the MSR.

It causes problem in below situation:
In current loop, SDF does not set, but error status is found by
imx_lpci2c_check_clear_error (for example, NDF), then NDF will be cleared
and result has NDF error. However, because SDF does not set in this loop,
it goes not next loop. When SDF is set in next loop,
imx_lpci2c_check_clear_error is re-executed, but as the MSR is cleared,
the result is 0. Then the stop return 0. But it should return NDF error.

Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
drivers/i2c/imx_lpi2c.c

index a309fd6f07ce0dad22ae49bb4414c6e331b29927..e2b4fd334ecbcb966bbeda17c74fe2d49d3e9cd1 100644 (file)
@@ -239,7 +239,6 @@ static int bus_i2c_stop(struct udevice *bus)
        start_time = get_timer(0);
        while (1) {
                status = readl(&regs->msr);
-               result = imx_lpci2c_check_clear_error(regs);
                /* stop detect flag */
                if (status & LPI2C_MSR_SDF_MASK) {
                        /* clear stop flag */
@@ -250,10 +249,13 @@ static int bus_i2c_stop(struct udevice *bus)
 
                if (get_timer(start_time) > LPI2C_NACK_TOUT_MS) {
                        debug("stop timeout\n");
+                       result = imx_lpci2c_check_clear_error(regs);
                        return -ETIMEDOUT;
                }
        }
 
+       result = imx_lpci2c_check_clear_error(regs);
+
        return result;
 }