From patchwork Sat Jan 4 10:55:51 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: 3433461 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 A4D2DC02DD for ; Sat, 4 Jan 2014 13:59:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D109320138 for ; Sat, 4 Jan 2014 13:59:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFA0620136 for ; Sat, 4 Jan 2014 13:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753236AbaADN7l (ORCPT ); Sat, 4 Jan 2014 08:59:41 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:43697 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753625AbaADN7S (ORCPT ); Sat, 4 Jan 2014 08:59:18 -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 1VzRkz-00013s-VQ; Sat, 04 Jan 2014 13:59:18 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1VzOtV-0003l5-P5; Sat, 04 Jan 2014 08:55:53 -0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH v4 22/22] [media] em28xx: retry read operation if it fails Date: Sat, 4 Jan 2014 08:55:51 -0200 Message-Id: <1388832951-11195-23-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1388832951-11195-1-git-send-email-m.chehab@samsung.com> References: <1388832951-11195-1-git-send-email-m.chehab@samsung.com> 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 I2C read operations can also take some time to happen. Try again, if it fails with return code different than 0x10 until timeout. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/em28xx/em28xx-i2c.c | 62 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c index e030e0b7d645..6cd3d909bb3a 100644 --- a/drivers/media/usb/em28xx/em28xx-i2c.c +++ b/drivers/media/usb/em28xx/em28xx-i2c.c @@ -237,6 +237,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf, */ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len) { + unsigned long timeout = jiffies + msecs_to_jiffies(EM2800_I2C_XFER_TIMEOUT); int ret; if (len < 1 || len > 64) @@ -246,39 +247,44 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len) * Zero length reads always succeed, even if no device is connected */ - /* Read data from i2c device */ - ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); - if (ret < 0) { - em28xx_warn("reading from i2c device at 0x%x failed (error=%i)\n", - addr, ret); - return ret; - } - /* - * NOTE: some devices with two i2c busses have the bad habit to return 0 - * bytes if we are on bus B AND there was no write attempt to the - * specified slave address before AND no device is present at the - * requested slave address. - * Anyway, the next check will fail with -EREMOTEIO in this case, so avoid - * spamming the system log on device probing and do nothing here. - */ + do { + /* Read data from i2c device */ + ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); + if (ret < 0) { + em28xx_warn("reading from i2c device at 0x%x failed (error=%i)\n", + addr, ret); + return ret; + } + /* + * NOTE: some devices with two i2c busses have the bad habit to return 0 + * bytes if we are on bus B AND there was no write attempt to the + * specified slave address before AND no device is present at the + * requested slave address. + * Anyway, the next check will fail with -EREMOTEIO in this case, so avoid + * spamming the system log on device probing and do nothing here. + */ + + /* Check success of the i2c operation */ + ret = dev->em28xx_read_reg(dev, 0x05); + if (ret == 0) /* success */ + return len; + if (ret < 0) { + em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n", + ret); + return ret; + } + if (ret != 0x10) + break; + msleep(5); + } while (time_is_after_jiffies(timeout)); - /* Check success of the i2c operation */ - ret = dev->em28xx_read_reg(dev, 0x05); - if (ret == 0) /* success */ - return len; - if (ret < 0) { - em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n", - ret); - return ret; - } if (ret == 0x10) { if (i2c_debug) - em28xx_warn("I2C transfer timeout on writing to addr 0x%02x", + em28xx_warn("I2C transfer timeout on reading from addr 0x%02x", addr); - return -EREMOTEIO; + } else { + em28xx_warn("unknown i2c error (status=%i)\n", ret); } - - em28xx_warn("unknown i2c error (status=%i)\n", ret); return -EREMOTEIO; }