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 */
13 #include <dm/of_access.h>
15 #include <phy_interface.h>
17 /* Enable checks to protect against invalid calls */
22 #include <dm/ofnode_decl.h>
24 struct ofnode_phandle_args {
27 uint32_t args[OF_MAX_PHANDLE_ARGS];
31 * ofnode_to_np() - convert an ofnode to a live DT node pointer
33 * This cannot be called if the reference contains an offset.
35 * @node: Reference containing struct device_node * (possibly invalid)
36 * Return: pointer to device node (can be NULL)
38 static inline const struct device_node *ofnode_to_np(ofnode node)
41 if (!of_live_active())
48 * ofnode_to_npw() - convert an ofnode to a writeable live DT node pointer
50 * This cannot be called if the reference contains an offset.
52 * @node: Reference containing struct device_node * (possibly invalid)
53 * Return: pointer to device node (can be NULL)
55 static inline struct device_node *ofnode_to_npw(ofnode node)
58 if (!of_live_active())
62 return (struct device_node *)node.np;
66 * ofnode_to_offset() - convert an ofnode to a flat DT offset
68 * This cannot be called if the reference contains a node pointer.
70 * @node: Reference containing offset (possibly invalid)
71 * Return: DT offset (can be -1)
73 static inline int ofnode_to_offset(ofnode node)
79 return node.of_offset;
83 * ofnode_valid() - check if an ofnode is valid
85 * @node: Reference containing offset (possibly invalid)
86 * Return: true if the reference contains a valid ofnode, false if it is NULL
88 static inline bool ofnode_valid(ofnode node)
91 return node.np != NULL;
93 return node.of_offset >= 0;
97 * offset_to_ofnode() - convert a DT offset to an ofnode
99 * @of_offset: DT offset (either valid, or -1)
100 * Return: reference to the associated DT offset
102 static inline ofnode offset_to_ofnode(int of_offset)
106 if (of_live_active())
109 node.of_offset = of_offset >= 0 ? of_offset : -1;
115 * np_to_ofnode() - convert a node pointer to an ofnode
117 * @np: Live node pointer (can be NULL)
118 * Return: reference to the associated node pointer
120 static inline ofnode np_to_ofnode(const struct device_node *np)
130 * ofnode_is_np() - check if a reference is a node pointer
132 * This function associated that if there is a valid live tree then all
133 * references will use it. This is because using the flat DT when the live tree
134 * is valid is not permitted.
136 * @node: reference to check (possibly invalid)
137 * Return: true if the reference is a live node pointer, false if it is a DT
140 static inline bool ofnode_is_np(ofnode node)
144 * Check our assumption that flat tree offsets are not used when a
145 * live tree is in use.
147 assert(!ofnode_valid(node) ||
148 (of_live_active() ? ofnode_to_np(node)
149 : ofnode_to_np(node)));
151 return of_live_active() && ofnode_valid(node);
155 * ofnode_equal() - check if two references are equal
157 * @ref1: first reference to check (possibly invalid)
158 * @ref2: second reference to check (possibly invalid)
159 * Return: true if equal, else false
161 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
163 /* We only need to compare the contents */
164 return ref1.of_offset == ref2.of_offset;
168 * ofnode_null() - Obtain a null ofnode
170 * This returns an ofnode which points to no node. It works both with the flat
173 static inline ofnode ofnode_null(void)
177 if (of_live_active())
185 static inline ofnode ofnode_root(void)
189 if (of_live_active())
190 node.np = gd_of_root();
198 * oftree_default() - Returns the default device tree (U-Boot's control FDT)
200 * Returns: reference to the control FDT
202 static inline oftree oftree_default(void)
206 if (of_live_active())
207 tree.np = gd_of_root();
209 tree.fdt = (void *)gd->fdt_blob;
215 * ofnode_name_eq() - Check if the node name is equivalent to a given name
216 * ignoring the unit address
218 * @node: valid node reference that has to be compared
219 * @name: name that has to be compared with the node name
220 * Return: true if matches, false if it doesn't match
222 bool ofnode_name_eq(ofnode node, const char *name);
225 * ofnode_read_u8() - Read a 8-bit integer from a property
227 * @node: valid node reference to read property from
228 * @propname: name of the property to read from
229 * @outp: place to put value (if found)
230 * Return: 0 if OK, -ve on error
232 int ofnode_read_u8(ofnode node, const char *propname, u8 *outp);
235 * ofnode_read_u8_default() - Read a 8-bit integer from a property
237 * @node: valid node reference to read property from
238 * @propname: name of the property to read from
239 * @def: default value to return if the property has no value
240 * Return: property value, or @def if not found
242 u8 ofnode_read_u8_default(ofnode node, const char *propname, u8 def);
245 * ofnode_read_u16() - Read a 16-bit integer from a property
247 * @node: 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_u16(ofnode node, const char *propname, u16 *outp);
255 * ofnode_read_u16_default() - Read a 16-bit integer from a property
257 * @node: valid node reference to read property from
258 * @propname: name of the property to read from
259 * @def: default value to return if the property has no value
260 * Return: property value, or @def if not found
262 u16 ofnode_read_u16_default(ofnode node, const char *propname, u16 def);
265 * ofnode_read_u32() - Read a 32-bit integer from a property
267 * @node: valid node reference to read property from
268 * @propname: name of the property to read from
269 * @outp: place to put value (if found)
270 * Return: 0 if OK, -ve on error
272 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
275 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
277 * @node: valid node reference to read property from
278 * @propname: name of the property to read from
279 * @index: index of the integer to return
280 * @outp: place to put value (if found)
281 * Return: 0 if OK, -ve on error
283 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
287 * ofnode_read_s32() - Read a 32-bit integer from a property
289 * @node: valid node reference to read property from
290 * @propname: name of the property to read from
291 * @outp: place to put value (if found)
292 * Return: 0 if OK, -ve on error
294 static inline int ofnode_read_s32(ofnode node, const char *propname,
297 return ofnode_read_u32(node, propname, (u32 *)outp);
301 * ofnode_read_u32_default() - Read a 32-bit integer from a property
303 * @node: valid node reference to read property from
304 * @propname: name of the property to read from
305 * @def: default value to return if the property has no value
306 * Return: property value, or @def if not found
308 u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def);
311 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
314 * @node: valid node reference to read property from
315 * @propname: name of the property to read from
316 * @index: index of the integer to return
317 * @def: default value to return if the property has no value
318 * Return: property value, or @def if not found
320 u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
324 * ofnode_read_s32_default() - Read a 32-bit integer from a property
326 * @node: 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 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
334 * ofnode_read_u64() - Read a 64-bit integer from a property
336 * @node: valid node reference to read property from
337 * @propname: name of the property to read from
338 * @outp: place to put value (if found)
339 * Return: 0 if OK, -ve on error
341 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
344 * ofnode_read_u64_default() - Read a 64-bit integer from a property
346 * @node: valid node reference to read property from
347 * @propname: name of the property to read from
348 * @def: default value to return if the property has no value
349 * Return: property value, or @def if not found
351 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
354 * ofnode_read_prop() - Read a property from a node
356 * @node: valid node reference to read property from
357 * @propname: name of the property to read
358 * @sizep: if non-NULL, returns the size of the property, or an error code
360 * Return: property value, or NULL if there is no such property
362 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
365 * ofnode_read_string() - Read a string from a property
367 * @node: valid node reference to read property from
368 * @propname: name of the property to read
369 * Return: string from property value, or NULL if there is no such property
371 const char *ofnode_read_string(ofnode node, const char *propname);
374 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
376 * @node: valid node reference to read property from
377 * @propname: name of the property to read
378 * @out_values: pointer to return value, modified only if return value is 0
379 * @sz: number of array elements to read
380 * Return: 0 if OK, -ve on error
382 * Search for a property in a device node and read 32-bit value(s) from
383 * it. Returns 0 on success, -EINVAL if the property does not exist,
384 * -ENODATA if property does not have a value, and -EOVERFLOW if the
385 * property data isn't large enough.
387 * The out_values is modified only if a valid u32 value can be decoded.
389 int ofnode_read_u32_array(ofnode node, const char *propname,
390 u32 *out_values, size_t sz);
393 * ofnode_read_bool() - read a boolean value from a property
395 * @node: valid node reference to read property from
396 * @propname: name of property to read
397 * Return: true if property is present (meaning true), false if not present
399 bool ofnode_read_bool(ofnode node, const char *propname);
402 * ofnode_find_subnode() - find a named subnode of a parent node
404 * @node: valid reference to parent node
405 * @subnode_name: name of subnode to find
406 * Return: reference to subnode (which can be invalid if there is no such
409 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
411 #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
412 #include <asm/global_data.h>
414 static inline bool ofnode_is_enabled(ofnode node)
416 if (ofnode_is_np(node)) {
417 return of_device_is_available(ofnode_to_np(node));
419 return fdtdec_get_is_enabled(gd->fdt_blob,
420 ofnode_to_offset(node));
424 static inline ofnode ofnode_first_subnode(ofnode node)
426 assert(ofnode_valid(node));
427 if (ofnode_is_np(node))
428 return np_to_ofnode(node.np->child);
430 return offset_to_ofnode(
431 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
434 static inline ofnode ofnode_next_subnode(ofnode node)
436 assert(ofnode_valid(node));
437 if (ofnode_is_np(node))
438 return np_to_ofnode(node.np->sibling);
440 return offset_to_ofnode(
441 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
445 * ofnode_is_enabled() - Checks whether a node is enabled.
446 * This looks for a 'status' property. If this exists, then returns true if
447 * the status is 'okay' and false otherwise. If there is no status property,
448 * it returns true on the assumption that anything mentioned should be enabled
451 * @node: node to examine
452 * Return: false (not enabled) or true (enabled)
454 bool ofnode_is_enabled(ofnode node);
457 * ofnode_first_subnode() - find the first subnode of a parent node
459 * @node: valid reference to a valid parent node
460 * Return: reference to the first subnode (which can be invalid if the parent
461 * node has no subnodes)
463 ofnode ofnode_first_subnode(ofnode node);
466 * ofnode_next_subnode() - find the next sibling of a subnode
468 * @node: valid reference to previous node (sibling)
469 * Return: reference to the next subnode (which can be invalid if the node
470 * has no more siblings)
472 ofnode ofnode_next_subnode(ofnode node);
473 #endif /* DM_INLINE_OFNODE */
476 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
478 * @node: valid node to look up
479 * Return: ofnode reference of the parent node
481 ofnode ofnode_get_parent(ofnode node);
484 * ofnode_get_name() - get the name of a node
486 * @node: valid node to look up
487 * Return: name of node
489 const char *ofnode_get_name(ofnode node);
492 * ofnode_get_path() - get the full path of a node
494 * @node: valid node to look up
495 * @buf: buffer to write the node path into
496 * @buflen: buffer size
497 * Return: 0 if OK, -ve on error
499 int ofnode_get_path(ofnode node, char *buf, int buflen);
502 * ofnode_get_by_phandle() - get ofnode from phandle
504 * @phandle: phandle to look up
505 * Return: ofnode reference to the phandle
507 ofnode ofnode_get_by_phandle(uint phandle);
510 * ofnode_read_size() - read the size of a property
512 * @node: node to check
513 * @propname: property to check
514 * Return: size of property if present, or -EINVAL if not
516 int ofnode_read_size(ofnode node, const char *propname);
519 * ofnode_get_addr_size_index() - get an address/size from a node
522 * This reads the register address/size from a node based on index
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(ofnode node, int index,
533 * ofnode_get_addr_size_index_notrans() - get an address/size from a node
534 * based on index, without address
537 * This reads the register address/size from a node based on index.
538 * The resulting address is not translated. Useful for example for on-disk
541 * @node: node to read from
542 * @index: Index of address to read (0 for first)
543 * @size: Pointer to size of the address
544 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
546 phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
550 * ofnode_get_addr_index() - get an address from a node
552 * This reads the register address from a node
554 * @node: node to read from
555 * @index: Index of address to read (0 for first)
556 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
558 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
561 * ofnode_get_addr() - get an address from a node
563 * This reads the register address from a node
565 * @node: node to read from
566 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
568 phys_addr_t ofnode_get_addr(ofnode node);
571 * ofnode_get_size() - get size from a node
573 * This reads the register size from a node
575 * @node: node to read from
576 * Return: size of the address, or FDT_SIZE_T_NONE if not present or invalid
578 fdt_size_t ofnode_get_size(ofnode node);
581 * ofnode_stringlist_search() - find a string in a string list and return index
583 * Note that it is possible for this function to succeed on property values
584 * that are not NUL-terminated. That's because the function will stop after
585 * finding the first occurrence of @string. This can for example happen with
586 * small-valued cell properties, such as #address-cells, when searching for
589 * @node: node to check
590 * @propname: name of the property containing the string list
591 * @string: string to look up in the string list
594 * the index of the string in the list of strings
595 * -ENODATA if the property is not found
596 * -EINVAL on some other error
598 int ofnode_stringlist_search(ofnode node, const char *propname,
602 * ofnode_read_string_index() - obtain an indexed string from a string list
604 * Note that this will successfully extract strings from properties with
605 * non-NUL-terminated values. For example on small-valued cell properties
606 * this function will return the empty string.
608 * If non-NULL, the length of the string (on success) or a negative error-code
609 * (on failure) will be stored in the integer pointer to by lenp.
611 * @node: node to check
612 * @propname: name of the property containing the string list
613 * @index: index of the string to return (cannot be negative)
614 * @outp: return location for the string
617 * 0 if found or -ve error value if not found
619 int ofnode_read_string_index(ofnode node, const char *propname, int index,
623 * ofnode_read_string_count() - find the number of strings in a string list
625 * @node: node to check
626 * @property: name of the property containing the string list
628 * number of strings in the list, or -ve error value if not found
630 int ofnode_read_string_count(ofnode node, const char *property);
633 * ofnode_read_string_list() - read a list of strings
635 * This produces a list of string pointers with each one pointing to a string
636 * in the string list. If the property does not exist, it returns {NULL}.
638 * The data is allocated and the caller is reponsible for freeing the return
639 * value (the list of string pointers). The strings themselves may not be
640 * changed as they point directly into the devicetree property.
642 * @node: node to check
643 * @property: name of the property containing the string list
644 * @listp: returns an allocated, NULL-terminated list of strings if the return
645 * value is > 0, else is set to NULL
647 * number of strings in list, 0 if none, -ENOMEM if out of memory,
648 * -EINVAL if no such property, -EENODATA if property is empty
650 int ofnode_read_string_list(ofnode node, const char *property,
651 const char ***listp);
654 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
656 * This function is useful to parse lists of phandles and their arguments.
657 * Returns 0 on success and fills out_args, on error returns appropriate
660 * Caller is responsible to call of_node_put() on the returned out_args->np
674 * list = <&phandle1 1 2 &phandle2 3>;
677 * To get a device_node of the `node2' node you may call this:
678 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
680 * @node: device tree node containing a list
681 * @list_name: property name that contains a list
682 * @cells_name: property name that specifies phandles' arguments count
683 * @cell_count: Cell count to use if @cells_name is NULL
684 * @index: index of a phandle to parse out
685 * @out_args: optional pointer to output arguments structure (will be filled)
687 * 0 on success (with @out_args filled out if not NULL), -ENOENT if
688 * @list_name does not exist, -EINVAL if a phandle was not found,
689 * @cells_name could not be found, the arguments were truncated or there
690 * were too many arguments.
692 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
693 const char *cells_name, int cell_count,
695 struct ofnode_phandle_args *out_args);
698 * ofnode_count_phandle_with_args() - Count number of phandle in a list
700 * This function is useful to count phandles into a list.
701 * Returns number of phandle on success, on error returns appropriate
704 * @node: device tree node containing a list
705 * @list_name: property name that contains a list
706 * @cells_name: property name that specifies phandles' arguments count
707 * @cell_count: Cell count to use if @cells_name is NULL
709 * number of phandle on success, -ENOENT if @list_name does not exist,
710 * -EINVAL if a phandle was not found, @cells_name could not be found.
712 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
713 const char *cells_name, int cell_count);
716 * ofnode_path() - find a node by full path
718 * This uses the control FDT.
720 * @path: Full path to node, e.g. "/bus/spi@1"
721 * Return: reference to the node found. Use ofnode_valid() to check if it exists
723 ofnode ofnode_path(const char *path);
726 * ofnode_path_root() - find a node by full path from a root node
728 * @tree: Device tree to use
729 * @path: Full path to node, e.g. "/bus/spi@1"
730 * Return: reference to the node found. Use ofnode_valid() to check if it exists
732 ofnode ofnode_path_root(oftree tree, const char *path);
735 * ofnode_read_chosen_prop() - get the value of a chosen property
737 * This looks for a property within the /chosen node and returns its value
739 * @propname: Property name to look for
740 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
742 * Return: property value if found, else NULL
744 const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
747 * ofnode_read_chosen_string() - get the string value of a chosen property
749 * This looks for a property within the /chosen node and returns its value,
750 * checking that it is a valid nul-terminated string
752 * @propname: Property name to look for
753 * Return: string value if found, else NULL
755 const char *ofnode_read_chosen_string(const char *propname);
758 * ofnode_get_chosen_node() - get a referenced node from the chosen node
760 * This looks up a named property in the chosen node and uses that as a path to
763 * @propname: Property name to look for
764 * Return: the referenced node if present, else ofnode_null()
766 ofnode ofnode_get_chosen_node(const char *propname);
769 * ofnode_read_aliases_prop() - get the value of a aliases property
771 * This looks for a property within the /aliases node and returns its value
773 * @propname: Property name to look for
774 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
776 * Return: property value if found, else NULL
778 const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
781 * ofnode_get_aliases_node() - get a referenced node from the aliases node
783 * This looks up a named property in the aliases node and uses that as a path to
786 * @propname: Property name to look for
787 * Return: the referenced node if present, else ofnode_null()
789 ofnode ofnode_get_aliases_node(const char *propname);
791 struct display_timing;
793 * ofnode_decode_display_timing() - decode display timings
795 * Decode display timings from the supplied 'display-timings' node.
796 * See doc/device-tree-bindings/video/display-timing.txt for binding
799 * @node: 'display-timing' node containing the timing subnodes
800 * @index: Index number to read (0=first timing subnode)
801 * @config: Place to put timings
802 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
804 int ofnode_decode_display_timing(ofnode node, int index,
805 struct display_timing *config);
808 * ofnode_get_property() - get a pointer to the value of a node property
810 * @node: node to read
811 * @propname: property to read
812 * @lenp: place to put length on success
813 * Return: pointer to property, or NULL if not found
815 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
818 * ofnode_get_first_property()- get the reference of the first property
820 * Get reference to the first property of the node, it is used to iterate
821 * and read all the property with ofnode_get_property_by_prop().
823 * @node: node to read
824 * @prop: place to put argument reference
825 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
827 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
830 * ofnode_get_next_property() - get the reference of the next property
832 * Get reference to the next property of the node, it is used to iterate
833 * and read all the property with ofnode_get_property_by_prop().
835 * @prop: reference of current argument and place to put reference of next one
836 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
838 int ofnode_get_next_property(struct ofprop *prop);
841 * ofnode_get_property_by_prop() - get a pointer to the value of a property
843 * Get value for the property identified by the provided reference.
845 * @prop: reference on property
846 * @propname: If non-NULL, place to property name on success,
847 * @lenp: If non-NULL, place to put length on success
848 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
850 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
851 const char **propname, int *lenp);
854 * ofnode_is_available() - check if a node is marked available
856 * @node: node to check
857 * Return: true if node's 'status' property is "okay" (or is missing)
859 bool ofnode_is_available(ofnode node);
862 * ofnode_get_addr_size() - get address and size from a property
864 * This does no address translation. It simply reads an property that contains
865 * an address and a size value, one after the other.
867 * @node: node to read from
868 * @propname: property to read
869 * @sizep: place to put size value (on success)
870 * Return: address value, or FDT_ADDR_T_NONE on error
872 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
876 * ofnode_read_u8_array_ptr() - find an 8-bit array
878 * Look up a property in a node and return a pointer to its contents as a
879 * byte array of given length. The property must have at least enough data
880 * for the array (count bytes). It may have more, but this will be ignored.
881 * The data is not copied.
883 * @node: node to examine
884 * @propname: name of property to find
885 * @sz: number of array elements
887 * pointer to byte array if found, or NULL if the property is not found or
888 * there is not enough data
890 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
894 * ofnode_read_pci_addr() - look up a PCI address
896 * Look at an address property in a node and return the PCI address which
897 * corresponds to the given type in the form of fdt_pci_addr.
898 * The property must hold one fdt_pci_addr with a lengh.
900 * @node: node to examine
901 * @type: pci address type (FDT_PCI_SPACE_xxx)
902 * @propname: name of property to find
903 * @addr: returns pci address in the form of fdt_pci_addr
905 * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
906 * format of the property was invalid, -ENXIO if the requested
907 * address type was not found
909 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
910 const char *propname, struct fdt_pci_addr *addr);
913 * ofnode_read_pci_vendev() - look up PCI vendor and device id
915 * Look at the compatible property of a device node that represents a PCI
916 * device and extract pci vendor id and device id from it.
918 * @node: node to examine
919 * @vendor: vendor id of the pci device
920 * @device: device id of the pci device
921 * Return: 0 if ok, negative on error
923 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
926 * ofnode_read_eth_phy_id() - look up eth phy vendor and device id
928 * Look at the compatible property of a device node that represents a eth phy
929 * device and extract phy vendor id and device id from it.
931 * @node: node to examine
932 * @vendor: vendor id of the eth phy device
933 * @device: device id of the eth phy device
934 * Return: 0 if ok, negative on error
936 int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device);
939 * ofnode_read_addr_cells() - Get the number of address cells for a node
941 * This walks back up the tree to find the closest #address-cells property
942 * which controls the given node.
944 * @node: Node to check
945 * Return: number of address cells this node uses
947 int ofnode_read_addr_cells(ofnode node);
950 * ofnode_read_size_cells() - Get the number of size cells for a node
952 * This walks back up the tree to find the closest #size-cells property
953 * which controls the given node.
955 * @node: Node to check
956 * Return: number of size cells this node uses
958 int ofnode_read_size_cells(ofnode node);
961 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
963 * This function matches fdt_address_cells().
965 * @node: Node to check
966 * Return: value of #address-cells property in this node, or 2 if none
968 int ofnode_read_simple_addr_cells(ofnode node);
971 * ofnode_read_simple_size_cells() - Get the size cells property in a node
973 * This function matches fdt_size_cells().
975 * @node: Node to check
976 * Return: value of #size-cells property in this node, or 2 if none
978 int ofnode_read_simple_size_cells(ofnode node);
981 * ofnode_pre_reloc() - check if a node should be bound before relocation
983 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
984 * via special device tree properties.
986 * Before relocation this function can be used to check if nodes are required
987 * in either SPL or TPL stages.
989 * After relocation and jumping into the real U-Boot binary it is possible to
990 * determine if a node was bound in one of SPL/TPL stages.
992 * There are 4 settings currently in use
993 * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
994 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
995 * Existing platforms only use it to indicate nodes needed in
996 * SPL. Should probably be replaced by u-boot,dm-spl for new platforms.
997 * - u-boot,dm-spl: SPL and U-Boot pre-relocation
998 * - u-boot,dm-tpl: TPL and U-Boot pre-relocation
1000 * @node: node to check
1001 * Return: true if node is needed in SPL/TL, false otherwise
1003 bool ofnode_pre_reloc(ofnode node);
1006 * ofnode_read_resource() - Read a resource from a node
1008 * Read resource information from a node at the given index
1010 * @node: Node to read from
1011 * @index: Index of resource to read (0 = first)
1012 * @res: Returns resource that was read, on success
1013 * Return: 0 if OK, -ve on error
1015 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
1018 * ofnode_read_resource_byname() - Read a resource from a node by name
1020 * Read resource information from a node matching the given name. This uses a
1021 * 'reg-names' string list property with the names matching the associated
1022 * 'reg' property list.
1024 * @node: Node to read from
1025 * @name: Name of resource to read
1026 * @res: Returns resource that was read, on success
1027 * Return: 0 if OK, -ve on error
1029 int ofnode_read_resource_byname(ofnode node, const char *name,
1030 struct resource *res);
1033 * ofnode_by_compatible() - Find the next compatible node
1035 * Find the next node after @from that is compatible with @compat
1037 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
1038 * @compat: Compatible string to match
1039 * Return: ofnode found, or ofnode_null() if none
1041 ofnode ofnode_by_compatible(ofnode from, const char *compat);
1044 * ofnode_by_prop_value() - Find the next node with given property value
1046 * Find the next node after @from that has a @propname with a value
1047 * @propval and a length @proplen.
1049 * @from: ofnode to start from (use ofnode_null() to start at the
1051 * @propname: property name to check
1052 * @propval: property value to search for
1053 * @proplen: length of the value in propval
1054 * Return: ofnode found, or ofnode_null() if none
1056 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
1057 const void *propval, int proplen);
1060 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
1062 * @node: child node (ofnode, lvalue)
1063 * @parent: parent node (ofnode)
1065 * This is a wrapper around a for loop and is used like so::
1068 * ofnode_for_each_subnode(node, parent) {
1073 * Note that this is implemented as a macro and @node is used as
1074 * iterator in the loop. The parent variable can be a constant or even a
1077 #define ofnode_for_each_subnode(node, parent) \
1078 for (node = ofnode_first_subnode(parent); \
1079 ofnode_valid(node); \
1080 node = ofnode_next_subnode(node))
1083 * ofnode_for_each_compatible_node() - iterate over all nodes with a given
1086 * @node: child node (ofnode, lvalue)
1087 * @compat: compatible string to match
1089 * This is a wrapper around a for loop and is used like so::
1092 * ofnode_for_each_compatible_node(node, parent, compatible) {
1097 * Note that this is implemented as a macro and @node is used as
1098 * iterator in the loop.
1100 #define ofnode_for_each_compatible_node(node, compat) \
1101 for (node = ofnode_by_compatible(ofnode_null(), compat); \
1102 ofnode_valid(node); \
1103 node = ofnode_by_compatible(node, compat))
1106 * ofnode_get_child_count() - get the child count of a ofnode
1108 * @parent: valid node to get its child count
1109 * Return: the number of subnodes
1111 int ofnode_get_child_count(ofnode parent);
1114 * ofnode_translate_address() - Translate a device-tree address
1116 * Translate an address from the device-tree into a CPU physical address. This
1117 * function walks up the tree and applies the various bus mappings along the
1120 * @node: Device tree node giving the context in which to translate the address
1121 * @in_addr: pointer to the address to translate
1122 * Return: the translated address; OF_BAD_ADDR on error
1124 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
1127 * ofnode_translate_dma_address() - Translate a device-tree DMA address
1129 * Translate a DMA address from the device-tree into a CPU physical address.
1130 * This function walks up the tree and applies the various bus mappings along
1133 * @node: Device tree node giving the context in which to translate the
1135 * @in_addr: pointer to the DMA address to translate
1136 * Return: the translated DMA address; OF_BAD_ADDR on error
1138 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
1141 * ofnode_get_dma_range() - get dma-ranges for a specific DT node
1143 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
1144 * cpu->bus address translations
1146 * @node: Device tree node
1147 * @cpu: Pointer to variable storing the range's cpu address
1148 * @bus: Pointer to variable storing the range's bus address
1149 * @size: Pointer to variable storing the range's size
1150 * Return: translated DMA address or OF_BAD_ADDR on error
1152 int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
1156 * ofnode_device_is_compatible() - check if the node is compatible with compat
1158 * This allows to check whether the node is comaptible with the compat.
1160 * @node: Device tree node for which compatible needs to be verified.
1161 * @compat: Compatible string which needs to verified in the given node.
1162 * Return: true if OK, false if the compatible is not found
1164 int ofnode_device_is_compatible(ofnode node, const char *compat);
1167 * ofnode_write_prop() - Set a property of a ofnode
1169 * Note that the value passed to the function is *not* allocated by the
1170 * function itself, but must be allocated by the caller if necessary. However
1171 * it does allocate memory for the property struct and name.
1173 * @node: The node for whose property should be set
1174 * @propname: The name of the property to set
1175 * @value: The new value of the property (must be valid prior to calling
1177 * @len: The length of the new value of the property
1178 * Return: 0 if successful, -ve on error
1180 int ofnode_write_prop(ofnode node, const char *propname, const void *value,
1184 * ofnode_write_string() - Set a string property of a ofnode
1186 * Note that the value passed to the function is *not* allocated by the
1187 * function itself, but must be allocated by the caller if necessary.
1189 * @node: The node for whose string property should be set
1190 * @propname: The name of the string property to set
1191 * @value: The new value of the string property (must be valid prior to
1192 * calling the function)
1193 * Return: 0 if successful, -ve on error
1195 int ofnode_write_string(ofnode node, const char *propname, const char *value);
1198 * ofnode_write_u32() - Set an integer property of an ofnode
1200 * @node: The node for whose string property should be set
1201 * @propname: The name of the string property to set
1202 * @value: The new value of the 32-bit integer property
1203 * Return: 0 if successful, -ve on error
1205 int ofnode_write_u32(ofnode node, const char *propname, u32 value);
1208 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1211 * This function effectively sets the node's "status" property to either "okay"
1212 * or "disable", hence making it available for driver model initialization or
1215 * @node: The node to enable
1216 * @value: Flag that tells the function to either disable or enable the
1218 * Return: 0 if successful, -ve on error
1220 int ofnode_set_enabled(ofnode node, bool value);
1223 * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
1225 * This function parses PHY handle from the Ethernet controller's ofnode
1226 * (trying all possible PHY handle property names), and returns the PHY ofnode.
1228 * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
1229 * if the result to that is true, this function should not be called.
1231 * @eth_node: ofnode belonging to the Ethernet controller
1232 * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
1234 ofnode ofnode_get_phy_node(ofnode eth_node);
1237 * ofnode_read_phy_mode() - Read PHY connection type from a MAC node
1239 * This function parses the "phy-mode" / "phy-connection-type" property and
1240 * returns the corresponding PHY interface type.
1242 * @mac_node: ofnode containing the property
1243 * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on
1246 phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
1248 #if CONFIG_IS_ENABLED(DM)
1250 * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config
1252 * This reads a property from the /config node of the devicetree.
1254 * See doc/config.txt for bindings
1256 * @prop_name: property name to look up
1257 * Return: true, if it exists, false if not
1259 bool ofnode_conf_read_bool(const char *prop_name);
1262 * ofnode_conf_read_int() - Read an integer value from the U-Boot config
1264 * This reads a property from the /config node of the devicetree.
1266 * See doc/config.txt for bindings
1268 * @prop_name: property name to look up
1269 * @default_val: default value to return if the property is not found
1270 * Return: integer value, if found, or @default_val if not
1272 int ofnode_conf_read_int(const char *prop_name, int default_val);
1275 * ofnode_conf_read_str() - Read a string value from the U-Boot config
1277 * This reads a property from the /config node of the devicetree.
1279 * See doc/config.txt for bindings
1281 * @prop_name: property name to look up
1282 * Return: string value, if found, or NULL if not
1284 const char *ofnode_conf_read_str(const char *prop_name);
1286 #else /* CONFIG_DM */
1287 static inline bool ofnode_conf_read_bool(const char *prop_name)
1292 static inline int ofnode_conf_read_int(const char *prop_name, int default_val)
1297 static inline const char *ofnode_conf_read_str(const char *prop_name)
1301 #endif /* CONFIG_DM */