From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Peter Meerwald <pmeerw@pmeerw.net>,
Daniel Baluta <daniel.baluta@intel.com>,
linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH v2 3/4] staging:iio:ad5933: Report temperature as raw value
Date: Thu, 25 Sep 2014 16:27:14 +0200 [thread overview]
Message-ID: <1411655235-7635-3-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1411655235-7635-1-git-send-email-lars@metafoo.de>
We shouldn't be doing the unit conversion in kernel space. Just report the
raw value for the property and the scale. Userspace can do the conversion if
necessary.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
Changes from v1:
* Slightly restructured error path to make it clear that the mutex is
only unlocked when it was locked before.
---
drivers/staging/iio/impedance-analyzer/ad5933.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index b6bd609..95b17c5 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -113,7 +113,8 @@ static const struct iio_chan_spec ad5933_channels[] = {
.type = IIO_TEMP,
.indexed = 1,
.channel = 0,
- .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
.address = AD5933_REG_TEMP_DATA,
.scan_index = -1,
.scan_type = {
@@ -520,12 +521,11 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
{
struct ad5933_state *st = iio_priv(indio_dev);
__be16 dat;
- int ret = -EINVAL;
+ int ret;
- mutex_lock(&indio_dev->mlock);
switch (m) {
case IIO_CHAN_INFO_RAW:
- case IIO_CHAN_INFO_PROCESSED:
+ mutex_lock(&indio_dev->mlock);
if (iio_buffer_enabled(indio_dev)) {
ret = -EBUSY;
goto out;
@@ -543,16 +543,16 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
if (ret < 0)
goto out;
mutex_unlock(&indio_dev->mlock);
- ret = be16_to_cpu(dat);
- /* Temp in Milli degrees Celsius */
- if (ret < 8192)
- *val = ret * 1000 / 32;
- else
- *val = (ret - 16384) * 1000 / 32;
+ *val = sign_extend32(be16_to_cpu(dat), 13);
return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ *val = 1000;
+ *val2 = 5;
+ return IIO_VAL_FRACTIONAL_LOG2;
}
+ return -EINVAL;
out:
mutex_unlock(&indio_dev->mlock);
return ret;
--
1.8.0
next prev parent reply other threads:[~2014-09-25 14:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 14:27 [PATCH v2 1/4] staging:iio:ad5933: Fix NULL pointer deref when enabling buffer Lars-Peter Clausen
2014-09-25 14:27 ` [PATCH v2 2/4] staging:iio:ad5933: Drop "raw" from channel names Lars-Peter Clausen
2014-09-25 14:27 ` Lars-Peter Clausen [this message]
2014-09-27 9:52 ` [PATCH v2 3/4] staging:iio:ad5933: Report temperature as raw value Jonathan Cameron
2015-01-04 17:55 ` Jonathan Cameron
2014-09-25 14:27 ` [PATCH v2 4/4] staging:iio:ad5933: Remove platform data from state struct Lars-Peter Clausen
2015-01-04 17:55 ` Jonathan Cameron
2014-09-27 9:35 ` [PATCH v2 1/4] staging:iio:ad5933: Fix NULL pointer deref when enabling buffer Jonathan Cameron
2014-09-27 20:35 ` Lars-Peter Clausen
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=1411655235-7635-3-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=daniel.baluta@intel.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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).