Re: [PATCH v4 3/5] iio: adc: ad7606: add offset and phase calibration support

From: Andy Shevchenko
Date: Thu May 08 2025 - 14:40:15 EST


On Thu, May 08, 2025 at 12:06:07PM +0200, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@xxxxxxxxxxxx>
>
> Add support for offset and phase calibration, only for
> devices that support software mode, that are:
>
> ad7606b
> ad7606c-16
> ad7606c-18

...

> +static int ad7606_get_calib_offset(struct ad7606_state *st, int ch, int *val)
> +{
> + int ret;
> +
> + ret = st->bops->reg_read(st, AD7606_CALIB_OFFSET(ch));
> + if (ret < 0)
> + return ret;

> + *val = st->chip_info->calib_offset_avail[0] + ret *
> + st->chip_info->calib_offset_avail[1];

You are too fast with new versions... As I pointed out, this is not a logical
split. My only concern was the column, i.e. to be as

*val = st->chip_info->calib_offset_avail[0] +
ret * st->chip_info->calib_offset_avail[1];

> + return 0;
> +}

...

> + val -= start_val;
> + val /= step_val;

Hmm...

To me the

val = (val - start_val) / step_val;

looks better as it immediately gives an idea of the initial content of the val.
Ideally I would even add a new temporary variable for this, so the operand and
the assignee won't be the same variable.

> + return st->bops->reg_write(st, AD7606_CALIB_OFFSET(ch), val);

--
With Best Regards,
Andy Shevchenko