From cc73614014b96f807552507d652ae7d91459f179 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <marc.zyngier@arm.com>
Date: Tue, 21 Jun 2011 11:40:51 +0100
Subject: [PATCH] dt: early platform devices support
Add support for populating early platform devices from the device
tree, by walking the tree and adding nodes whose 'compatible'
property matches the 'class' string passed as a parameter.
This allows devices to be probed long before the whole device
infrastructure is available.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
drivers/of/platform.c | 31 +++++++++++++++++++++++++++++++
include/linux/of_platform.h | 2 ++
2 files changed, 33 insertions(+), 0 deletions(-)
@@ -326,4 +326,35 @@ int of_platform_populate(struct device_node *root,
of_node_put(root);
return rc;
}
+
+/**
+ * of_early_platform_populate() - Populate early platform devices from DT
+ * @class: string to compare to the 'compatible' attributes
+ *
+ * This function walks the device tree and register devices whose
+ * 'compatible' property matches the 'class' parameter.
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int of_early_platform_populate(const char *class)
+{
+ struct platform_device *pdev;
+ struct device_node *np = NULL;
+ int id = 0, rc = 0;
+
+ while ((np = of_find_compatible_node(np, NULL, class))) {
+ pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
+ if (!pdev) {
+ of_node_put(np);
+ rc = -ENOMEM;
+ break;
+ }
+ pdev->name = np->name;
+ pdev->id = id++;
+ pdev->dev.of_node = of_node_get(np);
+ early_platform_add_devices(&pdev, 1);
+ }
+
+ return rc;
+}
#endif /* !CONFIG_SPARC */
@@ -58,6 +58,8 @@ extern int of_platform_bus_probe(struct device_node *root,
extern int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
struct device *parent);
+
+extern int of_early_platform_populate(const char *class);
#endif /* !CONFIG_SPARC */
#endif /* CONFIG_OF_DEVICE */
--
1.7.0.4