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> |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 15 | |
| 16 | /* Enable checks to protect against invalid calls */ |
| 17 | #undef OF_CHECKS |
| 18 | |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 19 | struct resource; |
| 20 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 21 | /** |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 22 | * typedef union ofnode_union ofnode - reference to a device tree node |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 23 | * |
| 24 | * This union can hold either a straightforward pointer to a struct device_node |
| 25 | * in the live device tree, or an offset within the flat device tree. In the |
| 26 | * latter case, the pointer value is just the integer offset within the flat DT. |
| 27 | * |
| 28 | * Thus we can reference nodes in both the live tree (once available) and the |
| 29 | * flat tree (until then). Functions are available to translate between an |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 30 | * ofnode and either an offset or a `struct device_node *`. |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 31 | * |
| 32 | * The reference can also hold a null offset, in which case the pointer value |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 33 | * here is NULL. This corresponds to a struct device_node * value of |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 34 | * NULL, or an offset of -1. |
| 35 | * |
| 36 | * There is no ambiguity as to whether ofnode holds an offset or a node |
| 37 | * pointer: when the live tree is active it holds a node pointer, otherwise it |
| 38 | * holds an offset. The value itself does not need to be unique and in theory |
| 39 | * the same value could point to a valid device node or a valid offset. We |
| 40 | * could arrange for a unique value to be used (e.g. by making the pointer |
| 41 | * point to an offset within the flat device tree in the case of an offset) but |
| 42 | * this increases code size slightly due to the subtraction. Since it offers no |
| 43 | * real benefit, the approach described here seems best. |
| 44 | * |
| 45 | * For now these points use constant types, since we don't allow writing |
| 46 | * the DT. |
| 47 | * |
| 48 | * @np: Pointer to device node, used for live tree |
Baruch Siach | 6bcca14 | 2017-11-09 13:44:28 +0200 | [diff] [blame] | 49 | * @of_offset: Pointer into flat device tree, used for flat tree. Note that this |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 50 | * is not a really a pointer to a node: it is an offset value. See above. |
| 51 | */ |
| 52 | typedef union ofnode_union { |
Heinrich Schuchardt | b571d92 | 2020-07-24 18:39:43 +0200 | [diff] [blame] | 53 | const struct device_node *np; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 54 | long of_offset; |
| 55 | } ofnode; |
| 56 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 57 | struct ofnode_phandle_args { |
| 58 | ofnode node; |
| 59 | int args_count; |
| 60 | uint32_t args[OF_MAX_PHANDLE_ARGS]; |
| 61 | }; |
| 62 | |
| 63 | /** |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 64 | * struct ofprop - reference to a property of a device tree node |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 65 | * |
| 66 | * This struct hold the reference on one property of one node, |
| 67 | * using struct ofnode and an offset within the flat device tree or either |
| 68 | * a pointer to a struct property in the live device tree. |
| 69 | * |
| 70 | * Thus we can reference arguments in both the live tree and the flat tree. |
| 71 | * |
| 72 | * The property reference can also hold a null reference. This corresponds to |
| 73 | * a struct property NULL pointer or an offset of -1. |
| 74 | * |
| 75 | * @node: Pointer to device node |
| 76 | * @offset: Pointer into flat device tree, used for flat tree. |
| 77 | * @prop: Pointer to property, used for live treee. |
| 78 | */ |
| 79 | |
| 80 | struct ofprop { |
| 81 | ofnode node; |
| 82 | union { |
| 83 | int offset; |
| 84 | const struct property *prop; |
| 85 | }; |
| 86 | }; |
| 87 | |
| 88 | /** |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 89 | * ofnode_to_np() - convert an ofnode to a live DT node pointer |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 90 | * |
| 91 | * This cannot be called if the reference contains an offset. |
| 92 | * |
| 93 | * @node: Reference containing struct device_node * (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 94 | * Return: pointer to device node (can be NULL) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 95 | */ |
| 96 | static inline const struct device_node *ofnode_to_np(ofnode node) |
| 97 | { |
| 98 | #ifdef OF_CHECKS |
| 99 | if (!of_live_active()) |
| 100 | return NULL; |
| 101 | #endif |
| 102 | return node.np; |
| 103 | } |
| 104 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 105 | /** |
| 106 | * ofnode_to_offset() - convert an ofnode to a flat DT offset |
| 107 | * |
| 108 | * This cannot be called if the reference contains a node pointer. |
| 109 | * |
| 110 | * @node: Reference containing offset (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 111 | * Return: DT offset (can be -1) |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 112 | */ |
| 113 | static inline int ofnode_to_offset(ofnode node) |
| 114 | { |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 115 | #ifdef OF_CHECKS |
| 116 | if (of_live_active()) |
| 117 | return -1; |
| 118 | #endif |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 119 | return node.of_offset; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * ofnode_valid() - check if an ofnode is valid |
| 124 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 125 | * @node: Reference containing offset (possibly invalid) |
| 126 | * Return: true if the reference contains a valid ofnode, false if it is NULL |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 127 | */ |
| 128 | static inline bool ofnode_valid(ofnode node) |
| 129 | { |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 130 | if (of_live_active()) |
| 131 | return node.np != NULL; |
| 132 | else |
Patrick Delaunay | 04fcfe7 | 2020-09-24 17:26:20 +0200 | [diff] [blame] | 133 | return node.of_offset >= 0; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * offset_to_ofnode() - convert a DT offset to an ofnode |
| 138 | * |
| 139 | * @of_offset: DT offset (either valid, or -1) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 140 | * Return: reference to the associated DT offset |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 141 | */ |
| 142 | static inline ofnode offset_to_ofnode(int of_offset) |
| 143 | { |
| 144 | ofnode node; |
| 145 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 146 | if (of_live_active()) |
| 147 | node.np = NULL; |
| 148 | else |
Simon Glass | 1ab8b89 | 2019-12-06 21:41:36 -0700 | [diff] [blame] | 149 | node.of_offset = of_offset >= 0 ? of_offset : -1; |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 150 | |
| 151 | return node; |
| 152 | } |
| 153 | |
| 154 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 155 | * np_to_ofnode() - convert a node pointer to an ofnode |
| 156 | * |
| 157 | * @np: Live node pointer (can be NULL) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 158 | * Return: reference to the associated node pointer |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 159 | */ |
| 160 | static inline ofnode np_to_ofnode(const struct device_node *np) |
| 161 | { |
| 162 | ofnode node; |
| 163 | |
| 164 | node.np = np; |
| 165 | |
| 166 | return node; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * ofnode_is_np() - check if a reference is a node pointer |
| 171 | * |
| 172 | * This function associated that if there is a valid live tree then all |
| 173 | * references will use it. This is because using the flat DT when the live tree |
| 174 | * is valid is not permitted. |
| 175 | * |
| 176 | * @node: reference to check (possibly invalid) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 177 | * 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] | 178 | * offset |
| 179 | */ |
| 180 | static inline bool ofnode_is_np(ofnode node) |
| 181 | { |
| 182 | #ifdef OF_CHECKS |
| 183 | /* |
| 184 | * Check our assumption that flat tree offsets are not used when a |
| 185 | * live tree is in use. |
| 186 | */ |
| 187 | assert(!ofnode_valid(node) || |
Stefan Roese | c14df8b | 2020-09-23 08:23:27 +0200 | [diff] [blame] | 188 | (of_live_active() ? ofnode_to_np(node) |
| 189 | : ofnode_to_np(node))); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 190 | #endif |
| 191 | return of_live_active() && ofnode_valid(node); |
| 192 | } |
| 193 | |
| 194 | /** |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 195 | * ofnode_equal() - check if two references are equal |
| 196 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 197 | * @ref1: first reference to check (possibly invalid) |
| 198 | * @ref2: second reference to check (possibly invalid) |
| 199 | * Return: true if equal, else false |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 200 | */ |
| 201 | static inline bool ofnode_equal(ofnode ref1, ofnode ref2) |
| 202 | { |
| 203 | /* We only need to compare the contents */ |
| 204 | return ref1.of_offset == ref2.of_offset; |
| 205 | } |
| 206 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 207 | /** |
| 208 | * ofnode_null() - Obtain a null ofnode |
| 209 | * |
| 210 | * This returns an ofnode which points to no node. It works both with the flat |
| 211 | * tree and livetree. |
| 212 | */ |
| 213 | static inline ofnode ofnode_null(void) |
| 214 | { |
| 215 | ofnode node; |
| 216 | |
| 217 | if (of_live_active()) |
| 218 | node.np = NULL; |
| 219 | else |
| 220 | node.of_offset = -1; |
| 221 | |
| 222 | return node; |
| 223 | } |
| 224 | |
Simon Glass | 278ddba | 2020-11-28 17:50:07 -0700 | [diff] [blame] | 225 | static inline ofnode ofnode_root(void) |
| 226 | { |
| 227 | ofnode node; |
| 228 | |
| 229 | if (of_live_active()) |
| 230 | node.np = gd_of_root(); |
| 231 | else |
| 232 | node.of_offset = 0; |
| 233 | |
| 234 | return node; |
| 235 | } |
| 236 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 237 | /** |
Kishon Vijay Abraham I | d6388f2 | 2021-07-21 21:28:30 +0530 | [diff] [blame] | 238 | * ofnode_name_eq() - Check if the node name is equivalent to a given name |
| 239 | * ignoring the unit address |
| 240 | * |
| 241 | * @node: valid node reference that has to be compared |
| 242 | * @name: name that has to be compared with the node name |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 243 | * Return: true if matches, false if it doesn't match |
Kishon Vijay Abraham I | d6388f2 | 2021-07-21 21:28:30 +0530 | [diff] [blame] | 244 | */ |
| 245 | bool ofnode_name_eq(ofnode node, const char *name); |
| 246 | |
| 247 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 248 | * ofnode_read_u32() - Read a 32-bit integer from a property |
| 249 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 250 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 251 | * @propname: name of the property to read from |
| 252 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 253 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 254 | */ |
| 255 | int ofnode_read_u32(ofnode node, const char *propname, u32 *outp); |
| 256 | |
| 257 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 258 | * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property |
| 259 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 260 | * @node: valid node reference to read property from |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 261 | * @propname: name of the property to read from |
| 262 | * @index: index of the integer to return |
| 263 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 264 | * Return: 0 if OK, -ve on error |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 265 | */ |
| 266 | int ofnode_read_u32_index(ofnode node, const char *propname, int index, |
| 267 | u32 *outp); |
| 268 | |
| 269 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 270 | * ofnode_read_s32() - Read a 32-bit integer from a property |
| 271 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 272 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 273 | * @propname: name of the property to read from |
| 274 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 275 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 276 | */ |
| 277 | static inline int ofnode_read_s32(ofnode node, const char *propname, |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 278 | s32 *outp) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 279 | { |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 280 | return ofnode_read_u32(node, propname, (u32 *)outp); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * ofnode_read_u32_default() - Read a 32-bit integer from a property |
| 285 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 286 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 287 | * @propname: name of the property to read from |
| 288 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 289 | * Return: property value, or @def if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 290 | */ |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 291 | u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 292 | |
| 293 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 294 | * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value |
| 295 | * property |
| 296 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 297 | * @node: valid node reference to read property from |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 298 | * @propname: name of the property to read from |
| 299 | * @index: index of the integer to return |
| 300 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 301 | * Return: property value, or @def if not found |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 302 | */ |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 303 | 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] | 304 | u32 def); |
| 305 | |
| 306 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 307 | * ofnode_read_s32_default() - Read a 32-bit integer from a property |
| 308 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 309 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 310 | * @propname: name of the property to read from |
| 311 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 312 | * Return: property value, or @def if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 313 | */ |
| 314 | int ofnode_read_s32_default(ofnode node, const char *propname, s32 def); |
| 315 | |
| 316 | /** |
Lukas Auer | b03a60b | 2018-11-22 11:26:35 +0100 | [diff] [blame] | 317 | * ofnode_read_u64() - Read a 64-bit integer from a property |
| 318 | * |
| 319 | * @node: valid node reference to read property from |
| 320 | * @propname: name of the property to read from |
| 321 | * @outp: place to put value (if found) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 322 | * Return: 0 if OK, -ve on error |
Lukas Auer | b03a60b | 2018-11-22 11:26:35 +0100 | [diff] [blame] | 323 | */ |
| 324 | int ofnode_read_u64(ofnode node, const char *propname, u64 *outp); |
| 325 | |
| 326 | /** |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 327 | * ofnode_read_u64_default() - Read a 64-bit integer from a property |
| 328 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 329 | * @node: valid node reference to read property from |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 330 | * @propname: name of the property to read from |
| 331 | * @def: default value to return if the property has no value |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 332 | * Return: property value, or @def if not found |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 333 | */ |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 334 | u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def); |
Simon Glass | 9d54a7a | 2018-06-11 13:07:10 -0600 | [diff] [blame] | 335 | |
| 336 | /** |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 337 | * ofnode_read_prop() - Read a property from a node |
| 338 | * |
| 339 | * @node: valid node reference to read property from |
| 340 | * @propname: name of the property to read |
| 341 | * @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] | 342 | * if not found |
| 343 | * Return: property value, or NULL if there is no such property |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 344 | */ |
| 345 | const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep); |
| 346 | |
| 347 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 348 | * ofnode_read_string() - Read a string from a property |
| 349 | * |
Simon Glass | 0c2e980 | 2020-01-27 08:49:44 -0700 | [diff] [blame] | 350 | * @node: valid node reference to read property from |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 351 | * @propname: name of the property to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 352 | * 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] | 353 | */ |
| 354 | const char *ofnode_read_string(ofnode node, const char *propname); |
| 355 | |
| 356 | /** |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 357 | * 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] | 358 | * |
| 359 | * @node: valid node reference to read property from |
| 360 | * @propname: name of the property to read |
| 361 | * @out_values: pointer to return value, modified only if return value is 0 |
| 362 | * @sz: number of array elements to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 363 | * Return: 0 if OK, -ve on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 364 | * |
| 365 | * Search for a property in a device node and read 32-bit value(s) from |
| 366 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
| 367 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 368 | * property data isn't large enough. |
| 369 | * |
| 370 | * The out_values is modified only if a valid u32 value can be decoded. |
| 371 | */ |
| 372 | int ofnode_read_u32_array(ofnode node, const char *propname, |
| 373 | u32 *out_values, size_t sz); |
| 374 | |
| 375 | /** |
| 376 | * ofnode_read_bool() - read a boolean value from a property |
| 377 | * |
| 378 | * @node: valid node reference to read property from |
| 379 | * @propname: name of property to read |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 380 | * Return: true if property is present (meaning true), false if not present |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 381 | */ |
| 382 | bool ofnode_read_bool(ofnode node, const char *propname); |
| 383 | |
| 384 | /** |
| 385 | * ofnode_find_subnode() - find a named subnode of a parent node |
| 386 | * |
| 387 | * @node: valid reference to parent node |
| 388 | * @subnode_name: name of subnode to find |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 389 | * 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] | 390 | * subnode) |
| 391 | */ |
| 392 | ofnode ofnode_find_subnode(ofnode node, const char *subnode_name); |
| 393 | |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 394 | #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE) |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 395 | #include <asm/global_data.h> |
| 396 | |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 397 | static inline bool ofnode_is_enabled(ofnode node) |
| 398 | { |
| 399 | if (ofnode_is_np(node)) { |
| 400 | return of_device_is_available(ofnode_to_np(node)); |
| 401 | } else { |
| 402 | return fdtdec_get_is_enabled(gd->fdt_blob, |
| 403 | ofnode_to_offset(node)); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | static inline ofnode ofnode_first_subnode(ofnode node) |
| 408 | { |
| 409 | assert(ofnode_valid(node)); |
| 410 | if (ofnode_is_np(node)) |
| 411 | return np_to_ofnode(node.np->child); |
| 412 | |
| 413 | return offset_to_ofnode( |
| 414 | fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node))); |
| 415 | } |
| 416 | |
| 417 | static inline ofnode ofnode_next_subnode(ofnode node) |
| 418 | { |
| 419 | assert(ofnode_valid(node)); |
| 420 | if (ofnode_is_np(node)) |
| 421 | return np_to_ofnode(node.np->sibling); |
| 422 | |
| 423 | return offset_to_ofnode( |
| 424 | fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node))); |
| 425 | } |
| 426 | #else |
| 427 | /** |
| 428 | * ofnode_is_enabled() - Checks whether a node is enabled. |
| 429 | * This looks for a 'status' property. If this exists, then returns true if |
| 430 | * the status is 'okay' and false otherwise. If there is no status property, |
| 431 | * it returns true on the assumption that anything mentioned should be enabled |
| 432 | * by default. |
| 433 | * |
| 434 | * @node: node to examine |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 435 | * Return: false (not enabled) or true (enabled) |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 436 | */ |
| 437 | bool ofnode_is_enabled(ofnode node); |
| 438 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 439 | /** |
| 440 | * ofnode_first_subnode() - find the first subnode of a parent node |
| 441 | * |
| 442 | * @node: valid reference to a valid parent node |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 443 | * 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] | 444 | * node has no subnodes) |
| 445 | */ |
| 446 | ofnode ofnode_first_subnode(ofnode node); |
| 447 | |
| 448 | /** |
| 449 | * ofnode_next_subnode() - find the next sibling of a subnode |
| 450 | * |
| 451 | * @node: valid reference to previous node (sibling) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 452 | * 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] | 453 | * has no more siblings) |
| 454 | */ |
| 455 | ofnode ofnode_next_subnode(ofnode node); |
Simon Glass | 39f1d28 | 2020-12-16 17:25:06 -0700 | [diff] [blame] | 456 | #endif /* DM_INLINE_OFNODE */ |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 457 | |
| 458 | /** |
Philipp Tomsich | 6fce1dd | 2018-02-23 17:38:49 +0100 | [diff] [blame] | 459 | * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode) |
| 460 | * |
| 461 | * @node: valid node to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 462 | * Return: ofnode reference of the parent node |
Philipp Tomsich | 6fce1dd | 2018-02-23 17:38:49 +0100 | [diff] [blame] | 463 | */ |
| 464 | ofnode ofnode_get_parent(ofnode node); |
| 465 | |
| 466 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 467 | * ofnode_get_name() - get the name of a node |
| 468 | * |
| 469 | * @node: valid node to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 470 | * Return: name of node |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 471 | */ |
| 472 | const char *ofnode_get_name(ofnode node); |
| 473 | |
| 474 | /** |
Marek Behún | e897e3c | 2021-05-26 14:08:18 +0200 | [diff] [blame] | 475 | * ofnode_get_path() - get the full path of a node |
| 476 | * |
| 477 | * @node: valid node to look up |
| 478 | * @buf: buffer to write the node path into |
| 479 | * @buflen: buffer size |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 480 | * Return: 0 if OK, -ve on error |
Marek Behún | e897e3c | 2021-05-26 14:08:18 +0200 | [diff] [blame] | 481 | */ |
| 482 | int ofnode_get_path(ofnode node, char *buf, int buflen); |
| 483 | |
| 484 | /** |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 485 | * ofnode_get_by_phandle() - get ofnode from phandle |
| 486 | * |
| 487 | * @phandle: phandle to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 488 | * Return: ofnode reference to the phandle |
Kever Yang | 37df0e0 | 2018-02-23 17:38:50 +0100 | [diff] [blame] | 489 | */ |
| 490 | ofnode ofnode_get_by_phandle(uint phandle); |
| 491 | |
| 492 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 493 | * ofnode_read_size() - read the size of a property |
| 494 | * |
| 495 | * @node: node to check |
| 496 | * @propname: property to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 497 | * Return: size of property if present, or -EINVAL if not |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 498 | */ |
| 499 | int ofnode_read_size(ofnode node, const char *propname); |
| 500 | |
| 501 | /** |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 502 | * ofnode_get_addr_size_index() - get an address/size from a node |
| 503 | * based on index |
| 504 | * |
| 505 | * This reads the register address/size from a node based on index |
| 506 | * |
| 507 | * @node: node to read from |
| 508 | * @index: Index of address to read (0 for first) |
| 509 | * @size: Pointer to size of the address |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 510 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Keerthy | d332e6e | 2019-04-24 17:19:53 +0530 | [diff] [blame] | 511 | */ |
| 512 | phys_addr_t ofnode_get_addr_size_index(ofnode node, int index, |
| 513 | fdt_size_t *size); |
| 514 | |
| 515 | /** |
Marek Behún | 177ab7f | 2021-05-26 14:08:17 +0200 | [diff] [blame] | 516 | * ofnode_get_addr_size_index_notrans() - get an address/size from a node |
| 517 | * based on index, without address |
| 518 | * translation |
| 519 | * |
| 520 | * This reads the register address/size from a node based on index. |
| 521 | * The resulting address is not translated. Useful for example for on-disk |
| 522 | * addresses. |
| 523 | * |
| 524 | * @node: node to read from |
| 525 | * @index: Index of address to read (0 for first) |
| 526 | * @size: Pointer to size of the address |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 527 | * 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] | 528 | */ |
| 529 | phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index, |
| 530 | fdt_size_t *size); |
| 531 | |
| 532 | /** |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 533 | * ofnode_get_addr_index() - get an address from a node |
| 534 | * |
| 535 | * This reads the register address from a node |
| 536 | * |
| 537 | * @node: node to read from |
| 538 | * @index: Index of address to read (0 for first) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 539 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 540 | */ |
| 541 | phys_addr_t ofnode_get_addr_index(ofnode node, int index); |
| 542 | |
| 543 | /** |
| 544 | * ofnode_get_addr() - get an address from a node |
| 545 | * |
| 546 | * This reads the register address from a node |
| 547 | * |
| 548 | * @node: node to read from |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 549 | * Return: address, or FDT_ADDR_T_NONE if not present or invalid |
Simon Glass | 049ae1b | 2017-05-18 20:09:01 -0600 | [diff] [blame] | 550 | */ |
| 551 | phys_addr_t ofnode_get_addr(ofnode node); |
| 552 | |
| 553 | /** |
Chen Guanqiao | 223f17d | 2021-04-12 14:51:11 +0800 | [diff] [blame] | 554 | * ofnode_get_size() - get size from a node |
| 555 | * |
| 556 | * This reads the register size from a node |
| 557 | * |
| 558 | * @node: node to read from |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 559 | * 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] | 560 | */ |
| 561 | fdt_size_t ofnode_get_size(ofnode node); |
| 562 | |
| 563 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 564 | * ofnode_stringlist_search() - find a string in a string list and return index |
| 565 | * |
| 566 | * Note that it is possible for this function to succeed on property values |
| 567 | * that are not NUL-terminated. That's because the function will stop after |
| 568 | * finding the first occurrence of @string. This can for example happen with |
| 569 | * small-valued cell properties, such as #address-cells, when searching for |
| 570 | * the empty string. |
| 571 | * |
| 572 | * @node: node to check |
| 573 | * @propname: name of the property containing the string list |
| 574 | * @string: string to look up in the string list |
| 575 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 576 | * Return: |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 577 | * the index of the string in the list of strings |
| 578 | * -ENODATA if the property is not found |
| 579 | * -EINVAL on some other error |
| 580 | */ |
| 581 | int ofnode_stringlist_search(ofnode node, const char *propname, |
| 582 | const char *string); |
| 583 | |
| 584 | /** |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 585 | * ofnode_read_string_index() - obtain an indexed string from a string list |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 586 | * |
| 587 | * Note that this will successfully extract strings from properties with |
| 588 | * non-NUL-terminated values. For example on small-valued cell properties |
| 589 | * this function will return the empty string. |
| 590 | * |
| 591 | * If non-NULL, the length of the string (on success) or a negative error-code |
| 592 | * (on failure) will be stored in the integer pointer to by lenp. |
| 593 | * |
| 594 | * @node: node to check |
| 595 | * @propname: name of the property containing the string list |
Simon Glass | 7a3a167 | 2021-10-23 17:26:06 -0600 | [diff] [blame] | 596 | * @index: index of the string to return (cannot be negative) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 597 | * @outp: return location for the string |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 598 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 599 | * Return: |
Simon Glass | 7a3a167 | 2021-10-23 17:26:06 -0600 | [diff] [blame] | 600 | * 0 if found or -ve error value if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 601 | */ |
| 602 | int ofnode_read_string_index(ofnode node, const char *propname, int index, |
| 603 | const char **outp); |
| 604 | |
| 605 | /** |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 606 | * ofnode_read_string_count() - find the number of strings in a string list |
| 607 | * |
| 608 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 609 | * @property: name of the property containing the string list |
| 610 | * Return: |
Simon Glass | 5fdb005 | 2017-06-12 06:21:28 -0600 | [diff] [blame] | 611 | * number of strings in the list, or -ve error value if not found |
| 612 | */ |
| 613 | int ofnode_read_string_count(ofnode node, const char *property); |
| 614 | |
| 615 | /** |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 616 | * ofnode_read_string_list() - read a list of strings |
| 617 | * |
| 618 | * This produces a list of string pointers with each one pointing to a string |
| 619 | * in the string list. If the property does not exist, it returns {NULL}. |
| 620 | * |
| 621 | * The data is allocated and the caller is reponsible for freeing the return |
| 622 | * value (the list of string pointers). The strings themselves may not be |
| 623 | * changed as they point directly into the devicetree property. |
| 624 | * |
| 625 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 626 | * @property: name of the property containing the string list |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 627 | * @listp: returns an allocated, NULL-terminated list of strings if the return |
| 628 | * value is > 0, else is set to NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 629 | * Return: |
| 630 | * number of strings in list, 0 if none, -ENOMEM if out of memory, |
| 631 | * -EINVAL if no such property, -EENODATA if property is empty |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 632 | */ |
| 633 | int ofnode_read_string_list(ofnode node, const char *property, |
| 634 | const char ***listp); |
| 635 | |
| 636 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 637 | * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list |
| 638 | * |
| 639 | * This function is useful to parse lists of phandles and their arguments. |
| 640 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 641 | * errno value. |
| 642 | * |
| 643 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 644 | * pointer. |
| 645 | * |
| 646 | * Example: |
| 647 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 648 | * .. code-block:: |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 649 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 650 | * phandle1: node1 { |
| 651 | * #list-cells = <2>; |
| 652 | * }; |
| 653 | * phandle2: node2 { |
| 654 | * #list-cells = <1>; |
| 655 | * }; |
| 656 | * node3 { |
| 657 | * list = <&phandle1 1 2 &phandle2 3>; |
| 658 | * }; |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 659 | * |
| 660 | * To get a device_node of the `node2' node you may call this: |
| 661 | * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args); |
| 662 | * |
| 663 | * @node: device tree node containing a list |
| 664 | * @list_name: property name that contains a list |
| 665 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 666 | * @cell_count: Cell count to use if @cells_name is NULL |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 667 | * @index: index of a phandle to parse out |
| 668 | * @out_args: optional pointer to output arguments structure (will be filled) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 669 | * Return: |
| 670 | * 0 on success (with @out_args filled out if not NULL), -ENOENT if |
| 671 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 672 | * @cells_name could not be found, the arguments were truncated or there |
| 673 | * were too many arguments. |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 674 | */ |
| 675 | int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, |
| 676 | const char *cells_name, int cell_count, |
| 677 | int index, |
| 678 | struct ofnode_phandle_args *out_args); |
| 679 | |
| 680 | /** |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 681 | * ofnode_count_phandle_with_args() - Count number of phandle in a list |
| 682 | * |
| 683 | * This function is useful to count phandles into a list. |
| 684 | * Returns number of phandle on success, on error returns appropriate |
| 685 | * errno value. |
| 686 | * |
| 687 | * @node: device tree node containing a list |
| 688 | * @list_name: property name that contains a list |
| 689 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 690 | * @cell_count: Cell count to use if @cells_name is NULL |
| 691 | * Return: |
| 692 | * number of phandle on success, -ENOENT if @list_name does not exist, |
| 693 | * -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] | 694 | */ |
| 695 | int ofnode_count_phandle_with_args(ofnode node, const char *list_name, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 696 | const char *cells_name, int cell_count); |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 697 | |
| 698 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 699 | * ofnode_path() - find a node by full path |
| 700 | * |
| 701 | * @path: Full path to node, e.g. "/bus/spi@1" |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 702 | * 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] | 703 | */ |
| 704 | ofnode ofnode_path(const char *path); |
| 705 | |
| 706 | /** |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 707 | * ofnode_read_chosen_prop() - get the value of a chosen property |
| 708 | * |
| 709 | * This looks for a property within the /chosen node and returns its value |
| 710 | * |
| 711 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 712 | * @sizep: Returns size of property, or `FDT_ERR_...` error code if function |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 713 | * returns NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 714 | * Return: property value if found, else NULL |
Simon Glass | e09223c | 2020-01-27 08:49:46 -0700 | [diff] [blame] | 715 | */ |
| 716 | const void *ofnode_read_chosen_prop(const char *propname, int *sizep); |
| 717 | |
| 718 | /** |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 719 | * ofnode_read_chosen_string() - get the string value of a chosen property |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 720 | * |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 721 | * This looks for a property within the /chosen node and returns its value, |
| 722 | * checking that it is a valid nul-terminated string |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 723 | * |
| 724 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 725 | * Return: string value if found, else NULL |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 726 | */ |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 727 | const char *ofnode_read_chosen_string(const char *propname); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 728 | |
| 729 | /** |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 730 | * ofnode_get_chosen_node() - get a referenced node from the chosen node |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 731 | * |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 732 | * This looks up a named property in the chosen node and uses that as a path to |
| 733 | * look up a code. |
| 734 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 735 | * @propname: Property name to look for |
| 736 | * Return: the referenced node if present, else ofnode_null() |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 737 | */ |
Simon Glass | c99ba91 | 2020-01-27 08:49:42 -0700 | [diff] [blame] | 738 | ofnode ofnode_get_chosen_node(const char *propname); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 739 | |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 740 | /** |
| 741 | * ofnode_read_aliases_prop() - get the value of a aliases property |
| 742 | * |
| 743 | * This looks for a property within the /aliases node and returns its value |
| 744 | * |
| 745 | * @propname: Property name to look for |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 746 | * @sizep: Returns size of property, or `FDT_ERR_...` error code if function |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 747 | * returns NULL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 748 | * Return: property value if found, else NULL |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 749 | */ |
| 750 | const void *ofnode_read_aliases_prop(const char *propname, int *sizep); |
| 751 | |
| 752 | /** |
| 753 | * ofnode_get_aliases_node() - get a referenced node from the aliases node |
| 754 | * |
| 755 | * This looks up a named property in the aliases node and uses that as a path to |
| 756 | * look up a code. |
| 757 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 758 | * @propname: Property name to look for |
| 759 | * Return: the referenced node if present, else ofnode_null() |
Michal Simek | 92a8862 | 2020-07-28 12:51:08 +0200 | [diff] [blame] | 760 | */ |
| 761 | ofnode ofnode_get_aliases_node(const char *propname); |
| 762 | |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 763 | struct display_timing; |
| 764 | /** |
| 765 | * ofnode_decode_display_timing() - decode display timings |
| 766 | * |
| 767 | * Decode display timings from the supplied 'display-timings' node. |
| 768 | * See doc/device-tree-bindings/video/display-timing.txt for binding |
| 769 | * information. |
| 770 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 771 | * @node: 'display-timing' node containing the timing subnodes |
| 772 | * @index: Index number to read (0=first timing subnode) |
| 773 | * @config: Place to put timings |
| 774 | * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 775 | */ |
| 776 | int ofnode_decode_display_timing(ofnode node, int index, |
| 777 | struct display_timing *config); |
| 778 | |
| 779 | /** |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 780 | * 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] | 781 | * |
| 782 | * @node: node to read |
| 783 | * @propname: property to read |
| 784 | * @lenp: place to put length on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 785 | * Return: pointer to property, or NULL if not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 786 | */ |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 787 | const void *ofnode_get_property(ofnode node, const char *propname, int *lenp); |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 788 | |
| 789 | /** |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 790 | * ofnode_get_first_property()- get the reference of the first property |
| 791 | * |
| 792 | * Get reference to the first property of the node, it is used to iterate |
| 793 | * and read all the property with ofnode_get_property_by_prop(). |
| 794 | * |
| 795 | * @node: node to read |
| 796 | * @prop: place to put argument reference |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 797 | * 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] | 798 | */ |
| 799 | int ofnode_get_first_property(ofnode node, struct ofprop *prop); |
| 800 | |
| 801 | /** |
| 802 | * ofnode_get_next_property() - get the reference of the next property |
| 803 | * |
| 804 | * Get reference to the next property of the node, it is used to iterate |
| 805 | * and read all the property with ofnode_get_property_by_prop(). |
| 806 | * |
| 807 | * @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] | 808 | * 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] | 809 | */ |
| 810 | int ofnode_get_next_property(struct ofprop *prop); |
| 811 | |
| 812 | /** |
| 813 | * ofnode_get_property_by_prop() - get a pointer to the value of a property |
| 814 | * |
| 815 | * Get value for the property identified by the provided reference. |
| 816 | * |
| 817 | * @prop: reference on property |
| 818 | * @propname: If non-NULL, place to property name on success, |
| 819 | * @lenp: If non-NULL, place to put length on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 820 | * 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] | 821 | */ |
| 822 | const void *ofnode_get_property_by_prop(const struct ofprop *prop, |
| 823 | const char **propname, int *lenp); |
| 824 | |
| 825 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 826 | * ofnode_is_available() - check if a node is marked available |
| 827 | * |
| 828 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 829 | * Return: true if node's 'status' property is "okay" (or is missing) |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 830 | */ |
| 831 | bool ofnode_is_available(ofnode node); |
| 832 | |
| 833 | /** |
| 834 | * ofnode_get_addr_size() - get address and size from a property |
| 835 | * |
| 836 | * This does no address translation. It simply reads an property that contains |
| 837 | * an address and a size value, one after the other. |
| 838 | * |
| 839 | * @node: node to read from |
| 840 | * @propname: property to read |
| 841 | * @sizep: place to put size value (on success) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 842 | * Return: address value, or FDT_ADDR_T_NONE on error |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 843 | */ |
| 844 | phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname, |
| 845 | phys_size_t *sizep); |
| 846 | |
| 847 | /** |
| 848 | * ofnode_read_u8_array_ptr() - find an 8-bit array |
| 849 | * |
| 850 | * Look up a property in a node and return a pointer to its contents as a |
| 851 | * byte array of given length. The property must have at least enough data |
| 852 | * for the array (count bytes). It may have more, but this will be ignored. |
| 853 | * The data is not copied. |
| 854 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 855 | * @node: node to examine |
| 856 | * @propname: name of property to find |
| 857 | * @sz: number of array elements |
| 858 | * Return: |
| 859 | * pointer to byte array if found, or NULL if the property is not found or |
| 860 | * there is not enough data |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 861 | */ |
| 862 | const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname, |
| 863 | size_t sz); |
| 864 | |
| 865 | /** |
| 866 | * ofnode_read_pci_addr() - look up a PCI address |
| 867 | * |
| 868 | * Look at an address property in a node and return the PCI address which |
| 869 | * corresponds to the given type in the form of fdt_pci_addr. |
| 870 | * The property must hold one fdt_pci_addr with a lengh. |
| 871 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 872 | * @node: node to examine |
| 873 | * @type: pci address type (FDT_PCI_SPACE_xxx) |
| 874 | * @propname: name of property to find |
| 875 | * @addr: returns pci address in the form of fdt_pci_addr |
| 876 | * Return: |
| 877 | * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the |
| 878 | * format of the property was invalid, -ENXIO if the requested |
| 879 | * address type was not found |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 880 | */ |
| 881 | int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, |
| 882 | const char *propname, struct fdt_pci_addr *addr); |
| 883 | |
| 884 | /** |
Bin Meng | fa15771 | 2018-08-03 01:14:35 -0700 | [diff] [blame] | 885 | * ofnode_read_pci_vendev() - look up PCI vendor and device id |
| 886 | * |
| 887 | * Look at the compatible property of a device node that represents a PCI |
| 888 | * device and extract pci vendor id and device id from it. |
| 889 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 890 | * @node: node to examine |
| 891 | * @vendor: vendor id of the pci device |
| 892 | * @device: device id of the pci device |
| 893 | * Return: 0 if ok, negative on error |
Bin Meng | fa15771 | 2018-08-03 01:14:35 -0700 | [diff] [blame] | 894 | */ |
| 895 | int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device); |
| 896 | |
| 897 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 898 | * ofnode_read_addr_cells() - Get the number of address cells for a node |
| 899 | * |
| 900 | * This walks back up the tree to find the closest #address-cells property |
| 901 | * which controls the given node. |
| 902 | * |
| 903 | * @node: Node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 904 | * Return: number of address cells this node uses |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 905 | */ |
| 906 | int ofnode_read_addr_cells(ofnode node); |
| 907 | |
| 908 | /** |
| 909 | * ofnode_read_size_cells() - Get the number of size cells for a node |
| 910 | * |
| 911 | * This walks back up the tree to find the closest #size-cells property |
| 912 | * which controls the given node. |
| 913 | * |
| 914 | * @node: Node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 915 | * Return: number of size cells this node uses |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 916 | */ |
| 917 | int ofnode_read_size_cells(ofnode node); |
| 918 | |
| 919 | /** |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 920 | * ofnode_read_simple_addr_cells() - Get the address cells property in a node |
| 921 | * |
| 922 | * This function matches fdt_address_cells(). |
| 923 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 924 | * @node: Node to check |
| 925 | * 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] | 926 | */ |
| 927 | int ofnode_read_simple_addr_cells(ofnode node); |
| 928 | |
| 929 | /** |
| 930 | * ofnode_read_simple_size_cells() - Get the size cells property in a node |
| 931 | * |
| 932 | * This function matches fdt_size_cells(). |
| 933 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 934 | * @node: Node to check |
| 935 | * 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] | 936 | */ |
| 937 | int ofnode_read_simple_size_cells(ofnode node); |
| 938 | |
| 939 | /** |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 940 | * ofnode_pre_reloc() - check if a node should be bound before relocation |
| 941 | * |
| 942 | * Device tree nodes can be marked as needing-to-be-bound in the loader stages |
| 943 | * via special device tree properties. |
| 944 | * |
| 945 | * Before relocation this function can be used to check if nodes are required |
| 946 | * in either SPL or TPL stages. |
| 947 | * |
| 948 | * After relocation and jumping into the real U-Boot binary it is possible to |
| 949 | * determine if a node was bound in one of SPL/TPL stages. |
| 950 | * |
Patrick Delaunay | 63e4d11 | 2019-05-21 19:19:13 +0200 | [diff] [blame] | 951 | * There are 4 settings currently in use |
| 952 | * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 953 | * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 954 | * Existing platforms only use it to indicate nodes needed in |
| 955 | * SPL. Should probably be replaced by u-boot,dm-spl for new platforms. |
Patrick Delaunay | 63e4d11 | 2019-05-21 19:19:13 +0200 | [diff] [blame] | 956 | * - u-boot,dm-spl: SPL and U-Boot pre-relocation |
| 957 | * - u-boot,dm-tpl: TPL and U-Boot pre-relocation |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 958 | * |
| 959 | * @node: node to check |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 960 | * Return: true if node is needed in SPL/TL, false otherwise |
Simon Glass | c4fc562 | 2017-05-18 20:08:58 -0600 | [diff] [blame] | 961 | */ |
| 962 | bool ofnode_pre_reloc(ofnode node); |
| 963 | |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 964 | /** |
| 965 | * ofnode_read_resource() - Read a resource from a node |
| 966 | * |
| 967 | * Read resource information from a node at the given index |
| 968 | * |
| 969 | * @node: Node to read from |
| 970 | * @index: Index of resource to read (0 = first) |
| 971 | * @res: Returns resource that was read, on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 972 | * Return: 0 if OK, -ve on error |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 973 | */ |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 974 | int ofnode_read_resource(ofnode node, uint index, struct resource *res); |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 975 | |
| 976 | /** |
| 977 | * ofnode_read_resource_byname() - Read a resource from a node by name |
| 978 | * |
| 979 | * Read resource information from a node matching the given name. This uses a |
| 980 | * 'reg-names' string list property with the names matching the associated |
| 981 | * 'reg' property list. |
| 982 | * |
| 983 | * @node: Node to read from |
| 984 | * @name: Name of resource to read |
| 985 | * @res: Returns resource that was read, on success |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 986 | * Return: 0 if OK, -ve on error |
Simon Glass | a8173d6 | 2018-06-11 13:07:12 -0600 | [diff] [blame] | 987 | */ |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 988 | int ofnode_read_resource_byname(ofnode node, const char *name, |
| 989 | struct resource *res); |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 990 | |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 991 | /** |
Simon Glass | 954eeae | 2018-06-11 13:07:13 -0600 | [diff] [blame] | 992 | * ofnode_by_compatible() - Find the next compatible node |
| 993 | * |
| 994 | * Find the next node after @from that is compatible with @compat |
| 995 | * |
| 996 | * @from: ofnode to start from (use ofnode_null() to start at the beginning) |
| 997 | * @compat: Compatible string to match |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 998 | * Return: ofnode found, or ofnode_null() if none |
Simon Glass | 954eeae | 2018-06-11 13:07:13 -0600 | [diff] [blame] | 999 | */ |
| 1000 | ofnode ofnode_by_compatible(ofnode from, const char *compat); |
| 1001 | |
| 1002 | /** |
Jens Wiklander | 7b68dad | 2018-08-20 11:09:58 +0200 | [diff] [blame] | 1003 | * ofnode_by_prop_value() - Find the next node with given property value |
| 1004 | * |
| 1005 | * Find the next node after @from that has a @propname with a value |
| 1006 | * @propval and a length @proplen. |
| 1007 | * |
| 1008 | * @from: ofnode to start from (use ofnode_null() to start at the |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1009 | * beginning) |
| 1010 | * @propname: property name to check |
| 1011 | * @propval: property value to search for |
| 1012 | * @proplen: length of the value in propval |
| 1013 | * Return: ofnode found, or ofnode_null() if none |
Jens Wiklander | 7b68dad | 2018-08-20 11:09:58 +0200 | [diff] [blame] | 1014 | */ |
| 1015 | ofnode ofnode_by_prop_value(ofnode from, const char *propname, |
| 1016 | const void *propval, int proplen); |
| 1017 | |
| 1018 | /** |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1019 | * ofnode_for_each_subnode() - iterate over all subnodes of a parent |
| 1020 | * |
| 1021 | * @node: child node (ofnode, lvalue) |
| 1022 | * @parent: parent node (ofnode) |
| 1023 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1024 | * 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] | 1025 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1026 | * ofnode node; |
| 1027 | * ofnode_for_each_subnode(node, parent) { |
| 1028 | * Use node |
| 1029 | * ... |
| 1030 | * } |
Simon Glass | 2852976 | 2017-08-05 15:45:54 -0600 | [diff] [blame] | 1031 | * |
| 1032 | * Note that this is implemented as a macro and @node is used as |
| 1033 | * iterator in the loop. The parent variable can be a constant or even a |
| 1034 | * literal. |
| 1035 | */ |
| 1036 | #define ofnode_for_each_subnode(node, parent) \ |
| 1037 | for (node = ofnode_first_subnode(parent); \ |
| 1038 | ofnode_valid(node); \ |
| 1039 | node = ofnode_next_subnode(node)) |
| 1040 | |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1041 | /** |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1042 | * ofnode_for_each_compatible_node() - iterate over all nodes with a given |
| 1043 | * compatible string |
| 1044 | * |
| 1045 | * @node: child node (ofnode, lvalue) |
| 1046 | * @compat: compatible string to match |
| 1047 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1048 | * 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] | 1049 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1050 | * ofnode node; |
| 1051 | * ofnode_for_each_compatible_node(node, parent, compatible) { |
| 1052 | * Use node |
| 1053 | * ... |
| 1054 | * } |
Michael Walle | a7b9df2 | 2021-10-15 15:15:17 +0200 | [diff] [blame] | 1055 | * |
| 1056 | * Note that this is implemented as a macro and @node is used as |
| 1057 | * iterator in the loop. |
| 1058 | */ |
| 1059 | #define ofnode_for_each_compatible_node(node, compat) \ |
| 1060 | for (node = ofnode_by_compatible(ofnode_null(), compat); \ |
| 1061 | ofnode_valid(node); \ |
| 1062 | node = ofnode_by_compatible(node, compat)) |
| 1063 | |
| 1064 | /** |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1065 | * ofnode_get_child_count() - get the child count of a ofnode |
| 1066 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1067 | * @parent: valid node to get its child count |
| 1068 | * Return: the number of subnodes |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1069 | */ |
| 1070 | int ofnode_get_child_count(ofnode parent); |
| 1071 | |
| 1072 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1073 | * ofnode_translate_address() - Translate a device-tree address |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1074 | * |
| 1075 | * Translate an address from the device-tree into a CPU physical address. This |
| 1076 | * function walks up the tree and applies the various bus mappings along the |
| 1077 | * way. |
| 1078 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1079 | * @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] | 1080 | * @in_addr: pointer to the address to translate |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1081 | * Return: the translated address; OF_BAD_ADDR on error |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1082 | */ |
| 1083 | u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr); |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1084 | |
| 1085 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1086 | * ofnode_translate_dma_address() - Translate a device-tree DMA address |
| 1087 | * |
| 1088 | * Translate a DMA address from the device-tree into a CPU physical address. |
| 1089 | * This function walks up the tree and applies the various bus mappings along |
| 1090 | * the way. |
| 1091 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1092 | * @node: Device tree node giving the context in which to translate the |
| 1093 | * DMA address |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1094 | * @in_addr: pointer to the DMA address to translate |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1095 | * Return: the translated DMA address; OF_BAD_ADDR on error |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1096 | */ |
| 1097 | u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr); |
| 1098 | |
| 1099 | /** |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1100 | * ofnode_get_dma_range() - get dma-ranges for a specific DT node |
| 1101 | * |
| 1102 | * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and |
| 1103 | * cpu->bus address translations |
| 1104 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1105 | * @node: Device tree node |
| 1106 | * @cpu: Pointer to variable storing the range's cpu address |
| 1107 | * @bus: Pointer to variable storing the range's bus address |
| 1108 | * @size: Pointer to variable storing the range's size |
| 1109 | * Return: translated DMA address or OF_BAD_ADDR on error |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1110 | */ |
| 1111 | int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, |
| 1112 | u64 *size); |
| 1113 | |
| 1114 | /** |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1115 | * ofnode_device_is_compatible() - check if the node is compatible with compat |
| 1116 | * |
| 1117 | * This allows to check whether the node is comaptible with the compat. |
| 1118 | * |
| 1119 | * @node: Device tree node for which compatible needs to be verified. |
| 1120 | * @compat: Compatible string which needs to verified in the given node. |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1121 | * Return: true if OK, false if the compatible is not found |
Masahiro Yamada | 9349bcc | 2018-04-19 12:14:02 +0900 | [diff] [blame] | 1122 | */ |
| 1123 | int ofnode_device_is_compatible(ofnode node, const char *compat); |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1124 | |
| 1125 | /** |
| 1126 | * ofnode_write_prop() - Set a property of a ofnode |
| 1127 | * |
| 1128 | * Note that the value passed to the function is *not* allocated by the |
| 1129 | * function itself, but must be allocated by the caller if necessary. |
| 1130 | * |
| 1131 | * @node: The node for whose property should be set |
| 1132 | * @propname: The name of the property to set |
| 1133 | * @len: The length of the new value of the property |
| 1134 | * @value: The new value of the property (must be valid prior to calling |
| 1135 | * the function) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1136 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1137 | */ |
| 1138 | int ofnode_write_prop(ofnode node, const char *propname, int len, |
| 1139 | const void *value); |
| 1140 | |
| 1141 | /** |
| 1142 | * ofnode_write_string() - Set a string property of a ofnode |
| 1143 | * |
| 1144 | * Note that the value passed to the function is *not* allocated by the |
| 1145 | * function itself, but must be allocated by the caller if necessary. |
| 1146 | * |
| 1147 | * @node: The node for whose string property should be set |
| 1148 | * @propname: The name of the string property to set |
| 1149 | * @value: The new value of the string property (must be valid prior to |
| 1150 | * calling the function) |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1151 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1152 | */ |
| 1153 | int ofnode_write_string(ofnode node, const char *propname, const char *value); |
| 1154 | |
| 1155 | /** |
| 1156 | * ofnode_set_enabled() - Enable or disable a device tree node given by its |
| 1157 | * ofnode |
| 1158 | * |
| 1159 | * This function effectively sets the node's "status" property to either "okay" |
| 1160 | * or "disable", hence making it available for driver model initialization or |
| 1161 | * not. |
| 1162 | * |
| 1163 | * @node: The node to enable |
| 1164 | * @value: Flag that tells the function to either disable or enable the |
| 1165 | * node |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1166 | * Return: 0 if successful, -ve on error |
Mario Six | 047dafc | 2018-06-26 08:46:48 +0200 | [diff] [blame] | 1167 | */ |
| 1168 | int ofnode_set_enabled(ofnode node, bool value); |
| 1169 | |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1170 | /** |
| 1171 | * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config |
| 1172 | * |
| 1173 | * This reads a property from the /config node of the devicetree. |
| 1174 | * |
| 1175 | * See doc/config.txt for bindings |
| 1176 | * |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1177 | * @prop_name: property name to look up |
| 1178 | * Return: true, if it exists, false if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1179 | */ |
| 1180 | bool ofnode_conf_read_bool(const char *prop_name); |
| 1181 | |
| 1182 | /** |
| 1183 | * ofnode_conf_read_int() - Read an integer value from the U-Boot config |
| 1184 | * |
| 1185 | * This reads a property from the /config node of the devicetree. |
| 1186 | * |
| 1187 | * See doc/config.txt for bindings |
| 1188 | * |
| 1189 | * @prop_name: property name to look up |
| 1190 | * @default_val: default value to return if the property is not found |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1191 | * Return: integer value, if found, or @default_val if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1192 | */ |
| 1193 | int ofnode_conf_read_int(const char *prop_name, int default_val); |
| 1194 | |
| 1195 | /** |
| 1196 | * ofnode_conf_read_str() - Read a string value from the U-Boot config |
| 1197 | * |
| 1198 | * This reads a property from the /config node of the devicetree. |
| 1199 | * |
| 1200 | * See doc/config.txt for bindings |
| 1201 | * |
| 1202 | * @prop_name: property name to look up |
Patrick Delaunay | 92c1c5c | 2022-01-12 10:53:49 +0100 | [diff] [blame] | 1203 | * Return: string value, if found, or NULL if not |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1204 | */ |
| 1205 | const char *ofnode_conf_read_str(const char *prop_name); |
| 1206 | |
Simon Glass | 9a14860 | 2017-05-17 17:18:10 -0600 | [diff] [blame] | 1207 | #endif |