regulator: leave one item to record whether regulator is enabled
authorChunyan Zhang <zhang.chunyan@linaro.org>
Fri, 26 Jan 2018 13:08:45 +0000 (21:08 +0800)
committerMark Brown <broonie@kernel.org>
Fri, 26 Jan 2018 14:43:46 +0000 (14:43 +0000)
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>
drivers/regulator/core.c
drivers/regulator/of_regulator.c
include/linux/regulator/machine.h

index 97bc9f7adf2f3b8a8060bee89eca8d0e0f86e4d7..5ea80e94eb692d8f989dc0277b25444b2f3cb7e1 100644 (file)
@@ -742,21 +742,19 @@ static int suspend_set_state(struct regulator_dev *rdev,
         * only warn if the driver implements set_suspend_voltage or
         * set_suspend_mode callback.
         */
-       if (!rstate->enabled && !rstate->disabled) {
+       if (rstate->enabled != ENABLE_IN_SUSPEND &&
+           rstate->enabled != DISABLE_IN_SUSPEND) {
                if (rdev->desc->ops->set_suspend_voltage ||
                    rdev->desc->ops->set_suspend_mode)
                        rdev_warn(rdev, "No configuration\n");
                return 0;
        }
 
-       if (rstate->enabled && rstate->disabled) {
-               rdev_err(rdev, "invalid configuration\n");
-               return -EINVAL;
-       }
-
-       if (rstate->enabled && rdev->desc->ops->set_suspend_enable)
+       if (rstate->enabled == ENABLE_IN_SUSPEND &&
+               rdev->desc->ops->set_suspend_enable)
                ret = rdev->desc->ops->set_suspend_enable(rdev);
-       else if (rstate->disabled && rdev->desc->ops->set_suspend_disable)
+       else if (rstate->enabled == DISABLE_IN_SUSPEND &&
+               rdev->desc->ops->set_suspend_disable)
                ret = rdev->desc->ops->set_suspend_disable(rdev);
        else /* OK if set_suspend_enable or set_suspend_disable is NULL */
                ret = 0;
index 14637a01ba2d3db64d3357ab3e4ea7ad2915ca8b..41dad42b18f07e794fd67cb8e42f902e162cb22c 100644 (file)
@@ -177,10 +177,12 @@ static void of_get_regulation_constraints(struct device_node *np,
 
                if (of_property_read_bool(suspend_np,
                                        "regulator-on-in-suspend"))
-                       suspend_state->enabled = true;
+                       suspend_state->enabled = ENABLE_IN_SUSPEND;
                else if (of_property_read_bool(suspend_np,
                                        "regulator-off-in-suspend"))
-                       suspend_state->disabled = true;
+                       suspend_state->enabled = DISABLE_IN_SUSPEND;
+               else
+                       suspend_state->enabled = DO_NOTHING_IN_SUSPEND;
 
                if (!of_property_read_u32(suspend_np,
                                        "regulator-suspend-microvolt", &pval))
index 9cd4fef37203cbdc8fc76a07a1d81334acc789d3..ce89c5548c89cfb1b6bdad904a976333a6d266c3 100644 (file)
@@ -42,6 +42,16 @@ struct regulator;
 #define REGULATOR_CHANGE_DRMS          0x10
 #define REGULATOR_CHANGE_BYPASS                0x20
 
+/*
+ * operations in suspend mode
+ * DO_NOTHING_IN_SUSPEND - the default value
+ * DISABLE_IN_SUSPEND  - turn off regulator in suspend states
+ * ENABLE_IN_SUSPEND   - keep regulator on in suspend states
+ */
+#define DO_NOTHING_IN_SUSPEND  (-1)
+#define DISABLE_IN_SUSPEND     0
+#define ENABLE_IN_SUSPEND      1
+
 /* Regulator active discharge flags */
 enum regulator_active_discharge {
        REGULATOR_ACTIVE_DISCHARGE_DEFAULT,
@@ -58,14 +68,15 @@ enum regulator_active_discharge {
  *
  * @uV: Operating voltage during suspend.
  * @mode: Operating mode during suspend.
- * @enabled: Enabled during suspend.
- * @disabled: Disabled during suspend.
+ * @enabled: operations during suspend.
+ *          - DO_NOTHING_IN_SUSPEND
+ *          - DISABLE_IN_SUSPEND
+ *          - ENABLE_IN_SUSPEND
  */
 struct regulator_state {
        int uV; /* suspend voltage */
        unsigned int mode; /* suspend regulator operating mode */
-       int enabled; /* is regulator enabled in this suspend state */
-       int disabled; /* is the regulator disabled in this suspend state */
+       int enabled;
 };
 
 /**