From patchwork Wed May 6 19:33:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 207642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D5A2C47256 for ; Wed, 6 May 2020 19:34:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60C8B20747 for ; Wed, 6 May 2020 19:34:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g/FQLcyN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729220AbgEFTeK (ORCPT ); Wed, 6 May 2020 15:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729209AbgEFTeJ (ORCPT ); Wed, 6 May 2020 15:34:09 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75985C061A0F; Wed, 6 May 2020 12:34:09 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id e16so3573290wra.7; Wed, 06 May 2020 12:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3/vHHfXaPkc2BVemCUzY7Jz2Az00+vaAtxpSsXyV1G0=; b=g/FQLcyNVN5aT1SKsfGFiX+UVYAzZUluVs5BRfBQXEqvXPfMsoduxKl2q8KSZyAYSN gPJvY/daHdcOnrcWC6K/pUAtQhNoSYrQunUunddXmKWYvx0R1S3EIeLLNdgUzHMLKMue 4BhRlEEVmPuTHlwH0eXfBOFFfwDNVZtllgFxH7/vamZoSmT1aYoitCpMfOt9jnh7sUVd s2vduz3kBR1jOEeeY7j7Ce2rJ4xtYykxEjOm3sE/teSzRKZ9bwxF2k4dpwQJGkucTYvA mMXf/ekrEk4rcfs46J/0BogMxMyzBKTOf/pqMElneJSr0v34dtC9yBagllzDbNuYetal jW+w== 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:mime-version:content-transfer-encoding; bh=3/vHHfXaPkc2BVemCUzY7Jz2Az00+vaAtxpSsXyV1G0=; b=pP7H2Yoas1XFVPINZEEJa+fNpOkHWCIUTV4pYBL+mgELbYS0xpLCtDR7CFUlfh8L2Z vVKmtza9oEQjVkVhKviTyC7iCEdBuCIlOaQIG6dlHnI8RFqeKYERc6gkUIuOgRFiEO7/ PEfarGa2rP3Ba2B5RD9aRy6MXcf80/vQYsK6PggQm+/VV8jWGLezGbgIh61U7vF4gbZQ fAFfuOreOthZAClDvzw6lCtdFjP3Bp/nLvLpHaEZhpZQQ6It59nXsfPAr7ZQiFPpLeGn HB2ln+BWa7efuxZ4yvNw60S/7TdG6FU9jrp3yqb75yhaxSx8TGZJFWsThCQJa/QdKO8j GBdw== X-Gm-Message-State: AGi0PuZkpuOgWr3Fd8KeuasYKDOKO6f3PezBIQTDhQo4sUG+ybLyK1IF Z6LqjSZ03Qc7uhDuH3Fal/yfUXQkU2o= X-Google-Smtp-Source: APiQypKOqLaPHR2GXr38hzeADI8lY4uWafphydd2x0K9hIW5mO+Z/kTlD16xMidFIH9HhnltDFTBhQ== X-Received: by 2002:a05:6000:146:: with SMTP id r6mr11864833wrx.9.1588793648128; Wed, 06 May 2020 12:34:08 -0700 (PDT) Received: from localhost (p2E5BE57B.dip0.t-ipconnect.de. [46.91.229.123]) by smtp.gmail.com with ESMTPSA id x7sm3885312wmi.17.2020.05.06.12.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 12:34:07 -0700 (PDT) From: Thierry Reding To: Wolfram Sang Cc: Dmitry Osipenko , Jon Hunter , linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH 2/5] i2c: tegra: Restore pinmux on system resume Date: Wed, 6 May 2020 21:33:55 +0200 Message-Id: <20200506193358.2807244-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200506193358.2807244-1-thierry.reding@gmail.com> References: <20200506193358.2807244-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Thierry Reding Depending on the board design, the I2C controllers found on Tegra SoCs may require pinmuxing in order to function. This is done as part of the driver's runtime suspend/resume operations. However, the PM core does not allow devices to go into runtime suspend during system sleep to avoid potential races with the suspend/resume of their parents. As a result of this, when Tegra SoCs resume from system suspend, their I2C controllers may have lost the pinmux state in hardware, whereas the pinctrl subsystem is not aware of this. To fix this, make sure that if the I2C controller is not runtime suspended, the runtime suspend code is still executed in order to disable the module clock (which we don't need to be enabled during sleep) and set the pinmux to the idle state. Conversely, make sure that the I2C controller is properly resumed when waking up from sleep so that pinmux settings are properly restored. This fixes a bug seen with DDC transactions to an HDMI monitor timing out when resuming from system suspend. Signed-off-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 7c88611c732c..db142d897604 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1769,10 +1769,14 @@ static int tegra_i2c_remove(struct platform_device *pdev) static int __maybe_unused tegra_i2c_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + int err = 0; i2c_mark_adapter_suspended(&i2c_dev->adapter); - return 0; + if (!pm_runtime_status_suspended(dev)) + err = tegra_i2c_runtime_suspend(dev); + + return err; } static int __maybe_unused tegra_i2c_resume(struct device *dev) @@ -1788,9 +1792,11 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev) if (err) return err; - err = tegra_i2c_runtime_suspend(dev); - if (err) - return err; + if (pm_runtime_status_suspended(dev)) { + err = tegra_i2c_runtime_suspend(dev); + if (err) + return err; + } i2c_mark_adapter_resumed(&i2c_dev->adapter); From patchwork Wed May 6 19:33:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 207641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0AB1C28CBC for ; Wed, 6 May 2020 19:34:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B435020747 for ; Wed, 6 May 2020 19:34:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TpSxpvYu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729234AbgEFTeO (ORCPT ); Wed, 6 May 2020 15:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729209AbgEFTeN (ORCPT ); Wed, 6 May 2020 15:34:13 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89A75C061A0F; Wed, 6 May 2020 12:34:13 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id y4so3551338wrm.11; Wed, 06 May 2020 12:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gEh6bhHeuAdoM/EB265B3gc7pO8dHOdUfXpo6OZKqxw=; b=TpSxpvYu8L9lYyJ8Bo4/zcn5j61LQYsjwRVFCiSjYohmbh5P+2mLSMq7qKnc7ymMuE ouiW1dzHGlX/Tjzi14J3d3kzHpdZZWXL50DgSZUUB9zkBrIcdVQownGuMyw/dNJgro/Q CtvoPRdmweEIqwRzYUVDFFwZ48e3+gewjhHBx4izGFCRYZL87OXj/M5+YSiAaFCxAlgm pW9AD2ONavTRRvDPzWJcLEVEWs0IFWn2pCgpzy3Kg+aj6eiffms7v4qp+eUmsnY8XkCV fGCOLgDPc0bu4PTOD5iVXjNug9JwESnKQ4So2MOADXoXE4FOj9H0SyRJHZB32b8/Nj83 dw3Q== 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:mime-version:content-transfer-encoding; bh=gEh6bhHeuAdoM/EB265B3gc7pO8dHOdUfXpo6OZKqxw=; b=Xm5vqDbD9BSFH6Ffnt2ZqhCiUzZTpTXLJm7L1JwttX1nFXTrWIjGgTaZH0jgMrUFO4 NEbNdm1obqAT7+GUkW6zzYEB/389SDPe4szlxvV8twBfqSWRXqETasrtAa1UnJ+b54BS jmBoQo7jKJQjfK1F6GLrCrE/ZQ7Ip2KUhyMb0f+/3vCu7ihoSiYjyhAp0hX5weJ6ss4r VEK6jbpL4r+Bxbj+wOWybeBJGdB+KLAi5qkO0IpnM8UXpnS+85uDbDQk9uTT8ha67kWy YJ4XVJaxV4nwFuEJdYIaUgENCKNRRLHZaleNn28ZmXDOUfJfwf8601WTJCnu77p3Tfyh Ha2A== X-Gm-Message-State: AGi0Puas8EAg9XBHjR8FSyW6PvDH7gJQF57YsJBZ7pHiaNDFwOQf0ewo HP0SOXfIceanuv/QobueTBM= X-Google-Smtp-Source: APiQypJwySYyUIHYluM8YTJXQDMbfRwwRRhsRHHWCVSZKfaLtC9DfIz7IxrVJ0gEpk3TLh+qVPMqhw== X-Received: by 2002:a5d:61c5:: with SMTP id q5mr7451442wrv.398.1588793652205; Wed, 06 May 2020 12:34:12 -0700 (PDT) Received: from localhost (p2E5BE57B.dip0.t-ipconnect.de. [46.91.229.123]) by smtp.gmail.com with ESMTPSA id b12sm4528294wro.18.2020.05.06.12.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 12:34:11 -0700 (PDT) From: Thierry Reding To: Wolfram Sang Cc: Dmitry Osipenko , Jon Hunter , linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH 4/5] i2c: tegra: Better handle case where CPU0 is busy for a long time Date: Wed, 6 May 2020 21:33:57 +0200 Message-Id: <20200506193358.2807244-5-thierry.reding@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200506193358.2807244-1-thierry.reding@gmail.com> References: <20200506193358.2807244-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Dmitry Osipenko Boot CPU0 always handle I2C interrupt and under some rare circumstances (like running KASAN + NFS root) it may stuck in uninterruptible state for a significant time. In this case we will get timeout if I2C transfer is running on a sibling CPU, despite of IRQ being raised. In order to handle this rare condition, the IRQ status needs to be checked after completion timeout. Signed-off-by: Dmitry Osipenko Signed-off-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 8d2a212db733..d504e272d9fa 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -996,14 +996,13 @@ tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev, do { u32 status = i2c_readl(i2c_dev, I2C_INT_STATUS); - if (status) { + if (status) tegra_i2c_isr(i2c_dev->irq, i2c_dev); - if (completion_done(complete)) { - s64 delta = ktime_ms_delta(ktimeout, ktime); + if (completion_done(complete)) { + s64 delta = ktime_ms_delta(ktimeout, ktime); - return msecs_to_jiffies(delta) ?: 1; - } + return msecs_to_jiffies(delta) ?: 1; } ktime = ktime_get(); @@ -1030,14 +1029,18 @@ tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, disable_irq(i2c_dev->irq); /* - * There is a chance that completion may happen after IRQ - * synchronization, which is done by disable_irq(). + * Under some rare circumstances (like running KASAN + + * NFS root) CPU, which handles interrupt, may stuck in + * uninterruptible state for a significant time. In this + * case we will get timeout if I2C transfer is running on + * a sibling CPU, despite of IRQ being raised. + * + * In order to handle this rare condition, the IRQ status + * needs to be checked after timeout. */ - if (ret == 0 && completion_done(complete)) { - dev_warn(i2c_dev->dev, - "completion done after timeout\n"); - ret = 1; - } + if (ret == 0) + ret = tegra_i2c_poll_completion_timeout(i2c_dev, + complete, 0); } return ret;