Skip to content

Commit 72069f9

Browse files
Chunyan Zhangbroonie
authored andcommitted
regulator: leave one item to record whether regulator is enabled
The items "disabled" and "enabled" are a little redundant, since only one of them would be set to record if the regulator device should keep on or be switched to off in suspend states. So in this patch, the "disabled" was removed, only leave the "enabled": - enabled == 1 for regulator-on-in-suspend - enabled == 0 for regulator-off-in-suspend - enabled == -1 means do nothing when entering suspend mode. Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c360a6d commit 72069f9

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

drivers/regulator/core.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,21 +742,19 @@ static int suspend_set_state(struct regulator_dev *rdev,
742742
* only warn if the driver implements set_suspend_voltage or
743743
* set_suspend_mode callback.
744744
*/
745-
if (!rstate->enabled && !rstate->disabled) {
745+
if (rstate->enabled != ENABLE_IN_SUSPEND &&
746+
rstate->enabled != DISABLE_IN_SUSPEND) {
746747
if (rdev->desc->ops->set_suspend_voltage ||
747748
rdev->desc->ops->set_suspend_mode)
748749
rdev_warn(rdev, "No configuration\n");
749750
return 0;
750751
}
751752

752-
if (rstate->enabled && rstate->disabled) {
753-
rdev_err(rdev, "invalid configuration\n");
754-
return -EINVAL;
755-
}
756-
757-
if (rstate->enabled && rdev->desc->ops->set_suspend_enable)
753+
if (rstate->enabled == ENABLE_IN_SUSPEND &&
754+
rdev->desc->ops->set_suspend_enable)
758755
ret = rdev->desc->ops->set_suspend_enable(rdev);
759-
else if (rstate->disabled && rdev->desc->ops->set_suspend_disable)
756+
else if (rstate->enabled == DISABLE_IN_SUSPEND &&
757+
rdev->desc->ops->set_suspend_disable)
760758
ret = rdev->desc->ops->set_suspend_disable(rdev);
761759
else /* OK if set_suspend_enable or set_suspend_disable is NULL */
762760
ret = 0;

drivers/regulator/of_regulator.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ static void of_get_regulation_constraints(struct device_node *np,
177177

178178
if (of_property_read_bool(suspend_np,
179179
"regulator-on-in-suspend"))
180-
suspend_state->enabled = true;
180+
suspend_state->enabled = ENABLE_IN_SUSPEND;
181181
else if (of_property_read_bool(suspend_np,
182182
"regulator-off-in-suspend"))
183-
suspend_state->disabled = true;
183+
suspend_state->enabled = DISABLE_IN_SUSPEND;
184+
else
185+
suspend_state->enabled = DO_NOTHING_IN_SUSPEND;
184186

185187
if (!of_property_read_u32(suspend_np,
186188
"regulator-suspend-microvolt", &pval))

include/linux/regulator/machine.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ struct regulator;
4242
#define REGULATOR_CHANGE_DRMS 0x10
4343
#define REGULATOR_CHANGE_BYPASS 0x20
4444

45+
/*
46+
* operations in suspend mode
47+
* DO_NOTHING_IN_SUSPEND - the default value
48+
* DISABLE_IN_SUSPEND - turn off regulator in suspend states
49+
* ENABLE_IN_SUSPEND - keep regulator on in suspend states
50+
*/
51+
#define DO_NOTHING_IN_SUSPEND (-1)
52+
#define DISABLE_IN_SUSPEND 0
53+
#define ENABLE_IN_SUSPEND 1
54+
4555
/* Regulator active discharge flags */
4656
enum regulator_active_discharge {
4757
REGULATOR_ACTIVE_DISCHARGE_DEFAULT,
@@ -58,14 +68,15 @@ enum regulator_active_discharge {
5868
*
5969
* @uV: Operating voltage during suspend.
6070
* @mode: Operating mode during suspend.
61-
* @enabled: Enabled during suspend.
62-
* @disabled: Disabled during suspend.
71+
* @enabled: operations during suspend.
72+
* - DO_NOTHING_IN_SUSPEND
73+
* - DISABLE_IN_SUSPEND
74+
* - ENABLE_IN_SUSPEND
6375
*/
6476
struct regulator_state {
6577
int uV; /* suspend voltage */
6678
unsigned int mode; /* suspend regulator operating mode */
67-
int enabled; /* is regulator enabled in this suspend state */
68-
int disabled; /* is the regulator disabled in this suspend state */
79+
int enabled;
6980
};
7081

7182
/**

0 commit comments

Comments
 (0)