blob: 0f38b3e736de415dcd206587340b0424afaff29d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass4984de22017-05-17 17:18:10 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass4984de22017-05-17 17:18:10 -06005 */
6
7#ifndef _DM_OFNODE_H
8#define _DM_OFNODE_H
9
Simon Glass9e512042017-05-18 20:08:58 -060010/* TODO(sjg@chromium.org): Drop fdtdec.h include */
11#include <fdtdec.h>
12#include <dm/of.h>
Simon Glassec1add12020-12-16 17:25:06 -070013#include <dm/of_access.h>
Stefan Roese45dbe752020-09-23 08:23:27 +020014#include <log.h>
Marek Behún123ca112022-04-07 00:33:01 +020015#include <phy_interface.h>
Simon Glass9e512042017-05-18 20:08:58 -060016
17/* Enable checks to protect against invalid calls */
18#undef OF_CHECKS
19
Simon Glassdcf98852017-07-25 08:29:55 -060020struct resource;
21
Simon Glass5063ced2022-07-30 15:52:06 -060022#include <dm/ofnode_decl.h>
Simon Glass4984de22017-05-17 17:18:10 -060023
Simon Glass9e512042017-05-18 20:08:58 -060024struct ofnode_phandle_args {
25 ofnode node;
26 int args_count;
27 uint32_t args[OF_MAX_PHANDLE_ARGS];
28};
29
Simon Glass92291652022-09-06 20:27:26 -060030#if CONFIG_IS_ENABLED(OFNODE_MULTI_TREE)
Simon Glass9e512042017-05-18 20:08:58 -060031/**
Simon Glassee88ba72022-09-06 20:27:19 -060032 * oftree_reset() - reset the state of the oftree list
33 *
34 * Reset the oftree list so it can be started again. This should be called
35 * once the control FDT is in place, but before the ofnode interface is used.
36 */
Simon Glass92291652022-09-06 20:27:26 -060037void oftree_reset(void);
Simon Glassee88ba72022-09-06 20:27:19 -060038
39/**
Simon Glassa3f50d02022-09-06 20:27:20 -060040 * ofnode_to_fdt() - convert an ofnode to a flat DT pointer
41 *
42 * This cannot be called if the reference contains a node pointer.
43 *
44 * @node: Reference containing offset (possibly invalid)
45 * Return: DT offset (can be NULL)
46 */
Simon Glass92291652022-09-06 20:27:26 -060047__attribute_const__ void *ofnode_to_fdt(ofnode node);
Simon Glassa3f50d02022-09-06 20:27:20 -060048
49/**
Simon Glass2187cb72022-09-06 20:27:23 -060050 * ofnode_to_offset() - convert an ofnode to a flat DT offset
51 *
52 * This cannot be called if the reference contains a node pointer.
53 *
54 * @node: Reference containing offset (possibly invalid)
55 * Return: DT offset (can be -1)
56 */
Simon Glass92291652022-09-06 20:27:26 -060057__attribute_const__ int ofnode_to_offset(ofnode node);
58
59/**
60 * oftree_from_fdt() - Returns an oftree from a flat device tree pointer
61 *
Simon Glasse7a18f72022-10-11 09:47:19 -060062 * If @fdt is not already registered in the list of current device trees, it is
63 * added to the list.
64 *
Simon Glass92291652022-09-06 20:27:26 -060065 * @fdt: Device tree to use
66 *
67 * Returns: reference to the given node
68 */
69oftree oftree_from_fdt(void *fdt);
70
71/**
72 * noffset_to_ofnode() - convert a DT offset to an ofnode
73 *
74 * @other_node: Node in the same tree to use as a reference
75 * @of_offset: DT offset (either valid, or -1)
76 * Return: reference to the associated DT offset
77 */
78ofnode noffset_to_ofnode(ofnode other_node, int of_offset);
79
80#else /* !OFNODE_MULTI_TREE */
81static inline void oftree_reset(void) {}
82
83static inline void *ofnode_to_fdt(ofnode node)
84{
85#ifdef OF_CHECKS
86 if (of_live_active())
87 return NULL;
88#endif
89 /* Use the control FDT by default */
90 return (void *)gd->fdt_blob;
91}
92
93static inline __attribute_const__ int ofnode_to_offset(ofnode node)
Simon Glass2187cb72022-09-06 20:27:23 -060094{
95#ifdef OF_CHECKS
96 if (of_live_active())
97 return -1;
98#endif
99 return node.of_offset;
100}
101
Simon Glass92291652022-09-06 20:27:26 -0600102static inline oftree oftree_from_fdt(void *fdt)
103{
104 oftree tree;
105
106 /* we cannot access other trees without OFNODE_MULTI_TREE */
107 if (fdt == gd->fdt_blob)
108 tree.fdt = fdt;
109 else
110 tree.fdt = NULL;
111
112 return tree;
113}
114
115static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset)
116{
117 ofnode node;
118
119 if (of_live_active())
120 node.np = NULL;
121 else
122 node.of_offset = of_offset;
123
124 return node;
125}
126
127#endif /* OFNODE_MULTI_TREE */
128
Simon Glass2187cb72022-09-06 20:27:23 -0600129/**
Stefan Roese45dbe752020-09-23 08:23:27 +0200130 * ofnode_to_np() - convert an ofnode to a live DT node pointer
Simon Glass9e512042017-05-18 20:08:58 -0600131 *
132 * This cannot be called if the reference contains an offset.
133 *
134 * @node: Reference containing struct device_node * (possibly invalid)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100135 * Return: pointer to device node (can be NULL)
Simon Glass9e512042017-05-18 20:08:58 -0600136 */
Simon Glass98306982022-09-06 20:27:04 -0600137static inline struct device_node *ofnode_to_np(ofnode node)
Simon Glass9e512042017-05-18 20:08:58 -0600138{
139#ifdef OF_CHECKS
140 if (!of_live_active())
141 return NULL;
142#endif
143 return node.np;
144}
145
Simon Glass4984de22017-05-17 17:18:10 -0600146/**
Simon Glass4984de22017-05-17 17:18:10 -0600147 * ofnode_valid() - check if an ofnode is valid
148 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100149 * @node: Reference containing offset (possibly invalid)
Simon Glass92291652022-09-06 20:27:26 -0600150 * Return: true if the reference contains a valid ofnode, false if not
Simon Glass4984de22017-05-17 17:18:10 -0600151 */
152static inline bool ofnode_valid(ofnode node)
153{
Simon Glass9e512042017-05-18 20:08:58 -0600154 if (of_live_active())
155 return node.np != NULL;
156 else
Patrick Delaunay6d9949f2020-09-24 17:26:20 +0200157 return node.of_offset >= 0;
Simon Glass4984de22017-05-17 17:18:10 -0600158}
159
160/**
Simon Glass928d2672022-09-06 20:27:22 -0600161 * oftree_lookup_fdt() - obtain the FDT pointer from an oftree
162 *
163 * This can only be called when flat tree is enabled
164 *
165 * @tree: Tree to look at
166 * @return FDT pointer from the tree
167 */
168static inline void *oftree_lookup_fdt(oftree tree)
169{
170 if (of_live_active())
171 return NULL;
172 else
173 return tree.fdt;
174}
175
176/**
Simon Glass4984de22017-05-17 17:18:10 -0600177 * offset_to_ofnode() - convert a DT offset to an ofnode
178 *
179 * @of_offset: DT offset (either valid, or -1)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100180 * Return: reference to the associated DT offset
Simon Glass4984de22017-05-17 17:18:10 -0600181 */
182static inline ofnode offset_to_ofnode(int of_offset)
183{
184 ofnode node;
185
Simon Glass9e512042017-05-18 20:08:58 -0600186 if (of_live_active())
187 node.np = NULL;
188 else
Simon Glassb14c5332019-12-06 21:41:36 -0700189 node.of_offset = of_offset >= 0 ? of_offset : -1;
Simon Glass4984de22017-05-17 17:18:10 -0600190
191 return node;
192}
193
194/**
Simon Glass9e512042017-05-18 20:08:58 -0600195 * np_to_ofnode() - convert a node pointer to an ofnode
196 *
197 * @np: Live node pointer (can be NULL)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100198 * Return: reference to the associated node pointer
Simon Glass9e512042017-05-18 20:08:58 -0600199 */
Simon Glass98306982022-09-06 20:27:04 -0600200static inline ofnode np_to_ofnode(struct device_node *np)
Simon Glass9e512042017-05-18 20:08:58 -0600201{
202 ofnode node;
203
204 node.np = np;
205
206 return node;
207}
208
209/**
210 * ofnode_is_np() - check if a reference is a node pointer
211 *
212 * This function associated that if there is a valid live tree then all
213 * references will use it. This is because using the flat DT when the live tree
214 * is valid is not permitted.
215 *
216 * @node: reference to check (possibly invalid)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100217 * Return: true if the reference is a live node pointer, false if it is a DT
Simon Glass9e512042017-05-18 20:08:58 -0600218 * offset
219 */
220static inline bool ofnode_is_np(ofnode node)
221{
222#ifdef OF_CHECKS
223 /*
224 * Check our assumption that flat tree offsets are not used when a
225 * live tree is in use.
226 */
227 assert(!ofnode_valid(node) ||
Stefan Roese45dbe752020-09-23 08:23:27 +0200228 (of_live_active() ? ofnode_to_np(node)
229 : ofnode_to_np(node)));
Simon Glass9e512042017-05-18 20:08:58 -0600230#endif
231 return of_live_active() && ofnode_valid(node);
232}
233
234/**
Simon Glass4984de22017-05-17 17:18:10 -0600235 * ofnode_equal() - check if two references are equal
236 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100237 * @ref1: first reference to check (possibly invalid)
238 * @ref2: second reference to check (possibly invalid)
239 * Return: true if equal, else false
Simon Glass4984de22017-05-17 17:18:10 -0600240 */
241static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
242{
243 /* We only need to compare the contents */
244 return ref1.of_offset == ref2.of_offset;
245}
246
Simon Glass9e512042017-05-18 20:08:58 -0600247/**
Simon Glass085d5942022-09-06 20:27:21 -0600248 * oftree_valid() - check if an oftree is valid
249 *
250 * @tree: Reference containing oftree
251 * Return: true if the reference contains a valid oftree, false if node
252 */
253static inline bool oftree_valid(oftree tree)
254{
255 if (of_live_active())
256 return tree.np;
257 else
258 return tree.fdt;
259}
260
261/**
262 * oftree_null() - Obtain a null oftree
263 *
264 * This returns an oftree which points to no tree. It works both with the flat
265 * tree and livetree.
266 */
267static inline oftree oftree_null(void)
268{
269 oftree tree;
270
271 if (of_live_active())
272 tree.np = NULL;
273 else
274 tree.fdt = NULL;
275
276 return tree;
277}
278
279/**
Simon Glass9e512042017-05-18 20:08:58 -0600280 * ofnode_null() - Obtain a null ofnode
281 *
282 * This returns an ofnode which points to no node. It works both with the flat
283 * tree and livetree.
284 */
285static inline ofnode ofnode_null(void)
286{
287 ofnode node;
288
289 if (of_live_active())
290 node.np = NULL;
291 else
292 node.of_offset = -1;
293
294 return node;
295}
296
Simon Glassd0c20ce2020-11-28 17:50:07 -0700297static inline ofnode ofnode_root(void)
298{
299 ofnode node;
300
301 if (of_live_active())
302 node.np = gd_of_root();
303 else
304 node.of_offset = 0;
305
306 return node;
307}
308
Simon Glass9e512042017-05-18 20:08:58 -0600309/**
Simon Glass52ad21a2022-09-06 20:27:16 -0600310 * ofprop_valid() - check if an ofprop is valid
311 *
312 * @prop: Pointer to ofprop to check
313 * Return: true if the reference contains a valid ofprop, false if not
314 */
315static inline bool ofprop_valid(struct ofprop *prop)
316{
317 if (of_live_active())
318 return prop->prop;
319 else
320 return prop->offset >= 0;
321}
322
323/**
Simon Glass33104842022-07-30 15:52:08 -0600324 * oftree_default() - Returns the default device tree (U-Boot's control FDT)
325 *
326 * Returns: reference to the control FDT
327 */
328static inline oftree oftree_default(void)
329{
330 oftree tree;
331
332 if (of_live_active())
333 tree.np = gd_of_root();
334 else
335 tree.fdt = (void *)gd->fdt_blob;
336
337 return tree;
338}
339
340/**
Simon Glass085d5942022-09-06 20:27:21 -0600341 * oftree_from_np() - Returns an oftree from a node pointer
342 *
343 * @root: Root node of the tree
344 * Returns: reference to the given node
345 */
346static inline oftree oftree_from_np(struct device_node *root)
347{
348 oftree tree;
349
350 tree.np = root;
351
352 return tree;
353}
354
355/**
Simon Glassa8f2ac22023-06-01 10:22:42 -0600356 * oftree_dispose() - Dispose of an oftree
357 *
358 * This can be used to dispose of a tree that has been created (other than
359 * the control FDT which must not be disposed)
360 *
361 * @tree: Tree to dispose
362 */
363void oftree_dispose(oftree tree);
364
365/**
Kishon Vijay Abraham I77cbaf82021-07-21 21:28:30 +0530366 * ofnode_name_eq() - Check if the node name is equivalent to a given name
367 * ignoring the unit address
368 *
369 * @node: valid node reference that has to be compared
370 * @name: name that has to be compared with the node name
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100371 * Return: true if matches, false if it doesn't match
Kishon Vijay Abraham I77cbaf82021-07-21 21:28:30 +0530372 */
373bool ofnode_name_eq(ofnode node, const char *name);
374
375/**
Stefan Herbrechtsmeierb471bdc2022-06-14 15:21:30 +0200376 * ofnode_read_u8() - Read a 8-bit integer from a property
377 *
378 * @node: valid node reference to read property from
379 * @propname: name of the property to read from
380 * @outp: place to put value (if found)
381 * Return: 0 if OK, -ve on error
382 */
383int ofnode_read_u8(ofnode node, const char *propname, u8 *outp);
384
385/**
386 * ofnode_read_u8_default() - Read a 8-bit integer from a property
387 *
388 * @node: valid node reference to read property from
389 * @propname: name of the property to read from
390 * @def: default value to return if the property has no value
391 * Return: property value, or @def if not found
392 */
393u8 ofnode_read_u8_default(ofnode node, const char *propname, u8 def);
394
395/**
396 * ofnode_read_u16() - Read a 16-bit integer from a property
397 *
398 * @node: valid node reference to read property from
399 * @propname: name of the property to read from
400 * @outp: place to put value (if found)
401 * Return: 0 if OK, -ve on error
402 */
403int ofnode_read_u16(ofnode node, const char *propname, u16 *outp);
404
405/**
406 * ofnode_read_u16_default() - Read a 16-bit integer from a property
407 *
408 * @node: valid node reference to read property from
409 * @propname: name of the property to read from
410 * @def: default value to return if the property has no value
411 * Return: property value, or @def if not found
412 */
413u16 ofnode_read_u16_default(ofnode node, const char *propname, u16 def);
414
415/**
Simon Glass9e512042017-05-18 20:08:58 -0600416 * ofnode_read_u32() - Read a 32-bit integer from a property
417 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100418 * @node: valid node reference to read property from
Simon Glass9e512042017-05-18 20:08:58 -0600419 * @propname: name of the property to read from
420 * @outp: place to put value (if found)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100421 * Return: 0 if OK, -ve on error
Simon Glass9e512042017-05-18 20:08:58 -0600422 */
423int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
424
425/**
Dario Binacchi4bb70752020-03-29 18:04:41 +0200426 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
427 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100428 * @node: valid node reference to read property from
Dario Binacchi4bb70752020-03-29 18:04:41 +0200429 * @propname: name of the property to read from
430 * @index: index of the integer to return
431 * @outp: place to put value (if found)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100432 * Return: 0 if OK, -ve on error
Dario Binacchi4bb70752020-03-29 18:04:41 +0200433 */
434int ofnode_read_u32_index(ofnode node, const char *propname, int index,
435 u32 *outp);
436
437/**
Simon Glass9e512042017-05-18 20:08:58 -0600438 * ofnode_read_s32() - Read a 32-bit integer from a property
439 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100440 * @node: valid node reference to read property from
Simon Glass9e512042017-05-18 20:08:58 -0600441 * @propname: name of the property to read from
442 * @outp: place to put value (if found)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100443 * Return: 0 if OK, -ve on error
Simon Glass9e512042017-05-18 20:08:58 -0600444 */
445static inline int ofnode_read_s32(ofnode node, const char *propname,
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100446 s32 *outp)
Simon Glass9e512042017-05-18 20:08:58 -0600447{
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100448 return ofnode_read_u32(node, propname, (u32 *)outp);
Simon Glass9e512042017-05-18 20:08:58 -0600449}
450
451/**
452 * ofnode_read_u32_default() - Read a 32-bit integer from a property
453 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100454 * @node: valid node reference to read property from
Simon Glass9e512042017-05-18 20:08:58 -0600455 * @propname: name of the property to read from
456 * @def: default value to return if the property has no value
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100457 * Return: property value, or @def if not found
Simon Glass9e512042017-05-18 20:08:58 -0600458 */
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100459u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def);
Simon Glass9e512042017-05-18 20:08:58 -0600460
461/**
Dario Binacchi4bb70752020-03-29 18:04:41 +0200462 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
463 * property
464 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100465 * @node: valid node reference to read property from
Dario Binacchi4bb70752020-03-29 18:04:41 +0200466 * @propname: name of the property to read from
467 * @index: index of the integer to return
468 * @def: default value to return if the property has no value
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100469 * Return: property value, or @def if not found
Dario Binacchi4bb70752020-03-29 18:04:41 +0200470 */
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100471u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
Dario Binacchi4bb70752020-03-29 18:04:41 +0200472 u32 def);
473
474/**
Simon Glass9e512042017-05-18 20:08:58 -0600475 * ofnode_read_s32_default() - Read a 32-bit integer from a property
476 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100477 * @node: valid node reference to read property from
Simon Glass9e512042017-05-18 20:08:58 -0600478 * @propname: name of the property to read from
479 * @def: default value to return if the property has no value
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100480 * Return: property value, or @def if not found
Simon Glass9e512042017-05-18 20:08:58 -0600481 */
482int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
483
484/**
Lukas Auerafb30122018-11-22 11:26:35 +0100485 * ofnode_read_u64() - Read a 64-bit integer from a property
486 *
487 * @node: valid node reference to read property from
488 * @propname: name of the property to read from
489 * @outp: place to put value (if found)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100490 * Return: 0 if OK, -ve on error
Lukas Auerafb30122018-11-22 11:26:35 +0100491 */
492int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
493
494/**
Simon Glass7e5196c2018-06-11 13:07:10 -0600495 * ofnode_read_u64_default() - Read a 64-bit integer from a property
496 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100497 * @node: valid node reference to read property from
Simon Glass7e5196c2018-06-11 13:07:10 -0600498 * @propname: name of the property to read from
499 * @def: default value to return if the property has no value
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100500 * Return: property value, or @def if not found
Simon Glass7e5196c2018-06-11 13:07:10 -0600501 */
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200502u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
Simon Glass7e5196c2018-06-11 13:07:10 -0600503
504/**
Simon Glassa8167d82020-01-27 08:49:44 -0700505 * ofnode_read_prop() - Read a property from a node
506 *
507 * @node: valid node reference to read property from
508 * @propname: name of the property to read
509 * @sizep: if non-NULL, returns the size of the property, or an error code
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100510 * if not found
511 * Return: property value, or NULL if there is no such property
Simon Glassa8167d82020-01-27 08:49:44 -0700512 */
513const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
514
515/**
Simon Glass9e512042017-05-18 20:08:58 -0600516 * ofnode_read_string() - Read a string from a property
517 *
Simon Glassa8167d82020-01-27 08:49:44 -0700518 * @node: valid node reference to read property from
Simon Glass9e512042017-05-18 20:08:58 -0600519 * @propname: name of the property to read
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100520 * Return: string from property value, or NULL if there is no such property
Simon Glass9e512042017-05-18 20:08:58 -0600521 */
522const char *ofnode_read_string(ofnode node, const char *propname);
523
524/**
Simon Glassbed77492017-05-18 20:09:01 -0600525 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
Simon Glass9e512042017-05-18 20:08:58 -0600526 *
527 * @node: valid node reference to read property from
528 * @propname: name of the property to read
529 * @out_values: pointer to return value, modified only if return value is 0
530 * @sz: number of array elements to read
Simon Glass66d0d0c2022-09-06 20:27:18 -0600531 * Return: 0 on success, -EINVAL if the property does not exist,
532 * -ENODATA if property does not have a value, and -EOVERFLOW if the
533 * property data isn't large enough
Simon Glass9e512042017-05-18 20:08:58 -0600534 *
535 * Search for a property in a device node and read 32-bit value(s) from
Simon Glass66d0d0c2022-09-06 20:27:18 -0600536 * it.
Simon Glass9e512042017-05-18 20:08:58 -0600537 *
538 * The out_values is modified only if a valid u32 value can be decoded.
539 */
540int ofnode_read_u32_array(ofnode node, const char *propname,
541 u32 *out_values, size_t sz);
542
543/**
544 * ofnode_read_bool() - read a boolean value from a property
545 *
546 * @node: valid node reference to read property from
547 * @propname: name of property to read
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100548 * Return: true if property is present (meaning true), false if not present
Simon Glass9e512042017-05-18 20:08:58 -0600549 */
550bool ofnode_read_bool(ofnode node, const char *propname);
551
552/**
553 * ofnode_find_subnode() - find a named subnode of a parent node
554 *
555 * @node: valid reference to parent node
556 * @subnode_name: name of subnode to find
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100557 * Return: reference to subnode (which can be invalid if there is no such
Simon Glass9e512042017-05-18 20:08:58 -0600558 * subnode)
559 */
560ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
561
Simon Glassec1add12020-12-16 17:25:06 -0700562#if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
Simon Glass401d1c42020-10-30 21:38:53 -0600563#include <asm/global_data.h>
564
Simon Glassec1add12020-12-16 17:25:06 -0700565static inline bool ofnode_is_enabled(ofnode node)
566{
567 if (ofnode_is_np(node)) {
568 return of_device_is_available(ofnode_to_np(node));
569 } else {
570 return fdtdec_get_is_enabled(gd->fdt_blob,
571 ofnode_to_offset(node));
572 }
573}
574
575static inline ofnode ofnode_first_subnode(ofnode node)
576{
577 assert(ofnode_valid(node));
578 if (ofnode_is_np(node))
579 return np_to_ofnode(node.np->child);
580
581 return offset_to_ofnode(
582 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
583}
584
585static inline ofnode ofnode_next_subnode(ofnode node)
586{
587 assert(ofnode_valid(node));
588 if (ofnode_is_np(node))
589 return np_to_ofnode(node.np->sibling);
590
591 return offset_to_ofnode(
592 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
593}
594#else
595/**
596 * ofnode_is_enabled() - Checks whether a node is enabled.
597 * This looks for a 'status' property. If this exists, then returns true if
598 * the status is 'okay' and false otherwise. If there is no status property,
599 * it returns true on the assumption that anything mentioned should be enabled
600 * by default.
601 *
602 * @node: node to examine
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100603 * Return: false (not enabled) or true (enabled)
Simon Glassec1add12020-12-16 17:25:06 -0700604 */
605bool ofnode_is_enabled(ofnode node);
606
Simon Glass9e512042017-05-18 20:08:58 -0600607/**
608 * ofnode_first_subnode() - find the first subnode of a parent node
609 *
610 * @node: valid reference to a valid parent node
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100611 * Return: reference to the first subnode (which can be invalid if the parent
Simon Glass9e512042017-05-18 20:08:58 -0600612 * node has no subnodes)
613 */
614ofnode ofnode_first_subnode(ofnode node);
615
616/**
617 * ofnode_next_subnode() - find the next sibling of a subnode
618 *
619 * @node: valid reference to previous node (sibling)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100620 * Return: reference to the next subnode (which can be invalid if the node
Simon Glass9e512042017-05-18 20:08:58 -0600621 * has no more siblings)
622 */
623ofnode ofnode_next_subnode(ofnode node);
Simon Glassec1add12020-12-16 17:25:06 -0700624#endif /* DM_INLINE_OFNODE */
Simon Glass9e512042017-05-18 20:08:58 -0600625
626/**
Philipp Tomsiche2d59972018-02-23 17:38:49 +0100627 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
628 *
629 * @node: valid node to look up
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100630 * Return: ofnode reference of the parent node
Philipp Tomsiche2d59972018-02-23 17:38:49 +0100631 */
632ofnode ofnode_get_parent(ofnode node);
633
634/**
Simon Glass9e512042017-05-18 20:08:58 -0600635 * ofnode_get_name() - get the name of a node
636 *
637 * @node: valid node to look up
Simon Glassf46ec932022-09-06 20:27:15 -0600638 * Return: name of node (for the root node this is "")
Simon Glass9e512042017-05-18 20:08:58 -0600639 */
640const char *ofnode_get_name(ofnode node);
641
642/**
Marek Behún0e116be2021-05-26 14:08:18 +0200643 * ofnode_get_path() - get the full path of a node
644 *
645 * @node: valid node to look up
646 * @buf: buffer to write the node path into
647 * @buflen: buffer size
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100648 * Return: 0 if OK, -ve on error
Marek Behún0e116be2021-05-26 14:08:18 +0200649 */
650int ofnode_get_path(ofnode node, char *buf, int buflen);
651
652/**
Kever Yangb4f20762018-02-23 17:38:50 +0100653 * ofnode_get_by_phandle() - get ofnode from phandle
654 *
Simon Glass829d5122022-09-06 20:26:57 -0600655 * This uses the default (control) device tree
656 *
Kever Yangb4f20762018-02-23 17:38:50 +0100657 * @phandle: phandle to look up
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100658 * Return: ofnode reference to the phandle
Kever Yangb4f20762018-02-23 17:38:50 +0100659 */
660ofnode ofnode_get_by_phandle(uint phandle);
661
662/**
Simon Glass928d2672022-09-06 20:27:22 -0600663 * oftree_get_by_phandle() - get ofnode from phandle
664 *
665 * @tree: tree to use
666 * @phandle: phandle to look up
667 * Return: ofnode reference to the phandle
668 */
669ofnode oftree_get_by_phandle(oftree tree, uint phandle);
670
671/**
Simon Glass9e512042017-05-18 20:08:58 -0600672 * ofnode_read_size() - read the size of a property
673 *
674 * @node: node to check
675 * @propname: property to check
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100676 * Return: size of property if present, or -EINVAL if not
Simon Glass9e512042017-05-18 20:08:58 -0600677 */
678int ofnode_read_size(ofnode node, const char *propname);
679
680/**
Keerthye679d032019-04-24 17:19:53 +0530681 * ofnode_get_addr_size_index() - get an address/size from a node
682 * based on index
683 *
684 * This reads the register address/size from a node based on index
685 *
686 * @node: node to read from
687 * @index: Index of address to read (0 for first)
688 * @size: Pointer to size of the address
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100689 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Keerthye679d032019-04-24 17:19:53 +0530690 */
Johan Jonkeraecae812023-03-13 01:30:33 +0100691fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index,
692 fdt_size_t *size);
Keerthye679d032019-04-24 17:19:53 +0530693
694/**
Marek Behún31a7b712021-05-26 14:08:17 +0200695 * ofnode_get_addr_size_index_notrans() - get an address/size from a node
696 * based on index, without address
697 * translation
698 *
699 * This reads the register address/size from a node based on index.
700 * The resulting address is not translated. Useful for example for on-disk
701 * addresses.
702 *
703 * @node: node to read from
704 * @index: Index of address to read (0 for first)
705 * @size: Pointer to size of the address
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100706 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Marek Behún31a7b712021-05-26 14:08:17 +0200707 */
Johan Jonkeraecae812023-03-13 01:30:33 +0100708fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
709 fdt_size_t *size);
Marek Behún31a7b712021-05-26 14:08:17 +0200710
711/**
Simon Glassbed77492017-05-18 20:09:01 -0600712 * ofnode_get_addr_index() - get an address from a node
713 *
714 * This reads the register address from a node
715 *
716 * @node: node to read from
717 * @index: Index of address to read (0 for first)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100718 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Simon Glassbed77492017-05-18 20:09:01 -0600719 */
Johan Jonkeraecae812023-03-13 01:30:33 +0100720fdt_addr_t ofnode_get_addr_index(ofnode node, int index);
Simon Glassbed77492017-05-18 20:09:01 -0600721
722/**
723 * ofnode_get_addr() - get an address from a node
724 *
725 * This reads the register address from a node
726 *
727 * @node: node to read from
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100728 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Simon Glassbed77492017-05-18 20:09:01 -0600729 */
Johan Jonkeraecae812023-03-13 01:30:33 +0100730fdt_addr_t ofnode_get_addr(ofnode node);
Simon Glassbed77492017-05-18 20:09:01 -0600731
732/**
Chen Guanqiaoaa351a12021-04-12 14:51:11 +0800733 * ofnode_get_size() - get size from a node
734 *
735 * This reads the register size from a node
736 *
737 * @node: node to read from
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100738 * Return: size of the address, or FDT_SIZE_T_NONE if not present or invalid
Chen Guanqiaoaa351a12021-04-12 14:51:11 +0800739 */
740fdt_size_t ofnode_get_size(ofnode node);
741
742/**
Simon Glass9e512042017-05-18 20:08:58 -0600743 * ofnode_stringlist_search() - find a string in a string list and return index
744 *
745 * Note that it is possible for this function to succeed on property values
746 * that are not NUL-terminated. That's because the function will stop after
747 * finding the first occurrence of @string. This can for example happen with
748 * small-valued cell properties, such as #address-cells, when searching for
749 * the empty string.
750 *
751 * @node: node to check
752 * @propname: name of the property containing the string list
753 * @string: string to look up in the string list
754 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100755 * Return:
Simon Glass9e512042017-05-18 20:08:58 -0600756 * the index of the string in the list of strings
757 * -ENODATA if the property is not found
758 * -EINVAL on some other error
759 */
760int ofnode_stringlist_search(ofnode node, const char *propname,
761 const char *string);
762
763/**
Simon Glass8c293d62017-06-12 06:21:28 -0600764 * ofnode_read_string_index() - obtain an indexed string from a string list
Simon Glass9e512042017-05-18 20:08:58 -0600765 *
766 * Note that this will successfully extract strings from properties with
767 * non-NUL-terminated values. For example on small-valued cell properties
768 * this function will return the empty string.
769 *
770 * If non-NULL, the length of the string (on success) or a negative error-code
771 * (on failure) will be stored in the integer pointer to by lenp.
772 *
773 * @node: node to check
774 * @propname: name of the property containing the string list
Simon Glass32c6a8e2021-10-23 17:26:06 -0600775 * @index: index of the string to return (cannot be negative)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100776 * @outp: return location for the string
Simon Glass9e512042017-05-18 20:08:58 -0600777 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100778 * Return:
Simon Glass32c6a8e2021-10-23 17:26:06 -0600779 * 0 if found or -ve error value if not found
Simon Glass9e512042017-05-18 20:08:58 -0600780 */
781int ofnode_read_string_index(ofnode node, const char *propname, int index,
782 const char **outp);
783
784/**
Simon Glass8c293d62017-06-12 06:21:28 -0600785 * ofnode_read_string_count() - find the number of strings in a string list
786 *
787 * @node: node to check
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100788 * @property: name of the property containing the string list
789 * Return:
Simon Glass8c293d62017-06-12 06:21:28 -0600790 * number of strings in the list, or -ve error value if not found
791 */
792int ofnode_read_string_count(ofnode node, const char *property);
793
794/**
Simon Glass075bfc92021-10-23 17:26:07 -0600795 * ofnode_read_string_list() - read a list of strings
796 *
797 * This produces a list of string pointers with each one pointing to a string
798 * in the string list. If the property does not exist, it returns {NULL}.
799 *
800 * The data is allocated and the caller is reponsible for freeing the return
801 * value (the list of string pointers). The strings themselves may not be
802 * changed as they point directly into the devicetree property.
803 *
804 * @node: node to check
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100805 * @property: name of the property containing the string list
Simon Glass075bfc92021-10-23 17:26:07 -0600806 * @listp: returns an allocated, NULL-terminated list of strings if the return
807 * value is > 0, else is set to NULL
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100808 * Return:
809 * number of strings in list, 0 if none, -ENOMEM if out of memory,
810 * -EINVAL if no such property, -EENODATA if property is empty
Simon Glass075bfc92021-10-23 17:26:07 -0600811 */
812int ofnode_read_string_list(ofnode node, const char *property,
813 const char ***listp);
814
815/**
Simon Glass9e512042017-05-18 20:08:58 -0600816 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
817 *
818 * This function is useful to parse lists of phandles and their arguments.
819 * Returns 0 on success and fills out_args, on error returns appropriate
820 * errno value.
821 *
822 * Caller is responsible to call of_node_put() on the returned out_args->np
823 * pointer.
824 *
825 * Example:
826 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100827 * .. code-block::
Simon Glass9e512042017-05-18 20:08:58 -0600828 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100829 * phandle1: node1 {
830 * #list-cells = <2>;
831 * };
832 * phandle2: node2 {
833 * #list-cells = <1>;
834 * };
835 * node3 {
836 * list = <&phandle1 1 2 &phandle2 3>;
837 * };
Simon Glass9e512042017-05-18 20:08:58 -0600838 *
839 * To get a device_node of the `node2' node you may call this:
840 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
841 *
842 * @node: device tree node containing a list
843 * @list_name: property name that contains a list
844 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100845 * @cell_count: Cell count to use if @cells_name is NULL
Simon Glass9e512042017-05-18 20:08:58 -0600846 * @index: index of a phandle to parse out
847 * @out_args: optional pointer to output arguments structure (will be filled)
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100848 * Return:
849 * 0 on success (with @out_args filled out if not NULL), -ENOENT if
850 * @list_name does not exist, -EINVAL if a phandle was not found,
851 * @cells_name could not be found, the arguments were truncated or there
852 * were too many arguments.
Simon Glass9e512042017-05-18 20:08:58 -0600853 */
854int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
855 const char *cells_name, int cell_count,
856 int index,
857 struct ofnode_phandle_args *out_args);
858
859/**
Patrice Chotard642346a2017-07-18 11:57:08 +0200860 * ofnode_count_phandle_with_args() - Count number of phandle in a list
861 *
862 * This function is useful to count phandles into a list.
863 * Returns number of phandle on success, on error returns appropriate
864 * errno value.
865 *
866 * @node: device tree node containing a list
867 * @list_name: property name that contains a list
868 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100869 * @cell_count: Cell count to use if @cells_name is NULL
870 * Return:
871 * number of phandle on success, -ENOENT if @list_name does not exist,
872 * -EINVAL if a phandle was not found, @cells_name could not be found.
Patrice Chotard642346a2017-07-18 11:57:08 +0200873 */
874int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200875 const char *cells_name, int cell_count);
Patrice Chotard642346a2017-07-18 11:57:08 +0200876
877/**
Simon Glass9e512042017-05-18 20:08:58 -0600878 * ofnode_path() - find a node by full path
879 *
Simon Glass33104842022-07-30 15:52:08 -0600880 * This uses the control FDT.
881 *
Simon Glass9e512042017-05-18 20:08:58 -0600882 * @path: Full path to node, e.g. "/bus/spi@1"
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100883 * Return: reference to the node found. Use ofnode_valid() to check if it exists
Simon Glass9e512042017-05-18 20:08:58 -0600884 */
885ofnode ofnode_path(const char *path);
886
887/**
Simon Glassb7bd94f2022-09-06 20:27:24 -0600888 * oftree_path() - find a node by full path from a root node
Simon Glass33104842022-07-30 15:52:08 -0600889 *
890 * @tree: Device tree to use
891 * @path: Full path to node, e.g. "/bus/spi@1"
892 * Return: reference to the node found. Use ofnode_valid() to check if it exists
893 */
Simon Glassb7bd94f2022-09-06 20:27:24 -0600894ofnode oftree_path(oftree tree, const char *path);
895
896/**
897 * oftree_root() - get the root node of a tree
898 *
899 * @tree: Device tree to use
900 * Return: reference to the root node
901 */
902ofnode oftree_root(oftree tree);
Simon Glass33104842022-07-30 15:52:08 -0600903
904/**
Simon Glassbd933bf2020-01-27 08:49:46 -0700905 * ofnode_read_chosen_prop() - get the value of a chosen property
906 *
Simon Glassb7bd94f2022-09-06 20:27:24 -0600907 * This looks for a property within the /chosen node and returns its value.
908 *
909 * This only works with the control FDT.
Simon Glassbd933bf2020-01-27 08:49:46 -0700910 *
911 * @propname: Property name to look for
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100912 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
Simon Glassbd933bf2020-01-27 08:49:46 -0700913 * returns NULL
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100914 * Return: property value if found, else NULL
Simon Glassbd933bf2020-01-27 08:49:46 -0700915 */
916const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
917
918/**
Simon Glass14ca9f72020-01-27 08:49:43 -0700919 * ofnode_read_chosen_string() - get the string value of a chosen property
Simon Glass9e512042017-05-18 20:08:58 -0600920 *
Simon Glass14ca9f72020-01-27 08:49:43 -0700921 * This looks for a property within the /chosen node and returns its value,
922 * checking that it is a valid nul-terminated string
Simon Glass9e512042017-05-18 20:08:58 -0600923 *
Simon Glass988f1462022-09-06 20:27:28 -0600924 * This only works with the control FDT.
925 *
Simon Glass9e512042017-05-18 20:08:58 -0600926 * @propname: Property name to look for
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100927 * Return: string value if found, else NULL
Simon Glass9e512042017-05-18 20:08:58 -0600928 */
Simon Glass14ca9f72020-01-27 08:49:43 -0700929const char *ofnode_read_chosen_string(const char *propname);
Simon Glass9e512042017-05-18 20:08:58 -0600930
931/**
Simon Glass74d594a2020-01-27 08:49:42 -0700932 * ofnode_get_chosen_node() - get a referenced node from the chosen node
Simon Glass9e512042017-05-18 20:08:58 -0600933 *
Simon Glass74d594a2020-01-27 08:49:42 -0700934 * This looks up a named property in the chosen node and uses that as a path to
935 * look up a code.
936 *
Simon Glass988f1462022-09-06 20:27:28 -0600937 * This only works with the control FDT.
938 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100939 * @propname: Property name to look for
940 * Return: the referenced node if present, else ofnode_null()
Simon Glass9e512042017-05-18 20:08:58 -0600941 */
Simon Glass74d594a2020-01-27 08:49:42 -0700942ofnode ofnode_get_chosen_node(const char *propname);
Simon Glass9e512042017-05-18 20:08:58 -0600943
Michal Simek305d3182020-07-28 12:51:08 +0200944/**
945 * ofnode_read_aliases_prop() - get the value of a aliases property
946 *
947 * This looks for a property within the /aliases node and returns its value
948 *
Simon Glass988f1462022-09-06 20:27:28 -0600949 * This only works with the control FDT.
950 *
Michal Simek305d3182020-07-28 12:51:08 +0200951 * @propname: Property name to look for
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100952 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
Michal Simek305d3182020-07-28 12:51:08 +0200953 * returns NULL
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100954 * Return: property value if found, else NULL
Michal Simek305d3182020-07-28 12:51:08 +0200955 */
956const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
957
958/**
959 * ofnode_get_aliases_node() - get a referenced node from the aliases node
960 *
961 * This looks up a named property in the aliases node and uses that as a path to
962 * look up a code.
963 *
Simon Glass988f1462022-09-06 20:27:28 -0600964 * This only works with the control FDT.
965 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100966 * @propname: Property name to look for
967 * Return: the referenced node if present, else ofnode_null()
Michal Simek305d3182020-07-28 12:51:08 +0200968 */
969ofnode ofnode_get_aliases_node(const char *propname);
970
Simon Glass9e512042017-05-18 20:08:58 -0600971struct display_timing;
972/**
973 * ofnode_decode_display_timing() - decode display timings
974 *
975 * Decode display timings from the supplied 'display-timings' node.
976 * See doc/device-tree-bindings/video/display-timing.txt for binding
977 * information.
978 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100979 * @node: 'display-timing' node containing the timing subnodes
980 * @index: Index number to read (0=first timing subnode)
981 * @config: Place to put timings
982 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
Simon Glass9e512042017-05-18 20:08:58 -0600983 */
984int ofnode_decode_display_timing(ofnode node, int index,
985 struct display_timing *config);
986
987/**
Nikhil M Jain0347cc72023-01-31 15:35:14 +0530988 * ofnode_decode_panel_timing() - decode display timings
989 *
990 * Decode panel timings from the supplied 'panel-timings' node.
991 *
992 * @node: 'display-timing' node containing the timing subnodes
993 * @config: Place to put timings
994 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
995 */
996int ofnode_decode_panel_timing(ofnode node,
997 struct display_timing *config);
998
999/**
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001000 * ofnode_get_property() - get a pointer to the value of a node property
Simon Glass9e512042017-05-18 20:08:58 -06001001 *
1002 * @node: node to read
1003 * @propname: property to read
1004 * @lenp: place to put length on success
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001005 * Return: pointer to property, or NULL if not found
Simon Glass9e512042017-05-18 20:08:58 -06001006 */
Masahiro Yamada61e51ba2017-06-22 16:54:05 +09001007const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
Simon Glass9e512042017-05-18 20:08:58 -06001008
1009/**
Simon Glass4b1f5712022-09-06 20:27:13 -06001010 * ofnode_first_property()- get the reference of the first property
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001011 *
1012 * Get reference to the first property of the node, it is used to iterate
Simon Glass92432242022-09-06 20:27:14 -06001013 * and read all the property with ofprop_get_property().
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001014 *
1015 * @node: node to read
1016 * @prop: place to put argument reference
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001017 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001018 */
Simon Glass4b1f5712022-09-06 20:27:13 -06001019int ofnode_first_property(ofnode node, struct ofprop *prop);
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001020
1021/**
Simon Glass4b1f5712022-09-06 20:27:13 -06001022 * ofnode_next_property() - get the reference of the next property
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001023 *
1024 * Get reference to the next property of the node, it is used to iterate
Simon Glass92432242022-09-06 20:27:14 -06001025 * and read all the property with ofprop_get_property().
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001026 *
1027 * @prop: reference of current argument and place to put reference of next one
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001028 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001029 */
Simon Glass4b1f5712022-09-06 20:27:13 -06001030int ofnode_next_property(struct ofprop *prop);
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001031
1032/**
Simon Glass52ad21a2022-09-06 20:27:16 -06001033 * ofnode_for_each_prop() - iterate over all properties of a node
1034 *
1035 * @prop: struct ofprop
1036 * @node: node (lvalue, ofnode)
1037 *
1038 * This is a wrapper around a for loop and is used like this::
1039 *
1040 * ofnode node;
1041 * struct ofprop prop;
1042 *
1043 * ofnode_for_each_prop(prop, node) {
1044 * ...use prop...
1045 * }
1046 *
1047 * Note that this is implemented as a macro and @prop is used as
1048 * iterator in the loop. The parent variable can be a constant or even a
1049 * literal.
1050 */
1051#define ofnode_for_each_prop(prop, node) \
1052 for (ofnode_first_property(node, &prop); \
1053 ofprop_valid(&prop); \
1054 ofnode_next_property(&prop))
1055
1056/**
Simon Glass92432242022-09-06 20:27:14 -06001057 * ofprop_get_property() - get a pointer to the value of a property
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001058 *
1059 * Get value for the property identified by the provided reference.
1060 *
1061 * @prop: reference on property
1062 * @propname: If non-NULL, place to property name on success,
Simon Glass92432242022-09-06 20:27:14 -06001063 * @lenp: If non-NULL, place to put length on success, or error code on failure
1064 * Return: pointer to property, or NULL if not found
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001065 */
Simon Glass92432242022-09-06 20:27:14 -06001066const void *ofprop_get_property(const struct ofprop *prop,
1067 const char **propname, int *lenp);
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001068
1069/**
Simon Glass9e512042017-05-18 20:08:58 -06001070 * ofnode_get_addr_size() - get address and size from a property
1071 *
1072 * This does no address translation. It simply reads an property that contains
1073 * an address and a size value, one after the other.
1074 *
1075 * @node: node to read from
1076 * @propname: property to read
1077 * @sizep: place to put size value (on success)
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001078 * Return: address value, or FDT_ADDR_T_NONE on error
Simon Glass9e512042017-05-18 20:08:58 -06001079 */
Johan Jonkeraecae812023-03-13 01:30:33 +01001080fdt_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
1081 fdt_size_t *sizep);
Simon Glass9e512042017-05-18 20:08:58 -06001082
1083/**
1084 * ofnode_read_u8_array_ptr() - find an 8-bit array
1085 *
1086 * Look up a property in a node and return a pointer to its contents as a
1087 * byte array of given length. The property must have at least enough data
1088 * for the array (count bytes). It may have more, but this will be ignored.
1089 * The data is not copied.
1090 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001091 * @node: node to examine
1092 * @propname: name of property to find
1093 * @sz: number of array elements
1094 * Return:
1095 * pointer to byte array if found, or NULL if the property is not found or
1096 * there is not enough data
Simon Glass9e512042017-05-18 20:08:58 -06001097 */
1098const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
1099 size_t sz);
1100
1101/**
1102 * ofnode_read_pci_addr() - look up a PCI address
1103 *
1104 * Look at an address property in a node and return the PCI address which
1105 * corresponds to the given type in the form of fdt_pci_addr.
1106 * The property must hold one fdt_pci_addr with a lengh.
1107 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001108 * @node: node to examine
1109 * @type: pci address type (FDT_PCI_SPACE_xxx)
1110 * @propname: name of property to find
1111 * @addr: returns pci address in the form of fdt_pci_addr
1112 * Return:
1113 * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
1114 * format of the property was invalid, -ENXIO if the requested
1115 * address type was not found
Simon Glass9e512042017-05-18 20:08:58 -06001116 */
1117int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
1118 const char *propname, struct fdt_pci_addr *addr);
1119
1120/**
Bin Meng7b9cbad2018-08-03 01:14:35 -07001121 * ofnode_read_pci_vendev() - look up PCI vendor and device id
1122 *
1123 * Look at the compatible property of a device node that represents a PCI
1124 * device and extract pci vendor id and device id from it.
1125 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001126 * @node: node to examine
1127 * @vendor: vendor id of the pci device
1128 * @device: device id of the pci device
1129 * Return: 0 if ok, negative on error
Bin Meng7b9cbad2018-08-03 01:14:35 -07001130 */
1131int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
1132
1133/**
Michal Simekdb681d42022-02-23 15:45:40 +01001134 * ofnode_read_eth_phy_id() - look up eth phy vendor and device id
1135 *
1136 * Look at the compatible property of a device node that represents a eth phy
1137 * device and extract phy vendor id and device id from it.
1138 *
Heinrich Schuchardtd23f2902022-03-24 16:22:32 +01001139 * @node: node to examine
1140 * @vendor: vendor id of the eth phy device
1141 * @device: device id of the eth phy device
1142 * Return: 0 if ok, negative on error
Michal Simekdb681d42022-02-23 15:45:40 +01001143 */
1144int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device);
1145
1146/**
Simon Glass9e512042017-05-18 20:08:58 -06001147 * ofnode_read_addr_cells() - Get the number of address cells for a node
1148 *
1149 * This walks back up the tree to find the closest #address-cells property
1150 * which controls the given node.
1151 *
1152 * @node: Node to check
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001153 * Return: number of address cells this node uses
Simon Glass9e512042017-05-18 20:08:58 -06001154 */
1155int ofnode_read_addr_cells(ofnode node);
1156
1157/**
1158 * ofnode_read_size_cells() - Get the number of size cells for a node
1159 *
1160 * This walks back up the tree to find the closest #size-cells property
1161 * which controls the given node.
1162 *
1163 * @node: Node to check
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001164 * Return: number of size cells this node uses
Simon Glass9e512042017-05-18 20:08:58 -06001165 */
1166int ofnode_read_size_cells(ofnode node);
1167
1168/**
Simon Glass878d68c2017-06-12 06:21:31 -06001169 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
1170 *
1171 * This function matches fdt_address_cells().
1172 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001173 * @node: Node to check
1174 * Return: value of #address-cells property in this node, or 2 if none
Simon Glass878d68c2017-06-12 06:21:31 -06001175 */
1176int ofnode_read_simple_addr_cells(ofnode node);
1177
1178/**
1179 * ofnode_read_simple_size_cells() - Get the size cells property in a node
1180 *
1181 * This function matches fdt_size_cells().
1182 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001183 * @node: Node to check
1184 * Return: value of #size-cells property in this node, or 2 if none
Simon Glass878d68c2017-06-12 06:21:31 -06001185 */
1186int ofnode_read_simple_size_cells(ofnode node);
1187
1188/**
Simon Glass9e512042017-05-18 20:08:58 -06001189 * ofnode_pre_reloc() - check if a node should be bound before relocation
1190 *
1191 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
1192 * via special device tree properties.
1193 *
1194 * Before relocation this function can be used to check if nodes are required
1195 * in either SPL or TPL stages.
1196 *
1197 * After relocation and jumping into the real U-Boot binary it is possible to
1198 * determine if a node was bound in one of SPL/TPL stages.
1199 *
Patrick Delaunay54e12232019-05-21 19:19:13 +02001200 * There are 4 settings currently in use
Simon Glasse316fba2023-02-13 08:56:34 -07001201 * - bootph-some-ram: U-Boot proper pre-relocation only
1202 * - bootph-all: all phases
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001203 * Existing platforms only use it to indicate nodes needed in
Simon Glasse316fba2023-02-13 08:56:34 -07001204 * SPL. Should probably be replaced by bootph-pre-ram for new platforms.
1205 * - bootph-pre-ram: SPL and U-Boot pre-relocation
1206 * - bootph-pre-sram: TPL and U-Boot pre-relocation
Simon Glass9e512042017-05-18 20:08:58 -06001207 *
1208 * @node: node to check
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001209 * Return: true if node is needed in SPL/TL, false otherwise
Simon Glass9e512042017-05-18 20:08:58 -06001210 */
1211bool ofnode_pre_reloc(ofnode node);
1212
Simon Glassc98ad442018-06-11 13:07:12 -06001213/**
1214 * ofnode_read_resource() - Read a resource from a node
1215 *
1216 * Read resource information from a node at the given index
1217 *
1218 * @node: Node to read from
1219 * @index: Index of resource to read (0 = first)
1220 * @res: Returns resource that was read, on success
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001221 * Return: 0 if OK, -ve on error
Simon Glassc98ad442018-06-11 13:07:12 -06001222 */
Simon Glassdcf98852017-07-25 08:29:55 -06001223int ofnode_read_resource(ofnode node, uint index, struct resource *res);
Simon Glassc98ad442018-06-11 13:07:12 -06001224
1225/**
1226 * ofnode_read_resource_byname() - Read a resource from a node by name
1227 *
1228 * Read resource information from a node matching the given name. This uses a
1229 * 'reg-names' string list property with the names matching the associated
1230 * 'reg' property list.
1231 *
1232 * @node: Node to read from
1233 * @name: Name of resource to read
1234 * @res: Returns resource that was read, on success
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001235 * Return: 0 if OK, -ve on error
Simon Glassc98ad442018-06-11 13:07:12 -06001236 */
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +09001237int ofnode_read_resource_byname(ofnode node, const char *name,
1238 struct resource *res);
Simon Glassdcf98852017-07-25 08:29:55 -06001239
Simon Glass3991f422017-08-05 15:45:54 -06001240/**
Simon Glassc60f6712018-06-11 13:07:13 -06001241 * ofnode_by_compatible() - Find the next compatible node
1242 *
1243 * Find the next node after @from that is compatible with @compat
1244 *
1245 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
1246 * @compat: Compatible string to match
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001247 * Return: ofnode found, or ofnode_null() if none
Simon Glassc60f6712018-06-11 13:07:13 -06001248 */
1249ofnode ofnode_by_compatible(ofnode from, const char *compat);
1250
1251/**
Jens Wiklander61fba0f2018-08-20 11:09:58 +02001252 * ofnode_by_prop_value() - Find the next node with given property value
1253 *
1254 * Find the next node after @from that has a @propname with a value
1255 * @propval and a length @proplen.
1256 *
Simon Glass2187cb72022-09-06 20:27:23 -06001257 * @from: ofnode to start from. Use ofnode_null() to start at the
1258 * beginning, or the return value from oftree_root() to start at the first
1259 * child of the root
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001260 * @propname: property name to check
1261 * @propval: property value to search for
1262 * @proplen: length of the value in propval
1263 * Return: ofnode found, or ofnode_null() if none
Jens Wiklander61fba0f2018-08-20 11:09:58 +02001264 */
1265ofnode ofnode_by_prop_value(ofnode from, const char *propname,
1266 const void *propval, int proplen);
1267
1268/**
Simon Glass3991f422017-08-05 15:45:54 -06001269 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
1270 *
1271 * @node: child node (ofnode, lvalue)
1272 * @parent: parent node (ofnode)
1273 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001274 * This is a wrapper around a for loop and is used like so::
Simon Glass3991f422017-08-05 15:45:54 -06001275 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001276 * ofnode node;
1277 * ofnode_for_each_subnode(node, parent) {
1278 * Use node
1279 * ...
1280 * }
Simon Glass3991f422017-08-05 15:45:54 -06001281 *
1282 * Note that this is implemented as a macro and @node is used as
1283 * iterator in the loop. The parent variable can be a constant or even a
1284 * literal.
1285 */
1286#define ofnode_for_each_subnode(node, parent) \
1287 for (node = ofnode_first_subnode(parent); \
1288 ofnode_valid(node); \
1289 node = ofnode_next_subnode(node))
1290
Mario Six147c6072018-01-15 11:07:19 +01001291/**
Michael Walleb8ec9452021-10-15 15:15:17 +02001292 * ofnode_for_each_compatible_node() - iterate over all nodes with a given
1293 * compatible string
1294 *
1295 * @node: child node (ofnode, lvalue)
1296 * @compat: compatible string to match
1297 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001298 * This is a wrapper around a for loop and is used like so::
Michael Walleb8ec9452021-10-15 15:15:17 +02001299 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001300 * ofnode node;
1301 * ofnode_for_each_compatible_node(node, parent, compatible) {
1302 * Use node
1303 * ...
1304 * }
Michael Walleb8ec9452021-10-15 15:15:17 +02001305 *
1306 * Note that this is implemented as a macro and @node is used as
1307 * iterator in the loop.
1308 */
1309#define ofnode_for_each_compatible_node(node, compat) \
1310 for (node = ofnode_by_compatible(ofnode_null(), compat); \
1311 ofnode_valid(node); \
1312 node = ofnode_by_compatible(node, compat))
1313
1314/**
Chunfeng Yun89b84b82020-05-02 11:35:09 +02001315 * ofnode_get_child_count() - get the child count of a ofnode
1316 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001317 * @parent: valid node to get its child count
1318 * Return: the number of subnodes
Chunfeng Yun89b84b82020-05-02 11:35:09 +02001319 */
1320int ofnode_get_child_count(ofnode parent);
1321
1322/**
Fabien Dessenne641067f2019-05-31 15:11:30 +02001323 * ofnode_translate_address() - Translate a device-tree address
Mario Six147c6072018-01-15 11:07:19 +01001324 *
1325 * Translate an address from the device-tree into a CPU physical address. This
1326 * function walks up the tree and applies the various bus mappings along the
1327 * way.
1328 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001329 * @node: Device tree node giving the context in which to translate the address
Mario Six147c6072018-01-15 11:07:19 +01001330 * @in_addr: pointer to the address to translate
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001331 * Return: the translated address; OF_BAD_ADDR on error
Mario Six147c6072018-01-15 11:07:19 +01001332 */
1333u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
Masahiro Yamada5ccc2c22018-04-19 12:14:02 +09001334
1335/**
Fabien Dessenne641067f2019-05-31 15:11:30 +02001336 * ofnode_translate_dma_address() - Translate a device-tree DMA address
1337 *
1338 * Translate a DMA address from the device-tree into a CPU physical address.
1339 * This function walks up the tree and applies the various bus mappings along
1340 * the way.
1341 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001342 * @node: Device tree node giving the context in which to translate the
1343 * DMA address
Fabien Dessenne641067f2019-05-31 15:11:30 +02001344 * @in_addr: pointer to the DMA address to translate
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001345 * Return: the translated DMA address; OF_BAD_ADDR on error
Fabien Dessenne641067f2019-05-31 15:11:30 +02001346 */
1347u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
1348
1349/**
Nicolas Saenz Julienne51bdb502021-01-12 13:55:22 +01001350 * ofnode_get_dma_range() - get dma-ranges for a specific DT node
1351 *
1352 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
1353 * cpu->bus address translations
1354 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001355 * @node: Device tree node
1356 * @cpu: Pointer to variable storing the range's cpu address
1357 * @bus: Pointer to variable storing the range's bus address
1358 * @size: Pointer to variable storing the range's size
1359 * Return: translated DMA address or OF_BAD_ADDR on error
Nicolas Saenz Julienne51bdb502021-01-12 13:55:22 +01001360 */
1361int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
1362 u64 *size);
1363
1364/**
Masahiro Yamada5ccc2c22018-04-19 12:14:02 +09001365 * ofnode_device_is_compatible() - check if the node is compatible with compat
1366 *
1367 * This allows to check whether the node is comaptible with the compat.
1368 *
1369 * @node: Device tree node for which compatible needs to be verified.
1370 * @compat: Compatible string which needs to verified in the given node.
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001371 * Return: true if OK, false if the compatible is not found
Masahiro Yamada5ccc2c22018-04-19 12:14:02 +09001372 */
1373int ofnode_device_is_compatible(ofnode node, const char *compat);
Mario Sixe369e582018-06-26 08:46:48 +02001374
1375/**
1376 * ofnode_write_prop() - Set a property of a ofnode
1377 *
Simon Glass0b58eaa2022-09-06 20:27:32 -06001378 * Note that if @copy is false, the value passed to the function is *not*
1379 * allocated by the function itself, but must be allocated by the caller if
1380 * necessary. However it does allocate memory for the property struct and name.
Mario Sixe369e582018-06-26 08:46:48 +02001381 *
1382 * @node: The node for whose property should be set
1383 * @propname: The name of the property to set
Mario Sixe369e582018-06-26 08:46:48 +02001384 * @value: The new value of the property (must be valid prior to calling
1385 * the function)
Simon Glassbe0789a2022-07-30 15:52:10 -06001386 * @len: The length of the new value of the property
Simon Glass0b58eaa2022-09-06 20:27:32 -06001387 * @copy: true to allocate memory for the value. This only has any effect with
1388 * live tree, since flat tree handles this automatically. It allows a
1389 * node's value to be written to the tree, without requiring that the
1390 * caller allocate it
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001391 * Return: 0 if successful, -ve on error
Mario Sixe369e582018-06-26 08:46:48 +02001392 */
Simon Glassbe0789a2022-07-30 15:52:10 -06001393int ofnode_write_prop(ofnode node, const char *propname, const void *value,
Simon Glass0b58eaa2022-09-06 20:27:32 -06001394 int len, bool copy);
Mario Sixe369e582018-06-26 08:46:48 +02001395
1396/**
1397 * ofnode_write_string() - Set a string property of a ofnode
1398 *
1399 * Note that the value passed to the function is *not* allocated by the
1400 * function itself, but must be allocated by the caller if necessary.
1401 *
1402 * @node: The node for whose string property should be set
1403 * @propname: The name of the string property to set
1404 * @value: The new value of the string property (must be valid prior to
1405 * calling the function)
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001406 * Return: 0 if successful, -ve on error
Mario Sixe369e582018-06-26 08:46:48 +02001407 */
1408int ofnode_write_string(ofnode node, const char *propname, const char *value);
1409
1410/**
Simon Glass55f79902022-07-30 15:52:14 -06001411 * ofnode_write_u32() - Set an integer property of an ofnode
1412 *
1413 * @node: The node for whose string property should be set
1414 * @propname: The name of the string property to set
1415 * @value: The new value of the 32-bit integer property
1416 * Return: 0 if successful, -ve on error
1417 */
1418int ofnode_write_u32(ofnode node, const char *propname, u32 value);
1419
1420/**
Mario Sixe369e582018-06-26 08:46:48 +02001421 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1422 * ofnode
1423 *
1424 * This function effectively sets the node's "status" property to either "okay"
1425 * or "disable", hence making it available for driver model initialization or
1426 * not.
1427 *
1428 * @node: The node to enable
1429 * @value: Flag that tells the function to either disable or enable the
1430 * node
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001431 * Return: 0 if successful, -ve on error
Mario Sixe369e582018-06-26 08:46:48 +02001432 */
1433int ofnode_set_enabled(ofnode node, bool value);
1434
Simon Glass7de8bd02021-08-07 07:24:01 -06001435/**
Sean Anderson8b52f232022-03-28 18:14:37 -04001436 * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
1437 *
1438 * This function parses PHY handle from the Ethernet controller's ofnode
1439 * (trying all possible PHY handle property names), and returns the PHY ofnode.
1440 *
1441 * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
1442 * if the result to that is true, this function should not be called.
1443 *
1444 * @eth_node: ofnode belonging to the Ethernet controller
1445 * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
1446 */
1447ofnode ofnode_get_phy_node(ofnode eth_node);
1448
1449/**
1450 * ofnode_read_phy_mode() - Read PHY connection type from a MAC node
1451 *
1452 * This function parses the "phy-mode" / "phy-connection-type" property and
1453 * returns the corresponding PHY interface type.
1454 *
1455 * @mac_node: ofnode containing the property
1456 * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on
1457 * error
1458 */
1459phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
1460
1461#if CONFIG_IS_ENABLED(DM)
1462/**
Simon Glass7de8bd02021-08-07 07:24:01 -06001463 * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config
1464 *
1465 * This reads a property from the /config node of the devicetree.
1466 *
Simon Glass988f1462022-09-06 20:27:28 -06001467 * This only works with the control FDT.
1468 *
1469 * See doc/device-tree-bindings/config.txt for bindings
Simon Glass7de8bd02021-08-07 07:24:01 -06001470 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001471 * @prop_name: property name to look up
1472 * Return: true, if it exists, false if not
Simon Glass7de8bd02021-08-07 07:24:01 -06001473 */
1474bool ofnode_conf_read_bool(const char *prop_name);
1475
1476/**
1477 * ofnode_conf_read_int() - Read an integer value from the U-Boot config
1478 *
1479 * This reads a property from the /config node of the devicetree.
1480 *
Simon Glass988f1462022-09-06 20:27:28 -06001481 * See doc/device-tree-bindings/config.txt for bindings
Simon Glass7de8bd02021-08-07 07:24:01 -06001482 *
1483 * @prop_name: property name to look up
1484 * @default_val: default value to return if the property is not found
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001485 * Return: integer value, if found, or @default_val if not
Simon Glass7de8bd02021-08-07 07:24:01 -06001486 */
1487int ofnode_conf_read_int(const char *prop_name, int default_val);
1488
1489/**
1490 * ofnode_conf_read_str() - Read a string value from the U-Boot config
1491 *
1492 * This reads a property from the /config node of the devicetree.
1493 *
Simon Glass988f1462022-09-06 20:27:28 -06001494 * This only works with the control FDT.
1495 *
1496 * See doc/device-tree-bindings/config.txt for bindings
Simon Glass7de8bd02021-08-07 07:24:01 -06001497 *
1498 * @prop_name: property name to look up
Patrick Delaunaybe74f712022-01-12 10:53:49 +01001499 * Return: string value, if found, or NULL if not
Simon Glass7de8bd02021-08-07 07:24:01 -06001500 */
1501const char *ofnode_conf_read_str(const char *prop_name);
1502
Sean Anderson8b52f232022-03-28 18:14:37 -04001503#else /* CONFIG_DM */
1504static inline bool ofnode_conf_read_bool(const char *prop_name)
1505{
1506 return false;
1507}
Marek Behúnf3dd2132022-04-07 00:32:57 +02001508
Sean Anderson8b52f232022-03-28 18:14:37 -04001509static inline int ofnode_conf_read_int(const char *prop_name, int default_val)
1510{
1511 return default_val;
1512}
1513
1514static inline const char *ofnode_conf_read_str(const char *prop_name)
1515{
1516 return NULL;
1517}
Simon Glassffe90392022-09-06 20:27:02 -06001518
Sean Anderson8b52f232022-03-28 18:14:37 -04001519#endif /* CONFIG_DM */
Marek Behún123ca112022-04-07 00:33:01 +02001520
Simon Glassffe90392022-09-06 20:27:02 -06001521/**
1522 * of_add_subnode() - add a new subnode to a node
1523 *
1524 * @parent: parent node to add to
1525 * @name: name of subnode
1526 * @nodep: returns pointer to new subnode (valid if the function returns 0
1527 * or -EEXIST)
1528 * Returns 0 if OK, -EEXIST if already exists, -ENOMEM if out of memory, other
1529 * -ve on other error
1530 */
1531int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep);
1532
Simon Glassdb1ef1e2022-09-06 20:27:33 -06001533/**
1534 * ofnode_copy_props() - copy all properties from one node to another
1535 *
1536 * Makes a copy of all properties from the source note in the destination node.
1537 * Existing properties in the destination node remain unchanged, except that
1538 * any with the same name are overwritten, including changing the size of the
1539 * property.
1540 *
1541 * For livetree, properties are copied / allocated, so the source tree does not
1542 * need to be present afterwards.
1543 *
1544 * @src: Source node to read properties from
1545 * @dst: Destination node to write properties too
1546 */
1547int ofnode_copy_props(ofnode src, ofnode dst);
1548
Simon Glass4984de22017-05-17 17:18:10 -06001549#endif