kernel: 5.15: update Aquantia PHY driver to v6.1 code
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 832-v6.8-of-device-Export-of_device_make_bus_id.patch
1 From 7f38b70042fcaa49219045bd1a9a2836e27a58ac Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Fri, 15 Dec 2023 11:15:27 +0000
4 Subject: [PATCH] of: device: Export of_device_make_bus_id()
5
6 This helper is really handy to create unique device names based on their
7 device tree path, we may need it outside of the OF core (in the NVMEM
8 subsystem) so let's export it. As this helper has nothing patform
9 specific, let's move it to of/device.c instead of of/platform.c so we
10 can add its prototype to of_device.h.
11
12 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
13 Acked-by: Rob Herring <robh@kernel.org>
14 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
15 Link: https://lore.kernel.org/r/20231215111536.316972-2-srinivas.kandagatla@linaro.org
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 ---
18 drivers/of/device.c | 41 +++++++++++++++++++++++++++++++++++++++
19 drivers/of/platform.c | 40 --------------------------------------
20 include/linux/of_device.h | 6 ++++++
21 3 files changed, 47 insertions(+), 40 deletions(-)
22
23 --- a/drivers/of/device.c
24 +++ b/drivers/of/device.c
25 @@ -337,3 +337,38 @@ int of_device_uevent_modalias(struct dev
26 return 0;
27 }
28 EXPORT_SYMBOL_GPL(of_device_uevent_modalias);
29 +
30 +/**
31 + * of_device_make_bus_id - Use the device node data to assign a unique name
32 + * @dev: pointer to device structure that is linked to a device tree node
33 + *
34 + * This routine will first try using the translated bus address to
35 + * derive a unique name. If it cannot, then it will prepend names from
36 + * parent nodes until a unique name can be derived.
37 + */
38 +void of_device_make_bus_id(struct device *dev)
39 +{
40 + struct device_node *node = dev->of_node;
41 + const __be32 *reg;
42 + u64 addr;
43 +
44 + /* Construct the name, using parent nodes if necessary to ensure uniqueness */
45 + while (node->parent) {
46 + /*
47 + * If the address can be translated, then that is as much
48 + * uniqueness as we need. Make it the first component and return
49 + */
50 + reg = of_get_property(node, "reg", NULL);
51 + if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
52 + dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
53 + addr, node, dev_name(dev));
54 + return;
55 + }
56 +
57 + /* format arguments only used if dev_name() resolves to NULL */
58 + dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
59 + kbasename(node->full_name), dev_name(dev));
60 + node = node->parent;
61 + }
62 +}
63 +EXPORT_SYMBOL_GPL(of_device_make_bus_id);
64 --- a/drivers/of/platform.c
65 +++ b/drivers/of/platform.c
66 @@ -64,40 +64,6 @@ EXPORT_SYMBOL(of_find_device_by_node);
67 */
68
69 /**
70 - * of_device_make_bus_id - Use the device node data to assign a unique name
71 - * @dev: pointer to device structure that is linked to a device tree node
72 - *
73 - * This routine will first try using the translated bus address to
74 - * derive a unique name. If it cannot, then it will prepend names from
75 - * parent nodes until a unique name can be derived.
76 - */
77 -static void of_device_make_bus_id(struct device *dev)
78 -{
79 - struct device_node *node = dev->of_node;
80 - const __be32 *reg;
81 - u64 addr;
82 -
83 - /* Construct the name, using parent nodes if necessary to ensure uniqueness */
84 - while (node->parent) {
85 - /*
86 - * If the address can be translated, then that is as much
87 - * uniqueness as we need. Make it the first component and return
88 - */
89 - reg = of_get_property(node, "reg", NULL);
90 - if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
91 - dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
92 - addr, node, dev_name(dev));
93 - return;
94 - }
95 -
96 - /* format arguments only used if dev_name() resolves to NULL */
97 - dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
98 - kbasename(node->full_name), dev_name(dev));
99 - node = node->parent;
100 - }
101 -}
102 -
103 -/**
104 * of_device_alloc - Allocate and initialize an of_device
105 * @np: device node to assign to device
106 * @bus_id: Name to assign to the device. May be null to use default name.
107 --- a/include/linux/of_device.h
108 +++ b/include/linux/of_device.h
109 @@ -56,6 +56,9 @@ static inline int of_dma_configure(struc
110 {
111 return of_dma_configure_id(dev, np, force_dma, NULL);
112 }
113 +
114 +void of_device_make_bus_id(struct device *dev);
115 +
116 #else /* CONFIG_OF */
117
118 static inline int of_driver_match_device(struct device *dev,
119 @@ -113,6 +116,9 @@ static inline int of_dma_configure(struc
120 {
121 return 0;
122 }
123 +
124 +static inline void of_device_make_bus_id(struct device *dev) {}
125 +
126 #endif /* CONFIG_OF */
127
128 #endif /* _LINUX_OF_DEVICE_H */