xref: /rk3399_rockchip-uboot/include/dm/of_access.h (revision 3cf4841077bc170e305243e4ba2aac4420b9fb55)
1644ec0a9SSimon Glass /*
2644ec0a9SSimon Glass  * Originally from Linux v4.9
3644ec0a9SSimon Glass  * Copyright (C) 1996-2005 Paul Mackerras.
4644ec0a9SSimon Glass  *
5644ec0a9SSimon Glass  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
6644ec0a9SSimon Glass  * Updates for SPARC64 by David S. Miller
7644ec0a9SSimon Glass  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
8644ec0a9SSimon Glass  *
9644ec0a9SSimon Glass  * Copyright (c) 2017 Google, Inc
10644ec0a9SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
11644ec0a9SSimon Glass  *
12644ec0a9SSimon Glass  * Modified for U-Boot
13644ec0a9SSimon Glass  * Copyright (c) 2017 Google, Inc
14644ec0a9SSimon Glass  *
15644ec0a9SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
16644ec0a9SSimon Glass  */
17644ec0a9SSimon Glass 
18644ec0a9SSimon Glass #ifndef _DM_OF_ACCESS_H
19644ec0a9SSimon Glass #define _DM_OF_ACCESS_H
20644ec0a9SSimon Glass 
21644ec0a9SSimon Glass #include <dm/of.h>
22644ec0a9SSimon Glass 
23644ec0a9SSimon Glass /**
24644ec0a9SSimon Glass  * of_find_all_nodes - Get next node in global list
25644ec0a9SSimon Glass  * @prev:	Previous node or NULL to start iteration
26644ec0a9SSimon Glass  *		of_node_put() will be called on it
27644ec0a9SSimon Glass  *
28644ec0a9SSimon Glass  * Returns a node pointer with refcount incremented, use
29644ec0a9SSimon Glass  * of_node_put() on it when done.
30644ec0a9SSimon Glass  */
31644ec0a9SSimon Glass struct device_node *of_find_all_nodes(struct device_node *prev);
32644ec0a9SSimon Glass 
33644ec0a9SSimon Glass #define for_each_of_allnodes_from(from, dn) \
34644ec0a9SSimon Glass 	for (dn = of_find_all_nodes(from); dn; dn = of_find_all_nodes(dn))
35644ec0a9SSimon Glass #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
36644ec0a9SSimon Glass 
37644ec0a9SSimon Glass /* Dummy functions to mirror Linux. These are not used in U-Boot */
38644ec0a9SSimon Glass #define of_node_get(x) (x)
of_node_put(const struct device_node * np)39644ec0a9SSimon Glass static inline void of_node_put(const struct device_node *np) { }
40644ec0a9SSimon Glass 
41644ec0a9SSimon Glass /**
42644ec0a9SSimon Glass  * of_n_addr_cells() - Get the number of address cells for a node
43644ec0a9SSimon Glass  *
44644ec0a9SSimon Glass  * This walks back up the tree to find the closest #address-cells property
45644ec0a9SSimon Glass  * which controls the given node.
46644ec0a9SSimon Glass  *
47644ec0a9SSimon Glass  * @np: Node pointer to check
48644ec0a9SSimon Glass  * @return number of address cells this node uses
49644ec0a9SSimon Glass  */
50644ec0a9SSimon Glass int of_n_addr_cells(const struct device_node *np);
51644ec0a9SSimon Glass 
52644ec0a9SSimon Glass /**
53644ec0a9SSimon Glass  * of_n_size_cells() - Get the number of size cells for a node
54644ec0a9SSimon Glass  *
55644ec0a9SSimon Glass  * This walks back up the tree to find the closest #size-cells property
56644ec0a9SSimon Glass  * which controls the given node.
57644ec0a9SSimon Glass  *
58644ec0a9SSimon Glass  * @np: Node pointer to check
59644ec0a9SSimon Glass  * @return number of size cells this node uses
60644ec0a9SSimon Glass  */
61644ec0a9SSimon Glass int of_n_size_cells(const struct device_node *np);
62644ec0a9SSimon Glass 
63644ec0a9SSimon Glass /**
64878d68c0SSimon Glass  * of_simple_addr_cells() - Get the address cells property in a node
65878d68c0SSimon Glass  *
66878d68c0SSimon Glass  * This function matches fdt_address_cells().
67878d68c0SSimon Glass  *
68878d68c0SSimon Glass  * @np: Node pointer to check
69878d68c0SSimon Glass  * @return value of #address-cells property in this node, or 2 if none
70878d68c0SSimon Glass  */
71878d68c0SSimon Glass int of_simple_addr_cells(const struct device_node *np);
72878d68c0SSimon Glass 
73878d68c0SSimon Glass /**
74878d68c0SSimon Glass  * of_simple_size_cells() - Get the size cells property in a node
75878d68c0SSimon Glass  *
76878d68c0SSimon Glass  * This function matches fdt_size_cells().
77878d68c0SSimon Glass  *
78878d68c0SSimon Glass  * @np: Node pointer to check
79878d68c0SSimon Glass  * @return value of #size-cells property in this node, or 2 if none
80878d68c0SSimon Glass  */
81878d68c0SSimon Glass int of_simple_size_cells(const struct device_node *np);
82878d68c0SSimon Glass 
83878d68c0SSimon Glass /**
84644ec0a9SSimon Glass  * of_find_property() - find a property in a node
85644ec0a9SSimon Glass  *
86644ec0a9SSimon Glass  * @np: Pointer to device node holding property
87644ec0a9SSimon Glass  * @name: Name of property
88644ec0a9SSimon Glass  * @lenp: If non-NULL, returns length of property
89644ec0a9SSimon Glass  * @return pointer to property, or NULL if not found
90644ec0a9SSimon Glass  */
91644ec0a9SSimon Glass struct property *of_find_property(const struct device_node *np,
92644ec0a9SSimon Glass 				  const char *name, int *lenp);
93644ec0a9SSimon Glass 
94644ec0a9SSimon Glass /**
95644ec0a9SSimon Glass  * of_get_property() - get a property value
96644ec0a9SSimon Glass  *
97644ec0a9SSimon Glass  * Find a property with a given name for a given node and return the value.
98644ec0a9SSimon Glass  *
99644ec0a9SSimon Glass  * @np: Pointer to device node holding property
100644ec0a9SSimon Glass  * @name: Name of property
101644ec0a9SSimon Glass  * @lenp: If non-NULL, returns length of property
102644ec0a9SSimon Glass  * @return pointer to property value, or NULL if not found
103644ec0a9SSimon Glass  */
104644ec0a9SSimon Glass const void *of_get_property(const struct device_node *np, const char *name,
105644ec0a9SSimon Glass 			    int *lenp);
106644ec0a9SSimon Glass 
107644ec0a9SSimon Glass /**
108*3cf48410SPatrick Delaunay  * of_get_first_property()- get to the pointer of the first property
109*3cf48410SPatrick Delaunay  *
110*3cf48410SPatrick Delaunay  * Get pointer to the first property of the node, it is used to iterate
111*3cf48410SPatrick Delaunay  * and read all the property with of_get_next_property_by_prop().
112*3cf48410SPatrick Delaunay  *
113*3cf48410SPatrick Delaunay  * @np: Pointer to device node
114*3cf48410SPatrick Delaunay  * @return pointer to property or NULL if not found
115*3cf48410SPatrick Delaunay  */
116*3cf48410SPatrick Delaunay const struct property *of_get_first_property(const struct device_node *np);
117*3cf48410SPatrick Delaunay 
118*3cf48410SPatrick Delaunay /**
119*3cf48410SPatrick Delaunay  * of_get_next_property() - get to the pointer of the next property
120*3cf48410SPatrick Delaunay  *
121*3cf48410SPatrick Delaunay  * Get pointer to the next property of the node, it is used to iterate
122*3cf48410SPatrick Delaunay  * and read all the property with of_get_property_by_prop().
123*3cf48410SPatrick Delaunay  *
124*3cf48410SPatrick Delaunay  * @np: Pointer to device node
125*3cf48410SPatrick Delaunay  * @property: pointer of the current property
126*3cf48410SPatrick Delaunay  * @return pointer to next property or NULL if not found
127*3cf48410SPatrick Delaunay  */
128*3cf48410SPatrick Delaunay const struct property *of_get_next_property(const struct device_node *np,
129*3cf48410SPatrick Delaunay 					    const struct property *property);
130*3cf48410SPatrick Delaunay 
131*3cf48410SPatrick Delaunay /**
132*3cf48410SPatrick Delaunay  * of_get_property_by_prop() - get a property value of a node property
133*3cf48410SPatrick Delaunay  *
134*3cf48410SPatrick Delaunay  * Get value for the property identified by node and property pointer.
135*3cf48410SPatrick Delaunay  *
136*3cf48410SPatrick Delaunay  * @node: node to read
137*3cf48410SPatrick Delaunay  * @property: pointer of the property to read
138*3cf48410SPatrick Delaunay  * @propname: place to property name on success
139*3cf48410SPatrick Delaunay  * @lenp: place to put length on success
140*3cf48410SPatrick Delaunay  * @return pointer to property value or NULL if error
141*3cf48410SPatrick Delaunay  */
142*3cf48410SPatrick Delaunay const void *of_get_property_by_prop(const struct device_node *np,
143*3cf48410SPatrick Delaunay 				    const struct property *property,
144*3cf48410SPatrick Delaunay 				    const char **name,
145*3cf48410SPatrick Delaunay 				    int *lenp);
146*3cf48410SPatrick Delaunay 
147*3cf48410SPatrick Delaunay /**
148644ec0a9SSimon Glass  * of_device_is_compatible() - Check if the node matches given constraints
149644ec0a9SSimon Glass  * @device: pointer to node
150644ec0a9SSimon Glass  * @compat: required compatible string, NULL or "" for any match
151644ec0a9SSimon Glass  * @type: required device_type value, NULL or "" for any match
152644ec0a9SSimon Glass  * @name: required node name, NULL or "" for any match
153644ec0a9SSimon Glass  *
154644ec0a9SSimon Glass  * Checks if the given @compat, @type and @name strings match the
155644ec0a9SSimon Glass  * properties of the given @device. A constraints can be skipped by
156644ec0a9SSimon Glass  * passing NULL or an empty string as the constraint.
157644ec0a9SSimon Glass  *
158644ec0a9SSimon Glass  * @return 0 for no match, and a positive integer on match. The return
159644ec0a9SSimon Glass  * value is a relative score with larger values indicating better
160644ec0a9SSimon Glass  * matches. The score is weighted for the most specific compatible value
161644ec0a9SSimon Glass  * to get the highest score. Matching type is next, followed by matching
162644ec0a9SSimon Glass  * name. Practically speaking, this results in the following priority
163644ec0a9SSimon Glass  * order for matches:
164644ec0a9SSimon Glass  *
165644ec0a9SSimon Glass  * 1. specific compatible && type && name
166644ec0a9SSimon Glass  * 2. specific compatible && type
167644ec0a9SSimon Glass  * 3. specific compatible && name
168644ec0a9SSimon Glass  * 4. specific compatible
169644ec0a9SSimon Glass  * 5. general compatible && type && name
170644ec0a9SSimon Glass  * 6. general compatible && type
171644ec0a9SSimon Glass  * 7. general compatible && name
172644ec0a9SSimon Glass  * 8. general compatible
173644ec0a9SSimon Glass  * 9. type && name
174644ec0a9SSimon Glass  * 10. type
175644ec0a9SSimon Glass  * 11. name
176644ec0a9SSimon Glass  */
177644ec0a9SSimon Glass int of_device_is_compatible(const struct device_node *np, const char *compat,
178644ec0a9SSimon Glass 			    const char *type, const char *name);
179644ec0a9SSimon Glass 
180644ec0a9SSimon Glass /**
181644ec0a9SSimon Glass  * of_device_is_available() - check if a device is available for use
182644ec0a9SSimon Glass  *
183644ec0a9SSimon Glass  * @device: Node to check for availability
184644ec0a9SSimon Glass  *
185644ec0a9SSimon Glass  * @return true if the status property is absent or set to "okay", false
186644ec0a9SSimon Glass  * otherwise
187644ec0a9SSimon Glass  */
188644ec0a9SSimon Glass bool of_device_is_available(const struct device_node *np);
189644ec0a9SSimon Glass 
190644ec0a9SSimon Glass /**
191644ec0a9SSimon Glass  * of_get_parent() - Get a node's parent, if any
192644ec0a9SSimon Glass  *
193644ec0a9SSimon Glass  * @node: Node to check
194644ec0a9SSimon Glass  * @eturns a node pointer, or NULL if none
195644ec0a9SSimon Glass  */
196644ec0a9SSimon Glass struct device_node *of_get_parent(const struct device_node *np);
197644ec0a9SSimon Glass 
198644ec0a9SSimon Glass /**
199644ec0a9SSimon Glass  * of_find_node_opts_by_path() - Find a node matching a full OF path
200644ec0a9SSimon Glass  *
201644ec0a9SSimon Glass  * @path: Either the full path to match, or if the path does not start with
202644ec0a9SSimon Glass  *	'/', the name of a property of the /aliases node (an alias). In the
203644ec0a9SSimon Glass  *	case of an alias, the node matching the alias' value will be returned.
204644ec0a9SSimon Glass  * @opts: Address of a pointer into which to store the start of an options
205644ec0a9SSimon Glass  *	string appended to the end of the path with a ':' separator. Can be NULL
206644ec0a9SSimon Glass  *
207644ec0a9SSimon Glass  * Valid paths:
208644ec0a9SSimon Glass  *	/foo/bar	Full path
209644ec0a9SSimon Glass  *	foo		Valid alias
210644ec0a9SSimon Glass  *	foo/bar		Valid alias + relative path
211644ec0a9SSimon Glass  *
212644ec0a9SSimon Glass  * @return a node pointer or NULL if not found
213644ec0a9SSimon Glass  */
214644ec0a9SSimon Glass struct device_node *of_find_node_opts_by_path(const char *path,
215644ec0a9SSimon Glass 					      const char **opts);
216644ec0a9SSimon Glass 
of_find_node_by_path(const char * path)217644ec0a9SSimon Glass static inline struct device_node *of_find_node_by_path(const char *path)
218644ec0a9SSimon Glass {
219644ec0a9SSimon Glass 	return of_find_node_opts_by_path(path, NULL);
220644ec0a9SSimon Glass }
221644ec0a9SSimon Glass 
222644ec0a9SSimon Glass /**
223644ec0a9SSimon Glass  * of_find_compatible_node() - find a node based on its compatible string
224644ec0a9SSimon Glass  *
225644ec0a9SSimon Glass  * Find a node based on type and one of the tokens in its "compatible" property
226644ec0a9SSimon Glass  * @from: Node to start searching from or NULL. the node you pass will not be
227644ec0a9SSimon Glass  *	searched, only the next one will; typically, you pass what the previous
228644ec0a9SSimon Glass  *	call returned.
229644ec0a9SSimon Glass  * @type: The type string to match "device_type" or NULL to ignore
230644ec0a9SSimon Glass  * @compatible:	The string to match to one of the tokens in the device
231644ec0a9SSimon Glass  *	"compatible" list.
232644ec0a9SSimon Glass  * @return node pointer or NULL if not found
233644ec0a9SSimon Glass  */
234644ec0a9SSimon Glass struct device_node *of_find_compatible_node(struct device_node *from,
235644ec0a9SSimon Glass 				const char *type, const char *compatible);
236644ec0a9SSimon Glass 
237644ec0a9SSimon Glass /**
238644ec0a9SSimon Glass  * of_find_node_by_phandle() - Find a node given a phandle
239644ec0a9SSimon Glass  *
240644ec0a9SSimon Glass  * @handle:	phandle of the node to find
241644ec0a9SSimon Glass  *
242644ec0a9SSimon Glass  * @return node pointer, or NULL if not found
243644ec0a9SSimon Glass  */
244644ec0a9SSimon Glass struct device_node *of_find_node_by_phandle(phandle handle);
245644ec0a9SSimon Glass 
246644ec0a9SSimon Glass /**
247644ec0a9SSimon Glass  * of_read_u32() - Find and read a 32-bit integer from a property
248644ec0a9SSimon Glass  *
249644ec0a9SSimon Glass  * Search for a property in a device node and read a 32-bit value from
250644ec0a9SSimon Glass  * it.
251644ec0a9SSimon Glass  *
252644ec0a9SSimon Glass  * @np:		device node from which the property value is to be read.
253644ec0a9SSimon Glass  * @propname:	name of the property to be searched.
254644ec0a9SSimon Glass  * @outp:	pointer to return value, modified only if return value is 0.
255644ec0a9SSimon Glass  *
256644ec0a9SSimon Glass  * @return 0 on success, -EINVAL if the property does not exist,
257644ec0a9SSimon Glass  * -ENODATA if property does not have a value, and -EOVERFLOW if the
258644ec0a9SSimon Glass  * property data isn't large enough.
259644ec0a9SSimon Glass  */
260644ec0a9SSimon Glass int of_read_u32(const struct device_node *np, const char *propname, u32 *outp);
261644ec0a9SSimon Glass 
262644ec0a9SSimon Glass /**
263d59cf5aeSJoseph Chen  * of_property_read_u64 - Find and read a 64 bit integer from a property
264d59cf5aeSJoseph Chen  * @np:         device node from which the property value is to be read.
265d59cf5aeSJoseph Chen  * @propname:   name of the property to be searched.
266d59cf5aeSJoseph Chen  * @out_value:  pointer to return value, modified only if return value is 0.
267d59cf5aeSJoseph Chen  *
268d59cf5aeSJoseph Chen  * Search for a property in a device node and read a 64-bit value from
269d59cf5aeSJoseph Chen  * it. Returns 0 on success, -EINVAL if the property does not exist,
270d59cf5aeSJoseph Chen  * -ENODATA if property does not have a value, and -EOVERFLOW if the
271d59cf5aeSJoseph Chen  * property data isn't large enough.
272d59cf5aeSJoseph Chen  *
273d59cf5aeSJoseph Chen  * The out_value is modified only if a valid u64 value can be decoded.
274d59cf5aeSJoseph Chen  */
275d59cf5aeSJoseph Chen int of_property_read_u64(const struct device_node *np, const char *propname,
276d59cf5aeSJoseph Chen                          u64 *out_value);
277d59cf5aeSJoseph Chen 
278d59cf5aeSJoseph Chen /**
279644ec0a9SSimon Glass  * of_read_u32_array() - Find and read an array of 32 bit integers
280644ec0a9SSimon Glass  *
281644ec0a9SSimon Glass  * Search for a property in a device node and read 32-bit value(s) from
282644ec0a9SSimon Glass  * it.
283644ec0a9SSimon Glass  *
284644ec0a9SSimon Glass  * @np:		device node from which the property value is to be read.
285644ec0a9SSimon Glass  * @propname:	name of the property to be searched.
286644ec0a9SSimon Glass  * @out_values:	pointer to return value, modified only if return value is 0.
287644ec0a9SSimon Glass  * @sz:		number of array elements to read
288644ec0a9SSimon Glass  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
289644ec0a9SSimon Glass  * if property does not have a value, and -EOVERFLOW is longer than sz.
290644ec0a9SSimon Glass  */
291644ec0a9SSimon Glass int of_read_u32_array(const struct device_node *np, const char *propname,
292644ec0a9SSimon Glass 		      u32 *out_values, size_t sz);
293644ec0a9SSimon Glass 
294644ec0a9SSimon Glass /**
29504539b46SJoseph Chen  * of_write_u32_array() - Find and write an array of 32 bit integers
29604539b46SJoseph Chen  *
29704539b46SJoseph Chen  * Search for a property in a device node and write 32-bit value(s) to
29804539b46SJoseph Chen  * it.
29904539b46SJoseph Chen  *
30004539b46SJoseph Chen  * @np:		device node from which the property value is to be read.
30104539b46SJoseph Chen  * @propname:	name of the property to be searched.
30204539b46SJoseph Chen  * @values:	pointer to update value, modified only if return value is 0.
30304539b46SJoseph Chen  * @sz:		number of array elements to read
30404539b46SJoseph Chen  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
30504539b46SJoseph Chen  * if property does not have a value, and -EOVERFLOW is longer than sz.
30604539b46SJoseph Chen  */
30704539b46SJoseph Chen int of_write_u32_array(const struct device_node *np, const char *propname,
30804539b46SJoseph Chen 		       u32 *values, size_t sz);
30904539b46SJoseph Chen 
31004539b46SJoseph Chen /**
311644ec0a9SSimon Glass  * of_property_match_string() - Find string in a list and return index
312644ec0a9SSimon Glass  *
313644ec0a9SSimon Glass  * This function searches a string list property and returns the index
314644ec0a9SSimon Glass  * of a specific string value.
315644ec0a9SSimon Glass  *
316644ec0a9SSimon Glass  * @np: pointer to node containing string list property
317644ec0a9SSimon Glass  * @propname: string list property name
318644ec0a9SSimon Glass  * @string: pointer to string to search for in string list
319644ec0a9SSimon Glass  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
320644ec0a9SSimon Glass  * if property does not have a value, and -EOVERFLOW is longer than sz.
321644ec0a9SSimon Glass  */
322644ec0a9SSimon Glass int of_property_match_string(const struct device_node *np, const char *propname,
323644ec0a9SSimon Glass 			     const char *string);
324644ec0a9SSimon Glass 
325644ec0a9SSimon Glass int of_property_read_string_helper(const struct device_node *np,
326644ec0a9SSimon Glass 				   const char *propname, const char **out_strs,
327644ec0a9SSimon Glass 				   size_t sz, int index);
328644ec0a9SSimon Glass 
329644ec0a9SSimon Glass /**
330644ec0a9SSimon Glass  * of_property_read_string_index() - Find and read a string from a multiple
331644ec0a9SSimon Glass  * strings property.
332644ec0a9SSimon Glass  * @np:		device node from which the property value is to be read.
333644ec0a9SSimon Glass  * @propname:	name of the property to be searched.
334644ec0a9SSimon Glass  * @index:	index of the string in the list of strings
335644ec0a9SSimon Glass  * @out_string:	pointer to null terminated return string, modified only if
336644ec0a9SSimon Glass  *		return value is 0.
337644ec0a9SSimon Glass  *
338644ec0a9SSimon Glass  * Search for a property in a device tree node and retrieve a null
339644ec0a9SSimon Glass  * terminated string value (pointer to data, not a copy) in the list of strings
340644ec0a9SSimon Glass  * contained in that property.
341644ec0a9SSimon Glass  * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
342644ec0a9SSimon Glass  * property does not have a value, and -EILSEQ if the string is not
343644ec0a9SSimon Glass  * null-terminated within the length of the property data.
344644ec0a9SSimon Glass  *
345644ec0a9SSimon Glass  * The out_string pointer is modified only if a valid string can be decoded.
346644ec0a9SSimon Glass  */
of_property_read_string_index(const struct device_node * np,const char * propname,int index,const char ** output)347644ec0a9SSimon Glass static inline int of_property_read_string_index(const struct device_node *np,
348644ec0a9SSimon Glass 						const char *propname,
349644ec0a9SSimon Glass 						int index, const char **output)
350644ec0a9SSimon Glass {
351644ec0a9SSimon Glass 	int rc = of_property_read_string_helper(np, propname, output, 1, index);
352644ec0a9SSimon Glass 	return rc < 0 ? rc : 0;
353644ec0a9SSimon Glass }
354644ec0a9SSimon Glass 
355644ec0a9SSimon Glass /**
3568c293d6aSSimon Glass  * of_property_count_strings() - Find and return the number of strings from a
3578c293d6aSSimon Glass  * multiple strings property.
3588c293d6aSSimon Glass  * @np:		device node from which the property value is to be read.
3598c293d6aSSimon Glass  * @propname:	name of the property to be searched.
3608c293d6aSSimon Glass  *
3618c293d6aSSimon Glass  * Search for a property in a device tree node and retrieve the number of null
3628c293d6aSSimon Glass  * terminated string contain in it. Returns the number of strings on
3638c293d6aSSimon Glass  * success, -EINVAL if the property does not exist, -ENODATA if property
3648c293d6aSSimon Glass  * does not have a value, and -EILSEQ if the string is not null-terminated
3658c293d6aSSimon Glass  * within the length of the property data.
3668c293d6aSSimon Glass  */
of_property_count_strings(const struct device_node * np,const char * propname)3678c293d6aSSimon Glass static inline int of_property_count_strings(const struct device_node *np,
3688c293d6aSSimon Glass 					    const char *propname)
3698c293d6aSSimon Glass {
3708c293d6aSSimon Glass 	return of_property_read_string_helper(np, propname, NULL, 0, 0);
3718c293d6aSSimon Glass }
3728c293d6aSSimon Glass 
3738c293d6aSSimon Glass /**
374644ec0a9SSimon Glass  * of_parse_phandle - Resolve a phandle property to a device_node pointer
375644ec0a9SSimon Glass  * @np: Pointer to device node holding phandle property
376644ec0a9SSimon Glass  * @phandle_name: Name of property holding a phandle value
377644ec0a9SSimon Glass  * @index: For properties holding a table of phandles, this is the index into
378644ec0a9SSimon Glass  *         the table
379644ec0a9SSimon Glass  *
380644ec0a9SSimon Glass  * Returns the device_node pointer with refcount incremented.  Use
381644ec0a9SSimon Glass  * of_node_put() on it when done.
382644ec0a9SSimon Glass  */
383644ec0a9SSimon Glass struct device_node *of_parse_phandle(const struct device_node *np,
384644ec0a9SSimon Glass 				     const char *phandle_name, int index);
385644ec0a9SSimon Glass 
386644ec0a9SSimon Glass /**
387644ec0a9SSimon Glass  * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
388644ec0a9SSimon Glass  *
389644ec0a9SSimon Glass  * @np:		pointer to a device tree node containing a list
390644ec0a9SSimon Glass  * @list_name:	property name that contains a list
391644ec0a9SSimon Glass  * @cells_name:	property name that specifies phandles' arguments count
392644ec0a9SSimon Glass  * @index:	index of a phandle to parse out
393644ec0a9SSimon Glass  * @out_args:	optional pointer to output arguments structure (will be filled)
394644ec0a9SSimon Glass  * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
395644ec0a9SSimon Glass  *	@list_name does not exist, -EINVAL if a phandle was not found,
396644ec0a9SSimon Glass  *	@cells_name could not be found, the arguments were truncated or there
397644ec0a9SSimon Glass  *	were too many arguments.
398644ec0a9SSimon Glass  *
399644ec0a9SSimon Glass  * This function is useful to parse lists of phandles and their arguments.
400644ec0a9SSimon Glass  * Returns 0 on success and fills out_args, on error returns appropriate
401644ec0a9SSimon Glass  * errno value.
402644ec0a9SSimon Glass  *
403644ec0a9SSimon Glass  * Caller is responsible to call of_node_put() on the returned out_args->np
404644ec0a9SSimon Glass  * pointer.
405644ec0a9SSimon Glass  *
406644ec0a9SSimon Glass  * Example:
407644ec0a9SSimon Glass  *
408644ec0a9SSimon Glass  * phandle1: node1 {
409644ec0a9SSimon Glass  *	#list-cells = <2>;
410644ec0a9SSimon Glass  * }
411644ec0a9SSimon Glass  *
412644ec0a9SSimon Glass  * phandle2: node2 {
413644ec0a9SSimon Glass  *	#list-cells = <1>;
414644ec0a9SSimon Glass  * }
415644ec0a9SSimon Glass  *
416644ec0a9SSimon Glass  * node3 {
417644ec0a9SSimon Glass  *	list = <&phandle1 1 2 &phandle2 3>;
418644ec0a9SSimon Glass  * }
419644ec0a9SSimon Glass  *
420644ec0a9SSimon Glass  * To get a device_node of the `node2' node you may call this:
421644ec0a9SSimon Glass  * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
422644ec0a9SSimon Glass  */
423644ec0a9SSimon Glass int of_parse_phandle_with_args(const struct device_node *np,
424644ec0a9SSimon Glass 			       const char *list_name, const char *cells_name,
425644ec0a9SSimon Glass 			       int index, struct of_phandle_args *out_args);
426644ec0a9SSimon Glass 
427644ec0a9SSimon Glass /**
428642346aeSPatrice Chotard  * of_count_phandle_with_args() - Count the number of phandle in a list
429642346aeSPatrice Chotard  *
430642346aeSPatrice Chotard  * @np:		pointer to a device tree node containing a list
431642346aeSPatrice Chotard  * @list_name:	property name that contains a list
432642346aeSPatrice Chotard  * @cells_name:	property name that specifies phandles' arguments count
433642346aeSPatrice Chotard  * @return number of phandle found, -ENOENT if
434642346aeSPatrice Chotard  *	@list_name does not exist, -EINVAL if a phandle was not found,
435642346aeSPatrice Chotard  *	@cells_name could not be found, the arguments were truncated or there
436642346aeSPatrice Chotard  *	were too many arguments.
437642346aeSPatrice Chotard  *
438642346aeSPatrice Chotard  * Returns number of phandle found on success, on error returns appropriate
439642346aeSPatrice Chotard  * errno value.
440642346aeSPatrice Chotard  *
441642346aeSPatrice Chotard  */
442642346aeSPatrice Chotard int of_count_phandle_with_args(const struct device_node *np,
443642346aeSPatrice Chotard 			       const char *list_name, const char *cells_name);
444642346aeSPatrice Chotard 
445642346aeSPatrice Chotard /**
446644ec0a9SSimon Glass  * of_alias_scan() - Scan all properties of the 'aliases' node
447644ec0a9SSimon Glass  *
448644ec0a9SSimon Glass  * The function scans all the properties of the 'aliases' node and populates
449644ec0a9SSimon Glass  * the lookup table with the properties.  It returns the number of alias
450644ec0a9SSimon Glass  * properties found, or an error code in case of failure.
451644ec0a9SSimon Glass  *
452644ec0a9SSimon Glass  * @return 9 if OK, -ENOMEM if not enough memory
453644ec0a9SSimon Glass  */
454644ec0a9SSimon Glass int of_alias_scan(void);
455644ec0a9SSimon Glass 
456644ec0a9SSimon Glass /**
457644ec0a9SSimon Glass  * of_alias_get_id - Get alias id for the given device_node
458644ec0a9SSimon Glass  *
459644ec0a9SSimon Glass  * Travels the lookup table to get the alias id for the given device_node and
460644ec0a9SSimon Glass  * alias stem.
461644ec0a9SSimon Glass  *
462644ec0a9SSimon Glass  * @np:		Pointer to the given device_node
463644ec0a9SSimon Glass  * @stem:	Alias stem of the given device_node
464644ec0a9SSimon Glass  * @return alias ID, if found, else -ENODEV
465644ec0a9SSimon Glass  */
466644ec0a9SSimon Glass int of_alias_get_id(const struct device_node *np, const char *stem);
467644ec0a9SSimon Glass 
468644ec0a9SSimon Glass /**
4692e02c4e2SJoseph Chen  * of_alias_get_dev - Get device_node by given stem and alias id
4702e02c4e2SJoseph Chen  *
4712e02c4e2SJoseph Chen  * Travels the lookup table to get the device_node by given stem and alias id.
4722e02c4e2SJoseph Chen  *
4732e02c4e2SJoseph Chen  * @stem:	Alias stem of the given device_node
4742e02c4e2SJoseph Chen  * @id:         Alias id of the given device_node
4752e02c4e2SJoseph Chen  * @return device_node, if found, else NULL
4762e02c4e2SJoseph Chen  */
4772e02c4e2SJoseph Chen struct device_node *of_alias_get_dev(const char *stem, int id);
4782e02c4e2SJoseph Chen 
4792e02c4e2SJoseph Chen /**
4802e02c4e2SJoseph Chen  * of_alias_dump - Dump of alias nodes added in aliases_lookup.
4812e02c4e2SJoseph Chen  */
4822e02c4e2SJoseph Chen struct device_node *of_alias_dump(void);
4832e02c4e2SJoseph Chen 
4842e02c4e2SJoseph Chen /**
485644ec0a9SSimon Glass  * of_get_stdout() - Get node to use for stdout
486644ec0a9SSimon Glass  *
487644ec0a9SSimon Glass  * @return node referred to by stdout-path alias, or NULL if none
488644ec0a9SSimon Glass  */
489644ec0a9SSimon Glass struct device_node *of_get_stdout(void);
490644ec0a9SSimon Glass 
491644ec0a9SSimon Glass #endif
492