Re: [PATCH v3 3/3] iio: adc: ti-ads112c14: add continuous mode support

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
On Fri, Aug 07, 2026 at 04:19:48PM -0500, David Lechner (TI) wrote:
> Add support for continuous mode in the TI ADS112C14 ADC driver. In this
> mode the ADC itself is starting each conversion, so we add a trigger
> based on the DRDY interrupt to read each sample. This mode is also
> limited in that only one channel can be enabled at a time since the
> chip does not have a sequencer or simultaneous sampling capability.
> Continuous mode will only be used when this new trigger is the current
> trigger.

...

> static irqreturn_t ads112c14_trigger_handler(int irq, void *private)

>  	struct iio_poll_func *pf = private;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct ads112c14_data *data = iio_priv(indio_dev);
> +	unsigned int scan_mask_len = iio_get_masklength(indio_dev);

This is from indio_dev, which is defined two lines up, so this, longer one, can
be bumped one line up.

>  	u32 offset = 0;
>  	u32 i;
>  	int ret;
>  
> +	if (iio_trigger_using_own(indio_dev)) {
> +		i = find_first_bit(indio_dev->active_scan_mask, scan_mask_len);
> +		if (i >= scan_mask_len)

'>' is redundant, '==' suffices.

> +			goto out;
> +
> +		ret = ads112c14_scan_read(data, (u8 *)&data->scan[0]);
> +		if (ret) {
> +			const struct iio_chan_spec *chan = &indio_dev->channels[i];
> +
> +			dev_err_once(indio_dev->dev.parent,
> +				     "failed to read channel %d: %pe; additional errors will be suppressed\n",
> +				     chan->channel, ERR_PTR(ret));
> +			goto out;
> +		}
> +
> +		iio_push_to_buffers_with_ts(indio_dev, data->scan,
> +					    sizeof(data->scan), pf->timestamp);
> +		goto out;
> +	}

...

> +static int ads112c14_buffer_postenable(struct iio_dev *indio_dev)
> +{
> +	unsigned int scan_mask_len = iio_get_masklength(indio_dev);
> +	struct ads112c14_data *data = iio_priv(indio_dev);
> +	const struct iio_chan_spec *chan;
> +	unsigned int i;
> +	int ret;
> +
> +	if (!ads112c14_using_drdy_trigger(indio_dev))
> +		return 0;

> +	i = find_first_bit(indio_dev->active_scan_mask, scan_mask_len);
> +	if (i >= scan_mask_len)
> +		return -EINVAL;
> +
> +	chan = &indio_dev->channels[i];

These lines repeat what you have in ads112c14_trigger_handler(). Perhaps
a helper to return a channel or error pointer or NULL?

> +	guard(mutex)(&data->lock);
> +
> +	ret = ads112c14_prepare_channel(data, chan);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_assign_bits(data->regmap, ADS112C14_REG_DEVICE_CFG,
> +				 ADS112C14_DEVICE_CFG_CONV_MODE,
> +				 ADS112C14_DEVICE_CFG_CONV_MODE_CONTINUOUS);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(data->regmap, ADS112C14_REG_CONVERSION_CTRL,
> +			   ADS112C14_CONVERSION_CTRL_START);
> +	if (ret) {
> +		regmap_assign_bits(data->regmap, ADS112C14_REG_DEVICE_CFG,
> +				   ADS112C14_DEVICE_CFG_CONV_MODE,
> +				   ADS112C14_DEVICE_CFG_CONV_MODE_SINGLE_SHOT);
> +		return ret;
> +	}
> +
> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.