Regulator core already handles always-on property by enabling always-on
regulators at registration time, so we can remove duplicate handling in
the fixed-regulator driver. To avoid regressions due to previously
unnoticed unbalanced regulator usage, maintain a positive use count
always like Linux does and additionally warn on violation attempt.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
v1 -> v2:
  - prevent use count dipping below 1 due to unbalanced use.
    This should avoid regressions and still warn us if they occur
---
 drivers/regulator/core.c  |  9 +++++++--
 drivers/regulator/fixed.c | 10 ----------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index af8a0cb4fc3e..1fb344656f38 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -66,6 +66,7 @@ static int regulator_enable_internal(struct 
regulator_internal *ri)
 
 static int regulator_disable_internal(struct regulator_internal *ri)
 {
+       struct regulator_dev *rdev = ri->rdev;
        int ret;
 
        if (!ri->enable_count)
@@ -76,10 +77,14 @@ static int regulator_disable_internal(struct 
regulator_internal *ri)
                return 0;
        }
 
-       if (!ri->rdev->desc->ops->disable)
+       /* Crisis averted, be loud about the unbalanced regulator use */
+       if (WARN_ON(rdev->always_on))
+               return -EPERM;
+
+       if (!rdev->desc->ops->disable)
                return -ENOSYS;
 
-       ret = ri->rdev->desc->ops->disable(ri->rdev);
+       ret = rdev->desc->ops->disable(rdev);
        if (ret)
                return ret;
 
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index c5f97d78df40..ec64f39b86c7 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -15,7 +15,6 @@
 
 struct regulator_fixed {
        int gpio;
-       int always_on;
        struct regulator_dev rdev;
        struct regulator_desc rdesc;
 };
@@ -34,9 +33,6 @@ static int regulator_fixed_disable(struct regulator_dev *rdev)
 {
        struct regulator_fixed *fix = container_of(rdev, struct 
regulator_fixed, rdev);
 
-       if (fix->always_on)
-               return 0;
-
        if (!gpio_is_valid(fix->gpio))
                return 0;
 
@@ -76,12 +72,6 @@ static int regulator_fixed_probe(struct device_d *dev)
        if (!of_property_read_u32(np, "off-on-delay-us", &delay))
                fix->rdesc.off_on_delay = delay;
 
-       if (of_find_property(np, "regulator-always-on", NULL) ||
-           of_find_property(np, "regulator-boot-on", NULL)) {
-               fix->always_on = 1;
-               regulator_fixed_enable(&fix->rdev);
-       }
-
        ret = of_regulator_register(&fix->rdev, np);
        if (ret)
                goto err;
-- 
2.34.1


Reply via email to