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 8/8] of: populate devices based on "simple-bus" property
Date: Mon, 20 May 2013 16:14:20 +0200	[thread overview]
Message-ID: <1369059260-28872-9-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1369059260-28872-1-git-send-email-s.hauer@pengutronix.de>

We used to populate the devices from the devicetree based on the
presence of the 'reg' property. This is incorrect since this only
allows us to probe devices with resources.
Instead use the 'simple-bus' property to see if we have iterate
deeper. This also registers devices with their buses as parents.

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

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85d9dc0..3b9cc65 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -825,13 +825,16 @@ static struct device_d *add_of_amba_device(struct device_node *node)
 	return &dev->dev;
 }
 
-static struct device_d *add_of_platform_device(struct device_node *node)
+static struct device_d *add_of_platform_device(struct device_node *node,
+		struct device_d *parent)
 {
 	struct device_d *dev;
 	char *name, *at;
 
 	dev = xzalloc(sizeof(*dev));
 
+	dev->parent = parent;
+
 	name = xstrdup(node->name);
 	at = strchr(name, '@');
 	if (at) {
@@ -856,7 +859,8 @@ static struct device_d *add_of_platform_device(struct device_node *node)
 	return dev;
 }
 
-static struct device_d *add_of_device(struct device_node *node)
+static struct device_d *add_of_device(struct device_node *node,
+		struct device_d *parent)
 {
 	const struct property *cp;
 
@@ -871,7 +875,7 @@ static struct device_d *add_of_device(struct device_node *node)
 	    of_device_is_compatible(node, "arm,primecell") == 1)
 		return add_of_amba_device(node);
 	else
-		return add_of_platform_device(node);
+		return add_of_platform_device(node, parent);
 }
 EXPORT_SYMBOL(add_of_device);
 
@@ -928,7 +932,8 @@ int of_add_memory(struct device_node *node, bool dump)
 	return 0;
 }
 
-static int add_of_device_resource(struct device_node *node)
+static struct device_d *add_of_device_resource(struct device_node *node,
+		struct device_d *parent)
 {
 	u64 address = 0, size;
 	struct resource *res, *resp;
@@ -940,7 +945,7 @@ static int add_of_device_resource(struct device_node *node)
 
 	reg = of_get_property(node, "reg", &len);
 	if (!reg)
-		return -EINVAL;
+		return add_of_device(node, parent);
 
 	of_bus_count_cells(node, &na, &nc);
 
@@ -995,14 +1000,12 @@ static int add_of_device_resource(struct device_node *node)
 	node->resource = res;
 	node->num_resource = n_resources;
 
-	add_of_device(node);
-
-	return 0;
+	return add_of_device(node, parent);
 
 err_free:
 	free(res);
 
-	return ret;
+	return NULL;
 }
 
 void of_free(struct device_node *node)
@@ -1042,17 +1045,23 @@ void of_free(struct device_node *node)
 		of_set_root_node(NULL);
 }
 
-static void __of_probe(struct device_node *node)
+static void __of_probe(struct device_node *node,
+		const struct of_device_id *matches,
+		struct device_d *parent)
 {
 	struct device_node *n;
+	struct device_d *dev;
 
 	if (node->device)
 		return;
 
-	add_of_device_resource(node);
+	dev = add_of_device_resource(node, parent);
+
+	if (!of_match_node(matches, node))
+		return;
 
 	list_for_each_entry(n, &node->children, parent_list)
-		__of_probe(n);
+		__of_probe(n, matches, dev);
 }
 
 static void __of_parse_phandles(struct device_node *node)
@@ -1079,9 +1088,17 @@ const char *of_get_model(void)
 	return of_model;
 }
 
+const struct of_device_id of_default_bus_match_table[] = {
+	{
+		.compatible = "simple-bus",
+	}, {
+		/* sentinel */
+	}
+};
+
 int of_probe(void)
 {
-	struct device_node *memory;
+	struct device_node *memory, *n;
 
 	if(!root_node)
 		return -ENODEV;
@@ -1090,12 +1107,14 @@ int of_probe(void)
 	of_property_read_string(root_node, "model", &of_model);
 
 	__of_parse_phandles(root_node);
-	__of_probe(root_node);
 
 	memory = of_find_node_by_path(root_node, "/memory");
 	if (memory)
 		of_add_memory(memory, false);
 
+	list_for_each_entry(n, &root_node->children, parent_list)
+		__of_probe(n, of_default_bus_match_table, NULL);
+
 	return 0;
 }
 
-- 
1.8.2.rc2


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

      parent reply	other threads:[~2013-05-20 14:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
2013-05-20 14:14 ` [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target Sascha Hauer
2013-05-20 14:14 ` [PATCH 2/8] ARM: build dtbs during build process using extra-y Sascha Hauer
2013-05-20 14:14 ` [PATCH 3/8] scripts: fixdep: update from v3.10-rc1 Sascha Hauer
2013-05-20 14:14 ` [PATCH 4/8] kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp Sascha Hauer
2013-05-20 14:14 ` [PATCH 5/8] of: When checking for existing devices also check resource end Sascha Hauer
2013-05-20 14:14 ` [PATCH 6/8] of: Call of_add_memory from of_probe Sascha Hauer
2013-05-20 14:14 ` [PATCH 7/8] of: Add of_match_node function Sascha Hauer
2013-05-20 14:14 ` Sascha Hauer [this message]

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=1369059260-28872-9-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