From: "Ivan T. Ivanov" <iivanov@mm-sol.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Ivan T. Ivanov" <iivanov@mm-sol.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Sachin Kamat <sachin.kamat@linaro.org>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
John Stultz <john.stultz@linaro.org>,
linux-iio@vger.kernel.org, svarbanov@mm-sol.com,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org
Subject: [PATCH] iio: inkern: Add of_xlate function to struct iio_dev
Date: Thu, 2 Oct 2014 15:32:08 +0300 [thread overview]
Message-ID: <1412253128-32165-1-git-send-email-iivanov@mm-sol.com> (raw)
When #iio-cells is greater than '0', the driver could provide
a custom of_xlate function that reads the *args* and returns
the appropriate index in registered IIO channels array.
Add simple translation function, suitable for the most 1:1
mapped channels in IIO chips, and use it when driver did not
provide custom implementation.
Signed-off-by: Ivan T. Ivanov <iivanov@mm-sol.com>
---
drivers/iio/inkern.c | 32 +++++++++++++++++++++++++++-----
include/linux/iio/iio.h | 8 ++++++++
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index f084610..6c3e478 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -100,6 +100,28 @@ static int iio_dev_node_match(struct device *dev, void *data)
return dev->of_node == data && dev->type == &iio_device_type;
}
+/**
+ * __of_iio_simple_xlate - translate iiospec to the IIO channel index
+ * @indio_dev: pointer to the iio_dev structure
+ * @iiospec: IIO specifier as found in the device tree
+ *
+ * This is simple translation function, suitable for the most 1:1 mapped
+ * channels in IIO chips. This function performs only one sanity check:
+ * whether IIO index is less than num_channels (that is specified in the
+ * iio_dev).
+ */
+static int __of_iio_simple_xlate(struct iio_dev *indio_dev,
+ const struct of_phandle_args *iiospec)
+{
+ if (!iiospec->args_count)
+ return 0;
+
+ if (iiospec->args[0] >= indio_dev->num_channels)
+ return -EINVAL;
+
+ return iiospec->args[0];
+}
+
static int __of_iio_channel_get(struct iio_channel *channel,
struct device_node *np, int index)
{
@@ -122,18 +144,18 @@ static int __of_iio_channel_get(struct iio_channel *channel,
indio_dev = dev_to_iio_dev(idev);
channel->indio_dev = indio_dev;
- index = iiospec.args_count ? iiospec.args[0] : 0;
- if (index >= indio_dev->num_channels) {
- err = -EINVAL;
+ if (!indio_dev->of_xlate)
+ indio_dev->of_xlate = __of_iio_simple_xlate;
+ index = indio_dev->of_xlate(indio_dev, &iiospec);
+ if (index < 0)
goto err_put;
- }
channel->channel = &indio_dev->channels[index];
return 0;
err_put:
iio_device_put(indio_dev);
- return err;
+ return index;
}
static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 15dc6bc..d5bb219 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -13,6 +13,7 @@
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/iio/types.h>
+#include <linux/of.h>
/* IIO TODO LIST */
/*
* Provide means of adjusting timer accuracy.
@@ -413,6 +414,11 @@ struct iio_buffer_setup_ops {
* @currentmode: [DRIVER] current operating mode
* @dev: [DRIVER] device structure, should be assigned a parent
* and owner
+ * @of_xlate: [DRIVER] function pointer to obtain channel specifier
+ * index. When #iio-cells is greater than '0', the driver
+ * could provide a custom of_xlate function that reads
+ * the *args* and returns the appropriate index in
+ * registered IIO channels array.
* @event_interface: [INTERN] event chrdevs associated with interrupt lines
* @buffer: [DRIVER] any buffer present
* @buffer_list: [INTERN] list of all buffers currently attached
@@ -451,6 +457,8 @@ struct iio_dev {
int currentmode;
struct device dev;
+ int (*of_xlate)(struct iio_dev *indio_dev,
+ const struct of_phandle_args *iiospec);
struct iio_event_interface *event_interface;
struct iio_buffer *buffer;
--
1.9.1
next reply other threads:[~2014-10-02 12:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-02 12:32 Ivan T. Ivanov [this message]
2014-10-02 13:30 ` [PATCH] iio: inkern: Add of_xlate function to struct iio_dev Lars-Peter Clausen
2014-10-02 13:49 ` Ivan T. Ivanov
2014-10-03 14:31 ` Srinivas Pandruvada
2014-10-03 15:08 ` Ivan T. Ivanov
2014-10-18 11:42 ` Jonathan Cameron
2014-10-18 11:50 ` Lars-Peter Clausen
2014-10-18 12:14 ` Jonathan Cameron
2014-10-20 11:22 ` Ivan T. Ivanov
2014-10-18 17:13 ` Srinivas Pandruvada
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=1412253128-32165-1-git-send-email-iivanov@mm-sol.com \
--to=iivanov@mm-sol.com \
--cc=jic23@kernel.org \
--cc=john.stultz@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sachin.kamat@linaro.org \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=svarbanov@mm-sol.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