Skip to contentSkip to conversation

of: Move of_platform_register_reconfig_notifier() into DT core

PATCH In review Rob Herring 2 participants 4 messages Jul 17, 2023 – Aug 4, 2023

Subsystems (2)
lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

PATCH 1/2 of: Move of_platform_register_reconfig_notifier() into DT core

There's no reason the generic platform bus code needs to call of_platform_register_reconfig_notifier(). The notifier can be setup before the platform bus is. Let's move it into of_core_init() which is called just before platform_bus_init() instead to keep more of the DT bits in the DT code.

---
 drivers/base/platform.c     | 2 +-
 drivers/of/base.c           | 1 +
 drivers/of/of_private.h     | 6 ++++++
 drivers/of/platform.c       | 2 ++
 include/linux/of_platform.h | 6 ------
 5 files changed, 10 insertions(+), 7 deletions(-)
drivers/base/platform.c +1 -1
index 77510e4f47de..76bfcba25003 100644
@@ -1528,6 +1528,6 @@ int __init platform_bus_init(void)
 	error =  bus_register(&platform_bus_type);
 	if (error)
 		device_unregister(&platform_bus);
-	of_platform_register_reconfig_notifier();
+
 	return error;
 }
drivers/of/base.c +1 -0
index 166fb7d75337..e235f3a57ea8 100644
@@ -167,6 +167,7 @@ void __init of_core_init(void)
 {
 	struct device_node *np;
 
+	of_platform_register_reconfig_notifier();
 
 	/* Create the kset, and register existing nodes */
 	mutex_lock(&of_mutex);
drivers/of/of_private.h +6 -0
index b57f1014e419..f38397c7b582 100644
@@ -60,6 +60,12 @@ static inline int of_property_notify(int action, struct device_node *np,
 }
 #endif /* CONFIG_OF_DYNAMIC */
 
+#if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
+void of_platform_register_reconfig_notifier(void);
+#else
+static inline void of_platform_register_reconfig_notifier(void) { }
+#endif
+
 #if defined(CONFIG_OF_KOBJ)
 int of_node_is_attached(const struct device_node *node);
 int __of_add_property_sysfs(struct device_node *np, struct property *pp);
drivers/of/platform.c +2 -0
index 051e29b7ad2b..e71adb394b41 100644
@@ -21,6 +21,8 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 
+#include "of_private.h"
+
 const struct of_device_id of_default_bus_match_table[] = {
 	{ .compatible = "simple-bus", },
 	{ .compatible = "simple-mfd", },
include/linux/of_platform.h +0 -6
index d8045bcfc35e..fadfea575485 100644
@@ -127,10 +127,4 @@ static inline int devm_of_platform_populate(struct device *dev)
 static inline void devm_of_platform_depopulate(struct device *dev) { }
 #endif
 
-#if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
-extern void of_platform_register_reconfig_notifier(void);
-#else
-static inline void of_platform_register_reconfig_notifier(void) { }
-#endif
-
 #endif	/* _LINUX_OF_PLATFORM_H */
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 2/2 of: Move of_device_{add,register,unregister} to platform.c

The declarations for of_device_{add,register,unregister} were moved into of_platform.h, so the implementations should be moved to platform.c as well.

---
 drivers/of/device.c   | 32 --------------------------------
 drivers/of/platform.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 32 deletions(-)
drivers/of/device.c +0 -32
index 0f00f1b80708..2319e0e73048 100644
@@ -32,25 +32,6 @@ const struct of_device_id *of_match_device(const struct of_device_id *matches,
 }
 EXPORT_SYMBOL(of_match_device);
 
-int of_device_add(struct platform_device *ofdev)
-{
-	BUG_ON(ofdev->dev.of_node == NULL);
-
-	/* name and id have to be set so that the platform bus doesn't get
-	 * confused on matching */
-	ofdev->name = dev_name(&ofdev->dev);
-	ofdev->id = PLATFORM_DEVID_NONE;
-
-	/*
-	 * If this device has not binding numa node in devicetree, that is
-	 * of_node_to_nid returns NUMA_NO_NODE. device_add will assume that this
-	 * device is on the same node as the parent.
-	 */
-	set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node));
-
-	return device_add(&ofdev->dev);
-}
-
 static void
 of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 {
@@ -221,19 +202,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_dma_configure_id);
 
-int of_device_register(struct platform_device *pdev)
-{
-	device_initialize(&pdev->dev);
-	return of_device_add(pdev);
-}
-EXPORT_SYMBOL(of_device_register);
-
-void of_device_unregister(struct platform_device *ofdev)
-{
-	device_unregister(&ofdev->dev);
-}
-EXPORT_SYMBOL(of_device_unregister);
-
 const void *of_device_get_match_data(const struct device *dev)
 {
 	const struct of_device_id *match;
drivers/of/platform.c +32 -0
index e71adb394b41..8d03d9e65ef9 100644
@@ -56,6 +56,38 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
 }
 EXPORT_SYMBOL(of_find_device_by_node);
 
+int of_device_add(struct platform_device *ofdev)
+{
+	BUG_ON(ofdev->dev.of_node == NULL);
+
+	/* name and id have to be set so that the platform bus doesn't get
+	 * confused on matching */
+	ofdev->name = dev_name(&ofdev->dev);
+	ofdev->id = PLATFORM_DEVID_NONE;
+
+	/*
+	 * If this device has not binding numa node in devicetree, that is
+	 * of_node_to_nid returns NUMA_NO_NODE. device_add will assume that this
+	 * device is on the same node as the parent.
+	 */
+	set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node));
+
+	return device_add(&ofdev->dev);
+}
+
+int of_device_register(struct platform_device *pdev)
+{
+	device_initialize(&pdev->dev);
+	return of_device_add(pdev);
+}
+EXPORT_SYMBOL(of_device_register);
+
+void of_device_unregister(struct platform_device *ofdev)
+{
+	device_unregister(&ofdev->dev);
+}
+EXPORT_SYMBOL(of_device_unregister);
+
 #ifdef CONFIG_OF_ADDRESS
 /*
  * The following routines scan a subtree and registers a device for
Signature · 1 line
2.40.1
maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Rob Herring
Quoted 6 lines · Rob Herring

There's no reason the generic platform bus code needs to call of_platform_register_reconfig_notifier(). The notifier can be setup before the platform bus is. Let's move it into of_core_init() which is called just before platform_bus_init() instead to keep more of the DT bits in the DT code.

Quoted 9 lines
---
 drivers/base/platform.c     | 2 +-
 drivers/of/base.c           | 1 +
 drivers/of/of_private.h     | 6 ++++++
 drivers/of/platform.c       | 2 ++
 include/linux/of_platform.h | 6 ------
 5 files changed, 10 insertions(+), 7 deletions(-)