From patchwork Fri Sep 23 12:04:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 76839 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp528945qgf; Fri, 23 Sep 2016 05:02:43 -0700 (PDT) X-Received: by 10.98.13.73 with SMTP id v70mr11652563pfi.149.1474632163224; Fri, 23 Sep 2016 05:02:43 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si7710635paf.87.2016.09.23.05.02.42; Fri, 23 Sep 2016 05:02:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759509AbcIWMCk (ORCPT + 27 others); Fri, 23 Sep 2016 08:02:40 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:21734 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752772AbcIWMCi (ORCPT ); Fri, 23 Sep 2016 08:02:38 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id u8NC1oGq014030; Fri, 23 Sep 2016 21:01:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u8NC1oGq014030 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1474632111; bh=plpune5ID7i05ap10w+ZhyuOOyHyY3aDDfGELX+rLjw=; h=From:To:Cc:Subject:Date:From; b=bCyRechxBku6O+j1Q1JXohv9LKEwC4gEyolbos7Af2QJa7RzS4uV19pcoHb8F+vkz JWi8az+nHx91SAEM97Z9w3VlZOsqPdJKNoecCvHb1iAJa3qw0xTzR16VUeRxEouVo2 7484bHm0ei1xW2jyWKbm1U2Z175dtGnyVgfbGJkf5bMcxshCVlmv4eql5pwSObB789 SdQ2E/jOaGbg9q+zSGfq1DrxN0s4jy0jT33Jz+0w1/hJ0TjOk9/x08vYM9rawF32DL D7o1UhiR6dLCJFhztoAAjp0YZT3mnLMiTQZGrduvXJWOqGeZ5M9VyXKVipgTapQgGE Ni60QcWESHcIQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-i2c@vger.kernel.org Cc: Masahiro Yamada , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Wolfram Sang Subject: [PATCH] i2c: uniphier-f: fix misdetection of incomplete STOP condition Date: Fri, 23 Sep 2016 21:04:01 +0900 Message-Id: <1474632241-10440-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the status register FI2C_SR is checked immediately after a STOP condition is issued in case of the deferred STOP condition. It takes typically 5-10 usec until the corresponding bits in the register are set, so the error check for "stop condition was not completed" is very likely to be false positive. Add wait code to relax the status register check. Signed-off-by: Masahiro Yamada --- drivers/i2c/busses/i2c-uniphier-f.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index 829df91..e5886eb 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -348,10 +349,19 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, dev_dbg(&adap->dev, "complete\n"); if (unlikely(priv->flags & UNIPHIER_FI2C_DEFER_STOP_COMP)) { - u32 status = readl(priv->membase + UNIPHIER_FI2C_SR); + time_left = 20; - if (!(status & UNIPHIER_FI2C_SR_STS) || - status & UNIPHIER_FI2C_SR_BB) { + while (--time_left) { + u32 status = readl(priv->membase + UNIPHIER_FI2C_SR); + + if ((status & UNIPHIER_FI2C_SR_STS) && + !(status & UNIPHIER_FI2C_SR_BB)) + break; + + udelay(1); + } + + if (!time_left) { dev_err(&adap->dev, "stop condition was not completed.\n"); uniphier_fi2c_recover(priv);