Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

MyungJoo Ham and committed by
Liam Girdwood
7a32b589 fb7c18ca

+42
+41
drivers/regulator/core.c
··· 2656 2656 EXPORT_SYMBOL_GPL(regulator_suspend_prepare); 2657 2657 2658 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 + 2699 + /** 2659 2700 * regulator_has_full_constraints - the system has fully specified constraints 2660 2701 * 2661 2702 * Calling this function will cause the regulator API to disable all
+1
include/linux/regulator/machine.h
··· 186 186 }; 187 187 188 188 int regulator_suspend_prepare(suspend_state_t state); 189 + int regulator_suspend_finish(void); 189 190 190 191 #ifdef CONFIG_REGULATOR 191 192 void regulator_has_full_constraints(void);