Skip to content

Commit 638f85c

Browse files
broonieLiam Girdwood
authored andcommitted
regulator: Handle regulators without suspend mode configuration
Since some regulators in the system may not support suspend mode configuration we need to allow some regulators to have a missing suspend mode configuration. Do this by requiring that disabled regulators are explicitly flagged and then skip over regulators that have no state specified. Try to avoid surprises by warning the if we could set the state but no configuration is provided. This also ensures that an all zeros configuration generates a warning rather than silently disabling the regulator. Reported-by: Joonyoung Shim <jy0922.shim@samsung.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
1 parent 1083c39 commit 638f85c

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,29 @@ static int suspend_set_state(struct regulator_dev *rdev,
581581
struct regulator_state *rstate)
582582
{
583583
int ret = 0;
584+
bool can_set_state;
584585

585-
/* enable & disable are mandatory for suspend control */
586-
if (!rdev->desc->ops->set_suspend_enable ||
587-
!rdev->desc->ops->set_suspend_disable) {
586+
can_set_state = rdev->desc->ops->set_suspend_enable &&
587+
rdev->desc->ops->set_suspend_disable;
588+
589+
/* If we have no suspend mode configration don't set anything;
590+
* only warn if the driver actually makes the suspend mode
591+
* configurable.
592+
*/
593+
if (!rstate->enabled && !rstate->disabled) {
594+
if (can_set_state)
595+
printk(KERN_WARNING "%s: No configuration for %s\n",
596+
__func__, rdev_get_name(rdev));
597+
return 0;
598+
}
599+
600+
if (rstate->enabled && rstate->disabled) {
601+
printk(KERN_ERR "%s: invalid configuration for %s\n",
602+
__func__, rdev_get_name(rdev));
603+
return -EINVAL;
604+
}
605+
606+
if (!can_set_state) {
588607
printk(KERN_ERR "%s: no way to set suspend state\n",
589608
__func__);
590609
return -EINVAL;

‎include/linux/regulator/machine.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ struct regulator;
4343
/**
4444
* struct regulator_state - regulator state during low power system states
4545
*
46-
* This describes a regulators state during a system wide low power state.
46+
* This describes a regulators state during a system wide low power
47+
* state. One of enabled or disabled must be set for the
48+
* configuration to be applied.
4749
*
4850
* @uV: Operating voltage during suspend.
4951
* @mode: Operating mode during suspend.
5052
* @enabled: Enabled during suspend.
53+
* @disabled: Disabled during suspend.
5154
*/
5255
struct regulator_state {
5356
int uV; /* suspend voltage */
5457
unsigned int mode; /* suspend regulator operating mode */
5558
int enabled; /* is regulator enabled in this suspend state */
59+
int disabled; /* is the regulator disbled in this suspend state */
5660
};
5761

5862
/**

0 commit comments

Comments
 (0)