diff options
author | Michael Hennerich <michael.hennerich@analog.com> | 2012-05-11 05:36:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-05-14 16:15:38 -0400 |
commit | 67eedba39ed1ac29908453647652c02fbbeeca1b (patch) | |
tree | 76f65924a8813a964fbd01ac6e750205082d8ed5 /drivers/iio | |
parent | 49b81a3c7415d9b02169f37b8559d468fd17686a (diff) |
iio: core: introduce dB scle: IIO_VAL_INT_PLUS_MICRO_DB
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/industrialio-core.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index b39a58757907..425cd4cf31fb 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c | |||
@@ -295,26 +295,33 @@ static ssize_t iio_read_channel_info(struct device *dev, | |||
295 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | 295 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
296 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | 296 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
297 | int val, val2; | 297 | int val, val2; |
298 | bool scale_db = false; | ||
298 | int ret = indio_dev->info->read_raw(indio_dev, this_attr->c, | 299 | int ret = indio_dev->info->read_raw(indio_dev, this_attr->c, |
299 | &val, &val2, this_attr->address); | 300 | &val, &val2, this_attr->address); |
300 | 301 | ||
301 | if (ret < 0) | 302 | if (ret < 0) |
302 | return ret; | 303 | return ret; |
303 | 304 | ||
304 | if (ret == IIO_VAL_INT) | 305 | switch (ret) { |
306 | case IIO_VAL_INT: | ||
305 | return sprintf(buf, "%d\n", val); | 307 | return sprintf(buf, "%d\n", val); |
306 | else if (ret == IIO_VAL_INT_PLUS_MICRO) { | 308 | case IIO_VAL_INT_PLUS_MICRO_DB: |
309 | scale_db = true; | ||
310 | case IIO_VAL_INT_PLUS_MICRO: | ||
307 | if (val2 < 0) | 311 | if (val2 < 0) |
308 | return sprintf(buf, "-%d.%06u\n", val, -val2); | 312 | return sprintf(buf, "-%d.%06u%s\n", val, -val2, |
313 | scale_db ? " dB" : ""); | ||
309 | else | 314 | else |
310 | return sprintf(buf, "%d.%06u\n", val, val2); | 315 | return sprintf(buf, "%d.%06u%s\n", val, val2, |
311 | } else if (ret == IIO_VAL_INT_PLUS_NANO) { | 316 | scale_db ? " dB" : ""); |
317 | case IIO_VAL_INT_PLUS_NANO: | ||
312 | if (val2 < 0) | 318 | if (val2 < 0) |
313 | return sprintf(buf, "-%d.%09u\n", val, -val2); | 319 | return sprintf(buf, "-%d.%09u\n", val, -val2); |
314 | else | 320 | else |
315 | return sprintf(buf, "%d.%09u\n", val, val2); | 321 | return sprintf(buf, "%d.%09u\n", val, val2); |
316 | } else | 322 | default: |
317 | return 0; | 323 | return 0; |
324 | } | ||
318 | } | 325 | } |
319 | 326 | ||
320 | static ssize_t iio_write_channel_info(struct device *dev, | 327 | static ssize_t iio_write_channel_info(struct device *dev, |