Skip to content

Commit 9251d14

Browse files
larsclausenjic23
authored andcommitted
staging:iio:ad5933: Report temperature as raw value
We shouldn't be doing the unit conversion in kernel space. Just report the raw value for the property and the scale. Userspace can do the conversion if necessary. Signed-off-by: Lars-Peter Clausen <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 66ad1fd commit 9251d14

File tree

1 file changed

+10
-10
lines changed
  • drivers/staging/iio/impedance-analyzer

1 file changed

+10
-10
lines changed

drivers/staging/iio/impedance-analyzer/ad5933.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ static const struct iio_chan_spec ad5933_channels[] = {
113113
.type = IIO_TEMP,
114114
.indexed = 1,
115115
.channel = 0,
116-
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
116+
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
117+
BIT(IIO_CHAN_INFO_SCALE),
117118
.address = AD5933_REG_TEMP_DATA,
118119
.scan_index = -1,
119120
.scan_type = {
@@ -520,12 +521,11 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
520521
{
521522
struct ad5933_state *st = iio_priv(indio_dev);
522523
__be16 dat;
523-
int ret = -EINVAL;
524+
int ret;
524525

525-
mutex_lock(&indio_dev->mlock);
526526
switch (m) {
527527
case IIO_CHAN_INFO_RAW:
528-
case IIO_CHAN_INFO_PROCESSED:
528+
mutex_lock(&indio_dev->mlock);
529529
if (iio_buffer_enabled(indio_dev)) {
530530
ret = -EBUSY;
531531
goto out;
@@ -543,16 +543,16 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
543543
if (ret < 0)
544544
goto out;
545545
mutex_unlock(&indio_dev->mlock);
546-
ret = be16_to_cpu(dat);
547-
/* Temp in Milli degrees Celsius */
548-
if (ret < 8192)
549-
*val = ret * 1000 / 32;
550-
else
551-
*val = (ret - 16384) * 1000 / 32;
546+
*val = sign_extend32(be16_to_cpu(dat), 13);
552547

553548
return IIO_VAL_INT;
549+
case IIO_CHAN_INFO_SCALE:
550+
*val = 1000;
551+
*val2 = 5;
552+
return IIO_VAL_FRACTIONAL_LOG2;
554553
}
555554

555+
return -EINVAL;
556556
out:
557557
mutex_unlock(&indio_dev->mlock);
558558
return ret;

0 commit comments

Comments
 (0)