Re: [PATCH v3 7/8] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel
From: Jonathan Cameron
Date: Sun Jul 12 2026 - 22:21:53 EST
On Fri, 10 Jul 2026 17:50:40 -0500
"David Lechner (TI)" <dlechner@xxxxxxxxxxxx> wrote:
> Implement support for the programmable gain amplifier on the internal
> short SYS_MON channel. This channel is used for calibration, so it is
> useful to be able to set the PGA to the same gain as the external
> channels. The gain setting is implemented via the `_scale` attribute.
>
> In the future, we may want to support different reference voltages for
> this channel, so the scale_available table is populated during probe
> rather than being a static table.
>
> Signed-off-by: David Lechner (TI) <dlechner@xxxxxxxxxxxx>
> ---
> v3 changes:
> * Use IIO_VAL_DECIMAL64_PICO for scale.
Sashiko (I think rightly) raised endian concerns on the read_avail
side of things. It think you need to do the decompose to fill that
that rather than relying on placement of bytes in the 64 bit int.
Jonathan
> ---
> drivers/iio/adc/ti-ads112c14.c | 128 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 125 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> index 4d2e7d37be82..2ce4411a0d86 100644
> --- a/drivers/iio/adc/ti-ads112c14.c
> +++ b/drivers/iio/adc/ti-ads112c14.c
>
> +static int ads112c14_read_avail(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, const int **vals,
> + int *type, int *length, long mask)
> +{
> + struct ads112c14_data *data = iio_priv(indio_dev);
> +
> + if (chan->channel == ADS112C14_SYS_MON_CHANNEL_SHORT) {
> + *vals = (const int *)data->sys_mon_chan_short_scale_available;
Sashiko is mean about this and it may have a point.. Definitely needs
a comment as you are forcing a u64 to be interpreted as an array of ints and
on big endian systems the top and bottom half will get swapped.
> + *length = 2 * ARRAY_SIZE(data->sys_mon_chan_short_scale_available);
> + *type = IIO_VAL_DECIMAL64_PICO;
> + return IIO_AVAIL_LIST;
> + }
> +
> + return -EINVAL;
> +}
> +
>
> +static void ads112c14_populate_scale_available(s64 *scale_avail, u32 full_scale,
> + u32 fsr_bits)
> +{
> + for (u32 i = 0; i < ARRAY_SIZE(ads112c14_pga_gains_x10); i++) {
> + u64 gain_x10 = ads112c14_pga_gains_x10[i];
> +
> + scale_avail[i] = div64_u64((u64)PICO * 10U * full_scale,
> + gain_x10 * BIT(fsr_bits));
I think this needs to happen into a local variable that is then decomposed
into two int elements of scale_avail[]. I.e. type of that needs to change.
> + }
> +}