Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: si7020: Swap data byte order
@ 2015-11-02 21:45 Chris Lesiak
  2015-11-08 15:57 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Lesiak @ 2015-11-02 21:45 UTC (permalink / raw)
  To: linux-iio

>From e983f08f5cdeb811fd59abfc5ed9b47cef647bf6 Mon Sep 17 00:00:00 2001
From: Chris Lesiak <chris.lesiak@licor.com>
Date: Mon, 2 Nov 2015 15:13:45 -0600
Subject: [PATCH] iio: si7020: Swap data byte order

The Silicon Labs Si7013, Si7020, and Si7021 family of I2C humidity and
temperature sensors deliver 16 bit data high byte first.

See the datasheet available at:
https://www.silabs.com/Support%20Documents%2fTechnicalDocs%2fSi7020-A20.pdf

But as documented in Documentation/i2c/smbus-protocol,
i2c_smbus_read_word_data() expects the low byte first.

Change the driver to use i2c_smbus_read_word_swapped to get correct byte
order.

Signed-off-by: Chris Lesiak <chris.lesiak@licor.com>
---
 drivers/iio/humidity/si7020.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
index 00aec56..d169e90 100644
--- a/drivers/iio/humidity/si7020.c
+++ b/drivers/iio/humidity/si7020.c
@@ -50,10 +50,10 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		ret = i2c_smbus_read_word_data(*client,
-					       chan->type == IIO_TEMP ?
-					       SI7020CMD_TEMP_HOLD :
-					       SI7020CMD_RH_HOLD);
+		ret = i2c_smbus_read_word_swapped(*client,
+						  chan->type == IIO_TEMP ?
+						  SI7020CMD_TEMP_HOLD :
+						  SI7020CMD_RH_HOLD);
 		if (ret < 0)
 			return ret;
 		*val = ret >> 2;
-- 
2.4.3


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

* Re: [PATCH] iio: si7020: Swap data byte order
  2015-11-02 21:45 [PATCH] iio: si7020: Swap data byte order Chris Lesiak
@ 2015-11-08 15:57 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2015-11-08 15:57 UTC (permalink / raw)
  To: Chris Lesiak, linux-iio, Andrey Smirnov, Nicola Corna

On 02/11/15 21:45, Chris Lesiak wrote:
> From e983f08f5cdeb811fd59abfc5ed9b47cef647bf6 Mon Sep 17 00:00:00 2001
> From: Chris Lesiak <chris.lesiak@licor.com>
> Date: Mon, 2 Nov 2015 15:13:45 -0600
> Subject: [PATCH] iio: si7020: Swap data byte order
This is the email header, doesn't want to be repeated here as it'll then
end up in the patch description as well.

> 
> The Silicon Labs Si7013, Si7020, and Si7021 family of I2C humidity and
> temperature sensors deliver 16 bit data high byte first.
> 
> See the datasheet available at:
> https://www.silabs.com/Support%20Documents%2fTechnicalDocs%2fSi7020-A20.pdf
> 
> But as documented in Documentation/i2c/smbus-protocol,
> i2c_smbus_read_word_data() expects the low byte first.
> 
> Change the driver to use i2c_smbus_read_word_swapped to get correct byte
> order.
> 
> Signed-off-by: Chris Lesiak <chris.lesiak@licor.com>
Hi Chris,

Andrey posted a previous patch for this, but was going to come back with a neater
version (what you have here pretty much!).  
I've also cc'd Nicola who has some patches in the works for this driver.

Anyhow, applied to the fixes-togreg branch of iio.git and marked for stable.

Jonathan
> ---
>  drivers/iio/humidity/si7020.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
> index 00aec56..d169e90 100644
> --- a/drivers/iio/humidity/si7020.c
> +++ b/drivers/iio/humidity/si7020.c
> @@ -50,10 +50,10 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		ret = i2c_smbus_read_word_data(*client,
> -					       chan->type == IIO_TEMP ?
> -					       SI7020CMD_TEMP_HOLD :
> -					       SI7020CMD_RH_HOLD);
> +		ret = i2c_smbus_read_word_swapped(*client,
> +						  chan->type == IIO_TEMP ?
> +						  SI7020CMD_TEMP_HOLD :
> +						  SI7020CMD_RH_HOLD);
>  		if (ret < 0)
>  			return ret;
>  		*val = ret >> 2;
> 


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

end of thread, other threads:[~2015-11-08 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-02 21:45 [PATCH] iio: si7020: Swap data byte order Chris Lesiak
2015-11-08 15:57 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox