Re: [PATCH v2 6/7] iio: adc: ad4170: Add support for internal temperature sensor

Jonathan Cameron
2025-05-04T17:44:59Z

On Mon, 28 Apr 2025 09:29:12 -0300
Marcelo Schmitt <marcelo.schmitt@analog.com> wrote:

> The AD4170 has an internal temperature sensor that can be read using the
> ADC. Whenever possible, configure an IIO channel to provide the chip's
> temperature.
>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>

One trivial comment below.
I don't mind that much given you already did it this way though.

> /*
> * Receives the number of a multiplexed AD4170 input (ain_n), and stores the
> * voltage (in µV) of the specified input into ain_voltage. If the input number
> @@ -1189,9 +1210,27 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
> return ret;
> case IIO_CHAN_INFO_SCALE:
> pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
> - *val = chan_info->scale_tbl[pga][0];
> - *val2 = chan_info->scale_tbl[pga][1];
> - return IIO_VAL_INT_PLUS_NANO;
> + switch (chan->type) {
> + case IIO_VOLTAGE:

When you know you are going to have changes like this in later patches
in the same posted series it is fine to make the diff smaller by
using a switch from the start.

Occasionally you'll get a comment from someone like me who can't
hold the whole set in my head and misses that is what is going on.
Just reply to say it was diff minimization and likely no one will ever
mind!

> + *val = chan_info->scale_tbl[pga][0];
> + *val2 = chan_info->scale_tbl[pga][1];
> + return IIO_VAL_INT_PLUS_NANO;
> +
> + case IIO_TEMP:
> + /*
> + * The scale_tbl converts output codes to mV units so
> + * multiply by MILLI to make the factor convert to µV.
> + * Then, apply the temperature sensor change sensitivity
> + * of 477 μV/K. Finally, multiply the result by MILLI
> + * again to comply with milli degrees Celsius IIO ABI.
> + */
> + *val = 0;
> + *val2 = DIV_ROUND_CLOSEST(chan_info->scale_tbl[pga][1] * MILLI,
> + 477) * MILLI;
> + return IIO_VAL_INT_PLUS_NANO;
> + default:
> + return -EINVAL;
> + }