All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] stagging:iio:ad9834: add devicetree property support
@ 2016-09-11 10:52 Gwenhael Goavec-Merou
  2016-09-12 12:02 ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Gwenhael Goavec-Merou @ 2016-09-11 10:52 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Paul Cercueil, devel,
	Gwenhael Goavec-Merou

ad9834 driver needs some default properties. Currently these parameters are
provided through platform_data.
This patch adds a function to create this pdata based on device-tree node.

Signed-off-by: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
---
 drivers/staging/iio/frequency/ad9834.c | 39 ++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 6366216..6cec154 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -316,6 +316,39 @@ static const struct iio_info ad9833_info = {
 	.driver_module = THIS_MODULE,
 };
 
+#if defined(CONFIG_OF)
+static struct ad9834_platform_data *ad9834_parse_dt(struct spi_device *spi)
+{
+	struct ad9834_platform_data *pdata;
+	struct device_node *np = spi->dev.of_node;
+
+	pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	if (of_property_read_u32(np, "mclk", &pdata->mclk))
+		return ERR_PTR(-ENODEV);
+	if (of_property_read_u32(np, "freq0", &pdata->freq0))
+		return ERR_PTR(-ENODEV);
+	if (of_property_read_u32(np, "freq1", &pdata->freq1))
+		return ERR_PTR(-ENODEV);
+	if (of_property_read_u16(np, "phase0", &pdata->phase0))
+		return ERR_PTR(-ENODEV);
+	if (of_property_read_u16(np, "phase1", &pdata->phase1))
+		return ERR_PTR(-ENODEV);
+	pdata->en_div2 = of_property_read_bool(np, "en_div2");
+	pdata->en_signbit_msb_out = of_property_read_bool(np,
+					"en_signbit_msb_out");
+
+	return pdata;
+}
+#else
+static struct ad9834_platform_data *ad9834_parse_dt(struct spi_device *spi)
+{
+	return NULL;
+}
+#endif
+
 static int ad9834_probe(struct spi_device *spi)
 {
 	struct ad9834_platform_data *pdata = dev_get_platdata(&spi->dev);
@@ -324,6 +357,12 @@ static int ad9834_probe(struct spi_device *spi)
 	struct regulator *reg;
 	int ret;
 
+	if (!pdata && spi->dev.of_node) {
+		pdata = ad9834_parse_dt(spi);
+		if (IS_ERR(pdata))
+			return PTR_ERR(pdata);
+	}
+
 	if (!pdata) {
 		dev_dbg(&spi->dev, "no platform data?\n");
 		return -ENODEV;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] stagging:iio:ad9834: add devicetree property support
  2016-09-11 10:52 [PATCH] stagging:iio:ad9834: add devicetree property support Gwenhael Goavec-Merou
@ 2016-09-12 12:02 ` Lars-Peter Clausen
  2016-09-18  8:53   ` Gwenhael Goavec-Merou
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2016-09-12 12:02 UTC (permalink / raw)
  To: Gwenhael Goavec-Merou, linux-iio
  Cc: Michael Hennerich, Jonathan Cameron, Hartmut Knaack,
	Peter Meerwald-Stadler, Paul Cercueil, devel

Hi,

Thanks for the patch.

On 09/11/2016 12:52 PM, Gwenhael Goavec-Merou wrote:
> +static struct ad9834_platform_data *ad9834_parse_dt(struct spi_device *spi)
> +{
> +	struct ad9834_platform_data *pdata;
> +	struct device_node *np = spi->dev.of_node;
> +
> +	pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
> +	if (!pdata)
> +		return ERR_PTR(-ENOMEM);
> +
> +	if (of_property_read_u32(np, "mclk", &pdata->mclk))
> +		return ERR_PTR(-ENODEV);

The input clock should be using the standard clock bindings.

> +	if (of_property_read_u32(np, "freq0", &pdata->freq0))
> +		return ERR_PTR(-ENODEV);
> +	if (of_property_read_u32(np, "freq1", &pdata->freq1))
> +		return ERR_PTR(-ENODEV);
> +	if (of_property_read_u16(np, "phase0", &pdata->phase0))
> +		return ERR_PTR(-ENODEV);
> +	if (of_property_read_u16(np, "phase1", &pdata->phase1))
> +		return ERR_PTR(-ENODEV);
> +	pdata->en_div2 = of_property_read_bool(np, "en_div2");
> +	pdata->en_signbit_msb_out = of_property_read_bool(np,
> +					"en_signbit_msb_out");

The other attributes seem to be more runtime configuration data, rather than
hardware description. Maybe just choose a fixed default.

- Lars

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] stagging:iio:ad9834: add devicetree property support
  2016-09-12 12:02 ` Lars-Peter Clausen
@ 2016-09-18  8:53   ` Gwenhael Goavec-Merou
  0 siblings, 0 replies; 3+ messages in thread
From: Gwenhael Goavec-Merou @ 2016-09-18  8:53 UTC (permalink / raw)
  To: Lars-Peter Clausen, Gwenhael Goavec-Merou, linux-iio
  Cc: Michael Hennerich, Jonathan Cameron, Hartmut Knaack,
	Peter Meerwald-Stadler, Paul Cercueil, devel

Hi,
Thanks for the review. I will send a new patch.
Gwenhael

On 12/09/2016 14:02, Lars-Peter Clausen wrote:
> Hi,
>
> Thanks for the patch.
>
> On 09/11/2016 12:52 PM, Gwenhael Goavec-Merou wrote:
>> +static struct ad9834_platform_data *ad9834_parse_dt(struct spi_device *spi)
>> +{
>> +	struct ad9834_platform_data *pdata;
>> +	struct device_node *np = spi->dev.of_node;
>> +
>> +	pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
>> +	if (!pdata)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	if (of_property_read_u32(np, "mclk", &pdata->mclk))
>> +		return ERR_PTR(-ENODEV);
>
> The input clock should be using the standard clock bindings.
>
>> +	if (of_property_read_u32(np, "freq0", &pdata->freq0))
>> +		return ERR_PTR(-ENODEV);
>> +	if (of_property_read_u32(np, "freq1", &pdata->freq1))
>> +		return ERR_PTR(-ENODEV);
>> +	if (of_property_read_u16(np, "phase0", &pdata->phase0))
>> +		return ERR_PTR(-ENODEV);
>> +	if (of_property_read_u16(np, "phase1", &pdata->phase1))
>> +		return ERR_PTR(-ENODEV);
>> +	pdata->en_div2 = of_property_read_bool(np, "en_div2");
>> +	pdata->en_signbit_msb_out = of_property_read_bool(np,
>> +					"en_signbit_msb_out");
>
> The other attributes seem to be more runtime configuration data, rather than
> hardware description. Maybe just choose a fixed default.
>
> - Lars
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-18  8:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-11 10:52 [PATCH] stagging:iio:ad9834: add devicetree property support Gwenhael Goavec-Merou
2016-09-12 12:02 ` Lars-Peter Clausen
2016-09-18  8:53   ` Gwenhael Goavec-Merou

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.