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