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: 779067 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wtF2W0k8lz9s1h for ; Thu, 22 Jun 2017 05:21:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="UGZ4I4pI"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751927AbdFUTVw (ORCPT ); Wed, 21 Jun 2017 15:21:52 -0400 Received: from mail-lf0-f46.google.com ([209.85.215.46]:35381 "EHLO mail-lf0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751762AbdFUTVu (ORCPT ); Wed, 21 Jun 2017 15:21:50 -0400 Received: by mail-lf0-f46.google.com with SMTP id p189so102983596lfe.2 for ; Wed, 21 Jun 2017 12:21:49 -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=CaaQWmePTvENvBhC9OMP6Hs56QSHEC8qx4bjle1ZDcSFwcfTFi6TXKaiexmQN0UqSP 44314YzkeZ98kSJiLM4pH269wjEcHoLp1Ue2d5qewuCkS9O/qAjJwRxQA9N+l0cqSGnf HyqTo5Mmpl4HCjZUnByTBj881uvxBrMH5nu+K2GpL++zGq3QTvJYuCrOorzRoOAt/EcI Dd4DVT+vpwcpFMWj3fqW60u6Qri/6IpHNw8Xj8D3pUV2mdcQUbAMj9FgsVFhT7I7dspi ZqiUBFN5O53HogUT1VYKlFb+U/hKkkmhGP9m1IbBdo8oHpaSbhMjgQoBNpBa5K+EMnDM CTdg== X-Gm-Message-State: AKS2vOybS4myzYVqaxT9KOOtURaQB2MWAKZJL2h+LMmsetYEr4c52SWj l8USpBieJv6XHa31 X-Received: by 10.25.31.18 with SMTP id f18mr12377097lff.126.1498072908287; Wed, 21 Jun 2017 12:21:48 -0700 (PDT) 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> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.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(-) 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) };