xref: /OK3568_Linux_fs/u-boot/include/dm/read.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Function to read values from the device tree node attached to a udevice.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (c) 2017 Google, Inc
5*4882a593Smuzhiyun  * Written by Simon Glass <sjg@chromium.org>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef _DM_READ_H
11*4882a593Smuzhiyun #define _DM_READ_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <dm/fdtaddr.h>
14*4882a593Smuzhiyun #include <dm/ofnode.h>
15*4882a593Smuzhiyun #include <dm/uclass.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun struct resource;
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(OF_LIVE)
dev_np(struct udevice * dev)20*4882a593Smuzhiyun static inline const struct device_node *dev_np(struct udevice *dev)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	return ofnode_to_np(dev->node);
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun #else
dev_np(struct udevice * dev)25*4882a593Smuzhiyun static inline const struct device_node *dev_np(struct udevice *dev)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun 	return NULL;
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /**
32*4882a593Smuzhiyun  * dev_ofnode() - get the DT node reference associated with a udevice
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  * @dev:	device to check
35*4882a593Smuzhiyun  * @return reference of the the device's DT node
36*4882a593Smuzhiyun  */
dev_ofnode(struct udevice * dev)37*4882a593Smuzhiyun static inline ofnode dev_ofnode(struct udevice *dev)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun 	return dev->node;
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun 
dev_of_valid(struct udevice * dev)42*4882a593Smuzhiyun static inline bool dev_of_valid(struct udevice *dev)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 	return ofnode_valid(dev_ofnode(dev));
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #ifndef CONFIG_DM_DEV_READ_INLINE
48*4882a593Smuzhiyun /**
49*4882a593Smuzhiyun  * dev_read_u32_default() - read a 32-bit integer from a device's DT property
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * @dev:	device to read DT property from
52*4882a593Smuzhiyun  * @propname:	name of the property to read from
53*4882a593Smuzhiyun  * @def:	default value to return if the property has no value
54*4882a593Smuzhiyun  * @return property value, or @def if not found
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /**
59*4882a593Smuzhiyun  * dev_read_s32_default() - read a signed 32-bit integer from a device's DT property
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * @dev:	device to read DT property from
62*4882a593Smuzhiyun  * @propname:	name of the property to read from
63*4882a593Smuzhiyun  * @def:	default value to return if the property has no value
64*4882a593Smuzhiyun  * @return property value, or @def if not found
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun int dev_read_s32_default(struct udevice *dev, const char *propname, int def);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /**
69*4882a593Smuzhiyun  * dev_read_string() - Read a string from a device's DT property
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * @dev:	device to read DT property from
72*4882a593Smuzhiyun  * @propname:	name of the property to read
73*4882a593Smuzhiyun  * @return string from property value, or NULL if there is no such property
74*4882a593Smuzhiyun  */
75*4882a593Smuzhiyun const char *dev_read_string(struct udevice *dev, const char *propname);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /**
78*4882a593Smuzhiyun  * dev_read_bool() - read a boolean value from a device's DT property
79*4882a593Smuzhiyun  *
80*4882a593Smuzhiyun  * @dev:	device to read DT property from
81*4882a593Smuzhiyun  * @propname:	name of property to read
82*4882a593Smuzhiyun  * @return true if property is present (meaning true), false if not present
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun bool dev_read_bool(struct udevice *dev, const char *propname);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /**
87*4882a593Smuzhiyun  * dev_read_subnode() - find a named subnode of a device
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * @dev:	device whose DT node contains the subnode
90*4882a593Smuzhiyun  * @subnode_name: name of subnode to find
91*4882a593Smuzhiyun  * @return reference to subnode (which can be invalid if there is no such
92*4882a593Smuzhiyun  * subnode)
93*4882a593Smuzhiyun  */
94*4882a593Smuzhiyun ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /**
97*4882a593Smuzhiyun  * dev_read_size() - read the size of a property
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  * @dev: device to check
100*4882a593Smuzhiyun  * @propname: property to check
101*4882a593Smuzhiyun  * @return size of property if present, or -EINVAL if not
102*4882a593Smuzhiyun  */
103*4882a593Smuzhiyun int dev_read_size(struct udevice *dev, const char *propname);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun  * dev_read_addr_index() - Get the indexed reg property of a device
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @dev: Device to read from
109*4882a593Smuzhiyun  * @index: the 'reg' property can hold a list of <addr, size> pairs
110*4882a593Smuzhiyun  *	   and @index is used to select which one is required
111*4882a593Smuzhiyun  *
112*4882a593Smuzhiyun  * @return address or FDT_ADDR_T_NONE if not found
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun  * dev_read_addr() - Get the reg property of a device
118*4882a593Smuzhiyun  *
119*4882a593Smuzhiyun  * @dev: Device to read from
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * @return address or FDT_ADDR_T_NONE if not found
122*4882a593Smuzhiyun  */
123*4882a593Smuzhiyun fdt_addr_t dev_read_addr(struct udevice *dev);
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun  * dev_read_addr_ptr() - Get the reg property of a device
127*4882a593Smuzhiyun  *                       as a pointer
128*4882a593Smuzhiyun  *
129*4882a593Smuzhiyun  * @dev: Device to read from
130*4882a593Smuzhiyun  *
131*4882a593Smuzhiyun  * @return pointer or NULL if not found
132*4882a593Smuzhiyun  */
133*4882a593Smuzhiyun void *dev_read_addr_ptr(struct udevice *dev);
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /**
136*4882a593Smuzhiyun  * dev_read_addr_size() - get address and size from a device property
137*4882a593Smuzhiyun  *
138*4882a593Smuzhiyun  * This does no address translation. It simply reads an property that contains
139*4882a593Smuzhiyun  * an address and a size value, one after the other.
140*4882a593Smuzhiyun  *
141*4882a593Smuzhiyun  * @dev: Device to read from
142*4882a593Smuzhiyun  * @propname: property to read
143*4882a593Smuzhiyun  * @sizep: place to put size value (on success)
144*4882a593Smuzhiyun  * @return address value, or FDT_ADDR_T_NONE on error
145*4882a593Smuzhiyun  */
146*4882a593Smuzhiyun fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
147*4882a593Smuzhiyun 				fdt_size_t *sizep);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /**
150*4882a593Smuzhiyun  * dev_read_name() - get the name of a device's node
151*4882a593Smuzhiyun  *
152*4882a593Smuzhiyun  * @node: valid node to look up
153*4882a593Smuzhiyun  * @return name of node
154*4882a593Smuzhiyun  */
155*4882a593Smuzhiyun const char *dev_read_name(struct udevice *dev);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /**
158*4882a593Smuzhiyun  * dev_read_stringlist_search() - find string in a string list and return index
159*4882a593Smuzhiyun  *
160*4882a593Smuzhiyun  * Note that it is possible for this function to succeed on property values
161*4882a593Smuzhiyun  * that are not NUL-terminated. That's because the function will stop after
162*4882a593Smuzhiyun  * finding the first occurrence of @string. This can for example happen with
163*4882a593Smuzhiyun  * small-valued cell properties, such as #address-cells, when searching for
164*4882a593Smuzhiyun  * the empty string.
165*4882a593Smuzhiyun  *
166*4882a593Smuzhiyun  * @dev: device to check
167*4882a593Smuzhiyun  * @propname: name of the property containing the string list
168*4882a593Smuzhiyun  * @string: string to look up in the string list
169*4882a593Smuzhiyun  *
170*4882a593Smuzhiyun  * @return:
171*4882a593Smuzhiyun  *   the index of the string in the list of strings
172*4882a593Smuzhiyun  *   -ENODATA if the property is not found
173*4882a593Smuzhiyun  *   -EINVAL on some other error
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun int dev_read_stringlist_search(struct udevice *dev, const char *property,
176*4882a593Smuzhiyun 			  const char *string);
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun  * dev_read_string_index() - obtain an indexed string from a string list
180*4882a593Smuzhiyun  *
181*4882a593Smuzhiyun  * @dev: device to examine
182*4882a593Smuzhiyun  * @propname: name of the property containing the string list
183*4882a593Smuzhiyun  * @index: index of the string to return
184*4882a593Smuzhiyun  * @out: return location for the string
185*4882a593Smuzhiyun  *
186*4882a593Smuzhiyun  * @return:
187*4882a593Smuzhiyun  *   length of string, if found or -ve error value if not found
188*4882a593Smuzhiyun  */
189*4882a593Smuzhiyun int dev_read_string_index(struct udevice *dev, const char *propname, int index,
190*4882a593Smuzhiyun 			  const char **outp);
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /**
193*4882a593Smuzhiyun  * dev_read_string_count() - find the number of strings in a string list
194*4882a593Smuzhiyun  *
195*4882a593Smuzhiyun  * @dev: device to examine
196*4882a593Smuzhiyun  * @propname: name of the property containing the string list
197*4882a593Smuzhiyun  * @return:
198*4882a593Smuzhiyun  *   number of strings in the list, or -ve error value if not found
199*4882a593Smuzhiyun  */
200*4882a593Smuzhiyun int dev_read_string_count(struct udevice *dev, const char *propname);
201*4882a593Smuzhiyun /**
202*4882a593Smuzhiyun  * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * This function is useful to parse lists of phandles and their arguments.
205*4882a593Smuzhiyun  * Returns 0 on success and fills out_args, on error returns appropriate
206*4882a593Smuzhiyun  * errno value.
207*4882a593Smuzhiyun  *
208*4882a593Smuzhiyun  * Caller is responsible to call of_node_put() on the returned out_args->np
209*4882a593Smuzhiyun  * pointer.
210*4882a593Smuzhiyun  *
211*4882a593Smuzhiyun  * Example:
212*4882a593Smuzhiyun  *
213*4882a593Smuzhiyun  * phandle1: node1 {
214*4882a593Smuzhiyun  *	#list-cells = <2>;
215*4882a593Smuzhiyun  * }
216*4882a593Smuzhiyun  *
217*4882a593Smuzhiyun  * phandle2: node2 {
218*4882a593Smuzhiyun  *	#list-cells = <1>;
219*4882a593Smuzhiyun  * }
220*4882a593Smuzhiyun  *
221*4882a593Smuzhiyun  * node3 {
222*4882a593Smuzhiyun  *	list = <&phandle1 1 2 &phandle2 3>;
223*4882a593Smuzhiyun  * }
224*4882a593Smuzhiyun  *
225*4882a593Smuzhiyun  * To get a device_node of the `node2' node you may call this:
226*4882a593Smuzhiyun  * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
227*4882a593Smuzhiyun  *
228*4882a593Smuzhiyun  * @dev:	device whose node containing a list
229*4882a593Smuzhiyun  * @list_name:	property name that contains a list
230*4882a593Smuzhiyun  * @cells_name:	property name that specifies phandles' arguments count
231*4882a593Smuzhiyun  * @cells_count: Cell count to use if @cells_name is NULL
232*4882a593Smuzhiyun  * @index:	index of a phandle to parse out
233*4882a593Smuzhiyun  * @out_args:	optional pointer to output arguments structure (will be filled)
234*4882a593Smuzhiyun  * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
235*4882a593Smuzhiyun  *	@list_name does not exist, -EINVAL if a phandle was not found,
236*4882a593Smuzhiyun  *	@cells_name could not be found, the arguments were truncated or there
237*4882a593Smuzhiyun  *	were too many arguments.
238*4882a593Smuzhiyun  */
239*4882a593Smuzhiyun int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
240*4882a593Smuzhiyun 				const char *cells_name, int cell_count,
241*4882a593Smuzhiyun 				int index,
242*4882a593Smuzhiyun 				struct ofnode_phandle_args *out_args);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun /**
245*4882a593Smuzhiyun  * dev_count_phandle_with_args() - Return phandle number in a list
246*4882a593Smuzhiyun  *
247*4882a593Smuzhiyun  * This function is usefull to get phandle number contained in a property list.
248*4882a593Smuzhiyun  * For example, this allows to allocate the right amount of memory to keep
249*4882a593Smuzhiyun  * clock's reference contained into the "clocks" property.
250*4882a593Smuzhiyun  *
251*4882a593Smuzhiyun  *
252*4882a593Smuzhiyun  * @dev:	device whose node containing a list
253*4882a593Smuzhiyun  * @list_name:	property name that contains a list
254*4882a593Smuzhiyun  * @cells_name:	property name that specifies phandles' arguments count
255*4882a593Smuzhiyun  * @Returns number of phandle found on success, on error returns appropriate
256*4882a593Smuzhiyun  * errno value.
257*4882a593Smuzhiyun  */
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
260*4882a593Smuzhiyun 				const char *cells_name);
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun /**
263*4882a593Smuzhiyun  * dev_read_addr_cells() - Get the number of address cells for a device's node
264*4882a593Smuzhiyun  *
265*4882a593Smuzhiyun  * This walks back up the tree to find the closest #address-cells property
266*4882a593Smuzhiyun  * which controls the given node.
267*4882a593Smuzhiyun  *
268*4882a593Smuzhiyun  * @dev: devioe to check
269*4882a593Smuzhiyun  * @return number of address cells this node uses
270*4882a593Smuzhiyun  */
271*4882a593Smuzhiyun int dev_read_addr_cells(struct udevice *dev);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun /**
274*4882a593Smuzhiyun  * dev_remap_addr_index() - Get the indexed reg property of a device
275*4882a593Smuzhiyun  *                               as a memory-mapped I/O pointer
276*4882a593Smuzhiyun  *
277*4882a593Smuzhiyun  * @dev: Device to read from
278*4882a593Smuzhiyun  * @index: the 'reg' property can hold a list of <addr, size> pairs
279*4882a593Smuzhiyun  *         and @index is used to select which one is required
280*4882a593Smuzhiyun  *
281*4882a593Smuzhiyun  * Return: pointer or NULL if not found
282*4882a593Smuzhiyun  */
283*4882a593Smuzhiyun void *dev_remap_addr_index(struct udevice *dev, int index);
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun /**
286*4882a593Smuzhiyun  * dev_read_size_cells() - Get the number of size cells for a device's node
287*4882a593Smuzhiyun  *
288*4882a593Smuzhiyun  * This walks back up the tree to find the closest #size-cells property
289*4882a593Smuzhiyun  * which controls the given node.
290*4882a593Smuzhiyun  *
291*4882a593Smuzhiyun  * @dev: devioe to check
292*4882a593Smuzhiyun  * @return number of size cells this node uses
293*4882a593Smuzhiyun  */
294*4882a593Smuzhiyun int dev_read_size_cells(struct udevice *dev);
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun /**
297*4882a593Smuzhiyun  * dev_read_addr_cells() - Get the address cells property in a node
298*4882a593Smuzhiyun  *
299*4882a593Smuzhiyun  * This function matches fdt_address_cells().
300*4882a593Smuzhiyun  *
301*4882a593Smuzhiyun  * @dev: devioe to check
302*4882a593Smuzhiyun  * @return number of address cells this node uses
303*4882a593Smuzhiyun  */
304*4882a593Smuzhiyun int dev_read_simple_addr_cells(struct udevice *dev);
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun /**
307*4882a593Smuzhiyun  * dev_read_size_cells() - Get the size cells property in a node
308*4882a593Smuzhiyun  *
309*4882a593Smuzhiyun  * This function matches fdt_size_cells().
310*4882a593Smuzhiyun  *
311*4882a593Smuzhiyun  * @dev: devioe to check
312*4882a593Smuzhiyun  * @return number of size cells this node uses
313*4882a593Smuzhiyun  */
314*4882a593Smuzhiyun int dev_read_simple_size_cells(struct udevice *dev);
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /**
317*4882a593Smuzhiyun  * dev_read_phandle() - Get the phandle from a device
318*4882a593Smuzhiyun  *
319*4882a593Smuzhiyun  * @dev: device to check
320*4882a593Smuzhiyun  * @return phandle (1 or greater), or 0 if no phandle or other error
321*4882a593Smuzhiyun  */
322*4882a593Smuzhiyun int dev_read_phandle(struct udevice *dev);
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun /**
325*4882a593Smuzhiyun  * dev_read_prop()- - read a property from a device's node
326*4882a593Smuzhiyun  *
327*4882a593Smuzhiyun  * @dev: device to check
328*4882a593Smuzhiyun  * @propname: property to read
329*4882a593Smuzhiyun  * @lenp: place to put length on success
330*4882a593Smuzhiyun  * @return pointer to property, or NULL if not found
331*4882a593Smuzhiyun  */
332*4882a593Smuzhiyun const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun /**
335*4882a593Smuzhiyun  * dev_read_first_prop()- get the reference of the first property
336*4882a593Smuzhiyun  *
337*4882a593Smuzhiyun  * Get reference to the first property of the node, it is used to iterate
338*4882a593Smuzhiyun  * and read all the property with dev_read_prop_by_prop().
339*4882a593Smuzhiyun  *
340*4882a593Smuzhiyun  * @dev: device to check
341*4882a593Smuzhiyun  * @prop: place to put argument reference
342*4882a593Smuzhiyun  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
343*4882a593Smuzhiyun  */
344*4882a593Smuzhiyun int dev_read_first_prop(struct udevice *dev, struct ofprop *prop);
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /**
347*4882a593Smuzhiyun  * ofnode_get_next_property() - get the reference of the next property
348*4882a593Smuzhiyun  *
349*4882a593Smuzhiyun  * Get reference to the next property of the node, it is used to iterate
350*4882a593Smuzhiyun  * and read all the property with dev_read_prop_by_prop().
351*4882a593Smuzhiyun  *
352*4882a593Smuzhiyun  * @prop: reference of current argument and place to put reference of next one
353*4882a593Smuzhiyun  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
354*4882a593Smuzhiyun  */
355*4882a593Smuzhiyun int dev_read_next_prop(struct ofprop *prop);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /**
358*4882a593Smuzhiyun  * dev_read_prop_by_prop() - get a pointer to the value of a property
359*4882a593Smuzhiyun  *
360*4882a593Smuzhiyun  * Get value for the property identified by the provided reference.
361*4882a593Smuzhiyun  *
362*4882a593Smuzhiyun  * @prop: reference on property
363*4882a593Smuzhiyun  * @propname: If non-NULL, place to property name on success,
364*4882a593Smuzhiyun  * @lenp: If non-NULL, place to put length on success
365*4882a593Smuzhiyun  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
366*4882a593Smuzhiyun  */
367*4882a593Smuzhiyun const void *dev_read_prop_by_prop(struct ofprop *prop,
368*4882a593Smuzhiyun 				  const char **propname, int *lenp);
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun /**
371*4882a593Smuzhiyun  * dev_read_alias_seq() - Get the alias sequence number of a node
372*4882a593Smuzhiyun  *
373*4882a593Smuzhiyun  * This works out whether a node is pointed to by an alias, and if so, the
374*4882a593Smuzhiyun  * sequence number of that alias. Aliases are of the form <base><num> where
375*4882a593Smuzhiyun  * <num> is the sequence number. For example spi2 would be sequence number 2.
376*4882a593Smuzhiyun  *
377*4882a593Smuzhiyun  * @dev: device to look up
378*4882a593Smuzhiyun  * @devnump: set to the sequence number if one is found
379*4882a593Smuzhiyun  * @return 0 if a sequence was found, -ve if not
380*4882a593Smuzhiyun  */
381*4882a593Smuzhiyun int dev_read_alias_seq(struct udevice *dev, int *devnump);
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun /**
384*4882a593Smuzhiyun  * dev_read_u32_array() - Find and read an array of 32 bit integers
385*4882a593Smuzhiyun  *
386*4882a593Smuzhiyun  * Search for a property in a device node and read 32-bit value(s) from
387*4882a593Smuzhiyun  * it.
388*4882a593Smuzhiyun  *
389*4882a593Smuzhiyun  * The out_values is modified only if a valid u32 value can be decoded.
390*4882a593Smuzhiyun  *
391*4882a593Smuzhiyun  * @dev: device to look up
392*4882a593Smuzhiyun  * @propname:	name of the property to read
393*4882a593Smuzhiyun  * @out_values:	pointer to return value, modified only if return value is 0
394*4882a593Smuzhiyun  * @sz:		number of array elements to read
395*4882a593Smuzhiyun  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
396*4882a593Smuzhiyun  * property does not have a value, and -EOVERFLOW if the property data isn't
397*4882a593Smuzhiyun  * large enough.
398*4882a593Smuzhiyun  */
399*4882a593Smuzhiyun int dev_read_u32_array(struct udevice *dev, const char *propname,
400*4882a593Smuzhiyun 		       u32 *out_values, size_t sz);
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun /**
403*4882a593Smuzhiyun  * dev_write_u32_array() - Find and write an array of 32 bit integers
404*4882a593Smuzhiyun  *
405*4882a593Smuzhiyun  * Search for a property in a device node and write 32-bit value(s) to
406*4882a593Smuzhiyun  * it.
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * The out_values is modified only if a valid u32 value can be decoded.
409*4882a593Smuzhiyun  *
410*4882a593Smuzhiyun  * @dev: device to look up
411*4882a593Smuzhiyun  * @propname:	name of the property to read
412*4882a593Smuzhiyun  * @values:	pointer to update value, modified only if return value is 0
413*4882a593Smuzhiyun  * @sz:		number of array elements to read
414*4882a593Smuzhiyun  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
415*4882a593Smuzhiyun  * property does not have a value, and -EOVERFLOW if the property data isn't
416*4882a593Smuzhiyun  * large enough.
417*4882a593Smuzhiyun  */
418*4882a593Smuzhiyun int dev_write_u32_array(struct udevice *dev, const char *propname,
419*4882a593Smuzhiyun 			u32 *values, size_t sz);
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun /**
422*4882a593Smuzhiyun  * dev_read_first_subnode() - find the first subnode of a device's node
423*4882a593Smuzhiyun  *
424*4882a593Smuzhiyun  * @dev: device to look up
425*4882a593Smuzhiyun  * @return reference to the first subnode (which can be invalid if the device's
426*4882a593Smuzhiyun  * node has no subnodes)
427*4882a593Smuzhiyun  */
428*4882a593Smuzhiyun ofnode dev_read_first_subnode(struct udevice *dev);
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun /**
431*4882a593Smuzhiyun  * ofnode_next_subnode() - find the next sibling of a subnode
432*4882a593Smuzhiyun  *
433*4882a593Smuzhiyun  * @node:	valid reference to previous node (sibling)
434*4882a593Smuzhiyun  * @return reference to the next subnode (which can be invalid if the node
435*4882a593Smuzhiyun  * has no more siblings)
436*4882a593Smuzhiyun  */
437*4882a593Smuzhiyun ofnode dev_read_next_subnode(ofnode node);
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun /**
440*4882a593Smuzhiyun  * dev_read_u8_array_ptr() - find an 8-bit array
441*4882a593Smuzhiyun  *
442*4882a593Smuzhiyun  * Look up a device's node property and return a pointer to its contents as a
443*4882a593Smuzhiyun  * byte array of given length. The property must have at least enough data
444*4882a593Smuzhiyun  * for the array (count bytes). It may have more, but this will be ignored.
445*4882a593Smuzhiyun  * The data is not copied.
446*4882a593Smuzhiyun  *
447*4882a593Smuzhiyun  * @dev: device to look up
448*4882a593Smuzhiyun  * @propname: name of property to find
449*4882a593Smuzhiyun  * @sz: number of array elements
450*4882a593Smuzhiyun  * @return pointer to byte array if found, or NULL if the property is not
451*4882a593Smuzhiyun  *		found or there is not enough data
452*4882a593Smuzhiyun  */
453*4882a593Smuzhiyun const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
454*4882a593Smuzhiyun 				     size_t sz);
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun /**
457*4882a593Smuzhiyun  * dev_read_enabled() - check whether a node is enabled
458*4882a593Smuzhiyun  *
459*4882a593Smuzhiyun  * This looks for a 'status' property. If this exists, then returns 1 if
460*4882a593Smuzhiyun  * the status is 'ok' and 0 otherwise. If there is no status property,
461*4882a593Smuzhiyun  * it returns 1 on the assumption that anything mentioned should be enabled
462*4882a593Smuzhiyun  * by default.
463*4882a593Smuzhiyun  *
464*4882a593Smuzhiyun  * @dev: device to examine
465*4882a593Smuzhiyun  * @return integer value 0 (not enabled) or 1 (enabled)
466*4882a593Smuzhiyun  */
467*4882a593Smuzhiyun int dev_read_enabled(struct udevice *dev);
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun /**
470*4882a593Smuzhiyun  * dev_read_resource() - obtain an indexed resource from a device.
471*4882a593Smuzhiyun  *
472*4882a593Smuzhiyun  * @dev: device to examine
473*4882a593Smuzhiyun  * @index index of the resource to retrieve (0 = first)
474*4882a593Smuzhiyun  * @res returns the resource
475*4882a593Smuzhiyun  * @return 0 if ok, negative on error
476*4882a593Smuzhiyun  */
477*4882a593Smuzhiyun int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun /**
480*4882a593Smuzhiyun  * dev_read_resource_byname() - obtain a named resource from a device.
481*4882a593Smuzhiyun  *
482*4882a593Smuzhiyun  * @dev: device to examine
483*4882a593Smuzhiyun  * @name: name of the resource to retrieve
484*4882a593Smuzhiyun  * @res: returns the resource
485*4882a593Smuzhiyun  * @return 0 if ok, negative on error
486*4882a593Smuzhiyun  */
487*4882a593Smuzhiyun int dev_read_resource_byname(struct udevice *dev, const char *name,
488*4882a593Smuzhiyun 			     struct resource *res);
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun /**
491*4882a593Smuzhiyun  * dev_translate_address() - Tranlate a device-tree address
492*4882a593Smuzhiyun  *
493*4882a593Smuzhiyun  * Translate an address from the device-tree into a CPU physical address.  This
494*4882a593Smuzhiyun  * function walks up the tree and applies the various bus mappings along the
495*4882a593Smuzhiyun  * way.
496*4882a593Smuzhiyun  *
497*4882a593Smuzhiyun  * @dev: device giving the context in which to translate the address
498*4882a593Smuzhiyun  * @in_addr: pointer to the address to translate
499*4882a593Smuzhiyun  * @return the translated address; OF_BAD_ADDR on error
500*4882a593Smuzhiyun  */
501*4882a593Smuzhiyun u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
502*4882a593Smuzhiyun #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
503*4882a593Smuzhiyun 
dev_read_u32_default(struct udevice * dev,const char * propname,int def)504*4882a593Smuzhiyun static inline int dev_read_u32_default(struct udevice *dev,
505*4882a593Smuzhiyun 				       const char *propname, int def)
506*4882a593Smuzhiyun {
507*4882a593Smuzhiyun 	return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun 
dev_read_string(struct udevice * dev,const char * propname)510*4882a593Smuzhiyun static inline const char *dev_read_string(struct udevice *dev,
511*4882a593Smuzhiyun 					  const char *propname)
512*4882a593Smuzhiyun {
513*4882a593Smuzhiyun 	return ofnode_read_string(dev_ofnode(dev), propname);
514*4882a593Smuzhiyun }
515*4882a593Smuzhiyun 
dev_read_bool(struct udevice * dev,const char * propname)516*4882a593Smuzhiyun static inline bool dev_read_bool(struct udevice *dev, const char *propname)
517*4882a593Smuzhiyun {
518*4882a593Smuzhiyun 	return ofnode_read_bool(dev_ofnode(dev), propname);
519*4882a593Smuzhiyun }
520*4882a593Smuzhiyun 
dev_read_subnode(struct udevice * dev,const char * subbnode_name)521*4882a593Smuzhiyun static inline ofnode dev_read_subnode(struct udevice *dev,
522*4882a593Smuzhiyun 				      const char *subbnode_name)
523*4882a593Smuzhiyun {
524*4882a593Smuzhiyun 	return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun 
dev_read_size(struct udevice * dev,const char * propname)527*4882a593Smuzhiyun static inline int dev_read_size(struct udevice *dev, const char *propname)
528*4882a593Smuzhiyun {
529*4882a593Smuzhiyun 	return ofnode_read_size(dev_ofnode(dev), propname);
530*4882a593Smuzhiyun }
531*4882a593Smuzhiyun 
dev_read_addr_index(struct udevice * dev,int index)532*4882a593Smuzhiyun static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
533*4882a593Smuzhiyun {
534*4882a593Smuzhiyun 	return devfdt_get_addr_index(dev, index);
535*4882a593Smuzhiyun }
536*4882a593Smuzhiyun 
dev_read_addr(struct udevice * dev)537*4882a593Smuzhiyun static inline fdt_addr_t dev_read_addr(struct udevice *dev)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun 	return devfdt_get_addr(dev);
540*4882a593Smuzhiyun }
541*4882a593Smuzhiyun 
dev_read_addr_ptr(struct udevice * dev)542*4882a593Smuzhiyun static inline void *dev_read_addr_ptr(struct udevice *dev)
543*4882a593Smuzhiyun {
544*4882a593Smuzhiyun 	return devfdt_get_addr_ptr(dev);
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun 
dev_read_addr_size(struct udevice * dev,const char * propname,fdt_size_t * sizep)547*4882a593Smuzhiyun static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
548*4882a593Smuzhiyun 					    const char *propname,
549*4882a593Smuzhiyun 					    fdt_size_t *sizep)
550*4882a593Smuzhiyun {
551*4882a593Smuzhiyun 	return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
552*4882a593Smuzhiyun }
553*4882a593Smuzhiyun 
dev_read_name(struct udevice * dev)554*4882a593Smuzhiyun static inline const char *dev_read_name(struct udevice *dev)
555*4882a593Smuzhiyun {
556*4882a593Smuzhiyun 	if (!dev_of_valid(dev))
557*4882a593Smuzhiyun 		return NULL;
558*4882a593Smuzhiyun 	return ofnode_get_name(dev_ofnode(dev));
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun 
dev_read_stringlist_search(struct udevice * dev,const char * propname,const char * string)561*4882a593Smuzhiyun static inline int dev_read_stringlist_search(struct udevice *dev,
562*4882a593Smuzhiyun 					     const char *propname,
563*4882a593Smuzhiyun 					     const char *string)
564*4882a593Smuzhiyun {
565*4882a593Smuzhiyun 	return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
566*4882a593Smuzhiyun }
567*4882a593Smuzhiyun 
dev_read_string_index(struct udevice * dev,const char * propname,int index,const char ** outp)568*4882a593Smuzhiyun static inline int dev_read_string_index(struct udevice *dev,
569*4882a593Smuzhiyun 					const char *propname, int index,
570*4882a593Smuzhiyun 					const char **outp)
571*4882a593Smuzhiyun {
572*4882a593Smuzhiyun 	return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun 
dev_read_string_count(struct udevice * dev,const char * propname)575*4882a593Smuzhiyun static inline int dev_read_string_count(struct udevice *dev,
576*4882a593Smuzhiyun 					const char *propname)
577*4882a593Smuzhiyun {
578*4882a593Smuzhiyun 	return ofnode_read_string_count(dev_ofnode(dev), propname);
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun 
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)581*4882a593Smuzhiyun static inline int dev_read_phandle_with_args(struct udevice *dev,
582*4882a593Smuzhiyun 		const char *list_name, const char *cells_name, int cell_count,
583*4882a593Smuzhiyun 		int index, struct ofnode_phandle_args *out_args)
584*4882a593Smuzhiyun {
585*4882a593Smuzhiyun 	return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
586*4882a593Smuzhiyun 					      cells_name, cell_count, index,
587*4882a593Smuzhiyun 					      out_args);
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun 
dev_count_phandle_with_args(struct udevice * dev,const char * list_name,const char * cells_name)590*4882a593Smuzhiyun static inline int dev_count_phandle_with_args(struct udevice *dev,
591*4882a593Smuzhiyun 		const char *list_name, const char *cells_name)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun 	return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
594*4882a593Smuzhiyun 					      cells_name);
595*4882a593Smuzhiyun }
596*4882a593Smuzhiyun 
dev_read_addr_cells(struct udevice * dev)597*4882a593Smuzhiyun static inline int dev_read_addr_cells(struct udevice *dev)
598*4882a593Smuzhiyun {
599*4882a593Smuzhiyun 	/* NOTE: this call should walk up the parent stack */
600*4882a593Smuzhiyun 	return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
601*4882a593Smuzhiyun }
602*4882a593Smuzhiyun 
dev_remap_addr_index(struct udevice * dev,int index)603*4882a593Smuzhiyun static inline void *dev_remap_addr_index(struct udevice *dev, int index)
604*4882a593Smuzhiyun {
605*4882a593Smuzhiyun 	return devfdt_remap_addr_index(dev, index);
606*4882a593Smuzhiyun }
607*4882a593Smuzhiyun 
dev_read_size_cells(struct udevice * dev)608*4882a593Smuzhiyun static inline int dev_read_size_cells(struct udevice *dev)
609*4882a593Smuzhiyun {
610*4882a593Smuzhiyun 	/* NOTE: this call should walk up the parent stack */
611*4882a593Smuzhiyun 	return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun 
dev_read_simple_addr_cells(struct udevice * dev)614*4882a593Smuzhiyun static inline int dev_read_simple_addr_cells(struct udevice *dev)
615*4882a593Smuzhiyun {
616*4882a593Smuzhiyun 	return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun 
dev_read_simple_size_cells(struct udevice * dev)619*4882a593Smuzhiyun static inline int dev_read_simple_size_cells(struct udevice *dev)
620*4882a593Smuzhiyun {
621*4882a593Smuzhiyun 	return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
622*4882a593Smuzhiyun }
623*4882a593Smuzhiyun 
dev_read_phandle(struct udevice * dev)624*4882a593Smuzhiyun static inline int dev_read_phandle(struct udevice *dev)
625*4882a593Smuzhiyun {
626*4882a593Smuzhiyun 	return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun 
dev_read_prop(struct udevice * dev,const char * propname,int * lenp)629*4882a593Smuzhiyun static inline const void *dev_read_prop(struct udevice *dev,
630*4882a593Smuzhiyun 					const char *propname, int *lenp)
631*4882a593Smuzhiyun {
632*4882a593Smuzhiyun 	return ofnode_get_property(dev_ofnode(dev), propname, lenp);
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun 
dev_read_first_prop(struct udevice * dev,struct ofprop * prop)635*4882a593Smuzhiyun static inline int dev_read_first_prop(struct udevice *dev, struct ofprop *prop)
636*4882a593Smuzhiyun {
637*4882a593Smuzhiyun 	return ofnode_get_first_property(dev_ofnode(dev), prop);
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun 
dev_read_next_prop(struct ofprop * prop)640*4882a593Smuzhiyun static inline int dev_read_next_prop(struct ofprop *prop)
641*4882a593Smuzhiyun {
642*4882a593Smuzhiyun 	return ofnode_get_next_property(prop);
643*4882a593Smuzhiyun }
644*4882a593Smuzhiyun 
dev_read_prop_by_prop(struct ofprop * prop,const char ** propname,int * lenp)645*4882a593Smuzhiyun static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
646*4882a593Smuzhiyun 						const char **propname,
647*4882a593Smuzhiyun 						int *lenp)
648*4882a593Smuzhiyun {
649*4882a593Smuzhiyun 	return ofnode_get_property_by_prop(prop, propname, lenp);
650*4882a593Smuzhiyun }
651*4882a593Smuzhiyun 
dev_read_alias_seq(struct udevice * dev,int * devnump)652*4882a593Smuzhiyun static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
653*4882a593Smuzhiyun {
654*4882a593Smuzhiyun 	return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
655*4882a593Smuzhiyun 				    dev_of_offset(dev), devnump);
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun 
dev_read_u32_array(struct udevice * dev,const char * propname,u32 * out_values,size_t sz)658*4882a593Smuzhiyun static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
659*4882a593Smuzhiyun 				     u32 *out_values, size_t sz)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun 	if (!dev_of_valid(dev))
662*4882a593Smuzhiyun 		return -EINVAL;
663*4882a593Smuzhiyun 	return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
664*4882a593Smuzhiyun }
665*4882a593Smuzhiyun 
dev_read_first_subnode(struct udevice * dev)666*4882a593Smuzhiyun static inline ofnode dev_read_first_subnode(struct udevice *dev)
667*4882a593Smuzhiyun {
668*4882a593Smuzhiyun 	return ofnode_first_subnode(dev_ofnode(dev));
669*4882a593Smuzhiyun }
670*4882a593Smuzhiyun 
dev_read_next_subnode(ofnode node)671*4882a593Smuzhiyun static inline ofnode dev_read_next_subnode(ofnode node)
672*4882a593Smuzhiyun {
673*4882a593Smuzhiyun 	return ofnode_next_subnode(node);
674*4882a593Smuzhiyun }
675*4882a593Smuzhiyun 
dev_read_u8_array_ptr(struct udevice * dev,const char * propname,size_t sz)676*4882a593Smuzhiyun static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
677*4882a593Smuzhiyun 					const char *propname, size_t sz)
678*4882a593Smuzhiyun {
679*4882a593Smuzhiyun 	return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
680*4882a593Smuzhiyun }
681*4882a593Smuzhiyun 
dev_read_enabled(struct udevice * dev)682*4882a593Smuzhiyun static inline int dev_read_enabled(struct udevice *dev)
683*4882a593Smuzhiyun {
684*4882a593Smuzhiyun 	return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
685*4882a593Smuzhiyun }
686*4882a593Smuzhiyun 
dev_read_resource(struct udevice * dev,uint index,struct resource * res)687*4882a593Smuzhiyun static inline int dev_read_resource(struct udevice *dev, uint index,
688*4882a593Smuzhiyun 				    struct resource *res)
689*4882a593Smuzhiyun {
690*4882a593Smuzhiyun 	return ofnode_read_resource(dev_ofnode(dev), index, res);
691*4882a593Smuzhiyun }
692*4882a593Smuzhiyun 
dev_read_resource_byname(struct udevice * dev,const char * name,struct resource * res)693*4882a593Smuzhiyun static inline int dev_read_resource_byname(struct udevice *dev,
694*4882a593Smuzhiyun 					   const char *name,
695*4882a593Smuzhiyun 					   struct resource *res)
696*4882a593Smuzhiyun {
697*4882a593Smuzhiyun 	return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
698*4882a593Smuzhiyun }
699*4882a593Smuzhiyun 
dev_translate_address(struct udevice * dev,const fdt32_t * in_addr)700*4882a593Smuzhiyun static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
701*4882a593Smuzhiyun {
702*4882a593Smuzhiyun 	return ofnode_translate_address(dev_ofnode(dev), in_addr);
703*4882a593Smuzhiyun }
704*4882a593Smuzhiyun 
705*4882a593Smuzhiyun #endif /* CONFIG_DM_DEV_READ_INLINE */
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun /**
708*4882a593Smuzhiyun  * dev_for_each_subnode() - Helper function to iterate through subnodes
709*4882a593Smuzhiyun  *
710*4882a593Smuzhiyun  * This creates a for() loop which works through the subnodes in a device's
711*4882a593Smuzhiyun  * device-tree node.
712*4882a593Smuzhiyun  *
713*4882a593Smuzhiyun  * @subnode: ofnode holding the current subnode
714*4882a593Smuzhiyun  * @dev: device to use for interation (struct udevice *)
715*4882a593Smuzhiyun  */
716*4882a593Smuzhiyun #define dev_for_each_subnode(subnode, dev) \
717*4882a593Smuzhiyun 	for (subnode = dev_read_first_subnode(dev); \
718*4882a593Smuzhiyun 	     ofnode_valid(subnode); \
719*4882a593Smuzhiyun 	     subnode = ofnode_next_subnode(subnode))
720*4882a593Smuzhiyun 
721*4882a593Smuzhiyun /**
722*4882a593Smuzhiyun  * dev_for_each_property() - Helper function to iterate through property
723*4882a593Smuzhiyun  *
724*4882a593Smuzhiyun  * This creates a for() loop which works through the property in a device's
725*4882a593Smuzhiyun  * device-tree node.
726*4882a593Smuzhiyun  *
727*4882a593Smuzhiyun  * @prop: struct ofprop holding the current property
728*4882a593Smuzhiyun  * @dev: device to use for interation (struct udevice *)
729*4882a593Smuzhiyun  */
730*4882a593Smuzhiyun #define dev_for_each_property(prop, dev) \
731*4882a593Smuzhiyun 	for (int ret_prop = dev_read_first_prop(dev, &prop); \
732*4882a593Smuzhiyun 	     !ret_prop; \
733*4882a593Smuzhiyun 	     ret_prop = dev_read_next_prop(&prop))
734*4882a593Smuzhiyun 
735*4882a593Smuzhiyun #endif
736