xref: /linux/include/linux/property.h (revision dc567f36f9adcb63b75c045a26b9dbb77c812472)
1 /* SPDX-License-Identifier: GPL-2.0-only */
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>
8  */
9 
10 #ifndef _LINUX_PROPERTY_H_
11 #define _LINUX_PROPERTY_H_
12 
13 #include <linux/args.h>
14 #include <linux/array_size.h>
15 #include <linux/bits.h>
16 #include <linux/cleanup.h>
17 #include <linux/fwnode.h>
18 #include <linux/stddef.h>
19 #include <linux/types.h>
20 #include <linux/util_macros.h>
21 
22 struct device;
23 
24 enum dev_prop_type {
25 	DEV_PROP_U8,
26 	DEV_PROP_U16,
27 	DEV_PROP_U32,
28 	DEV_PROP_U64,
29 	DEV_PROP_STRING,
30 	DEV_PROP_REF,
31 };
32 
33 const struct fwnode_handle *__dev_fwnode_const(const struct device *dev);
34 struct fwnode_handle *__dev_fwnode(struct device *dev);
35 #define dev_fwnode(dev)							\
36 	_Generic((dev),							\
37 		 const struct device *: __dev_fwnode_const,	\
38 		 struct device *: __dev_fwnode)(dev)
39 
40 bool device_property_present(const struct device *dev, const char *propname);
41 bool device_property_read_bool(const struct device *dev, const char *propname);
42 int device_property_read_u8_array(const struct device *dev, const char *propname,
43 				  u8 *val, size_t nval);
44 int device_property_read_u16_array(const struct device *dev, const char *propname,
45 				   u16 *val, size_t nval);
46 int device_property_read_u32_array(const struct device *dev, const char *propname,
47 				   u32 *val, size_t nval);
48 int device_property_read_u64_array(const struct device *dev, const char *propname,
49 				   u64 *val, size_t nval);
50 int device_property_read_string_array(const struct device *dev, const char *propname,
51 				      const char **val, size_t nval);
52 int device_property_read_string(const struct device *dev, const char *propname,
53 				const char **val);
54 int device_property_match_string(const struct device *dev,
55 				 const char *propname, const char *string);
56 
57 bool fwnode_property_present(const struct fwnode_handle *fwnode,
58 			     const char *propname);
59 bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
60 			     const char *propname);
61 int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
62 				  const char *propname, u8 *val,
63 				  size_t nval);
64 int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
65 				   const char *propname, u16 *val,
66 				   size_t nval);
67 int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
68 				   const char *propname, u32 *val,
69 				   size_t nval);
70 int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
71 				   const char *propname, u64 *val,
72 				   size_t nval);
73 int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
74 				      const char *propname, const char **val,
75 				      size_t nval);
76 int fwnode_property_read_string(const struct fwnode_handle *fwnode,
77 				const char *propname, const char **val);
78 int fwnode_property_match_string(const struct fwnode_handle *fwnode,
79 				 const char *propname, const char *string);
80 
81 bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
82 
fwnode_device_is_big_endian(const struct fwnode_handle * fwnode)83 static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode)
84 {
85 	if (fwnode_property_present(fwnode, "big-endian"))
86 		return true;
87 	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) &&
88 	    fwnode_property_present(fwnode, "native-endian"))
89 		return true;
90 	return false;
91 }
92 
93 static inline
fwnode_device_is_compatible(const struct fwnode_handle * fwnode,const char * compat)94 bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat)
95 {
96 	return fwnode_property_match_string(fwnode, "compatible", compat) >= 0;
97 }
98 
99 /**
100  * device_is_big_endian - check if a device has BE registers
101  * @dev: Pointer to the struct device
102  *
103  * Returns: true if the device has a "big-endian" property, or if the kernel
104  * was compiled for BE *and* the device has a "native-endian" property.
105  * Returns false otherwise.
106  *
107  * Callers would nominally use ioread32be/iowrite32be if
108  * device_is_big_endian() == true, or readl/writel otherwise.
109  */
device_is_big_endian(const struct device * dev)110 static inline bool device_is_big_endian(const struct device *dev)
111 {
112 	return fwnode_device_is_big_endian(dev_fwnode(dev));
113 }
114 
115 /**
116  * device_is_compatible - match 'compatible' property of the device with a given string
117  * @dev: Pointer to the struct device
118  * @compat: The string to match 'compatible' property with
119  *
120  * Returns: true if matches, otherwise false.
121  */
device_is_compatible(const struct device * dev,const char * compat)122 static inline bool device_is_compatible(const struct device *dev, const char *compat)
123 {
124 	return fwnode_device_is_compatible(dev_fwnode(dev), compat);
125 }
126 
127 int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
128 					  const char *propname,
129 					  const char * const *array, size_t n);
130 
131 static inline
device_property_match_property_string(const struct device * dev,const char * propname,const char * const * array,size_t n)132 int device_property_match_property_string(const struct device *dev,
133 					  const char *propname,
134 					  const char * const *array, size_t n)
135 {
136 	return fwnode_property_match_property_string(dev_fwnode(dev), propname, array, n);
137 }
138 
139 int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
140 				       const char *prop, const char *nargs_prop,
141 				       unsigned int nargs, unsigned int index,
142 				       struct fwnode_reference_args *args);
143 
144 struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
145 					    const char *name,
146 					    unsigned int index);
147 
148 const char *fwnode_get_name(const struct fwnode_handle *fwnode);
149 const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
150 bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name);
151 
152 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
153 struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
154 
155 #define fwnode_for_each_parent_node(fwnode, parent)		\
156 	for (parent = fwnode_get_parent(fwnode); parent;	\
157 	     parent = fwnode_get_next_parent(parent))
158 
159 unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
160 struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
161 					    unsigned int depth);
162 struct fwnode_handle *fwnode_get_next_child_node(
163 	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
164 struct fwnode_handle *fwnode_get_next_available_child_node(
165 	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
166 
167 #define fwnode_for_each_child_node(fwnode, child)			\
168 	for (child = fwnode_get_next_child_node(fwnode, NULL); child;	\
169 	     child = fwnode_get_next_child_node(fwnode, child))
170 
171 #define fwnode_for_each_named_child_node(fwnode, child, name)		\
172 	fwnode_for_each_child_node(fwnode, child)			\
173 		for_each_if(fwnode_name_eq(child, name))
174 
175 #define fwnode_for_each_available_child_node(fwnode, child)		       \
176 	for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
177 	     child = fwnode_get_next_available_child_node(fwnode, child))
178 
179 #define fwnode_for_each_child_node_scoped(fwnode, child)		\
180 	for (struct fwnode_handle *child __free(fwnode_handle) =	\
181 		fwnode_get_next_child_node(fwnode, NULL);		\
182 	     child; child = fwnode_get_next_child_node(fwnode, child))
183 
184 #define fwnode_for_each_available_child_node_scoped(fwnode, child)	\
185 	for (struct fwnode_handle *child __free(fwnode_handle) =	\
186 		fwnode_get_next_available_child_node(fwnode, NULL);	\
187 	     child; child = fwnode_get_next_available_child_node(fwnode, child))
188 
189 struct fwnode_handle *device_get_next_child_node(const struct device *dev,
190 						 struct fwnode_handle *child);
191 
192 #define device_for_each_child_node(dev, child)				\
193 	for (child = device_get_next_child_node(dev, NULL); child;	\
194 	     child = device_get_next_child_node(dev, child))
195 
196 #define device_for_each_named_child_node(dev, child, name)		\
197 	device_for_each_child_node(dev, child)				\
198 		for_each_if(fwnode_name_eq(child, name))
199 
200 #define device_for_each_child_node_scoped(dev, child)			\
201 	for (struct fwnode_handle *child __free(fwnode_handle) =	\
202 		device_get_next_child_node(dev, NULL);			\
203 	     child; child = device_get_next_child_node(dev, child))
204 
205 #define device_for_each_named_child_node_scoped(dev, child, name)	\
206 	device_for_each_child_node_scoped(dev, child)			\
207 		for_each_if(fwnode_name_eq(child, name))
208 
209 struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
210 						  const char *childname);
211 struct fwnode_handle *device_get_named_child_node(const struct device *dev,
212 						  const char *childname);
213 
214 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
215 
216 /**
217  * fwnode_handle_put - Drop reference to a device node
218  * @fwnode: Pointer to the device node to drop the reference to.
219  *
220  * This has to be used when terminating device_for_each_child_node() iteration
221  * with break or return to prevent stale device node references from being left
222  * behind.
223  */
fwnode_handle_put(struct fwnode_handle * fwnode)224 static inline void fwnode_handle_put(struct fwnode_handle *fwnode)
225 {
226 	fwnode_call_void_op(fwnode, put);
227 }
228 
229 DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T))
230 
231 int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
232 int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);
233 
234 unsigned int fwnode_get_child_node_count(const struct fwnode_handle *fwnode);
235 
device_get_child_node_count(const struct device * dev)236 static inline unsigned int device_get_child_node_count(const struct device *dev)
237 {
238 	return fwnode_get_child_node_count(dev_fwnode(dev));
239 }
240 
241 unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode,
242 					       const char *name);
device_get_named_child_node_count(const struct device * dev,const char * name)243 static inline unsigned int device_get_named_child_node_count(const struct device *dev,
244 							     const char *name)
245 {
246 	return fwnode_get_named_child_node_count(dev_fwnode(dev), name);
247 }
248 
device_property_read_u8(const struct device * dev,const char * propname,u8 * val)249 static inline int device_property_read_u8(const struct device *dev,
250 					  const char *propname, u8 *val)
251 {
252 	return device_property_read_u8_array(dev, propname, val, 1);
253 }
254 
device_property_read_u16(const struct device * dev,const char * propname,u16 * val)255 static inline int device_property_read_u16(const struct device *dev,
256 					   const char *propname, u16 *val)
257 {
258 	return device_property_read_u16_array(dev, propname, val, 1);
259 }
260 
device_property_read_u32(const struct device * dev,const char * propname,u32 * val)261 static inline int device_property_read_u32(const struct device *dev,
262 					   const char *propname, u32 *val)
263 {
264 	return device_property_read_u32_array(dev, propname, val, 1);
265 }
266 
device_property_read_u64(const struct device * dev,const char * propname,u64 * val)267 static inline int device_property_read_u64(const struct device *dev,
268 					   const char *propname, u64 *val)
269 {
270 	return device_property_read_u64_array(dev, propname, val, 1);
271 }
272 
device_property_count_u8(const struct device * dev,const char * propname)273 static inline int device_property_count_u8(const struct device *dev, const char *propname)
274 {
275 	return device_property_read_u8_array(dev, propname, NULL, 0);
276 }
277 
device_property_count_u16(const struct device * dev,const char * propname)278 static inline int device_property_count_u16(const struct device *dev, const char *propname)
279 {
280 	return device_property_read_u16_array(dev, propname, NULL, 0);
281 }
282 
device_property_count_u32(const struct device * dev,const char * propname)283 static inline int device_property_count_u32(const struct device *dev, const char *propname)
284 {
285 	return device_property_read_u32_array(dev, propname, NULL, 0);
286 }
287 
device_property_count_u64(const struct device * dev,const char * propname)288 static inline int device_property_count_u64(const struct device *dev, const char *propname)
289 {
290 	return device_property_read_u64_array(dev, propname, NULL, 0);
291 }
292 
device_property_string_array_count(const struct device * dev,const char * propname)293 static inline int device_property_string_array_count(const struct device *dev,
294 						     const char *propname)
295 {
296 	return device_property_read_string_array(dev, propname, NULL, 0);
297 }
298 
fwnode_property_read_u8(const struct fwnode_handle * fwnode,const char * propname,u8 * val)299 static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
300 					  const char *propname, u8 *val)
301 {
302 	return fwnode_property_read_u8_array(fwnode, propname, val, 1);
303 }
304 
fwnode_property_read_u16(const struct fwnode_handle * fwnode,const char * propname,u16 * val)305 static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
306 					   const char *propname, u16 *val)
307 {
308 	return fwnode_property_read_u16_array(fwnode, propname, val, 1);
309 }
310 
fwnode_property_read_u32(const struct fwnode_handle * fwnode,const char * propname,u32 * val)311 static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
312 					   const char *propname, u32 *val)
313 {
314 	return fwnode_property_read_u32_array(fwnode, propname, val, 1);
315 }
316 
fwnode_property_read_u64(const struct fwnode_handle * fwnode,const char * propname,u64 * val)317 static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
318 					   const char *propname, u64 *val)
319 {
320 	return fwnode_property_read_u64_array(fwnode, propname, val, 1);
321 }
322 
fwnode_property_count_u8(const struct fwnode_handle * fwnode,const char * propname)323 static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode,
324 					   const char *propname)
325 {
326 	return fwnode_property_read_u8_array(fwnode, propname, NULL, 0);
327 }
328 
fwnode_property_count_u16(const struct fwnode_handle * fwnode,const char * propname)329 static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode,
330 					    const char *propname)
331 {
332 	return fwnode_property_read_u16_array(fwnode, propname, NULL, 0);
333 }
334 
fwnode_property_count_u32(const struct fwnode_handle * fwnode,const char * propname)335 static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode,
336 					    const char *propname)
337 {
338 	return fwnode_property_read_u32_array(fwnode, propname, NULL, 0);
339 }
340 
fwnode_property_count_u64(const struct fwnode_handle * fwnode,const char * propname)341 static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode,
342 					    const char *propname)
343 {
344 	return fwnode_property_read_u64_array(fwnode, propname, NULL, 0);
345 }
346 
347 static inline int
fwnode_property_string_array_count(const struct fwnode_handle * fwnode,const char * propname)348 fwnode_property_string_array_count(const struct fwnode_handle *fwnode,
349 				   const char *propname)
350 {
351 	return fwnode_property_read_string_array(fwnode, propname, NULL, 0);
352 }
353 
354 struct software_node;
355 
356 /**
357  * struct software_node_ref_args - Reference property with additional arguments
358  * @swnode: Reference to a software node
359  * @fwnode: Alternative reference to a firmware node handle
360  * @nargs: Number of elements in @args array
361  * @args: Integer arguments
362  */
363 struct software_node_ref_args {
364 	const struct software_node *swnode;
365 	struct fwnode_handle *fwnode;
366 	unsigned int nargs;
367 	u64 args[NR_FWNODE_REFERENCE_ARGS];
368 };
369 
370 #define SOFTWARE_NODE_REFERENCE(_ref_, ...)			\
371 (const struct software_node_ref_args) {				\
372 	.swnode = _Generic(_ref_,				\
373 			   const struct software_node *: _ref_,	\
374 			   default: NULL),			\
375 	.fwnode = _Generic(_ref_,				\
376 			   struct fwnode_handle *: _ref_,	\
377 			   default: NULL),			\
378 	.nargs = COUNT_ARGS(__VA_ARGS__),			\
379 	.args = { __VA_ARGS__ },				\
380 }
381 
382 /**
383  * struct property_entry - "Built-in" device property representation.
384  * @name: Name of the property.
385  * @length: Length of data making up the value.
386  * @is_inline: True when the property value is stored inline.
387  * @type: Type of the data in unions.
388  * @pointer: Pointer to the property when it is not stored inline.
389  * @value: Value of the property when it is stored inline.
390  */
391 struct property_entry {
392 	const char *name;
393 	size_t length;
394 	bool is_inline;
395 	enum dev_prop_type type;
396 	union {
397 		const void *pointer;
398 		union {
399 			u8 u8_data[sizeof(u64) / sizeof(u8)];
400 			u16 u16_data[sizeof(u64) / sizeof(u16)];
401 			u32 u32_data[sizeof(u64) / sizeof(u32)];
402 			u64 u64_data[sizeof(u64) / sizeof(u64)];
403 			const char *str[sizeof(u64) / sizeof(char *)];
404 		} value;
405 	};
406 };
407 
408 /*
409  * Note: the below initializers for the anonymous union are carefully
410  * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
411  * and structs.
412  */
413 #define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)		\
414 (struct property_entry) {								\
415 	.name = _name_,									\
416 	.length = (_len_) * sizeof_field(struct property_entry, value._elem_[0]),	\
417 	.type = DEV_PROP_##_Type_,							\
418 	{ .pointer = _val_ },								\
419 }
420 
421 #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_)		\
422 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_)
423 #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_)		\
424 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_)
425 #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_)		\
426 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_)
427 #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_)		\
428 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_)
429 #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_)		\
430 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_)
431 
432 #define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_)		\
433 (struct property_entry) {						\
434 	.name = _name_,							\
435 	.length = (_len_) * sizeof(struct software_node_ref_args),	\
436 	.type = DEV_PROP_REF,						\
437 	{ .pointer = _val_ },						\
438 }
439 
440 #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_)				\
441 	PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
442 #define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_)				\
443 	PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
444 #define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_)				\
445 	PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
446 #define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_)				\
447 	PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
448 #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_)			\
449 	PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
450 #define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_)				\
451 	PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
452 
453 #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_)		\
454 (struct property_entry) {						\
455 	.name = _name_,							\
456 	.length = sizeof_field(struct property_entry, value._elem_[0]),	\
457 	.is_inline = true,						\
458 	.type = DEV_PROP_##_Type_,					\
459 	{ .value = { ._elem_[0] = _val_ } },				\
460 }
461 
462 #define PROPERTY_ENTRY_U8(_name_, _val_)				\
463 	__PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_)
464 #define PROPERTY_ENTRY_U16(_name_, _val_)				\
465 	__PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_)
466 #define PROPERTY_ENTRY_U32(_name_, _val_)				\
467 	__PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_)
468 #define PROPERTY_ENTRY_U64(_name_, _val_)				\
469 	__PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_)
470 #define PROPERTY_ENTRY_STRING(_name_, _val_)				\
471 	__PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_)
472 
473 #define PROPERTY_ENTRY_REF(_name_, _ref_, ...)				\
474 (struct property_entry) {						\
475 	.name = _name_,							\
476 	.length = sizeof(struct software_node_ref_args),		\
477 	.type = DEV_PROP_REF,						\
478 	{ .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), },	\
479 }
480 
481 #define PROPERTY_ENTRY_BOOL(_name_)		\
482 (struct property_entry) {			\
483 	.name = _name_,				\
484 	.is_inline = true,			\
485 }
486 
487 struct property_entry *
488 property_entries_dup(const struct property_entry *properties);
489 void property_entries_free(const struct property_entry *properties);
490 
491 bool device_dma_supported(const struct device *dev);
492 enum dev_dma_attr device_get_dma_attr(const struct device *dev);
493 
494 const void *device_get_match_data(const struct device *dev);
495 
496 int device_get_phy_mode(struct device *dev);
497 int fwnode_get_phy_mode(const struct fwnode_handle *fwnode);
498 
499 void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
500 
501 struct fwnode_handle *fwnode_graph_get_next_endpoint(
502 	const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
503 struct fwnode_handle *
504 fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
505 struct fwnode_handle *fwnode_graph_get_remote_port_parent(
506 	const struct fwnode_handle *fwnode);
507 struct fwnode_handle *fwnode_graph_get_remote_port(
508 	const struct fwnode_handle *fwnode);
509 struct fwnode_handle *fwnode_graph_get_remote_endpoint(
510 	const struct fwnode_handle *fwnode);
511 
fwnode_graph_is_endpoint(const struct fwnode_handle * fwnode)512 static inline bool fwnode_graph_is_endpoint(const struct fwnode_handle *fwnode)
513 {
514 	return fwnode_property_present(fwnode, "remote-endpoint");
515 }
516 
517 /*
518  * Fwnode lookup flags
519  *
520  * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the
521  *				closest endpoint ID greater than the specified
522  *				one.
523  * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote
524  *				  endpoint of the given endpoint belongs to,
525  *				  may be disabled, or that the endpoint is not
526  *				  connected.
527  */
528 #define FWNODE_GRAPH_ENDPOINT_NEXT	BIT(0)
529 #define FWNODE_GRAPH_DEVICE_DISABLED	BIT(1)
530 
531 struct fwnode_handle *
532 fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
533 				u32 port, u32 endpoint, unsigned long flags);
534 unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode,
535 					     unsigned long flags);
536 
537 #define fwnode_graph_for_each_endpoint(fwnode, child)				\
538 	for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child;	\
539 	     child = fwnode_graph_get_next_endpoint(fwnode, child))
540 
541 int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
542 				struct fwnode_endpoint *endpoint);
543 
544 typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id,
545 				   void *data);
546 
547 void *fwnode_connection_find_match(const struct fwnode_handle *fwnode,
548 				   const char *con_id, void *data,
549 				   devcon_match_fn_t match);
550 
device_connection_find_match(const struct device * dev,const char * con_id,void * data,devcon_match_fn_t match)551 static inline void *device_connection_find_match(const struct device *dev,
552 						 const char *con_id, void *data,
553 						 devcon_match_fn_t match)
554 {
555 	return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match);
556 }
557 
558 int fwnode_connection_find_matches(const struct fwnode_handle *fwnode,
559 				   const char *con_id, void *data,
560 				   devcon_match_fn_t match,
561 				   void **matches, unsigned int matches_len);
562 
563 /* -------------------------------------------------------------------------- */
564 /* Software fwnode support - when HW description is incomplete or missing */
565 
566 /**
567  * struct software_node - Software node description
568  * @name: Name of the software node
569  * @parent: Parent of the software node
570  * @properties: Array of device properties
571  */
572 struct software_node {
573 	const char *name;
574 	const struct software_node *parent;
575 	const struct property_entry *properties;
576 };
577 
578 #define SOFTWARE_NODE(_name_, _properties_, _parent_)	\
579 	(struct software_node) {			\
580 		.name = _name_,				\
581 		.properties = _properties_,		\
582 		.parent = _parent_,			\
583 	}
584 
585 bool is_software_node(const struct fwnode_handle *fwnode);
586 const struct software_node *
587 to_software_node(const struct fwnode_handle *fwnode);
588 struct fwnode_handle *software_node_fwnode(const struct software_node *node);
589 
590 const struct software_node *
591 software_node_find_by_name(const struct software_node *parent,
592 			   const char *name);
593 
594 int software_node_register_node_group(const struct software_node * const *node_group);
595 void software_node_unregister_node_group(const struct software_node * const *node_group);
596 
597 int software_node_register(const struct software_node *node);
598 void software_node_unregister(const struct software_node *node);
599 
600 struct fwnode_handle *
601 fwnode_create_software_node(const struct property_entry *properties,
602 			    const struct fwnode_handle *parent);
603 void fwnode_remove_software_node(struct fwnode_handle *fwnode);
604 
605 int device_add_software_node(struct device *dev, const struct software_node *node);
606 void device_remove_software_node(struct device *dev);
607 
608 int device_create_managed_software_node(struct device *dev,
609 					const struct property_entry *properties,
610 					const struct software_node *parent);
611 
612 #endif /* _LINUX_PROPERTY_H_ */
613