linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: linux-iio@vger.kernel.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
	linux-kernel@vger.kernel.org, quad@symbo1ics.com
Subject: [PATCH] iio: si7020: Fix endianness for I2C reads
Date: Thu, 12 Mar 2015 19:53:18 -0700	[thread overview]
Message-ID: <1426215198-28630-1-git-send-email-andrew.smirnov@gmail.com> (raw)

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

             reply	other threads:[~2015-03-13  2:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13  2:53 Andrey Smirnov [this message]
2015-03-13 10:45 ` [PATCH] iio: si7020: Fix endianness for I2C reads Lars-Peter Clausen
2015-03-14 19:48   ` Andrey Smirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426215198-28630-1-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quad@symbo1ics.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).