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