Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
b31384fa RW |
2 | /* |
3 | * property.h - Unified device property interface. | |
4 | * | |
5 | * Copyright (C) 2014, Intel Corporation | |
6 | * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | |
7 | * Mika Westerberg <mika.westerberg@linux.intel.com> | |
b31384fa RW |
8 | */ |
9 | ||
10 | #ifndef _LINUX_PROPERTY_H_ | |
11 | #define _LINUX_PROPERTY_H_ | |
12 | ||
0fcc2bdc | 13 | #include <linux/bits.h> |
ce793486 | 14 | #include <linux/fwnode.h> |
40eb28dc | 15 | #include <linux/stddef.h> |
b31384fa RW |
16 | #include <linux/types.h> |
17 | ||
18 | struct device; | |
d9eb4490 | 19 | struct net_device; |
b31384fa RW |
20 | |
21 | enum dev_prop_type { | |
22 | DEV_PROP_U8, | |
23 | DEV_PROP_U16, | |
24 | DEV_PROP_U32, | |
25 | DEV_PROP_U64, | |
26 | DEV_PROP_STRING, | |
e64b674b | 27 | DEV_PROP_REF, |
b31384fa RW |
28 | }; |
29 | ||
1b9863c6 SS |
30 | enum dev_dma_attr { |
31 | DEV_DMA_NOT_SUPPORTED, | |
32 | DEV_DMA_NON_COHERENT, | |
33 | DEV_DMA_COHERENT, | |
34 | }; | |
35 | ||
b295d484 AS |
36 | const struct fwnode_handle *__dev_fwnode_const(const struct device *dev); |
37 | struct fwnode_handle *__dev_fwnode(struct device *dev); | |
38 | #define dev_fwnode(dev) \ | |
39 | _Generic((dev), \ | |
40 | const struct device *: __dev_fwnode_const, \ | |
41 | struct device *: __dev_fwnode)(dev) | |
e44bb0cb | 42 | |
b31384fa RW |
43 | bool device_property_present(struct device *dev, const char *propname); |
44 | int device_property_read_u8_array(struct device *dev, const char *propname, | |
45 | u8 *val, size_t nval); | |
46 | int device_property_read_u16_array(struct device *dev, const char *propname, | |
47 | u16 *val, size_t nval); | |
48 | int device_property_read_u32_array(struct device *dev, const char *propname, | |
49 | u32 *val, size_t nval); | |
50 | int device_property_read_u64_array(struct device *dev, const char *propname, | |
51 | u64 *val, size_t nval); | |
52 | int device_property_read_string_array(struct device *dev, const char *propname, | |
53 | const char **val, size_t nval); | |
54 | int device_property_read_string(struct device *dev, const char *propname, | |
55 | const char **val); | |
3f5c8d31 MW |
56 | int device_property_match_string(struct device *dev, |
57 | const char *propname, const char *string); | |
b31384fa | 58 | |
37ba983c SA |
59 | bool fwnode_property_present(const struct fwnode_handle *fwnode, |
60 | const char *propname); | |
61 | int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode, | |
8a0662d9 RW |
62 | const char *propname, u8 *val, |
63 | size_t nval); | |
37ba983c | 64 | int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
65 | const char *propname, u16 *val, |
66 | size_t nval); | |
37ba983c | 67 | int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
68 | const char *propname, u32 *val, |
69 | size_t nval); | |
37ba983c | 70 | int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
71 | const char *propname, u64 *val, |
72 | size_t nval); | |
37ba983c | 73 | int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
74 | const char *propname, const char **val, |
75 | size_t nval); | |
37ba983c | 76 | int fwnode_property_read_string(const struct fwnode_handle *fwnode, |
8a0662d9 | 77 | const char *propname, const char **val); |
37ba983c | 78 | int fwnode_property_match_string(const struct fwnode_handle *fwnode, |
3f5c8d31 | 79 | const char *propname, const char *string); |
a521075d AS |
80 | |
81 | bool fwnode_device_is_available(const struct fwnode_handle *fwnode); | |
82 | ||
83 | static inline | |
84 | bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat) | |
85 | { | |
86 | return fwnode_property_match_string(fwnode, "compatible", compat) >= 0; | |
87 | } | |
88 | ||
3e3119d3 SA |
89 | int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, |
90 | const char *prop, const char *nargs_prop, | |
91 | unsigned int nargs, unsigned int index, | |
92 | struct fwnode_reference_args *args); | |
8a0662d9 | 93 | |
83b34afb HK |
94 | struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, |
95 | const char *name, | |
96 | unsigned int index); | |
97 | ||
bc0500c1 | 98 | const char *fwnode_get_name(const struct fwnode_handle *fwnode); |
e7e242bc | 99 | const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); |
87ffea09 | 100 | |
37ba983c | 101 | struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); |
87ffea09 AS |
102 | struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); |
103 | ||
104 | #define fwnode_for_each_parent_node(fwnode, parent) \ | |
105 | for (parent = fwnode_get_parent(fwnode); parent; \ | |
106 | parent = fwnode_get_next_parent(parent)) | |
107 | ||
b5d3e2fb | 108 | struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); |
87e5e95d SA |
109 | unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); |
110 | struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, | |
111 | unsigned int depth); | |
022fe6bc | 112 | bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child); |
37ba983c SA |
113 | struct fwnode_handle *fwnode_get_next_child_node( |
114 | const struct fwnode_handle *fwnode, struct fwnode_handle *child); | |
3395de96 MW |
115 | struct fwnode_handle *fwnode_get_next_available_child_node( |
116 | const struct fwnode_handle *fwnode, struct fwnode_handle *child); | |
34055190 MW |
117 | |
118 | #define fwnode_for_each_child_node(fwnode, child) \ | |
119 | for (child = fwnode_get_next_child_node(fwnode, NULL); child; \ | |
120 | child = fwnode_get_next_child_node(fwnode, child)) | |
afaf26fd | 121 | |
3395de96 MW |
122 | #define fwnode_for_each_available_child_node(fwnode, child) \ |
123 | for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\ | |
124 | child = fwnode_get_next_available_child_node(fwnode, child)) | |
125 | ||
7952cd2b AS |
126 | struct fwnode_handle *device_get_next_child_node(const struct device *dev, |
127 | struct fwnode_handle *child); | |
8a0662d9 | 128 | |
1d656fb7 AS |
129 | #define device_for_each_child_node(dev, child) \ |
130 | for (child = device_get_next_child_node(dev, NULL); child; \ | |
8a0662d9 RW |
131 | child = device_get_next_child_node(dev, child)) |
132 | ||
7952cd2b AS |
133 | struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, |
134 | const char *childname); | |
135 | struct fwnode_handle *device_get_named_child_node(const struct device *dev, | |
613e9721 AT |
136 | const char *childname); |
137 | ||
cf89a31c | 138 | struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); |
8a0662d9 RW |
139 | void fwnode_handle_put(struct fwnode_handle *fwnode); |
140 | ||
fb38f314 | 141 | int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); |
ca0acb51 | 142 | int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); |
7c6c57f2 | 143 | |
7952cd2b | 144 | unsigned int device_get_child_node_count(const struct device *dev); |
8a0662d9 | 145 | |
b31384fa RW |
146 | static inline bool device_property_read_bool(struct device *dev, |
147 | const char *propname) | |
148 | { | |
149 | return device_property_present(dev, propname); | |
150 | } | |
151 | ||
152 | static inline int device_property_read_u8(struct device *dev, | |
153 | const char *propname, u8 *val) | |
154 | { | |
155 | return device_property_read_u8_array(dev, propname, val, 1); | |
156 | } | |
157 | ||
158 | static inline int device_property_read_u16(struct device *dev, | |
159 | const char *propname, u16 *val) | |
160 | { | |
161 | return device_property_read_u16_array(dev, propname, val, 1); | |
162 | } | |
163 | ||
164 | static inline int device_property_read_u32(struct device *dev, | |
165 | const char *propname, u32 *val) | |
166 | { | |
167 | return device_property_read_u32_array(dev, propname, val, 1); | |
168 | } | |
169 | ||
170 | static inline int device_property_read_u64(struct device *dev, | |
171 | const char *propname, u64 *val) | |
172 | { | |
173 | return device_property_read_u64_array(dev, propname, val, 1); | |
174 | } | |
175 | ||
33ee09cd AS |
176 | static inline int device_property_count_u8(struct device *dev, const char *propname) |
177 | { | |
178 | return device_property_read_u8_array(dev, propname, NULL, 0); | |
179 | } | |
180 | ||
181 | static inline int device_property_count_u16(struct device *dev, const char *propname) | |
182 | { | |
183 | return device_property_read_u16_array(dev, propname, NULL, 0); | |
184 | } | |
185 | ||
186 | static inline int device_property_count_u32(struct device *dev, const char *propname) | |
187 | { | |
188 | return device_property_read_u32_array(dev, propname, NULL, 0); | |
189 | } | |
190 | ||
191 | static inline int device_property_count_u64(struct device *dev, const char *propname) | |
192 | { | |
193 | return device_property_read_u64_array(dev, propname, NULL, 0); | |
194 | } | |
195 | ||
6b6ff4ac BG |
196 | static inline int device_property_string_array_count(struct device *dev, |
197 | const char *propname) | |
198 | { | |
199 | return device_property_read_string_array(dev, propname, NULL, 0); | |
200 | } | |
201 | ||
37ba983c | 202 | static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
203 | const char *propname) |
204 | { | |
205 | return fwnode_property_present(fwnode, propname); | |
206 | } | |
207 | ||
37ba983c | 208 | static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
209 | const char *propname, u8 *val) |
210 | { | |
211 | return fwnode_property_read_u8_array(fwnode, propname, val, 1); | |
212 | } | |
213 | ||
37ba983c | 214 | static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
215 | const char *propname, u16 *val) |
216 | { | |
217 | return fwnode_property_read_u16_array(fwnode, propname, val, 1); | |
218 | } | |
219 | ||
37ba983c | 220 | static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
221 | const char *propname, u32 *val) |
222 | { | |
223 | return fwnode_property_read_u32_array(fwnode, propname, val, 1); | |
224 | } | |
225 | ||
37ba983c | 226 | static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
227 | const char *propname, u64 *val) |
228 | { | |
229 | return fwnode_property_read_u64_array(fwnode, propname, val, 1); | |
230 | } | |
231 | ||
33ee09cd AS |
232 | static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode, |
233 | const char *propname) | |
234 | { | |
235 | return fwnode_property_read_u8_array(fwnode, propname, NULL, 0); | |
236 | } | |
237 | ||
238 | static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode, | |
239 | const char *propname) | |
240 | { | |
241 | return fwnode_property_read_u16_array(fwnode, propname, NULL, 0); | |
242 | } | |
243 | ||
244 | static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode, | |
245 | const char *propname) | |
246 | { | |
247 | return fwnode_property_read_u32_array(fwnode, propname, NULL, 0); | |
248 | } | |
249 | ||
250 | static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, | |
251 | const char *propname) | |
252 | { | |
253 | return fwnode_property_read_u64_array(fwnode, propname, NULL, 0); | |
254 | } | |
255 | ||
6b6ff4ac BG |
256 | static inline int |
257 | fwnode_property_string_array_count(const struct fwnode_handle *fwnode, | |
258 | const char *propname) | |
259 | { | |
260 | return fwnode_property_read_string_array(fwnode, propname, NULL, 0); | |
261 | } | |
262 | ||
e64b674b DT |
263 | struct software_node; |
264 | ||
265 | /** | |
266 | * struct software_node_ref_args - Reference property with additional arguments | |
267 | * @node: Reference to a software node | |
268 | * @nargs: Number of elements in @args array | |
269 | * @args: Integer arguments | |
270 | */ | |
271 | struct software_node_ref_args { | |
272 | const struct software_node *node; | |
273 | unsigned int nargs; | |
274 | u64 args[NR_FWNODE_REFERENCE_ARGS]; | |
275 | }; | |
276 | ||
e588fead AS |
277 | #define SOFTWARE_NODE_REFERENCE(_ref_, ...) \ |
278 | (const struct software_node_ref_args) { \ | |
279 | .node = _ref_, \ | |
280 | .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \ | |
281 | .args = { __VA_ARGS__ }, \ | |
282 | } | |
283 | ||
16ba08d5 RW |
284 | /** |
285 | * struct property_entry - "Built-in" device property representation. | |
286 | * @name: Name of the property. | |
318a1971 | 287 | * @length: Length of data making up the value. |
e6bff466 | 288 | * @is_inline: True when the property value is stored inline. |
63dcc709 | 289 | * @type: Type of the data in unions. |
e6bff466 DT |
290 | * @pointer: Pointer to the property when it is not stored inline. |
291 | * @value: Value of the property when it is stored inline. | |
16ba08d5 RW |
292 | */ |
293 | struct property_entry { | |
294 | const char *name; | |
318a1971 | 295 | size_t length; |
e6bff466 | 296 | bool is_inline; |
63dcc709 | 297 | enum dev_prop_type type; |
16ba08d5 | 298 | union { |
1f74d70f | 299 | const void *pointer; |
66586bab | 300 | union { |
996b0830 DT |
301 | u8 u8_data[sizeof(u64) / sizeof(u8)]; |
302 | u16 u16_data[sizeof(u64) / sizeof(u16)]; | |
303 | u32 u32_data[sizeof(u64) / sizeof(u32)]; | |
304 | u64 u64_data[sizeof(u64) / sizeof(u64)]; | |
305 | const char *str[sizeof(u64) / sizeof(char *)]; | |
66586bab AS |
306 | } value; |
307 | }; | |
16ba08d5 RW |
308 | }; |
309 | ||
d76eebfa | 310 | /* |
daeba9bf | 311 | * Note: the below initializers for the anonymous union are carefully |
d76eebfa AM |
312 | * crafted to avoid gcc-4.4.4's problems with initialization of anon unions |
313 | * and structs. | |
314 | */ | |
40eb28dc AS |
315 | #define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_) \ |
316 | (struct property_entry) { \ | |
317 | .name = _name_, \ | |
318 | .length = (_len_) * sizeof_field(struct property_entry, value._elem_[0]), \ | |
319 | .type = DEV_PROP_##_Type_, \ | |
320 | { .pointer = _val_ }, \ | |
a85f4204 HK |
321 | } |
322 | ||
1741cfac | 323 | #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 324 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) |
1741cfac | 325 | #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 326 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_) |
1741cfac | 327 | #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 328 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_) |
1741cfac | 329 | #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 330 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) |
1741cfac | 331 | #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 332 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) |
c6c76563 | 333 | |
e64b674b | 334 | #define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_) \ |
40eb28dc AS |
335 | (struct property_entry) { \ |
336 | .name = _name_, \ | |
337 | .length = (_len_) * sizeof(struct software_node_ref_args), \ | |
338 | .type = DEV_PROP_REF, \ | |
339 | { .pointer = _val_ }, \ | |
340 | } | |
a85f4204 | 341 | |
1741cfac DT |
342 | #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ |
343 | PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
344 | #define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ | |
345 | PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
346 | #define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ | |
347 | PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
348 | #define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ | |
349 | PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
350 | #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ | |
351 | PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
c6c76563 | 352 | #define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_) \ |
e64b674b | 353 | PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) |
1741cfac | 354 | |
daeba9bf DT |
355 | #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ |
356 | (struct property_entry) { \ | |
357 | .name = _name_, \ | |
40eb28dc | 358 | .length = sizeof_field(struct property_entry, value._elem_[0]), \ |
e6bff466 | 359 | .is_inline = true, \ |
daeba9bf | 360 | .type = DEV_PROP_##_Type_, \ |
996b0830 | 361 | { .value = { ._elem_[0] = _val_ } }, \ |
a85f4204 HK |
362 | } |
363 | ||
daeba9bf DT |
364 | #define PROPERTY_ENTRY_U8(_name_, _val_) \ |
365 | __PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_) | |
366 | #define PROPERTY_ENTRY_U16(_name_, _val_) \ | |
367 | __PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_) | |
368 | #define PROPERTY_ENTRY_U32(_name_, _val_) \ | |
369 | __PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_) | |
370 | #define PROPERTY_ENTRY_U64(_name_, _val_) \ | |
371 | __PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_) | |
372 | #define PROPERTY_ENTRY_STRING(_name_, _val_) \ | |
373 | __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_) | |
a85f4204 | 374 | |
e64b674b DT |
375 | #define PROPERTY_ENTRY_REF(_name_, _ref_, ...) \ |
376 | (struct property_entry) { \ | |
377 | .name = _name_, \ | |
378 | .length = sizeof(struct software_node_ref_args), \ | |
379 | .type = DEV_PROP_REF, \ | |
e588fead | 380 | { .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), }, \ |
e64b674b DT |
381 | } |
382 | ||
c6c76563 AS |
383 | #define PROPERTY_ENTRY_BOOL(_name_) \ |
384 | (struct property_entry) { \ | |
385 | .name = _name_, \ | |
386 | .is_inline = true, \ | |
387 | } | |
388 | ||
2d479e1f DT |
389 | struct property_entry * |
390 | property_entries_dup(const struct property_entry *properties); | |
2d479e1f DT |
391 | void property_entries_free(const struct property_entry *properties); |
392 | ||
59789f34 AS |
393 | bool device_dma_supported(const struct device *dev); |
394 | enum dev_dma_attr device_get_dma_attr(const struct device *dev); | |
b283f157 | 395 | |
aade55c8 | 396 | const void *device_get_match_data(const struct device *dev); |
e5e55864 | 397 | |
4c96b7dc | 398 | int device_get_phy_mode(struct device *dev); |
b28f263b | 399 | int fwnode_get_phy_mode(struct fwnode_handle *fwnode); |
b2638e56 AS |
400 | |
401 | void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index); | |
402 | ||
07bb80d4 | 403 | struct fwnode_handle *fwnode_graph_get_next_endpoint( |
37ba983c | 404 | const struct fwnode_handle *fwnode, struct fwnode_handle *prev); |
6a71d8d7 | 405 | struct fwnode_handle * |
37ba983c | 406 | fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode); |
07bb80d4 | 407 | struct fwnode_handle *fwnode_graph_get_remote_port_parent( |
37ba983c | 408 | const struct fwnode_handle *fwnode); |
07bb80d4 | 409 | struct fwnode_handle *fwnode_graph_get_remote_port( |
37ba983c | 410 | const struct fwnode_handle *fwnode); |
07bb80d4 | 411 | struct fwnode_handle *fwnode_graph_get_remote_endpoint( |
37ba983c | 412 | const struct fwnode_handle *fwnode); |
07bb80d4 | 413 | |
a1bfed60 | 414 | static inline bool fwnode_graph_is_endpoint(const struct fwnode_handle *fwnode) |
35694afc LP |
415 | { |
416 | return fwnode_property_present(fwnode, "remote-endpoint"); | |
417 | } | |
418 | ||
0fcc2bdc SA |
419 | /* |
420 | * Fwnode lookup flags | |
421 | * | |
422 | * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the | |
423 | * closest endpoint ID greater than the specified | |
424 | * one. | |
425 | * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote | |
426 | * endpoint of the given endpoint belongs to, | |
49f39cb0 SA |
427 | * may be disabled, or that the endpoint is not |
428 | * connected. | |
0fcc2bdc SA |
429 | */ |
430 | #define FWNODE_GRAPH_ENDPOINT_NEXT BIT(0) | |
431 | #define FWNODE_GRAPH_DEVICE_DISABLED BIT(1) | |
432 | ||
433 | struct fwnode_handle * | |
434 | fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode, | |
435 | u32 port, u32 endpoint, unsigned long flags); | |
c87b8fc5 SA |
436 | unsigned int fwnode_graph_get_endpoint_count(struct fwnode_handle *fwnode, |
437 | unsigned long flags); | |
0fcc2bdc | 438 | |
52af7863 AS |
439 | #define fwnode_graph_for_each_endpoint(fwnode, child) \ |
440 | for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child; \ | |
441 | child = fwnode_graph_get_next_endpoint(fwnode, child)) | |
5e4b1b70 | 442 | |
37ba983c | 443 | int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, |
2bd5452d SA |
444 | struct fwnode_endpoint *endpoint); |
445 | ||
23ead33b | 446 | typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id, |
d7cf5590 HK |
447 | void *data); |
448 | ||
23ead33b | 449 | void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, |
d7cf5590 HK |
450 | const char *con_id, void *data, |
451 | devcon_match_fn_t match); | |
452 | ||
23ead33b | 453 | static inline void *device_connection_find_match(const struct device *dev, |
d7cf5590 HK |
454 | const char *con_id, void *data, |
455 | devcon_match_fn_t match) | |
456 | { | |
457 | return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match); | |
458 | } | |
459 | ||
23ead33b | 460 | int fwnode_connection_find_matches(const struct fwnode_handle *fwnode, |
7a20917d BA |
461 | const char *con_id, void *data, |
462 | devcon_match_fn_t match, | |
463 | void **matches, unsigned int matches_len); | |
464 | ||
59abd836 HK |
465 | /* -------------------------------------------------------------------------- */ |
466 | /* Software fwnode support - when HW description is incomplete or missing */ | |
467 | ||
80488a6b HK |
468 | /** |
469 | * struct software_node - Software node description | |
470 | * @name: Name of the software node | |
471 | * @parent: Parent of the software node | |
472 | * @properties: Array of device properties | |
473 | */ | |
474 | struct software_node { | |
475 | const char *name; | |
476 | const struct software_node *parent; | |
477 | const struct property_entry *properties; | |
478 | }; | |
479 | ||
59abd836 | 480 | bool is_software_node(const struct fwnode_handle *fwnode); |
56c9aa07 SA |
481 | const struct software_node * |
482 | to_software_node(const struct fwnode_handle *fwnode); | |
80488a6b HK |
483 | struct fwnode_handle *software_node_fwnode(const struct software_node *node); |
484 | ||
1666faed HK |
485 | const struct software_node * |
486 | software_node_find_by_name(const struct software_node *parent, | |
487 | const char *name); | |
488 | ||
02094d54 AS |
489 | int software_node_register_node_group(const struct software_node **node_group); |
490 | void software_node_unregister_node_group(const struct software_node **node_group); | |
491 | ||
80488a6b | 492 | int software_node_register(const struct software_node *node); |
46d26819 | 493 | void software_node_unregister(const struct software_node *node); |
59abd836 | 494 | |
59abd836 HK |
495 | struct fwnode_handle * |
496 | fwnode_create_software_node(const struct property_entry *properties, | |
497 | const struct fwnode_handle *parent); | |
498 | void fwnode_remove_software_node(struct fwnode_handle *fwnode); | |
499 | ||
2a92c90f | 500 | int device_add_software_node(struct device *dev, const struct software_node *node); |
e68d0119 HK |
501 | void device_remove_software_node(struct device *dev); |
502 | ||
151f6ff7 HK |
503 | int device_create_managed_software_node(struct device *dev, |
504 | const struct property_entry *properties, | |
505 | const struct software_node *parent); | |
506 | ||
b31384fa | 507 | #endif /* _LINUX_PROPERTY_H_ */ |