Re: [PATCH 4/5] iio: adc: ti-ads1262: Add calibration support

From: Jonathan Cameron

Date: Sat Jun 13 2026 - 09:51:12 EST


On Fri, 12 Jun 2026 17:46:22 -0500
Kurt Borja <kuurtb@xxxxxxxxx> wrote:

> Add channel calibration support.
>
> Signed-off-by: Kurt Borja <kuurtb@xxxxxxxxx>
> ---
> drivers/iio/adc/ti-ads1262.c | 70 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 69 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ti-ads1262.c b/drivers/iio/adc/ti-ads1262.c
> index 6d5f22836ad8..b33505e7fdc7 100644
> --- a/drivers/iio/adc/ti-ads1262.c
> +++ b/drivers/iio/adc/ti-ads1262.c
> @@ -217,6 +217,10 @@
> #define ADS1262_RMUX_AVDD_AVSS 4
> #define ADS1262_RMUX_COUNT 5
>
> +/* The calibration word is signed 24 bits value */
> +#define ADS1262_CALIB_WORD_MAX ((int)(GENMASK(22, 0)))
> +#define ADS1262_CALIB_WORD_MIN (-ADS1262_CALIB_WORD_MAX - 1)
> +
> struct ads1262_channel {
> /* MODE0 */
> u8 conv_delay:4;
> @@ -453,6 +457,32 @@ static int ads1262_dev_start_one(struct ads1262 *st, u8 runmode)
> return 0;
> }
>
> +static int ads1262_read_calib(struct ads1262 *st, unsigned int reg, u32 *val)
> +{
> + __le32 lval;
> + int ret;
> +
> + /*
> + * The calibration word is a signed 24 bit LSB-first value.

Single line comment. However, it's also fairly clear from the code, so maybe
no comment at all.

> + */
> + ret = regmap_bulk_read(st->regmap, reg, &lval, 3);

Read it into a u8 [3] and use get_unaligned_le24()
That avoids us having to think too much about the bits that aren't
initialized and static analysis / compilers having to figure out
they don't matter. I general it is easier to understand.

> + if (ret)
> + return ret;
> + *val = sign_extend32(le32_to_cpu(lval), 23);
> +
> + return 0;
> +}
> +
> +static int ads1262_write_calib(struct ads1262 *st, unsigned int reg, u32 val)
> +{
> + __le32 lval = cpu_to_le32(val);
> +
> + /*
> + * The calibration word is a signed 24 bit LSB-first value.
> + */
> + return regmap_bulk_write(st->regmap, reg, &lval, 3);

Similar with a u8 [3] for the '__le24' storage.

> +}
> +