mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/6] of: Allow multiple resources in 'reg' property
Date: Mon, 22 Apr 2013 09:27:20 +0200	[thread overview]
Message-ID: <1366615643-22213-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1366615643-22213-1-git-send-email-s.hauer@pengutronix.de>

Some devices need multiple resources in the reg property. This patch
adds support for it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 55 ++++++++++++++++++++++++++++++++++++++-----------------
 include/of.h      |  1 +
 2 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index c086f7e..b8c2e89 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -828,7 +828,7 @@ static struct device_d *add_of_platform_device(struct device_node *node)
 
 	dev->id = DEVICE_ID_SINGLE;
 	dev->resource = node->resource;
-	dev->num_resources = 1;
+	dev->num_resources = node->num_resource;
 	dev->device_node = node;
 	node->device = dev;
 
@@ -915,25 +915,44 @@ int of_add_memory(struct device_node *node, bool dump)
 
 static int add_of_device_resource(struct device_node *node)
 {
-	struct property *reg;
-	u64 address, size;
-	struct resource *res;
+	u64 address = 0, size;
+	struct resource *res, *resp;
 	struct device_d *dev;
-	int ret;
+	const __be32 *endp, *reg;
+	int na, nc, n_resources;
+	int ret, len;
 
 	ret = of_add_memory(node, false);
 	if (ret != -ENXIO)
 		return ret;
 
-	reg = of_find_property(node, "reg");
+	reg = of_get_property(node, "reg", &len);
 	if (!reg)
-		return -ENODEV;
-
-	address = of_translate_address(node, reg->value);
-	if (address == OF_BAD_ADDR)
 		return -EINVAL;
 
-	size = be32_to_cpu(((u32 *)reg->value)[1]);
+	of_bus_count_cells(node, &na, &nc);
+
+	n_resources = (len / sizeof(__be32)) / (na + nc);
+
+	res = resp = xzalloc(sizeof(*res) * n_resources);
+
+	endp = reg + (len / sizeof(__be32));
+
+	while ((endp - reg) >= (na + nc)) {
+		address = of_translate_address(node, reg);
+		if (address == OF_BAD_ADDR) {
+			ret =  -EINVAL;
+			goto err_free;
+		}
+
+		reg += na;
+		size = dt_mem_next_cell(nc, &reg);
+
+		resp->start = address;
+		resp->end = address + size - 1;
+		resp->flags = IORESOURCE_MEM;
+		resp++;
+        }
 
 	/*
 	 * A device may already be registered as platform_device.
@@ -948,20 +967,22 @@ static int add_of_device_resource(struct device_node *node)
 			node->device = dev;
 			dev->device_node = node;
 			node->resource = dev->resource;
-			return 0;
+			ret = 0;
+			goto err_free;
 		}
 	}
 
-	res = xzalloc(sizeof(*res));
-	res->start = address;
-	res->end = address + size - 1;
-	res->flags = IORESOURCE_MEM;
-
 	node->resource = res;
+	node->num_resource = n_resources;
 
 	add_of_device(node);
 
 	return 0;
+
+err_free:
+	free(res);
+
+	return ret;
 }
 
 void of_free(struct device_node *node)
diff --git a/include/of.h b/include/of.h
index 852231e..9349e6a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -26,6 +26,7 @@ struct device_node {
 	struct list_head parent_list;
 	struct list_head list;
 	struct resource *resource;
+	int num_resource;
 	struct device_d *device;
 	struct list_head phandles;
 	phandle phandle;
-- 
1.8.2.rc2


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

  parent reply	other threads:[~2013-04-22  7:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-22  7:27 [PATCH] devicetree patches Sascha Hauer
2013-04-22  7:27 ` [PATCH 1/6] of: parse phandles before probing devices Sascha Hauer
2013-04-22  7:27 ` [PATCH 2/6] of: Add of_property_read_string_index() Sascha Hauer
2013-04-22  7:27 ` Sascha Hauer [this message]
2013-04-22  7:27 ` [PATCH 4/6] of: read resource names from devicetree Sascha Hauer
2013-04-22  7:27 ` [PATCH 5/6] of: partitions: pass struct cdev as argument Sascha Hauer
2013-04-22  7:27 ` [PATCH 6/6] of: partitions: create bb device for nand flashes Sascha Hauer

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=1366615643-22213-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox