From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 04/11] dt: add of_platform_populate() for creating device from the device tree
Date: Wed, 15 Jun 2011 22:41:55 -0600 [thread overview]
Message-ID: <20110616044150.29371.19347.stgit@ponder> (raw)
In-Reply-To: <20110616042653.29371.2052.stgit@ponder>
of_platform_populate() is similar to of_platform_bus_probe() except
that it strictly enforces that all device nodes must have a compatible
property, and it can be used to register devices (not buses) which are
children of the root node.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
drivers/of/platform.c | 54 +++++++++++++++++++++++++++++++++++++++---
include/linux/of_platform.h | 3 ++
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 63d3cb7..9b785be 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -221,19 +221,26 @@ EXPORT_SYMBOL(of_platform_device_create);
*/
static int of_platform_bus_create(struct device_node *bus,
const struct of_device_id *matches,
- struct device *parent)
+ struct device *parent, bool strict)
{
struct device_node *child;
struct platform_device *dev;
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;
+ }
+
dev = of_platform_device_create(bus, NULL, parent);
if (!dev || !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_platform_bus_create(child, matches, &dev->dev);
+ rc = of_platform_bus_create(child, matches, &dev->dev, strict);
if (rc) {
of_node_put(child);
break;
@@ -267,11 +274,11 @@ int of_platform_bus_probe(struct device_node *root,
/* Do a self check of bus type, if there's a match, create children */
if (of_match_node(matches, root)) {
- rc = of_platform_bus_create(root, matches, parent);
+ rc = of_platform_bus_create(root, matches, parent, false);
} else for_each_child_of_node(root, child) {
if (!of_match_node(matches, child))
continue;
- rc = of_platform_bus_create(child, matches, parent);
+ rc = of_platform_bus_create(child, matches, parent, false);
if (rc)
break;
}
@@ -280,4 +287,43 @@ int of_platform_bus_probe(struct device_node *root,
return rc;
}
EXPORT_SYMBOL(of_platform_bus_probe);
+
+/**
+ * of_platform_populate() - Populate platform_devices from device tree data
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: match table, NULL to use the default
+ * @parent: parent to hook devices from, NULL for toplevel
+ *
+ * Similar to of_platform_bus_probe(), this function walks the device tree
+ * and creates devices from nodes. It differs in that it follows the modern
+ * convention of requiring all device nodes to have a 'compatible' property,
+ * and it is suitable for creating devices which are children of the root
+ * node (of_platform_bus_probe will only create children of the root which
+ * are selected by the @matches argument).
+ *
+ * New board support should be using this function instead of
+ * of_platform_bus_probe().
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int of_platform_populate(struct device_node *root,
+ const struct of_device_id *matches,
+ struct device *parent)
+{
+ struct device_node *child;
+ int rc = 0;
+
+ root = root ? of_node_get(root) : of_find_node_by_path("/");
+ if (!root)
+ return -EINVAL;
+
+ for_each_child_of_node(root, child) {
+ rc = of_platform_bus_create(child, matches, parent, true);
+ if (rc)
+ break;
+ }
+
+ of_node_put(root);
+ return rc;
+}
#endif /* !CONFIG_SPARC */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index fb51ae3..43c723d 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -55,6 +55,9 @@ extern struct platform_device *of_platform_device_create(struct device_node *np,
extern int of_platform_bus_probe(struct device_node *root,
const struct of_device_id *matches,
struct device *parent);
+extern int of_platform_populate(struct device_node *root,
+ const struct of_device_id *matches,
+ struct device *parent);
#endif /* !CONFIG_SPARC */
#endif /* CONFIG_OF_DEVICE */
next prev parent reply other threads:[~2011-06-16 4:41 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-16 4:40 [RFC PATCH 00/11] Full device tree support for ARM Versatile Grant Likely
2011-06-16 4:41 ` [RFC PATCH 01/11] irq: add irq_domain translation infrastructure Grant Likely
2011-06-20 9:54 ` Marc Zyngier
2011-06-16 4:41 ` [RFC PATCH 02/11] of/address: Add of_find_matching_node_by_address helper Grant Likely
2011-06-16 4:41 ` [RFC PATCH 03/11] dt/irq: add irq_domain_add_simple() helper Grant Likely
2011-06-16 14:04 ` Rob Herring
2011-06-16 14:21 ` Rob Herring
2011-06-16 16:57 ` Grant Likely
2011-06-16 16:56 ` Grant Likely
2011-06-16 4:41 ` Grant Likely [this message]
2011-06-16 4:42 ` [RFC PATCH 05/11] dt: Add default match table for bus ids Grant Likely
2011-06-16 4:42 ` [RFC PATCH 06/11] drivers/amba: create devices from device tree Grant Likely
2011-06-16 4:42 ` [RFC PATCH 07/11] dt/platform: allow device name to be overridden Grant Likely
2011-06-16 4:42 ` [RFC PATCH 08/11] powerpc/5200: convert mpc5200 to use of_platform_populate() Grant Likely
2011-06-16 4:42 ` [RFC PATCH 09/11] arm/dt: Add dt machine definition Grant Likely
2011-07-08 14:30 ` Rob Herring
2011-06-16 4:43 ` [RFC PATCH 10/11] arm/dt: Add skeleton dtsi file Grant Likely
2011-06-16 4:43 ` [RFC PATCH 11/11] arm/versatile: Add device tree support Grant Likely
2011-06-16 14:19 ` Rob Herring
2011-06-16 15:42 ` Grant Likely
2011-06-16 14:20 ` Arnd Bergmann
2011-06-16 14:56 ` Grant Likely
2011-06-17 1:11 ` Shawn Guo
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=20110616044150.29371.19347.stgit@ponder \
--to=grant.likely@secretlab.ca \
--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).