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