diff mbox

[RFC,00/16] Consolidation: move SMP local timers to driver/clocksource

Message ID 4E00A0BC.1090203@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marc Zyngier June 21, 2011, 1:46 p.m. UTC
On 21/06/11 14:18, Rob Herring wrote:
> On 06/21/2011 08:02 AM, Marc Zyngier wrote:
>> On 21/06/11 13:51, Rob Herring wrote:
>>> Marc,
>>>
>>> On 06/21/2011 06:13 AM, Marc Zyngier wrote:
>>>> On 17/06/11 18:25, Rob Herring wrote:
>>>>> Also, device tree support for early platform devices would be useful for
>>>>> this.
>>>>
>>>> What about the attached patch? I've used it to boot a VExpress board
>>>> with the following DT snippet (and the corresponding support in the
>>>> amp_smp_twd driver):
>>>>
>>>> 	localtimer@2c000600 {
>>>> 		device_type = "localtimer";
>>>
>>> My understanding is device_type is only supposed to be used for devices
>>> with real OpenFirmware. You could just add localtimer or timer as a 2nd
>>> compatible string. I think localtimer is a bit of a Linux name, so just
>>> timer may be better.
>>
>> Using "compatible" would not work. You'd have to add the same compatible
>> string to all drivers, and get drivers probing the wrong device. Any
>> other property we could use instead?
> 
> No, I'm saying you have a compatible property like this:
> 
> compatible = "arm,smp-twd", "timer";
> 
> You create the early platform device(s) based on matches with "timer",
> but match the driver based on "arm,smp-twd".

Right. What about the attached patch? Test-booted on the same VE with
the above "compatible" property.

	M.
diff mbox

Patch

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(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 9b785be..1ba304e 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -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 */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 43c723d..fee17f7 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -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