From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Olivier MOYSAN <olivier.moysan@foss.st.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-iio@vger.kernel.org>
Subject: Re: [PATCH 7/8] iio: add sd modulator generic iio backend
Date: Mon, 24 Jun 2024 18:41:29 +0100 [thread overview]
Message-ID: <20240624184129.000065e4@Huawei.com> (raw)
In-Reply-To: <2dbd160b-135e-4882-9fd3-9d921742f49d@foss.st.com>
> >> + }
> >> +
> >> + return -EINVAL;
> >> +};
> >> +
> >> +static const struct iio_backend_ops sd_backend_ops = {
> >> + .enable = sd_backend_enable,
> >> + .disable = sd_backend_disable,
> >> + .read_raw = sd_backend_read,
> >> +};
> >> +
> >> +static int iio_sd_backend_probe(struct platform_device *pdev)
> >> +{
> >> + struct device *dev = &pdev->dev;
> >> + struct regulator *vref;
> >> + struct iio_sd_backend_priv *priv;
> >> + int ret;
> >> +
> >> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> >> + if (!priv)
> >> + return -ENOMEM;
> >> +
> >> + vref = devm_regulator_get_optional(dev, "vref");
> >
> > New devm_regulator_get_enable_read_voltage() slightly simplifies this
> > and means you don't need to keep vref around.
> >
> >> + if (IS_ERR(vref)) {
> >> + if (PTR_ERR(vref) != -ENODEV)
> >> + return dev_err_probe(dev, PTR_ERR(vref), "Failed to get vref\n");
> >> + } else {
> >> + ret = regulator_get_voltage(vref);
> > You haven't turned it on so it's not guaranteed to give you a useful
> > answer.
> >
>
> My understanding is that regulator_get_voltage() always returns the
> regulator voltage, whatever the regulator state, as documented in the
> API description:
> "* NOTE: If the regulator is disabled it will return the voltage value.
> * This function should not be used to determine regulator state."
>
> So, my logic was to enable the regulator only when requested, through
> enable/disable callbacks to manage power.
>
> Please, let me know if I missed something here.
Ah ok. I had a vague and it seems incorrect recollection that you had
to turn the regs on to get voltage in some cases. Ah well. Clearly not :)
What you have is fine. Add a comment though just so no one replaces
this code with the helper.
Jonathan
next prev parent reply other threads:[~2024-06-24 17:41 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 16:08 [PATCH 0/8] iio: adc: dfsdm: add scaling support Olivier Moysan
2024-06-18 16:08 ` [PATCH 1/8] iio: add read raw service to iio backend framework Olivier Moysan
2024-06-19 5:25 ` Nuno Sá
2024-06-18 16:08 ` [PATCH 2/8] iio: add enable and disable services " Olivier Moysan
2024-06-19 5:21 ` Nuno Sá
2024-06-19 15:59 ` Olivier MOYSAN
2024-06-20 10:07 ` Nuno Sá
2024-06-23 13:56 ` Jonathan Cameron
2024-06-24 8:13 ` Nuno Sá
2024-06-18 16:08 ` [PATCH 3/8] iio: add child nodes support in " Olivier Moysan
2024-06-19 5:31 ` Nuno Sá
2024-06-19 16:00 ` Olivier MOYSAN
2024-06-23 13:59 ` Jonathan Cameron
2024-06-18 16:08 ` [PATCH 4/8] dt-bindings: iio: dfsdm: move to " Olivier Moysan
2024-06-18 18:10 ` Conor Dooley
2024-06-20 8:03 ` Olivier MOYSAN
2024-06-20 8:51 ` Conor Dooley
2024-06-23 15:01 ` Jonathan Cameron
2024-06-18 16:08 ` [PATCH 5/8] dt-bindings: iio: add sigma delta modulator backend Olivier Moysan
2024-06-18 18:13 ` Conor Dooley
2024-06-25 9:26 ` Olivier MOYSAN
2024-06-18 16:08 ` [PATCH 6/8] iio: adc: stm32-dfsdm: adopt generic channels bindings Olivier Moysan
2024-06-23 15:01 ` Jonathan Cameron
2024-06-18 16:08 ` [PATCH 7/8] iio: add sd modulator generic iio backend Olivier Moysan
2024-06-23 15:11 ` Jonathan Cameron
2024-06-24 12:43 ` Olivier MOYSAN
2024-06-24 15:22 ` Nuno Sá
2024-06-24 16:26 ` Olivier MOYSAN
2024-06-25 12:14 ` Nuno Sá
2024-06-24 17:41 ` Jonathan Cameron [this message]
2024-06-18 16:08 ` [PATCH 8/8] iio: adc: stm32-dfsdm: add scaling support to dfsdm Olivier Moysan
2024-06-19 5:47 ` Nuno Sá
2024-06-20 14:15 ` Olivier MOYSAN
2024-06-23 15:21 ` Jonathan Cameron
2024-06-25 9:39 ` Olivier MOYSAN
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=20240624184129.000065e4@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=broonie@kernel.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olivier.moysan@foss.st.com \
/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;
as well as URLs for NNTP newsgroup(s).