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