Skip to content

Commit 67eedba

Browse files
mhennerichgregkh
authored andcommitted
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>
1 parent 49b81a3 commit 67eedba

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎drivers/iio/industrialio-core.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,26 +295,33 @@ static ssize_t iio_read_channel_info(struct device *dev,
295295
struct iio_dev *indio_dev = dev_get_drvdata(dev);
296296
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
297297
int val, val2;
298+
bool scale_db = false;
298299
int ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
299300
&val, &val2, this_attr->address);
300301

301302
if (ret < 0)
302303
return ret;
303304

304-
if (ret == IIO_VAL_INT)
305+
switch (ret) {
306+
case IIO_VAL_INT:
305307
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:
307311
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" : "");
309314
else
310-
return sprintf(buf, "%d.%06u\n", val, val2);
311-
} else if (ret == IIO_VAL_INT_PLUS_NANO) {
315+
return sprintf(buf, "%d.%06u%s\n", val, val2,
316+
scale_db ? " dB" : "");
317+
case IIO_VAL_INT_PLUS_NANO:
312318
if (val2 < 0)
313319
return sprintf(buf, "-%d.%09u\n", val, -val2);
314320
else
315321
return sprintf(buf, "%d.%09u\n", val, val2);
316-
} else
322+
default:
317323
return 0;
324+
}
318325
}
319326

320327
static ssize_t iio_write_channel_info(struct device *dev,

‎include/linux/iio/types.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ enum iio_modifier {
5050
#define IIO_VAL_INT 1
5151
#define IIO_VAL_INT_PLUS_MICRO 2
5252
#define IIO_VAL_INT_PLUS_NANO 3
53+
#define IIO_VAL_INT_PLUS_MICRO_DB 4
5354

5455
#endif /* _IIO_TYPES_H_ */

0 commit comments

Comments
 (0)