Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 256924
b: refs/heads/master
c: 5248051
h: refs/heads/master
v: v3
  • Loading branch information
Rafael J. Wysocki committed Jul 2, 2011
1 parent 18caa8a commit cffa455
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 56 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e5291928839877f8e73c2643ee1d3fe0bcdcaf5c
refs/heads/master: 5248051b9afb6684cd817b2fbdaefa5063761dab
120 changes: 65 additions & 55 deletions trunk/drivers/base/power/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,74 @@
#include <linux/slab.h>
#include <linux/err.h>

#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)
{
if (!WARN_ON(genpd->sd_count == 0))
genpd->sd_count--;
}

/**
* 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_nested(&genpd->lock, SINGLE_DEPTH_NESTING);

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.
Expand Down Expand Up @@ -174,11 +234,10 @@ static int pm_genpd_runtime_suspend(struct device *dev)

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_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
Expand All @@ -200,54 +259,6 @@ static int pm_genpd_runtime_suspend(struct device *dev)
return 0;
}

/**
* 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_nested(&genpd->lock, SINGLE_DEPTH_NESTING);

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.
Expand All @@ -264,11 +275,10 @@ static int pm_genpd_runtime_resume(struct device *dev)

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;
Expand Down

0 comments on commit cffa455

Please sign in to comment.