Re: [PATCH v4 2/5] iio: adc: ti-adc128s052: Use shift and realbits

From: Jonathan Cameron
Date: Sun Jun 29 2025 - 12:27:12 EST


On Sat, 28 Jun 2025 13:01:53 -0700

> > > + .type = IIO_VOLTAGE, \
> > > + .indexed = 1, \
> > > + .channel = (num), \
> > > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> > > + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
> > > + .scan_index = (num), \
> > > + .scan_type = { \
> > > + .sign = 'u', \
> > > + .realbits = (real_bits), \
> > > + .storagebits = 16, \
> > > + .shift = (12 - real_bits), \
> > > + }, \
> > > }
> > >
> > > +#define ADC128_VOLTAGE_CHANNEL(num) _ADC128_VOLTAGE_CHANNEL(num, 12)
> >
> > I wonder if it would be clearer to just have the 12 explicit in each entry
> > and skip this two levels of macro thing?
> >
> Do you mean to pass realbits to
> ADC128_VOLTAGE_CHANNEL/_ADC128_VOLTAGE_CHANNEL as e.g.,
>
> static const struct iio_chan_spec adc122s021_channels[] = {
> ADC128_VOLTAGE_CHANNEL(0, 12),
> ADC128_VOLTAGE_CHANNEL(1, 12),
> };
>
> I think we added 2nd level macros as ADC082_VOLTAGE_CHANNEL,
> ADC102_VOLTAGE_CHANNEL, etc., to have a visual distinction for a different
> part nos.

I think as we can have lots of parts with each resolution that will
end up confusing.

> But I am ok if you prefer ADC128_VOLTAGE_CHANNEL with a second parameter
> as real_bits.

I think that's going to be easier to follow.

Jonathan