devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Alisa-Dariana Roman <alisadariana@gmail.com>
Cc: michael.hennerich@analog.com, linux-iio@vger.kernel.org,
	 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	 alexandru.tachici@analog.com, lars@metafoo.de, jic23@kernel.org,
	 robh@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	conor+dt@kernel.org,  lgirdwood@gmail.com, broonie@kernel.org,
	andy@kernel.org, nuno.sa@analog.com,  marcelo.schmitt@analog.com,
	bigunclemax@gmail.com, okan.sahin@analog.com,
	 fr0st61te@gmail.com, alisa.roman@analog.com,
	marcus.folkesson@gmail.com,  schnelle@linux.ibm.com,
	liambeguin@gmail.com
Subject: Re: [PATCH v7 3/6] iio: adc: ad7192: Add aincom supply
Date: Wed, 1 May 2024 11:54:27 -0500	[thread overview]
Message-ID: <CAMknhBHa7zfWeQj7LDFCZDWc8i8as1WD964L2J3z6v_Un6kXFQ@mail.gmail.com> (raw)
In-Reply-To: <20240430162946.589423-4-alisa.roman@analog.com>

On Tue, Apr 30, 2024 at 11:30 AM Alisa-Dariana Roman
<alisadariana@gmail.com> wrote:
>
> AINCOM should actually be a supply. AINx inputs are referenced to AINCOM
> in pseudo-differential operation mode. AINCOM voltage represents the
> offset of corresponding channels.
>
> Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
> ---
>  drivers/iio/adc/ad7192.c | 41 ++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 39 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index ace81e3817a1..3e797ff48086 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -20,6 +20,7 @@
>  #include <linux/module.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/property.h>
> +#include <linux/units.h>
>
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
> @@ -186,6 +187,7 @@ struct ad7192_state {
>         struct regulator                *vref;
>         struct clk                      *mclk;
>         u16                             int_vref_mv;
> +       u32                             aincom_mv;
>         u32                             fclk;
>         u32                             mode;
>         u32                             conf;
> @@ -742,10 +744,19 @@ static int ad7192_read_raw(struct iio_dev *indio_dev,
>                         *val = -(1 << (chan->scan_type.realbits - 1));
>                 else
>                         *val = 0;

nit: add blank line before switch for readability

> +               switch (chan->type) {
> +               case IIO_VOLTAGE:

Comment could be helpful here as a few things might not be obvious:
* Only applies to pseudo-differential inputs (!chan->differential)
* AINCOM voltage has to be converted to "raw" units.

> +                       if (st->aincom_mv && !chan->differential)
> +                               *val += DIV_ROUND_CLOSEST_ULL((u64)st->aincom_mv * NANO,
> +                                                             st->scale_avail[gain][1]);
> +                       return IIO_VAL_INT;
>                 /* Kelvin to Celsius */
> -               if (chan->type == IIO_TEMP)
> +               case IIO_TEMP:
>                         *val -= 273 * ad7192_get_temp_scale(unipolar);
> -               return IIO_VAL_INT;
> +                       return IIO_VAL_INT;
> +               default:
> +                       return -EINVAL;
> +               }
>         case IIO_CHAN_INFO_SAMP_FREQ:
>                 *val = DIV_ROUND_CLOSEST(ad7192_get_f_adc(st), 1024);
>                 return IIO_VAL_INT;
> @@ -1052,6 +1063,7 @@ static int ad7192_probe(struct spi_device *spi)
>  {
>         struct ad7192_state *st;
>         struct iio_dev *indio_dev;
> +       struct regulator *aincom;
>         int ret;
>
>         if (!spi->irq) {
> @@ -1067,6 +1079,31 @@ static int ad7192_probe(struct spi_device *spi)
>
>         mutex_init(&st->lock);
>
> +       /*
> +        * Regulator aincom is optional to maintain compatibility with older DT.
> +        * Newer firmware should provide a zero volt fixed supply if wired to
> +        * ground.
> +        */
> +       aincom = devm_regulator_get_optional(&spi->dev, "aincom");

Do we need to consider other errors separate from -EINVAL?

I've done something like this in other drivers:

if (IS_ERR(aincom)) {
    if (PTR_ERR(aincom) != -EINVAL)
        return dev_err_probe(...);

    st->aincom_mv = 0;
} else {
   ...
    st->aincom_mv = ...;
}
> +       if (IS_ERR(aincom)) {
> +               st->aincom_mv = 0;
> +       } else {
> +               ret = regulator_enable(aincom);
> +               if (ret)
> +                       return dev_err_probe(&spi->dev, ret,
> +                                            "Failed to enable specified AINCOM supply\n");
> +
> +               ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, aincom);
> +               if (ret)
> +                       return ret;
> +
> +               ret = regulator_get_voltage(aincom);
> +               if (ret < 0)
> +                       return dev_err_probe(&spi->dev, ret,
> +                                            "Device tree error, AINCOM voltage undefined\n");
> +               st->aincom_mv = ret / 1000;
> +       }
> +
>         st->avdd = devm_regulator_get(&spi->dev, "avdd");
>         if (IS_ERR(st->avdd))
>                 return PTR_ERR(st->avdd);
> --
> 2.34.1
>

  parent reply	other threads:[~2024-05-01 16:54 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 16:29 [PATCH v7 0/6] iio: adc: ad7192: Add AD7194 support Alisa-Dariana Roman
2024-04-30 16:29 ` [PATCH v7 1/6] iio: adc: ad7192: Use standard attribute Alisa-Dariana Roman
2024-04-30 16:29 ` [PATCH v7 2/6] dt-bindings: iio: adc: ad7192: Add aincom supply Alisa-Dariana Roman
2024-04-30 16:29 ` [PATCH v7 3/6] " Alisa-Dariana Roman
2024-04-30 20:28   ` Andy Shevchenko
2024-05-01 16:54   ` David Lechner [this message]
2024-04-30 16:29 ` [PATCH v7 4/6] dt-bindings: iio: adc: Add single-channel property Alisa-Dariana Roman
2024-04-30 17:15   ` Conor Dooley
2024-04-30 16:29 ` [PATCH v7 5/6] dt-bindings: iio: adc: ad7192: Add AD7194 support Alisa-Dariana Roman
2024-04-30 17:21   ` Conor Dooley
2024-05-05 19:46     ` Jonathan Cameron
2024-05-06 15:54       ` Conor Dooley
2024-05-10 10:05     ` Alisa-Dariana Roman
2024-05-10 14:21       ` David Lechner
2024-05-10 21:26         ` Conor Dooley
2024-05-11 11:29           ` Jonathan Cameron
2024-04-30 17:26   ` Conor Dooley
2024-04-30 16:29 ` [PATCH v7 6/6] " Alisa-Dariana Roman
2024-04-30 20:33   ` Andy Shevchenko
2024-05-01 17:54   ` David Lechner
2024-05-06 13:39   ` Jonathan Cameron
2024-04-30 17:19 ` [PATCH v7 0/6] " Conor Dooley

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=CAMknhBHa7zfWeQj7LDFCZDWc8i8as1WD964L2J3z6v_Un6kXFQ@mail.gmail.com \
    --to=dlechner@baylibre.com \
    --cc=alexandru.tachici@analog.com \
    --cc=alisa.roman@analog.com \
    --cc=alisadariana@gmail.com \
    --cc=andy@kernel.org \
    --cc=bigunclemax@gmail.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fr0st61te@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=liambeguin@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt@analog.com \
    --cc=marcus.folkesson@gmail.com \
    --cc=michael.hennerich@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=okan.sahin@analog.com \
    --cc=robh@kernel.org \
    --cc=schnelle@linux.ibm.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).