1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Function to read values from the device tree node attached to a udevice.
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
12 #include <linux/errno.h>
14 #include <dm/device.h>
15 #include <dm/fdtaddr.h>
16 #include <dm/ofnode.h>
17 #include <dm/uclass.h>
21 #if CONFIG_IS_ENABLED(OF_LIVE)
22 static inline const struct device_node *dev_np(const struct udevice *dev)
24 return ofnode_to_np(dev_ofnode(dev));
27 static inline const struct device_node *dev_np(const struct udevice *dev)
33 #if !defined(CONFIG_DM_DEV_READ_INLINE) || CONFIG_IS_ENABLED(OF_PLATDATA)
35 * dev_read_u32() - read a 32-bit integer from a device's DT property
37 * @dev: device to read DT property from
38 * @propname: name of the property to read from
39 * @outp: place to put value (if found)
40 * Return: 0 if OK, -ve on error
42 int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
45 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
47 * @dev: device to read DT property from
48 * @propname: name of the property to read from
49 * @def: default value to return if the property has no value
50 * Return: property value, or @def if not found
52 int dev_read_u32_default(const struct udevice *dev, const char *propname,
56 * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
59 * @dev: device to read DT property from
60 * @propname: name of the property to read from
61 * @index: index of the integer to return
62 * @outp: place to put value (if found)
63 * Return: 0 if OK, -ve on error
65 int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
69 * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
72 * @dev: device to read DT property from
73 * @propname: name of the property to read from
74 * @index: index of the integer to return
75 * @def: default value to return if the property has no value
76 * Return: property value, or @def if not found
78 u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
82 * dev_read_s32() - read a signed 32-bit integer from a device's DT property
84 * @dev: device to read DT property from
85 * @propname: name of the property to read from
86 * @outp: place to put value (if found)
87 * Return: 0 if OK, -ve on error
89 int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
92 * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
94 * @dev: device to read DT property from
95 * @propname: name of the property to read from
96 * @def: default value to return if the property has no value
97 * Return: property value, or @def if not found
99 int dev_read_s32_default(const struct udevice *dev, const char *propname,
103 * dev_read_u32u() - read a 32-bit integer from a device's DT property
105 * This version uses a standard uint type.
107 * @dev: device to read DT property from
108 * @propname: name of the property to read from
109 * @outp: place to put value (if found)
110 * Return: 0 if OK, -ve on error
112 int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
115 * dev_read_u64() - read a 64-bit integer from a device's DT property
117 * @dev: device to read DT property from
118 * @propname: name of the property to read from
119 * @outp: place to put value (if found)
120 * Return: 0 if OK, -ve on error
122 int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
125 * dev_read_u64_default() - read a 64-bit integer from a device's DT property
127 * @dev: device to read DT property from
128 * @propname: name of the property to read from
129 * @def: default value to return if the property has no value
130 * Return: property value, or @def if not found
132 u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
136 * dev_read_string() - Read a string from a device's DT property
138 * @dev: device to read DT property from
139 * @propname: name of the property to read
140 * Return: string from property value, or NULL if there is no such property
142 const char *dev_read_string(const struct udevice *dev, const char *propname);
145 * dev_read_bool() - read a boolean value from a device's DT property
147 * @dev: device to read DT property from
148 * @propname: name of property to read
149 * Return: true if property is present (meaning true), false if not present
151 bool dev_read_bool(const struct udevice *dev, const char *propname);
154 * dev_read_subnode() - find a named subnode of a device
156 * @dev: device whose DT node contains the subnode
157 * @subnode_name: name of subnode to find
158 * Return: reference to subnode (which can be invalid if there is no such
161 ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name);
164 * dev_read_size() - read the size of a property
166 * @dev: device to check
167 * @propname: property to check
168 * Return: size of property if present, or -EINVAL if not
170 int dev_read_size(const struct udevice *dev, const char *propname);
173 * dev_read_addr_index() - Get the indexed reg property of a device
175 * @dev: Device to read from
176 * @index: the 'reg' property can hold a list of <addr, size> pairs
177 * and @index is used to select which one is required
179 * Return: address or FDT_ADDR_T_NONE if not found
181 fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
184 * dev_read_addr_index_ptr() - Get the indexed reg property of a device
187 * @dev: Device to read from
188 * @index: the 'reg' property can hold a list of <addr, size> pairs
189 * and @index is used to select which one is required
191 * Return: pointer or NULL if not found
193 void *dev_read_addr_index_ptr(const struct udevice *dev, int index);
196 * dev_read_addr_size_index() - Get the indexed reg property of a device
198 * @dev: Device to read from
199 * @index: the 'reg' property can hold a list of <addr, size> pairs
200 * and @index is used to select which one is required
201 * @size: place to put size value (on success)
203 * Return: address or FDT_ADDR_T_NONE if not found
205 fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
209 * dev_remap_addr_index() - Get the indexed reg property of a device
210 * as a memory-mapped I/O pointer
212 * @dev: Device to read from
213 * @index: the 'reg' property can hold a list of <addr, size> pairs
214 * and @index is used to select which one is required
216 * Return: pointer or NULL if not found
218 void *dev_remap_addr_index(const struct udevice *dev, int index);
221 * dev_read_addr_name() - Get the reg property of a device, indexed by name
223 * @dev: Device to read from
224 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
225 * 'reg-names' property providing named-based identification. @index
226 * indicates the value to search for in 'reg-names'.
228 * Return: address or FDT_ADDR_T_NONE if not found
230 fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
233 * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
235 * @dev: Device to read from
236 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
237 * 'reg-names' property providing named-based identification. @index
238 * indicates the value to search for in 'reg-names'.
239 * @size: place to put size value (on success)
241 * Return: address or FDT_ADDR_T_NONE if not found
243 fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
247 * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
248 * as a memory-mapped I/O pointer
250 * @dev: Device to read from
251 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
252 * 'reg-names' property providing named-based identification. @index
253 * indicates the value to search for in 'reg-names'.
255 * Return: pointer or NULL if not found
257 void *dev_remap_addr_name(const struct udevice *dev, const char *name);
260 * dev_read_addr() - Get the reg property of a device
262 * @dev: Device to read from
264 * Return: address or FDT_ADDR_T_NONE if not found
266 fdt_addr_t dev_read_addr(const struct udevice *dev);
269 * dev_read_addr_ptr() - Get the reg property of a device
272 * @dev: Device to read from
274 * Return: pointer or NULL if not found
276 void *dev_read_addr_ptr(const struct udevice *dev);
279 * dev_read_addr_pci() - Read an address and handle PCI address translation
281 * At present U-Boot does not have address translation logic for PCI in the
282 * livetree implementation (of_addr.c). This special function supports this for
283 * the flat tree implementation.
285 * This function should be removed (and code should use dev_read() instead)
288 * 1. PCI address translation is added; and either
289 * 2. everything uses livetree where PCI translation is used (which is feasible
290 * in SPL and U-Boot proper) or PCI address translation is added to
291 * fdtdec_get_addr() and friends.
293 * @dev: Device to read from
294 * Return: address or FDT_ADDR_T_NONE if not found
296 fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
299 * dev_remap_addr() - Get the reg property of a device as a
300 * memory-mapped I/O pointer
302 * @dev: Device to read from
304 * Return: pointer or NULL if not found
306 void *dev_remap_addr(const struct udevice *dev);
309 * dev_read_addr_size() - get address and size from a device property
311 * This does no address translation. It simply reads an property that contains
312 * an address and a size value, one after the other.
314 * @dev: Device to read from
315 * @propname: property to read
316 * @sizep: place to put size value (on success)
317 * Return: address value, or FDT_ADDR_T_NONE on error
319 fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
323 * dev_read_name() - get the name of a device's node
325 * @dev: Device to read from
326 * Return: name of node
328 const char *dev_read_name(const struct udevice *dev);
331 * dev_read_stringlist_search() - find string in a string list and return index
333 * Note that it is possible for this function to succeed on property values
334 * that are not NUL-terminated. That's because the function will stop after
335 * finding the first occurrence of @string. This can for example happen with
336 * small-valued cell properties, such as #address-cells, when searching for
339 * @dev: device to check
340 * @propname: name of the property containing the string list
341 * @string: string to look up in the string list
344 * the index of the string in the list of strings
345 * -ENODATA if the property is not found
346 * -EINVAL on some other error
348 int dev_read_stringlist_search(const struct udevice *dev, const char *propname,
352 * dev_read_string_index() - obtain an indexed string from a string list
354 * @dev: device to examine
355 * @propname: name of the property containing the string list
356 * @index: index of the string to return
357 * @outp: return location for the string
360 * length of string, if found or -ve error value if not found
362 int dev_read_string_index(const struct udevice *dev, const char *propname,
363 int index, const char **outp);
366 * dev_read_string_count() - find the number of strings in a string list
368 * @dev: device to examine
369 * @propname: name of the property containing the string list
371 * number of strings in the list, or -ve error value if not found
373 int dev_read_string_count(const struct udevice *dev, const char *propname);
376 * dev_read_string_list() - read a list of strings
378 * This produces a list of string pointers with each one pointing to a string
379 * in the string list. If the property does not exist, it returns {NULL}.
381 * The data is allocated and the caller is reponsible for freeing the return
382 * value (the list of string pointers). The strings themselves may not be
383 * changed as they point directly into the devicetree property.
385 * @dev: device to examine
386 * @propname: name of the property containing the string list
387 * @listp: returns an allocated, NULL-terminated list of strings if the return
388 * value is > 0, else is set to NULL
390 * number of strings in list, 0 if none, -ENOMEM if out of memory,
391 * -ENOENT if no such property
393 int dev_read_string_list(const struct udevice *dev, const char *propname,
394 const char ***listp);
397 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
399 * This function is useful to parse lists of phandles and their arguments.
400 * Returns 0 on success and fills out_args, on error returns appropriate
403 * Caller is responsible to call of_node_put() on the returned out_args->np
417 * list = <&phandle1 1 2 &phandle2 3>;
420 * To get a device_node of the `node2' node you may call this:
421 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
423 * @dev: device whose node containing a list
424 * @list_name: property name that contains a list
425 * @cells_name: property name that specifies phandles' arguments count
426 * @cell_count: Cell count to use if @cells_name is NULL
427 * @index: index of a phandle to parse out
428 * @out_args: optional pointer to output arguments structure (will be filled)
429 * Return: 0 on success (with @out_args filled out if not NULL), -ENOENT if
430 * @list_name does not exist, -EINVAL if a phandle was not found,
431 * @cells_name could not be found, the arguments were truncated or there
432 * were too many arguments.
434 int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
435 const char *cells_name, int cell_count,
436 int index, struct ofnode_phandle_args *out_args);
439 * dev_count_phandle_with_args() - Return phandle number in a list
441 * This function is usefull to get phandle number contained in a property list.
442 * For example, this allows to allocate the right amount of memory to keep
443 * clock's reference contained into the "clocks" property.
445 * @dev: device whose node containing a list
446 * @list_name: property name that contains a list
447 * @cells_name: property name that specifies phandles' arguments count
448 * @cell_count: Cell count to use if @cells_name is NULL
449 * Return: number of phandle found on success, on error returns appropriate
453 int dev_count_phandle_with_args(const struct udevice *dev,
454 const char *list_name, const char *cells_name,
458 * dev_read_addr_cells() - Get the number of address cells for a device's node
460 * This walks back up the tree to find the closest #address-cells property
461 * which controls the given node.
463 * @dev: device to check
464 * Return: number of address cells this node uses
466 int dev_read_addr_cells(const struct udevice *dev);
469 * dev_read_size_cells() - Get the number of size cells for a device's node
471 * This walks back up the tree to find the closest #size-cells property
472 * which controls the given node.
474 * @dev: device to check
475 * Return: number of size cells this node uses
477 int dev_read_size_cells(const struct udevice *dev);
480 * dev_read_addr_cells() - Get the address cells property in a node
482 * This function matches fdt_address_cells().
484 * @dev: device to check
485 * Return: number of address cells this node uses
487 int dev_read_simple_addr_cells(const struct udevice *dev);
490 * dev_read_size_cells() - Get the size cells property in a node
492 * This function matches fdt_size_cells().
494 * @dev: device to check
495 * Return: number of size cells this node uses
497 int dev_read_simple_size_cells(const struct udevice *dev);
500 * dev_read_phandle() - Get the phandle from a device
502 * @dev: device to check
503 * Return: phandle (1 or greater), or 0 if no phandle or other error
505 int dev_read_phandle(const struct udevice *dev);
508 * dev_read_prop()- - read a property from a device's node
510 * @dev: device to check
511 * @propname: property to read
512 * @lenp: place to put length on success
513 * Return: pointer to property, or NULL if not found
515 const void *dev_read_prop(const struct udevice *dev, const char *propname,
519 * dev_read_first_prop()- get the reference of the first property
521 * Get reference to the first property of the node, it is used to iterate
522 * and read all the property with dev_read_prop_by_prop().
524 * @dev: device to check
525 * @prop: place to put argument reference
526 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
528 int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
531 * ofnode_get_next_property() - get the reference of the next property
533 * Get reference to the next property of the node, it is used to iterate
534 * and read all the property with dev_read_prop_by_prop().
536 * @prop: reference of current argument and place to put reference of next one
537 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
539 int dev_read_next_prop(struct ofprop *prop);
542 * dev_read_prop_by_prop() - get a pointer to the value of a property
544 * Get value for the property identified by the provided reference.
546 * @prop: reference on property
547 * @propname: If non-NULL, place to property name on success,
548 * @lenp: If non-NULL, place to put length on success
549 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
551 const void *dev_read_prop_by_prop(struct ofprop *prop,
552 const char **propname, int *lenp);
555 * dev_read_alias_seq() - Get the alias sequence number of a node
557 * This works out whether a node is pointed to by an alias, and if so, the
558 * sequence number of that alias. Aliases are of the form <base><num> where
559 * <num> is the sequence number. For example spi2 would be sequence number 2.
561 * @dev: device to look up
562 * @devnump: set to the sequence number if one is found
563 * Return: 0 if a sequence was found, -ve if not
565 int dev_read_alias_seq(const struct udevice *dev, int *devnump);
568 * dev_read_u32_array() - Find and read an array of 32 bit integers
570 * Search for a property in a device node and read 32-bit value(s) from
573 * The out_values is modified only if a valid u32 value can be decoded.
575 * @dev: device to look up
576 * @propname: name of the property to read
577 * @out_values: pointer to return value, modified only if return value is 0
578 * @sz: number of array elements to read
579 * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if
580 * property does not have a value, and -EOVERFLOW if the property data isn't
583 int dev_read_u32_array(const struct udevice *dev, const char *propname,
584 u32 *out_values, size_t sz);
587 * dev_read_first_subnode() - find the first subnode of a device's node
589 * @dev: device to look up
590 * Return: reference to the first subnode (which can be invalid if the device's
591 * node has no subnodes)
593 ofnode dev_read_first_subnode(const struct udevice *dev);
596 * ofnode_next_subnode() - find the next sibling of a subnode
598 * @node: valid reference to previous node (sibling)
599 * Return: reference to the next subnode (which can be invalid if the node
600 * has no more siblings)
602 ofnode dev_read_next_subnode(ofnode node);
605 * dev_read_u8_array_ptr() - find an 8-bit array
607 * Look up a device's node property and return a pointer to its contents as a
608 * byte array of given length. The property must have at least enough data
609 * for the array (count bytes). It may have more, but this will be ignored.
610 * The data is not copied.
612 * @dev: device to look up
613 * @propname: name of property to find
614 * @sz: number of array elements
616 * pointer to byte array if found, or NULL if the property is not found or
617 * there is not enough data
619 const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
620 const char *propname, size_t sz);
623 * dev_read_enabled() - check whether a node is enabled
625 * This looks for a 'status' property. If this exists, then returns 1 if
626 * the status is 'ok' and 0 otherwise. If there is no status property,
627 * it returns 1 on the assumption that anything mentioned should be enabled
630 * @dev: device to examine
631 * Return: integer value 0 (not enabled) or 1 (enabled)
633 int dev_read_enabled(const struct udevice *dev);
636 * dev_read_resource() - obtain an indexed resource from a device.
638 * @dev: device to examine
639 * @index: index of the resource to retrieve (0 = first)
640 * @res: returns the resource
641 * Return: 0 if ok, negative on error
643 int dev_read_resource(const struct udevice *dev, uint index,
644 struct resource *res);
647 * dev_read_resource_byname() - obtain a named resource from a device.
649 * @dev: device to examine
650 * @name: name of the resource to retrieve
651 * @res: returns the resource
652 * Return: 0 if ok, negative on error
654 int dev_read_resource_byname(const struct udevice *dev, const char *name,
655 struct resource *res);
658 * dev_translate_address() - Translate a device-tree address
660 * Translate an address from the device-tree into a CPU physical address. This
661 * function walks up the tree and applies the various bus mappings along the
664 * @dev: device giving the context in which to translate the address
665 * @in_addr: pointer to the address to translate
666 * Return: the translated address; OF_BAD_ADDR on error
668 u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
671 * dev_translate_dma_address() - Translate a device-tree DMA address
673 * Translate a DMA address from the device-tree into a CPU physical address.
674 * This function walks up the tree and applies the various bus mappings along
677 * @dev: device giving the context in which to translate the DMA address
678 * @in_addr: pointer to the DMA address to translate
679 * Return: the translated DMA address; OF_BAD_ADDR on error
681 u64 dev_translate_dma_address(const struct udevice *dev,
682 const fdt32_t *in_addr);
685 * dev_get_dma_range() - Get a device's DMA constraints
687 * Provide the address bases and size of the linear mapping between the CPU and
688 * a device's BUS address space.
690 * @dev: device giving the context in which to translate the DMA address
691 * @cpu: base address for CPU's view of memory
692 * @bus: base address for BUS's view of memory
693 * @size: size of the address space
694 * Return: 0 if ok, negative on error
696 int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu,
697 dma_addr_t *bus, u64 *size);
700 * dev_read_alias_highest_id - Get highest alias id for the given stem
701 * @stem: Alias stem to be examined
703 * The function travels the lookup table to get the highest alias id for the
705 * Return: alias ID, if found, else -1
707 int dev_read_alias_highest_id(const char *stem);
710 * dev_get_child_count() - get the child count of a device
712 * @dev: device to use for interation (`struct udevice *`)
713 * Return: the count of child subnode
715 int dev_get_child_count(const struct udevice *dev);
718 * dev_read_pci_bus_range - Read PCI bus-range resource
720 * Look at the bus range property of a device node and return the pci bus
721 * range for this node.
723 * @dev: device to examine
724 * @res: returns the resource
725 * Return: 0 if ok, negative on error
727 int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
730 * dev_decode_display_timing() - decode display timings
732 * Decode display timings from the supplied 'display-timings' node.
733 * See doc/device-tree-bindings/video/display-timing.txt for binding
736 * @dev: device to read DT display timings from. The node linked to the device
737 * contains a child node called 'display-timings' which in turn contains
738 * one or more display timing nodes.
739 * @index: index number to read (0=first timing subnode)
740 * @config: place to put timings
741 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
743 int dev_decode_display_timing(const struct udevice *dev, int index,
744 struct display_timing *config);
747 * dev_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
749 * This function parses PHY handle from the Ethernet controller's ofnode
750 * (trying all possible PHY handle property names), and returns the PHY ofnode.
752 * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
753 * if the result to that is true, this function should not be called.
755 * @dev: device representing the MAC
756 * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
758 ofnode dev_get_phy_node(const struct udevice *dev);
761 * dev_read_phy_mode() - Read PHY connection type from a MAC
763 * This function parses the "phy-mode" / "phy-connection-type" property and
764 * returns the corresponding PHY interface type.
766 * @dev: device representing the MAC
767 * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on
770 phy_interface_t dev_read_phy_mode(const struct udevice *dev);
772 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
773 #include <asm/global_data.h>
775 static inline int dev_read_u32(const struct udevice *dev,
776 const char *propname, u32 *outp)
778 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
781 static inline int dev_read_u32_default(const struct udevice *dev,
782 const char *propname, int def)
784 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
787 static inline int dev_read_u32_index(struct udevice *dev,
788 const char *propname, int index, u32 *outp)
790 return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
793 static inline u32 dev_read_u32_index_default(struct udevice *dev,
794 const char *propname, int index,
797 return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
801 static inline int dev_read_s32(const struct udevice *dev,
802 const char *propname, s32 *outp)
804 return ofnode_read_s32(dev_ofnode(dev), propname, outp);
807 static inline int dev_read_s32_default(const struct udevice *dev,
808 const char *propname, int def)
810 return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
813 static inline int dev_read_u32u(const struct udevice *dev,
814 const char *propname, uint *outp)
819 ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
827 static inline int dev_read_u64(const struct udevice *dev,
828 const char *propname, u64 *outp)
830 return ofnode_read_u64(dev_ofnode(dev), propname, outp);
833 static inline u64 dev_read_u64_default(const struct udevice *dev,
834 const char *propname, u64 def)
836 return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
839 static inline const char *dev_read_string(const struct udevice *dev,
840 const char *propname)
842 return ofnode_read_string(dev_ofnode(dev), propname);
845 static inline bool dev_read_bool(const struct udevice *dev,
846 const char *propname)
848 return ofnode_read_bool(dev_ofnode(dev), propname);
851 static inline ofnode dev_read_subnode(const struct udevice *dev,
852 const char *subbnode_name)
854 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
857 static inline int dev_read_size(const struct udevice *dev, const char *propname)
859 return ofnode_read_size(dev_ofnode(dev), propname);
862 static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
865 return devfdt_get_addr_index(dev, index);
868 static inline void *dev_read_addr_index_ptr(const struct udevice *dev,
871 return devfdt_get_addr_index_ptr(dev, index);
874 static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
878 return devfdt_get_addr_size_index(dev, index, size);
881 static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
884 return devfdt_get_addr_name(dev, name);
887 static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
891 return devfdt_get_addr_size_name(dev, name, size);
894 static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
896 return devfdt_get_addr(dev);
899 static inline void *dev_read_addr_ptr(const struct udevice *dev)
901 return devfdt_get_addr_ptr(dev);
904 static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
906 return devfdt_get_addr_pci(dev);
909 static inline void *dev_remap_addr(const struct udevice *dev)
911 return devfdt_remap_addr(dev);
914 static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
916 return devfdt_remap_addr_index(dev, index);
919 static inline void *dev_remap_addr_name(const struct udevice *dev,
922 return devfdt_remap_addr_name(dev, name);
925 static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
926 const char *propname,
929 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
932 static inline const char *dev_read_name(const struct udevice *dev)
934 return ofnode_get_name(dev_ofnode(dev));
937 static inline int dev_read_stringlist_search(const struct udevice *dev,
938 const char *propname,
941 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
944 static inline int dev_read_string_index(const struct udevice *dev,
945 const char *propname, int index,
948 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
951 static inline int dev_read_string_count(const struct udevice *dev,
952 const char *propname)
954 return ofnode_read_string_count(dev_ofnode(dev), propname);
957 static inline int dev_read_string_list(const struct udevice *dev,
958 const char *propname,
961 return ofnode_read_string_list(dev_ofnode(dev), propname, listp);
964 static inline int dev_read_phandle_with_args(const struct udevice *dev,
965 const char *list_name, const char *cells_name, int cell_count,
966 int index, struct ofnode_phandle_args *out_args)
968 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
969 cells_name, cell_count, index,
973 static inline int dev_count_phandle_with_args(const struct udevice *dev,
974 const char *list_name, const char *cells_name, int cell_count)
976 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
977 cells_name, cell_count);
980 static inline int dev_read_addr_cells(const struct udevice *dev)
982 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
984 return fdt_address_cells(gd->fdt_blob, parent);
987 static inline int dev_read_size_cells(const struct udevice *dev)
989 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
991 return fdt_size_cells(gd->fdt_blob, parent);
994 static inline int dev_read_simple_addr_cells(const struct udevice *dev)
996 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
999 static inline int dev_read_simple_size_cells(const struct udevice *dev)
1001 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
1004 static inline int dev_read_phandle(const struct udevice *dev)
1006 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
1009 static inline const void *dev_read_prop(const struct udevice *dev,
1010 const char *propname, int *lenp)
1012 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
1015 static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
1017 return ofnode_get_first_property(dev_ofnode(dev), prop);
1020 static inline int dev_read_next_prop(struct ofprop *prop)
1022 return ofnode_get_next_property(prop);
1025 static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
1026 const char **propname,
1029 return ofnode_get_property_by_prop(prop, propname, lenp);
1032 static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
1034 #if CONFIG_IS_ENABLED(OF_CONTROL)
1035 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
1036 dev_of_offset(dev), devnump);
1042 static inline int dev_read_u32_array(const struct udevice *dev,
1043 const char *propname, u32 *out_values,
1046 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
1049 static inline ofnode dev_read_first_subnode(const struct udevice *dev)
1051 return ofnode_first_subnode(dev_ofnode(dev));
1054 static inline ofnode dev_read_next_subnode(ofnode node)
1056 return ofnode_next_subnode(node);
1059 static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
1060 const char *propname,
1063 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
1066 static inline int dev_read_enabled(const struct udevice *dev)
1068 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
1071 static inline int dev_read_resource(const struct udevice *dev, uint index,
1072 struct resource *res)
1074 return ofnode_read_resource(dev_ofnode(dev), index, res);
1077 static inline int dev_read_resource_byname(const struct udevice *dev,
1079 struct resource *res)
1081 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
1084 static inline u64 dev_translate_address(const struct udevice *dev,
1085 const fdt32_t *in_addr)
1087 return ofnode_translate_address(dev_ofnode(dev), in_addr);
1090 static inline u64 dev_translate_dma_address(const struct udevice *dev,
1091 const fdt32_t *in_addr)
1093 return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
1096 static inline int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu,
1097 dma_addr_t *bus, u64 *size)
1099 return ofnode_get_dma_range(dev_ofnode(dev), cpu, bus, size);
1102 static inline int dev_read_alias_highest_id(const char *stem)
1104 if (!CONFIG_IS_ENABLED(OF_LIBFDT) || !gd->fdt_blob)
1106 return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
1109 static inline int dev_get_child_count(const struct udevice *dev)
1111 return ofnode_get_child_count(dev_ofnode(dev));
1114 static inline int dev_decode_display_timing(const struct udevice *dev,
1116 struct display_timing *config)
1118 return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
1121 static inline ofnode dev_get_phy_node(const struct udevice *dev)
1123 return ofnode_get_phy_node(dev_ofnode(dev));
1126 static inline phy_interface_t dev_read_phy_mode(const struct udevice *dev)
1128 return ofnode_read_phy_mode(dev_ofnode(dev));
1131 #endif /* CONFIG_DM_DEV_READ_INLINE */
1134 * dev_for_each_subnode() - Helper function to iterate through subnodes
1136 * This creates a for() loop which works through the subnodes in a device's
1139 * @subnode: ofnode holding the current subnode
1140 * @dev: device to use for interation (`struct udevice *`)
1142 #define dev_for_each_subnode(subnode, dev) \
1143 for (subnode = dev_read_first_subnode(dev); \
1144 ofnode_valid(subnode); \
1145 subnode = ofnode_next_subnode(subnode))
1148 * dev_for_each_property() - Helper function to iterate through property
1150 * This creates a for() loop which works through the property in a device's
1153 * @prop: struct ofprop holding the current property
1154 * @dev: device to use for interation (`struct udevice *`)
1156 #define dev_for_each_property(prop, dev) \
1157 for (int ret_prop = dev_read_first_prop(dev, &prop); \
1159 ret_prop = dev_read_next_prop(&prop))