blob: 0a85db31f3604ccbe608656768a6957eb346e5e1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass9a148602017-05-17 17:18:10 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass9a148602017-05-17 17:18:10 -06005 */
6
7#ifndef _DM_OFNODE_H
8#define _DM_OFNODE_H
9
Simon Glassc4fc5622017-05-18 20:08:58 -060010/* TODO(sjg@chromium.org): Drop fdtdec.h include */
11#include <fdtdec.h>
12#include <dm/of.h>
Simon Glass39f1d282020-12-16 17:25:06 -070013#include <dm/of_access.h>
Stefan Roesec14df8b2020-09-23 08:23:27 +020014#include <log.h>
Marek Behúnbc194772022-04-07 00:33:01 +020015#include <phy_interface.h>
Simon Glassc4fc5622017-05-18 20:08:58 -060016
17/* Enable checks to protect against invalid calls */
18#undef OF_CHECKS
19
Simon Glassf7bfcc42017-07-25 08:29:55 -060020struct resource;
21
Simon Glass9693c1d2022-07-30 15:52:06 -060022#include <dm/ofnode_decl.h>
Simon Glass9a148602017-05-17 17:18:10 -060023
Simon Glassc4fc5622017-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 Glasscb13a1b2022-09-06 20:27:26 -060030#if CONFIG_IS_ENABLED(OFNODE_MULTI_TREE)
Simon Glassc4fc5622017-05-18 20:08:58 -060031/**
Simon Glassba8457b2022-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 Glasscb13a1b2022-09-06 20:27:26 -060037void oftree_reset(void);
Simon Glassba8457b2022-09-06 20:27:19 -060038
39/**
Simon Glass04fa09a2022-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 Glasscb13a1b2022-09-06 20:27:26 -060047__attribute_const__ void *ofnode_to_fdt(ofnode node);
48
49/**
50 * ofnode_to_offset() - convert an ofnode to a flat DT offset
51 *
52 * This cannot be called if the reference contains a node pointer.
53 *
54 * @node: Reference containing offset (possibly invalid)
55 * Return: DT offset (can be -1)
56 */
57__attribute_const__ int ofnode_to_offset(ofnode node);
58
59/**
60 * oftree_from_fdt() - Returns an oftree from a flat device tree pointer
61 *
Simon Glasse6a211c2022-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 Glasscb13a1b2022-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
Simon Glass04fa09a2022-09-06 20:27:20 -060083static inline void *ofnode_to_fdt(ofnode node)
84{
85#ifdef OF_CHECKS
86 if (of_live_active())
87 return NULL;
88#endif
Simon Glass04fa09a2022-09-06 20:27:20 -060089 /* Use the control FDT by default */
90 return (void *)gd->fdt_blob;
91}
92
Simon Glasscb13a1b2022-09-06 20:27:26 -060093static inline __attribute_const__ int ofnode_to_offset(ofnode node)
Simon Glass37dcd912022-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 Glasscb13a1b2022-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 Glass37dcd912022-09-06 20:27:23 -0600129/**
Stefan Roesec14df8b2020-09-23 08:23:27 +0200130 * ofnode_to_np() - convert an ofnode to a live DT node pointer
Simon Glassc4fc5622017-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 Delaunay92c1c5c2022-01-12 10:53:49 +0100135 * Return: pointer to device node (can be NULL)
Simon Glassc4fc5622017-05-18 20:08:58 -0600136 */
Simon Glass9036c5c2022-09-06 20:27:04 -0600137static inline struct device_node *ofnode_to_np(ofnode node)
Simon Glassc4fc5622017-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 Glass9a148602017-05-17 17:18:10 -0600146/**
Simon Glass9a148602017-05-17 17:18:10 -0600147 * ofnode_valid() - check if an ofnode is valid
148 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100149 * @node: Reference containing offset (possibly invalid)
Simon Glasscb13a1b2022-09-06 20:27:26 -0600150 * Return: true if the reference contains a valid ofnode, false if not
Simon Glass9a148602017-05-17 17:18:10 -0600151 */
152static inline bool ofnode_valid(ofnode node)
153{
Simon Glassc4fc5622017-05-18 20:08:58 -0600154 if (of_live_active())
155 return node.np != NULL;
156 else
Patrick Delaunay04fcfe72020-09-24 17:26:20 +0200157 return node.of_offset >= 0;
Simon Glass9a148602017-05-17 17:18:10 -0600158}
159
160/**
Simon Glass95fd2092022-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 Glass9a148602017-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 Delaunay92c1c5c2022-01-12 10:53:49 +0100180 * Return: reference to the associated DT offset
Simon Glass9a148602017-05-17 17:18:10 -0600181 */
182static inline ofnode offset_to_ofnode(int of_offset)
183{
184 ofnode node;
185
Simon Glassc4fc5622017-05-18 20:08:58 -0600186 if (of_live_active())
187 node.np = NULL;
188 else
Simon Glass1ab8b892019-12-06 21:41:36 -0700189 node.of_offset = of_offset >= 0 ? of_offset : -1;
Simon Glass9a148602017-05-17 17:18:10 -0600190
191 return node;
192}
193
194/**
Simon Glassc4fc5622017-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 Delaunay92c1c5c2022-01-12 10:53:49 +0100198 * Return: reference to the associated node pointer
Simon Glassc4fc5622017-05-18 20:08:58 -0600199 */
Simon Glass9036c5c2022-09-06 20:27:04 -0600200static inline ofnode np_to_ofnode(struct device_node *np)
Simon Glassc4fc5622017-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 Delaunay92c1c5c2022-01-12 10:53:49 +0100217 * Return: true if the reference is a live node pointer, false if it is a DT
Simon Glassc4fc5622017-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 Roesec14df8b2020-09-23 08:23:27 +0200228 (of_live_active() ? ofnode_to_np(node)
229 : ofnode_to_np(node)));
Simon Glassc4fc5622017-05-18 20:08:58 -0600230#endif
231 return of_live_active() && ofnode_valid(node);
232}
233
234/**
Simon Glass9a148602017-05-17 17:18:10 -0600235 * ofnode_equal() - check if two references are equal
236 *
Patrick Delaunay92c1c5c2022-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 Glass9a148602017-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 Glassc4fc5622017-05-18 20:08:58 -0600247/**
Simon Glass2b9b14582022-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 Glassc4fc5622017-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 Glass278ddba2020-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 Glassc4fc5622017-05-18 20:08:58 -0600309/**
Simon Glass4caa79a2022-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 Glassef75c592022-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 Glass2b9b14582022-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 Glass722281b2023-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 Id6388f22021-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 Delaunay92c1c5c2022-01-12 10:53:49 +0100371 * Return: true if matches, false if it doesn't match
Kishon Vijay Abraham Id6388f22021-07-21 21:28:30 +0530372 */
373bool ofnode_name_eq(ofnode node, const char *name);
374
375/**
Stefan Herbrechtsmeier1b090e62022-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 Glassc4fc5622017-05-18 20:08:58 -0600416 * ofnode_read_u32() - Read a 32-bit integer from a property
417 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100418 * @node: valid node reference to read property from
Simon Glassc4fc5622017-05-18 20:08:58 -0600419 * @propname: name of the property to read from
420 * @outp: place to put value (if found)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100421 * Return: 0 if OK, -ve on error
Simon Glassc4fc5622017-05-18 20:08:58 -0600422 */
423int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
424
425/**
Dario Binacchi81d80b52020-03-29 18:04:41 +0200426 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
427 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100428 * @node: valid node reference to read property from
Dario Binacchi81d80b52020-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 Delaunay92c1c5c2022-01-12 10:53:49 +0100432 * Return: 0 if OK, -ve on error
Dario Binacchi81d80b52020-03-29 18:04:41 +0200433 */
434int ofnode_read_u32_index(ofnode node, const char *propname, int index,
435 u32 *outp);
436
437/**
Michal Simek08a194e2023-08-25 11:37:46 +0200438 * ofnode_read_u64_index() - Read a 64-bit integer from a multi-value property
439 *
440 * @node: valid node reference to read property from
441 * @propname: name of the property to read from
442 * @index: index of the integer to return
443 * @outp: place to put value (if found)
444 * Return: 0 if OK, -ve on error
445 */
446int ofnode_read_u64_index(ofnode node, const char *propname, int index,
447 u64 *outp);
448
449/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600450 * ofnode_read_s32() - Read a 32-bit integer from a property
451 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100452 * @node: valid node reference to read property from
Simon Glassc4fc5622017-05-18 20:08:58 -0600453 * @propname: name of the property to read from
454 * @outp: place to put value (if found)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100455 * Return: 0 if OK, -ve on error
Simon Glassc4fc5622017-05-18 20:08:58 -0600456 */
457static inline int ofnode_read_s32(ofnode node, const char *propname,
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100458 s32 *outp)
Simon Glassc4fc5622017-05-18 20:08:58 -0600459{
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100460 return ofnode_read_u32(node, propname, (u32 *)outp);
Simon Glassc4fc5622017-05-18 20:08:58 -0600461}
462
463/**
464 * ofnode_read_u32_default() - Read a 32-bit integer from a property
465 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100466 * @node: valid node reference to read property from
Simon Glassc4fc5622017-05-18 20:08:58 -0600467 * @propname: name of the property to read from
468 * @def: default value to return if the property has no value
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100469 * Return: property value, or @def if not found
Simon Glassc4fc5622017-05-18 20:08:58 -0600470 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100471u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def);
Simon Glassc4fc5622017-05-18 20:08:58 -0600472
473/**
Dario Binacchi81d80b52020-03-29 18:04:41 +0200474 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
475 * property
476 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100477 * @node: valid node reference to read property from
Dario Binacchi81d80b52020-03-29 18:04:41 +0200478 * @propname: name of the property to read from
479 * @index: index of the integer to return
480 * @def: default value to return if the property has no value
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100481 * Return: property value, or @def if not found
Dario Binacchi81d80b52020-03-29 18:04:41 +0200482 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100483u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
Dario Binacchi81d80b52020-03-29 18:04:41 +0200484 u32 def);
485
486/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600487 * ofnode_read_s32_default() - Read a 32-bit integer from a property
488 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100489 * @node: valid node reference to read property from
Simon Glassc4fc5622017-05-18 20:08:58 -0600490 * @propname: name of the property to read from
491 * @def: default value to return if the property has no value
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100492 * Return: property value, or @def if not found
Simon Glassc4fc5622017-05-18 20:08:58 -0600493 */
494int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
495
496/**
Lukas Auerb03a60b2018-11-22 11:26:35 +0100497 * ofnode_read_u64() - Read a 64-bit integer from a property
498 *
499 * @node: valid node reference to read property from
500 * @propname: name of the property to read from
501 * @outp: place to put value (if found)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100502 * Return: 0 if OK, -ve on error
Lukas Auerb03a60b2018-11-22 11:26:35 +0100503 */
504int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
505
506/**
Simon Glass9d54a7a2018-06-11 13:07:10 -0600507 * ofnode_read_u64_default() - Read a 64-bit integer from a property
508 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100509 * @node: valid node reference to read property from
Simon Glass9d54a7a2018-06-11 13:07:10 -0600510 * @propname: name of the property to read from
511 * @def: default value to return if the property has no value
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100512 * Return: property value, or @def if not found
Simon Glass9d54a7a2018-06-11 13:07:10 -0600513 */
T Karthik Reddy478860d2019-09-02 16:34:30 +0200514u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
Simon Glass9d54a7a2018-06-11 13:07:10 -0600515
516/**
Simon Glass0c2e9802020-01-27 08:49:44 -0700517 * ofnode_read_prop() - Read a property from a node
518 *
519 * @node: valid node reference to read property from
520 * @propname: name of the property to read
521 * @sizep: if non-NULL, returns the size of the property, or an error code
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100522 * if not found
523 * Return: property value, or NULL if there is no such property
Simon Glass0c2e9802020-01-27 08:49:44 -0700524 */
525const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
526
527/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600528 * ofnode_read_string() - Read a string from a property
529 *
Simon Glass0c2e9802020-01-27 08:49:44 -0700530 * @node: valid node reference to read property from
Simon Glassc4fc5622017-05-18 20:08:58 -0600531 * @propname: name of the property to read
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100532 * Return: string from property value, or NULL if there is no such property
Simon Glassc4fc5622017-05-18 20:08:58 -0600533 */
534const char *ofnode_read_string(ofnode node, const char *propname);
535
536/**
Simon Glass049ae1b2017-05-18 20:09:01 -0600537 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
Simon Glassc4fc5622017-05-18 20:08:58 -0600538 *
539 * @node: valid node reference to read property from
540 * @propname: name of the property to read
541 * @out_values: pointer to return value, modified only if return value is 0
542 * @sz: number of array elements to read
Simon Glasse3be5fc2022-09-06 20:27:18 -0600543 * Return: 0 on success, -EINVAL if the property does not exist,
544 * -ENODATA if property does not have a value, and -EOVERFLOW if the
545 * property data isn't large enough
Simon Glassc4fc5622017-05-18 20:08:58 -0600546 *
547 * Search for a property in a device node and read 32-bit value(s) from
Simon Glasse3be5fc2022-09-06 20:27:18 -0600548 * it.
Simon Glassc4fc5622017-05-18 20:08:58 -0600549 *
550 * The out_values is modified only if a valid u32 value can be decoded.
551 */
552int ofnode_read_u32_array(ofnode node, const char *propname,
553 u32 *out_values, size_t sz);
554
555/**
556 * ofnode_read_bool() - read a boolean value from a property
557 *
558 * @node: valid node reference to read property from
559 * @propname: name of property to read
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100560 * Return: true if property is present (meaning true), false if not present
Simon Glassc4fc5622017-05-18 20:08:58 -0600561 */
562bool ofnode_read_bool(ofnode node, const char *propname);
563
564/**
565 * ofnode_find_subnode() - find a named subnode of a parent node
566 *
567 * @node: valid reference to parent node
568 * @subnode_name: name of subnode to find
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100569 * Return: reference to subnode (which can be invalid if there is no such
Simon Glassc4fc5622017-05-18 20:08:58 -0600570 * subnode)
571 */
572ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
573
Simon Glass39f1d282020-12-16 17:25:06 -0700574#if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
Simon Glass3ba929a2020-10-30 21:38:53 -0600575#include <asm/global_data.h>
576
Simon Glass39f1d282020-12-16 17:25:06 -0700577static inline bool ofnode_is_enabled(ofnode node)
578{
579 if (ofnode_is_np(node)) {
580 return of_device_is_available(ofnode_to_np(node));
581 } else {
582 return fdtdec_get_is_enabled(gd->fdt_blob,
583 ofnode_to_offset(node));
584 }
585}
586
587static inline ofnode ofnode_first_subnode(ofnode node)
588{
589 assert(ofnode_valid(node));
590 if (ofnode_is_np(node))
591 return np_to_ofnode(node.np->child);
592
593 return offset_to_ofnode(
594 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
595}
596
597static inline ofnode ofnode_next_subnode(ofnode node)
598{
599 assert(ofnode_valid(node));
600 if (ofnode_is_np(node))
601 return np_to_ofnode(node.np->sibling);
602
603 return offset_to_ofnode(
604 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
605}
606#else
607/**
608 * ofnode_is_enabled() - Checks whether a node is enabled.
609 * This looks for a 'status' property. If this exists, then returns true if
610 * the status is 'okay' and false otherwise. If there is no status property,
611 * it returns true on the assumption that anything mentioned should be enabled
612 * by default.
613 *
614 * @node: node to examine
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100615 * Return: false (not enabled) or true (enabled)
Simon Glass39f1d282020-12-16 17:25:06 -0700616 */
617bool ofnode_is_enabled(ofnode node);
618
Simon Glassc4fc5622017-05-18 20:08:58 -0600619/**
620 * ofnode_first_subnode() - find the first subnode of a parent node
621 *
622 * @node: valid reference to a valid parent node
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100623 * Return: reference to the first subnode (which can be invalid if the parent
Simon Glassc4fc5622017-05-18 20:08:58 -0600624 * node has no subnodes)
625 */
626ofnode ofnode_first_subnode(ofnode node);
627
628/**
629 * ofnode_next_subnode() - find the next sibling of a subnode
630 *
631 * @node: valid reference to previous node (sibling)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100632 * Return: reference to the next subnode (which can be invalid if the node
Simon Glassc4fc5622017-05-18 20:08:58 -0600633 * has no more siblings)
634 */
635ofnode ofnode_next_subnode(ofnode node);
Simon Glass39f1d282020-12-16 17:25:06 -0700636#endif /* DM_INLINE_OFNODE */
Simon Glassc4fc5622017-05-18 20:08:58 -0600637
638/**
Philipp Tomsich6fce1dd2018-02-23 17:38:49 +0100639 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
640 *
641 * @node: valid node to look up
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100642 * Return: ofnode reference of the parent node
Philipp Tomsich6fce1dd2018-02-23 17:38:49 +0100643 */
644ofnode ofnode_get_parent(ofnode node);
645
646/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600647 * ofnode_get_name() - get the name of a node
648 *
649 * @node: valid node to look up
Simon Glass91d89a82022-09-06 20:27:15 -0600650 * Return: name of node (for the root node this is "")
Simon Glassc4fc5622017-05-18 20:08:58 -0600651 */
652const char *ofnode_get_name(ofnode node);
653
654/**
Marek Behúne897e3c2021-05-26 14:08:18 +0200655 * ofnode_get_path() - get the full path of a node
656 *
657 * @node: valid node to look up
658 * @buf: buffer to write the node path into
659 * @buflen: buffer size
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100660 * Return: 0 if OK, -ve on error
Marek Behúne897e3c2021-05-26 14:08:18 +0200661 */
662int ofnode_get_path(ofnode node, char *buf, int buflen);
663
664/**
Kever Yang37df0e02018-02-23 17:38:50 +0100665 * ofnode_get_by_phandle() - get ofnode from phandle
666 *
Simon Glass176dd432022-09-06 20:26:57 -0600667 * This uses the default (control) device tree
668 *
Kever Yang37df0e02018-02-23 17:38:50 +0100669 * @phandle: phandle to look up
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100670 * Return: ofnode reference to the phandle
Kever Yang37df0e02018-02-23 17:38:50 +0100671 */
672ofnode ofnode_get_by_phandle(uint phandle);
673
674/**
Simon Glass95fd2092022-09-06 20:27:22 -0600675 * oftree_get_by_phandle() - get ofnode from phandle
676 *
677 * @tree: tree to use
678 * @phandle: phandle to look up
679 * Return: ofnode reference to the phandle
680 */
681ofnode oftree_get_by_phandle(oftree tree, uint phandle);
682
683/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600684 * ofnode_read_size() - read the size of a property
685 *
686 * @node: node to check
687 * @propname: property to check
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100688 * Return: size of property if present, or -EINVAL if not
Simon Glassc4fc5622017-05-18 20:08:58 -0600689 */
690int ofnode_read_size(ofnode node, const char *propname);
691
692/**
Keerthyd332e6e2019-04-24 17:19:53 +0530693 * ofnode_get_addr_size_index() - get an address/size from a node
694 * based on index
695 *
696 * This reads the register address/size from a node based on index
697 *
698 * @node: node to read from
699 * @index: Index of address to read (0 for first)
700 * @size: Pointer to size of the address
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100701 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Keerthyd332e6e2019-04-24 17:19:53 +0530702 */
Johan Jonker9f6971f2023-03-13 01:30:33 +0100703fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index,
704 fdt_size_t *size);
Keerthyd332e6e2019-04-24 17:19:53 +0530705
706/**
Marek Behún177ab7f2021-05-26 14:08:17 +0200707 * ofnode_get_addr_size_index_notrans() - get an address/size from a node
708 * based on index, without address
709 * translation
710 *
711 * This reads the register address/size from a node based on index.
712 * The resulting address is not translated. Useful for example for on-disk
713 * addresses.
714 *
715 * @node: node to read from
716 * @index: Index of address to read (0 for first)
717 * @size: Pointer to size of the address
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100718 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Marek Behún177ab7f2021-05-26 14:08:17 +0200719 */
Johan Jonker9f6971f2023-03-13 01:30:33 +0100720fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
721 fdt_size_t *size);
Marek Behún177ab7f2021-05-26 14:08:17 +0200722
723/**
Simon Glass049ae1b2017-05-18 20:09:01 -0600724 * ofnode_get_addr_index() - get an address from a node
725 *
726 * This reads the register address from a node
727 *
728 * @node: node to read from
729 * @index: Index of address to read (0 for first)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100730 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Simon Glass049ae1b2017-05-18 20:09:01 -0600731 */
Johan Jonker9f6971f2023-03-13 01:30:33 +0100732fdt_addr_t ofnode_get_addr_index(ofnode node, int index);
Simon Glass049ae1b2017-05-18 20:09:01 -0600733
734/**
735 * ofnode_get_addr() - get an address from a node
736 *
737 * This reads the register address from a node
738 *
739 * @node: node to read from
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100740 * Return: address, or FDT_ADDR_T_NONE if not present or invalid
Simon Glass049ae1b2017-05-18 20:09:01 -0600741 */
Johan Jonker9f6971f2023-03-13 01:30:33 +0100742fdt_addr_t ofnode_get_addr(ofnode node);
Simon Glass049ae1b2017-05-18 20:09:01 -0600743
744/**
Chen Guanqiao223f17d2021-04-12 14:51:11 +0800745 * ofnode_get_size() - get size from a node
746 *
747 * This reads the register size from a node
748 *
749 * @node: node to read from
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100750 * Return: size of the address, or FDT_SIZE_T_NONE if not present or invalid
Chen Guanqiao223f17d2021-04-12 14:51:11 +0800751 */
752fdt_size_t ofnode_get_size(ofnode node);
753
754/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600755 * ofnode_stringlist_search() - find a string in a string list and return index
756 *
757 * Note that it is possible for this function to succeed on property values
758 * that are not NUL-terminated. That's because the function will stop after
759 * finding the first occurrence of @string. This can for example happen with
760 * small-valued cell properties, such as #address-cells, when searching for
761 * the empty string.
762 *
763 * @node: node to check
764 * @propname: name of the property containing the string list
765 * @string: string to look up in the string list
766 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100767 * Return:
Simon Glassc4fc5622017-05-18 20:08:58 -0600768 * the index of the string in the list of strings
769 * -ENODATA if the property is not found
770 * -EINVAL on some other error
771 */
772int ofnode_stringlist_search(ofnode node, const char *propname,
773 const char *string);
774
775/**
Simon Glass5fdb0052017-06-12 06:21:28 -0600776 * ofnode_read_string_index() - obtain an indexed string from a string list
Simon Glassc4fc5622017-05-18 20:08:58 -0600777 *
778 * Note that this will successfully extract strings from properties with
779 * non-NUL-terminated values. For example on small-valued cell properties
780 * this function will return the empty string.
781 *
782 * If non-NULL, the length of the string (on success) or a negative error-code
783 * (on failure) will be stored in the integer pointer to by lenp.
784 *
785 * @node: node to check
786 * @propname: name of the property containing the string list
Simon Glass7a3a1672021-10-23 17:26:06 -0600787 * @index: index of the string to return (cannot be negative)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100788 * @outp: return location for the string
Simon Glassc4fc5622017-05-18 20:08:58 -0600789 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100790 * Return:
Simon Glass7a3a1672021-10-23 17:26:06 -0600791 * 0 if found or -ve error value if not found
Simon Glassc4fc5622017-05-18 20:08:58 -0600792 */
793int ofnode_read_string_index(ofnode node, const char *propname, int index,
794 const char **outp);
795
796/**
Simon Glass5fdb0052017-06-12 06:21:28 -0600797 * ofnode_read_string_count() - find the number of strings in a string list
798 *
799 * @node: node to check
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100800 * @property: name of the property containing the string list
801 * Return:
Simon Glass5fdb0052017-06-12 06:21:28 -0600802 * number of strings in the list, or -ve error value if not found
803 */
804int ofnode_read_string_count(ofnode node, const char *property);
805
806/**
Simon Glass9580bfc2021-10-23 17:26:07 -0600807 * ofnode_read_string_list() - read a list of strings
808 *
809 * This produces a list of string pointers with each one pointing to a string
810 * in the string list. If the property does not exist, it returns {NULL}.
811 *
812 * The data is allocated and the caller is reponsible for freeing the return
813 * value (the list of string pointers). The strings themselves may not be
814 * changed as they point directly into the devicetree property.
815 *
816 * @node: node to check
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100817 * @property: name of the property containing the string list
Simon Glass9580bfc2021-10-23 17:26:07 -0600818 * @listp: returns an allocated, NULL-terminated list of strings if the return
819 * value is > 0, else is set to NULL
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100820 * Return:
821 * number of strings in list, 0 if none, -ENOMEM if out of memory,
822 * -EINVAL if no such property, -EENODATA if property is empty
Simon Glass9580bfc2021-10-23 17:26:07 -0600823 */
824int ofnode_read_string_list(ofnode node, const char *property,
825 const char ***listp);
826
827/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600828 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
829 *
830 * This function is useful to parse lists of phandles and their arguments.
831 * Returns 0 on success and fills out_args, on error returns appropriate
832 * errno value.
833 *
834 * Caller is responsible to call of_node_put() on the returned out_args->np
835 * pointer.
836 *
837 * Example:
838 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100839 * .. code-block::
Simon Glassc4fc5622017-05-18 20:08:58 -0600840 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100841 * phandle1: node1 {
842 * #list-cells = <2>;
843 * };
844 * phandle2: node2 {
845 * #list-cells = <1>;
846 * };
847 * node3 {
848 * list = <&phandle1 1 2 &phandle2 3>;
849 * };
Simon Glassc4fc5622017-05-18 20:08:58 -0600850 *
851 * To get a device_node of the `node2' node you may call this:
852 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
853 *
854 * @node: device tree node containing a list
855 * @list_name: property name that contains a list
856 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100857 * @cell_count: Cell count to use if @cells_name is NULL
Simon Glassc4fc5622017-05-18 20:08:58 -0600858 * @index: index of a phandle to parse out
859 * @out_args: optional pointer to output arguments structure (will be filled)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100860 * Return:
861 * 0 on success (with @out_args filled out if not NULL), -ENOENT if
862 * @list_name does not exist, -EINVAL if a phandle was not found,
863 * @cells_name could not be found, the arguments were truncated or there
864 * were too many arguments.
Simon Glassc4fc5622017-05-18 20:08:58 -0600865 */
866int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
867 const char *cells_name, int cell_count,
868 int index,
869 struct ofnode_phandle_args *out_args);
870
871/**
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200872 * ofnode_count_phandle_with_args() - Count number of phandle in a list
873 *
874 * This function is useful to count phandles into a list.
875 * Returns number of phandle on success, on error returns appropriate
876 * errno value.
877 *
878 * @node: device tree node containing a list
879 * @list_name: property name that contains a list
880 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100881 * @cell_count: Cell count to use if @cells_name is NULL
882 * Return:
883 * number of phandle on success, -ENOENT if @list_name does not exist,
884 * -EINVAL if a phandle was not found, @cells_name could not be found.
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200885 */
886int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
Patrick Delaunayd776a842020-09-25 09:41:14 +0200887 const char *cells_name, int cell_count);
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200888
889/**
Simon Glassc4fc5622017-05-18 20:08:58 -0600890 * ofnode_path() - find a node by full path
891 *
Simon Glassef75c592022-07-30 15:52:08 -0600892 * This uses the control FDT.
893 *
Simon Glassc4fc5622017-05-18 20:08:58 -0600894 * @path: Full path to node, e.g. "/bus/spi@1"
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100895 * Return: reference to the node found. Use ofnode_valid() to check if it exists
Simon Glassc4fc5622017-05-18 20:08:58 -0600896 */
897ofnode ofnode_path(const char *path);
898
899/**
Simon Glass45ae59d2022-09-06 20:27:24 -0600900 * oftree_path() - find a node by full path from a root node
Simon Glassef75c592022-07-30 15:52:08 -0600901 *
902 * @tree: Device tree to use
903 * @path: Full path to node, e.g. "/bus/spi@1"
904 * Return: reference to the node found. Use ofnode_valid() to check if it exists
905 */
Simon Glass45ae59d2022-09-06 20:27:24 -0600906ofnode oftree_path(oftree tree, const char *path);
Simon Glassef75c592022-07-30 15:52:08 -0600907
908/**
Simon Glass45ae59d2022-09-06 20:27:24 -0600909 * oftree_root() - get the root node of a tree
910 *
911 * @tree: Device tree to use
912 * Return: reference to the root node
913 */
914ofnode oftree_root(oftree tree);
915
916/**
Simon Glasse09223c2020-01-27 08:49:46 -0700917 * ofnode_read_chosen_prop() - get the value of a chosen property
918 *
Simon Glass45ae59d2022-09-06 20:27:24 -0600919 * This looks for a property within the /chosen node and returns its value.
920 *
921 * This only works with the control FDT.
Simon Glasse09223c2020-01-27 08:49:46 -0700922 *
923 * @propname: Property name to look for
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100924 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
Simon Glasse09223c2020-01-27 08:49:46 -0700925 * returns NULL
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100926 * Return: property value if found, else NULL
Simon Glasse09223c2020-01-27 08:49:46 -0700927 */
928const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
929
930/**
Simon Glassf3455962020-01-27 08:49:43 -0700931 * ofnode_read_chosen_string() - get the string value of a chosen property
Simon Glassc4fc5622017-05-18 20:08:58 -0600932 *
Simon Glassf3455962020-01-27 08:49:43 -0700933 * This looks for a property within the /chosen node and returns its value,
934 * checking that it is a valid nul-terminated string
Simon Glassc4fc5622017-05-18 20:08:58 -0600935 *
Simon Glassc63ffd72022-09-06 20:27:28 -0600936 * This only works with the control FDT.
937 *
Simon Glassc4fc5622017-05-18 20:08:58 -0600938 * @propname: Property name to look for
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100939 * Return: string value if found, else NULL
Simon Glassc4fc5622017-05-18 20:08:58 -0600940 */
Simon Glassf3455962020-01-27 08:49:43 -0700941const char *ofnode_read_chosen_string(const char *propname);
Simon Glassc4fc5622017-05-18 20:08:58 -0600942
943/**
Simon Glassc99ba912020-01-27 08:49:42 -0700944 * ofnode_get_chosen_node() - get a referenced node from the chosen node
Simon Glassc4fc5622017-05-18 20:08:58 -0600945 *
Simon Glassc99ba912020-01-27 08:49:42 -0700946 * This looks up a named property in the chosen node and uses that as a path to
947 * look up a code.
948 *
Simon Glassc63ffd72022-09-06 20:27:28 -0600949 * This only works with the control FDT.
950 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100951 * @propname: Property name to look for
952 * Return: the referenced node if present, else ofnode_null()
Simon Glassc4fc5622017-05-18 20:08:58 -0600953 */
Simon Glassc99ba912020-01-27 08:49:42 -0700954ofnode ofnode_get_chosen_node(const char *propname);
Simon Glassc4fc5622017-05-18 20:08:58 -0600955
Michal Simek92a88622020-07-28 12:51:08 +0200956/**
957 * ofnode_read_aliases_prop() - get the value of a aliases property
958 *
959 * This looks for a property within the /aliases node and returns its value
960 *
Simon Glassc63ffd72022-09-06 20:27:28 -0600961 * This only works with the control FDT.
962 *
Michal Simek92a88622020-07-28 12:51:08 +0200963 * @propname: Property name to look for
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100964 * @sizep: Returns size of property, or `FDT_ERR_...` error code if function
Michal Simek92a88622020-07-28 12:51:08 +0200965 * returns NULL
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100966 * Return: property value if found, else NULL
Michal Simek92a88622020-07-28 12:51:08 +0200967 */
968const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
969
970/**
971 * ofnode_get_aliases_node() - get a referenced node from the aliases node
972 *
973 * This looks up a named property in the aliases node and uses that as a path to
974 * look up a code.
975 *
Simon Glassc63ffd72022-09-06 20:27:28 -0600976 * This only works with the control FDT.
977 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100978 * @propname: Property name to look for
979 * Return: the referenced node if present, else ofnode_null()
Michal Simek92a88622020-07-28 12:51:08 +0200980 */
981ofnode ofnode_get_aliases_node(const char *propname);
982
Simon Glassc4fc5622017-05-18 20:08:58 -0600983struct display_timing;
984/**
985 * ofnode_decode_display_timing() - decode display timings
986 *
987 * Decode display timings from the supplied 'display-timings' node.
988 * See doc/device-tree-bindings/video/display-timing.txt for binding
989 * information.
990 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +0100991 * @node: 'display-timing' node containing the timing subnodes
992 * @index: Index number to read (0=first timing subnode)
993 * @config: Place to put timings
994 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
Simon Glassc4fc5622017-05-18 20:08:58 -0600995 */
996int ofnode_decode_display_timing(ofnode node, int index,
997 struct display_timing *config);
998
999/**
Nikhil M Jainff407062023-01-31 15:35:14 +05301000 * ofnode_decode_panel_timing() - decode display timings
1001 *
1002 * Decode panel timings from the supplied 'panel-timings' node.
1003 *
1004 * @node: 'display-timing' node containing the timing subnodes
1005 * @config: Place to put timings
1006 * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
1007 */
1008int ofnode_decode_panel_timing(ofnode node,
1009 struct display_timing *config);
1010
1011/**
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001012 * ofnode_get_property() - get a pointer to the value of a node property
Simon Glassc4fc5622017-05-18 20:08:58 -06001013 *
1014 * @node: node to read
1015 * @propname: property to read
1016 * @lenp: place to put length on success
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001017 * Return: pointer to property, or NULL if not found
Simon Glassc4fc5622017-05-18 20:08:58 -06001018 */
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +09001019const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
Simon Glassc4fc5622017-05-18 20:08:58 -06001020
1021/**
Simon Glassfec058d2022-09-06 20:27:13 -06001022 * ofnode_first_property()- get the reference of the first property
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001023 *
1024 * Get reference to the first property of the node, it is used to iterate
Simon Glassd0aff8b2022-09-06 20:27:14 -06001025 * and read all the property with ofprop_get_property().
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001026 *
1027 * @node: node to read
1028 * @prop: place to put argument reference
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001029 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001030 */
Simon Glassfec058d2022-09-06 20:27:13 -06001031int ofnode_first_property(ofnode node, struct ofprop *prop);
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001032
1033/**
Simon Glassfec058d2022-09-06 20:27:13 -06001034 * ofnode_next_property() - get the reference of the next property
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001035 *
1036 * Get reference to the next property of the node, it is used to iterate
Simon Glassd0aff8b2022-09-06 20:27:14 -06001037 * and read all the property with ofprop_get_property().
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001038 *
1039 * @prop: reference of current argument and place to put reference of next one
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001040 * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001041 */
Simon Glassfec058d2022-09-06 20:27:13 -06001042int ofnode_next_property(struct ofprop *prop);
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001043
1044/**
Simon Glass4caa79a2022-09-06 20:27:16 -06001045 * ofnode_for_each_prop() - iterate over all properties of a node
1046 *
1047 * @prop: struct ofprop
1048 * @node: node (lvalue, ofnode)
1049 *
1050 * This is a wrapper around a for loop and is used like this::
1051 *
1052 * ofnode node;
1053 * struct ofprop prop;
1054 *
1055 * ofnode_for_each_prop(prop, node) {
1056 * ...use prop...
1057 * }
1058 *
1059 * Note that this is implemented as a macro and @prop is used as
1060 * iterator in the loop. The parent variable can be a constant or even a
1061 * literal.
1062 */
1063#define ofnode_for_each_prop(prop, node) \
1064 for (ofnode_first_property(node, &prop); \
1065 ofprop_valid(&prop); \
1066 ofnode_next_property(&prop))
1067
1068/**
Simon Glassd0aff8b2022-09-06 20:27:14 -06001069 * ofprop_get_property() - get a pointer to the value of a property
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001070 *
1071 * Get value for the property identified by the provided reference.
1072 *
1073 * @prop: reference on property
1074 * @propname: If non-NULL, place to property name on success,
Simon Glassd0aff8b2022-09-06 20:27:14 -06001075 * @lenp: If non-NULL, place to put length on success, or error code on failure
1076 * Return: pointer to property, or NULL if not found
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001077 */
Simon Glassd0aff8b2022-09-06 20:27:14 -06001078const void *ofprop_get_property(const struct ofprop *prop,
1079 const char **propname, int *lenp);
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001080
1081/**
Simon Glassc4fc5622017-05-18 20:08:58 -06001082 * ofnode_get_addr_size() - get address and size from a property
1083 *
1084 * This does no address translation. It simply reads an property that contains
1085 * an address and a size value, one after the other.
1086 *
1087 * @node: node to read from
1088 * @propname: property to read
1089 * @sizep: place to put size value (on success)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001090 * Return: address value, or FDT_ADDR_T_NONE on error
Simon Glassc4fc5622017-05-18 20:08:58 -06001091 */
Johan Jonker9f6971f2023-03-13 01:30:33 +01001092fdt_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
1093 fdt_size_t *sizep);
Simon Glassc4fc5622017-05-18 20:08:58 -06001094
1095/**
1096 * ofnode_read_u8_array_ptr() - find an 8-bit array
1097 *
1098 * Look up a property in a node and return a pointer to its contents as a
1099 * byte array of given length. The property must have at least enough data
1100 * for the array (count bytes). It may have more, but this will be ignored.
1101 * The data is not copied.
1102 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001103 * @node: node to examine
1104 * @propname: name of property to find
1105 * @sz: number of array elements
1106 * Return:
1107 * pointer to byte array if found, or NULL if the property is not found or
1108 * there is not enough data
Simon Glassc4fc5622017-05-18 20:08:58 -06001109 */
1110const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
1111 size_t sz);
1112
1113/**
1114 * ofnode_read_pci_addr() - look up a PCI address
1115 *
1116 * Look at an address property in a node and return the PCI address which
1117 * corresponds to the given type in the form of fdt_pci_addr.
1118 * The property must hold one fdt_pci_addr with a lengh.
1119 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001120 * @node: node to examine
1121 * @type: pci address type (FDT_PCI_SPACE_xxx)
1122 * @propname: name of property to find
1123 * @addr: returns pci address in the form of fdt_pci_addr
1124 * Return:
1125 * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
1126 * format of the property was invalid, -ENXIO if the requested
1127 * address type was not found
Simon Glassc4fc5622017-05-18 20:08:58 -06001128 */
1129int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
1130 const char *propname, struct fdt_pci_addr *addr);
1131
1132/**
Bin Mengfa157712018-08-03 01:14:35 -07001133 * ofnode_read_pci_vendev() - look up PCI vendor and device id
1134 *
1135 * Look at the compatible property of a device node that represents a PCI
1136 * device and extract pci vendor id and device id from it.
1137 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001138 * @node: node to examine
1139 * @vendor: vendor id of the pci device
1140 * @device: device id of the pci device
1141 * Return: 0 if ok, negative on error
Bin Mengfa157712018-08-03 01:14:35 -07001142 */
1143int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
1144
1145/**
Michal Simeka253c3b2022-02-23 15:45:40 +01001146 * ofnode_read_eth_phy_id() - look up eth phy vendor and device id
1147 *
1148 * Look at the compatible property of a device node that represents a eth phy
1149 * device and extract phy vendor id and device id from it.
1150 *
Heinrich Schuchardtc9ae4a82022-03-24 16:22:32 +01001151 * @node: node to examine
1152 * @vendor: vendor id of the eth phy device
1153 * @device: device id of the eth phy device
1154 * Return: 0 if ok, negative on error
Michal Simeka253c3b2022-02-23 15:45:40 +01001155 */
1156int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device);
1157
1158/**
Simon Glassc4fc5622017-05-18 20:08:58 -06001159 * ofnode_read_addr_cells() - Get the number of address cells for a node
1160 *
1161 * This walks back up the tree to find the closest #address-cells property
1162 * which controls the given node.
1163 *
1164 * @node: Node to check
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001165 * Return: number of address cells this node uses
Simon Glassc4fc5622017-05-18 20:08:58 -06001166 */
1167int ofnode_read_addr_cells(ofnode node);
1168
1169/**
1170 * ofnode_read_size_cells() - Get the number of size cells for a node
1171 *
1172 * This walks back up the tree to find the closest #size-cells property
1173 * which controls the given node.
1174 *
1175 * @node: Node to check
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001176 * Return: number of size cells this node uses
Simon Glassc4fc5622017-05-18 20:08:58 -06001177 */
1178int ofnode_read_size_cells(ofnode node);
1179
1180/**
Simon Glass4191dc12017-06-12 06:21:31 -06001181 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
1182 *
1183 * This function matches fdt_address_cells().
1184 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001185 * @node: Node to check
1186 * Return: value of #address-cells property in this node, or 2 if none
Simon Glass4191dc12017-06-12 06:21:31 -06001187 */
1188int ofnode_read_simple_addr_cells(ofnode node);
1189
1190/**
1191 * ofnode_read_simple_size_cells() - Get the size cells property in a node
1192 *
1193 * This function matches fdt_size_cells().
1194 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001195 * @node: Node to check
1196 * Return: value of #size-cells property in this node, or 2 if none
Simon Glass4191dc12017-06-12 06:21:31 -06001197 */
1198int ofnode_read_simple_size_cells(ofnode node);
1199
1200/**
Simon Glassc4fc5622017-05-18 20:08:58 -06001201 * ofnode_pre_reloc() - check if a node should be bound before relocation
1202 *
1203 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
1204 * via special device tree properties.
1205 *
1206 * Before relocation this function can be used to check if nodes are required
1207 * in either SPL or TPL stages.
1208 *
1209 * After relocation and jumping into the real U-Boot binary it is possible to
1210 * determine if a node was bound in one of SPL/TPL stages.
1211 *
Patrick Delaunay63e4d112019-05-21 19:19:13 +02001212 * There are 4 settings currently in use
Simon Glassfc1aa352023-02-13 08:56:34 -07001213 * - bootph-some-ram: U-Boot proper pre-relocation only
1214 * - bootph-all: all phases
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001215 * Existing platforms only use it to indicate nodes needed in
Simon Glassfc1aa352023-02-13 08:56:34 -07001216 * SPL. Should probably be replaced by bootph-pre-ram for new platforms.
1217 * - bootph-pre-ram: SPL and U-Boot pre-relocation
1218 * - bootph-pre-sram: TPL and U-Boot pre-relocation
Simon Glassc4fc5622017-05-18 20:08:58 -06001219 *
1220 * @node: node to check
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001221 * Return: true if node is needed in SPL/TL, false otherwise
Simon Glassc4fc5622017-05-18 20:08:58 -06001222 */
1223bool ofnode_pre_reloc(ofnode node);
1224
Simon Glassa8173d62018-06-11 13:07:12 -06001225/**
1226 * ofnode_read_resource() - Read a resource from a node
1227 *
1228 * Read resource information from a node at the given index
1229 *
1230 * @node: Node to read from
1231 * @index: Index of resource to read (0 = first)
1232 * @res: Returns resource that was read, on success
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001233 * Return: 0 if OK, -ve on error
Simon Glassa8173d62018-06-11 13:07:12 -06001234 */
Simon Glassf7bfcc42017-07-25 08:29:55 -06001235int ofnode_read_resource(ofnode node, uint index, struct resource *res);
Simon Glassa8173d62018-06-11 13:07:12 -06001236
1237/**
1238 * ofnode_read_resource_byname() - Read a resource from a node by name
1239 *
1240 * Read resource information from a node matching the given name. This uses a
1241 * 'reg-names' string list property with the names matching the associated
1242 * 'reg' property list.
1243 *
1244 * @node: Node to read from
1245 * @name: Name of resource to read
1246 * @res: Returns resource that was read, on success
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001247 * Return: 0 if OK, -ve on error
Simon Glassa8173d62018-06-11 13:07:12 -06001248 */
Masahiro Yamada4dada2c2017-08-26 01:12:30 +09001249int ofnode_read_resource_byname(ofnode node, const char *name,
1250 struct resource *res);
Simon Glassf7bfcc42017-07-25 08:29:55 -06001251
Simon Glass28529762017-08-05 15:45:54 -06001252/**
Simon Glass954eeae2018-06-11 13:07:13 -06001253 * ofnode_by_compatible() - Find the next compatible node
1254 *
1255 * Find the next node after @from that is compatible with @compat
1256 *
1257 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
1258 * @compat: Compatible string to match
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001259 * Return: ofnode found, or ofnode_null() if none
Simon Glass954eeae2018-06-11 13:07:13 -06001260 */
1261ofnode ofnode_by_compatible(ofnode from, const char *compat);
1262
1263/**
Jens Wiklander7b68dad2018-08-20 11:09:58 +02001264 * ofnode_by_prop_value() - Find the next node with given property value
1265 *
1266 * Find the next node after @from that has a @propname with a value
1267 * @propval and a length @proplen.
1268 *
Simon Glass37dcd912022-09-06 20:27:23 -06001269 * @from: ofnode to start from. Use ofnode_null() to start at the
1270 * beginning, or the return value from oftree_root() to start at the first
1271 * child of the root
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001272 * @propname: property name to check
1273 * @propval: property value to search for
1274 * @proplen: length of the value in propval
1275 * Return: ofnode found, or ofnode_null() if none
Jens Wiklander7b68dad2018-08-20 11:09:58 +02001276 */
1277ofnode ofnode_by_prop_value(ofnode from, const char *propname,
1278 const void *propval, int proplen);
1279
1280/**
Simon Glass28529762017-08-05 15:45:54 -06001281 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
1282 *
1283 * @node: child node (ofnode, lvalue)
1284 * @parent: parent node (ofnode)
1285 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001286 * This is a wrapper around a for loop and is used like so::
Simon Glass28529762017-08-05 15:45:54 -06001287 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001288 * ofnode node;
1289 * ofnode_for_each_subnode(node, parent) {
1290 * Use node
1291 * ...
1292 * }
Simon Glass28529762017-08-05 15:45:54 -06001293 *
1294 * Note that this is implemented as a macro and @node is used as
1295 * iterator in the loop. The parent variable can be a constant or even a
1296 * literal.
1297 */
1298#define ofnode_for_each_subnode(node, parent) \
1299 for (node = ofnode_first_subnode(parent); \
1300 ofnode_valid(node); \
1301 node = ofnode_next_subnode(node))
1302
Mario Sixaefac062018-01-15 11:07:19 +01001303/**
Michael Wallea7b9df22021-10-15 15:15:17 +02001304 * ofnode_for_each_compatible_node() - iterate over all nodes with a given
1305 * compatible string
1306 *
1307 * @node: child node (ofnode, lvalue)
1308 * @compat: compatible string to match
1309 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001310 * This is a wrapper around a for loop and is used like so::
Michael Wallea7b9df22021-10-15 15:15:17 +02001311 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001312 * ofnode node;
1313 * ofnode_for_each_compatible_node(node, parent, compatible) {
1314 * Use node
1315 * ...
1316 * }
Michael Wallea7b9df22021-10-15 15:15:17 +02001317 *
1318 * Note that this is implemented as a macro and @node is used as
1319 * iterator in the loop.
1320 */
1321#define ofnode_for_each_compatible_node(node, compat) \
1322 for (node = ofnode_by_compatible(ofnode_null(), compat); \
1323 ofnode_valid(node); \
1324 node = ofnode_by_compatible(node, compat))
1325
1326/**
developerd93c8b42020-05-02 11:35:09 +02001327 * ofnode_get_child_count() - get the child count of a ofnode
1328 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001329 * @parent: valid node to get its child count
1330 * Return: the number of subnodes
developerd93c8b42020-05-02 11:35:09 +02001331 */
1332int ofnode_get_child_count(ofnode parent);
1333
1334/**
Fabien Dessenne22236e02019-05-31 15:11:30 +02001335 * ofnode_translate_address() - Translate a device-tree address
Mario Sixaefac062018-01-15 11:07:19 +01001336 *
1337 * Translate an address from the device-tree into a CPU physical address. This
1338 * function walks up the tree and applies the various bus mappings along the
1339 * way.
1340 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001341 * @node: Device tree node giving the context in which to translate the address
Mario Sixaefac062018-01-15 11:07:19 +01001342 * @in_addr: pointer to the address to translate
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001343 * Return: the translated address; OF_BAD_ADDR on error
Mario Sixaefac062018-01-15 11:07:19 +01001344 */
1345u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
Masahiro Yamada9349bcc2018-04-19 12:14:02 +09001346
1347/**
Fabien Dessenne22236e02019-05-31 15:11:30 +02001348 * ofnode_translate_dma_address() - Translate a device-tree DMA address
1349 *
1350 * Translate a DMA address from the device-tree into a CPU physical address.
1351 * This function walks up the tree and applies the various bus mappings along
1352 * the way.
1353 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001354 * @node: Device tree node giving the context in which to translate the
1355 * DMA address
Fabien Dessenne22236e02019-05-31 15:11:30 +02001356 * @in_addr: pointer to the DMA address to translate
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001357 * Return: the translated DMA address; OF_BAD_ADDR on error
Fabien Dessenne22236e02019-05-31 15:11:30 +02001358 */
1359u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
1360
1361/**
Nicolas Saenz Julienne50d2fa42021-01-12 13:55:22 +01001362 * ofnode_get_dma_range() - get dma-ranges for a specific DT node
1363 *
1364 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
1365 * cpu->bus address translations
1366 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001367 * @node: Device tree node
1368 * @cpu: Pointer to variable storing the range's cpu address
1369 * @bus: Pointer to variable storing the range's bus address
1370 * @size: Pointer to variable storing the range's size
1371 * Return: translated DMA address or OF_BAD_ADDR on error
Nicolas Saenz Julienne50d2fa42021-01-12 13:55:22 +01001372 */
1373int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
1374 u64 *size);
1375
1376/**
Masahiro Yamada9349bcc2018-04-19 12:14:02 +09001377 * ofnode_device_is_compatible() - check if the node is compatible with compat
1378 *
1379 * This allows to check whether the node is comaptible with the compat.
1380 *
1381 * @node: Device tree node for which compatible needs to be verified.
1382 * @compat: Compatible string which needs to verified in the given node.
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001383 * Return: true if OK, false if the compatible is not found
Masahiro Yamada9349bcc2018-04-19 12:14:02 +09001384 */
1385int ofnode_device_is_compatible(ofnode node, const char *compat);
Mario Six047dafc2018-06-26 08:46:48 +02001386
1387/**
1388 * ofnode_write_prop() - Set a property of a ofnode
1389 *
Simon Glass17abed02022-09-06 20:27:32 -06001390 * Note that if @copy is false, the value passed to the function is *not*
1391 * allocated by the function itself, but must be allocated by the caller if
1392 * necessary. However it does allocate memory for the property struct and name.
Mario Six047dafc2018-06-26 08:46:48 +02001393 *
1394 * @node: The node for whose property should be set
1395 * @propname: The name of the property to set
Mario Six047dafc2018-06-26 08:46:48 +02001396 * @value: The new value of the property (must be valid prior to calling
1397 * the function)
Simon Glass5e2cd5e2022-07-30 15:52:10 -06001398 * @len: The length of the new value of the property
Simon Glass17abed02022-09-06 20:27:32 -06001399 * @copy: true to allocate memory for the value. This only has any effect with
1400 * live tree, since flat tree handles this automatically. It allows a
1401 * node's value to be written to the tree, without requiring that the
1402 * caller allocate it
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001403 * Return: 0 if successful, -ve on error
Mario Six047dafc2018-06-26 08:46:48 +02001404 */
Simon Glass5e2cd5e2022-07-30 15:52:10 -06001405int ofnode_write_prop(ofnode node, const char *propname, const void *value,
Simon Glass17abed02022-09-06 20:27:32 -06001406 int len, bool copy);
Mario Six047dafc2018-06-26 08:46:48 +02001407
1408/**
1409 * ofnode_write_string() - Set a string property of a ofnode
1410 *
1411 * Note that the value passed to the function is *not* allocated by the
1412 * function itself, but must be allocated by the caller if necessary.
1413 *
1414 * @node: The node for whose string property should be set
1415 * @propname: The name of the string property to set
1416 * @value: The new value of the string property (must be valid prior to
1417 * calling the function)
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001418 * Return: 0 if successful, -ve on error
Mario Six047dafc2018-06-26 08:46:48 +02001419 */
1420int ofnode_write_string(ofnode node, const char *propname, const char *value);
1421
1422/**
Simon Glassd28e31e2022-07-30 15:52:14 -06001423 * ofnode_write_u32() - Set an integer property of an ofnode
1424 *
1425 * @node: The node for whose string property should be set
1426 * @propname: The name of the string property to set
1427 * @value: The new value of the 32-bit integer property
1428 * Return: 0 if successful, -ve on error
1429 */
1430int ofnode_write_u32(ofnode node, const char *propname, u32 value);
1431
1432/**
Mario Six047dafc2018-06-26 08:46:48 +02001433 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1434 * ofnode
1435 *
1436 * This function effectively sets the node's "status" property to either "okay"
1437 * or "disable", hence making it available for driver model initialization or
1438 * not.
1439 *
1440 * @node: The node to enable
1441 * @value: Flag that tells the function to either disable or enable the
1442 * node
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001443 * Return: 0 if successful, -ve on error
Mario Six047dafc2018-06-26 08:46:48 +02001444 */
1445int ofnode_set_enabled(ofnode node, bool value);
1446
Simon Glass0034d962021-08-07 07:24:01 -06001447/**
Sean Anderson9b3a6392022-03-28 18:14:37 -04001448 * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
1449 *
1450 * This function parses PHY handle from the Ethernet controller's ofnode
1451 * (trying all possible PHY handle property names), and returns the PHY ofnode.
1452 *
1453 * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
1454 * if the result to that is true, this function should not be called.
1455 *
1456 * @eth_node: ofnode belonging to the Ethernet controller
1457 * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
1458 */
1459ofnode ofnode_get_phy_node(ofnode eth_node);
1460
1461/**
1462 * ofnode_read_phy_mode() - Read PHY connection type from a MAC node
1463 *
1464 * This function parses the "phy-mode" / "phy-connection-type" property and
1465 * returns the corresponding PHY interface type.
1466 *
1467 * @mac_node: ofnode containing the property
1468 * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on
1469 * error
1470 */
1471phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
1472
1473#if CONFIG_IS_ENABLED(DM)
1474/**
Simon Glass0034d962021-08-07 07:24:01 -06001475 * ofnode_conf_read_bool() - Read a boolean value from the U-Boot config
1476 *
1477 * This reads a property from the /config node of the devicetree.
1478 *
Simon Glassc63ffd72022-09-06 20:27:28 -06001479 * This only works with the control FDT.
1480 *
1481 * See doc/device-tree-bindings/config.txt for bindings
Simon Glass0034d962021-08-07 07:24:01 -06001482 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001483 * @prop_name: property name to look up
1484 * Return: true, if it exists, false if not
Simon Glass0034d962021-08-07 07:24:01 -06001485 */
1486bool ofnode_conf_read_bool(const char *prop_name);
1487
1488/**
1489 * ofnode_conf_read_int() - Read an integer value from the U-Boot config
1490 *
1491 * This reads a property from the /config node of the devicetree.
1492 *
Simon Glassc63ffd72022-09-06 20:27:28 -06001493 * See doc/device-tree-bindings/config.txt for bindings
Simon Glass0034d962021-08-07 07:24:01 -06001494 *
1495 * @prop_name: property name to look up
1496 * @default_val: default value to return if the property is not found
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001497 * Return: integer value, if found, or @default_val if not
Simon Glass0034d962021-08-07 07:24:01 -06001498 */
1499int ofnode_conf_read_int(const char *prop_name, int default_val);
1500
1501/**
1502 * ofnode_conf_read_str() - Read a string value from the U-Boot config
1503 *
1504 * This reads a property from the /config node of the devicetree.
1505 *
Simon Glassc63ffd72022-09-06 20:27:28 -06001506 * This only works with the control FDT.
1507 *
1508 * See doc/device-tree-bindings/config.txt for bindings
Simon Glass0034d962021-08-07 07:24:01 -06001509 *
1510 * @prop_name: property name to look up
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +01001511 * Return: string value, if found, or NULL if not
Simon Glass0034d962021-08-07 07:24:01 -06001512 */
1513const char *ofnode_conf_read_str(const char *prop_name);
1514
Sean Anderson9b3a6392022-03-28 18:14:37 -04001515#else /* CONFIG_DM */
1516static inline bool ofnode_conf_read_bool(const char *prop_name)
1517{
1518 return false;
1519}
Marek Behúnf4f1ddc2022-04-07 00:32:57 +02001520
Sean Anderson9b3a6392022-03-28 18:14:37 -04001521static inline int ofnode_conf_read_int(const char *prop_name, int default_val)
1522{
1523 return default_val;
1524}
1525
1526static inline const char *ofnode_conf_read_str(const char *prop_name)
1527{
1528 return NULL;
1529}
Simon Glass56bc3322022-09-06 20:27:02 -06001530
Sean Anderson9b3a6392022-03-28 18:14:37 -04001531#endif /* CONFIG_DM */
Marek Behúnbc194772022-04-07 00:33:01 +02001532
Simon Glass56bc3322022-09-06 20:27:02 -06001533/**
1534 * of_add_subnode() - add a new subnode to a node
1535 *
1536 * @parent: parent node to add to
1537 * @name: name of subnode
1538 * @nodep: returns pointer to new subnode (valid if the function returns 0
1539 * or -EEXIST)
1540 * Returns 0 if OK, -EEXIST if already exists, -ENOMEM if out of memory, other
1541 * -ve on other error
1542 */
1543int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep);
1544
Simon Glass7a7229a2022-09-06 20:27:33 -06001545/**
1546 * ofnode_copy_props() - copy all properties from one node to another
1547 *
1548 * Makes a copy of all properties from the source note in the destination node.
1549 * Existing properties in the destination node remain unchanged, except that
1550 * any with the same name are overwritten, including changing the size of the
1551 * property.
1552 *
1553 * For livetree, properties are copied / allocated, so the source tree does not
1554 * need to be present afterwards.
1555 *
1556 * @src: Source node to read properties from
1557 * @dst: Destination node to write properties too
1558 */
1559int ofnode_copy_props(ofnode src, ofnode dst);
1560
Simon Glass9a148602017-05-17 17:18:10 -06001561#endif