linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Hernán Gonzalez" <hernan@vanguardiasur.com.ar>
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	gregkh@linuxfoundation.org, Michael.Hennerich@analog.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 08/14] staging: iio: ad7746: Add dt-bindings
Date: Sun, 15 Apr 2018 16:19:09 +0100	[thread overview]
Message-ID: <20180415161909.34877620@archlinux> (raw)
In-Reply-To: <1523637411-8531-9-git-send-email-hernan@vanguardiasur.com.ar>

On Fri, 13 Apr 2018 13:36:45 -0300
Hernán Gonzalez <hernan@vanguardiasur.com.ar> wrote:

> This patch adds dt bindings by populating a pdata struct in order to
> modify as little as possible the existing code. It supports both
> platform_data and dt-bindings but uses only one depending on
> CONFIG_OF's value.
> 
> Signed-off-by: Hernán Gonzalez <hernan@vanguardiasur.com.ar>

Please reorder the patches in the next version to put the bindings
patch next to this one (before preferably, but after is fine as
well.)

Hmm. I can see why you want to minimize the effect of the older
code, but given that we will probably (eventually) drop the
platform data option, I wonder if it wouldn't be better
to move the data to a sensible location rather than faking
platform_data.

The pdata is only used in probe and only two bits of
it at that so it would be fine to use some local variables and
fill them from platform data or device tree as appropriate.

Jonathan

> ---
>  drivers/staging/iio/cdc/ad7746.c | 54 +++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 53 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
> index d39ab34..c29a221 100644
> --- a/drivers/staging/iio/cdc/ad7746.c
> +++ b/drivers/staging/iio/cdc/ad7746.c
> @@ -666,6 +666,43 @@ static const struct iio_info ad7746_info = {
>  /*
>   * device probe and remove
>   */
> +#ifdef CONFIG_OF
> +static struct ad7746_platform_data *ad7746_parse_dt(struct device *dev)
> +{
> +	struct device_node *np = dev->of_node;
> +	struct ad7746_platform_data *pdata;
> +	unsigned int tmp;
> +	int ret;
> +
> +	/* The default excitation outputs are not inverted, it should be stated
Please use standard multiline comment syntax.

/*
 * The...
 */
> +	 * in the dt if needed.
> +	 */
> +
> +	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> +	if (!pdata)
> +		return NULL;
> +
> +	ret = of_property_read_u32(np, "adi,exclvl", &tmp);
> +	if (ret || tmp > 3) {
> +		dev_warn(dev, "Wrong exclvl value, using default\n");

Seems a little odd to have the check in here rather than generic.

> +		pdata->exclvl = 3; /* default value */
> +	} else {
> +		pdata->exclvl = tmp;
> +	}
> +
> +	pdata->exca_en = true;
> +	pdata->excb_en = true;
> +	pdata->exca_inv_en = of_property_read_bool(np, "adi,nexca_en");
> +	pdata->excb_inv_en = of_property_read_bool(np, "adi,nexcb_en");
> +
> +	return pdata;
> +}
> +#else
> +static struct ad7746_platform_data *ad7746_parse_dt(struct device *dev)
> +{
> +	return NULL;
> +}
> +#endif
>  
>  static int ad7746_probe(struct i2c_client *client,
>  			const struct i2c_device_id *id)
> @@ -676,6 +713,11 @@ static int ad7746_probe(struct i2c_client *client,
>  	unsigned char regval = 0;
>  	int ret = 0;
>  
> +	if (client->dev.of_node)
> +		pdata = ad7746_parse_dt(&client->dev);
> +	else
> +		pdata = client->dev.platform_data;
> +
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
>  	if (!indio_dev)
>  		return -ENOMEM;
> @@ -739,12 +781,22 @@ static const struct i2c_device_id ad7746_id[] = {
>  	{ "ad7747", 7747 },
>  	{}
>  };
> -
>  MODULE_DEVICE_TABLE(i2c, ad7746_id);
>  
> +#ifdef CONFIG_OF
> +static const struct of_device_id ad7746_of_match[] = {
> +	{ .compatible = "adi,ad7745" },
> +	{ .compatible = "adi,ad7746" },
> +	{ .compatible = "adi,ad7747" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, ad7746_of_match);
> +#endif
> +
>  static struct i2c_driver ad7746_driver = {
>  	.driver = {
>  		.name = KBUILD_MODNAME,
> +		.of_match_table = of_match_ptr(ad7746_of_match),
>  	},
>  	.probe = ad7746_probe,
>  	.id_table = ad7746_id,


  reply	other threads:[~2018-04-15 15:19 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 16:36 [PATCH v2 00/14] Move ad7746 driver out of staging Hernán Gonzalez
2018-04-13 16:36 ` [PATCH v2 01/14] staging: iio: ad7746: Automatically swap values in readings/writings Hernán Gonzalez
2018-04-15 15:02   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 02/14] staging: iio: ad7746: Adjust arguments to match open parenthesis Hernán Gonzalez
2018-04-15 15:03   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 03/14] staging: iio: ad7746: Fix bound checkings Hernán Gonzalez
2018-04-15 15:05   ` Jonathan Cameron
2018-04-16 14:47     ` Hernán Gonzalez
2018-04-18  9:39       ` Jonathan Cameron
2018-04-21 14:40         ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 04/14] staging: iio: ad7746: Fix multiple line dereference Hernán Gonzalez
2018-04-15 15:07   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 05/14] staging: iio: ad7746: Reorder includes alphabetically Hernán Gonzalez
2018-04-15 15:09   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 06/14] staging: iio: ad7746: Reorder variable declarations Hernán Gonzalez
2018-04-15 15:10   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 07/14] staging: iio: ad7746: Remove unused defines Hernán Gonzalez
2018-04-15 15:12   ` Jonathan Cameron
2018-04-16 14:50     ` Hernán Gonzalez
2018-04-13 16:36 ` [PATCH v2 08/14] staging: iio: ad7746: Add dt-bindings Hernán Gonzalez
2018-04-15 15:19   ` Jonathan Cameron [this message]
2018-04-13 16:36 ` [PATCH v2 09/14] staging: iio: ad7746: Add remove() Hernán Gonzalez
2018-04-15 15:31   ` Jonathan Cameron
2018-04-18 19:25     ` Hernán Gonzalez
2018-04-19  9:14       ` Michael Hennerich
2018-04-13 16:36 ` [PATCH v2 10/14] staging: iio: ad7746: Add comments Hernán Gonzalez
2018-04-15 15:35   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 11/14] staging: iio: ad7746: Add devicetree bindings documentation Hernán Gonzalez
2018-04-15 15:37   ` Jonathan Cameron
2018-04-16 14:55     ` Hernán Gonzalez
2018-04-16 20:08   ` Rob Herring
2018-04-13 16:36 ` [PATCH v2 12/14] staging: iio: ad7746: Add ABI documentation Hernán Gonzalez
2018-04-15 15:40   ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 13/14] Move ad7746 out of staging Hernán Gonzalez
2018-04-15 17:04   ` Jonathan Cameron
2018-04-15 18:46     ` Joe Perches
2018-04-15 19:48       ` Jonathan Cameron
2018-04-13 16:36 ` [PATCH v2 14/14] staging: iio: Remove ad7746 from staging Hernán Gonzalez
2018-04-15 15:43   ` Jonathan Cameron
2018-04-15 19:24     ` Joe Perches
2018-04-15 19:52       ` Jonathan Cameron

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=20180415161909.34877620@archlinux \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hernan@vanguardiasur.com.ar \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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;
as well as URLs for NNTP newsgroup(s).