2 * drivers/of/property.c - Procedures for accessing and interpreting
3 * Devicetree properties and graphs.
5 * Initially created by copying procedures from drivers/of/base.c. This
6 * file contains the OF property as well as the OF graph interface
9 * Paul Mackerras August 1996.
10 * Copyright (C) 1996-2005 Paul Mackerras.
12 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
13 * {engebret|bergner}@us.ibm.com
15 * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
17 * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version
23 * 2 of the License, or (at your option) any later version.
26 #define pr_fmt(fmt) "OF: " fmt
29 #include <linux/of_device.h>
30 #include <linux/of_graph.h>
31 #include <linux/string.h>
33 #include "of_private.h"
36 * of_property_count_elems_of_size - Count the number of elements in a property
38 * @np: device node from which the property value is to be read.
39 * @propname: name of the property to be searched.
40 * @elem_size: size of the individual element
42 * Search for a property in a device node and count the number of elements of
43 * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
44 * property does not exist or its length does not match a multiple of elem_size
45 * and -ENODATA if the property does not have a value.
47 int of_property_count_elems_of_size(const struct device_node
*np
,
48 const char *propname
, int elem_size
)
50 struct property
*prop
= of_find_property(np
, propname
, NULL
);
57 if (prop
->length
% elem_size
!= 0) {
58 pr_err("size of %s in node %pOF is not a multiple of %d\n",
59 propname
, np
, elem_size
);
63 return prop
->length
/ elem_size
;
65 EXPORT_SYMBOL_GPL(of_property_count_elems_of_size
);
68 * of_find_property_value_of_size
70 * @np: device node from which the property value is to be read.
71 * @propname: name of the property to be searched.
72 * @min: minimum allowed length of property value
73 * @max: maximum allowed length of property value (0 means unlimited)
74 * @len: if !=NULL, actual length is written to here
76 * Search for a property in a device node and valid the requested size.
77 * Returns the property value on success, -EINVAL if the property does not
78 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
79 * property data is too small or too large.
82 static void *of_find_property_value_of_size(const struct device_node
*np
,
83 const char *propname
, u32 min
, u32 max
, size_t *len
)
85 struct property
*prop
= of_find_property(np
, propname
, NULL
);
88 return ERR_PTR(-EINVAL
);
90 return ERR_PTR(-ENODATA
);
91 if (prop
->length
< min
)
92 return ERR_PTR(-EOVERFLOW
);
93 if (max
&& prop
->length
> max
)
94 return ERR_PTR(-EOVERFLOW
);
103 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
105 * @np: device node from which the property value is to be read.
106 * @propname: name of the property to be searched.
107 * @index: index of the u32 in the list of values
108 * @out_value: pointer to return value, modified only if no error.
110 * Search for a property in a device node and read nth 32-bit value from
111 * it. Returns 0 on success, -EINVAL if the property does not exist,
112 * -ENODATA if property does not have a value, and -EOVERFLOW if the
113 * property data isn't large enough.
115 * The out_value is modified only if a valid u32 value can be decoded.
117 int of_property_read_u32_index(const struct device_node
*np
,
118 const char *propname
,
119 u32 index
, u32
*out_value
)
121 const u32
*val
= of_find_property_value_of_size(np
, propname
,
122 ((index
+ 1) * sizeof(*out_value
)),
129 *out_value
= be32_to_cpup(((__be32
*)val
) + index
);
132 EXPORT_SYMBOL_GPL(of_property_read_u32_index
);
135 * of_property_read_u64_index - Find and read a u64 from a multi-value property.
137 * @np: device node from which the property value is to be read.
138 * @propname: name of the property to be searched.
139 * @index: index of the u64 in the list of values
140 * @out_value: pointer to return value, modified only if no error.
142 * Search for a property in a device node and read nth 64-bit value from
143 * it. Returns 0 on success, -EINVAL if the property does not exist,
144 * -ENODATA if property does not have a value, and -EOVERFLOW if the
145 * property data isn't large enough.
147 * The out_value is modified only if a valid u64 value can be decoded.
149 int of_property_read_u64_index(const struct device_node
*np
,
150 const char *propname
,
151 u32 index
, u64
*out_value
)
153 const u64
*val
= of_find_property_value_of_size(np
, propname
,
154 ((index
+ 1) * sizeof(*out_value
)),
160 *out_value
= be64_to_cpup(((__be64
*)val
) + index
);
163 EXPORT_SYMBOL_GPL(of_property_read_u64_index
);
166 * of_property_read_variable_u8_array - Find and read an array of u8 from a
167 * property, with bounds on the minimum and maximum array size.
169 * @np: device node from which the property value is to be read.
170 * @propname: name of the property to be searched.
171 * @out_values: pointer to return value, modified only if return value is 0.
172 * @sz_min: minimum number of array elements to read
173 * @sz_max: maximum number of array elements to read, if zero there is no
174 * upper limit on the number of elements in the dts entry but only
175 * sz_min will be read.
177 * Search for a property in a device node and read 8-bit value(s) from
178 * it. Returns number of elements read on success, -EINVAL if the property
179 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
180 * if the property data is smaller than sz_min or longer than sz_max.
182 * dts entry of array should be like:
183 * property = /bits/ 8 <0x50 0x60 0x70>;
185 * The out_values is modified only if a valid u8 value can be decoded.
187 int of_property_read_variable_u8_array(const struct device_node
*np
,
188 const char *propname
, u8
*out_values
,
189 size_t sz_min
, size_t sz_max
)
192 const u8
*val
= of_find_property_value_of_size(np
, propname
,
193 (sz_min
* sizeof(*out_values
)),
194 (sz_max
* sizeof(*out_values
)),
203 sz
/= sizeof(*out_values
);
207 *out_values
++ = *val
++;
211 EXPORT_SYMBOL_GPL(of_property_read_variable_u8_array
);
214 * of_property_read_variable_u16_array - Find and read an array of u16 from a
215 * property, with bounds on the minimum and maximum array size.
217 * @np: device node from which the property value is to be read.
218 * @propname: name of the property to be searched.
219 * @out_values: pointer to return value, modified only if return value is 0.
220 * @sz_min: minimum number of array elements to read
221 * @sz_max: maximum number of array elements to read, if zero there is no
222 * upper limit on the number of elements in the dts entry but only
223 * sz_min will be read.
225 * Search for a property in a device node and read 16-bit value(s) from
226 * it. Returns number of elements read on success, -EINVAL if the property
227 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
228 * if the property data is smaller than sz_min or longer than sz_max.
230 * dts entry of array should be like:
231 * property = /bits/ 16 <0x5000 0x6000 0x7000>;
233 * The out_values is modified only if a valid u16 value can be decoded.
235 int of_property_read_variable_u16_array(const struct device_node
*np
,
236 const char *propname
, u16
*out_values
,
237 size_t sz_min
, size_t sz_max
)
240 const __be16
*val
= of_find_property_value_of_size(np
, propname
,
241 (sz_min
* sizeof(*out_values
)),
242 (sz_max
* sizeof(*out_values
)),
251 sz
/= sizeof(*out_values
);
255 *out_values
++ = be16_to_cpup(val
++);
259 EXPORT_SYMBOL_GPL(of_property_read_variable_u16_array
);
262 * of_property_read_variable_u32_array - Find and read an array of 32 bit
263 * integers from a property, with bounds on the minimum and maximum array size.
265 * @np: device node from which the property value is to be read.
266 * @propname: name of the property to be searched.
267 * @out_values: pointer to return value, modified only if return value is 0.
268 * @sz_min: minimum number of array elements to read
269 * @sz_max: maximum number of array elements to read, if zero there is no
270 * upper limit on the number of elements in the dts entry but only
271 * sz_min will be read.
273 * Search for a property in a device node and read 32-bit value(s) from
274 * it. Returns number of elements read on success, -EINVAL if the property
275 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
276 * if the property data is smaller than sz_min or longer than sz_max.
278 * The out_values is modified only if a valid u32 value can be decoded.
280 int of_property_read_variable_u32_array(const struct device_node
*np
,
281 const char *propname
, u32
*out_values
,
282 size_t sz_min
, size_t sz_max
)
285 const __be32
*val
= of_find_property_value_of_size(np
, propname
,
286 (sz_min
* sizeof(*out_values
)),
287 (sz_max
* sizeof(*out_values
)),
296 sz
/= sizeof(*out_values
);
300 *out_values
++ = be32_to_cpup(val
++);
304 EXPORT_SYMBOL_GPL(of_property_read_variable_u32_array
);
307 * of_property_read_u64 - Find and read a 64 bit integer from a property
308 * @np: device node from which the property value is to be read.
309 * @propname: name of the property to be searched.
310 * @out_value: pointer to return value, modified only if return value is 0.
312 * Search for a property in a device node and read a 64-bit value from
313 * it. Returns 0 on success, -EINVAL if the property does not exist,
314 * -ENODATA if property does not have a value, and -EOVERFLOW if the
315 * property data isn't large enough.
317 * The out_value is modified only if a valid u64 value can be decoded.
319 int of_property_read_u64(const struct device_node
*np
, const char *propname
,
322 const __be32
*val
= of_find_property_value_of_size(np
, propname
,
330 *out_value
= of_read_number(val
, 2);
333 EXPORT_SYMBOL_GPL(of_property_read_u64
);
336 * of_property_read_variable_u64_array - Find and read an array of 64 bit
337 * integers from a property, with bounds on the minimum and maximum array size.
339 * @np: device node from which the property value is to be read.
340 * @propname: name of the property to be searched.
341 * @out_values: pointer to return value, modified only if return value is 0.
342 * @sz_min: minimum number of array elements to read
343 * @sz_max: maximum number of array elements to read, if zero there is no
344 * upper limit on the number of elements in the dts entry but only
345 * sz_min will be read.
347 * Search for a property in a device node and read 64-bit value(s) from
348 * it. Returns number of elements read on success, -EINVAL if the property
349 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
350 * if the property data is smaller than sz_min or longer than sz_max.
352 * The out_values is modified only if a valid u64 value can be decoded.
354 int of_property_read_variable_u64_array(const struct device_node
*np
,
355 const char *propname
, u64
*out_values
,
356 size_t sz_min
, size_t sz_max
)
359 const __be32
*val
= of_find_property_value_of_size(np
, propname
,
360 (sz_min
* sizeof(*out_values
)),
361 (sz_max
* sizeof(*out_values
)),
370 sz
/= sizeof(*out_values
);
374 *out_values
++ = of_read_number(val
, 2);
380 EXPORT_SYMBOL_GPL(of_property_read_variable_u64_array
);
383 * of_property_read_string - Find and read a string from a property
384 * @np: device node from which the property value is to be read.
385 * @propname: name of the property to be searched.
386 * @out_string: pointer to null terminated return string, modified only if
389 * Search for a property in a device tree node and retrieve a null
390 * terminated string value (pointer to data, not a copy). Returns 0 on
391 * success, -EINVAL if the property does not exist, -ENODATA if property
392 * does not have a value, and -EILSEQ if the string is not null-terminated
393 * within the length of the property data.
395 * The out_string pointer is modified only if a valid string can be decoded.
397 int of_property_read_string(const struct device_node
*np
, const char *propname
,
398 const char **out_string
)
400 const struct property
*prop
= of_find_property(np
, propname
, NULL
);
405 if (strnlen(prop
->value
, prop
->length
) >= prop
->length
)
407 *out_string
= prop
->value
;
410 EXPORT_SYMBOL_GPL(of_property_read_string
);
413 * of_property_match_string() - Find string in a list and return index
414 * @np: pointer to node containing string list property
415 * @propname: string list property name
416 * @string: pointer to string to search for in string list
418 * This function searches a string list property and returns the index
419 * of a specific string value.
421 int of_property_match_string(const struct device_node
*np
, const char *propname
,
424 const struct property
*prop
= of_find_property(np
, propname
, NULL
);
435 end
= p
+ prop
->length
;
437 for (i
= 0; p
< end
; i
++, p
+= l
) {
438 l
= strnlen(p
, end
- p
) + 1;
441 pr_debug("comparing %s with %s\n", string
, p
);
442 if (strcmp(string
, p
) == 0)
443 return i
; /* Found it; return index */
447 EXPORT_SYMBOL_GPL(of_property_match_string
);
450 * of_property_read_string_helper() - Utility helper for parsing string properties
451 * @np: device node from which the property value is to be read.
452 * @propname: name of the property to be searched.
453 * @out_strs: output array of string pointers.
454 * @sz: number of array elements to read.
455 * @skip: Number of strings to skip over at beginning of list.
457 * Don't call this function directly. It is a utility helper for the
458 * of_property_read_string*() family of functions.
460 int of_property_read_string_helper(const struct device_node
*np
,
461 const char *propname
, const char **out_strs
,
464 const struct property
*prop
= of_find_property(np
, propname
, NULL
);
473 end
= p
+ prop
->length
;
475 for (i
= 0; p
< end
&& (!out_strs
|| i
< skip
+ sz
); i
++, p
+= l
) {
476 l
= strnlen(p
, end
- p
) + 1;
479 if (out_strs
&& i
>= skip
)
483 return i
<= 0 ? -ENODATA
: i
;
485 EXPORT_SYMBOL_GPL(of_property_read_string_helper
);
487 const __be32
*of_prop_next_u32(struct property
*prop
, const __be32
*cur
,
490 const void *curv
= cur
;
500 curv
+= sizeof(*cur
);
501 if (curv
>= prop
->value
+ prop
->length
)
505 *pu
= be32_to_cpup(curv
);
508 EXPORT_SYMBOL_GPL(of_prop_next_u32
);
510 const char *of_prop_next_string(struct property
*prop
, const char *cur
)
512 const void *curv
= cur
;
520 curv
+= strlen(cur
) + 1;
521 if (curv
>= prop
->value
+ prop
->length
)
526 EXPORT_SYMBOL_GPL(of_prop_next_string
);
529 * of_graph_parse_endpoint() - parse common endpoint node properties
530 * @node: pointer to endpoint device_node
531 * @endpoint: pointer to the OF endpoint data structure
533 * The caller should hold a reference to @node.
535 int of_graph_parse_endpoint(const struct device_node
*node
,
536 struct of_endpoint
*endpoint
)
538 struct device_node
*port_node
= of_get_parent(node
);
540 WARN_ONCE(!port_node
, "%s(): endpoint %pOF has no parent node\n",
543 memset(endpoint
, 0, sizeof(*endpoint
));
545 endpoint
->local_node
= node
;
547 * It doesn't matter whether the two calls below succeed.
548 * If they don't then the default value 0 is used.
550 of_property_read_u32(port_node
, "reg", &endpoint
->port
);
551 of_property_read_u32(node
, "reg", &endpoint
->id
);
553 of_node_put(port_node
);
557 EXPORT_SYMBOL(of_graph_parse_endpoint
);
560 * of_graph_get_port_by_id() - get the port matching a given id
561 * @parent: pointer to the parent device node
562 * @id: id of the port
564 * Return: A 'port' node pointer with refcount incremented. The caller
565 * has to use of_node_put() on it when done.
567 struct device_node
*of_graph_get_port_by_id(struct device_node
*parent
, u32 id
)
569 struct device_node
*node
, *port
;
571 node
= of_get_child_by_name(parent
, "ports");
575 for_each_child_of_node(parent
, port
) {
578 if (of_node_cmp(port
->name
, "port") != 0)
580 of_property_read_u32(port
, "reg", &port_id
);
589 EXPORT_SYMBOL(of_graph_get_port_by_id
);
592 * of_graph_get_next_endpoint() - get next endpoint node
593 * @parent: pointer to the parent device node
594 * @prev: previous endpoint node, or NULL to get first
596 * Return: An 'endpoint' node pointer with refcount incremented. Refcount
597 * of the passed @prev node is decremented.
599 struct device_node
*of_graph_get_next_endpoint(const struct device_node
*parent
,
600 struct device_node
*prev
)
602 struct device_node
*endpoint
;
603 struct device_node
*port
;
609 * Start by locating the port node. If no previous endpoint is specified
610 * search for the first port node, otherwise get the previous endpoint
614 struct device_node
*node
;
616 node
= of_get_child_by_name(parent
, "ports");
620 port
= of_get_child_by_name(parent
, "port");
624 pr_err("graph: no port node found in %pOF\n", parent
);
628 port
= of_get_parent(prev
);
629 if (WARN_ONCE(!port
, "%s(): endpoint %pOF has no parent node\n",
636 * Now that we have a port node, get the next endpoint by
637 * getting the next child. If the previous endpoint is NULL this
638 * will return the first child.
640 endpoint
= of_get_next_child(port
, prev
);
646 /* No more endpoints under this port, try the next one. */
650 port
= of_get_next_child(parent
, port
);
653 } while (of_node_cmp(port
->name
, "port"));
656 EXPORT_SYMBOL(of_graph_get_next_endpoint
);
659 * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
660 * @parent: pointer to the parent device node
661 * @port_reg: identifier (value of reg property) of the parent port node
662 * @reg: identifier (value of reg property) of the endpoint node
664 * Return: An 'endpoint' node pointer which is identified by reg and at the same
665 * is the child of a port node identified by port_reg. reg and port_reg are
666 * ignored when they are -1.
668 struct device_node
*of_graph_get_endpoint_by_regs(
669 const struct device_node
*parent
, int port_reg
, int reg
)
671 struct of_endpoint endpoint
;
672 struct device_node
*node
= NULL
;
674 for_each_endpoint_of_node(parent
, node
) {
675 of_graph_parse_endpoint(node
, &endpoint
);
676 if (((port_reg
== -1) || (endpoint
.port
== port_reg
)) &&
677 ((reg
== -1) || (endpoint
.id
== reg
)))
683 EXPORT_SYMBOL(of_graph_get_endpoint_by_regs
);
686 * of_graph_get_remote_endpoint() - get remote endpoint node
687 * @node: pointer to a local endpoint device_node
689 * Return: Remote endpoint node associated with remote endpoint node linked
690 * to @node. Use of_node_put() on it when done.
692 struct device_node
*of_graph_get_remote_endpoint(const struct device_node
*node
)
694 /* Get remote endpoint node. */
695 return of_parse_phandle(node
, "remote-endpoint", 0);
697 EXPORT_SYMBOL(of_graph_get_remote_endpoint
);
700 * of_graph_get_port_parent() - get port's parent node
701 * @node: pointer to a local endpoint device_node
703 * Return: device node associated with endpoint node linked
704 * to @node. Use of_node_put() on it when done.
706 struct device_node
*of_graph_get_port_parent(struct device_node
*node
)
714 * Preserve usecount for passed in node as of_get_next_parent()
715 * will do of_node_put() on it.
719 /* Walk 3 levels up only if there is 'ports' node. */
720 for (depth
= 3; depth
&& node
; depth
--) {
721 node
= of_get_next_parent(node
);
722 if (depth
== 2 && of_node_cmp(node
->name
, "ports"))
727 EXPORT_SYMBOL(of_graph_get_port_parent
);
730 * of_graph_get_remote_port_parent() - get remote port's parent node
731 * @node: pointer to a local endpoint device_node
733 * Return: Remote device node associated with remote endpoint node linked
734 * to @node. Use of_node_put() on it when done.
736 struct device_node
*of_graph_get_remote_port_parent(
737 const struct device_node
*node
)
739 struct device_node
*np
, *pp
;
741 /* Get remote endpoint node. */
742 np
= of_graph_get_remote_endpoint(node
);
744 pp
= of_graph_get_port_parent(np
);
750 EXPORT_SYMBOL(of_graph_get_remote_port_parent
);
753 * of_graph_get_remote_port() - get remote port node
754 * @node: pointer to a local endpoint device_node
756 * Return: Remote port node associated with remote endpoint node linked
757 * to @node. Use of_node_put() on it when done.
759 struct device_node
*of_graph_get_remote_port(const struct device_node
*node
)
761 struct device_node
*np
;
763 /* Get remote endpoint node. */
764 np
= of_graph_get_remote_endpoint(node
);
767 return of_get_next_parent(np
);
769 EXPORT_SYMBOL(of_graph_get_remote_port
);
771 int of_graph_get_endpoint_count(const struct device_node
*np
)
773 struct device_node
*endpoint
;
776 for_each_endpoint_of_node(np
, endpoint
)
781 EXPORT_SYMBOL(of_graph_get_endpoint_count
);
784 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
785 * @node: pointer to parent device_node containing graph port/endpoint
786 * @port: identifier (value of reg property) of the parent port node
787 * @endpoint: identifier (value of reg property) of the endpoint node
789 * Return: Remote device node associated with remote endpoint node linked
790 * to @node. Use of_node_put() on it when done.
792 struct device_node
*of_graph_get_remote_node(const struct device_node
*node
,
793 u32 port
, u32 endpoint
)
795 struct device_node
*endpoint_node
, *remote
;
797 endpoint_node
= of_graph_get_endpoint_by_regs(node
, port
, endpoint
);
798 if (!endpoint_node
) {
799 pr_debug("no valid endpoint (%d, %d) for node %pOF\n",
800 port
, endpoint
, node
);
804 remote
= of_graph_get_remote_port_parent(endpoint_node
);
805 of_node_put(endpoint_node
);
807 pr_debug("no valid remote node\n");
811 if (!of_device_is_available(remote
)) {
812 pr_debug("not available for remote node\n");
818 EXPORT_SYMBOL(of_graph_get_remote_node
);
820 static struct fwnode_handle
*of_fwnode_get(struct fwnode_handle
*fwnode
)
822 return of_fwnode_handle(of_node_get(to_of_node(fwnode
)));
825 static void of_fwnode_put(struct fwnode_handle
*fwnode
)
827 of_node_put(to_of_node(fwnode
));
830 static bool of_fwnode_device_is_available(const struct fwnode_handle
*fwnode
)
832 return of_device_is_available(to_of_node(fwnode
));
835 static bool of_fwnode_property_present(const struct fwnode_handle
*fwnode
,
836 const char *propname
)
838 return of_property_read_bool(to_of_node(fwnode
), propname
);
841 static int of_fwnode_property_read_int_array(const struct fwnode_handle
*fwnode
,
842 const char *propname
,
843 unsigned int elem_size
, void *val
,
846 const struct device_node
*node
= to_of_node(fwnode
);
849 return of_property_count_elems_of_size(node
, propname
,
854 return of_property_read_u8_array(node
, propname
, val
, nval
);
856 return of_property_read_u16_array(node
, propname
, val
, nval
);
858 return of_property_read_u32_array(node
, propname
, val
, nval
);
860 return of_property_read_u64_array(node
, propname
, val
, nval
);
867 of_fwnode_property_read_string_array(const struct fwnode_handle
*fwnode
,
868 const char *propname
, const char **val
,
871 const struct device_node
*node
= to_of_node(fwnode
);
874 of_property_read_string_array(node
, propname
, val
, nval
) :
875 of_property_count_strings(node
, propname
);
878 static struct fwnode_handle
*
879 of_fwnode_get_parent(const struct fwnode_handle
*fwnode
)
881 return of_fwnode_handle(of_get_parent(to_of_node(fwnode
)));
884 static struct fwnode_handle
*
885 of_fwnode_get_next_child_node(const struct fwnode_handle
*fwnode
,
886 struct fwnode_handle
*child
)
888 return of_fwnode_handle(of_get_next_available_child(to_of_node(fwnode
),
892 static struct fwnode_handle
*
893 of_fwnode_get_named_child_node(const struct fwnode_handle
*fwnode
,
894 const char *childname
)
896 const struct device_node
*node
= to_of_node(fwnode
);
897 struct device_node
*child
;
899 for_each_available_child_of_node(node
, child
)
900 if (!of_node_cmp(child
->name
, childname
))
901 return of_fwnode_handle(child
);
907 of_fwnode_get_reference_args(const struct fwnode_handle
*fwnode
,
908 const char *prop
, const char *nargs_prop
,
909 unsigned int nargs
, unsigned int index
,
910 struct fwnode_reference_args
*args
)
912 struct of_phandle_args of_args
;
917 ret
= of_parse_phandle_with_args(to_of_node(fwnode
), prop
,
918 nargs_prop
, index
, &of_args
);
920 ret
= of_parse_phandle_with_fixed_args(to_of_node(fwnode
), prop
,
921 nargs
, index
, &of_args
);
927 args
->nargs
= of_args
.args_count
;
928 args
->fwnode
= of_fwnode_handle(of_args
.np
);
930 for (i
= 0; i
< NR_FWNODE_REFERENCE_ARGS
; i
++)
931 args
->args
[i
] = i
< of_args
.args_count
? of_args
.args
[i
] : 0;
936 static struct fwnode_handle
*
937 of_fwnode_graph_get_next_endpoint(const struct fwnode_handle
*fwnode
,
938 struct fwnode_handle
*prev
)
940 return of_fwnode_handle(of_graph_get_next_endpoint(to_of_node(fwnode
),
944 static struct fwnode_handle
*
945 of_fwnode_graph_get_remote_endpoint(const struct fwnode_handle
*fwnode
)
947 return of_fwnode_handle(
948 of_graph_get_remote_endpoint(to_of_node(fwnode
)));
951 static struct fwnode_handle
*
952 of_fwnode_graph_get_port_parent(struct fwnode_handle
*fwnode
)
954 struct device_node
*np
;
956 /* Get the parent of the port */
957 np
= of_get_parent(to_of_node(fwnode
));
961 /* Is this the "ports" node? If not, it's the port parent. */
962 if (of_node_cmp(np
->name
, "ports"))
963 return of_fwnode_handle(np
);
965 return of_fwnode_handle(of_get_next_parent(np
));
968 static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle
*fwnode
,
969 struct fwnode_endpoint
*endpoint
)
971 const struct device_node
*node
= to_of_node(fwnode
);
972 struct device_node
*port_node
= of_get_parent(node
);
974 endpoint
->local_fwnode
= fwnode
;
976 of_property_read_u32(port_node
, "reg", &endpoint
->port
);
977 of_property_read_u32(node
, "reg", &endpoint
->id
);
979 of_node_put(port_node
);
984 const struct fwnode_operations of_fwnode_ops
= {
985 .get
= of_fwnode_get
,
986 .put
= of_fwnode_put
,
987 .device_is_available
= of_fwnode_device_is_available
,
988 .property_present
= of_fwnode_property_present
,
989 .property_read_int_array
= of_fwnode_property_read_int_array
,
990 .property_read_string_array
= of_fwnode_property_read_string_array
,
991 .get_parent
= of_fwnode_get_parent
,
992 .get_next_child_node
= of_fwnode_get_next_child_node
,
993 .get_named_child_node
= of_fwnode_get_named_child_node
,
994 .get_reference_args
= of_fwnode_get_reference_args
,
995 .graph_get_next_endpoint
= of_fwnode_graph_get_next_endpoint
,
996 .graph_get_remote_endpoint
= of_fwnode_graph_get_remote_endpoint
,
997 .graph_get_port_parent
= of_fwnode_graph_get_port_parent
,
998 .graph_parse_endpoint
= of_fwnode_graph_parse_endpoint
,
1000 EXPORT_SYMBOL_GPL(of_fwnode_ops
);