linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jon Hunter <jonathanh@nvidia.com>,
	Thierry Reding <treding@nvidia.com>,
	Wolfram Sang <wsa@the-dreams.de>, Sasha Levin <sashal@kernel.org>,
	linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: [PATCH AUTOSEL 5.3 35/49] i2c: tegra: Move suspend handling to NOIRQ phase
Date: Sun, 29 Sep 2019 13:30:35 -0400	[thread overview]
Message-ID: <20190929173053.8400-35-sashal@kernel.org> (raw)
In-Reply-To: <20190929173053.8400-1-sashal@kernel.org>

From: Jon Hunter <jonathanh@nvidia.com>

[ Upstream commit 8ebf15e9c869e764b3aab4928938ee68c0e2bd6d ]

Commit acc8abcb2a9c ("i2c: tegra: Add suspend-resume support") added
suspend support for the Tegra I2C driver and following this change on
Tegra30 the following WARNING is seen on entering suspend ...

 WARNING: CPU: 2 PID: 689 at /dvs/git/dirty/git-master_l4t-upstream/kernel/drivers/i2c/i2c-core.h:54 __i2c_transfer+0x35c/0x70c
 i2c i2c-4: Transfer while suspended
 Modules linked in: brcmfmac brcmutil
 CPU: 2 PID: 689 Comm: rtcwake Not tainted 5.3.0-rc7-g089cf7f6ecb2 #1
 Hardware name: NVIDIA Tegra SoC (Flattened Device Tree)
 [<c0112264>] (unwind_backtrace) from [<c010ca94>] (show_stack+0x10/0x14)
 [<c010ca94>] (show_stack) from [<c0a77024>] (dump_stack+0xb4/0xc8)
 [<c0a77024>] (dump_stack) from [<c0124198>] (__warn+0xe0/0xf8)
 [<c0124198>] (__warn) from [<c01241f8>] (warn_slowpath_fmt+0x48/0x6c)
 [<c01241f8>] (warn_slowpath_fmt) from [<c06f6c40>] (__i2c_transfer+0x35c/0x70c)
 [<c06f6c40>] (__i2c_transfer) from [<c06f7048>] (i2c_transfer+0x58/0xf4)
 [<c06f7048>] (i2c_transfer) from [<c06f7130>] (i2c_transfer_buffer_flags+0x4c/0x70)
 [<c06f7130>] (i2c_transfer_buffer_flags) from [<c05bee78>] (regmap_i2c_write+0x14/0x30)
 [<c05bee78>] (regmap_i2c_write) from [<c05b9cac>] (_regmap_raw_write_impl+0x35c/0x868)
 [<c05b9cac>] (_regmap_raw_write_impl) from [<c05b984c>] (_regmap_update_bits+0xe4/0xec)
 [<c05b984c>] (_regmap_update_bits) from [<c05bad04>] (regmap_update_bits_base+0x50/0x74)
 [<c05bad04>] (regmap_update_bits_base) from [<c04d453c>] (regulator_disable_regmap+0x44/0x54)
 [<c04d453c>] (regulator_disable_regmap) from [<c04cf9d4>] (_regulator_do_disable+0xf8/0x268)
 [<c04cf9d4>] (_regulator_do_disable) from [<c04d1694>] (_regulator_disable+0xf4/0x19c)
 [<c04d1694>] (_regulator_disable) from [<c04d1770>] (regulator_disable+0x34/0x64)
 [<c04d1770>] (regulator_disable) from [<c04d2310>] (regulator_bulk_disable+0x28/0xb4)
 [<c04d2310>] (regulator_bulk_disable) from [<c0495cd4>] (tegra_pcie_power_off+0x64/0xa8)
 [<c0495cd4>] (tegra_pcie_power_off) from [<c0495f74>] (tegra_pcie_pm_suspend+0x25c/0x3f4)
 [<c0495f74>] (tegra_pcie_pm_suspend) from [<c05af48c>] (dpm_run_callback+0x38/0x1d4)
 [<c05af48c>] (dpm_run_callback) from [<c05afe30>] (__device_suspend_noirq+0xc0/0x2b8)
 [<c05afe30>] (__device_suspend_noirq) from [<c05b1c24>] (dpm_noirq_suspend_devices+0x100/0x37c)
 [<c05b1c24>] (dpm_noirq_suspend_devices) from [<c05b1ebc>] (dpm_suspend_noirq+0x1c/0x48)
 [<c05b1ebc>] (dpm_suspend_noirq) from [<c017d2c0>] (suspend_devices_and_enter+0x1d0/0xa00)
 [<c017d2c0>] (suspend_devices_and_enter) from [<c017dd10>] (pm_suspend+0x220/0x74c)
 [<c017dd10>] (pm_suspend) from [<c017c2c8>] (state_store+0x6c/0xc8)
 [<c017c2c8>] (state_store) from [<c02ef398>] (kernfs_fop_write+0xe8/0x1c4)
 [<c02ef398>] (kernfs_fop_write) from [<c0271e38>] (__vfs_write+0x2c/0x1c4)
 [<c0271e38>] (__vfs_write) from [<c02748dc>] (vfs_write+0xa4/0x184)
 [<c02748dc>] (vfs_write) from [<c0274b7c>] (ksys_write+0x9c/0xdc)
 [<c0274b7c>] (ksys_write) from [<c0101000>] (ret_fast_syscall+0x0/0x54)
 Exception stack(0xe9f21fa8 to 0xe9f21ff0)
 1fa0:                   0000006c 004b2438 00000004 004b2438 00000004 00000000
 1fc0: 0000006c 004b2438 004b1228 00000004 00000004 00000004 0049e78c 004b1228
 1fe0: 00000004 be9809b8 b6f0bc0b b6e96206

The problem is that the Tegra PCIe driver indirectly uses I2C for
controlling some regulators and the I2C driver is now being suspended
before the PCIe driver causing the PCIe suspend to fail. The Tegra PCIe
driver is suspended during the NOIRQ phase and this cannot be changed
due to other dependencies. Therefore, we also need to move the suspend
handling for the Tegra I2C driver to the NOIRQ phase as well.

In order to move the I2C suspend handling to the NOIRQ phase we also
need to avoid calling pm_runtime_get/put() because per commit
1e2ef05bb8cf ("PM: Limit race conditions between runtime PM and system
sleep (v2)") these cannot be called early in resume. The function
tegra_i2c_init(), called during resume, calls pm_runtime_get/put() and
so move these calls outside of tegra_i2c_init(), so this function can
be used during the NOIRQ resume phase.

Fixes: acc8abcb2a9c ("i2c: tegra: Add suspend-resume support")

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/i2c/busses/i2c-tegra.c | 40 +++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 9fcb13beeb8f4..7a3291d91a5ee 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -713,12 +713,6 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit)
 	u32 tsu_thd;
 	u8 tlow, thigh;
 
-	err = pm_runtime_get_sync(i2c_dev->dev);
-	if (err < 0) {
-		dev_err(i2c_dev->dev, "runtime resume failed %d\n", err);
-		return err;
-	}
-
 	reset_control_assert(i2c_dev->rst);
 	udelay(2);
 	reset_control_deassert(i2c_dev->rst);
@@ -772,7 +766,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit)
 		if (err) {
 			dev_err(i2c_dev->dev,
 				"failed changing clock rate: %d\n", err);
-			goto err;
+			return err;
 		}
 	}
 
@@ -787,23 +781,21 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit)
 
 	err = tegra_i2c_flush_fifos(i2c_dev);
 	if (err)
-		goto err;
+		return err;
 
 	if (i2c_dev->is_multimaster_mode && i2c_dev->hw->has_slcg_override_reg)
 		i2c_writel(i2c_dev, I2C_MST_CORE_CLKEN_OVR, I2C_CLKEN_OVERRIDE);
 
 	err = tegra_i2c_wait_for_config_load(i2c_dev);
 	if (err)
-		goto err;
+		return err;
 
 	if (i2c_dev->irq_disabled) {
 		i2c_dev->irq_disabled = false;
 		enable_irq(i2c_dev->irq);
 	}
 
-err:
-	pm_runtime_put(i2c_dev->dev);
-	return err;
+	return 0;
 }
 
 static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev)
@@ -1616,12 +1608,14 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 	}
 
 	pm_runtime_enable(&pdev->dev);
-	if (!pm_runtime_enabled(&pdev->dev)) {
+	if (!pm_runtime_enabled(&pdev->dev))
 		ret = tegra_i2c_runtime_resume(&pdev->dev);
-		if (ret < 0) {
-			dev_err(&pdev->dev, "runtime resume failed\n");
-			goto unprepare_div_clk;
-		}
+	else
+		ret = pm_runtime_get_sync(i2c_dev->dev);
+
+	if (ret < 0) {
+		dev_err(&pdev->dev, "runtime resume failed\n");
+		goto unprepare_div_clk;
 	}
 
 	if (i2c_dev->is_multimaster_mode) {
@@ -1666,6 +1660,8 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 	if (ret)
 		goto release_dma;
 
+	pm_runtime_put(&pdev->dev);
+
 	return 0;
 
 release_dma:
@@ -1726,17 +1722,25 @@ static int tegra_i2c_resume(struct device *dev)
 	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
 	int err;
 
+	err = tegra_i2c_runtime_resume(dev);
+	if (err)
+		return err;
+
 	err = tegra_i2c_init(i2c_dev, false);
 	if (err)
 		return err;
 
+	err = tegra_i2c_runtime_suspend(dev);
+	if (err)
+		return err;
+
 	i2c_mark_adapter_resumed(&i2c_dev->adapter);
 
 	return 0;
 }
 
 static const struct dev_pm_ops tegra_i2c_pm = {
-	SET_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
+	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
 	SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,
 			   NULL)
 };
-- 
2.20.1


  parent reply	other threads:[~2019-09-29 17:42 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-29 17:30 [PATCH AUTOSEL 5.3 01/49] MIPS: Ingenic: Disable broken BTB lookup optimization Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 02/49] clk: jz4740: Add TCU clock Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 03/49] MIPS: Don't use bc_false uninitialized in __mm_isBranchInstr Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 04/49] MIPS: tlbex: Explicitly cast _PAGE_NO_EXEC to a boolean Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 05/49] i2c-cht-wc: Fix lockdep warning Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 06/49] mfd: intel-lpss: Remove D3cold delay Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 07/49] PCI: tegra: Fix OF node reference leak Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 08/49] HID: wacom: Fix several minor compiler warnings Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 09/49] rtc: bd70528: fix driver dependencies Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 10/49] mips/atomic: Fix loongson_llsc_mb() wreckage Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 11/49] PCI: pci-hyperv: Fix build errors on non-SYSFS config Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 12/49] PCI: layerscape: Add the bar_fixed_64bit property to the endpoint driver Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 13/49] livepatch: Nullify obj->mod in klp_module_coming()'s error path Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 14/49] mips/atomic: Fix smp_mb__{before,after}_atomic() Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 15/49] ARM: 8898/1: mm: Don't treat faults reported from cache maintenance as writes Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 16/49] soundwire: intel: fix channel number reported by hardware Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 17/49] PCI: mobiveil: Fix the CPU base address setup in inbound window Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 18/49] ARM: 8875/1: Kconfig: default to AEABI w/ Clang Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 19/49] MIPS: lantiq: update the clock alias' for the mainline PCIe PHY driver Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 20/49] firmware: bcm47xx_nvram: Correct size_t printf format Sasha Levin
2019-09-29 19:39   ` Florian Fainelli
2019-10-05 22:53     ` Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 21/49] rtc: snvs: fix possible race condition Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 22/49] rtc: pcf85363/pcf85263: fix regmap error in set_time Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 23/49] power: supply: register HWMON devices with valid names Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 24/49] selinux: fix residual uses of current_security() for the SELinux blob Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 25/49] PCI: Add pci_info_ratelimited() to ratelimit PCI separately Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 26/49] HID: apple: Fix stuck function keys when using FN Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 27/49] PCI: rockchip: Propagate errors for optional regulators Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 28/49] PCI: histb: " Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 29/49] PCI: imx6: " Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 30/49] PCI: exynos: Propagate errors for optional PHYs Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 31/49] security: smack: Fix possible null-pointer dereferences in smack_socket_sock_rcv_skb() Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 32/49] PCI: Use static const struct, not const static struct Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 33/49] ARM: 8905/1: Emit __gnu_mcount_nc when using Clang 10.0.0 or newer Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 34/49] ARM: 8903/1: ensure that usable memory in bank 0 starts from a PMD-aligned address Sasha Levin
2019-09-29 17:30 ` Sasha Levin [this message]
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 36/49] block, bfq: push up injection only after setting service time Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 37/49] fat: work around race with userspace's read via blockdev while mounting Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 38/49] pktcdvd: remove warning on attempting to register non-passthrough dev Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 39/49] hypfs: Fix error number left in struct pointer member Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 40/49] tools/power/x86/intel-speed-select: Fix high priority core mask over count Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 41/49] crypto: hisilicon - Fix double free in sec_free_hw_sgl() Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 42/49] mm: add dummy can_do_mlock() helper Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 43/49] kbuild: clean compressed initramfs image Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 44/49] ocfs2: wait for recovering done after direct unlock request Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 45/49] kmemleak: increase DEBUG_KMEMLEAK_EARLY_LOG_SIZE default to 16K Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 46/49] arm64: consider stack randomization for mmap base only when necessary Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 47/49] mips: properly account for stack randomization and stack guard gap Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 48/49] arm: " Sasha Levin
2019-09-29 17:30 ` [PATCH AUTOSEL 5.3 49/49] arm: use STACK_TOP when computing mmap base address Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190929173053.8400-35-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=treding@nvidia.com \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).