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