linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: si7020: Fix endianness for I2C reads
@ 2015-03-13  2:53 Andrey Smirnov
  2015-03-13 10:45 ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Smirnov @ 2015-03-13  2:53 UTC (permalink / raw)
  To: linux-iio; +Cc: Andrey Smirnov, linux-kernel, quad

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@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: si7020: Fix endianness for I2C reads
  2015-03-13  2:53 [PATCH] iio: si7020: Fix endianness for I2C reads Andrey Smirnov
@ 2015-03-13 10:45 ` Lars-Peter Clausen
  2015-03-14 19:48   ` Andrey Smirnov
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2015-03-13 10:45 UTC (permalink / raw)
  To: Andrey Smirnov, linux-iio; +Cc: linux-kernel, quad

On 03/13/2015 03:53 AM, Andrey Smirnov wrote:
> 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.

i2c_smbus_read_word_data() returns data in native endianess. But it 
interprets the word on the bus as little-endian (As specified by the SMBus 
spec). If your chip returns data in big-endian use 
i2c_smbus_read_word_data_swapped().

- Lars

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: si7020: Fix endianness for I2C reads
  2015-03-13 10:45 ` Lars-Peter Clausen
@ 2015-03-14 19:48   ` Andrey Smirnov
  0 siblings, 0 replies; 3+ messages in thread
From: Andrey Smirnov @ 2015-03-14 19:48 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio, linux-kernel, Robert Smith

>
> i2c_smbus_read_word_data() returns data in native endianess. But it
> interprets the word on the bus as little-endian (As specified by the SMBus
> spec). If your chip returns data in big-endian use
> i2c_smbus_read_word_data_swapped().
>
> - Lars

Ah, good to know. I'll update the patch accordingly.

Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-14 19:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13  2:53 [PATCH] iio: si7020: Fix endianness for I2C reads Andrey Smirnov
2015-03-13 10:45 ` Lars-Peter Clausen
2015-03-14 19:48   ` Andrey Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).