public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
@ 2012-08-16  7:39 Kim, Milo
  2012-08-16  7:42 ` Peter Meerwald
  2012-08-16  8:19 ` Lars-Peter Clausen
  0 siblings, 2 replies; 7+ messages in thread
From: Kim, Milo @ 2012-08-16  7:39 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, jic23@cam.ac.uk, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org

This allows the iio consumer to get the offset of the channel.
The value of offset can be used when calculating the result such
as 'result = raw * scale + offset'.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
---
 drivers/iio/inkern.c         |   21 +++++++++++++++++++++
 include/linux/iio/consumer.h |    9 +++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index b5afc2f..bd09245 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -269,6 +269,27 @@ err_unlock:
 }
 EXPORT_SYMBOL_GPL(iio_read_channel_scale);
 
+int iio_read_channel_offset(struct iio_channel *chan, int *val)
+{
+	int val2, ret;
+
+	mutex_lock(&chan->indio_dev->info_exist_lock);
+	if (chan->indio_dev->info == NULL) {
+		ret = -ENODEV;
+		goto err_unlock;
+	}
+
+	ret = chan->indio_dev->info->read_raw(chan->indio_dev,
+					      chan->channel,
+					      val, &val2,
+					      IIO_CHAN_INFO_OFFSET);
+err_unlock:
+	mutex_unlock(&chan->indio_dev->info_exist_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(iio_read_channel_offset);
+
 int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
 {
 	int ret = 0;
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
index e2657e6..d9d69fa 100644
--- a/include/linux/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -93,4 +93,13 @@ int iio_get_channel_type(struct iio_channel *channel,
 int iio_read_channel_scale(struct iio_channel *chan, int *val,
 			   int *val2);
 
+/**
+ * iio_read_channel_offset() - read offset from a given channel
+ * @channel:		The channel being queried.
+ * @val:		Offset Value read back.
+ *
+ * Note offset can be used in the consumer when calculating the result
+ * such as 'result = raw * scale + offset'.
+ */
+int iio_read_channel_offset(struct iio_channel *chan, int *val);
 #endif
-- 
1.7.2.5


Best Regards,
Milo



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

end of thread, other threads:[~2012-08-16 18:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-16  7:39 [PATCH 1/3] iio: add iio_read_channel_offset() consumer api Kim, Milo
2012-08-16  7:42 ` Peter Meerwald
2012-08-16  7:49   ` Kim, Milo
2012-08-16 18:56     ` Jonathan Cameron
2012-08-16  8:19 ` Lars-Peter Clausen
2012-08-16  8:25   ` Lars-Peter Clausen
2012-08-16  8:32   ` Jonathan Cameron

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