From: "Nuno Sá" <noname.nuno@gmail.com>
To: David Lechner <dlechner@baylibre.com>,
Jonathan Cameron <jic23@kernel.org>
Cc: "Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Jonathan Corbet" <corbet@lwn.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: adc: ad4695: implement triggered buffer
Date: Fri, 09 Aug 2024 16:24:00 +0200 [thread overview]
Message-ID: <8bb01a8946aaa5855b5ac15d79c0292a668eee59.camel@gmail.com> (raw)
In-Reply-To: <20240807-iio-adc-ad4695-buffered-read-v1-1-bdafc39b2283@baylibre.com>
On Wed, 2024-08-07 at 15:02 -0500, David Lechner wrote:
> This implements buffered reads for the ad4695 driver using the typical
> triggered buffer implementation, including adding a soft timestamp
> channel.
>
> The chip has 4 different modes for doing conversions. The driver is
> using the advanced sequencer mode since that is the only mode that
> allows individual configuration of all aspects each channel (e.g.
> bipolar config currently and oversampling to be added in the future).
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
Hi David,
Just two nit comments...
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> drivers/iio/adc/ad4695.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 230 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ad4695.c b/drivers/iio/adc/ad4695.c
> index 007ecb951bc3..a3bd5be36134 100644
> --- a/drivers/iio/adc/ad4695.c
> +++ b/drivers/iio/adc/ad4695.c
...
>
>
> +static int ad4695_buffer_preenable(struct iio_dev *indio_dev)
> +{
> + struct ad4695_state *st = iio_priv(indio_dev);
> + struct spi_transfer *xfer;
> + u8 temp_chan_bit = st->chip_info->num_voltage_inputs;
> + bool temp_chan_en = false;
> + u32 reg, mask, val, bit, num_xfer, num_slots;
> + int ret;
> +
> + /*
> + * We are using the advanced sequencer since it is the only way to read
> + * multiple channels that allows individual configuration of each
> + * voltage input channel. Slot 0 in the advanced sequencer is used to
> + * account for the gap between trigger polls - we don't read data from
> + * this slot. Each enabled voltage channel is assigned a slot starting
> + * with slot 1.
> + */
> + num_slots = 1;
> +
> + memset(st->buf_read_xfer, 0, sizeof(st->buf_read_xfer));
> +
> + /* First xfer is only to trigger conversion of slot 1, so no rx. */
> + xfer = &st->buf_read_xfer[0];
> + xfer->cs_change = 1;
> + xfer->delay.value = AD4695_T_CNVL_NS;
> + xfer->delay.unit = SPI_DELAY_UNIT_NSECS;
> + xfer->cs_change_delay.value = AD4695_T_CONVERT_NS;
> + xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
> + num_xfer = 1;
> +
> + iio_for_each_active_channel(indio_dev, bit) {
> + xfer = &st->buf_read_xfer[num_xfer];
> + xfer->bits_per_word = 16;
> + xfer->rx_buf = &st->buf[(num_xfer - 1) * 2];
> + xfer->len = 2;
> + xfer->cs_change = 1;
> + xfer->cs_change_delay.value = AD4695_T_CONVERT_NS;
> + xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
> +
> + if (bit == temp_chan_bit) {
> + temp_chan_en = true;
> + } else {
> + reg = AD4695_REG_AS_SLOT(num_slots);
> + val = FIELD_PREP(AD4695_REG_AS_SLOT_INX, bit);
> +
> + ret = regmap_write(st->regmap, reg, val);
> + if (ret)
> + return ret;
> +
> + num_slots++;
> + }
> +
> + num_xfer++;
> + }
> +
> + /*
> + * Don't keep CS asserted after last xfer. Also triggers conversion of
> + * slot 0.
> + */
> + xfer->cs_change = 0;
> +
> + /**
> + * The advanced sequencer requires that at least 2 slots are enabled.
> + * Since slot 0 is always used for other purposes, we need only 1
> + * enabled voltage channel to meet this requirement. This error will
> + * only happen if only the temperature channel is enabled.
> + */
> + if (num_slots < 2) {
> + dev_err_ratelimited(&indio_dev->dev,
> + "Buffered read requires at least 1 voltage channel
> enabled\n");
This one is intriguing... Why the ratelimited variant? Normally you'd use that in IRQ
routines where the log could be flooded.
> + return -EINVAL;
> + }
> +
> + /*
> + * Temperature channel isn't included in the sequence, but rather
> + * controlled by setting a bit in the TEMP_CTRL register.
> + */
> +
> + reg = AD4695_REG_TEMP_CTRL;
> + mask = AD4695_REG_TEMP_CTRL_TEMP_EN;
> + val = FIELD_PREP(mask, temp_chan_en ? 1 : 0);
> +
> + ret = regmap_update_bits(st->regmap, reg, mask, val);
> + if (ret)
> + return ret;
> +
> + spi_message_init_with_transfers(&st->buf_read_msg, st->buf_read_xfer,
> + num_xfer);
> +
> + ret = spi_optimize_message(st->spi, &st->buf_read_msg);
> + if (ret)
> + return ret;
> +
> + /* This triggers conversion of slot 0. */
> + ret = ad4695_enter_advanced_sequencer_mode(st, num_slots);
> + if (ret) {
> + spi_unoptimize_message(&st->buf_read_msg);
> + return ret;
> + }
Could save one line with (unless ad4695_enter_advanced_sequencer_mode() does not
return 0 on success)
ret = ad4695_enter_advanced_sequencer_mode(st, num_slots);
if (ret)
spi_unoptimize_message(&st->buf_read_msg);
return ret;
- Nuno Sá
next prev parent reply other threads:[~2024-08-09 14:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-07 20:02 [PATCH 0/2] iio: adc: ad4695: implement triggered buffer David Lechner
2024-08-07 20:02 ` [PATCH 1/2] " David Lechner
2024-08-08 8:52 ` kernel test robot
2024-08-10 9:20 ` Jonathan Cameron
2024-08-09 14:24 ` Nuno Sá [this message]
2024-08-09 16:01 ` David Lechner
2024-08-10 9:35 ` Jonathan Cameron
2024-08-12 17:03 ` David Lechner
2024-08-13 7:28 ` Nuno Sá
2024-08-14 18:56 ` Jonathan Cameron
2024-08-07 20:02 ` [PATCH 2/2] doc: iio: ad4695: document buffered read David Lechner
2024-08-10 9:36 ` 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=8bb01a8946aaa5855b5ac15d79c0292a668eee59.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=corbet@lwn.net \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox