Re: [PATCH] iio: inkern: pass through raw values if no scaling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 11 January 2017 10:48:39 GMT+00:00, Linus Walleij <linus.walleij@xxxxxxxxxx> wrote:
>When a consumer calls iio_read_channel_processed() the IIO core
>tries to apply scaling to the value, but if the channel only
>supports reading raw values, we should return that raw value
>to the cosumer instead of an error.
>
>This is what userspace is expected to do with sensors only
>providing raw values so the kernel should do the same, so as to
>avoid adding scaling boilerplate to drivers for hardware that
>actually return processed values from raw reads.
Hmm. I guess this is reasonable as it would be correct to have a raw value if the scale was 1
 and hence not supplied, but there was an offset
If neither is supplied so scale is 1 and offset 0 
then having it as raw is a bug.

Come to think of it the raw element is only useful on the case where we have no known units.
Otherwise the absence of offset and scale alone would indicate a processed value.

Upshot is I agree with change but might add info to patch message when I apply it.  Arguably
 userspace should be specifically indicating that there is no known transform (perhaps by not
 listing units) rather than sweeping it under the carpet.  This is perfectly valid for many intensity
 of reflection proximity sensors where the meaning of the value is dependant on the material which we can't know.


Fun fun fun 

Jonathan
>
>Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
>---
> drivers/iio/inkern.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
>index b0f4630a163f..7a13535dc3e9 100644
>--- a/drivers/iio/inkern.c
>+++ b/drivers/iio/inkern.c
>@@ -601,8 +601,14 @@ static int
>iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
> 
> 	scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
> 					IIO_CHAN_INFO_SCALE);
>-	if (scale_type < 0)
>-		return scale_type;
>+	if (scale_type < 0) {
>+		/*
>+		 * Just pass raw values as processed if no scaling is
>+		 * available.
>+		 */
>+		*processed = raw;
>+		return 0;
>+	}
> 
> 	switch (scale_type) {
> 	case IIO_VAL_INT:

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux