[PATCH v5 01/11] of/platform: Allow overlays to create platform devices from the root node

0 views
Skip to first unread message

Stephen Boyd

unread,
Jun 3, 2024, 6:38:15 PMJun 3
to Michael Turquette, Stephen Boyd, linux-...@vger.kernel.org, linu...@vger.kernel.org, pat...@lists.linux.dev, kuni...@googlegroups.com, linux-k...@vger.kernel.org, devic...@vger.kernel.org, Brendan Higgins, David Gow, Rae Moar, Greg Kroah-Hartman, Rafael J . Wysocki, Rob Herring, Saravana Kannan, Daniel Latypov, Christian Marangi, Krzysztof Kozlowski, Conor Dooley, Maxime Ripard
We'd like to apply overlays to the root node in KUnit so we can test
platform devices created as children of the root node.

On some architectures (powerpc), the root node isn't marked with
OF_POPULATED_BUS. If an overlay tries to modify the root node on these
platforms it will fail, while on other platforms, such as ARM, it will
succeed. This is because the root node is marked with OF_POPULATED_BUS
by of_platform_default_populate_init() calling
of_platform_default_populate() with NULL as the first argument.

Loosen the requirement here so that platform devices can be created for
nodes created as children of the root node via DT overlays even if the
platform bus wasn't populated for the root node.

Cc: Rob Herring <ro...@kernel.org>
Cc: Saravana Kannan <sara...@google.com>
Signed-off-by: Stephen Boyd <sb...@kernel.org>
---
drivers/of/platform.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 389d4ea6bfc1..bda6da866cc8 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -732,11 +732,14 @@ static int of_platform_notify(struct notifier_block *nb,
struct of_reconfig_data *rd = arg;
struct platform_device *pdev_parent, *pdev;
bool children_left;
+ struct device_node *parent;

switch (of_reconfig_get_state_change(action, rd)) {
case OF_RECONFIG_CHANGE_ADD:
- /* verify that the parent is a bus */
- if (!of_node_check_flag(rd->dn->parent, OF_POPULATED_BUS))
+ parent = rd->dn->parent;
+ /* verify that the parent is a bus (or the root node) */
+ if (!of_node_is_root(parent) &&
+ of_node_check_flag(parent, OF_POPULATED_BUS))
return NOTIFY_OK; /* not for us */

/* already populated? (driver using of_populate manually) */
@@ -749,7 +752,7 @@ static int of_platform_notify(struct notifier_block *nb,
*/
rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
/* pdev_parent may be NULL when no bus platform device */
- pdev_parent = of_find_device_by_node(rd->dn->parent);
+ pdev_parent = of_find_device_by_node(parent);
pdev = of_platform_device_create(rd->dn, NULL,
pdev_parent ? &pdev_parent->dev : NULL);
platform_device_put(pdev_parent);
--
https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/
https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git

Rob Herring (Arm)

unread,
Jun 5, 2024, 7:47:52 PMJun 5
to Stephen Boyd, Daniel Latypov, Saravana Kannan, Krzysztof Kozlowski, linux-...@vger.kernel.org, Christian Marangi, devic...@vger.kernel.org, Rae Moar, Conor Dooley, Maxime Ripard, linu...@vger.kernel.org, linux-k...@vger.kernel.org, David Gow, Rafael J . Wysocki, pat...@lists.linux.dev, Michael Turquette, kuni...@googlegroups.com, Brendan Higgins, Greg Kroah-Hartman

On Mon, 03 Jun 2024 15:37:58 -0700, Stephen Boyd wrote:
> We'd like to apply overlays to the root node in KUnit so we can test
> platform devices created as children of the root node.
>
> On some architectures (powerpc), the root node isn't marked with
> OF_POPULATED_BUS. If an overlay tries to modify the root node on these
> platforms it will fail, while on other platforms, such as ARM, it will
> succeed. This is because the root node is marked with OF_POPULATED_BUS
> by of_platform_default_populate_init() calling
> of_platform_default_populate() with NULL as the first argument.
>
> Loosen the requirement here so that platform devices can be created for
> nodes created as children of the root node via DT overlays even if the
> platform bus wasn't populated for the root node.
>
> Cc: Rob Herring <ro...@kernel.org>
> Cc: Saravana Kannan <sara...@google.com>
> Signed-off-by: Stephen Boyd <sb...@kernel.org>
> ---
> drivers/of/platform.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>

Reviewed-by: Rob Herring (Arm) <ro...@kernel.org>

Reply all
Reply to author
Forward
0 new messages