gperf: build as C++11
[openwrt/openwrt.git] / target / linux / generic / backport-6.6 / 818-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 @@ -304,3 +304,44 @@ int of_device_uevent_modalias(const stru
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 + u32 mask;
44 +
45 + /* Construct the name, using parent nodes if necessary to ensure uniqueness */
46 + while (node->parent) {
47 + /*
48 + * If the address can be translated, then that is as much
49 + * uniqueness as we need. Make it the first component and return
50 + */
51 + reg = of_get_property(node, "reg", NULL);
52 + if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
53 + if (!of_property_read_u32(node, "mask", &mask))
54 + dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn",
55 + addr, ffs(mask) - 1, node, dev_name(dev));
56 +
57 + else
58 + dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
59 + addr, node, dev_name(dev));
60 + return;
61 + }
62 +
63 + /* format arguments only used if dev_name() resolves to NULL */
64 + dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
65 + kbasename(node->full_name), dev_name(dev));
66 + node = node->parent;
67 + }
68 +}
69 +EXPORT_SYMBOL_GPL(of_device_make_bus_id);
70 --- a/drivers/of/platform.c
71 +++ b/drivers/of/platform.c
72 @@ -98,46 +98,6 @@ static const struct of_device_id of_skip
73 */
74
75 /**
76 - * of_device_make_bus_id - Use the device node data to assign a unique name
77 - * @dev: pointer to device structure that is linked to a device tree node
78 - *
79 - * This routine will first try using the translated bus address to
80 - * derive a unique name. If it cannot, then it will prepend names from
81 - * parent nodes until a unique name can be derived.
82 - */
83 -static void of_device_make_bus_id(struct device *dev)
84 -{
85 - struct device_node *node = dev->of_node;
86 - const __be32 *reg;
87 - u64 addr;
88 - u32 mask;
89 -
90 - /* Construct the name, using parent nodes if necessary to ensure uniqueness */
91 - while (node->parent) {
92 - /*
93 - * If the address can be translated, then that is as much
94 - * uniqueness as we need. Make it the first component and return
95 - */
96 - reg = of_get_property(node, "reg", NULL);
97 - if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
98 - if (!of_property_read_u32(node, "mask", &mask))
99 - dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn",
100 - addr, ffs(mask) - 1, node, dev_name(dev));
101 -
102 - else
103 - dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
104 - addr, node, dev_name(dev));
105 - return;
106 - }
107 -
108 - /* format arguments only used if dev_name() resolves to NULL */
109 - dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
110 - kbasename(node->full_name), dev_name(dev));
111 - node = node->parent;
112 - }
113 -}
114 -
115 -/**
116 * of_device_alloc - Allocate and initialize an of_device
117 * @np: device node to assign to device
118 * @bus_id: Name to assign to the device. May be null to use default name.
119 --- a/include/linux/of_device.h
120 +++ b/include/linux/of_device.h
121 @@ -40,6 +40,9 @@ static inline int of_dma_configure(struc
122 {
123 return of_dma_configure_id(dev, np, force_dma, NULL);
124 }
125 +
126 +void of_device_make_bus_id(struct device *dev);
127 +
128 #else /* CONFIG_OF */
129
130 static inline int of_driver_match_device(struct device *dev,
131 @@ -82,6 +85,9 @@ static inline int of_dma_configure(struc
132 {
133 return 0;
134 }
135 +
136 +static inline void of_device_make_bus_id(struct device *dev) {}
137 +
138 #endif /* CONFIG_OF */
139
140 #endif /* _LINUX_OF_DEVICE_H */