2011-03-11 01:14:03

by MyungJoo Ham

[permalink] [raw]
Subject: [PATCH v3] Regulator: add suspend-finish API for regulator core.

The regulator core had suspend-prepare that turns off the regulators
when entering a system-wide suspend. However, it did not have
suspend-finish that pairs with suspend-prepare and the regulator core
has assumed that the regulator devices and their drivers support
autonomous recover at resume.

This patch adds regulator_suspend_finish that pairs with the
previously-existed regulator_suspend_prepare. The function
regulator_suspend_finish turns on the regulators that have always_on set
or positive use_count so that we can reset the regulator states
appropriately at resume.

In regulator_suspend_finish, if has_full_constraints, it disables
unnecessary regulators.

Signed-off-by: MyungJoo Ham <[email protected]>
Signed-off-by: Kyungmin Park <[email protected]>
--
Updates
v3
comments corrected (Thanks to Igor)
v2
disable unnecessary regulators (Thanks to Mark)
---
drivers/regulator/core.c | 41 +++++++++++++++++++++++++++++++++++++
include/linux/regulator/machine.h | 1 +
2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9fa2095..cb9ad84 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2653,6 +2653,47 @@ out:
EXPORT_SYMBOL_GPL(regulator_suspend_prepare);

/**
+ * regulator_suspend_finish - resume regulators from system wide suspend
+ *
+ * Turn on regulators that might be turned off by regulator_suspend_prepare
+ * and that should be turned on according to the regulators properties.
+ */
+int regulator_suspend_finish(void)
+{
+ struct regulator_dev *rdev;
+ int ret = 0, error;
+
+ mutex_lock(&regulator_list_mutex);
+ list_for_each_entry(rdev, &regulator_list, list) {
+ struct regulator_ops *ops = rdev->desc->ops;
+
+ mutex_lock(&rdev->mutex);
+ if ((rdev->use_count > 0 || rdev->constraints->always_on) &&
+ ops->enable) {
+ error = ops->enable(rdev);
+ if (error)
+ ret = error;
+ } else {
+ if (!has_full_constraints)
+ goto unlock;
+ if (!ops->disable)
+ goto unlock;
+ if (ops->is_enabled && !ops->is_enabled(rdev))
+ goto unlock;
+
+ error = ops->disable(rdev);
+ if (error)
+ ret = error;
+ }
+unlock:
+ mutex_unlock(&rdev->mutex);
+ }
+ mutex_unlock(&regulator_list_mutex);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(regulator_suspend_finish);
+
+/**
* regulator_has_full_constraints - the system has fully specified constraints
*
* Calling this function will cause the regulator API to disable all
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 761c745..c4c4fc4 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -186,6 +186,7 @@ struct regulator_init_data {
};

int regulator_suspend_prepare(suspend_state_t state);
+int regulator_suspend_finish(void);

#ifdef CONFIG_REGULATOR
void regulator_has_full_constraints(void);
--
1.7.1


2011-03-14 15:03:14

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3] Regulator: add suspend-finish API for regulator core.

On Fri, Mar 11, 2011 at 10:13:59AM +0900, MyungJoo Ham wrote:
> The regulator core had suspend-prepare that turns off the regulators
> when entering a system-wide suspend. However, it did not have
> suspend-finish that pairs with suspend-prepare and the regulator core
> has assumed that the regulator devices and their drivers support
> autonomous recover at resume.

Acked-by: Mark Brown <[email protected]>

We should be doing this automatically as part of the core but since
we've not done that for suspend yet it seems reasonable to apply as-is
then fix both the teardown and powerup paths together. Since the code
won't be called unless someone explicitly does so there's very little
risk here.

2011-03-16 11:23:04

by Liam Girdwood

[permalink] [raw]
Subject: Re: [PATCH v3] Regulator: add suspend-finish API for regulator core.

On Mon, 2011-03-14 at 15:03 +0000, Mark Brown wrote:
> On Fri, Mar 11, 2011 at 10:13:59AM +0900, MyungJoo Ham wrote:
> > The regulator core had suspend-prepare that turns off the regulators
> > when entering a system-wide suspend. However, it did not have
> > suspend-finish that pairs with suspend-prepare and the regulator core
> > has assumed that the regulator devices and their drivers support
> > autonomous recover at resume.
>
> Acked-by: Mark Brown <[email protected]>

Applied.

Thanks

Liam