blob: b1a6108544031ea15ac50572606dcb1cf3947278 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass34ef0c22017-05-18 20:09:03 -06002/*
3 * Function to read values from the device tree node attached to a udevice.
4 *
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
Simon Glass34ef0c22017-05-18 20:09:03 -06007 */
8
9#ifndef _DM_READ_H
10#define _DM_READ_H
11
Dan Murphyd3aa90e2020-07-23 07:01:38 -050012#include <linux/errno.h>
13
Simon Glass34ef0c22017-05-18 20:09:03 -060014#include <dm/fdtaddr.h>
15#include <dm/ofnode.h>
16#include <dm/uclass.h>
17
Simon Glass170e17c2017-06-12 06:21:29 -060018struct resource;
19
Simon Glass34ef0c22017-05-18 20:09:03 -060020#if CONFIG_IS_ENABLED(OF_LIVE)
Simon Glass2f9a6122020-01-27 08:49:40 -070021static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glass34ef0c22017-05-18 20:09:03 -060022{
23 return ofnode_to_np(dev->node);
24}
25#else
Simon Glass2f9a6122020-01-27 08:49:40 -070026static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glass34ef0c22017-05-18 20:09:03 -060027{
28 return NULL;
29}
30#endif
31
32/**
33 * dev_ofnode() - get the DT node reference associated with a udevice
34 *
35 * @dev: device to check
36 * @return reference of the the device's DT node
37 */
Simon Glass2a580882020-01-27 08:49:36 -070038static inline ofnode dev_ofnode(const struct udevice *dev)
Simon Glass34ef0c22017-05-18 20:09:03 -060039{
40 return dev->node;
41}
42
Simon Glass2a580882020-01-27 08:49:36 -070043static inline bool dev_of_valid(const struct udevice *dev)
Simon Glass34ef0c22017-05-18 20:09:03 -060044{
45 return ofnode_valid(dev_ofnode(dev));
46}
47
Simon Glasscfdae5c2017-05-18 20:09:04 -060048#ifndef CONFIG_DM_DEV_READ_INLINE
T Karthik Reddy478860d2019-09-02 16:34:30 +020049
Simon Glasscfdae5c2017-05-18 20:09:04 -060050/**
Masahiro Yamada71d115f2017-12-30 02:00:05 +090051 * dev_read_u32() - read a 32-bit integer from a device's DT property
52 *
53 * @dev: device to read DT property from
54 * @propname: name of the property to read from
55 * @outp: place to put value (if found)
56 * @return 0 if OK, -ve on error
57 */
Simon Glass2f9a6122020-01-27 08:49:40 -070058int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
Masahiro Yamada71d115f2017-12-30 02:00:05 +090059
60/**
Simon Glasscfdae5c2017-05-18 20:09:04 -060061 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
62 *
63 * @dev: device to read DT property from
64 * @propname: name of the property to read from
65 * @def: default value to return if the property has no value
66 * @return property value, or @def if not found
67 */
Simon Glass2f9a6122020-01-27 08:49:40 -070068int dev_read_u32_default(const struct udevice *dev, const char *propname,
69 int def);
Simon Glass34ef0c22017-05-18 20:09:03 -060070
71/**
Dario Binacchi81d80b52020-03-29 18:04:41 +020072 * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
73 * property
74 *
75 * @dev: device to read DT property from
76 * @propname: name of the property to read from
77 * @index: index of the integer to return
78 * @outp: place to put value (if found)
79 * @return 0 if OK, -ve on error
80 */
81int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
82 u32 *outp);
83
84/**
85 * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
86 * DT property
87 *
88 * @dev: device to read DT property from
89 * @propname: name of the property to read from
90 * @index: index of the integer to return
91 * @def: default value to return if the property has no value
92 * @return property value, or @def if not found
93 */
94u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
95 int index, u32 def);
96
97/**
Simon Glass6df01f92018-12-10 10:37:37 -070098 * dev_read_s32() - read a signed 32-bit integer from a device's DT property
99 *
100 * @dev: device to read DT property from
101 * @propname: name of the property to read from
102 * @outp: place to put value (if found)
103 * @return 0 if OK, -ve on error
104 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700105int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
Simon Glass6df01f92018-12-10 10:37:37 -0700106
107/**
108 * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
109 *
110 * @dev: device to read DT property from
111 * @propname: name of the property to read from
112 * @def: default value to return if the property has no value
113 * @return property value, or @def if not found
114 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700115int dev_read_s32_default(const struct udevice *dev, const char *propname,
116 int def);
Simon Glass6df01f92018-12-10 10:37:37 -0700117
118/**
119 * dev_read_u32u() - read a 32-bit integer from a device's DT property
120 *
121 * This version uses a standard uint type.
122 *
123 * @dev: device to read DT property from
124 * @propname: name of the property to read from
125 * @outp: place to put value (if found)
126 * @return 0 if OK, -ve on error
127 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700128int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
Simon Glass6df01f92018-12-10 10:37:37 -0700129
130/**
T Karthik Reddy478860d2019-09-02 16:34:30 +0200131 * dev_read_u64() - read a 64-bit integer from a device's DT property
132 *
133 * @dev: device to read DT property from
134 * @propname: name of the property to read from
135 * @outp: place to put value (if found)
136 * @return 0 if OK, -ve on error
137 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700138int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
T Karthik Reddy478860d2019-09-02 16:34:30 +0200139
140/**
141 * dev_read_u64_default() - read a 64-bit integer from a device's DT property
142 *
143 * @dev: device to read DT property from
144 * @propname: name of the property to read from
145 * @def: default value to return if the property has no value
146 * @return property value, or @def if not found
147 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700148u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
149 u64 def);
T Karthik Reddy478860d2019-09-02 16:34:30 +0200150
151/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600152 * dev_read_string() - Read a string from a device's DT property
153 *
154 * @dev: device to read DT property from
155 * @propname: name of the property to read
156 * @return string from property value, or NULL if there is no such property
157 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700158const char *dev_read_string(const struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600159
160/**
161 * dev_read_bool() - read a boolean value from a device's DT property
162 *
163 * @dev: device to read DT property from
164 * @propname: name of property to read
165 * @return true if property is present (meaning true), false if not present
166 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700167bool dev_read_bool(const struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600168
169/**
170 * dev_read_subnode() - find a named subnode of a device
171 *
172 * @dev: device whose DT node contains the subnode
173 * @subnode_name: name of subnode to find
174 * @return reference to subnode (which can be invalid if there is no such
175 * subnode)
176 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700177ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
Simon Glass34ef0c22017-05-18 20:09:03 -0600178
179/**
180 * dev_read_size() - read the size of a property
181 *
182 * @dev: device to check
183 * @propname: property to check
184 * @return size of property if present, or -EINVAL if not
185 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700186int dev_read_size(const struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600187
188/**
189 * dev_read_addr_index() - Get the indexed reg property of a device
190 *
191 * @dev: Device to read from
192 * @index: the 'reg' property can hold a list of <addr, size> pairs
193 * and @index is used to select which one is required
194 *
195 * @return address or FDT_ADDR_T_NONE if not found
196 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700197fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
Simon Glass34ef0c22017-05-18 20:09:03 -0600198
199/**
Sekhar Norif677c6f2019-08-01 19:12:56 +0530200 * dev_read_addr_size_index() - Get the indexed reg property of a device
201 *
202 * @dev: Device to read from
203 * @index: the 'reg' property can hold a list of <addr, size> pairs
204 * and @index is used to select which one is required
205 * @size: place to put size value (on success)
206 *
207 * @return address or FDT_ADDR_T_NONE if not found
208 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700209fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
Sekhar Norif677c6f2019-08-01 19:12:56 +0530210 fdt_size_t *size);
211
212/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200213 * dev_remap_addr_index() - Get the indexed reg property of a device
214 * as a memory-mapped I/O pointer
215 *
216 * @dev: Device to read from
217 * @index: the 'reg' property can hold a list of <addr, size> pairs
218 * and @index is used to select which one is required
219 *
220 * @return pointer or NULL if not found
221 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700222void *dev_remap_addr_index(const struct udevice *dev, int index);
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200223
224/**
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100225 * dev_read_addr_name() - Get the reg property of a device, indexed by name
226 *
227 * @dev: Device to read from
228 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
229 * 'reg-names' property providing named-based identification. @index
230 * indicates the value to search for in 'reg-names'.
231 *
232 * @return address or FDT_ADDR_T_NONE if not found
233 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700234fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100235
236/**
Sekhar Norif677c6f2019-08-01 19:12:56 +0530237 * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
238 *
239 * @dev: Device to read from
240 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
241 * 'reg-names' property providing named-based identification. @index
242 * indicates the value to search for in 'reg-names'.
243 * @size: place to put size value (on success)
244 *
245 * @return address or FDT_ADDR_T_NONE if not found
246 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700247fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
Sekhar Norif677c6f2019-08-01 19:12:56 +0530248 fdt_size_t *size);
249
250/**
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100251 * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
252 * as a memory-mapped I/O pointer
253 *
254 * @dev: Device to read from
255 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
256 * 'reg-names' property providing named-based identification. @index
257 * indicates the value to search for in 'reg-names'.
258 *
259 * @return pointer or NULL if not found
260 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700261void *dev_remap_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100262
263/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600264 * dev_read_addr() - Get the reg property of a device
265 *
266 * @dev: Device to read from
267 *
268 * @return address or FDT_ADDR_T_NONE if not found
269 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700270fdt_addr_t dev_read_addr(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600271
272/**
Philipp Tomsich7719b392017-09-11 22:04:12 +0200273 * dev_read_addr_ptr() - Get the reg property of a device
274 * as a pointer
275 *
276 * @dev: Device to read from
277 *
278 * @return pointer or NULL if not found
279 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700280void *dev_read_addr_ptr(const struct udevice *dev);
Philipp Tomsich7719b392017-09-11 22:04:12 +0200281
282/**
Simon Glass23b27592019-09-15 12:08:58 -0600283 * dev_read_addr_pci() - Read an address and handle PCI address translation
284 *
285 * At present U-Boot does not have address translation logic for PCI in the
286 * livetree implementation (of_addr.c). This special function supports this for
287 * the flat tree implementation.
288 *
289 * This function should be removed (and code should use dev_read() instead)
290 * once:
291 *
292 * 1. PCI address translation is added; and either
293 * 2. everything uses livetree where PCI translation is used (which is feasible
294 * in SPL and U-Boot proper) or PCI address translation is added to
295 * fdtdec_get_addr() and friends.
296 *
297 * @dev: Device to read from
298 * @return address or FDT_ADDR_T_NONE if not found
299 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700300fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
Simon Glass23b27592019-09-15 12:08:58 -0600301
302/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200303 * dev_remap_addr() - Get the reg property of a device as a
304 * memory-mapped I/O pointer
305 *
306 * @dev: Device to read from
307 *
308 * @return pointer or NULL if not found
309 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700310void *dev_remap_addr(const struct udevice *dev);
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200311
312/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600313 * dev_read_addr_size() - get address and size from a device property
314 *
315 * This does no address translation. It simply reads an property that contains
316 * an address and a size value, one after the other.
317 *
318 * @dev: Device to read from
319 * @propname: property to read
320 * @sizep: place to put size value (on success)
321 * @return address value, or FDT_ADDR_T_NONE on error
322 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700323fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
324 fdt_size_t *sizep);
Simon Glass34ef0c22017-05-18 20:09:03 -0600325
326/**
327 * dev_read_name() - get the name of a device's node
328 *
Bin Meng4cf914d2019-07-05 09:23:18 -0700329 * @dev: Device to read from
Simon Glass34ef0c22017-05-18 20:09:03 -0600330 * @return name of node
331 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700332const char *dev_read_name(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600333
334/**
335 * dev_read_stringlist_search() - find string in a string list and return index
336 *
337 * Note that it is possible for this function to succeed on property values
338 * that are not NUL-terminated. That's because the function will stop after
339 * finding the first occurrence of @string. This can for example happen with
340 * small-valued cell properties, such as #address-cells, when searching for
341 * the empty string.
342 *
343 * @dev: device to check
344 * @propname: name of the property containing the string list
345 * @string: string to look up in the string list
346 *
347 * @return:
348 * the index of the string in the list of strings
349 * -ENODATA if the property is not found
350 * -EINVAL on some other error
351 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700352int dev_read_stringlist_search(const struct udevice *dev, const char *property,
353 const char *string);
Simon Glass34ef0c22017-05-18 20:09:03 -0600354
355/**
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200356 * dev_read_string_index() - obtain an indexed string from a string list
357 *
358 * @dev: device to examine
359 * @propname: name of the property containing the string list
360 * @index: index of the string to return
361 * @out: return location for the string
362 *
363 * @return:
364 * length of string, if found or -ve error value if not found
365 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700366int dev_read_string_index(const struct udevice *dev, const char *propname,
367 int index, const char **outp);
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200368
369/**
370 * dev_read_string_count() - find the number of strings in a string list
371 *
372 * @dev: device to examine
373 * @propname: name of the property containing the string list
374 * @return:
375 * number of strings in the list, or -ve error value if not found
376 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700377int dev_read_string_count(const struct udevice *dev, const char *propname);
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200378/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600379 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
380 *
381 * This function is useful to parse lists of phandles and their arguments.
382 * Returns 0 on success and fills out_args, on error returns appropriate
383 * errno value.
384 *
385 * Caller is responsible to call of_node_put() on the returned out_args->np
386 * pointer.
387 *
388 * Example:
389 *
390 * phandle1: node1 {
391 * #list-cells = <2>;
392 * }
393 *
394 * phandle2: node2 {
395 * #list-cells = <1>;
396 * }
397 *
398 * node3 {
399 * list = <&phandle1 1 2 &phandle2 3>;
400 * }
401 *
402 * To get a device_node of the `node2' node you may call this:
403 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
404 *
405 * @dev: device whose node containing a list
406 * @list_name: property name that contains a list
407 * @cells_name: property name that specifies phandles' arguments count
408 * @cells_count: Cell count to use if @cells_name is NULL
409 * @index: index of a phandle to parse out
410 * @out_args: optional pointer to output arguments structure (will be filled)
411 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
412 * @list_name does not exist, -EINVAL if a phandle was not found,
413 * @cells_name could not be found, the arguments were truncated or there
414 * were too many arguments.
415 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700416int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
417 const char *cells_name, int cell_count,
418 int index, struct ofnode_phandle_args *out_args);
Simon Glass34ef0c22017-05-18 20:09:03 -0600419
420/**
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200421 * dev_count_phandle_with_args() - Return phandle number in a list
422 *
423 * This function is usefull to get phandle number contained in a property list.
424 * For example, this allows to allocate the right amount of memory to keep
425 * clock's reference contained into the "clocks" property.
426 *
427 *
428 * @dev: device whose node containing a list
429 * @list_name: property name that contains a list
430 * @cells_name: property name that specifies phandles' arguments count
431 * @Returns number of phandle found on success, on error returns appropriate
432 * errno value.
433 */
434
Simon Glass2f9a6122020-01-27 08:49:40 -0700435int dev_count_phandle_with_args(const struct udevice *dev,
436 const char *list_name, const char *cells_name);
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200437
438/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600439 * dev_read_addr_cells() - Get the number of address cells for a device's node
440 *
441 * This walks back up the tree to find the closest #address-cells property
442 * which controls the given node.
443 *
Mario Six16408ee2018-01-15 11:09:36 +0100444 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600445 * @return number of address cells this node uses
446 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700447int dev_read_addr_cells(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600448
449/**
450 * dev_read_size_cells() - Get the number of size cells for a device's node
451 *
452 * This walks back up the tree to find the closest #size-cells property
453 * which controls the given node.
454 *
Mario Six16408ee2018-01-15 11:09:36 +0100455 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600456 * @return number of size cells this node uses
457 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700458int dev_read_size_cells(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600459
460/**
Simon Glass4191dc12017-06-12 06:21:31 -0600461 * dev_read_addr_cells() - Get the address cells property in a node
462 *
463 * This function matches fdt_address_cells().
464 *
Mario Six16408ee2018-01-15 11:09:36 +0100465 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600466 * @return number of address cells this node uses
467 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700468int dev_read_simple_addr_cells(const struct udevice *dev);
Simon Glass4191dc12017-06-12 06:21:31 -0600469
470/**
471 * dev_read_size_cells() - Get the size cells property in a node
472 *
473 * This function matches fdt_size_cells().
474 *
Mario Six16408ee2018-01-15 11:09:36 +0100475 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600476 * @return number of size cells this node uses
477 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700478int dev_read_simple_size_cells(const struct udevice *dev);
Simon Glass4191dc12017-06-12 06:21:31 -0600479
480/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600481 * dev_read_phandle() - Get the phandle from a device
482 *
483 * @dev: device to check
484 * @return phandle (1 or greater), or 0 if no phandle or other error
485 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700486int dev_read_phandle(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600487
488/**
489 * dev_read_prop()- - read a property from a device's node
490 *
491 * @dev: device to check
492 * @propname: property to read
493 * @lenp: place to put length on success
494 * @return pointer to property, or NULL if not found
495 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700496const void *dev_read_prop(const struct udevice *dev, const char *propname,
497 int *lenp);
Simon Glass34ef0c22017-05-18 20:09:03 -0600498
499/**
Patrick Delaunaycaee1552020-01-13 11:34:56 +0100500 * dev_read_first_prop()- get the reference of the first property
501 *
502 * Get reference to the first property of the node, it is used to iterate
503 * and read all the property with dev_read_prop_by_prop().
504 *
505 * @dev: device to check
506 * @prop: place to put argument reference
507 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
508 */
509int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
510
511/**
512 * ofnode_get_next_property() - get the reference of the next property
513 *
514 * Get reference to the next property of the node, it is used to iterate
515 * and read all the property with dev_read_prop_by_prop().
516 *
517 * @prop: reference of current argument and place to put reference of next one
518 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
519 */
520int dev_read_next_prop(struct ofprop *prop);
521
522/**
523 * dev_read_prop_by_prop() - get a pointer to the value of a property
524 *
525 * Get value for the property identified by the provided reference.
526 *
527 * @prop: reference on property
528 * @propname: If non-NULL, place to property name on success,
529 * @lenp: If non-NULL, place to put length on success
530 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
531 */
532const void *dev_read_prop_by_prop(struct ofprop *prop,
533 const char **propname, int *lenp);
534
535/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600536 * dev_read_alias_seq() - Get the alias sequence number of a node
537 *
538 * This works out whether a node is pointed to by an alias, and if so, the
539 * sequence number of that alias. Aliases are of the form <base><num> where
540 * <num> is the sequence number. For example spi2 would be sequence number 2.
541 *
542 * @dev: device to look up
543 * @devnump: set to the sequence number if one is found
544 * @return 0 if a sequence was found, -ve if not
545 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700546int dev_read_alias_seq(const struct udevice *dev, int *devnump);
Simon Glass34ef0c22017-05-18 20:09:03 -0600547
548/**
549 * dev_read_u32_array() - Find and read an array of 32 bit integers
550 *
551 * Search for a property in a device node and read 32-bit value(s) from
552 * it.
553 *
554 * The out_values is modified only if a valid u32 value can be decoded.
555 *
556 * @dev: device to look up
557 * @propname: name of the property to read
558 * @out_values: pointer to return value, modified only if return value is 0
559 * @sz: number of array elements to read
560 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
561 * property does not have a value, and -EOVERFLOW if the property data isn't
562 * large enough.
563 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700564int dev_read_u32_array(const struct udevice *dev, const char *propname,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600565 u32 *out_values, size_t sz);
Simon Glass34ef0c22017-05-18 20:09:03 -0600566
567/**
568 * dev_read_first_subnode() - find the first subnode of a device's node
569 *
570 * @dev: device to look up
571 * @return reference to the first subnode (which can be invalid if the device's
572 * node has no subnodes)
573 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700574ofnode dev_read_first_subnode(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600575
576/**
577 * ofnode_next_subnode() - find the next sibling of a subnode
578 *
579 * @node: valid reference to previous node (sibling)
580 * @return reference to the next subnode (which can be invalid if the node
581 * has no more siblings)
582 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600583ofnode dev_read_next_subnode(ofnode node);
Simon Glass34ef0c22017-05-18 20:09:03 -0600584
585/**
586 * dev_read_u8_array_ptr() - find an 8-bit array
587 *
588 * Look up a device's node property and return a pointer to its contents as a
589 * byte array of given length. The property must have at least enough data
590 * for the array (count bytes). It may have more, but this will be ignored.
591 * The data is not copied.
592 *
593 * @dev: device to look up
594 * @propname: name of property to find
595 * @sz: number of array elements
596 * @return pointer to byte array if found, or NULL if the property is not
597 * found or there is not enough data
598 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700599const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
600 const char *propname, size_t sz);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600601
Simon Glassfa031f82017-06-12 06:21:30 -0600602/**
603 * dev_read_enabled() - check whether a node is enabled
604 *
605 * This looks for a 'status' property. If this exists, then returns 1 if
606 * the status is 'ok' and 0 otherwise. If there is no status property,
607 * it returns 1 on the assumption that anything mentioned should be enabled
608 * by default.
609 *
610 * @dev: device to examine
611 * @return integer value 0 (not enabled) or 1 (enabled)
612 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700613int dev_read_enabled(const struct udevice *dev);
Simon Glassfa031f82017-06-12 06:21:30 -0600614
Simon Glassf7bfcc42017-07-25 08:29:55 -0600615/**
616 * dev_read_resource() - obtain an indexed resource from a device.
617 *
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900618 * @dev: device to examine
Simon Glassf7bfcc42017-07-25 08:29:55 -0600619 * @index index of the resource to retrieve (0 = first)
620 * @res returns the resource
621 * @return 0 if ok, negative on error
622 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700623int dev_read_resource(const struct udevice *dev, uint index,
624 struct resource *res);
Simon Glassf7bfcc42017-07-25 08:29:55 -0600625
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900626/**
627 * dev_read_resource_byname() - obtain a named resource from a device.
628 *
629 * @dev: device to examine
630 * @name: name of the resource to retrieve
631 * @res: returns the resource
632 * @return 0 if ok, negative on error
633 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700634int dev_read_resource_byname(const struct udevice *dev, const char *name,
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900635 struct resource *res);
636
Mario Sixaefac062018-01-15 11:07:19 +0100637/**
Fabien Dessenne22236e02019-05-31 15:11:30 +0200638 * dev_translate_address() - Translate a device-tree address
Mario Sixaefac062018-01-15 11:07:19 +0100639 *
640 * Translate an address from the device-tree into a CPU physical address. This
641 * function walks up the tree and applies the various bus mappings along the
642 * way.
643 *
644 * @dev: device giving the context in which to translate the address
645 * @in_addr: pointer to the address to translate
646 * @return the translated address; OF_BAD_ADDR on error
647 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700648u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
Michal Simekd0e30a02019-01-31 16:30:59 +0100649
650/**
Fabien Dessenne22236e02019-05-31 15:11:30 +0200651 * dev_translate_dma_address() - Translate a device-tree DMA address
652 *
653 * Translate a DMA address from the device-tree into a CPU physical address.
654 * This function walks up the tree and applies the various bus mappings along
655 * the way.
656 *
657 * @dev: device giving the context in which to translate the DMA address
658 * @in_addr: pointer to the DMA address to translate
659 * @return the translated DMA address; OF_BAD_ADDR on error
660 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700661u64 dev_translate_dma_address(const struct udevice *dev,
662 const fdt32_t *in_addr);
Fabien Dessenne22236e02019-05-31 15:11:30 +0200663
664/**
Michal Simekd0e30a02019-01-31 16:30:59 +0100665 * dev_read_alias_highest_id - Get highest alias id for the given stem
666 * @stem: Alias stem to be examined
667 *
668 * The function travels the lookup table to get the highest alias id for the
669 * given alias stem.
670 * @return alias ID, if found, else -1
671 */
672int dev_read_alias_highest_id(const char *stem);
673
developerd93c8b42020-05-02 11:35:09 +0200674/**
675 * dev_get_child_count() - get the child count of a device
676 *
677 * @dev: device to use for interation (struct udevice *)
678 * @return the count of child subnode
679 */
680int dev_get_child_count(const struct udevice *dev);
681
Simon Glasscfdae5c2017-05-18 20:09:04 -0600682#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
683
Simon Glass2f9a6122020-01-27 08:49:40 -0700684static inline int dev_read_u32(const struct udevice *dev,
Masahiro Yamada71d115f2017-12-30 02:00:05 +0900685 const char *propname, u32 *outp)
686{
687 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
688}
689
Simon Glass2f9a6122020-01-27 08:49:40 -0700690static inline int dev_read_u32_default(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600691 const char *propname, int def)
692{
693 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
694}
695
Dario Binacchi81d80b52020-03-29 18:04:41 +0200696static inline int dev_read_u32_index(struct udevice *dev,
697 const char *propname, int index, u32 *outp)
698{
699 return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
700}
701
702static inline u32 dev_read_u32_index_default(struct udevice *dev,
703 const char *propname, int index,
704 u32 def)
705{
706 return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
707 def);
708}
709
Simon Glass2f9a6122020-01-27 08:49:40 -0700710static inline int dev_read_s32(const struct udevice *dev,
Simon Glass6df01f92018-12-10 10:37:37 -0700711 const char *propname, s32 *outp)
712{
713 return ofnode_read_s32(dev_ofnode(dev), propname, outp);
714}
715
Simon Glass2f9a6122020-01-27 08:49:40 -0700716static inline int dev_read_s32_default(const struct udevice *dev,
Simon Glass6df01f92018-12-10 10:37:37 -0700717 const char *propname, int def)
718{
719 return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
720}
721
Simon Glass2f9a6122020-01-27 08:49:40 -0700722static inline int dev_read_u32u(const struct udevice *dev,
Simon Glass6df01f92018-12-10 10:37:37 -0700723 const char *propname, uint *outp)
724{
725 u32 val;
726 int ret;
727
728 ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
729 if (ret)
730 return ret;
731 *outp = val;
732
733 return 0;
734}
735
Simon Glass2f9a6122020-01-27 08:49:40 -0700736static inline int dev_read_u64(const struct udevice *dev,
T Karthik Reddy478860d2019-09-02 16:34:30 +0200737 const char *propname, u64 *outp)
738{
739 return ofnode_read_u64(dev_ofnode(dev), propname, outp);
740}
741
Simon Glass2f9a6122020-01-27 08:49:40 -0700742static inline u64 dev_read_u64_default(const struct udevice *dev,
T Karthik Reddy478860d2019-09-02 16:34:30 +0200743 const char *propname, u64 def)
744{
745 return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
746}
747
Simon Glass2f9a6122020-01-27 08:49:40 -0700748static inline const char *dev_read_string(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600749 const char *propname)
750{
751 return ofnode_read_string(dev_ofnode(dev), propname);
752}
753
Simon Glass2f9a6122020-01-27 08:49:40 -0700754static inline bool dev_read_bool(const struct udevice *dev,
755 const char *propname)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600756{
757 return ofnode_read_bool(dev_ofnode(dev), propname);
758}
759
Simon Glass2f9a6122020-01-27 08:49:40 -0700760static inline ofnode dev_read_subnode(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600761 const char *subbnode_name)
762{
763 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
764}
765
Simon Glass2f9a6122020-01-27 08:49:40 -0700766static inline int dev_read_size(const struct udevice *dev, const char *propname)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600767{
768 return ofnode_read_size(dev_ofnode(dev), propname);
769}
770
Simon Glass2f9a6122020-01-27 08:49:40 -0700771static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
772 int index)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600773{
774 return devfdt_get_addr_index(dev, index);
775}
776
Simon Glass2f9a6122020-01-27 08:49:40 -0700777static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
Sekhar Norif677c6f2019-08-01 19:12:56 +0530778 int index,
779 fdt_size_t *size)
780{
781 return devfdt_get_addr_size_index(dev, index, size);
782}
783
Simon Glass2f9a6122020-01-27 08:49:40 -0700784static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100785 const char *name)
786{
787 return devfdt_get_addr_name(dev, name);
788}
789
Simon Glass2f9a6122020-01-27 08:49:40 -0700790static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
Sekhar Norif677c6f2019-08-01 19:12:56 +0530791 const char *name,
792 fdt_size_t *size)
793{
794 return devfdt_get_addr_size_name(dev, name, size);
795}
796
Simon Glass2f9a6122020-01-27 08:49:40 -0700797static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600798{
799 return devfdt_get_addr(dev);
800}
801
Simon Glass2f9a6122020-01-27 08:49:40 -0700802static inline void *dev_read_addr_ptr(const struct udevice *dev)
Philipp Tomsich7719b392017-09-11 22:04:12 +0200803{
Sean Anderson42db70b2020-06-24 06:41:13 -0400804 void *addr = devfdt_get_addr_ptr(dev);
805
806 return ((fdt_addr_t)(uintptr_t)addr == FDT_ADDR_T_NONE) ? NULL : addr;
Philipp Tomsich7719b392017-09-11 22:04:12 +0200807}
808
Simon Glass2f9a6122020-01-27 08:49:40 -0700809static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
Simon Glass23b27592019-09-15 12:08:58 -0600810{
811 return devfdt_get_addr_pci(dev);
812}
813
Simon Glass2f9a6122020-01-27 08:49:40 -0700814static inline void *dev_remap_addr(const struct udevice *dev)
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200815{
816 return devfdt_remap_addr(dev);
817}
818
Simon Glass2f9a6122020-01-27 08:49:40 -0700819static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200820{
821 return devfdt_remap_addr_index(dev, index);
822}
823
Simon Glass2f9a6122020-01-27 08:49:40 -0700824static inline void *dev_remap_addr_name(const struct udevice *dev,
825 const char *name)
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100826{
827 return devfdt_remap_addr_name(dev, name);
828}
829
Simon Glass2f9a6122020-01-27 08:49:40 -0700830static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600831 const char *propname,
832 fdt_size_t *sizep)
833{
834 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
835}
836
Simon Glass2f9a6122020-01-27 08:49:40 -0700837static inline const char *dev_read_name(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600838{
839 return ofnode_get_name(dev_ofnode(dev));
840}
841
Simon Glass2f9a6122020-01-27 08:49:40 -0700842static inline int dev_read_stringlist_search(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600843 const char *propname,
844 const char *string)
845{
846 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
847}
848
Simon Glass2f9a6122020-01-27 08:49:40 -0700849static inline int dev_read_string_index(const struct udevice *dev,
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200850 const char *propname, int index,
851 const char **outp)
852{
853 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
854}
855
Simon Glass2f9a6122020-01-27 08:49:40 -0700856static inline int dev_read_string_count(const struct udevice *dev,
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200857 const char *propname)
858{
859 return ofnode_read_string_count(dev_ofnode(dev), propname);
860}
861
Simon Glass2f9a6122020-01-27 08:49:40 -0700862static inline int dev_read_phandle_with_args(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600863 const char *list_name, const char *cells_name, int cell_count,
864 int index, struct ofnode_phandle_args *out_args)
865{
866 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
867 cells_name, cell_count, index,
868 out_args);
869}
870
Simon Glass2f9a6122020-01-27 08:49:40 -0700871static inline int dev_count_phandle_with_args(const struct udevice *dev,
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200872 const char *list_name, const char *cells_name)
873{
874 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
875 cells_name);
876}
877
Simon Glass2f9a6122020-01-27 08:49:40 -0700878static inline int dev_read_addr_cells(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600879{
Simon Glass4191dc12017-06-12 06:21:31 -0600880 /* NOTE: this call should walk up the parent stack */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600881 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
882}
883
Simon Glass2f9a6122020-01-27 08:49:40 -0700884static inline int dev_read_size_cells(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600885{
Simon Glass4191dc12017-06-12 06:21:31 -0600886 /* NOTE: this call should walk up the parent stack */
887 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
888}
889
Simon Glass2f9a6122020-01-27 08:49:40 -0700890static inline int dev_read_simple_addr_cells(const struct udevice *dev)
Simon Glass4191dc12017-06-12 06:21:31 -0600891{
892 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
893}
894
Simon Glass2f9a6122020-01-27 08:49:40 -0700895static inline int dev_read_simple_size_cells(const struct udevice *dev)
Simon Glass4191dc12017-06-12 06:21:31 -0600896{
Simon Glasscfdae5c2017-05-18 20:09:04 -0600897 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
898}
899
Simon Glass2f9a6122020-01-27 08:49:40 -0700900static inline int dev_read_phandle(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600901{
902 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
903}
904
Simon Glass2f9a6122020-01-27 08:49:40 -0700905static inline const void *dev_read_prop(const struct udevice *dev,
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900906 const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600907{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900908 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600909}
910
Patrick Delaunaycaee1552020-01-13 11:34:56 +0100911static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
912{
913 return ofnode_get_first_property(dev_ofnode(dev), prop);
914}
915
916static inline int dev_read_next_prop(struct ofprop *prop)
917{
918 return ofnode_get_next_property(prop);
919}
920
921static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
922 const char **propname,
923 int *lenp)
924{
925 return ofnode_get_property_by_prop(prop, propname, lenp);
926}
927
Simon Glass2f9a6122020-01-27 08:49:40 -0700928static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600929{
Marcel Ziswiler65c2bf62019-05-20 02:44:57 +0200930#if CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600931 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
932 dev_of_offset(dev), devnump);
Marcel Ziswiler65c2bf62019-05-20 02:44:57 +0200933#else
934 return -ENOTSUPP;
935#endif
Simon Glasscfdae5c2017-05-18 20:09:04 -0600936}
937
Simon Glass2f9a6122020-01-27 08:49:40 -0700938static inline int dev_read_u32_array(const struct udevice *dev,
939 const char *propname, u32 *out_values,
940 size_t sz)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600941{
942 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
943}
944
Simon Glass2f9a6122020-01-27 08:49:40 -0700945static inline ofnode dev_read_first_subnode(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600946{
947 return ofnode_first_subnode(dev_ofnode(dev));
948}
949
950static inline ofnode dev_read_next_subnode(ofnode node)
951{
952 return ofnode_next_subnode(node);
953}
954
Simon Glass2f9a6122020-01-27 08:49:40 -0700955static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
Simon Glass000676b2020-01-27 08:49:47 -0700956 const char *propname,
957 size_t sz)
Simon Glass34ef0c22017-05-18 20:09:03 -0600958{
959 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
960}
961
Simon Glass2f9a6122020-01-27 08:49:40 -0700962static inline int dev_read_enabled(const struct udevice *dev)
Simon Glassfa031f82017-06-12 06:21:30 -0600963{
964 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
965}
966
Simon Glass2f9a6122020-01-27 08:49:40 -0700967static inline int dev_read_resource(const struct udevice *dev, uint index,
Simon Glassf7bfcc42017-07-25 08:29:55 -0600968 struct resource *res)
969{
970 return ofnode_read_resource(dev_ofnode(dev), index, res);
971}
972
Simon Glass2f9a6122020-01-27 08:49:40 -0700973static inline int dev_read_resource_byname(const struct udevice *dev,
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900974 const char *name,
975 struct resource *res)
976{
977 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
978}
979
Simon Glass2f9a6122020-01-27 08:49:40 -0700980static inline u64 dev_translate_address(const struct udevice *dev,
981 const fdt32_t *in_addr)
Mario Sixaefac062018-01-15 11:07:19 +0100982{
983 return ofnode_translate_address(dev_ofnode(dev), in_addr);
984}
985
Simon Glass2f9a6122020-01-27 08:49:40 -0700986static inline u64 dev_translate_dma_address(const struct udevice *dev,
987 const fdt32_t *in_addr)
Fabien Dessenne22236e02019-05-31 15:11:30 +0200988{
989 return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
990}
991
Michal Simekd0e30a02019-01-31 16:30:59 +0100992static inline int dev_read_alias_highest_id(const char *stem)
993{
Michael Walleeccf2d02020-06-02 01:47:08 +0200994 if (!CONFIG_IS_ENABLED(OF_LIBFDT))
995 return -1;
Michal Simekd0e30a02019-01-31 16:30:59 +0100996 return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
997}
998
developerd93c8b42020-05-02 11:35:09 +0200999static inline int dev_get_child_count(const struct udevice *dev)
1000{
1001 return ofnode_get_child_count(dev_ofnode(dev));
1002}
1003
Simon Glass34ef0c22017-05-18 20:09:03 -06001004#endif /* CONFIG_DM_DEV_READ_INLINE */
1005
1006/**
1007 * dev_for_each_subnode() - Helper function to iterate through subnodes
1008 *
1009 * This creates a for() loop which works through the subnodes in a device's
1010 * device-tree node.
1011 *
1012 * @subnode: ofnode holding the current subnode
1013 * @dev: device to use for interation (struct udevice *)
1014 */
1015#define dev_for_each_subnode(subnode, dev) \
1016 for (subnode = dev_read_first_subnode(dev); \
1017 ofnode_valid(subnode); \
1018 subnode = ofnode_next_subnode(subnode))
1019
Patrick Delaunaycaee1552020-01-13 11:34:56 +01001020/**
1021 * dev_for_each_property() - Helper function to iterate through property
1022 *
1023 * This creates a for() loop which works through the property in a device's
1024 * device-tree node.
1025 *
1026 * @prop: struct ofprop holding the current property
1027 * @dev: device to use for interation (struct udevice *)
1028 */
1029#define dev_for_each_property(prop, dev) \
1030 for (int ret_prop = dev_read_first_prop(dev, &prop); \
1031 !ret_prop; \
1032 ret_prop = dev_read_next_prop(&prop))
1033
Simon Glass34ef0c22017-05-18 20:09:03 -06001034#endif