[PATCH] i2c: imx_lpi2c: Fix MSR status check issue in STOP

Heiko Schocher hs at nabladev.com
Tue Apr 28 11:55:08 CEST 2026


Hello Ye Li,

On 28.04.26 10:53, Ye Li wrote:
> 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 at nxp.com>
> ---
>   drivers/i2c/imx_lpi2c.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c
> index a309fd6f07c..e2b4fd334ec 100644
> --- a/drivers/i2c/imx_lpi2c.c
> +++ b/drivers/i2c/imx_lpi2c.c
> @@ -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);

Wouldn;t it be better to evaluate bits in result too, and return
if error bits found?

>   		/* 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;
>   }
>   
> 

bye,
Heiko
-- 
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: office at nabladev.com
Geschäftsführer : Stefano Babic


More information about the U-Boot mailing list