Skip to content

Commit 1af14a9

Browse files
machschmittjic23
authored andcommitted
iio: adc: ad4170-4: Add timestamp channel
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> Link: https://patch.msgid.link/e0af7e5424898bee0f3edfbb017133624efc169d.1751895245.git.marcelo.schmitt@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent e16c8a7 commit 1af14a9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

drivers/iio/adc/ad4170-4.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138

139139
#define AD4170_NUM_ANALOG_PINS 9
140140
#define AD4170_MAX_ADC_CHANNELS 16
141+
#define AD4170_MAX_IIO_CHANNELS (AD4170_MAX_ADC_CHANNELS + 1)
141142
#define AD4170_MAX_ANALOG_PINS 8
142143
#define AD4170_MAX_SETUPS 8
143144
#define AD4170_INVALID_SETUP 9
@@ -334,7 +335,7 @@ struct ad4170_state {
334335
struct ad4170_setup_info setup_infos[AD4170_MAX_SETUPS];
335336
struct ad4170_chan_info chan_infos[AD4170_MAX_ADC_CHANNELS];
336337
struct completion completion;
337-
struct iio_chan_spec chans[AD4170_MAX_ADC_CHANNELS];
338+
struct iio_chan_spec chans[AD4170_MAX_IIO_CHANNELS];
338339
struct spi_device *spi;
339340
struct regmap *regmap;
340341
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)
16331634
return ret;
16341635
}
16351636

1637+
/* Add timestamp channel */
1638+
struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);
1639+
1640+
st->chans[chan_num] = ts_chan;
1641+
num_channels = num_channels + 1;
1642+
16361643
indio_dev->num_channels = num_channels;
16371644
indio_dev->channels = st->chans;
16381645

@@ -1693,6 +1700,9 @@ static int ad4170_initial_config(struct iio_dev *indio_dev)
16931700
unsigned int val;
16941701

16951702
chan = &indio_dev->channels[i];
1703+
if (chan->type == IIO_TIMESTAMP)
1704+
continue;
1705+
16961706
chan_info = &st->chan_infos[chan->address];
16971707

16981708
setup = &chan_info->setup;
@@ -1812,6 +1822,9 @@ static int ad4170_buffer_predisable(struct iio_dev *indio_dev)
18121822
* channels will be read.
18131823
*/
18141824
for (i = 0; i < indio_dev->num_channels; i++) {
1825+
if (indio_dev->channels[i].type == IIO_TIMESTAMP)
1826+
continue;
1827+
18151828
ret = ad4170_set_channel_enable(st, i, false);
18161829
if (ret)
18171830
return ret;
@@ -1863,7 +1876,9 @@ static irqreturn_t ad4170_trigger_handler(int irq, void *p)
18631876
memcpy(&st->bounce_buffer[i++], st->rx_buf, ARRAY_SIZE(st->rx_buf));
18641877
}
18651878

1866-
iio_push_to_buffers(indio_dev, st->bounce_buffer);
1879+
iio_push_to_buffers_with_ts(indio_dev, st->bounce_buffer,
1880+
sizeof(st->bounce_buffer),
1881+
iio_get_time_ns(indio_dev));
18671882
err_out:
18681883
iio_trigger_notify_done(indio_dev->trig);
18691884
return IRQ_HANDLED;

0 commit comments

Comments
 (0)