devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dt: platform driver: Fill the resources before probe and defer if needed
@ 2014-02-13  9:57 Jean-Jacques Hiblot
  2014-02-13 10:06 ` Jean-Jacques Hiblot
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Jean-Jacques Hiblot @ 2014-02-13  9:57 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	grant.likely-QSEj5FYQhm4dnm+yROfE0A,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	gregory.clement-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Jean-Jacques Hiblot

The goal of this patch is to allow drivers to be probed even if at the time of
the DT parsing some of their ressources are not available yet.

In the current situation, the resource of a platform device are filled from the
DT at the time the device is created (of_device_alloc()). The drawbackof this
is that a device sitting close to the top of the DT (ahb for example) but
depending on ressources that are initialized later (IRQ domain dynamically
created for example)  will fail to probe because the ressources don't exist
at this time.

This patch fills the resource structure only before the device is probed and
will defer the probe if the resource are not available yet.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot-dLKeG7h1OhBDOHtkgc7UlQ@public.gmane.org>
Reviewed-by: Gregory CLEMENT <gregory.clement-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
---
 drivers/base/platform.c     |  6 ++++
 drivers/of/platform.c       | 71 +++++++++++++++++++++++++++++----------------
 include/linux/of_platform.h | 10 +++++++
 3 files changed, 62 insertions(+), 25 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index bc78848..8e37d8b 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -481,6 +481,12 @@ static int platform_drv_probe(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 	int ret;
 
+	if (_dev->of_node) {
+		ret = of_platform_device_populate_resources(dev);
+		if (ret < 0)
+			return drv->prevent_deferred_probe ? ret : -EPROBE_DEFER;
+	}
+
 	if (ACPI_HANDLE(_dev))
 		acpi_dev_pm_attach(_dev, true);
 
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 404d1da..64a8eb8 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -141,36 +141,11 @@ struct platform_device *of_device_alloc(struct device_node *np,
 				  struct device *parent)
 {
 	struct platform_device *dev;
-	int rc, i, num_reg = 0, num_irq;
-	struct resource *res, temp_res;
 
 	dev = platform_device_alloc("", -1);
 	if (!dev)
 		return NULL;
 
-	/* count the io and irq resources */
-	if (of_can_translate_address(np))
-		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
-			num_reg++;
-	num_irq = of_irq_count(np);
-
-	/* Populate the resource table */
-	if (num_irq || num_reg) {
-		res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL);
-		if (!res) {
-			platform_device_put(dev);
-			return NULL;
-		}
-
-		dev->num_resources = num_reg + num_irq;
-		dev->resource = res;
-		for (i = 0; i < num_reg; i++, res++) {
-			rc = of_address_to_resource(np, i, res);
-			WARN_ON(rc);
-		}
-		WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
-	}
-
 	dev->dev.of_node = of_node_get(np);
 #if defined(CONFIG_MICROBLAZE)
 	dev->dev.dma_mask = &dev->archdata.dma_mask;
@@ -233,6 +208,52 @@ static struct platform_device *of_platform_device_create_pdata(
 	return dev;
 }
 
+int of_platform_device_populate_resources(struct platform_device *dev)
+{
+	struct device_node *np;
+	int rc = 0, i, nreg = 0, nirq;
+
+	np = dev->dev.of_node;
+
+	/* count the io and irq resources */
+	if (of_can_translate_address(np)) {
+		struct resource temp_res;
+		while (of_address_to_resource(np, nreg, &temp_res) == 0)
+			nreg++;
+	}
+	nirq = of_irq_count(np);
+
+	/* Populate the resource table */
+	if (nirq || nreg) {
+		struct resource *res;
+
+		res = krealloc(dev->resource, sizeof(*res) * (nirq + nreg),
+			       GFP_KERNEL);
+		if (!res) {
+			kfree(dev->resource);
+			dev->resource = NULL;
+			return -ENOMEM;
+		}
+		memset(res, 0, sizeof(*res) * (nirq + nreg));
+		dev->resource = res;
+		dev->num_resources = nreg + nirq;
+
+		for (i = 0; i < nreg; i++, res++) {
+			rc = of_address_to_resource(np, i, res);
+			WARN_ON(rc);
+			if (rc)
+				break;
+		}
+
+		if (!rc && of_irq_to_resource_table(np, res, nirq) != nirq) {
+			rc = -ENOENT;
+			WARN_ON(rc);
+		}
+	}
+	return rc;
+}
+EXPORT_SYMBOL(of_platform_device_populate_resources);
+
 /**
  * of_platform_device_create - Alloc, initialize and register an of_device
  * @np: pointer to node to create device for
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 05cb4a9..315e1e3 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -53,6 +53,16 @@ struct of_dev_auxdata {
 
 extern const struct of_device_id of_default_bus_match_table[];
 
+/* Populate the resource for a platform device */
+#ifdef CONFIG_OF
+int of_platform_device_populate_resources(struct platform_device *dev);
+#else
+static inline int of_platform_device_populate_resources(
+	struct platform_device *)
+{
+	return -ENOSYS;
+}
+#endif
 /* Platform drivers register/unregister */
 extern struct platform_device *of_device_alloc(struct device_node *np,
 					 const char *bus_id,
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2014-04-23 22:03 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-13  9:57 [PATCH] dt: platform driver: Fill the resources before probe and defer if needed Jean-Jacques Hiblot
2014-02-13 10:06 ` Jean-Jacques Hiblot
2014-02-18 20:22 ` Greg KH
2014-02-18 22:34   ` Grant Likely
2014-02-20 15:30 ` Grant Likely
2014-02-21 13:18   ` [PATCH v2] " Jean-Jacques Hiblot
     [not found]     ` <1392988720-20976-1-git-send-email-jjhiblot-dLKeG7h1OhBDOHtkgc7UlQ@public.gmane.org>
2014-02-21 15:37       ` Strashko, Grygorii
2014-02-21 16:22         ` Jean-Jacques Hiblot
2014-02-27 16:43           ` Jean-Jacques Hiblot
2014-03-08  7:32             ` Grant Likely
2014-02-27 15:01       ` Ludovic Desroches
2014-03-08  7:37       ` Grant Likely
     [not found]         ` <20140308073758.DA63FC408EC-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-03-08 11:59           ` Russell King - ARM Linux
2014-03-17 11:07         ` Jean-Jacques Hiblot
     [not found]   ` < 1392988720-20976-1-git-send-email-jjhiblot@traphandler.com>
     [not found]     ` < 902E09E6452B0E43903E4F2D568737AB0B9D2959@DFRE01.ent.ti.com>
     [not found]       ` < CACh+v5MPTx6nwVj1s3krntJqQ6DMTQ2hQ93Hc+rRNAuFa9+qPw@mail.gmail.com>
     [not found]     ` <20140308073758 .DA63FC408EC@trevor.secretlab.ca>
     [not found]       ` < CACh+v5P=tcc-h_9r7Btwyu+jWjwH2ocmW4VCgDYqY7VMWsHuOA@mail.gmail.com>
     [not found]         ` <CACh+v5P=tcc-h_9r7Btwyu+jWjwH2ocmW4VCgDYqY7VMWsHuOA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-17 14:24           ` Grant Likely
2014-03-17 15:20             ` Jean-Jacques Hiblot
     [not found]         ` < 20140317142443.A2447C40A85@trevor.secretlab.ca>
     [not found]           ` < CACh+v5M+0+C2JJwLqcp6erWa81kt=j1HucHiE52ufj1SO9F75w@mail.gmail.com>
     [not found]             ` <CACh+v5M+0+C2JJwLqcp6erWa81kt=j1HucHiE52ufj1SO9F75w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-20 16:11               ` Grant Likely
     [not found]                 ` <20140320161118.B7075C4067A-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-03-21 14:46                   ` [PATCH v3 0/2] " Jean-Jacques Hiblot
     [not found]                     ` <1395413185-29763-1-git-send-email-jjhiblot-dLKeG7h1OhBDOHtkgc7UlQ@public.gmane.org>
2014-03-21 14:46                       ` [PATCH v3 1/2] of: irq: Added of_find_irq_domain() to get the domain of an irq Jean-Jacques Hiblot
2014-03-21 14:46                     ` [PATCH v3 2/2] dt: platform driver: Fill the resources before probe and defer if needed Jean-Jacques Hiblot
2014-04-11 17:28                       ` Rob Herring
     [not found]                         ` <CAL_Jsq+aU+rs28gV=Gesb_-Dy6Ht7zuKrRA6_hmqp94Uun23Yg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-18 20:52                           ` Tony Lindgren
     [not found]                             ` <20140418205213.GA21823-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-04-18 21:39                               ` Rob Herring
     [not found]                                 ` <CAL_JsqJvVvo6R-qNXxur7wiZERKbi52xyKoWnmzJTfKS2iKK7A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-18 21:58                                   ` Tony Lindgren
     [not found]                                     ` <20140418215848.GD21823-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-04-18 23:03                                       ` Russell King - ARM Linux
     [not found]                                         ` <20140418230335.GI24070-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2014-04-18 23:24                                           ` Tony Lindgren
2014-04-21 13:47                                             ` Rob Herring
     [not found]                                               ` <CAL_JsqLvLTJwgsB-m0W72WxSUoTV4ubMdvM_a784J4k2eiK9AQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-21 15:54                                                 ` Tony Lindgren
     [not found]                                                   ` <20140421155424.GD23945-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-04-21 19:01                                                     ` Rob Herring
     [not found]                                                       ` <53556AF1.2030608-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-04-21 20:25                                                         ` Tony Lindgren
     [not found]                                                           ` <20140421202546.GA26554-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-04-22  3:05                                                             ` Tony Lindgren
2014-04-22  4:57                                                               ` Tony Lindgren
     [not found]                                                                 ` <20140422045730.GC26554-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-04-23 22:03                                                                   ` Rob Herring
2014-04-23 17:38                                                         ` Russell King - ARM Linux
2014-04-23 15:02                                               ` Grant Likely

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