Skip to content

Commit 76cda5a

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/b7789604240f964ddeb756f9d17002371435f936.1751289747.git.marcelo.schmitt@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 6dbc03d commit 76cda5a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

drivers/iio/adc/ad4170-4.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
#define AD4170_NUM_ANALOG_PINS 9
188188
#define AD4170_NUM_GPIO_PINS 4
189189
#define AD4170_MAX_CHANNELS 16
190+
#define AD4170_MAX_IIO_CHANNELS (AD4170_MAX_CHANNELS + 1)
190191
#define AD4170_MAX_ANALOG_PINS 8
191192
#define AD4170_MAX_SETUPS 8
192193
#define AD4170_INVALID_SETUP 9
@@ -439,7 +440,7 @@ struct ad4170_state {
439440
int vrefs_uv[AD4170_MAX_SUP];
440441
u32 mclk_hz;
441442
struct ad4170_setup_info setup_infos[AD4170_MAX_SETUPS];
442-
struct iio_chan_spec chans[AD4170_MAX_CHANNELS];
443+
struct iio_chan_spec chans[AD4170_MAX_IIO_CHANNELS];
443444
struct ad4170_chan_info chan_infos[AD4170_MAX_CHANNELS];
444445
struct spi_device *spi;
445446
struct regmap *regmap;
@@ -456,6 +457,7 @@ struct ad4170_state {
456457
unsigned int clock_ctrl;
457458
int gpio_fn[AD4170_NUM_GPIO_PINS];
458459
unsigned int cur_src_pins[AD4170_NUM_CURRENT_SRC];
460+
unsigned int num_adc_chans;
459461
/*
460462
* DMA (thus cache coherency maintenance) requires the transfer buffers
461463
* to live in their own cache lines.
@@ -2395,7 +2397,16 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
23952397
return dev_err_probe(dev, ret, "Invalid input config\n");
23962398

23972399
st->chan_infos[chan_num].input_range_uv = ret;
2400+
chan_num++;
23982401
}
2402+
st->num_adc_chans = chan_num;
2403+
2404+
/* Add timestamp channel */
2405+
struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);
2406+
2407+
st->chans[chan_num] = ts_chan;
2408+
num_channels = num_channels + 1;
2409+
23992410
indio_dev->num_channels = num_channels;
24002411
indio_dev->channels = st->chans;
24012412

@@ -2608,7 +2619,7 @@ static int ad4170_initial_config(struct iio_dev *indio_dev)
26082619
return dev_err_probe(dev, ret,
26092620
"Failed to set ADC mode to idle\n");
26102621

2611-
for (i = 0; i < indio_dev->num_channels; i++) {
2622+
for (i = 0; i < st->num_adc_chans; i++) {
26122623
struct ad4170_chan_info *chan_info;
26132624
struct iio_chan_spec const *chan;
26142625
struct ad4170_setup *setup;
@@ -2733,7 +2744,7 @@ static int ad4170_buffer_predisable(struct iio_dev *indio_dev)
27332744
* is done after buffer disable. Disable all channels so only requested
27342745
* channels will be read.
27352746
*/
2736-
for (i = 0; i < indio_dev->num_channels; i++) {
2747+
for (i = 0; i < st->num_adc_chans; i++) {
27372748
ret = ad4170_set_channel_enable(st, i, false);
27382749
if (ret)
27392750
return ret;
@@ -2785,7 +2796,9 @@ static irqreturn_t ad4170_trigger_handler(int irq, void *p)
27852796
memcpy(&st->bounce_buffer[i++], st->rx_buf, ARRAY_SIZE(st->rx_buf));
27862797
}
27872798

2788-
iio_push_to_buffers(indio_dev, st->bounce_buffer);
2799+
iio_push_to_buffers_with_ts(indio_dev, st->bounce_buffer,
2800+
sizeof(st->bounce_buffer),
2801+
iio_get_time_ns(indio_dev));
27892802
err_out:
27902803
iio_trigger_notify_done(indio_dev->trig);
27912804
return IRQ_HANDLED;

0 commit comments

Comments
 (0)