Skip to contentSkip to conversation

omap i2c: add timeout to a busy loop in isr

PATCH In review Alexander Shishkin 2 participants 2 messages Dec 14, 2009 – Dec 15, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 omap i2c: add timeout to a busy loop in isr

---
 drivers/i2c/busses/i2c-omap.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)
drivers/i2c/busses/i2c-omap.c +13 -8
index 75bf3ad..7617f18 100644
@@ -803,15 +803,20 @@ complete:
 				 */
 
 				if (dev->rev <= OMAP_I2C_REV_ON_3430) {
-						while (!(stat & OMAP_I2C_STAT_XUDF)) {
-							if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
-								omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
-								err |= OMAP_I2C_STAT_XUDF;
-								goto complete;
-							}
-							cpu_relax();
-							stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+					unsigned long timeout = 10000;
+
+					while (!(stat & OMAP_I2C_STAT_XUDF) && --timeout) {
+						if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
+							omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
+							err |= OMAP_I2C_STAT_XUDF;
+							goto complete;
 						}
+						cpu_relax();
+						stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+					}
+
+					if (!timeout)
+						dev_err(dev->dev, "timeout waiting on XUDF bit\n");
 				}
 
 				omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
Signature · 1 line
1.6.3.3
Tested-by on v1 1/1
#1 lore raw

Hi,

Quoted 1 line · Alexander Shishkin

Could you add a better patch description? I.e. the patch is needed because I2C failure can cause a kernel hang. The problem can be reproduced by running the bus with wrong (too high) speed.

Also, you should send the patch to [email protected] with linux-omap and [email protected] in CC.

Quoted 10 lines
 drivers/i2c/busses/i2c-omap.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)
drivers/i2c/busses/i2c-omap.c +0 -0
index 75bf3ad..7617f18 100644
@@ -803,15 +803,20 @@ complete:
 				 */
 

drivers/i2c/busses/i2c-omap.c complete: · line 806

Quoted 10 lines
drivers/i2c/busses/i2c-omap.c +1 -8
 				if (dev->rev <= OMAP_I2C_REV_ON_3430) {
-						while (!(stat & OMAP_I2C_STAT_XUDF)) {
-							if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
-								omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
-								err |= OMAP_I2C_STAT_XUDF;
-								goto complete;
-							}
-							cpu_relax();
-							stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+					unsigned long timeout = 10000;

I think 10000 reads (with L4 core interconnect latency) is at least 0.8 ms. It should be more than enough for normal cases.

Quoted 5 lines
drivers/i2c/busses/i2c-omap.c +5 -0
+					while (!(stat & OMAP_I2C_STAT_XUDF) && --timeout) {
+						if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
+							omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
+							err |= OMAP_I2C_STAT_XUDF;
+							goto complete;

drivers/i2c/busses/i2c-omap.c complete: · line 822

Quoted 10 lines
drivers/i2c/busses/i2c-omap.c +6 -0
 						}
+						cpu_relax();
+						stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+					}
+
+					if (!timeout)
+						dev_err(dev->dev, "timeout waiting on XUDF bit\n");
 				}
 
 				omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);

A.