Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

From: Jonathan Cameron

Date: Mon Jun 29 2026 - 20:29:07 EST


> > +static int ads1262_read_raw(struct iio_dev *indio_dev,
> > + struct iio_chan_spec const *chan, int *val,
> > + int *val2, long mask)
> > +{
> > + struct ads1262 *st = iio_priv(indio_dev);
> > + struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
> > + u8 realbits = chan->scan_type.realbits;
> > + __be32 raw;
> > + int ret;
> > +
> > + switch (mask) {
> > + case IIO_CHAN_INFO_RAW:
> > + ret = ads1262_channel_read(st, chan_data, &raw);
> > + if (ret)
> > + return ret;
> > + *val = sign_extend32(be32_to_cpu(raw), realbits - 1);
> > +
> > + return IIO_VAL_INT;
> > +
> > + case IIO_CHAN_INFO_SCALE: {
> > + guard(mutex)(&st->chan_lock);
> > +
> > + ret = ads1262_channel_get_scale(st, chan, val, val2);
> > + if (ret)
> > + return ret;
> > +
> > + return IIO_VAL_INT_PLUS_NANO;
> > + }
> > +
> > + case IIO_CHAN_INFO_HARDWAREGAIN: {
>
> There is only one other ADC that uses "hardwaregain". Usually, we just make
> scale writeable to control the gain. I don't remember what the rules for
> that attribute are. Using it for in_voltage is not documented in the ABI.

Roughly speaking it should only be used when the gain is no affecting
the thing being measured (so we can't do it with _scale).
Examples are things like the gain on a time of flight sensor - it
affects how likely we are to get a measurement, not what the measurement is.

Hmm. The one ADC using is the ina2xx - that's a weird device so it
would take some digging to try and figure out why that one go through
review.

>
> > + guard(mutex)(&st->chan_lock);
> > +
> > + *val = ads1262_pga_gain_avail[chan_data->gain];
> > +
> > + return IIO_VAL_INT;
> > + }
> > +
> > + case IIO_CHAN_INFO_SAMP_FREQ: {
> > + guard(mutex)(&st->chan_lock);
> > +
> > + *val = ads1262_data_rate_avail[chan_data->data_rate][0];
> > + *val2 = ads1262_data_rate_avail[chan_data->data_rate][1];
> > +
> > + return IIO_VAL_INT_PLUS_MICRO;
> > + }
> > +
> > + default:
> > + return -EOPNOTSUPP;
> > + }
> > +}