From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marc Zyngier Subject: [RFC PATCH 1/4] dt: early platform devices support Date: Fri, 24 Jun 2011 15:10:56 +0100 Message-ID: <1308924659-31894-2-git-send-email-marc.zyngier@arm.com> References: <1308924659-31894-1-git-send-email-marc.zyngier@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1308924659-31894-1-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org List-Id: devicetree@vger.kernel.org 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 --- drivers/of/platform.c | 26 ++++++++++++++++++++++++++ include/linux/of_platform.h | 1 + 2 files changed, 27 insertions(+), 0 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index e75af39..2a323ee 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -458,4 +458,30 @@ 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; + + while ((np = of_find_compatible_node(np, NULL, class))) { + pdev = of_device_alloc(np, NULL, NULL); + if (!pdev) + return -ENOMEM; + list_del(&pdev->dev.devres_head); + memset(&pdev->dev.devres_head, 0, sizeof(pdev->dev.devres_head)); + early_platform_add_devices(&pdev, 1); + } + + return 0; +} #endif /* !CONFIG_SPARC */ diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 5a6f458..dd1dc90 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -95,6 +95,7 @@ extern int of_platform_populate(struct device_node *root, const struct of_device_id *matches, const struct of_dev_auxdata *lookup, struct device *parent); +extern int of_early_platform_populate(const char *class); #endif /* !CONFIG_SPARC */ #endif /* CONFIG_OF_DEVICE */ -- 1.7.0.4