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 * 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 * 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 * @return true if the reference contains a valid ofnode, false if it is NULL
127 static inline bool ofnode_valid(ofnode node)
129 if (of_live_active())
130 return node.np != NULL;
132 return node.of_offset >= 0;
136 * offset_to_ofnode() - convert a DT offset to an ofnode
138 * @of_offset: DT offset (either valid, or -1)
139 * @return reference to the associated DT offset
141 static inline ofnode offset_to_ofnode(int of_offset)
145 if (of_live_active())
148 node.of_offset = of_offset >= 0 ? of_offset : -1;
154 * np_to_ofnode() - convert a node pointer to an ofnode
156 * @np: Live node pointer (can be NULL)
157 * @return reference to the associated node pointer
159 static inline ofnode np_to_ofnode(const struct device_node *np)
169 * ofnode_is_np() - check if a reference is a node pointer
171 * This function associated that if there is a valid live tree then all
172 * references will use it. This is because using the flat DT when the live tree
173 * is valid is not permitted.
175 * @node: reference to check (possibly invalid)
176 * @return true if the reference is a live node pointer, false if it is a DT
179 static inline bool ofnode_is_np(ofnode node)
183 * Check our assumption that flat tree offsets are not used when a
184 * live tree is in use.
186 assert(!ofnode_valid(node) ||
187 (of_live_active() ? ofnode_to_np(node)
188 : ofnode_to_np(node)));
190 return of_live_active() && ofnode_valid(node);
194 * ofnode_equal() - check if two references are equal
196 * @return true if equal, else false
198 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
200 /* We only need to compare the contents */
201 return ref1.of_offset == ref2.of_offset;
205 * ofnode_null() - Obtain a null ofnode
207 * This returns an ofnode which points to no node. It works both with the flat
210 static inline ofnode ofnode_null(void)
214 if (of_live_active())
222 static inline ofnode ofnode_root(void)
226 if (of_live_active())
227 node.np = gd_of_root();
235 * ofnode_name_eq() - Check if the node name is equivalent to a given name
236 * ignoring the unit address
238 * @node: valid node reference that has to be compared
239 * @name: name that has to be compared with the node name
240 * @return true if matches, false if it doesn't match
242 bool ofnode_name_eq(ofnode node, const char *name);
245 * ofnode_read_u32() - Read a 32-bit integer from a property
247 * @ref: valid node reference to read property from
248 * @propname: name of the property to read from
249 * @outp: place to put value (if found)
250 * @return 0 if OK, -ve on error
252 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
255 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
257 * @ref: valid node reference to read property from
258 * @propname: name of the property to read from
259 * @index: index of the integer to return
260 * @outp: place to put value (if found)
261 * @return 0 if OK, -ve on error
263 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
267 * ofnode_read_s32() - Read a 32-bit integer from a property
269 * @ref: valid node reference to read property from
270 * @propname: name of the property to read from
271 * @outp: place to put value (if found)
272 * @return 0 if OK, -ve on error
274 static inline int ofnode_read_s32(ofnode node, const char *propname,
277 return ofnode_read_u32(node, propname, (u32 *)out_value);
281 * ofnode_read_u32_default() - Read a 32-bit integer from a property
283 * @ref: valid node reference to read property from
284 * @propname: name of the property to read from
285 * @def: default value to return if the property has no value
286 * @return property value, or @def if not found
288 u32 ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
291 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
294 * @ref: valid node reference to read property from
295 * @propname: name of the property to read from
296 * @index: index of the integer to return
297 * @def: default value to return if the property has no value
298 * @return property value, or @def if not found
300 u32 ofnode_read_u32_index_default(ofnode ref, const char *propname, int index,
304 * ofnode_read_s32_default() - Read a 32-bit integer from a property
306 * @ref: valid node reference to read property from
307 * @propname: name of the property to read from
308 * @def: default value to return if the property has no value
309 * @return property value, or @def if not found
311 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
314 * ofnode_read_u64() - Read a 64-bit integer from a property
316 * @node: valid node reference to read property from
317 * @propname: name of the property to read from
318 * @outp: place to put value (if found)
319 * @return 0 if OK, -ve on error
321 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
324 * ofnode_read_u64_default() - Read a 64-bit integer from a property
326 * @ref: valid node reference to read property from
327 * @propname: name of the property to read from
328 * @def: default value to return if the property has no value
329 * @return property value, or @def if not found
331 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
334 * ofnode_read_prop() - Read a property from a node
336 * @node: valid node reference to read property from
337 * @propname: name of the property to read
338 * @sizep: if non-NULL, returns the size of the property, or an error code
340 * @return property value, or NULL if there is no such property
342 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
345 * ofnode_read_string() - Read a string from a property
347 * @node: valid node reference to read property from
348 * @propname: name of the property to read
349 * @return string from property value, or NULL if there is no such property
351 const char *ofnode_read_string(ofnode node, const char *propname);
354 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
356 * @node: valid node reference to read property from
357 * @propname: name of the property to read
358 * @out_values: pointer to return value, modified only if return value is 0
359 * @sz: number of array elements to read
360 * @return 0 if OK, -ve on error
362 * Search for a property in a device node and read 32-bit value(s) from
363 * it. Returns 0 on success, -EINVAL if the property does not exist,
364 * -ENODATA if property does not have a value, and -EOVERFLOW if the
365 * property data isn't large enough.
367 * The out_values is modified only if a valid u32 value can be decoded.
369 int ofnode_read_u32_array(ofnode node, const char *propname,
370 u32 *out_values, size_t sz);
373 * ofnode_read_bool() - read a boolean value from a property
375 * @node: valid node reference to read property from
376 * @propname: name of property to read
377 * @return true if property is present (meaning true), false if not present
379 bool ofnode_read_bool(ofnode node, const char *propname);
382 * ofnode_find_subnode() - find a named subnode of a parent node
384 * @node: valid reference to parent node
385 * @subnode_name: name of subnode to find
386 * @return reference to subnode (which can be invalid if there is no such
389 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
391 #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
392 #include <asm/global_data.h>
394 static inline bool ofnode_is_enabled(ofnode node)
396 if (ofnode_is_np(node)) {
397 return of_device_is_available(ofnode_to_np(node));
399 return fdtdec_get_is_enabled(gd->fdt_blob,
400 ofnode_to_offset(node));
404 static inline ofnode ofnode_first_subnode(ofnode node)
406 assert(ofnode_valid(node));
407 if (ofnode_is_np(node))
408 return np_to_ofnode(node.np->child);
410 return offset_to_ofnode(
411 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
414 static inline ofnode ofnode_next_subnode(ofnode node)
416 assert(ofnode_valid(node));
417 if (ofnode_is_np(node))
418 return np_to_ofnode(node.np->sibling);
420 return offset_to_ofnode(
421 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
425 * ofnode_is_enabled() - Checks whether a node is enabled.
426 * This looks for a 'status' property. If this exists, then returns true if
427 * the status is 'okay' and false otherwise. If there is no status property,
428 * it returns true on the assumption that anything mentioned should be enabled
431 * @node: node to examine
432 * @return false (not enabled) or true (enabled)
434 bool ofnode_is_enabled(ofnode node);
437 * ofnode_first_subnode() - find the first subnode of a parent node
439 * @node: valid reference to a valid parent node
440 * @return reference to the first subnode (which can be invalid if the parent
441 * node has no subnodes)
443 ofnode ofnode_first_subnode(ofnode node);
446 * ofnode_next_subnode() - find the next sibling of a subnode
448 * @node: valid reference to previous node (sibling)
449 * @return reference to the next subnode (which can be invalid if the node
450 * has no more siblings)
452 ofnode ofnode_next_subnode(ofnode node);
453 #endif /* DM_INLINE_OFNODE */
456 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
458 * @node: valid node to look up
459 * @return ofnode reference of the parent node
461 ofnode ofnode_get_parent(ofnode node);
464 * ofnode_get_name() - get the name of a node
466 * @node: valid node to look up
467 * @return name of node
469 const char *ofnode_get_name(ofnode node);
472 * ofnode_get_path() - get the full path of a node
474 * @node: valid node to look up
475 * @buf: buffer to write the node path into
476 * @buflen: buffer size
477 * @return 0 if OK, -ve on error
479 int ofnode_get_path(ofnode node, char *buf, int buflen);
482 * ofnode_get_by_phandle() - get ofnode from phandle
484 * @phandle: phandle to look up
485 * @return ofnode reference to the phandle
487 ofnode ofnode_get_by_phandle(uint phandle);
490 * ofnode_read_size() - read the size of a property
492 * @node: node to check
493 * @propname: property to check
494 * @return size of property if present, or -EINVAL if not
496 int ofnode_read_size(ofnode node, const char *propname);
499 * ofnode_get_addr_size_index() - get an address/size from a node
502 * This reads the register address/size from a node based on index
504 * @node: node to read from
505 * @index: Index of address to read (0 for first)
506 * @size: Pointer to size of the address
507 * @return address, or FDT_ADDR_T_NONE if not present or invalid
509 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
513 * ofnode_get_addr_size_index_notrans() - get an address/size from a node
514 * based on index, without address
517 * This reads the register address/size from a node based on index.
518 * The resulting address is not translated. Useful for example for on-disk
521 * @node: node to read from
522 * @index: Index of address to read (0 for first)
523 * @size: Pointer to size of the address
524 * @return address, or FDT_ADDR_T_NONE if not present or invalid
526 phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
530 * ofnode_get_addr_index() - get an address from a node
532 * This reads the register address from a node
534 * @node: node to read from
535 * @index: Index of address to read (0 for first)
536 * @return address, or FDT_ADDR_T_NONE if not present or invalid
538 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
541 * ofnode_get_addr() - get an address from a node
543 * This reads the register address from a node
545 * @node: node to read from
546 * @return address, or FDT_ADDR_T_NONE if not present or invalid
548 phys_addr_t ofnode_get_addr(ofnode node);
551 * ofnode_get_size() - get size from a node
553 * This reads the register size from a node
555 * @node: node to read from
556 * @return size of the address, or FDT_SIZE_T_NONE if not present or invalid
558 fdt_size_t ofnode_get_size(ofnode node);
561 * ofnode_stringlist_search() - find a string in a string list and return index
563 * Note that it is possible for this function to succeed on property values
564 * that are not NUL-terminated. That's because the function will stop after
565 * finding the first occurrence of @string. This can for example happen with
566 * small-valued cell properties, such as #address-cells, when searching for
569 * @node: node to check
570 * @propname: name of the property containing the string list
571 * @string: string to look up in the string list
574 * the index of the string in the list of strings
575 * -ENODATA if the property is not found
576 * -EINVAL on some other error
578 int ofnode_stringlist_search(ofnode node, const char *propname,
582 * ofnode_read_string_index() - obtain an indexed string from a string list
584 * Note that this will successfully extract strings from properties with
585 * non-NUL-terminated values. For example on small-valued cell properties
586 * this function will return the empty string.
588 * If non-NULL, the length of the string (on success) or a negative error-code
589 * (on failure) will be stored in the integer pointer to by lenp.
591 * @node: node to check
592 * @propname: name of the property containing the string list
593 * @index: index of the string to return
594 * @lenp: return location for the string length or an error code on failure
597 * length of string, if found or -ve error value if not found
599 int ofnode_read_string_index(ofnode node, const char *propname, int index,
603 * ofnode_read_string_count() - find the number of strings in a string list
605 * @node: node to check
606 * @propname: name of the property containing the string list
608 * number of strings in the list, or -ve error value if not found
610 int ofnode_read_string_count(ofnode node, const char *property);
613 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
615 * This function is useful to parse lists of phandles and their arguments.
616 * Returns 0 on success and fills out_args, on error returns appropriate
619 * Caller is responsible to call of_node_put() on the returned out_args->np
633 * list = <&phandle1 1 2 &phandle2 3>;
636 * To get a device_node of the `node2' node you may call this:
637 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
639 * @node: device tree node containing a list
640 * @list_name: property name that contains a list
641 * @cells_name: property name that specifies phandles' arguments count
642 * @cells_count: Cell count to use if @cells_name is NULL
643 * @index: index of a phandle to parse out
644 * @out_args: optional pointer to output arguments structure (will be filled)
645 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
646 * @list_name does not exist, -EINVAL if a phandle was not found,
647 * @cells_name could not be found, the arguments were truncated or there
648 * were too many arguments.
650 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
651 const char *cells_name, int cell_count,
653 struct ofnode_phandle_args *out_args);
656 * ofnode_count_phandle_with_args() - Count number of phandle in a list
658 * This function is useful to count phandles into a list.
659 * Returns number of phandle on success, on error returns appropriate
662 * @node: device tree node containing a list
663 * @list_name: property name that contains a list
664 * @cells_name: property name that specifies phandles' arguments count
665 * @cells_count: Cell count to use if @cells_name is NULL
666 * @return number of phandle on success, -ENOENT if @list_name does not
667 * exist, -EINVAL if a phandle was not found, @cells_name could not
670 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
671 const char *cells_name, int cell_count);
674 * ofnode_path() - find a node by full path
676 * @path: Full path to node, e.g. "/bus/spi@1"
677 * @return reference to the node found. Use ofnode_valid() to check if it exists
679 ofnode ofnode_path(const char *path);
682 * ofnode_read_chosen_prop() - get the value of a chosen property
684 * This looks for a property within the /chosen node and returns its value
686 * @propname: Property name to look for
687 * @sizep: Returns size of property, or FDT_ERR_... error code if function
689 * @return property value if found, else NULL
691 const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
694 * ofnode_read_chosen_string() - get the string value of a chosen property
696 * This looks for a property within the /chosen node and returns its value,
697 * checking that it is a valid nul-terminated string
699 * @propname: Property name to look for
700 * @return string value if found, else NULL
702 const char *ofnode_read_chosen_string(const char *propname);
705 * ofnode_get_chosen_node() - get a referenced node from the chosen node
707 * This looks up a named property in the chosen node and uses that as a path to
710 * @return the referenced node if present, else ofnode_null()
712 ofnode ofnode_get_chosen_node(const char *propname);
715 * ofnode_read_aliases_prop() - get the value of a aliases property
717 * This looks for a property within the /aliases node and returns its value
719 * @propname: Property name to look for
720 * @sizep: Returns size of property, or FDT_ERR_... error code if function
722 * @return property value if found, else NULL
724 const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
727 * ofnode_get_aliases_node() - get a referenced node from the aliases node
729 * This looks up a named property in the aliases node and uses that as a path to
732 * @return the referenced node if present, else ofnode_null()
734 ofnode ofnode_get_aliases_node(const char *propname);
736 struct display_timing;
738 * ofnode_decode_display_timing() - decode display timings
740 * Decode display timings from the supplied 'display-timings' node.
741 * See doc/device-tree-bindings/video/display-timing.txt for binding
744 * @node 'display-timing' node containing the timing subnodes
745 * @index Index number to read (0=first timing subnode)
746 * @config Place to put timings
747 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
749 int ofnode_decode_display_timing(ofnode node, int index,
750 struct display_timing *config);
753 * ofnode_get_property() - get a pointer to the value of a node property
755 * @node: node to read
756 * @propname: property to read
757 * @lenp: place to put length on success
758 * @return pointer to property, or NULL if not found
760 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
763 * ofnode_get_first_property()- get the reference of the first property
765 * Get reference to the first property of the node, it is used to iterate
766 * and read all the property with ofnode_get_property_by_prop().
768 * @node: node to read
769 * @prop: place to put argument reference
770 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
772 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
775 * ofnode_get_next_property() - get the reference of the next property
777 * Get reference to the next property of the node, it is used to iterate
778 * and read all the property with ofnode_get_property_by_prop().
780 * @prop: reference of current argument and place to put reference of next one
781 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
783 int ofnode_get_next_property(struct ofprop *prop);
786 * ofnode_get_property_by_prop() - get a pointer to the value of a property
788 * Get value for the property identified by the provided reference.
790 * @prop: reference on property
791 * @propname: If non-NULL, place to property name on success,
792 * @lenp: If non-NULL, place to put length on success
793 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
795 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
796 const char **propname, int *lenp);
799 * ofnode_is_available() - check if a node is marked available
801 * @node: node to check
802 * @return true if node's 'status' property is "okay" (or is missing)
804 bool ofnode_is_available(ofnode node);
807 * ofnode_get_addr_size() - get address and size from a property
809 * This does no address translation. It simply reads an property that contains
810 * an address and a size value, one after the other.
812 * @node: node to read from
813 * @propname: property to read
814 * @sizep: place to put size value (on success)
815 * @return address value, or FDT_ADDR_T_NONE on error
817 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
821 * ofnode_read_u8_array_ptr() - find an 8-bit array
823 * Look up a property in a node and return a pointer to its contents as a
824 * byte array of given length. The property must have at least enough data
825 * for the array (count bytes). It may have more, but this will be ignored.
826 * The data is not copied.
828 * @node node to examine
829 * @propname name of property to find
830 * @sz number of array elements
831 * @return pointer to byte array if found, or NULL if the property is not
832 * found or there is not enough data
834 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
838 * ofnode_read_pci_addr() - look up a PCI address
840 * Look at an address property in a node and return the PCI address which
841 * corresponds to the given type in the form of fdt_pci_addr.
842 * The property must hold one fdt_pci_addr with a lengh.
844 * @node node to examine
845 * @type pci address type (FDT_PCI_SPACE_xxx)
846 * @propname name of property to find
847 * @addr returns pci address in the form of fdt_pci_addr
848 * @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
849 * format of the property was invalid, -ENXIO if the requested
850 * address type was not found
852 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
853 const char *propname, struct fdt_pci_addr *addr);
856 * ofnode_read_pci_vendev() - look up PCI vendor and device id
858 * Look at the compatible property of a device node that represents a PCI
859 * device and extract pci vendor id and device id from it.
861 * @param node node to examine
862 * @param vendor vendor id of the pci device
863 * @param device device id of the pci device
864 * @return 0 if ok, negative on error
866 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
869 * ofnode_read_addr_cells() - Get the number of address cells for a node
871 * This walks back up the tree to find the closest #address-cells property
872 * which controls the given node.
874 * @node: Node to check
875 * @return number of address cells this node uses
877 int ofnode_read_addr_cells(ofnode node);
880 * ofnode_read_size_cells() - Get the number of size cells for a node
882 * This walks back up the tree to find the closest #size-cells property
883 * which controls the given node.
885 * @node: Node to check
886 * @return number of size cells this node uses
888 int ofnode_read_size_cells(ofnode node);
891 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
893 * This function matches fdt_address_cells().
895 * @np: Node pointer to check
896 * @return value of #address-cells property in this node, or 2 if none
898 int ofnode_read_simple_addr_cells(ofnode node);
901 * ofnode_read_simple_size_cells() - Get the size cells property in a node
903 * This function matches fdt_size_cells().
905 * @np: Node pointer to check
906 * @return value of #size-cells property in this node, or 2 if none
908 int ofnode_read_simple_size_cells(ofnode node);
911 * ofnode_pre_reloc() - check if a node should be bound before relocation
913 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
914 * via special device tree properties.
916 * Before relocation this function can be used to check if nodes are required
917 * in either SPL or TPL stages.
919 * After relocation and jumping into the real U-Boot binary it is possible to
920 * determine if a node was bound in one of SPL/TPL stages.
922 * There are 4 settings currently in use
923 * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
924 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
925 * Existing platforms only use it to indicate nodes needed in
926 * SPL. Should probably be replaced by u-boot,dm-spl for
928 * - u-boot,dm-spl: SPL and U-Boot pre-relocation
929 * - u-boot,dm-tpl: TPL and U-Boot pre-relocation
931 * @node: node to check
932 * @return true if node is needed in SPL/TL, false otherwise
934 bool ofnode_pre_reloc(ofnode node);
937 * ofnode_read_resource() - Read a resource from a node
939 * Read resource information from a node at the given index
941 * @node: Node to read from
942 * @index: Index of resource to read (0 = first)
943 * @res: Returns resource that was read, on success
944 * @return 0 if OK, -ve on error
946 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
949 * ofnode_read_resource_byname() - Read a resource from a node by name
951 * Read resource information from a node matching the given name. This uses a
952 * 'reg-names' string list property with the names matching the associated
953 * 'reg' property list.
955 * @node: Node to read from
956 * @name: Name of resource to read
957 * @res: Returns resource that was read, on success
958 * @return 0 if OK, -ve on error
960 int ofnode_read_resource_byname(ofnode node, const char *name,
961 struct resource *res);
964 * ofnode_by_compatible() - Find the next compatible node
966 * Find the next node after @from that is compatible with @compat
968 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
969 * @compat: Compatible string to match
970 * @return ofnode found, or ofnode_null() if none
972 ofnode ofnode_by_compatible(ofnode from, const char *compat);
975 * ofnode_by_prop_value() - Find the next node with given property value
977 * Find the next node after @from that has a @propname with a value
978 * @propval and a length @proplen.
980 * @from: ofnode to start from (use ofnode_null() to start at the
981 * beginning) @propname: property name to check @propval: property value to
982 * search for @proplen: length of the value in propval @return ofnode
983 * found, or ofnode_null() if none
985 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
986 const void *propval, int proplen);
989 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
991 * @node: child node (ofnode, lvalue)
992 * @parent: parent node (ofnode)
994 * This is a wrapper around a for loop and is used like so:
998 * ofnode_for_each_subnode(node, parent) {
1003 * Note that this is implemented as a macro and @node is used as
1004 * iterator in the loop. The parent variable can be a constant or even a
1007 #define ofnode_for_each_subnode(node, parent) \
1008 for (node = ofnode_first_subnode(parent); \
1009 ofnode_valid(node); \
1010 node = ofnode_next_subnode(node))
1013 * ofnode_get_child_count() - get the child count of a ofnode
1015 * @node: valid node to get its child count
1016 * @return the number of subnodes
1018 int ofnode_get_child_count(ofnode parent);
1021 * ofnode_translate_address() - Translate a device-tree address
1023 * Translate an address from the device-tree into a CPU physical address. This
1024 * function walks up the tree and applies the various bus mappings along the
1027 * @ofnode: Device tree node giving the context in which to translate the
1029 * @in_addr: pointer to the address to translate
1030 * @return the translated address; OF_BAD_ADDR on error
1032 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
1035 * ofnode_translate_dma_address() - Translate a device-tree DMA address
1037 * Translate a DMA address from the device-tree into a CPU physical address.
1038 * This function walks up the tree and applies the various bus mappings along
1041 * @ofnode: Device tree node giving the context in which to translate the
1043 * @in_addr: pointer to the DMA address to translate
1044 * @return the translated DMA address; OF_BAD_ADDR on error
1046 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
1049 * ofnode_get_dma_range() - get dma-ranges for a specific DT node
1051 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
1052 * cpu->bus address translations
1054 * @param blob Pointer to device tree blob
1055 * @param node_offset Node DT offset
1056 * @param cpu Pointer to variable storing the range's cpu address
1057 * @param bus Pointer to variable storing the range's bus address
1058 * @param size Pointer to variable storing the range's size
1059 * @return translated DMA address or OF_BAD_ADDR on error
1061 int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
1065 * ofnode_device_is_compatible() - check if the node is compatible with compat
1067 * This allows to check whether the node is comaptible with the compat.
1069 * @node: Device tree node for which compatible needs to be verified.
1070 * @compat: Compatible string which needs to verified in the given node.
1071 * @return true if OK, false if the compatible is not found
1073 int ofnode_device_is_compatible(ofnode node, const char *compat);
1076 * ofnode_write_prop() - Set a property of a ofnode
1078 * Note that the value passed to the function is *not* allocated by the
1079 * function itself, but must be allocated by the caller if necessary.
1081 * @node: The node for whose property should be set
1082 * @propname: The name of the property to set
1083 * @len: The length of the new value of the property
1084 * @value: The new value of the property (must be valid prior to calling
1086 * @return 0 if successful, -ve on error
1088 int ofnode_write_prop(ofnode node, const char *propname, int len,
1092 * ofnode_write_string() - Set a string property of a ofnode
1094 * Note that the value passed to the function is *not* allocated by the
1095 * function itself, but must be allocated by the caller if necessary.
1097 * @node: The node for whose string property should be set
1098 * @propname: The name of the string property to set
1099 * @value: The new value of the string property (must be valid prior to
1100 * calling the function)
1101 * @return 0 if successful, -ve on error
1103 int ofnode_write_string(ofnode node, const char *propname, const char *value);
1106 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1109 * This function effectively sets the node's "status" property to either "okay"
1110 * or "disable", hence making it available for driver model initialization or
1113 * @node: The node to enable
1114 * @value: Flag that tells the function to either disable or enable the
1116 * @return 0 if successful, -ve on error
1118 int ofnode_set_enabled(ofnode node, bool value);
1121 * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config
1123 * This reads a property from the /config node of the devicetree.
1125 * See doc/config.txt for bindings
1127 * @prop_name property name to look up
1128 * @return true, if it exists, false if not
1130 bool ofnode_conf_read_bool(const char *prop_name);
1133 * ofnode_conf_read_int() - Read an integer value from the U-Boot config
1135 * This reads a property from the /config node of the devicetree.
1137 * See doc/config.txt for bindings
1139 * @prop_name: property name to look up
1140 * @default_val: default value to return if the property is not found
1141 * @return integer value, if found, or @default_val if not
1143 int ofnode_conf_read_int(const char *prop_name, int default_val);
1146 * ofnode_conf_read_str() - Read a string value from the U-Boot config
1148 * This reads a property from the /config node of the devicetree.
1150 * See doc/config.txt for bindings
1152 * @prop_name: property name to look up
1153 * @return string value, if found, or NULL if not
1155 const char *ofnode_conf_read_str(const char *prop_name);