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