Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Peter Rosin <peda@axentia.se>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	"Hartmut Knaack" <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	"Peter Meerwald-Stadler" <pmeerw@pmeerw.net>
Subject: Re: [PATCH] iio: afe: iio-rescale: Support processed channels
Date: Mon, 14 Dec 2020 16:34:23 +0000	[thread overview]
Message-ID: <20201214163423.00005e6c@Huawei.com> (raw)
In-Reply-To: <e755c671-a212-e93c-427c-66ab031289c3@axentia.se>

On Mon, 14 Dec 2020 16:30:22 +0100
Peter Rosin <peda@axentia.se> wrote:

> On 2020-12-14 16:07, Jonathan Cameron wrote:
> > On Mon, 14 Dec 2020 09:34:40 +0100
> > Peter Rosin <peda@axentia.se> wrote:
> >   
> >> On 2020-12-13 13:16, Jonathan Cameron wrote:  
> >>> On Sun, 13 Dec 2020 00:22:17 +0100
> >>> Peter Rosin <peda@axentia.se> wrote:
> >>>     
> >>>> On 2020-12-12 13:26, Linus Walleij wrote:    
> >>>>> On Mon, Nov 2, 2020 at 12:22 AM Linus Walleij <linus.walleij@linaro.org> 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.
> >>>>>>
> >>>>>> Cc: Peter Rosin <peda@axentia.se>
> >>>>>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>      
> >>>>>
> >>>>> Did we reach any conclusion on this? I really need to use
> >>>>> the rescaler on an ADC that only handles processed channels...
> >>>>>
> >>>>> I'm sorry that I can't make this ADC disappear :D      
> >>>>
> >>>> Hi!
> >>>>
> >>>> My conclusion was that the patch is buggy since it presents inconsistent
> >>>> information. That needs to be fixed one way or the other. If the offending
> >>>> information cannot be filtered out for some reason, I don't know what to
> >>>> do. Details in my previous comment [1]. BTW, I still do not know the answer
> >>>> to the .read_avail question at the end of that message, and I don't have
> >>>> time to dig into it. Sorry.    
> >>>
> >>> Unless I'm missing something, I think it presents no information unless
> >>> we strangely have a driver providing read_avail for _RAW but only
> >>> _PROCESSED channels which is a bug.  I'm not that bothered about
> >>> missing information in this particular, somewhat obscure, corner case.
> >>>
> >>> So I think we should take the patch as it stands.  It's missed the
> >>> merge window now anyway unfortunately.  So Peter, I would suggest we
> >>> take this and perhaps revisit to tidy up loose corners when we all have
> >>> more time.    
> >>
> >> My concern was a driver with a raw channel, including read_avail, providing
> >> raw sample values but that no easy conversion existed to get from that to
> >> the processed values. One option for the driver in that case would be to
> >> provide these raw values, but then have no scaling info.  
> > 
> > Generally I resist this a lot. The reason is that it is impossible to write
> > generic userspace software against it. The one time we did let this happen
> > was with some of the heart rate sensors (pulse oximeters) where the algorithm
> > to derive the eventual value is both complex - based on published literature,
> > and proprietary (what was actually readily usable). What the measurement being
> > provided to userspace was is well documented, but not how on earth you get from
> > that to something useable for what the sensor is designed to measure.
> >   
> >> I.e. the way I see
> >> it, it is perfectly reasonable for a driver to provide raw with read_avail,
> >> no scaling but also processed values.  
> > 
> > Why?  What use would the raw values actually be?  There are a couple of historical
> > drivers where they evolved to this state, but it is not one we would normally accept.
> > We go to a lot of effort to try and avoid this.  
> 
> Drivers that have eveloved over time is exactly one such reason. E.g. a driver
> starts out by not caring about wrong measurements at one end of the spectrum
> because it is "linear enough" for the first use, someone comes along and fixes
> that. But by that time it's impossible to completely remove the raw channel
> because that would be a regression for some reason. And there you are. A
> driver with raw plus read_avail, no scaling but a processed channel. Or
> something like that...

Yup, that's pretty much what tends to happen.  I've gotten a lot stricter
on checking datasheets to try and stop this happening, but still possible more
will slip through (particularly as can't always get the datasheet)
> 
> >> And that gets transformed by the
> >> rescaler into the processed values being presented as raw, with rescaling
> >> added on top, but with the read_avail info for this new raw channel being
> >> completely wrong.
> >>
> >> For the intended driver (ab8500-gpadc) this is not the case (it has no
> >> read_avail for its raw channel). But it does have a raw channel, so adding
> >> read_avail seems easy and I can easily see other drivers already doing it.
> >> Haven't checked that though...  
> > 
> > Drat. I'd failed to register this is one of those corner cases.  
> 
> I'm not sure, I just browsed the code. Maybe I misread it?

It's doing both - you were right.  I think there are only a small number of
drivers that have that history.

Looks superficially like it's easy enough to catch this corner case and
block it - so lets do that.

Jonathan


> 
> Cheers,
> Peter
> 
> >> But if you say that this never happens, fine. Otherwise, since it's too
> >> late for the merge window anyway, the patch might as well be updated such
> >> that the rescaler blocks the read_avail channel in this situation, if it
> >> exists.  
> > 
> > That's fair enough.  A sanity check and then suitable warning message to explain
> > why it is blocked makes sense.  
> 


  reply	other threads:[~2020-12-14 16:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-01 23:22 [PATCH] iio: afe: iio-rescale: Support processed channels Linus Walleij
2020-11-15 11:21 ` Linus Walleij
2020-11-15 17:44 ` Jonathan Cameron
2020-11-16  8:18   ` Peter Rosin
2020-12-13 12:12     ` Jonathan Cameron
2020-12-12 12:26 ` Linus Walleij
2020-12-12 23:22   ` Peter Rosin
2020-12-13 12:16     ` Jonathan Cameron
2020-12-14  8:34       ` Peter Rosin
2020-12-14 15:07         ` Jonathan Cameron
2020-12-14 15:30           ` Peter Rosin
2020-12-14 16:34             ` Jonathan Cameron [this message]
2021-01-04 14:45               ` Linus Walleij
2021-01-04 17:11                 ` Jonathan Cameron
2021-01-04 18:09                   ` Peter Rosin
2020-12-13 15:16 ` Andy Shevchenko

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=20201214163423.00005e6c@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=peda@axentia.se \
    --cc=pmeerw@pmeerw.net \
    /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