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