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);