[PATCH 2/6] of: make of_add_memory available for other board

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Feb 13 05:06:40 EST 2013


so when the first stage booloader of firmware provide the dtb
we can use it to probe the memory

also allow to print what we probe

Cc: Rob Herring <rob.herring at calxeda.com>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 drivers/of/base.c |   20 ++++++++++++++------
 include/of.h      |    6 ++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1f32bfb..f2986ab 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -734,18 +734,23 @@ u64 dt_mem_next_cell(int s, const __be32 **cellp)
 	return of_read_number(p, s);
 }
 
-static int of_add_memory(struct device_node *node)
+int of_add_memory(struct device_node *node, bool dump)
 {
 	int na, nc;
 	const __be32 *reg, *endp;
 	int len, r = 0;
 	static char str[6];
+	struct property *type;
+
+	type = of_find_property(node, "device_type");
+	if (!type)
+		return -ENXIO;
 
 	of_bus_count_cells(node, &na, &nc);
 
 	reg = of_get_property(node, "reg", &len);
 	if (!reg)
-		return 0;
+		return -EINVAL;
 
 	endp = reg + (len / sizeof(__be32));
 
@@ -762,6 +767,9 @@ static int of_add_memory(struct device_node *node)
 
                 barebox_add_memory_bank(str, base, size);
 
+		if (dump)
+			pr_info("%s: %s: 0x%llx at 0x%llx\n", node->name, str, size, base);
+
 		r++;
         }
 
@@ -770,7 +778,7 @@ static int of_add_memory(struct device_node *node)
 
 static int add_of_device_resource(struct device_node *node)
 {
-	struct property *reg, *type;
+	struct property *reg;
 	u64 address, size;
 	struct resource *res;
 	struct device_d *dev;
@@ -783,9 +791,9 @@ 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);
+	ret = of_add_memory(node, false);
+	if (ret != -ENXIO)
+		return ret;
 
 	reg = of_find_property(node, "reg");
 	if (!reg)
diff --git a/include/of.h b/include/of.h
index d413d72..4dc5b6c 100644
--- a/include/of.h
+++ b/include/of.h
@@ -132,6 +132,7 @@ int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(void);
+int of_add_memory(struct device_node *node, bool dump);
 #else
 static inline int of_parse_partitions(const char *cdevname,
 					  struct device_node *node)
@@ -163,6 +164,11 @@ static inline void *of_flatten_dtb(void)
 {
 	return NULL;
 }
+
+static inline int of_add_memory(struct device_node *node, bool dump)
+{
+	return -EINVAL;
+}
 #endif
 
 #endif /* __OF_H */
-- 
1.7.10.4




More information about the barebox mailing list