blob: fc987f775986f6c61a701de479558730759cf495 [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{
Simon Glassf10643c2020-12-19 10:40:14 -070024 return ofnode_to_np(dev_ofnode(dev));
Simon Glassf11c7ab2017-05-18 20:09:03 -060025}
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
Simon Glass47a0fd32017-05-18 20:09:04 -060033#ifndef CONFIG_DM_DEV_READ_INLINE
T Karthik Reddy3f3d7712019-09-02 16:34:30 +020034
Simon Glass47a0fd32017-05-18 20:09:04 -060035/**
Masahiro Yamada3ab48f62017-12-30 02:00:05 +090036 * dev_read_u32() - read a 32-bit integer from a device's DT property
37 *
38 * @dev: device to read DT property from
39 * @propname: name of the property to read from
40 * @outp: place to put value (if found)
41 * @return 0 if OK, -ve on error
42 */
Simon Glass88b3a372020-01-27 08:49:40 -070043int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
Masahiro Yamada3ab48f62017-12-30 02:00:05 +090044
45/**
Simon Glass47a0fd32017-05-18 20:09:04 -060046 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
47 *
48 * @dev: device to read DT property from
49 * @propname: name of the property to read from
50 * @def: default value to return if the property has no value
51 * @return property value, or @def if not found
52 */
Simon Glass88b3a372020-01-27 08:49:40 -070053int dev_read_u32_default(const struct udevice *dev, const char *propname,
54 int def);
Simon Glassf11c7ab2017-05-18 20:09:03 -060055
56/**
Dario Binacchi4bb70752020-03-29 18:04:41 +020057 * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
58 * property
59 *
60 * @dev: device to read DT property from
61 * @propname: name of the property to read from
62 * @index: index of the integer to return
63 * @outp: place to put value (if found)
64 * @return 0 if OK, -ve on error
65 */
66int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
67 u32 *outp);
68
69/**
70 * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
71 * DT property
72 *
73 * @dev: device to read DT property from
74 * @propname: name of the property to read from
75 * @index: index of the integer to return
76 * @def: default value to return if the property has no value
77 * @return property value, or @def if not found
78 */
79u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
80 int index, u32 def);
81
82/**
Simon Glassa1b17e42018-12-10 10:37:37 -070083 * dev_read_s32() - read a signed 32-bit integer from a device's DT property
84 *
85 * @dev: device to read DT property from
86 * @propname: name of the property to read from
87 * @outp: place to put value (if found)
88 * @return 0 if OK, -ve on error
89 */
Simon Glass88b3a372020-01-27 08:49:40 -070090int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
Simon Glassa1b17e42018-12-10 10:37:37 -070091
92/**
93 * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
94 *
95 * @dev: device to read DT property from
96 * @propname: name of the property to read from
97 * @def: default value to return if the property has no value
98 * @return property value, or @def if not found
99 */
Simon Glass88b3a372020-01-27 08:49:40 -0700100int dev_read_s32_default(const struct udevice *dev, const char *propname,
101 int def);
Simon Glassa1b17e42018-12-10 10:37:37 -0700102
103/**
104 * dev_read_u32u() - read a 32-bit integer from a device's DT property
105 *
106 * This version uses a standard uint type.
107 *
108 * @dev: device to read DT property from
109 * @propname: name of the property to read from
110 * @outp: place to put value (if found)
111 * @return 0 if OK, -ve on error
112 */
Simon Glass88b3a372020-01-27 08:49:40 -0700113int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
Simon Glassa1b17e42018-12-10 10:37:37 -0700114
115/**
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200116 * dev_read_u64() - read a 64-bit integer from a device's DT property
117 *
118 * @dev: device to read DT property from
119 * @propname: name of the property to read from
120 * @outp: place to put value (if found)
121 * @return 0 if OK, -ve on error
122 */
Simon Glass88b3a372020-01-27 08:49:40 -0700123int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200124
125/**
126 * dev_read_u64_default() - read a 64-bit integer from a device's DT property
127 *
128 * @dev: device to read DT property from
129 * @propname: name of the property to read from
130 * @def: default value to return if the property has no value
131 * @return property value, or @def if not found
132 */
Simon Glass88b3a372020-01-27 08:49:40 -0700133u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
134 u64 def);
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200135
136/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600137 * dev_read_string() - Read a string from a device's DT property
138 *
139 * @dev: device to read DT property from
140 * @propname: name of the property to read
141 * @return string from property value, or NULL if there is no such property
142 */
Simon Glass88b3a372020-01-27 08:49:40 -0700143const char *dev_read_string(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600144
145/**
146 * dev_read_bool() - read a boolean value from a device's DT property
147 *
148 * @dev: device to read DT property from
149 * @propname: name of property to read
150 * @return true if property is present (meaning true), false if not present
151 */
Simon Glass88b3a372020-01-27 08:49:40 -0700152bool dev_read_bool(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600153
154/**
155 * dev_read_subnode() - find a named subnode of a device
156 *
157 * @dev: device whose DT node contains the subnode
158 * @subnode_name: name of subnode to find
159 * @return reference to subnode (which can be invalid if there is no such
160 * subnode)
161 */
Simon Glass88b3a372020-01-27 08:49:40 -0700162ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600163
164/**
165 * dev_read_size() - read the size of a property
166 *
167 * @dev: device to check
168 * @propname: property to check
169 * @return size of property if present, or -EINVAL if not
170 */
Simon Glass88b3a372020-01-27 08:49:40 -0700171int dev_read_size(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600172
173/**
174 * dev_read_addr_index() - Get the indexed reg property of a device
175 *
176 * @dev: Device to read from
177 * @index: the 'reg' property can hold a list of <addr, size> pairs
178 * and @index is used to select which one is required
179 *
180 * @return address or FDT_ADDR_T_NONE if not found
181 */
Simon Glass88b3a372020-01-27 08:49:40 -0700182fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600183
184/**
Sekhar Norif5b90472019-08-01 19:12:56 +0530185 * dev_read_addr_size_index() - Get the indexed reg property of a device
186 *
187 * @dev: Device to read from
188 * @index: the 'reg' property can hold a list of <addr, size> pairs
189 * and @index is used to select which one is required
190 * @size: place to put size value (on success)
191 *
192 * @return address or FDT_ADDR_T_NONE if not found
193 */
Simon Glass88b3a372020-01-27 08:49:40 -0700194fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
Sekhar Norif5b90472019-08-01 19:12:56 +0530195 fdt_size_t *size);
196
197/**
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200198 * dev_remap_addr_index() - Get the indexed reg property of a device
199 * as a memory-mapped I/O pointer
200 *
201 * @dev: Device to read from
202 * @index: the 'reg' property can hold a list of <addr, size> pairs
203 * and @index is used to select which one is required
204 *
205 * @return pointer or NULL if not found
206 */
Simon Glass88b3a372020-01-27 08:49:40 -0700207void *dev_remap_addr_index(const struct udevice *dev, int index);
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200208
209/**
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100210 * dev_read_addr_name() - Get the reg property of a device, indexed by name
211 *
212 * @dev: Device to read from
213 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
214 * 'reg-names' property providing named-based identification. @index
215 * indicates the value to search for in 'reg-names'.
216 *
217 * @return address or FDT_ADDR_T_NONE if not found
218 */
Simon Glass88b3a372020-01-27 08:49:40 -0700219fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100220
221/**
Sekhar Norif5b90472019-08-01 19:12:56 +0530222 * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
223 *
224 * @dev: Device to read from
225 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
226 * 'reg-names' property providing named-based identification. @index
227 * indicates the value to search for in 'reg-names'.
228 * @size: place to put size value (on success)
229 *
230 * @return address or FDT_ADDR_T_NONE if not found
231 */
Simon Glass88b3a372020-01-27 08:49:40 -0700232fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
Sekhar Norif5b90472019-08-01 19:12:56 +0530233 fdt_size_t *size);
234
235/**
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100236 * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
237 * as a memory-mapped I/O pointer
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 *
244 * @return pointer or NULL if not found
245 */
Simon Glass88b3a372020-01-27 08:49:40 -0700246void *dev_remap_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100247
248/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600249 * dev_read_addr() - Get the reg property of a device
250 *
251 * @dev: Device to read from
252 *
253 * @return address or FDT_ADDR_T_NONE if not found
254 */
Simon Glass88b3a372020-01-27 08:49:40 -0700255fdt_addr_t dev_read_addr(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600256
257/**
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200258 * dev_read_addr_ptr() - Get the reg property of a device
259 * as a pointer
260 *
261 * @dev: Device to read from
262 *
263 * @return pointer or NULL if not found
264 */
Simon Glass88b3a372020-01-27 08:49:40 -0700265void *dev_read_addr_ptr(const struct udevice *dev);
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200266
267/**
Simon Glass33c215a2019-09-15 12:08:58 -0600268 * dev_read_addr_pci() - Read an address and handle PCI address translation
269 *
270 * At present U-Boot does not have address translation logic for PCI in the
271 * livetree implementation (of_addr.c). This special function supports this for
272 * the flat tree implementation.
273 *
274 * This function should be removed (and code should use dev_read() instead)
275 * once:
276 *
277 * 1. PCI address translation is added; and either
278 * 2. everything uses livetree where PCI translation is used (which is feasible
279 * in SPL and U-Boot proper) or PCI address translation is added to
280 * fdtdec_get_addr() and friends.
281 *
282 * @dev: Device to read from
283 * @return address or FDT_ADDR_T_NONE if not found
284 */
Simon Glass88b3a372020-01-27 08:49:40 -0700285fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
Simon Glass33c215a2019-09-15 12:08:58 -0600286
287/**
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200288 * dev_remap_addr() - Get the reg property of a device as a
289 * memory-mapped I/O pointer
290 *
291 * @dev: Device to read from
292 *
293 * @return pointer or NULL if not found
294 */
Simon Glass88b3a372020-01-27 08:49:40 -0700295void *dev_remap_addr(const struct udevice *dev);
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200296
297/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600298 * dev_read_addr_size() - get address and size from a device property
299 *
300 * This does no address translation. It simply reads an property that contains
301 * an address and a size value, one after the other.
302 *
303 * @dev: Device to read from
304 * @propname: property to read
305 * @sizep: place to put size value (on success)
306 * @return address value, or FDT_ADDR_T_NONE on error
307 */
Simon Glass88b3a372020-01-27 08:49:40 -0700308fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
309 fdt_size_t *sizep);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600310
311/**
312 * dev_read_name() - get the name of a device's node
313 *
Bin Meng15d61d02019-07-05 09:23:18 -0700314 * @dev: Device to read from
Simon Glassf11c7ab2017-05-18 20:09:03 -0600315 * @return name of node
316 */
Simon Glass88b3a372020-01-27 08:49:40 -0700317const char *dev_read_name(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600318
319/**
320 * dev_read_stringlist_search() - find string in a string list and return index
321 *
322 * Note that it is possible for this function to succeed on property values
323 * that are not NUL-terminated. That's because the function will stop after
324 * finding the first occurrence of @string. This can for example happen with
325 * small-valued cell properties, such as #address-cells, when searching for
326 * the empty string.
327 *
328 * @dev: device to check
329 * @propname: name of the property containing the string list
330 * @string: string to look up in the string list
331 *
332 * @return:
333 * the index of the string in the list of strings
334 * -ENODATA if the property is not found
335 * -EINVAL on some other error
336 */
Simon Glass88b3a372020-01-27 08:49:40 -0700337int dev_read_stringlist_search(const struct udevice *dev, const char *property,
338 const char *string);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600339
340/**
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200341 * dev_read_string_index() - obtain an indexed string from a string list
342 *
343 * @dev: device to examine
344 * @propname: name of the property containing the string list
345 * @index: index of the string to return
346 * @out: return location for the string
347 *
348 * @return:
349 * length of string, if found or -ve error value if not found
350 */
Simon Glass88b3a372020-01-27 08:49:40 -0700351int dev_read_string_index(const struct udevice *dev, const char *propname,
352 int index, const char **outp);
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200353
354/**
355 * dev_read_string_count() - find the number of strings in a string list
356 *
357 * @dev: device to examine
358 * @propname: name of the property containing the string list
359 * @return:
360 * number of strings in the list, or -ve error value if not found
361 */
Simon Glass88b3a372020-01-27 08:49:40 -0700362int dev_read_string_count(const struct udevice *dev, const char *propname);
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200363/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600364 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
365 *
366 * This function is useful to parse lists of phandles and their arguments.
367 * Returns 0 on success and fills out_args, on error returns appropriate
368 * errno value.
369 *
370 * Caller is responsible to call of_node_put() on the returned out_args->np
371 * pointer.
372 *
373 * Example:
374 *
375 * phandle1: node1 {
376 * #list-cells = <2>;
377 * }
378 *
379 * phandle2: node2 {
380 * #list-cells = <1>;
381 * }
382 *
383 * node3 {
384 * list = <&phandle1 1 2 &phandle2 3>;
385 * }
386 *
387 * To get a device_node of the `node2' node you may call this:
388 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
389 *
390 * @dev: device whose node containing a list
391 * @list_name: property name that contains a list
392 * @cells_name: property name that specifies phandles' arguments count
393 * @cells_count: Cell count to use if @cells_name is NULL
394 * @index: index of a phandle to parse out
395 * @out_args: optional pointer to output arguments structure (will be filled)
396 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
397 * @list_name does not exist, -EINVAL if a phandle was not found,
398 * @cells_name could not be found, the arguments were truncated or there
399 * were too many arguments.
400 */
Simon Glass88b3a372020-01-27 08:49:40 -0700401int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
402 const char *cells_name, int cell_count,
403 int index, struct ofnode_phandle_args *out_args);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600404
405/**
Patrice Chotard642346a2017-07-18 11:57:08 +0200406 * dev_count_phandle_with_args() - Return phandle number in a list
407 *
408 * This function is usefull to get phandle number contained in a property list.
409 * For example, this allows to allocate the right amount of memory to keep
410 * clock's reference contained into the "clocks" property.
411 *
412 *
413 * @dev: device whose node containing a list
414 * @list_name: property name that contains a list
415 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunay89f68302020-09-25 09:41:14 +0200416 * @cells_count: Cell count to use if @cells_name is NULL
Patrice Chotard642346a2017-07-18 11:57:08 +0200417 * @Returns number of phandle found on success, on error returns appropriate
418 * errno value.
419 */
420
Simon Glass88b3a372020-01-27 08:49:40 -0700421int dev_count_phandle_with_args(const struct udevice *dev,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200422 const char *list_name, const char *cells_name,
423 int cell_count);
Patrice Chotard642346a2017-07-18 11:57:08 +0200424
425/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600426 * dev_read_addr_cells() - Get the number of address cells for a device's node
427 *
428 * This walks back up the tree to find the closest #address-cells property
429 * which controls the given node.
430 *
Mario Six7ba50412018-01-15 11:09:36 +0100431 * @dev: device to check
Simon Glassf11c7ab2017-05-18 20:09:03 -0600432 * @return number of address cells this node uses
433 */
Simon Glass88b3a372020-01-27 08:49:40 -0700434int dev_read_addr_cells(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600435
436/**
437 * dev_read_size_cells() - Get the number of size cells for a device's node
438 *
439 * This walks back up the tree to find the closest #size-cells property
440 * which controls the given node.
441 *
Mario Six7ba50412018-01-15 11:09:36 +0100442 * @dev: device to check
Simon Glassf11c7ab2017-05-18 20:09:03 -0600443 * @return number of size cells this node uses
444 */
Simon Glass88b3a372020-01-27 08:49:40 -0700445int dev_read_size_cells(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600446
447/**
Simon Glass878d68c2017-06-12 06:21:31 -0600448 * dev_read_addr_cells() - Get the address cells property in a node
449 *
450 * This function matches fdt_address_cells().
451 *
Mario Six7ba50412018-01-15 11:09:36 +0100452 * @dev: device to check
Simon Glass878d68c2017-06-12 06:21:31 -0600453 * @return number of address cells this node uses
454 */
Simon Glass88b3a372020-01-27 08:49:40 -0700455int dev_read_simple_addr_cells(const struct udevice *dev);
Simon Glass878d68c2017-06-12 06:21:31 -0600456
457/**
458 * dev_read_size_cells() - Get the size cells property in a node
459 *
460 * This function matches fdt_size_cells().
461 *
Mario Six7ba50412018-01-15 11:09:36 +0100462 * @dev: device to check
Simon Glass878d68c2017-06-12 06:21:31 -0600463 * @return number of size cells this node uses
464 */
Simon Glass88b3a372020-01-27 08:49:40 -0700465int dev_read_simple_size_cells(const struct udevice *dev);
Simon Glass878d68c2017-06-12 06:21:31 -0600466
467/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600468 * dev_read_phandle() - Get the phandle from a device
469 *
470 * @dev: device to check
471 * @return phandle (1 or greater), or 0 if no phandle or other error
472 */
Simon Glass88b3a372020-01-27 08:49:40 -0700473int dev_read_phandle(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600474
475/**
476 * dev_read_prop()- - read a property from a device's node
477 *
478 * @dev: device to check
479 * @propname: property to read
480 * @lenp: place to put length on success
481 * @return pointer to property, or NULL if not found
482 */
Simon Glass88b3a372020-01-27 08:49:40 -0700483const void *dev_read_prop(const struct udevice *dev, const char *propname,
484 int *lenp);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600485
486/**
Patrick Delaunayce891fca2020-01-13 11:34:56 +0100487 * dev_read_first_prop()- get the reference of the first property
488 *
489 * Get reference to the first property of the node, it is used to iterate
490 * and read all the property with dev_read_prop_by_prop().
491 *
492 * @dev: device to check
493 * @prop: place to put argument reference
494 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
495 */
496int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
497
498/**
499 * ofnode_get_next_property() - get the reference of the next property
500 *
501 * Get reference to the next property of the node, it is used to iterate
502 * and read all the property with dev_read_prop_by_prop().
503 *
504 * @prop: reference of current argument and place to put reference of next one
505 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
506 */
507int dev_read_next_prop(struct ofprop *prop);
508
509/**
510 * dev_read_prop_by_prop() - get a pointer to the value of a property
511 *
512 * Get value for the property identified by the provided reference.
513 *
514 * @prop: reference on property
515 * @propname: If non-NULL, place to property name on success,
516 * @lenp: If non-NULL, place to put length on success
517 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
518 */
519const void *dev_read_prop_by_prop(struct ofprop *prop,
520 const char **propname, int *lenp);
521
522/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600523 * dev_read_alias_seq() - Get the alias sequence number of a node
524 *
525 * This works out whether a node is pointed to by an alias, and if so, the
526 * sequence number of that alias. Aliases are of the form <base><num> where
527 * <num> is the sequence number. For example spi2 would be sequence number 2.
528 *
529 * @dev: device to look up
530 * @devnump: set to the sequence number if one is found
531 * @return 0 if a sequence was found, -ve if not
532 */
Simon Glass88b3a372020-01-27 08:49:40 -0700533int dev_read_alias_seq(const struct udevice *dev, int *devnump);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600534
535/**
536 * dev_read_u32_array() - Find and read an array of 32 bit integers
537 *
538 * Search for a property in a device node and read 32-bit value(s) from
539 * it.
540 *
541 * The out_values is modified only if a valid u32 value can be decoded.
542 *
543 * @dev: device to look up
544 * @propname: name of the property to read
545 * @out_values: pointer to return value, modified only if return value is 0
546 * @sz: number of array elements to read
547 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
548 * property does not have a value, and -EOVERFLOW if the property data isn't
549 * large enough.
550 */
Simon Glass88b3a372020-01-27 08:49:40 -0700551int dev_read_u32_array(const struct udevice *dev, const char *propname,
Simon Glass47a0fd32017-05-18 20:09:04 -0600552 u32 *out_values, size_t sz);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600553
554/**
555 * dev_read_first_subnode() - find the first subnode of a device's node
556 *
557 * @dev: device to look up
558 * @return reference to the first subnode (which can be invalid if the device's
559 * node has no subnodes)
560 */
Simon Glass88b3a372020-01-27 08:49:40 -0700561ofnode dev_read_first_subnode(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600562
563/**
564 * ofnode_next_subnode() - find the next sibling of a subnode
565 *
566 * @node: valid reference to previous node (sibling)
567 * @return reference to the next subnode (which can be invalid if the node
568 * has no more siblings)
569 */
Simon Glass47a0fd32017-05-18 20:09:04 -0600570ofnode dev_read_next_subnode(ofnode node);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600571
572/**
573 * dev_read_u8_array_ptr() - find an 8-bit array
574 *
575 * Look up a device's node property and return a pointer to its contents as a
576 * byte array of given length. The property must have at least enough data
577 * for the array (count bytes). It may have more, but this will be ignored.
578 * The data is not copied.
579 *
580 * @dev: device to look up
581 * @propname: name of property to find
582 * @sz: number of array elements
583 * @return pointer to byte array if found, or NULL if the property is not
584 * found or there is not enough data
585 */
Simon Glass88b3a372020-01-27 08:49:40 -0700586const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
587 const char *propname, size_t sz);
Simon Glass47a0fd32017-05-18 20:09:04 -0600588
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600589/**
590 * dev_read_enabled() - check whether a node is enabled
591 *
592 * This looks for a 'status' property. If this exists, then returns 1 if
593 * the status is 'ok' and 0 otherwise. If there is no status property,
594 * it returns 1 on the assumption that anything mentioned should be enabled
595 * by default.
596 *
597 * @dev: device to examine
598 * @return integer value 0 (not enabled) or 1 (enabled)
599 */
Simon Glass88b3a372020-01-27 08:49:40 -0700600int dev_read_enabled(const struct udevice *dev);
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600601
Simon Glassdcf98852017-07-25 08:29:55 -0600602/**
603 * dev_read_resource() - obtain an indexed resource from a device.
604 *
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900605 * @dev: device to examine
Simon Glassdcf98852017-07-25 08:29:55 -0600606 * @index index of the resource to retrieve (0 = first)
607 * @res returns the resource
608 * @return 0 if ok, negative on error
609 */
Simon Glass88b3a372020-01-27 08:49:40 -0700610int dev_read_resource(const struct udevice *dev, uint index,
611 struct resource *res);
Simon Glassdcf98852017-07-25 08:29:55 -0600612
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900613/**
614 * dev_read_resource_byname() - obtain a named resource from a device.
615 *
616 * @dev: device to examine
617 * @name: name of the resource to retrieve
618 * @res: returns the resource
619 * @return 0 if ok, negative on error
620 */
Simon Glass88b3a372020-01-27 08:49:40 -0700621int dev_read_resource_byname(const struct udevice *dev, const char *name,
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900622 struct resource *res);
623
Mario Six147c6072018-01-15 11:07:19 +0100624/**
Fabien Dessenne641067f2019-05-31 15:11:30 +0200625 * dev_translate_address() - Translate a device-tree address
Mario Six147c6072018-01-15 11:07:19 +0100626 *
627 * Translate an address from the device-tree into a CPU physical address. This
628 * function walks up the tree and applies the various bus mappings along the
629 * way.
630 *
631 * @dev: device giving the context in which to translate the address
632 * @in_addr: pointer to the address to translate
633 * @return the translated address; OF_BAD_ADDR on error
634 */
Simon Glass88b3a372020-01-27 08:49:40 -0700635u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
Michal Simek83e4c7e2019-01-31 16:30:59 +0100636
637/**
Fabien Dessenne641067f2019-05-31 15:11:30 +0200638 * dev_translate_dma_address() - Translate a device-tree DMA address
639 *
640 * Translate a DMA address from the device-tree into a CPU physical address.
641 * This function walks up the tree and applies the various bus mappings along
642 * the way.
643 *
644 * @dev: device giving the context in which to translate the DMA address
645 * @in_addr: pointer to the DMA address to translate
646 * @return the translated DMA address; OF_BAD_ADDR on error
647 */
Simon Glass88b3a372020-01-27 08:49:40 -0700648u64 dev_translate_dma_address(const struct udevice *dev,
649 const fdt32_t *in_addr);
Fabien Dessenne641067f2019-05-31 15:11:30 +0200650
651/**
Michal Simek83e4c7e2019-01-31 16:30:59 +0100652 * dev_read_alias_highest_id - Get highest alias id for the given stem
653 * @stem: Alias stem to be examined
654 *
655 * The function travels the lookup table to get the highest alias id for the
656 * given alias stem.
657 * @return alias ID, if found, else -1
658 */
659int dev_read_alias_highest_id(const char *stem);
660
Chunfeng Yun89b84b82020-05-02 11:35:09 +0200661/**
662 * dev_get_child_count() - get the child count of a device
663 *
664 * @dev: device to use for interation (struct udevice *)
665 * @return the count of child subnode
666 */
667int dev_get_child_count(const struct udevice *dev);
668
Stefan Roese68f81b82020-08-05 13:56:11 +0200669/**
670 * dev_read_pci_bus_range - Read PCI bus-range resource
671 *
672 * Look at the bus range property of a device node and return the pci bus
673 * range for this node.
674 *
675 * @dev: device to examine
676 * @res returns the resource
677 * @return 0 if ok, negative on error
678 */
679int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
680
Simon Glass47a0fd32017-05-18 20:09:04 -0600681#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
682
Simon Glass88b3a372020-01-27 08:49:40 -0700683static inline int dev_read_u32(const struct udevice *dev,
Masahiro Yamada3ab48f62017-12-30 02:00:05 +0900684 const char *propname, u32 *outp)
685{
686 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
687}
688
Simon Glass88b3a372020-01-27 08:49:40 -0700689static inline int dev_read_u32_default(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600690 const char *propname, int def)
691{
692 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
693}
694
Dario Binacchi4bb70752020-03-29 18:04:41 +0200695static inline int dev_read_u32_index(struct udevice *dev,
696 const char *propname, int index, u32 *outp)
697{
698 return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
699}
700
701static inline u32 dev_read_u32_index_default(struct udevice *dev,
702 const char *propname, int index,
703 u32 def)
704{
705 return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
706 def);
707}
708
Simon Glass88b3a372020-01-27 08:49:40 -0700709static inline int dev_read_s32(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700710 const char *propname, s32 *outp)
711{
712 return ofnode_read_s32(dev_ofnode(dev), propname, outp);
713}
714
Simon Glass88b3a372020-01-27 08:49:40 -0700715static inline int dev_read_s32_default(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700716 const char *propname, int def)
717{
718 return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
719}
720
Simon Glass88b3a372020-01-27 08:49:40 -0700721static inline int dev_read_u32u(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700722 const char *propname, uint *outp)
723{
724 u32 val;
725 int ret;
726
727 ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
728 if (ret)
729 return ret;
730 *outp = val;
731
732 return 0;
733}
734
Simon Glass88b3a372020-01-27 08:49:40 -0700735static inline int dev_read_u64(const struct udevice *dev,
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200736 const char *propname, u64 *outp)
737{
738 return ofnode_read_u64(dev_ofnode(dev), propname, outp);
739}
740
Simon Glass88b3a372020-01-27 08:49:40 -0700741static inline u64 dev_read_u64_default(const struct udevice *dev,
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200742 const char *propname, u64 def)
743{
744 return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
745}
746
Simon Glass88b3a372020-01-27 08:49:40 -0700747static inline const char *dev_read_string(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600748 const char *propname)
749{
750 return ofnode_read_string(dev_ofnode(dev), propname);
751}
752
Simon Glass88b3a372020-01-27 08:49:40 -0700753static inline bool dev_read_bool(const struct udevice *dev,
754 const char *propname)
Simon Glass47a0fd32017-05-18 20:09:04 -0600755{
756 return ofnode_read_bool(dev_ofnode(dev), propname);
757}
758
Simon Glass88b3a372020-01-27 08:49:40 -0700759static inline ofnode dev_read_subnode(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600760 const char *subbnode_name)
761{
762 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
763}
764
Simon Glass88b3a372020-01-27 08:49:40 -0700765static inline int dev_read_size(const struct udevice *dev, const char *propname)
Simon Glass47a0fd32017-05-18 20:09:04 -0600766{
767 return ofnode_read_size(dev_ofnode(dev), propname);
768}
769
Simon Glass88b3a372020-01-27 08:49:40 -0700770static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
771 int index)
Simon Glass47a0fd32017-05-18 20:09:04 -0600772{
773 return devfdt_get_addr_index(dev, index);
774}
775
Simon Glass88b3a372020-01-27 08:49:40 -0700776static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
Sekhar Norif5b90472019-08-01 19:12:56 +0530777 int index,
778 fdt_size_t *size)
779{
780 return devfdt_get_addr_size_index(dev, index, size);
781}
782
Simon Glass88b3a372020-01-27 08:49:40 -0700783static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100784 const char *name)
785{
786 return devfdt_get_addr_name(dev, name);
787}
788
Simon Glass88b3a372020-01-27 08:49:40 -0700789static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
Sekhar Norif5b90472019-08-01 19:12:56 +0530790 const char *name,
791 fdt_size_t *size)
792{
793 return devfdt_get_addr_size_name(dev, name, size);
794}
795
Simon Glass88b3a372020-01-27 08:49:40 -0700796static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600797{
798 return devfdt_get_addr(dev);
799}
800
Simon Glass88b3a372020-01-27 08:49:40 -0700801static inline void *dev_read_addr_ptr(const struct udevice *dev)
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200802{
Ovidiu Panait3fe69d32020-08-03 22:17:35 +0300803 return devfdt_get_addr_ptr(dev);
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200804}
805
Simon Glass88b3a372020-01-27 08:49:40 -0700806static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
Simon Glass33c215a2019-09-15 12:08:58 -0600807{
808 return devfdt_get_addr_pci(dev);
809}
810
Simon Glass88b3a372020-01-27 08:49:40 -0700811static inline void *dev_remap_addr(const struct udevice *dev)
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200812{
813 return devfdt_remap_addr(dev);
814}
815
Simon Glass88b3a372020-01-27 08:49:40 -0700816static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200817{
818 return devfdt_remap_addr_index(dev, index);
819}
820
Simon Glass88b3a372020-01-27 08:49:40 -0700821static inline void *dev_remap_addr_name(const struct udevice *dev,
822 const char *name)
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100823{
824 return devfdt_remap_addr_name(dev, name);
825}
826
Simon Glass88b3a372020-01-27 08:49:40 -0700827static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600828 const char *propname,
829 fdt_size_t *sizep)
830{
831 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
832}
833
Simon Glass88b3a372020-01-27 08:49:40 -0700834static inline const char *dev_read_name(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600835{
836 return ofnode_get_name(dev_ofnode(dev));
837}
838
Simon Glass88b3a372020-01-27 08:49:40 -0700839static inline int dev_read_stringlist_search(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600840 const char *propname,
841 const char *string)
842{
843 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
844}
845
Simon Glass88b3a372020-01-27 08:49:40 -0700846static inline int dev_read_string_index(const struct udevice *dev,
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200847 const char *propname, int index,
848 const char **outp)
849{
850 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
851}
852
Simon Glass88b3a372020-01-27 08:49:40 -0700853static inline int dev_read_string_count(const struct udevice *dev,
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200854 const char *propname)
855{
856 return ofnode_read_string_count(dev_ofnode(dev), propname);
857}
858
Simon Glass88b3a372020-01-27 08:49:40 -0700859static inline int dev_read_phandle_with_args(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600860 const char *list_name, const char *cells_name, int cell_count,
861 int index, struct ofnode_phandle_args *out_args)
862{
863 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
864 cells_name, cell_count, index,
865 out_args);
866}
867
Simon Glass88b3a372020-01-27 08:49:40 -0700868static inline int dev_count_phandle_with_args(const struct udevice *dev,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200869 const char *list_name, const char *cells_name, int cell_count)
Patrice Chotard642346a2017-07-18 11:57:08 +0200870{
871 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200872 cells_name, cell_count);
Patrice Chotard642346a2017-07-18 11:57:08 +0200873}
874
Simon Glass88b3a372020-01-27 08:49:40 -0700875static inline int dev_read_addr_cells(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600876{
Heinrich Schuchardtae6b33d2020-07-25 21:38:49 +0200877 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
878
879 return fdt_address_cells(gd->fdt_blob, parent);
Simon Glass47a0fd32017-05-18 20:09:04 -0600880}
881
Simon Glass88b3a372020-01-27 08:49:40 -0700882static inline int dev_read_size_cells(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600883{
Heinrich Schuchardtae6b33d2020-07-25 21:38:49 +0200884 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
885
886 return fdt_size_cells(gd->fdt_blob, parent);
Simon Glass878d68c2017-06-12 06:21:31 -0600887}
888
Simon Glass88b3a372020-01-27 08:49:40 -0700889static inline int dev_read_simple_addr_cells(const struct udevice *dev)
Simon Glass878d68c2017-06-12 06:21:31 -0600890{
891 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
892}
893
Simon Glass88b3a372020-01-27 08:49:40 -0700894static inline int dev_read_simple_size_cells(const struct udevice *dev)
Simon Glass878d68c2017-06-12 06:21:31 -0600895{
Simon Glass47a0fd32017-05-18 20:09:04 -0600896 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
897}
898
Simon Glass88b3a372020-01-27 08:49:40 -0700899static inline int dev_read_phandle(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600900{
901 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
902}
903
Simon Glass88b3a372020-01-27 08:49:40 -0700904static inline const void *dev_read_prop(const struct udevice *dev,
Masahiro Yamadafd736212017-07-17 12:18:39 +0900905 const char *propname, int *lenp)
Simon Glass47a0fd32017-05-18 20:09:04 -0600906{
Masahiro Yamada61e51ba2017-06-22 16:54:05 +0900907 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glass47a0fd32017-05-18 20:09:04 -0600908}
909
Patrick Delaunayce891fca2020-01-13 11:34:56 +0100910static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
911{
912 return ofnode_get_first_property(dev_ofnode(dev), prop);
913}
914
915static inline int dev_read_next_prop(struct ofprop *prop)
916{
917 return ofnode_get_next_property(prop);
918}
919
920static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
921 const char **propname,
922 int *lenp)
923{
924 return ofnode_get_property_by_prop(prop, propname, lenp);
925}
926
Simon Glass88b3a372020-01-27 08:49:40 -0700927static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
Simon Glass47a0fd32017-05-18 20:09:04 -0600928{
Marcel Ziswiler45224e82019-05-20 02:44:57 +0200929#if CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glass47a0fd32017-05-18 20:09:04 -0600930 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
931 dev_of_offset(dev), devnump);
Marcel Ziswiler45224e82019-05-20 02:44:57 +0200932#else
933 return -ENOTSUPP;
934#endif
Simon Glass47a0fd32017-05-18 20:09:04 -0600935}
936
Simon Glass88b3a372020-01-27 08:49:40 -0700937static inline int dev_read_u32_array(const struct udevice *dev,
938 const char *propname, u32 *out_values,
939 size_t sz)
Simon Glass47a0fd32017-05-18 20:09:04 -0600940{
941 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
942}
943
Simon Glass88b3a372020-01-27 08:49:40 -0700944static inline ofnode dev_read_first_subnode(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600945{
946 return ofnode_first_subnode(dev_ofnode(dev));
947}
948
949static inline ofnode dev_read_next_subnode(ofnode node)
950{
951 return ofnode_next_subnode(node);
952}
953
Simon Glass88b3a372020-01-27 08:49:40 -0700954static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
Simon Glassf262d4c2020-01-27 08:49:47 -0700955 const char *propname,
956 size_t sz)
Simon Glassf11c7ab2017-05-18 20:09:03 -0600957{
958 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
959}
960
Simon Glass88b3a372020-01-27 08:49:40 -0700961static inline int dev_read_enabled(const struct udevice *dev)
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600962{
963 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
964}
965
Simon Glass88b3a372020-01-27 08:49:40 -0700966static inline int dev_read_resource(const struct udevice *dev, uint index,
Simon Glassdcf98852017-07-25 08:29:55 -0600967 struct resource *res)
968{
969 return ofnode_read_resource(dev_ofnode(dev), index, res);
970}
971
Simon Glass88b3a372020-01-27 08:49:40 -0700972static inline int dev_read_resource_byname(const struct udevice *dev,
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900973 const char *name,
974 struct resource *res)
975{
976 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
977}
978
Simon Glass88b3a372020-01-27 08:49:40 -0700979static inline u64 dev_translate_address(const struct udevice *dev,
980 const fdt32_t *in_addr)
Mario Six147c6072018-01-15 11:07:19 +0100981{
982 return ofnode_translate_address(dev_ofnode(dev), in_addr);
983}
984
Simon Glass88b3a372020-01-27 08:49:40 -0700985static inline u64 dev_translate_dma_address(const struct udevice *dev,
986 const fdt32_t *in_addr)
Fabien Dessenne641067f2019-05-31 15:11:30 +0200987{
988 return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
989}
990
Michal Simek83e4c7e2019-01-31 16:30:59 +0100991static inline int dev_read_alias_highest_id(const char *stem)
992{
Michael Walle0a6b75f2020-06-02 01:47:08 +0200993 if (!CONFIG_IS_ENABLED(OF_LIBFDT))
994 return -1;
Michal Simek83e4c7e2019-01-31 16:30:59 +0100995 return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
996}
997
Chunfeng Yun89b84b82020-05-02 11:35:09 +0200998static inline int dev_get_child_count(const struct udevice *dev)
999{
1000 return ofnode_get_child_count(dev_ofnode(dev));
1001}
1002
Simon Glassf11c7ab2017-05-18 20:09:03 -06001003#endif /* CONFIG_DM_DEV_READ_INLINE */
1004
1005/**
1006 * dev_for_each_subnode() - Helper function to iterate through subnodes
1007 *
1008 * This creates a for() loop which works through the subnodes in a device's
1009 * device-tree node.
1010 *
1011 * @subnode: ofnode holding the current subnode
1012 * @dev: device to use for interation (struct udevice *)
1013 */
1014#define dev_for_each_subnode(subnode, dev) \
1015 for (subnode = dev_read_first_subnode(dev); \
1016 ofnode_valid(subnode); \
1017 subnode = ofnode_next_subnode(subnode))
1018
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001019/**
1020 * dev_for_each_property() - Helper function to iterate through property
1021 *
1022 * This creates a for() loop which works through the property in a device's
1023 * device-tree node.
1024 *
1025 * @prop: struct ofprop holding the current property
1026 * @dev: device to use for interation (struct udevice *)
1027 */
1028#define dev_for_each_property(prop, dev) \
1029 for (int ret_prop = dev_read_first_prop(dev, &prop); \
1030 !ret_prop; \
1031 ret_prop = dev_read_next_prop(&prop))
1032
Simon Glassf11c7ab2017-05-18 20:09:03 -06001033#endif