Lines Matching +full:string +full:- +full:array +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.
27 #include <linux/string.h>
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()
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.
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.
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.
168 * @sz_min: minimum number of array elements to read
169 * @sz_max: maximum number of array elements to read, if zero there is no
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.
178 * dts entry of array should be like:
179 * property = /bits/ 8 <0x50 0x60 0x70>;
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.
216 * @sz_min: minimum number of array elements to read
217 * @sz_max: maximum number of array elements to read, if zero there is no
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.
226 * dts entry of array should be like:
227 * property = /bits/ 16 <0x5000 0x6000 0x7000>;
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.
264 * @sz_min: minimum number of array elements to read
265 * @sz_max: maximum number of array elements to read, if zero there is no
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.
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.
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.
338 * @sz_min: minimum number of array elements to read
339 * @sz_max: maximum number of array elements to read, if zero there is no
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.
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.
382 * @out_string: pointer to null terminated return string, modified only if
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
412 * @string: pointer to string to search for in string list
414 * This function searches a string list property and returns the index
415 * of a specific string value.
418 const char *string) in of_property_match_string() argument
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()
437 pr_debug("comparing %s with %s\n", string, p); in of_property_match_string()
438 if (strcmp(string, p) == 0) 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.
449 * @out_strs: output array of string pointers.
450 * @sz: number of array elements to read.
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
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
574 if (of_node_cmp(port->name, "port") != 0) in of_graph_get_port_by_id()
588 * of_graph_get_next_endpoint() - get next endpoint node
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
657 * @port_reg: identifier (value of reg property) of the parent port node
658 * @reg: identifier (value of reg property) of the endpoint node
662 * ignored when they are -1.
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()
682 * of_graph_get_remote_endpoint() - get remote endpoint node
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
716 for (depth = 3; depth && node; depth--) { in of_graph_get_port_parent()
718 if (depth == 2 && of_node_cmp(node->name, "ports")) in of_graph_get_port_parent()
726 * of_graph_get_remote_port_parent() - get remote port's parent node
749 * of_graph_get_remote_port() - get remote port node
780 * of_graph_get_remote_node() - get remote parent device_node for given 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
860 return -ENXIO; in of_fwnode_property_read_int_array()
897 if (!of_node_cmp(child->name, childname)) 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()
959 if (of_node_cmp(np->name, "ports")) in of_fwnode_graph_get_port_parent()
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()