Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9251d14a authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron
Browse files

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: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 66ad1fd0
Loading
Loading
Loading
Loading
+10 −10
Original line number Original line Diff line number Diff line
@@ -113,7 +113,8 @@ static const struct iio_chan_spec ad5933_channels[] = {
		.type = IIO_TEMP,
		.type = IIO_TEMP,
		.indexed = 1,
		.indexed = 1,
		.channel = 0,
		.channel = 0,
		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
			BIT(IIO_CHAN_INFO_SCALE),
		.address = AD5933_REG_TEMP_DATA,
		.address = AD5933_REG_TEMP_DATA,
		.scan_index = -1,
		.scan_index = -1,
		.scan_type = {
		.scan_type = {
@@ -520,12 +521,11 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
{
{
	struct ad5933_state *st = iio_priv(indio_dev);
	struct ad5933_state *st = iio_priv(indio_dev);
	__be16 dat;
	__be16 dat;
	int ret = -EINVAL;
	int ret;


	mutex_lock(&indio_dev->mlock);
	switch (m) {
	switch (m) {
	case IIO_CHAN_INFO_RAW:
	case IIO_CHAN_INFO_RAW:
	case IIO_CHAN_INFO_PROCESSED:
		mutex_lock(&indio_dev->mlock);
		if (iio_buffer_enabled(indio_dev)) {
		if (iio_buffer_enabled(indio_dev)) {
			ret = -EBUSY;
			ret = -EBUSY;
			goto out;
			goto out;
@@ -543,16 +543,16 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
		if (ret < 0)
		if (ret < 0)
			goto out;
			goto out;
		mutex_unlock(&indio_dev->mlock);
		mutex_unlock(&indio_dev->mlock);
		ret = be16_to_cpu(dat);
		*val = sign_extend32(be16_to_cpu(dat), 13);
		/* Temp in Milli degrees Celsius */
		if (ret < 8192)
			*val = ret * 1000 / 32;
		else
			*val = (ret - 16384) * 1000 / 32;


		return IIO_VAL_INT;
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		*val = 1000;
		*val2 = 5;
		return IIO_VAL_FRACTIONAL_LOG2;
	}
	}


	return -EINVAL;
out:
out:
	mutex_unlock(&indio_dev->mlock);
	mutex_unlock(&indio_dev->mlock);
	return ret;
	return ret;