2 * Copyright (c) 2011 The Chromium OS Authors.
3 * See file CREDITS for list of people who contributed to this
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * This file contains convenience functions for decoding useful and
25 * enlightening information from FDTs. It is intended to be used by device
26 * drivers and board-specific code within U-Boot. It aims to reduce the
27 * amount of FDT munging required within U-Boot itself, so that driver code
28 * changes to support FDT are minimized.
34 * A typedef for a physical address. Note that fdt data is always big
35 * endian even on a litle endian machine.
37 #ifdef CONFIG_PHYS_64BIT
38 typedef u64 fdt_addr_t;
39 #define FDT_ADDR_T_NONE (-1ULL)
40 #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
42 typedef u32 fdt_addr_t;
43 #define FDT_ADDR_T_NONE (-1U)
44 #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
47 /* Information obtained about memory from the FDT */
54 * Compat types that we know about and for which we might have drivers.
55 * Each is named COMPAT_<dir>_<filename> where <dir> is the directory
65 * Find the next numbered alias for a peripheral. This is used to enumerate
66 * all the peripherals of a certain type.
68 * Do the first call with *upto = 0. Assuming /aliases/<name>0 exists then
69 * this function will return a pointer to the node the alias points to, and
70 * then update *upto to 1. Next time you call this function, the next node
73 * All nodes returned will match the compatible ID, as it is assumed that
74 * all peripherals use the same driver.
76 * @param blob FDT blob to use
77 * @param name Root name of alias to search for
78 * @param id Compatible ID to look for
79 * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
81 int fdtdec_next_alias(const void *blob, const char *name,
82 enum fdt_compat_id id, int *upto);
85 * Look up an address property in a node and return it as an address.
86 * The property must hold either one address with no trailing data or
87 * one address with a length. This is only tested on 32-bit machines.
89 * @param blob FDT blob
90 * @param node node to examine
91 * @param prop_name name of property to find
92 * @return address, if found, or FDT_ADDR_T_NONE if not
94 fdt_addr_t fdtdec_get_addr(const void *blob, int node,
95 const char *prop_name);
98 * Look up a 32-bit integer property in a node and return it. The property
99 * must have at least 4 bytes of data. The value of the first cell is
102 * @param blob FDT blob
103 * @param node node to examine
104 * @param prop_name name of property to find
105 * @param default_val default value to return if the property is not found
106 * @return integer value, if found, or default_val if not
108 s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
112 * Checks whether a node is enabled.
113 * This looks for a 'status' property. If this exists, then returns 1 if
114 * the status is 'ok' and 0 otherwise. If there is no status property,
115 * it returns the default value.
117 * @param blob FDT blob
118 * @param node node to examine
119 * @param default_val default value to return if no 'status' property exists
120 * @return integer value 0/1, if found, or default_val if not
122 int fdtdec_get_is_enabled(const void *blob, int node, int default_val);
125 * Checks whether we have a valid fdt available to control U-Boot, and panic
128 int fdtdec_check_fdt(void);
131 * Find the nodes for a peripheral and return a list of them in the correct
132 * order. This is used to enumerate all the peripherals of a certain type.
134 * To use this, optionally set up a /aliases node with alias properties for
135 * a peripheral. For example, for usb you could have:
138 * usb0 = "/ehci@c5008000";
139 * usb1 = "/ehci@c5000000";
142 * Pass "usb" as the name to this function and will return a list of two
143 * nodes offsets: /ehci@c5008000 and ehci@c5000000.
145 * All nodes returned will match the compatible ID, as it is assumed that
146 * all peripherals use the same driver.
148 * If no alias node is found, then the node list will be returned in the
149 * order found in the fdt. If the aliases mention a node which doesn't
150 * exist, then this will be ignored. If nodes are found with no aliases,
151 * they will be added in any order.
153 * If there is a gap in the aliases, then this function return a 0 node at
154 * that position. The return value will also count these gaps.
156 * This function checks node properties and will not return nodes which are
157 * marked disabled (status = "disabled").
159 * @param blob FDT blob to use
160 * @param name Root name of alias to search for
161 * @param id Compatible ID to look for
162 * @param node_list Place to put list of found nodes
163 * @param maxcount Maximum number of nodes to find
164 * @return number of nodes found on success, FTD_ERR_... on error
166 int fdtdec_find_aliases_for_id(const void *blob, const char *name,
167 enum fdt_compat_id id, int *node_list, int maxcount);
170 * Get the name for a compatible ID
172 * @param id Compatible ID to look for
173 * @return compatible string for that id
175 const char *fdtdec_get_compatible(enum fdt_compat_id id);