Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _DM_OFNODE_H |
| 8 | #define _DM_OFNODE_H |
| 9 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 10 | /* TODO(sjg@chromium.org): Drop fdtdec.h include */ |
| 11 | #include <fdtdec.h> |
| 12 | #include <dm/of.h> |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 13 | #include <dm/of_access.h> |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 14 | #include <log.h> |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 15 | #include <phy_interface.h> |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 16 | |
| 17 | /* Enable checks to protect against invalid calls */ |
| 18 | #undef OF_CHECKS |
| 19 | |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 20 | struct resource; |
| 21 | |
Simon Glass | 9693c1d | 2022-07-30 15:52:06 -0600 | [diff] [blame] | 22 | #include <dm/ofnode_decl.h> |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 23 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 24 | struct ofnode_phandle_args { |
| 25 | ofnode node; |
| 26 | int args_count; |
| 27 | uint32_t args[OF_MAX_PHANDLE_ARGS]; |
| 28 | }; |
| 29 | |
| 30 | /** |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 31 | * ofnode_to_np() - convert an ofnode to a live DT node pointer |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 32 | * |
| 33 | * This cannot be called if the reference contains an offset. |
| 34 | * |
| 35 | * @node: Reference containing struct device_node * (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 36 | * Return: pointer to device node (can be NULL) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 37 | */ |
| 38 | static inline const struct device_node *ofnode_to_np(ofnode node) |
| 39 | { |
| 40 | #ifdef OF_CHECKS |
| 41 | if (!of_live_active()) |
| 42 | return NULL; |
| 43 | #endif |
| 44 | return node.np; |
| 45 | } |
| 46 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 47 | /** |
Simon Glass | 3ee3d15 | 2022-07-30 15:52:13 -0600 | [diff] [blame] | 48 | * ofnode_to_npw() - convert an ofnode to a writeable live DT node pointer |
| 49 | * |
| 50 | * This cannot be called if the reference contains an offset. |
| 51 | * |
| 52 | * @node: Reference containing struct device_node * (possibly invalid) |
| 53 | * Return: pointer to device node (can be NULL) |
| 54 | */ |
| 55 | static inline struct device_node *ofnode_to_npw(ofnode node) |
| 56 | { |
| 57 | #ifdef OF_CHECKS |
| 58 | if (!of_live_active()) |
| 59 | return NULL; |
| 60 | #endif |
| 61 | /* Drop constant */ |
| 62 | return (struct device_node *)node.np; |
| 63 | } |
| 64 | |
| 65 | /** |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 66 | * ofnode_to_offset() - convert an ofnode to a flat DT offset |
| 67 | * |
| 68 | * This cannot be called if the reference contains a node pointer. |
| 69 | * |
| 70 | * @node: Reference containing offset (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 71 | * Return: DT offset (can be -1) |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 72 | */ |
| 73 | static inline int ofnode_to_offset(ofnode node) |
| 74 | { |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 75 | #ifdef OF_CHECKS |
| 76 | if (of_live_active()) |
| 77 | return -1; |
| 78 | #endif |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 79 | return node.of_offset; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * ofnode_valid() - check if an ofnode is valid |
| 84 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 85 | * @node: Reference containing offset (possibly invalid) |
| 86 | * Return: true if the reference contains a valid ofnode, false if it is NULL |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 87 | */ |
| 88 | static inline bool ofnode_valid(ofnode node) |
| 89 | { |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 90 | if (of_live_active()) |
| 91 | return node.np != NULL; |
| 92 | else |
Patrick Delaunay | 04fcfe7 | 2020-09-24 17:26:20 +0200 | [diff] [blame] | 93 | return node.of_offset >= 0; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * offset_to_ofnode() - convert a DT offset to an ofnode |
| 98 | * |
| 99 | * @of_offset: DT offset (either valid, or -1) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 100 | * Return: reference to the associated DT offset |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 101 | */ |
| 102 | static inline ofnode offset_to_ofnode(int of_offset) |
| 103 | { |
| 104 | ofnode node; |
| 105 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 106 | if (of_live_active()) |
| 107 | node.np = NULL; |
| 108 | else |
Simon Glass | 1ab8b89 | 2019-12-06 21:41:36 -0700 | [diff] [blame] | 109 | node.of_offset = of_offset >= 0 ? of_offset : -1; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 110 | |
| 111 | return node; |
| 112 | } |
| 113 | |
| 114 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 115 | * np_to_ofnode() - convert a node pointer to an ofnode |
| 116 | * |
| 117 | * @np: Live node pointer (can be NULL) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 118 | * Return: reference to the associated node pointer |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 119 | */ |
| 120 | static inline ofnode np_to_ofnode(const struct device_node *np) |
| 121 | { |
| 122 | ofnode node; |
| 123 | |
| 124 | node.np = np; |
| 125 | |
| 126 | return node; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * ofnode_is_np() - check if a reference is a node pointer |
| 131 | * |
| 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. |
| 135 | * |
| 136 | * @node: reference to check (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 137 | * Return: true if the reference is a live node pointer, false if it is a DT |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 138 | * offset |
| 139 | */ |
| 140 | static inline bool ofnode_is_np(ofnode node) |
| 141 | { |
| 142 | #ifdef OF_CHECKS |
| 143 | /* |
| 144 | * Check our assumption that flat tree offsets are not used when a |
| 145 | * live tree is in use. |
| 146 | */ |
| 147 | assert(!ofnode_valid(node) || |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 148 | (of_live_active() ? ofnode_to_np(node) |
| 149 | : ofnode_to_np(node))); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 150 | #endif |
| 151 | return of_live_active() && ofnode_valid(node); |
| 152 | } |
| 153 | |
| 154 | /** |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 155 | * ofnode_equal() - check if two references are equal |
| 156 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 157 | * @ref1: first reference to check (possibly invalid) |
| 158 | * @ref2: second reference to check (possibly invalid) |
| 159 | * Return: true if equal, else false |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 160 | */ |
| 161 | static inline bool ofnode_equal(ofnode ref1, ofnode ref2) |
| 162 | { |
| 163 | /* We only need to compare the contents */ |
| 164 | return ref1.of_offset == ref2.of_offset; |
| 165 | } |
| 166 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 167 | /** |
| 168 | * ofnode_null() - Obtain a null ofnode |
| 169 | * |
| 170 | * This returns an ofnode which points to no node. It works both with the flat |
| 171 | * tree and livetree. |
| 172 | */ |
| 173 | static inline ofnode ofnode_null(void) |
| 174 | { |
| 175 | ofnode node; |
| 176 | |
| 177 | if (of_live_active()) |
| 178 | node.np = NULL; |
| 179 | else |
| 180 | node.of_offset = -1; |
| 181 | |
| 182 | return node; |
| 183 | } |
| 184 | |
Simon Glass | 278ddba | 2020-11-28 17:50:07 -0700 | [diff] [blame] | 185 | static inline ofnode ofnode_root(void) |
| 186 | { |
| 187 | ofnode node; |
| 188 | |
| 189 | if (of_live_active()) |
| 190 | node.np = gd_of_root(); |
| 191 | else |
| 192 | node.of_offset = 0; |
| 193 | |
| 194 | return node; |
| 195 | } |
| 196 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 197 | /** |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 198 | * oftree_default() - Returns the default device tree (U-Boot's control FDT) |
| 199 | * |
| 200 | * Returns: reference to the control FDT |
| 201 | */ |
| 202 | static inline oftree oftree_default(void) |
| 203 | { |
| 204 | oftree tree; |
| 205 | |
| 206 | if (of_live_active()) |
| 207 | tree.np = gd_of_root(); |
| 208 | else |
| 209 | tree.fdt = (void *)gd->fdt_blob; |
| 210 | |
| 211 | return tree; |
| 212 | } |
| 213 | |
| 214 | /** |
Kishon Vijay Abraham I | d6388f2 | 2021-07-21 21:28:30 +0530 | [diff] [blame] | 215 | * ofnode_name_eq() - Check if the node name is equivalent to a given name |
| 216 | * ignoring the unit address |
| 217 | * |
| 218 | * @node: valid node reference that has to be compared |
| 219 | * @name: name that has to be compared with the node name |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 220 | * Return: true if matches, false if it doesn't match |
Kishon Vijay Abraham I | d6388f2 | 2021-07-21 21:28:30 +0530 | [diff] [blame] | 221 | */ |
| 222 | bool ofnode_name_eq(ofnode node, const char *name); |
| 223 | |
| 224 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 225 | * ofnode_read_u32() - Read a 32-bit integer from a property |
| 226 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 227 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 228 | * @propname: name of the property to read from |
| 229 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 230 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 231 | */ |
| 232 | int ofnode_read_u32(ofnode node, const char *propname, u32 *outp); |
| 233 | |
| 234 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 235 | * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property |
| 236 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 237 | * @node: valid node reference to read property from |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 238 | * @propname: name of the property to read from |
| 239 | * @index: index of the integer to return |
| 240 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 241 | * Return: 0 if OK, -ve on error |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 242 | */ |
| 243 | int ofnode_read_u32_index(ofnode node, const char *propname, int index, |
| 244 | u32 *outp); |
| 245 | |
| 246 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 247 | * ofnode_read_s32() - Read a 32-bit integer from a property |
| 248 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 249 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 250 | * @propname: name of the property to read from |
| 251 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 252 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 253 | */ |
| 254 | static inline int ofnode_read_s32(ofnode node, const char *propname, |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 255 | s32 *outp) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 256 | { |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 257 | return ofnode_read_u32(node, propname, (u32 *)outp); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
| 261 | * ofnode_read_u32_default() - Read a 32-bit integer from a property |
| 262 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 263 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 264 | * @propname: name of the property to read from |
| 265 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 266 | * Return: property value, or @def if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 267 | */ |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 268 | u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 269 | |
| 270 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 271 | * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value |
| 272 | * property |
| 273 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 274 | * @node: valid node reference to read property from |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 275 | * @propname: name of the property to read from |
| 276 | * @index: index of the integer to return |
| 277 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 278 | * Return: property value, or @def if not found |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 279 | */ |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 280 | u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index, |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 281 | u32 def); |
| 282 | |
| 283 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 284 | * ofnode_read_s32_default() - Read a 32-bit integer from a property |
| 285 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 286 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 287 | * @propname: name of the property to read from |
| 288 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 289 | * Return: property value, or @def if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 290 | */ |
| 291 | int ofnode_read_s32_default(ofnode node, const char *propname, s32 def); |
| 292 | |
| 293 | /** |
Lukas Auer | b03a60b | 2018-11-22 11:26:35 +0100 | [diff] [blame] | 294 | * ofnode_read_u64() - Read a 64-bit integer from a property |
| 295 | * |
| 296 | * @node: valid node reference to read property from |
| 297 | * @propname: name of the property to read from |
| 298 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 299 | * Return: 0 if OK, -ve on error |
Lukas Auer | b03a60b | 2018-11-22 11:26:35 +0100 | [diff] [blame] | 300 | */ |
| 301 | int ofnode_read_u64(ofnode node, const char *propname, u64 *outp); |
| 302 | |
| 303 | /** |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 304 | * ofnode_read_u64_default() - Read a 64-bit integer from a property |
| 305 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 306 | * @node: valid node reference to read property from |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 307 | * @propname: name of the property to read from |
| 308 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 309 | * Return: property value, or @def if not found |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 310 | */ |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 311 | u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def); |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 312 | |
| 313 | /** |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 314 | * ofnode_read_prop() - Read a property from a node |
| 315 | * |
| 316 | * @node: valid node reference to read property from |
| 317 | * @propname: name of the property to read |
| 318 | * @sizep: if non-NULL, returns the size of the property, or an error code |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 319 | * if not found |
| 320 | * Return: property value, or NULL if there is no such property |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 321 | */ |
| 322 | const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep); |
| 323 | |
| 324 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 325 | * ofnode_read_string() - Read a string from a property |
| 326 | * |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 327 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 328 | * @propname: name of the property to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 329 | * Return: string from property value, or NULL if there is no such property |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 330 | */ |
| 331 | const char *ofnode_read_string(ofnode node, const char *propname); |
| 332 | |
| 333 | /** |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 334 | * ofnode_read_u32_array() - Find and read an array of 32 bit integers |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 335 | * |
| 336 | * @node: valid node reference to read property from |
| 337 | * @propname: name of the property to read |
| 338 | * @out_values: pointer to return value, modified only if return value is 0 |
| 339 | * @sz: number of array elements to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 340 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 341 | * |
| 342 | * Search for a property in a device node and read 32-bit value(s) from |
| 343 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
| 344 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 345 | * property data isn't large enough. |
| 346 | * |
| 347 | * The out_values is modified only if a valid u32 value can be decoded. |
| 348 | */ |
| 349 | int ofnode_read_u32_array(ofnode node, const char *propname, |
| 350 | u32 *out_values, size_t sz); |
| 351 | |
| 352 | /** |
| 353 | * ofnode_read_bool() - read a boolean value from a property |
| 354 | * |
| 355 | * @node: valid node reference to read property from |
| 356 | * @propname: name of property to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 357 | * Return: true if property is present (meaning true), false if not present |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 358 | */ |
| 359 | bool ofnode_read_bool(ofnode node, const char *propname); |
| 360 | |
| 361 | /** |
| 362 | * ofnode_find_subnode() - find a named subnode of a parent node |
| 363 | * |
| 364 | * @node: valid reference to parent node |
| 365 | * @subnode_name: name of subnode to find |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 366 | * Return: reference to subnode (which can be invalid if there is no such |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 367 | * subnode) |
| 368 | */ |
| 369 | ofnode ofnode_find_subnode(ofnode node, const char *subnode_name); |
| 370 | |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 371 | #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE) |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 372 | #include <asm/global_data.h> |
| 373 | |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 374 | static inline bool ofnode_is_enabled(ofnode node) |
| 375 | { |
| 376 | if (ofnode_is_np(node)) { |
| 377 | return of_device_is_available(ofnode_to_np(node)); |
| 378 | } else { |
| 379 | return fdtdec_get_is_enabled(gd->fdt_blob, |
| 380 | ofnode_to_offset(node)); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | static inline ofnode ofnode_first_subnode(ofnode node) |
| 385 | { |
| 386 | assert(ofnode_valid(node)); |
| 387 | if (ofnode_is_np(node)) |
| 388 | return np_to_ofnode(node.np->child); |
| 389 | |
| 390 | return offset_to_ofnode( |
| 391 | fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node))); |
| 392 | } |
| 393 | |
| 394 | static inline ofnode ofnode_next_subnode(ofnode node) |
| 395 | { |
| 396 | assert(ofnode_valid(node)); |
| 397 | if (ofnode_is_np(node)) |
| 398 | return np_to_ofnode(node.np->sibling); |
| 399 | |
| 400 | return offset_to_ofnode( |
| 401 | fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node))); |
| 402 | } |
| 403 | #else |
| 404 | /** |
| 405 | * ofnode_is_enabled() - Checks whether a node is enabled. |
| 406 | * This looks for a 'status' property. If this exists, then returns true if |
| 407 | * the status is 'okay' and false otherwise. If there is no status property, |
| 408 | * it returns true on the assumption that anything mentioned should be enabled |
| 409 | * by default. |
| 410 | * |
| 411 | * @node: node to examine |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 412 | * Return: false (not enabled) or true (enabled) |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 413 | */ |
| 414 | bool ofnode_is_enabled(ofnode node); |
| 415 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 416 | /** |
| 417 | * ofnode_first_subnode() - find the first subnode of a parent node |
| 418 | * |
| 419 | * @node: valid reference to a valid parent node |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 420 | * Return: reference to the first subnode (which can be invalid if the parent |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 421 | * node has no subnodes) |
| 422 | */ |
| 423 | ofnode ofnode_first_subnode(ofnode node); |
| 424 | |
| 425 | /** |
| 426 | * ofnode_next_subnode() - find the next sibling of a subnode |
| 427 | * |
| 428 | * @node: valid reference to previous node (sibling) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 429 | * Return: reference to the next subnode (which can be invalid if the node |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 430 | * has no more siblings) |
| 431 | */ |
| 432 | ofnode ofnode_next_subnode(ofnode node); |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 433 | #endif /* DM_INLINE_OFNODE */ |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 434 | |
| 435 | /** |
Philipp Tomsich | 6fce1dd | 2018-02-23 17:38:49 +0100 | [diff] [blame] | 436 | * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode) |
| 437 | * |
| 438 | * @node: valid node to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 439 | * Return: ofnode reference of the parent node |
Philipp Tomsich | 6fce1dd | 2018-02-23 17:38:49 +0100 | [diff] [blame] | 440 | */ |
| 441 | ofnode ofnode_get_parent(ofnode node); |
| 442 | |
| 443 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 444 | * ofnode_get_name() - get the name of a node |
| 445 | * |
| 446 | * @node: valid node to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 447 | * Return: name of node |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 448 | */ |
| 449 | const char *ofnode_get_name(ofnode node); |
| 450 | |
| 451 | /** |
Marek Behún | e897e3c | 2021-05-26 14:08:18 +0200 | [diff] [blame] | 452 | * ofnode_get_path() - get the full path of a node |
| 453 | * |
| 454 | * @node: valid node to look up |
| 455 | * @buf: buffer to write the node path into |
| 456 | * @buflen: buffer size |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 457 | * Return: 0 if OK, -ve on error |
Marek Behún | e897e3c | 2021-05-26 14:08:18 +0200 | [diff] [blame] | 458 | */ |
| 459 | int ofnode_get_path(ofnode node, char *buf, int buflen); |
| 460 | |
| 461 | /** |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 462 | * ofnode_get_by_phandle() - get ofnode from phandle |
| 463 | * |
| 464 | * @phandle: phandle to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 465 | * Return: ofnode reference to the phandle |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 466 | */ |
| 467 | ofnode ofnode_get_by_phandle(uint phandle); |
| 468 | |
| 469 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 470 | * ofnode_read_size() - read the size of a property |
| 471 | * |
| 472 | * @node: node to check |
| 473 | * @propname: property to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 474 | * Return: size of property if present, or -EINVAL if not |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 475 | */ |
| 476 | int ofnode_read_size(ofnode node, const char *propname); |
| 477 | |
| 478 | /** |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 479 | * ofnode_get_addr_size_index() - get an address/size from a node |
| 480 | * based on index |
| 481 | * |
| 482 | * This reads the register address/size from a node based on index |
| 483 | * |
| 484 | * @node: node to read from |
| 485 | * @index: Index of address to read (0 for first) |
| 486 | * @size: Pointer to size of the address |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 487 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 488 | */ |
| 489 | phys_addr_t ofnode_get_addr_size_index(ofnode node, int index, |
| 490 | fdt_size_t *size); |
| 491 | |
| 492 | /** |
Marek Behún | 177ab7f | 2021-05-26 14:08:17 +0200 | [diff] [blame] | 493 | * ofnode_get_addr_size_index_notrans() - get an address/size from a node |
| 494 | * based on index, without address |
| 495 | * translation |
| 496 | * |
| 497 | * This reads the register address/size from a node based on index. |
| 498 | * The resulting address is not translated. Useful for example for on-disk |
| 499 | * addresses. |
| 500 | * |
| 501 | * @node: node to read from |
| 502 | * @index: Index of address to read (0 for first) |
| 503 | * @size: Pointer to size of the address |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 504 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Marek Behún | 177ab7f | 2021-05-26 14:08:17 +0200 | [diff] [blame] | 505 | */ |
| 506 | phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index, |
| 507 | fdt_size_t *size); |
| 508 | |
| 509 | /** |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 510 | * ofnode_get_addr_index() - get an address from a node |
| 511 | * |
| 512 | * This reads the register address from a node |
| 513 | * |
| 514 | * @node: node to read from |
| 515 | * @index: Index of address to read (0 for first) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 516 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 517 | */ |
| 518 | phys_addr_t ofnode_get_addr_index(ofnode node, int index); |
| 519 | |
| 520 | /** |
| 521 | * ofnode_get_addr() - get an address from a node |
| 522 | * |
| 523 | * This reads the register address from a node |
| 524 | * |
| 525 | * @node: node to read from |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 526 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 527 | */ |
| 528 | phys_addr_t ofnode_get_addr(ofnode node); |
| 529 | |
| 530 | /** |
Chen Guanqiao | 223f17d | 2021-04-12 14:51:11 +0800 | [diff] [blame] | 531 | * ofnode_get_size() - get size from a node |
| 532 | * |
| 533 | * This reads the register size from a node |
| 534 | * |
| 535 | * @node: node to read from |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 536 | * Return: size of the address, or FDT_SIZE_T_NONE if not present or invalid |
Chen Guanqiao | 223f17d | 2021-04-12 14:51:11 +0800 | [diff] [blame] | 537 | */ |
| 538 | fdt_size_t ofnode_get_size(ofnode node); |
| 539 | |
| 540 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 541 | * ofnode_stringlist_search() - find a string in a string list and return index |
| 542 | * |
| 543 | * Note that it is possible for this function to succeed on property values |
| 544 | * that are not NUL-terminated. That's because the function will stop after |
| 545 | * finding the first occurrence of @string. This can for example happen with |
| 546 | * small-valued cell properties, such as #address-cells, when searching for |
| 547 | * the empty string. |
| 548 | * |
| 549 | * @node: node to check |
| 550 | * @propname: name of the property containing the string list |
| 551 | * @string: string to look up in the string list |
| 552 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 553 | * Return: |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 554 | * the index of the string in the list of strings |
| 555 | * -ENODATA if the property is not found |
| 556 | * -EINVAL on some other error |
| 557 | */ |
| 558 | int ofnode_stringlist_search(ofnode node, const char *propname, |
| 559 | const char *string); |
| 560 | |
| 561 | /** |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 562 | * ofnode_read_string_index() - obtain an indexed string from a string list |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 563 | * |
| 564 | * Note that this will successfully extract strings from properties with |
| 565 | * non-NUL-terminated values. For example on small-valued cell properties |
| 566 | * this function will return the empty string. |
| 567 | * |
| 568 | * If non-NULL, the length of the string (on success) or a negative error-code |
| 569 | * (on failure) will be stored in the integer pointer to by lenp. |
| 570 | * |
| 571 | * @node: node to check |
| 572 | * @propname: name of the property containing the string list |
Simon Glass | 7a3a167 | 2021-10-23 17:26:06 -0600 | [diff] [blame] | 573 | * @index: index of the string to return (cannot be negative) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 574 | * @outp: return location for the string |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 575 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 576 | * Return: |
Simon Glass | 7a3a167 | 2021-10-23 17:26:06 -0600 | [diff] [blame] | 577 | * 0 if found or -ve error value if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 578 | */ |
| 579 | int ofnode_read_string_index(ofnode node, const char *propname, int index, |
| 580 | const char **outp); |
| 581 | |
| 582 | /** |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 583 | * ofnode_read_string_count() - find the number of strings in a string list |
| 584 | * |
| 585 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 586 | * @property: name of the property containing the string list |
| 587 | * Return: |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 588 | * number of strings in the list, or -ve error value if not found |
| 589 | */ |
| 590 | int ofnode_read_string_count(ofnode node, const char *property); |
| 591 | |
| 592 | /** |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 593 | * ofnode_read_string_list() - read a list of strings |
| 594 | * |
| 595 | * This produces a list of string pointers with each one pointing to a string |
| 596 | * in the string list. If the property does not exist, it returns {NULL}. |
| 597 | * |
| 598 | * The data is allocated and the caller is reponsible for freeing the return |
| 599 | * value (the list of string pointers). The strings themselves may not be |
| 600 | * changed as they point directly into the devicetree property. |
| 601 | * |
| 602 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 603 | * @property: name of the property containing the string list |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 604 | * @listp: returns an allocated, NULL-terminated list of strings if the return |
| 605 | * value is > 0, else is set to NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 606 | * Return: |
| 607 | * number of strings in list, 0 if none, -ENOMEM if out of memory, |
| 608 | * -EINVAL if no such property, -EENODATA if property is empty |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 609 | */ |
| 610 | int ofnode_read_string_list(ofnode node, const char *property, |
| 611 | const char ***listp); |
| 612 | |
| 613 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 614 | * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list |
| 615 | * |
| 616 | * This function is useful to parse lists of phandles and their arguments. |
| 617 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 618 | * errno value. |
| 619 | * |
| 620 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 621 | * pointer. |
| 622 | * |
| 623 | * Example: |
| 624 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 625 | * .. code-block:: |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 626 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 627 | * phandle1: node1 { |
| 628 | * #list-cells = <2>; |
| 629 | * }; |
| 630 | * phandle2: node2 { |
| 631 | * #list-cells = <1>; |
| 632 | * }; |
| 633 | * node3 { |
| 634 | * list = <&phandle1 1 2 &phandle2 3>; |
| 635 | * }; |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 636 | * |
| 637 | * To get a device_node of the `node2' node you may call this: |
| 638 | * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args); |
| 639 | * |
| 640 | * @node: device tree node containing a list |
| 641 | * @list_name: property name that contains a list |
| 642 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 643 | * @cell_count: Cell count to use if @cells_name is NULL |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 644 | * @index: index of a phandle to parse out |
| 645 | * @out_args: optional pointer to output arguments structure (will be filled) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 646 | * Return: |
| 647 | * 0 on success (with @out_args filled out if not NULL), -ENOENT if |
| 648 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 649 | * @cells_name could not be found, the arguments were truncated or there |
| 650 | * were too many arguments. |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 651 | */ |
| 652 | int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, |
| 653 | const char *cells_name, int cell_count, |
| 654 | int index, |
| 655 | struct ofnode_phandle_args *out_args); |
| 656 | |
| 657 | /** |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 658 | * ofnode_count_phandle_with_args() - Count number of phandle in a list |
| 659 | * |
| 660 | * This function is useful to count phandles into a list. |
| 661 | * Returns number of phandle on success, on error returns appropriate |
| 662 | * errno value. |
| 663 | * |
| 664 | * @node: device tree node containing a list |
| 665 | * @list_name: property name that contains a list |
| 666 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 667 | * @cell_count: Cell count to use if @cells_name is NULL |
| 668 | * Return: |
| 669 | * number of phandle on success, -ENOENT if @list_name does not exist, |
| 670 | * -EINVAL if a phandle was not found, @cells_name could not be found. |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 671 | */ |
| 672 | int ofnode_count_phandle_with_args(ofnode node, const char *list_name, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 673 | const char *cells_name, int cell_count); |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 674 | |
| 675 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 676 | * ofnode_path() - find a node by full path |
| 677 | * |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 678 | * This uses the control FDT. |
| 679 | * |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 680 | * @path: Full path to node, e.g. "/bus/spi@1" |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 681 | * Return: reference to the node found. Use ofnode_valid() to check if it exists |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 682 | */ |
| 683 | ofnode ofnode_path(const char *path); |
| 684 | |
| 685 | /** |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 686 | * ofnode_path_root() - find a node by full path from a root node |
| 687 | * |
| 688 | * @tree: Device tree to use |
| 689 | * @path: Full path to node, e.g. "/bus/spi@1" |
| 690 | * Return: reference to the node found. Use ofnode_valid() to check if it exists |
| 691 | */ |
| 692 | ofnode ofnode_path_root(oftree tree, const char *path); |
| 693 | |
| 694 | /** |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 695 | * ofnode_read_chosen_prop() - get the value of a chosen property |
| 696 | * |
| 697 | * This looks for a property within the /chosen node and returns its value |
| 698 | * |
| 699 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 700 | * @sizep: Returns size of property, or `FDT_ERR_...` error code if function |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 701 | * returns NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 702 | * Return: property value if found, else NULL |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 703 | */ |
| 704 | const void *ofnode_read_chosen_prop(const char *propname, int *sizep); |
| 705 | |
| 706 | /** |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 707 | * ofnode_read_chosen_string() - get the string value of a chosen property |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 708 | * |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 709 | * This looks for a property within the /chosen node and returns its value, |
| 710 | * checking that it is a valid nul-terminated string |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 711 | * |
| 712 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 713 | * Return: string value if found, else NULL |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 714 | */ |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 715 | const char *ofnode_read_chosen_string(const char *propname); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 716 | |
| 717 | /** |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 718 | * ofnode_get_chosen_node() - get a referenced node from the chosen node |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 719 | * |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 720 | * This looks up a named property in the chosen node and uses that as a path to |
| 721 | * look up a code. |
| 722 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 723 | * @propname: Property name to look for |
| 724 | * Return: the referenced node if present, else ofnode_null() |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 725 | */ |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 726 | ofnode ofnode_get_chosen_node(const char *propname); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 727 | |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 728 | /** |
| 729 | * ofnode_read_aliases_prop() - get the value of a aliases property |
| 730 | * |
| 731 | * This looks for a property within the /aliases node and returns its value |
| 732 | * |
| 733 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 734 | * @sizep: Returns size of property, or `FDT_ERR_...` error code if function |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 735 | * returns NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 736 | * Return: property value if found, else NULL |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 737 | */ |
| 738 | const void *ofnode_read_aliases_prop(const char *propname, int *sizep); |
| 739 | |
| 740 | /** |
| 741 | * ofnode_get_aliases_node() - get a referenced node from the aliases node |
| 742 | * |
| 743 | * This looks up a named property in the aliases node and uses that as a path to |
| 744 | * look up a code. |
| 745 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 746 | * @propname: Property name to look for |
| 747 | * Return: the referenced node if present, else ofnode_null() |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 748 | */ |
| 749 | ofnode ofnode_get_aliases_node(const char *propname); |
| 750 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 751 | struct display_timing; |
| 752 | /** |
| 753 | * ofnode_decode_display_timing() - decode display timings |
| 754 | * |
| 755 | * Decode display timings from the supplied 'display-timings' node. |
| 756 | * See doc/device-tree-bindings/video/display-timing.txt for binding |
| 757 | * information. |
| 758 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 759 | * @node: 'display-timing' node containing the timing subnodes |
| 760 | * @index: Index number to read (0=first timing subnode) |
| 761 | * @config: Place to put timings |
| 762 | * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 763 | */ |
| 764 | int ofnode_decode_display_timing(ofnode node, int index, |
| 765 | struct display_timing *config); |
| 766 | |
| 767 | /** |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 768 | * ofnode_get_property() - get a pointer to the value of a node property |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 769 | * |
| 770 | * @node: node to read |
| 771 | * @propname: property to read |
| 772 | * @lenp: place to put length on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 773 | * Return: pointer to property, or NULL if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 774 | */ |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 775 | const void *ofnode_get_property(ofnode node, const char *propname, int *lenp); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 776 | |
| 777 | /** |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 778 | * ofnode_get_first_property()- get the reference of the first property |
| 779 | * |
| 780 | * Get reference to the first property of the node, it is used to iterate |
| 781 | * and read all the property with ofnode_get_property_by_prop(). |
| 782 | * |
| 783 | * @node: node to read |
| 784 | * @prop: place to put argument reference |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 785 | * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 786 | */ |
| 787 | int ofnode_get_first_property(ofnode node, struct ofprop *prop); |
| 788 | |
| 789 | /** |
| 790 | * ofnode_get_next_property() - get the reference of the next property |
| 791 | * |
| 792 | * Get reference to the next property of the node, it is used to iterate |
| 793 | * and read all the property with ofnode_get_property_by_prop(). |
| 794 | * |
| 795 | * @prop: reference of current argument and place to put reference of next one |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 796 | * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 797 | */ |
| 798 | int ofnode_get_next_property(struct ofprop *prop); |
| 799 | |
| 800 | /** |
| 801 | * ofnode_get_property_by_prop() - get a pointer to the value of a property |
| 802 | * |
| 803 | * Get value for the property identified by the provided reference. |
| 804 | * |
| 805 | * @prop: reference on property |
| 806 | * @propname: If non-NULL, place to property name on success, |
| 807 | * @lenp: If non-NULL, place to put length on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 808 | * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 809 | */ |
| 810 | const void *ofnode_get_property_by_prop(const struct ofprop *prop, |
| 811 | const char **propname, int *lenp); |
| 812 | |
| 813 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 814 | * ofnode_is_available() - check if a node is marked available |
| 815 | * |
| 816 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 817 | * Return: true if node's 'status' property is "okay" (or is missing) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 818 | */ |
| 819 | bool ofnode_is_available(ofnode node); |
| 820 | |
| 821 | /** |
| 822 | * ofnode_get_addr_size() - get address and size from a property |
| 823 | * |
| 824 | * This does no address translation. It simply reads an property that contains |
| 825 | * an address and a size value, one after the other. |
| 826 | * |
| 827 | * @node: node to read from |
| 828 | * @propname: property to read |
| 829 | * @sizep: place to put size value (on success) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 830 | * Return: address value, or FDT_ADDR_T_NONE on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 831 | */ |
| 832 | phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname, |
| 833 | phys_size_t *sizep); |
| 834 | |
| 835 | /** |
| 836 | * ofnode_read_u8_array_ptr() - find an 8-bit array |
| 837 | * |
| 838 | * Look up a property in a node and return a pointer to its contents as a |
| 839 | * byte array of given length. The property must have at least enough data |
| 840 | * for the array (count bytes). It may have more, but this will be ignored. |
| 841 | * The data is not copied. |
| 842 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 843 | * @node: node to examine |
| 844 | * @propname: name of property to find |
| 845 | * @sz: number of array elements |
| 846 | * Return: |
| 847 | * pointer to byte array if found, or NULL if the property is not found or |
| 848 | * there is not enough data |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 849 | */ |
| 850 | const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname, |
| 851 | size_t sz); |
| 852 | |
| 853 | /** |
| 854 | * ofnode_read_pci_addr() - look up a PCI address |
| 855 | * |
| 856 | * Look at an address property in a node and return the PCI address which |
| 857 | * corresponds to the given type in the form of fdt_pci_addr. |
| 858 | * The property must hold one fdt_pci_addr with a lengh. |
| 859 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 860 | * @node: node to examine |
| 861 | * @type: pci address type (FDT_PCI_SPACE_xxx) |
| 862 | * @propname: name of property to find |
| 863 | * @addr: returns pci address in the form of fdt_pci_addr |
| 864 | * Return: |
| 865 | * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the |
| 866 | * format of the property was invalid, -ENXIO if the requested |
| 867 | * address type was not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 868 | */ |
| 869 | int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, |
| 870 | const char *propname, struct fdt_pci_addr *addr); |
| 871 | |
| 872 | /** |
Bin Meng | fa15771 | 2018-08-03 01:14:35 -0700 | [diff] [blame] | 873 | * ofnode_read_pci_vendev() - look up PCI vendor and device id |
| 874 | * |
| 875 | * Look at the compatible property of a device node that represents a PCI |
| 876 | * device and extract pci vendor id and device id from it. |
| 877 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 878 | * @node: node to examine |
| 879 | * @vendor: vendor id of the pci device |
| 880 | * @device: device id of the pci device |
| 881 | * Return: 0 if ok, negative on error |
Bin Meng | fa15771 | 2018-08-03 01:14:35 -0700 | [diff] [blame] | 882 | */ |
| 883 | int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device); |
| 884 | |
| 885 | /** |
Michal Simek | a253c3b | 2022-02-23 15:45:40 +0100 | [diff] [blame] | 886 | * ofnode_read_eth_phy_id() - look up eth phy vendor and device id |
| 887 | * |
| 888 | * Look at the compatible property of a device node that represents a eth phy |
| 889 | * device and extract phy vendor id and device id from it. |
| 890 | * |
Heinrich Schuchardt | c9ae4a8 | 2022-03-24 16:22:32 +0100 | [diff] [blame] | 891 | * @node: node to examine |
| 892 | * @vendor: vendor id of the eth phy device |
| 893 | * @device: device id of the eth phy device |
| 894 | * Return: 0 if ok, negative on error |
Michal Simek | a253c3b | 2022-02-23 15:45:40 +0100 | [diff] [blame] | 895 | */ |
| 896 | int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device); |
| 897 | |
| 898 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 899 | * ofnode_read_addr_cells() - Get the number of address cells for a node |
| 900 | * |
| 901 | * This walks back up the tree to find the closest #address-cells property |
| 902 | * which controls the given node. |
| 903 | * |
| 904 | * @node: Node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 905 | * Return: number of address cells this node uses |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 906 | */ |
| 907 | int ofnode_read_addr_cells(ofnode node); |
| 908 | |
| 909 | /** |
| 910 | * ofnode_read_size_cells() - Get the number of size cells for a node |
| 911 | * |
| 912 | * This walks back up the tree to find the closest #size-cells property |
| 913 | * which controls the given node. |
| 914 | * |
| 915 | * @node: Node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 916 | * Return: number of size cells this node uses |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 917 | */ |
| 918 | int ofnode_read_size_cells(ofnode node); |
| 919 | |
| 920 | /** |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 921 | * ofnode_read_simple_addr_cells() - Get the address cells property in a node |
| 922 | * |
| 923 | * This function matches fdt_address_cells(). |
| 924 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 925 | * @node: Node to check |
| 926 | * Return: value of #address-cells property in this node, or 2 if none |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 927 | */ |
| 928 | int ofnode_read_simple_addr_cells(ofnode node); |
| 929 | |
| 930 | /** |
| 931 | * ofnode_read_simple_size_cells() - Get the size cells property in a node |
| 932 | * |
| 933 | * This function matches fdt_size_cells(). |
| 934 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 935 | * @node: Node to check |
| 936 | * Return: value of #size-cells property in this node, or 2 if none |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 937 | */ |
| 938 | int ofnode_read_simple_size_cells(ofnode node); |
| 939 | |
| 940 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 941 | * ofnode_pre_reloc() - check if a node should be bound before relocation |
| 942 | * |
| 943 | * Device tree nodes can be marked as needing-to-be-bound in the loader stages |
| 944 | * via special device tree properties. |
| 945 | * |
| 946 | * Before relocation this function can be used to check if nodes are required |
| 947 | * in either SPL or TPL stages. |
| 948 | * |
| 949 | * After relocation and jumping into the real U-Boot binary it is possible to |
| 950 | * determine if a node was bound in one of SPL/TPL stages. |
| 951 | * |
Patrick Delaunay | 63e4d11 | 2019-05-21 19:19:13 +0200 | [diff] [blame] | 952 | * There are 4 settings currently in use |
| 953 | * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 954 | * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 955 | * Existing platforms only use it to indicate nodes needed in |
| 956 | * SPL. Should probably be replaced by u-boot,dm-spl for new platforms. |
Patrick Delaunay | 63e4d11 | 2019-05-21 19:19:13 +0200 | [diff] [blame] | 957 | * - u-boot,dm-spl: SPL and U-Boot pre-relocation |
| 958 | * - u-boot,dm-tpl: TPL and U-Boot pre-relocation |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 959 | * |
| 960 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 961 | * Return: true if node is needed in SPL/TL, false otherwise |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 962 | */ |
| 963 | bool ofnode_pre_reloc(ofnode node); |
| 964 | |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 965 | /** |
| 966 | * ofnode_read_resource() - Read a resource from a node |
| 967 | * |
| 968 | * Read resource information from a node at the given index |
| 969 | * |
| 970 | * @node: Node to read from |
| 971 | * @index: Index of resource to read (0 = first) |
| 972 | * @res: Returns resource that was read, on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 973 | * Return: 0 if OK, -ve on error |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 974 | */ |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 975 | int ofnode_read_resource(ofnode node, uint index, struct resource *res); |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 976 | |
| 977 | /** |
| 978 | * ofnode_read_resource_byname() - Read a resource from a node by name |
| 979 | * |
| 980 | * Read resource information from a node matching the given name. This uses a |
| 981 | * 'reg-names' string list property with the names matching the associated |
| 982 | * 'reg' property list. |
| 983 | * |
| 984 | * @node: Node to read from |
| 985 | * @name: Name of resource to read |
| 986 | * @res: Returns resource that was read, on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 987 | * Return: 0 if OK, -ve on error |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 988 | */ |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 989 | int ofnode_read_resource_byname(ofnode node, const char *name, |
| 990 | struct resource *res); |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 991 | |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 992 | /** |
Simon Glass | 954eeae | 2018-06-11 13:07:13 -0600 | [diff] [blame] | 993 | * ofnode_by_compatible() - Find the next compatible node |
| 994 | * |
| 995 | * Find the next node after @from that is compatible with @compat |
| 996 | * |
| 997 | * @from: ofnode to start from (use ofnode_null() to start at the beginning) |
| 998 | * @compat: Compatible string to match |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 999 | * Return: ofnode found, or ofnode_null() if none |
Simon Glass | 954eeae | 2018-06-11 13:07:13 -0600 | [diff] [blame] | 1000 | */ |
| 1001 | ofnode ofnode_by_compatible(ofnode from, const char *compat); |
| 1002 | |
| 1003 | /** |
Jens Wiklander | 7b68dad | 2018-08-20 11:09:58 +0200 | [diff] [blame] | 1004 | * ofnode_by_prop_value() - Find the next node with given property value |
| 1005 | * |
| 1006 | * Find the next node after @from that has a @propname with a value |
| 1007 | * @propval and a length @proplen. |
| 1008 | * |
| 1009 | * @from: ofnode to start from (use ofnode_null() to start at the |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1010 | * beginning) |
| 1011 | * @propname: property name to check |
| 1012 | * @propval: property value to search for |
| 1013 | * @proplen: length of the value in propval |
| 1014 | * Return: ofnode found, or ofnode_null() if none |
Jens Wiklander | 7b68dad | 2018-08-20 11:09:58 +0200 | [diff] [blame] | 1015 | */ |
| 1016 | ofnode ofnode_by_prop_value(ofnode from, const char *propname, |
| 1017 | const void *propval, int proplen); |
| 1018 | |
| 1019 | /** |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1020 | * ofnode_for_each_subnode() - iterate over all subnodes of a parent |
| 1021 | * |
| 1022 | * @node: child node (ofnode, lvalue) |
| 1023 | * @parent: parent node (ofnode) |
| 1024 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1025 | * This is a wrapper around a for loop and is used like so:: |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1026 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1027 | * ofnode node; |
| 1028 | * ofnode_for_each_subnode(node, parent) { |
| 1029 | * Use node |
| 1030 | * ... |
| 1031 | * } |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1032 | * |
| 1033 | * Note that this is implemented as a macro and @node is used as |
| 1034 | * iterator in the loop. The parent variable can be a constant or even a |
| 1035 | * literal. |
| 1036 | */ |
| 1037 | #define ofnode_for_each_subnode(node, parent) \ |
| 1038 | for (node = ofnode_first_subnode(parent); \ |
| 1039 | ofnode_valid(node); \ |
| 1040 | node = ofnode_next_subnode(node)) |
| 1041 | |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1042 | /** |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1043 | * ofnode_for_each_compatible_node() - iterate over all nodes with a given |
| 1044 | * compatible string |
| 1045 | * |
| 1046 | * @node: child node (ofnode, lvalue) |
| 1047 | * @compat: compatible string to match |
| 1048 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1049 | * This is a wrapper around a for loop and is used like so:: |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1050 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1051 | * ofnode node; |
| 1052 | * ofnode_for_each_compatible_node(node, parent, compatible) { |
| 1053 | * Use node |
| 1054 | * ... |
| 1055 | * } |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1056 | * |
| 1057 | * Note that this is implemented as a macro and @node is used as |
| 1058 | * iterator in the loop. |
| 1059 | */ |
| 1060 | #define ofnode_for_each_compatible_node(node, compat) \ |
| 1061 | for (node = ofnode_by_compatible(ofnode_null(), compat); \ |
| 1062 | ofnode_valid(node); \ |
| 1063 | node = ofnode_by_compatible(node, compat)) |
| 1064 | |
| 1065 | /** |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1066 | * ofnode_get_child_count() - get the child count of a ofnode |
| 1067 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1068 | * @parent: valid node to get its child count |
| 1069 | * Return: the number of subnodes |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1070 | */ |
| 1071 | int ofnode_get_child_count(ofnode parent); |
| 1072 | |
| 1073 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1074 | * ofnode_translate_address() - Translate a device-tree address |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1075 | * |
| 1076 | * Translate an address from the device-tree into a CPU physical address. This |
| 1077 | * function walks up the tree and applies the various bus mappings along the |
| 1078 | * way. |
| 1079 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1080 | * @node: Device tree node giving the context in which to translate the address |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1081 | * @in_addr: pointer to the address to translate |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1082 | * Return: the translated address; OF_BAD_ADDR on error |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1083 | */ |
| 1084 | u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr); |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1085 | |
| 1086 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1087 | * ofnode_translate_dma_address() - Translate a device-tree DMA address |
| 1088 | * |
| 1089 | * Translate a DMA address from the device-tree into a CPU physical address. |
| 1090 | * This function walks up the tree and applies the various bus mappings along |
| 1091 | * the way. |
| 1092 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1093 | * @node: Device tree node giving the context in which to translate the |
| 1094 | * DMA address |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1095 | * @in_addr: pointer to the DMA address to translate |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1096 | * Return: the translated DMA address; OF_BAD_ADDR on error |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1097 | */ |
| 1098 | u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr); |
| 1099 | |
| 1100 | /** |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1101 | * ofnode_get_dma_range() - get dma-ranges for a specific DT node |
| 1102 | * |
| 1103 | * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and |
| 1104 | * cpu->bus address translations |
| 1105 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1106 | * @node: Device tree node |
| 1107 | * @cpu: Pointer to variable storing the range's cpu address |
| 1108 | * @bus: Pointer to variable storing the range's bus address |
| 1109 | * @size: Pointer to variable storing the range's size |
| 1110 | * Return: translated DMA address or OF_BAD_ADDR on error |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1111 | */ |
| 1112 | int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, |
| 1113 | u64 *size); |
| 1114 | |
| 1115 | /** |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1116 | * ofnode_device_is_compatible() - check if the node is compatible with compat |
| 1117 | * |
| 1118 | * This allows to check whether the node is comaptible with the compat. |
| 1119 | * |
| 1120 | * @node: Device tree node for which compatible needs to be verified. |
| 1121 | * @compat: Compatible string which needs to verified in the given node. |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1122 | * Return: true if OK, false if the compatible is not found |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1123 | */ |
| 1124 | int ofnode_device_is_compatible(ofnode node, const char *compat); |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1125 | |
| 1126 | /** |
| 1127 | * ofnode_write_prop() - Set a property of a ofnode |
| 1128 | * |
| 1129 | * Note that the value passed to the function is *not* allocated by the |
Simon Glass | 1817f71 | 2022-07-30 15:52:07 -0600 | [diff] [blame] | 1130 | * function itself, but must be allocated by the caller if necessary. However |
| 1131 | * it does allocate memory for the property struct and name. |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1132 | * |
| 1133 | * @node: The node for whose property should be set |
| 1134 | * @propname: The name of the property to set |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1135 | * @value: The new value of the property (must be valid prior to calling |
| 1136 | * the function) |
Simon Glass | 5e2cd5e | 2022-07-30 15:52:10 -0600 | [diff] [blame] | 1137 | * @len: The length of the new value of the property |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1138 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1139 | */ |
Simon Glass | 5e2cd5e | 2022-07-30 15:52:10 -0600 | [diff] [blame] | 1140 | int ofnode_write_prop(ofnode node, const char *propname, const void *value, |
| 1141 | int len); |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1142 | |
| 1143 | /** |
| 1144 | * ofnode_write_string() - Set a string property of a ofnode |
| 1145 | * |
| 1146 | * Note that the value passed to the function is *not* allocated by the |
| 1147 | * function itself, but must be allocated by the caller if necessary. |
| 1148 | * |
| 1149 | * @node: The node for whose string property should be set |
| 1150 | * @propname: The name of the string property to set |
| 1151 | * @value: The new value of the string property (must be valid prior to |
| 1152 | * calling the function) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1153 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1154 | */ |
| 1155 | int ofnode_write_string(ofnode node, const char *propname, const char *value); |
| 1156 | |
| 1157 | /** |
Simon Glass | d28e31e | 2022-07-30 15:52:14 -0600 | [diff] [blame] | 1158 | * ofnode_write_u32() - Set an integer property of an ofnode |
| 1159 | * |
| 1160 | * @node: The node for whose string property should be set |
| 1161 | * @propname: The name of the string property to set |
| 1162 | * @value: The new value of the 32-bit integer property |
| 1163 | * Return: 0 if successful, -ve on error |
| 1164 | */ |
| 1165 | int ofnode_write_u32(ofnode node, const char *propname, u32 value); |
| 1166 | |
| 1167 | /** |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1168 | * ofnode_set_enabled() - Enable or disable a device tree node given by its |
| 1169 | * ofnode |
| 1170 | * |
| 1171 | * This function effectively sets the node's "status" property to either "okay" |
| 1172 | * or "disable", hence making it available for driver model initialization or |
| 1173 | * not. |
| 1174 | * |
| 1175 | * @node: The node to enable |
| 1176 | * @value: Flag that tells the function to either disable or enable the |
| 1177 | * node |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1178 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1179 | */ |
| 1180 | int ofnode_set_enabled(ofnode node, bool value); |
| 1181 | |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1182 | /** |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1183 | * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link) |
| 1184 | * |
| 1185 | * This function parses PHY handle from the Ethernet controller's ofnode |
| 1186 | * (trying all possible PHY handle property names), and returns the PHY ofnode. |
| 1187 | * |
| 1188 | * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and |
| 1189 | * if the result to that is true, this function should not be called. |
| 1190 | * |
| 1191 | * @eth_node: ofnode belonging to the Ethernet controller |
| 1192 | * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode |
| 1193 | */ |
| 1194 | ofnode ofnode_get_phy_node(ofnode eth_node); |
| 1195 | |
| 1196 | /** |
| 1197 | * ofnode_read_phy_mode() - Read PHY connection type from a MAC node |
| 1198 | * |
| 1199 | * This function parses the "phy-mode" / "phy-connection-type" property and |
| 1200 | * returns the corresponding PHY interface type. |
| 1201 | * |
| 1202 | * @mac_node: ofnode containing the property |
| 1203 | * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on |
| 1204 | * error |
| 1205 | */ |
| 1206 | phy_interface_t ofnode_read_phy_mode(ofnode mac_node); |
| 1207 | |
| 1208 | #if CONFIG_IS_ENABLED(DM) |
| 1209 | /** |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1210 | * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config |
| 1211 | * |
| 1212 | * This reads a property from the /config node of the devicetree. |
| 1213 | * |
| 1214 | * See doc/config.txt for bindings |
| 1215 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1216 | * @prop_name: property name to look up |
| 1217 | * Return: true, if it exists, false if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1218 | */ |
| 1219 | bool ofnode_conf_read_bool(const char *prop_name); |
| 1220 | |
| 1221 | /** |
| 1222 | * ofnode_conf_read_int() - Read an integer value from the U-Boot config |
| 1223 | * |
| 1224 | * This reads a property from the /config node of the devicetree. |
| 1225 | * |
| 1226 | * See doc/config.txt for bindings |
| 1227 | * |
| 1228 | * @prop_name: property name to look up |
| 1229 | * @default_val: default value to return if the property is not found |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1230 | * Return: integer value, if found, or @default_val if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1231 | */ |
| 1232 | int ofnode_conf_read_int(const char *prop_name, int default_val); |
| 1233 | |
| 1234 | /** |
| 1235 | * ofnode_conf_read_str() - Read a string value from the U-Boot config |
| 1236 | * |
| 1237 | * This reads a property from the /config node of the devicetree. |
| 1238 | * |
| 1239 | * See doc/config.txt for bindings |
| 1240 | * |
| 1241 | * @prop_name: property name to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1242 | * Return: string value, if found, or NULL if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1243 | */ |
| 1244 | const char *ofnode_conf_read_str(const char *prop_name); |
| 1245 | |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1246 | #else /* CONFIG_DM */ |
| 1247 | static inline bool ofnode_conf_read_bool(const char *prop_name) |
| 1248 | { |
| 1249 | return false; |
| 1250 | } |
Marek Behún | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 1251 | |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1252 | static inline int ofnode_conf_read_int(const char *prop_name, int default_val) |
| 1253 | { |
| 1254 | return default_val; |
| 1255 | } |
| 1256 | |
| 1257 | static inline const char *ofnode_conf_read_str(const char *prop_name) |
| 1258 | { |
| 1259 | return NULL; |
| 1260 | } |
| 1261 | #endif /* CONFIG_DM */ |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1262 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 1263 | #endif |