1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
10 /* TODO(sjg@chromium.org): Drop fdtdec.h include */
15 /* Enable checks to protect against invalid calls */
21 * ofnode - reference to a device tree node
23 * This union can hold either a straightforward pointer to a struct device_node
24 * in the live device tree, or an offset within the flat device tree. In the
25 * latter case, the pointer value is just the integer offset within the flat DT.
27 * Thus we can reference nodes in both the live tree (once available) and the
28 * flat tree (until then). Functions are available to translate between an
29 * ofnode and either an offset or a struct device_node *.
31 * The reference can also hold a null offset, in which case the pointer value
32 * here is NULL. This corresponds to a struct device_node * value of
33 * NULL, or an offset of -1.
35 * There is no ambiguity as to whether ofnode holds an offset or a node
36 * pointer: when the live tree is active it holds a node pointer, otherwise it
37 * holds an offset. The value itself does not need to be unique and in theory
38 * the same value could point to a valid device node or a valid offset. We
39 * could arrange for a unique value to be used (e.g. by making the pointer
40 * point to an offset within the flat device tree in the case of an offset) but
41 * this increases code size slightly due to the subtraction. Since it offers no
42 * real benefit, the approach described here seems best.
44 * For now these points use constant types, since we don't allow writing
47 * @np: Pointer to device node, used for live tree
48 * @of_offset: Pointer into flat device tree, used for flat tree. Note that this
49 * is not a really a pointer to a node: it is an offset value. See above.
51 typedef union ofnode_union {
52 const struct device_node *np;
56 struct ofnode_phandle_args {
59 uint32_t args[OF_MAX_PHANDLE_ARGS];
63 * ofprop - reference to a property of a device tree node
65 * This struct hold the reference on one property of one node,
66 * using struct ofnode and an offset within the flat device tree or either
67 * a pointer to a struct property in the live device tree.
69 * Thus we can reference arguments in both the live tree and the flat tree.
71 * The property reference can also hold a null reference. This corresponds to
72 * a struct property NULL pointer or an offset of -1.
74 * @node: Pointer to device node
75 * @offset: Pointer into flat device tree, used for flat tree.
76 * @prop: Pointer to property, used for live treee.
83 const struct property *prop;
88 * ofnode_to_np() - convert an ofnode to a live DT node pointer
90 * This cannot be called if the reference contains an offset.
92 * @node: Reference containing struct device_node * (possibly invalid)
93 * @return pointer to device node (can be NULL)
95 static inline const struct device_node *ofnode_to_np(ofnode node)
98 if (!of_live_active())
105 * ofnode_to_offset() - convert an ofnode to a flat DT offset
107 * This cannot be called if the reference contains a node pointer.
109 * @node: Reference containing offset (possibly invalid)
110 * @return DT offset (can be -1)
112 static inline int ofnode_to_offset(ofnode node)
115 if (of_live_active())
118 return node.of_offset;
122 * ofnode_valid() - check if an ofnode is valid
124 * @return true if the reference contains a valid ofnode, false if it is NULL
126 static inline bool ofnode_valid(ofnode node)
128 if (of_live_active())
129 return node.np != NULL;
131 return node.of_offset >= 0;
135 * offset_to_ofnode() - convert a DT offset to an ofnode
137 * @of_offset: DT offset (either valid, or -1)
138 * @return reference to the associated DT offset
140 static inline ofnode offset_to_ofnode(int of_offset)
144 if (of_live_active())
147 node.of_offset = of_offset >= 0 ? of_offset : -1;
153 * np_to_ofnode() - convert a node pointer to an ofnode
155 * @np: Live node pointer (can be NULL)
156 * @return reference to the associated node pointer
158 static inline ofnode np_to_ofnode(const struct device_node *np)
168 * ofnode_is_np() - check if a reference is a node pointer
170 * This function associated that if there is a valid live tree then all
171 * references will use it. This is because using the flat DT when the live tree
172 * is valid is not permitted.
174 * @node: reference to check (possibly invalid)
175 * @return true if the reference is a live node pointer, false if it is a DT
178 static inline bool ofnode_is_np(ofnode node)
182 * Check our assumption that flat tree offsets are not used when a
183 * live tree is in use.
185 assert(!ofnode_valid(node) ||
186 (of_live_active() ? ofnode_to_np(node)
187 : ofnode_to_np(node)));
189 return of_live_active() && ofnode_valid(node);
193 * ofnode_equal() - check if two references are equal
195 * @return true if equal, else false
197 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
199 /* We only need to compare the contents */
200 return ref1.of_offset == ref2.of_offset;
204 * ofnode_null() - Obtain a null ofnode
206 * This returns an ofnode which points to no node. It works both with the flat
209 static inline ofnode ofnode_null(void)
213 if (of_live_active())
221 static inline ofnode ofnode_root(void)
225 if (of_live_active())
226 node.np = gd_of_root();
234 * ofnode_read_u32() - Read a 32-bit integer from a property
236 * @ref: valid node reference to read property from
237 * @propname: name of the property to read from
238 * @outp: place to put value (if found)
239 * @return 0 if OK, -ve on error
241 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
244 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
246 * @ref: valid node reference to read property from
247 * @propname: name of the property to read from
248 * @index: index of the integer to return
249 * @outp: place to put value (if found)
250 * @return 0 if OK, -ve on error
252 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
256 * ofnode_read_s32() - Read a 32-bit integer from a property
258 * @ref: valid node reference to read property from
259 * @propname: name of the property to read from
260 * @outp: place to put value (if found)
261 * @return 0 if OK, -ve on error
263 static inline int ofnode_read_s32(ofnode node, const char *propname,
266 return ofnode_read_u32(node, propname, (u32 *)out_value);
270 * ofnode_read_u32_default() - Read a 32-bit integer from a property
272 * @ref: valid node reference to read property from
273 * @propname: name of the property to read from
274 * @def: default value to return if the property has no value
275 * @return property value, or @def if not found
277 u32 ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
280 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
283 * @ref: valid node reference to read property from
284 * @propname: name of the property to read from
285 * @index: index of the integer to return
286 * @def: default value to return if the property has no value
287 * @return property value, or @def if not found
289 u32 ofnode_read_u32_index_default(ofnode ref, const char *propname, int index,
293 * ofnode_read_s32_default() - Read a 32-bit integer from a property
295 * @ref: valid node reference to read property from
296 * @propname: name of the property to read from
297 * @def: default value to return if the property has no value
298 * @return property value, or @def if not found
300 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
303 * ofnode_read_u64() - Read a 64-bit integer from a property
305 * @node: valid node reference to read property from
306 * @propname: name of the property to read from
307 * @outp: place to put value (if found)
308 * @return 0 if OK, -ve on error
310 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
313 * ofnode_read_u64_default() - Read a 64-bit integer from a property
315 * @ref: valid node reference to read property from
316 * @propname: name of the property to read from
317 * @def: default value to return if the property has no value
318 * @return property value, or @def if not found
320 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
323 * ofnode_read_prop() - Read a property from a node
325 * @node: valid node reference to read property from
326 * @propname: name of the property to read
327 * @sizep: if non-NULL, returns the size of the property, or an error code
329 * @return property value, or NULL if there is no such property
331 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
334 * ofnode_read_string() - Read a string from a property
336 * @node: valid node reference to read property from
337 * @propname: name of the property to read
338 * @return string from property value, or NULL if there is no such property
340 const char *ofnode_read_string(ofnode node, const char *propname);
343 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
345 * @node: valid node reference to read property from
346 * @propname: name of the property to read
347 * @out_values: pointer to return value, modified only if return value is 0
348 * @sz: number of array elements to read
349 * @return 0 if OK, -ve on error
351 * Search for a property in a device node and read 32-bit value(s) from
352 * it. Returns 0 on success, -EINVAL if the property does not exist,
353 * -ENODATA if property does not have a value, and -EOVERFLOW if the
354 * property data isn't large enough.
356 * The out_values is modified only if a valid u32 value can be decoded.
358 int ofnode_read_u32_array(ofnode node, const char *propname,
359 u32 *out_values, size_t sz);
361 * ofnode_is_enabled() - Checks whether a node is enabled.
362 * This looks for a 'status' property. If this exists, then returns true if
363 * the status is 'okay' and false otherwise. If there is no status property,
364 * it returns true on the assumption that anything mentioned should be enabled
367 * @node: node to examine
368 * @return false (not enabled) or true (enabled)
370 bool ofnode_is_enabled(ofnode node);
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);
392 * ofnode_first_subnode() - find the first subnode of a parent node
394 * @node: valid reference to a valid parent node
395 * @return reference to the first subnode (which can be invalid if the parent
396 * node has no subnodes)
398 ofnode ofnode_first_subnode(ofnode node);
401 * ofnode_next_subnode() - find the next sibling of a subnode
403 * @node: valid reference to previous node (sibling)
404 * @return reference to the next subnode (which can be invalid if the node
405 * has no more siblings)
407 ofnode ofnode_next_subnode(ofnode node);
410 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
412 * @node: valid node to look up
413 * @return ofnode reference of the parent node
415 ofnode ofnode_get_parent(ofnode node);
418 * ofnode_get_name() - get the name of a node
420 * @node: valid node to look up
421 * @return name of node
423 const char *ofnode_get_name(ofnode node);
426 * ofnode_get_by_phandle() - get ofnode from phandle
428 * @phandle: phandle to look up
429 * @return ofnode reference to the phandle
431 ofnode ofnode_get_by_phandle(uint phandle);
434 * ofnode_read_size() - read the size of a property
436 * @node: node to check
437 * @propname: property to check
438 * @return size of property if present, or -EINVAL if not
440 int ofnode_read_size(ofnode node, const char *propname);
443 * ofnode_get_addr_size_index() - get an address/size from a node
446 * This reads the register address/size from a node based on index
448 * @node: node to read from
449 * @index: Index of address to read (0 for first)
450 * @size: Pointer to size of the address
451 * @return address, or FDT_ADDR_T_NONE if not present or invalid
453 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
457 * ofnode_get_addr_index() - get an address from a node
459 * This reads the register address from a node
461 * @node: node to read from
462 * @index: Index of address to read (0 for first)
463 * @return address, or FDT_ADDR_T_NONE if not present or invalid
465 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
468 * ofnode_get_addr() - get an address from a node
470 * This reads the register address from a node
472 * @node: node to read from
473 * @return address, or FDT_ADDR_T_NONE if not present or invalid
475 phys_addr_t ofnode_get_addr(ofnode node);
478 * ofnode_stringlist_search() - find a string in a string list and return index
480 * Note that it is possible for this function to succeed on property values
481 * that are not NUL-terminated. That's because the function will stop after
482 * finding the first occurrence of @string. This can for example happen with
483 * small-valued cell properties, such as #address-cells, when searching for
486 * @node: node to check
487 * @propname: name of the property containing the string list
488 * @string: string to look up in the string list
491 * the index of the string in the list of strings
492 * -ENODATA if the property is not found
493 * -EINVAL on some other error
495 int ofnode_stringlist_search(ofnode node, const char *propname,
499 * ofnode_read_string_index() - obtain an indexed string from a string list
501 * Note that this will successfully extract strings from properties with
502 * non-NUL-terminated values. For example on small-valued cell properties
503 * this function will return the empty string.
505 * If non-NULL, the length of the string (on success) or a negative error-code
506 * (on failure) will be stored in the integer pointer to by lenp.
508 * @node: node to check
509 * @propname: name of the property containing the string list
510 * @index: index of the string to return
511 * @lenp: return location for the string length or an error code on failure
514 * length of string, if found or -ve error value if not found
516 int ofnode_read_string_index(ofnode node, const char *propname, int index,
520 * ofnode_read_string_count() - find the number of strings in a string list
522 * @node: node to check
523 * @propname: name of the property containing the string list
525 * number of strings in the list, or -ve error value if not found
527 int ofnode_read_string_count(ofnode node, const char *property);
530 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
532 * This function is useful to parse lists of phandles and their arguments.
533 * Returns 0 on success and fills out_args, on error returns appropriate
536 * Caller is responsible to call of_node_put() on the returned out_args->np
550 * list = <&phandle1 1 2 &phandle2 3>;
553 * To get a device_node of the `node2' node you may call this:
554 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
556 * @node: device tree node containing a list
557 * @list_name: property name that contains a list
558 * @cells_name: property name that specifies phandles' arguments count
559 * @cells_count: Cell count to use if @cells_name is NULL
560 * @index: index of a phandle to parse out
561 * @out_args: optional pointer to output arguments structure (will be filled)
562 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
563 * @list_name does not exist, -EINVAL if a phandle was not found,
564 * @cells_name could not be found, the arguments were truncated or there
565 * were too many arguments.
567 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
568 const char *cells_name, int cell_count,
570 struct ofnode_phandle_args *out_args);
573 * ofnode_count_phandle_with_args() - Count number of phandle in a list
575 * This function is useful to count phandles into a list.
576 * Returns number of phandle on success, on error returns appropriate
579 * @node: device tree node containing a list
580 * @list_name: property name that contains a list
581 * @cells_name: property name that specifies phandles' arguments count
582 * @cells_count: Cell count to use if @cells_name is NULL
583 * @return number of phandle on success, -ENOENT if @list_name does not
584 * exist, -EINVAL if a phandle was not found, @cells_name could not
587 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
588 const char *cells_name, int cell_count);
591 * ofnode_path() - find a node by full path
593 * @path: Full path to node, e.g. "/bus/spi@1"
594 * @return reference to the node found. Use ofnode_valid() to check if it exists
596 ofnode ofnode_path(const char *path);
599 * ofnode_read_chosen_prop() - get the value of a chosen property
601 * This looks for a property within the /chosen node and returns its value
603 * @propname: Property name to look for
604 * @sizep: Returns size of property, or FDT_ERR_... error code if function
606 * @return property value if found, else NULL
608 const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
611 * ofnode_read_chosen_string() - get the string value of a chosen property
613 * This looks for a property within the /chosen node and returns its value,
614 * checking that it is a valid nul-terminated string
616 * @propname: Property name to look for
617 * @return string value if found, else NULL
619 const char *ofnode_read_chosen_string(const char *propname);
622 * ofnode_get_chosen_node() - get a referenced node from the chosen node
624 * This looks up a named property in the chosen node and uses that as a path to
627 * @return the referenced node if present, else ofnode_null()
629 ofnode ofnode_get_chosen_node(const char *propname);
632 * ofnode_read_aliases_prop() - get the value of a aliases property
634 * This looks for a property within the /aliases node and returns its value
636 * @propname: Property name to look for
637 * @sizep: Returns size of property, or FDT_ERR_... error code if function
639 * @return property value if found, else NULL
641 const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
644 * ofnode_get_aliases_node() - get a referenced node from the aliases node
646 * This looks up a named property in the aliases node and uses that as a path to
649 * @return the referenced node if present, else ofnode_null()
651 ofnode ofnode_get_aliases_node(const char *propname);
653 struct display_timing;
655 * ofnode_decode_display_timing() - decode display timings
657 * Decode display timings from the supplied 'display-timings' node.
658 * See doc/device-tree-bindings/video/display-timing.txt for binding
661 * @node 'display-timing' node containing the timing subnodes
662 * @index Index number to read (0=first timing subnode)
663 * @config Place to put timings
664 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
666 int ofnode_decode_display_timing(ofnode node, int index,
667 struct display_timing *config);
670 * ofnode_get_property() - get a pointer to the value of a node property
672 * @node: node to read
673 * @propname: property to read
674 * @lenp: place to put length on success
675 * @return pointer to property, or NULL if not found
677 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
680 * ofnode_get_first_property()- get the reference of the first property
682 * Get reference to the first property of the node, it is used to iterate
683 * and read all the property with ofnode_get_property_by_prop().
685 * @node: node to read
686 * @prop: place to put argument reference
687 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
689 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
692 * ofnode_get_next_property() - get the reference of the next property
694 * Get reference to the next property of the node, it is used to iterate
695 * and read all the property with ofnode_get_property_by_prop().
697 * @prop: reference of current argument and place to put reference of next one
698 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
700 int ofnode_get_next_property(struct ofprop *prop);
703 * ofnode_get_property_by_prop() - get a pointer to the value of a property
705 * Get value for the property identified by the provided reference.
707 * @prop: reference on property
708 * @propname: If non-NULL, place to property name on success,
709 * @lenp: If non-NULL, place to put length on success
710 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
712 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
713 const char **propname, int *lenp);
716 * ofnode_is_available() - check if a node is marked available
718 * @node: node to check
719 * @return true if node's 'status' property is "okay" (or is missing)
721 bool ofnode_is_available(ofnode node);
724 * ofnode_get_addr_size() - get address and size from a property
726 * This does no address translation. It simply reads an property that contains
727 * an address and a size value, one after the other.
729 * @node: node to read from
730 * @propname: property to read
731 * @sizep: place to put size value (on success)
732 * @return address value, or FDT_ADDR_T_NONE on error
734 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
738 * ofnode_read_u8_array_ptr() - find an 8-bit array
740 * Look up a property in a node and return a pointer to its contents as a
741 * byte array of given length. The property must have at least enough data
742 * for the array (count bytes). It may have more, but this will be ignored.
743 * The data is not copied.
745 * @node node to examine
746 * @propname name of property to find
747 * @sz number of array elements
748 * @return pointer to byte array if found, or NULL if the property is not
749 * found or there is not enough data
751 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
755 * ofnode_read_pci_addr() - look up a PCI address
757 * Look at an address property in a node and return the PCI address which
758 * corresponds to the given type in the form of fdt_pci_addr.
759 * The property must hold one fdt_pci_addr with a lengh.
761 * @node node to examine
762 * @type pci address type (FDT_PCI_SPACE_xxx)
763 * @propname name of property to find
764 * @addr returns pci address in the form of fdt_pci_addr
765 * @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
766 * format of the property was invalid, -ENXIO if the requested
767 * address type was not found
769 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
770 const char *propname, struct fdt_pci_addr *addr);
773 * ofnode_read_pci_vendev() - look up PCI vendor and device id
775 * Look at the compatible property of a device node that represents a PCI
776 * device and extract pci vendor id and device id from it.
778 * @param node node to examine
779 * @param vendor vendor id of the pci device
780 * @param device device id of the pci device
781 * @return 0 if ok, negative on error
783 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
786 * ofnode_read_addr_cells() - Get the number of address cells for a node
788 * This walks back up the tree to find the closest #address-cells property
789 * which controls the given node.
791 * @node: Node to check
792 * @return number of address cells this node uses
794 int ofnode_read_addr_cells(ofnode node);
797 * ofnode_read_size_cells() - Get the number of size cells for a node
799 * This walks back up the tree to find the closest #size-cells property
800 * which controls the given node.
802 * @node: Node to check
803 * @return number of size cells this node uses
805 int ofnode_read_size_cells(ofnode node);
808 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
810 * This function matches fdt_address_cells().
812 * @np: Node pointer to check
813 * @return value of #address-cells property in this node, or 2 if none
815 int ofnode_read_simple_addr_cells(ofnode node);
818 * ofnode_read_simple_size_cells() - Get the size cells property in a node
820 * This function matches fdt_size_cells().
822 * @np: Node pointer to check
823 * @return value of #size-cells property in this node, or 2 if none
825 int ofnode_read_simple_size_cells(ofnode node);
828 * ofnode_pre_reloc() - check if a node should be bound before relocation
830 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
831 * via special device tree properties.
833 * Before relocation this function can be used to check if nodes are required
834 * in either SPL or TPL stages.
836 * After relocation and jumping into the real U-Boot binary it is possible to
837 * determine if a node was bound in one of SPL/TPL stages.
839 * There are 4 settings currently in use
840 * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
841 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
842 * Existing platforms only use it to indicate nodes needed in
843 * SPL. Should probably be replaced by u-boot,dm-spl for
845 * - u-boot,dm-spl: SPL and U-Boot pre-relocation
846 * - u-boot,dm-tpl: TPL and U-Boot pre-relocation
848 * @node: node to check
849 * @return true if node is needed in SPL/TL, false otherwise
851 bool ofnode_pre_reloc(ofnode node);
854 * ofnode_read_resource() - Read a resource from a node
856 * Read resource information from a node at the given index
858 * @node: Node to read from
859 * @index: Index of resource to read (0 = first)
860 * @res: Returns resource that was read, on success
861 * @return 0 if OK, -ve on error
863 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
866 * ofnode_read_resource_byname() - Read a resource from a node by name
868 * Read resource information from a node matching the given name. This uses a
869 * 'reg-names' string list property with the names matching the associated
870 * 'reg' property list.
872 * @node: Node to read from
873 * @name: Name of resource to read
874 * @res: Returns resource that was read, on success
875 * @return 0 if OK, -ve on error
877 int ofnode_read_resource_byname(ofnode node, const char *name,
878 struct resource *res);
881 * ofnode_by_compatible() - Find the next compatible node
883 * Find the next node after @from that is compatible with @compat
885 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
886 * @compat: Compatible string to match
887 * @return ofnode found, or ofnode_null() if none
889 ofnode ofnode_by_compatible(ofnode from, const char *compat);
892 * ofnode_by_prop_value() - Find the next node with given property value
894 * Find the next node after @from that has a @propname with a value
895 * @propval and a length @proplen.
897 * @from: ofnode to start from (use ofnode_null() to start at the
898 * beginning) @propname: property name to check @propval: property value to
899 * search for @proplen: length of the value in propval @return ofnode
900 * found, or ofnode_null() if none
902 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
903 const void *propval, int proplen);
906 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
908 * @node: child node (ofnode, lvalue)
909 * @parent: parent node (ofnode)
911 * This is a wrapper around a for loop and is used like so:
915 * ofnode_for_each_subnode(node, parent) {
920 * Note that this is implemented as a macro and @node is used as
921 * iterator in the loop. The parent variable can be a constant or even a
924 #define ofnode_for_each_subnode(node, parent) \
925 for (node = ofnode_first_subnode(parent); \
926 ofnode_valid(node); \
927 node = ofnode_next_subnode(node))
930 * ofnode_get_child_count() - get the child count of a ofnode
932 * @node: valid node to get its child count
933 * @return the number of subnodes
935 int ofnode_get_child_count(ofnode parent);
938 * ofnode_translate_address() - Translate a device-tree address
940 * Translate an address from the device-tree into a CPU physical address. This
941 * function walks up the tree and applies the various bus mappings along the
944 * @ofnode: Device tree node giving the context in which to translate the
946 * @in_addr: pointer to the address to translate
947 * @return the translated address; OF_BAD_ADDR on error
949 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
952 * ofnode_translate_dma_address() - Translate a device-tree DMA address
954 * Translate a DMA address from the device-tree into a CPU physical address.
955 * This function walks up the tree and applies the various bus mappings along
958 * @ofnode: Device tree node giving the context in which to translate the
960 * @in_addr: pointer to the DMA address to translate
961 * @return the translated DMA address; OF_BAD_ADDR on error
963 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
966 * ofnode_device_is_compatible() - check if the node is compatible with compat
968 * This allows to check whether the node is comaptible with the compat.
970 * @node: Device tree node for which compatible needs to be verified.
971 * @compat: Compatible string which needs to verified in the given node.
972 * @return true if OK, false if the compatible is not found
974 int ofnode_device_is_compatible(ofnode node, const char *compat);
977 * ofnode_write_prop() - Set a property of a ofnode
979 * Note that the value passed to the function is *not* allocated by the
980 * function itself, but must be allocated by the caller if necessary.
982 * @node: The node for whose property should be set
983 * @propname: The name of the property to set
984 * @len: The length of the new value of the property
985 * @value: The new value of the property (must be valid prior to calling
987 * @return 0 if successful, -ve on error
989 int ofnode_write_prop(ofnode node, const char *propname, int len,
993 * ofnode_write_string() - Set a string property of a ofnode
995 * Note that the value passed to the function is *not* allocated by the
996 * function itself, but must be allocated by the caller if necessary.
998 * @node: The node for whose string property should be set
999 * @propname: The name of the string property to set
1000 * @value: The new value of the string property (must be valid prior to
1001 * calling the function)
1002 * @return 0 if successful, -ve on error
1004 int ofnode_write_string(ofnode node, const char *propname, const char *value);
1007 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1010 * This function effectively sets the node's "status" property to either "okay"
1011 * or "disable", hence making it available for driver model initialization or
1014 * @node: The node to enable
1015 * @value: Flag that tells the function to either disable or enable the
1017 * @return 0 if successful, -ve on error
1019 int ofnode_set_enabled(ofnode node, bool value);