Port Linux commit: | commit 7f38b70042fcaa49219045bd1a9a2836e27a58ac | Author: Miquel Raynal <miquel.ray...@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.ray...@bootlin.com> | Acked-by: Rob Herring <r...@kernel.org> | Signed-off-by: Srinivas Kandagatla <srinivas.kandaga...@linaro.org> | Link: https://lore.kernel.org/r/20231215111536.316972-2-srinivas.kandaga...@linaro.org | Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
This is required for the upcoming nvmem layout support. Signed-off-by: Marco Felsch <m.fel...@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