From patchwork Sat Jun 25 21:27:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Wysocki X-Patchwork-Id: 918582 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5PLXfTe012058 for ; Sat, 25 Jun 2011 21:33:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752546Ab1FYVd1 (ORCPT ); Sat, 25 Jun 2011 17:33:27 -0400 Received: from ogre.sisk.pl ([217.79.144.158]:58131 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752284Ab1FYVbm (ORCPT ); Sat, 25 Jun 2011 17:31:42 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by ogre.sisk.pl (Postfix) with ESMTP id 803FC1B007C; Sat, 25 Jun 2011 23:09:58 +0200 (CEST) Received: from ogre.sisk.pl ([127.0.0.1]) by localhost (ogre.sisk.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24278-04; Sat, 25 Jun 2011 23:09:33 +0200 (CEST) Received: from ferrari.rjw.lan (220-bem-13.acn.waw.pl [82.210.184.220]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ogre.sisk.pl (Postfix) with ESMTP id 8B23B1B3A5E; Sat, 25 Jun 2011 23:09:03 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM mailing list Subject: [PATCH 5/10 v6] PM / Domains: Move code from under #ifdef CONFIG_PM_RUNTIME (v2) Date: Sat, 25 Jun 2011 23:27:49 +0200 User-Agent: KMail/1.13.6 (Linux/3.0.0-rc4+; KDE/4.6.0; x86_64; ; ) Cc: "Greg Kroah-Hartman" , Magnus Damm , Paul Walmsley , Kevin Hilman , Alan Stern , LKML , linux-sh@vger.kernel.org, Paul Mundt References: <201106112223.04972.rjw@sisk.pl> <201106252324.13454.rjw@sisk.pl> In-Reply-To: <201106252324.13454.rjw@sisk.pl> MIME-Version: 1.0 Message-Id: <201106252327.49552.rjw@sisk.pl> X-Virus-Scanned: amavisd-new at ogre.sisk.pl using MkS_Vir for Linux Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 25 Jun 2011 21:33:41 +0000 (UTC) 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 | 120 +++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 55 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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,7 +14,15 @@ #include #include -#ifdef CONFIG_PM_RUNTIME +#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); +} static void genpd_sd_counter_dec(struct generic_pm_domain *genpd) { @@ -23,6 +31,58 @@ static void genpd_sd_counter_dec(struct } /** + * 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); + 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 + +/** * __pm_genpd_save_device - Save the pre-suspend state of a device. * @dle: Device list entry of the device to save the state of. * @genpd: PM domain the device belongs to. @@ -174,11 +234,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); @@ -201,54 +260,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); - 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. * @@ -264,11 +275,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;