[PATCH] iio: si7020: Fix endianness for I2C reads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Si7020 outputs most significant byte of the measurement result first
and least significant byte last. As a result the data returned by
i2c_smbus_read_word_data appears as big endian. Fix this by making a
call to an approbriate byte conversion routine.

Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
---
 drivers/iio/humidity/si7020.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
index fa3b809..5c89e14 100644
--- a/drivers/iio/humidity/si7020.c
+++ b/drivers/iio/humidity/si7020.c
@@ -56,7 +56,7 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
 					       SI7020CMD_RH_HOLD);
 		if (ret < 0)
 			return ret;
-		*val = ret >> 2;
+		*val = be16_to_cpu(ret) >> 2;
 		if (chan->type == IIO_HUMIDITYRELATIVE)
 			*val &= GENMASK(11, 0);
 		return IIO_VAL_INT;
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux