summaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2022-07-08 08:15:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-07-11 11:35:17 +0200
commit2b2b0527a3750a96cc90ca146e754ad9bd350466 (patch)
tree048fd7c7ee0eff9a4dbac00c17249b06acb677d0 /drivers/regulator
parent1d09667d3b37628df2902be25a4776ad9867228f (diff)
downloadbarebox-2b2b0527a3750a96cc90ca146e754ad9bd350466.tar.gz
regulator: fixed: remove duplicate always-on handling
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 <ahmad@a3f.at> Link: https://lore.barebox.org/20220708061539.1193059-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/core.c9
-rw-r--r--drivers/regulator/fixed.c10
2 files changed, 7 insertions, 12 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index af8a0cb4fc..1fb344656f 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 c5f97d78df..ec64f39b86 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;