All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: "Nuno Sá" <noname.nuno@gmail.com>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	"Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Michael Hennerich" <michael.hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	linux-kernel@vger.kernel.org,
	"Stefan Popa" <stefan.popa@analog.com>
Subject: Re: [PATCH v2 3/3] iio: adc: ad7380: new driver for AD7380 ADCs
Date: Wed, 13 Dec 2023 14:47:16 +0100	[thread overview]
Message-ID: <CAMknhBE6mPepiE=EYBj0ScU8SHXMhpO+D_kKBKFj6W+go_Jrxg@mail.gmail.com> (raw)
In-Reply-To: <5f7a1c60ccebe13ba6cdfa5d8f9632bc9b838137.camel@gmail.com>

On Wed, Dec 13, 2023 at 1:18 PM Nuno Sá <noname.nuno@gmail.com> wrote:
>
> On Wed, 2023-12-13 at 05:21 -0600, David Lechner wrote:
> > 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@analog.com>
> > Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---
> >
> > v2 changes:
> > - Fixed CONFIG_AD7380 in Makefile
> > - rx_buf = st->scan_data.raw instead of rx_buf = &st->scan_data
> > - Moved iio_push_to_buffers_with_timestamp() outside of if statement
> > - Removed extra blank lines
> > - Renamed regulator disable function
> > - Dropped checking of adi,sdo-mode property (regardless of the actual
> >         wiring, we can always use 1-wire mode)
> > - Added available_scan_masks (we always sample two channels at the same time
> >   so we need to let userspace know this)
> > - Added check for missing driver match data
> >
> >  MAINTAINERS              |   1 +
> >  drivers/iio/adc/Kconfig  |  16 ++
> >  drivers/iio/adc/Makefile |   1 +
> >  drivers/iio/adc/ad7380.c | 464 +++++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 482 insertions(+)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index e2a998be5879..5a54620a31b8 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -438,6 +438,7 @@ S:  Supported
> >  W:
> > https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad738x
> >  W:     https://ez.analog.com/linux-software-drivers
> >  F:     Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
> > +F:     drivers/iio/adc/ad7380.c
> >
> >  AD7877 TOUCHSCREEN DRIVER
> >  M:     Michael Hennerich <michael.hennerich@analog.com>
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index 35f9867da12c..cbfd626712e3 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -122,6 +122,22 @@ config AD7298
> >           To compile this driver as a module, choose M here: the
> >           module will be called ad7298.
> >
> > +config AD7380
> > +       tristate "Analog Devices AD7380 ADC driver"
> > +       depends on SPI_MASTER
> > +       select IIO_BUFFER
> > +       select IIO_TRIGGER
> > +       select IIO_TRIGGERED_BUFFER
> > +       help
> > +         AD7380 is a family of simultaneous sampling ADCs that share the same
> > +         SPI register map and have similar pinouts.
> > +
> > +         Say yes here to build support for Analog Devices AD7380 ADC and
> > +         similar chips.
> > +
> > +         To compile this driver as a module, choose M here: the module will be
> > +         called ad7380.
> > +
> >  config AD7476
> >         tristate "Analog Devices AD7476 1-channel ADCs driver and other similar
> > devices from AD and TI"
> >         depends on SPI
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index bee11d442af4..9c921c497655 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -16,6 +16,7 @@ obj-$(CONFIG_AD7291) += ad7291.o
> >  obj-$(CONFIG_AD7292) += ad7292.o
> >  obj-$(CONFIG_AD7298) += ad7298.o
> >  obj-$(CONFIG_AD7923) += ad7923.o
> > +obj-$(CONFIG_AD7380) += ad7380.o
> >  obj-$(CONFIG_AD7476) += ad7476.o
> >  obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
> >  obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
> > diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
> > new file mode 100644
> > index 000000000000..b8025b636b67
> > --- /dev/null
> > +++ b/drivers/iio/adc/ad7380.c
> > @@ -0,0 +1,464 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Analog Devices AD738x Simultaneous Sampling SAR ADCs
> > + *
> > + * Copyright 2017 Analog Devices Inc.
> > + * Copyright 2023 BayLibre, SAS
> > + */
> > +
> > +#include <linux/bitfield.h>
> > +#include <linux/bitops.h>
> > +#include <linux/cleanup.h>
> > +#include <linux/device.h>
> > +#include <linux/err.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/regmap.h>
> > +#include <linux/regulator/consumer.h>
> > +#include <linux/slab.h>
> > +#include <linux/spi/spi.h>
> > +#include <linux/sysfs.h>
> > +
> > +#include <linux/iio/buffer.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/iio/sysfs.h>
> > +#include <linux/iio/trigger_consumer.h>
> > +#include <linux/iio/triggered_buffer.h>
> > +
>
> ...
>
> >
> > +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");
> > +       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");
>
> Still not using a regmap_bus... You could at least argue in the last version why
> you're not doing it rather than ignoring the comment :).
>
> I'm asking for it because it already happened (in IIO) to me and I was asked for
> implementing the bus. You also gain things like regmap core handling endianism and
> formatting the work buffer for you (eg: regmap_bulk_read() could be more efficient),
>
> > +       indio_dev->channels = st->chip_info->channels;
> > +       indio_dev->num_channels = st->chip_info->num_channels;
> > +       indio_dev->dev.parent = &spi->dev;
>
> still not addressed...
>
> With at least the above (for the regmap_bus I'll leave the ultimate decision to
> Jonathan - not a deal breaker for me):
>
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
>
>
> - Nuno Sá
>

Sorry, I did not mean to ignore these. I just did a bad job of
double-checking that I addressed all comments before sending v2. :-(

If we need a v3, I will look into regmap_bus but at leas
superficially, I don't see much difference for this part, i.e not
really any case where bulk ops make sense and since it uses SPI bus
underneath, endianness isn't an issue.

  reply	other threads:[~2023-12-13 13:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13 11:21 [PATCH v2 0/3] iio: adc: add new ad7380 driver David Lechner
2023-12-13 11:21 ` [PATCH v2 1/3] dt-bindings: spi: add spi-rx-bus-channels peripheral property David Lechner
2023-12-13 11:21 ` [PATCH v2 2/3] dt-bindings: iio: adc: Add binding for AD7380 ADCs David Lechner
2023-12-13 16:10   ` Conor Dooley
2023-12-13 16:11     ` Conor Dooley
2023-12-13 16:15   ` Conor Dooley
2023-12-13 11:21 ` [PATCH v2 3/3] iio: adc: ad7380: new driver " David Lechner
2023-12-13 12:18   ` Nuno Sá
2023-12-13 13:47     ` David Lechner [this message]
2023-12-13 14:07       ` Nuno Sá
2023-12-14 10:14   ` Jonathan Cameron
2023-12-14 10:33     ` David Lechner
2023-12-14 12:36       ` Jonathan Cameron
2023-12-14 15:03         ` David Lechner

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='CAMknhBE6mPepiE=EYBj0ScU8SHXMhpO+D_kKBKFj6W+go_Jrxg@mail.gmail.com' \
    --to=dlechner@baylibre.com \
    --cc=broonie@kernel.org \
    --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=michael.hennerich@analog.com \
    --cc=noname.nuno@gmail.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.