* [PATCH v3] iio: afe: iio-rescale: Support processed channels
@ 2021-05-18 9:27 Linus Walleij
2021-05-18 10:00 ` Peter Rosin
0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2021-05-18 9:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
Linus Walleij, Peter Rosin
It happens that an ADC will only provide raw or processed
voltage conversion channels. (adc/ab8500-gpadc.c).
On the Samsung GT-I9070 this is used for a light sensor
and current sense amplifier so we need to think of something.
The idea is to allow processed channels and scale them
with 1/1 and then the rescaler can modify the result
on top.
Link: https://lore.kernel.org/linux-iio/20201101232211.1194304-1-linus.walleij@linaro.org/
Cc: Peter Rosin <peda@axentia.se>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v2->v3:
- Reverse logic on raw+rescale vs processed channels.
- Make sure to not announce .read_avail() when using a processed
channel.
ChangeLog v1->v2:
- Deny calls to .read_avail() for processed channels, and
insert a comment.
- Move an assignment of IIO_VAL_FRACTIONAL down to the end
of the block for better readability.
---
drivers/iio/afe/iio-rescale.c | 41 ++++++++++++++++++++++++++++++-----
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
index e42ea2b1707d..774eb3044edd 100644
--- a/drivers/iio/afe/iio-rescale.c
+++ b/drivers/iio/afe/iio-rescale.c
@@ -29,6 +29,7 @@ struct rescale {
struct iio_channel *source;
struct iio_chan_spec chan;
struct iio_chan_spec_ext_info *ext_info;
+ bool chan_processed;
s32 numerator;
s32 denominator;
};
@@ -43,10 +44,27 @@ static int rescale_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- return iio_read_channel_raw(rescale->source, val);
+ if (rescale->chan_processed)
+ /*
+ * When only processed channels are supported, we
+ * read the processed data and scale it by 1/1
+ * augmented with whatever the rescaler has calculated.
+ */
+ return iio_read_channel_processed(rescale->source, val);
+ else
+ return iio_read_channel_raw(rescale->source, val);
case IIO_CHAN_INFO_SCALE:
- ret = iio_read_channel_scale(rescale->source, val, val2);
+ if (rescale->chan_processed) {
+ /*
+ * Processed channels are scaled 1-to-1
+ */
+ *val = 1;
+ *val2 = 1;
+ ret = IIO_VAL_FRACTIONAL;
+ } else {
+ ret = iio_read_channel_scale(rescale->source, val, val2);
+ }
switch (ret) {
case IIO_VAL_FRACTIONAL:
*val *= rescale->numerator;
@@ -130,16 +148,27 @@ static int rescale_configure_channel(struct device *dev,
chan->ext_info = rescale->ext_info;
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_err(dev, "source channel does not support raw/scale\n");
+ 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");
+ } else if (iio_channel_has_info(schan, IIO_CHAN_INFO_PROCESSED)) {
+ dev_info(dev, "using processed channel\n");
+ rescale->chan_processed = true;
+ } else {
+ dev_err(dev, "source channel is not supported\n");
return -EINVAL;
}
chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE);
- if (iio_channel_has_available(schan, IIO_CHAN_INFO_RAW))
+ /*
+ * Using .read_avail() is fringe to begin with and makes no sense
+ * whatsoever for processed channels, so we make sure that this cannot
+ * be called on a processed channel.
+ */
+ if (iio_channel_has_available(schan, IIO_CHAN_INFO_RAW) &&
+ !rescale->chan_processed)
chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW);
return 0;
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] iio: afe: iio-rescale: Support processed channels
2021-05-18 9:27 [PATCH v3] iio: afe: iio-rescale: Support processed channels Linus Walleij
@ 2021-05-18 10:00 ` Peter Rosin
2021-05-18 18:02 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Peter Rosin @ 2021-05-18 10:00 UTC (permalink / raw)
To: Linus Walleij, Jonathan Cameron, linux-iio
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler
Hi!
Thanks, this looks nice!
On 2021-05-18 11:27, Linus Walleij wrote:
> It happens that an ADC will only provide raw or processed
> voltage conversion channels. (adc/ab8500-gpadc.c).
> On the Samsung GT-I9070 this is used for a light sensor
> and current sense amplifier so we need to think of something.
>
> The idea is to allow processed channels and scale them
> with 1/1 and then the rescaler can modify the result
> on top.
>
> Link: https://lore.kernel.org/linux-iio/20201101232211.1194304-1-linus.walleij@linaro.org/
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Peter Rosin <peda@axentia.se>
Cheers,
Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] iio: afe: iio-rescale: Support processed channels
2021-05-18 10:00 ` Peter Rosin
@ 2021-05-18 18:02 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2021-05-18 18:02 UTC (permalink / raw)
To: Peter Rosin
Cc: Linus Walleij, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler
On Tue, 18 May 2021 12:00:10 +0200
Peter Rosin <peda@axentia.se> wrote:
> Hi!
>
> Thanks, this looks nice!
>
> On 2021-05-18 11:27, Linus Walleij wrote:
> > It happens that an ADC will only provide raw or processed
> > voltage conversion channels. (adc/ab8500-gpadc.c).
> > On the Samsung GT-I9070 this is used for a light sensor
> > and current sense amplifier so we need to think of something.
> >
> > The idea is to allow processed channels and scale them
> > with 1/1 and then the rescaler can modify the result
> > on top.
> >
> > Link: https://lore.kernel.org/linux-iio/20201101232211.1194304-1-linus.walleij@linaro.org/
> > Cc: Peter Rosin <peda@axentia.se>
> > Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
>
> Reviewed-by: Peter Rosin <peda@axentia.se>
Applied to the togreg branch of iio.git and pushed out as testing for
0-day to poke at it.
Thanks,
Jonathan
>
> Cheers,
> Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-18 18:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 9:27 [PATCH v3] iio: afe: iio-rescale: Support processed channels Linus Walleij
2021-05-18 10:00 ` Peter Rosin
2021-05-18 18:02 ` Jonathan Cameron
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).