Lines Matching +full:string +full:- +full:array +full:- +full:property
1 // SPDX-License-Identifier: GPL-2.0
3 * property.c - Unified device property interface.
17 #include <linux/property.h>
31 return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &pset_fwnode_ops; in is_pset_node()
49 if (!pset || !pset->properties) in pset_prop_get()
52 for (prop = pset->properties; prop->name; prop++) in pset_prop_get()
53 if (!strcmp(name, prop->name)) in pset_prop_get()
61 switch (prop->type) { in property_get_pointer()
63 if (prop->is_array) in property_get_pointer()
64 return prop->pointer.u8_data; in property_get_pointer()
65 return &prop->value.u8_data; in property_get_pointer()
67 if (prop->is_array) in property_get_pointer()
68 return prop->pointer.u16_data; in property_get_pointer()
69 return &prop->value.u16_data; in property_get_pointer()
71 if (prop->is_array) in property_get_pointer()
72 return prop->pointer.u32_data; in property_get_pointer()
73 return &prop->value.u32_data; in property_get_pointer()
75 if (prop->is_array) in property_get_pointer()
76 return prop->pointer.u64_data; in property_get_pointer()
77 return &prop->value.u64_data; in property_get_pointer()
79 if (prop->is_array) in property_get_pointer()
80 return prop->pointer.str; in property_get_pointer()
81 return &prop->value.str; in property_get_pointer()
89 switch (prop->type) { in property_set_pointer()
91 if (prop->is_array) in property_set_pointer()
92 prop->pointer.u8_data = pointer; in property_set_pointer()
94 prop->value.u8_data = *((u8 *)pointer); in property_set_pointer()
97 if (prop->is_array) in property_set_pointer()
98 prop->pointer.u16_data = pointer; in property_set_pointer()
100 prop->value.u16_data = *((u16 *)pointer); in property_set_pointer()
103 if (prop->is_array) in property_set_pointer()
104 prop->pointer.u32_data = pointer; in property_set_pointer()
106 prop->value.u32_data = *((u32 *)pointer); in property_set_pointer()
109 if (prop->is_array) in property_set_pointer()
110 prop->pointer.u64_data = pointer; in property_set_pointer()
112 prop->value.u64_data = *((u64 *)pointer); in property_set_pointer()
115 if (prop->is_array) in property_set_pointer()
116 prop->pointer.str = pointer; in property_set_pointer()
118 prop->value.str = pointer; in property_set_pointer()
133 return ERR_PTR(-EINVAL); in pset_prop_find()
136 return ERR_PTR(-ENODATA); in pset_prop_find()
137 if (length > prop->length) in pset_prop_find()
138 return ERR_PTR(-EOVERFLOW); in pset_prop_find()
209 return -EINVAL; in pset_prop_count_elems_of_size()
211 return prop->length / length; in pset_prop_count_elems_of_size()
222 /* Find out the array length. */ in pset_prop_read_string_array()
225 return -EINVAL; in pset_prop_read_string_array()
227 if (!prop->is_array) in pset_prop_read_string_array()
228 /* The array length for a non-array string property is 1. */ in pset_prop_read_string_array()
231 /* Find the length of an array. */ in pset_prop_read_string_array()
253 return IS_ENABLED(CONFIG_OF) && dev->of_node ? in dev_fwnode()
254 &dev->of_node->fwnode : dev->fwnode; in dev_fwnode()
285 return -ENXIO; in pset_fwnode_read_int_array()
304 * device_property_present - check if a property of a device is present
305 * @dev: Device whose property is being checked
306 * @propname: Name of the property
308 * Check if property @propname is present in the device firmware description.
317 * fwnode_property_present - check if a property of a firmware node is present
318 * @fwnode: Firmware node whose property to check
319 * @propname: Name of the property
328 !IS_ERR_OR_NULL(fwnode->secondary)) in fwnode_property_present()
329 ret = fwnode_call_bool_op(fwnode->secondary, property_present, in fwnode_property_present()
336 * device_property_read_u8_array - return a u8 array property of a device
337 * @dev: Device to get the property of
338 * @propname: Name of the property
340 * @nval: Size of the @val array
342 * Function reads an array of u8 properties with @propname from the device
346 * %0 if the property was found (success),
347 * %-EINVAL if given arguments are not valid,
348 * %-ENODATA if the property does not have a value,
349 * %-EPROTO if the property is not an array of numbers,
350 * %-EOVERFLOW if the size of the property is not as expected.
351 * %-ENXIO if no suitable firmware interface is present.
361 * device_property_read_u16_array - return a u16 array property of a device
362 * @dev: Device to get the property of
363 * @propname: Name of the property
365 * @nval: Size of the @val array
367 * Function reads an array of u16 properties with @propname from the device
371 * %0 if the property was found (success),
372 * %-EINVAL if given arguments are not valid,
373 * %-ENODATA if the property does not have a value,
374 * %-EPROTO if the property is not an array of numbers,
375 * %-EOVERFLOW if the size of the property is not as expected.
376 * %-ENXIO if no suitable firmware interface is present.
386 * device_property_read_u32_array - return a u32 array property of a device
387 * @dev: Device to get the property of
388 * @propname: Name of the property
390 * @nval: Size of the @val array
392 * Function reads an array of u32 properties with @propname from the device
396 * %0 if the property was found (success),
397 * %-EINVAL if given arguments are not valid,
398 * %-ENODATA if the property does not have a value,
399 * %-EPROTO if the property is not an array of numbers,
400 * %-EOVERFLOW if the size of the property is not as expected.
401 * %-ENXIO if no suitable firmware interface is present.
411 * device_property_read_u64_array - return a u64 array property of a device
412 * @dev: Device to get the property of
413 * @propname: Name of the property
415 * @nval: Size of the @val array
417 * Function reads an array of u64 properties with @propname from the device
421 * %0 if the property was found (success),
422 * %-EINVAL if given arguments are not valid,
423 * %-ENODATA if the property does not have a value,
424 * %-EPROTO if the property is not an array of numbers,
425 * %-EOVERFLOW if the size of the property is not as expected.
426 * %-ENXIO if no suitable firmware interface is present.
436 * device_property_read_string_array - return a string array property of device
437 * @dev: Device to get the property of
438 * @propname: Name of the property
440 * @nval: Size of the @val array
442 * Function reads an array of string properties with @propname from the device
445 * Return: number of values read on success if @val is non-NULL,
447 * %-EINVAL if given arguments are not valid,
448 * %-ENODATA if the property does not have a value,
449 * %-EPROTO or %-EILSEQ if the property is not an array of strings,
450 * %-EOVERFLOW if the size of the property is not as expected.
451 * %-ENXIO if no suitable firmware interface is present.
461 * device_property_read_string - return a string property of a device
462 * @dev: Device to get the property of
463 * @propname: Name of the property
466 * Function reads property @propname from the device firmware description and
467 * stores the value into @val if found. The value is checked to be a string.
469 * Return: %0 if the property was found (success),
470 * %-EINVAL if given arguments are not valid,
471 * %-ENODATA if the property does not have a value,
472 * %-EPROTO or %-EILSEQ if the property type is not a string.
473 * %-ENXIO if no suitable firmware interface is present.
483 * device_property_match_string - find a string in an array and return index
484 * @dev: Device to get the property of
485 * @propname: Name of the property holding the array
486 * @string: String to look for
488 * Find a given string in a string array and if it is found return the
491 * Return: %0 if the property was found (success),
492 * %-EINVAL if given arguments are not valid,
493 * %-ENODATA if the property does not have a value,
494 * %-EPROTO if the property is not an array of strings,
495 * %-ENXIO if no suitable firmware interface is present.
498 const char *string) in device_property_match_string() argument
500 return fwnode_property_match_string(dev_fwnode(dev), propname, string); in device_property_match_string()
513 if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && in fwnode_property_read_int_array()
514 !IS_ERR_OR_NULL(fwnode->secondary)) in fwnode_property_read_int_array()
516 fwnode->secondary, property_read_int_array, propname, in fwnode_property_read_int_array()
523 * fwnode_property_read_u8_array - return a u8 array property of firmware node
524 * @fwnode: Firmware node to get the property of
525 * @propname: Name of the property
527 * @nval: Size of the @val array
529 * Read an array of u8 properties with @propname from @fwnode and stores them to
533 * %0 if the property was found (success),
534 * %-EINVAL if given arguments are not valid,
535 * %-ENODATA if the property does not have a value,
536 * %-EPROTO if the property is not an array of numbers,
537 * %-EOVERFLOW if the size of the property is not as expected,
538 * %-ENXIO if no suitable firmware interface is present.
549 * fwnode_property_read_u16_array - return a u16 array property of firmware node
550 * @fwnode: Firmware node to get the property of
551 * @propname: Name of the property
553 * @nval: Size of the @val array
555 * Read an array of u16 properties with @propname from @fwnode and store them to
559 * %0 if the property was found (success),
560 * %-EINVAL if given arguments are not valid,
561 * %-ENODATA if the property does not have a value,
562 * %-EPROTO if the property is not an array of numbers,
563 * %-EOVERFLOW if the size of the property is not as expected,
564 * %-ENXIO if no suitable firmware interface is present.
575 * fwnode_property_read_u32_array - return a u32 array property of firmware node
576 * @fwnode: Firmware node to get the property of
577 * @propname: Name of the property
579 * @nval: Size of the @val array
581 * Read an array of u32 properties with @propname from @fwnode store them to
585 * %0 if the property was found (success),
586 * %-EINVAL if given arguments are not valid,
587 * %-ENODATA if the property does not have a value,
588 * %-EPROTO if the property is not an array of numbers,
589 * %-EOVERFLOW if the size of the property is not as expected,
590 * %-ENXIO if no suitable firmware interface is present.
601 * fwnode_property_read_u64_array - return a u64 array property firmware node
602 * @fwnode: Firmware node to get the property of
603 * @propname: Name of the property
605 * @nval: Size of the @val array
607 * Read an array of u64 properties with @propname from @fwnode and store them to
611 * %0 if the property was found (success),
612 * %-EINVAL if given arguments are not valid,
613 * %-ENODATA if the property does not have a value,
614 * %-EPROTO if the property is not an array of numbers,
615 * %-EOVERFLOW if the size of the property is not as expected,
616 * %-ENXIO if no suitable firmware interface is present.
627 * fwnode_property_read_string_array - return string array property of a node
628 * @fwnode: Firmware node to get the property of
629 * @propname: Name of the property
631 * @nval: Size of the @val array
633 * Read an string list property @propname from the given firmware node and store
636 * Return: number of values read on success if @val is non-NULL,
638 * %-EINVAL if given arguments are not valid,
639 * %-ENODATA if the property does not have a value,
640 * %-EPROTO or %-EILSEQ if the property is not an array of strings,
641 * %-EOVERFLOW if the size of the property is not as expected,
642 * %-ENXIO if no suitable firmware interface is present.
652 if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && in fwnode_property_read_string_array()
653 !IS_ERR_OR_NULL(fwnode->secondary)) in fwnode_property_read_string_array()
654 ret = fwnode_call_int_op(fwnode->secondary, in fwnode_property_read_string_array()
662 * fwnode_property_read_string - return a string property of a firmware node
663 * @fwnode: Firmware node to get the property of
664 * @propname: Name of the property
667 * Read property @propname from the given firmware node and store the value into
668 * @val if found. The value is checked to be a string.
670 * Return: %0 if the property was found (success),
671 * %-EINVAL if given arguments are not valid,
672 * %-ENODATA if the property does not have a value,
673 * %-EPROTO or %-EILSEQ if the property is not a string,
674 * %-ENXIO if no suitable firmware interface is present.
686 * fwnode_property_match_string - find a string in an array and return index
687 * @fwnode: Firmware node to get the property of
688 * @propname: Name of the property holding the array
689 * @string: String to look for
691 * Find a given string in a string array and if it is found return the
694 * Return: %0 if the property was found (success),
695 * %-EINVAL if given arguments are not valid,
696 * %-ENODATA if the property does not have a value,
697 * %-EPROTO if the property is not an array of strings,
698 * %-ENXIO if no suitable firmware interface is present.
701 const char *propname, const char *string) in fwnode_property_match_string() argument
711 return -ENODATA; in fwnode_property_match_string()
715 return -ENOMEM; in fwnode_property_match_string()
721 ret = match_string(values, nval, string); in fwnode_property_match_string()
723 ret = -ENODATA; in fwnode_property_match_string()
731 * fwnode_property_get_reference_args() - Find a reference with arguments
733 * @prop: The name of the property
734 * @nargs_prop: The name of the property telling the number of
737 * @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL.
741 * Obtain a reference based on a named property in an fwnode, with
745 * args->fwnode pointer.
748 * %-ENOENT when the index is out of bounds, the index has an empty
749 * reference or the property was not found
750 * %-EINVAL on parse error
767 if (p->is_array) { in property_entry_free_data()
768 if (p->type == DEV_PROP_STRING && p->pointer.str) { in property_entry_free_data()
769 nval = p->length / sizeof(const char *); in property_entry_free_data()
771 kfree(p->pointer.str[i]); in property_entry_free_data()
774 } else if (p->type == DEV_PROP_STRING) { in property_entry_free_data()
775 kfree(p->value.str); in property_entry_free_data()
777 kfree(p->name); in property_entry_free_data()
784 size_t nval = src->length / sizeof(*d); in property_copy_string_array()
789 return -ENOMEM; in property_copy_string_array()
792 d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL); in property_copy_string_array()
793 if (!d[i] && src->pointer.str[i]) { in property_copy_string_array()
794 while (--i >= 0) in property_copy_string_array()
797 return -ENOMEM; in property_copy_string_array()
801 dst->pointer.str = d; in property_copy_string_array()
812 if (src->is_array) { in property_entry_copy_data()
813 if (!src->length) in property_entry_copy_data()
814 return -ENODATA; in property_entry_copy_data()
816 if (src->type == DEV_PROP_STRING) { in property_entry_copy_data()
820 new = dst->pointer.str; in property_entry_copy_data()
822 new = kmemdup(pointer, src->length, GFP_KERNEL); in property_entry_copy_data()
824 return -ENOMEM; in property_entry_copy_data()
826 } else if (src->type == DEV_PROP_STRING) { in property_entry_copy_data()
827 new = kstrdup(src->value.str, GFP_KERNEL); in property_entry_copy_data()
828 if (!new && src->value.str) in property_entry_copy_data()
829 return -ENOMEM; in property_entry_copy_data()
834 dst->length = src->length; in property_entry_copy_data()
835 dst->is_array = src->is_array; in property_entry_copy_data()
836 dst->type = src->type; in property_entry_copy_data()
840 dst->name = kstrdup(src->name, GFP_KERNEL); in property_entry_copy_data()
841 if (!dst->name) in property_entry_copy_data()
848 return -ENOMEM; in property_entry_copy_data()
852 * property_entries_dup - duplicate array of properties
853 * @properties: array of properties to copy
855 * This function creates a deep copy of the given NULL-terminated array
856 * of property entries.
869 return ERR_PTR(-ENOMEM); in property_entries_dup()
874 while (--i >= 0) in property_entries_dup()
886 * property_entries_free - free previously allocated array of properties
887 * @properties: array of properties to destroy
889 * This function frees given NULL-terminated array of property entries,
896 for (p = properties; p->name; p++) in property_entries_free()
904 * pset_free_set - releases memory allocated for copied property set
905 * @pset: Property set to release
907 * Function takes previously copied property set and releases all the
915 property_entries_free(pset->properties); in pset_free_set()
920 * pset_copy_set - copies property set
921 * @pset: Property set to copy
923 * This function takes a deep copy of the given property set and returns
927 * Return: Pointer to the new property set or error pointer.
936 return ERR_PTR(-ENOMEM); in pset_copy_set()
938 properties = property_entries_dup(pset->properties); in pset_copy_set()
944 p->properties = properties; in pset_copy_set()
949 * device_remove_properties - Remove properties from a device object.
973 pset = to_pset_node(fwnode->secondary); in device_remove_properties()
974 if (pset && dev == pset->dev) in device_remove_properties()
977 if (pset && dev == pset->dev) in device_remove_properties()
983 * device_add_properties - Add a collection of properties to a device object.
997 return -EINVAL; in device_add_properties()
1005 p->fwnode.ops = &pset_fwnode_ops; in device_add_properties()
1006 set_secondary_fwnode(dev, &p->fwnode); in device_add_properties()
1007 p->dev = dev; in device_add_properties()
1013 * fwnode_get_next_parent - Iterate to the node's parent
1034 * fwnode_get_parent - Return parent firwmare node
1047 * fwnode_get_next_child_node - Return the next child node handle for a node
1060 * fwnode_get_next_available_child_node - Return the next
1086 * device_get_next_child_node - Return the next child node handle for a device
1096 if (dev->of_node) in device_get_next_child_node()
1097 fwnode = &dev->of_node->fwnode; in device_get_next_child_node()
1106 * fwnode_get_named_child_node - Return first matching named child node handle
1108 * @childname: String to match child node name against.
1119 * device_get_named_child_node - Return first matching named child node handle
1121 * @childname: String to match child node name against.
1131 * fwnode_handle_get - Obtain a reference to a device node
1146 * fwnode_handle_put - Drop reference to a device node
1160 * fwnode_device_is_available - check if a device is available for use
1170 * device_get_child_node_count - return the number of child nodes for device
1191 if (IS_ENABLED(CONFIG_OF) && dev->of_node) in device_dma_supported()
1202 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in device_get_dma_attr()
1203 if (of_dma_is_coherent(dev->of_node)) in device_get_dma_attr()
1215 * fwnode_get_phy_mode - Get phy mode for given firmware node
1218 * The function gets phy interface string from property 'phy-mode' or
1219 * 'phy-connection-type', and return its index in phy_modes table, or errno in
1227 err = fwnode_property_read_string(fwnode, "phy-mode", &pm); in fwnode_get_phy_mode()
1230 "phy-connection-type", &pm); in fwnode_get_phy_mode()
1238 return -ENODEV; in fwnode_get_phy_mode()
1243 * device_get_phy_mode - Get phy mode for given device
1246 * The function gets phy interface string from property 'phy-mode' or
1247 * 'phy-connection-type', and return its index in phy_modes table, or errno in
1268 * fwnode_get_mac_address - Get the MAC from the firmware node
1273 * Search the firmware node for the best MAC address to use. 'mac-address' is
1275 * address. If that isn't set, then 'local-mac-address' is checked next,
1279 * Note that the 'address' property is supposed to contain a virtual address of
1280 * the register set, but some DTS files have redefined that property to be the
1283 * All-zero MAC addresses are rejected, because those could be properties that
1285 * example, the DTS could define 'mac-address' and 'local-mac-address', with
1286 * zero MAC addresses. Some older U-Boots only initialized 'local-mac-address'.
1287 * In this case, the real MAC is in 'local-mac-address', and 'mac-address'
1294 res = fwnode_get_mac_addr(fwnode, "mac-address", addr, alen); in fwnode_get_mac_address()
1298 res = fwnode_get_mac_addr(fwnode, "local-mac-address", addr, alen); in fwnode_get_mac_address()
1307 * device_get_mac_address - Get the MAC for a given device
1319 * fwnode_irq_get - Get IRQ directly from a fwnode
1321 * @index: Zero-based index of the IRQ
1344 * device_graph_get_next_endpoint - Get next endpoint firmware node
1360 * fwnode_graph_get_port_parent - Return the device fwnode of a port endpoint
1380 * fwnode_graph_get_remote_port_parent - Return fwnode of a remote device
1400 * fwnode_graph_get_remote_port - Return fwnode of a remote port
1413 * fwnode_graph_get_remote_endpoint - Return fwnode of a remote endpoint
1426 * fwnode_graph_get_remote_node - get remote parent node for given port/endpoint
1464 * fwnode_graph_parse_endpoint - parse common endpoint node properties