Linux IIO development
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 6/6] iio: adc: ad7124: Implement system calibration
Date: Tue, 18 Feb 2025 13:37:45 -0600	[thread overview]
Message-ID: <f3f074fb-312c-4f40-818a-05de28b229eb@baylibre.com> (raw)
In-Reply-To: <5ee955a72e6f5226233053a883e8897ae325b568.1739902968.git.u.kleine-koenig@baylibre.com>

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@baylibre.com>
> ---

...

> +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;
> +}
> +

  reply	other threads:[~2025-02-18 19:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 18:31 [PATCH v2 0/6] iio: adc: ad{4130,7124,7173}: A few fixes and ad7124 calibration Uwe Kleine-König
2025-02-18 18:31 ` [PATCH v2 1/6] iio: adc: ad_sigma_delta: Disable channel after calibration Uwe Kleine-König
2025-02-18 18:31 ` [PATCH v2 2/6] iio: adc: ad4130: Fix comparison of channel setups Uwe Kleine-König
2025-02-18 19:18   ` David Lechner
2025-02-19  8:53   ` Andy Shevchenko
2025-02-19 15:54     ` Uwe Kleine-König
2025-02-18 18:31 ` [PATCH v2 3/6] iio: adc: ad7124: Fix comparison of channel configs Uwe Kleine-König
2025-02-18 18:31 ` [PATCH v2 4/6] iio: adc: ad7173: " Uwe Kleine-König
2025-02-18 18:31 ` [PATCH v2 5/6] iio: adc: ad7124: Implement internal calibration at probe time Uwe Kleine-König
2025-02-22 14:44   ` Jonathan Cameron
2025-02-18 18:31 ` [PATCH v2 6/6] iio: adc: ad7124: Implement system calibration Uwe Kleine-König
2025-02-18 19:37   ` David Lechner [this message]
2025-02-21 18:23     ` Uwe Kleine-König
2025-02-19 10:45   ` Nuno Sá
2025-02-22 14:48 ` [PATCH v2 0/6] iio: adc: ad{4130,7124,7173}: A few fixes and ad7124 calibration Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f3f074fb-312c-4f40-818a-05de28b229eb@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox