Skip to contentSkip to conversation

i2c: imx_lpi2c: Fix MSR status check issue in STOP

PATCH In review Ye Li 4 participants 5 messages Apr 28 – May 9

Subsystems (2)
lore
Share & tools
lore

Ye Li

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/i2c/imx_lpi2c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/imx_lpi2c.c +3 -1
index a309fd6f07c..e2b4fd334ec 100644
@@ -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;
 }
 
Signature · 1 line
2.37.1
#1 lore raw

Hello Ye Li,

Quoted 23 lines · Ye Li

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.

---
  drivers/i2c/imx_lpi2c.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/imx_lpi2c.c +0 -0
index a309fd6f07c..e2b4fd334ec 100644

drivers/i2c/imx_lpi2c.c static int bus_i2c_stop(struct udevice *bus) · line 242

Quoted 4 lines
drivers/i2c/imx_lpi2c.c +0 -1
@@ -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?

Quoted 8 lines
drivers/i2c/imx_lpi2c.c +0 -0
  		/* 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");

drivers/i2c/imx_lpi2c.c static int bus_i2c_stop(struct udevice *bus) · line 261

Quoted 10 lines
drivers/i2c/imx_lpi2c.c +3 -0
+			result = imx_lpci2c_check_clear_error(regs);
  			return -ETIMEDOUT;
  		}
  	}
 
+	result = imx_lpci2c_check_clear_error(regs);
+
  	return result;
  }
 

bye,
Heiko

Signature · 5 lines
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic
Reviewed-by Heiko Schocher
#2 lore raw

Hi Heiko,

Quoted 21 lines · Heiko Schocher

Hello Ye Li,

Quoted 18 lines · Ye Li

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.

---
  drivers/i2c/imx_lpi2c.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

drivers/i2c/imx_lpi2c.c static int bus_i2c_stop(struct udevice *bus) · line 242

Quoted 9 lines
drivers/i2c/imx_lpi2c.c +0 -1
index a309fd6f07c..e2b4fd334ec 100644
@@ -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?

I find below commit in history, please take a look. If evaluate bits and return, it moves back to previous clock issue.

commit a32effd2838a62a5d1dcc01f613508f1d90b5667

Author: Gao Pan <[email protected]>
Date:   Sun Jul 8 11:46:41 2018 +0800

imx: lpi2c: fix clock issue when NACK detected

For LPI2C IP, NACK is detected by the rising edge of the ninth clock. In current uboot driver, once NACK is detected, it will reset and then disable LPI2C master. As a result, we can never see the falling edge of the ninth clock.

Best regards,
Ye Li

Quoted 19 lines
Quoted 6 lines
drivers/i2c/imx_lpi2c.c +0 -0
           /* 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) {

drivers/i2c/imx_lpi2c.c static int bus_i2c_stop(struct udevice *bus) · line 259

Quoted 10 lines
drivers/i2c/imx_lpi2c.c +3 -0
               debug("stop timeout\n");
+            result = imx_lpci2c_check_clear_error(regs);
               return -ETIMEDOUT;
           }
       }
+    result = imx_lpci2c_check_clear_error(regs);
+
       return result;
   }
 

bye,
Heiko

#3 lore raw

Hello Ye li,

Quoted 45 lines · Ye Li

Hi Heiko,

Quoted 21 lines · Heiko Schocher

Hello Ye Li,

Quoted 18 lines · Ye Li

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.

---
  drivers/i2c/imx_lpi2c.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

drivers/i2c/imx_lpi2c.c static int bus_i2c_stop(struct udevice *bus) · line 242

Quoted 9 lines
drivers/i2c/imx_lpi2c.c +0 -1
index a309fd6f07c..e2b4fd334ec 100644
@@ -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?

I find below commit in history, please take a look. If evaluate bits and return, it moves back to previous clock issue.

commit a32effd2838a62a5d1dcc01f613508f1d90b5667
Author: Gao Pan <[email protected]>
Date:   Sun Jul 8 11:46:41 2018 +0800

    imx: lpi2c: fix clock issue when NACK detected

Quoted 8 lines

    For LPI2C IP, NACK is detected by the rising edge of the ninth clock. In current uboot driver, once NACK is detected, it will reset and then disable LPI2C master. As a result, we can never see the falling edge of the ninth clock.

Ah, okay. May Peng or Gao (added to this thread) can than review your patch.

Thanks for the hint!

bye,
Heiko

Quoted 25 lines

Best regards,
Ye Li

Quoted 19 lines
Quoted 6 lines
drivers/i2c/imx_lpi2c.c +0 -0
           /* 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) {

drivers/i2c/imx_lpi2c.c static int bus_i2c_stop(struct udevice *bus) · line 259

Quoted 10 lines
drivers/i2c/imx_lpi2c.c +3 -0
               debug("stop timeout\n");
+            result = imx_lpci2c_check_clear_error(regs);
               return -ETIMEDOUT;
           }
       }
+    result = imx_lpci2c_check_clear_error(regs);
+
       return result;
   }
 

bye,
Heiko

Signature · 5 lines
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic
Reviewed-by on v1 1/1
#4 lore raw
In reply to Ye Li
Quoted 13 lines · Ye Li

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.

Quoted 1 line