mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 2/4] of: support of_ensure_probed for top-level machine device
Date: Fri, 10 Feb 2023 17:53:51 +0100	[thread overview]
Message-ID: <20230210165353.3601175-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230210165353.3601175-1-a.fatoum@pengutronix.de>

Creation of a machine device for the top-level node has special casing
in of_probe(). Export of_platform_device_create_root(), so it's possible
to ensure probe of the machine device. This is required when doing
of_devices_ensure_probed_by_dev_id with the machine compatible.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - new patch to facilitate patch 3/4
---
 drivers/of/base.c     | 10 +++++++---
 drivers/of/platform.c |  2 +-
 include/of.h          |  1 +
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1221cd316cdf..7ba0655401cc 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2512,13 +2512,13 @@ static int of_probe_memory(void)
 }
 mem_initcall(of_probe_memory);
 
-static void of_platform_device_create_root(struct device_node *np)
+struct device *of_platform_device_create_root(struct device_node *np)
 {
 	static struct device *dev;
 	int ret;
 
 	if (dev)
-		return;
+		return dev;
 
 	dev = xzalloc(sizeof(*dev));
 	dev->id = DEVICE_ID_SINGLE;
@@ -2526,8 +2526,12 @@ static void of_platform_device_create_root(struct device_node *np)
 	dev_set_name(dev, "machine");
 
 	ret = platform_device_register(dev);
-	if (ret)
+	if (ret) {
 		free_device(dev);
+		return ERR_PTR(ret);
+	}
+
+	return dev;
 }
 
 static const struct of_device_id reserved_mem_matches[] = {
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 69f9ddec50ca..11cde8924f94 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -421,7 +421,7 @@ static struct device *of_device_create_on_demand(struct device_node *np)
 
 	parent = of_get_parent(np);
 	if (!parent)
-		return NULL;
+		return of_platform_device_create_root(np);
 
 	if (!np->dev && parent->dev) {
 		ret = device_detect(parent->dev);
diff --git a/include/of.h b/include/of.h
index 1a38774615a4..63c90255cd64 100644
--- a/include/of.h
+++ b/include/of.h
@@ -298,6 +298,7 @@ extern void of_platform_device_dummy_drv(struct device *dev);
 extern int of_platform_populate(struct device_node *root,
 				const struct of_device_id *matches,
 				struct device *parent);
+extern struct device *of_platform_device_create_root(struct device_node *np);
 extern struct device *of_find_device_by_node(struct device_node *np);
 extern struct device *of_device_enable_and_register(struct device_node *np);
 extern struct device *of_device_enable_and_register_by_name(const char *name);
-- 
2.30.2




  reply	other threads:[~2023-02-10 16:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10 16:53 [PATCH v2 1/4] of: base: factor out of_merge_nodes from of_copy_node Ahmad Fatoum
2023-02-10 16:53 ` Ahmad Fatoum [this message]
2023-03-10 14:46   ` [PATCH v2 2/4] of: support of_ensure_probed for top-level machine device Michael Riesch
2023-03-10 16:19     ` Ahmad Fatoum
2023-03-13  7:05       ` Michael Riesch
2023-03-13 14:43         ` Ahmad Fatoum
2023-02-10 16:53 ` [PATCH v2 3/4] boards: qemu-virt: ensure board driver probe at postcore_initcall level Ahmad Fatoum
2023-02-10 16:53 ` [PATCH v2 4/4] boards: qemu-virt: support passing in FIT public key Ahmad Fatoum
2023-02-10 17:32   ` Jan Lübbe
2023-02-13  8:45   ` Sascha Hauer
2023-02-17 13:03     ` Ahmad Fatoum
2023-03-09 12:47       ` Ahmad Fatoum
2023-03-10  9:51 ` [PATCH v2 1/4] of: base: factor out of_merge_nodes from of_copy_node Sascha Hauer

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=20230210165353.3601175-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@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