i2c: imx_lpi2c: Fix MSR status check issue in STOP

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>
This commit is contained in:
Ye Li
2026-05-15 17:31:39 -03:00
committed by Fabio Estevam
parent 39f52b7c29
commit 6bc840568f
+3 -1
View 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;
}