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 1/3] of: platform: call struct device::detect in of_device_create_on_demand
Date: Mon, 16 Jan 2023 14:36:37 +0100	[thread overview]
Message-ID: <20230116133639.1999170-1-a.fatoum@pengutronix.de> (raw)

Most devices featuring a detect callback use it to probe an underlying
bus. However, of_device_create_on_demand so far created devices on the
platform bus, ignoring that it might be e.g. an I2C device that's
supposed to be crated by the parent controller.

Fix this by calling the parent's detect callback if available. Busses
that probe via device tree, but register their devices on a different
bus will need to register a detect callback to benefit from this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/platform.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ff7096b6eedd..edb082b106ff 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -414,11 +414,18 @@ static struct device *of_device_create_on_demand(struct device_node *np)
 {
 	struct device_node *parent;
 	struct device *parent_dev, *dev;
+	int ret;
 
 	parent = of_get_parent(np);
 	if (!parent)
 		return NULL;
 
+	if (!np->dev && parent->dev) {
+		ret = device_detect(parent->dev);
+		if (ret && ret != -ENOSYS)
+			return ERR_PTR(ret);
+	}
+
 	if (!np->dev)
 		pr_debug("Creating device for %s\n", np->full_name);
 
-- 
2.30.2




             reply	other threads:[~2023-01-16 13:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 13:36 Ahmad Fatoum [this message]
2023-01-16 13:36 ` [PATCH 2/3] i2c: write debug print when registering any i2c client Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 3/3] i2c: implement detect callback Ahmad Fatoum
2023-01-20  7:36 ` [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand 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=20230116133639.1999170-1-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