Skip to content

Commit bee4483

Browse files
linuswjic23
authored andcommitted
iio: afe: rescale: Accept only offset channels
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: 53ebee9 ("iio: afe: iio-rescale: Support processed channels") Fixes: 9decacd ("iio: afe: rescale: Fix boolean logic bug") Reported-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Peter Rosin <peda@axentia.se> Link: https://lore.kernel.org/r/20230902-iio-rescale-only-offset-v2-1-988b807754c8@linaro.org Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 865b080 commit bee4483

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/iio/afe/iio-rescale.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,18 @@ static int rescale_read_raw(struct iio_dev *indio_dev,
214214
return ret < 0 ? ret : -EOPNOTSUPP;
215215
}
216216

217-
ret = iio_read_channel_scale(rescale->source, &scale, &scale2);
218-
return rescale_process_offset(rescale, ret, scale, scale2,
217+
if (iio_channel_has_info(rescale->source->channel,
218+
IIO_CHAN_INFO_SCALE)) {
219+
ret = iio_read_channel_scale(rescale->source, &scale, &scale2);
220+
return rescale_process_offset(rescale, ret, scale, scale2,
221+
schan_off, val, val2);
222+
}
223+
224+
/*
225+
* If we get here we have no scale so scale 1:1 but apply
226+
* rescaler and offset, if any.
227+
*/
228+
return rescale_process_offset(rescale, IIO_VAL_FRACTIONAL, 1, 1,
219229
schan_off, val, val2);
220230
default:
221231
return -EINVAL;
@@ -280,8 +290,9 @@ static int rescale_configure_channel(struct device *dev,
280290
chan->type = rescale->cfg->type;
281291

282292
if (iio_channel_has_info(schan, IIO_CHAN_INFO_RAW) &&
283-
iio_channel_has_info(schan, IIO_CHAN_INFO_SCALE)) {
284-
dev_info(dev, "using raw+scale source channel\n");
293+
(iio_channel_has_info(schan, IIO_CHAN_INFO_SCALE) ||
294+
iio_channel_has_info(schan, IIO_CHAN_INFO_OFFSET))) {
295+
dev_info(dev, "using raw+scale/offset source channel\n");
285296
} else if (iio_channel_has_info(schan, IIO_CHAN_INFO_PROCESSED)) {
286297
dev_info(dev, "using processed channel\n");
287298
rescale->chan_processed = true;

0 commit comments

Comments
 (0)