diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-10-16 17:29:00 +0100 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-10-19 18:46:51 +0100 |
commit | 103d9fb907058e4eb052f4f7302d1b07eb6a7792 (patch) | |
tree | 8ab834da14137f068195eb30660ffdd19f41acdd /drivers/iio/industrialio-core.c | |
parent | 948ad20504894436c008c8a50f74e277edeff9a1 (diff) | |
download | blackbird-obmc-linux-103d9fb907058e4eb052f4f7302d1b07eb6a7792.tar.gz blackbird-obmc-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/industrialio-core.c')
-rw-r--r-- | drivers/iio/industrialio-core.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 6eb24dbc081e..37650a72b31f 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -397,6 +397,11 @@ static ssize_t iio_read_channel_info(struct device *dev, val2 = do_div(tmp, 1000000000LL); val = tmp; return sprintf(buf, "%d.%09u\n", val, val2); + case IIO_VAL_FRACTIONAL_LOG2: + tmp = (s64)val * 1000000000LL >> val2; + val2 = do_div(tmp, 1000000000LL); + val = tmp; + return sprintf(buf, "%d.%09u\n", val, val2); default: return 0; } |