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_u16_index - Find and read a u16 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 16-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.
184 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
186 * @np: device node from which the property value is to be read.
187 * @propname: name of the property to be searched.
191 * Search for a property in a device node and read nth 32-bit value from
194 * Return: 0 on success, -EINVAL if the property does not exist,
195 * -ENODATA if property does not have a value, and -EOVERFLOW if the
196 * property data isn't large enough.
218 * of_property_read_u64_index - Find and read a u64 from a multi-value property.
220 * @np: device node from which the property value is to be read.
221 * @propname: name of the property to be searched.
225 * Search for a property in a device node and read nth 64-bit value from
228 * Return: 0 on success, -EINVAL if the property does not exist,
229 * -ENODATA if property does not have a value, and -EOVERFLOW if the
230 * property data isn't large enough.
251 * of_property_read_variable_u8_array - Find and read an array of u8 from a
252 * property, with bounds on the minimum and maximum array size.
254 * @np: device node from which the property value is to be read.
255 * @propname: name of the property to be searched.
262 * Search for a property in a device node and read 8-bit value(s) from
266 * ``property = /bits/ 8 <0x50 0x60 0x70>;``
268 * Return: The number of elements read on success, -EINVAL if the property
269 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
270 * if the property data is smaller than sz_min or longer than sz_max.
293 while (count--) in of_property_read_variable_u8_array()
301 * of_property_read_variable_u16_array - Find and read an array of u16 from a
302 * property, with bounds on the minimum and maximum array size.
304 * @np: device node from which the property value is to be read.
305 * @propname: name of the property to be searched.
312 * Search for a property in a device node and read 16-bit value(s) from
316 * ``property = /bits/ 16 <0x5000 0x6000 0x7000>;``
318 * Return: The number of elements read on success, -EINVAL if the property
319 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
320 * if the property data is smaller than sz_min or longer than sz_max.
343 while (count--) in of_property_read_variable_u16_array()
351 * of_property_read_variable_u32_array - Find and read an array of 32 bit
352 * integers from a property, with bounds on the minimum and maximum array size.
354 * @np: device node from which the property value is to be read.
355 * @propname: name of the property to be searched.
362 * Search for a property in a device node and read 32-bit value(s) from
365 * Return: The number of elements read on success, -EINVAL if the property
366 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
367 * if the property data is smaller than sz_min or longer than sz_max.
390 while (count--) in of_property_read_variable_u32_array()
398 * of_property_read_u64 - Find and read a 64 bit integer from a property
399 * @np: device node from which the property value is to be read.
400 * @propname: name of the property to be searched.
403 * Search for a property in a device node and read a 64-bit value from
406 * Return: 0 on success, -EINVAL if the property does not exist,
407 * -ENODATA if property does not have a value, and -EOVERFLOW if the
408 * property data isn't large enough.
429 * of_property_read_variable_u64_array - Find and read an array of 64 bit
430 * integers from a property, with bounds on the minimum and maximum array size.
432 * @np: device node from which the property value is to be read.
433 * @propname: name of the property to be searched.
440 * Search for a property in a device node and read 64-bit value(s) from
443 * Return: The number of elements read on success, -EINVAL if the property
444 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
445 * if the property data is smaller than sz_min or longer than sz_max.
468 while (count--) { in of_property_read_variable_u64_array()
478 * of_property_read_string - Find and read a string from a property
479 * @np: device node from which the property value is to be read.
480 * @propname: name of the property to be searched.
484 * Search for a property in a device tree node and retrieve a null
487 * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if
488 * property does not have a value, and -EILSEQ if the string is not
489 * null-terminated within the length of the property data.
491 * Note that the empty string "" has length of 1, thus -ENODATA cannot
499 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string()
502 return -EINVAL; in of_property_read_string()
503 if (!prop->length) in of_property_read_string()
504 return -ENODATA; in of_property_read_string()
505 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string()
506 return -EILSEQ; in of_property_read_string()
507 *out_string = prop->value; in of_property_read_string()
513 * of_property_match_string() - Find string in a list and return index
514 * @np: pointer to the node containing the string list property
515 * @propname: string list property name
518 * Search for an exact match of string in a device node property which is a
521 * Return: the index of the first occurrence of the string on success, -EINVAL
522 * if the property does not exist, -ENODATA if the property does not have a
523 * value, and -EILSEQ if the string is not null-terminated within the length of
524 * the property data.
529 const struct property *prop = of_find_property(np, propname, NULL); in of_property_match_string()
535 return -EINVAL; in of_property_match_string()
536 if (!prop->value) in of_property_match_string()
537 return -ENODATA; in of_property_match_string()
539 p = prop->value; in of_property_match_string()
540 end = p + prop->length; in of_property_match_string()
543 l = strnlen(p, end - p) + 1; in of_property_match_string()
545 return -EILSEQ; in of_property_match_string()
550 return -ENODATA; in of_property_match_string()
555 * of_property_read_string_helper() - Utility helper for parsing string properties
556 * @np: device node from which the property value is to be read.
557 * @propname: name of the property to be searched.
569 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string_helper()
574 return -EINVAL; in of_property_read_string_helper()
575 if (!prop->value) in of_property_read_string_helper()
576 return -ENODATA; in of_property_read_string_helper()
577 p = prop->value; in of_property_read_string_helper()
578 end = p + prop->length; in of_property_read_string_helper()
581 l = strnlen(p, end - p) + 1; in of_property_read_string_helper()
583 return -EILSEQ; in of_property_read_string_helper()
587 i -= skip; in of_property_read_string_helper()
588 return i <= 0 ? -ENODATA : i; in of_property_read_string_helper()
592 const __be32 *of_prop_next_u32(const struct property *prop, const __be32 *cur, in of_prop_next_u32()
601 curv = prop->value; in of_prop_next_u32()
606 if (curv >= prop->value + prop->length) in of_prop_next_u32()
615 const char *of_prop_next_string(const struct property *prop, const char *cur) in of_prop_next_string()
623 return prop->value; in of_prop_next_string()
626 if (curv >= prop->value + prop->length) in of_prop_next_string()
634 * of_graph_parse_endpoint() - parse common endpoint node properties
651 endpoint->local_node = node; in of_graph_parse_endpoint()
656 of_property_read_u32(port_node, "reg", &endpoint->port); in of_graph_parse_endpoint()
657 of_property_read_u32(node, "reg", &endpoint->id); in of_graph_parse_endpoint()
664 * of_graph_get_port_by_id() - get the port matching a given id
693 * of_graph_get_next_port() - get next port node.
730 * of_graph_get_next_port_endpoint() - get next endpoint node in port.
757 * of_graph_get_next_endpoint() - get next endpoint node
814 * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
816 * @port_reg: identifier (value of reg property) of the parent port node
817 * @reg: identifier (value of reg property) of the endpoint node
821 * ignored when they are -1. Use of_node_put() on the pointer when done.
831 if (((port_reg == -1) || (endpoint.port == port_reg)) && in of_graph_get_endpoint_by_regs()
832 ((reg == -1) || (endpoint.id == reg))) in of_graph_get_endpoint_by_regs()
841 * of_graph_get_remote_endpoint() - get remote endpoint node
850 return of_parse_phandle(node, "remote-endpoint", 0); in of_graph_get_remote_endpoint()
855 * of_graph_get_port_parent() - get port's parent node
875 for (depth = 3; depth && node; depth--) { in of_graph_get_port_parent()
878 !of_node_name_eq(node, "in-ports") && in of_graph_get_port_parent()
879 !of_node_name_eq(node, "out-ports")) in of_graph_get_port_parent()
887 * of_graph_get_remote_port_parent() - get remote port's parent node
905 * of_graph_get_remote_port() - get remote port node
924 * of_graph_get_endpoint_count() - get the number of endpoints in a device node
942 * of_graph_get_port_count() - get the number of port in a device or ports node
959 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
961 * @port: identifier (value of reg property) of the parent port node
962 * @endpoint: identifier (value of reg property) of the endpoint node
1006 static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode) in of_fwnode_device_is_available()
1011 static bool of_fwnode_device_dma_supported(const struct fwnode_handle *fwnode) in of_fwnode_device_dma_supported()
1025 static bool of_fwnode_property_present(const struct fwnode_handle *fwnode, in of_fwnode_property_present()
1031 static bool of_fwnode_property_read_bool(const struct fwnode_handle *fwnode, in of_fwnode_property_read_bool()
1059 return -ENXIO; in of_fwnode_property_read_int_array()
1076 return kbasename(to_of_node(fwnode)->full_name); in of_fwnode_get_name()
1082 if (!to_of_node(fwnode)->parent) in of_fwnode_get_name_prefix()
1139 args->nargs = of_args.args_count; in of_fwnode_get_reference_args()
1140 args->fwnode = of_fwnode_handle(of_args.np); in of_fwnode_get_reference_args()
1143 args->args[i] = i < of_args.args_count ? of_args.args[i] : 0; in of_fwnode_get_reference_args()
1186 endpoint->local_fwnode = fwnode; in of_fwnode_graph_parse_endpoint()
1188 of_property_read_u32(port_node, "reg", &endpoint->port); in of_fwnode_graph_parse_endpoint()
1189 of_property_read_u32(node, "reg", &endpoint->id); in of_fwnode_graph_parse_endpoint()
1209 if (of_fwnode_handle(tmp_np)->dev) in of_link_to_phandle()
1222 * parse_prop_cells - Property parsing function for suppliers
1225 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1228 * @list_name: Property name that is known to contain list of phandle(s) to
1230 * @cells_name: property name that specifies phandles' arguments count
1236 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1238 * - NULL if no phandle found at index
1271 return -1; in strcmp_suffix()
1272 return strcmp(str + len - suffix_len, suffix); in strcmp_suffix()
1276 * parse_suffix_prop_cells - Suffix property parsing function for suppliers
1279 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1282 * @suffix: Property suffix that is known to contain list of phandle(s) to
1284 * @cells_name: property name that specifies phandles' arguments count
1290 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1292 * - NULL if no phandle found at index
1319 * struct supplier_bindings - Property parsing functions for suppliers
1323 * parse_prop.np: Pointer to device node holding supplier phandle property
1324 * parse_prop.prop_name: Name of property holding a phandle value
1327 * @get_con_dev: If the consumer node containing the property is never converted
1332 * for this property.
1336 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1338 * - NULL if no phandle found at index
1344 bool optional;
1348 DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells")
1349 DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells")
1350 DEFINE_SIMPLE_PROP(iommus, "iommus", "#iommu-cells")
1351 DEFINE_SIMPLE_PROP(mboxes, "mboxes", "#mbox-cells")
1352 DEFINE_SIMPLE_PROP(io_channels, "io-channels", "#io-channel-cells")
1353 DEFINE_SIMPLE_PROP(io_backends, "io-backends", "#io-backend-cells")
1354 DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells")
1355 DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells")
1356 DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells")
1358 DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells")
1359 DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
1360 DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
1361 DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL)
1362 DEFINE_SIMPLE_PROP(pinctrl1, "pinctrl-1", NULL)
1363 DEFINE_SIMPLE_PROP(pinctrl2, "pinctrl-2", NULL)
1364 DEFINE_SIMPLE_PROP(pinctrl3, "pinctrl-3", NULL)
1365 DEFINE_SIMPLE_PROP(pinctrl4, "pinctrl-4", NULL)
1366 DEFINE_SIMPLE_PROP(pinctrl5, "pinctrl-5", NULL)
1367 DEFINE_SIMPLE_PROP(pinctrl6, "pinctrl-6", NULL)
1368 DEFINE_SIMPLE_PROP(pinctrl7, "pinctrl-7", NULL)
1369 DEFINE_SIMPLE_PROP(pinctrl8, "pinctrl-8", NULL)
1370 DEFINE_SIMPLE_PROP(pwms, "pwms", "#pwm-cells")
1371 DEFINE_SIMPLE_PROP(resets, "resets", "#reset-cells")
1375 DEFINE_SIMPLE_PROP(msi_parent, "msi-parent", "#msi-cells")
1376 DEFINE_SIMPLE_PROP(post_init_providers, "post-init-providers", NULL)
1377 DEFINE_SIMPLE_PROP(access_controllers, "access-controllers", "#access-controller-cells")
1378 DEFINE_SIMPLE_PROP(pses, "pses", "#pse-cells")
1379 DEFINE_SIMPLE_PROP(power_supplies, "power-supplies", NULL)
1380 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
1381 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
1386 if (!strcmp_suffix(prop_name, ",nr-gpios")) in parse_gpios()
1389 return parse_suffix_prop_cells(np, prop_name, index, "-gpios", in parse_gpios()
1390 "#gpio-cells"); in parse_gpios()
1396 if (strcmp(prop_name, "iommu-map")) in parse_iommu_maps()
1411 * Ignore node with gpio-hog property since its gpios are all provided in parse_gpio_compat()
1414 if (of_property_read_bool(np, "gpio-hog")) in parse_gpio_compat()
1417 if (of_parse_phandle_with_args(np, prop_name, "#gpio-cells", index, in parse_gpio_compat()
1433 strcmp(prop_name, "interrupts-extended")) in parse_interrupts()
1450 if (strcmp(prop_name, "interrupt-map")) in parse_interrupt_map()
1453 if (of_property_read_u32(np, "#interrupt-cells", &intcells)) in parse_interrupt_map()
1457 imap = of_get_property(np, "interrupt-map", &imaplen); in parse_interrupt_map()
1467 imap = of_irq_parse_imap_parent(imap, imap_end - imap, &sup_args); in parse_interrupt_map()
1484 /* Return NULL for index > 0 to signify end of remote-endpoints. */ in parse_remote_endpoint()
1485 if (index > 0 || strcmp(prop_name, "remote-endpoint")) in parse_remote_endpoint()
1542 * of_link_property - Create device links to suppliers listed in a property
1543 * @con_np: The consumer device tree node which contains the property
1544 * @prop_name: Name of property to be parsed
1546 * This function checks if the property @prop_name that is present in the
1565 bool matched = false; in of_link_property()
1568 while (!matched && s->parse_prop) { in of_link_property()
1569 if (s->optional && !fw_devlink_is_strict()) { in of_link_property()
1574 while ((phandle = s->parse_prop(con_np, prop_name, i))) { in of_link_property()
1576 s->get_con_dev ? s->get_con_dev(con_np) : of_node_get(con_np); in of_link_property()
1580 of_link_to_phandle(con_dev_np, phandle, s->fwlink_flags); in of_link_property()
1605 const struct property *p; in of_fwnode_add_links()
1612 return -EINVAL; in of_fwnode_add_links()
1615 of_link_property(con_np, p->name); in of_fwnode_add_links()