All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout
@ 2014-01-04 11:09 Mauro Carvalho Chehab
  2014-01-04 11:09 ` [PATCH v4 RFC 2/2] [media] em28xx: USB: adjust for changed 3.8 USB API Mauro Carvalho Chehab
  2014-01-04 17:58 ` [PATCH v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout Markus Rechberger
  0 siblings, 2 replies; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2014-01-04 11:09 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

At least on HVR-950, sometimes an I2C operation fails.

This seems to be more frequent when the device is connected
into an USB 3.0 port.

Instead of report an error, try to repeat it, for up to
20 ms. That makes the code more reliable.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c
index 6cd3d909bb3a..35d6808aa9ff 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -189,6 +189,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
 	 * Zero length reads always succeed, even if no device is connected
 	 */
 
+retry:
 	/* Write to i2c device */
 	ret = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
 	if (ret != len) {
@@ -208,26 +209,24 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
 		ret = dev->em28xx_read_reg(dev, 0x05);
 		if (ret == 0) /* success */
 			return len;
-		if (ret == 0x10) {
-			em28xx_warn("I2C transfer timeout on writing to addr 0x%02x",
-				    addr);
-			return -EREMOTEIO;
-		}
+		if (ret == 0x10)
+			goto retry;
 		if (ret < 0) {
 			em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n",
 				    ret);
 			return ret;
 		}
 		msleep(5);
-		/*
-		 * NOTE: do we really have to wait for success ?
-		 * Never seen anything else than 0x00 or 0x10
-		 * (even with high payload) ...
-		 */
 	}
 
-	if (i2c_debug)
-		em28xx_warn("write to i2c device at 0x%x timed out\n", addr);
+	if (ret == 0x10) {
+		if (i2c_debug)
+			em28xx_warn("I2C transfer timeout on writing to addr 0x%02x",
+				    addr);
+	} else {
+		em28xx_warn("write to i2c device at 0x%x timed out (ret=0x%02x)\n",
+			    addr, ret);
+	}
 	return -EREMOTEIO;
 }
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-05 21:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-04 11:09 [PATCH v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout Mauro Carvalho Chehab
2014-01-04 11:09 ` [PATCH v4 RFC 2/2] [media] em28xx: USB: adjust for changed 3.8 USB API Mauro Carvalho Chehab
2014-01-04 17:58 ` [PATCH v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout Markus Rechberger
2014-01-05 21:15   ` Frank Schäfer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.