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 | ebbe90b | 2023-09-26 08:14:43 -0600 | [diff] [blame] | 20 | struct abuf; |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 21 | struct resource; |
| 22 | |
Simon Glass | 9693c1d | 2022-07-30 15:52:06 -0600 | [diff] [blame] | 23 | #include <dm/ofnode_decl.h> |
Michal Simek | 43c42bd | 2023-08-31 08:59:05 +0200 | [diff] [blame] | 24 | #include <linux/errno.h> |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 25 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 26 | struct ofnode_phandle_args { |
| 27 | ofnode node; |
| 28 | int args_count; |
| 29 | uint32_t args[OF_MAX_PHANDLE_ARGS]; |
| 30 | }; |
| 31 | |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 32 | #if CONFIG_IS_ENABLED(OFNODE_MULTI_TREE) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 33 | /** |
Simon Glass | ba8457b | 2022-09-06 20:27:19 -0600 | [diff] [blame] | 34 | * oftree_reset() - reset the state of the oftree list |
| 35 | * |
| 36 | * Reset the oftree list so it can be started again. This should be called |
| 37 | * once the control FDT is in place, but before the ofnode interface is used. |
| 38 | */ |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 39 | void oftree_reset(void); |
Simon Glass | ba8457b | 2022-09-06 20:27:19 -0600 | [diff] [blame] | 40 | |
| 41 | /** |
Simon Glass | 04fa09a | 2022-09-06 20:27:20 -0600 | [diff] [blame] | 42 | * ofnode_to_fdt() - convert an ofnode to a flat DT pointer |
| 43 | * |
| 44 | * This cannot be called if the reference contains a node pointer. |
| 45 | * |
| 46 | * @node: Reference containing offset (possibly invalid) |
| 47 | * Return: DT offset (can be NULL) |
| 48 | */ |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 49 | __attribute_const__ void *ofnode_to_fdt(ofnode node); |
| 50 | |
| 51 | /** |
| 52 | * ofnode_to_offset() - convert an ofnode to a flat DT offset |
| 53 | * |
| 54 | * This cannot be called if the reference contains a node pointer. |
| 55 | * |
| 56 | * @node: Reference containing offset (possibly invalid) |
| 57 | * Return: DT offset (can be -1) |
| 58 | */ |
| 59 | __attribute_const__ int ofnode_to_offset(ofnode node); |
| 60 | |
| 61 | /** |
| 62 | * oftree_from_fdt() - Returns an oftree from a flat device tree pointer |
| 63 | * |
Simon Glass | e6a211c | 2022-10-11 09:47:19 -0600 | [diff] [blame] | 64 | * If @fdt is not already registered in the list of current device trees, it is |
| 65 | * added to the list. |
| 66 | * |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 67 | * @fdt: Device tree to use |
| 68 | * |
| 69 | * Returns: reference to the given node |
| 70 | */ |
| 71 | oftree oftree_from_fdt(void *fdt); |
| 72 | |
| 73 | /** |
| 74 | * noffset_to_ofnode() - convert a DT offset to an ofnode |
| 75 | * |
| 76 | * @other_node: Node in the same tree to use as a reference |
| 77 | * @of_offset: DT offset (either valid, or -1) |
| 78 | * Return: reference to the associated DT offset |
| 79 | */ |
| 80 | ofnode noffset_to_ofnode(ofnode other_node, int of_offset); |
| 81 | |
| 82 | #else /* !OFNODE_MULTI_TREE */ |
| 83 | static inline void oftree_reset(void) {} |
| 84 | |
Simon Glass | 04fa09a | 2022-09-06 20:27:20 -0600 | [diff] [blame] | 85 | static inline void *ofnode_to_fdt(ofnode node) |
| 86 | { |
| 87 | #ifdef OF_CHECKS |
| 88 | if (of_live_active()) |
| 89 | return NULL; |
| 90 | #endif |
Simon Glass | 04fa09a | 2022-09-06 20:27:20 -0600 | [diff] [blame] | 91 | /* Use the control FDT by default */ |
| 92 | return (void *)gd->fdt_blob; |
| 93 | } |
| 94 | |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 95 | static inline __attribute_const__ int ofnode_to_offset(ofnode node) |
Simon Glass | 37dcd91 | 2022-09-06 20:27:23 -0600 | [diff] [blame] | 96 | { |
| 97 | #ifdef OF_CHECKS |
| 98 | if (of_live_active()) |
| 99 | return -1; |
| 100 | #endif |
| 101 | return node.of_offset; |
| 102 | } |
| 103 | |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 104 | static inline oftree oftree_from_fdt(void *fdt) |
| 105 | { |
| 106 | oftree tree; |
| 107 | |
| 108 | /* we cannot access other trees without OFNODE_MULTI_TREE */ |
| 109 | if (fdt == gd->fdt_blob) |
| 110 | tree.fdt = fdt; |
| 111 | else |
| 112 | tree.fdt = NULL; |
| 113 | |
| 114 | return tree; |
| 115 | } |
| 116 | |
| 117 | static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset) |
| 118 | { |
| 119 | ofnode node; |
| 120 | |
| 121 | if (of_live_active()) |
| 122 | node.np = NULL; |
| 123 | else |
| 124 | node.of_offset = of_offset; |
| 125 | |
| 126 | return node; |
| 127 | } |
| 128 | |
| 129 | #endif /* OFNODE_MULTI_TREE */ |
| 130 | |
Simon Glass | 37dcd91 | 2022-09-06 20:27:23 -0600 | [diff] [blame] | 131 | /** |
Simon Glass | a869a1b | 2023-09-26 08:14:40 -0600 | [diff] [blame] | 132 | * oftree_new() - Create a new, empty tree |
| 133 | * |
| 134 | * @treep: Returns a pointer to the tree, on success |
| 135 | * Returns: 0 on success, -ENOMEM if out of memory, -E2BIG if !OF_LIVE and |
| 136 | * there are too many (flattrees) already |
| 137 | */ |
| 138 | int oftree_new(oftree *treep); |
| 139 | |
| 140 | /** |
Simon Glass | ebbe90b | 2023-09-26 08:14:43 -0600 | [diff] [blame] | 141 | * oftree_to_fdt() - Convert an oftree to a flat FDT |
| 142 | * |
| 143 | * @tree: tree to flatten (if livetree) or copy (if not) |
| 144 | * @buf: Returns inited buffer containing the newly created flat tree. Note |
| 145 | * that for flat tree the buffer is not allocated. In either case the caller |
| 146 | * must call abut_uninit() to free any memory used by @buf |
| 147 | * Return: 0 on success, -ENOMEM if out of memory, other -ve value for any other |
| 148 | * error |
| 149 | */ |
| 150 | int oftree_to_fdt(oftree tree, struct abuf *buf); |
| 151 | |
| 152 | /** |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 153 | * ofnode_to_np() - convert an ofnode to a live DT node pointer |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 154 | * |
| 155 | * This cannot be called if the reference contains an offset. |
| 156 | * |
| 157 | * @node: Reference containing struct device_node * (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 158 | * Return: pointer to device node (can be NULL) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 159 | */ |
Simon Glass | 9036c5c | 2022-09-06 20:27:04 -0600 | [diff] [blame] | 160 | static inline struct device_node *ofnode_to_np(ofnode node) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 161 | { |
| 162 | #ifdef OF_CHECKS |
| 163 | if (!of_live_active()) |
| 164 | return NULL; |
| 165 | #endif |
| 166 | return node.np; |
| 167 | } |
| 168 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 169 | /** |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 170 | * ofnode_valid() - check if an ofnode is valid |
| 171 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 172 | * @node: Reference containing offset (possibly invalid) |
Simon Glass | cb13a1b | 2022-09-06 20:27:26 -0600 | [diff] [blame] | 173 | * Return: true if the reference contains a valid ofnode, false if not |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 174 | */ |
| 175 | static inline bool ofnode_valid(ofnode node) |
| 176 | { |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 177 | if (of_live_active()) |
| 178 | return node.np != NULL; |
| 179 | else |
Patrick Delaunay | 04fcfe7 | 2020-09-24 17:26:20 +0200 | [diff] [blame] | 180 | return node.of_offset >= 0; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
Simon Glass | 95fd209 | 2022-09-06 20:27:22 -0600 | [diff] [blame] | 184 | * oftree_lookup_fdt() - obtain the FDT pointer from an oftree |
| 185 | * |
| 186 | * This can only be called when flat tree is enabled |
| 187 | * |
| 188 | * @tree: Tree to look at |
| 189 | * @return FDT pointer from the tree |
| 190 | */ |
| 191 | static inline void *oftree_lookup_fdt(oftree tree) |
| 192 | { |
| 193 | if (of_live_active()) |
| 194 | return NULL; |
| 195 | else |
| 196 | return tree.fdt; |
| 197 | } |
| 198 | |
| 199 | /** |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 200 | * offset_to_ofnode() - convert a DT offset to an ofnode |
| 201 | * |
| 202 | * @of_offset: DT offset (either valid, or -1) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 203 | * Return: reference to the associated DT offset |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 204 | */ |
| 205 | static inline ofnode offset_to_ofnode(int of_offset) |
| 206 | { |
| 207 | ofnode node; |
| 208 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 209 | if (of_live_active()) |
| 210 | node.np = NULL; |
| 211 | else |
Simon Glass | 1ab8b89 | 2019-12-06 21:41:36 -0700 | [diff] [blame] | 212 | node.of_offset = of_offset >= 0 ? of_offset : -1; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 213 | |
| 214 | return node; |
| 215 | } |
| 216 | |
| 217 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 218 | * np_to_ofnode() - convert a node pointer to an ofnode |
| 219 | * |
| 220 | * @np: Live node pointer (can be NULL) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 221 | * Return: reference to the associated node pointer |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 222 | */ |
Simon Glass | 9036c5c | 2022-09-06 20:27:04 -0600 | [diff] [blame] | 223 | static inline ofnode np_to_ofnode(struct device_node *np) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 224 | { |
| 225 | ofnode node; |
| 226 | |
| 227 | node.np = np; |
| 228 | |
| 229 | return node; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * ofnode_is_np() - check if a reference is a node pointer |
| 234 | * |
| 235 | * This function associated that if there is a valid live tree then all |
| 236 | * references will use it. This is because using the flat DT when the live tree |
| 237 | * is valid is not permitted. |
| 238 | * |
| 239 | * @node: reference to check (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 240 | * 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] | 241 | * offset |
| 242 | */ |
| 243 | static inline bool ofnode_is_np(ofnode node) |
| 244 | { |
| 245 | #ifdef OF_CHECKS |
| 246 | /* |
| 247 | * Check our assumption that flat tree offsets are not used when a |
| 248 | * live tree is in use. |
| 249 | */ |
| 250 | assert(!ofnode_valid(node) || |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 251 | (of_live_active() ? ofnode_to_np(node) |
| 252 | : ofnode_to_np(node))); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 253 | #endif |
| 254 | return of_live_active() && ofnode_valid(node); |
| 255 | } |
| 256 | |
| 257 | /** |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 258 | * ofnode_equal() - check if two references are equal |
| 259 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 260 | * @ref1: first reference to check (possibly invalid) |
| 261 | * @ref2: second reference to check (possibly invalid) |
| 262 | * Return: true if equal, else false |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 263 | */ |
| 264 | static inline bool ofnode_equal(ofnode ref1, ofnode ref2) |
| 265 | { |
| 266 | /* We only need to compare the contents */ |
| 267 | return ref1.of_offset == ref2.of_offset; |
| 268 | } |
| 269 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 270 | /** |
Simon Glass | 2b9b1458 | 2022-09-06 20:27:21 -0600 | [diff] [blame] | 271 | * oftree_valid() - check if an oftree is valid |
| 272 | * |
| 273 | * @tree: Reference containing oftree |
| 274 | * Return: true if the reference contains a valid oftree, false if node |
| 275 | */ |
| 276 | static inline bool oftree_valid(oftree tree) |
| 277 | { |
| 278 | if (of_live_active()) |
| 279 | return tree.np; |
| 280 | else |
| 281 | return tree.fdt; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * oftree_null() - Obtain a null oftree |
| 286 | * |
| 287 | * This returns an oftree which points to no tree. It works both with the flat |
| 288 | * tree and livetree. |
| 289 | */ |
| 290 | static inline oftree oftree_null(void) |
| 291 | { |
| 292 | oftree tree; |
| 293 | |
| 294 | if (of_live_active()) |
| 295 | tree.np = NULL; |
| 296 | else |
| 297 | tree.fdt = NULL; |
| 298 | |
| 299 | return tree; |
| 300 | } |
| 301 | |
| 302 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 303 | * ofnode_null() - Obtain a null ofnode |
| 304 | * |
| 305 | * This returns an ofnode which points to no node. It works both with the flat |
| 306 | * tree and livetree. |
| 307 | */ |
| 308 | static inline ofnode ofnode_null(void) |
| 309 | { |
| 310 | ofnode node; |
| 311 | |
| 312 | if (of_live_active()) |
| 313 | node.np = NULL; |
| 314 | else |
| 315 | node.of_offset = -1; |
| 316 | |
| 317 | return node; |
| 318 | } |
| 319 | |
Simon Glass | 278ddba | 2020-11-28 17:50:07 -0700 | [diff] [blame] | 320 | static inline ofnode ofnode_root(void) |
| 321 | { |
| 322 | ofnode node; |
| 323 | |
| 324 | if (of_live_active()) |
| 325 | node.np = gd_of_root(); |
| 326 | else |
| 327 | node.of_offset = 0; |
| 328 | |
| 329 | return node; |
| 330 | } |
| 331 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 332 | /** |
Simon Glass | 4caa79a | 2022-09-06 20:27:16 -0600 | [diff] [blame] | 333 | * ofprop_valid() - check if an ofprop is valid |
| 334 | * |
| 335 | * @prop: Pointer to ofprop to check |
| 336 | * Return: true if the reference contains a valid ofprop, false if not |
| 337 | */ |
| 338 | static inline bool ofprop_valid(struct ofprop *prop) |
| 339 | { |
| 340 | if (of_live_active()) |
| 341 | return prop->prop; |
| 342 | else |
| 343 | return prop->offset >= 0; |
| 344 | } |
| 345 | |
| 346 | /** |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 347 | * oftree_default() - Returns the default device tree (U-Boot's control FDT) |
| 348 | * |
| 349 | * Returns: reference to the control FDT |
| 350 | */ |
| 351 | static inline oftree oftree_default(void) |
| 352 | { |
| 353 | oftree tree; |
| 354 | |
| 355 | if (of_live_active()) |
| 356 | tree.np = gd_of_root(); |
| 357 | else |
| 358 | tree.fdt = (void *)gd->fdt_blob; |
| 359 | |
| 360 | return tree; |
| 361 | } |
| 362 | |
| 363 | /** |
Simon Glass | 2b9b1458 | 2022-09-06 20:27:21 -0600 | [diff] [blame] | 364 | * oftree_from_np() - Returns an oftree from a node pointer |
| 365 | * |
| 366 | * @root: Root node of the tree |
| 367 | * Returns: reference to the given node |
| 368 | */ |
| 369 | static inline oftree oftree_from_np(struct device_node *root) |
| 370 | { |
| 371 | oftree tree; |
| 372 | |
| 373 | tree.np = root; |
| 374 | |
| 375 | return tree; |
| 376 | } |
| 377 | |
| 378 | /** |
Simon Glass | 722281b | 2023-06-01 10:22:42 -0600 | [diff] [blame] | 379 | * oftree_dispose() - Dispose of an oftree |
| 380 | * |
| 381 | * This can be used to dispose of a tree that has been created (other than |
| 382 | * the control FDT which must not be disposed) |
| 383 | * |
| 384 | * @tree: Tree to dispose |
| 385 | */ |
| 386 | void oftree_dispose(oftree tree); |
| 387 | |
| 388 | /** |
Simon Glass | 6dc1eb3 | 2025-01-10 17:00:27 -0700 | [diff] [blame] | 389 | * ofnode_name_eq() - Check a node name ignoring its unit address |
Kishon Vijay Abraham I | d6388f2 | 2021-07-21 21:28:30 +0530 | [diff] [blame] | 390 | * |
Simon Glass | 6dc1eb3 | 2025-01-10 17:00:27 -0700 | [diff] [blame] | 391 | * @node: valid node to compared, which may have a unit address |
| 392 | * @name: name (without unit address) to compare with the node name |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 393 | * Return: true if matches, false if it doesn't match |
Kishon Vijay Abraham I | d6388f2 | 2021-07-21 21:28:30 +0530 | [diff] [blame] | 394 | */ |
| 395 | bool ofnode_name_eq(ofnode node, const char *name); |
| 396 | |
| 397 | /** |
Simon Glass | 9d300ce | 2025-01-10 17:00:28 -0700 | [diff] [blame] | 398 | * ofnode_name_eq_unit() - Check a node name ignoring its unit address |
| 399 | * |
| 400 | * This is separate from ofnode_name_eq() to avoid code-size increase for |
| 401 | * boards which don't need this function |
| 402 | * |
| 403 | * @node: valid node to compared, which may have a unit address |
| 404 | * @name: name to compare with the node name. If this contains a unit |
| 405 | * address, it is matched, otherwise the unit address is ignored |
| 406 | * when searching for matches |
| 407 | * Return: true if matches, false if it doesn't match |
| 408 | */ |
| 409 | bool ofnode_name_eq_unit(ofnode node, const char *name); |
| 410 | |
| 411 | /** |
Stefan Herbrechtsmeier | 1b090e6 | 2022-06-14 15:21:30 +0200 | [diff] [blame] | 412 | * ofnode_read_u8() - Read a 8-bit integer from a property |
| 413 | * |
| 414 | * @node: valid node reference to read property from |
| 415 | * @propname: name of the property to read from |
| 416 | * @outp: place to put value (if found) |
| 417 | * Return: 0 if OK, -ve on error |
| 418 | */ |
| 419 | int ofnode_read_u8(ofnode node, const char *propname, u8 *outp); |
| 420 | |
| 421 | /** |
| 422 | * ofnode_read_u8_default() - Read a 8-bit integer from a property |
| 423 | * |
| 424 | * @node: valid node reference to read property from |
| 425 | * @propname: name of the property to read from |
| 426 | * @def: default value to return if the property has no value |
| 427 | * Return: property value, or @def if not found |
| 428 | */ |
| 429 | u8 ofnode_read_u8_default(ofnode node, const char *propname, u8 def); |
| 430 | |
| 431 | /** |
| 432 | * ofnode_read_u16() - Read a 16-bit integer from a property |
| 433 | * |
| 434 | * @node: valid node reference to read property from |
| 435 | * @propname: name of the property to read from |
| 436 | * @outp: place to put value (if found) |
| 437 | * Return: 0 if OK, -ve on error |
| 438 | */ |
| 439 | int ofnode_read_u16(ofnode node, const char *propname, u16 *outp); |
| 440 | |
| 441 | /** |
| 442 | * ofnode_read_u16_default() - Read a 16-bit integer from a property |
| 443 | * |
| 444 | * @node: valid node reference to read property from |
| 445 | * @propname: name of the property to read from |
| 446 | * @def: default value to return if the property has no value |
| 447 | * Return: property value, or @def if not found |
| 448 | */ |
| 449 | u16 ofnode_read_u16_default(ofnode node, const char *propname, u16 def); |
| 450 | |
| 451 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 452 | * ofnode_read_u32() - Read a 32-bit integer from a property |
| 453 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 454 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 455 | * @propname: name of the property to read from |
| 456 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 457 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 458 | */ |
| 459 | int ofnode_read_u32(ofnode node, const char *propname, u32 *outp); |
| 460 | |
| 461 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 462 | * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property |
| 463 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 464 | * @node: valid node reference to read property from |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 465 | * @propname: name of the property to read from |
| 466 | * @index: index of the integer to return |
| 467 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 468 | * Return: 0 if OK, -ve on error |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 469 | */ |
| 470 | int ofnode_read_u32_index(ofnode node, const char *propname, int index, |
| 471 | u32 *outp); |
| 472 | |
| 473 | /** |
Michal Simek | 08a194e | 2023-08-25 11:37:46 +0200 | [diff] [blame] | 474 | * ofnode_read_u64_index() - Read a 64-bit integer from a multi-value property |
| 475 | * |
| 476 | * @node: valid node reference to read property from |
| 477 | * @propname: name of the property to read from |
| 478 | * @index: index of the integer to return |
| 479 | * @outp: place to put value (if found) |
| 480 | * Return: 0 if OK, -ve on error |
| 481 | */ |
| 482 | int ofnode_read_u64_index(ofnode node, const char *propname, int index, |
| 483 | u64 *outp); |
| 484 | |
| 485 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 486 | * ofnode_read_s32() - Read a 32-bit integer from a property |
| 487 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 488 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 489 | * @propname: name of the property to read from |
| 490 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 491 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 492 | */ |
| 493 | static inline int ofnode_read_s32(ofnode node, const char *propname, |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 494 | s32 *outp) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 495 | { |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 496 | return ofnode_read_u32(node, propname, (u32 *)outp); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /** |
| 500 | * ofnode_read_u32_default() - Read a 32-bit integer from a property |
| 501 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 502 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 503 | * @propname: name of the property to read from |
| 504 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 505 | * Return: property value, or @def if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 506 | */ |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 507 | u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 508 | |
| 509 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 510 | * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value |
| 511 | * property |
| 512 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 513 | * @node: valid node reference to read property from |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 514 | * @propname: name of the property to read from |
| 515 | * @index: index of the integer to return |
| 516 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 517 | * Return: property value, or @def if not found |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 518 | */ |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 519 | 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] | 520 | u32 def); |
| 521 | |
| 522 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 523 | * ofnode_read_s32_default() - Read a 32-bit integer from a property |
| 524 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 525 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 526 | * @propname: name of the property to read from |
| 527 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 528 | * Return: property value, or @def if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 529 | */ |
| 530 | int ofnode_read_s32_default(ofnode node, const char *propname, s32 def); |
| 531 | |
| 532 | /** |
Lukas Auer | b03a60b | 2018-11-22 11:26:35 +0100 | [diff] [blame] | 533 | * ofnode_read_u64() - Read a 64-bit integer from a property |
| 534 | * |
| 535 | * @node: valid node reference to read property from |
| 536 | * @propname: name of the property to read from |
| 537 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 538 | * Return: 0 if OK, -ve on error |
Lukas Auer | b03a60b | 2018-11-22 11:26:35 +0100 | [diff] [blame] | 539 | */ |
| 540 | int ofnode_read_u64(ofnode node, const char *propname, u64 *outp); |
| 541 | |
| 542 | /** |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 543 | * ofnode_read_u64_default() - Read a 64-bit integer from a property |
| 544 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 545 | * @node: valid node reference to read property from |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 546 | * @propname: name of the property to read from |
| 547 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 548 | * Return: property value, or @def if not found |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 549 | */ |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 550 | u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def); |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 551 | |
| 552 | /** |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 553 | * ofnode_read_prop() - Read a property from a node |
| 554 | * |
| 555 | * @node: valid node reference to read property from |
| 556 | * @propname: name of the property to read |
| 557 | * @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] | 558 | * if not found |
| 559 | * Return: property value, or NULL if there is no such property |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 560 | */ |
| 561 | const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep); |
| 562 | |
| 563 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 564 | * ofnode_read_string() - Read a string from a property |
| 565 | * |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 566 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 567 | * @propname: name of the property to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 568 | * 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] | 569 | */ |
| 570 | const char *ofnode_read_string(ofnode node, const char *propname); |
| 571 | |
| 572 | /** |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 573 | * 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] | 574 | * |
| 575 | * @node: valid node reference to read property from |
| 576 | * @propname: name of the property to read |
| 577 | * @out_values: pointer to return value, modified only if return value is 0 |
| 578 | * @sz: number of array elements to read |
Simon Glass | e3be5fc | 2022-09-06 20:27:18 -0600 | [diff] [blame] | 579 | * Return: 0 on success, -EINVAL if the property does not exist, |
| 580 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 581 | * property data isn't large enough |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 582 | * |
| 583 | * Search for a property in a device node and read 32-bit value(s) from |
Simon Glass | e3be5fc | 2022-09-06 20:27:18 -0600 | [diff] [blame] | 584 | * it. |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 585 | * |
| 586 | * The out_values is modified only if a valid u32 value can be decoded. |
| 587 | */ |
| 588 | int ofnode_read_u32_array(ofnode node, const char *propname, |
| 589 | u32 *out_values, size_t sz); |
| 590 | |
| 591 | /** |
| 592 | * ofnode_read_bool() - read a boolean value from a property |
| 593 | * |
| 594 | * @node: valid node reference to read property from |
| 595 | * @propname: name of property to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 596 | * Return: true if property is present (meaning true), false if not present |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 597 | */ |
| 598 | bool ofnode_read_bool(ofnode node, const char *propname); |
| 599 | |
| 600 | /** |
| 601 | * ofnode_find_subnode() - find a named subnode of a parent node |
| 602 | * |
| 603 | * @node: valid reference to parent node |
| 604 | * @subnode_name: name of subnode to find |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 605 | * 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] | 606 | * subnode) |
| 607 | */ |
| 608 | ofnode ofnode_find_subnode(ofnode node, const char *subnode_name); |
| 609 | |
Simon Glass | 4afa191 | 2025-01-10 17:00:29 -0700 | [diff] [blame^] | 610 | /** |
| 611 | * ofnode_find_subnode_unit() - find a named subnode of a parent node |
| 612 | * |
| 613 | * @node: valid reference to parent node |
| 614 | * @subnode_name: name of subnode to find, including any unit address. If the |
| 615 | * unit address is omitted, any subnode which matches the name (excluding |
| 616 | * any unit address) is returned |
| 617 | * Return: reference to subnode (which can be invalid if there is no such |
| 618 | * subnode) |
| 619 | */ |
| 620 | ofnode ofnode_find_subnode_unit(ofnode node, const char *subnode_name); |
| 621 | |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 622 | #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE) |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 623 | #include <asm/global_data.h> |
| 624 | |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 625 | static inline bool ofnode_is_enabled(ofnode node) |
| 626 | { |
| 627 | if (ofnode_is_np(node)) { |
| 628 | return of_device_is_available(ofnode_to_np(node)); |
| 629 | } else { |
| 630 | return fdtdec_get_is_enabled(gd->fdt_blob, |
| 631 | ofnode_to_offset(node)); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | static inline ofnode ofnode_first_subnode(ofnode node) |
| 636 | { |
| 637 | assert(ofnode_valid(node)); |
| 638 | if (ofnode_is_np(node)) |
| 639 | return np_to_ofnode(node.np->child); |
| 640 | |
| 641 | return offset_to_ofnode( |
| 642 | fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node))); |
| 643 | } |
| 644 | |
| 645 | static inline ofnode ofnode_next_subnode(ofnode node) |
| 646 | { |
| 647 | assert(ofnode_valid(node)); |
| 648 | if (ofnode_is_np(node)) |
| 649 | return np_to_ofnode(node.np->sibling); |
| 650 | |
| 651 | return offset_to_ofnode( |
| 652 | fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node))); |
| 653 | } |
| 654 | #else |
| 655 | /** |
| 656 | * ofnode_is_enabled() - Checks whether a node is enabled. |
| 657 | * This looks for a 'status' property. If this exists, then returns true if |
| 658 | * the status is 'okay' and false otherwise. If there is no status property, |
| 659 | * it returns true on the assumption that anything mentioned should be enabled |
| 660 | * by default. |
| 661 | * |
| 662 | * @node: node to examine |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 663 | * Return: false (not enabled) or true (enabled) |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 664 | */ |
| 665 | bool ofnode_is_enabled(ofnode node); |
| 666 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 667 | /** |
| 668 | * ofnode_first_subnode() - find the first subnode of a parent node |
| 669 | * |
| 670 | * @node: valid reference to a valid parent node |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 671 | * 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] | 672 | * node has no subnodes) |
| 673 | */ |
| 674 | ofnode ofnode_first_subnode(ofnode node); |
| 675 | |
| 676 | /** |
| 677 | * ofnode_next_subnode() - find the next sibling of a subnode |
| 678 | * |
| 679 | * @node: valid reference to previous node (sibling) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 680 | * 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] | 681 | * has no more siblings) |
| 682 | */ |
| 683 | ofnode ofnode_next_subnode(ofnode node); |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 684 | #endif /* DM_INLINE_OFNODE */ |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 685 | |
| 686 | /** |
Philipp Tomsich | 6fce1dd | 2018-02-23 17:38:49 +0100 | [diff] [blame] | 687 | * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode) |
| 688 | * |
| 689 | * @node: valid node to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 690 | * Return: ofnode reference of the parent node |
Philipp Tomsich | 6fce1dd | 2018-02-23 17:38:49 +0100 | [diff] [blame] | 691 | */ |
| 692 | ofnode ofnode_get_parent(ofnode node); |
| 693 | |
| 694 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 695 | * ofnode_get_name() - get the name of a node |
| 696 | * |
| 697 | * @node: valid node to look up |
Simon Glass | 91d89a8 | 2022-09-06 20:27:15 -0600 | [diff] [blame] | 698 | * Return: name of node (for the root node this is "") |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 699 | */ |
| 700 | const char *ofnode_get_name(ofnode node); |
| 701 | |
| 702 | /** |
Marek Behún | e897e3c | 2021-05-26 14:08:18 +0200 | [diff] [blame] | 703 | * ofnode_get_path() - get the full path of a node |
| 704 | * |
| 705 | * @node: valid node to look up |
| 706 | * @buf: buffer to write the node path into |
| 707 | * @buflen: buffer size |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 708 | * Return: 0 if OK, -ve on error |
Marek Behún | e897e3c | 2021-05-26 14:08:18 +0200 | [diff] [blame] | 709 | */ |
| 710 | int ofnode_get_path(ofnode node, char *buf, int buflen); |
| 711 | |
| 712 | /** |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 713 | * ofnode_get_by_phandle() - get ofnode from phandle |
| 714 | * |
Simon Glass | 176dd43 | 2022-09-06 20:26:57 -0600 | [diff] [blame] | 715 | * This uses the default (control) device tree |
| 716 | * |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 717 | * @phandle: phandle to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 718 | * Return: ofnode reference to the phandle |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 719 | */ |
| 720 | ofnode ofnode_get_by_phandle(uint phandle); |
| 721 | |
| 722 | /** |
Simon Glass | 95fd209 | 2022-09-06 20:27:22 -0600 | [diff] [blame] | 723 | * oftree_get_by_phandle() - get ofnode from phandle |
| 724 | * |
| 725 | * @tree: tree to use |
| 726 | * @phandle: phandle to look up |
| 727 | * Return: ofnode reference to the phandle |
| 728 | */ |
| 729 | ofnode oftree_get_by_phandle(oftree tree, uint phandle); |
| 730 | |
| 731 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 732 | * ofnode_read_size() - read the size of a property |
| 733 | * |
| 734 | * @node: node to check |
| 735 | * @propname: property to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 736 | * Return: size of property if present, or -EINVAL if not |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 737 | */ |
| 738 | int ofnode_read_size(ofnode node, const char *propname); |
| 739 | |
| 740 | /** |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 741 | * ofnode_get_addr_size_index() - get an address/size from a node |
| 742 | * based on index |
| 743 | * |
| 744 | * This reads the register address/size from a node based on index |
| 745 | * |
| 746 | * @node: node to read from |
| 747 | * @index: Index of address to read (0 for first) |
| 748 | * @size: Pointer to size of the address |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 749 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 750 | */ |
Johan Jonker | 9f6971f | 2023-03-13 01:30:33 +0100 | [diff] [blame] | 751 | fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, |
| 752 | fdt_size_t *size); |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 753 | |
| 754 | /** |
Marek Behún | 177ab7f | 2021-05-26 14:08:17 +0200 | [diff] [blame] | 755 | * ofnode_get_addr_size_index_notrans() - get an address/size from a node |
| 756 | * based on index, without address |
| 757 | * translation |
| 758 | * |
| 759 | * This reads the register address/size from a node based on index. |
| 760 | * The resulting address is not translated. Useful for example for on-disk |
| 761 | * addresses. |
| 762 | * |
| 763 | * @node: node to read from |
| 764 | * @index: Index of address to read (0 for first) |
| 765 | * @size: Pointer to size of the address |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 766 | * 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] | 767 | */ |
Johan Jonker | 9f6971f | 2023-03-13 01:30:33 +0100 | [diff] [blame] | 768 | fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index, |
| 769 | fdt_size_t *size); |
Marek Behún | 177ab7f | 2021-05-26 14:08:17 +0200 | [diff] [blame] | 770 | |
| 771 | /** |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 772 | * ofnode_get_addr_index() - get an address from a node |
| 773 | * |
| 774 | * This reads the register address from a node |
| 775 | * |
| 776 | * @node: node to read from |
| 777 | * @index: Index of address to read (0 for first) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 778 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 779 | */ |
Johan Jonker | 9f6971f | 2023-03-13 01:30:33 +0100 | [diff] [blame] | 780 | fdt_addr_t ofnode_get_addr_index(ofnode node, int index); |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 781 | |
| 782 | /** |
| 783 | * ofnode_get_addr() - get an address from a node |
| 784 | * |
| 785 | * This reads the register address from a node |
| 786 | * |
| 787 | * @node: node to read from |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 788 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 789 | */ |
Johan Jonker | 9f6971f | 2023-03-13 01:30:33 +0100 | [diff] [blame] | 790 | fdt_addr_t ofnode_get_addr(ofnode node); |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 791 | |
| 792 | /** |
Chen Guanqiao | 223f17d | 2021-04-12 14:51:11 +0800 | [diff] [blame] | 793 | * ofnode_get_size() - get size from a node |
| 794 | * |
| 795 | * This reads the register size from a node |
| 796 | * |
| 797 | * @node: node to read from |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 798 | * 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] | 799 | */ |
| 800 | fdt_size_t ofnode_get_size(ofnode node); |
| 801 | |
| 802 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 803 | * ofnode_stringlist_search() - find a string in a string list and return index |
| 804 | * |
| 805 | * Note that it is possible for this function to succeed on property values |
| 806 | * that are not NUL-terminated. That's because the function will stop after |
| 807 | * finding the first occurrence of @string. This can for example happen with |
| 808 | * small-valued cell properties, such as #address-cells, when searching for |
| 809 | * the empty string. |
| 810 | * |
| 811 | * @node: node to check |
| 812 | * @propname: name of the property containing the string list |
| 813 | * @string: string to look up in the string list |
| 814 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 815 | * Return: |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 816 | * the index of the string in the list of strings |
| 817 | * -ENODATA if the property is not found |
| 818 | * -EINVAL on some other error |
| 819 | */ |
| 820 | int ofnode_stringlist_search(ofnode node, const char *propname, |
| 821 | const char *string); |
| 822 | |
| 823 | /** |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 824 | * ofnode_read_string_index() - obtain an indexed string from a string list |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 825 | * |
| 826 | * Note that this will successfully extract strings from properties with |
| 827 | * non-NUL-terminated values. For example on small-valued cell properties |
| 828 | * this function will return the empty string. |
| 829 | * |
| 830 | * If non-NULL, the length of the string (on success) or a negative error-code |
| 831 | * (on failure) will be stored in the integer pointer to by lenp. |
| 832 | * |
| 833 | * @node: node to check |
| 834 | * @propname: name of the property containing the string list |
Simon Glass | 7a3a167 | 2021-10-23 17:26:06 -0600 | [diff] [blame] | 835 | * @index: index of the string to return (cannot be negative) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 836 | * @outp: return location for the string |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 837 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 838 | * Return: |
Simon Glass | 7a3a167 | 2021-10-23 17:26:06 -0600 | [diff] [blame] | 839 | * 0 if found or -ve error value if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 840 | */ |
| 841 | int ofnode_read_string_index(ofnode node, const char *propname, int index, |
| 842 | const char **outp); |
| 843 | |
| 844 | /** |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 845 | * ofnode_read_string_count() - find the number of strings in a string list |
| 846 | * |
| 847 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 848 | * @property: name of the property containing the string list |
| 849 | * Return: |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 850 | * number of strings in the list, or -ve error value if not found |
| 851 | */ |
| 852 | int ofnode_read_string_count(ofnode node, const char *property); |
| 853 | |
| 854 | /** |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 855 | * ofnode_read_string_list() - read a list of strings |
| 856 | * |
| 857 | * This produces a list of string pointers with each one pointing to a string |
| 858 | * in the string list. If the property does not exist, it returns {NULL}. |
| 859 | * |
| 860 | * The data is allocated and the caller is reponsible for freeing the return |
| 861 | * value (the list of string pointers). The strings themselves may not be |
| 862 | * changed as they point directly into the devicetree property. |
| 863 | * |
| 864 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 865 | * @property: name of the property containing the string list |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 866 | * @listp: returns an allocated, NULL-terminated list of strings if the return |
| 867 | * value is > 0, else is set to NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 868 | * Return: |
| 869 | * number of strings in list, 0 if none, -ENOMEM if out of memory, |
| 870 | * -EINVAL if no such property, -EENODATA if property is empty |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 871 | */ |
| 872 | int ofnode_read_string_list(ofnode node, const char *property, |
| 873 | const char ***listp); |
| 874 | |
| 875 | /** |
Christian Marangi | e810bcd | 2024-11-10 12:50:22 +0100 | [diff] [blame] | 876 | * ofnode_parse_phandle() - Resolve a phandle property to an ofnode |
| 877 | * |
| 878 | * @node: node to check |
| 879 | * @phandle_name: Name of property holding a phandle value |
| 880 | * @index: For properties holding a table of phandles, this is the index into |
| 881 | * the table |
| 882 | * Return: ofnode that the phandle points to or ofnode_null() on error. |
| 883 | */ |
| 884 | ofnode ofnode_parse_phandle(ofnode node, const char *phandle_name, |
| 885 | int index); |
| 886 | |
| 887 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 888 | * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list |
| 889 | * |
| 890 | * This function is useful to parse lists of phandles and their arguments. |
| 891 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 892 | * errno value. |
| 893 | * |
| 894 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 895 | * pointer. |
| 896 | * |
| 897 | * Example: |
| 898 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 899 | * .. code-block:: |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 900 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 901 | * phandle1: node1 { |
| 902 | * #list-cells = <2>; |
| 903 | * }; |
| 904 | * phandle2: node2 { |
| 905 | * #list-cells = <1>; |
| 906 | * }; |
| 907 | * node3 { |
| 908 | * list = <&phandle1 1 2 &phandle2 3>; |
| 909 | * }; |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 910 | * |
| 911 | * To get a device_node of the `node2' node you may call this: |
| 912 | * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args); |
| 913 | * |
| 914 | * @node: device tree node containing a list |
| 915 | * @list_name: property name that contains a list |
| 916 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 917 | * @cell_count: Cell count to use if @cells_name is NULL |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 918 | * @index: index of a phandle to parse out |
| 919 | * @out_args: optional pointer to output arguments structure (will be filled) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 920 | * Return: |
| 921 | * 0 on success (with @out_args filled out if not NULL), -ENOENT if |
| 922 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 923 | * @cells_name could not be found, the arguments were truncated or there |
| 924 | * were too many arguments. |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 925 | */ |
| 926 | int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, |
| 927 | const char *cells_name, int cell_count, |
| 928 | int index, |
| 929 | struct ofnode_phandle_args *out_args); |
| 930 | |
| 931 | /** |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 932 | * ofnode_count_phandle_with_args() - Count number of phandle in a list |
| 933 | * |
| 934 | * This function is useful to count phandles into a list. |
| 935 | * Returns number of phandle on success, on error returns appropriate |
| 936 | * errno value. |
| 937 | * |
| 938 | * @node: device tree node containing a list |
| 939 | * @list_name: property name that contains a list |
| 940 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 941 | * @cell_count: Cell count to use if @cells_name is NULL |
| 942 | * Return: |
| 943 | * number of phandle on success, -ENOENT if @list_name does not exist, |
| 944 | * -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] | 945 | */ |
| 946 | int ofnode_count_phandle_with_args(ofnode node, const char *list_name, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 947 | const char *cells_name, int cell_count); |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 948 | |
| 949 | /** |
Christian Marangi | e810bcd | 2024-11-10 12:50:22 +0100 | [diff] [blame] | 950 | * oftree_parse_phandle() - Resolve a phandle property to an ofnode |
| 951 | * from a root node |
| 952 | * |
| 953 | * @tree: device tree to use |
| 954 | * @node: node to check |
| 955 | * @phandle_name: Name of property holding a phandle value |
| 956 | * @index: For properties holding a table of phandles, this is the index into |
| 957 | * the table |
| 958 | * Return: ofnode that the phandle points to or ofnode_null() on error. |
| 959 | */ |
| 960 | ofnode oftree_parse_phandle(oftree tree, ofnode node, const char *phandle_name, |
| 961 | int index); |
| 962 | |
| 963 | /** |
Christian Marangi | 98715ac | 2024-11-10 12:50:20 +0100 | [diff] [blame] | 964 | * oftree_parse_phandle_with_args() - Find a node pointed by phandle in a list |
| 965 | * from a root node |
| 966 | * |
| 967 | * This function is useful to parse lists of phandles and their arguments. |
| 968 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 969 | * errno value. |
| 970 | * |
| 971 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 972 | * pointer. |
| 973 | * |
| 974 | * Example: |
| 975 | * |
| 976 | * .. code-block:: |
| 977 | * |
| 978 | * phandle1: node1 { |
| 979 | * #list-cells = <2>; |
| 980 | * }; |
| 981 | * phandle2: node2 { |
| 982 | * #list-cells = <1>; |
| 983 | * }; |
| 984 | * node3 { |
| 985 | * list = <&phandle1 1 2 &phandle2 3>; |
| 986 | * }; |
| 987 | * |
| 988 | * To get a device_node of the `node2' node you may call this: |
| 989 | * oftree_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args); |
| 990 | * |
| 991 | * @tree: device tree to use |
| 992 | * @node: device tree node containing a list |
| 993 | * @list_name: property name that contains a list |
| 994 | * @cells_name: property name that specifies phandles' arguments count |
| 995 | * @cell_count: Cell count to use if @cells_name is NULL |
| 996 | * @index: index of a phandle to parse out |
| 997 | * @out_args: optional pointer to output arguments structure (will be filled) |
| 998 | * Return: |
| 999 | * 0 on success (with @out_args filled out if not NULL), -ENOENT if |
| 1000 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 1001 | * @cells_name could not be found, the arguments were truncated or there |
| 1002 | * were too many arguments. |
| 1003 | */ |
| 1004 | int oftree_parse_phandle_with_args(oftree tree, ofnode node, const char *list_name, |
| 1005 | const char *cells_name, int cell_count, |
| 1006 | int index, |
| 1007 | struct ofnode_phandle_args *out_args); |
| 1008 | |
| 1009 | /** |
| 1010 | * oftree_count_phandle_with_args() - Count number of phandle in a list |
| 1011 | * from a root node |
| 1012 | * |
| 1013 | * This function is useful to count phandles into a list. |
| 1014 | * Returns number of phandle on success, on error returns appropriate |
| 1015 | * errno value. |
| 1016 | * |
| 1017 | * @tree: device tree to use |
| 1018 | * @node: device tree node containing a list |
| 1019 | * @list_name: property name that contains a list |
| 1020 | * @cells_name: property name that specifies phandles' arguments count |
| 1021 | * @cell_count: Cell count to use if @cells_name is NULL |
| 1022 | * Return: |
| 1023 | * number of phandle on success, -ENOENT if @list_name does not exist, |
| 1024 | * -EINVAL if a phandle was not found, @cells_name could not be found. |
| 1025 | */ |
| 1026 | int oftree_count_phandle_with_args(oftree tree, ofnode node, const char *list_name, |
| 1027 | const char *cells_name, int cell_count); |
| 1028 | |
| 1029 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1030 | * ofnode_path() - find a node by full path |
| 1031 | * |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 1032 | * This uses the control FDT. |
| 1033 | * |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1034 | * @path: Full path to node, e.g. "/bus/spi@1" |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1035 | * 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] | 1036 | */ |
| 1037 | ofnode ofnode_path(const char *path); |
| 1038 | |
| 1039 | /** |
Simon Glass | 45ae59d | 2022-09-06 20:27:24 -0600 | [diff] [blame] | 1040 | * oftree_path() - find a node by full path from a root node |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 1041 | * |
| 1042 | * @tree: Device tree to use |
| 1043 | * @path: Full path to node, e.g. "/bus/spi@1" |
| 1044 | * Return: reference to the node found. Use ofnode_valid() to check if it exists |
| 1045 | */ |
Simon Glass | 45ae59d | 2022-09-06 20:27:24 -0600 | [diff] [blame] | 1046 | ofnode oftree_path(oftree tree, const char *path); |
Simon Glass | ef75c59 | 2022-07-30 15:52:08 -0600 | [diff] [blame] | 1047 | |
| 1048 | /** |
Simon Glass | 45ae59d | 2022-09-06 20:27:24 -0600 | [diff] [blame] | 1049 | * oftree_root() - get the root node of a tree |
| 1050 | * |
| 1051 | * @tree: Device tree to use |
| 1052 | * Return: reference to the root node |
| 1053 | */ |
| 1054 | ofnode oftree_root(oftree tree); |
| 1055 | |
| 1056 | /** |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 1057 | * ofnode_read_chosen_prop() - get the value of a chosen property |
| 1058 | * |
Simon Glass | 45ae59d | 2022-09-06 20:27:24 -0600 | [diff] [blame] | 1059 | * This looks for a property within the /chosen node and returns its value. |
| 1060 | * |
| 1061 | * This only works with the control FDT. |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 1062 | * |
| 1063 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1064 | * @sizep: Returns size of property, or `FDT_ERR_...` error code if function |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 1065 | * returns NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1066 | * Return: property value if found, else NULL |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 1067 | */ |
| 1068 | const void *ofnode_read_chosen_prop(const char *propname, int *sizep); |
| 1069 | |
| 1070 | /** |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 1071 | * ofnode_read_chosen_string() - get the string value of a chosen property |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1072 | * |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 1073 | * This looks for a property within the /chosen node and returns its value, |
| 1074 | * checking that it is a valid nul-terminated string |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1075 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1076 | * This only works with the control FDT. |
| 1077 | * |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1078 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1079 | * Return: string value if found, else NULL |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1080 | */ |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 1081 | const char *ofnode_read_chosen_string(const char *propname); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1082 | |
| 1083 | /** |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 1084 | * ofnode_get_chosen_node() - get a referenced node from the chosen node |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1085 | * |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 1086 | * This looks up a named property in the chosen node and uses that as a path to |
| 1087 | * look up a code. |
| 1088 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1089 | * This only works with the control FDT. |
| 1090 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1091 | * @propname: Property name to look for |
| 1092 | * Return: the referenced node if present, else ofnode_null() |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1093 | */ |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 1094 | ofnode ofnode_get_chosen_node(const char *propname); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1095 | |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1096 | /** |
Algapally Santosh Sagar | df17899 | 2023-09-21 16:50:43 +0530 | [diff] [blame] | 1097 | * ofnode_read_baud() - get the baudrate from string value of chosen property |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1098 | * |
Algapally Santosh Sagar | df17899 | 2023-09-21 16:50:43 +0530 | [diff] [blame] | 1099 | * This looks for stdout-path property within the /chosen node and parses its |
| 1100 | * value to return baudrate. |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1101 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1102 | * This only works with the control FDT. |
| 1103 | * |
Algapally Santosh Sagar | df17899 | 2023-09-21 16:50:43 +0530 | [diff] [blame] | 1104 | * Return: baudrate value if found, else -ve error code |
| 1105 | */ |
| 1106 | int ofnode_read_baud(void); |
| 1107 | |
| 1108 | /** |
| 1109 | * ofnode_read_aliases_prop() - get the value of a aliases property |
| 1110 | * |
| 1111 | * This looks for a property within the /aliases node and returns its value |
| 1112 | * |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1113 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1114 | * @sizep: Returns size of property, or `FDT_ERR_...` error code if function |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1115 | * returns NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1116 | * Return: property value if found, else NULL |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1117 | */ |
| 1118 | const void *ofnode_read_aliases_prop(const char *propname, int *sizep); |
| 1119 | |
| 1120 | /** |
| 1121 | * ofnode_get_aliases_node() - get a referenced node from the aliases node |
| 1122 | * |
| 1123 | * This looks up a named property in the aliases node and uses that as a path to |
| 1124 | * look up a code. |
| 1125 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1126 | * This only works with the control FDT. |
| 1127 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1128 | * @propname: Property name to look for |
| 1129 | * Return: the referenced node if present, else ofnode_null() |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 1130 | */ |
| 1131 | ofnode ofnode_get_aliases_node(const char *propname); |
| 1132 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1133 | struct display_timing; |
| 1134 | /** |
| 1135 | * ofnode_decode_display_timing() - decode display timings |
| 1136 | * |
| 1137 | * Decode display timings from the supplied 'display-timings' node. |
| 1138 | * See doc/device-tree-bindings/video/display-timing.txt for binding |
| 1139 | * information. |
| 1140 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1141 | * @node: 'display-timing' node containing the timing subnodes |
| 1142 | * @index: Index number to read (0=first timing subnode) |
| 1143 | * @config: Place to put timings |
| 1144 | * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1145 | */ |
| 1146 | int ofnode_decode_display_timing(ofnode node, int index, |
| 1147 | struct display_timing *config); |
| 1148 | |
| 1149 | /** |
Nikhil M Jain | ff40706 | 2023-01-31 15:35:14 +0530 | [diff] [blame] | 1150 | * ofnode_decode_panel_timing() - decode display timings |
| 1151 | * |
| 1152 | * Decode panel timings from the supplied 'panel-timings' node. |
| 1153 | * |
| 1154 | * @node: 'display-timing' node containing the timing subnodes |
| 1155 | * @config: Place to put timings |
| 1156 | * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found |
| 1157 | */ |
| 1158 | int ofnode_decode_panel_timing(ofnode node, |
| 1159 | struct display_timing *config); |
| 1160 | |
| 1161 | /** |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1162 | * 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] | 1163 | * |
| 1164 | * @node: node to read |
| 1165 | * @propname: property to read |
| 1166 | * @lenp: place to put length on success |
Simon Glass | 86ef399 | 2023-09-26 08:14:44 -0600 | [diff] [blame] | 1167 | * Return: pointer to property value, or NULL if not found or empty |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1168 | */ |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 1169 | const void *ofnode_get_property(ofnode node, const char *propname, int *lenp); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1170 | |
| 1171 | /** |
Simon Glass | 86ef399 | 2023-09-26 08:14:44 -0600 | [diff] [blame] | 1172 | * ofnode_has_property() - check if a node has a named property |
| 1173 | * |
| 1174 | * @node: node to read |
| 1175 | * @propname: property to read |
| 1176 | * Return: true if the property exists in the node, false if not |
| 1177 | */ |
| 1178 | bool ofnode_has_property(ofnode node, const char *propname); |
| 1179 | |
| 1180 | /** |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 1181 | * ofnode_first_property()- get the reference of the first property |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1182 | * |
| 1183 | * Get reference to the first property of the node, it is used to iterate |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 1184 | * and read all the property with ofprop_get_property(). |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1185 | * |
| 1186 | * @node: node to read |
| 1187 | * @prop: place to put argument reference |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1188 | * 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] | 1189 | */ |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 1190 | int ofnode_first_property(ofnode node, struct ofprop *prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1191 | |
| 1192 | /** |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 1193 | * ofnode_next_property() - get the reference of the next property |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1194 | * |
| 1195 | * Get reference to the next property of the node, it is used to iterate |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 1196 | * and read all the property with ofprop_get_property(). |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1197 | * |
| 1198 | * @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] | 1199 | * 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] | 1200 | */ |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 1201 | int ofnode_next_property(struct ofprop *prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1202 | |
| 1203 | /** |
Simon Glass | 4caa79a | 2022-09-06 20:27:16 -0600 | [diff] [blame] | 1204 | * ofnode_for_each_prop() - iterate over all properties of a node |
| 1205 | * |
| 1206 | * @prop: struct ofprop |
| 1207 | * @node: node (lvalue, ofnode) |
| 1208 | * |
| 1209 | * This is a wrapper around a for loop and is used like this:: |
| 1210 | * |
| 1211 | * ofnode node; |
| 1212 | * struct ofprop prop; |
| 1213 | * |
| 1214 | * ofnode_for_each_prop(prop, node) { |
| 1215 | * ...use prop... |
| 1216 | * } |
| 1217 | * |
| 1218 | * Note that this is implemented as a macro and @prop is used as |
| 1219 | * iterator in the loop. The parent variable can be a constant or even a |
| 1220 | * literal. |
| 1221 | */ |
| 1222 | #define ofnode_for_each_prop(prop, node) \ |
| 1223 | for (ofnode_first_property(node, &prop); \ |
| 1224 | ofprop_valid(&prop); \ |
| 1225 | ofnode_next_property(&prop)) |
| 1226 | |
| 1227 | /** |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 1228 | * ofprop_get_property() - get a pointer to the value of a property |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1229 | * |
| 1230 | * Get value for the property identified by the provided reference. |
| 1231 | * |
| 1232 | * @prop: reference on property |
| 1233 | * @propname: If non-NULL, place to property name on success, |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 1234 | * @lenp: If non-NULL, place to put length on success, or error code on failure |
| 1235 | * Return: pointer to property, or NULL if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1236 | */ |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 1237 | const void *ofprop_get_property(const struct ofprop *prop, |
| 1238 | const char **propname, int *lenp); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1239 | |
| 1240 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1241 | * ofnode_get_addr_size() - get address and size from a property |
| 1242 | * |
| 1243 | * This does no address translation. It simply reads an property that contains |
| 1244 | * an address and a size value, one after the other. |
| 1245 | * |
| 1246 | * @node: node to read from |
| 1247 | * @propname: property to read |
| 1248 | * @sizep: place to put size value (on success) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1249 | * Return: address value, or FDT_ADDR_T_NONE on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1250 | */ |
Johan Jonker | 9f6971f | 2023-03-13 01:30:33 +0100 | [diff] [blame] | 1251 | fdt_addr_t ofnode_get_addr_size(ofnode node, const char *propname, |
| 1252 | fdt_size_t *sizep); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1253 | |
| 1254 | /** |
| 1255 | * ofnode_read_u8_array_ptr() - find an 8-bit array |
| 1256 | * |
| 1257 | * Look up a property in a node and return a pointer to its contents as a |
| 1258 | * byte array of given length. The property must have at least enough data |
| 1259 | * for the array (count bytes). It may have more, but this will be ignored. |
| 1260 | * The data is not copied. |
| 1261 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1262 | * @node: node to examine |
| 1263 | * @propname: name of property to find |
| 1264 | * @sz: number of array elements |
| 1265 | * Return: |
| 1266 | * pointer to byte array if found, or NULL if the property is not found or |
| 1267 | * there is not enough data |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1268 | */ |
| 1269 | const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname, |
| 1270 | size_t sz); |
| 1271 | |
| 1272 | /** |
| 1273 | * ofnode_read_pci_addr() - look up a PCI address |
| 1274 | * |
| 1275 | * Look at an address property in a node and return the PCI address which |
| 1276 | * corresponds to the given type in the form of fdt_pci_addr. |
| 1277 | * The property must hold one fdt_pci_addr with a lengh. |
| 1278 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1279 | * @node: node to examine |
| 1280 | * @type: pci address type (FDT_PCI_SPACE_xxx) |
| 1281 | * @propname: name of property to find |
| 1282 | * @addr: returns pci address in the form of fdt_pci_addr |
Simon Glass | 4289c26 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 1283 | * @size: if non-null, returns register-space size |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1284 | * Return: |
| 1285 | * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the |
| 1286 | * format of the property was invalid, -ENXIO if the requested |
| 1287 | * address type was not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1288 | */ |
| 1289 | int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, |
Simon Glass | 4289c26 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 1290 | const char *propname, struct fdt_pci_addr *addr, |
| 1291 | fdt_size_t *size); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1292 | |
| 1293 | /** |
Bin Meng | fa15771 | 2018-08-03 01:14:35 -0700 | [diff] [blame] | 1294 | * ofnode_read_pci_vendev() - look up PCI vendor and device id |
| 1295 | * |
| 1296 | * Look at the compatible property of a device node that represents a PCI |
| 1297 | * device and extract pci vendor id and device id from it. |
| 1298 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1299 | * @node: node to examine |
| 1300 | * @vendor: vendor id of the pci device |
| 1301 | * @device: device id of the pci device |
| 1302 | * Return: 0 if ok, negative on error |
Bin Meng | fa15771 | 2018-08-03 01:14:35 -0700 | [diff] [blame] | 1303 | */ |
| 1304 | int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device); |
| 1305 | |
| 1306 | /** |
Michal Simek | a253c3b | 2022-02-23 15:45:40 +0100 | [diff] [blame] | 1307 | * ofnode_read_eth_phy_id() - look up eth phy vendor and device id |
| 1308 | * |
| 1309 | * Look at the compatible property of a device node that represents a eth phy |
| 1310 | * device and extract phy vendor id and device id from it. |
| 1311 | * |
Heinrich Schuchardt | c9ae4a8 | 2022-03-24 16:22:32 +0100 | [diff] [blame] | 1312 | * @node: node to examine |
| 1313 | * @vendor: vendor id of the eth phy device |
| 1314 | * @device: device id of the eth phy device |
| 1315 | * Return: 0 if ok, negative on error |
Michal Simek | a253c3b | 2022-02-23 15:45:40 +0100 | [diff] [blame] | 1316 | */ |
| 1317 | int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device); |
| 1318 | |
| 1319 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1320 | * ofnode_read_addr_cells() - Get the number of address cells for a node |
| 1321 | * |
| 1322 | * This walks back up the tree to find the closest #address-cells property |
| 1323 | * which controls the given node. |
| 1324 | * |
| 1325 | * @node: Node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1326 | * Return: number of address cells this node uses |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1327 | */ |
| 1328 | int ofnode_read_addr_cells(ofnode node); |
| 1329 | |
| 1330 | /** |
| 1331 | * ofnode_read_size_cells() - Get the number of size cells for a node |
| 1332 | * |
| 1333 | * This walks back up the tree to find the closest #size-cells property |
| 1334 | * which controls the given node. |
| 1335 | * |
| 1336 | * @node: Node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1337 | * Return: number of size cells this node uses |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1338 | */ |
| 1339 | int ofnode_read_size_cells(ofnode node); |
| 1340 | |
| 1341 | /** |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 1342 | * ofnode_read_simple_addr_cells() - Get the address cells property in a node |
| 1343 | * |
| 1344 | * This function matches fdt_address_cells(). |
| 1345 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1346 | * @node: Node to check |
| 1347 | * 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] | 1348 | */ |
| 1349 | int ofnode_read_simple_addr_cells(ofnode node); |
| 1350 | |
| 1351 | /** |
| 1352 | * ofnode_read_simple_size_cells() - Get the size cells property in a node |
| 1353 | * |
| 1354 | * This function matches fdt_size_cells(). |
| 1355 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1356 | * @node: Node to check |
| 1357 | * 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] | 1358 | */ |
| 1359 | int ofnode_read_simple_size_cells(ofnode node); |
| 1360 | |
| 1361 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1362 | * ofnode_pre_reloc() - check if a node should be bound before relocation |
| 1363 | * |
| 1364 | * Device tree nodes can be marked as needing-to-be-bound in the loader stages |
| 1365 | * via special device tree properties. |
| 1366 | * |
| 1367 | * Before relocation this function can be used to check if nodes are required |
| 1368 | * in either SPL or TPL stages. |
| 1369 | * |
| 1370 | * After relocation and jumping into the real U-Boot binary it is possible to |
| 1371 | * determine if a node was bound in one of SPL/TPL stages. |
| 1372 | * |
Patrick Delaunay | 63e4d11 | 2019-05-21 19:19:13 +0200 | [diff] [blame] | 1373 | * There are 4 settings currently in use |
Jonas Karlman | c43411b | 2023-08-20 22:03:18 +0000 | [diff] [blame] | 1374 | * - bootph-some-ram: U-Boot proper pre-relocation phase |
Simon Glass | fc1aa35 | 2023-02-13 08:56:34 -0700 | [diff] [blame] | 1375 | * - bootph-all: all phases |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1376 | * Existing platforms only use it to indicate nodes needed in |
Simon Glass | fc1aa35 | 2023-02-13 08:56:34 -0700 | [diff] [blame] | 1377 | * SPL. Should probably be replaced by bootph-pre-ram for new platforms. |
Jonas Karlman | c43411b | 2023-08-20 22:03:18 +0000 | [diff] [blame] | 1378 | * - bootph-pre-ram: SPL phase |
| 1379 | * - bootph-pre-sram: TPL phase |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1380 | * |
| 1381 | * @node: node to check |
Jonas Karlman | c43411b | 2023-08-20 22:03:18 +0000 | [diff] [blame] | 1382 | * Return: true if node should be or was bound, false otherwise |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 1383 | */ |
| 1384 | bool ofnode_pre_reloc(ofnode node); |
| 1385 | |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 1386 | /** |
| 1387 | * ofnode_read_resource() - Read a resource from a node |
| 1388 | * |
| 1389 | * Read resource information from a node at the given index |
| 1390 | * |
| 1391 | * @node: Node to read from |
| 1392 | * @index: Index of resource to read (0 = first) |
| 1393 | * @res: Returns resource that was read, on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1394 | * Return: 0 if OK, -ve on error |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 1395 | */ |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 1396 | int ofnode_read_resource(ofnode node, uint index, struct resource *res); |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 1397 | |
| 1398 | /** |
| 1399 | * ofnode_read_resource_byname() - Read a resource from a node by name |
| 1400 | * |
| 1401 | * Read resource information from a node matching the given name. This uses a |
| 1402 | * 'reg-names' string list property with the names matching the associated |
| 1403 | * 'reg' property list. |
| 1404 | * |
| 1405 | * @node: Node to read from |
| 1406 | * @name: Name of resource to read |
| 1407 | * @res: Returns resource that was read, on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1408 | * Return: 0 if OK, -ve on error |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 1409 | */ |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 1410 | int ofnode_read_resource_byname(ofnode node, const char *name, |
| 1411 | struct resource *res); |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 1412 | |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1413 | /** |
Simon Glass | 954eeae | 2018-06-11 13:07:13 -0600 | [diff] [blame] | 1414 | * ofnode_by_compatible() - Find the next compatible node |
| 1415 | * |
| 1416 | * Find the next node after @from that is compatible with @compat |
| 1417 | * |
| 1418 | * @from: ofnode to start from (use ofnode_null() to start at the beginning) |
| 1419 | * @compat: Compatible string to match |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1420 | * Return: ofnode found, or ofnode_null() if none |
Simon Glass | 954eeae | 2018-06-11 13:07:13 -0600 | [diff] [blame] | 1421 | */ |
| 1422 | ofnode ofnode_by_compatible(ofnode from, const char *compat); |
| 1423 | |
| 1424 | /** |
Jens Wiklander | 7b68dad | 2018-08-20 11:09:58 +0200 | [diff] [blame] | 1425 | * ofnode_by_prop_value() - Find the next node with given property value |
| 1426 | * |
| 1427 | * Find the next node after @from that has a @propname with a value |
| 1428 | * @propval and a length @proplen. |
| 1429 | * |
Simon Glass | 37dcd91 | 2022-09-06 20:27:23 -0600 | [diff] [blame] | 1430 | * @from: ofnode to start from. Use ofnode_null() to start at the |
| 1431 | * beginning, or the return value from oftree_root() to start at the first |
| 1432 | * child of the root |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1433 | * @propname: property name to check |
| 1434 | * @propval: property value to search for |
| 1435 | * @proplen: length of the value in propval |
| 1436 | * Return: ofnode found, or ofnode_null() if none |
Jens Wiklander | 7b68dad | 2018-08-20 11:09:58 +0200 | [diff] [blame] | 1437 | */ |
| 1438 | ofnode ofnode_by_prop_value(ofnode from, const char *propname, |
| 1439 | const void *propval, int proplen); |
| 1440 | |
| 1441 | /** |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1442 | * ofnode_for_each_subnode() - iterate over all subnodes of a parent |
| 1443 | * |
| 1444 | * @node: child node (ofnode, lvalue) |
| 1445 | * @parent: parent node (ofnode) |
| 1446 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1447 | * 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] | 1448 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1449 | * ofnode node; |
| 1450 | * ofnode_for_each_subnode(node, parent) { |
| 1451 | * Use node |
| 1452 | * ... |
| 1453 | * } |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1454 | * |
| 1455 | * Note that this is implemented as a macro and @node is used as |
| 1456 | * iterator in the loop. The parent variable can be a constant or even a |
| 1457 | * literal. |
| 1458 | */ |
| 1459 | #define ofnode_for_each_subnode(node, parent) \ |
| 1460 | for (node = ofnode_first_subnode(parent); \ |
| 1461 | ofnode_valid(node); \ |
| 1462 | node = ofnode_next_subnode(node)) |
| 1463 | |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1464 | /** |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1465 | * ofnode_for_each_compatible_node() - iterate over all nodes with a given |
| 1466 | * compatible string |
| 1467 | * |
| 1468 | * @node: child node (ofnode, lvalue) |
| 1469 | * @compat: compatible string to match |
| 1470 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1471 | * 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] | 1472 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1473 | * ofnode node; |
| 1474 | * ofnode_for_each_compatible_node(node, parent, compatible) { |
| 1475 | * Use node |
| 1476 | * ... |
| 1477 | * } |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1478 | * |
| 1479 | * Note that this is implemented as a macro and @node is used as |
| 1480 | * iterator in the loop. |
| 1481 | */ |
| 1482 | #define ofnode_for_each_compatible_node(node, compat) \ |
| 1483 | for (node = ofnode_by_compatible(ofnode_null(), compat); \ |
| 1484 | ofnode_valid(node); \ |
| 1485 | node = ofnode_by_compatible(node, compat)) |
| 1486 | |
| 1487 | /** |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1488 | * ofnode_get_child_count() - get the child count of a ofnode |
| 1489 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1490 | * @parent: valid node to get its child count |
| 1491 | * Return: the number of subnodes |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1492 | */ |
| 1493 | int ofnode_get_child_count(ofnode parent); |
| 1494 | |
| 1495 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1496 | * ofnode_translate_address() - Translate a device-tree address |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1497 | * |
| 1498 | * Translate an address from the device-tree into a CPU physical address. This |
| 1499 | * function walks up the tree and applies the various bus mappings along the |
| 1500 | * way. |
| 1501 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1502 | * @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] | 1503 | * @in_addr: pointer to the address to translate |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1504 | * Return: the translated address; OF_BAD_ADDR on error |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1505 | */ |
| 1506 | u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr); |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1507 | |
| 1508 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1509 | * ofnode_translate_dma_address() - Translate a device-tree DMA address |
| 1510 | * |
| 1511 | * Translate a DMA address from the device-tree into a CPU physical address. |
| 1512 | * This function walks up the tree and applies the various bus mappings along |
| 1513 | * the way. |
| 1514 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1515 | * @node: Device tree node giving the context in which to translate the |
| 1516 | * DMA address |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1517 | * @in_addr: pointer to the DMA address to translate |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1518 | * Return: the translated DMA address; OF_BAD_ADDR on error |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1519 | */ |
| 1520 | u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr); |
| 1521 | |
| 1522 | /** |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1523 | * ofnode_get_dma_range() - get dma-ranges for a specific DT node |
| 1524 | * |
| 1525 | * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and |
| 1526 | * cpu->bus address translations |
| 1527 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1528 | * @node: Device tree node |
| 1529 | * @cpu: Pointer to variable storing the range's cpu address |
| 1530 | * @bus: Pointer to variable storing the range's bus address |
| 1531 | * @size: Pointer to variable storing the range's size |
| 1532 | * Return: translated DMA address or OF_BAD_ADDR on error |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1533 | */ |
| 1534 | int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, |
| 1535 | u64 *size); |
| 1536 | |
| 1537 | /** |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1538 | * ofnode_device_is_compatible() - check if the node is compatible with compat |
| 1539 | * |
| 1540 | * This allows to check whether the node is comaptible with the compat. |
| 1541 | * |
| 1542 | * @node: Device tree node for which compatible needs to be verified. |
| 1543 | * @compat: Compatible string which needs to verified in the given node. |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1544 | * Return: true if OK, false if the compatible is not found |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1545 | */ |
| 1546 | int ofnode_device_is_compatible(ofnode node, const char *compat); |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1547 | |
| 1548 | /** |
| 1549 | * ofnode_write_prop() - Set a property of a ofnode |
| 1550 | * |
Simon Glass | 17abed0 | 2022-09-06 20:27:32 -0600 | [diff] [blame] | 1551 | * Note that if @copy is false, the value passed to the function is *not* |
| 1552 | * allocated by the function itself, but must be allocated by the caller if |
| 1553 | * necessary. However it does allocate memory for the property struct and name. |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1554 | * |
| 1555 | * @node: The node for whose property should be set |
| 1556 | * @propname: The name of the property to set |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1557 | * @value: The new value of the property (must be valid prior to calling |
| 1558 | * the function) |
Simon Glass | 5e2cd5e | 2022-07-30 15:52:10 -0600 | [diff] [blame] | 1559 | * @len: The length of the new value of the property |
Simon Glass | 17abed0 | 2022-09-06 20:27:32 -0600 | [diff] [blame] | 1560 | * @copy: true to allocate memory for the value. This only has any effect with |
| 1561 | * live tree, since flat tree handles this automatically. It allows a |
| 1562 | * node's value to be written to the tree, without requiring that the |
| 1563 | * caller allocate it |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1564 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1565 | */ |
Simon Glass | 5e2cd5e | 2022-07-30 15:52:10 -0600 | [diff] [blame] | 1566 | int ofnode_write_prop(ofnode node, const char *propname, const void *value, |
Simon Glass | 17abed0 | 2022-09-06 20:27:32 -0600 | [diff] [blame] | 1567 | int len, bool copy); |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1568 | |
| 1569 | /** |
| 1570 | * ofnode_write_string() - Set a string property of a ofnode |
| 1571 | * |
| 1572 | * Note that the value passed to the function is *not* allocated by the |
| 1573 | * function itself, but must be allocated by the caller if necessary. |
| 1574 | * |
| 1575 | * @node: The node for whose string property should be set |
| 1576 | * @propname: The name of the string property to set |
| 1577 | * @value: The new value of the string property (must be valid prior to |
| 1578 | * calling the function) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1579 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1580 | */ |
| 1581 | int ofnode_write_string(ofnode node, const char *propname, const char *value); |
| 1582 | |
| 1583 | /** |
Simon Glass | d28e31e | 2022-07-30 15:52:14 -0600 | [diff] [blame] | 1584 | * ofnode_write_u32() - Set an integer property of an ofnode |
| 1585 | * |
| 1586 | * @node: The node for whose string property should be set |
| 1587 | * @propname: The name of the string property to set |
| 1588 | * @value: The new value of the 32-bit integer property |
| 1589 | * Return: 0 if successful, -ve on error |
| 1590 | */ |
| 1591 | int ofnode_write_u32(ofnode node, const char *propname, u32 value); |
| 1592 | |
| 1593 | /** |
Simon Glass | c681e09 | 2023-09-26 08:14:45 -0600 | [diff] [blame] | 1594 | * ofnode_write_u64() - Set an integer property of an ofnode |
| 1595 | * |
| 1596 | * @node: The node for whose string property should be set |
| 1597 | * @propname: The name of the string property to set |
| 1598 | * @value: The new value of the 64-bit integer property |
| 1599 | * Return: 0 if successful, -ve on error |
| 1600 | */ |
| 1601 | int ofnode_write_u64(ofnode node, const char *propname, u64 value); |
| 1602 | |
| 1603 | /** |
Simon Glass | 86ef399 | 2023-09-26 08:14:44 -0600 | [diff] [blame] | 1604 | * ofnode_write_bool() - Set a boolean property of an ofnode |
| 1605 | * |
| 1606 | * This either adds or deleted a property with a zero-length value |
| 1607 | * |
| 1608 | * @node: The node for whose string property should be set |
| 1609 | * @propname: The name of the string property to set |
| 1610 | * @value: The new value of the boolean property |
| 1611 | * Return: 0 if successful, -ve on error |
| 1612 | */ |
| 1613 | int ofnode_write_bool(ofnode node, const char *propname, bool value); |
| 1614 | |
| 1615 | /** |
| 1616 | * ofnode_delete_prop() - Delete a property |
| 1617 | * |
| 1618 | * @node: Node containing the property to delete |
| 1619 | * @propname: Name of property to delete |
| 1620 | * Return: 0 if successful, -ve on error |
| 1621 | */ |
| 1622 | int ofnode_delete_prop(ofnode node, const char *propname); |
| 1623 | |
| 1624 | /** |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1625 | * ofnode_set_enabled() - Enable or disable a device tree node given by its |
| 1626 | * ofnode |
| 1627 | * |
| 1628 | * This function effectively sets the node's "status" property to either "okay" |
| 1629 | * or "disable", hence making it available for driver model initialization or |
| 1630 | * not. |
| 1631 | * |
| 1632 | * @node: The node to enable |
| 1633 | * @value: Flag that tells the function to either disable or enable the |
| 1634 | * node |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1635 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1636 | */ |
| 1637 | int ofnode_set_enabled(ofnode node, bool value); |
| 1638 | |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1639 | /** |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1640 | * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link) |
| 1641 | * |
| 1642 | * This function parses PHY handle from the Ethernet controller's ofnode |
| 1643 | * (trying all possible PHY handle property names), and returns the PHY ofnode. |
| 1644 | * |
| 1645 | * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and |
| 1646 | * if the result to that is true, this function should not be called. |
| 1647 | * |
| 1648 | * @eth_node: ofnode belonging to the Ethernet controller |
| 1649 | * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode |
| 1650 | */ |
| 1651 | ofnode ofnode_get_phy_node(ofnode eth_node); |
| 1652 | |
| 1653 | /** |
| 1654 | * ofnode_read_phy_mode() - Read PHY connection type from a MAC node |
| 1655 | * |
| 1656 | * This function parses the "phy-mode" / "phy-connection-type" property and |
| 1657 | * returns the corresponding PHY interface type. |
| 1658 | * |
| 1659 | * @mac_node: ofnode containing the property |
| 1660 | * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on |
| 1661 | * error |
| 1662 | */ |
| 1663 | phy_interface_t ofnode_read_phy_mode(ofnode mac_node); |
| 1664 | |
| 1665 | #if CONFIG_IS_ENABLED(DM) |
| 1666 | /** |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1667 | * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config |
| 1668 | * |
| 1669 | * This reads a property from the /config node of the devicetree. |
| 1670 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1671 | * This only works with the control FDT. |
| 1672 | * |
| 1673 | * See doc/device-tree-bindings/config.txt for bindings |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1674 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1675 | * @prop_name: property name to look up |
| 1676 | * Return: true, if it exists, false if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1677 | */ |
| 1678 | bool ofnode_conf_read_bool(const char *prop_name); |
| 1679 | |
| 1680 | /** |
| 1681 | * ofnode_conf_read_int() - Read an integer value from the U-Boot config |
| 1682 | * |
| 1683 | * This reads a property from the /config node of the devicetree. |
| 1684 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1685 | * See doc/device-tree-bindings/config.txt for bindings |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1686 | * |
| 1687 | * @prop_name: property name to look up |
| 1688 | * @default_val: default value to return if the property is not found |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1689 | * Return: integer value, if found, or @default_val if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1690 | */ |
| 1691 | int ofnode_conf_read_int(const char *prop_name, int default_val); |
| 1692 | |
| 1693 | /** |
| 1694 | * ofnode_conf_read_str() - Read a string value from the U-Boot config |
| 1695 | * |
| 1696 | * This reads a property from the /config node of the devicetree. |
| 1697 | * |
Simon Glass | c63ffd7 | 2022-09-06 20:27:28 -0600 | [diff] [blame] | 1698 | * This only works with the control FDT. |
| 1699 | * |
| 1700 | * See doc/device-tree-bindings/config.txt for bindings |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1701 | * |
| 1702 | * @prop_name: property name to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1703 | * Return: string value, if found, or NULL if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1704 | */ |
| 1705 | const char *ofnode_conf_read_str(const char *prop_name); |
| 1706 | |
Michal Simek | 43c42bd | 2023-08-31 08:59:05 +0200 | [diff] [blame] | 1707 | /** |
Christian Marangi | 7254473 | 2024-10-01 14:24:35 +0200 | [diff] [blame] | 1708 | * ofnode_options_read_bool() - Read a boolean value from the U-Boot options |
| 1709 | * |
| 1710 | * This reads a property from the /options/u-boot/ node of the devicetree. |
| 1711 | * |
| 1712 | * This only works with the control FDT. |
| 1713 | * |
| 1714 | * See dtschema/schemas/options/u-boot.yaml in dt-schema project for bindings |
| 1715 | * |
| 1716 | * @prop_name: property name to look up |
| 1717 | * Return: true, if it exists, false if not |
| 1718 | */ |
| 1719 | bool ofnode_options_read_bool(const char *prop_name); |
| 1720 | |
| 1721 | /** |
| 1722 | * ofnode_options_read_int() - Read an integer value from the U-Boot options |
| 1723 | * |
| 1724 | * This reads a property from the /options/u-boot/ node of the devicetree. |
| 1725 | * |
| 1726 | * See dtschema/schemas/options/u-boot.yaml in dt-schema project for bindings |
| 1727 | * |
| 1728 | * @prop_name: property name to look up |
| 1729 | * @default_val: default value to return if the property is not found |
| 1730 | * Return: integer value, if found, or @default_val if not |
| 1731 | */ |
| 1732 | int ofnode_options_read_int(const char *prop_name, int default_val); |
| 1733 | |
| 1734 | /** |
| 1735 | * ofnode_options_read_str() - Read a string value from the U-Boot options |
| 1736 | * |
| 1737 | * This reads a property from the /options/u-boot/ node of the devicetree. |
| 1738 | * |
| 1739 | * This only works with the control FDT. |
| 1740 | * |
| 1741 | * See dtschema/schemas/options/u-boot.yaml in dt-schema project for bindings |
| 1742 | * |
| 1743 | * @prop_name: property name to look up |
| 1744 | * Return: string value, if found, or NULL if not |
| 1745 | */ |
| 1746 | const char *ofnode_options_read_str(const char *prop_name); |
| 1747 | |
| 1748 | /** |
Christian Marangi | cdaa995 | 2024-11-10 12:50:24 +0100 | [diff] [blame] | 1749 | * ofnode_options_get_by_phandle() - Get a ofnode from phandle from the U-Boot options |
| 1750 | * |
| 1751 | * This reads a property from the /options/u-boot/ node of the devicetree. |
| 1752 | * |
| 1753 | * This only works with the control FDT. |
| 1754 | * |
| 1755 | * See dtschema/schemas/options/u-boot.yaml in dt-schema project for bindings |
| 1756 | * |
| 1757 | * @prop_name: property name to look up |
| 1758 | * @nodep: pointer to ofnode where node is stored |
| 1759 | * Return: 0, if found, or negative error if not |
| 1760 | */ |
| 1761 | int ofnode_options_get_by_phandle(const char *prop_name, ofnode *nodep); |
| 1762 | |
| 1763 | /** |
Michal Simek | 43c42bd | 2023-08-31 08:59:05 +0200 | [diff] [blame] | 1764 | * ofnode_read_bootscript_address() - Read bootscr-address or bootscr-ram-offset |
| 1765 | * |
| 1766 | * @bootscr_address: pointer to 64bit address where bootscr-address property value |
| 1767 | * is stored |
| 1768 | * @bootscr_offset: pointer to 64bit offset address where bootscr-ram-offset |
| 1769 | * property value is stored |
| 1770 | * |
| 1771 | * This reads a bootscr-address or bootscr-ram-offset property from |
| 1772 | * the /options/u-boot/ node of the devicetree. bootscr-address holds the full |
| 1773 | * address of the boot script file. bootscr-ram-offset holds the boot script |
| 1774 | * file offset from the start of the ram base address. When bootscr-address is |
| 1775 | * defined, bootscr-ram-offset property is ignored. |
| 1776 | * |
| 1777 | * This only works with the control FDT. |
| 1778 | * |
| 1779 | * Return: 0 if OK, -EINVAL if property is not found. |
| 1780 | */ |
| 1781 | int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset); |
| 1782 | |
Michal Simek | 6a7c1ce | 2023-08-31 09:04:27 +0200 | [diff] [blame] | 1783 | /** |
| 1784 | * ofnode_read_bootscript_flash() - Read bootscr-flash-offset/size |
| 1785 | * |
| 1786 | * @bootscr_flash_offset: pointer to 64bit offset where bootscr-flash-offset |
| 1787 | * property value is stored |
| 1788 | * @bootscr_flash_size: pointer to 64bit size where bootscr-flash-size property |
| 1789 | * value is stored |
| 1790 | * |
| 1791 | * This reads a bootscr-flash-offset and bootscr-flash-size properties from |
| 1792 | * the /options/u-boot/ node of the devicetree. bootscr-flash-offset holds |
| 1793 | * the offset of the boot script file from start of flash. bootscr-flash-size |
| 1794 | * holds the boot script size in flash. When bootscr-flash-size is not defined, |
| 1795 | * bootscr-flash-offset property is cleaned. |
| 1796 | * |
| 1797 | * This only works with the control FDT. |
| 1798 | * |
| 1799 | * Return: 0 if OK, -EINVAL if property is not found or incorrect. |
| 1800 | */ |
| 1801 | int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset, |
| 1802 | u64 *bootscr_flash_size); |
| 1803 | |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1804 | #else /* CONFIG_DM */ |
| 1805 | static inline bool ofnode_conf_read_bool(const char *prop_name) |
| 1806 | { |
| 1807 | return false; |
| 1808 | } |
Marek Behún | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 1809 | |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1810 | static inline int ofnode_conf_read_int(const char *prop_name, int default_val) |
| 1811 | { |
| 1812 | return default_val; |
| 1813 | } |
| 1814 | |
| 1815 | static inline const char *ofnode_conf_read_str(const char *prop_name) |
| 1816 | { |
| 1817 | return NULL; |
| 1818 | } |
Simon Glass | 56bc332 | 2022-09-06 20:27:02 -0600 | [diff] [blame] | 1819 | |
Michal Simek | 43c42bd | 2023-08-31 08:59:05 +0200 | [diff] [blame] | 1820 | static inline int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset) |
| 1821 | { |
| 1822 | return -EINVAL; |
| 1823 | } |
| 1824 | |
Michal Simek | 6a7c1ce | 2023-08-31 09:04:27 +0200 | [diff] [blame] | 1825 | static inline int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset, |
| 1826 | u64 *bootscr_flash_size) |
| 1827 | { |
| 1828 | return -EINVAL; |
| 1829 | } |
| 1830 | |
Sean Anderson | 9b3a639 | 2022-03-28 18:14:37 -0400 | [diff] [blame] | 1831 | #endif /* CONFIG_DM */ |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1832 | |
Simon Glass | 56bc332 | 2022-09-06 20:27:02 -0600 | [diff] [blame] | 1833 | /** |
| 1834 | * of_add_subnode() - add a new subnode to a node |
| 1835 | * |
| 1836 | * @parent: parent node to add to |
Simon Glass | bdbd96a | 2025-01-10 17:00:11 -0700 | [diff] [blame] | 1837 | * @name: name of subnode (allocated by this function) |
Simon Glass | 56bc332 | 2022-09-06 20:27:02 -0600 | [diff] [blame] | 1838 | * @nodep: returns pointer to new subnode (valid if the function returns 0 |
| 1839 | * or -EEXIST) |
| 1840 | * Returns 0 if OK, -EEXIST if already exists, -ENOMEM if out of memory, other |
| 1841 | * -ve on other error |
| 1842 | */ |
| 1843 | int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); |
| 1844 | |
Simon Glass | 7a7229a | 2022-09-06 20:27:33 -0600 | [diff] [blame] | 1845 | /** |
| 1846 | * ofnode_copy_props() - copy all properties from one node to another |
| 1847 | * |
Simon Glass | 6816489 | 2023-09-26 08:14:37 -0600 | [diff] [blame] | 1848 | * Makes a copy of all properties from the source node to the destination node. |
Simon Glass | 7a7229a | 2022-09-06 20:27:33 -0600 | [diff] [blame] | 1849 | * Existing properties in the destination node remain unchanged, except that |
| 1850 | * any with the same name are overwritten, including changing the size of the |
| 1851 | * property. |
| 1852 | * |
| 1853 | * For livetree, properties are copied / allocated, so the source tree does not |
| 1854 | * need to be present afterwards. |
| 1855 | * |
Simon Glass | 6816489 | 2023-09-26 08:14:37 -0600 | [diff] [blame] | 1856 | * @dst: Destination node to write properties to |
Simon Glass | 7a7229a | 2022-09-06 20:27:33 -0600 | [diff] [blame] | 1857 | * @src: Source node to read properties from |
Simon Glass | 7a7229a | 2022-09-06 20:27:33 -0600 | [diff] [blame] | 1858 | */ |
Simon Glass | 6816489 | 2023-09-26 08:14:37 -0600 | [diff] [blame] | 1859 | int ofnode_copy_props(ofnode dst, ofnode src); |
Simon Glass | 7a7229a | 2022-09-06 20:27:33 -0600 | [diff] [blame] | 1860 | |
Simon Glass | 7c33c96 | 2023-09-26 08:14:41 -0600 | [diff] [blame] | 1861 | /** |
| 1862 | * ofnode_copy_node() - Copy a node to another place |
| 1863 | * |
| 1864 | * If a node with this name already exists in dst_parent, this returns an |
| 1865 | * .error |
| 1866 | * |
| 1867 | * @dst_parent: Parent of the newly copied node |
| 1868 | * @name: Name to give the new node |
| 1869 | * @src: Source node to copy |
| 1870 | * @nodep: Returns the new node, or the existing node if there is one |
| 1871 | * Return: 0 if OK, -EEXIST if dst_parent already has a node with this parent |
| 1872 | */ |
| 1873 | int ofnode_copy_node(ofnode dst_parent, const char *name, ofnode src, |
| 1874 | ofnode *nodep); |
| 1875 | |
Simon Glass | 4544877 | 2023-09-26 08:14:42 -0600 | [diff] [blame] | 1876 | /** |
| 1877 | * ofnode_delete() - Delete a node |
| 1878 | * |
| 1879 | * Delete a node from the tree |
| 1880 | * |
| 1881 | * @nodep: Pointer to node to delete (set to ofnode_null() on success) |
| 1882 | * Return: 0 if OK, -ENOENT if the node does not exist, -EPERM if it is the root |
| 1883 | * node (wWhich cannot be removed), -EFAULT if the tree is broken (to_remove is |
| 1884 | * not a child of its parent), |
| 1885 | * |
| 1886 | */ |
| 1887 | int ofnode_delete(ofnode *nodep); |
| 1888 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 1889 | #endif |