All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/6] dm: adc: uclass: get reference regulator once
Date: Mon, 23 Jul 2018 17:48:03 -0600	[thread overview]
Message-ID: <CAPnjgZ3VYg7SHjo7ccCNJZYs9ZWYcR-AOWh=+q8LiMMj8UrC0w@mail.gmail.com> (raw)
In-Reply-To: <1532349355-32671-2-git-send-email-fabrice.gasnier@st.com>

Hi Fabrice,

On 23 July 2018 at 06:35, Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> device_get_supply_regulator() only needs to be called once.
> But each time there's call to adc_vxx_value() for instance, it calls
> adc_vxx_platdata_update() -> device_get_supply_regulator().
>
> This also allows vdd_supply/vss_supply to be provided directly from
> uc_pdata, e.g dt-binding variant like stm32-adc provide its own
> 'vref-supply'.
>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
> ---
>
>  drivers/adc/adc-uclass.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)

The original code doesn't look right to me.

Reading from the DT should happen in the ofdata_to_platdata() method,
except (as here) where we need to probe another device, iwc we can use
the probe() method.

So can you move this code into a new probe() method, so it just
happens once, when the device is probed?

>
> diff --git a/drivers/adc/adc-uclass.c b/drivers/adc/adc-uclass.c
> index 17c1a4e..70f4cde 100644
> --- a/drivers/adc/adc-uclass.c
> +++ b/drivers/adc/adc-uclass.c
> @@ -264,10 +264,13 @@ static int adc_vdd_platdata_update(struct udevice *dev)
>          * will bind before its supply regulator device, then the below 'get'
>          * will return an error.
>          */
> -       ret = device_get_supply_regulator(dev, "vdd-supply",
> -                                         &uc_pdata->vdd_supply);
> -       if (ret)
> -               return ret;
> +       if (!uc_pdata->vdd_supply) {
> +               /* Only get vdd_supply once */
> +               ret = device_get_supply_regulator(dev, "vdd-supply",
> +                                                 &uc_pdata->vdd_supply);
> +               if (ret)
> +                       return ret;
> +       }
>
>         ret = regulator_get_value(uc_pdata->vdd_supply);
>         if (ret < 0)
> @@ -283,10 +286,12 @@ static int adc_vss_platdata_update(struct udevice *dev)
>         struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
>         int ret;
>
> -       ret = device_get_supply_regulator(dev, "vss-supply",
> -                                         &uc_pdata->vss_supply);
> -       if (ret)
> -               return ret;
> +       if (!uc_pdata->vss_supply) {
> +               ret = device_get_supply_regulator(dev, "vss-supply",
> +                                                 &uc_pdata->vss_supply);
> +               if (ret)
> +                       return ret;
> +       }
>
>         ret = regulator_get_value(uc_pdata->vss_supply);
>         if (ret < 0)
> --
> 1.9.1
>

Regards,
Simon

  reply	other threads:[~2018-07-23 23:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23 12:35 [U-Boot] [PATCH 1/6] clk: add clk_valid() Fabrice Gasnier
2018-07-23 12:35 ` [U-Boot] [PATCH 2/6] dm: adc: uclass: get reference regulator once Fabrice Gasnier
2018-07-23 23:48   ` Simon Glass [this message]
2018-07-24 14:37     ` Fabrice Gasnier
2018-07-23 12:35 ` [U-Boot] [PATCH 3/6] dt-bindings: Document STM32 ADC DT bindings Fabrice Gasnier
2018-07-23 23:48   ` Simon Glass
2018-07-23 12:35 ` [U-Boot] [PATCH 4/6] adc: Add driver for STM32 ADC Fabrice Gasnier
2018-07-23 23:48   ` Simon Glass
2018-07-23 12:35 ` [U-Boot] [PATCH 5/6] configs: stm32mp15: enable ADC Fabrice Gasnier
2018-07-23 23:48   ` Simon Glass
2018-07-23 12:35 ` [U-Boot] [PATCH 6/6] ARM: dts: stm32mp157: Add ADC DT node Fabrice Gasnier
2018-07-23 23:48 ` [U-Boot] [PATCH 1/6] clk: add clk_valid() Simon Glass

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='CAPnjgZ3VYg7SHjo7ccCNJZYs9ZWYcR-AOWh=+q8LiMMj8UrC0w@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.