From patchwork Wed Jun 21 19:21:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 106115 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp2092603qgd; Wed, 21 Jun 2017 12:21:48 -0700 (PDT) X-Received: by 10.46.22.4 with SMTP id w4mr10608399ljd.76.1498072908699; Wed, 21 Jun 2017 12:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498072908; cv=none; d=google.com; s=arc-20160816; b=fTeFJCDW/6wKo0LADlHqGxlYc4MM2FXSgX+4M54JHa8sv85GkxgtMYgM7BBQSCv4Qd kexGuAc58bVSQY9OeXrmeGMIupCG+brNWiARfAHwDSWCw+VpQy/Vwp2CGJKQcQrIYWsB 5mlxIO2AJ/Pw/ZKN5vRUcmfDCuGvLKcSY6EBLGTBfqv0HXUNIPttYjKUvnJZ+b5uRNNx MfS1JZ5+tqskR8w8PkwEE1JwK3SGW9b2YCWZfSk75DUk0cVq+7u23UUxNCFZz6B2KmBl GxsPXWnZj7xF1nlgtKuUNgv4t98Xe5Loi9ox/r6QlQTUoNX3Pz1xZhn4z9sBjGuf8bu1 8q/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Hkbj1E2AEUQlZDx5XqIyiBh7IzpD/A3kthJqUCXy8qM=; b=dMhk76ll3c/xyO4oN1WwApB5A/LVHKJRWn7PPa3yRCAyAHdrFO9LhWc0qEq4akbOqK Mrv8orkTsVPwA8wYzW3nrhPVLozA/0ufTLk8wN1RICk/9OOKOSOxEh5/y9IKJr9xO0Hp +IMI9To2QrN7XiFT0YHvXPfwwsBToOnOWzbXwSWabAhfuoJ46iftpADlHVKTGef8L8Gf 3KpXa5E6Y1vksQTBXlz52btfE7feyKMslCrvOixhMS+AebbWlcV8YQZDh8f3tdeMMy/p UejSwQ5HlNPY84BTR5t8RtqMmAPP/pZEM8Mgj7wLSC2XN9AKwndFls5ICCOWVVOdqDiO R6qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=UGZ4I4pI; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-lf0-x232.google.com (mail-lf0-x232.google.com. [2a00:1450:4010:c07::232]) by mx.google.com with ESMTPS id j14si9464908lfg.150.2017.06.21.12.21.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 12:21:48 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) client-ip=2a00:1450:4010:c07::232; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=UGZ4I4pI; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x232.google.com with SMTP id h22so23138237lfk.3 for ; Wed, 21 Jun 2017 12:21:48 -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=Hkbj1E2AEUQlZDx5XqIyiBh7IzpD/A3kthJqUCXy8qM=; b=UGZ4I4pISJ+TP0a5uQR0NyfLYpvw0L22hGRxWwbOH6JExVqFsUecKehSdFbjCCDrx8 rVkIN8J6XagH/1SPeb3174ZfBggHEdHVVqNpTLyEg2ypNNrz2/yfPN11LWcmGkQTqVkc 9es5X2xa2dqyRQKzFwE4LicMureVSIz+WhlSc= 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=Hkbj1E2AEUQlZDx5XqIyiBh7IzpD/A3kthJqUCXy8qM=; b=BrK7ysH9c3SwBrbfFtSjCdp8i4IjzhLTBFncii/UiDdwjRMY06PHUGMbB9J7aJJDwM W/+CAgmp0ULAMHuxD5iDrQDmVD4tVkRoIdHXeaNEAzDj0a2WEXPEihEZlB+YHKJjNZht Tc2a8uXRxL0jNTTdhHM1i9kkGMxU8HPq5E9YV8ysAyeto/UlcLb4er+W+Ru48SYhl2GH mQokBlqs9d/E42CQaQb6eNWNhZkQRsjCBfmy7MW0wVf8bj2Qrr3zWSob73sOe2Hr8xKf +UtvUqngCt7KgERkN61/VahJLN1zBVEyNpQEzWuLbh5kPCJDb1oyrVvSC6gWRLlX4Lil shjQ== X-Gm-Message-State: AKS2vOxtEj7Bqqr+TaZLYmKeHi4Jx8XYVqzgplXvD/9bmOkKeYh39cJI ZuVPq4ngiKCTODCMf7E= X-Received: by 10.25.31.18 with SMTP id f18mr12377097lff.126.1498072908287; Wed, 21 Jun 2017 12:21:48 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id t24sm3920047ljd.1.2017.06.21.12.21.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 12:21:47 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Kevin Hilman , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jisheng Zhang , John Stultz , Guodong Xu , Sumit Semwal , Haojian Zhuang , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Ulf Hansson , stable@vger.linux.org Subject: [PATCH 1/9] i2c: designware: Fix system suspend Date: Wed, 21 Jun 2017 21:21:20 +0200 Message-Id: <1498072888-14782-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498072888-14782-1-git-send-email-ulf.hansson@linaro.org> References: <1498072888-14782-1-git-send-email-ulf.hansson@linaro.org> The commit 8503ff166504 ("i2c: designware: Avoid unnecessary resuming during system suspend"), may suggest to the PM core to try out the so called direct_complete path for system sleep. In this path, the PM core treats a runtime suspended device as it's already in a proper low power state for system sleep, which makes it skip calling the system sleep callbacks for the device, except for the ->prepare() and the ->complete() callback. Moreover, under certain circumstances the PM core may unset the direct_complete flag for a parent device, in case its child device are being system suspended before. In other words, the PM core doesn't skip calling the system sleep callbacks, no matter if the device is runtime suspended or not. In cases of an i2c slave device, the above situation is triggered. Unfortunate, this also breaks the assumption that the i2c device is always runtime resumed, whenever the dw_i2c_plat_suspend() callback is being invoked, which then leads to a regression. More precisely, dw_i2c_plat_suspend() then calls clk_core_disable() and clk_core_unprepare(), for an already disabled/unprepared clock, leading to complaints about clocks calls being wrongly balanced. In cases when the i2c device is attached to the ACPI PM domain, the problem doesn't occur. That's because ACPI's ->suspend() callback, assigned to acpi_subsys_suspend(), calls pm_runtime_resume() for the i2c device. To make a simple fix for this regression, let's runtime resume the i2c device in the ->prepare() callback, assigned to dw_i2c_plat_prepare(). This prevents the direct_complete path from being executed by the PM core and guarantees the dw_i2c_plat_suspend() is called with the i2c device always being runtime resumed. Of course this change is suboptimal, because to always force a runtime resume of the i2c device in ->prepare() is a waste, especially in those cases when it could have remained runtime suspended during the entire system sleep sequence. However, to accomplish that behaviour a bigger change is needed, so defer that to future changes not applicable as fixes or for stable. Fixes: 8503ff166504 ("i2c: designware: Avoid unnecessary resuming...") Cc: stable@vger.linux.org Signed-off-by: Ulf Hansson --- drivers/i2c/busses/i2c-designware-platdrv.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index d1263b8..2b7fa75 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -375,17 +375,11 @@ MODULE_DEVICE_TABLE(of, dw_i2c_of_match); #ifdef CONFIG_PM_SLEEP static int dw_i2c_plat_prepare(struct device *dev) { - return pm_runtime_suspended(dev); -} - -static void dw_i2c_plat_complete(struct device *dev) -{ - if (dev->power.direct_complete) - pm_request_resume(dev); + pm_runtime_resume(dev); + return 0; } #else #define dw_i2c_plat_prepare NULL -#define dw_i2c_plat_complete NULL #endif #ifdef CONFIG_PM @@ -413,7 +407,6 @@ static int dw_i2c_plat_resume(struct device *dev) static const struct dev_pm_ops dw_i2c_dev_pm_ops = { .prepare = dw_i2c_plat_prepare, - .complete = dw_i2c_plat_complete, SET_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) SET_RUNTIME_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume, NULL) };