linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: robherring2@gmail.com (Rob Herring)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH] drivers/amba: probe via device tree reworked
Date: Wed, 18 May 2011 13:14:47 -0500	[thread overview]
Message-ID: <1305742487-28325-1-git-send-email-robherring2@gmail.com> (raw)

From: Rob Herring <rob.herring@calxeda.com>

This reworks the original amba bus device tree probing to be more inline with
how platform bus probing via device tree is done using a match table.

The amba bus code doesn't support creation of parent devices, so a flat tree
is created even if the device tree contains a heirarchy of devices.

Cc: Jeremy Kerr <jeremy.kerr@canonical.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 drivers/amba/bus.c       |   84 +++++++++++++++++++++++++++++++++++++++++-----
 include/linux/amba/bus.h |    4 ++-
 2 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index ed5c49d..4e46b54 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -7,6 +7,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#define DEBUG
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/device.h>
@@ -797,7 +798,7 @@ EXPORT_SYMBOL(amba_request_regions);
 EXPORT_SYMBOL(amba_release_regions);
 
 #ifdef CONFIG_OF
-static int of_amba_device_create(struct device_node *node,struct device *parent)
+static struct amba_device *of_amba_device_create(struct device_node *node,struct device *parent)
 {
 	struct amba_device *dev;
 	const void *prop;
@@ -805,7 +806,7 @@ static int of_amba_device_create(struct device_node *node,struct device *parent)
 
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
 	if (!dev)
-		return -ENOMEM;
+		return NULL;
 
 	/* setup generic device info */
 	dev->dev.coherent_dma_mask = ~0;
@@ -839,22 +840,87 @@ static int of_amba_device_create(struct device_node *node,struct device *parent)
 				    "probed value (0x%08x) don't agree.",
 				    of_read_ulong(prop, 1), dev->periphid);
 
-	return 0;
+	return dev;
 
 err_free:
 	kfree(dev);
-	return ret;
+	return NULL;
+}
+
+/**
+ * of_amba_bus_create() - Create a device for a node and its children.
+ * @bus: device node of the bus to instantiate
+ * @matches: match table for bus nodes
+ * disallow recursive creation of child buses
+ * @parent: parent for new device, or NULL for top level.
+ *
+ * Recursively create devices for all the child nodes.
+ */
+static int of_amba_bus_create(struct device_node *bus,
+				  const struct of_device_id *matches,
+				  struct device *parent, bool strict)
+{
+	struct device_node *child;
+	struct amba_device *dev = NULL;
+	int rc = 0;
+
+	/* Make sure it has a compatible property */
+	if (strict && (!of_get_property(bus, "compatible", NULL))) {
+		pr_debug("%s() - skipping %s, no compatible prop\n",
+			 __func__, bus->full_name);
+		return 0;
+	}
+
+	if (of_device_is_compatible(bus, "arm,amba-device"))
+		dev = of_amba_device_create(bus, parent);
+	else if (!of_match_node(matches, bus))
+		return 0;
+
+	for_each_child_of_node(bus, child) {
+		pr_debug("   create child: %s\n", child->full_name);
+		rc = of_amba_bus_create(child, matches, parent, strict);
+		if (rc) {
+			of_node_put(child);
+			break;
+		}
+	}
+	return rc;
 }
 
-void of_amba_bus_populate(struct device_node *node, struct device *parent)
+/**
+ * of_amba_bus_probe() - Probe the device-tree for amba buses
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: match table for bus nodes
+ * @parent: parent to hook devices from, NULL for toplevel
+ *
+ * Note that children of the provided root are not instantiated as devices
+ * unless the specified root itself matches the bus list and is not NULL.
+ */
+int of_amba_bus_probe(struct device_node *root,
+		       const struct of_device_id *matches,
+		       struct device *parent)
 {
+	int rc = 0;
 	struct device_node *child;
 
-	for_each_child_of_node(node, child) {
-		if (of_device_is_compatible(child, "arm,amba-device"))
-			of_amba_device_create(child, parent);
+	root = root ? of_node_get(root) : of_find_node_by_path("/");
+	if (!root)
+		return -EINVAL;
+
+	/* Do a self check of bus type, if there's a match, create children */
+	if (of_match_node(matches, root)) {
+		rc = of_amba_bus_create(root, matches, parent, false);
+	} else for_each_child_of_node(root, child) {
+		if (!of_match_node(matches, child))
+			continue;
+		rc = of_amba_bus_create(child, matches, parent, false);
+		if (rc)
+			break;
 	}
+
+	of_node_put(root);
+	return rc;
 }
-EXPORT_SYMBOL(of_amba_bus_populate);
+EXPORT_SYMBOL(of_amba_bus_probe);
 
 #endif /* CONFIG_OF */
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index cb17dfd..6df9535 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -96,7 +96,9 @@ void amba_release_regions(struct amba_device *);
 
 #ifdef CONFIG_OF
 struct device_node;
-void of_amba_bus_populate(struct device_node *node, struct device *parent);
+int of_amba_bus_probe(struct device_node *root,
+		      const struct of_device_id *matches,
+		      struct device *parent);
 #endif
 
 #endif
-- 
1.7.4.1

             reply	other threads:[~2011-05-18 18:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-18 18:14 Rob Herring [this message]
2011-05-18 18:47 ` [RFC PATCH] drivers/amba: probe via device tree reworked Grant Likely
2011-05-18 19:39   ` Rob Herring
2011-05-18 20:22     ` Grant Likely

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=1305742487-28325-1-git-send-email-robherring2@gmail.com \
    --to=robherring2@gmail.com \
    --cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).