mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC] net: dm9k: add device tree support
@ 2014-09-10  7:53 Antony Pavlov
  2014-09-11  6:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Antony Pavlov @ 2014-09-10  7:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/net/dm9k.c | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/drivers/net/dm9k.c b/drivers/net/dm9k.c
index e525a84..9e7b415 100644
--- a/drivers/net/dm9k.c
+++ b/drivers/net/dm9k.c
@@ -707,16 +707,30 @@ static int dm9k_init_dev(struct eth_device *edev)
 	return 0;
 }
 
+static struct dm9000_platform_data *dm9000_parse_dt(struct device_d *dev)
+{
+	struct dm9000_platform_data *pdata;
+	struct device_node *np = dev->device_node;
+
+	if (!IS_ENABLED(CONFIG_OF) || !np)
+		return NULL;
+
+	pdata = xzalloc(sizeof(*pdata));
+
+	pdata->srom = 0;
+
+	return pdata;
+}
+
 static int dm9k_probe(struct device_d *dev)
 {
 	unsigned io_mode;
 	struct eth_device *edev;
 	struct dm9k *priv;
-	struct dm9000_platform_data *pdata;
+	struct dm9000_platform_data *pdata = dev->platform_data;
 
-	if (!dev->platform_data) {
-		dev_err(dev, "No platform_data\n");
-		return -ENODEV;
+	if (!pdata) {
+		pdata = dm9000_parse_dt(dev);
 	}
 
 	if (dev->num_resources < 2) {
@@ -727,11 +741,23 @@ static int dm9k_probe(struct device_d *dev)
 	edev = xzalloc(sizeof(struct eth_device) + sizeof(struct dm9k));
 	edev->priv = (struct dm9k *)(edev + 1);
 
-	pdata = dev->platform_data;
-
 	priv = edev->priv;
 
-	priv->buswidth = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+	switch (resource_size(&dev->resource[0])) {
+	case 1:
+		priv->buswidth = IORESOURCE_MEM_8BIT;
+		break;
+	case 2:
+		priv->buswidth = IORESOURCE_MEM_16BIT;
+		break;
+	case 4:
+		priv->buswidth = IORESOURCE_MEM_32BIT;
+		break;
+	default:
+		dev_err(dev, "Wrong io resource size\n");
+		priv->buswidth = 0;
+	}
+
 	priv->iodata = dev_request_mem_region(dev, 1);
 	if (!priv->iodata)
 		return -EBUSY;
@@ -791,8 +817,14 @@ static int dm9k_probe(struct device_d *dev)
 	return 0;
 }
 
+static struct of_device_id dm9000_of_matches[] = {
+	{ .compatible = "davicom,dm9000", },
+	{ /* sentinel */ }
+};
+
 static struct driver_d dm9k_driver = {
 	.name  = "dm9000",
 	.probe = dm9k_probe,
+	.of_compatible = DRV_OF_COMPAT(dm9000_of_matches),
 };
 device_platform_driver(dm9k_driver);
-- 
2.1.0


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

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

* Re: [RFC] net: dm9k: add device tree support
  2014-09-10  7:53 [RFC] net: dm9k: add device tree support Antony Pavlov
@ 2014-09-11  6:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-09-11  6:23 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Wed, Sep 10, 2014 at 11:53:48AM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  drivers/net/dm9k.c | 46 +++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 39 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/dm9k.c b/drivers/net/dm9k.c
> index e525a84..9e7b415 100644
> --- a/drivers/net/dm9k.c
> +++ b/drivers/net/dm9k.c
> @@ -707,16 +707,30 @@ static int dm9k_init_dev(struct eth_device *edev)
>  	return 0;
>  }
>  
> +static struct dm9000_platform_data *dm9000_parse_dt(struct device_d *dev)
> +{
> +	struct dm9000_platform_data *pdata;
> +	struct device_node *np = dev->device_node;
> +
> +	if (!IS_ENABLED(CONFIG_OF) || !np)
> +		return NULL;
> +
> +	pdata = xzalloc(sizeof(*pdata));
> +
> +	pdata->srom = 0;

Please don't allocate platform_data for the device tree case. Instead,
add a srom variable to struct dm9k and set it either from platform_data
or device tree.

> -	priv->buswidth = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
> +	switch (resource_size(&dev->resource[0])) {
> +	case 1:
> +		priv->buswidth = IORESOURCE_MEM_8BIT;
> +		break;
> +	case 2:
> +		priv->buswidth = IORESOURCE_MEM_16BIT;
> +		break;
> +	case 4:
> +		priv->buswidth = IORESOURCE_MEM_32BIT;
> +		break;
> +	default:
> +		dev_err(dev, "Wrong io resource size\n");
> +		priv->buswidth = 0;
> +	}

Does this work for 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] 2+ messages in thread

end of thread, other threads:[~2014-09-11  6:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-10  7:53 [RFC] net: dm9k: add device tree support Antony Pavlov
2014-09-11  6:23 ` Sascha Hauer

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