From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: David Lechner <dlechner@baylibre.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Jonathan Corbet" <corbet@lwn.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: Re: [PATCH 2/4] iio: adc: ad4695: implement calibration support
Date: Wed, 21 Aug 2024 17:33:52 +0100 [thread overview]
Message-ID: <20240821173352.000000b6@Huawei.com> (raw)
In-Reply-To: <e2401290-5504-4a17-93bd-af8684a82a7a@baylibre.com>
On Wed, 21 Aug 2024 11:12:12 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 8/21/24 8:16 AM, Jonathan Cameron wrote:
> > On Tue, 20 Aug 2024 10:58:36 -0500
> > David Lechner <dlechner@baylibre.com> wrote:
> >
> >> The AD4695 has a calibration feature that allows the user to compensate
> >> for variations in the analog front end. This implements this feature in
> >> the driver using the standard `calibgain` and `calibbias` attributes.
> >>
> >> Signed-off-by: David Lechner <dlechner@baylibre.com>
> > Hi David,
> >
> > Whilst some of the messy value manipulation is unavoidable
> > (oh for signed integer zero!), I wonder if we can at least
> > move one case into the core.
> >
> > See below.
> >
> >> +
> >> +static int ad4695_write_raw(struct iio_dev *indio_dev,
> >> + struct iio_chan_spec const *chan,
> >> + int val, int val2, long mask)
> >> +{
> >> + struct ad4695_state *st = iio_priv(indio_dev);
> >> + unsigned int reg_val;
> >> + int ret;
> >> +
> >> + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> >> + switch (mask) {
> >> + case IIO_CHAN_INFO_CALIBSCALE:
> >> + switch (chan->type) {
> >> + case IIO_VOLTAGE:
> >> + if (val < 0 || val2 < 0)
> >> + reg_val = 0;
> >> + else if (val > 1)
> >> + reg_val = U16_MAX;
> >> + else
> >> + reg_val = (val * (1 << 16) +
> >> + mul_u64_u32_div(val2, 1 << 16,
> >> + MICRO)) / 2;
> > Maybe worth extending iio_write_channel_info() to handle
> > IIO_VAL_FRACTIONAL_LOG2()?
> > It'll look much like this and you'll need to provide write_raw_get_fmt()
> > so the core know what to do with the value formatting.
> >
> > I don't really like the mixture here between the read path being able
> > to rely on the core code to deal with the /2^X and the write path not.
>
> Sounds like a good idea to me.
>
> It seems like we would need to add an extra out parameter to
> write_raw_get_fmt to say what we want the X in 2^X to be. For
> example, we would want to make sure the val2 we get in write_raw
> for this driver is 15.
Yes. (I tried to reply to say I'd neglected this but managed to
just email myself. oops.)
Maybe it's too complex to bother given that. Definitely a job
for another day rather than something to block this series on.
Jonathan
>
> >> +
> >> + return regmap_write(st->regmap16,
> >> + AD4695_REG_GAIN_IN(chan->scan_index),
> >> + reg_val);
> >> + default:
> >> + return -EINVAL;
> >
> >
> >
>
next prev parent reply other threads:[~2024-08-21 16:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 15:58 [PATCH 0/4] iio: adc: ad4695: implement calibration support David Lechner
2024-08-20 15:58 ` [PATCH 1/4] iio: adc: ad4695: add 2nd regmap for 16-bit registers David Lechner
2024-08-20 15:58 ` [PATCH 2/4] iio: adc: ad4695: implement calibration support David Lechner
2024-08-21 4:21 ` kernel test robot
2024-08-26 10:57 ` Jonathan Cameron
2024-08-21 13:16 ` Jonathan Cameron
2024-08-21 16:12 ` David Lechner
2024-08-21 16:33 ` Jonathan Cameron [this message]
2024-08-20 15:58 ` [PATCH 3/4] doc: iio: ad4695: update for " David Lechner
2024-08-20 15:58 ` [PATCH 4/4] iio: ABI: document ad4695 new attributes David Lechner
2024-08-26 10:46 ` [PATCH 0/4] iio: adc: ad4695: implement calibration support 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=20240821173352.000000b6@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=corbet@lwn.net \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.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;
as well as URLs for NNTP newsgroup(s).