1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2017 Google, Inc
13 #include <dm/of_access.h>
16 /* Enable checks to protect against invalid calls */
22 * typedef union ofnode_union ofnode - reference to a device tree node
24 * This union can hold either a straightforward pointer to a struct device_node
25 * in the live device tree, or an offset within the flat device tree. In the
26 * latter case, the pointer value is just the integer offset within the flat DT.
28 * Thus we can reference nodes in both the live tree (once available) and the
29 * flat tree (until then). Functions are available to translate between an
30 * ofnode and either an offset or a `struct device_node *`.
32 * The reference can also hold a null offset, in which case the pointer value
33 * here is NULL. This corresponds to a struct device_node * value of
34 * NULL, or an offset of -1.
36 * There is no ambiguity as to whether ofnode holds an offset or a node
37 * pointer: when the live tree is active it holds a node pointer, otherwise it
38 * holds an offset. The value itself does not need to be unique and in theory
39 * the same value could point to a valid device node or a valid offset. We
40 * could arrange for a unique value to be used (e.g. by making the pointer
41 * point to an offset within the flat device tree in the case of an offset) but
42 * this increases code size slightly due to the subtraction. Since it offers no
43 * real benefit, the approach described here seems best.
45 * For now these points use constant types, since we don't allow writing
48 * @np: Pointer to device node, used for live tree
49 * @of_offset: Pointer into flat device tree, used for flat tree. Note that this
50 * is not a really a pointer to a node: it is an offset value. See above.
52 typedef union ofnode_union {
53 const struct device_node *np;
57 struct ofnode_phandle_args {
60 uint32_t args[OF_MAX_PHANDLE_ARGS];
64 * struct ofprop - reference to a property of a device tree node
66 * This struct hold the reference on one property of one node,
67 * using struct ofnode and an offset within the flat device tree or either
68 * a pointer to a struct property in the live device tree.
70 * Thus we can reference arguments in both the live tree and the flat tree.
72 * The property reference can also hold a null reference. This corresponds to
73 * a struct property NULL pointer or an offset of -1.
75 * @node: Pointer to device node
76 * @offset: Pointer into flat device tree, used for flat tree.
77 * @prop: Pointer to property, used for live treee.
84 const struct property *prop;
89 * ofnode_to_np() - convert an ofnode to a live DT node pointer
91 * This cannot be called if the reference contains an offset.
93 * @node: Reference containing struct device_node * (possibly invalid)
94 * Return: pointer to device node (can be NULL)
96 static inline const struct device_node *ofnode_to_np(ofnode node)
99 if (!of_live_active())
106 * ofnode_to_offset() - convert an ofnode to a flat DT offset
108 * This cannot be called if the reference contains a node pointer.
110 * @node: Reference containing offset (possibly invalid)
111 * Return: DT offset (can be -1)
113 static inline int ofnode_to_offset(ofnode node)
116 if (of_live_active())
119 return node.of_offset;
123 * ofnode_valid() - check if an ofnode is valid
125 * @node: Reference containing offset (possibly invalid)
126 * Return: true if the reference contains a valid ofnode, false if it is NULL
128 static inline bool ofnode_valid(ofnode node)
130 if (of_live_active())
131 return node.np != NULL;
133 return node.of_offset >= 0;
137 * offset_to_ofnode() - convert a DT offset to an ofnode
139 * @of_offset: DT offset (either valid, or -1)
140 * Return: reference to the associated DT offset
142 static inline ofnode offset_to_ofnode(int of_offset)
146 if (of_live_active())
149 node.of_offset = of_offset >= 0 ? of_offset : -1;
155 * np_to_ofnode() - convert a node pointer to an ofnode
157 * @np: Live node pointer (can be NULL)
158 * Return: reference to the associated node pointer
160 static inline ofnode np_to_ofnode(const struct device_node *np)
170 * ofnode_is_np() - check if a reference is a node pointer
172 * This function associated that if there is a valid live tree then all
173 * references will use it. This is because using the flat DT when the live tree
174 * is valid is not permitted.
176 * @node: reference to check (possibly invalid)
177 * Return: true if the reference is a live node pointer, false if it is a DT
180 static inline bool ofnode_is_np(ofnode node)
184 * Check our assumption that flat tree offsets are not used when a
185 * live tree is in use.
187 assert(!ofnode_valid(node) ||
188 (of_live_active() ? ofnode_to_np(node)
189 : ofnode_to_np(node)));
191 return of_live_active() && ofnode_valid(node);
195 * ofnode_equal() - check if two references are equal
197 * @ref1: first reference to check (possibly invalid)
198 * @ref2: second reference to check (possibly invalid)
199 * Return: true if equal, else false
201 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
203 /* We only need to compare the contents */
204 return ref1.of_offset == ref2.of_offset;
208 * ofnode_null() - Obtain a null ofnode
210 * This returns an ofnode which points to no node. It works both with the flat
213 static inline ofnode ofnode_null(void)
217 if (of_live_active())
225 static inline ofnode ofnode_root(void)
229 if (of_live_active())
230 node.np = gd_of_root();
238 * ofnode_name_eq() - Check if the node name is equivalent to a given name
239 * ignoring the unit address
241 * @node: valid node reference that has to be compared
242 * @name: name that has to be compared with the node name
243 * Return: true if matches, false if it doesn't match
245 bool ofnode_name_eq(ofnode node, const char *name);
248 * ofnode_read_u32() - Read a 32-bit integer from a property
250 * @node: valid node reference to read property from
251 * @propname: name of the property to read from
252 * @outp: place to put value (if found)
253 * Return: 0 if OK, -ve on error
255 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
258 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
260 * @node: valid node reference to read property from
261 * @propname: name of the property to read from
262 * @index: index of the integer to return
263 * @outp: place to put value (if found)
264 * Return: 0 if OK, -ve on error
266 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
270 * ofnode_read_s32() - Read a 32-bit integer from a property
272 * @node: valid node reference to read property from
273 * @propname: name of the property to read from
274 * @outp: place to put value (if found)
275 * Return: 0 if OK, -ve on error
277 static inline int ofnode_read_s32(ofnode node, const char *propname,
280 return ofnode_read_u32(node, propname, (u32 *)outp);
284 * ofnode_read_u32_default() - Read a 32-bit integer from a property
286 * @node: valid node reference to read property from
287 * @propname: name of the property to read from
288 * @def: default value to return if the property has no value
289 * Return: property value, or @def if not found
291 u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def);
294 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
297 * @node: valid node reference to read property from
298 * @propname: name of the property to read from
299 * @index: index of the integer to return
300 * @def: default value to return if the property has no value
301 * Return: property value, or @def if not found
303 u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
307 * ofnode_read_s32_default() - Read a 32-bit integer from a property
309 * @node: valid node reference to read property from
310 * @propname: name of the property to read from
311 * @def: default value to return if the property has no value
312 * Return: property value, or @def if not found
314 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
317 * ofnode_read_u64() - Read a 64-bit integer from a property
319 * @node: valid node reference to read property from
320 * @propname: name of the property to read from
321 * @outp: place to put value (if found)
322 * Return: 0 if OK, -ve on error
324 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
327 * ofnode_read_u64_default() - Read a 64-bit integer from a property
329 * @node: valid node reference to read property from
330 * @propname: name of the property to read from
331 * @def: default value to return if the property has no value
332 * Return: property value, or @def if not found
334 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
337 * ofnode_read_prop() - Read a property from a node
339 * @node: valid node reference to read property from
340 * @propname: name of the property to read
341 * @sizep: if non-NULL, returns the size of the property, or an error code
343 * Return: property value, or NULL if there is no such property
345 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
348 * ofnode_read_string() - Read a string from a property
350 * @node: valid node reference to read property from
351 * @propname: name of the property to read
352 * Return: string from property value, or NULL if there is no such property
354 const char *ofnode_read_string(ofnode node, const char *propname);
357 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
359 * @node: valid node reference to read property from
360 * @propname: name of the property to read
361 * @out_values: pointer to return value, modified only if return value is 0
362 * @sz: number of array elements to read
363 * Return: 0 if OK, -ve on error
365 * Search for a property in a device node and read 32-bit value(s) from
366 * it. Returns 0 on success, -EINVAL if the property does not exist,
367 * -ENODATA if property does not have a value, and -EOVERFLOW if the
368 * property data isn't large enough.
370 * The out_values is modified only if a valid u32 value can be decoded.
372 int ofnode_read_u32_array(ofnode node, const char *propname,
373 u32 *out_values, size_t sz);
376 * ofnode_read_bool() - read a boolean value from a property
378 * @node: valid node reference to read property from
379 * @propname: name of property to read
380 * Return: true if property is present (meaning true), false if not present
382 bool ofnode_read_bool(ofnode node, const char *propname);
385 * ofnode_find_subnode() - find a named subnode of a parent node
387 * @node: valid reference to parent node
388 * @subnode_name: name of subnode to find
389 * Return: reference to subnode (which can be invalid if there is no such
392 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
394 #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
395 #include <asm/global_data.h>
397 static inline bool ofnode_is_enabled(ofnode node)
399 if (ofnode_is_np(node)) {
400 return of_device_is_available(ofnode_to_np(node));
402 return fdtdec_get_is_enabled(gd->fdt_blob,
403 ofnode_to_offset(node));
407 static inline ofnode ofnode_first_subnode(ofnode node)
409 assert(ofnode_valid(node));
410 if (ofnode_is_np(node))
411 return np_to_ofnode(node.np->child);
413 return offset_to_ofnode(
414 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
417 static inline ofnode ofnode_next_subnode(ofnode node)
419 assert(ofnode_valid(node));
420 if (ofnode_is_np(node))
421 return np_to_ofnode(node.np->sibling);
423 return offset_to_ofnode(
424 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
428 * ofnode_is_enabled() - Checks whether a node is enabled.
429 * This looks for a 'status' property. If this exists, then returns true if
430 * the status is 'okay' and false otherwise. If there is no status property,
431 * it returns true on the assumption that anything mentioned should be enabled
434 * @node: node to examine
435 * Return: false (not enabled) or true (enabled)
437 bool ofnode_is_enabled(ofnode node);
440 * ofnode_first_subnode() - find the first subnode of a parent node
442 * @node: valid reference to a valid parent node
443 * Return: reference to the first subnode (which can be invalid if the parent
444 * node has no subnodes)
446 ofnode ofnode_first_subnode(ofnode node);
449 * ofnode_next_subnode() - find the next sibling of a subnode
451 * @node: valid reference to previous node (sibling)
452 * Return: reference to the next subnode (which can be invalid if the node
453 * has no more siblings)
455 ofnode ofnode_next_subnode(ofnode node);
456 #endif /* DM_INLINE_OFNODE */
459 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
461 * @node: valid node to look up
462 * Return: ofnode reference of the parent node
464 ofnode ofnode_get_parent(ofnode node);
467 * ofnode_get_name() - get the name of a node
469 * @node: valid node to look up
470 * Return: name of node
472 const char *ofnode_get_name(ofnode node);
475 * ofnode_get_path() - get the full path of a node
477 * @node: valid node to look up
478 * @buf: buffer to write the node path into
479 * @buflen: buffer size
480 * Return: 0 if OK, -ve on error
482 int ofnode_get_path(ofnode node, char *buf, int buflen);
485 * ofnode_get_by_phandle() - get ofnode from phandle
487 * @phandle: phandle to look up
488 * Return: ofnode reference to the phandle
490 ofnode ofnode_get_by_phandle(uint phandle);
493 * ofnode_read_size() - read the size of a property
495 * @node: node to check
496 * @propname: property to check
497 * Return: size of property if present, or -EINVAL if not
499 int ofnode_read_size(ofnode node, const char *propname);
502 * ofnode_get_addr_size_index() - get an address/size from a node
505 * This reads the register address/size from a node based on index
507 * @node: node to read from
508 * @index: Index of address to read (0 for first)
509 * @size: Pointer to size of the address
510 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
512 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
516 * ofnode_get_addr_size_index_notrans() - get an address/size from a node
517 * based on index, without address
520 * This reads the register address/size from a node based on index.
521 * The resulting address is not translated. Useful for example for on-disk
524 * @node: node to read from
525 * @index: Index of address to read (0 for first)
526 * @size: Pointer to size of the address
527 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
529 phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
533 * ofnode_get_addr_index() - get an address from a node
535 * This reads the register address from a node
537 * @node: node to read from
538 * @index: Index of address to read (0 for first)
539 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
541 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
544 * ofnode_get_addr() - get an address from a node
546 * This reads the register address from a node
548 * @node: node to read from
549 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
551 phys_addr_t ofnode_get_addr(ofnode node);
554 * ofnode_get_size() - get size from a node
556 * This reads the register size from a node
558 * @node: node to read from
559 * Return: size of the address, or FDT_SIZE_T_NONE if not present or invalid
561 fdt_size_t ofnode_get_size(ofnode node);
564 * ofnode_stringlist_search() - find a string in a string list and return index
566 * Note that it is possible for this function to succeed on property values
567 * that are not NUL-terminated. That's because the function will stop after
568 * finding the first occurrence of @string. This can for example happen with
569 * small-valued cell properties, such as #address-cells, when searching for
572 * @node: node to check
573 * @propname: name of the property containing the string list
574 * @string: string to look up in the string list
577 * the index of the string in the list of strings
578 * -ENODATA if the property is not found
579 * -EINVAL on some other error
581 int ofnode_stringlist_search(ofnode node, const char *propname,
585 * ofnode_read_string_index() - obtain an indexed string from a string list
587 * Note that this will successfully extract strings from properties with
588 * non-NUL-terminated values. For example on small-valued cell properties
589 * this function will return the empty string.
591 * If non-NULL, the length of the string (on success) or a negative error-code
592 * (on failure) will be stored in the integer pointer to by lenp.
594 * @node: node to check
595 * @propname: name of the property containing the string list
596 * @index: index of the string to return (cannot be negative)
597 * @outp: return location for the string
600 * 0 if found or -ve error value if not found
602 int ofnode_read_string_index(ofnode node, const char *propname, int index,
606 * ofnode_read_string_count() - find the number of strings in a string list
608 * @node: node to check
609 * @property: name of the property containing the string list
611 * number of strings in the list, or -ve error value if not found
613 int ofnode_read_string_count(ofnode node, const char *property);
616 * ofnode_read_string_list() - read a list of strings
618 * This produces a list of string pointers with each one pointing to a string
619 * in the string list. If the property does not exist, it returns {NULL}.
621 * The data is allocated and the caller is reponsible for freeing the return
622 * value (the list of string pointers). The strings themselves may not be
623 * changed as they point directly into the devicetree property.
625 * @node: node to check
626 * @property: name of the property containing the string list
627 * @listp: returns an allocated, NULL-terminated list of strings if the return
628 * value is > 0, else is set to NULL
630 * number of strings in list, 0 if none, -ENOMEM if out of memory,
631 * -EINVAL if no such property, -EENODATA if property is empty
633 int ofnode_read_string_list(ofnode node, const char *property,
634 const char ***listp);
637 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
639 * This function is useful to parse lists of phandles and their arguments.
640 * Returns 0 on success and fills out_args, on error returns appropriate
643 * Caller is responsible to call of_node_put() on the returned out_args->np
657 * list = <&phandle1 1 2 &phandle2 3>;
660 * To get a device_node of the `node2' node you may call this:
661 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
663 * @node: device tree node containing a list
664 * @list_name: property name that contains a list
665 * @cells_name: property name that specifies phandles' arguments count
666 * @cell_count: Cell count to use if @cells_name is NULL
667 * @index: index of a phandle to parse out
668 * @out_args: optional pointer to output arguments structure (will be filled)
670 * 0 on success (with @out_args filled out if not NULL), -ENOENT if
671 * @list_name does not exist, -EINVAL if a phandle was not found,
672 * @cells_name could not be found, the arguments were truncated or there
673 * were too many arguments.
675 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
676 const char *cells_name, int cell_count,
678 struct ofnode_phandle_args *out_args);
681 * ofnode_count_phandle_with_args() - Count number of phandle in a list
683 * This function is useful to count phandles into a list.
684 * Returns number of phandle on success, on error returns appropriate
687 * @node: device tree node containing a list
688 * @list_name: property name that contains a list
689 * @cells_name: property name that specifies phandles' arguments count
690 * @cell_count: Cell count to use if @cells_name is NULL
692 * number of phandle on success, -ENOENT if @list_name does not exist,
693 * -EINVAL if a phandle was not found, @cells_name could not be found.
695 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
696 const char *cells_name, int cell_count);
699 * ofnode_path() - find a node by full path
701 * @path: Full path to node, e.g. "/bus/spi@1"
702 * Return: reference to the node found. Use ofnode_valid() to check if it exists
704 ofnode ofnode_path(const char *path);
707 * ofnode_read_chosen_prop() - get the value of a chosen property
709 * This looks for a property within the /chosen node and returns its value
711 * @propname: Property name to look for
712 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
714 * Return: property value if found, else NULL
716 const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
719 * ofnode_read_chosen_string() - get the string value of a chosen property
721 * This looks for a property within the /chosen node and returns its value,
722 * checking that it is a valid nul-terminated string
724 * @propname: Property name to look for
725 * Return: string value if found, else NULL
727 const char *ofnode_read_chosen_string(const char *propname);
730 * ofnode_get_chosen_node() - get a referenced node from the chosen node
732 * This looks up a named property in the chosen node and uses that as a path to
735 * @propname: Property name to look for
736 * Return: the referenced node if present, else ofnode_null()
738 ofnode ofnode_get_chosen_node(const char *propname);
741 * ofnode_read_aliases_prop() - get the value of a aliases property
743 * This looks for a property within the /aliases node and returns its value
745 * @propname: Property name to look for
746 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
748 * Return: property value if found, else NULL
750 const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
753 * ofnode_get_aliases_node() - get a referenced node from the aliases node
755 * This looks up a named property in the aliases node and uses that as a path to
758 * @propname: Property name to look for
759 * Return: the referenced node if present, else ofnode_null()
761 ofnode ofnode_get_aliases_node(const char *propname);
763 struct display_timing;
765 * ofnode_decode_display_timing() - decode display timings
767 * Decode display timings from the supplied 'display-timings' node.
768 * See doc/device-tree-bindings/video/display-timing.txt for binding
771 * @node: 'display-timing' node containing the timing subnodes
772 * @index: Index number to read (0=first timing subnode)
773 * @config: Place to put timings
774 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
776 int ofnode_decode_display_timing(ofnode node, int index,
777 struct display_timing *config);
780 * ofnode_get_property() - get a pointer to the value of a node property
782 * @node: node to read
783 * @propname: property to read
784 * @lenp: place to put length on success
785 * Return: pointer to property, or NULL if not found
787 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
790 * ofnode_get_first_property()- get the reference of the first property
792 * Get reference to the first property of the node, it is used to iterate
793 * and read all the property with ofnode_get_property_by_prop().
795 * @node: node to read
796 * @prop: place to put argument reference
797 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
799 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
802 * ofnode_get_next_property() - get the reference of the next property
804 * Get reference to the next property of the node, it is used to iterate
805 * and read all the property with ofnode_get_property_by_prop().
807 * @prop: reference of current argument and place to put reference of next one
808 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
810 int ofnode_get_next_property(struct ofprop *prop);
813 * ofnode_get_property_by_prop() - get a pointer to the value of a property
815 * Get value for the property identified by the provided reference.
817 * @prop: reference on property
818 * @propname: If non-NULL, place to property name on success,
819 * @lenp: If non-NULL, place to put length on success
820 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
822 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
823 const char **propname, int *lenp);
826 * ofnode_is_available() - check if a node is marked available
828 * @node: node to check
829 * Return: true if node's 'status' property is "okay" (or is missing)
831 bool ofnode_is_available(ofnode node);
834 * ofnode_get_addr_size() - get address and size from a property
836 * This does no address translation. It simply reads an property that contains
837 * an address and a size value, one after the other.
839 * @node: node to read from
840 * @propname: property to read
841 * @sizep: place to put size value (on success)
842 * Return: address value, or FDT_ADDR_T_NONE on error
844 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
848 * ofnode_read_u8_array_ptr() - find an 8-bit array
850 * Look up a property in a node and return a pointer to its contents as a
851 * byte array of given length. The property must have at least enough data
852 * for the array (count bytes). It may have more, but this will be ignored.
853 * The data is not copied.
855 * @node: node to examine
856 * @propname: name of property to find
857 * @sz: number of array elements
859 * pointer to byte array if found, or NULL if the property is not found or
860 * there is not enough data
862 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
866 * ofnode_read_pci_addr() - look up a PCI address
868 * Look at an address property in a node and return the PCI address which
869 * corresponds to the given type in the form of fdt_pci_addr.
870 * The property must hold one fdt_pci_addr with a lengh.
872 * @node: node to examine
873 * @type: pci address type (FDT_PCI_SPACE_xxx)
874 * @propname: name of property to find
875 * @addr: returns pci address in the form of fdt_pci_addr
877 * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
878 * format of the property was invalid, -ENXIO if the requested
879 * address type was not found
881 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
882 const char *propname, struct fdt_pci_addr *addr);
885 * ofnode_read_pci_vendev() - look up PCI vendor and device id
887 * Look at the compatible property of a device node that represents a PCI
888 * device and extract pci vendor id and device id from it.
890 * @node: node to examine
891 * @vendor: vendor id of the pci device
892 * @device: device id of the pci device
893 * Return: 0 if ok, negative on error
895 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
898 * ofnode_read_eth_phy_id() - look up eth phy vendor and device id
900 * Look at the compatible property of a device node that represents a eth phy
901 * device and extract phy vendor id and device id from it.
903 * @node: node to examine
904 * @vendor: vendor id of the eth phy device
905 * @device: device id of the eth phy device
906 * Return: 0 if ok, negative on error
908 int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device);
911 * ofnode_read_addr_cells() - Get the number of address cells for a node
913 * This walks back up the tree to find the closest #address-cells property
914 * which controls the given node.
916 * @node: Node to check
917 * Return: number of address cells this node uses
919 int ofnode_read_addr_cells(ofnode node);
922 * ofnode_read_size_cells() - Get the number of size cells for a node
924 * This walks back up the tree to find the closest #size-cells property
925 * which controls the given node.
927 * @node: Node to check
928 * Return: number of size cells this node uses
930 int ofnode_read_size_cells(ofnode node);
933 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
935 * This function matches fdt_address_cells().
937 * @node: Node to check
938 * Return: value of #address-cells property in this node, or 2 if none
940 int ofnode_read_simple_addr_cells(ofnode node);
943 * ofnode_read_simple_size_cells() - Get the size cells property in a node
945 * This function matches fdt_size_cells().
947 * @node: Node to check
948 * Return: value of #size-cells property in this node, or 2 if none
950 int ofnode_read_simple_size_cells(ofnode node);
953 * ofnode_pre_reloc() - check if a node should be bound before relocation
955 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
956 * via special device tree properties.
958 * Before relocation this function can be used to check if nodes are required
959 * in either SPL or TPL stages.
961 * After relocation and jumping into the real U-Boot binary it is possible to
962 * determine if a node was bound in one of SPL/TPL stages.
964 * There are 4 settings currently in use
965 * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
966 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
967 * Existing platforms only use it to indicate nodes needed in
968 * SPL. Should probably be replaced by u-boot,dm-spl for new platforms.
969 * - u-boot,dm-spl: SPL and U-Boot pre-relocation
970 * - u-boot,dm-tpl: TPL and U-Boot pre-relocation
972 * @node: node to check
973 * Return: true if node is needed in SPL/TL, false otherwise
975 bool ofnode_pre_reloc(ofnode node);
978 * ofnode_read_resource() - Read a resource from a node
980 * Read resource information from a node at the given index
982 * @node: Node to read from
983 * @index: Index of resource to read (0 = first)
984 * @res: Returns resource that was read, on success
985 * Return: 0 if OK, -ve on error
987 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
990 * ofnode_read_resource_byname() - Read a resource from a node by name
992 * Read resource information from a node matching the given name. This uses a
993 * 'reg-names' string list property with the names matching the associated
994 * 'reg' property list.
996 * @node: Node to read from
997 * @name: Name of resource to read
998 * @res: Returns resource that was read, on success
999 * Return: 0 if OK, -ve on error
1001 int ofnode_read_resource_byname(ofnode node, const char *name,
1002 struct resource *res);
1005 * ofnode_by_compatible() - Find the next compatible node
1007 * Find the next node after @from that is compatible with @compat
1009 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
1010 * @compat: Compatible string to match
1011 * Return: ofnode found, or ofnode_null() if none
1013 ofnode ofnode_by_compatible(ofnode from, const char *compat);
1016 * ofnode_by_prop_value() - Find the next node with given property value
1018 * Find the next node after @from that has a @propname with a value
1019 * @propval and a length @proplen.
1021 * @from: ofnode to start from (use ofnode_null() to start at the
1023 * @propname: property name to check
1024 * @propval: property value to search for
1025 * @proplen: length of the value in propval
1026 * Return: ofnode found, or ofnode_null() if none
1028 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
1029 const void *propval, int proplen);
1032 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
1034 * @node: child node (ofnode, lvalue)
1035 * @parent: parent node (ofnode)
1037 * This is a wrapper around a for loop and is used like so::
1040 * ofnode_for_each_subnode(node, parent) {
1045 * Note that this is implemented as a macro and @node is used as
1046 * iterator in the loop. The parent variable can be a constant or even a
1049 #define ofnode_for_each_subnode(node, parent) \
1050 for (node = ofnode_first_subnode(parent); \
1051 ofnode_valid(node); \
1052 node = ofnode_next_subnode(node))
1055 * ofnode_for_each_compatible_node() - iterate over all nodes with a given
1058 * @node: child node (ofnode, lvalue)
1059 * @compat: compatible string to match
1061 * This is a wrapper around a for loop and is used like so::
1064 * ofnode_for_each_compatible_node(node, parent, compatible) {
1069 * Note that this is implemented as a macro and @node is used as
1070 * iterator in the loop.
1072 #define ofnode_for_each_compatible_node(node, compat) \
1073 for (node = ofnode_by_compatible(ofnode_null(), compat); \
1074 ofnode_valid(node); \
1075 node = ofnode_by_compatible(node, compat))
1078 * ofnode_get_child_count() - get the child count of a ofnode
1080 * @parent: valid node to get its child count
1081 * Return: the number of subnodes
1083 int ofnode_get_child_count(ofnode parent);
1086 * ofnode_translate_address() - Translate a device-tree address
1088 * Translate an address from the device-tree into a CPU physical address. This
1089 * function walks up the tree and applies the various bus mappings along the
1092 * @node: Device tree node giving the context in which to translate the address
1093 * @in_addr: pointer to the address to translate
1094 * Return: the translated address; OF_BAD_ADDR on error
1096 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
1099 * ofnode_translate_dma_address() - Translate a device-tree DMA address
1101 * Translate a DMA address from the device-tree into a CPU physical address.
1102 * This function walks up the tree and applies the various bus mappings along
1105 * @node: Device tree node giving the context in which to translate the
1107 * @in_addr: pointer to the DMA address to translate
1108 * Return: the translated DMA address; OF_BAD_ADDR on error
1110 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
1113 * ofnode_get_dma_range() - get dma-ranges for a specific DT node
1115 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
1116 * cpu->bus address translations
1118 * @node: Device tree node
1119 * @cpu: Pointer to variable storing the range's cpu address
1120 * @bus: Pointer to variable storing the range's bus address
1121 * @size: Pointer to variable storing the range's size
1122 * Return: translated DMA address or OF_BAD_ADDR on error
1124 int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
1128 * ofnode_device_is_compatible() - check if the node is compatible with compat
1130 * This allows to check whether the node is comaptible with the compat.
1132 * @node: Device tree node for which compatible needs to be verified.
1133 * @compat: Compatible string which needs to verified in the given node.
1134 * Return: true if OK, false if the compatible is not found
1136 int ofnode_device_is_compatible(ofnode node, const char *compat);
1139 * ofnode_write_prop() - Set a property of a ofnode
1141 * Note that the value passed to the function is *not* allocated by the
1142 * function itself, but must be allocated by the caller if necessary.
1144 * @node: The node for whose property should be set
1145 * @propname: The name of the property to set
1146 * @len: The length of the new value of the property
1147 * @value: The new value of the property (must be valid prior to calling
1149 * Return: 0 if successful, -ve on error
1151 int ofnode_write_prop(ofnode node, const char *propname, int len,
1155 * ofnode_write_string() - Set a string property of a ofnode
1157 * Note that the value passed to the function is *not* allocated by the
1158 * function itself, but must be allocated by the caller if necessary.
1160 * @node: The node for whose string property should be set
1161 * @propname: The name of the string property to set
1162 * @value: The new value of the string property (must be valid prior to
1163 * calling the function)
1164 * Return: 0 if successful, -ve on error
1166 int ofnode_write_string(ofnode node, const char *propname, const char *value);
1169 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1172 * This function effectively sets the node's "status" property to either "okay"
1173 * or "disable", hence making it available for driver model initialization or
1176 * @node: The node to enable
1177 * @value: Flag that tells the function to either disable or enable the
1179 * Return: 0 if successful, -ve on error
1181 int ofnode_set_enabled(ofnode node, bool value);
1184 * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config
1186 * This reads a property from the /config node of the devicetree.
1188 * See doc/config.txt for bindings
1190 * @prop_name: property name to look up
1191 * Return: true, if it exists, false if not
1193 bool ofnode_conf_read_bool(const char *prop_name);
1196 * ofnode_conf_read_int() - Read an integer value from the U-Boot config
1198 * This reads a property from the /config node of the devicetree.
1200 * See doc/config.txt for bindings
1202 * @prop_name: property name to look up
1203 * @default_val: default value to return if the property is not found
1204 * Return: integer value, if found, or @default_val if not
1206 int ofnode_conf_read_int(const char *prop_name, int default_val);
1209 * ofnode_conf_read_str() - Read a string value from the U-Boot config
1211 * This reads a property from the /config node of the devicetree.
1213 * See doc/config.txt for bindings
1215 * @prop_name: property name to look up
1216 * Return: string value, if found, or NULL if not
1218 const char *ofnode_conf_read_str(const char *prop_name);