[PATCH 1/2] regulator: core: Implement regulator_is_enabled() call
Sascha Hauer
s.hauer at pengutronix.de
Sun Mar 30 23:49:21 PDT 2025
On Fri, Mar 28, 2025 at 09:31:21AM +0300, Alexander Shiyan wrote:
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
> drivers/regulator/core.c | 11 +++++++++++
> include/regulator.h | 6 ++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 2c3b009ea6..c9e30ab3fd 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -610,6 +610,17 @@ int regulator_disable(struct regulator *r)
> return regulator_disable_rdev(r->rdev);
> }
>
> +int regulator_is_enabled(struct regulator *r)
> +{
> + if (!r)
> + return 0;
> +
> + if (r->rdev->always_on)
> + return 1;
> +
> + return r->rdev->enable_count;
> +}
This differs from what Linux does. Linux will return the result of the
is_enabled hook here. We should likely do the same and only if the
is_enabled hook is not present return the enable_count.
> +
> int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV)
> {
> if (!r)
> diff --git a/include/regulator.h b/include/regulator.h
> index 9785b8ac07..5fdf1602dd 100644
> --- a/include/regulator.h
> +++ b/include/regulator.h
> @@ -217,6 +217,7 @@ void regulator_put(struct regulator *r);
> struct regulator *regulator_get_name(const char *name);
> int regulator_enable(struct regulator *);
> int regulator_disable(struct regulator *);
> +int regulator_is_enabled(struct regulator *);
> int regulator_is_enabled_regmap(struct regulator_dev *);
> int regulator_enable_regmap(struct regulator_dev *);
> int regulator_disable_regmap(struct regulator_dev *);
> @@ -285,6 +286,11 @@ static inline int regulator_disable(struct regulator *r)
> return 0;
> }
>
> +static inline int regulator_is_enabled(struct regulator *r)
> +{
> + return 0;
> +}
I think we should return true here as it likely makes the consumers
happier.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list