From patchwork Sat Jan 4 11:09:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 3434011 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 83B55C02DC for ; Sat, 4 Jan 2014 17:26:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BDF8A20158 for ; Sat, 4 Jan 2014 17:26:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F37CD20145 for ; Sat, 4 Jan 2014 17:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754774AbaADR0O (ORCPT ); Sat, 4 Jan 2014 12:26:14 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:44196 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754814AbaADR0M (ORCPT ); Sat, 4 Jan 2014 12:26:12 -0500 Received: from [177.143.150.208] (helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1VzUzC-0008VZ-0B; Sat, 04 Jan 2014 17:26:10 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1VzP6Z-00065C-1q; Sat, 04 Jan 2014 09:09:23 -0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout Date: Sat, 4 Jan 2014 09:09:19 -0200 Message-Id: <1388833760-23260-1-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.3.1 To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }