Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Peter Rosin <peda@axentia.se>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v3 1/1] iio: multiplexer: Make use of device properties
Date: Sun, 20 Mar 2022 15:44:25 +0000	[thread overview]
Message-ID: <20220320154425.57643a5c@jic23-huawei> (raw)
In-Reply-To: <20220302160025.54348-1-andriy.shevchenko@linux.intel.com>

On Wed,  2 Mar 2022 18:00:25 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Convert the module to be property provider agnostic and allow
> it to be used on non-OF platforms.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Acked-by: Peter Rosin <peda@axentia.se>
Applied to the togreg branch of iio.git and pushed out as testing (which will be rebased)
so 0-day can take an early poke at what I have queued up.

Thanks,

Jonathan

> ---
> v3: split variable definitions on 1 per line basis (Peter), fixed typo (Jonathan)
>  drivers/iio/multiplexer/Kconfig   |  1 -
>  drivers/iio/multiplexer/iio-mux.c | 49 +++++++++++++++----------------
>  2 files changed, 23 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/iio/multiplexer/Kconfig b/drivers/iio/multiplexer/Kconfig
> index a1e1332d1206..928f424a1ed3 100644
> --- a/drivers/iio/multiplexer/Kconfig
> +++ b/drivers/iio/multiplexer/Kconfig
> @@ -9,7 +9,6 @@ menu "Multiplexers"
>  config IIO_MUX
>  	tristate "IIO multiplexer driver"
>  	select MULTIPLEXER
> -	depends on OF || COMPILE_TEST
>  	help
>  	  Say yes here to build support for the IIO multiplexer.
>  
> diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c
> index f422d44377df..93558fddfa9b 100644
> --- a/drivers/iio/multiplexer/iio-mux.c
> +++ b/drivers/iio/multiplexer/iio-mux.c
> @@ -10,11 +10,12 @@
>  #include <linux/err.h>
>  #include <linux/iio/consumer.h>
>  #include <linux/iio/iio.h>
> +#include <linux/mod_devicetable.h>
>  #include <linux/module.h>
>  #include <linux/mutex.h>
>  #include <linux/mux/consumer.h>
> -#include <linux/of.h>
>  #include <linux/platform_device.h>
> +#include <linux/property.h>
>  
>  struct mux_ext_info_cache {
>  	char *data;
> @@ -324,37 +325,21 @@ static int mux_configure_channel(struct device *dev, struct mux *mux,
>  	return 0;
>  }
>  
> -/*
> - * Same as of_property_for_each_string(), but also keeps track of the
> - * index of each string.
> - */
> -#define of_property_for_each_string_index(np, propname, prop, s, i)	\
> -	for (prop = of_find_property(np, propname, NULL),		\
> -	     s = of_prop_next_string(prop, NULL),			\
> -	     i = 0;							\
> -	     s;								\
> -	     s = of_prop_next_string(prop, s),				\
> -	     i++)
> -
>  static int mux_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	struct device_node *np = pdev->dev.of_node;
>  	struct iio_dev *indio_dev;
>  	struct iio_channel *parent;
>  	struct mux *mux;
> -	struct property *prop;
> -	const char *label;
> +	const char **labels;
> +	int all_children;
> +	int children;
>  	u32 state;
>  	int sizeof_ext_info;
> -	int children;
>  	int sizeof_priv;
>  	int i;
>  	int ret;
>  
> -	if (!np)
> -		return -ENODEV;
> -
>  	parent = devm_iio_channel_get(dev, "parent");
>  	if (IS_ERR(parent))
>  		return dev_err_probe(dev, PTR_ERR(parent),
> @@ -366,9 +351,21 @@ static int mux_probe(struct platform_device *pdev)
>  		sizeof_ext_info *= sizeof(*mux->ext_info);
>  	}
>  
> +	all_children = device_property_string_array_count(dev, "channels");
> +	if (all_children < 0)
> +		return all_children;
> +
> +	labels = devm_kmalloc_array(dev, all_children, sizeof(*labels), GFP_KERNEL);
> +	if (!labels)
> +		return -ENOMEM;
> +
> +	ret = device_property_read_string_array(dev, "channels", labels, all_children);
> +	if (ret < 0)
> +		return ret;
> +
>  	children = 0;
> -	of_property_for_each_string(np, "channels", prop, label) {
> -		if (*label)
> +	for (state = 0; state < all_children; state++) {
> +		if (*labels[state])
>  			children++;
>  	}
>  	if (children <= 0) {
> @@ -395,7 +392,7 @@ static int mux_probe(struct platform_device *pdev)
>  	mux->cached_state = -1;
>  
>  	mux->delay_us = 0;
> -	of_property_read_u32(np, "settle-time-us", &mux->delay_us);
> +	device_property_read_u32(dev, "settle-time-us", &mux->delay_us);
>  
>  	indio_dev->name = dev_name(dev);
>  	indio_dev->info = &mux_info;
> @@ -426,11 +423,11 @@ static int mux_probe(struct platform_device *pdev)
>  	}
>  
>  	i = 0;
> -	of_property_for_each_string_index(np, "channels", prop, label, state) {
> -		if (!*label)
> +	for (state = 0; state < all_children; state++) {
> +		if (!*labels[state])
>  			continue;
>  
> -		ret = mux_configure_channel(dev, mux, state, label, i++);
> +		ret = mux_configure_channel(dev, mux, state, labels[state], i++);
>  		if (ret < 0)
>  			return ret;
>  	}


      reply	other threads:[~2022-03-20 15:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 16:00 [PATCH v3 1/1] iio: multiplexer: Make use of device properties Andy Shevchenko
2022-03-20 15:44 ` Jonathan Cameron [this message]

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=20220320154425.57643a5c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@axentia.se \
    /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