From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH v2] regulator: fixed: remove duplicate always-on handling
Date: Fri, 8 Jul 2022 08:15:40 +0200 [thread overview]
Message-ID: <20220708061539.1193059-1-ahmad@a3f.at> (raw)
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>
---
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
next reply other threads:[~2022-07-08 6:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-08 6:15 Ahmad Fatoum [this message]
2022-07-11 9:35 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220708061539.1193059-1-ahmad@a3f.at \
--to=ahmad@a3f.at \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox