From: Jonathan Cameron <jic23@kernel.org>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <lars@metafoo.de>,
<Michael.Hennerich@analog.com>, <dlechner@baylibre.com>,
<nuno.sa@analog.com>, <andy@kernel.org>, <robh@kernel.org>,
<krzk+dt@kernel.org>, <conor+dt@kernel.org>,
<marcelo.schmitt1@gmail.com>
Subject: Re: [PATCH v2 3/7] iio: adc: ad4170: Add support for buffered data capture
Date: Sun, 4 May 2025 18:57:24 +0100 [thread overview]
Message-ID: <20250504185724.4700284f@jic23-huawei> (raw)
In-Reply-To: <db98c6cc188b501d914293268b67b0bdf26a4a46.1745841276.git.marcelo.schmitt@analog.com>
On Mon, 28 Apr 2025 09:28:20 -0300
Marcelo Schmitt <marcelo.schmitt@analog.com> wrote:
> Extend the AD4170 driver to allow buffered data capture in continuous read
> mode. In continuous read mode, the chip skips the instruction phase and
> outputs just ADC sample data, enabling faster sample rates to be reached.
> The internal channel sequencer always starts sampling from channel 0 and
> channel 0 must be enabled if more than one channel is selected for data
> capture. The scan mask validation callback checks the aforementioned
> condition is met.
>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
A few minor things spotted inline.
Thanks,
Jonathan
> ---
> changes since v1
> - Using bitmap_weight().
> - rx_buf changed from __be32 to u8 array to better cope with new regmap config.
>
> drivers/iio/adc/Kconfig | 2 +
> drivers/iio/adc/ad4170.c | 199 ++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 199 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index d5d0308da007..9b4787c127fc 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -75,6 +75,8 @@ config AD4170
> tristate "Analog Device AD4170 ADC Driver"
> depends on SPI
> select REGMAP_SPI
> + select IIO_BUFFER
> + select IIO_TRIGGERED_BUFFER
> help
> Say yes here to build support for Analog Devices AD4170 SPI analog
> to digital converters (ADC).
> diff --git a/drivers/iio/adc/ad4170.c b/drivers/iio/adc/ad4170.c
> index 4d0af15cb48d..5fcf1c023ac2 100644
> --- a/drivers/iio/adc/ad4170.c
> +++ b/drivers/iio/adc/ad4170.c
> @@ -10,8 +10,12 @@
> #include <linux/delay.h>
> #include <linux/device.h>
> #include <linux/err.h>
> +#include <linux/iio/buffer.h>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> +#include <linux/iio/trigger.h>
> +#include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/triggered_buffer.h>
> #include <linux/interrupt.h>
> #include <linux/irq.h>
> #include <linux/kernel.h>
> @@ -54,6 +58,7 @@
> #define AD4170_FILTER_FS_REG(x) (0xC7 + 14 * (x))
> #define AD4170_OFFSET_REG(x) (0xCA + 14 * (x))
> #define AD4170_GAIN_REG(x) (0xCD + 14 * (x))
> +#define AD4170_ADC_CTRL_CONT_READ_EXIT_REG 0x200 /* virtual reg */
>
> #define AD4170_REG_READ_MASK BIT(14)
>
> @@ -221,6 +226,7 @@ static const unsigned int ad4170_reg_size[] = {
> [AD4170_OFFSET_REG(5) ... AD4170_GAIN_REG(5)] = 3,
> [AD4170_OFFSET_REG(6) ... AD4170_GAIN_REG(6)] = 3,
> [AD4170_OFFSET_REG(7) ... AD4170_GAIN_REG(7)] = 3,
> + [AD4170_ADC_CTRL_CONT_READ_EXIT_REG] = 0,
> };
>
> enum ad4170_ref_buf {
> @@ -347,12 +353,16 @@ struct ad4170_state {
> u32 int_pin_sel;
> int sps_tbl[ARRAY_SIZE(ad4170_filt_names)][AD4170_MAX_FS_TBL_SIZE][2];
> struct completion completion;
> + struct iio_trigger *trig;
> + struct spi_transfer xfer;
> + struct spi_message msg;
> + __be32 bounce_buffer[AD4170_MAX_CHANNELS];
> /*
> * DMA (thus cache coherency maintenance) requires the transfer buffers
> * to live in their own cache lines.
> */
> u8 tx_buf[AD4170_SPI_MAX_XFER_LEN] __aligned(IIO_DMA_MINALIGN);
> - u8 rx_buf[AD4170_SPI_MAX_XFER_LEN];
> + u8 rx_buf[4];
Why this change?
> };
> +
> +static int ad4170_buffer_postenable(struct iio_dev *indio_dev)
> +{
> + struct ad4170_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = ad4170_set_mode(st, AD4170_ADC_CTRL_MODE_CONT);
> + if (ret < 0)
> + return ret;
> +
> + /*
> + * Enables continuous data register read.
> + * This enables continuous read of the ADC Data register. The ADC must
First two sentences seem to say the same thing.
> + * be in a continuous conversion mode.
> + */
> + return regmap_update_bits(st->regmap, AD4170_ADC_CTRL_REG,
> + AD4170_ADC_CTRL_CONT_READ_MSK,
> + FIELD_PREP(AD4170_ADC_CTRL_CONT_READ_MSK,
> + AD4170_ADC_CTRL_CONT_READ_ENABLE));
> +}
> +
> +static int ad4170_buffer_predisable(struct iio_dev *indio_dev)
> +{
> + struct ad4170_state *st = iio_priv(indio_dev);
> + int ret, i;
> +
> + /*
> + * Use a high register address (virtual register) to request a write of
> + * 0xA5 to the ADC during the first 8 SCLKs of the ADC data read cycle,
> + * thus exiting continuous read.
> + */
> + ret = regmap_write(st->regmap, AD4170_ADC_CTRL_CONT_READ_EXIT_REG, 0);
> +
> + ret = regmap_update_bits(st->regmap, AD4170_ADC_CTRL_REG,
> + AD4170_ADC_CTRL_CONT_READ_MSK,
> + FIELD_PREP(AD4170_ADC_CTRL_CONT_READ_MSK,
> + AD4170_ADC_CTRL_CONT_READ_DISABLE));
> + if (ret)
> + return ret;
> +
> + ret = ad4170_set_mode(st, AD4170_ADC_CTRL_MODE_IDLE);
> + if (ret)
> + return ret;
> +
> + /*
> + * The ADC sequences through all the enabled channels (see datasheet
> + * page 95). That can lead to incorrect channel being read if a
> + * single-shot read (or buffered read with different active_scan_mask)
> + * is done after buffer disable. Disable all channels so only requested
> + * channels will be read.
> + */
> + for (i = 0; i < indio_dev->num_channels; i++) {
> + ret = ad4170_set_channel_enable(st, i, false);
> + if (ret)
> + return ret;
> + }
> + return ret;
return 0; When we know we are in a good path we should make that clear.
> +}
next prev parent reply other threads:[~2025-05-04 17:57 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 12:27 [PATCH v2 0/7] iio: adc: Add support for AD4170 series of ADCs Marcelo Schmitt
2025-04-28 12:27 ` [PATCH v2 1/7] dt-bindings: iio: adc: Add AD4170 Marcelo Schmitt
2025-05-09 18:56 ` Rob Herring
2025-05-11 15:27 ` Marcelo Schmitt
2025-04-28 12:28 ` [PATCH v2 2/7] iio: adc: Add basic support for AD4170 Marcelo Schmitt
2025-05-02 11:28 ` Andy Shevchenko
2025-05-12 13:23 ` Marcelo Schmitt
2025-05-04 18:21 ` Jonathan Cameron
2025-04-28 12:28 ` [PATCH v2 3/7] iio: adc: ad4170: Add support for buffered data capture Marcelo Schmitt
2025-04-29 22:00 ` Andy Shevchenko
2025-04-30 13:40 ` Marcelo Schmitt
2025-05-02 8:56 ` Andy Shevchenko
2025-05-04 17:27 ` Jonathan Cameron
2025-05-04 17:57 ` Jonathan Cameron [this message]
2025-04-28 12:28 ` [PATCH v2 4/7] iio: adc: ad4170: Add clock provider support Marcelo Schmitt
2025-04-29 22:10 ` Andy Shevchenko
2025-05-06 8:21 ` kernel test robot
2025-04-28 12:28 ` [PATCH v2 5/7] iio: adc: ad4170: Add GPIO controller support Marcelo Schmitt
2025-04-29 22:14 ` Andy Shevchenko
2025-05-04 17:50 ` Jonathan Cameron
2025-04-28 12:29 ` [PATCH v2 6/7] iio: adc: ad4170: Add support for internal temperature sensor Marcelo Schmitt
2025-04-29 22:16 ` Andy Shevchenko
2025-05-04 17:44 ` Jonathan Cameron
2025-04-28 12:29 ` [PATCH v2 7/7] iio: adc: ad4170: Add support for weigh scale and RTD sensors Marcelo Schmitt
2025-04-29 22:26 ` Andy Shevchenko
2025-05-01 19:50 ` kernel test robot
2025-05-04 17:42 ` 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=20250504185724.4700284f@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=marcelo.schmitt@analog.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/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