Skip to content

Commit 7a32b58

Browse files
myungjooLiam Girdwood
authored andcommitted
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 <myungjoo.ham@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> -- Updates v3 comments corrected (Thanks to Igor) v2 disable unnecessary regulators (Thanks to Mark) Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
1 parent fb7c18c commit 7a32b58

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,47 @@ int regulator_suspend_prepare(suspend_state_t state)
26552655
}
26562656
EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
26572657

2658+
/**
2659+
* regulator_suspend_finish - resume regulators from system wide suspend
2660+
*
2661+
* Turn on regulators that might be turned off by regulator_suspend_prepare
2662+
* and that should be turned on according to the regulators properties.
2663+
*/
2664+
int regulator_suspend_finish(void)
2665+
{
2666+
struct regulator_dev *rdev;
2667+
int ret = 0, error;
2668+
2669+
mutex_lock(&regulator_list_mutex);
2670+
list_for_each_entry(rdev, &regulator_list, list) {
2671+
struct regulator_ops *ops = rdev->desc->ops;
2672+
2673+
mutex_lock(&rdev->mutex);
2674+
if ((rdev->use_count > 0 || rdev->constraints->always_on) &&
2675+
ops->enable) {
2676+
error = ops->enable(rdev);
2677+
if (error)
2678+
ret = error;
2679+
} else {
2680+
if (!has_full_constraints)
2681+
goto unlock;
2682+
if (!ops->disable)
2683+
goto unlock;
2684+
if (ops->is_enabled && !ops->is_enabled(rdev))
2685+
goto unlock;
2686+
2687+
error = ops->disable(rdev);
2688+
if (error)
2689+
ret = error;
2690+
}
2691+
unlock:
2692+
mutex_unlock(&rdev->mutex);
2693+
}
2694+
mutex_unlock(&regulator_list_mutex);
2695+
return ret;
2696+
}
2697+
EXPORT_SYMBOL_GPL(regulator_suspend_finish);
2698+
26582699
/**
26592700
* regulator_has_full_constraints - the system has fully specified constraints
26602701
*

‎include/linux/regulator/machine.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ struct regulator_init_data {
186186
};
187187

188188
int regulator_suspend_prepare(suspend_state_t state);
189+
int regulator_suspend_finish(void);
189190

190191
#ifdef CONFIG_REGULATOR
191192
void regulator_has_full_constraints(void);

0 commit comments

Comments
 (0)