From patchwork Thu Sep 5 16:17:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 173161 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp935248ilq; Thu, 5 Sep 2019 09:18:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+pRhKYuEnvE3CThgimIVw5TpRtan8ZWwhAGnST8wCob248r0dzc29cHNB215HtFaBP1P6 X-Received: by 2002:a63:cc14:: with SMTP id x20mr4011220pgf.142.1567700306199; Thu, 05 Sep 2019 09:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567700306; cv=none; d=google.com; s=arc-20160816; b=IgS9uFhb5TPg8N51U2c2mYrRKFtgyeT1/SYJXRfmyYqyOSui3XNqK/VHS6c9aRYwsG SxY7n3pB5yIBGYE+rYxwDLm4hsKLiqFNI7nga1p6mUbHzQ4kaRqg6ginJaeIjzR7q691 fhNOyXU5aclB7Yw09EaJzLugsszLRZV99AcdDDNRKMPt2cEMMzPNYHljr16pGLtBDvto x55oWN8InbPBP0R/lU0R6BxX7DQbpLVEfM60hvZTOG5NBpUJZyTzFjr7UdGd6MooxgB3 qBrJg1pY402ZIxokwrVSNnk2IPnJnlqPrnE3HLrmcnXs+cDcfnriFAQDV0xG72gpMKsF Nshw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=hTEru9Lo54OU309HOwpQ2LAFUsKEGLtu5GnynJbae0I=; b=V9mWPrDbCFux0lCT0bFNYxuN1JC1b2LjS9L0ObgKfC3L4IZpjLA4p8wcApUjkX30dH pRShq8IQircHNSYMGDoPgLLGI/+eaGRnSU90zmpYQHHf+CVK8Ccy5Ta1t7p6Gbl8llwY rfq1rceyr0A9ohIRqiIMxe3TP2xfjdYiPpLVlioAYM3QpWMPJLZcBQBpV3rA51j95R5p j/svh7ep5N8o31oTSlqQiFVda74DaY9Ie5bFuni07AJ6Rva0f9mObV0mIryg62V21a3g GMNqImcgFQwxkdqZzJkN5l/EsVdbYbp+aDEpyKPEgj6ZSkbzdcl8+u4ERL3GxWxOQtu6 y+JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UXrdRBNR; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13si2148057pgr.460.2019.09.05.09.18.26; Thu, 05 Sep 2019 09:18:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-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=@linaro.org header.s=google header.b=UXrdRBNR; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388874AbfIEQSY (ORCPT + 5 others); Thu, 5 Sep 2019 12:18:24 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37751 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388740AbfIEQSW (ORCPT ); Thu, 5 Sep 2019 12:18:22 -0400 Received: by mail-pf1-f194.google.com with SMTP id y9so2078993pfl.4 for ; Thu, 05 Sep 2019 09:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hTEru9Lo54OU309HOwpQ2LAFUsKEGLtu5GnynJbae0I=; b=UXrdRBNRv4eBFBI2US9eb56BJw2QFySRmdCdiI/+LAIvG/m2c60c9K3NqHc9JzTcvb d8dwqHteqwZIJwmYizpsubVkvO7TeVXDOVTe6aX5zdW2UD3IAtqJ/uiyS9Lx2SPK8Tif Ec3qJAS3tr4mZ7bec9KhbwJfgkz2i4i8m38SHu1mvaoBC5wPzGtmlDymSmvre0XS7bbB i4Ro8UZZSf2iDGafbRHglF0mzarE9YVWxA+kdHTx/AktvE3YQZ90hkW58NANUCfMxmkq vIUoM/uekP6tFp8QDwySUHFho1wZKNrREHBB6M0EcCmSSQ1TR8BMwXKfB/JtNSwWr7kI o+bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hTEru9Lo54OU309HOwpQ2LAFUsKEGLtu5GnynJbae0I=; b=rR0V2Jo375shssr04SDGhzY1jLshfTHqHsBSnDPzkgYYgqaAikHUOeJphGF5AEo76T AW8xvivzQS6Ea/3rwMlGY/LlrgyHHcZ07F10zgVbl865m0o5f/173dfzx8TvhZjlUXAq UnlQoky/siheIEb+xARHKvscwpDlJ1pnWzRV3odbaGFsRIPNKPHUX61YBj7kDM7tHFG4 iZhxWl8YLyvIAS9VSGCfvabwFwP6rhD6fUSFKq4M8QHa6Bjd+i58d43CQyDW5NDgldvu eUkdBiZCYa0vu5tA7BYzJkEUpLbfXbxqVteAn3SleocxO6QKbB7mTqrhXoKdrHYM+xG8 XhWA== X-Gm-Message-State: APjAAAXjSnZr+jD78TjFO1ahgcYgNpeQDakbptM6hI9Lf9R5lNBEm4Nv dXtlipzEG5hEPyOmRYmXv5JRwA== X-Received: by 2002:a63:a35c:: with SMTP id v28mr3980810pgn.144.1567700301882; Thu, 05 Sep 2019 09:18:21 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m129sm6324005pga.39.2019.09.05.09.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2019 09:18:21 -0700 (PDT) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [BACKPORT 4.14.y 17/18] i2c: omap: Trigger bus recovery in lockup case Date: Thu, 5 Sep 2019 10:17:58 -0600 Message-Id: <20190905161759.28036-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905161759.28036-1-mathieu.poirier@linaro.org> References: <20190905161759.28036-1-mathieu.poirier@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Claudio Foellmi commit 93367bfca98f36cece57c01dbce6ea1b4ac58245 upstream A very conservative check for bus activity (to prevent interference in multimaster setups) prevented the bus recovery methods from being triggered in the case that SDA or SCL was stuck low. This defeats the purpose of the recovery mechanism, which was introduced for exactly this situation (a slave device keeping SDA pulled down). Also added a check to make sure SDA is low before attempting recovery. If SDA is not stuck low, recovery will not help, so we can skip it. Note that bus lockups can persist across reboots. The only other options are to reset or power cycle the offending slave device, and many i2c slaves do not even have a reset pin. If we see that one of the lines is low for the entire timeout duration, we can actually be sure that there is no other master driving the bus. It is therefore save for us to attempt a bus recovery. Signed-off-by: Claudio Foellmi Tested-by: Vignesh R Reviewed-by: Grygorii Strashko [wsa: fixed one return code to -EBUSY] Signed-off-by: Wolfram Sang Signed-off-by: Mathieu Poirier --- drivers/i2c/busses/i2c-omap.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 12ba183693d6..a03564f41ad0 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c @@ -486,6 +486,22 @@ static int omap_i2c_init(struct omap_i2c_dev *omap) return 0; } +/* + * Try bus recovery, but only if SDA is actually low. + */ +static int omap_i2c_recover_bus(struct omap_i2c_dev *omap) +{ + u16 systest; + + systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG); + if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) && + (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC)) + return 0; /* bus seems to already be fine */ + if (!(systest & OMAP_I2C_SYSTEST_SCL_I_FUNC)) + return -EBUSY; /* recovery would not fix SCL */ + return i2c_recover_bus(&omap->adapter); +} + /* * Waiting on Bus Busy */ @@ -496,7 +512,7 @@ static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap) timeout = jiffies + OMAP_I2C_TIMEOUT; while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { if (time_after(jiffies, timeout)) - return i2c_recover_bus(&omap->adapter); + return omap_i2c_recover_bus(omap); msleep(1); } @@ -577,8 +593,13 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap) } if (time_after(jiffies, timeout)) { + /* + * SDA or SCL were low for the entire timeout without + * any activity detected. Most likely, a slave is + * locking up the bus with no master driving the clock. + */ dev_warn(omap->dev, "timeout waiting for bus ready\n"); - return -ETIMEDOUT; + return omap_i2c_recover_bus(omap); } msleep(1);