Lines Matching +full:reg +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.
34 * of_graph_is_present() - check graph's presence
37 * Return: True if @node has a port or ports (with a port) sub-node,
57 * of_property_count_elems_of_size - Count the number of elements in a property
59 * @np: device node from which the property value is to be read.
60 * @propname: name of the property to be searched.
63 * Search for a property in a device node and count the number of elements of
64 * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
65 * property does not exist or its length does not match a multiple of elem_size
66 * and -ENODATA if the property does not have a value.
71 struct property *prop = of_find_property(np, propname, NULL); in of_property_count_elems_of_size()
74 return -EINVAL; in of_property_count_elems_of_size()
75 if (!prop->value) in of_property_count_elems_of_size()
76 return -ENODATA; in of_property_count_elems_of_size()
78 if (prop->length % elem_size != 0) { in of_property_count_elems_of_size()
81 return -EINVAL; in of_property_count_elems_of_size()
84 return prop->length / elem_size; in of_property_count_elems_of_size()
91 * @np: device node from which the property value is to be read.
92 * @propname: name of the property to be searched.
93 * @min: minimum allowed length of property value
94 * @max: maximum allowed length of property value (0 means unlimited)
97 * Search for a property in a device node and valid the requested size.
98 * Returns the property value on success, -EINVAL if the property does not
99 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
100 * property data is too small or too large.
106 struct property *prop = of_find_property(np, propname, NULL); in of_find_property_value_of_size()
109 return ERR_PTR(-EINVAL); in of_find_property_value_of_size()
110 if (!prop->value) in of_find_property_value_of_size()
111 return ERR_PTR(-ENODATA); in of_find_property_value_of_size()
112 if (prop->length < min) in of_find_property_value_of_size()
113 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
114 if (max && prop->length > max) in of_find_property_value_of_size()
115 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
118 *len = prop->length; in of_find_property_value_of_size()
120 return prop->value; in of_find_property_value_of_size()
124 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
126 * @np: device node from which the property value is to be read.
127 * @propname: name of the property to be searched.
131 * Search for a property in a device node and read nth 32-bit value from
132 * it. Returns 0 on success, -EINVAL if the property does not exist,
133 * -ENODATA if property does not have a value, and -EOVERFLOW if the
134 * property data isn't large enough.
156 * of_property_read_u64_index - Find and read a u64 from a multi-value property.
158 * @np: device node from which the property value is to be read.
159 * @propname: name of the property to be searched.
163 * Search for a property in a device node and read nth 64-bit value from
164 * it. Returns 0 on success, -EINVAL if the property does not exist,
165 * -ENODATA if property does not have a value, and -EOVERFLOW if the
166 * property data isn't large enough.
187 * of_property_read_variable_u8_array - Find and read an array of u8 from a
188 * property, with bounds on the minimum and maximum array size.
190 * @np: device node from which the property value is to be read.
191 * @propname: name of the property to be searched.
198 * Search for a property in a device node and read 8-bit value(s) from
199 * it. Returns number of elements read on success, -EINVAL if the property
200 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
201 * if the property data is smaller than sz_min or longer than sz_max.
204 * property = /bits/ 8 <0x50 0x60 0x70>;
227 while (count--) in of_property_read_variable_u8_array()
235 * of_property_read_variable_u16_array - Find and read an array of u16 from a
236 * property, with bounds on the minimum and maximum array size.
238 * @np: device node from which the property value is to be read.
239 * @propname: name of the property to be searched.
246 * Search for a property in a device node and read 16-bit value(s) from
247 * it. Returns number of elements read on success, -EINVAL if the property
248 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
249 * if the property data is smaller than sz_min or longer than sz_max.
252 * property = /bits/ 16 <0x5000 0x6000 0x7000>;
275 while (count--) in of_property_read_variable_u16_array()
283 * of_property_read_variable_u32_array - Find and read an array of 32 bit
284 * integers from a property, with bounds on the minimum and maximum array size.
286 * @np: device node from which the property value is to be read.
287 * @propname: name of the property to be searched.
294 * Search for a property in a device node and read 32-bit value(s) from
295 * it. Returns number of elements read on success, -EINVAL if the property
296 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
297 * if the property data is smaller than sz_min or longer than sz_max.
320 while (count--) in of_property_read_variable_u32_array()
328 * of_property_read_u64 - Find and read a 64 bit integer from a property
329 * @np: device node from which the property value is to be read.
330 * @propname: name of the property to be searched.
333 * Search for a property in a device node and read a 64-bit value from
334 * it. Returns 0 on success, -EINVAL if the property does not exist,
335 * -ENODATA if property does not have a value, and -EOVERFLOW if the
336 * property data isn't large enough.
357 * of_property_read_variable_u64_array - Find and read an array of 64 bit
358 * integers from a property, with bounds on the minimum and maximum array size.
360 * @np: device node from which the property value is to be read.
361 * @propname: name of the property to be searched.
368 * Search for a property in a device node and read 64-bit value(s) from
369 * it. Returns number of elements read on success, -EINVAL if the property
370 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
371 * if the property data is smaller than sz_min or longer than sz_max.
394 while (count--) { in of_property_read_variable_u64_array()
404 * of_property_read_string - Find and read a string from a property
405 * @np: device node from which the property value is to be read.
406 * @propname: name of the property to be searched.
410 * Search for a property in a device tree node and retrieve a null
412 * success, -EINVAL if the property does not exist, -ENODATA if property
413 * does not have a value, and -EILSEQ if the string is not null-terminated
414 * within the length of the property data.
421 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string()
423 return -EINVAL; in of_property_read_string()
424 if (!prop->value) in of_property_read_string()
425 return -ENODATA; in of_property_read_string()
426 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string()
427 return -EILSEQ; in of_property_read_string()
428 *out_string = prop->value; in of_property_read_string()
434 * of_property_match_string() - Find string in a list and return index
435 * @np: pointer to node containing string list property
436 * @propname: string list property name
439 * This function searches a string list property and returns the index
445 const struct property *prop = of_find_property(np, propname, NULL); in of_property_match_string()
451 return -EINVAL; in of_property_match_string()
452 if (!prop->value) in of_property_match_string()
453 return -ENODATA; in of_property_match_string()
455 p = prop->value; in of_property_match_string()
456 end = p + prop->length; in of_property_match_string()
459 l = strnlen(p, end - p) + 1; in of_property_match_string()
461 return -EILSEQ; in of_property_match_string()
466 return -ENODATA; in of_property_match_string()
471 * of_property_read_string_helper() - Utility helper for parsing string properties
472 * @np: device node from which the property value is to be read.
473 * @propname: name of the property to be searched.
485 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string_helper()
490 return -EINVAL; in of_property_read_string_helper()
491 if (!prop->value) in of_property_read_string_helper()
492 return -ENODATA; in of_property_read_string_helper()
493 p = prop->value; in of_property_read_string_helper()
494 end = p + prop->length; in of_property_read_string_helper()
497 l = strnlen(p, end - p) + 1; in of_property_read_string_helper()
499 return -EILSEQ; in of_property_read_string_helper()
503 i -= skip; in of_property_read_string_helper()
504 return i <= 0 ? -ENODATA : i; in of_property_read_string_helper()
508 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, in of_prop_next_u32()
517 curv = prop->value; in of_prop_next_u32()
522 if (curv >= prop->value + prop->length) in of_prop_next_u32()
531 const char *of_prop_next_string(struct property *prop, const char *cur) in of_prop_next_string()
539 return prop->value; in of_prop_next_string()
542 if (curv >= prop->value + prop->length) in of_prop_next_string()
550 * of_graph_parse_endpoint() - parse common endpoint node properties
566 endpoint->local_node = node; in of_graph_parse_endpoint()
571 of_property_read_u32(port_node, "reg", &endpoint->port); in of_graph_parse_endpoint()
572 of_property_read_u32(node, "reg", &endpoint->id); in of_graph_parse_endpoint()
581 * of_graph_get_port_by_id() - get the port matching a given id
601 of_property_read_u32(port, "reg", &port_id); in of_graph_get_port_by_id()
613 * of_graph_get_next_endpoint() - get next endpoint node
680 * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
682 * @port_reg: identifier (value of reg property) of the parent port node
683 * @reg: identifier (value of reg property) of the endpoint node
685 * Return: An 'endpoint' node pointer which is identified by reg and at the same
686 * is the child of a port node identified by port_reg. reg and port_reg are
687 * ignored when they are -1. Use of_node_put() on the pointer when done.
690 const struct device_node *parent, int port_reg, int reg) in of_graph_get_endpoint_by_regs() argument
697 if (((port_reg == -1) || (endpoint.port == port_reg)) && in of_graph_get_endpoint_by_regs()
698 ((reg == -1) || (endpoint.id == reg))) in of_graph_get_endpoint_by_regs()
707 * of_graph_get_remote_endpoint() - get remote endpoint node
716 return of_parse_phandle(node, "remote-endpoint", 0); in of_graph_get_remote_endpoint()
721 * of_graph_get_port_parent() - get port's parent node
741 for (depth = 3; depth && node; depth--) { in of_graph_get_port_parent()
751 * of_graph_get_remote_port_parent() - get remote port's parent node
774 * of_graph_get_remote_port() - get remote port node
805 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
807 * @port: identifier (value of reg property) of the parent port node
808 * @endpoint: identifier (value of reg property) of the endpoint node
885 return -ENXIO; in of_fwnode_property_read_int_array()
902 return kbasename(to_of_node(fwnode)->full_name); in of_fwnode_get_name()
908 if (!to_of_node(fwnode)->parent) in of_fwnode_get_name_prefix()
965 args->nargs = of_args.args_count; in of_fwnode_get_reference_args()
966 args->fwnode = of_fwnode_handle(of_args.np); in of_fwnode_get_reference_args()
969 args->args[i] = i < of_args.args_count ? of_args.args[i] : 0; in of_fwnode_get_reference_args()
1012 endpoint->local_fwnode = fwnode; in of_fwnode_graph_parse_endpoint()
1014 of_property_read_u32(port_node, "reg", &endpoint->port); in of_fwnode_graph_parse_endpoint()
1015 of_property_read_u32(node, "reg", &endpoint->id); in of_fwnode_graph_parse_endpoint()
1044 * of_link_to_phandle - Add fwnode link to supplier from supplier phandle
1056 * - 0 if fwnode link successfully created to supplier
1057 * - -EINVAL if the supplier link is invalid and should not be created
1058 * - -ENODEV if struct device will never be create for supplier
1086 pr_debug("Not linking %pOFP to %pOFP - No device\n", in of_link_to_phandle()
1088 return -ENODEV; in of_link_to_phandle()
1097 pr_debug("Not linking %pOFP to %pOFP - is descendant\n", in of_link_to_phandle()
1100 return -EINVAL; in of_link_to_phandle()
1107 sup_dev = get_dev_from_fwnode(&sup_np->fwnode); in of_link_to_phandle()
1110 sup_np->fwnode.flags & FWNODE_FLAG_NOT_DEVICE)) { in of_link_to_phandle()
1111 pr_debug("Not linking %pOFP to %pOFP - No struct device\n", in of_link_to_phandle()
1114 return -ENODEV; in of_link_to_phandle()
1125 * parse_prop_cells - Property parsing function for suppliers
1128 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1131 * @list_name: Property name that is known to contain list of phandle(s) to
1133 * @cells_name: property name that specifies phandles' arguments count
1139 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1141 * - NULL if no phandle found at index
1174 return -1; in strcmp_suffix()
1175 return strcmp(str + len - suffix_len, suffix); in strcmp_suffix()
1179 * parse_suffix_prop_cells - Suffix property parsing function for suppliers
1182 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1185 * @suffix: Property suffix that is known to contain list of phandle(s) to
1187 * @cells_name: property name that specifies phandles' arguments count
1193 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1195 * - NULL if no phandle found at index
1222 * struct supplier_bindings - Property parsing functions for suppliers
1226 * @parse_prop.np: Pointer to device node holding supplier phandle property
1227 * @parse_prop.prop_name: Name of property holding a phandle value
1233 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1235 * - NULL if no phandle found at index
1243 DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells")
1244 DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells")
1245 DEFINE_SIMPLE_PROP(iommus, "iommus", "#iommu-cells")
1246 DEFINE_SIMPLE_PROP(mboxes, "mboxes", "#mbox-cells")
1247 DEFINE_SIMPLE_PROP(io_channels, "io-channel", "#io-channel-cells")
1248 DEFINE_SIMPLE_PROP(interrupt_parent, "interrupt-parent", NULL)
1249 DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells")
1250 DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells")
1251 DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells")
1253 DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL)
1254 DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
1255 DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
1256 DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL)
1257 DEFINE_SIMPLE_PROP(pinctrl1, "pinctrl-1", NULL)
1258 DEFINE_SIMPLE_PROP(pinctrl2, "pinctrl-2", NULL)
1259 DEFINE_SIMPLE_PROP(pinctrl3, "pinctrl-3", NULL)
1260 DEFINE_SIMPLE_PROP(pinctrl4, "pinctrl-4", NULL)
1261 DEFINE_SIMPLE_PROP(pinctrl5, "pinctrl-5", NULL)
1262 DEFINE_SIMPLE_PROP(pinctrl6, "pinctrl-6", NULL)
1263 DEFINE_SIMPLE_PROP(pinctrl7, "pinctrl-7", NULL)
1264 DEFINE_SIMPLE_PROP(pinctrl8, "pinctrl-8", NULL)
1265 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
1266 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
1271 if (!strcmp_suffix(prop_name, ",nr-gpios")) in parse_gpios()
1274 return parse_suffix_prop_cells(np, prop_name, index, "-gpios", in parse_gpios()
1275 "#gpio-cells"); in parse_gpios()
1281 if (strcmp(prop_name, "iommu-map")) in parse_iommu_maps()
1296 * Ignore node with gpio-hog property since its gpios are all provided in parse_gpio_compat()
1299 if (of_find_property(np, "gpio-hog", NULL)) in parse_gpio_compat()
1302 if (of_parse_phandle_with_args(np, prop_name, "#gpio-cells", index, in parse_gpio_compat()
1318 strcmp(prop_name, "interrupts-extended")) in parse_interrupts()
1357 * of_link_property - Create device links to suppliers listed in a property
1359 * @con_np: The consumer device tree node which contains the property
1360 * @prop_name: Name of property to be parsed
1362 * This function checks if the property @prop_name that is present in the
1385 while (!matched && s->parse_prop) { in of_link_property()
1386 if (s->optional && !fw_devlink_is_strict()) { in of_link_property()
1391 while ((phandle = s->parse_prop(con_np, prop_name, i))) { in of_link_property()
1404 struct property *p; in of_fwnode_add_links()
1408 return -EINVAL; in of_fwnode_add_links()
1411 of_link_property(con_np, p->name); in of_fwnode_add_links()