From patchwork Fri Mar 13 16:23:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 6007041 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EEEACBF910 for ; Fri, 13 Mar 2015 16:24:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D96A520148 for ; Fri, 13 Mar 2015 16:24:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B66262015A for ; Fri, 13 Mar 2015 16:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932168AbbCMQYW (ORCPT ); Fri, 13 Mar 2015 12:24:22 -0400 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:43496 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752252AbbCMQYU (ORCPT ); Fri, 13 Mar 2015 12:24:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=0NdH8Lnkml5S0EpnyB85N9kl3tEmaZqv1RaV0tWk7xI=; b=Hvy4lDoKm4SSV3VQIWH/2sTDzs5zGv7v2Ih7wugVmJj+79w/W6QqUArxH1N2Le9hY/D7PQ1cPVG/tNhrHGyGj1JQJMFqpz7ga5ARQZycUttyB0hzqn5Aw7UpUbSOF9ZwI9hxe1x2F/LcHq9gd/84M0IHDgxwiKQrV8eBz3+uhkY=; Received: from e0022681537dd.dyn.arm.linux.org.uk ([2002:4e20:1eda:1:222:68ff:fe15:37dd]:35396 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1YWSNC-0000hM-0K; Fri, 13 Mar 2015 16:23:42 +0000 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1YWSN5-0006G5-Ld; Fri, 13 Mar 2015 16:23:35 +0000 In-Reply-To: <20150312183020.GU8656@n2100.arm.linux.org.uk> References: <20150312183020.GU8656@n2100.arm.linux.org.uk> From: Russell King To: Andrew Lunn , Jason Cooper , "Rafael J. Wysocki" , Sebastian Hesselbarth , linux-arm-kernel@lists.infradead.org Cc: Greg Kroah-Hartman , Len Brown , Wolfram Sang , Mark Brown , linux-pm@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org Subject: [PATCH 04/10] pm: domains: sync runtime PM status with PM domains after probe MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Fri, 13 Mar 2015 16:23:35 +0000 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Synchronise the PM domain status with runtime PM's status after a platform device has been probed. This augments the solution in commit 2ed127697eb1 ("PM / Domains: Power on the PM domain right after attach completes"). The above commit added a call to power up the PM domain when a device attaches to the domain in order to match the behaviour required by drivers that make no use of runtime PM. The assumption is that the device driver will cause a runtime PM transition, which will synchronise the PM domain state with the runtime PM state. However, by default, runtime PM will assume that the device is initially suspended, and some drivers may make use of this should they not need to touch the hardware during probe. In order to allow such drivers, trigger the PM domain code to check whether the PM domain can be suspended after the probe function, undoing the effect of the power-on prior to the probe. Signed-off-by: Russell King Acked-by: Kevin Hilman --- drivers/amba/bus.c | 4 +++- drivers/base/platform.c | 2 ++ drivers/base/power/common.c | 15 +++++++++++++++ drivers/base/power/domain.c | 12 ++++++++++++ drivers/i2c/i2c-core.c | 2 ++ drivers/spi/spi.c | 2 ++ include/linux/pm.h | 1 + include/linux/pm_domain.h | 4 ++++ 8 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 52ddd9fbb55e..8d4097f982d1 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -205,8 +205,10 @@ static int amba_probe(struct device *dev) pm_runtime_enable(dev); ret = pcdrv->probe(pcdev, id); - if (ret == 0) + if (ret == 0) { + dev_pm_domain_sync(dev); break; + } pm_runtime_disable(dev); pm_runtime_set_suspended(dev); diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9421fed40905..552d1affc060 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -512,6 +512,8 @@ static int platform_drv_probe(struct device *_dev) ret = drv->probe(dev); if (ret) dev_pm_domain_detach(_dev, true); + else + dev_pm_domain_sync(_dev); } if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) { diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index b0f138806bbc..8c739a14d3c7 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -134,3 +134,18 @@ void dev_pm_domain_detach(struct device *dev, bool power_off) dev->pm_domain->detach(dev, power_off); } EXPORT_SYMBOL_GPL(dev_pm_domain_detach); + +/** + * dev_pm_domain_sync - synchronise the PM domain state with its devices + * @dev: device corresponding with domain + * + * Synchronise the PM domain state with the recently probed device, which + * may be in a variety of PM states. This ensures that a device which + * enables runtime PM in suspended state, and never transitions to active + * in its probe handler is properly suspended after the probe. + */ +void dev_pm_domain_sync(struct device *dev) +{ + if (dev->pm_domain && dev->pm_domain->sync) + dev->pm_domain->sync(dev); +} diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 69fa87aa3b52..2b552a2d3544 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2169,6 +2169,17 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off) genpd_queue_power_off_work(pd); } +static void genpd_dev_pm_sync(struct device *dev) +{ + struct generic_pm_domain *pd; + + pd = pm_genpd_lookup_dev(dev); + if (!pd) + return; + + genpd_queue_power_off_work(pd); +} + /** * genpd_dev_pm_attach - Attach a device to its PM domain using DT. * @dev: Device to attach. @@ -2235,6 +2246,7 @@ int genpd_dev_pm_attach(struct device *dev) } dev->pm_domain->detach = genpd_dev_pm_detach; + dev->pm_domain->sync = genpd_dev_pm_sync; pm_genpd_poweron(pd); return 0; diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index e9eae57a2b50..a6d628542907 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -659,6 +659,8 @@ static int i2c_device_probe(struct device *dev) client)); if (status) dev_pm_domain_detach(&client->dev, true); + else + dev_pm_domain_sync(&client->dev); } return status; diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 66a70e9bc743..9f697cb51097 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -270,6 +270,8 @@ static int spi_drv_probe(struct device *dev) ret = sdrv->probe(to_spi_device(dev)); if (ret) dev_pm_domain_detach(dev, true); + else + dev_pm_domain_sync(dev); } return ret; diff --git a/include/linux/pm.h b/include/linux/pm.h index 8b5976364619..676ca4055239 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -607,6 +607,7 @@ extern int dev_pm_put_subsys_data(struct device *dev); struct dev_pm_domain { struct dev_pm_ops ops; void (*detach)(struct device *dev, bool power_off); + void (*sync)(struct device *dev); }; /* diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index a9edab2c787a..8d58b30e23ac 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -319,12 +319,16 @@ static inline int of_genpd_add_provider_onecell(struct device_node *np, #ifdef CONFIG_PM extern int dev_pm_domain_attach(struct device *dev, bool power_on); extern void dev_pm_domain_detach(struct device *dev, bool power_off); +void dev_pm_domain_sync(struct device *dev); #else static inline int dev_pm_domain_attach(struct device *dev, bool power_on) { return -ENODEV; } static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} +static inline void dev_pm_domain_sync(struct device *dev) +{ +} #endif #endif /* _LINUX_PM_DOMAIN_H */