All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: broonie@kernel.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org,  jic23@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, lgirdwood@gmail.com,
	 linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-spi@vger.kernel.org, michael.hennerich@analog.com,
	nuno.sa@analog.com,  robh+dt@kernel.org, stefan.popa@analog.com
Subject: Re: [PATCH v3 3/3] iio: adc: ad7380: new driver for AD7380 ADCs
Date: Fri, 15 Dec 2023 18:31:46 +0100	[thread overview]
Message-ID: <CAMknhBEPxYtZps2cFk0ZPckbcHenXJ_v4Dv+82ENg47J52gHxQ@mail.gmail.com> (raw)
In-Reply-To: <66e9fe7a-927b-465f-aafe-8aea0e5998a4@wanadoo.fr>

On Fri, Dec 15, 2023 at 5:53 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> Le 15/12/2023 à 11:32, David Lechner a écrit :
> > This adds a new driver for the AD7380 family ADCs.
> >
> > The driver currently implements basic support for the AD7380, AD7381,
> > AD7383, and AD7384 2-channel differential ADCs. Support for additional
> > single-ended and 4-channel chips that use the same register map as well
> > as additional features of the chip will be added in future patches.
> >
> > Co-developed-by: Stefan Popa <stefan.popa-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
> > Signed-off-by: Stefan Popa <stefan.popa-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
> > Reviewed-by: Nuno Sa <nuno.sa-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
> > Signed-off-by: David Lechner <dlechner-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
> > ---
>
> ...
>
> > +static void ad7380_regulator_disable(void *p)
> > +{
> > +     regulator_disable(p);
> > +}
> > +
> > +static int ad7380_probe(struct spi_device *spi)
> > +{
> > +     struct iio_dev *indio_dev;
> > +     struct ad7380_state *st;
> > +     int ret;
> > +
> > +     indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> > +     if (!indio_dev)
> > +             return -ENOMEM;
> > +
> > +     st = iio_priv(indio_dev);
> > +     st->spi = spi;
> > +     st->chip_info = spi_get_device_match_data(spi);
> > +     if (!st->chip_info)
> > +             return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n");
> > +
> > +     st->vref = devm_regulator_get_optional(&spi->dev, "refio");
>
> Hi,
>
> devm_regulator_get_enable_optional()?
> to save some LoC below and ad7380_regulator_disable()

It would be nice if we could, but we need the pointer to the regulator
to read the voltage of the regulator (it is the reference voltage for
an ADC). So we can't use devm_regulator_get_enable_optional() because
it only an int and not the pointer to the regulator.

>
> CJ
>
> > +     if (IS_ERR(st->vref)) {
> > +             /*
> > +              * If there is no REFIO supply, then it means that we are using
> > +              * the internal 2.5V reference.
> > +              */
> > +             if (PTR_ERR(st->vref) == -ENODEV)
> > +                     st->vref = NULL;
> > +             else
> > +                     return dev_err_probe(&spi->dev, PTR_ERR(st->vref),
> > +                                          "Failed to get refio regulator\n");
> > +     }
> > +
> > +     if (st->vref) {
> > +             ret = regulator_enable(st->vref);
> > +             if (ret)
> > +                     return ret;
> > +
> > +             ret = devm_add_action_or_reset(&spi->dev, ad7380_regulator_disable,
> > +                                            st->vref);
> > +             if (ret)
> > +                     return ret;
> > +     }
> > +
> > +     st->regmap = devm_regmap_init(&spi->dev, NULL, st, &ad7380_regmap_config);
> > +     if (IS_ERR(st->regmap))
> > +             return dev_err_probe(&spi->dev, PTR_ERR(st->regmap),
> > +                                  "failed to allocate register map\n");
> > +
> > +     indio_dev->channels = st->chip_info->channels;
> > +     indio_dev->num_channels = st->chip_info->num_channels;
> > +     indio_dev->name = st->chip_info->name;
> > +     indio_dev->info = &ad7380_info;
> > +     indio_dev->modes = INDIO_DIRECT_MODE;
> > +     indio_dev->available_scan_masks = ad7380_2_channel_scan_masks;
> > +
> > +     ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
> > +                                           iio_pollfunc_store_time,
> > +                                           ad7380_trigger_handler, NULL);
> > +     if (ret)
> > +             return ret;
> > +
> > +     ret = ad7380_init(st);
> > +     if (ret)
> > +             return ret;
> > +
> > +     return devm_iio_device_register(&spi->dev, indio_dev);
> > +}
>
> ...
>

  reply	other threads:[~2023-12-15 17:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15 10:32 [PATCH v3 0/3] iio: adc: add new ad7380 driver David Lechner
2023-12-15 10:32 ` [PATCH v3 1/3] dt-bindings: spi: add spi-rx-bus-channels peripheral property David Lechner
2023-12-15 19:58   ` Rob Herring
2024-01-07 16:43   ` Jonathan Cameron
2024-01-07 21:26     ` Mark Brown
2024-01-07 23:02       ` David Lechner
2024-01-08  8:40         ` Krzysztof Kozlowski
2024-01-08 16:39         ` Mark Brown
2024-01-08 17:15           ` David Lechner
2024-01-10  9:09             ` Jonathan Cameron
2023-12-15 10:32 ` [PATCH v3 2/3] dt-bindings: iio: adc: Add binding for AD7380 ADCs David Lechner
2023-12-15 10:32 ` [PATCH v3 3/3] iio: adc: ad7380: new driver " David Lechner
2023-12-15 16:53   ` Christophe JAILLET
2023-12-15 17:31     ` David Lechner [this message]
2023-12-15 17:34       ` David Lechner
2023-12-17 14:29   ` Jonathan Cameron

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=CAMknhBEPxYtZps2cFk0ZPckbcHenXJ_v4Dv+82ENg47J52gHxQ@mail.gmail.com \
    --to=dlechner@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=robh+dt@kernel.org \
    --cc=stefan.popa@analog.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 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.