From: Gwendal Grignou <gwendal@chromium.org>
To: jic23@kernel.org, lars@metafoo.de
Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org,
Gwendal Grignou <gwendal@chromium.org>
Subject: [PATCH 4/4] iio: mpl3115: Use scan_type.shift and realbit in mpl3115_read_raw
Date: Mon, 1 Nov 2021 00:18:22 -0700 [thread overview]
Message-ID: <20211101071822.522178-5-gwendal@chromium.org> (raw)
In-Reply-To: <20211101071822.522178-1-gwendal@chromium.org>
When processing raw data using channel scan_type.shift as source of
trust to shift data appropriately.
When processing the temperature channel, use a 16bit big endian variable
as buffer to increase conversion readability.
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
drivers/iio/pressure/mpl3115.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index 1eb9e7b29e050..e95b9a5475b4e 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -74,7 +74,6 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct mpl3115_data *data = iio_priv(indio_dev);
- __be32 tmp = 0;
int ret;
switch (mask) {
@@ -84,7 +83,9 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
return ret;
switch (chan->type) {
- case IIO_PRESSURE: /* in 0.25 pascal / LSB */
+ case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
+ __be32 tmp = 0;
+
mutex_lock(&data->lock);
ret = mpl3115_request(data);
if (ret < 0) {
@@ -96,10 +97,13 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&data->lock);
if (ret < 0)
break;
- *val = be32_to_cpu(tmp) >> 12;
+ *val = be32_to_cpu(tmp) >> chan->scan_type.shift;
ret = IIO_VAL_INT;
break;
- case IIO_TEMP: /* in 0.0625 celsius / LSB */
+ }
+ case IIO_TEMP: { /* in 0.0625 celsius / LSB */
+ __be16 tmp;
+
mutex_lock(&data->lock);
ret = mpl3115_request(data);
if (ret < 0) {
@@ -111,9 +115,11 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&data->lock);
if (ret < 0)
break;
- *val = sign_extend32(be32_to_cpu(tmp) >> 20, 11);
+ *val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift,
+ chan->scan_type.realbits - 1);
ret = IIO_VAL_INT;
break;
+ }
default:
ret = -EINVAL;
break;
--
2.33.1.1089.g2158813163f-goog
next prev parent reply other threads:[~2021-11-01 7:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-01 7:18 [PATCH 0/4] iio: Use scan_type shift and realbits when processing raw data Gwendal Grignou
2021-11-01 7:18 ` [PATCH 1/4] " Gwendal Grignou
2021-11-03 18:42 ` Jonathan Cameron
2021-11-04 8:24 ` Gwendal Grignou
2021-11-04 8:49 ` Eugen.Hristev
2021-11-01 7:18 ` [PATCH 2/4] iio: ti-ads1015: Remove shift variable ads1015_read_raw Gwendal Grignou
2021-11-03 18:53 ` Jonathan Cameron
2021-11-01 7:18 ` [PATCH 3/4] iio: xilinx-xadc-core: Use local variable in xadc_read_raw Gwendal Grignou
2021-11-03 18:55 ` Jonathan Cameron
2021-11-01 7:18 ` Gwendal Grignou [this message]
2021-11-03 18:58 ` [PATCH 4/4] iio: mpl3115: Use scan_type.shift and realbit in mpl3115_read_raw Jonathan Cameron
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=20211101071822.522178-5-gwendal@chromium.org \
--to=gwendal@chromium.org \
--cc=andy.shevchenko@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/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