Lines Matching +full:int +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.
33 * of_graph_is_present() - check graph's presence
36 * Return: True if @node has a port or ports (with a port) sub-node,
56 * of_property_count_elems_of_size - Count the number of elements in a property
58 * @np: device node from which the property value is to be read.
59 * @propname: name of the property to be searched.
62 * Search for a property in a device node and count the number of elements of
63 * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
64 * property does not exist or its length does not match a multiple of elem_size
65 * and -ENODATA if the property does not have a value.
67 int of_property_count_elems_of_size(const struct device_node *np, in of_property_count_elems_of_size()
68 const char *propname, int elem_size) in of_property_count_elems_of_size()
70 struct property *prop = of_find_property(np, propname, NULL); in of_property_count_elems_of_size()
73 return -EINVAL; in of_property_count_elems_of_size()
74 if (!prop->value) in of_property_count_elems_of_size()
75 return -ENODATA; in of_property_count_elems_of_size()
77 if (prop->length % elem_size != 0) { in of_property_count_elems_of_size()
80 return -EINVAL; in of_property_count_elems_of_size()
83 return prop->length / elem_size; in of_property_count_elems_of_size()
90 * @np: device node from which the property value is to be read.
91 * @propname: name of the property to be searched.
92 * @min: minimum allowed length of property value
93 * @max: maximum allowed length of property value (0 means unlimited)
96 * Search for a property in a device node and valid the requested size.
97 * Returns the property value on success, -EINVAL if the property does not
98 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
99 * property data is too small or too large.
105 struct property *prop = of_find_property(np, propname, NULL); in of_find_property_value_of_size()
108 return ERR_PTR(-EINVAL); in of_find_property_value_of_size()
109 if (!prop->value) in of_find_property_value_of_size()
110 return ERR_PTR(-ENODATA); in of_find_property_value_of_size()
111 if (prop->length < min) in of_find_property_value_of_size()
112 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
113 if (max && prop->length > max) in of_find_property_value_of_size()
114 return ERR_PTR(-EOVERFLOW); in of_find_property_value_of_size()
117 *len = prop->length; in of_find_property_value_of_size()
119 return prop->value; in of_find_property_value_of_size()
123 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
125 * @np: device node from which the property value is to be read.
126 * @propname: name of the property to be searched.
130 * Search for a property in a device node and read nth 32-bit value from
131 * it. Returns 0 on success, -EINVAL if the property does not exist,
132 * -ENODATA if property does not have a value, and -EOVERFLOW if the
133 * property data isn't large enough.
137 int of_property_read_u32_index(const struct device_node *np, in of_property_read_u32_index()
155 * of_property_read_u64_index - Find and read a u64 from a multi-value property.
157 * @np: device node from which the property value is to be read.
158 * @propname: name of the property to be searched.
162 * Search for a property in a device node and read nth 64-bit value from
163 * it. Returns 0 on success, -EINVAL if the property does not exist,
164 * -ENODATA if property does not have a value, and -EOVERFLOW if the
165 * property data isn't large enough.
169 int of_property_read_u64_index(const struct device_node *np, in of_property_read_u64_index()
186 * of_property_read_variable_u8_array - Find and read an array of u8 from a
187 * property, with bounds on the minimum and maximum array size.
189 * @np: device node from which the property value is to be read.
190 * @propname: name of the property to be searched.
197 * Search for a property in a device node and read 8-bit value(s) from
198 * it. Returns number of elements read on success, -EINVAL if the property
199 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
200 * if the property data is smaller than sz_min or longer than sz_max.
203 * property = /bits/ 8 <0x50 0x60 0x70>;
207 int of_property_read_variable_u8_array(const struct device_node *np, in of_property_read_variable_u8_array()
226 while (count--) in of_property_read_variable_u8_array()
234 * of_property_read_variable_u16_array - Find and read an array of u16 from a
235 * property, with bounds on the minimum and maximum array size.
237 * @np: device node from which the property value is to be read.
238 * @propname: name of the property to be searched.
245 * Search for a property in a device node and read 16-bit value(s) from
246 * it. Returns number of elements read on success, -EINVAL if the property
247 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
248 * if the property data is smaller than sz_min or longer than sz_max.
251 * property = /bits/ 16 <0x5000 0x6000 0x7000>;
255 int of_property_read_variable_u16_array(const struct device_node *np, in of_property_read_variable_u16_array()
274 while (count--) in of_property_read_variable_u16_array()
282 * of_property_read_variable_u32_array - Find and read an array of 32 bit
283 * integers from a property, with bounds on the minimum and maximum array size.
285 * @np: device node from which the property value is to be read.
286 * @propname: name of the property to be searched.
293 * Search for a property in a device node and read 32-bit value(s) from
294 * it. Returns number of elements read on success, -EINVAL if the property
295 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
296 * if the property data is smaller than sz_min or longer than sz_max.
300 int of_property_read_variable_u32_array(const struct device_node *np, in of_property_read_variable_u32_array()
319 while (count--) in of_property_read_variable_u32_array()
327 * of_property_read_u64 - Find and read a 64 bit integer from a property
328 * @np: device node from which the property value is to be read.
329 * @propname: name of the property to be searched.
332 * Search for a property in a device node and read a 64-bit value from
333 * it. Returns 0 on success, -EINVAL if the property does not exist,
334 * -ENODATA if property does not have a value, and -EOVERFLOW if the
335 * property data isn't large enough.
339 int of_property_read_u64(const struct device_node *np, const char *propname, in of_property_read_u64()
356 * of_property_read_variable_u64_array - Find and read an array of 64 bit
357 * integers from a property, with bounds on the minimum and maximum array size.
359 * @np: device node from which the property value is to be read.
360 * @propname: name of the property to be searched.
367 * Search for a property in a device node and read 64-bit value(s) from
368 * it. Returns number of elements read on success, -EINVAL if the property
369 * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
370 * if the property data is smaller than sz_min or longer than sz_max.
374 int of_property_read_variable_u64_array(const struct device_node *np, in of_property_read_variable_u64_array()
393 while (count--) { in of_property_read_variable_u64_array()
403 * of_property_read_string - Find and read a string from a property
404 * @np: device node from which the property value is to be read.
405 * @propname: name of the property to be searched.
409 * Search for a property in a device tree node and retrieve a null
411 * success, -EINVAL if the property does not exist, -ENODATA if property
412 * does not have a value, and -EILSEQ if the string is not null-terminated
413 * within the length of the property data.
417 int of_property_read_string(const struct device_node *np, const char *propname, in of_property_read_string()
420 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string()
422 return -EINVAL; in of_property_read_string()
423 if (!prop->value) in of_property_read_string()
424 return -ENODATA; in of_property_read_string()
425 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string()
426 return -EILSEQ; in of_property_read_string()
427 *out_string = prop->value; in of_property_read_string()
433 * of_property_match_string() - Find string in a list and return index
434 * @np: pointer to node containing string list property
435 * @propname: string list property name
438 * This function searches a string list property and returns the index
441 int of_property_match_string(const struct device_node *np, const char *propname, in of_property_match_string()
444 const struct property *prop = of_find_property(np, propname, NULL); in of_property_match_string()
446 int i; in of_property_match_string()
450 return -EINVAL; in of_property_match_string()
451 if (!prop->value) in of_property_match_string()
452 return -ENODATA; in of_property_match_string()
454 p = prop->value; in of_property_match_string()
455 end = p + prop->length; in of_property_match_string()
458 l = strnlen(p, end - p) + 1; in of_property_match_string()
460 return -EILSEQ; in of_property_match_string()
465 return -ENODATA; in of_property_match_string()
470 * of_property_read_string_helper() - Utility helper for parsing string properties
471 * @np: device node from which the property value is to be read.
472 * @propname: name of the property to be searched.
480 int of_property_read_string_helper(const struct device_node *np, in of_property_read_string_helper()
482 size_t sz, int skip) in of_property_read_string_helper()
484 const struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string_helper()
485 int l = 0, i = 0; in of_property_read_string_helper()
489 return -EINVAL; in of_property_read_string_helper()
490 if (!prop->value) in of_property_read_string_helper()
491 return -ENODATA; in of_property_read_string_helper()
492 p = prop->value; in of_property_read_string_helper()
493 end = p + prop->length; in of_property_read_string_helper()
496 l = strnlen(p, end - p) + 1; in of_property_read_string_helper()
498 return -EILSEQ; in of_property_read_string_helper()
502 i -= skip; in of_property_read_string_helper()
503 return i <= 0 ? -ENODATA : i; in of_property_read_string_helper()
507 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, in of_prop_next_u32()
516 curv = prop->value; in of_prop_next_u32()
521 if (curv >= prop->value + prop->length) in of_prop_next_u32()
530 const char *of_prop_next_string(struct property *prop, const char *cur) in of_prop_next_string()
538 return prop->value; in of_prop_next_string()
541 if (curv >= prop->value + prop->length) in of_prop_next_string()
549 * of_graph_parse_endpoint() - parse common endpoint node properties
555 int of_graph_parse_endpoint(const struct device_node *node, in of_graph_parse_endpoint()
565 endpoint->local_node = node; in of_graph_parse_endpoint()
570 of_property_read_u32(port_node, "reg", &endpoint->port); in of_graph_parse_endpoint()
571 of_property_read_u32(node, "reg", &endpoint->id); in of_graph_parse_endpoint()
580 * of_graph_get_port_by_id() - get the port matching a given id
612 * of_graph_get_next_endpoint() - get next endpoint node
679 * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
681 * @port_reg: identifier (value of reg property) of the parent port node
682 * @reg: identifier (value of reg property) of the endpoint node
686 * ignored when they are -1. Use of_node_put() on the pointer when done.
689 const struct device_node *parent, int port_reg, int reg) in of_graph_get_endpoint_by_regs()
696 if (((port_reg == -1) || (endpoint.port == port_reg)) && in of_graph_get_endpoint_by_regs()
697 ((reg == -1) || (endpoint.id == reg))) in of_graph_get_endpoint_by_regs()
706 * of_graph_get_remote_endpoint() - get remote endpoint node
715 return of_parse_phandle(node, "remote-endpoint", 0); in of_graph_get_remote_endpoint()
720 * of_graph_get_port_parent() - get port's parent node
728 unsigned int depth; in of_graph_get_port_parent()
740 for (depth = 3; depth && node; depth--) { in of_graph_get_port_parent()
750 * of_graph_get_remote_port_parent() - get remote port's parent node
773 * of_graph_get_remote_port() - get remote port node
791 int of_graph_get_endpoint_count(const struct device_node *np) in of_graph_get_endpoint_count()
794 int num = 0; in of_graph_get_endpoint_count()
804 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
806 * @port: identifier (value of reg property) of the parent port node
807 * @endpoint: identifier (value of reg property) of the endpoint node
862 static int of_fwnode_property_read_int_array(const struct fwnode_handle *fwnode, in of_fwnode_property_read_int_array()
864 unsigned int elem_size, void *val, in of_fwnode_property_read_int_array()
884 return -ENXIO; in of_fwnode_property_read_int_array()
887 static int
901 return kbasename(to_of_node(fwnode)->full_name); in of_fwnode_get_name()
907 if (!to_of_node(fwnode)->parent) in of_fwnode_get_name_prefix()
941 static int
944 unsigned int nargs, unsigned int index, in of_fwnode_get_reference_args()
948 unsigned int i; in of_fwnode_get_reference_args()
949 int ret; in of_fwnode_get_reference_args()
962 args->nargs = of_args.args_count; in of_fwnode_get_reference_args()
963 args->fwnode = of_fwnode_handle(of_args.np); in of_fwnode_get_reference_args()
966 args->args[i] = i < of_args.args_count ? of_args.args[i] : 0; in of_fwnode_get_reference_args()
1003 static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, in of_fwnode_graph_parse_endpoint()
1009 endpoint->local_fwnode = fwnode; in of_fwnode_graph_parse_endpoint()
1011 of_property_read_u32(port_node, "reg", &endpoint->port); in of_fwnode_graph_parse_endpoint()
1012 of_property_read_u32(node, "reg", &endpoint->id); in of_fwnode_graph_parse_endpoint()
1041 * of_get_next_parent_dev - Add device link to supplier from supplier phandle
1058 dev = get_dev_from_fwnode(&np->fwnode); in of_get_next_parent_dev()
1065 * of_link_to_phandle - Add device link to supplier from supplier phandle
1077 * - 0 if link successfully created to supplier
1078 * - -EAGAIN if linking to the supplier should be reattempted
1079 * - -EINVAL if the supplier link is invalid and should not be created
1080 * - -ENODEV if there is no device that corresponds to the supplier phandle
1082 static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, in of_link_to_phandle()
1086 int ret = 0; in of_link_to_phandle()
1109 dev_dbg(dev, "Not linking to %pOFP - No device\n", tmp_np); in of_link_to_phandle()
1110 return -ENODEV; in of_link_to_phandle()
1118 if (of_is_ancestor_of(dev->of_node, sup_np)) { in of_link_to_phandle()
1119 dev_dbg(dev, "Not linking to %pOFP - is descendant\n", sup_np); in of_link_to_phandle()
1121 return -EINVAL; in of_link_to_phandle()
1123 sup_dev = get_dev_from_fwnode(&sup_np->fwnode); in of_link_to_phandle()
1126 dev_dbg(dev, "Not linking to %pOFP - No struct device\n", in of_link_to_phandle()
1129 return -ENODEV; in of_link_to_phandle()
1138 return -EAGAIN; in of_link_to_phandle()
1145 dev_dbg(dev, "Not linking to %pOFP - cycle detected\n", in of_link_to_phandle()
1147 ret = -EINVAL; in of_link_to_phandle()
1153 ret = -EAGAIN; in of_link_to_phandle()
1162 ret = -EINVAL; in of_link_to_phandle()
1168 * parse_prop_cells - Property parsing function for suppliers
1171 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1174 * @list_name: Property name that is known to contain list of phandle(s) to
1176 * @cells_name: property name that specifies phandles' arguments count
1182 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1184 * - NULL if no phandle found at index
1187 const char *prop_name, int index, in parse_prop_cells()
1205 const char *prop_name, int index) \
1210 static int strcmp_suffix(const char *str, const char *suffix) in strcmp_suffix()
1212 unsigned int len, suffix_len; in strcmp_suffix()
1217 return -1; in strcmp_suffix()
1218 return strcmp(str + len - suffix_len, suffix); in strcmp_suffix()
1222 * parse_suffix_prop_cells - Suffix property parsing function for suppliers
1225 * @prop_name: Name of property to be parsed. Expected to hold phandle values
1228 * @suffix: Property suffix 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
1241 const char *prop_name, int index, in parse_suffix_prop_cells()
1259 const char *prop_name, int index) \
1265 * struct supplier_bindings - Property parsing functions for suppliers
1269 * @parse_prop.np: Pointer to device node holding supplier phandle property
1270 * @parse_prop.prop_name: Name of property holding a phandle value
1276 * - phandle node pointer with refcount incremented. Caller must of_node_put()
1278 * - NULL if no phandle found at index
1282 const char *prop_name, int index);
1285 DEFINE_SIMPLE_PROP(clocks, "clocks", "#clock-cells")
1286 DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells")
1287 DEFINE_SIMPLE_PROP(iommus, "iommus", "#iommu-cells")
1288 DEFINE_SIMPLE_PROP(mboxes, "mboxes", "#mbox-cells")
1289 DEFINE_SIMPLE_PROP(io_channels, "io-channel", "#io-channel-cells")
1290 DEFINE_SIMPLE_PROP(interrupt_parent, "interrupt-parent", NULL)
1291 DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells")
1292 DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells")
1293 DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells")
1295 DEFINE_SIMPLE_PROP(interrupts_extended, "interrupts-extended",
1296 "#interrupt-cells")
1297 DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL)
1298 DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
1299 DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
1300 DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL)
1301 DEFINE_SIMPLE_PROP(pinctrl1, "pinctrl-1", NULL)
1302 DEFINE_SIMPLE_PROP(pinctrl2, "pinctrl-2", NULL)
1303 DEFINE_SIMPLE_PROP(pinctrl3, "pinctrl-3", NULL)
1304 DEFINE_SIMPLE_PROP(pinctrl4, "pinctrl-4", NULL)
1305 DEFINE_SIMPLE_PROP(pinctrl5, "pinctrl-5", NULL)
1306 DEFINE_SIMPLE_PROP(pinctrl6, "pinctrl-6", NULL)
1307 DEFINE_SIMPLE_PROP(pinctrl7, "pinctrl-7", NULL)
1308 DEFINE_SIMPLE_PROP(pinctrl8, "pinctrl-8", NULL)
1309 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
1310 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
1311 DEFINE_SUFFIX_PROP(gpios, "-gpios", "#gpio-cells")
1314 const char *prop_name, int index) in parse_iommu_maps()
1316 if (strcmp(prop_name, "iommu-map")) in parse_iommu_maps()
1354 * of_link_property - Create device links to suppliers listed in a property
1356 * @con_np: The consumer device tree node which contains the property
1357 * @prop_name: Name of property to be parsed
1359 * This function checks if the property @prop_name that is present in the
1372 static int of_link_property(struct device *dev, struct device_node *con_np, in of_link_property()
1377 unsigned int i = 0; in of_link_property()
1379 int ret = 0; in of_link_property()
1382 if (dev->of_node == con_np) in of_link_property()
1388 while (!matched && s->parse_prop) { in of_link_property()
1389 while ((phandle = s->parse_prop(con_np, prop_name, i))) { in of_link_property()
1393 == -EAGAIN) in of_link_property()
1394 ret = -EAGAIN; in of_link_property()
1402 static int of_link_to_suppliers(struct device *dev, in of_link_to_suppliers()
1406 struct property *p; in of_link_to_suppliers()
1407 int ret = 0; in of_link_to_suppliers()
1410 if (of_link_property(dev, con_np, p->name)) in of_link_to_suppliers()
1411 ret = -ENODEV; in of_link_to_suppliers()
1415 ret = -EAGAIN; in of_link_to_suppliers()
1420 static int of_fwnode_add_links(const struct fwnode_handle *fwnode, in of_fwnode_add_links()