Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp874745pxk; Thu, 17 Sep 2020 19:59:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcdrETGMVJdYOmdvBlaRTPC+GEyb8htfW9YALk0oOqZMadg0HwSF625oHgoSmnNDDfzvvS X-Received: by 2002:a17:906:b7d1:: with SMTP id fy17mr35161785ejb.391.1600397988217; Thu, 17 Sep 2020 19:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600397988; cv=none; d=google.com; s=arc-20160816; b=0HWIliEmGId8Qq9vN83uy1eNEp5RrVJkJpZEuwc4KUmIrJmpJ/1EPEhqfKJYdN+c3u 6AYb2TiftDvLLKxj5QESuRfsVWR38RVKQsbWrLVspRceBbZ7Wtzvdclajz1TXeetvZRu HyCUxTUkrV32Y2Ha9ljCZd6/Bfc6WPQ1IEeB/Ks2azE3HsCy2mXgnGQc00z2/FxJTp79 pTDhzG3FQfjZv6zYUdR2ZpI3XvLAOYQBTsvK45ZOP9f08CXY09wCV6iEsBeTj9T+gE6P 1qzJIsElhQQq2ESQhZJX6jB+kDGqzWR58x9WawfKzgfPXJE1oKLcmebhMGDMGeZg7h5Y SD3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4Yp10WctNfcqlxZP7OmIl6UXPilMgVxfsodeQtgRA9Q=; b=pwEtg3hMyqSDrnD14NeuBNljO+U+nDq+mYqoNDc3VPHpH0PRIGANhGC4QYiOZpfY1z hUGEwitudyTo084O8yBmvw9+GFToZQ70YwFtLVmTk7PUN3DJOekjcQSi7oyz2D5EefPe NRKdnOCsWQG+DgY6mejpbdYYtkRLiCK7xzbv8jyZPRBVJe5KE8qQj1OW3qxF3PWCGnNs Cv0mhS/WvIwKaNQGRpmxvR+39lcgkgnRjKhsMgIsWD7mnTFemt7MVeSr1shfxsMf9IGf P94fXE2TVUajMiOT7ow6/467QeTGjwiWwgYbRniD7oDHTpXkPIFYImJ2DZ1YTdrS6raR lrFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="g/CBaejq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si1092499edw.461.2020.09.17.19.59.24; Thu, 17 Sep 2020 19:59:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="g/CBaejq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728965AbgIRC5f (ORCPT + 99 others); Thu, 17 Sep 2020 22:57:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:55812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727773AbgIRCGc (ORCPT ); Thu, 17 Sep 2020 22:06:32 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 220DE206BE; Fri, 18 Sep 2020 02:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394787; bh=soD9mfSC5yZAZGe0nPc7J0LkSN9i+t1bMSXV0n6QPQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/CBaejqwMsUM5XzM90vNGl0xVcGMKeZzJl1S9lKAjyps1hJYiApJn7R7Dbzfs9XR 39hj5COngNJtC3gYc+AwnzJ0M13Wdr/ciSDX8MV02yZFegE2iN4Gx+VWb7bKXccxTa g4hQRtMs14m7kv4Y7ofAwNTfnaBueQav1XoeupVY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thierry Reding , Sasha Levin , linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 258/330] i2c: tegra: Restore pinmux on system resume Date: Thu, 17 Sep 2020 21:59:58 -0400 Message-Id: <20200918020110.2063155-258-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thierry Reding [ Upstream commit 44c99904cf61f945d02ac9976ab10dd5ccaea393 ] 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 Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-tegra.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 5ca72fb0b406c..db94e96aed77e 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1721,10 +1721,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) @@ -1732,6 +1736,10 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev) struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); int err; + /* + * We need to ensure that clocks are enabled so that registers can be + * restored in tegra_i2c_init(). + */ err = tegra_i2c_runtime_resume(dev); if (err) return err; @@ -1740,9 +1748,16 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev) if (err) return err; - err = tegra_i2c_runtime_suspend(dev); - if (err) - return err; + /* + * In case we are runtime suspended, disable clocks again so that we + * don't unbalance the clock reference counts during the next runtime + * resume transition. + */ + if (pm_runtime_status_suspended(dev)) { + err = tegra_i2c_runtime_suspend(dev); + if (err) + return err; + } i2c_mark_adapter_resumed(&i2c_dev->adapter); -- 2.25.1