From patchwork Wed Aug 9 13:28:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 109718 Delivered-To: patches@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp886741obb; Wed, 9 Aug 2017 06:28:59 -0700 (PDT) X-Received: by 10.25.29.83 with SMTP id d80mr2987962lfd.50.1502285339209; Wed, 09 Aug 2017 06:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502285339; cv=none; d=google.com; s=arc-20160816; b=uw3rgpS/+YrndQYF7R9hBpUrxqatXaHbr5MWPaMgHb5hFOTVFTr7tK4fCK7qZmM8bX V+MJQNPsgxzyOkuaxMjUeJITLC28/jqdPr2O4JQMo4OkYX/r8ZYOjHpFcfFHoK3ou9db WzM0jtqdhwpElAbKKaKjhYYI9fBCeSmkCJFY5CC+pGawlUtLoR6mNY+JsgubSg4XLuSk DQxs83L9mLEm6BDBuszz/l/yx4j53es01TzDRMrutgmynRrfKdJIa+PEjNgWsr+fJBWa 2T9H9X+TwhyfIhR81kB8+qpCxuR9KRuIBdrfmdY5g9eVCIOFrtyFNnQUmgQx5c1/7vKg gEPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=F3JnYvi9oTiTlu3ZcgARhVGlD2nGeE5aMqx1AqSMwjI=; b=npZjXMuIMvpcj06q61bBi+jrzQyQazBMC2+A0VIsjt1sNzTb4wytVq7yUxbp7hdNc+ cDOtpn1SD5Fgo71u2tEw/WrcuUznwwx+/so0BpJUx9iTf3Oha8ulD3LsJjlbdHyWQ2aC Blu+G2w7h/eNZpGfX2eqqn0wNEsAHQl/bPcyM7MpoyJDDspLpGKO4CDsl0r9CEm3+MUy nkKse4MaV+RBUQAcw9g5lFqjA6M42jtonCOkySXsbugoTxEIo2hbFqzIzWEKwbpO3E4q ToHdjqrkJvUU2ovp0nFMh8qKyXN79H/E0GKVCnxFv2Lb93tsb8PxXUPd6DYcux5pmLfc H4Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VS3+xInC; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 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-x233.google.com (mail-lf0-x233.google.com. [2a00:1450:4010:c07::233]) by mx.google.com with ESMTPS id i77si1928020lfl.200.2017.08.09.06.28.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Aug 2017 06:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 as permitted sender) client-ip=2a00:1450:4010:c07::233; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VS3+xInC; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 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-x233.google.com with SMTP id t128so28153489lff.2 for ; Wed, 09 Aug 2017 06:28:58 -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; bh=F3JnYvi9oTiTlu3ZcgARhVGlD2nGeE5aMqx1AqSMwjI=; b=VS3+xInCz9FDHcFoRpeZ93MNlT29RVxIYCxeYcrmxHNgnvob4zf4TPjBna+ndaWfg3 ZhbafUjZE1VL0nsE6u0diFYgQGn1tu6sx0KgAZ5PCKdEbKDnZp8JtY+GA4PHls2NaOAG +WyJ3rIOn0983yo0p5ohvvhRxFAPfPrd+zWG4= 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; bh=F3JnYvi9oTiTlu3ZcgARhVGlD2nGeE5aMqx1AqSMwjI=; b=W6RI+MxGVrWBICx978ex0QT5On7B3UktitwJuCQfP+gjAuFunSucvhQK+wnqIP78aY q5c65WnMoCKHZR597kftpoyEr/ircVnvvTMbUzvkKrnB9SAutODbqTGuUWyctguPD8ZJ UhjIYocM3uH0u+RZ4buhWHdbIGizXdbT8D1n0UR9ZoJHlRnwhwAVW5v9OsvpLm0SxU7r ECthQhRxZbtKVemrXnowMy5PTLIh0nuO2c+5Zt41/SKCiXTwv0O6XGq2hwsopfw69q42 So7B0w4LUcQNNlICofKHg7ZHXkNA60XYCohJ038AZwJZwZ58uQ+HegBF1vEdqyJYWpLh iGLA== X-Gm-Message-State: AHYfb5jyZllgSRCizv9l4/S1gTQ/hrq7d0rS9Ib6Ub5BPN2AKyVzSNIo gatM/PepmLg//bc7RX0= X-Received: by 10.25.81.141 with SMTP id g13mr739070lfl.52.1502285338775; Wed, 09 Aug 2017 06:28:58 -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 s27sm654282ljd.67.2017.08.09.06.28.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Aug 2017 06:28:58 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , "Rafael J . Wysocki" , linux-i2c@vger.kernel.org Cc: Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jisheng Zhang , John Stultz , Guodong Xu , Sumit Semwal , Haojian Zhuang , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, Ulf Hansson , "# v4 . 4+" Subject: [PATCH] i2c: designware: Fix system suspend Date: Wed, 9 Aug 2017 15:28:22 +0200 Message-Id: <1502285302-21552-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 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() callbacks. However, the PM core may unset the direct_complete flag for a parent device, in case its child device are being system suspended before. In this scenario, the PM core invokes the system sleep callbacks, no matter if the device is runtime suspended or not. Particularly in cases of an existing i2c slave device, the above path is triggered, which breaks the assumption that the i2c device is always runtime resumed whenever the dw_i2c_plat_suspend() is being called. More precisely, dw_i2c_plat_suspend() calls clk_core_disable() and clk_core_unprepare(), for an already disabled/unprepared clock, leading to a splat in the log about clocks calls being wrongly balanced and breaking system sleep. To still allow the direct_complete path in cases when it's possible, but also to keep the fix simple, let's runtime resume the i2c device in the ->suspend() callback, before continuing to put the device into low power state. Note, in cases when the i2c device is attached to the ACPI PM domain, this problem doesn't occur, because ACPI's ->suspend() callback, assigned to acpi_subsys_suspend(), already calls pm_runtime_resume() for the device. It should also be noted that this change does not fix commit 8503ff166504 ("i2c: designware: Avoid unnecessary resuming during system suspend"). Because for the non-ACPI case, the system sleep support was already broken prior that point. Cc: # v4.4+ Signed-off-by: Ulf Hansson --- I decided to post this as a separate change, instead of as earlier folding it in the series that extends the ACPI PM domain to cope with the runtime PM centric path for system sleep. This change applies on a fresh v4.4+. If someone wants it's applied for earlier version, please send a backport yourself. It's based on 4.13 rc4 and I assume it should go as a fix via the i2c tree. Changes in v2: - Updated changelog. - Runtime resume the device in ->suspend() instead of in ->prepare(). --- drivers/i2c/busses/i2c-designware-platdrv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 2ea6d0d..bb3b8c8 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -426,7 +426,7 @@ static void dw_i2c_plat_complete(struct device *dev) #endif #ifdef CONFIG_PM -static int dw_i2c_plat_suspend(struct device *dev) +static int dw_i2c_plat_runtime_suspend(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); @@ -448,11 +448,21 @@ static int dw_i2c_plat_resume(struct device *dev) return 0; } +#ifdef CONFIG_PM_SLEEP +static int dw_i2c_plat_suspend(struct device *dev) +{ + pm_runtime_resume(dev); + return dw_i2c_plat_runtime_suspend(dev); +} +#endif + 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) + SET_RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, + dw_i2c_plat_resume, + NULL) }; #define DW_I2C_DEV_PMOPS (&dw_i2c_dev_pm_ops)