blob: 0a7aacd2d04ccb0a567f5002dd46ecad803ed045 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassf11c7ab2017-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 Glassf11c7ab2017-05-18 20:09:03 -06007 */
8
9#ifndef _DM_READ_H
10#define _DM_READ_H
11
Dan Murphy9beacb62020-07-23 07:01:38 -050012#include <linux/errno.h>
13
Simon Glass2a64ada2020-07-19 10:15:39 -060014#include <dm/device.h>
Simon Glassf11c7ab2017-05-18 20:09:03 -060015#include <dm/fdtaddr.h>
16#include <dm/ofnode.h>
17#include <dm/uclass.h>
18
Simon Glassa4481012017-06-12 06:21:29 -060019struct resource;
20
Simon Glassf11c7ab2017-05-18 20:09:03 -060021#if CONFIG_IS_ENABLED(OF_LIVE)
Simon Glass88b3a372020-01-27 08:49:40 -070022static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glassf11c7ab2017-05-18 20:09:03 -060023{
24 return ofnode_to_np(dev->node);
25}
26#else
Simon Glass88b3a372020-01-27 08:49:40 -070027static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glassf11c7ab2017-05-18 20:09:03 -060028{
29 return NULL;
30}
31#endif
32
33/**
34 * dev_ofnode() - get the DT node reference associated with a udevice
35 *
36 * @dev: device to check
37 * @return reference of the the device's DT node
38 */
Simon Glassfc347fb2020-01-27 08:49:36 -070039static inline ofnode dev_ofnode(const struct udevice *dev)
Simon Glassf11c7ab2017-05-18 20:09:03 -060040{
41 return dev->node;
42}
43
Simon Glassfc347fb2020-01-27 08:49:36 -070044static inline bool dev_of_valid(const struct udevice *dev)
Simon Glassf11c7ab2017-05-18 20:09:03 -060045{
46 return ofnode_valid(dev_ofnode(dev));
47}
48
Simon Glass47a0fd32017-05-18 20:09:04 -060049#ifndef CONFIG_DM_DEV_READ_INLINE
T Karthik Reddy3f3d7712019-09-02 16:34:30 +020050
Simon Glass47a0fd32017-05-18 20:09:04 -060051/**
Masahiro Yamada3ab48f62017-12-30 02:00:05 +090052 * dev_read_u32() - read a 32-bit integer from a device's DT property
53 *
54 * @dev: device to read DT property from
55 * @propname: name of the property to read from
56 * @outp: place to put value (if found)
57 * @return 0 if OK, -ve on error
58 */
Simon Glass88b3a372020-01-27 08:49:40 -070059int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
Masahiro Yamada3ab48f62017-12-30 02:00:05 +090060
61/**
Simon Glass47a0fd32017-05-18 20:09:04 -060062 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
63 *
64 * @dev: device to read DT property from
65 * @propname: name of the property to read from
66 * @def: default value to return if the property has no value
67 * @return property value, or @def if not found
68 */
Simon Glass88b3a372020-01-27 08:49:40 -070069int dev_read_u32_default(const struct udevice *dev, const char *propname,
70 int def);
Simon Glassf11c7ab2017-05-18 20:09:03 -060071
72/**
Dario Binacchi4bb70752020-03-29 18:04:41 +020073 * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
74 * property
75 *
76 * @dev: device to read DT property from
77 * @propname: name of the property to read from
78 * @index: index of the integer to return
79 * @outp: place to put value (if found)
80 * @return 0 if OK, -ve on error
81 */
82int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
83 u32 *outp);
84
85/**
86 * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
87 * DT property
88 *
89 * @dev: device to read DT property from
90 * @propname: name of the property to read from
91 * @index: index of the integer to return
92 * @def: default value to return if the property has no value
93 * @return property value, or @def if not found
94 */
95u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
96 int index, u32 def);
97
98/**
Simon Glassa1b17e42018-12-10 10:37:37 -070099 * dev_read_s32() - read a signed 32-bit integer from a device's DT property
100 *
101 * @dev: device to read DT property from
102 * @propname: name of the property to read from
103 * @outp: place to put value (if found)
104 * @return 0 if OK, -ve on error
105 */
Simon Glass88b3a372020-01-27 08:49:40 -0700106int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
Simon Glassa1b17e42018-12-10 10:37:37 -0700107
108/**
109 * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
110 *
111 * @dev: device to read DT property from
112 * @propname: name of the property to read from
113 * @def: default value to return if the property has no value
114 * @return property value, or @def if not found
115 */
Simon Glass88b3a372020-01-27 08:49:40 -0700116int dev_read_s32_default(const struct udevice *dev, const char *propname,
117 int def);
Simon Glassa1b17e42018-12-10 10:37:37 -0700118
119/**
120 * dev_read_u32u() - read a 32-bit integer from a device's DT property
121 *
122 * This version uses a standard uint type.
123 *
124 * @dev: device to read DT property from
125 * @propname: name of the property to read from
126 * @outp: place to put value (if found)
127 * @return 0 if OK, -ve on error
128 */
Simon Glass88b3a372020-01-27 08:49:40 -0700129int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
Simon Glassa1b17e42018-12-10 10:37:37 -0700130
131/**
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200132 * dev_read_u64() - read a 64-bit integer from a device's DT property
133 *
134 * @dev: device to read DT property from
135 * @propname: name of the property to read from
136 * @outp: place to put value (if found)
137 * @return 0 if OK, -ve on error
138 */
Simon Glass88b3a372020-01-27 08:49:40 -0700139int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200140
141/**
142 * dev_read_u64_default() - read a 64-bit integer from a device's DT property
143 *
144 * @dev: device to read DT property from
145 * @propname: name of the property to read from
146 * @def: default value to return if the property has no value
147 * @return property value, or @def if not found
148 */
Simon Glass88b3a372020-01-27 08:49:40 -0700149u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
150 u64 def);
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200151
152/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600153 * dev_read_string() - Read a string from a device's DT property
154 *
155 * @dev: device to read DT property from
156 * @propname: name of the property to read
157 * @return string from property value, or NULL if there is no such property
158 */
Simon Glass88b3a372020-01-27 08:49:40 -0700159const char *dev_read_string(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600160
161/**
162 * dev_read_bool() - read a boolean value from a device's DT property
163 *
164 * @dev: device to read DT property from
165 * @propname: name of property to read
166 * @return true if property is present (meaning true), false if not present
167 */
Simon Glass88b3a372020-01-27 08:49:40 -0700168bool dev_read_bool(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600169
170/**
171 * dev_read_subnode() - find a named subnode of a device
172 *
173 * @dev: device whose DT node contains the subnode
174 * @subnode_name: name of subnode to find
175 * @return reference to subnode (which can be invalid if there is no such
176 * subnode)
177 */
Simon Glass88b3a372020-01-27 08:49:40 -0700178ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600179
180/**
181 * dev_read_size() - read the size of a property
182 *
183 * @dev: device to check
184 * @propname: property to check
185 * @return size of property if present, or -EINVAL if not
186 */
Simon Glass88b3a372020-01-27 08:49:40 -0700187int dev_read_size(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600188
189/**
190 * dev_read_addr_index() - Get the indexed reg property of a device
191 *
192 * @dev: Device to read from
193 * @index: the 'reg' property can hold a list of <addr, size> pairs
194 * and @index is used to select which one is required
195 *
196 * @return address or FDT_ADDR_T_NONE if not found
197 */
Simon Glass88b3a372020-01-27 08:49:40 -0700198fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600199
200/**
Sekhar Norif5b90472019-08-01 19:12:56 +0530201 * dev_read_addr_size_index() - Get the indexed reg property of a device
202 *
203 * @dev: Device to read from
204 * @index: the 'reg' property can hold a list of <addr, size> pairs
205 * and @index is used to select which one is required
206 * @size: place to put size value (on success)
207 *
208 * @return address or FDT_ADDR_T_NONE if not found
209 */
Simon Glass88b3a372020-01-27 08:49:40 -0700210fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
Sekhar Norif5b90472019-08-01 19:12:56 +0530211 fdt_size_t *size);
212
213/**
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200214 * dev_remap_addr_index() - Get the indexed reg property of a device
215 * as a memory-mapped I/O pointer
216 *
217 * @dev: Device to read from
218 * @index: the 'reg' property can hold a list of <addr, size> pairs
219 * and @index is used to select which one is required
220 *
221 * @return pointer or NULL if not found
222 */
Simon Glass88b3a372020-01-27 08:49:40 -0700223void *dev_remap_addr_index(const struct udevice *dev, int index);
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200224
225/**
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100226 * dev_read_addr_name() - Get the reg property of a device, indexed by name
227 *
228 * @dev: Device to read from
229 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
230 * 'reg-names' property providing named-based identification. @index
231 * indicates the value to search for in 'reg-names'.
232 *
233 * @return address or FDT_ADDR_T_NONE if not found
234 */
Simon Glass88b3a372020-01-27 08:49:40 -0700235fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100236
237/**
Sekhar Norif5b90472019-08-01 19:12:56 +0530238 * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
239 *
240 * @dev: Device to read from
241 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
242 * 'reg-names' property providing named-based identification. @index
243 * indicates the value to search for in 'reg-names'.
244 * @size: place to put size value (on success)
245 *
246 * @return address or FDT_ADDR_T_NONE if not found
247 */
Simon Glass88b3a372020-01-27 08:49:40 -0700248fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
Sekhar Norif5b90472019-08-01 19:12:56 +0530249 fdt_size_t *size);
250
251/**
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100252 * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
253 * as a memory-mapped I/O pointer
254 *
255 * @dev: Device to read from
256 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
257 * 'reg-names' property providing named-based identification. @index
258 * indicates the value to search for in 'reg-names'.
259 *
260 * @return pointer or NULL if not found
261 */
Simon Glass88b3a372020-01-27 08:49:40 -0700262void *dev_remap_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100263
264/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600265 * dev_read_addr() - Get the reg property of a device
266 *
267 * @dev: Device to read from
268 *
269 * @return address or FDT_ADDR_T_NONE if not found
270 */
Simon Glass88b3a372020-01-27 08:49:40 -0700271fdt_addr_t dev_read_addr(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600272
273/**
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200274 * dev_read_addr_ptr() - Get the reg property of a device
275 * as a pointer
276 *
277 * @dev: Device to read from
278 *
279 * @return pointer or NULL if not found
280 */
Simon Glass88b3a372020-01-27 08:49:40 -0700281void *dev_read_addr_ptr(const struct udevice *dev);
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200282
283/**
Simon Glass33c215a2019-09-15 12:08:58 -0600284 * dev_read_addr_pci() - Read an address and handle PCI address translation
285 *
286 * At present U-Boot does not have address translation logic for PCI in the
287 * livetree implementation (of_addr.c). This special function supports this for
288 * the flat tree implementation.
289 *
290 * This function should be removed (and code should use dev_read() instead)
291 * once:
292 *
293 * 1. PCI address translation is added; and either
294 * 2. everything uses livetree where PCI translation is used (which is feasible
295 * in SPL and U-Boot proper) or PCI address translation is added to
296 * fdtdec_get_addr() and friends.
297 *
298 * @dev: Device to read from
299 * @return address or FDT_ADDR_T_NONE if not found
300 */
Simon Glass88b3a372020-01-27 08:49:40 -0700301fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
Simon Glass33c215a2019-09-15 12:08:58 -0600302
303/**
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200304 * dev_remap_addr() - Get the reg property of a device as a
305 * memory-mapped I/O pointer
306 *
307 * @dev: Device to read from
308 *
309 * @return pointer or NULL if not found
310 */
Simon Glass88b3a372020-01-27 08:49:40 -0700311void *dev_remap_addr(const struct udevice *dev);
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200312
313/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600314 * dev_read_addr_size() - get address and size from a device property
315 *
316 * This does no address translation. It simply reads an property that contains
317 * an address and a size value, one after the other.
318 *
319 * @dev: Device to read from
320 * @propname: property to read
321 * @sizep: place to put size value (on success)
322 * @return address value, or FDT_ADDR_T_NONE on error
323 */
Simon Glass88b3a372020-01-27 08:49:40 -0700324fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
325 fdt_size_t *sizep);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600326
327/**
328 * dev_read_name() - get the name of a device's node
329 *
Bin Meng15d61d02019-07-05 09:23:18 -0700330 * @dev: Device to read from
Simon Glassf11c7ab2017-05-18 20:09:03 -0600331 * @return name of node
332 */
Simon Glass88b3a372020-01-27 08:49:40 -0700333const char *dev_read_name(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600334
335/**
336 * dev_read_stringlist_search() - find string in a string list and return index
337 *
338 * Note that it is possible for this function to succeed on property values
339 * that are not NUL-terminated. That's because the function will stop after
340 * finding the first occurrence of @string. This can for example happen with
341 * small-valued cell properties, such as #address-cells, when searching for
342 * the empty string.
343 *
344 * @dev: device to check
345 * @propname: name of the property containing the string list
346 * @string: string to look up in the string list
347 *
348 * @return:
349 * the index of the string in the list of strings
350 * -ENODATA if the property is not found
351 * -EINVAL on some other error
352 */
Simon Glass88b3a372020-01-27 08:49:40 -0700353int dev_read_stringlist_search(const struct udevice *dev, const char *property,
354 const char *string);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600355
356/**
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200357 * dev_read_string_index() - obtain an indexed string from a string list
358 *
359 * @dev: device to examine
360 * @propname: name of the property containing the string list
361 * @index: index of the string to return
362 * @out: return location for the string
363 *
364 * @return:
365 * length of string, if found or -ve error value if not found
366 */
Simon Glass88b3a372020-01-27 08:49:40 -0700367int dev_read_string_index(const struct udevice *dev, const char *propname,
368 int index, const char **outp);
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200369
370/**
371 * dev_read_string_count() - find the number of strings in a string list
372 *
373 * @dev: device to examine
374 * @propname: name of the property containing the string list
375 * @return:
376 * number of strings in the list, or -ve error value if not found
377 */
Simon Glass88b3a372020-01-27 08:49:40 -0700378int dev_read_string_count(const struct udevice *dev, const char *propname);
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200379/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600380 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
381 *
382 * This function is useful to parse lists of phandles and their arguments.
383 * Returns 0 on success and fills out_args, on error returns appropriate
384 * errno value.
385 *
386 * Caller is responsible to call of_node_put() on the returned out_args->np
387 * pointer.
388 *
389 * Example:
390 *
391 * phandle1: node1 {
392 * #list-cells = <2>;
393 * }
394 *
395 * phandle2: node2 {
396 * #list-cells = <1>;
397 * }
398 *
399 * node3 {
400 * list = <&phandle1 1 2 &phandle2 3>;
401 * }
402 *
403 * To get a device_node of the `node2' node you may call this:
404 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
405 *
406 * @dev: device whose node containing a list
407 * @list_name: property name that contains a list
408 * @cells_name: property name that specifies phandles' arguments count
409 * @cells_count: Cell count to use if @cells_name is NULL
410 * @index: index of a phandle to parse out
411 * @out_args: optional pointer to output arguments structure (will be filled)
412 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
413 * @list_name does not exist, -EINVAL if a phandle was not found,
414 * @cells_name could not be found, the arguments were truncated or there
415 * were too many arguments.
416 */
Simon Glass88b3a372020-01-27 08:49:40 -0700417int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
418 const char *cells_name, int cell_count,
419 int index, struct ofnode_phandle_args *out_args);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600420
421/**
Patrice Chotard642346a2017-07-18 11:57:08 +0200422 * dev_count_phandle_with_args() - Return phandle number in a list
423 *
424 * This function is usefull to get phandle number contained in a property list.
425 * For example, this allows to allocate the right amount of memory to keep
426 * clock's reference contained into the "clocks" property.
427 *
428 *
429 * @dev: device whose node containing a list
430 * @list_name: property name that contains a list
431 * @cells_name: property name that specifies phandles' arguments count
432 * @Returns number of phandle found on success, on error returns appropriate
433 * errno value.
434 */
435
Simon Glass88b3a372020-01-27 08:49:40 -0700436int dev_count_phandle_with_args(const struct udevice *dev,
437 const char *list_name, const char *cells_name);
Patrice Chotard642346a2017-07-18 11:57:08 +0200438
439/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600440 * dev_read_addr_cells() - Get the number of address cells for a device's node
441 *
442 * This walks back up the tree to find the closest #address-cells property
443 * which controls the given node.
444 *
Mario Six7ba50412018-01-15 11:09:36 +0100445 * @dev: device to check
Simon Glassf11c7ab2017-05-18 20:09:03 -0600446 * @return number of address cells this node uses
447 */
Simon Glass88b3a372020-01-27 08:49:40 -0700448int dev_read_addr_cells(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600449
450/**
451 * dev_read_size_cells() - Get the number of size cells for a device's node
452 *
453 * This walks back up the tree to find the closest #size-cells property
454 * which controls the given node.
455 *
Mario Six7ba50412018-01-15 11:09:36 +0100456 * @dev: device to check
Simon Glassf11c7ab2017-05-18 20:09:03 -0600457 * @return number of size cells this node uses
458 */
Simon Glass88b3a372020-01-27 08:49:40 -0700459int dev_read_size_cells(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600460
461/**
Simon Glass878d68c2017-06-12 06:21:31 -0600462 * dev_read_addr_cells() - Get the address cells property in a node
463 *
464 * This function matches fdt_address_cells().
465 *
Mario Six7ba50412018-01-15 11:09:36 +0100466 * @dev: device to check
Simon Glass878d68c2017-06-12 06:21:31 -0600467 * @return number of address cells this node uses
468 */
Simon Glass88b3a372020-01-27 08:49:40 -0700469int dev_read_simple_addr_cells(const struct udevice *dev);
Simon Glass878d68c2017-06-12 06:21:31 -0600470
471/**
472 * dev_read_size_cells() - Get the size cells property in a node
473 *
474 * This function matches fdt_size_cells().
475 *
Mario Six7ba50412018-01-15 11:09:36 +0100476 * @dev: device to check
Simon Glass878d68c2017-06-12 06:21:31 -0600477 * @return number of size cells this node uses
478 */
Simon Glass88b3a372020-01-27 08:49:40 -0700479int dev_read_simple_size_cells(const struct udevice *dev);
Simon Glass878d68c2017-06-12 06:21:31 -0600480
481/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600482 * dev_read_phandle() - Get the phandle from a device
483 *
484 * @dev: device to check
485 * @return phandle (1 or greater), or 0 if no phandle or other error
486 */
Simon Glass88b3a372020-01-27 08:49:40 -0700487int dev_read_phandle(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600488
489/**
490 * dev_read_prop()- - read a property from a device's node
491 *
492 * @dev: device to check
493 * @propname: property to read
494 * @lenp: place to put length on success
495 * @return pointer to property, or NULL if not found
496 */
Simon Glass88b3a372020-01-27 08:49:40 -0700497const void *dev_read_prop(const struct udevice *dev, const char *propname,
498 int *lenp);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600499
500/**
Patrick Delaunayce891fca2020-01-13 11:34:56 +0100501 * dev_read_first_prop()- get the reference of the first property
502 *
503 * Get reference to the first property of the node, it is used to iterate
504 * and read all the property with dev_read_prop_by_prop().
505 *
506 * @dev: device to check
507 * @prop: place to put argument reference
508 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
509 */
510int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
511
512/**
513 * ofnode_get_next_property() - get the reference of the next property
514 *
515 * Get reference to the next property of the node, it is used to iterate
516 * and read all the property with dev_read_prop_by_prop().
517 *
518 * @prop: reference of current argument and place to put reference of next one
519 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
520 */
521int dev_read_next_prop(struct ofprop *prop);
522
523/**
524 * dev_read_prop_by_prop() - get a pointer to the value of a property
525 *
526 * Get value for the property identified by the provided reference.
527 *
528 * @prop: reference on property
529 * @propname: If non-NULL, place to property name on success,
530 * @lenp: If non-NULL, place to put length on success
531 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
532 */
533const void *dev_read_prop_by_prop(struct ofprop *prop,
534 const char **propname, int *lenp);
535
536/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600537 * dev_read_alias_seq() - Get the alias sequence number of a node
538 *
539 * This works out whether a node is pointed to by an alias, and if so, the
540 * sequence number of that alias. Aliases are of the form <base><num> where
541 * <num> is the sequence number. For example spi2 would be sequence number 2.
542 *
543 * @dev: device to look up
544 * @devnump: set to the sequence number if one is found
545 * @return 0 if a sequence was found, -ve if not
546 */
Simon Glass88b3a372020-01-27 08:49:40 -0700547int dev_read_alias_seq(const struct udevice *dev, int *devnump);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600548
549/**
550 * dev_read_u32_array() - Find and read an array of 32 bit integers
551 *
552 * Search for a property in a device node and read 32-bit value(s) from
553 * it.
554 *
555 * The out_values is modified only if a valid u32 value can be decoded.
556 *
557 * @dev: device to look up
558 * @propname: name of the property to read
559 * @out_values: pointer to return value, modified only if return value is 0
560 * @sz: number of array elements to read
561 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
562 * property does not have a value, and -EOVERFLOW if the property data isn't
563 * large enough.
564 */
Simon Glass88b3a372020-01-27 08:49:40 -0700565int dev_read_u32_array(const struct udevice *dev, const char *propname,
Simon Glass47a0fd32017-05-18 20:09:04 -0600566 u32 *out_values, size_t sz);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600567
568/**
569 * dev_read_first_subnode() - find the first subnode of a device's node
570 *
571 * @dev: device to look up
572 * @return reference to the first subnode (which can be invalid if the device's
573 * node has no subnodes)
574 */
Simon Glass88b3a372020-01-27 08:49:40 -0700575ofnode dev_read_first_subnode(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600576
577/**
578 * ofnode_next_subnode() - find the next sibling of a subnode
579 *
580 * @node: valid reference to previous node (sibling)
581 * @return reference to the next subnode (which can be invalid if the node
582 * has no more siblings)
583 */
Simon Glass47a0fd32017-05-18 20:09:04 -0600584ofnode dev_read_next_subnode(ofnode node);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600585
586/**
587 * dev_read_u8_array_ptr() - find an 8-bit array
588 *
589 * Look up a device's node property and return a pointer to its contents as a
590 * byte array of given length. The property must have at least enough data
591 * for the array (count bytes). It may have more, but this will be ignored.
592 * The data is not copied.
593 *
594 * @dev: device to look up
595 * @propname: name of property to find
596 * @sz: number of array elements
597 * @return pointer to byte array if found, or NULL if the property is not
598 * found or there is not enough data
599 */
Simon Glass88b3a372020-01-27 08:49:40 -0700600const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
601 const char *propname, size_t sz);
Simon Glass47a0fd32017-05-18 20:09:04 -0600602
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600603/**
604 * dev_read_enabled() - check whether a node is enabled
605 *
606 * This looks for a 'status' property. If this exists, then returns 1 if
607 * the status is 'ok' and 0 otherwise. If there is no status property,
608 * it returns 1 on the assumption that anything mentioned should be enabled
609 * by default.
610 *
611 * @dev: device to examine
612 * @return integer value 0 (not enabled) or 1 (enabled)
613 */
Simon Glass88b3a372020-01-27 08:49:40 -0700614int dev_read_enabled(const struct udevice *dev);
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600615
Simon Glassdcf98852017-07-25 08:29:55 -0600616/**
617 * dev_read_resource() - obtain an indexed resource from a device.
618 *
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900619 * @dev: device to examine
Simon Glassdcf98852017-07-25 08:29:55 -0600620 * @index index of the resource to retrieve (0 = first)
621 * @res returns the resource
622 * @return 0 if ok, negative on error
623 */
Simon Glass88b3a372020-01-27 08:49:40 -0700624int dev_read_resource(const struct udevice *dev, uint index,
625 struct resource *res);
Simon Glassdcf98852017-07-25 08:29:55 -0600626
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900627/**
628 * dev_read_resource_byname() - obtain a named resource from a device.
629 *
630 * @dev: device to examine
631 * @name: name of the resource to retrieve
632 * @res: returns the resource
633 * @return 0 if ok, negative on error
634 */
Simon Glass88b3a372020-01-27 08:49:40 -0700635int dev_read_resource_byname(const struct udevice *dev, const char *name,
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900636 struct resource *res);
637
Mario Six147c6072018-01-15 11:07:19 +0100638/**
Fabien Dessenne641067f2019-05-31 15:11:30 +0200639 * dev_translate_address() - Translate a device-tree address
Mario Six147c6072018-01-15 11:07:19 +0100640 *
641 * Translate an address from the device-tree into a CPU physical address. This
642 * function walks up the tree and applies the various bus mappings along the
643 * way.
644 *
645 * @dev: device giving the context in which to translate the address
646 * @in_addr: pointer to the address to translate
647 * @return the translated address; OF_BAD_ADDR on error
648 */
Simon Glass88b3a372020-01-27 08:49:40 -0700649u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
Michal Simek83e4c7e2019-01-31 16:30:59 +0100650
651/**
Fabien Dessenne641067f2019-05-31 15:11:30 +0200652 * dev_translate_dma_address() - Translate a device-tree DMA address
653 *
654 * Translate a DMA address from the device-tree into a CPU physical address.
655 * This function walks up the tree and applies the various bus mappings along
656 * the way.
657 *
658 * @dev: device giving the context in which to translate the DMA address
659 * @in_addr: pointer to the DMA address to translate
660 * @return the translated DMA address; OF_BAD_ADDR on error
661 */
Simon Glass88b3a372020-01-27 08:49:40 -0700662u64 dev_translate_dma_address(const struct udevice *dev,
663 const fdt32_t *in_addr);
Fabien Dessenne641067f2019-05-31 15:11:30 +0200664
665/**
Michal Simek83e4c7e2019-01-31 16:30:59 +0100666 * dev_read_alias_highest_id - Get highest alias id for the given stem
667 * @stem: Alias stem to be examined
668 *
669 * The function travels the lookup table to get the highest alias id for the
670 * given alias stem.
671 * @return alias ID, if found, else -1
672 */
673int dev_read_alias_highest_id(const char *stem);
674
Chunfeng Yun89b84b82020-05-02 11:35:09 +0200675/**
676 * dev_get_child_count() - get the child count of a device
677 *
678 * @dev: device to use for interation (struct udevice *)
679 * @return the count of child subnode
680 */
681int dev_get_child_count(const struct udevice *dev);
682
Simon Glass47a0fd32017-05-18 20:09:04 -0600683#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
684
Simon Glass88b3a372020-01-27 08:49:40 -0700685static inline int dev_read_u32(const struct udevice *dev,
Masahiro Yamada3ab48f62017-12-30 02:00:05 +0900686 const char *propname, u32 *outp)
687{
688 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
689}
690
Simon Glass88b3a372020-01-27 08:49:40 -0700691static inline int dev_read_u32_default(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600692 const char *propname, int def)
693{
694 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
695}
696
Dario Binacchi4bb70752020-03-29 18:04:41 +0200697static inline int dev_read_u32_index(struct udevice *dev,
698 const char *propname, int index, u32 *outp)
699{
700 return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
701}
702
703static inline u32 dev_read_u32_index_default(struct udevice *dev,
704 const char *propname, int index,
705 u32 def)
706{
707 return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
708 def);
709}
710
Simon Glass88b3a372020-01-27 08:49:40 -0700711static inline int dev_read_s32(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700712 const char *propname, s32 *outp)
713{
714 return ofnode_read_s32(dev_ofnode(dev), propname, outp);
715}
716
Simon Glass88b3a372020-01-27 08:49:40 -0700717static inline int dev_read_s32_default(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700718 const char *propname, int def)
719{
720 return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
721}
722
Simon Glass88b3a372020-01-27 08:49:40 -0700723static inline int dev_read_u32u(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700724 const char *propname, uint *outp)
725{
726 u32 val;
727 int ret;
728
729 ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
730 if (ret)
731 return ret;
732 *outp = val;
733
734 return 0;
735}
736
Simon Glass88b3a372020-01-27 08:49:40 -0700737static inline int dev_read_u64(const struct udevice *dev,
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200738 const char *propname, u64 *outp)
739{
740 return ofnode_read_u64(dev_ofnode(dev), propname, outp);
741}
742
Simon Glass88b3a372020-01-27 08:49:40 -0700743static inline u64 dev_read_u64_default(const struct udevice *dev,
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200744 const char *propname, u64 def)
745{
746 return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
747}
748
Simon Glass88b3a372020-01-27 08:49:40 -0700749static inline const char *dev_read_string(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600750 const char *propname)
751{
752 return ofnode_read_string(dev_ofnode(dev), propname);
753}
754
Simon Glass88b3a372020-01-27 08:49:40 -0700755static inline bool dev_read_bool(const struct udevice *dev,
756 const char *propname)
Simon Glass47a0fd32017-05-18 20:09:04 -0600757{
758 return ofnode_read_bool(dev_ofnode(dev), propname);
759}
760
Simon Glass88b3a372020-01-27 08:49:40 -0700761static inline ofnode dev_read_subnode(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600762 const char *subbnode_name)
763{
764 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
765}
766
Simon Glass88b3a372020-01-27 08:49:40 -0700767static inline int dev_read_size(const struct udevice *dev, const char *propname)
Simon Glass47a0fd32017-05-18 20:09:04 -0600768{
769 return ofnode_read_size(dev_ofnode(dev), propname);
770}
771
Simon Glass88b3a372020-01-27 08:49:40 -0700772static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
773 int index)
Simon Glass47a0fd32017-05-18 20:09:04 -0600774{
775 return devfdt_get_addr_index(dev, index);
776}
777
Simon Glass88b3a372020-01-27 08:49:40 -0700778static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
Sekhar Norif5b90472019-08-01 19:12:56 +0530779 int index,
780 fdt_size_t *size)
781{
782 return devfdt_get_addr_size_index(dev, index, size);
783}
784
Simon Glass88b3a372020-01-27 08:49:40 -0700785static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100786 const char *name)
787{
788 return devfdt_get_addr_name(dev, name);
789}
790
Simon Glass88b3a372020-01-27 08:49:40 -0700791static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
Sekhar Norif5b90472019-08-01 19:12:56 +0530792 const char *name,
793 fdt_size_t *size)
794{
795 return devfdt_get_addr_size_name(dev, name, size);
796}
797
Simon Glass88b3a372020-01-27 08:49:40 -0700798static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600799{
800 return devfdt_get_addr(dev);
801}
802
Simon Glass88b3a372020-01-27 08:49:40 -0700803static inline void *dev_read_addr_ptr(const struct udevice *dev)
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200804{
Ovidiu Panait3fe69d32020-08-03 22:17:35 +0300805 return devfdt_get_addr_ptr(dev);
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200806}
807
Simon Glass88b3a372020-01-27 08:49:40 -0700808static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
Simon Glass33c215a2019-09-15 12:08:58 -0600809{
810 return devfdt_get_addr_pci(dev);
811}
812
Simon Glass88b3a372020-01-27 08:49:40 -0700813static inline void *dev_remap_addr(const struct udevice *dev)
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200814{
815 return devfdt_remap_addr(dev);
816}
817
Simon Glass88b3a372020-01-27 08:49:40 -0700818static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200819{
820 return devfdt_remap_addr_index(dev, index);
821}
822
Simon Glass88b3a372020-01-27 08:49:40 -0700823static inline void *dev_remap_addr_name(const struct udevice *dev,
824 const char *name)
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100825{
826 return devfdt_remap_addr_name(dev, name);
827}
828
Simon Glass88b3a372020-01-27 08:49:40 -0700829static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600830 const char *propname,
831 fdt_size_t *sizep)
832{
833 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
834}
835
Simon Glass88b3a372020-01-27 08:49:40 -0700836static inline const char *dev_read_name(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600837{
838 return ofnode_get_name(dev_ofnode(dev));
839}
840
Simon Glass88b3a372020-01-27 08:49:40 -0700841static inline int dev_read_stringlist_search(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600842 const char *propname,
843 const char *string)
844{
845 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
846}
847
Simon Glass88b3a372020-01-27 08:49:40 -0700848static inline int dev_read_string_index(const struct udevice *dev,
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200849 const char *propname, int index,
850 const char **outp)
851{
852 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
853}
854
Simon Glass88b3a372020-01-27 08:49:40 -0700855static inline int dev_read_string_count(const struct udevice *dev,
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200856 const char *propname)
857{
858 return ofnode_read_string_count(dev_ofnode(dev), propname);
859}
860
Simon Glass88b3a372020-01-27 08:49:40 -0700861static inline int dev_read_phandle_with_args(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600862 const char *list_name, const char *cells_name, int cell_count,
863 int index, struct ofnode_phandle_args *out_args)
864{
865 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
866 cells_name, cell_count, index,
867 out_args);
868}
869
Simon Glass88b3a372020-01-27 08:49:40 -0700870static inline int dev_count_phandle_with_args(const struct udevice *dev,
Patrice Chotard642346a2017-07-18 11:57:08 +0200871 const char *list_name, const char *cells_name)
872{
873 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
874 cells_name);
875}
876
Simon Glass88b3a372020-01-27 08:49:40 -0700877static inline int dev_read_addr_cells(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600878{
Heinrich Schuchardtae6b33d2020-07-25 21:38:49 +0200879 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
880
881 return fdt_address_cells(gd->fdt_blob, parent);
Simon Glass47a0fd32017-05-18 20:09:04 -0600882}
883
Simon Glass88b3a372020-01-27 08:49:40 -0700884static inline int dev_read_size_cells(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600885{
Heinrich Schuchardtae6b33d2020-07-25 21:38:49 +0200886 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
887
888 return fdt_size_cells(gd->fdt_blob, parent);
Simon Glass878d68c2017-06-12 06:21:31 -0600889}
890
Simon Glass88b3a372020-01-27 08:49:40 -0700891static inline int dev_read_simple_addr_cells(const struct udevice *dev)
Simon Glass878d68c2017-06-12 06:21:31 -0600892{
893 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
894}
895
Simon Glass88b3a372020-01-27 08:49:40 -0700896static inline int dev_read_simple_size_cells(const struct udevice *dev)
Simon Glass878d68c2017-06-12 06:21:31 -0600897{
Simon Glass47a0fd32017-05-18 20:09:04 -0600898 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
899}
900
Simon Glass88b3a372020-01-27 08:49:40 -0700901static inline int dev_read_phandle(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600902{
903 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
904}
905
Simon Glass88b3a372020-01-27 08:49:40 -0700906static inline const void *dev_read_prop(const struct udevice *dev,
Masahiro Yamadafd736212017-07-17 12:18:39 +0900907 const char *propname, int *lenp)
Simon Glass47a0fd32017-05-18 20:09:04 -0600908{
Masahiro Yamada61e51ba2017-06-22 16:54:05 +0900909 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glass47a0fd32017-05-18 20:09:04 -0600910}
911
Patrick Delaunayce891fca2020-01-13 11:34:56 +0100912static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
913{
914 return ofnode_get_first_property(dev_ofnode(dev), prop);
915}
916
917static inline int dev_read_next_prop(struct ofprop *prop)
918{
919 return ofnode_get_next_property(prop);
920}
921
922static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
923 const char **propname,
924 int *lenp)
925{
926 return ofnode_get_property_by_prop(prop, propname, lenp);
927}
928
Simon Glass88b3a372020-01-27 08:49:40 -0700929static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
Simon Glass47a0fd32017-05-18 20:09:04 -0600930{
Marcel Ziswiler45224e82019-05-20 02:44:57 +0200931#if CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glass47a0fd32017-05-18 20:09:04 -0600932 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
933 dev_of_offset(dev), devnump);
Marcel Ziswiler45224e82019-05-20 02:44:57 +0200934#else
935 return -ENOTSUPP;
936#endif
Simon Glass47a0fd32017-05-18 20:09:04 -0600937}
938
Simon Glass88b3a372020-01-27 08:49:40 -0700939static inline int dev_read_u32_array(const struct udevice *dev,
940 const char *propname, u32 *out_values,
941 size_t sz)
Simon Glass47a0fd32017-05-18 20:09:04 -0600942{
943 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
944}
945
Simon Glass88b3a372020-01-27 08:49:40 -0700946static inline ofnode dev_read_first_subnode(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600947{
948 return ofnode_first_subnode(dev_ofnode(dev));
949}
950
951static inline ofnode dev_read_next_subnode(ofnode node)
952{
953 return ofnode_next_subnode(node);
954}
955
Simon Glass88b3a372020-01-27 08:49:40 -0700956static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
Simon Glassf262d4c2020-01-27 08:49:47 -0700957 const char *propname,
958 size_t sz)
Simon Glassf11c7ab2017-05-18 20:09:03 -0600959{
960 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
961}
962
Simon Glass88b3a372020-01-27 08:49:40 -0700963static inline int dev_read_enabled(const struct udevice *dev)
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600964{
965 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
966}
967
Simon Glass88b3a372020-01-27 08:49:40 -0700968static inline int dev_read_resource(const struct udevice *dev, uint index,
Simon Glassdcf98852017-07-25 08:29:55 -0600969 struct resource *res)
970{
971 return ofnode_read_resource(dev_ofnode(dev), index, res);
972}
973
Simon Glass88b3a372020-01-27 08:49:40 -0700974static inline int dev_read_resource_byname(const struct udevice *dev,
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900975 const char *name,
976 struct resource *res)
977{
978 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
979}
980
Simon Glass88b3a372020-01-27 08:49:40 -0700981static inline u64 dev_translate_address(const struct udevice *dev,
982 const fdt32_t *in_addr)
Mario Six147c6072018-01-15 11:07:19 +0100983{
984 return ofnode_translate_address(dev_ofnode(dev), in_addr);
985}
986
Simon Glass88b3a372020-01-27 08:49:40 -0700987static inline u64 dev_translate_dma_address(const struct udevice *dev,
988 const fdt32_t *in_addr)
Fabien Dessenne641067f2019-05-31 15:11:30 +0200989{
990 return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
991}
992
Michal Simek83e4c7e2019-01-31 16:30:59 +0100993static inline int dev_read_alias_highest_id(const char *stem)
994{
Michael Walle0a6b75f2020-06-02 01:47:08 +0200995 if (!CONFIG_IS_ENABLED(OF_LIBFDT))
996 return -1;
Michal Simek83e4c7e2019-01-31 16:30:59 +0100997 return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
998}
999
Chunfeng Yun89b84b82020-05-02 11:35:09 +02001000static inline int dev_get_child_count(const struct udevice *dev)
1001{
1002 return ofnode_get_child_count(dev_ofnode(dev));
1003}
1004
Simon Glassf11c7ab2017-05-18 20:09:03 -06001005#endif /* CONFIG_DM_DEV_READ_INLINE */
1006
1007/**
1008 * dev_for_each_subnode() - Helper function to iterate through subnodes
1009 *
1010 * This creates a for() loop which works through the subnodes in a device's
1011 * device-tree node.
1012 *
1013 * @subnode: ofnode holding the current subnode
1014 * @dev: device to use for interation (struct udevice *)
1015 */
1016#define dev_for_each_subnode(subnode, dev) \
1017 for (subnode = dev_read_first_subnode(dev); \
1018 ofnode_valid(subnode); \
1019 subnode = ofnode_next_subnode(subnode))
1020
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001021/**
1022 * dev_for_each_property() - Helper function to iterate through property
1023 *
1024 * This creates a for() loop which works through the property in a device's
1025 * device-tree node.
1026 *
1027 * @prop: struct ofprop holding the current property
1028 * @dev: device to use for interation (struct udevice *)
1029 */
1030#define dev_for_each_property(prop, dev) \
1031 for (int ret_prop = dev_read_first_prop(dev, &prop); \
1032 !ret_prop; \
1033 ret_prop = dev_read_next_prop(&prop))
1034
Simon Glassf11c7ab2017-05-18 20:09:03 -06001035#endif