diff mbox

omap i2c: add timeout to a busy loop in isr

Message ID 1260796864-8560-1-git-send-email-virtuoso@slind.org (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Alexander Shishkin Dec. 14, 2009, 1:21 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 75bf3ad..7617f18 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -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);