diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-10-16 18:29:00 +0200 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-10-19 19:46:51 +0200 |
commit | 103d9fb907058e4eb052f4f7302d1b07eb6a7792 (patch) | |
tree | 8ab834da14137f068195eb30660ffdd19f41acdd /drivers/iio/inkern.c | |
parent | iio: Use strict_strtouint instead of kstrtoul (diff) | |
download | linux-103d9fb907058e4eb052f4f7302d1b07eb6a7792.tar.xz linux-103d9fb907058e4eb052f4f7302d1b07eb6a7792.zip |
iio: Add a logarithmic fractional value type
For ADCs or DACs the denominator for fractional types often is a power of two.
In this case we can use a shift operation instead of the rather expensive 64 bit
division. This patch adds a new fractional type which expects the denominator to
be specified as the log2 of the actual denominator. E.g. for ADCs and DACs this
will usually be the number of significant bits.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/inkern.c')
-rw-r--r-- | drivers/iio/inkern.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 5230a33886c0..b394621d362c 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -314,6 +314,9 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, *processed = div_s64(raw64 * (s64)scale_val * scale, scale_val2); break; + case IIO_VAL_FRACTIONAL_LOG2: + *processed = (raw64 * (s64)scale_val * scale) >> scale_val2; + break; default: return -EINVAL; } |