mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, has@pengutronix.de
Subject: Re: [PATCH 1/4] regulator: add regulator_get_voltage() to API
Date: Wed, 10 Feb 2021 10:15:00 +0100	[thread overview]
Message-ID: <20210210091500.GQ19583@pengutronix.de> (raw)
In-Reply-To: <20210208191827.19241-1-a.fatoum@pengutronix.de>

On Mon, Feb 08, 2021 at 08:18:24PM +0100, Ahmad Fatoum wrote:
> ADC drivers need to query their reference regulator's voltage to
> format their raw readings. Provide regulator_get_voltage() so ADC
> drivers need not hardcode a reference voltage. Regulator drivers
> that don't support this (i.e. nearly everything in-tree) will
> have the function return with -EINVAL.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/regulator/core.c | 27 +++++++++++++++++++++++++++
>  include/regulator.h      | 21 +++++++++++++++++++++
>  2 files changed, 48 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 6ea21a4609d5..7ced283c116c 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -176,6 +176,9 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
>  
>  	ri->node = node;
>  
> +	if (rd->desc->fixed_uV && rd->desc->n_voltages == 1)
> +		ri->min_uv = ri->max_uv = rd->desc->fixed_uV;
> +
>  	of_property_read_u32(node, "regulator-enable-ramp-delay",
>  			&ri->enable_time_us);
>  	of_property_read_u32(node, "regulator-min-microvolt",
> @@ -539,6 +542,30 @@ void regulator_bulk_free(int num_consumers,
>  }
>  EXPORT_SYMBOL_GPL(regulator_bulk_free);
>  
> +int regulator_get_voltage(struct regulator *regulator)
> +{
> +	struct regulator_dev *rdev = regulator->ri->rdev;
> +	int sel, ret;
> +
> +	if (rdev->desc->ops->get_voltage_sel) {
> +		sel = rdev->desc->ops->get_voltage_sel(rdev);
> +		if (sel < 0)
> +			return sel;
> +		ret = rdev->desc->ops->list_voltage(rdev, sel);
> +	} else if (rdev->desc->ops->get_voltage) {
> +		ret = rdev->desc->ops->get_voltage(rdev);
> +	} else if (rdev->desc->ops->list_voltage) {
> +		ret = rdev->desc->ops->list_voltage(rdev, 0);
> +	} else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) {
> +		ret = rdev->desc->fixed_uV;
> +	} else {
> +		return -EINVAL;
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(regulator_get_voltage_rdev);
> +
>  static void regulator_print_one(struct regulator_internal *ri)
>  {
>  	struct regulator *r;
> diff --git a/include/regulator.h b/include/regulator.h
> index 7c2a01b6875c..524e53042c92 100644
> --- a/include/regulator.h
> +++ b/include/regulator.h
> @@ -51,6 +51,7 @@ struct regulator_bulk_data {
>   * @disable_val: Disabling value for control when using regmap enable/disable ops
>   * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
>   *                      when using regulator_enable_regmap and friends APIs.
> + * @fixed_uV: Fixed voltage of rails.
>   */
>  
>  struct regulator_desc {
> @@ -73,6 +74,7 @@ struct regulator_desc {
>  
>  	const struct regulator_linear_range *linear_ranges;
>  	int n_linear_ranges;
> +	int fixed_uV;
>  };
>  
>  struct regulator_dev {
> @@ -92,6 +94,9 @@ struct regulator_ops {
>  	int (*list_voltage) (struct regulator_dev *, unsigned int);
>  	int (*set_voltage_sel) (struct regulator_dev *, unsigned int);
>  	int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
> +
> +	int (*get_voltage) (struct regulator_dev *);
> +	int (*get_voltage_sel) (struct regulator_dev *);
>  };
>  
>  /*
> @@ -166,6 +171,17 @@ int regulator_bulk_disable(int num_consumers,
>  void regulator_bulk_free(int num_consumers,
>  			 struct regulator_bulk_data *consumers);
>  
> +/**
> + * regulator_get_voltage - get regulator output voltage
> + * @regulator: regulator source
> + *
> + * This returns the current regulator voltage in uV.
> + *
> + * NOTE: If the regulator is disabled it will return the voltage value. This
> + * function should not be used to determine regulator state.
> + */
> +int regulator_get_voltage(struct regulator *regulator);
> +
>  /*
>   * Helper functions intended to be used by regulator drivers prior registering
>   * their regulators.
> @@ -223,6 +239,11 @@ static inline void regulator_bulk_free(int num_consumers,
>  {
>  }
>  
> +static inline int regulator_get_voltage(struct regulator *regulator)
> +{
> +	return -EINVAL;
> +}
> +
>  #endif
>  
>  #endif /* __REGULATOR_H */
> -- 
> 2.30.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2021-02-10  9:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 19:18 Ahmad Fatoum
2021-02-08 19:18 ` [PATCH 2/4] regulator: add support for struct regulator_desc::off_on_delay Ahmad Fatoum
2021-02-08 19:18 ` [PATCH 3/4] regulator: add driver for stm32-vrefbuf Ahmad Fatoum
2021-02-08 19:18 ` [PATCH 4/4] aiodev: add support for STM32 ADC Ahmad Fatoum
2021-02-09  8:00   ` [PATCH] fixup! " Ahmad Fatoum
2021-02-10  9:15 ` Sascha Hauer [this message]

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=20210210091500.GQ19583@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=has@pengutronix.de \
    /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