[PATCH 2/3] Fix a timeout problem of the interrupt driven i2c-transfer of the SAA7146

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

the attached patch adds a timeout to the waiting for an interrupt after the executing of an i2c-operation. This prevents
 against a endless waiting, if the SAA7146 does not hit the interrupt.

This patch needs my previous patch.

- Hartmut

Signed-of-by: Hartmut Birr <e9hack@xxxxxxxxxxxxxx>

Add a timeout to the wait for the i2c-interrupt. 
The interrupt may never hit. The timeout prevents from endless waiting.

diff -r 5e9d301ef13b linux/drivers/media/common/saa7146_i2c.c
--- a/linux/drivers/media/common/saa7146_i2c.c	Thu Oct 26 10:10:56 2006 -0300
+++ b/linux/drivers/media/common/saa7146_i2c.c	Sat Oct 28 10:03:44 2006 +0200
@@ -193,10 +193,22 @@ static int saa7146_i2c_writeout(struct s
 		SAA7146_IER_ENABLE(dev, MASK_16|MASK_17);
 		saa7146_write(dev, MC2, (MASK_00 | MASK_16));
 
-		wait_event_interruptible(dev->i2c_wq, dev->i2c_op == 0);
-		if (signal_pending (current)) {
-			/* a signal arrived */
-			return -ERESTARTSYS;
+		timeout = HZ/100 + 1; /* 10ms */
+		timeout = wait_event_interruptible_timeout(dev->i2c_wq, dev->i2c_op == 0, timeout);
+		if (timeout == -ERESTARTSYS || dev->i2c_op) {
+			spin_lock_irqsave(&dev->slock, flags);
+			SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
+			saa7146_write(dev, ISR, MASK_16|MASK_17);
+			spin_unlock_irqrestore(&dev->slock, flags);
+			if (timeout == -ERESTARTSYS) {
+				/* a signal arrived */
+				return -ERESTARTSYS;
+			}
+			/* this is normal when probing the bus
+			 * (no answer from nonexisistant device...)
+			 */
+			DEB_I2C(("saa7146_i2c_writeout: timed out waiting for end of xfer\n"));
+			return -EIO;
 		}
 		status = saa7146_read(dev, I2C_STATUS);
 	} else {
_______________________________________________
linux-dvb mailing list
linux-dvb@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb

[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux