Skip to content

Commit

Permalink
iio: inkern: pass through raw values if no scaling
Browse files Browse the repository at this point in the history
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.

A sensor not providing a scale, but providing a _raw attribute
could be valid if for example the scale is the default of 1,
but an offset needs to be applied to convert to the _processed
form.

Signed-off-by: Linus Walleij <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
linusw authored and jic23 committed Jan 14, 2017
1 parent 948b707 commit adc8ec5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/iio/inkern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit adc8ec5

Please sign in to comment.