• Home
  • Raw
  • Download

Lines Matching +full:a +full:- +full:child +full:- +full:node +full:- +full:property

1 // SPDX-License-Identifier: GPL-2.0+
3 * drivers/of/property.c - Procedures for accessing and interpreting
7 * file contains the OF property as well as the OF graph interface
11 * Copyright (C) 1996-2005 Paul Mackerras.
32 * of_property_count_elems_of_size - Count the number of elements in a property
34 * @np: device node from which the property value is to be read.
35 * @propname: name of the property to be searched.
38 * Search for a property in a device node and count the number of elements of
39 * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
40 * property does not exist or its length does not match a multiple of elem_size
41 * and -ENODATA if the property does not have a value.
46 struct property *prop = of_find_property(np, propname, NULL); in of_property_count_elems_of_size()
49 return -EINVAL; in of_property_count_elems_of_size()
50 if (!prop->value) in of_property_count_elems_of_size()
51 return -ENODATA; in of_property_count_elems_of_size()
53 if (prop->length % elem_size != 0) { in of_property_count_elems_of_size()
54 pr_err("size of %s in node %pOF is not a multiple of %d\n", in of_property_count_elems_of_size()
56 return -EINVAL; in of_property_count_elems_of_size()
59 return prop->length / elem_size; in of_property_count_elems_of_size()
66 * @np: device node from which the property value is to be read.
67 * @propname: name of the property to be searched.
68 * @min: minimum allowed length of property value
69 * @max: maximum allowed length of property value (0 means unlimited)
72 * Search for a property in a device node and valid the requested size.
73 * Returns the property value on success, -EINVAL if the property does not
74 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
75 * property data is too small or too large.
81 struct property *prop = of_find_property(np, propname, NULL); in of_find_property_value_of_size()
84 return ERR_PTR(-EINVAL); in of_find_property_value_of_size()
85 if (!prop->value) in of_find_property_value_of_size()
86 return ERR_PTR(-ENODATA); in of_find_property_value_of_size()
87 if (prop->length < min) in of_find_property_value_of_size()
88 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
89 if (max && prop->length > max) in of_find_property_value_of_size()
90 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
93 *len = prop->length; in of_find_property_value_of_size()
95 return prop->value; in of_find_property_value_of_size()
99 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
101 * @np: device node from which the property value is to be read.
102 * @propname: name of the property to be searched.
106 * Search for a property in a device node and read nth 32-bit value from
107 * it. Returns 0 on success, -EINVAL if the property does not exist,
108 * -ENODATA if property does not have a value, and -EOVERFLOW if the
109 * property data isn't large enough.
111 * The out_value is modified only if a valid u32 value can be decoded.
131 * of_property_read_u64_index - Find and read a u64 from a multi-value property.
133 * @np: device node from which the property value is to be read.
134 * @propname: name of the property to be searched.
138 * Search for a property in a device node and read nth 64-bit value from
139 * it. Returns 0 on success, -EINVAL if the property does not exist,
140 * -ENODATA if property does not have a value, and -EOVERFLOW if the
141 * property data isn't large enough.
143 * The out_value is modified only if a valid u64 value can be decoded.
162 * of_property_read_variable_u8_array - Find and read an array of u8 from a
163 * property, with bounds on the minimum and maximum array size.
165 * @np: device node from which the property value is to be read.
166 * @propname: name of the property to be searched.
173 * Search for a property in a device node and read 8-bit value(s) from
174 * it. Returns number of elements read on success, -EINVAL if the property
175 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
176 * if the property data is smaller than sz_min or longer than sz_max.
179 * property = /bits/ 8 <0x50 0x60 0x70>;
181 * The out_values is modified only if a valid u8 value can be decoded.
202 while (count--) in of_property_read_variable_u8_array()
210 * of_property_read_variable_u16_array - Find and read an array of u16 from a
211 * property, with bounds on the minimum and maximum array size.
213 * @np: device node from which the property value is to be read.
214 * @propname: name of the property to be searched.
221 * Search for a property in a device node and read 16-bit value(s) from
222 * it. Returns number of elements read on success, -EINVAL if the property
223 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
224 * if the property data is smaller than sz_min or longer than sz_max.
227 * property = /bits/ 16 <0x5000 0x6000 0x7000>;
229 * The out_values is modified only if a valid u16 value can be decoded.
250 while (count--) in of_property_read_variable_u16_array()
258 * of_property_read_variable_u32_array - Find and read an array of 32 bit
259 * integers from a property, with bounds on the minimum and maximum array size.
261 * @np: device node from which the property value is to be read.
262 * @propname: name of the property to be searched.
269 * Search for a property in a device node and read 32-bit value(s) from
270 * it. Returns number of elements read on success, -EINVAL if the property
271 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
272 * if the property data is smaller than sz_min or longer than sz_max.
274 * The out_values is modified only if a valid u32 value can be decoded.
295 while (count--) in of_property_read_variable_u32_array()
303 * of_property_read_u64 - Find and read a 64 bit integer from a property
304 * @np: device node from which the property value is to be read.
305 * @propname: name of the property to be searched.
308 * Search for a property in a device node and read a 64-bit value from
309 * it. Returns 0 on success, -EINVAL if the property does not exist,
310 * -ENODATA if property does not have a value, and -EOVERFLOW if the
311 * property data isn't large enough.
313 * The out_value is modified only if a valid u64 value can be decoded.
332 * of_property_read_variable_u64_array - Find and read an array of 64 bit
333 * integers from a property, with bounds on the minimum and maximum array size.
335 * @np: device node from which the property value is to be read.
336 * @propname: name of the property to be searched.
343 * Search for a property in a device node and read 64-bit value(s) from
344 * it. Returns number of elements read on success, -EINVAL if the property
345 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
346 * if the property data is smaller than sz_min or longer than sz_max.
348 * The out_values is modified only if a valid u64 value can be decoded.
369 while (count--) { in of_property_read_variable_u64_array()
379 * of_property_read_string - Find and read a string from a property
380 * @np: device node from which the property value is to be read.
381 * @propname: name of the property to be searched.
385 * Search for a property in a device tree node and retrieve a null
386 * terminated string value (pointer to data, not a copy). Returns 0 on
387 * success, -EINVAL if the property does not exist, -ENODATA if property
388 * does not have a value, and -EILSEQ if the string is not null-terminated
389 * within the length of the property data.
391 * The out_string pointer is modified only if a valid string can be decoded.
396 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string()
398 return -EINVAL; in of_property_read_string()
399 if (!prop->value) in of_property_read_string()
400 return -ENODATA; in of_property_read_string()
401 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string()
402 return -EILSEQ; in of_property_read_string()
403 *out_string = prop->value; in of_property_read_string()
409 * of_property_match_string() - Find string in a list and return index
410 * @np: pointer to node containing string list property
411 * @propname: string list property name
414 * This function searches a string list property and returns the index
415 * of a specific string value.
420 const struct property *prop = of_find_property(np, propname, NULL); in of_property_match_string()
426 return -EINVAL; in of_property_match_string()
427 if (!prop->value) in of_property_match_string()
428 return -ENODATA; in of_property_match_string()
430 p = prop->value; in of_property_match_string()
431 end = p + prop->length; in of_property_match_string()
434 l = strnlen(p, end - p) + 1; in of_property_match_string()
436 return -EILSEQ; in of_property_match_string()
441 return -ENODATA; in of_property_match_string()
446 * of_property_read_string_helper() - Utility helper for parsing string properties
447 * @np: device node from which the property value is to be read.
448 * @propname: name of the property to be searched.
453 * Don't call this function directly. It is a utility helper for the
460 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string_helper()
465 return -EINVAL; in of_property_read_string_helper()
466 if (!prop->value) in of_property_read_string_helper()
467 return -ENODATA; in of_property_read_string_helper()
468 p = prop->value; in of_property_read_string_helper()
469 end = p + prop->length; in of_property_read_string_helper()
472 l = strnlen(p, end - p) + 1; in of_property_read_string_helper()
474 return -EILSEQ; in of_property_read_string_helper()
478 i -= skip; in of_property_read_string_helper()
479 return i <= 0 ? -ENODATA : i; in of_property_read_string_helper()
483 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, in of_prop_next_u32()
492 curv = prop->value; in of_prop_next_u32()
497 if (curv >= prop->value + prop->length) in of_prop_next_u32()
506 const char *of_prop_next_string(struct property *prop, const char *cur) in of_prop_next_string()
514 return prop->value; in of_prop_next_string()
517 if (curv >= prop->value + prop->length) in of_prop_next_string()
525 * of_graph_parse_endpoint() - parse common endpoint node properties
526 * @node: pointer to endpoint device_node
529 * The caller should hold a reference to @node.
531 int of_graph_parse_endpoint(const struct device_node *node, in of_graph_parse_endpoint() argument
534 struct device_node *port_node = of_get_parent(node); in of_graph_parse_endpoint()
536 WARN_ONCE(!port_node, "%s(): endpoint %pOF has no parent node\n", in of_graph_parse_endpoint()
537 __func__, node); in of_graph_parse_endpoint()
541 endpoint->local_node = node; in of_graph_parse_endpoint()
546 of_property_read_u32(port_node, "reg", &endpoint->port); in of_graph_parse_endpoint()
547 of_property_read_u32(node, "reg", &endpoint->id); in of_graph_parse_endpoint()
556 * of_graph_get_port_by_id() - get the port matching a given id
557 * @parent: pointer to the parent device node
560 * Return: A 'port' node pointer with refcount incremented. The caller
565 struct device_node *node, *port; in of_graph_get_port_by_id() local
567 node = of_get_child_by_name(parent, "ports"); in of_graph_get_port_by_id()
568 if (node) in of_graph_get_port_by_id()
569 parent = node; in of_graph_get_port_by_id()
574 if (of_node_cmp(port->name, "port") != 0) in of_graph_get_port_by_id()
581 of_node_put(node); in of_graph_get_port_by_id()
588 * of_graph_get_next_endpoint() - get next endpoint node
589 * @parent: pointer to the parent device node
590 * @prev: previous endpoint node, or NULL to get first
592 * Return: An 'endpoint' node pointer with refcount incremented. Refcount
593 * of the passed @prev node is decremented.
605 * Start by locating the port node. If no previous endpoint is specified in of_graph_get_next_endpoint()
606 * search for the first port node, otherwise get the previous endpoint in of_graph_get_next_endpoint()
607 * parent port node. in of_graph_get_next_endpoint()
610 struct device_node *node; in of_graph_get_next_endpoint() local
612 node = of_get_child_by_name(parent, "ports"); in of_graph_get_next_endpoint()
613 if (node) in of_graph_get_next_endpoint()
614 parent = node; in of_graph_get_next_endpoint()
617 of_node_put(node); in of_graph_get_next_endpoint()
620 pr_err("graph: no port node found in %pOF\n", parent); in of_graph_get_next_endpoint()
625 if (WARN_ONCE(!port, "%s(): endpoint %pOF has no parent node\n", in of_graph_get_next_endpoint()
632 * Now that we have a port node, get the next endpoint by in of_graph_get_next_endpoint()
633 * getting the next child. If the previous endpoint is NULL this in of_graph_get_next_endpoint()
634 * will return the first child. in of_graph_get_next_endpoint()
649 } while (of_node_cmp(port->name, "port")); in of_graph_get_next_endpoint()
655 * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
656 * @parent: pointer to the parent device node
657 * @port_reg: identifier (value of reg property) of the parent port node
658 * @reg: identifier (value of reg property) of the endpoint node
660 * Return: An 'endpoint' node pointer which is identified by reg and at the same
661 * is the child of a port node identified by port_reg. reg and port_reg are
662 * ignored when they are -1.
668 struct device_node *node = NULL; in of_graph_get_endpoint_by_regs() local
670 for_each_endpoint_of_node(parent, node) { in of_graph_get_endpoint_by_regs()
671 of_graph_parse_endpoint(node, &endpoint); in of_graph_get_endpoint_by_regs()
672 if (((port_reg == -1) || (endpoint.port == port_reg)) && in of_graph_get_endpoint_by_regs()
673 ((reg == -1) || (endpoint.id == reg))) in of_graph_get_endpoint_by_regs()
674 return node; in of_graph_get_endpoint_by_regs()
682 * of_graph_get_remote_endpoint() - get remote endpoint node
683 * @node: pointer to a local endpoint device_node
685 * Return: Remote endpoint node associated with remote endpoint node linked
686 * to @node. Use of_node_put() on it when done.
688 struct device_node *of_graph_get_remote_endpoint(const struct device_node *node) in of_graph_get_remote_endpoint() argument
690 /* Get remote endpoint node. */ in of_graph_get_remote_endpoint()
691 return of_parse_phandle(node, "remote-endpoint", 0); in of_graph_get_remote_endpoint()
696 * of_graph_get_port_parent() - get port's parent node
697 * @node: pointer to a local endpoint device_node
699 * Return: device node associated with endpoint node linked
700 * to @node. Use of_node_put() on it when done.
702 struct device_node *of_graph_get_port_parent(struct device_node *node) in of_graph_get_port_parent() argument
706 if (!node) in of_graph_get_port_parent()
710 * Preserve usecount for passed in node as of_get_next_parent() in of_graph_get_port_parent()
713 of_node_get(node); in of_graph_get_port_parent()
715 /* Walk 3 levels up only if there is 'ports' node. */ in of_graph_get_port_parent()
716 for (depth = 3; depth && node; depth--) { in of_graph_get_port_parent()
717 node = of_get_next_parent(node); in of_graph_get_port_parent()
718 if (depth == 2 && of_node_cmp(node->name, "ports")) in of_graph_get_port_parent()
721 return node; in of_graph_get_port_parent()
726 * of_graph_get_remote_port_parent() - get remote port's parent node
727 * @node: pointer to a local endpoint device_node
729 * Return: Remote device node associated with remote endpoint node linked
730 * to @node. Use of_node_put() on it when done.
733 const struct device_node *node) in of_graph_get_remote_port_parent() argument
737 /* Get remote endpoint node. */ in of_graph_get_remote_port_parent()
738 np = of_graph_get_remote_endpoint(node); in of_graph_get_remote_port_parent()
749 * of_graph_get_remote_port() - get remote port node
750 * @node: pointer to a local endpoint device_node
752 * Return: Remote port node associated with remote endpoint node linked
753 * to @node. Use of_node_put() on it when done.
755 struct device_node *of_graph_get_remote_port(const struct device_node *node) in of_graph_get_remote_port() argument
759 /* Get remote endpoint node. */ in of_graph_get_remote_port()
760 np = of_graph_get_remote_endpoint(node); in of_graph_get_remote_port()
780 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
781 * @node: pointer to parent device_node containing graph port/endpoint
782 * @port: identifier (value of reg property) of the parent port node
783 * @endpoint: identifier (value of reg property) of the endpoint node
785 * Return: Remote device node associated with remote endpoint node linked
786 * to @node. Use of_node_put() on it when done.
788 struct device_node *of_graph_get_remote_node(const struct device_node *node, in of_graph_get_remote_node() argument
793 endpoint_node = of_graph_get_endpoint_by_regs(node, port, endpoint); in of_graph_get_remote_node()
795 pr_debug("no valid endpoint (%d, %d) for node %pOF\n", in of_graph_get_remote_node()
796 port, endpoint, node); in of_graph_get_remote_node()
803 pr_debug("no valid remote node\n"); in of_graph_get_remote_node()
808 pr_debug("not available for remote node\n"); in of_graph_get_remote_node()
843 const struct device_node *node = to_of_node(fwnode); in of_fwnode_property_read_int_array() local
846 return of_property_count_elems_of_size(node, propname, in of_fwnode_property_read_int_array()
851 return of_property_read_u8_array(node, propname, val, nval); in of_fwnode_property_read_int_array()
853 return of_property_read_u16_array(node, propname, val, nval); in of_fwnode_property_read_int_array()
855 return of_property_read_u32_array(node, propname, val, nval); in of_fwnode_property_read_int_array()
857 return of_property_read_u64_array(node, propname, val, nval); in of_fwnode_property_read_int_array()
860 return -ENXIO; in of_fwnode_property_read_int_array()
868 const struct device_node *node = to_of_node(fwnode); in of_fwnode_property_read_string_array() local
871 of_property_read_string_array(node, propname, val, nval) : in of_fwnode_property_read_string_array()
872 of_property_count_strings(node, propname); in of_fwnode_property_read_string_array()
883 struct fwnode_handle *child) in of_fwnode_get_next_child_node() argument
886 to_of_node(child))); in of_fwnode_get_next_child_node()
893 const struct device_node *node = to_of_node(fwnode); in of_fwnode_get_named_child_node() local
894 struct device_node *child; in of_fwnode_get_named_child_node() local
896 for_each_available_child_of_node(node, child) in of_fwnode_get_named_child_node()
897 if (!of_node_cmp(child->name, childname)) in of_fwnode_get_named_child_node()
898 return of_fwnode_handle(child); in of_fwnode_get_named_child_node()
924 args->nargs = of_args.args_count; in of_fwnode_get_reference_args()
925 args->fwnode = of_fwnode_handle(of_args.np); in of_fwnode_get_reference_args()
928 args->args[i] = i < of_args.args_count ? of_args.args[i] : 0; in of_fwnode_get_reference_args()
958 /* Is this the "ports" node? If not, it's the port parent. */ in of_fwnode_graph_get_port_parent()
959 if (of_node_cmp(np->name, "ports")) in of_fwnode_graph_get_port_parent()
968 const struct device_node *node = to_of_node(fwnode); in of_fwnode_graph_parse_endpoint() local
969 struct device_node *port_node = of_get_parent(node); in of_fwnode_graph_parse_endpoint()
971 endpoint->local_fwnode = fwnode; in of_fwnode_graph_parse_endpoint()
973 of_property_read_u32(port_node, "reg", &endpoint->port); in of_fwnode_graph_parse_endpoint()
974 of_property_read_u32(node, "reg", &endpoint->id); in of_fwnode_graph_parse_endpoint()