Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753286Ab1FKUkx (ORCPT ); Sat, 11 Jun 2011 16:40:53 -0400 Received: from ogre.sisk.pl ([217.79.144.158]:48647 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752279Ab1FKUkk (ORCPT ); Sat, 11 Jun 2011 16:40:40 -0400 From: "Rafael J. Wysocki" To: Linux PM mailing list Subject: [PATCH 6/8] PM / Domains: Move code from under #ifdef CONFIG_PM_RUNTIME Date: Sat, 11 Jun 2011 22:37:48 +0200 User-Agent: KMail/1.13.6 (Linux/2.6.39+; KDE/4.6.0; x86_64; ; ) Cc: "Greg Kroah-Hartman" , Magnus Damm , Paul Walmsley , Kevin Hilman , Alan Stern , LKML , linux-sh@vger.kernel.org References: <201106112223.04972.rjw@sisk.pl> In-Reply-To: <201106112223.04972.rjw@sisk.pl> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201106112237.48634.rjw@sisk.pl> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4152 Lines: 171 From: Rafael J. Wysocki There is some code in drivers/base/power/domain.c that will be useful for both runtime PM and system-wide power transitions, so make it depend on CONFIG_PM instead of CONFIG_PM_RUNTIME. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 118 +++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 54 deletions(-) Index: linux-2.6/drivers/base/power/domain.c =================================================================== --- linux-2.6.orig/drivers/base/power/domain.c +++ linux-2.6/drivers/base/power/domain.c @@ -14,6 +14,66 @@ #include #include +#ifdef CONFIG_PM + +static struct generic_pm_domain *dev_to_genpd(struct device *dev) +{ + if (IS_ERR_OR_NULL(dev->pm_domain)) + return ERR_PTR(-EINVAL); + + return container_of(dev->pm_domain, struct generic_pm_domain, domain); +} + +/** + * pm_genpd_poweron - Restore power to a given PM domain and its parents. + * @genpd: PM domain to power up. + * + * Restore power to @genpd and all of its parents so that it is possible to + * resume a device belonging to it. + */ +static int pm_genpd_poweron(struct generic_pm_domain *genpd) +{ + int ret = 0; + + start: + if (genpd->parent) + mutex_lock(&genpd->parent->lock); + mutex_lock(&genpd->lock); + + if (!genpd->power_is_off) + goto out; + + if (genpd->parent && genpd->parent->power_is_off) { + mutex_unlock(&genpd->lock); + mutex_unlock(&genpd->parent->lock); + + ret = pm_genpd_poweron(genpd->parent); + if (ret) + return ret; + + goto start; + } + + if (genpd->power_on) { + int ret = genpd->power_on(&genpd->domain); + if (ret) + goto out; + } + + genpd->power_is_off = false; + if (genpd->parent) + genpd->parent->sd_count++; + + out: + mutex_unlock(&genpd->lock); + if (genpd->parent) + mutex_unlock(&genpd->parent->lock); + + return ret; +} + +#endif /* CONFIG_PM */ + #ifdef CONFIG_PM_RUNTIME static void genpd_sd_counter_dec(struct generic_pm_domain *genpd) @@ -155,11 +215,10 @@ static int pm_genpd_runtime_suspend(stru dev_dbg(dev, "%s()\n", __func__); - if (IS_ERR_OR_NULL(dev->pm_domain)) + genpd = dev_to_genpd(dev); + if (IS_ERR(genpd)) return -EINVAL; - genpd = container_of(dev->pm_domain, struct generic_pm_domain, domain); - if (genpd->parent) mutex_lock(&genpd->parent->lock); mutex_lock(&genpd->lock); @@ -182,54 +241,6 @@ static int pm_genpd_runtime_suspend(stru } /** - * pm_genpd_poweron - Restore power to a given PM domain and its parents. - * @genpd: PM domain to power up. - * - * Restore power to @genpd and all of its parents so that it is possible to - * resume a device belonging to it. - */ -static int pm_genpd_poweron(struct generic_pm_domain *genpd) -{ - int ret = 0; - - start: - if (genpd->parent) - mutex_lock(&genpd->parent->lock); - mutex_lock(&genpd->lock); - - if (!genpd->power_is_off) - goto out; - - if (genpd->parent && genpd->parent->power_is_off) { - mutex_unlock(&genpd->lock); - mutex_unlock(&genpd->parent->lock); - - ret = pm_genpd_poweron(genpd->parent); - if (ret) - return ret; - - goto start; - } - - if (genpd->power_on) { - int ret = genpd->power_on(&genpd->domain); - if (ret) - goto out; - } - - genpd->power_is_off = false; - if (genpd->parent) - genpd->parent->sd_count++; - - out: - mutex_unlock(&genpd->lock); - if (genpd->parent) - mutex_unlock(&genpd->parent->lock); - - return ret; -} - -/** * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain. * @dev: Device to resume. * @@ -245,11 +256,10 @@ static int pm_genpd_runtime_resume(struc dev_dbg(dev, "%s()\n", __func__); - if (IS_ERR_OR_NULL(dev->pm_domain)) + genpd = dev_to_genpd(dev); + if (IS_ERR(genpd)) return -EINVAL; - genpd = container_of(dev->pm_domain, struct generic_pm_domain, domain); - ret = pm_genpd_poweron(genpd); if (ret) return ret; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/