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 2/5] of: find and register memory during probe
Date: Mon,  8 Oct 2012 21:46:21 +0200	[thread overview]
Message-ID: <1349725584-20509-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1349725584-20509-1-git-send-email-s.hauer@pengutronix.de>

This automatically registers the memory nodes in the devicetree.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index fd152d6..09785fb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -23,6 +23,7 @@
 #include <libfdt.h>
 #include <malloc.h>
 #include <init.h>
+#include <memory.h>
 #include <linux/ctype.h>
 
 /**
@@ -612,9 +613,51 @@ static struct device_d *add_of_device(struct device_node *node)
 }
 EXPORT_SYMBOL(add_of_device);
 
+u64 dt_mem_next_cell(int s, const __be32 **cellp)
+{
+	const __be32 *p = *cellp;
+
+	*cellp = p + s;
+	return of_read_number(p, s);
+}
+
+static int of_add_memory(struct device_node *node)
+{
+	int na, nc;
+	const __be32 *reg, *endp;
+	int len, r = 0;
+	static char str[6];
+
+	of_bus_count_cells(node, &na, &nc);
+
+	reg = of_get_property(node, "reg", &len);
+	if (!reg)
+		return 0;
+
+	endp = reg + (len / sizeof(__be32));
+
+	while ((endp - reg) >= (na + nc)) {
+		u64 base, size;
+
+		base = dt_mem_next_cell(na, &reg);
+		size = dt_mem_next_cell(nc, &reg);
+
+		if (size == 0)
+			continue;
+
+		sprintf(str, "ram%d", r);
+
+                barebox_add_memory_bank(str, base, size);
+
+		r++;
+        }
+
+	return 0;
+}
+
 static int add_of_device_resource(struct device_node *node)
 {
-	struct property *reg;
+	struct property *reg, *type;
 	u64 address, size;
 	struct resource *res;
 	struct device_d *dev;
@@ -627,6 +670,10 @@ static int add_of_device_resource(struct device_node *node)
 		list_add_tail(&node->phandles, &phandle_list);
 	}
 
+	type = of_find_property(node, "device_type");
+	if (type)
+		return of_add_memory(node);
+
 	reg = of_find_property(node, "reg");
 	if (!reg)
 		return -ENODEV;
-- 
1.7.10.4


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

  parent reply	other threads:[~2012-10-08 19:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08 19:46 [PATCH] of patches Sascha Hauer
2012-10-08 19:46 ` [PATCH 1/5] memory: return error in barebox_add_memory_bank Sascha Hauer
2012-10-08 19:46 ` Sascha Hauer [this message]
2012-10-08 19:46 ` [PATCH 3/5] console/of: evaluate linux,stdout-path property Sascha Hauer
2012-10-08 19:46 ` [PATCH 4/5] of: Add function to get the model name Sascha Hauer
2012-10-08 19:46 ` [PATCH 5/5] of: Print model name in banner 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=1349725584-20509-3-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