xref: /OK3568_Linux_fs/u-boot/include/dm/of_access.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Originally from Linux v4.9
3*4882a593Smuzhiyun  * Copyright (C) 1996-2005 Paul Mackerras.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
6*4882a593Smuzhiyun  * Updates for SPARC64 by David S. Miller
7*4882a593Smuzhiyun  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Copyright (c) 2017 Google, Inc
10*4882a593Smuzhiyun  * Written by Simon Glass <sjg@chromium.org>
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * Modified for U-Boot
13*4882a593Smuzhiyun  * Copyright (c) 2017 Google, Inc
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #ifndef _DM_OF_ACCESS_H
19*4882a593Smuzhiyun #define _DM_OF_ACCESS_H
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include <dm/of.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /**
24*4882a593Smuzhiyun  * of_find_all_nodes - Get next node in global list
25*4882a593Smuzhiyun  * @prev:	Previous node or NULL to start iteration
26*4882a593Smuzhiyun  *		of_node_put() will be called on it
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * Returns a node pointer with refcount incremented, use
29*4882a593Smuzhiyun  * of_node_put() on it when done.
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun struct device_node *of_find_all_nodes(struct device_node *prev);
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define for_each_of_allnodes_from(from, dn) \
34*4882a593Smuzhiyun 	for (dn = of_find_all_nodes(from); dn; dn = of_find_all_nodes(dn))
35*4882a593Smuzhiyun #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /* Dummy functions to mirror Linux. These are not used in U-Boot */
38*4882a593Smuzhiyun #define of_node_get(x) (x)
of_node_put(const struct device_node * np)39*4882a593Smuzhiyun static inline void of_node_put(const struct device_node *np) { }
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /**
42*4882a593Smuzhiyun  * of_n_addr_cells() - Get the number of address cells for a node
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * This walks back up the tree to find the closest #address-cells property
45*4882a593Smuzhiyun  * which controls the given node.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * @np: Node pointer to check
48*4882a593Smuzhiyun  * @return number of address cells this node uses
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun int of_n_addr_cells(const struct device_node *np);
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /**
53*4882a593Smuzhiyun  * of_n_size_cells() - Get the number of size cells for a node
54*4882a593Smuzhiyun  *
55*4882a593Smuzhiyun  * This walks back up the tree to find the closest #size-cells property
56*4882a593Smuzhiyun  * which controls the given node.
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * @np: Node pointer to check
59*4882a593Smuzhiyun  * @return number of size cells this node uses
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun int of_n_size_cells(const struct device_node *np);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /**
64*4882a593Smuzhiyun  * of_simple_addr_cells() - Get the address cells property in a node
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * This function matches fdt_address_cells().
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * @np: Node pointer to check
69*4882a593Smuzhiyun  * @return value of #address-cells property in this node, or 2 if none
70*4882a593Smuzhiyun  */
71*4882a593Smuzhiyun int of_simple_addr_cells(const struct device_node *np);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /**
74*4882a593Smuzhiyun  * of_simple_size_cells() - Get the size cells property in a node
75*4882a593Smuzhiyun  *
76*4882a593Smuzhiyun  * This function matches fdt_size_cells().
77*4882a593Smuzhiyun  *
78*4882a593Smuzhiyun  * @np: Node pointer to check
79*4882a593Smuzhiyun  * @return value of #size-cells property in this node, or 2 if none
80*4882a593Smuzhiyun  */
81*4882a593Smuzhiyun int of_simple_size_cells(const struct device_node *np);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /**
84*4882a593Smuzhiyun  * of_find_property() - find a property in a node
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * @np: Pointer to device node holding property
87*4882a593Smuzhiyun  * @name: Name of property
88*4882a593Smuzhiyun  * @lenp: If non-NULL, returns length of property
89*4882a593Smuzhiyun  * @return pointer to property, or NULL if not found
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun struct property *of_find_property(const struct device_node *np,
92*4882a593Smuzhiyun 				  const char *name, int *lenp);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /**
95*4882a593Smuzhiyun  * of_get_property() - get a property value
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  * Find a property with a given name for a given node and return the value.
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  * @np: Pointer to device node holding property
100*4882a593Smuzhiyun  * @name: Name of property
101*4882a593Smuzhiyun  * @lenp: If non-NULL, returns length of property
102*4882a593Smuzhiyun  * @return pointer to property value, or NULL if not found
103*4882a593Smuzhiyun  */
104*4882a593Smuzhiyun const void *of_get_property(const struct device_node *np, const char *name,
105*4882a593Smuzhiyun 			    int *lenp);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /**
108*4882a593Smuzhiyun  * of_get_first_property()- get to the pointer of the first property
109*4882a593Smuzhiyun  *
110*4882a593Smuzhiyun  * Get pointer to the first property of the node, it is used to iterate
111*4882a593Smuzhiyun  * and read all the property with of_get_next_property_by_prop().
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  * @np: Pointer to device node
114*4882a593Smuzhiyun  * @return pointer to property or NULL if not found
115*4882a593Smuzhiyun  */
116*4882a593Smuzhiyun const struct property *of_get_first_property(const struct device_node *np);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /**
119*4882a593Smuzhiyun  * of_get_next_property() - get to the pointer of the next property
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * Get pointer to the next property of the node, it is used to iterate
122*4882a593Smuzhiyun  * and read all the property with of_get_property_by_prop().
123*4882a593Smuzhiyun  *
124*4882a593Smuzhiyun  * @np: Pointer to device node
125*4882a593Smuzhiyun  * @property: pointer of the current property
126*4882a593Smuzhiyun  * @return pointer to next property or NULL if not found
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun const struct property *of_get_next_property(const struct device_node *np,
129*4882a593Smuzhiyun 					    const struct property *property);
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /**
132*4882a593Smuzhiyun  * of_get_property_by_prop() - get a property value of a node property
133*4882a593Smuzhiyun  *
134*4882a593Smuzhiyun  * Get value for the property identified by node and property pointer.
135*4882a593Smuzhiyun  *
136*4882a593Smuzhiyun  * @node: node to read
137*4882a593Smuzhiyun  * @property: pointer of the property to read
138*4882a593Smuzhiyun  * @propname: place to property name on success
139*4882a593Smuzhiyun  * @lenp: place to put length on success
140*4882a593Smuzhiyun  * @return pointer to property value or NULL if error
141*4882a593Smuzhiyun  */
142*4882a593Smuzhiyun const void *of_get_property_by_prop(const struct device_node *np,
143*4882a593Smuzhiyun 				    const struct property *property,
144*4882a593Smuzhiyun 				    const char **name,
145*4882a593Smuzhiyun 				    int *lenp);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun /**
148*4882a593Smuzhiyun  * of_device_is_compatible() - Check if the node matches given constraints
149*4882a593Smuzhiyun  * @device: pointer to node
150*4882a593Smuzhiyun  * @compat: required compatible string, NULL or "" for any match
151*4882a593Smuzhiyun  * @type: required device_type value, NULL or "" for any match
152*4882a593Smuzhiyun  * @name: required node name, NULL or "" for any match
153*4882a593Smuzhiyun  *
154*4882a593Smuzhiyun  * Checks if the given @compat, @type and @name strings match the
155*4882a593Smuzhiyun  * properties of the given @device. A constraints can be skipped by
156*4882a593Smuzhiyun  * passing NULL or an empty string as the constraint.
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * @return 0 for no match, and a positive integer on match. The return
159*4882a593Smuzhiyun  * value is a relative score with larger values indicating better
160*4882a593Smuzhiyun  * matches. The score is weighted for the most specific compatible value
161*4882a593Smuzhiyun  * to get the highest score. Matching type is next, followed by matching
162*4882a593Smuzhiyun  * name. Practically speaking, this results in the following priority
163*4882a593Smuzhiyun  * order for matches:
164*4882a593Smuzhiyun  *
165*4882a593Smuzhiyun  * 1. specific compatible && type && name
166*4882a593Smuzhiyun  * 2. specific compatible && type
167*4882a593Smuzhiyun  * 3. specific compatible && name
168*4882a593Smuzhiyun  * 4. specific compatible
169*4882a593Smuzhiyun  * 5. general compatible && type && name
170*4882a593Smuzhiyun  * 6. general compatible && type
171*4882a593Smuzhiyun  * 7. general compatible && name
172*4882a593Smuzhiyun  * 8. general compatible
173*4882a593Smuzhiyun  * 9. type && name
174*4882a593Smuzhiyun  * 10. type
175*4882a593Smuzhiyun  * 11. name
176*4882a593Smuzhiyun  */
177*4882a593Smuzhiyun int of_device_is_compatible(const struct device_node *np, const char *compat,
178*4882a593Smuzhiyun 			    const char *type, const char *name);
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun /**
181*4882a593Smuzhiyun  * of_device_is_available() - check if a device is available for use
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * @device: Node to check for availability
184*4882a593Smuzhiyun  *
185*4882a593Smuzhiyun  * @return true if the status property is absent or set to "okay", false
186*4882a593Smuzhiyun  * otherwise
187*4882a593Smuzhiyun  */
188*4882a593Smuzhiyun bool of_device_is_available(const struct device_node *np);
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun /**
191*4882a593Smuzhiyun  * of_get_parent() - Get a node's parent, if any
192*4882a593Smuzhiyun  *
193*4882a593Smuzhiyun  * @node: Node to check
194*4882a593Smuzhiyun  * @eturns a node pointer, or NULL if none
195*4882a593Smuzhiyun  */
196*4882a593Smuzhiyun struct device_node *of_get_parent(const struct device_node *np);
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /**
199*4882a593Smuzhiyun  * of_find_node_opts_by_path() - Find a node matching a full OF path
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * @path: Either the full path to match, or if the path does not start with
202*4882a593Smuzhiyun  *	'/', the name of a property of the /aliases node (an alias). In the
203*4882a593Smuzhiyun  *	case of an alias, the node matching the alias' value will be returned.
204*4882a593Smuzhiyun  * @opts: Address of a pointer into which to store the start of an options
205*4882a593Smuzhiyun  *	string appended to the end of the path with a ':' separator. Can be NULL
206*4882a593Smuzhiyun  *
207*4882a593Smuzhiyun  * Valid paths:
208*4882a593Smuzhiyun  *	/foo/bar	Full path
209*4882a593Smuzhiyun  *	foo		Valid alias
210*4882a593Smuzhiyun  *	foo/bar		Valid alias + relative path
211*4882a593Smuzhiyun  *
212*4882a593Smuzhiyun  * @return a node pointer or NULL if not found
213*4882a593Smuzhiyun  */
214*4882a593Smuzhiyun struct device_node *of_find_node_opts_by_path(const char *path,
215*4882a593Smuzhiyun 					      const char **opts);
216*4882a593Smuzhiyun 
of_find_node_by_path(const char * path)217*4882a593Smuzhiyun static inline struct device_node *of_find_node_by_path(const char *path)
218*4882a593Smuzhiyun {
219*4882a593Smuzhiyun 	return of_find_node_opts_by_path(path, NULL);
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /**
223*4882a593Smuzhiyun  * of_find_compatible_node() - find a node based on its compatible string
224*4882a593Smuzhiyun  *
225*4882a593Smuzhiyun  * Find a node based on type and one of the tokens in its "compatible" property
226*4882a593Smuzhiyun  * @from: Node to start searching from or NULL. the node you pass will not be
227*4882a593Smuzhiyun  *	searched, only the next one will; typically, you pass what the previous
228*4882a593Smuzhiyun  *	call returned.
229*4882a593Smuzhiyun  * @type: The type string to match "device_type" or NULL to ignore
230*4882a593Smuzhiyun  * @compatible:	The string to match to one of the tokens in the device
231*4882a593Smuzhiyun  *	"compatible" list.
232*4882a593Smuzhiyun  * @return node pointer or NULL if not found
233*4882a593Smuzhiyun  */
234*4882a593Smuzhiyun struct device_node *of_find_compatible_node(struct device_node *from,
235*4882a593Smuzhiyun 				const char *type, const char *compatible);
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun /**
238*4882a593Smuzhiyun  * of_find_node_by_phandle() - Find a node given a phandle
239*4882a593Smuzhiyun  *
240*4882a593Smuzhiyun  * @handle:	phandle of the node to find
241*4882a593Smuzhiyun  *
242*4882a593Smuzhiyun  * @return node pointer, or NULL if not found
243*4882a593Smuzhiyun  */
244*4882a593Smuzhiyun struct device_node *of_find_node_by_phandle(phandle handle);
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun /**
247*4882a593Smuzhiyun  * of_read_u32() - Find and read a 32-bit integer from a property
248*4882a593Smuzhiyun  *
249*4882a593Smuzhiyun  * Search for a property in a device node and read a 32-bit value from
250*4882a593Smuzhiyun  * it.
251*4882a593Smuzhiyun  *
252*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
253*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
254*4882a593Smuzhiyun  * @outp:	pointer to return value, modified only if return value is 0.
255*4882a593Smuzhiyun  *
256*4882a593Smuzhiyun  * @return 0 on success, -EINVAL if the property does not exist,
257*4882a593Smuzhiyun  * -ENODATA if property does not have a value, and -EOVERFLOW if the
258*4882a593Smuzhiyun  * property data isn't large enough.
259*4882a593Smuzhiyun  */
260*4882a593Smuzhiyun int of_read_u32(const struct device_node *np, const char *propname, u32 *outp);
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun /**
263*4882a593Smuzhiyun  * of_property_read_u64 - Find and read a 64 bit integer from a property
264*4882a593Smuzhiyun  * @np:         device node from which the property value is to be read.
265*4882a593Smuzhiyun  * @propname:   name of the property to be searched.
266*4882a593Smuzhiyun  * @out_value:  pointer to return value, modified only if return value is 0.
267*4882a593Smuzhiyun  *
268*4882a593Smuzhiyun  * Search for a property in a device node and read a 64-bit value from
269*4882a593Smuzhiyun  * it. Returns 0 on success, -EINVAL if the property does not exist,
270*4882a593Smuzhiyun  * -ENODATA if property does not have a value, and -EOVERFLOW if the
271*4882a593Smuzhiyun  * property data isn't large enough.
272*4882a593Smuzhiyun  *
273*4882a593Smuzhiyun  * The out_value is modified only if a valid u64 value can be decoded.
274*4882a593Smuzhiyun  */
275*4882a593Smuzhiyun int of_property_read_u64(const struct device_node *np, const char *propname,
276*4882a593Smuzhiyun                          u64 *out_value);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun /**
279*4882a593Smuzhiyun  * of_read_u32_array() - Find and read an array of 32 bit integers
280*4882a593Smuzhiyun  *
281*4882a593Smuzhiyun  * Search for a property in a device node and read 32-bit value(s) from
282*4882a593Smuzhiyun  * it.
283*4882a593Smuzhiyun  *
284*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
285*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
286*4882a593Smuzhiyun  * @out_values:	pointer to return value, modified only if return value is 0.
287*4882a593Smuzhiyun  * @sz:		number of array elements to read
288*4882a593Smuzhiyun  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
289*4882a593Smuzhiyun  * if property does not have a value, and -EOVERFLOW is longer than sz.
290*4882a593Smuzhiyun  */
291*4882a593Smuzhiyun int of_read_u32_array(const struct device_node *np, const char *propname,
292*4882a593Smuzhiyun 		      u32 *out_values, size_t sz);
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun /**
295*4882a593Smuzhiyun  * of_write_u32_array() - Find and write an array of 32 bit integers
296*4882a593Smuzhiyun  *
297*4882a593Smuzhiyun  * Search for a property in a device node and write 32-bit value(s) to
298*4882a593Smuzhiyun  * it.
299*4882a593Smuzhiyun  *
300*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
301*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
302*4882a593Smuzhiyun  * @values:	pointer to update value, modified only if return value is 0.
303*4882a593Smuzhiyun  * @sz:		number of array elements to read
304*4882a593Smuzhiyun  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
305*4882a593Smuzhiyun  * if property does not have a value, and -EOVERFLOW is longer than sz.
306*4882a593Smuzhiyun  */
307*4882a593Smuzhiyun int of_write_u32_array(const struct device_node *np, const char *propname,
308*4882a593Smuzhiyun 		       u32 *values, size_t sz);
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun /**
311*4882a593Smuzhiyun  * of_property_match_string() - Find string in a list and return index
312*4882a593Smuzhiyun  *
313*4882a593Smuzhiyun  * This function searches a string list property and returns the index
314*4882a593Smuzhiyun  * of a specific string value.
315*4882a593Smuzhiyun  *
316*4882a593Smuzhiyun  * @np: pointer to node containing string list property
317*4882a593Smuzhiyun  * @propname: string list property name
318*4882a593Smuzhiyun  * @string: pointer to string to search for in string list
319*4882a593Smuzhiyun  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
320*4882a593Smuzhiyun  * if property does not have a value, and -EOVERFLOW is longer than sz.
321*4882a593Smuzhiyun  */
322*4882a593Smuzhiyun int of_property_match_string(const struct device_node *np, const char *propname,
323*4882a593Smuzhiyun 			     const char *string);
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun int of_property_read_string_helper(const struct device_node *np,
326*4882a593Smuzhiyun 				   const char *propname, const char **out_strs,
327*4882a593Smuzhiyun 				   size_t sz, int index);
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun /**
330*4882a593Smuzhiyun  * of_property_read_string_index() - Find and read a string from a multiple
331*4882a593Smuzhiyun  * strings property.
332*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
333*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
334*4882a593Smuzhiyun  * @index:	index of the string in the list of strings
335*4882a593Smuzhiyun  * @out_string:	pointer to null terminated return string, modified only if
336*4882a593Smuzhiyun  *		return value is 0.
337*4882a593Smuzhiyun  *
338*4882a593Smuzhiyun  * Search for a property in a device tree node and retrieve a null
339*4882a593Smuzhiyun  * terminated string value (pointer to data, not a copy) in the list of strings
340*4882a593Smuzhiyun  * contained in that property.
341*4882a593Smuzhiyun  * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
342*4882a593Smuzhiyun  * property does not have a value, and -EILSEQ if the string is not
343*4882a593Smuzhiyun  * null-terminated within the length of the property data.
344*4882a593Smuzhiyun  *
345*4882a593Smuzhiyun  * The out_string pointer is modified only if a valid string can be decoded.
346*4882a593Smuzhiyun  */
of_property_read_string_index(const struct device_node * np,const char * propname,int index,const char ** output)347*4882a593Smuzhiyun static inline int of_property_read_string_index(const struct device_node *np,
348*4882a593Smuzhiyun 						const char *propname,
349*4882a593Smuzhiyun 						int index, const char **output)
350*4882a593Smuzhiyun {
351*4882a593Smuzhiyun 	int rc = of_property_read_string_helper(np, propname, output, 1, index);
352*4882a593Smuzhiyun 	return rc < 0 ? rc : 0;
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun /**
356*4882a593Smuzhiyun  * of_property_count_strings() - Find and return the number of strings from a
357*4882a593Smuzhiyun  * multiple strings property.
358*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
359*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
360*4882a593Smuzhiyun  *
361*4882a593Smuzhiyun  * Search for a property in a device tree node and retrieve the number of null
362*4882a593Smuzhiyun  * terminated string contain in it. Returns the number of strings on
363*4882a593Smuzhiyun  * success, -EINVAL if the property does not exist, -ENODATA if property
364*4882a593Smuzhiyun  * does not have a value, and -EILSEQ if the string is not null-terminated
365*4882a593Smuzhiyun  * within the length of the property data.
366*4882a593Smuzhiyun  */
of_property_count_strings(const struct device_node * np,const char * propname)367*4882a593Smuzhiyun static inline int of_property_count_strings(const struct device_node *np,
368*4882a593Smuzhiyun 					    const char *propname)
369*4882a593Smuzhiyun {
370*4882a593Smuzhiyun 	return of_property_read_string_helper(np, propname, NULL, 0, 0);
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun /**
374*4882a593Smuzhiyun  * of_parse_phandle - Resolve a phandle property to a device_node pointer
375*4882a593Smuzhiyun  * @np: Pointer to device node holding phandle property
376*4882a593Smuzhiyun  * @phandle_name: Name of property holding a phandle value
377*4882a593Smuzhiyun  * @index: For properties holding a table of phandles, this is the index into
378*4882a593Smuzhiyun  *         the table
379*4882a593Smuzhiyun  *
380*4882a593Smuzhiyun  * Returns the device_node pointer with refcount incremented.  Use
381*4882a593Smuzhiyun  * of_node_put() on it when done.
382*4882a593Smuzhiyun  */
383*4882a593Smuzhiyun struct device_node *of_parse_phandle(const struct device_node *np,
384*4882a593Smuzhiyun 				     const char *phandle_name, int index);
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun /**
387*4882a593Smuzhiyun  * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
388*4882a593Smuzhiyun  *
389*4882a593Smuzhiyun  * @np:		pointer to a device tree node containing a list
390*4882a593Smuzhiyun  * @list_name:	property name that contains a list
391*4882a593Smuzhiyun  * @cells_name:	property name that specifies phandles' arguments count
392*4882a593Smuzhiyun  * @index:	index of a phandle to parse out
393*4882a593Smuzhiyun  * @out_args:	optional pointer to output arguments structure (will be filled)
394*4882a593Smuzhiyun  * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
395*4882a593Smuzhiyun  *	@list_name does not exist, -EINVAL if a phandle was not found,
396*4882a593Smuzhiyun  *	@cells_name could not be found, the arguments were truncated or there
397*4882a593Smuzhiyun  *	were too many arguments.
398*4882a593Smuzhiyun  *
399*4882a593Smuzhiyun  * This function is useful to parse lists of phandles and their arguments.
400*4882a593Smuzhiyun  * Returns 0 on success and fills out_args, on error returns appropriate
401*4882a593Smuzhiyun  * errno value.
402*4882a593Smuzhiyun  *
403*4882a593Smuzhiyun  * Caller is responsible to call of_node_put() on the returned out_args->np
404*4882a593Smuzhiyun  * pointer.
405*4882a593Smuzhiyun  *
406*4882a593Smuzhiyun  * Example:
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * phandle1: node1 {
409*4882a593Smuzhiyun  *	#list-cells = <2>;
410*4882a593Smuzhiyun  * }
411*4882a593Smuzhiyun  *
412*4882a593Smuzhiyun  * phandle2: node2 {
413*4882a593Smuzhiyun  *	#list-cells = <1>;
414*4882a593Smuzhiyun  * }
415*4882a593Smuzhiyun  *
416*4882a593Smuzhiyun  * node3 {
417*4882a593Smuzhiyun  *	list = <&phandle1 1 2 &phandle2 3>;
418*4882a593Smuzhiyun  * }
419*4882a593Smuzhiyun  *
420*4882a593Smuzhiyun  * To get a device_node of the `node2' node you may call this:
421*4882a593Smuzhiyun  * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
422*4882a593Smuzhiyun  */
423*4882a593Smuzhiyun int of_parse_phandle_with_args(const struct device_node *np,
424*4882a593Smuzhiyun 			       const char *list_name, const char *cells_name,
425*4882a593Smuzhiyun 			       int index, struct of_phandle_args *out_args);
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun /**
428*4882a593Smuzhiyun  * of_count_phandle_with_args() - Count the number of phandle in a list
429*4882a593Smuzhiyun  *
430*4882a593Smuzhiyun  * @np:		pointer to a device tree node containing a list
431*4882a593Smuzhiyun  * @list_name:	property name that contains a list
432*4882a593Smuzhiyun  * @cells_name:	property name that specifies phandles' arguments count
433*4882a593Smuzhiyun  * @return number of phandle found, -ENOENT if
434*4882a593Smuzhiyun  *	@list_name does not exist, -EINVAL if a phandle was not found,
435*4882a593Smuzhiyun  *	@cells_name could not be found, the arguments were truncated or there
436*4882a593Smuzhiyun  *	were too many arguments.
437*4882a593Smuzhiyun  *
438*4882a593Smuzhiyun  * Returns number of phandle found on success, on error returns appropriate
439*4882a593Smuzhiyun  * errno value.
440*4882a593Smuzhiyun  *
441*4882a593Smuzhiyun  */
442*4882a593Smuzhiyun int of_count_phandle_with_args(const struct device_node *np,
443*4882a593Smuzhiyun 			       const char *list_name, const char *cells_name);
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun /**
446*4882a593Smuzhiyun  * of_alias_scan() - Scan all properties of the 'aliases' node
447*4882a593Smuzhiyun  *
448*4882a593Smuzhiyun  * The function scans all the properties of the 'aliases' node and populates
449*4882a593Smuzhiyun  * the lookup table with the properties.  It returns the number of alias
450*4882a593Smuzhiyun  * properties found, or an error code in case of failure.
451*4882a593Smuzhiyun  *
452*4882a593Smuzhiyun  * @return 9 if OK, -ENOMEM if not enough memory
453*4882a593Smuzhiyun  */
454*4882a593Smuzhiyun int of_alias_scan(void);
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun /**
457*4882a593Smuzhiyun  * of_alias_get_id - Get alias id for the given device_node
458*4882a593Smuzhiyun  *
459*4882a593Smuzhiyun  * Travels the lookup table to get the alias id for the given device_node and
460*4882a593Smuzhiyun  * alias stem.
461*4882a593Smuzhiyun  *
462*4882a593Smuzhiyun  * @np:		Pointer to the given device_node
463*4882a593Smuzhiyun  * @stem:	Alias stem of the given device_node
464*4882a593Smuzhiyun  * @return alias ID, if found, else -ENODEV
465*4882a593Smuzhiyun  */
466*4882a593Smuzhiyun int of_alias_get_id(const struct device_node *np, const char *stem);
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun /**
469*4882a593Smuzhiyun  * of_alias_get_dev - Get device_node by given stem and alias id
470*4882a593Smuzhiyun  *
471*4882a593Smuzhiyun  * Travels the lookup table to get the device_node by given stem and alias id.
472*4882a593Smuzhiyun  *
473*4882a593Smuzhiyun  * @stem:	Alias stem of the given device_node
474*4882a593Smuzhiyun  * @id:         Alias id of the given device_node
475*4882a593Smuzhiyun  * @return device_node, if found, else NULL
476*4882a593Smuzhiyun  */
477*4882a593Smuzhiyun struct device_node *of_alias_get_dev(const char *stem, int id);
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun /**
480*4882a593Smuzhiyun  * of_alias_dump - Dump of alias nodes added in aliases_lookup.
481*4882a593Smuzhiyun  */
482*4882a593Smuzhiyun struct device_node *of_alias_dump(void);
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun /**
485*4882a593Smuzhiyun  * of_get_stdout() - Get node to use for stdout
486*4882a593Smuzhiyun  *
487*4882a593Smuzhiyun  * @return node referred to by stdout-path alias, or NULL if none
488*4882a593Smuzhiyun  */
489*4882a593Smuzhiyun struct device_node *of_get_stdout(void);
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun #endif
492