Lines Matching +full:bool +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.
35 * of_property_read_bool - Find a property
36 * @np: device node from which the property value is to be read.
37 * @propname: name of the property to be searched.
39 * Search for a boolean property in a device node. Usage on non-boolean
40 * property types is deprecated.
42 * Return: true if the property exists false otherwise.
44 bool of_property_read_bool(const struct device_node *np, const char *propname) in of_property_read_bool()
46 struct property *prop = of_find_property(np, propname, NULL); in of_property_read_bool()
49 * Boolean properties should not have a value. Testing for property in of_property_read_bool()
51 * property value and check the returned error code. in of_property_read_bool()
53 if (prop && prop->length) in of_property_read_bool()
54 pr_warn("%pOF: Read of boolean property '%s' with a value.\n", np, propname); in of_property_read_bool()
61 * of_graph_is_present() - check graph's presence
64 * Return: True if @node has a port or ports (with a port) sub-node,
67 bool of_graph_is_present(const struct device_node *node) in of_graph_is_present()
81 * of_property_count_elems_of_size - Count the number of elements in a property
83 * @np: device node from which the property value is to be read.
84 * @propname: name of the property to be searched.
87 * Search for a property in a device node and count the number of elements of
90 * Return: The number of elements on sucess, -EINVAL if the property does not
91 * exist or its length does not match a multiple of elem_size and -ENODATA if
92 * the property does not have a value.
97 const struct property *prop = of_find_property(np, propname, NULL); in of_property_count_elems_of_size()
100 return -EINVAL; in of_property_count_elems_of_size()
101 if (!prop->value) in of_property_count_elems_of_size()
102 return -ENODATA; in of_property_count_elems_of_size()
104 if (prop->length % elem_size != 0) { in of_property_count_elems_of_size()
107 return -EINVAL; in of_property_count_elems_of_size()
110 return prop->length / elem_size; in of_property_count_elems_of_size()
117 * @np: device node from which the property value is to be read.
118 * @propname: name of the property to be searched.
119 * @min: minimum allowed length of property value
120 * @max: maximum allowed length of property value (0 means unlimited)
123 * Search for a property in a device node and valid the requested size.
125 * Return: The property value on success, -EINVAL if the property does not
126 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
127 * property data is too small or too large.
133 const struct property *prop = of_find_property(np, propname, NULL); in of_find_property_value_of_size()
136 return ERR_PTR(-EINVAL); in of_find_property_value_of_size()
137 if (!prop->value) in of_find_property_value_of_size()
138 return ERR_PTR(-ENODATA); in of_find_property_value_of_size()
139 if (prop->length < min) in of_find_property_value_of_size()
140 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
141 if (max && prop->length > max) in of_find_property_value_of_size()
142 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
145 *len = prop->length; in of_find_property_value_of_size()
147 return prop->value; in of_find_property_value_of_size()
151 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
153 * @np: device node from which the property value is to be read.
154 * @propname: name of the property to be searched.
158 * Search for a property in a device node and read nth 32-bit value from
161 * Return: 0 on success, -EINVAL if the property does not exist,
162 * -ENODATA if property does not have a value, and -EOVERFLOW if the
163 * property data isn't large enough.
185 * of_property_read_u64_index - Find and read a u64 from a multi-value property.
187 * @np: device node from which the property value is to be read.
188 * @propname: name of the property to be searched.
192 * Search for a property in a device node and read nth 64-bit value from
195 * Return: 0 on success, -EINVAL if the property does not exist,
196 * -ENODATA if property does not have a value, and -EOVERFLOW if the
197 * property data isn't large enough.
218 * of_property_read_variable_u8_array - Find and read an array of u8 from a
219 * property, with bounds on the minimum and maximum array size.
221 * @np: device node from which the property value is to be read.
222 * @propname: name of the property to be searched.
229 * Search for a property in a device node and read 8-bit value(s) from
233 * ``property = /bits/ 8 <0x50 0x60 0x70>;``
235 * Return: The number of elements read on success, -EINVAL if the property
236 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
237 * if the property data is smaller than sz_min or longer than sz_max.
260 while (count--) in of_property_read_variable_u8_array()
268 * of_property_read_variable_u16_array - Find and read an array of u16 from a
269 * property, with bounds on the minimum and maximum array size.
271 * @np: device node from which the property value is to be read.
272 * @propname: name of the property to be searched.
279 * Search for a property in a device node and read 16-bit value(s) from
283 * ``property = /bits/ 16 <0x5000 0x6000 0x7000>;``
285 * Return: The number of elements read on success, -EINVAL if the property
286 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
287 * if the property data is smaller than sz_min or longer than sz_max.
310 while (count--) in of_property_read_variable_u16_array()
318 * of_property_read_variable_u32_array - Find and read an array of 32 bit
319 * integers from a property, with bounds on the minimum and maximum array size.
321 * @np: device node from which the property value is to be read.
322 * @propname: name of the property to be searched.
329 * Search for a property in a device node and read 32-bit value(s) from
332 * Return: The number of elements read on success, -EINVAL if the property
333 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
334 * if the property data is smaller than sz_min or longer than sz_max.
357 while (count--) in of_property_read_variable_u32_array()
365 * of_property_read_u64 - Find and read a 64 bit integer from a property
366 * @np: device node from which the property value is to be read.
367 * @propname: name of the property to be searched.
370 * Search for a property in a device node and read a 64-bit value from
373 * Return: 0 on success, -EINVAL if the property does not exist,
374 * -ENODATA if property does not have a value, and -EOVERFLOW if the
375 * property data isn't large enough.
396 * of_property_read_variable_u64_array - Find and read an array of 64 bit
397 * integers from a property, with bounds on the minimum and maximum array size.
399 * @np: device node from which the property value is to be read.
400 * @propname: name of the property to be searched.
407 * Search for a property in a device node and read 64-bit value(s) from
410 * Return: The number of elements read on success, -EINVAL if the property
411 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
412 * if the property data is smaller than sz_min or longer than sz_max.
435 while (count--) { in of_property_read_variable_u64_array()
445 * of_property_read_string - Find and read a string from a property
446 * @np: device node from which the property value is to be read.
447 * @propname: name of the property to be searched.
451 * Search for a property in a device tree node and retrieve a null
454 * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if
455 * property does not have a value, and -EILSEQ if the string is not
456 * null-terminated within the length of the property data.
458 * Note that the empty string "" has length of 1, thus -ENODATA cannot
466 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string()
469 return -EINVAL; in of_property_read_string()
470 if (!prop->length) in of_property_read_string()
471 return -ENODATA; in of_property_read_string()
472 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string()
473 return -EILSEQ; in of_property_read_string()
474 *out_string = prop->value; in of_property_read_string()
480 * of_property_match_string() - Find string in a list and return index
481 * @np: pointer to the node containing the string list property
482 * @propname: string list property name
485 * Search for an exact match of string in a device node property which is a
488 * Return: the index of the first occurrence of the string on success, -EINVAL
489 * if the property does not exist, -ENODATA if the property does not have a
490 * value, and -EILSEQ if the string is not null-terminated within the length of
491 * the property data.
496 const struct property *prop = of_find_property(np, propname, NULL); in of_property_match_string()
502 return -EINVAL; in of_property_match_string()
503 if (!prop->value) in of_property_match_string()
504 return -ENODATA; in of_property_match_string()
506 p = prop->value; in of_property_match_string()
507 end = p + prop->length; in of_property_match_string()
510 l = strnlen(p, end - p) + 1; in of_property_match_string()
512 return -EILSEQ; in of_property_match_string()
517 return -ENODATA; in of_property_match_string()
522 * of_property_read_string_helper() - Utility helper for parsing string properties
523 * @np: device node from which the property value is to be read.
524 * @propname: name of the property to be searched.
536 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string_helper()
541 return -EINVAL; in of_property_read_string_helper()
542 if (!prop->value) in of_property_read_string_helper()
543 return -ENODATA; in of_property_read_string_helper()
544 p = prop->value; in of_property_read_string_helper()
545 end = p + prop->length; in of_property_read_string_helper()
548 l = strnlen(p, end - p) + 1; in of_property_read_string_helper()
550 return -EILSEQ; in of_property_read_string_helper()
554 i -= skip; in of_property_read_string_helper()
555 return i <= 0 ? -ENODATA : i; in of_property_read_string_helper()
559 const __be32 *of_prop_next_u32(const struct property *prop, const __be32 *cur, in of_prop_next_u32()
568 curv = prop->value; in of_prop_next_u32()
573 if (curv >= prop->value + prop->length) in of_prop_next_u32()
582 const char *of_prop_next_string(const struct property *prop, const char *cur) in of_prop_next_string()
590 return prop->value; in of_prop_next_string()
593 if (curv >= prop->value + prop->length) in of_prop_next_string()
601 * of_graph_parse_endpoint() - parse common endpoint node properties
618 endpoint->local_node = node; in of_graph_parse_endpoint()
623 of_property_read_u32(port_node, "reg", &endpoint->port); in of_graph_parse_endpoint()
624 of_property_read_u32(node, "reg", &endpoint->id); in of_graph_parse_endpoint()
631 * of_graph_get_port_by_id() - get the port matching a given id
660 * of_graph_get_next_port() - get next port node.
697 * of_graph_get_next_port_endpoint() - get next endpoint node in port.
724 * of_graph_get_next_endpoint() - get next endpoint node
781 * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
783 * @port_reg: identifier (value of reg property) of the parent port node
784 * @reg: identifier (value of reg property) of the endpoint node
788 * ignored when they are -1. Use of_node_put() on the pointer when done.
798 if (((port_reg == -1) || (endpoint.port == port_reg)) && in of_graph_get_endpoint_by_regs()
799 ((reg == -1) || (endpoint.id == reg))) in of_graph_get_endpoint_by_regs()
808 * of_graph_get_remote_endpoint() - get remote endpoint node
817 return of_parse_phandle(node, "remote-endpoint", 0); in of_graph_get_remote_endpoint()
822 * of_graph_get_port_parent() - get port's parent node
842 for (depth = 3; depth && node; depth--) { in of_graph_get_port_parent()
845 !of_node_name_eq(node, "in-ports") && in of_graph_get_port_parent()
846 !of_node_name_eq(node, "out-ports")) in of_graph_get_port_parent()
854 * of_graph_get_remote_port_parent() - get remote port's parent node
872 * of_graph_get_remote_port() - get remote port node
891 * of_graph_get_endpoint_count() - get the number of endpoints in a device node
909 * of_graph_get_port_count() - get the number of port in a device or ports node
926 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
928 * @port: identifier (value of reg property) of the parent port node
929 * @endpoint: identifier (value of reg property) of the endpoint node
973 static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode) in of_fwnode_device_is_available()
978 static bool of_fwnode_device_dma_supported(const struct fwnode_handle *fwnode) in of_fwnode_device_dma_supported()
992 static bool of_fwnode_property_present(const struct fwnode_handle *fwnode, in of_fwnode_property_present()
998 static bool of_fwnode_property_read_bool(const struct fwnode_handle *fwnode, in of_fwnode_property_read_bool()
1026 return -ENXIO; in of_fwnode_property_read_int_array()
1043 return kbasename(to_of_node(fwnode)->full_name); in of_fwnode_get_name()
1049 if (!to_of_node(fwnode)->parent) in of_fwnode_get_name_prefix()
1106 args->nargs = of_args.args_count; in of_fwnode_get_reference_args()
1107 args->fwnode = of_fwnode_handle(of_args.np); in of_fwnode_get_reference_args()
1110 args->args[i] = i < of_args.args_count ? of_args.args[i] : 0; in of_fwnode_get_reference_args()
1153 endpoint->local_fwnode = fwnode; in of_fwnode_graph_parse_endpoint()
1155 of_property_read_u32(port_node, "reg", &endpoint->port); in of_fwnode_graph_parse_endpoint()
1156 of_property_read_u32(node, "reg", &endpoint->id); in of_fwnode_graph_parse_endpoint()
1176 if (of_fwnode_handle(tmp_np)->dev) in of_link_to_phandle()
1189 * parse_prop_cells - Property parsing function for suppliers
1192 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1195 * @list_name: Property name that is known to contain list of phandle(s) to
1197 * @cells_name: property name that specifies phandles' arguments count
1203 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1205 * - NULL if no phandle found at index
1238 return -1; in strcmp_suffix()
1239 return strcmp(str + len - suffix_len, suffix); in strcmp_suffix()
1243 * parse_suffix_prop_cells - Suffix property parsing function for suppliers
1246 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1249 * @suffix: Property suffix that is known to contain list of phandle(s) to
1251 * @cells_name: property name that specifies phandles' arguments count
1257 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1259 * - NULL if no phandle found at index
1286 * struct supplier_bindings - Property parsing functions for suppliers
1290 * parse_prop.np: Pointer to device node holding supplier phandle property
1291 * parse_prop.prop_name: Name of property holding a phandle value
1294 * @get_con_dev: If the consumer node containing the property is never converted
1299 * for this property.
1303 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1305 * - NULL if no phandle found at index
1311 bool optional;
1315 DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells")
1316 DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells")
1317 DEFINE_SIMPLE_PROP(iommus, "iommus", "#iommu-cells")
1318 DEFINE_SIMPLE_PROP(mboxes, "mboxes", "#mbox-cells")
1319 DEFINE_SIMPLE_PROP(io_channels, "io-channels", "#io-channel-cells")
1320 DEFINE_SIMPLE_PROP(io_backends, "io-backends", "#io-backend-cells")
1321 DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells")
1322 DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells")
1323 DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells")
1325 DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells")
1326 DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
1327 DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
1328 DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL)
1329 DEFINE_SIMPLE_PROP(pinctrl1, "pinctrl-1", NULL)
1330 DEFINE_SIMPLE_PROP(pinctrl2, "pinctrl-2", NULL)
1331 DEFINE_SIMPLE_PROP(pinctrl3, "pinctrl-3", NULL)
1332 DEFINE_SIMPLE_PROP(pinctrl4, "pinctrl-4", NULL)
1333 DEFINE_SIMPLE_PROP(pinctrl5, "pinctrl-5", NULL)
1334 DEFINE_SIMPLE_PROP(pinctrl6, "pinctrl-6", NULL)
1335 DEFINE_SIMPLE_PROP(pinctrl7, "pinctrl-7", NULL)
1336 DEFINE_SIMPLE_PROP(pinctrl8, "pinctrl-8", NULL)
1337 DEFINE_SIMPLE_PROP(pwms, "pwms", "#pwm-cells")
1338 DEFINE_SIMPLE_PROP(resets, "resets", "#reset-cells")
1342 DEFINE_SIMPLE_PROP(msi_parent, "msi-parent", "#msi-cells")
1343 DEFINE_SIMPLE_PROP(post_init_providers, "post-init-providers", NULL)
1344 DEFINE_SIMPLE_PROP(access_controllers, "access-controllers", "#access-controller-cells")
1345 DEFINE_SIMPLE_PROP(pses, "pses", "#pse-cells")
1346 DEFINE_SIMPLE_PROP(power_supplies, "power-supplies", NULL)
1347 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
1348 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
1353 if (!strcmp_suffix(prop_name, ",nr-gpios")) in parse_gpios()
1356 return parse_suffix_prop_cells(np, prop_name, index, "-gpios", in parse_gpios()
1357 "#gpio-cells"); in parse_gpios()
1363 if (strcmp(prop_name, "iommu-map")) in parse_iommu_maps()
1378 * Ignore node with gpio-hog property since its gpios are all provided in parse_gpio_compat()
1381 if (of_property_read_bool(np, "gpio-hog")) in parse_gpio_compat()
1384 if (of_parse_phandle_with_args(np, prop_name, "#gpio-cells", index, in parse_gpio_compat()
1400 strcmp(prop_name, "interrupts-extended")) in parse_interrupts()
1417 if (strcmp(prop_name, "interrupt-map")) in parse_interrupt_map()
1420 if (of_property_read_u32(np, "#interrupt-cells", &intcells)) in parse_interrupt_map()
1424 imap = of_get_property(np, "interrupt-map", &imaplen); in parse_interrupt_map()
1434 imap = of_irq_parse_imap_parent(imap, imap_end - imap, &sup_args); in parse_interrupt_map()
1451 /* Return NULL for index > 0 to signify end of remote-endpoints. */ in parse_remote_endpoint()
1452 if (index > 0 || strcmp(prop_name, "remote-endpoint")) in parse_remote_endpoint()
1509 * of_link_property - Create device links to suppliers listed in a property
1510 * @con_np: The consumer device tree node which contains the property
1511 * @prop_name: Name of property to be parsed
1513 * This function checks if the property @prop_name that is present in the
1532 bool matched = false; in of_link_property()
1535 while (!matched && s->parse_prop) { in of_link_property()
1536 if (s->optional && !fw_devlink_is_strict()) { in of_link_property()
1541 while ((phandle = s->parse_prop(con_np, prop_name, i))) { in of_link_property()
1543 s->get_con_dev ? s->get_con_dev(con_np) : of_node_get(con_np); in of_link_property()
1547 of_link_to_phandle(con_dev_np, phandle, s->fwlink_flags); in of_link_property()
1572 const struct property *p; in of_fwnode_add_links()
1579 return -EINVAL; in of_fwnode_add_links()
1582 of_link_property(con_np, p->name); in of_fwnode_add_links()