From: Jonathan Cameron <jic23@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Peter Rosin <peda@axentia.se>,
Lars-Peter Clausen <lars@metafoo.de>,
Liam Beguin <liambeguin@gmail.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: afe: rescale: Accept only offset channels
Date: Sat, 14 Oct 2023 17:48:58 +0100 [thread overview]
Message-ID: <20231014174858.73bcabbc@jic23-huawei> (raw)
In-Reply-To: <20230902-iio-rescale-only-offset-v2-1-988b807754c8@linaro.org>
On Sat, 02 Sep 2023 21:46:20 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:
> As noted by Jonathan Cameron: it is perfectly legal for a channel
> to have an offset but no scale in addition to the raw interface.
> The conversion will imply that scale is 1:1.
>
> Make rescale_configure_channel() accept just scale, or just offset
> to process a channel.
>
> When a user asks for IIO_CHAN_INFO_OFFSET in rescale_read_raw()
> we now have to deal with the fact that OFFSET could be present
> but SCALE missing. Add code to simply scale 1:1 in this case.
>
> Link: https://lore.kernel.org/linux-iio/CACRpkdZXBjHU4t-GVOCFxRO-AHGxKnxMeHD2s4Y4PuC29gBq6g@mail.gmail.com/
> Fixes: 53ebee949980 ("iio: afe: iio-rescale: Support processed channels")
> Fixes: 9decacd8b3a4 ("iio: afe: rescale: Fix boolean logic bug")
> Reported-by: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Peter, can you take a look at this v2?
Thanks,
Jonathan
> ---
> Changes in v2:
> - Fix rescale_read_raw() handle channels with offset but no scale.
> - Link to v1: https://lore.kernel.org/r/20230830-iio-rescale-only-offset-v1-1-40ab9f4436c7@linaro.org
> ---
> drivers/iio/afe/iio-rescale.c | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
> index 1f280c360701..56e5913ab82d 100644
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -214,8 +214,18 @@ static int rescale_read_raw(struct iio_dev *indio_dev,
> return ret < 0 ? ret : -EOPNOTSUPP;
> }
>
> - ret = iio_read_channel_scale(rescale->source, &scale, &scale2);
> - return rescale_process_offset(rescale, ret, scale, scale2,
> + if (iio_channel_has_info(rescale->source->channel,
> + IIO_CHAN_INFO_SCALE)) {
> + ret = iio_read_channel_scale(rescale->source, &scale, &scale2);
> + return rescale_process_offset(rescale, ret, scale, scale2,
> + schan_off, val, val2);
> + }
> +
> + /*
> + * If we get here we have no scale so scale 1:1 but apply
> + * rescaler and offset, if any.
> + */
> + return rescale_process_offset(rescale, IIO_VAL_FRACTIONAL, 1, 1,
> schan_off, val, val2);
> default:
> return -EINVAL;
> @@ -280,8 +290,9 @@ static int rescale_configure_channel(struct device *dev,
> chan->type = rescale->cfg->type;
>
> if (iio_channel_has_info(schan, IIO_CHAN_INFO_RAW) &&
> - iio_channel_has_info(schan, IIO_CHAN_INFO_SCALE)) {
> - dev_info(dev, "using raw+scale source channel\n");
> + (iio_channel_has_info(schan, IIO_CHAN_INFO_SCALE) ||
> + iio_channel_has_info(schan, IIO_CHAN_INFO_OFFSET))) {
> + dev_info(dev, "using raw+scale/offset source channel\n");
> } else if (iio_channel_has_info(schan, IIO_CHAN_INFO_PROCESSED)) {
> dev_info(dev, "using processed channel\n");
> rescale->chan_processed = true;
>
> ---
> base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
> change-id: 20230830-iio-rescale-only-offset-f28e05bd2deb
>
> Best regards,
next prev parent reply other threads:[~2023-10-14 16:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-02 19:46 [PATCH v2] iio: afe: rescale: Accept only offset channels Linus Walleij
2023-10-14 16:48 ` Jonathan Cameron [this message]
2023-10-14 22:38 ` Peter Rosin
2023-10-16 8:39 ` Linus Walleij
2023-10-16 10:05 ` Peter Rosin
2023-10-16 12:54 ` Linus Walleij
2023-10-17 9:05 ` Jonathan Cameron
2023-10-17 14:00 ` Peter Rosin
2023-10-17 19:27 ` 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=20231014174858.73bcabbc@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=lars@metafoo.de \
--cc=liambeguin@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peda@axentia.se \
/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