mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH 03/15] of: device: Export of_device_make_bus_id()
Date: Mon, 04 Aug 2025 16:36:49 +0200	[thread overview]
Message-ID: <20250804-v2025-06-0-topic-nvmem-v1-3-7603eaa4d2b0@pengutronix.de> (raw)
In-Reply-To: <20250804-v2025-06-0-topic-nvmem-v1-0-7603eaa4d2b0@pengutronix.de>

Port Linux commit:

| commit 7f38b70042fcaa49219045bd1a9a2836e27a58ac
| Author: Miquel Raynal <miquel.raynal@bootlin.com>
| Date:   Fri Dec 15 11:15:27 2023 +0000
|
|     of: device: Export of_device_make_bus_id()
|
|     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>

This is required for the upcoming nvmem layout support.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/of/device.c   | 37 +++++++++++++++++++++++++++++++++++++
 drivers/of/platform.c | 36 +-----------------------------------
 include/of_device.h   |  3 +++
 3 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 77c027b57e3fd0edaed2270d7694b7367ac174d9..e28b8229c46f19c8403b688fba9255aae3bf31f0 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -2,6 +2,7 @@
 #include <common.h>
 #include <of.h>
 #include <of_device.h>
+#include <of_address.h>
 
 /**
  * of_match_device - Tell if a struct device matches an of_device_id list
@@ -44,3 +45,39 @@ const char *of_device_get_match_compatible(const struct device *dev)
 	return match->compatible;
 }
 EXPORT_SYMBOL(of_device_get_match_compatible);
+
+/**
+ * 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;
+
+	/* 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) {
+			dev_set_name(dev, dev->name ? "%llx.%s:%s" : "%llx.%s.of",
+				     (unsigned long long)addr, node->name,
+				     dev->name);
+			return;
+		}
+
+		/* format arguments only used if dev_name() resolves to NULL */
+		dev_set_name(dev, dev->name ? "%s:%s" : "%s.of",
+			     kbasename(node->full_name), dev->name);
+		node = node->parent;
+	}
+}
+EXPORT_SYMBOL_GPL(of_device_make_bus_id);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 3600b5f9c10b1968007f84c60e266299c7be8e9e..760ad9527374e559a39ed655419b991bc3a8e6a0 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -12,6 +12,7 @@
 #include <malloc.h>
 #include <of.h>
 #include <of_address.h>
+#include <of_device.h>
 #include <linux/amba/bus.h>
 #include <mmu.h>
 
@@ -38,41 +39,6 @@ struct device *of_find_device_by_node(struct device_node *np)
 }
 EXPORT_SYMBOL(of_find_device_by_node);
 
-/**
- * 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;
-
-	/* 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) {
-			dev_set_name(dev, dev->name ? "%llx.%s:%s" : "%llx.%s.of",
-				     (unsigned long long)addr, node->name,
-				     dev->name);
-			return;
-		}
-
-		/* format arguments only used if dev_name() resolves to NULL */
-		dev_set_name(dev, dev->name ? "%s:%s" : "%s.of",
-			     kbasename(node->full_name), dev->name);
-		node = node->parent;
-	}
-}
-
 static struct device_node *of_get_next_dma_parent(const struct device_node *np)
 {
 	struct of_phandle_args args;
diff --git a/include/of_device.h b/include/of_device.h
index 5afcc5ff94b1095031659dd4a418f6c42442147f..14f9062c6c2c61a3b05b6e6ee94f59960812d26e 100644
--- a/include/of_device.h
+++ b/include/of_device.h
@@ -23,6 +23,7 @@ static inline int of_driver_match_device(struct device *dev,
 
 extern const void *of_device_get_match_data(const struct device *dev);
 extern const char *of_device_get_match_compatible(const struct device *dev);
+void of_device_make_bus_id(struct device *dev);
 
 #else /* CONFIG_OFTREE */
 
@@ -50,6 +51,8 @@ static inline const struct of_device_id *__of_match_device(
 #define of_match_device(matches, dev)	\
 	__of_match_device(matches, (dev))
 
+static inline void of_device_make_bus_id(struct device *dev) {}
+
 #endif /* CONFIG_OFTREE */
 
 #endif /* _LINUX_OF_DEVICE_H */

-- 
2.39.5




  parent reply	other threads:[~2025-08-04 15:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 14:36 [PATCH 00/15] NVMEM: Add support for layout drivers Marco Felsch
2025-08-04 14:36 ` [PATCH 01/15] of: sync of_*_phandle_with_args with Linux Marco Felsch
2025-08-04 14:36 ` [PATCH 02/15] of: base: add of_parse_phandle_with_optional_args() Marco Felsch
2025-08-04 14:36 ` Marco Felsch [this message]
2025-08-04 14:36 ` [PATCH 04/15] nvmem: core: fix nvmem_register error path Marco Felsch
2025-08-04 14:36 ` [PATCH 05/15] nvmem: core: sync with Linux Marco Felsch
2025-08-04 14:36 ` [PATCH 06/15] nvmem: core: expose nvmem cells as cdev Marco Felsch
2025-08-04 14:36 ` [PATCH 07/15] nvmem: core: allow single and dynamic device ids Marco Felsch
2025-08-04 14:36 ` [PATCH 08/15] eeprom: at24: fix device name handling Marco Felsch
2025-08-04 14:36 ` [PATCH 09/15] nvmem: core: create a header for internal sharing Marco Felsch
2025-08-04 14:36 ` [PATCH 10/15] nvmem: core: add nvmem-layout support Marco Felsch
2025-08-04 14:36 ` [PATCH 11/15] nvmem: core: add an index parameter to the cell Marco Felsch
2025-08-04 14:36 ` [PATCH 12/15] nvmem: core: add per-cell post processing Marco Felsch
2025-08-04 14:36 ` [PATCH 13/15] nvmem: core: add cell based fixup logic Marco Felsch
2025-08-04 14:37 ` [PATCH 14/15] nvmem: core: provide own priv pointer in post process callback Marco Felsch
2025-08-04 14:37 ` [PATCH 15/15] nvmem: core: drop global cell_post_process Marco Felsch
2025-08-05 10:44 ` [PATCH 00/15] NVMEM: Add support for layout drivers 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=20250804-v2025-06-0-topic-nvmem-v1-3-7603eaa4d2b0@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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