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