Re: [PATCH v2 6/6] iio: adc: ad7124: Implement system calibration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/18/25 12:31 PM, Uwe Kleine-König wrote:
> Allow triggering both zero-scale and full-scale calibration via sysfs in
> the same way as it's done for ad7173.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx>
> ---

...

> +static ssize_t ad7124_write_syscalib(struct iio_dev *indio_dev,
> +				     uintptr_t private,
> +				     const struct iio_chan_spec *chan,
> +				     const char *buf, size_t len)
> +{
> +	struct ad7124_state *st = iio_priv(indio_dev);
> +	struct ad7124_channel *ch = &st->channels[chan->channel];
> +	struct device *dev = &st->sd.spi->dev;
> +	bool sys_calib;
> +	int ret, mode;
> +
> +	ret = kstrtobool(buf, &sys_calib);
> +	if (ret)
> +		return ret;
> +
> +	mode = ch->syscalib_mode;
> +	if (sys_calib) {

Could save some indent by inverting the if and doing early return.

> +		if (mode == AD7124_SYSCALIB_ZERO_SCALE) {

Probably should claim direct mode here to prevent calibration during
a buffered read or other operation (this seems to be missing from
other ad_sigma_delta driver calibrations functions as well).

> +			ch->cfg.calibration_offset = 0x800000;
> +
> +			ret = ad_sd_calibrate(&st->sd, AD7124_MODE_CAL_SYS_ZERO,
> +					      chan->address);
> +			if (ret < 0)
> +				return ret;
> +
> +			ret = ad_sd_read_reg(&st->sd, AD7124_OFFSET(ch->cfg.cfg_slot), 3,
> +					     &ch->cfg.calibration_offset);
> +			if (ret < 0)
> +				return ret;
> +
> +			dev_dbg(dev, "offset for channel %d after zero-scale calibration: 0x%x\n",
> +				chan->channel, ch->cfg.calibration_offset);
> +		} else {
> +			ch->cfg.calibration_gain = st->gain_default;
> +
> +			ret = ad_sd_calibrate(&st->sd, AD7124_MODE_CAL_SYS_FULL,
> +					      chan->address);
> +			if (ret < 0)
> +				return ret;
> +
> +			ret = ad_sd_read_reg(&st->sd, AD7124_GAIN(ch->cfg.cfg_slot), 3,
> +					     &ch->cfg.calibration_gain);
> +			if (ret < 0)
> +				return ret;
> +
> +			dev_dbg(dev, "gain for channel %d after full-scale calibration: 0x%x\n",
> +				chan->channel, ch->cfg.calibration_gain);
> +		}
> +	}
> +
> +	return len;
> +}
> +




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux