From: Marcelo Schmitt <marcelo.schmitt@analog.com>
To: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, <lars@metafoo.de>,
<Michael.Hennerich@analog.com>, <dlechner@baylibre.com>,
<nuno.sa@analog.com>, <andy@kernel.org>,
<andriy.shevchenko@intel.com>, <robh@kernel.org>,
<krzk+dt@kernel.org>, <conor+dt@kernel.org>,
<linus.walleij@linaro.org>, <brgl@bgdev.pl>, <broonie@kernel.org>,
<lgirdwood@gmail.com>, <marcelo.schmitt1@gmail.com>
Subject: [PATCH v8 08/12] iio: adc: ad4170-4: Add timestamp channel
Date: Mon, 7 Jul 2025 10:53:08 -0300 [thread overview]
Message-ID: <e0af7e5424898bee0f3edfbb017133624efc169d.1751895245.git.marcelo.schmitt@analog.com> (raw)
In-Reply-To: <cover.1751895245.git.marcelo.schmitt@analog.com>
Add timestamp channel allowing to record the moment at which ADC samples
are captured in buffered read mode.
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
Change log v7 -> v8
- This is now patch 8 in the series (moved from end of the series to right after
buffer support patch).
- Reworked to not add 'num_adc_chans' field to struct ad4170_state.
drivers/iio/adc/ad4170-4.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 738f37394402..30ae667a252c 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -138,6 +138,7 @@
#define AD4170_NUM_ANALOG_PINS 9
#define AD4170_MAX_ADC_CHANNELS 16
+#define AD4170_MAX_IIO_CHANNELS (AD4170_MAX_ADC_CHANNELS + 1)
#define AD4170_MAX_ANALOG_PINS 8
#define AD4170_MAX_SETUPS 8
#define AD4170_INVALID_SETUP 9
@@ -334,7 +335,7 @@ struct ad4170_state {
struct ad4170_setup_info setup_infos[AD4170_MAX_SETUPS];
struct ad4170_chan_info chan_infos[AD4170_MAX_ADC_CHANNELS];
struct completion completion;
- struct iio_chan_spec chans[AD4170_MAX_ADC_CHANNELS];
+ struct iio_chan_spec chans[AD4170_MAX_IIO_CHANNELS];
struct spi_device *spi;
struct regmap *regmap;
int sps_tbl[ARRAY_SIZE(ad4170_filt_names)][AD4170_MAX_FS_TBL_SIZE][2];
@@ -1633,6 +1634,12 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
return ret;
}
+ /* Add timestamp channel */
+ struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);
+
+ st->chans[chan_num] = ts_chan;
+ num_channels = num_channels + 1;
+
indio_dev->num_channels = num_channels;
indio_dev->channels = st->chans;
@@ -1693,6 +1700,9 @@ static int ad4170_initial_config(struct iio_dev *indio_dev)
unsigned int val;
chan = &indio_dev->channels[i];
+ if (chan->type == IIO_TIMESTAMP)
+ continue;
+
chan_info = &st->chan_infos[chan->address];
setup = &chan_info->setup;
@@ -1812,6 +1822,9 @@ static int ad4170_buffer_predisable(struct iio_dev *indio_dev)
* channels will be read.
*/
for (i = 0; i < indio_dev->num_channels; i++) {
+ if (indio_dev->channels[i].type == IIO_TIMESTAMP)
+ continue;
+
ret = ad4170_set_channel_enable(st, i, false);
if (ret)
return ret;
@@ -1863,7 +1876,9 @@ static irqreturn_t ad4170_trigger_handler(int irq, void *p)
memcpy(&st->bounce_buffer[i++], st->rx_buf, ARRAY_SIZE(st->rx_buf));
}
- iio_push_to_buffers(indio_dev, st->bounce_buffer);
+ iio_push_to_buffers_with_ts(indio_dev, st->bounce_buffer,
+ sizeof(st->bounce_buffer),
+ iio_get_time_ns(indio_dev));
err_out:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.47.2
next prev parent reply other threads:[~2025-07-07 13:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 13:49 [PATCH v8 00/12] iio: adc: Add support for AD4170 series of ADCs Marcelo Schmitt
2025-07-07 13:50 ` [PATCH v8 01/12] dt-bindings: iio: adc: Add AD4170-4 Marcelo Schmitt
2025-07-07 13:50 ` [PATCH v8 02/12] iio: adc: Add basic support for AD4170-4 Marcelo Schmitt
2025-07-07 13:51 ` [PATCH v8 03/12] iio: adc: ad4170-4: Add support for calibration gain Marcelo Schmitt
2025-07-07 13:51 ` [PATCH v8 04/12] iio: adc: ad4170-4: Add support for calibration bias Marcelo Schmitt
2025-07-07 13:51 ` [PATCH v8 05/12] Documentation: ABI: IIO: Add sinc5+avg to the filter_type_available list Marcelo Schmitt
2025-07-07 13:52 ` [PATCH v8 06/12] iio: adc: ad4170-4: Add digital filter and sample frequency config support Marcelo Schmitt
2025-07-07 13:52 ` [PATCH v8 07/12] iio: adc: ad4170-4: Add support for buffered data capture Marcelo Schmitt
2025-07-07 13:53 ` Marcelo Schmitt [this message]
2025-07-07 13:53 ` [PATCH v8 09/12] iio: adc: ad4170-4: Add clock provider support Marcelo Schmitt
2025-07-07 13:53 ` [PATCH v8 10/12] iio: adc: ad4170-4: Add GPIO controller support Marcelo Schmitt
2025-07-07 13:54 ` [PATCH v8 11/12] iio: adc: ad4170-4: Add support for internal temperature sensor Marcelo Schmitt
2025-07-07 13:54 ` [PATCH v8 12/12] iio: adc: ad4170-4: Add support for weigh scale, thermocouple, and RTD sens Marcelo Schmitt
2025-07-07 17:48 ` [PATCH v8 00/12] iio: adc: Add support for AD4170 series of ADCs 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=e0af7e5424898bee0f3edfbb017133624efc169d.1751895245.git.marcelo.schmitt@analog.com \
--to=marcelo.schmitt@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.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
all inboxes | Powered by JetHome®