linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saravana Kannan <saravanak@google.com>
To: Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com>
Cc: Saravana Kannan <saravanak@google.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	kernel-team@android.com, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: [PATCH v2 1/2] of: platform: Make sure bus only devices get probed
Date: Thu,  2 Sep 2021 16:04:40 -0700	[thread overview]
Message-ID: <20210902230442.1515531-2-saravanak@google.com> (raw)
In-Reply-To: <20210902230442.1515531-1-saravanak@google.com>

fw_devlink could end up creating device links for bus only devices.
However, bus only devices don't get probed and can block probe() or
sync_state() [1] call backs of other devices. To avoid this, set up
these devices to get probed by the simple-pm-bus.

[1] - https://lore.kernel.org/lkml/CAPDyKFo9Bxremkb1dDrr4OcXSpE0keVze94Cm=zrkOVxHHxBmQ@mail.gmail.com/
Signed-off-by: Saravana Kannan <saravanak@google.com>
Tested-by: Saravana Kannan <saravanak@google.com>
---
 drivers/of/platform.c | 45 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 74afbb7a4f5e..b010e2310131 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -97,6 +97,48 @@ static void of_device_make_bus_id(struct device *dev)
 	}
 }
 
+/**
+ * of_match_only_simple_bus - Check if a device node is only a simple bus
+ * @np: device node to check
+ *
+ * A simple bus in this context is defined as a transparent bus whose child
+ * devices are automatically populated but has no hardware specific
+ * functionality.
+ *
+ * Returns true if the device node is only a simple bus and can never match
+ * with any other specific driver.  Otherwise, returns false.
+ */
+static bool of_match_only_simple_bus(struct device_node *np)
+{
+	/* List of buses that don't have an explicit driver. */
+	static const char * const of_simple_bus_table[] = {
+		"simple-bus",
+		"simple-mfd",
+		"isa",
+		"arm,amba-bus",
+	};
+	const char *cp;
+	struct property *prop;
+	int i;
+
+	prop = of_find_property(np, "compatible", NULL);
+	for (cp = of_prop_next_string(prop, NULL); cp;
+	     cp = of_prop_next_string(prop, cp)) {
+		bool match = false;
+		const char *bus = of_simple_bus_table[i];
+
+		for (i = 0; i < ARRAY_SIZE(of_simple_bus_table); i++)
+			if (!of_compat_cmp(cp, bus, strlen(bus))) {
+				match = true;
+				break;
+			}
+		if (!match)
+			return false;
+	}
+
+	return true;
+}
+
 /**
  * of_device_alloc - Allocate and initialize an of_device
  * @np: device node to assign to device
@@ -143,6 +185,9 @@ struct platform_device *of_device_alloc(struct device_node *np,
 	dev->dev.fwnode = &np->fwnode;
 	dev->dev.parent = parent ? : &platform_bus;
 
+	if (of_match_only_simple_bus(np))
+		dev->driver_override = "simple-pm-bus";
+
 	if (bus_id)
 		dev_set_name(&dev->dev, "%s", bus_id);
 	else
-- 
2.33.0.153.gba50c8fa24-goog


  reply	other threads:[~2021-09-02 23:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 23:04 [PATCH v2 0/2] Fix simple-bus issues with fw_devlink Saravana Kannan
2021-09-02 23:04 ` Saravana Kannan [this message]
2021-09-03  9:18   ` [PATCH v2 1/2] of: platform: Make sure bus only devices get probed Ulf Hansson
2021-09-03 14:29     ` Geert Uytterhoeven
2021-09-03 17:09       ` Saravana Kannan
2021-09-03 19:06         ` Geert Uytterhoeven
2021-09-03 19:08           ` Saravana Kannan
2021-09-07 10:35       ` Ulf Hansson
2021-09-07 10:52         ` Geert Uytterhoeven
2021-09-07 11:02           ` Ulf Hansson
2021-09-02 23:04 ` [PATCH v2 2/2] drivers: bus: simple-pm-bus: Add support for probing simple bus only devices Saravana Kannan
2021-09-03  9:14   ` Ulf Hansson
2021-09-03 17:10     ` Saravana Kannan

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=20210902230442.1515531-2-saravanak@google.com \
    --to=saravanak@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=ulf.hansson@linaro.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;
as well as URLs for NNTP newsgroup(s).