mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ata: intf_platform_ide: add OF bindings
@ 2015-09-03 13:38 Peter Mamonov
  2015-09-03 14:24 ` Antony Pavlov
  2015-09-03 15:46 ` [PATCH] " Lucas Stach
  0 siblings, 2 replies; 15+ messages in thread
From: Peter Mamonov @ 2015-09-03 13:38 UTC (permalink / raw)
  To: barebox; +Cc: Peter Mamonov

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/ata/intf_platform_ide.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 0d392d8..f20e0e0 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -29,6 +29,7 @@
 #include <ata_drive.h>
 #include <platform_ide.h>
 #include <linux/err.h>
+#include <of.h>
 
 /**
  * Setup the register specific addresses for an ATA like divice
@@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d *dev)
 	void *reg_base, *alt_base = NULL;
 	struct resource *reg, *alt;
 	int mmio = 0;
+	struct device_node *dn = dev->device_node;
+	u32 tmp32;
 
 	if (pdata == NULL) {
-		dev_err(dev, "No platform data. Cannot continue\n");
-		return -EINVAL;
+		/* try to get platform data from the device tree */
+		if (dn == NULL) {
+			dev_err(dev, "No platform data. Cannot continue\n");
+			return -EINVAL;
+		}
+
+		pdata = xzalloc(sizeof(struct ide_port_info));
+
+		if (!pdata) {
+			dev_err(dev, "Platform data allocation failed\n");
+			return -ENOMEM;
+		}
+		device_add_data(dev, pdata, sizeof(struct ide_port_info));
+
+		if (of_property_read_bool(dn, "dataif-be"))
+			pdata->dataif_be = 1;
+
+		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
+			pdata->ioport_shift = (unsigned)tmp32;
+
+		dev->platform_data = pdata;
 	}
 
 	reg_base = dev_request_mem_region(dev, 0);
@@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d *dev)
 	return rc;
 }
 
+static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
+	{
+		.compatible = "ata-generic",
+	}, {
+		/* sentinel */
+	}
+};
+
 static struct driver_d platform_ide_driver = {
 	.name   = "ide_intf",
 	.probe  = platform_ide_probe,
+	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
 };
 device_platform_driver(platform_ide_driver);
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 13:38 [PATCH] ata: intf_platform_ide: add OF bindings Peter Mamonov
@ 2015-09-03 14:24 ` Antony Pavlov
  2015-09-03 15:33   ` Peter Mamonov
  2015-09-03 16:04   ` Peter Mamonov
  2015-09-03 15:46 ` [PATCH] " Lucas Stach
  1 sibling, 2 replies; 15+ messages in thread
From: Antony Pavlov @ 2015-09-03 14:24 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

On Thu,  3 Sep 2015 16:38:46 +0300
Peter Mamonov <pmamonov@gmail.com> wrote:

> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
>  drivers/ata/intf_platform_ide.c | 35 +++++++++++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
> index 0d392d8..f20e0e0 100644
> --- a/drivers/ata/intf_platform_ide.c
> +++ b/drivers/ata/intf_platform_ide.c
> @@ -29,6 +29,7 @@
>  #include <ata_drive.h>
>  #include <platform_ide.h>
>  #include <linux/err.h>
> +#include <of.h>
>  
>  /**
>   * Setup the register specific addresses for an ATA like divice
> @@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d *dev)
>  	void *reg_base, *alt_base = NULL;
>  	struct resource *reg, *alt;
>  	int mmio = 0;
> +	struct device_node *dn = dev->device_node;
> +	u32 tmp32;

Can we move dn and tmp32 declarations under 'if (pdata == NULL) {' ?

>  
>  	if (pdata == NULL) {
> -		dev_err(dev, "No platform data. Cannot continue\n");
> -		return -EINVAL;
> +		/* try to get platform data from the device tree */
> +		if (dn == NULL) {
> +			dev_err(dev, "No platform data. Cannot continue\n");
> +			return -EINVAL;
> +		}
> +
> +		pdata = xzalloc(sizeof(struct ide_port_info));
> +
> +		if (!pdata) {

xzalloc() can't return NULL.

Please drop this 'if' operator.

> +			dev_err(dev, "Platform data allocation failed\n");
> +			return -ENOMEM;
> +		}
> +		device_add_data(dev, pdata, sizeof(struct ide_port_info));
> +
> +		if (of_property_read_bool(dn, "dataif-be"))
> +			pdata->dataif_be = 1;
> +
> +		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
> +			pdata->ioport_shift = (unsigned)tmp32;
> +
> +		dev->platform_data = pdata;
>  	}
>  
>  	reg_base = dev_request_mem_region(dev, 0);
> @@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d *dev)
>  	return rc;
>  }
>  
> +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> +	{
> +		.compatible = "ata-generic",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
>  static struct driver_d platform_ide_driver = {
>  	.name   = "ide_intf",
>  	.probe  = platform_ide_probe,
> +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
>  };
>  device_platform_driver(platform_ide_driver);
>  
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 14:24 ` Antony Pavlov
@ 2015-09-03 15:33   ` Peter Mamonov
  2015-09-03 16:04   ` Peter Mamonov
  1 sibling, 0 replies; 15+ messages in thread
From: Peter Mamonov @ 2015-09-03 15:33 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Thu, 3 Sep 2015 17:24:55 +0300
Antony Pavlov <antonynpavlov@gmail.com> wrote:

> On Thu,  3 Sep 2015 16:38:46 +0300
> Peter Mamonov <pmamonov@gmail.com> wrote:
> 
> > Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> > ---
> >  drivers/ata/intf_platform_ide.c | 35
> > +++++++++++++++++++++++++++++++++-- 1 file changed, 33
> > insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/ata/intf_platform_ide.c
> > b/drivers/ata/intf_platform_ide.c index 0d392d8..f20e0e0 100644
> > --- a/drivers/ata/intf_platform_ide.c
> > +++ b/drivers/ata/intf_platform_ide.c
> > @@ -29,6 +29,7 @@
> >  #include <ata_drive.h>
> >  #include <platform_ide.h>
> >  #include <linux/err.h>
> > +#include <of.h>
> >  
> >  /**
> >   * Setup the register specific addresses for an ATA like divice
> > @@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d
> > *dev) void *reg_base, *alt_base = NULL;
> >  	struct resource *reg, *alt;
> >  	int mmio = 0;
> > +	struct device_node *dn = dev->device_node;
> > +	u32 tmp32;
> 
> Can we move dn and tmp32 declarations under 'if (pdata == NULL) {' ?
> 
> >  
> >  	if (pdata == NULL) {
> > -		dev_err(dev, "No platform data. Cannot
> > continue\n");
> > -		return -EINVAL;
> > +		/* try to get platform data from the device tree */
> > +		if (dn == NULL) {
> > +			dev_err(dev, "No platform data. Cannot
> > continue\n");
> > +			return -EINVAL;
> > +		}
> > +
> > +		pdata = xzalloc(sizeof(struct ide_port_info));
> > +
> > +		if (!pdata) {
> 
> xzalloc() can't return NULL.
> 
> Please drop this 'if' operator.
> 
> > +			dev_err(dev, "Platform data allocation
> > failed\n");
> > +			return -ENOMEM;
> > +		}
> > +		device_add_data(dev, pdata, sizeof(struct
> > ide_port_info)); +
> > +		if (of_property_read_bool(dn, "dataif-be"))
> > +			pdata->dataif_be = 1;
> > +
> > +		if (of_property_read_u32(dn, "reg-shift", &tmp32)
> > == 0)
> > +			pdata->ioport_shift = (unsigned)tmp32;
> > +
> > +		dev->platform_data = pdata;

This line is also excessive. device_add_data() have already done the
job.

> >  	}
> >  
> >  	reg_base = dev_request_mem_region(dev, 0);
> > @@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d
> > *dev) return rc;
> >  }
> >  
> > +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> > +	{
> > +		.compatible = "ata-generic",
> > +	}, {
> > +		/* sentinel */
> > +	}
> > +};
> > +
> >  static struct driver_d platform_ide_driver = {
> >  	.name   = "ide_intf",
> >  	.probe  = platform_ide_probe,
> > +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
> >  };
> >  device_platform_driver(platform_ide_driver);
> >  
> > -- 
> > 2.1.4
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> 
> 


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 13:38 [PATCH] ata: intf_platform_ide: add OF bindings Peter Mamonov
  2015-09-03 14:24 ` Antony Pavlov
@ 2015-09-03 15:46 ` Lucas Stach
  2015-09-03 16:31   ` Antony Pavlov
  2015-09-04  9:40   ` Peter Mamonov
  1 sibling, 2 replies; 15+ messages in thread
From: Lucas Stach @ 2015-09-03 15:46 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

Hi Peter.

Sorry, but this patch is wrong. You can't just make up completely ad-hoc
DT bindings. You are pushing platformdata 1:1 into the DT, which is not
how the conversion to DT should be done.

There is also no pre-existing binding for "ata-generic" in the Linux
kernel which would define any of those properties.

Most likely your IDE controller is inside some SoC specific block, with
a specific compatible, which may also handle clocks and other required
stuff and that one should instantiate the IDE driver if needed.

Regards,
Lucas

Am Donnerstag, den 03.09.2015, 16:38 +0300 schrieb Peter Mamonov:
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
>  drivers/ata/intf_platform_ide.c | 35 +++++++++++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
> index 0d392d8..f20e0e0 100644
> --- a/drivers/ata/intf_platform_ide.c
> +++ b/drivers/ata/intf_platform_ide.c
> @@ -29,6 +29,7 @@
>  #include <ata_drive.h>
>  #include <platform_ide.h>
>  #include <linux/err.h>
> +#include <of.h>
>  
>  /**
>   * Setup the register specific addresses for an ATA like divice
> @@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d *dev)
>  	void *reg_base, *alt_base = NULL;
>  	struct resource *reg, *alt;
>  	int mmio = 0;
> +	struct device_node *dn = dev->device_node;
> +	u32 tmp32;
>  
>  	if (pdata == NULL) {
> -		dev_err(dev, "No platform data. Cannot continue\n");
> -		return -EINVAL;
> +		/* try to get platform data from the device tree */
> +		if (dn == NULL) {
> +			dev_err(dev, "No platform data. Cannot continue\n");
> +			return -EINVAL;
> +		}
> +
> +		pdata = xzalloc(sizeof(struct ide_port_info));
> +
> +		if (!pdata) {
> +			dev_err(dev, "Platform data allocation failed\n");
> +			return -ENOMEM;
> +		}
> +		device_add_data(dev, pdata, sizeof(struct ide_port_info));
> +
> +		if (of_property_read_bool(dn, "dataif-be"))
> +			pdata->dataif_be = 1;
> +
> +		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
> +			pdata->ioport_shift = (unsigned)tmp32;
> +
> +		dev->platform_data = pdata;
>  	}
>  
>  	reg_base = dev_request_mem_region(dev, 0);
> @@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d *dev)
>  	return rc;
>  }
>  
> +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> +	{
> +		.compatible = "ata-generic",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
>  static struct driver_d platform_ide_driver = {
>  	.name   = "ide_intf",
>  	.probe  = platform_ide_probe,
> +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
>  };
>  device_platform_driver(platform_ide_driver);
>  

-- 
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 14:24 ` Antony Pavlov
  2015-09-03 15:33   ` Peter Mamonov
@ 2015-09-03 16:04   ` Peter Mamonov
  2015-09-03 18:13     ` Sascha Hauer
  1 sibling, 1 reply; 15+ messages in thread
From: Peter Mamonov @ 2015-09-03 16:04 UTC (permalink / raw)
  To: antonynpavlov, barebox; +Cc: Peter Mamonov

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/ata/intf_platform_ide.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 0d392d8..ba28f17 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -29,6 +29,7 @@
 #include <ata_drive.h>
 #include <platform_ide.h>
 #include <linux/err.h>
+#include <of.h>
 
 /**
  * Setup the register specific addresses for an ATA like divice
@@ -87,8 +88,24 @@ static int platform_ide_probe(struct device_d *dev)
 	int mmio = 0;
 
 	if (pdata == NULL) {
-		dev_err(dev, "No platform data. Cannot continue\n");
-		return -EINVAL;
+		/* try to get platform data from the device tree */
+		struct device_node *dn = dev->device_node;
+		u32 tmp32;
+
+		if (dn == NULL) {
+			dev_err(dev, "No platform data. Cannot continue\n");
+			return -EINVAL;
+		}
+
+		pdata = xzalloc(sizeof(struct ide_port_info));
+
+		if (of_property_read_bool(dn, "dataif-be"))
+			pdata->dataif_be = 1;
+
+		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
+			pdata->ioport_shift = (unsigned)tmp32;
+
+		device_add_data(dev, pdata, sizeof(struct ide_port_info));
 	}
 
 	reg_base = dev_request_mem_region(dev, 0);
@@ -136,9 +153,18 @@ static int platform_ide_probe(struct device_d *dev)
 	return rc;
 }
 
+static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
+	{
+		.compatible = "ata-generic",
+	}, {
+		/* sentinel */
+	}
+};
+
 static struct driver_d platform_ide_driver = {
 	.name   = "ide_intf",
 	.probe  = platform_ide_probe,
+	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
 };
 device_platform_driver(platform_ide_driver);
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 15:46 ` [PATCH] " Lucas Stach
@ 2015-09-03 16:31   ` Antony Pavlov
  2015-09-03 18:16     ` Sascha Hauer
  2015-09-04  9:40   ` Peter Mamonov
  1 sibling, 1 reply; 15+ messages in thread
From: Antony Pavlov @ 2015-09-03 16:31 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox, Peter Mamonov

On Thu, 03 Sep 2015 17:46:32 +0200
Lucas Stach <l.stach@pengutronix.de> wrote:

> Hi Peter.
> 
> Sorry, but this patch is wrong. You can't just make up completely ad-hoc
> DT bindings. You are pushing platformdata 1:1 into the DT, which is not
> how the conversion to DT should be done.
> 
> There is also no pre-existing binding for "ata-generic" in the Linux
> kernel which would define any of those properties.

Hmmm. in linux-4.2/drivers/ata/pata_of_platform.c I see "ata-generic"
with "reg-shift" and "pio-mode" properties.

> Most likely your IDE controller is inside some SoC specific block, with
> a specific compatible, which may also handle clocks and other required
> stuff and that one should instantiate the IDE driver if needed.
> 
> Regards,
> Lucas
> 
> Am Donnerstag, den 03.09.2015, 16:38 +0300 schrieb Peter Mamonov:
> > Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> > ---
> >  drivers/ata/intf_platform_ide.c | 35 +++++++++++++++++++++++++++++++++--
> >  1 file changed, 33 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
> > index 0d392d8..f20e0e0 100644
> > --- a/drivers/ata/intf_platform_ide.c
> > +++ b/drivers/ata/intf_platform_ide.c
> > @@ -29,6 +29,7 @@
> >  #include <ata_drive.h>
> >  #include <platform_ide.h>
> >  #include <linux/err.h>
> > +#include <of.h>
> >  
> >  /**
> >   * Setup the register specific addresses for an ATA like divice
> > @@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d *dev)
> >  	void *reg_base, *alt_base = NULL;
> >  	struct resource *reg, *alt;
> >  	int mmio = 0;
> > +	struct device_node *dn = dev->device_node;
> > +	u32 tmp32;
> >  
> >  	if (pdata == NULL) {
> > -		dev_err(dev, "No platform data. Cannot continue\n");
> > -		return -EINVAL;
> > +		/* try to get platform data from the device tree */
> > +		if (dn == NULL) {
> > +			dev_err(dev, "No platform data. Cannot continue\n");
> > +			return -EINVAL;
> > +		}
> > +
> > +		pdata = xzalloc(sizeof(struct ide_port_info));
> > +
> > +		if (!pdata) {
> > +			dev_err(dev, "Platform data allocation failed\n");
> > +			return -ENOMEM;
> > +		}
> > +		device_add_data(dev, pdata, sizeof(struct ide_port_info));
> > +
> > +		if (of_property_read_bool(dn, "dataif-be"))
> > +			pdata->dataif_be = 1;
> > +
> > +		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
> > +			pdata->ioport_shift = (unsigned)tmp32;
> > +
> > +		dev->platform_data = pdata;
> >  	}
> >  
> >  	reg_base = dev_request_mem_region(dev, 0);
> > @@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d *dev)
> >  	return rc;
> >  }
> >  
> > +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> > +	{
> > +		.compatible = "ata-generic",
> > +	}, {
> > +		/* sentinel */
> > +	}
> > +};
> > +
> >  static struct driver_d platform_ide_driver = {
> >  	.name   = "ide_intf",
> >  	.probe  = platform_ide_probe,
> > +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
> >  };
> >  device_platform_driver(platform_ide_driver);
> >  
> 
> -- 
> Pengutronix e.K.             | Lucas Stach                 |
> Industrial Linux Solutions   | http://www.pengutronix.de/  |
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 16:04   ` Peter Mamonov
@ 2015-09-03 18:13     ` Sascha Hauer
  2015-09-07 15:44       ` [PATCHv2] " Peter Mamonov
  0 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2015-09-03 18:13 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

On Thu, Sep 03, 2015 at 07:04:18PM +0300, Peter Mamonov wrote:
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
>  drivers/ata/intf_platform_ide.c | 30 ++++++++++++++++++++++++++++--
>  1 file changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
> index 0d392d8..ba28f17 100644
> --- a/drivers/ata/intf_platform_ide.c
> +++ b/drivers/ata/intf_platform_ide.c
> @@ -29,6 +29,7 @@
>  #include <ata_drive.h>
>  #include <platform_ide.h>
>  #include <linux/err.h>
> +#include <of.h>
>  
>  /**
>   * Setup the register specific addresses for an ATA like divice
> @@ -87,8 +88,24 @@ static int platform_ide_probe(struct device_d *dev)
>  	int mmio = 0;
>  
>  	if (pdata == NULL) {
> -		dev_err(dev, "No platform data. Cannot continue\n");
> -		return -EINVAL;
> +		/* try to get platform data from the device tree */
> +		struct device_node *dn = dev->device_node;
> +		u32 tmp32;
> +
> +		if (dn == NULL) {
> +			dev_err(dev, "No platform data. Cannot continue\n");
> +			return -EINVAL;
> +		}
> +
> +		pdata = xzalloc(sizeof(struct ide_port_info));
> +
> +		if (of_property_read_bool(dn, "dataif-be"))
> +			pdata->dataif_be = 1;
> +
> +		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
> +			pdata->ioport_shift = (unsigned)tmp32;

No need to allocate extra memory for platform_data which is solely used
in this function. Please just use two local variables dataif_be and
ioport_shift which you either fill in from platform_data or from device
tree.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 16:31   ` Antony Pavlov
@ 2015-09-03 18:16     ` Sascha Hauer
  2015-09-04 10:15       ` Peter Mamonov
  0 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2015-09-03 18:16 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox, Peter Mamonov

On Thu, Sep 03, 2015 at 07:31:55PM +0300, Antony Pavlov wrote:
> On Thu, 03 Sep 2015 17:46:32 +0200
> Lucas Stach <l.stach@pengutronix.de> wrote:
> 
> > Hi Peter.
> > 
> > Sorry, but this patch is wrong. You can't just make up completely ad-hoc
> > DT bindings. You are pushing platformdata 1:1 into the DT, which is not
> > how the conversion to DT should be done.
> > 
> > There is also no pre-existing binding for "ata-generic" in the Linux
> > kernel which would define any of those properties.
> 
> Hmmm. in linux-4.2/drivers/ata/pata_of_platform.c I see "ata-generic"
> with "reg-shift" and "pio-mode" properties.

It seems this binding comes from the good old days when writing binding
doc was an optional task ;)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 15:46 ` [PATCH] " Lucas Stach
  2015-09-03 16:31   ` Antony Pavlov
@ 2015-09-04  9:40   ` Peter Mamonov
  2015-09-04 10:23     ` Lucas Stach
  1 sibling, 1 reply; 15+ messages in thread
From: Peter Mamonov @ 2015-09-04  9:40 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

Hi, Lucas!

On Thu, 03 Sep 2015 17:46:32 +0200
Lucas Stach <l.stach@pengutronix.de> wrote:

> Hi Peter.
> 
> Sorry, but this patch is wrong. You can't just make up completely
> ad-hoc DT bindings. You are pushing platformdata 1:1 into the DT,
> which is not how the conversion to DT should be done.

Could you clarify your point? My current understanding is that drivers
instantiation from a platform code and from a DT are equal approaches,
which should mirror each other.

> 
> There is also no pre-existing binding for "ata-generic" in the Linux
> kernel which would define any of those properties.
> 
> Most likely your IDE controller is inside some SoC specific block,
> with a specific compatible, which may also handle clocks and other
> required stuff and that one should instantiate the IDE driver if
> needed.

I've got your point. However, drivers/ata/pata_of_platform.c from Linux
also lacks any clock/stuff initialization.

Regards,
Peter


> 
> Regards,
> Lucas
> 
> Am Donnerstag, den 03.09.2015, 16:38 +0300 schrieb Peter Mamonov:
> > Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> > ---
> >  drivers/ata/intf_platform_ide.c | 35
> > +++++++++++++++++++++++++++++++++-- 1 file changed, 33
> > insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/ata/intf_platform_ide.c
> > b/drivers/ata/intf_platform_ide.c index 0d392d8..f20e0e0 100644
> > --- a/drivers/ata/intf_platform_ide.c
> > +++ b/drivers/ata/intf_platform_ide.c
> > @@ -29,6 +29,7 @@
> >  #include <ata_drive.h>
> >  #include <platform_ide.h>
> >  #include <linux/err.h>
> > +#include <of.h>
> >  
> >  /**
> >   * Setup the register specific addresses for an ATA like divice
> > @@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d
> > *dev) void *reg_base, *alt_base = NULL;
> >  	struct resource *reg, *alt;
> >  	int mmio = 0;
> > +	struct device_node *dn = dev->device_node;
> > +	u32 tmp32;
> >  
> >  	if (pdata == NULL) {
> > -		dev_err(dev, "No platform data. Cannot
> > continue\n");
> > -		return -EINVAL;
> > +		/* try to get platform data from the device tree */
> > +		if (dn == NULL) {
> > +			dev_err(dev, "No platform data. Cannot
> > continue\n");
> > +			return -EINVAL;
> > +		}
> > +
> > +		pdata = xzalloc(sizeof(struct ide_port_info));
> > +
> > +		if (!pdata) {
> > +			dev_err(dev, "Platform data allocation
> > failed\n");
> > +			return -ENOMEM;
> > +		}
> > +		device_add_data(dev, pdata, sizeof(struct
> > ide_port_info)); +
> > +		if (of_property_read_bool(dn, "dataif-be"))
> > +			pdata->dataif_be = 1;
> > +
> > +		if (of_property_read_u32(dn, "reg-shift", &tmp32)
> > == 0)
> > +			pdata->ioport_shift = (unsigned)tmp32;
> > +
> > +		dev->platform_data = pdata;
> >  	}
> >  
> >  	reg_base = dev_request_mem_region(dev, 0);
> > @@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d
> > *dev) return rc;
> >  }
> >  
> > +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> > +	{
> > +		.compatible = "ata-generic",
> > +	}, {
> > +		/* sentinel */
> > +	}
> > +};
> > +
> >  static struct driver_d platform_ide_driver = {
> >  	.name   = "ide_intf",
> >  	.probe  = platform_ide_probe,
> > +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
> >  };
> >  device_platform_driver(platform_ide_driver);
> >  
> 


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-03 18:16     ` Sascha Hauer
@ 2015-09-04 10:15       ` Peter Mamonov
  0 siblings, 0 replies; 15+ messages in thread
From: Peter Mamonov @ 2015-09-04 10:15 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi, Sascha!

On Thu, 3 Sep 2015 20:16:36 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:

> On Thu, Sep 03, 2015 at 07:31:55PM +0300, Antony Pavlov wrote:
> > On Thu, 03 Sep 2015 17:46:32 +0200
> > Lucas Stach <l.stach@pengutronix.de> wrote:
> > 
> > > Hi Peter.
> > > 
> > > Sorry, but this patch is wrong. You can't just make up completely
> > > ad-hoc DT bindings. You are pushing platformdata 1:1 into the DT,
> > > which is not how the conversion to DT should be done.
> > > 
> > > There is also no pre-existing binding for "ata-generic" in the
> > > Linux kernel which would define any of those properties.
> > 
> > Hmmm. in linux-4.2/drivers/ata/pata_of_platform.c I see
> > "ata-generic" with "reg-shift" and "pio-mode" properties.
> 
> It seems this binding comes from the good old days when writing
> binding doc was an optional task ;)
> 
> Sascha
> 

So, do we need this linux-like binding in barebox, or should we prefer
a soc-specific approach, as Lucas described:
> Most likely your IDE controller is inside some SoC specific block,
> with a specific compatible, which may also handle clocks and other
> required stuff and that one should instantiate the IDE driver if
> needed.
?

Peter

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ata: intf_platform_ide: add OF bindings
  2015-09-04  9:40   ` Peter Mamonov
@ 2015-09-04 10:23     ` Lucas Stach
  0 siblings, 0 replies; 15+ messages in thread
From: Lucas Stach @ 2015-09-04 10:23 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

Am Freitag, den 04.09.2015, 12:40 +0300 schrieb Peter Mamonov:
> Hi, Lucas!
> 
> On Thu, 03 Sep 2015 17:46:32 +0200
> Lucas Stach <l.stach@pengutronix.de> wrote:
> 
> > Hi Peter.
> > 
> > Sorry, but this patch is wrong. You can't just make up completely
> > ad-hoc DT bindings. You are pushing platformdata 1:1 into the DT,
> > which is not how the conversion to DT should be done.
> 
> Could you clarify your point? My current understanding is that drivers
> instantiation from a platform code and from a DT are equal approaches,
> which should mirror each other.
> 
No not at all. DT bindings are API between the DT and barebox/Linux, so
they can not in all cases mirror platformdata, which we are able to
change at will.

DT instantiation need a well thought through binding, which isn't some
ad-hoc mirroring of the current platformdata.

Normally the binding is established by writing it down in the Linux
kernel Documentation/devicetree/bindings folder (and obviously getting
it through the DT review process).

> > 
> > There is also no pre-existing binding for "ata-generic" in the Linux
> > kernel which would define any of those properties.
> > 
> > Most likely your IDE controller is inside some SoC specific block,
> > with a specific compatible, which may also handle clocks and other
> > required stuff and that one should instantiate the IDE driver if
> > needed.
> 
> I've got your point. However, drivers/ata/pata_of_platform.c from Linux
> also lacks any clock/stuff initialization.
> 
If there is already a Linux driver with this binding you can reuse that
one, as it's already established, even if there is no proper
documentation there. If the binding is enough for your use-case that's
okay.

You can however not make any ad-hoc additions to the established
bindings, so if it doesn't fit your needs you need to propose the
addition to the generic binding to DT reviewers, or think about a SoC
specific binding if you need clocks/regulators or other things that
don't belong in a generic binding.

Regards,
Lucas

> Regards,
> Peter
> 
> 
> > 
> > Regards,
> > Lucas
> > 
> > Am Donnerstag, den 03.09.2015, 16:38 +0300 schrieb Peter Mamonov:
> > > Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> > > ---
> > >  drivers/ata/intf_platform_ide.c | 35
> > > +++++++++++++++++++++++++++++++++-- 1 file changed, 33
> > > insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/ata/intf_platform_ide.c
> > > b/drivers/ata/intf_platform_ide.c index 0d392d8..f20e0e0 100644
> > > --- a/drivers/ata/intf_platform_ide.c
> > > +++ b/drivers/ata/intf_platform_ide.c
> > > @@ -29,6 +29,7 @@
> > >  #include <ata_drive.h>
> > >  #include <platform_ide.h>
> > >  #include <linux/err.h>
> > > +#include <of.h>
> > >  
> > >  /**
> > >   * Setup the register specific addresses for an ATA like divice
> > > @@ -85,10 +86,31 @@ static int platform_ide_probe(struct device_d
> > > *dev) void *reg_base, *alt_base = NULL;
> > >  	struct resource *reg, *alt;
> > >  	int mmio = 0;
> > > +	struct device_node *dn = dev->device_node;
> > > +	u32 tmp32;
> > >  
> > >  	if (pdata == NULL) {
> > > -		dev_err(dev, "No platform data. Cannot
> > > continue\n");
> > > -		return -EINVAL;
> > > +		/* try to get platform data from the device tree */
> > > +		if (dn == NULL) {
> > > +			dev_err(dev, "No platform data. Cannot
> > > continue\n");
> > > +			return -EINVAL;
> > > +		}
> > > +
> > > +		pdata = xzalloc(sizeof(struct ide_port_info));
> > > +
> > > +		if (!pdata) {
> > > +			dev_err(dev, "Platform data allocation
> > > failed\n");
> > > +			return -ENOMEM;
> > > +		}
> > > +		device_add_data(dev, pdata, sizeof(struct
> > > ide_port_info)); +
> > > +		if (of_property_read_bool(dn, "dataif-be"))
> > > +			pdata->dataif_be = 1;
> > > +
> > > +		if (of_property_read_u32(dn, "reg-shift", &tmp32)
> > > == 0)
> > > +			pdata->ioport_shift = (unsigned)tmp32;
> > > +
> > > +		dev->platform_data = pdata;
> > >  	}
> > >  
> > >  	reg_base = dev_request_mem_region(dev, 0);
> > > @@ -136,9 +158,18 @@ static int platform_ide_probe(struct device_d
> > > *dev) return rc;
> > >  }
> > >  
> > > +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> > > +	{
> > > +		.compatible = "ata-generic",
> > > +	}, {
> > > +		/* sentinel */
> > > +	}
> > > +};
> > > +
> > >  static struct driver_d platform_ide_driver = {
> > >  	.name   = "ide_intf",
> > >  	.probe  = platform_ide_probe,
> > > +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
> > >  };
> > >  device_platform_driver(platform_ide_driver);
> > >  
> > 
> 

-- 
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCHv2] ata: intf_platform_ide: add OF bindings
  2015-09-03 18:13     ` Sascha Hauer
@ 2015-09-07 15:44       ` Peter Mamonov
  2015-09-07 15:53         ` Lucas Stach
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Mamonov @ 2015-09-07 15:44 UTC (permalink / raw)
  To: s.hauer; +Cc: barebox, Peter Mamonov

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/ata/intf_platform_ide.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 0d392d8..e46c2c8 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -29,6 +29,7 @@
 #include <ata_drive.h>
 #include <platform_ide.h>
 #include <linux/err.h>
+#include <of.h>
 
 /**
  * Setup the register specific addresses for an ATA like divice
@@ -85,8 +86,24 @@ static int platform_ide_probe(struct device_d *dev)
 	void *reg_base, *alt_base = NULL;
 	struct resource *reg, *alt;
 	int mmio = 0;
-
-	if (pdata == NULL) {
+	struct device_node *dn = dev->device_node;
+	unsigned ioport_shift = 0;
+	int dataif_be = 0;
+	void (*reset)(int) = NULL;
+
+	if (pdata) {
+		ioport_shift = pdata->ioport_shift;
+		dataif_be = pdata->dataif_be;
+		reset = pdata->reset;
+	} else if (dn) {
+		/* try to get platform data from the device tree */
+		u32 tmp32;
+
+		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
+			ioport_shift = (unsigned)tmp32;
+		if (of_property_read_bool(dn, "dataif-be"))
+			dataif_be = 1;
+	} else {
 		dev_err(dev, "No platform data. Cannot continue\n");
 		return -EINVAL;
 	}
@@ -123,9 +140,9 @@ static int platform_ide_probe(struct device_d *dev)
 	ide = xzalloc(sizeof(*ide));
 	ide->io.mmio = mmio;
 
-	platform_ide_setup_port(reg_base, alt_base, &ide->io, pdata->ioport_shift);
-	ide->io.reset = pdata->reset;
-	ide->io.dataif_be = pdata->dataif_be;
+	platform_ide_setup_port(reg_base, alt_base, &ide->io, ioport_shift);
+	ide->io.reset = reset;
+	ide->io.dataif_be = dataif_be;
 
 	rc = ide_port_register(ide);
 	if (rc != 0) {
@@ -136,9 +153,18 @@ static int platform_ide_probe(struct device_d *dev)
 	return rc;
 }
 
+static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
+	{
+		.compatible = "ata-generic",
+	}, {
+		/* sentinel */
+	}
+};
+
 static struct driver_d platform_ide_driver = {
 	.name   = "ide_intf",
 	.probe  = platform_ide_probe,
+	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
 };
 device_platform_driver(platform_ide_driver);
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCHv2] ata: intf_platform_ide: add OF bindings
  2015-09-07 15:44       ` [PATCHv2] " Peter Mamonov
@ 2015-09-07 15:53         ` Lucas Stach
  2015-09-07 16:43           ` [PATCHv3] " Peter Mamonov
  0 siblings, 1 reply; 15+ messages in thread
From: Lucas Stach @ 2015-09-07 15:53 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

Am Montag, den 07.09.2015, 18:44 +0300 schrieb Peter Mamonov:
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
>  drivers/ata/intf_platform_ide.c | 36 +++++++++++++++++++++++++++++++-----
>  1 file changed, 31 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
> index 0d392d8..e46c2c8 100644
> --- a/drivers/ata/intf_platform_ide.c
> +++ b/drivers/ata/intf_platform_ide.c
> @@ -29,6 +29,7 @@
>  #include <ata_drive.h>
>  #include <platform_ide.h>
>  #include <linux/err.h>
> +#include <of.h>
>  
>  /**
>   * Setup the register specific addresses for an ATA like divice
> @@ -85,8 +86,24 @@ static int platform_ide_probe(struct device_d *dev)
>  	void *reg_base, *alt_base = NULL;
>  	struct resource *reg, *alt;
>  	int mmio = 0;
> -
> -	if (pdata == NULL) {
> +	struct device_node *dn = dev->device_node;
> +	unsigned ioport_shift = 0;
> +	int dataif_be = 0;
> +	void (*reset)(int) = NULL;
> +
> +	if (pdata) {
> +		ioport_shift = pdata->ioport_shift;
> +		dataif_be = pdata->dataif_be;
> +		reset = pdata->reset;
> +	} else if (dn) {
> +		/* try to get platform data from the device tree */
> +		u32 tmp32;
> +
> +		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
> +			ioport_shift = (unsigned)tmp32;

This is okay, as it's already used by the established precedent in
Linux.

> +		if (of_property_read_bool(dn, "dataif-be"))
> +			dataif_be = 1;

This is not okay, there is no precedent for this property in Linux and
there is no binding specifying this property.

> +	} else {
>  		dev_err(dev, "No platform data. Cannot continue\n");
>  		return -EINVAL;
>  	}
> @@ -123,9 +140,9 @@ static int platform_ide_probe(struct device_d *dev)
>  	ide = xzalloc(sizeof(*ide));
>  	ide->io.mmio = mmio;
>  
> -	platform_ide_setup_port(reg_base, alt_base, &ide->io, pdata->ioport_shift);
> -	ide->io.reset = pdata->reset;
> -	ide->io.dataif_be = pdata->dataif_be;
> +	platform_ide_setup_port(reg_base, alt_base, &ide->io, ioport_shift);
> +	ide->io.reset = reset;
> +	ide->io.dataif_be = dataif_be;
>  
>  	rc = ide_port_register(ide);
>  	if (rc != 0) {
> @@ -136,9 +153,18 @@ static int platform_ide_probe(struct device_d *dev)
>  	return rc;
>  }
>  
> +static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
> +	{
> +		.compatible = "ata-generic",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
>  static struct driver_d platform_ide_driver = {
>  	.name   = "ide_intf",
>  	.probe  = platform_ide_probe,
> +	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
>  };
>  device_platform_driver(platform_ide_driver);
>  

-- 
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCHv3] ata: intf_platform_ide: add OF bindings
  2015-09-07 15:53         ` Lucas Stach
@ 2015-09-07 16:43           ` Peter Mamonov
  2015-09-09  6:54             ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Mamonov @ 2015-09-07 16:43 UTC (permalink / raw)
  To: l.stach, s.hauer; +Cc: barebox, Peter Mamonov

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/ata/intf_platform_ide.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 0d392d8..ab633c0 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -29,6 +29,7 @@
 #include <ata_drive.h>
 #include <platform_ide.h>
 #include <linux/err.h>
+#include <of.h>
 
 /**
  * Setup the register specific addresses for an ATA like divice
@@ -85,8 +86,22 @@ static int platform_ide_probe(struct device_d *dev)
 	void *reg_base, *alt_base = NULL;
 	struct resource *reg, *alt;
 	int mmio = 0;
-
-	if (pdata == NULL) {
+	struct device_node *dn = dev->device_node;
+	unsigned ioport_shift = 0;
+	int dataif_be = 0;
+	void (*reset)(int) = NULL;
+
+	if (pdata) {
+		ioport_shift = pdata->ioport_shift;
+		dataif_be = pdata->dataif_be;
+		reset = pdata->reset;
+	} else if (dn) {
+		/* try to get platform data from the device tree */
+		u32 tmp32;
+
+		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
+			ioport_shift = (unsigned)tmp32;
+	} else {
 		dev_err(dev, "No platform data. Cannot continue\n");
 		return -EINVAL;
 	}
@@ -123,9 +138,9 @@ static int platform_ide_probe(struct device_d *dev)
 	ide = xzalloc(sizeof(*ide));
 	ide->io.mmio = mmio;
 
-	platform_ide_setup_port(reg_base, alt_base, &ide->io, pdata->ioport_shift);
-	ide->io.reset = pdata->reset;
-	ide->io.dataif_be = pdata->dataif_be;
+	platform_ide_setup_port(reg_base, alt_base, &ide->io, ioport_shift);
+	ide->io.reset = reset;
+	ide->io.dataif_be = dataif_be;
 
 	rc = ide_port_register(ide);
 	if (rc != 0) {
@@ -136,9 +151,18 @@ static int platform_ide_probe(struct device_d *dev)
 	return rc;
 }
 
+static __maybe_unused struct of_device_id platform_ide_dt_ids[] = {
+	{
+		.compatible = "ata-generic",
+	}, {
+		/* sentinel */
+	}
+};
+
 static struct driver_d platform_ide_driver = {
 	.name   = "ide_intf",
 	.probe  = platform_ide_probe,
+	.of_compatible = DRV_OF_COMPAT(platform_ide_dt_ids),
 };
 device_platform_driver(platform_ide_driver);
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCHv3] ata: intf_platform_ide: add OF bindings
  2015-09-07 16:43           ` [PATCHv3] " Peter Mamonov
@ 2015-09-09  6:54             ` Sascha Hauer
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-09-09  6:54 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

Hi Peter,

On Mon, Sep 07, 2015 at 07:43:53PM +0300, Peter Mamonov wrote:
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
>  drivers/ata/intf_platform_ide.c | 34 +++++++++++++++++++++++++++++-----
>  1 file changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
> index 0d392d8..ab633c0 100644
> --- a/drivers/ata/intf_platform_ide.c
> +++ b/drivers/ata/intf_platform_ide.c
> @@ -29,6 +29,7 @@
>  #include <ata_drive.h>
>  #include <platform_ide.h>
>  #include <linux/err.h>
> +#include <of.h>
>  
>  /**
>   * Setup the register specific addresses for an ATA like divice
> @@ -85,8 +86,22 @@ static int platform_ide_probe(struct device_d *dev)
>  	void *reg_base, *alt_base = NULL;
>  	struct resource *reg, *alt;
>  	int mmio = 0;
> -
> -	if (pdata == NULL) {
> +	struct device_node *dn = dev->device_node;
> +	unsigned ioport_shift = 0;
> +	int dataif_be = 0;
> +	void (*reset)(int) = NULL;
> +
> +	if (pdata) {
> +		ioport_shift = pdata->ioport_shift;
> +		dataif_be = pdata->dataif_be;
> +		reset = pdata->reset;
> +	} else if (dn) {
> +		/* try to get platform data from the device tree */
> +		u32 tmp32;
> +
> +		if (of_property_read_u32(dn, "reg-shift", &tmp32) == 0)
> +			ioport_shift = (unsigned)tmp32;

Applied with one little change. We can simplify this by doing passing
&ioport_shift directly to of_property_read_u32. We do not have to check
the return value then.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2015-09-09  6:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 13:38 [PATCH] ata: intf_platform_ide: add OF bindings Peter Mamonov
2015-09-03 14:24 ` Antony Pavlov
2015-09-03 15:33   ` Peter Mamonov
2015-09-03 16:04   ` Peter Mamonov
2015-09-03 18:13     ` Sascha Hauer
2015-09-07 15:44       ` [PATCHv2] " Peter Mamonov
2015-09-07 15:53         ` Lucas Stach
2015-09-07 16:43           ` [PATCHv3] " Peter Mamonov
2015-09-09  6:54             ` Sascha Hauer
2015-09-03 15:46 ` [PATCH] " Lucas Stach
2015-09-03 16:31   ` Antony Pavlov
2015-09-03 18:16     ` Sascha Hauer
2015-09-04 10:15       ` Peter Mamonov
2015-09-04  9:40   ` Peter Mamonov
2015-09-04 10:23     ` Lucas Stach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox