All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Sean Nyekjær" <sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
To: linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 3/4] iio: ad5755: added full support for devicetree
Date: Tue, 9 Feb 2016 09:22:10 +0100	[thread overview]
Message-ID: <56B9A1B2.6030007@prevas.dk> (raw)
In-Reply-To: <1454509864-32285-3-git-send-email-sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>


On 2016-02-03 15:31, Sean Nyekjaer wrote:
> Devicetree can provide platform data
>
> Signed-off-by: Sean Nyekjaer <sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
Lars do you have time to look at this before i'm fixing the comments 
from Jonathan and Rob :-)

Sean
> ---
> Changes since v1:
> - this patch added
>
> I'm adding dt bindings header file with the same info as, the platform data as
> the devicetree can't understand enums.
> Please give an idea to work around this :-)
>
>   drivers/iio/dac/ad5755.c             | 87 +++++++++++++++++++++++++++++++++++-
>   include/dt-bindings/iio/adi,ad5755.h | 66 +++++++++++++++++++++++++++
>   2 files changed, 152 insertions(+), 1 deletion(-)
>   create mode 100644 include/dt-bindings/iio/adi,ad5755.h
>
> diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
> index e1b6e78..c1e2546 100644
> --- a/drivers/iio/dac/ad5755.c
> +++ b/drivers/iio/dac/ad5755.c
> @@ -14,9 +14,11 @@
>   #include <linux/slab.h>
>   #include <linux/sysfs.h>
>   #include <linux/delay.h>
> +#include <linux/of.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
>   #include <linux/platform_data/ad5755.h>
> +#include <dt-bindings/iio/adi,ad5755.h>
>   
>   #define AD5755_NUM_CHANNELS 4
>   
> @@ -556,6 +558,82 @@ static const struct ad5755_platform_data ad5755_default_pdata = {
>   	},
>   };
>   
> +#ifdef CONFIG_OF
> +static struct ad5755_platform_data *ad5755_parse_dt(struct device *dev)
> +{
> +	struct device_node *np = dev->of_node;
> +	struct device_node *pp;
> +	struct ad5755_platform_data *pdata;
> +	unsigned int tmp;
> +	unsigned int tmparray[3];
> +	int devnr;
> +
> +	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> +	if (!pdata)
> +		return NULL;
> +
> +	pdata->ext_dc_dc_compenstation_resistor =
> +	       of_property_read_bool(np, "adi,ext_dc_dc_compenstation_resistor");
> +
> +	if (!of_property_read_u32(np, "adi,dc_dc_phase", &tmp))
> +		pdata->dc_dc_phase = tmp;
> +	else
> +		pdata->dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE;
> +
> +	if (!of_property_read_u32(np, "adi,dc_dc_freq", &tmp))
> +		pdata->dc_dc_freq = tmp;
> +	else
> +		pdata->dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ;
> +
> +	if (!of_property_read_u32(np, "adi,dc_dc_maxv", &tmp))
> +		pdata->dc_dc_maxv = tmp;
> +	else
> +		pdata->dc_dc_maxv = AD5755_DC_DC_MAXV_23V;
> +
> +	devnr = 0;
> +	for_each_child_of_node(np, pp) {
> +		if (devnr > AD5755_NUM_CHANNELS) {
> +			dev_err(dev, "There is to many channels defined in DT\n");
> +			goto error_out;
> +		}
> +
> +		if (!of_property_read_u32(pp, "adi,mode", &tmp))
> +			pdata->dac[devnr].mode = tmp;
> +		else
> +			pdata->dac[devnr].mode = AD5755_MODE_CURRENT_4mA_20mA;
> +
> +		pdata->dac[devnr].ext_current_sense_resistor =
> +		       of_property_read_bool(pp, "adi,ext_current_sense_resistor");
> +
> +		pdata->dac[devnr].enable_voltage_overrange =
> +			of_property_read_bool(pp, "adi,enable_voltage_overrange");
> +		if (!of_property_read_u32_array(pp, "adi,slew", tmparray, 3)) {
> +			pdata->dac[devnr].slew.enable = tmparray[0];
> +			pdata->dac[devnr].slew.rate = tmparray[1];
> +			pdata->dac[devnr].slew.step_size = tmparray[2];
> +		} else {
> +			pdata->dac[devnr].slew.enable = false;
> +			pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k;
> +			pdata->dac[devnr].slew.step_size = AD5755_SLEW_STEP_SIZE_1;
> +		}
> +
> +		devnr++;
> +	}
> +
> +	return pdata;
> +
> +error_out:
> +	devm_kfree(dev, pdata);
> +	return NULL;
> +}
> +#else
> +static
> +struct adf4350_platform_data *adf4350_parse_dt(struct device *dev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>   static int ad5755_probe(struct spi_device *spi)
>   {
>   	enum ad5755_type type = spi_get_device_id(spi)->driver_data;
> @@ -583,8 +661,15 @@ static int ad5755_probe(struct spi_device *spi)
>   	indio_dev->modes = INDIO_DIRECT_MODE;
>   	indio_dev->num_channels = AD5755_NUM_CHANNELS;
>   
> -	if (!pdata)
> +	if (spi->dev.of_node)
> +		pdata = ad5755_parse_dt(&spi->dev);
> +	else
> +		pdata = spi->dev.platform_data;
> +
> +	if (!pdata) {
> +		dev_warn(&spi->dev, "no platform data? using default\n");
>   		pdata = &ad5755_default_pdata;
> +	}
>   
>   	ret = ad5755_init_channels(indio_dev, pdata);
>   	if (ret)
> diff --git a/include/dt-bindings/iio/adi,ad5755.h b/include/dt-bindings/iio/adi,ad5755.h
> new file mode 100644
> index 0000000..117466b
> --- /dev/null
> +++ b/include/dt-bindings/iio/adi,ad5755.h
> @@ -0,0 +1,66 @@
> +/*
> + * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#ifndef _DT_BINDINGS_AD5755_H
> +#define _DT_BINDINGS_AD5755_H
> +
> +#define	AD5755_MODE_VOLTAGE_0V_5V			0
> +#define AD5755_MODE_VOLTAGE_0V_10V			1
> +#define AD5755_MODE_VOLTAGE_PLUSMINUS_5V		2
> +#define AD5755_MODE_VOLTAGE_PLUSMINUS_10V		3
> +#define AD5755_MODE_CURRENT_4mA_20mA			4
> +#define AD5755_MODE_CURRENT_0mA_20mA			5
> +#define AD5755_MODE_CURRENT_0mA_24mA			6
> +
> +#define AD5755_DC_DC_PHASE_ALL_SAME_EDGE		0
> +#define AD5755_DC_DC_PHASE_A_B_SAME_EDGE_C_D_OPP_EDGE	1
> +#define AD5755_DC_DC_PHASE_A_C_SAME_EDGE_B_D_OPP_EDGE	2
> +#define AD5755_DC_DC_PHASE_90_DEGREE			3
> +
> +#define AD5755_DC_DC_FREQ_250kHZ			0
> +#define AD5755_DC_DC_FREQ_410kHZ			1
> +#define AD5755_DC_DC_FREQ_650kHZ			2
> +
> +#define AD5755_DC_DC_MAXV_23V				0
> +#define AD5755_DC_DC_MAXV_24V5				1
> +#define AD5755_DC_DC_MAXV_27V				2
> +#define AD5755_DC_DC_MAXV_29V5				3
> +
> +#define AD5755_SLEW_RATE_64k				0
> +#define AD5755_SLEW_RATE_32k				1
> +#define AD5755_SLEW_RATE_16k				2
> +#define AD5755_SLEW_RATE_8k				3
> +#define AD5755_SLEW_RATE_4k				4
> +#define AD5755_SLEW_RATE_2k				5
> +#define AD5755_SLEW_RATE_1k				6
> +#define AD5755_SLEW_RATE_500				7
> +#define AD5755_SLEW_RATE_250				8
> +#define AD5755_SLEW_RATE_125				9
> +#define AD5755_SLEW_RATE_64				10
> +#define AD5755_SLEW_RATE_32				11
> +#define AD5755_SLEW_RATE_16				12
> +#define AD5755_SLEW_RATE_8				13
> +#define AD5755_SLEW_RATE_4				14
> +#define AD5755_SLEW_RATE_0_5				15
> +
> +#define AD5755_SLEW_STEP_SIZE_1				0
> +#define AD5755_SLEW_STEP_SIZE_2				1
> +#define AD5755_SLEW_STEP_SIZE_4				2
> +#define AD5755_SLEW_STEP_SIZE_8				3
> +#define AD5755_SLEW_STEP_SIZE_16 			4
> +#define AD5755_SLEW_STEP_SIZE_32			5
> +#define AD5755_SLEW_STEP_SIZE_64			6
> +#define AD5755_SLEW_STEP_SIZE_128			7
> +#define AD5755_SLEW_STEP_SIZE_256			8
> +
> +#endif				/* _DT_BINDINGS_AD5755_H */

WARNING: multiple messages have this Message-ID (diff)
From: "Sean Nyekjær" <sean.nyekjaer@prevas.dk>
To: <linux-iio@vger.kernel.org>, Lars-Peter Clausen <lars@metafoo.de>
Cc: <devicetree@vger.kernel.org>
Subject: Re: [PATCH v2 3/4] iio: ad5755: added full support for devicetree
Date: Tue, 9 Feb 2016 09:22:10 +0100	[thread overview]
Message-ID: <56B9A1B2.6030007@prevas.dk> (raw)
In-Reply-To: <1454509864-32285-3-git-send-email-sean.nyekjaer@prevas.dk>


On 2016-02-03 15:31, Sean Nyekjaer wrote:
> Devicetree can provide platform data
>
> Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Lars do you have time to look at this before i'm fixing the comments 
from Jonathan and Rob :-)

Sean
> ---
> Changes since v1:
> - this patch added
>
> I'm adding dt bindings header file with the same info as, the platform data as
> the devicetree can't understand enums.
> Please give an idea to work around this :-)
>
>   drivers/iio/dac/ad5755.c             | 87 +++++++++++++++++++++++++++++++++++-
>   include/dt-bindings/iio/adi,ad5755.h | 66 +++++++++++++++++++++++++++
>   2 files changed, 152 insertions(+), 1 deletion(-)
>   create mode 100644 include/dt-bindings/iio/adi,ad5755.h
>
> diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
> index e1b6e78..c1e2546 100644
> --- a/drivers/iio/dac/ad5755.c
> +++ b/drivers/iio/dac/ad5755.c
> @@ -14,9 +14,11 @@
>   #include <linux/slab.h>
>   #include <linux/sysfs.h>
>   #include <linux/delay.h>
> +#include <linux/of.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
>   #include <linux/platform_data/ad5755.h>
> +#include <dt-bindings/iio/adi,ad5755.h>
>   
>   #define AD5755_NUM_CHANNELS 4
>   
> @@ -556,6 +558,82 @@ static const struct ad5755_platform_data ad5755_default_pdata = {
>   	},
>   };
>   
> +#ifdef CONFIG_OF
> +static struct ad5755_platform_data *ad5755_parse_dt(struct device *dev)
> +{
> +	struct device_node *np = dev->of_node;
> +	struct device_node *pp;
> +	struct ad5755_platform_data *pdata;
> +	unsigned int tmp;
> +	unsigned int tmparray[3];
> +	int devnr;
> +
> +	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> +	if (!pdata)
> +		return NULL;
> +
> +	pdata->ext_dc_dc_compenstation_resistor =
> +	       of_property_read_bool(np, "adi,ext_dc_dc_compenstation_resistor");
> +
> +	if (!of_property_read_u32(np, "adi,dc_dc_phase", &tmp))
> +		pdata->dc_dc_phase = tmp;
> +	else
> +		pdata->dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE;
> +
> +	if (!of_property_read_u32(np, "adi,dc_dc_freq", &tmp))
> +		pdata->dc_dc_freq = tmp;
> +	else
> +		pdata->dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ;
> +
> +	if (!of_property_read_u32(np, "adi,dc_dc_maxv", &tmp))
> +		pdata->dc_dc_maxv = tmp;
> +	else
> +		pdata->dc_dc_maxv = AD5755_DC_DC_MAXV_23V;
> +
> +	devnr = 0;
> +	for_each_child_of_node(np, pp) {
> +		if (devnr > AD5755_NUM_CHANNELS) {
> +			dev_err(dev, "There is to many channels defined in DT\n");
> +			goto error_out;
> +		}
> +
> +		if (!of_property_read_u32(pp, "adi,mode", &tmp))
> +			pdata->dac[devnr].mode = tmp;
> +		else
> +			pdata->dac[devnr].mode = AD5755_MODE_CURRENT_4mA_20mA;
> +
> +		pdata->dac[devnr].ext_current_sense_resistor =
> +		       of_property_read_bool(pp, "adi,ext_current_sense_resistor");
> +
> +		pdata->dac[devnr].enable_voltage_overrange =
> +			of_property_read_bool(pp, "adi,enable_voltage_overrange");
> +		if (!of_property_read_u32_array(pp, "adi,slew", tmparray, 3)) {
> +			pdata->dac[devnr].slew.enable = tmparray[0];
> +			pdata->dac[devnr].slew.rate = tmparray[1];
> +			pdata->dac[devnr].slew.step_size = tmparray[2];
> +		} else {
> +			pdata->dac[devnr].slew.enable = false;
> +			pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k;
> +			pdata->dac[devnr].slew.step_size = AD5755_SLEW_STEP_SIZE_1;
> +		}
> +
> +		devnr++;
> +	}
> +
> +	return pdata;
> +
> +error_out:
> +	devm_kfree(dev, pdata);
> +	return NULL;
> +}
> +#else
> +static
> +struct adf4350_platform_data *adf4350_parse_dt(struct device *dev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>   static int ad5755_probe(struct spi_device *spi)
>   {
>   	enum ad5755_type type = spi_get_device_id(spi)->driver_data;
> @@ -583,8 +661,15 @@ static int ad5755_probe(struct spi_device *spi)
>   	indio_dev->modes = INDIO_DIRECT_MODE;
>   	indio_dev->num_channels = AD5755_NUM_CHANNELS;
>   
> -	if (!pdata)
> +	if (spi->dev.of_node)
> +		pdata = ad5755_parse_dt(&spi->dev);
> +	else
> +		pdata = spi->dev.platform_data;
> +
> +	if (!pdata) {
> +		dev_warn(&spi->dev, "no platform data? using default\n");
>   		pdata = &ad5755_default_pdata;
> +	}
>   
>   	ret = ad5755_init_channels(indio_dev, pdata);
>   	if (ret)
> diff --git a/include/dt-bindings/iio/adi,ad5755.h b/include/dt-bindings/iio/adi,ad5755.h
> new file mode 100644
> index 0000000..117466b
> --- /dev/null
> +++ b/include/dt-bindings/iio/adi,ad5755.h
> @@ -0,0 +1,66 @@
> +/*
> + * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#ifndef _DT_BINDINGS_AD5755_H
> +#define _DT_BINDINGS_AD5755_H
> +
> +#define	AD5755_MODE_VOLTAGE_0V_5V			0
> +#define AD5755_MODE_VOLTAGE_0V_10V			1
> +#define AD5755_MODE_VOLTAGE_PLUSMINUS_5V		2
> +#define AD5755_MODE_VOLTAGE_PLUSMINUS_10V		3
> +#define AD5755_MODE_CURRENT_4mA_20mA			4
> +#define AD5755_MODE_CURRENT_0mA_20mA			5
> +#define AD5755_MODE_CURRENT_0mA_24mA			6
> +
> +#define AD5755_DC_DC_PHASE_ALL_SAME_EDGE		0
> +#define AD5755_DC_DC_PHASE_A_B_SAME_EDGE_C_D_OPP_EDGE	1
> +#define AD5755_DC_DC_PHASE_A_C_SAME_EDGE_B_D_OPP_EDGE	2
> +#define AD5755_DC_DC_PHASE_90_DEGREE			3
> +
> +#define AD5755_DC_DC_FREQ_250kHZ			0
> +#define AD5755_DC_DC_FREQ_410kHZ			1
> +#define AD5755_DC_DC_FREQ_650kHZ			2
> +
> +#define AD5755_DC_DC_MAXV_23V				0
> +#define AD5755_DC_DC_MAXV_24V5				1
> +#define AD5755_DC_DC_MAXV_27V				2
> +#define AD5755_DC_DC_MAXV_29V5				3
> +
> +#define AD5755_SLEW_RATE_64k				0
> +#define AD5755_SLEW_RATE_32k				1
> +#define AD5755_SLEW_RATE_16k				2
> +#define AD5755_SLEW_RATE_8k				3
> +#define AD5755_SLEW_RATE_4k				4
> +#define AD5755_SLEW_RATE_2k				5
> +#define AD5755_SLEW_RATE_1k				6
> +#define AD5755_SLEW_RATE_500				7
> +#define AD5755_SLEW_RATE_250				8
> +#define AD5755_SLEW_RATE_125				9
> +#define AD5755_SLEW_RATE_64				10
> +#define AD5755_SLEW_RATE_32				11
> +#define AD5755_SLEW_RATE_16				12
> +#define AD5755_SLEW_RATE_8				13
> +#define AD5755_SLEW_RATE_4				14
> +#define AD5755_SLEW_RATE_0_5				15
> +
> +#define AD5755_SLEW_STEP_SIZE_1				0
> +#define AD5755_SLEW_STEP_SIZE_2				1
> +#define AD5755_SLEW_STEP_SIZE_4				2
> +#define AD5755_SLEW_STEP_SIZE_8				3
> +#define AD5755_SLEW_STEP_SIZE_16 			4
> +#define AD5755_SLEW_STEP_SIZE_32			5
> +#define AD5755_SLEW_STEP_SIZE_64			6
> +#define AD5755_SLEW_STEP_SIZE_128			7
> +#define AD5755_SLEW_STEP_SIZE_256			8
> +
> +#endif				/* _DT_BINDINGS_AD5755_H */


  parent reply	other threads:[~2016-02-09  8:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03 14:31 [PATCH v2 1/4] iio: ad5755: add support for dt bindings Sean Nyekjaer
2016-02-03 14:31 ` Sean Nyekjaer
     [not found] ` <1454509864-32285-1-git-send-email-sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
2016-02-03 14:31   ` [PATCH v2 2/4] iio: ad5755: Add DT binding documentation Sean Nyekjaer
2016-02-03 14:31     ` Sean Nyekjaer
     [not found]     ` <1454509864-32285-2-git-send-email-sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
2016-02-03 14:31       ` [PATCH v2 3/4] iio: ad5755: added full support for devicetree Sean Nyekjaer
2016-02-03 14:31         ` Sean Nyekjaer
     [not found]         ` <1454509864-32285-3-git-send-email-sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
2016-02-03 14:31           ` [PATCH v2 4/4] iio: ad5755: Add full DT binding documentation Sean Nyekjaer
2016-02-03 14:31             ` Sean Nyekjaer
     [not found]             ` <1454509864-32285-4-git-send-email-sean.nyekjaer-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
2016-02-06 18:30               ` Jonathan Cameron
2016-02-06 18:30                 ` Jonathan Cameron
     [not found]                 ` <56B63BAC.2040001-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-02-08 17:37                   ` Rob Herring
2016-02-08 17:37                     ` Rob Herring
2016-02-09  8:22           ` Sean Nyekjær [this message]
2016-02-09  8:22             ` [PATCH v2 3/4] iio: ad5755: added full support for devicetree Sean Nyekjær
     [not found]             ` <56B9A1B2.6030007-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
2016-02-09 20:30               ` Lars-Peter Clausen
2016-02-09 20:30                 ` Lars-Peter Clausen
     [not found]                 ` <56BA4C74.9030503-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2016-02-16 13:46                   ` Sean Nyekjær
2016-02-16 13:46                     ` Sean Nyekjær
2016-02-06 18:36       ` [PATCH v2 2/4] iio: ad5755: Add DT binding documentation Jonathan Cameron
2016-02-06 18:36         ` 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=56B9A1B2.6030007@prevas.dk \
    --to=sean.nyekjaer-rjjw5hvvqkzaa/9udqfwiw@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.