* [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info @ 2014-10-22 15:29 Ivan T. Ivanov 2014-10-22 15:32 ` Lars-Peter Clausen 0 siblings, 1 reply; 8+ messages in thread From: Ivan T. Ivanov @ 2014-10-22 15:29 UTC (permalink / raw) To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald Cc: Ivan T. Ivanov, Srinivas Pandruvada, Sachin Kamat, Thomas Gleixner, linux-iio, linux-kernel, linux-arm-msm 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> --- Changes: - Move of_xlate function from iio_dev to iio_info structure, where all the other callbacks are. drivers/iio/inkern.c | 33 ++++++++++++++++++++++++++++----- include/linux/iio/iio.h | 8 ++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index f084610..866fe90 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,19 @@ 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->info->of_xlate) + index = indio_dev->info->of_xlate(indio_dev, &iiospec); + else + index = __of_iio_simple_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..3642ce7 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. @@ -326,6 +327,11 @@ struct iio_dev; * @update_scan_mode: function to configure device and scan buffer when * channels have changed * @debugfs_reg_access: function to read or write register value of device + * @of_xlate: 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. **/ struct iio_info { struct module *driver_module; @@ -385,6 +391,8 @@ struct iio_info { int (*debugfs_reg_access)(struct iio_dev *indio_dev, unsigned reg, unsigned writeval, unsigned *readval); + int (*of_xlate)(struct iio_dev *indio_dev, + const struct of_phandle_args *iiospec); }; /** -- 1.9.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info 2014-10-22 15:29 [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info Ivan T. Ivanov @ 2014-10-22 15:32 ` Lars-Peter Clausen 2014-10-25 10:04 ` Jonathan Cameron 0 siblings, 1 reply; 8+ messages in thread From: Lars-Peter Clausen @ 2014-10-22 15:32 UTC (permalink / raw) To: Ivan T. Ivanov, Jonathan Cameron, Hartmut Knaack, Peter Meerwald Cc: Srinivas Pandruvada, Sachin Kamat, Thomas Gleixner, linux-iio, linux-kernel, linux-arm-msm On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: > 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> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Thanks. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info 2014-10-22 15:32 ` Lars-Peter Clausen @ 2014-10-25 10:04 ` Jonathan Cameron [not found] ` <544B75B8.1010505-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Jonathan Cameron @ 2014-10-25 10:04 UTC (permalink / raw) To: Lars-Peter Clausen, Ivan T. Ivanov, Hartmut Knaack, Peter Meerwald Cc: Srinivas Pandruvada, Sachin Kamat, Thomas Gleixner, linux-iio, linux-kernel, linux-arm-msm On 22/10/14 16:32, Lars-Peter Clausen wrote: > On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: >> 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> > > Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> > Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it. Thanks, Jonathan ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <544B75B8.1010505-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>]
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info [not found] ` <544B75B8.1010505-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> @ 2014-11-03 10:07 ` Ivan T. Ivanov 2014-11-03 10:31 ` Lars-Peter Clausen 2014-11-03 10:36 ` Srinivas Pandruvada 0 siblings, 2 replies; 8+ messages in thread From: Ivan T. Ivanov @ 2014-11-03 10:07 UTC (permalink / raw) To: Jonathan Cameron Cc: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald, Srinivas Pandruvada, Sachin Kamat, Thomas Gleixner, linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-arm-msm-u79uwXL29TY76Z2rM5mHXA On Sat, 2014-10-25 at 11:04 +0100, Jonathan Cameron wrote: > On 22/10/14 16:32, Lars-Peter Clausen wrote: > > On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: > > > 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-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org> > > > > Reviewed-by: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> > > > Applied to the togreg branch of iio.git - initially pushed out as testing > for the autobuilders to play with it. Thank you. Probably my git skills failed me, but I can not find it in aforementioned branches. Is it publicly pushed? Regards, Ivan ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info 2014-11-03 10:07 ` Ivan T. Ivanov @ 2014-11-03 10:31 ` Lars-Peter Clausen [not found] ` <5457598B.1050408-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> 2014-11-03 10:36 ` Srinivas Pandruvada 1 sibling, 1 reply; 8+ messages in thread From: Lars-Peter Clausen @ 2014-11-03 10:31 UTC (permalink / raw) To: Ivan T. Ivanov, Jonathan Cameron Cc: Hartmut Knaack, Peter Meerwald, Srinivas Pandruvada, Sachin Kamat, Thomas Gleixner, linux-iio, linux-kernel, linux-arm-msm On 11/03/2014 11:07 AM, Ivan T. Ivanov wrote: > > On Sat, 2014-10-25 at 11:04 +0100, Jonathan Cameron wrote: >> On 22/10/14 16:32, Lars-Peter Clausen wrote: >>> On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: >>>> 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> >>> >>> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> >>> >> Applied to the togreg branch of iio.git - initially pushed out as testing >> for the autobuilders to play with it. > > Thank you. Probably my git skills failed me, but I can not > find it in aforementioned branches. Is it publicly pushed? It's in the testing branch. http://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <5457598B.1050408-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>]
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info [not found] ` <5457598B.1050408-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> @ 2014-11-03 10:51 ` Ivan T. Ivanov 0 siblings, 0 replies; 8+ messages in thread From: Ivan T. Ivanov @ 2014-11-03 10:51 UTC (permalink / raw) To: Lars-Peter Clausen Cc: Jonathan Cameron, Hartmut Knaack, Peter Meerwald, Srinivas Pandruvada, Sachin Kamat, Thomas Gleixner, linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-arm-msm-u79uwXL29TY76Z2rM5mHXA On Mon, 2014-11-03 at 11:31 +0100, Lars-Peter Clausen wrote: > On 11/03/2014 11:07 AM, Ivan T. Ivanov wrote: > > On Sat, 2014-10-25 at 11:04 +0100, Jonathan Cameron wrote: > > > On 22/10/14 16:32, Lars-Peter Clausen wrote: > > > > On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: > > > > > 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-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org> > > > > > > > > Reviewed-by: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> > > > > > > > Applied to the togreg branch of iio.git - initially pushed out as testing > > > for the autobuilders to play with it. > > > > Thank you. Probably my git skills failed me, but I can not > > find it in aforementioned branches. Is it publicly pushed? > > It's in the testing branch. > > http://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing > Thank you. Ivan ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info 2014-11-03 10:07 ` Ivan T. Ivanov 2014-11-03 10:31 ` Lars-Peter Clausen @ 2014-11-03 10:36 ` Srinivas Pandruvada 2014-11-03 10:50 ` Ivan T. Ivanov 1 sibling, 1 reply; 8+ messages in thread From: Srinivas Pandruvada @ 2014-11-03 10:36 UTC (permalink / raw) To: Ivan T. Ivanov Cc: Jonathan Cameron, Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald, Sachin Kamat, Thomas Gleixner, linux-iio, linux-kernel, linux-arm-msm On Mon, 2014-11-03 at 12:07 +0200, Ivan T. Ivanov wrote: > On Sat, 2014-10-25 at 11:04 +0100, Jonathan Cameron wrote: > > On 22/10/14 16:32, Lars-Peter Clausen wrote: > > > On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: > > > > 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> > > > > > > Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> > > > > > Applied to the togreg branch of iio.git - initially pushed out as testing > > for the autobuilders to play with it. > > Thank you. Probably my git skills failed me, but I can not > find it in aforementioned branches. Is it publicly pushed? > check here https://www.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git checkout branch: remotes/origin/testing > Regards, > Ivan > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info 2014-11-03 10:36 ` Srinivas Pandruvada @ 2014-11-03 10:50 ` Ivan T. Ivanov 0 siblings, 0 replies; 8+ messages in thread From: Ivan T. Ivanov @ 2014-11-03 10:50 UTC (permalink / raw) To: Srinivas Pandruvada Cc: Jonathan Cameron, Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald, Sachin Kamat, Thomas Gleixner, linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-arm-msm-u79uwXL29TY76Z2rM5mHXA On Mon, 2014-11-03 at 02:36 -0800, Srinivas Pandruvada wrote: > On Mon, 2014-11-03 at 12:07 +0200, Ivan T. Ivanov wrote: > > On Sat, 2014-10-25 at 11:04 +0100, Jonathan Cameron wrote: > > > On 22/10/14 16:32, Lars-Peter Clausen wrote: > > > > On 10/22/2014 05:29 PM, Ivan T. Ivanov wrote: > > > > > 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-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org> > > > > > > > > Reviewed-by: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> > > > > > > > Applied to the togreg branch of iio.git - initially pushed out as testing > > > for the autobuilders to play with it. > > > > Thank you. Probably my git skills failed me, but I can not > > find it in aforementioned branches. Is it publicly pushed? > > > check here > https://www.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git > checkout branch: remotes/origin/testing Thank you. Ivan ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-11-03 10:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-22 15:29 [PATCH v2] iio: inkern: Add of_xlate function to struct iio_info Ivan T. Ivanov
2014-10-22 15:32 ` Lars-Peter Clausen
2014-10-25 10:04 ` Jonathan Cameron
[not found] ` <544B75B8.1010505-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-11-03 10:07 ` Ivan T. Ivanov
2014-11-03 10:31 ` Lars-Peter Clausen
[not found] ` <5457598B.1050408-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2014-11-03 10:51 ` Ivan T. Ivanov
2014-11-03 10:36 ` Srinivas Pandruvada
2014-11-03 10:50 ` Ivan T. Ivanov
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).