iio: inkern: Add of_xlate function to struct iio_info
Subsystems (2)
PATCH v2 1/1 iio: inkern: Add of_xlate function to struct iio_info
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.
---
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(-)
drivers/iio/inkern.c +28 -5
@@ -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)
include/linux/iio/iio.h +8 -0
@@ -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); };/**
Signature · 1 line
1.9.1
Quoted 9 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction 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 <[email protected]>
Thanks.
Jonathan Cameron
maintainerQuoted 5 lines · Lars-Peter Clausen
Quoted 4 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction that reads the *args* and returns the appropriate index in registered IIO channels array.
Quoted 8 lines
Quoted 5 lines
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 <[email protected]>Reviewed-by Lars-Peter Clausen <[email protected]>
Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 10 lines · Jonathan Cameron
Quoted 9 lines · Lars-Peter Clausen
Quoted 8 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction 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.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Ivan T. Ivanov <[email protected]>Reviewed-by Lars-Peter Clausen <[email protected]>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
Quoted 14 lines · Ivan T. Ivanov
Quoted 12 lines · Jonathan Cameron
Quoted 11 lines · Lars-Peter Clausen
Quoted 9 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction 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 <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Reviewed-by Lars-Peter Clausen <[email protected]>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
Quoted 19 lines · Lars-Peter Clausen
Quoted 18 lines · Ivan T. Ivanov
Quoted 16 lines · Jonathan Cameron
Quoted 5 lines · Lars-Peter Clausen
Quoted 4 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction that reads the *args* and returns the appropriate index in registered IIO channels array.Quoted 8 lines
Quoted 5 lines
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 <[email protected]>Reviewed-by Lars-Peter Clausen <[email protected]>Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Quoted 7 lines
Quoted 2 lines
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
Quoted 13 lines · Ivan T. Ivanov
Quoted 12 lines · Jonathan Cameron
Quoted 11 lines · Lars-Peter Clausen
Quoted 9 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction 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 <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Reviewed-by Lars-Peter Clausen <[email protected]>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
Quoted 3 lines
Regards,
Ivan
Quoted 19 lines · Srinivas Pandruvada
Quoted 18 lines · Ivan T. Ivanov
Quoted 16 lines · Jonathan Cameron
Quoted 5 lines · Lars-Peter Clausen
Quoted 4 lines · Ivan T. Ivanov
When #iio-cells is greater than '0', the driver could provide a custom
of_xlatefunction that reads the *args* and returns the appropriate index in registered IIO channels array.Quoted 8 lines
Quoted 5 lines
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 <[email protected]>Reviewed-by Lars-Peter Clausen <[email protected]>Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Quoted 6 lines
Quoted 3 lines
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