xref: /rk3399_rockchip-uboot/include/dm/read.h (revision 8f7de5145da2de88e169e58343cceeee233362d4)
1f11c7ab9SSimon Glass /*
2f11c7ab9SSimon Glass  * Function to read values from the device tree node attached to a udevice.
3f11c7ab9SSimon Glass  *
4f11c7ab9SSimon Glass  * Copyright (c) 2017 Google, Inc
5f11c7ab9SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
6f11c7ab9SSimon Glass  *
7f11c7ab9SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
8f11c7ab9SSimon Glass  */
9f11c7ab9SSimon Glass 
10f11c7ab9SSimon Glass #ifndef _DM_READ_H
11f11c7ab9SSimon Glass #define _DM_READ_H
12f11c7ab9SSimon Glass 
13f11c7ab9SSimon Glass #include <dm/fdtaddr.h>
14f11c7ab9SSimon Glass #include <dm/ofnode.h>
15f11c7ab9SSimon Glass #include <dm/uclass.h>
16f11c7ab9SSimon Glass 
17a4481012SSimon Glass struct resource;
18a4481012SSimon Glass 
19f11c7ab9SSimon Glass #if CONFIG_IS_ENABLED(OF_LIVE)
dev_np(struct udevice * dev)20f11c7ab9SSimon Glass static inline const struct device_node *dev_np(struct udevice *dev)
21f11c7ab9SSimon Glass {
22f11c7ab9SSimon Glass 	return ofnode_to_np(dev->node);
23f11c7ab9SSimon Glass }
24f11c7ab9SSimon Glass #else
dev_np(struct udevice * dev)25f11c7ab9SSimon Glass static inline const struct device_node *dev_np(struct udevice *dev)
26f11c7ab9SSimon Glass {
27f11c7ab9SSimon Glass 	return NULL;
28f11c7ab9SSimon Glass }
29f11c7ab9SSimon Glass #endif
30f11c7ab9SSimon Glass 
31f11c7ab9SSimon Glass /**
32f11c7ab9SSimon Glass  * dev_ofnode() - get the DT node reference associated with a udevice
33f11c7ab9SSimon Glass  *
34f11c7ab9SSimon Glass  * @dev:	device to check
35f11c7ab9SSimon Glass  * @return reference of the the device's DT node
36f11c7ab9SSimon Glass  */
dev_ofnode(struct udevice * dev)37f11c7ab9SSimon Glass static inline ofnode dev_ofnode(struct udevice *dev)
38f11c7ab9SSimon Glass {
39f11c7ab9SSimon Glass 	return dev->node;
40f11c7ab9SSimon Glass }
41f11c7ab9SSimon Glass 
dev_of_valid(struct udevice * dev)42f11c7ab9SSimon Glass static inline bool dev_of_valid(struct udevice *dev)
43f11c7ab9SSimon Glass {
44f11c7ab9SSimon Glass 	return ofnode_valid(dev_ofnode(dev));
45f11c7ab9SSimon Glass }
46f11c7ab9SSimon Glass 
4747a0fd3bSSimon Glass #ifndef CONFIG_DM_DEV_READ_INLINE
4847a0fd3bSSimon Glass /**
4947a0fd3bSSimon Glass  * dev_read_u32_default() - read a 32-bit integer from a device's DT property
5047a0fd3bSSimon Glass  *
5147a0fd3bSSimon Glass  * @dev:	device to read DT property from
5247a0fd3bSSimon Glass  * @propname:	name of the property to read from
5347a0fd3bSSimon Glass  * @def:	default value to return if the property has no value
5447a0fd3bSSimon Glass  * @return property value, or @def if not found
5547a0fd3bSSimon Glass  */
5647a0fd3bSSimon Glass int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
57f11c7ab9SSimon Glass 
58f11c7ab9SSimon Glass /**
59270d4d86SJoseph Chen  * dev_read_s32_default() - read a signed 32-bit integer from a device's DT property
60270d4d86SJoseph Chen  *
61270d4d86SJoseph Chen  * @dev:	device to read DT property from
62270d4d86SJoseph Chen  * @propname:	name of the property to read from
63270d4d86SJoseph Chen  * @def:	default value to return if the property has no value
64270d4d86SJoseph Chen  * @return property value, or @def if not found
65270d4d86SJoseph Chen  */
66270d4d86SJoseph Chen int dev_read_s32_default(struct udevice *dev, const char *propname, int def);
67270d4d86SJoseph Chen 
68270d4d86SJoseph Chen /**
69f11c7ab9SSimon Glass  * dev_read_string() - Read a string from a device's DT property
70f11c7ab9SSimon Glass  *
71f11c7ab9SSimon Glass  * @dev:	device to read DT property from
72f11c7ab9SSimon Glass  * @propname:	name of the property to read
73f11c7ab9SSimon Glass  * @return string from property value, or NULL if there is no such property
74f11c7ab9SSimon Glass  */
7547a0fd3bSSimon Glass const char *dev_read_string(struct udevice *dev, const char *propname);
76f11c7ab9SSimon Glass 
77f11c7ab9SSimon Glass /**
78f11c7ab9SSimon Glass  * dev_read_bool() - read a boolean value from a device's DT property
79f11c7ab9SSimon Glass  *
80f11c7ab9SSimon Glass  * @dev:	device to read DT property from
81f11c7ab9SSimon Glass  * @propname:	name of property to read
82f11c7ab9SSimon Glass  * @return true if property is present (meaning true), false if not present
83f11c7ab9SSimon Glass  */
8447a0fd3bSSimon Glass bool dev_read_bool(struct udevice *dev, const char *propname);
85f11c7ab9SSimon Glass 
86f11c7ab9SSimon Glass /**
87f11c7ab9SSimon Glass  * dev_read_subnode() - find a named subnode of a device
88f11c7ab9SSimon Glass  *
89f11c7ab9SSimon Glass  * @dev:	device whose DT node contains the subnode
90f11c7ab9SSimon Glass  * @subnode_name: name of subnode to find
91f11c7ab9SSimon Glass  * @return reference to subnode (which can be invalid if there is no such
92f11c7ab9SSimon Glass  * subnode)
93f11c7ab9SSimon Glass  */
9447a0fd3bSSimon Glass ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
95f11c7ab9SSimon Glass 
96f11c7ab9SSimon Glass /**
97f11c7ab9SSimon Glass  * dev_read_size() - read the size of a property
98f11c7ab9SSimon Glass  *
99f11c7ab9SSimon Glass  * @dev: device to check
100f11c7ab9SSimon Glass  * @propname: property to check
101f11c7ab9SSimon Glass  * @return size of property if present, or -EINVAL if not
102f11c7ab9SSimon Glass  */
10347a0fd3bSSimon Glass int dev_read_size(struct udevice *dev, const char *propname);
104f11c7ab9SSimon Glass 
105f11c7ab9SSimon Glass /**
106f11c7ab9SSimon Glass  * dev_read_addr_index() - Get the indexed reg property of a device
107f11c7ab9SSimon Glass  *
108f11c7ab9SSimon Glass  * @dev: Device to read from
109f11c7ab9SSimon Glass  * @index: the 'reg' property can hold a list of <addr, size> pairs
110f11c7ab9SSimon Glass  *	   and @index is used to select which one is required
111f11c7ab9SSimon Glass  *
112f11c7ab9SSimon Glass  * @return address or FDT_ADDR_T_NONE if not found
113f11c7ab9SSimon Glass  */
11447a0fd3bSSimon Glass fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
115f11c7ab9SSimon Glass 
116f11c7ab9SSimon Glass /**
117f11c7ab9SSimon Glass  * dev_read_addr() - Get the reg property of a device
118f11c7ab9SSimon Glass  *
119f11c7ab9SSimon Glass  * @dev: Device to read from
120f11c7ab9SSimon Glass  *
121f11c7ab9SSimon Glass  * @return address or FDT_ADDR_T_NONE if not found
122f11c7ab9SSimon Glass  */
12347a0fd3bSSimon Glass fdt_addr_t dev_read_addr(struct udevice *dev);
124f11c7ab9SSimon Glass 
125f11c7ab9SSimon Glass /**
12618a0c4a6SPhilipp Tomsich  * dev_read_addr_ptr() - Get the reg property of a device
12718a0c4a6SPhilipp Tomsich  *                       as a pointer
12818a0c4a6SPhilipp Tomsich  *
12918a0c4a6SPhilipp Tomsich  * @dev: Device to read from
13018a0c4a6SPhilipp Tomsich  *
13118a0c4a6SPhilipp Tomsich  * @return pointer or NULL if not found
13218a0c4a6SPhilipp Tomsich  */
13318a0c4a6SPhilipp Tomsich void *dev_read_addr_ptr(struct udevice *dev);
13418a0c4a6SPhilipp Tomsich 
13518a0c4a6SPhilipp Tomsich /**
136f11c7ab9SSimon Glass  * dev_read_addr_size() - get address and size from a device property
137f11c7ab9SSimon Glass  *
138f11c7ab9SSimon Glass  * This does no address translation. It simply reads an property that contains
139f11c7ab9SSimon Glass  * an address and a size value, one after the other.
140f11c7ab9SSimon Glass  *
141f11c7ab9SSimon Glass  * @dev: Device to read from
142f11c7ab9SSimon Glass  * @propname: property to read
143f11c7ab9SSimon Glass  * @sizep: place to put size value (on success)
144f11c7ab9SSimon Glass  * @return address value, or FDT_ADDR_T_NONE on error
145f11c7ab9SSimon Glass  */
14647a0fd3bSSimon Glass fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
14747a0fd3bSSimon Glass 				fdt_size_t *sizep);
148f11c7ab9SSimon Glass 
149f11c7ab9SSimon Glass /**
150f11c7ab9SSimon Glass  * dev_read_name() - get the name of a device's node
151f11c7ab9SSimon Glass  *
152f11c7ab9SSimon Glass  * @node: valid node to look up
153f11c7ab9SSimon Glass  * @return name of node
154f11c7ab9SSimon Glass  */
15547a0fd3bSSimon Glass const char *dev_read_name(struct udevice *dev);
156f11c7ab9SSimon Glass 
157f11c7ab9SSimon Glass /**
158f11c7ab9SSimon Glass  * dev_read_stringlist_search() - find string in a string list and return index
159f11c7ab9SSimon Glass  *
160f11c7ab9SSimon Glass  * Note that it is possible for this function to succeed on property values
161f11c7ab9SSimon Glass  * that are not NUL-terminated. That's because the function will stop after
162f11c7ab9SSimon Glass  * finding the first occurrence of @string. This can for example happen with
163f11c7ab9SSimon Glass  * small-valued cell properties, such as #address-cells, when searching for
164f11c7ab9SSimon Glass  * the empty string.
165f11c7ab9SSimon Glass  *
166f11c7ab9SSimon Glass  * @dev: device to check
167f11c7ab9SSimon Glass  * @propname: name of the property containing the string list
168f11c7ab9SSimon Glass  * @string: string to look up in the string list
169f11c7ab9SSimon Glass  *
170f11c7ab9SSimon Glass  * @return:
171f11c7ab9SSimon Glass  *   the index of the string in the list of strings
172f11c7ab9SSimon Glass  *   -ENODATA if the property is not found
173f11c7ab9SSimon Glass  *   -EINVAL on some other error
174f11c7ab9SSimon Glass  */
17547a0fd3bSSimon Glass int dev_read_stringlist_search(struct udevice *dev, const char *property,
17647a0fd3bSSimon Glass 			  const char *string);
177f11c7ab9SSimon Glass 
178f11c7ab9SSimon Glass /**
17957a9c706SJean-Jacques Hiblot  * dev_read_string_index() - obtain an indexed string from a string list
18057a9c706SJean-Jacques Hiblot  *
18157a9c706SJean-Jacques Hiblot  * @dev: device to examine
18257a9c706SJean-Jacques Hiblot  * @propname: name of the property containing the string list
18357a9c706SJean-Jacques Hiblot  * @index: index of the string to return
18457a9c706SJean-Jacques Hiblot  * @out: return location for the string
18557a9c706SJean-Jacques Hiblot  *
18657a9c706SJean-Jacques Hiblot  * @return:
18757a9c706SJean-Jacques Hiblot  *   length of string, if found or -ve error value if not found
18857a9c706SJean-Jacques Hiblot  */
18957a9c706SJean-Jacques Hiblot int dev_read_string_index(struct udevice *dev, const char *propname, int index,
19057a9c706SJean-Jacques Hiblot 			  const char **outp);
19157a9c706SJean-Jacques Hiblot 
19257a9c706SJean-Jacques Hiblot /**
19357a9c706SJean-Jacques Hiblot  * dev_read_string_count() - find the number of strings in a string list
19457a9c706SJean-Jacques Hiblot  *
19557a9c706SJean-Jacques Hiblot  * @dev: device to examine
19657a9c706SJean-Jacques Hiblot  * @propname: name of the property containing the string list
19757a9c706SJean-Jacques Hiblot  * @return:
19857a9c706SJean-Jacques Hiblot  *   number of strings in the list, or -ve error value if not found
19957a9c706SJean-Jacques Hiblot  */
20057a9c706SJean-Jacques Hiblot int dev_read_string_count(struct udevice *dev, const char *propname);
20157a9c706SJean-Jacques Hiblot /**
202f11c7ab9SSimon Glass  * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
203f11c7ab9SSimon Glass  *
204f11c7ab9SSimon Glass  * This function is useful to parse lists of phandles and their arguments.
205f11c7ab9SSimon Glass  * Returns 0 on success and fills out_args, on error returns appropriate
206f11c7ab9SSimon Glass  * errno value.
207f11c7ab9SSimon Glass  *
208f11c7ab9SSimon Glass  * Caller is responsible to call of_node_put() on the returned out_args->np
209f11c7ab9SSimon Glass  * pointer.
210f11c7ab9SSimon Glass  *
211f11c7ab9SSimon Glass  * Example:
212f11c7ab9SSimon Glass  *
213f11c7ab9SSimon Glass  * phandle1: node1 {
214f11c7ab9SSimon Glass  *	#list-cells = <2>;
215f11c7ab9SSimon Glass  * }
216f11c7ab9SSimon Glass  *
217f11c7ab9SSimon Glass  * phandle2: node2 {
218f11c7ab9SSimon Glass  *	#list-cells = <1>;
219f11c7ab9SSimon Glass  * }
220f11c7ab9SSimon Glass  *
221f11c7ab9SSimon Glass  * node3 {
222f11c7ab9SSimon Glass  *	list = <&phandle1 1 2 &phandle2 3>;
223f11c7ab9SSimon Glass  * }
224f11c7ab9SSimon Glass  *
225f11c7ab9SSimon Glass  * To get a device_node of the `node2' node you may call this:
226f11c7ab9SSimon Glass  * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
227f11c7ab9SSimon Glass  *
228f11c7ab9SSimon Glass  * @dev:	device whose node containing a list
229f11c7ab9SSimon Glass  * @list_name:	property name that contains a list
230f11c7ab9SSimon Glass  * @cells_name:	property name that specifies phandles' arguments count
231f11c7ab9SSimon Glass  * @cells_count: Cell count to use if @cells_name is NULL
232f11c7ab9SSimon Glass  * @index:	index of a phandle to parse out
233f11c7ab9SSimon Glass  * @out_args:	optional pointer to output arguments structure (will be filled)
234f11c7ab9SSimon Glass  * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
235f11c7ab9SSimon Glass  *	@list_name does not exist, -EINVAL if a phandle was not found,
236f11c7ab9SSimon Glass  *	@cells_name could not be found, the arguments were truncated or there
237f11c7ab9SSimon Glass  *	were too many arguments.
238f11c7ab9SSimon Glass  */
23947a0fd3bSSimon Glass int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
24047a0fd3bSSimon Glass 				const char *cells_name, int cell_count,
24147a0fd3bSSimon Glass 				int index,
24247a0fd3bSSimon Glass 				struct ofnode_phandle_args *out_args);
243f11c7ab9SSimon Glass 
244f11c7ab9SSimon Glass /**
245642346aeSPatrice Chotard  * dev_count_phandle_with_args() - Return phandle number in a list
246642346aeSPatrice Chotard  *
247642346aeSPatrice Chotard  * This function is usefull to get phandle number contained in a property list.
248642346aeSPatrice Chotard  * For example, this allows to allocate the right amount of memory to keep
249642346aeSPatrice Chotard  * clock's reference contained into the "clocks" property.
250642346aeSPatrice Chotard  *
251642346aeSPatrice Chotard  *
252642346aeSPatrice Chotard  * @dev:	device whose node containing a list
253642346aeSPatrice Chotard  * @list_name:	property name that contains a list
254642346aeSPatrice Chotard  * @cells_name:	property name that specifies phandles' arguments count
255642346aeSPatrice Chotard  * @Returns number of phandle found on success, on error returns appropriate
256642346aeSPatrice Chotard  * errno value.
257642346aeSPatrice Chotard  */
258642346aeSPatrice Chotard 
259642346aeSPatrice Chotard int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
260642346aeSPatrice Chotard 				const char *cells_name);
261642346aeSPatrice Chotard 
262642346aeSPatrice Chotard /**
263f11c7ab9SSimon Glass  * dev_read_addr_cells() - Get the number of address cells for a device's node
264f11c7ab9SSimon Glass  *
265f11c7ab9SSimon Glass  * This walks back up the tree to find the closest #address-cells property
266f11c7ab9SSimon Glass  * which controls the given node.
267f11c7ab9SSimon Glass  *
268f11c7ab9SSimon Glass  * @dev: devioe to check
269f11c7ab9SSimon Glass  * @return number of address cells this node uses
270f11c7ab9SSimon Glass  */
27147a0fd3bSSimon Glass int dev_read_addr_cells(struct udevice *dev);
272f11c7ab9SSimon Glass 
273f11c7ab9SSimon Glass /**
274*8f7de514SShawn Lin  * dev_remap_addr_index() - Get the indexed reg property of a device
275*8f7de514SShawn Lin  *                               as a memory-mapped I/O pointer
276*8f7de514SShawn Lin  *
277*8f7de514SShawn Lin  * @dev: Device to read from
278*8f7de514SShawn Lin  * @index: the 'reg' property can hold a list of <addr, size> pairs
279*8f7de514SShawn Lin  *         and @index is used to select which one is required
280*8f7de514SShawn Lin  *
281*8f7de514SShawn Lin  * Return: pointer or NULL if not found
282*8f7de514SShawn Lin  */
283*8f7de514SShawn Lin void *dev_remap_addr_index(struct udevice *dev, int index);
284*8f7de514SShawn Lin 
285*8f7de514SShawn Lin /**
286f11c7ab9SSimon Glass  * dev_read_size_cells() - Get the number of size cells for a device's node
287f11c7ab9SSimon Glass  *
288f11c7ab9SSimon Glass  * This walks back up the tree to find the closest #size-cells property
289f11c7ab9SSimon Glass  * which controls the given node.
290f11c7ab9SSimon Glass  *
291f11c7ab9SSimon Glass  * @dev: devioe to check
292f11c7ab9SSimon Glass  * @return number of size cells this node uses
293f11c7ab9SSimon Glass  */
29447a0fd3bSSimon Glass int dev_read_size_cells(struct udevice *dev);
295f11c7ab9SSimon Glass 
296f11c7ab9SSimon Glass /**
297878d68c0SSimon Glass  * dev_read_addr_cells() - Get the address cells property in a node
298878d68c0SSimon Glass  *
299878d68c0SSimon Glass  * This function matches fdt_address_cells().
300878d68c0SSimon Glass  *
301878d68c0SSimon Glass  * @dev: devioe to check
302878d68c0SSimon Glass  * @return number of address cells this node uses
303878d68c0SSimon Glass  */
304878d68c0SSimon Glass int dev_read_simple_addr_cells(struct udevice *dev);
305878d68c0SSimon Glass 
306878d68c0SSimon Glass /**
307878d68c0SSimon Glass  * dev_read_size_cells() - Get the size cells property in a node
308878d68c0SSimon Glass  *
309878d68c0SSimon Glass  * This function matches fdt_size_cells().
310878d68c0SSimon Glass  *
311878d68c0SSimon Glass  * @dev: devioe to check
312878d68c0SSimon Glass  * @return number of size cells this node uses
313878d68c0SSimon Glass  */
314878d68c0SSimon Glass int dev_read_simple_size_cells(struct udevice *dev);
315878d68c0SSimon Glass 
316878d68c0SSimon Glass /**
317f11c7ab9SSimon Glass  * dev_read_phandle() - Get the phandle from a device
318f11c7ab9SSimon Glass  *
319f11c7ab9SSimon Glass  * @dev: device to check
320f11c7ab9SSimon Glass  * @return phandle (1 or greater), or 0 if no phandle or other error
321f11c7ab9SSimon Glass  */
32247a0fd3bSSimon Glass int dev_read_phandle(struct udevice *dev);
323f11c7ab9SSimon Glass 
324f11c7ab9SSimon Glass /**
325f11c7ab9SSimon Glass  * dev_read_prop()- - read a property from a device's node
326f11c7ab9SSimon Glass  *
327f11c7ab9SSimon Glass  * @dev: device to check
328f11c7ab9SSimon Glass  * @propname: property to read
329f11c7ab9SSimon Glass  * @lenp: place to put length on success
330f11c7ab9SSimon Glass  * @return pointer to property, or NULL if not found
331f11c7ab9SSimon Glass  */
332fd73621cSMasahiro Yamada const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
333f11c7ab9SSimon Glass 
334f11c7ab9SSimon Glass /**
3353cf48410SPatrick Delaunay  * dev_read_first_prop()- get the reference of the first property
3363cf48410SPatrick Delaunay  *
3373cf48410SPatrick Delaunay  * Get reference to the first property of the node, it is used to iterate
3383cf48410SPatrick Delaunay  * and read all the property with dev_read_prop_by_prop().
3393cf48410SPatrick Delaunay  *
3403cf48410SPatrick Delaunay  * @dev: device to check
3413cf48410SPatrick Delaunay  * @prop: place to put argument reference
3423cf48410SPatrick Delaunay  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
3433cf48410SPatrick Delaunay  */
3443cf48410SPatrick Delaunay int dev_read_first_prop(struct udevice *dev, struct ofprop *prop);
3453cf48410SPatrick Delaunay 
3463cf48410SPatrick Delaunay /**
3473cf48410SPatrick Delaunay  * ofnode_get_next_property() - get the reference of the next property
3483cf48410SPatrick Delaunay  *
3493cf48410SPatrick Delaunay  * Get reference to the next property of the node, it is used to iterate
3503cf48410SPatrick Delaunay  * and read all the property with dev_read_prop_by_prop().
3513cf48410SPatrick Delaunay  *
3523cf48410SPatrick Delaunay  * @prop: reference of current argument and place to put reference of next one
3533cf48410SPatrick Delaunay  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
3543cf48410SPatrick Delaunay  */
3553cf48410SPatrick Delaunay int dev_read_next_prop(struct ofprop *prop);
3563cf48410SPatrick Delaunay 
3573cf48410SPatrick Delaunay /**
3583cf48410SPatrick Delaunay  * dev_read_prop_by_prop() - get a pointer to the value of a property
3593cf48410SPatrick Delaunay  *
3603cf48410SPatrick Delaunay  * Get value for the property identified by the provided reference.
3613cf48410SPatrick Delaunay  *
3623cf48410SPatrick Delaunay  * @prop: reference on property
3633cf48410SPatrick Delaunay  * @propname: If non-NULL, place to property name on success,
3643cf48410SPatrick Delaunay  * @lenp: If non-NULL, place to put length on success
3653cf48410SPatrick Delaunay  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
3663cf48410SPatrick Delaunay  */
3673cf48410SPatrick Delaunay const void *dev_read_prop_by_prop(struct ofprop *prop,
3683cf48410SPatrick Delaunay 				  const char **propname, int *lenp);
3693cf48410SPatrick Delaunay 
3703cf48410SPatrick Delaunay /**
371f11c7ab9SSimon Glass  * dev_read_alias_seq() - Get the alias sequence number of a node
372f11c7ab9SSimon Glass  *
373f11c7ab9SSimon Glass  * This works out whether a node is pointed to by an alias, and if so, the
374f11c7ab9SSimon Glass  * sequence number of that alias. Aliases are of the form <base><num> where
375f11c7ab9SSimon Glass  * <num> is the sequence number. For example spi2 would be sequence number 2.
376f11c7ab9SSimon Glass  *
377f11c7ab9SSimon Glass  * @dev: device to look up
378f11c7ab9SSimon Glass  * @devnump: set to the sequence number if one is found
379f11c7ab9SSimon Glass  * @return 0 if a sequence was found, -ve if not
380f11c7ab9SSimon Glass  */
38147a0fd3bSSimon Glass int dev_read_alias_seq(struct udevice *dev, int *devnump);
382f11c7ab9SSimon Glass 
383f11c7ab9SSimon Glass /**
384f11c7ab9SSimon Glass  * dev_read_u32_array() - Find and read an array of 32 bit integers
385f11c7ab9SSimon Glass  *
386f11c7ab9SSimon Glass  * Search for a property in a device node and read 32-bit value(s) from
387f11c7ab9SSimon Glass  * it.
388f11c7ab9SSimon Glass  *
389f11c7ab9SSimon Glass  * The out_values is modified only if a valid u32 value can be decoded.
390f11c7ab9SSimon Glass  *
391f11c7ab9SSimon Glass  * @dev: device to look up
392f11c7ab9SSimon Glass  * @propname:	name of the property to read
393f11c7ab9SSimon Glass  * @out_values:	pointer to return value, modified only if return value is 0
394f11c7ab9SSimon Glass  * @sz:		number of array elements to read
395f11c7ab9SSimon Glass  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
396f11c7ab9SSimon Glass  * property does not have a value, and -EOVERFLOW if the property data isn't
397f11c7ab9SSimon Glass  * large enough.
398f11c7ab9SSimon Glass  */
39947a0fd3bSSimon Glass int dev_read_u32_array(struct udevice *dev, const char *propname,
40047a0fd3bSSimon Glass 		       u32 *out_values, size_t sz);
401f11c7ab9SSimon Glass 
402f11c7ab9SSimon Glass /**
40304539b46SJoseph Chen  * dev_write_u32_array() - Find and write an array of 32 bit integers
40404539b46SJoseph Chen  *
40504539b46SJoseph Chen  * Search for a property in a device node and write 32-bit value(s) to
40604539b46SJoseph Chen  * it.
40704539b46SJoseph Chen  *
40804539b46SJoseph Chen  * The out_values is modified only if a valid u32 value can be decoded.
40904539b46SJoseph Chen  *
41004539b46SJoseph Chen  * @dev: device to look up
41104539b46SJoseph Chen  * @propname:	name of the property to read
41204539b46SJoseph Chen  * @values:	pointer to update value, modified only if return value is 0
41304539b46SJoseph Chen  * @sz:		number of array elements to read
41404539b46SJoseph Chen  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
41504539b46SJoseph Chen  * property does not have a value, and -EOVERFLOW if the property data isn't
41604539b46SJoseph Chen  * large enough.
41704539b46SJoseph Chen  */
41804539b46SJoseph Chen int dev_write_u32_array(struct udevice *dev, const char *propname,
41904539b46SJoseph Chen 			u32 *values, size_t sz);
42004539b46SJoseph Chen 
42104539b46SJoseph Chen /**
422f11c7ab9SSimon Glass  * dev_read_first_subnode() - find the first subnode of a device's node
423f11c7ab9SSimon Glass  *
424f11c7ab9SSimon Glass  * @dev: device to look up
425f11c7ab9SSimon Glass  * @return reference to the first subnode (which can be invalid if the device's
426f11c7ab9SSimon Glass  * node has no subnodes)
427f11c7ab9SSimon Glass  */
42847a0fd3bSSimon Glass ofnode dev_read_first_subnode(struct udevice *dev);
429f11c7ab9SSimon Glass 
430f11c7ab9SSimon Glass /**
431f11c7ab9SSimon Glass  * ofnode_next_subnode() - find the next sibling of a subnode
432f11c7ab9SSimon Glass  *
433f11c7ab9SSimon Glass  * @node:	valid reference to previous node (sibling)
434f11c7ab9SSimon Glass  * @return reference to the next subnode (which can be invalid if the node
435f11c7ab9SSimon Glass  * has no more siblings)
436f11c7ab9SSimon Glass  */
43747a0fd3bSSimon Glass ofnode dev_read_next_subnode(ofnode node);
438f11c7ab9SSimon Glass 
439f11c7ab9SSimon Glass /**
440f11c7ab9SSimon Glass  * dev_read_u8_array_ptr() - find an 8-bit array
441f11c7ab9SSimon Glass  *
442f11c7ab9SSimon Glass  * Look up a device's node property and return a pointer to its contents as a
443f11c7ab9SSimon Glass  * byte array of given length. The property must have at least enough data
444f11c7ab9SSimon Glass  * for the array (count bytes). It may have more, but this will be ignored.
445f11c7ab9SSimon Glass  * The data is not copied.
446f11c7ab9SSimon Glass  *
447f11c7ab9SSimon Glass  * @dev: device to look up
448f11c7ab9SSimon Glass  * @propname: name of property to find
449f11c7ab9SSimon Glass  * @sz: number of array elements
450f11c7ab9SSimon Glass  * @return pointer to byte array if found, or NULL if the property is not
451f11c7ab9SSimon Glass  *		found or there is not enough data
452f11c7ab9SSimon Glass  */
45347a0fd3bSSimon Glass const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
45447a0fd3bSSimon Glass 				     size_t sz);
45547a0fd3bSSimon Glass 
456f7d6fcf7SSimon Glass /**
457f7d6fcf7SSimon Glass  * dev_read_enabled() - check whether a node is enabled
458f7d6fcf7SSimon Glass  *
459f7d6fcf7SSimon Glass  * This looks for a 'status' property. If this exists, then returns 1 if
460f7d6fcf7SSimon Glass  * the status is 'ok' and 0 otherwise. If there is no status property,
461f7d6fcf7SSimon Glass  * it returns 1 on the assumption that anything mentioned should be enabled
462f7d6fcf7SSimon Glass  * by default.
463f7d6fcf7SSimon Glass  *
464f7d6fcf7SSimon Glass  * @dev: device to examine
465f7d6fcf7SSimon Glass  * @return integer value 0 (not enabled) or 1 (enabled)
466f7d6fcf7SSimon Glass  */
467f7d6fcf7SSimon Glass int dev_read_enabled(struct udevice *dev);
468f7d6fcf7SSimon Glass 
469dcf98852SSimon Glass /**
470dcf98852SSimon Glass  * dev_read_resource() - obtain an indexed resource from a device.
471dcf98852SSimon Glass  *
4727b8b47bdSMasahiro Yamada  * @dev: device to examine
473dcf98852SSimon Glass  * @index index of the resource to retrieve (0 = first)
474dcf98852SSimon Glass  * @res returns the resource
475dcf98852SSimon Glass  * @return 0 if ok, negative on error
476dcf98852SSimon Glass  */
477dcf98852SSimon Glass int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
478dcf98852SSimon Glass 
4797b8b47bdSMasahiro Yamada /**
4807b8b47bdSMasahiro Yamada  * dev_read_resource_byname() - obtain a named resource from a device.
4817b8b47bdSMasahiro Yamada  *
4827b8b47bdSMasahiro Yamada  * @dev: device to examine
4837b8b47bdSMasahiro Yamada  * @name: name of the resource to retrieve
4847b8b47bdSMasahiro Yamada  * @res: returns the resource
4857b8b47bdSMasahiro Yamada  * @return 0 if ok, negative on error
4867b8b47bdSMasahiro Yamada  */
4877b8b47bdSMasahiro Yamada int dev_read_resource_byname(struct udevice *dev, const char *name,
4887b8b47bdSMasahiro Yamada 			     struct resource *res);
4897b8b47bdSMasahiro Yamada 
490a9bd1c73SMario Six /**
491a9bd1c73SMario Six  * dev_translate_address() - Tranlate a device-tree address
492a9bd1c73SMario Six  *
493a9bd1c73SMario Six  * Translate an address from the device-tree into a CPU physical address.  This
494a9bd1c73SMario Six  * function walks up the tree and applies the various bus mappings along the
495a9bd1c73SMario Six  * way.
496a9bd1c73SMario Six  *
497a9bd1c73SMario Six  * @dev: device giving the context in which to translate the address
498a9bd1c73SMario Six  * @in_addr: pointer to the address to translate
499a9bd1c73SMario Six  * @return the translated address; OF_BAD_ADDR on error
500a9bd1c73SMario Six  */
501a9bd1c73SMario Six u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
50247a0fd3bSSimon Glass #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
50347a0fd3bSSimon Glass 
dev_read_u32_default(struct udevice * dev,const char * propname,int def)50447a0fd3bSSimon Glass static inline int dev_read_u32_default(struct udevice *dev,
50547a0fd3bSSimon Glass 				       const char *propname, int def)
50647a0fd3bSSimon Glass {
50747a0fd3bSSimon Glass 	return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
50847a0fd3bSSimon Glass }
50947a0fd3bSSimon Glass 
dev_read_string(struct udevice * dev,const char * propname)51047a0fd3bSSimon Glass static inline const char *dev_read_string(struct udevice *dev,
51147a0fd3bSSimon Glass 					  const char *propname)
51247a0fd3bSSimon Glass {
51347a0fd3bSSimon Glass 	return ofnode_read_string(dev_ofnode(dev), propname);
51447a0fd3bSSimon Glass }
51547a0fd3bSSimon Glass 
dev_read_bool(struct udevice * dev,const char * propname)51647a0fd3bSSimon Glass static inline bool dev_read_bool(struct udevice *dev, const char *propname)
51747a0fd3bSSimon Glass {
51847a0fd3bSSimon Glass 	return ofnode_read_bool(dev_ofnode(dev), propname);
51947a0fd3bSSimon Glass }
52047a0fd3bSSimon Glass 
dev_read_subnode(struct udevice * dev,const char * subbnode_name)52147a0fd3bSSimon Glass static inline ofnode dev_read_subnode(struct udevice *dev,
52247a0fd3bSSimon Glass 				      const char *subbnode_name)
52347a0fd3bSSimon Glass {
52447a0fd3bSSimon Glass 	return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
52547a0fd3bSSimon Glass }
52647a0fd3bSSimon Glass 
dev_read_size(struct udevice * dev,const char * propname)52747a0fd3bSSimon Glass static inline int dev_read_size(struct udevice *dev, const char *propname)
52847a0fd3bSSimon Glass {
52947a0fd3bSSimon Glass 	return ofnode_read_size(dev_ofnode(dev), propname);
53047a0fd3bSSimon Glass }
53147a0fd3bSSimon Glass 
dev_read_addr_index(struct udevice * dev,int index)53247a0fd3bSSimon Glass static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
53347a0fd3bSSimon Glass {
53447a0fd3bSSimon Glass 	return devfdt_get_addr_index(dev, index);
53547a0fd3bSSimon Glass }
53647a0fd3bSSimon Glass 
dev_read_addr(struct udevice * dev)53747a0fd3bSSimon Glass static inline fdt_addr_t dev_read_addr(struct udevice *dev)
53847a0fd3bSSimon Glass {
53947a0fd3bSSimon Glass 	return devfdt_get_addr(dev);
54047a0fd3bSSimon Glass }
54147a0fd3bSSimon Glass 
dev_read_addr_ptr(struct udevice * dev)54218a0c4a6SPhilipp Tomsich static inline void *dev_read_addr_ptr(struct udevice *dev)
54318a0c4a6SPhilipp Tomsich {
54418a0c4a6SPhilipp Tomsich 	return devfdt_get_addr_ptr(dev);
54518a0c4a6SPhilipp Tomsich }
54618a0c4a6SPhilipp Tomsich 
dev_read_addr_size(struct udevice * dev,const char * propname,fdt_size_t * sizep)54747a0fd3bSSimon Glass static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
54847a0fd3bSSimon Glass 					    const char *propname,
54947a0fd3bSSimon Glass 					    fdt_size_t *sizep)
55047a0fd3bSSimon Glass {
55147a0fd3bSSimon Glass 	return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
55247a0fd3bSSimon Glass }
55347a0fd3bSSimon Glass 
dev_read_name(struct udevice * dev)55447a0fd3bSSimon Glass static inline const char *dev_read_name(struct udevice *dev)
55547a0fd3bSSimon Glass {
556b283d2aeSKever Yang 	if (!dev_of_valid(dev))
557b283d2aeSKever Yang 		return NULL;
55847a0fd3bSSimon Glass 	return ofnode_get_name(dev_ofnode(dev));
55947a0fd3bSSimon Glass }
56047a0fd3bSSimon Glass 
dev_read_stringlist_search(struct udevice * dev,const char * propname,const char * string)56147a0fd3bSSimon Glass static inline int dev_read_stringlist_search(struct udevice *dev,
56247a0fd3bSSimon Glass 					     const char *propname,
56347a0fd3bSSimon Glass 					     const char *string)
56447a0fd3bSSimon Glass {
56547a0fd3bSSimon Glass 	return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
56647a0fd3bSSimon Glass }
56747a0fd3bSSimon Glass 
dev_read_string_index(struct udevice * dev,const char * propname,int index,const char ** outp)56857a9c706SJean-Jacques Hiblot static inline int dev_read_string_index(struct udevice *dev,
56957a9c706SJean-Jacques Hiblot 					const char *propname, int index,
57057a9c706SJean-Jacques Hiblot 					const char **outp)
57157a9c706SJean-Jacques Hiblot {
57257a9c706SJean-Jacques Hiblot 	return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
57357a9c706SJean-Jacques Hiblot }
57457a9c706SJean-Jacques Hiblot 
dev_read_string_count(struct udevice * dev,const char * propname)57557a9c706SJean-Jacques Hiblot static inline int dev_read_string_count(struct udevice *dev,
57657a9c706SJean-Jacques Hiblot 					const char *propname)
57757a9c706SJean-Jacques Hiblot {
57857a9c706SJean-Jacques Hiblot 	return ofnode_read_string_count(dev_ofnode(dev), propname);
57957a9c706SJean-Jacques Hiblot }
58057a9c706SJean-Jacques Hiblot 
dev_read_phandle_with_args(struct udevice * dev,const char * list_name,const char * cells_name,int cell_count,int index,struct ofnode_phandle_args * out_args)58147a0fd3bSSimon Glass static inline int dev_read_phandle_with_args(struct udevice *dev,
58247a0fd3bSSimon Glass 		const char *list_name, const char *cells_name, int cell_count,
58347a0fd3bSSimon Glass 		int index, struct ofnode_phandle_args *out_args)
58447a0fd3bSSimon Glass {
58547a0fd3bSSimon Glass 	return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
58647a0fd3bSSimon Glass 					      cells_name, cell_count, index,
58747a0fd3bSSimon Glass 					      out_args);
58847a0fd3bSSimon Glass }
58947a0fd3bSSimon Glass 
dev_count_phandle_with_args(struct udevice * dev,const char * list_name,const char * cells_name)590642346aeSPatrice Chotard static inline int dev_count_phandle_with_args(struct udevice *dev,
591642346aeSPatrice Chotard 		const char *list_name, const char *cells_name)
592642346aeSPatrice Chotard {
593642346aeSPatrice Chotard 	return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
594642346aeSPatrice Chotard 					      cells_name);
595642346aeSPatrice Chotard }
596642346aeSPatrice Chotard 
dev_read_addr_cells(struct udevice * dev)59747a0fd3bSSimon Glass static inline int dev_read_addr_cells(struct udevice *dev)
59847a0fd3bSSimon Glass {
599878d68c0SSimon Glass 	/* NOTE: this call should walk up the parent stack */
60047a0fd3bSSimon Glass 	return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
60147a0fd3bSSimon Glass }
60247a0fd3bSSimon Glass 
dev_remap_addr_index(struct udevice * dev,int index)603*8f7de514SShawn Lin static inline void *dev_remap_addr_index(struct udevice *dev, int index)
604*8f7de514SShawn Lin {
605*8f7de514SShawn Lin 	return devfdt_remap_addr_index(dev, index);
606*8f7de514SShawn Lin }
607*8f7de514SShawn Lin 
dev_read_size_cells(struct udevice * dev)60847a0fd3bSSimon Glass static inline int dev_read_size_cells(struct udevice *dev)
60947a0fd3bSSimon Glass {
610878d68c0SSimon Glass 	/* NOTE: this call should walk up the parent stack */
611878d68c0SSimon Glass 	return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
612878d68c0SSimon Glass }
613878d68c0SSimon Glass 
dev_read_simple_addr_cells(struct udevice * dev)614878d68c0SSimon Glass static inline int dev_read_simple_addr_cells(struct udevice *dev)
615878d68c0SSimon Glass {
616878d68c0SSimon Glass 	return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
617878d68c0SSimon Glass }
618878d68c0SSimon Glass 
dev_read_simple_size_cells(struct udevice * dev)619878d68c0SSimon Glass static inline int dev_read_simple_size_cells(struct udevice *dev)
620878d68c0SSimon Glass {
62147a0fd3bSSimon Glass 	return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
62247a0fd3bSSimon Glass }
62347a0fd3bSSimon Glass 
dev_read_phandle(struct udevice * dev)62447a0fd3bSSimon Glass static inline int dev_read_phandle(struct udevice *dev)
62547a0fd3bSSimon Glass {
62647a0fd3bSSimon Glass 	return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
62747a0fd3bSSimon Glass }
62847a0fd3bSSimon Glass 
dev_read_prop(struct udevice * dev,const char * propname,int * lenp)629fd73621cSMasahiro Yamada static inline const void *dev_read_prop(struct udevice *dev,
63047a0fd3bSSimon Glass 					const char *propname, int *lenp)
63147a0fd3bSSimon Glass {
63261e51babSMasahiro Yamada 	return ofnode_get_property(dev_ofnode(dev), propname, lenp);
63347a0fd3bSSimon Glass }
63447a0fd3bSSimon Glass 
dev_read_first_prop(struct udevice * dev,struct ofprop * prop)6353cf48410SPatrick Delaunay static inline int dev_read_first_prop(struct udevice *dev, struct ofprop *prop)
6363cf48410SPatrick Delaunay {
6373cf48410SPatrick Delaunay 	return ofnode_get_first_property(dev_ofnode(dev), prop);
6383cf48410SPatrick Delaunay }
6393cf48410SPatrick Delaunay 
dev_read_next_prop(struct ofprop * prop)6403cf48410SPatrick Delaunay static inline int dev_read_next_prop(struct ofprop *prop)
6413cf48410SPatrick Delaunay {
6423cf48410SPatrick Delaunay 	return ofnode_get_next_property(prop);
6433cf48410SPatrick Delaunay }
6443cf48410SPatrick Delaunay 
dev_read_prop_by_prop(struct ofprop * prop,const char ** propname,int * lenp)6453cf48410SPatrick Delaunay static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
6463cf48410SPatrick Delaunay 						const char **propname,
6473cf48410SPatrick Delaunay 						int *lenp)
6483cf48410SPatrick Delaunay {
6493cf48410SPatrick Delaunay 	return ofnode_get_property_by_prop(prop, propname, lenp);
6503cf48410SPatrick Delaunay }
6513cf48410SPatrick Delaunay 
dev_read_alias_seq(struct udevice * dev,int * devnump)65247a0fd3bSSimon Glass static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
65347a0fd3bSSimon Glass {
65447a0fd3bSSimon Glass 	return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
65547a0fd3bSSimon Glass 				    dev_of_offset(dev), devnump);
65647a0fd3bSSimon Glass }
65747a0fd3bSSimon Glass 
dev_read_u32_array(struct udevice * dev,const char * propname,u32 * out_values,size_t sz)65847a0fd3bSSimon Glass static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
65947a0fd3bSSimon Glass 				     u32 *out_values, size_t sz)
66047a0fd3bSSimon Glass {
661b283d2aeSKever Yang 	if (!dev_of_valid(dev))
662b283d2aeSKever Yang 		return -EINVAL;
66347a0fd3bSSimon Glass 	return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
66447a0fd3bSSimon Glass }
66547a0fd3bSSimon Glass 
dev_read_first_subnode(struct udevice * dev)66647a0fd3bSSimon Glass static inline ofnode dev_read_first_subnode(struct udevice *dev)
66747a0fd3bSSimon Glass {
66847a0fd3bSSimon Glass 	return ofnode_first_subnode(dev_ofnode(dev));
66947a0fd3bSSimon Glass }
67047a0fd3bSSimon Glass 
dev_read_next_subnode(ofnode node)67147a0fd3bSSimon Glass static inline ofnode dev_read_next_subnode(ofnode node)
67247a0fd3bSSimon Glass {
67347a0fd3bSSimon Glass 	return ofnode_next_subnode(node);
67447a0fd3bSSimon Glass }
67547a0fd3bSSimon Glass 
dev_read_u8_array_ptr(struct udevice * dev,const char * propname,size_t sz)676f11c7ab9SSimon Glass static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
677f11c7ab9SSimon Glass 					const char *propname, size_t sz)
678f11c7ab9SSimon Glass {
679f11c7ab9SSimon Glass 	return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
680f11c7ab9SSimon Glass }
681f11c7ab9SSimon Glass 
dev_read_enabled(struct udevice * dev)682f7d6fcf7SSimon Glass static inline int dev_read_enabled(struct udevice *dev)
683f7d6fcf7SSimon Glass {
684f7d6fcf7SSimon Glass 	return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
685f7d6fcf7SSimon Glass }
686f7d6fcf7SSimon Glass 
dev_read_resource(struct udevice * dev,uint index,struct resource * res)687dcf98852SSimon Glass static inline int dev_read_resource(struct udevice *dev, uint index,
688dcf98852SSimon Glass 				    struct resource *res)
689dcf98852SSimon Glass {
690dcf98852SSimon Glass 	return ofnode_read_resource(dev_ofnode(dev), index, res);
691dcf98852SSimon Glass }
692dcf98852SSimon Glass 
dev_read_resource_byname(struct udevice * dev,const char * name,struct resource * res)6937b8b47bdSMasahiro Yamada static inline int dev_read_resource_byname(struct udevice *dev,
6947b8b47bdSMasahiro Yamada 					   const char *name,
6957b8b47bdSMasahiro Yamada 					   struct resource *res)
6967b8b47bdSMasahiro Yamada {
6977b8b47bdSMasahiro Yamada 	return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
6987b8b47bdSMasahiro Yamada }
6997b8b47bdSMasahiro Yamada 
dev_translate_address(struct udevice * dev,const fdt32_t * in_addr)700a9bd1c73SMario Six static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
701a9bd1c73SMario Six {
702a9bd1c73SMario Six 	return ofnode_translate_address(dev_ofnode(dev), in_addr);
703a9bd1c73SMario Six }
704a9bd1c73SMario Six 
705f11c7ab9SSimon Glass #endif /* CONFIG_DM_DEV_READ_INLINE */
706f11c7ab9SSimon Glass 
707f11c7ab9SSimon Glass /**
708f11c7ab9SSimon Glass  * dev_for_each_subnode() - Helper function to iterate through subnodes
709f11c7ab9SSimon Glass  *
710f11c7ab9SSimon Glass  * This creates a for() loop which works through the subnodes in a device's
711f11c7ab9SSimon Glass  * device-tree node.
712f11c7ab9SSimon Glass  *
713f11c7ab9SSimon Glass  * @subnode: ofnode holding the current subnode
714f11c7ab9SSimon Glass  * @dev: device to use for interation (struct udevice *)
715f11c7ab9SSimon Glass  */
716f11c7ab9SSimon Glass #define dev_for_each_subnode(subnode, dev) \
717f11c7ab9SSimon Glass 	for (subnode = dev_read_first_subnode(dev); \
718f11c7ab9SSimon Glass 	     ofnode_valid(subnode); \
719f11c7ab9SSimon Glass 	     subnode = ofnode_next_subnode(subnode))
720f11c7ab9SSimon Glass 
7213cf48410SPatrick Delaunay /**
7223cf48410SPatrick Delaunay  * dev_for_each_property() - Helper function to iterate through property
7233cf48410SPatrick Delaunay  *
7243cf48410SPatrick Delaunay  * This creates a for() loop which works through the property in a device's
7253cf48410SPatrick Delaunay  * device-tree node.
7263cf48410SPatrick Delaunay  *
7273cf48410SPatrick Delaunay  * @prop: struct ofprop holding the current property
7283cf48410SPatrick Delaunay  * @dev: device to use for interation (struct udevice *)
7293cf48410SPatrick Delaunay  */
7303cf48410SPatrick Delaunay #define dev_for_each_property(prop, dev) \
7313cf48410SPatrick Delaunay 	for (int ret_prop = dev_read_first_prop(dev, &prop); \
7323cf48410SPatrick Delaunay 	     !ret_prop; \
7333cf48410SPatrick Delaunay 	     ret_prop = dev_read_next_prop(&prop))
7343cf48410SPatrick Delaunay 
735f11c7ab9SSimon Glass #endif
736