of: device: Export of_device_make_bus_id()
authorMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 15 Dec 2023 11:15:27 +0000 (11:15 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Dec 2023 12:30:07 +0000 (13:30 +0100)
This helper is really handy to create unique device names based on their
device tree path, we may need it outside of the OF core (in the NVMEM
subsystem) so let's export it. As this helper has nothing patform
specific, let's move it to of/device.c instead of of/platform.c so we
can add its prototype to of_device.h.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20231215111536.316972-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/of/device.c
drivers/of/platform.c
include/linux/of_device.h

index 1ca42ad9dd159d4409b7edb73dd232e9b3dcc7fa..6e9572c4af83b9b0dbe06c2945ca380f274d4445 100644 (file)
@@ -304,3 +304,44 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *
        return 0;
 }
 EXPORT_SYMBOL_GPL(of_device_uevent_modalias);
+
+/**
+ * of_device_make_bus_id - Use the device node data to assign a unique name
+ * @dev: pointer to device structure that is linked to a device tree node
+ *
+ * This routine will first try using the translated bus address to
+ * derive a unique name. If it cannot, then it will prepend names from
+ * parent nodes until a unique name can be derived.
+ */
+void of_device_make_bus_id(struct device *dev)
+{
+       struct device_node *node = dev->of_node;
+       const __be32 *reg;
+       u64 addr;
+       u32 mask;
+
+       /* Construct the name, using parent nodes if necessary to ensure uniqueness */
+       while (node->parent) {
+               /*
+                * If the address can be translated, then that is as much
+                * uniqueness as we need. Make it the first component and return
+                */
+               reg = of_get_property(node, "reg", NULL);
+               if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
+                       if (!of_property_read_u32(node, "mask", &mask))
+                               dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn",
+                                            addr, ffs(mask) - 1, node, dev_name(dev));
+
+                       else
+                               dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
+                                            addr, node, dev_name(dev));
+                       return;
+               }
+
+               /* format arguments only used if dev_name() resolves to NULL */
+               dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
+                            kbasename(node->full_name), dev_name(dev));
+               node = node->parent;
+       }
+}
+EXPORT_SYMBOL_GPL(of_device_make_bus_id);
index 126d265aa7d860ea553fe85864a4edc046ea1673..c39e49a1eba00afaeee4baa3c3a735023fd4c6a2 100644 (file)
@@ -97,46 +97,6 @@ static const struct of_device_id of_skipped_node_table[] = {
  * mechanism for creating devices from device tree nodes.
  */
 
-/**
- * of_device_make_bus_id - Use the device node data to assign a unique name
- * @dev: pointer to device structure that is linked to a device tree node
- *
- * This routine will first try using the translated bus address to
- * derive a unique name. If it cannot, then it will prepend names from
- * parent nodes until a unique name can be derived.
- */
-static void of_device_make_bus_id(struct device *dev)
-{
-       struct device_node *node = dev->of_node;
-       const __be32 *reg;
-       u64 addr;
-       u32 mask;
-
-       /* Construct the name, using parent nodes if necessary to ensure uniqueness */
-       while (node->parent) {
-               /*
-                * If the address can be translated, then that is as much
-                * uniqueness as we need. Make it the first component and return
-                */
-               reg = of_get_property(node, "reg", NULL);
-               if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
-                       if (!of_property_read_u32(node, "mask", &mask))
-                               dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn",
-                                            addr, ffs(mask) - 1, node, dev_name(dev));
-
-                       else
-                               dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
-                                            addr, node, dev_name(dev));
-                       return;
-               }
-
-               /* format arguments only used if dev_name() resolves to NULL */
-               dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
-                            kbasename(node->full_name), dev_name(dev));
-               node = node->parent;
-       }
-}
-
 /**
  * of_device_alloc - Allocate and initialize an of_device
  * @np: device node to assign to device
index 2c7a3d4bc775b95f7092a181a75a2d6152e5a96d..a72661e47faa56a6c316dcd387153275e0990626 100644 (file)
@@ -40,6 +40,9 @@ static inline int of_dma_configure(struct device *dev,
 {
        return of_dma_configure_id(dev, np, force_dma, NULL);
 }
+
+void of_device_make_bus_id(struct device *dev);
+
 #else /* CONFIG_OF */
 
 static inline int of_driver_match_device(struct device *dev,
@@ -82,6 +85,9 @@ static inline int of_dma_configure(struct device *dev,
 {
        return 0;
 }
+
+static inline void of_device_make_bus_id(struct device *dev) {}
+
 #endif /* CONFIG_OF */
 
 #endif /* _LINUX_OF_DEVICE_H */