xref: /OK3568_Linux_fs/kernel/include/linux/of.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun #ifndef _LINUX_OF_H
3*4882a593Smuzhiyun #define _LINUX_OF_H
4*4882a593Smuzhiyun /*
5*4882a593Smuzhiyun  * Definitions for talking to the Open Firmware PROM on
6*4882a593Smuzhiyun  * Power Macintosh and other computers.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (C) 1996-2005 Paul Mackerras.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
11*4882a593Smuzhiyun  * Updates for SPARC64 by David S. Miller
12*4882a593Smuzhiyun  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun #include <linux/types.h>
15*4882a593Smuzhiyun #include <linux/bitops.h>
16*4882a593Smuzhiyun #include <linux/errno.h>
17*4882a593Smuzhiyun #include <linux/kobject.h>
18*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
19*4882a593Smuzhiyun #include <linux/spinlock.h>
20*4882a593Smuzhiyun #include <linux/topology.h>
21*4882a593Smuzhiyun #include <linux/notifier.h>
22*4882a593Smuzhiyun #include <linux/property.h>
23*4882a593Smuzhiyun #include <linux/list.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #include <asm/byteorder.h>
26*4882a593Smuzhiyun #include <asm/errno.h>
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun typedef u32 phandle;
29*4882a593Smuzhiyun typedef u32 ihandle;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun struct property {
32*4882a593Smuzhiyun 	char	*name;
33*4882a593Smuzhiyun 	int	length;
34*4882a593Smuzhiyun 	void	*value;
35*4882a593Smuzhiyun 	struct property *next;
36*4882a593Smuzhiyun #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
37*4882a593Smuzhiyun 	unsigned long _flags;
38*4882a593Smuzhiyun #endif
39*4882a593Smuzhiyun #if defined(CONFIG_OF_PROMTREE)
40*4882a593Smuzhiyun 	unsigned int unique_id;
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun #if defined(CONFIG_OF_KOBJ)
43*4882a593Smuzhiyun 	struct bin_attribute attr;
44*4882a593Smuzhiyun #endif
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #if defined(CONFIG_SPARC)
48*4882a593Smuzhiyun struct of_irq_controller;
49*4882a593Smuzhiyun #endif
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun struct device_node {
52*4882a593Smuzhiyun 	const char *name;
53*4882a593Smuzhiyun 	phandle phandle;
54*4882a593Smuzhiyun 	const char *full_name;
55*4882a593Smuzhiyun 	struct fwnode_handle fwnode;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	struct	property *properties;
58*4882a593Smuzhiyun 	struct	property *deadprops;	/* removed properties */
59*4882a593Smuzhiyun 	struct	device_node *parent;
60*4882a593Smuzhiyun 	struct	device_node *child;
61*4882a593Smuzhiyun 	struct	device_node *sibling;
62*4882a593Smuzhiyun #if defined(CONFIG_OF_KOBJ)
63*4882a593Smuzhiyun 	struct	kobject kobj;
64*4882a593Smuzhiyun #endif
65*4882a593Smuzhiyun 	unsigned long _flags;
66*4882a593Smuzhiyun 	void	*data;
67*4882a593Smuzhiyun #if defined(CONFIG_SPARC)
68*4882a593Smuzhiyun 	unsigned int unique_id;
69*4882a593Smuzhiyun 	struct of_irq_controller *irq_trans;
70*4882a593Smuzhiyun #endif
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define MAX_PHANDLE_ARGS 16
74*4882a593Smuzhiyun struct of_phandle_args {
75*4882a593Smuzhiyun 	struct device_node *np;
76*4882a593Smuzhiyun 	int args_count;
77*4882a593Smuzhiyun 	uint32_t args[MAX_PHANDLE_ARGS];
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun struct of_phandle_iterator {
81*4882a593Smuzhiyun 	/* Common iterator information */
82*4882a593Smuzhiyun 	const char *cells_name;
83*4882a593Smuzhiyun 	int cell_count;
84*4882a593Smuzhiyun 	const struct device_node *parent;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	/* List size information */
87*4882a593Smuzhiyun 	const __be32 *list_end;
88*4882a593Smuzhiyun 	const __be32 *phandle_end;
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	/* Current position state */
91*4882a593Smuzhiyun 	const __be32 *cur;
92*4882a593Smuzhiyun 	uint32_t cur_count;
93*4882a593Smuzhiyun 	phandle phandle;
94*4882a593Smuzhiyun 	struct device_node *node;
95*4882a593Smuzhiyun };
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun struct of_reconfig_data {
98*4882a593Smuzhiyun 	struct device_node	*dn;
99*4882a593Smuzhiyun 	struct property		*prop;
100*4882a593Smuzhiyun 	struct property		*old_prop;
101*4882a593Smuzhiyun };
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /* initialize a node */
104*4882a593Smuzhiyun extern struct kobj_type of_node_ktype;
105*4882a593Smuzhiyun extern const struct fwnode_operations of_fwnode_ops;
of_node_init(struct device_node * node)106*4882a593Smuzhiyun static inline void of_node_init(struct device_node *node)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun #if defined(CONFIG_OF_KOBJ)
109*4882a593Smuzhiyun 	kobject_init(&node->kobj, &of_node_ktype);
110*4882a593Smuzhiyun #endif
111*4882a593Smuzhiyun 	fwnode_init(&node->fwnode, &of_fwnode_ops);
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #if defined(CONFIG_OF_KOBJ)
115*4882a593Smuzhiyun #define of_node_kobj(n) (&(n)->kobj)
116*4882a593Smuzhiyun #else
117*4882a593Smuzhiyun #define of_node_kobj(n) NULL
118*4882a593Smuzhiyun #endif
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun #ifdef CONFIG_OF_DYNAMIC
121*4882a593Smuzhiyun extern struct device_node *of_node_get(struct device_node *node);
122*4882a593Smuzhiyun extern void of_node_put(struct device_node *node);
123*4882a593Smuzhiyun #else /* CONFIG_OF_DYNAMIC */
124*4882a593Smuzhiyun /* Dummy ref counting routines - to be implemented later */
of_node_get(struct device_node * node)125*4882a593Smuzhiyun static inline struct device_node *of_node_get(struct device_node *node)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun 	return node;
128*4882a593Smuzhiyun }
of_node_put(struct device_node * node)129*4882a593Smuzhiyun static inline void of_node_put(struct device_node *node) { }
130*4882a593Smuzhiyun #endif /* !CONFIG_OF_DYNAMIC */
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun /* Pointer for first entry in chain of all nodes. */
133*4882a593Smuzhiyun extern struct device_node *of_root;
134*4882a593Smuzhiyun extern struct device_node *of_chosen;
135*4882a593Smuzhiyun extern struct device_node *of_aliases;
136*4882a593Smuzhiyun extern struct device_node *of_stdout;
137*4882a593Smuzhiyun extern raw_spinlock_t devtree_lock;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /*
140*4882a593Smuzhiyun  * struct device_node flag descriptions
141*4882a593Smuzhiyun  * (need to be visible even when !CONFIG_OF)
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun #define OF_DYNAMIC		1 /* (and properties) allocated via kmalloc */
144*4882a593Smuzhiyun #define OF_DETACHED		2 /* detached from the device tree */
145*4882a593Smuzhiyun #define OF_POPULATED		3 /* device already created */
146*4882a593Smuzhiyun #define OF_POPULATED_BUS	4 /* platform bus created for children */
147*4882a593Smuzhiyun #define OF_OVERLAY		5 /* allocated for an overlay */
148*4882a593Smuzhiyun #define OF_OVERLAY_FREE_CSET	6 /* in overlay cset being freed */
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun #define OF_BAD_ADDR	((u64)-1)
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun #ifdef CONFIG_OF
153*4882a593Smuzhiyun void of_core_init(void);
154*4882a593Smuzhiyun 
is_of_node(const struct fwnode_handle * fwnode)155*4882a593Smuzhiyun static inline bool is_of_node(const struct fwnode_handle *fwnode)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun 	return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun #define to_of_node(__fwnode)						\
161*4882a593Smuzhiyun 	({								\
162*4882a593Smuzhiyun 		typeof(__fwnode) __to_of_node_fwnode = (__fwnode);	\
163*4882a593Smuzhiyun 									\
164*4882a593Smuzhiyun 		is_of_node(__to_of_node_fwnode) ?			\
165*4882a593Smuzhiyun 			container_of(__to_of_node_fwnode,		\
166*4882a593Smuzhiyun 				     struct device_node, fwnode) :	\
167*4882a593Smuzhiyun 			NULL;						\
168*4882a593Smuzhiyun 	})
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun #define of_fwnode_handle(node)						\
171*4882a593Smuzhiyun 	({								\
172*4882a593Smuzhiyun 		typeof(node) __of_fwnode_handle_node = (node);		\
173*4882a593Smuzhiyun 									\
174*4882a593Smuzhiyun 		__of_fwnode_handle_node ?				\
175*4882a593Smuzhiyun 			&__of_fwnode_handle_node->fwnode : NULL;	\
176*4882a593Smuzhiyun 	})
177*4882a593Smuzhiyun 
of_have_populated_dt(void)178*4882a593Smuzhiyun static inline bool of_have_populated_dt(void)
179*4882a593Smuzhiyun {
180*4882a593Smuzhiyun 	return of_root != NULL;
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun 
of_node_is_root(const struct device_node * node)183*4882a593Smuzhiyun static inline bool of_node_is_root(const struct device_node *node)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun 	return node && (node->parent == NULL);
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun 
of_node_check_flag(struct device_node * n,unsigned long flag)188*4882a593Smuzhiyun static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun 	return test_bit(flag, &n->_flags);
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun 
of_node_test_and_set_flag(struct device_node * n,unsigned long flag)193*4882a593Smuzhiyun static inline int of_node_test_and_set_flag(struct device_node *n,
194*4882a593Smuzhiyun 					    unsigned long flag)
195*4882a593Smuzhiyun {
196*4882a593Smuzhiyun 	return test_and_set_bit(flag, &n->_flags);
197*4882a593Smuzhiyun }
198*4882a593Smuzhiyun 
of_node_set_flag(struct device_node * n,unsigned long flag)199*4882a593Smuzhiyun static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun 	set_bit(flag, &n->_flags);
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun 
of_node_clear_flag(struct device_node * n,unsigned long flag)204*4882a593Smuzhiyun static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun 	clear_bit(flag, &n->_flags);
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
of_property_check_flag(struct property * p,unsigned long flag)210*4882a593Smuzhiyun static inline int of_property_check_flag(struct property *p, unsigned long flag)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun 	return test_bit(flag, &p->_flags);
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun 
of_property_set_flag(struct property * p,unsigned long flag)215*4882a593Smuzhiyun static inline void of_property_set_flag(struct property *p, unsigned long flag)
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun 	set_bit(flag, &p->_flags);
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun 
of_property_clear_flag(struct property * p,unsigned long flag)220*4882a593Smuzhiyun static inline void of_property_clear_flag(struct property *p, unsigned long flag)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun 	clear_bit(flag, &p->_flags);
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun #endif
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun extern struct device_node *__of_find_all_nodes(struct device_node *prev);
227*4882a593Smuzhiyun extern struct device_node *of_find_all_nodes(struct device_node *prev);
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun /*
230*4882a593Smuzhiyun  * OF address retrieval & translation
231*4882a593Smuzhiyun  */
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun /* Helper to read a big number; size is in cells (not bytes) */
of_read_number(const __be32 * cell,int size)234*4882a593Smuzhiyun static inline u64 of_read_number(const __be32 *cell, int size)
235*4882a593Smuzhiyun {
236*4882a593Smuzhiyun 	u64 r = 0;
237*4882a593Smuzhiyun 	for (; size--; cell++)
238*4882a593Smuzhiyun 		r = (r << 32) | be32_to_cpu(*cell);
239*4882a593Smuzhiyun 	return r;
240*4882a593Smuzhiyun }
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun /* Like of_read_number, but we want an unsigned long result */
of_read_ulong(const __be32 * cell,int size)243*4882a593Smuzhiyun static inline unsigned long of_read_ulong(const __be32 *cell, int size)
244*4882a593Smuzhiyun {
245*4882a593Smuzhiyun 	/* toss away upper bits if unsigned long is smaller than u64 */
246*4882a593Smuzhiyun 	return of_read_number(cell, size);
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun #if defined(CONFIG_SPARC)
250*4882a593Smuzhiyun #include <asm/prom.h>
251*4882a593Smuzhiyun #endif
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
254*4882a593Smuzhiyun #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun extern bool of_node_name_eq(const struct device_node *np, const char *name);
257*4882a593Smuzhiyun extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
258*4882a593Smuzhiyun 
of_node_full_name(const struct device_node * np)259*4882a593Smuzhiyun static inline const char *of_node_full_name(const struct device_node *np)
260*4882a593Smuzhiyun {
261*4882a593Smuzhiyun 	return np ? np->full_name : "<no-node>";
262*4882a593Smuzhiyun }
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun #define for_each_of_allnodes_from(from, dn) \
265*4882a593Smuzhiyun 	for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
266*4882a593Smuzhiyun #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
267*4882a593Smuzhiyun extern struct device_node *of_find_node_by_name(struct device_node *from,
268*4882a593Smuzhiyun 	const char *name);
269*4882a593Smuzhiyun extern struct device_node *of_find_node_by_type(struct device_node *from,
270*4882a593Smuzhiyun 	const char *type);
271*4882a593Smuzhiyun extern struct device_node *of_find_compatible_node(struct device_node *from,
272*4882a593Smuzhiyun 	const char *type, const char *compat);
273*4882a593Smuzhiyun extern struct device_node *of_find_matching_node_and_match(
274*4882a593Smuzhiyun 	struct device_node *from,
275*4882a593Smuzhiyun 	const struct of_device_id *matches,
276*4882a593Smuzhiyun 	const struct of_device_id **match);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun extern struct device_node *of_find_node_opts_by_path(const char *path,
279*4882a593Smuzhiyun 	const char **opts);
of_find_node_by_path(const char * path)280*4882a593Smuzhiyun static inline struct device_node *of_find_node_by_path(const char *path)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun 	return of_find_node_opts_by_path(path, NULL);
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun extern struct device_node *of_find_node_by_phandle(phandle handle);
286*4882a593Smuzhiyun extern struct device_node *of_get_parent(const struct device_node *node);
287*4882a593Smuzhiyun extern struct device_node *of_get_next_parent(struct device_node *node);
288*4882a593Smuzhiyun extern struct device_node *of_get_next_child(const struct device_node *node,
289*4882a593Smuzhiyun 					     struct device_node *prev);
290*4882a593Smuzhiyun extern struct device_node *of_get_next_available_child(
291*4882a593Smuzhiyun 	const struct device_node *node, struct device_node *prev);
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun extern struct device_node *of_get_compatible_child(const struct device_node *parent,
294*4882a593Smuzhiyun 					const char *compatible);
295*4882a593Smuzhiyun extern struct device_node *of_get_child_by_name(const struct device_node *node,
296*4882a593Smuzhiyun 					const char *name);
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun /* cache lookup */
299*4882a593Smuzhiyun extern struct device_node *of_find_next_cache_node(const struct device_node *);
300*4882a593Smuzhiyun extern int of_find_last_cache_level(unsigned int cpu);
301*4882a593Smuzhiyun extern struct device_node *of_find_node_with_property(
302*4882a593Smuzhiyun 	struct device_node *from, const char *prop_name);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun extern struct property *of_find_property(const struct device_node *np,
305*4882a593Smuzhiyun 					 const char *name,
306*4882a593Smuzhiyun 					 int *lenp);
307*4882a593Smuzhiyun extern int of_property_count_elems_of_size(const struct device_node *np,
308*4882a593Smuzhiyun 				const char *propname, int elem_size);
309*4882a593Smuzhiyun extern int of_property_read_u32_index(const struct device_node *np,
310*4882a593Smuzhiyun 				       const char *propname,
311*4882a593Smuzhiyun 				       u32 index, u32 *out_value);
312*4882a593Smuzhiyun extern int of_property_read_u64_index(const struct device_node *np,
313*4882a593Smuzhiyun 				       const char *propname,
314*4882a593Smuzhiyun 				       u32 index, u64 *out_value);
315*4882a593Smuzhiyun extern int of_property_read_variable_u8_array(const struct device_node *np,
316*4882a593Smuzhiyun 					const char *propname, u8 *out_values,
317*4882a593Smuzhiyun 					size_t sz_min, size_t sz_max);
318*4882a593Smuzhiyun extern int of_property_read_variable_u16_array(const struct device_node *np,
319*4882a593Smuzhiyun 					const char *propname, u16 *out_values,
320*4882a593Smuzhiyun 					size_t sz_min, size_t sz_max);
321*4882a593Smuzhiyun extern int of_property_read_variable_u32_array(const struct device_node *np,
322*4882a593Smuzhiyun 					const char *propname,
323*4882a593Smuzhiyun 					u32 *out_values,
324*4882a593Smuzhiyun 					size_t sz_min,
325*4882a593Smuzhiyun 					size_t sz_max);
326*4882a593Smuzhiyun extern int of_property_read_u64(const struct device_node *np,
327*4882a593Smuzhiyun 				const char *propname, u64 *out_value);
328*4882a593Smuzhiyun extern int of_property_read_variable_u64_array(const struct device_node *np,
329*4882a593Smuzhiyun 					const char *propname,
330*4882a593Smuzhiyun 					u64 *out_values,
331*4882a593Smuzhiyun 					size_t sz_min,
332*4882a593Smuzhiyun 					size_t sz_max);
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun extern int of_property_read_string(const struct device_node *np,
335*4882a593Smuzhiyun 				   const char *propname,
336*4882a593Smuzhiyun 				   const char **out_string);
337*4882a593Smuzhiyun extern int of_property_match_string(const struct device_node *np,
338*4882a593Smuzhiyun 				    const char *propname,
339*4882a593Smuzhiyun 				    const char *string);
340*4882a593Smuzhiyun extern int of_property_read_string_helper(const struct device_node *np,
341*4882a593Smuzhiyun 					      const char *propname,
342*4882a593Smuzhiyun 					      const char **out_strs, size_t sz, int index);
343*4882a593Smuzhiyun extern int of_device_is_compatible(const struct device_node *device,
344*4882a593Smuzhiyun 				   const char *);
345*4882a593Smuzhiyun extern int of_device_compatible_match(struct device_node *device,
346*4882a593Smuzhiyun 				      const char *const *compat);
347*4882a593Smuzhiyun extern bool of_device_is_available(const struct device_node *device);
348*4882a593Smuzhiyun extern bool of_device_is_big_endian(const struct device_node *device);
349*4882a593Smuzhiyun extern const void *of_get_property(const struct device_node *node,
350*4882a593Smuzhiyun 				const char *name,
351*4882a593Smuzhiyun 				int *lenp);
352*4882a593Smuzhiyun extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
353*4882a593Smuzhiyun extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
354*4882a593Smuzhiyun extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
355*4882a593Smuzhiyun 						 int index);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun #define for_each_property_of_node(dn, pp) \
358*4882a593Smuzhiyun 	for (pp = dn->properties; pp != NULL; pp = pp->next)
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun extern int of_n_addr_cells(struct device_node *np);
361*4882a593Smuzhiyun extern int of_n_size_cells(struct device_node *np);
362*4882a593Smuzhiyun extern const struct of_device_id *of_match_node(
363*4882a593Smuzhiyun 	const struct of_device_id *matches, const struct device_node *node);
364*4882a593Smuzhiyun extern int of_modalias_node(struct device_node *node, char *modalias, int len);
365*4882a593Smuzhiyun extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
366*4882a593Smuzhiyun extern struct device_node *of_parse_phandle(const struct device_node *np,
367*4882a593Smuzhiyun 					    const char *phandle_name,
368*4882a593Smuzhiyun 					    int index);
369*4882a593Smuzhiyun extern int of_parse_phandle_with_args(const struct device_node *np,
370*4882a593Smuzhiyun 	const char *list_name, const char *cells_name, int index,
371*4882a593Smuzhiyun 	struct of_phandle_args *out_args);
372*4882a593Smuzhiyun extern int of_parse_phandle_with_args_map(const struct device_node *np,
373*4882a593Smuzhiyun 	const char *list_name, const char *stem_name, int index,
374*4882a593Smuzhiyun 	struct of_phandle_args *out_args);
375*4882a593Smuzhiyun extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
376*4882a593Smuzhiyun 	const char *list_name, int cells_count, int index,
377*4882a593Smuzhiyun 	struct of_phandle_args *out_args);
378*4882a593Smuzhiyun extern int of_count_phandle_with_args(const struct device_node *np,
379*4882a593Smuzhiyun 	const char *list_name, const char *cells_name);
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun /* phandle iterator functions */
382*4882a593Smuzhiyun extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
383*4882a593Smuzhiyun 				    const struct device_node *np,
384*4882a593Smuzhiyun 				    const char *list_name,
385*4882a593Smuzhiyun 				    const char *cells_name,
386*4882a593Smuzhiyun 				    int cell_count);
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
389*4882a593Smuzhiyun extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
390*4882a593Smuzhiyun 				    uint32_t *args,
391*4882a593Smuzhiyun 				    int size);
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
394*4882a593Smuzhiyun extern int of_alias_get_id(struct device_node *np, const char *stem);
395*4882a593Smuzhiyun extern int of_alias_get_highest_id(const char *stem);
396*4882a593Smuzhiyun extern int of_alias_get_alias_list(const struct of_device_id *matches,
397*4882a593Smuzhiyun 				   const char *stem, unsigned long *bitmap,
398*4882a593Smuzhiyun 				   unsigned int nbits);
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun extern int of_machine_is_compatible(const char *compat);
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun extern int of_add_property(struct device_node *np, struct property *prop);
403*4882a593Smuzhiyun extern int of_remove_property(struct device_node *np, struct property *prop);
404*4882a593Smuzhiyun extern int of_update_property(struct device_node *np, struct property *newprop);
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun /* For updating the device tree at runtime */
407*4882a593Smuzhiyun #define OF_RECONFIG_ATTACH_NODE		0x0001
408*4882a593Smuzhiyun #define OF_RECONFIG_DETACH_NODE		0x0002
409*4882a593Smuzhiyun #define OF_RECONFIG_ADD_PROPERTY	0x0003
410*4882a593Smuzhiyun #define OF_RECONFIG_REMOVE_PROPERTY	0x0004
411*4882a593Smuzhiyun #define OF_RECONFIG_UPDATE_PROPERTY	0x0005
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun extern int of_attach_node(struct device_node *);
414*4882a593Smuzhiyun extern int of_detach_node(struct device_node *);
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun #define of_match_ptr(_ptr)	(_ptr)
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun /**
419*4882a593Smuzhiyun  * of_property_read_u8_array - Find and read an array of u8 from a property.
420*4882a593Smuzhiyun  *
421*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
422*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
423*4882a593Smuzhiyun  * @out_values:	pointer to return value, modified only if return value is 0.
424*4882a593Smuzhiyun  * @sz:		number of array elements to read
425*4882a593Smuzhiyun  *
426*4882a593Smuzhiyun  * Search for a property in a device node and read 8-bit value(s) from
427*4882a593Smuzhiyun  * it. Returns 0 on success, -EINVAL if the property does not exist,
428*4882a593Smuzhiyun  * -ENODATA if property does not have a value, and -EOVERFLOW if the
429*4882a593Smuzhiyun  * property data isn't large enough.
430*4882a593Smuzhiyun  *
431*4882a593Smuzhiyun  * dts entry of array should be like:
432*4882a593Smuzhiyun  *	property = /bits/ 8 <0x50 0x60 0x70>;
433*4882a593Smuzhiyun  *
434*4882a593Smuzhiyun  * The out_values is modified only if a valid u8 value can be decoded.
435*4882a593Smuzhiyun  */
of_property_read_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz)436*4882a593Smuzhiyun static inline int of_property_read_u8_array(const struct device_node *np,
437*4882a593Smuzhiyun 					    const char *propname,
438*4882a593Smuzhiyun 					    u8 *out_values, size_t sz)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun 	int ret = of_property_read_variable_u8_array(np, propname, out_values,
441*4882a593Smuzhiyun 						     sz, 0);
442*4882a593Smuzhiyun 	if (ret >= 0)
443*4882a593Smuzhiyun 		return 0;
444*4882a593Smuzhiyun 	else
445*4882a593Smuzhiyun 		return ret;
446*4882a593Smuzhiyun }
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun /**
449*4882a593Smuzhiyun  * of_property_read_u16_array - Find and read an array of u16 from a property.
450*4882a593Smuzhiyun  *
451*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
452*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
453*4882a593Smuzhiyun  * @out_values:	pointer to return value, modified only if return value is 0.
454*4882a593Smuzhiyun  * @sz:		number of array elements to read
455*4882a593Smuzhiyun  *
456*4882a593Smuzhiyun  * Search for a property in a device node and read 16-bit value(s) from
457*4882a593Smuzhiyun  * it. Returns 0 on success, -EINVAL if the property does not exist,
458*4882a593Smuzhiyun  * -ENODATA if property does not have a value, and -EOVERFLOW if the
459*4882a593Smuzhiyun  * property data isn't large enough.
460*4882a593Smuzhiyun  *
461*4882a593Smuzhiyun  * dts entry of array should be like:
462*4882a593Smuzhiyun  *	property = /bits/ 16 <0x5000 0x6000 0x7000>;
463*4882a593Smuzhiyun  *
464*4882a593Smuzhiyun  * The out_values is modified only if a valid u16 value can be decoded.
465*4882a593Smuzhiyun  */
of_property_read_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz)466*4882a593Smuzhiyun static inline int of_property_read_u16_array(const struct device_node *np,
467*4882a593Smuzhiyun 					     const char *propname,
468*4882a593Smuzhiyun 					     u16 *out_values, size_t sz)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun 	int ret = of_property_read_variable_u16_array(np, propname, out_values,
471*4882a593Smuzhiyun 						      sz, 0);
472*4882a593Smuzhiyun 	if (ret >= 0)
473*4882a593Smuzhiyun 		return 0;
474*4882a593Smuzhiyun 	else
475*4882a593Smuzhiyun 		return ret;
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun 
478*4882a593Smuzhiyun /**
479*4882a593Smuzhiyun  * of_property_read_u32_array - Find and read an array of 32 bit integers
480*4882a593Smuzhiyun  * from a property.
481*4882a593Smuzhiyun  *
482*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
483*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
484*4882a593Smuzhiyun  * @out_values:	pointer to return value, modified only if return value is 0.
485*4882a593Smuzhiyun  * @sz:		number of array elements to read
486*4882a593Smuzhiyun  *
487*4882a593Smuzhiyun  * Search for a property in a device node and read 32-bit value(s) from
488*4882a593Smuzhiyun  * it. Returns 0 on success, -EINVAL if the property does not exist,
489*4882a593Smuzhiyun  * -ENODATA if property does not have a value, and -EOVERFLOW if the
490*4882a593Smuzhiyun  * property data isn't large enough.
491*4882a593Smuzhiyun  *
492*4882a593Smuzhiyun  * The out_values is modified only if a valid u32 value can be decoded.
493*4882a593Smuzhiyun  */
of_property_read_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz)494*4882a593Smuzhiyun static inline int of_property_read_u32_array(const struct device_node *np,
495*4882a593Smuzhiyun 					     const char *propname,
496*4882a593Smuzhiyun 					     u32 *out_values, size_t sz)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun 	int ret = of_property_read_variable_u32_array(np, propname, out_values,
499*4882a593Smuzhiyun 						      sz, 0);
500*4882a593Smuzhiyun 	if (ret >= 0)
501*4882a593Smuzhiyun 		return 0;
502*4882a593Smuzhiyun 	else
503*4882a593Smuzhiyun 		return ret;
504*4882a593Smuzhiyun }
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun /**
507*4882a593Smuzhiyun  * of_property_read_u64_array - Find and read an array of 64 bit integers
508*4882a593Smuzhiyun  * from a property.
509*4882a593Smuzhiyun  *
510*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
511*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
512*4882a593Smuzhiyun  * @out_values:	pointer to return value, modified only if return value is 0.
513*4882a593Smuzhiyun  * @sz:		number of array elements to read
514*4882a593Smuzhiyun  *
515*4882a593Smuzhiyun  * Search for a property in a device node and read 64-bit value(s) from
516*4882a593Smuzhiyun  * it. Returns 0 on success, -EINVAL if the property does not exist,
517*4882a593Smuzhiyun  * -ENODATA if property does not have a value, and -EOVERFLOW if the
518*4882a593Smuzhiyun  * property data isn't large enough.
519*4882a593Smuzhiyun  *
520*4882a593Smuzhiyun  * The out_values is modified only if a valid u64 value can be decoded.
521*4882a593Smuzhiyun  */
of_property_read_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz)522*4882a593Smuzhiyun static inline int of_property_read_u64_array(const struct device_node *np,
523*4882a593Smuzhiyun 					     const char *propname,
524*4882a593Smuzhiyun 					     u64 *out_values, size_t sz)
525*4882a593Smuzhiyun {
526*4882a593Smuzhiyun 	int ret = of_property_read_variable_u64_array(np, propname, out_values,
527*4882a593Smuzhiyun 						      sz, 0);
528*4882a593Smuzhiyun 	if (ret >= 0)
529*4882a593Smuzhiyun 		return 0;
530*4882a593Smuzhiyun 	else
531*4882a593Smuzhiyun 		return ret;
532*4882a593Smuzhiyun }
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun /*
535*4882a593Smuzhiyun  * struct property *prop;
536*4882a593Smuzhiyun  * const __be32 *p;
537*4882a593Smuzhiyun  * u32 u;
538*4882a593Smuzhiyun  *
539*4882a593Smuzhiyun  * of_property_for_each_u32(np, "propname", prop, p, u)
540*4882a593Smuzhiyun  *         printk("U32 value: %x\n", u);
541*4882a593Smuzhiyun  */
542*4882a593Smuzhiyun const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
543*4882a593Smuzhiyun 			       u32 *pu);
544*4882a593Smuzhiyun /*
545*4882a593Smuzhiyun  * struct property *prop;
546*4882a593Smuzhiyun  * const char *s;
547*4882a593Smuzhiyun  *
548*4882a593Smuzhiyun  * of_property_for_each_string(np, "propname", prop, s)
549*4882a593Smuzhiyun  *         printk("String value: %s\n", s);
550*4882a593Smuzhiyun  */
551*4882a593Smuzhiyun const char *of_prop_next_string(struct property *prop, const char *cur);
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun bool of_console_check(struct device_node *dn, char *name, int index);
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun extern int of_cpu_node_to_id(struct device_node *np);
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun int of_map_id(struct device_node *np, u32 id,
558*4882a593Smuzhiyun 	       const char *map_name, const char *map_mask_name,
559*4882a593Smuzhiyun 	       struct device_node **target, u32 *id_out);
560*4882a593Smuzhiyun 
561*4882a593Smuzhiyun phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
562*4882a593Smuzhiyun 
563*4882a593Smuzhiyun #else /* CONFIG_OF */
564*4882a593Smuzhiyun 
of_core_init(void)565*4882a593Smuzhiyun static inline void of_core_init(void)
566*4882a593Smuzhiyun {
567*4882a593Smuzhiyun }
568*4882a593Smuzhiyun 
is_of_node(const struct fwnode_handle * fwnode)569*4882a593Smuzhiyun static inline bool is_of_node(const struct fwnode_handle *fwnode)
570*4882a593Smuzhiyun {
571*4882a593Smuzhiyun 	return false;
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun 
to_of_node(const struct fwnode_handle * fwnode)574*4882a593Smuzhiyun static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
575*4882a593Smuzhiyun {
576*4882a593Smuzhiyun 	return NULL;
577*4882a593Smuzhiyun }
578*4882a593Smuzhiyun 
of_node_name_eq(const struct device_node * np,const char * name)579*4882a593Smuzhiyun static inline bool of_node_name_eq(const struct device_node *np, const char *name)
580*4882a593Smuzhiyun {
581*4882a593Smuzhiyun 	return false;
582*4882a593Smuzhiyun }
583*4882a593Smuzhiyun 
of_node_name_prefix(const struct device_node * np,const char * prefix)584*4882a593Smuzhiyun static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
585*4882a593Smuzhiyun {
586*4882a593Smuzhiyun 	return false;
587*4882a593Smuzhiyun }
588*4882a593Smuzhiyun 
of_node_full_name(const struct device_node * np)589*4882a593Smuzhiyun static inline const char* of_node_full_name(const struct device_node *np)
590*4882a593Smuzhiyun {
591*4882a593Smuzhiyun 	return "<no-node>";
592*4882a593Smuzhiyun }
593*4882a593Smuzhiyun 
of_find_node_by_name(struct device_node * from,const char * name)594*4882a593Smuzhiyun static inline struct device_node *of_find_node_by_name(struct device_node *from,
595*4882a593Smuzhiyun 	const char *name)
596*4882a593Smuzhiyun {
597*4882a593Smuzhiyun 	return NULL;
598*4882a593Smuzhiyun }
599*4882a593Smuzhiyun 
of_find_node_by_type(struct device_node * from,const char * type)600*4882a593Smuzhiyun static inline struct device_node *of_find_node_by_type(struct device_node *from,
601*4882a593Smuzhiyun 	const char *type)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun 	return NULL;
604*4882a593Smuzhiyun }
605*4882a593Smuzhiyun 
of_find_matching_node_and_match(struct device_node * from,const struct of_device_id * matches,const struct of_device_id ** match)606*4882a593Smuzhiyun static inline struct device_node *of_find_matching_node_and_match(
607*4882a593Smuzhiyun 	struct device_node *from,
608*4882a593Smuzhiyun 	const struct of_device_id *matches,
609*4882a593Smuzhiyun 	const struct of_device_id **match)
610*4882a593Smuzhiyun {
611*4882a593Smuzhiyun 	return NULL;
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun 
of_find_node_by_path(const char * path)614*4882a593Smuzhiyun static inline struct device_node *of_find_node_by_path(const char *path)
615*4882a593Smuzhiyun {
616*4882a593Smuzhiyun 	return NULL;
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun 
of_find_node_opts_by_path(const char * path,const char ** opts)619*4882a593Smuzhiyun static inline struct device_node *of_find_node_opts_by_path(const char *path,
620*4882a593Smuzhiyun 	const char **opts)
621*4882a593Smuzhiyun {
622*4882a593Smuzhiyun 	return NULL;
623*4882a593Smuzhiyun }
624*4882a593Smuzhiyun 
of_find_node_by_phandle(phandle handle)625*4882a593Smuzhiyun static inline struct device_node *of_find_node_by_phandle(phandle handle)
626*4882a593Smuzhiyun {
627*4882a593Smuzhiyun 	return NULL;
628*4882a593Smuzhiyun }
629*4882a593Smuzhiyun 
of_get_parent(const struct device_node * node)630*4882a593Smuzhiyun static inline struct device_node *of_get_parent(const struct device_node *node)
631*4882a593Smuzhiyun {
632*4882a593Smuzhiyun 	return NULL;
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun 
of_get_next_parent(struct device_node * node)635*4882a593Smuzhiyun static inline struct device_node *of_get_next_parent(struct device_node *node)
636*4882a593Smuzhiyun {
637*4882a593Smuzhiyun 	return NULL;
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun 
of_get_next_child(const struct device_node * node,struct device_node * prev)640*4882a593Smuzhiyun static inline struct device_node *of_get_next_child(
641*4882a593Smuzhiyun 	const struct device_node *node, struct device_node *prev)
642*4882a593Smuzhiyun {
643*4882a593Smuzhiyun 	return NULL;
644*4882a593Smuzhiyun }
645*4882a593Smuzhiyun 
of_get_next_available_child(const struct device_node * node,struct device_node * prev)646*4882a593Smuzhiyun static inline struct device_node *of_get_next_available_child(
647*4882a593Smuzhiyun 	const struct device_node *node, struct device_node *prev)
648*4882a593Smuzhiyun {
649*4882a593Smuzhiyun 	return NULL;
650*4882a593Smuzhiyun }
651*4882a593Smuzhiyun 
of_find_node_with_property(struct device_node * from,const char * prop_name)652*4882a593Smuzhiyun static inline struct device_node *of_find_node_with_property(
653*4882a593Smuzhiyun 	struct device_node *from, const char *prop_name)
654*4882a593Smuzhiyun {
655*4882a593Smuzhiyun 	return NULL;
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun 
658*4882a593Smuzhiyun #define of_fwnode_handle(node) NULL
659*4882a593Smuzhiyun 
of_have_populated_dt(void)660*4882a593Smuzhiyun static inline bool of_have_populated_dt(void)
661*4882a593Smuzhiyun {
662*4882a593Smuzhiyun 	return false;
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun 
of_get_compatible_child(const struct device_node * parent,const char * compatible)665*4882a593Smuzhiyun static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
666*4882a593Smuzhiyun 					const char *compatible)
667*4882a593Smuzhiyun {
668*4882a593Smuzhiyun 	return NULL;
669*4882a593Smuzhiyun }
670*4882a593Smuzhiyun 
of_get_child_by_name(const struct device_node * node,const char * name)671*4882a593Smuzhiyun static inline struct device_node *of_get_child_by_name(
672*4882a593Smuzhiyun 					const struct device_node *node,
673*4882a593Smuzhiyun 					const char *name)
674*4882a593Smuzhiyun {
675*4882a593Smuzhiyun 	return NULL;
676*4882a593Smuzhiyun }
677*4882a593Smuzhiyun 
of_device_is_compatible(const struct device_node * device,const char * name)678*4882a593Smuzhiyun static inline int of_device_is_compatible(const struct device_node *device,
679*4882a593Smuzhiyun 					  const char *name)
680*4882a593Smuzhiyun {
681*4882a593Smuzhiyun 	return 0;
682*4882a593Smuzhiyun }
683*4882a593Smuzhiyun 
of_device_compatible_match(struct device_node * device,const char * const * compat)684*4882a593Smuzhiyun static inline  int of_device_compatible_match(struct device_node *device,
685*4882a593Smuzhiyun 					      const char *const *compat)
686*4882a593Smuzhiyun {
687*4882a593Smuzhiyun 	return 0;
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun 
of_device_is_available(const struct device_node * device)690*4882a593Smuzhiyun static inline bool of_device_is_available(const struct device_node *device)
691*4882a593Smuzhiyun {
692*4882a593Smuzhiyun 	return false;
693*4882a593Smuzhiyun }
694*4882a593Smuzhiyun 
of_device_is_big_endian(const struct device_node * device)695*4882a593Smuzhiyun static inline bool of_device_is_big_endian(const struct device_node *device)
696*4882a593Smuzhiyun {
697*4882a593Smuzhiyun 	return false;
698*4882a593Smuzhiyun }
699*4882a593Smuzhiyun 
of_find_property(const struct device_node * np,const char * name,int * lenp)700*4882a593Smuzhiyun static inline struct property *of_find_property(const struct device_node *np,
701*4882a593Smuzhiyun 						const char *name,
702*4882a593Smuzhiyun 						int *lenp)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun 	return NULL;
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun 
of_find_compatible_node(struct device_node * from,const char * type,const char * compat)707*4882a593Smuzhiyun static inline struct device_node *of_find_compatible_node(
708*4882a593Smuzhiyun 						struct device_node *from,
709*4882a593Smuzhiyun 						const char *type,
710*4882a593Smuzhiyun 						const char *compat)
711*4882a593Smuzhiyun {
712*4882a593Smuzhiyun 	return NULL;
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun 
of_property_count_elems_of_size(const struct device_node * np,const char * propname,int elem_size)715*4882a593Smuzhiyun static inline int of_property_count_elems_of_size(const struct device_node *np,
716*4882a593Smuzhiyun 			const char *propname, int elem_size)
717*4882a593Smuzhiyun {
718*4882a593Smuzhiyun 	return -ENOSYS;
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun 
of_property_read_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz)721*4882a593Smuzhiyun static inline int of_property_read_u8_array(const struct device_node *np,
722*4882a593Smuzhiyun 			const char *propname, u8 *out_values, size_t sz)
723*4882a593Smuzhiyun {
724*4882a593Smuzhiyun 	return -ENOSYS;
725*4882a593Smuzhiyun }
726*4882a593Smuzhiyun 
of_property_read_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz)727*4882a593Smuzhiyun static inline int of_property_read_u16_array(const struct device_node *np,
728*4882a593Smuzhiyun 			const char *propname, u16 *out_values, size_t sz)
729*4882a593Smuzhiyun {
730*4882a593Smuzhiyun 	return -ENOSYS;
731*4882a593Smuzhiyun }
732*4882a593Smuzhiyun 
of_property_read_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz)733*4882a593Smuzhiyun static inline int of_property_read_u32_array(const struct device_node *np,
734*4882a593Smuzhiyun 					     const char *propname,
735*4882a593Smuzhiyun 					     u32 *out_values, size_t sz)
736*4882a593Smuzhiyun {
737*4882a593Smuzhiyun 	return -ENOSYS;
738*4882a593Smuzhiyun }
739*4882a593Smuzhiyun 
of_property_read_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz)740*4882a593Smuzhiyun static inline int of_property_read_u64_array(const struct device_node *np,
741*4882a593Smuzhiyun 					     const char *propname,
742*4882a593Smuzhiyun 					     u64 *out_values, size_t sz)
743*4882a593Smuzhiyun {
744*4882a593Smuzhiyun 	return -ENOSYS;
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun 
of_property_read_u32_index(const struct device_node * np,const char * propname,u32 index,u32 * out_value)747*4882a593Smuzhiyun static inline int of_property_read_u32_index(const struct device_node *np,
748*4882a593Smuzhiyun 			const char *propname, u32 index, u32 *out_value)
749*4882a593Smuzhiyun {
750*4882a593Smuzhiyun 	return -ENOSYS;
751*4882a593Smuzhiyun }
752*4882a593Smuzhiyun 
of_property_read_u64_index(const struct device_node * np,const char * propname,u32 index,u64 * out_value)753*4882a593Smuzhiyun static inline int of_property_read_u64_index(const struct device_node *np,
754*4882a593Smuzhiyun 			const char *propname, u32 index, u64 *out_value)
755*4882a593Smuzhiyun {
756*4882a593Smuzhiyun 	return -ENOSYS;
757*4882a593Smuzhiyun }
758*4882a593Smuzhiyun 
of_get_property(const struct device_node * node,const char * name,int * lenp)759*4882a593Smuzhiyun static inline const void *of_get_property(const struct device_node *node,
760*4882a593Smuzhiyun 				const char *name,
761*4882a593Smuzhiyun 				int *lenp)
762*4882a593Smuzhiyun {
763*4882a593Smuzhiyun 	return NULL;
764*4882a593Smuzhiyun }
765*4882a593Smuzhiyun 
of_get_cpu_node(int cpu,unsigned int * thread)766*4882a593Smuzhiyun static inline struct device_node *of_get_cpu_node(int cpu,
767*4882a593Smuzhiyun 					unsigned int *thread)
768*4882a593Smuzhiyun {
769*4882a593Smuzhiyun 	return NULL;
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun 
of_get_next_cpu_node(struct device_node * prev)772*4882a593Smuzhiyun static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
773*4882a593Smuzhiyun {
774*4882a593Smuzhiyun 	return NULL;
775*4882a593Smuzhiyun }
776*4882a593Smuzhiyun 
of_get_cpu_state_node(struct device_node * cpu_node,int index)777*4882a593Smuzhiyun static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
778*4882a593Smuzhiyun 					int index)
779*4882a593Smuzhiyun {
780*4882a593Smuzhiyun 	return NULL;
781*4882a593Smuzhiyun }
782*4882a593Smuzhiyun 
of_n_addr_cells(struct device_node * np)783*4882a593Smuzhiyun static inline int of_n_addr_cells(struct device_node *np)
784*4882a593Smuzhiyun {
785*4882a593Smuzhiyun 	return 0;
786*4882a593Smuzhiyun 
787*4882a593Smuzhiyun }
of_n_size_cells(struct device_node * np)788*4882a593Smuzhiyun static inline int of_n_size_cells(struct device_node *np)
789*4882a593Smuzhiyun {
790*4882a593Smuzhiyun 	return 0;
791*4882a593Smuzhiyun }
792*4882a593Smuzhiyun 
of_property_read_variable_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz_min,size_t sz_max)793*4882a593Smuzhiyun static inline int of_property_read_variable_u8_array(const struct device_node *np,
794*4882a593Smuzhiyun 					const char *propname, u8 *out_values,
795*4882a593Smuzhiyun 					size_t sz_min, size_t sz_max)
796*4882a593Smuzhiyun {
797*4882a593Smuzhiyun 	return -ENOSYS;
798*4882a593Smuzhiyun }
799*4882a593Smuzhiyun 
of_property_read_variable_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz_min,size_t sz_max)800*4882a593Smuzhiyun static inline int of_property_read_variable_u16_array(const struct device_node *np,
801*4882a593Smuzhiyun 					const char *propname, u16 *out_values,
802*4882a593Smuzhiyun 					size_t sz_min, size_t sz_max)
803*4882a593Smuzhiyun {
804*4882a593Smuzhiyun 	return -ENOSYS;
805*4882a593Smuzhiyun }
806*4882a593Smuzhiyun 
of_property_read_variable_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz_min,size_t sz_max)807*4882a593Smuzhiyun static inline int of_property_read_variable_u32_array(const struct device_node *np,
808*4882a593Smuzhiyun 					const char *propname,
809*4882a593Smuzhiyun 					u32 *out_values,
810*4882a593Smuzhiyun 					size_t sz_min,
811*4882a593Smuzhiyun 					size_t sz_max)
812*4882a593Smuzhiyun {
813*4882a593Smuzhiyun 	return -ENOSYS;
814*4882a593Smuzhiyun }
815*4882a593Smuzhiyun 
of_property_read_u64(const struct device_node * np,const char * propname,u64 * out_value)816*4882a593Smuzhiyun static inline int of_property_read_u64(const struct device_node *np,
817*4882a593Smuzhiyun 				       const char *propname, u64 *out_value)
818*4882a593Smuzhiyun {
819*4882a593Smuzhiyun 	return -ENOSYS;
820*4882a593Smuzhiyun }
821*4882a593Smuzhiyun 
of_property_read_variable_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz_min,size_t sz_max)822*4882a593Smuzhiyun static inline int of_property_read_variable_u64_array(const struct device_node *np,
823*4882a593Smuzhiyun 					const char *propname,
824*4882a593Smuzhiyun 					u64 *out_values,
825*4882a593Smuzhiyun 					size_t sz_min,
826*4882a593Smuzhiyun 					size_t sz_max)
827*4882a593Smuzhiyun {
828*4882a593Smuzhiyun 	return -ENOSYS;
829*4882a593Smuzhiyun }
830*4882a593Smuzhiyun 
of_property_read_string(const struct device_node * np,const char * propname,const char ** out_string)831*4882a593Smuzhiyun static inline int of_property_read_string(const struct device_node *np,
832*4882a593Smuzhiyun 					  const char *propname,
833*4882a593Smuzhiyun 					  const char **out_string)
834*4882a593Smuzhiyun {
835*4882a593Smuzhiyun 	return -ENOSYS;
836*4882a593Smuzhiyun }
837*4882a593Smuzhiyun 
of_property_match_string(const struct device_node * np,const char * propname,const char * string)838*4882a593Smuzhiyun static inline int of_property_match_string(const struct device_node *np,
839*4882a593Smuzhiyun 					   const char *propname,
840*4882a593Smuzhiyun 					   const char *string)
841*4882a593Smuzhiyun {
842*4882a593Smuzhiyun 	return -ENOSYS;
843*4882a593Smuzhiyun }
844*4882a593Smuzhiyun 
of_property_read_string_helper(const struct device_node * np,const char * propname,const char ** out_strs,size_t sz,int index)845*4882a593Smuzhiyun static inline int of_property_read_string_helper(const struct device_node *np,
846*4882a593Smuzhiyun 						 const char *propname,
847*4882a593Smuzhiyun 						 const char **out_strs, size_t sz, int index)
848*4882a593Smuzhiyun {
849*4882a593Smuzhiyun 	return -ENOSYS;
850*4882a593Smuzhiyun }
851*4882a593Smuzhiyun 
of_parse_phandle(const struct device_node * np,const char * phandle_name,int index)852*4882a593Smuzhiyun static inline struct device_node *of_parse_phandle(const struct device_node *np,
853*4882a593Smuzhiyun 						   const char *phandle_name,
854*4882a593Smuzhiyun 						   int index)
855*4882a593Smuzhiyun {
856*4882a593Smuzhiyun 	return NULL;
857*4882a593Smuzhiyun }
858*4882a593Smuzhiyun 
of_parse_phandle_with_args(const struct device_node * np,const char * list_name,const char * cells_name,int index,struct of_phandle_args * out_args)859*4882a593Smuzhiyun static inline int of_parse_phandle_with_args(const struct device_node *np,
860*4882a593Smuzhiyun 					     const char *list_name,
861*4882a593Smuzhiyun 					     const char *cells_name,
862*4882a593Smuzhiyun 					     int index,
863*4882a593Smuzhiyun 					     struct of_phandle_args *out_args)
864*4882a593Smuzhiyun {
865*4882a593Smuzhiyun 	return -ENOSYS;
866*4882a593Smuzhiyun }
867*4882a593Smuzhiyun 
of_parse_phandle_with_args_map(const struct device_node * np,const char * list_name,const char * stem_name,int index,struct of_phandle_args * out_args)868*4882a593Smuzhiyun static inline int of_parse_phandle_with_args_map(const struct device_node *np,
869*4882a593Smuzhiyun 						 const char *list_name,
870*4882a593Smuzhiyun 						 const char *stem_name,
871*4882a593Smuzhiyun 						 int index,
872*4882a593Smuzhiyun 						 struct of_phandle_args *out_args)
873*4882a593Smuzhiyun {
874*4882a593Smuzhiyun 	return -ENOSYS;
875*4882a593Smuzhiyun }
876*4882a593Smuzhiyun 
of_parse_phandle_with_fixed_args(const struct device_node * np,const char * list_name,int cells_count,int index,struct of_phandle_args * out_args)877*4882a593Smuzhiyun static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
878*4882a593Smuzhiyun 	const char *list_name, int cells_count, int index,
879*4882a593Smuzhiyun 	struct of_phandle_args *out_args)
880*4882a593Smuzhiyun {
881*4882a593Smuzhiyun 	return -ENOSYS;
882*4882a593Smuzhiyun }
883*4882a593Smuzhiyun 
of_count_phandle_with_args(struct device_node * np,const char * list_name,const char * cells_name)884*4882a593Smuzhiyun static inline int of_count_phandle_with_args(struct device_node *np,
885*4882a593Smuzhiyun 					     const char *list_name,
886*4882a593Smuzhiyun 					     const char *cells_name)
887*4882a593Smuzhiyun {
888*4882a593Smuzhiyun 	return -ENOSYS;
889*4882a593Smuzhiyun }
890*4882a593Smuzhiyun 
of_phandle_iterator_init(struct of_phandle_iterator * it,const struct device_node * np,const char * list_name,const char * cells_name,int cell_count)891*4882a593Smuzhiyun static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
892*4882a593Smuzhiyun 					   const struct device_node *np,
893*4882a593Smuzhiyun 					   const char *list_name,
894*4882a593Smuzhiyun 					   const char *cells_name,
895*4882a593Smuzhiyun 					   int cell_count)
896*4882a593Smuzhiyun {
897*4882a593Smuzhiyun 	return -ENOSYS;
898*4882a593Smuzhiyun }
899*4882a593Smuzhiyun 
of_phandle_iterator_next(struct of_phandle_iterator * it)900*4882a593Smuzhiyun static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
901*4882a593Smuzhiyun {
902*4882a593Smuzhiyun 	return -ENOSYS;
903*4882a593Smuzhiyun }
904*4882a593Smuzhiyun 
of_phandle_iterator_args(struct of_phandle_iterator * it,uint32_t * args,int size)905*4882a593Smuzhiyun static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
906*4882a593Smuzhiyun 					   uint32_t *args,
907*4882a593Smuzhiyun 					   int size)
908*4882a593Smuzhiyun {
909*4882a593Smuzhiyun 	return 0;
910*4882a593Smuzhiyun }
911*4882a593Smuzhiyun 
of_alias_get_id(struct device_node * np,const char * stem)912*4882a593Smuzhiyun static inline int of_alias_get_id(struct device_node *np, const char *stem)
913*4882a593Smuzhiyun {
914*4882a593Smuzhiyun 	return -ENOSYS;
915*4882a593Smuzhiyun }
916*4882a593Smuzhiyun 
of_alias_get_highest_id(const char * stem)917*4882a593Smuzhiyun static inline int of_alias_get_highest_id(const char *stem)
918*4882a593Smuzhiyun {
919*4882a593Smuzhiyun 	return -ENOSYS;
920*4882a593Smuzhiyun }
921*4882a593Smuzhiyun 
of_alias_get_alias_list(const struct of_device_id * matches,const char * stem,unsigned long * bitmap,unsigned int nbits)922*4882a593Smuzhiyun static inline int of_alias_get_alias_list(const struct of_device_id *matches,
923*4882a593Smuzhiyun 					  const char *stem, unsigned long *bitmap,
924*4882a593Smuzhiyun 					  unsigned int nbits)
925*4882a593Smuzhiyun {
926*4882a593Smuzhiyun 	return -ENOSYS;
927*4882a593Smuzhiyun }
928*4882a593Smuzhiyun 
of_machine_is_compatible(const char * compat)929*4882a593Smuzhiyun static inline int of_machine_is_compatible(const char *compat)
930*4882a593Smuzhiyun {
931*4882a593Smuzhiyun 	return 0;
932*4882a593Smuzhiyun }
933*4882a593Smuzhiyun 
of_add_property(struct device_node * np,struct property * prop)934*4882a593Smuzhiyun static inline int of_add_property(struct device_node *np, struct property *prop)
935*4882a593Smuzhiyun {
936*4882a593Smuzhiyun 	return 0;
937*4882a593Smuzhiyun }
938*4882a593Smuzhiyun 
of_remove_property(struct device_node * np,struct property * prop)939*4882a593Smuzhiyun static inline int of_remove_property(struct device_node *np, struct property *prop)
940*4882a593Smuzhiyun {
941*4882a593Smuzhiyun 	return 0;
942*4882a593Smuzhiyun }
943*4882a593Smuzhiyun 
of_console_check(const struct device_node * dn,const char * name,int index)944*4882a593Smuzhiyun static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
945*4882a593Smuzhiyun {
946*4882a593Smuzhiyun 	return false;
947*4882a593Smuzhiyun }
948*4882a593Smuzhiyun 
of_prop_next_u32(struct property * prop,const __be32 * cur,u32 * pu)949*4882a593Smuzhiyun static inline const __be32 *of_prop_next_u32(struct property *prop,
950*4882a593Smuzhiyun 		const __be32 *cur, u32 *pu)
951*4882a593Smuzhiyun {
952*4882a593Smuzhiyun 	return NULL;
953*4882a593Smuzhiyun }
954*4882a593Smuzhiyun 
of_prop_next_string(struct property * prop,const char * cur)955*4882a593Smuzhiyun static inline const char *of_prop_next_string(struct property *prop,
956*4882a593Smuzhiyun 		const char *cur)
957*4882a593Smuzhiyun {
958*4882a593Smuzhiyun 	return NULL;
959*4882a593Smuzhiyun }
960*4882a593Smuzhiyun 
of_node_check_flag(struct device_node * n,unsigned long flag)961*4882a593Smuzhiyun static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
962*4882a593Smuzhiyun {
963*4882a593Smuzhiyun 	return 0;
964*4882a593Smuzhiyun }
965*4882a593Smuzhiyun 
of_node_test_and_set_flag(struct device_node * n,unsigned long flag)966*4882a593Smuzhiyun static inline int of_node_test_and_set_flag(struct device_node *n,
967*4882a593Smuzhiyun 					    unsigned long flag)
968*4882a593Smuzhiyun {
969*4882a593Smuzhiyun 	return 0;
970*4882a593Smuzhiyun }
971*4882a593Smuzhiyun 
of_node_set_flag(struct device_node * n,unsigned long flag)972*4882a593Smuzhiyun static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
973*4882a593Smuzhiyun {
974*4882a593Smuzhiyun }
975*4882a593Smuzhiyun 
of_node_clear_flag(struct device_node * n,unsigned long flag)976*4882a593Smuzhiyun static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
977*4882a593Smuzhiyun {
978*4882a593Smuzhiyun }
979*4882a593Smuzhiyun 
of_property_check_flag(struct property * p,unsigned long flag)980*4882a593Smuzhiyun static inline int of_property_check_flag(struct property *p, unsigned long flag)
981*4882a593Smuzhiyun {
982*4882a593Smuzhiyun 	return 0;
983*4882a593Smuzhiyun }
984*4882a593Smuzhiyun 
of_property_set_flag(struct property * p,unsigned long flag)985*4882a593Smuzhiyun static inline void of_property_set_flag(struct property *p, unsigned long flag)
986*4882a593Smuzhiyun {
987*4882a593Smuzhiyun }
988*4882a593Smuzhiyun 
of_property_clear_flag(struct property * p,unsigned long flag)989*4882a593Smuzhiyun static inline void of_property_clear_flag(struct property *p, unsigned long flag)
990*4882a593Smuzhiyun {
991*4882a593Smuzhiyun }
992*4882a593Smuzhiyun 
of_cpu_node_to_id(struct device_node * np)993*4882a593Smuzhiyun static inline int of_cpu_node_to_id(struct device_node *np)
994*4882a593Smuzhiyun {
995*4882a593Smuzhiyun 	return -ENODEV;
996*4882a593Smuzhiyun }
997*4882a593Smuzhiyun 
of_map_id(struct device_node * np,u32 id,const char * map_name,const char * map_mask_name,struct device_node ** target,u32 * id_out)998*4882a593Smuzhiyun static inline int of_map_id(struct device_node *np, u32 id,
999*4882a593Smuzhiyun 			     const char *map_name, const char *map_mask_name,
1000*4882a593Smuzhiyun 			     struct device_node **target, u32 *id_out)
1001*4882a593Smuzhiyun {
1002*4882a593Smuzhiyun 	return -EINVAL;
1003*4882a593Smuzhiyun }
1004*4882a593Smuzhiyun 
of_dma_get_max_cpu_address(struct device_node * np)1005*4882a593Smuzhiyun static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
1006*4882a593Smuzhiyun {
1007*4882a593Smuzhiyun 	return PHYS_ADDR_MAX;
1008*4882a593Smuzhiyun }
1009*4882a593Smuzhiyun 
1010*4882a593Smuzhiyun #define of_match_ptr(_ptr)	NULL
1011*4882a593Smuzhiyun #define of_match_node(_matches, _node)	NULL
1012*4882a593Smuzhiyun #endif /* CONFIG_OF */
1013*4882a593Smuzhiyun 
1014*4882a593Smuzhiyun /* Default string compare functions, Allow arch asm/prom.h to override */
1015*4882a593Smuzhiyun #if !defined(of_compat_cmp)
1016*4882a593Smuzhiyun #define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
1017*4882a593Smuzhiyun #define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
1018*4882a593Smuzhiyun #define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
1019*4882a593Smuzhiyun #endif
1020*4882a593Smuzhiyun 
of_prop_val_eq(struct property * p1,struct property * p2)1021*4882a593Smuzhiyun static inline int of_prop_val_eq(struct property *p1, struct property *p2)
1022*4882a593Smuzhiyun {
1023*4882a593Smuzhiyun 	return p1->length == p2->length &&
1024*4882a593Smuzhiyun 	       !memcmp(p1->value, p2->value, (size_t)p1->length);
1025*4882a593Smuzhiyun }
1026*4882a593Smuzhiyun 
1027*4882a593Smuzhiyun #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
1028*4882a593Smuzhiyun extern int of_node_to_nid(struct device_node *np);
1029*4882a593Smuzhiyun #else
of_node_to_nid(struct device_node * device)1030*4882a593Smuzhiyun static inline int of_node_to_nid(struct device_node *device)
1031*4882a593Smuzhiyun {
1032*4882a593Smuzhiyun 	return NUMA_NO_NODE;
1033*4882a593Smuzhiyun }
1034*4882a593Smuzhiyun #endif
1035*4882a593Smuzhiyun 
1036*4882a593Smuzhiyun #ifdef CONFIG_OF_NUMA
1037*4882a593Smuzhiyun extern int of_numa_init(void);
1038*4882a593Smuzhiyun #else
of_numa_init(void)1039*4882a593Smuzhiyun static inline int of_numa_init(void)
1040*4882a593Smuzhiyun {
1041*4882a593Smuzhiyun 	return -ENOSYS;
1042*4882a593Smuzhiyun }
1043*4882a593Smuzhiyun #endif
1044*4882a593Smuzhiyun 
of_find_matching_node(struct device_node * from,const struct of_device_id * matches)1045*4882a593Smuzhiyun static inline struct device_node *of_find_matching_node(
1046*4882a593Smuzhiyun 	struct device_node *from,
1047*4882a593Smuzhiyun 	const struct of_device_id *matches)
1048*4882a593Smuzhiyun {
1049*4882a593Smuzhiyun 	return of_find_matching_node_and_match(from, matches, NULL);
1050*4882a593Smuzhiyun }
1051*4882a593Smuzhiyun 
of_node_get_device_type(const struct device_node * np)1052*4882a593Smuzhiyun static inline const char *of_node_get_device_type(const struct device_node *np)
1053*4882a593Smuzhiyun {
1054*4882a593Smuzhiyun 	return of_get_property(np, "device_type", NULL);
1055*4882a593Smuzhiyun }
1056*4882a593Smuzhiyun 
of_node_is_type(const struct device_node * np,const char * type)1057*4882a593Smuzhiyun static inline bool of_node_is_type(const struct device_node *np, const char *type)
1058*4882a593Smuzhiyun {
1059*4882a593Smuzhiyun 	const char *match = of_node_get_device_type(np);
1060*4882a593Smuzhiyun 
1061*4882a593Smuzhiyun 	return np && match && type && !strcmp(match, type);
1062*4882a593Smuzhiyun }
1063*4882a593Smuzhiyun 
1064*4882a593Smuzhiyun /**
1065*4882a593Smuzhiyun  * of_property_count_u8_elems - Count the number of u8 elements in a property
1066*4882a593Smuzhiyun  *
1067*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1068*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1069*4882a593Smuzhiyun  *
1070*4882a593Smuzhiyun  * Search for a property in a device node and count the number of u8 elements
1071*4882a593Smuzhiyun  * in it. Returns number of elements on sucess, -EINVAL if the property does
1072*4882a593Smuzhiyun  * not exist or its length does not match a multiple of u8 and -ENODATA if the
1073*4882a593Smuzhiyun  * property does not have a value.
1074*4882a593Smuzhiyun  */
of_property_count_u8_elems(const struct device_node * np,const char * propname)1075*4882a593Smuzhiyun static inline int of_property_count_u8_elems(const struct device_node *np,
1076*4882a593Smuzhiyun 				const char *propname)
1077*4882a593Smuzhiyun {
1078*4882a593Smuzhiyun 	return of_property_count_elems_of_size(np, propname, sizeof(u8));
1079*4882a593Smuzhiyun }
1080*4882a593Smuzhiyun 
1081*4882a593Smuzhiyun /**
1082*4882a593Smuzhiyun  * of_property_count_u16_elems - Count the number of u16 elements in a property
1083*4882a593Smuzhiyun  *
1084*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1085*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1086*4882a593Smuzhiyun  *
1087*4882a593Smuzhiyun  * Search for a property in a device node and count the number of u16 elements
1088*4882a593Smuzhiyun  * in it. Returns number of elements on sucess, -EINVAL if the property does
1089*4882a593Smuzhiyun  * not exist or its length does not match a multiple of u16 and -ENODATA if the
1090*4882a593Smuzhiyun  * property does not have a value.
1091*4882a593Smuzhiyun  */
of_property_count_u16_elems(const struct device_node * np,const char * propname)1092*4882a593Smuzhiyun static inline int of_property_count_u16_elems(const struct device_node *np,
1093*4882a593Smuzhiyun 				const char *propname)
1094*4882a593Smuzhiyun {
1095*4882a593Smuzhiyun 	return of_property_count_elems_of_size(np, propname, sizeof(u16));
1096*4882a593Smuzhiyun }
1097*4882a593Smuzhiyun 
1098*4882a593Smuzhiyun /**
1099*4882a593Smuzhiyun  * of_property_count_u32_elems - Count the number of u32 elements in a property
1100*4882a593Smuzhiyun  *
1101*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1102*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1103*4882a593Smuzhiyun  *
1104*4882a593Smuzhiyun  * Search for a property in a device node and count the number of u32 elements
1105*4882a593Smuzhiyun  * in it. Returns number of elements on sucess, -EINVAL if the property does
1106*4882a593Smuzhiyun  * not exist or its length does not match a multiple of u32 and -ENODATA if the
1107*4882a593Smuzhiyun  * property does not have a value.
1108*4882a593Smuzhiyun  */
of_property_count_u32_elems(const struct device_node * np,const char * propname)1109*4882a593Smuzhiyun static inline int of_property_count_u32_elems(const struct device_node *np,
1110*4882a593Smuzhiyun 				const char *propname)
1111*4882a593Smuzhiyun {
1112*4882a593Smuzhiyun 	return of_property_count_elems_of_size(np, propname, sizeof(u32));
1113*4882a593Smuzhiyun }
1114*4882a593Smuzhiyun 
1115*4882a593Smuzhiyun /**
1116*4882a593Smuzhiyun  * of_property_count_u64_elems - Count the number of u64 elements in a property
1117*4882a593Smuzhiyun  *
1118*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1119*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1120*4882a593Smuzhiyun  *
1121*4882a593Smuzhiyun  * Search for a property in a device node and count the number of u64 elements
1122*4882a593Smuzhiyun  * in it. Returns number of elements on sucess, -EINVAL if the property does
1123*4882a593Smuzhiyun  * not exist or its length does not match a multiple of u64 and -ENODATA if the
1124*4882a593Smuzhiyun  * property does not have a value.
1125*4882a593Smuzhiyun  */
of_property_count_u64_elems(const struct device_node * np,const char * propname)1126*4882a593Smuzhiyun static inline int of_property_count_u64_elems(const struct device_node *np,
1127*4882a593Smuzhiyun 				const char *propname)
1128*4882a593Smuzhiyun {
1129*4882a593Smuzhiyun 	return of_property_count_elems_of_size(np, propname, sizeof(u64));
1130*4882a593Smuzhiyun }
1131*4882a593Smuzhiyun 
1132*4882a593Smuzhiyun /**
1133*4882a593Smuzhiyun  * of_property_read_string_array() - Read an array of strings from a multiple
1134*4882a593Smuzhiyun  * strings property.
1135*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1136*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1137*4882a593Smuzhiyun  * @out_strs:	output array of string pointers.
1138*4882a593Smuzhiyun  * @sz:		number of array elements to read.
1139*4882a593Smuzhiyun  *
1140*4882a593Smuzhiyun  * Search for a property in a device tree node and retrieve a list of
1141*4882a593Smuzhiyun  * terminated string values (pointer to data, not a copy) in that property.
1142*4882a593Smuzhiyun  *
1143*4882a593Smuzhiyun  * If @out_strs is NULL, the number of strings in the property is returned.
1144*4882a593Smuzhiyun  */
of_property_read_string_array(const struct device_node * np,const char * propname,const char ** out_strs,size_t sz)1145*4882a593Smuzhiyun static inline int of_property_read_string_array(const struct device_node *np,
1146*4882a593Smuzhiyun 						const char *propname, const char **out_strs,
1147*4882a593Smuzhiyun 						size_t sz)
1148*4882a593Smuzhiyun {
1149*4882a593Smuzhiyun 	return of_property_read_string_helper(np, propname, out_strs, sz, 0);
1150*4882a593Smuzhiyun }
1151*4882a593Smuzhiyun 
1152*4882a593Smuzhiyun /**
1153*4882a593Smuzhiyun  * of_property_count_strings() - Find and return the number of strings from a
1154*4882a593Smuzhiyun  * multiple strings property.
1155*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1156*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1157*4882a593Smuzhiyun  *
1158*4882a593Smuzhiyun  * Search for a property in a device tree node and retrieve the number of null
1159*4882a593Smuzhiyun  * terminated string contain in it. Returns the number of strings on
1160*4882a593Smuzhiyun  * success, -EINVAL if the property does not exist, -ENODATA if property
1161*4882a593Smuzhiyun  * does not have a value, and -EILSEQ if the string is not null-terminated
1162*4882a593Smuzhiyun  * within the length of the property data.
1163*4882a593Smuzhiyun  */
of_property_count_strings(const struct device_node * np,const char * propname)1164*4882a593Smuzhiyun static inline int of_property_count_strings(const struct device_node *np,
1165*4882a593Smuzhiyun 					    const char *propname)
1166*4882a593Smuzhiyun {
1167*4882a593Smuzhiyun 	return of_property_read_string_helper(np, propname, NULL, 0, 0);
1168*4882a593Smuzhiyun }
1169*4882a593Smuzhiyun 
1170*4882a593Smuzhiyun /**
1171*4882a593Smuzhiyun  * of_property_read_string_index() - Find and read a string from a multiple
1172*4882a593Smuzhiyun  * strings property.
1173*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1174*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1175*4882a593Smuzhiyun  * @index:	index of the string in the list of strings
1176*4882a593Smuzhiyun  * @out_string:	pointer to null terminated return string, modified only if
1177*4882a593Smuzhiyun  *		return value is 0.
1178*4882a593Smuzhiyun  *
1179*4882a593Smuzhiyun  * Search for a property in a device tree node and retrieve a null
1180*4882a593Smuzhiyun  * terminated string value (pointer to data, not a copy) in the list of strings
1181*4882a593Smuzhiyun  * contained in that property.
1182*4882a593Smuzhiyun  * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
1183*4882a593Smuzhiyun  * property does not have a value, and -EILSEQ if the string is not
1184*4882a593Smuzhiyun  * null-terminated within the length of the property data.
1185*4882a593Smuzhiyun  *
1186*4882a593Smuzhiyun  * The out_string pointer is modified only if a valid string can be decoded.
1187*4882a593Smuzhiyun  */
of_property_read_string_index(const struct device_node * np,const char * propname,int index,const char ** output)1188*4882a593Smuzhiyun static inline int of_property_read_string_index(const struct device_node *np,
1189*4882a593Smuzhiyun 						const char *propname,
1190*4882a593Smuzhiyun 						int index, const char **output)
1191*4882a593Smuzhiyun {
1192*4882a593Smuzhiyun 	int rc = of_property_read_string_helper(np, propname, output, 1, index);
1193*4882a593Smuzhiyun 	return rc < 0 ? rc : 0;
1194*4882a593Smuzhiyun }
1195*4882a593Smuzhiyun 
1196*4882a593Smuzhiyun /**
1197*4882a593Smuzhiyun  * of_property_read_bool - Find a property
1198*4882a593Smuzhiyun  * @np:		device node from which the property value is to be read.
1199*4882a593Smuzhiyun  * @propname:	name of the property to be searched.
1200*4882a593Smuzhiyun  *
1201*4882a593Smuzhiyun  * Search for a property in a device node.
1202*4882a593Smuzhiyun  * Returns true if the property exists false otherwise.
1203*4882a593Smuzhiyun  */
of_property_read_bool(const struct device_node * np,const char * propname)1204*4882a593Smuzhiyun static inline bool of_property_read_bool(const struct device_node *np,
1205*4882a593Smuzhiyun 					 const char *propname)
1206*4882a593Smuzhiyun {
1207*4882a593Smuzhiyun 	struct property *prop = of_find_property(np, propname, NULL);
1208*4882a593Smuzhiyun 
1209*4882a593Smuzhiyun 	return prop ? true : false;
1210*4882a593Smuzhiyun }
1211*4882a593Smuzhiyun 
of_property_read_u8(const struct device_node * np,const char * propname,u8 * out_value)1212*4882a593Smuzhiyun static inline int of_property_read_u8(const struct device_node *np,
1213*4882a593Smuzhiyun 				       const char *propname,
1214*4882a593Smuzhiyun 				       u8 *out_value)
1215*4882a593Smuzhiyun {
1216*4882a593Smuzhiyun 	return of_property_read_u8_array(np, propname, out_value, 1);
1217*4882a593Smuzhiyun }
1218*4882a593Smuzhiyun 
of_property_read_u16(const struct device_node * np,const char * propname,u16 * out_value)1219*4882a593Smuzhiyun static inline int of_property_read_u16(const struct device_node *np,
1220*4882a593Smuzhiyun 				       const char *propname,
1221*4882a593Smuzhiyun 				       u16 *out_value)
1222*4882a593Smuzhiyun {
1223*4882a593Smuzhiyun 	return of_property_read_u16_array(np, propname, out_value, 1);
1224*4882a593Smuzhiyun }
1225*4882a593Smuzhiyun 
of_property_read_u32(const struct device_node * np,const char * propname,u32 * out_value)1226*4882a593Smuzhiyun static inline int of_property_read_u32(const struct device_node *np,
1227*4882a593Smuzhiyun 				       const char *propname,
1228*4882a593Smuzhiyun 				       u32 *out_value)
1229*4882a593Smuzhiyun {
1230*4882a593Smuzhiyun 	return of_property_read_u32_array(np, propname, out_value, 1);
1231*4882a593Smuzhiyun }
1232*4882a593Smuzhiyun 
of_property_read_s32(const struct device_node * np,const char * propname,s32 * out_value)1233*4882a593Smuzhiyun static inline int of_property_read_s32(const struct device_node *np,
1234*4882a593Smuzhiyun 				       const char *propname,
1235*4882a593Smuzhiyun 				       s32 *out_value)
1236*4882a593Smuzhiyun {
1237*4882a593Smuzhiyun 	return of_property_read_u32(np, propname, (u32*) out_value);
1238*4882a593Smuzhiyun }
1239*4882a593Smuzhiyun 
1240*4882a593Smuzhiyun #define of_for_each_phandle(it, err, np, ln, cn, cc)			\
1241*4882a593Smuzhiyun 	for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)),	\
1242*4882a593Smuzhiyun 	     err = of_phandle_iterator_next(it);			\
1243*4882a593Smuzhiyun 	     err == 0;							\
1244*4882a593Smuzhiyun 	     err = of_phandle_iterator_next(it))
1245*4882a593Smuzhiyun 
1246*4882a593Smuzhiyun #define of_property_for_each_u32(np, propname, prop, p, u)	\
1247*4882a593Smuzhiyun 	for (prop = of_find_property(np, propname, NULL),	\
1248*4882a593Smuzhiyun 		p = of_prop_next_u32(prop, NULL, &u);		\
1249*4882a593Smuzhiyun 		p;						\
1250*4882a593Smuzhiyun 		p = of_prop_next_u32(prop, p, &u))
1251*4882a593Smuzhiyun 
1252*4882a593Smuzhiyun #define of_property_for_each_string(np, propname, prop, s)	\
1253*4882a593Smuzhiyun 	for (prop = of_find_property(np, propname, NULL),	\
1254*4882a593Smuzhiyun 		s = of_prop_next_string(prop, NULL);		\
1255*4882a593Smuzhiyun 		s;						\
1256*4882a593Smuzhiyun 		s = of_prop_next_string(prop, s))
1257*4882a593Smuzhiyun 
1258*4882a593Smuzhiyun #define for_each_node_by_name(dn, name) \
1259*4882a593Smuzhiyun 	for (dn = of_find_node_by_name(NULL, name); dn; \
1260*4882a593Smuzhiyun 	     dn = of_find_node_by_name(dn, name))
1261*4882a593Smuzhiyun #define for_each_node_by_type(dn, type) \
1262*4882a593Smuzhiyun 	for (dn = of_find_node_by_type(NULL, type); dn; \
1263*4882a593Smuzhiyun 	     dn = of_find_node_by_type(dn, type))
1264*4882a593Smuzhiyun #define for_each_compatible_node(dn, type, compatible) \
1265*4882a593Smuzhiyun 	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
1266*4882a593Smuzhiyun 	     dn = of_find_compatible_node(dn, type, compatible))
1267*4882a593Smuzhiyun #define for_each_matching_node(dn, matches) \
1268*4882a593Smuzhiyun 	for (dn = of_find_matching_node(NULL, matches); dn; \
1269*4882a593Smuzhiyun 	     dn = of_find_matching_node(dn, matches))
1270*4882a593Smuzhiyun #define for_each_matching_node_and_match(dn, matches, match) \
1271*4882a593Smuzhiyun 	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
1272*4882a593Smuzhiyun 	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
1273*4882a593Smuzhiyun 
1274*4882a593Smuzhiyun #define for_each_child_of_node(parent, child) \
1275*4882a593Smuzhiyun 	for (child = of_get_next_child(parent, NULL); child != NULL; \
1276*4882a593Smuzhiyun 	     child = of_get_next_child(parent, child))
1277*4882a593Smuzhiyun #define for_each_available_child_of_node(parent, child) \
1278*4882a593Smuzhiyun 	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
1279*4882a593Smuzhiyun 	     child = of_get_next_available_child(parent, child))
1280*4882a593Smuzhiyun 
1281*4882a593Smuzhiyun #define for_each_of_cpu_node(cpu) \
1282*4882a593Smuzhiyun 	for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
1283*4882a593Smuzhiyun 	     cpu = of_get_next_cpu_node(cpu))
1284*4882a593Smuzhiyun 
1285*4882a593Smuzhiyun #define for_each_node_with_property(dn, prop_name) \
1286*4882a593Smuzhiyun 	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
1287*4882a593Smuzhiyun 	     dn = of_find_node_with_property(dn, prop_name))
1288*4882a593Smuzhiyun 
of_get_child_count(const struct device_node * np)1289*4882a593Smuzhiyun static inline int of_get_child_count(const struct device_node *np)
1290*4882a593Smuzhiyun {
1291*4882a593Smuzhiyun 	struct device_node *child;
1292*4882a593Smuzhiyun 	int num = 0;
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun 	for_each_child_of_node(np, child)
1295*4882a593Smuzhiyun 		num++;
1296*4882a593Smuzhiyun 
1297*4882a593Smuzhiyun 	return num;
1298*4882a593Smuzhiyun }
1299*4882a593Smuzhiyun 
of_get_available_child_count(const struct device_node * np)1300*4882a593Smuzhiyun static inline int of_get_available_child_count(const struct device_node *np)
1301*4882a593Smuzhiyun {
1302*4882a593Smuzhiyun 	struct device_node *child;
1303*4882a593Smuzhiyun 	int num = 0;
1304*4882a593Smuzhiyun 
1305*4882a593Smuzhiyun 	for_each_available_child_of_node(np, child)
1306*4882a593Smuzhiyun 		num++;
1307*4882a593Smuzhiyun 
1308*4882a593Smuzhiyun 	return num;
1309*4882a593Smuzhiyun }
1310*4882a593Smuzhiyun 
1311*4882a593Smuzhiyun #if defined(CONFIG_OF) && !defined(MODULE)
1312*4882a593Smuzhiyun #define _OF_DECLARE(table, name, compat, fn, fn_type)			\
1313*4882a593Smuzhiyun 	static const struct of_device_id __of_table_##name		\
1314*4882a593Smuzhiyun 		__used __section("__" #table "_of_table")		\
1315*4882a593Smuzhiyun 		__aligned(__alignof__(struct of_device_id))		\
1316*4882a593Smuzhiyun 		 = { .compatible = compat,				\
1317*4882a593Smuzhiyun 		     .data = (fn == (fn_type)NULL) ? fn : fn  }
1318*4882a593Smuzhiyun #else
1319*4882a593Smuzhiyun #define _OF_DECLARE(table, name, compat, fn, fn_type)			\
1320*4882a593Smuzhiyun 	static const struct of_device_id __of_table_##name		\
1321*4882a593Smuzhiyun 		__attribute__((unused))					\
1322*4882a593Smuzhiyun 		 = { .compatible = compat,				\
1323*4882a593Smuzhiyun 		     .data = (fn == (fn_type)NULL) ? fn : fn }
1324*4882a593Smuzhiyun #endif
1325*4882a593Smuzhiyun 
1326*4882a593Smuzhiyun typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
1327*4882a593Smuzhiyun typedef int (*of_init_fn_1_ret)(struct device_node *);
1328*4882a593Smuzhiyun typedef void (*of_init_fn_1)(struct device_node *);
1329*4882a593Smuzhiyun 
1330*4882a593Smuzhiyun #define OF_DECLARE_1(table, name, compat, fn) \
1331*4882a593Smuzhiyun 		_OF_DECLARE(table, name, compat, fn, of_init_fn_1)
1332*4882a593Smuzhiyun #define OF_DECLARE_1_RET(table, name, compat, fn) \
1333*4882a593Smuzhiyun 		_OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
1334*4882a593Smuzhiyun #define OF_DECLARE_2(table, name, compat, fn) \
1335*4882a593Smuzhiyun 		_OF_DECLARE(table, name, compat, fn, of_init_fn_2)
1336*4882a593Smuzhiyun 
1337*4882a593Smuzhiyun /**
1338*4882a593Smuzhiyun  * struct of_changeset_entry	- Holds a changeset entry
1339*4882a593Smuzhiyun  *
1340*4882a593Smuzhiyun  * @node:	list_head for the log list
1341*4882a593Smuzhiyun  * @action:	notifier action
1342*4882a593Smuzhiyun  * @np:		pointer to the device node affected
1343*4882a593Smuzhiyun  * @prop:	pointer to the property affected
1344*4882a593Smuzhiyun  * @old_prop:	hold a pointer to the original property
1345*4882a593Smuzhiyun  *
1346*4882a593Smuzhiyun  * Every modification of the device tree during a changeset
1347*4882a593Smuzhiyun  * is held in a list of of_changeset_entry structures.
1348*4882a593Smuzhiyun  * That way we can recover from a partial application, or we can
1349*4882a593Smuzhiyun  * revert the changeset
1350*4882a593Smuzhiyun  */
1351*4882a593Smuzhiyun struct of_changeset_entry {
1352*4882a593Smuzhiyun 	struct list_head node;
1353*4882a593Smuzhiyun 	unsigned long action;
1354*4882a593Smuzhiyun 	struct device_node *np;
1355*4882a593Smuzhiyun 	struct property *prop;
1356*4882a593Smuzhiyun 	struct property *old_prop;
1357*4882a593Smuzhiyun };
1358*4882a593Smuzhiyun 
1359*4882a593Smuzhiyun /**
1360*4882a593Smuzhiyun  * struct of_changeset - changeset tracker structure
1361*4882a593Smuzhiyun  *
1362*4882a593Smuzhiyun  * @entries:	list_head for the changeset entries
1363*4882a593Smuzhiyun  *
1364*4882a593Smuzhiyun  * changesets are a convenient way to apply bulk changes to the
1365*4882a593Smuzhiyun  * live tree. In case of an error, changes are rolled-back.
1366*4882a593Smuzhiyun  * changesets live on after initial application, and if not
1367*4882a593Smuzhiyun  * destroyed after use, they can be reverted in one single call.
1368*4882a593Smuzhiyun  */
1369*4882a593Smuzhiyun struct of_changeset {
1370*4882a593Smuzhiyun 	struct list_head entries;
1371*4882a593Smuzhiyun };
1372*4882a593Smuzhiyun 
1373*4882a593Smuzhiyun enum of_reconfig_change {
1374*4882a593Smuzhiyun 	OF_RECONFIG_NO_CHANGE = 0,
1375*4882a593Smuzhiyun 	OF_RECONFIG_CHANGE_ADD,
1376*4882a593Smuzhiyun 	OF_RECONFIG_CHANGE_REMOVE,
1377*4882a593Smuzhiyun };
1378*4882a593Smuzhiyun 
1379*4882a593Smuzhiyun #ifdef CONFIG_OF_DYNAMIC
1380*4882a593Smuzhiyun extern int of_reconfig_notifier_register(struct notifier_block *);
1381*4882a593Smuzhiyun extern int of_reconfig_notifier_unregister(struct notifier_block *);
1382*4882a593Smuzhiyun extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
1383*4882a593Smuzhiyun extern int of_reconfig_get_state_change(unsigned long action,
1384*4882a593Smuzhiyun 					struct of_reconfig_data *arg);
1385*4882a593Smuzhiyun 
1386*4882a593Smuzhiyun extern void of_changeset_init(struct of_changeset *ocs);
1387*4882a593Smuzhiyun extern void of_changeset_destroy(struct of_changeset *ocs);
1388*4882a593Smuzhiyun extern int of_changeset_apply(struct of_changeset *ocs);
1389*4882a593Smuzhiyun extern int of_changeset_revert(struct of_changeset *ocs);
1390*4882a593Smuzhiyun extern int of_changeset_action(struct of_changeset *ocs,
1391*4882a593Smuzhiyun 		unsigned long action, struct device_node *np,
1392*4882a593Smuzhiyun 		struct property *prop);
1393*4882a593Smuzhiyun 
of_changeset_attach_node(struct of_changeset * ocs,struct device_node * np)1394*4882a593Smuzhiyun static inline int of_changeset_attach_node(struct of_changeset *ocs,
1395*4882a593Smuzhiyun 		struct device_node *np)
1396*4882a593Smuzhiyun {
1397*4882a593Smuzhiyun 	return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
1398*4882a593Smuzhiyun }
1399*4882a593Smuzhiyun 
of_changeset_detach_node(struct of_changeset * ocs,struct device_node * np)1400*4882a593Smuzhiyun static inline int of_changeset_detach_node(struct of_changeset *ocs,
1401*4882a593Smuzhiyun 		struct device_node *np)
1402*4882a593Smuzhiyun {
1403*4882a593Smuzhiyun 	return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
1404*4882a593Smuzhiyun }
1405*4882a593Smuzhiyun 
of_changeset_add_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1406*4882a593Smuzhiyun static inline int of_changeset_add_property(struct of_changeset *ocs,
1407*4882a593Smuzhiyun 		struct device_node *np, struct property *prop)
1408*4882a593Smuzhiyun {
1409*4882a593Smuzhiyun 	return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
1410*4882a593Smuzhiyun }
1411*4882a593Smuzhiyun 
of_changeset_remove_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1412*4882a593Smuzhiyun static inline int of_changeset_remove_property(struct of_changeset *ocs,
1413*4882a593Smuzhiyun 		struct device_node *np, struct property *prop)
1414*4882a593Smuzhiyun {
1415*4882a593Smuzhiyun 	return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
1416*4882a593Smuzhiyun }
1417*4882a593Smuzhiyun 
of_changeset_update_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1418*4882a593Smuzhiyun static inline int of_changeset_update_property(struct of_changeset *ocs,
1419*4882a593Smuzhiyun 		struct device_node *np, struct property *prop)
1420*4882a593Smuzhiyun {
1421*4882a593Smuzhiyun 	return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
1422*4882a593Smuzhiyun }
1423*4882a593Smuzhiyun #else /* CONFIG_OF_DYNAMIC */
of_reconfig_notifier_register(struct notifier_block * nb)1424*4882a593Smuzhiyun static inline int of_reconfig_notifier_register(struct notifier_block *nb)
1425*4882a593Smuzhiyun {
1426*4882a593Smuzhiyun 	return -EINVAL;
1427*4882a593Smuzhiyun }
of_reconfig_notifier_unregister(struct notifier_block * nb)1428*4882a593Smuzhiyun static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
1429*4882a593Smuzhiyun {
1430*4882a593Smuzhiyun 	return -EINVAL;
1431*4882a593Smuzhiyun }
of_reconfig_notify(unsigned long action,struct of_reconfig_data * arg)1432*4882a593Smuzhiyun static inline int of_reconfig_notify(unsigned long action,
1433*4882a593Smuzhiyun 				     struct of_reconfig_data *arg)
1434*4882a593Smuzhiyun {
1435*4882a593Smuzhiyun 	return -EINVAL;
1436*4882a593Smuzhiyun }
of_reconfig_get_state_change(unsigned long action,struct of_reconfig_data * arg)1437*4882a593Smuzhiyun static inline int of_reconfig_get_state_change(unsigned long action,
1438*4882a593Smuzhiyun 						struct of_reconfig_data *arg)
1439*4882a593Smuzhiyun {
1440*4882a593Smuzhiyun 	return -EINVAL;
1441*4882a593Smuzhiyun }
1442*4882a593Smuzhiyun #endif /* CONFIG_OF_DYNAMIC */
1443*4882a593Smuzhiyun 
1444*4882a593Smuzhiyun /**
1445*4882a593Smuzhiyun  * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
1446*4882a593Smuzhiyun  * @np: Pointer to the given device_node
1447*4882a593Smuzhiyun  *
1448*4882a593Smuzhiyun  * return true if present false otherwise
1449*4882a593Smuzhiyun  */
of_device_is_system_power_controller(const struct device_node * np)1450*4882a593Smuzhiyun static inline bool of_device_is_system_power_controller(const struct device_node *np)
1451*4882a593Smuzhiyun {
1452*4882a593Smuzhiyun 	return of_property_read_bool(np, "system-power-controller");
1453*4882a593Smuzhiyun }
1454*4882a593Smuzhiyun 
1455*4882a593Smuzhiyun /**
1456*4882a593Smuzhiyun  * Overlay support
1457*4882a593Smuzhiyun  */
1458*4882a593Smuzhiyun 
1459*4882a593Smuzhiyun enum of_overlay_notify_action {
1460*4882a593Smuzhiyun 	OF_OVERLAY_PRE_APPLY = 0,
1461*4882a593Smuzhiyun 	OF_OVERLAY_POST_APPLY,
1462*4882a593Smuzhiyun 	OF_OVERLAY_PRE_REMOVE,
1463*4882a593Smuzhiyun 	OF_OVERLAY_POST_REMOVE,
1464*4882a593Smuzhiyun };
1465*4882a593Smuzhiyun 
1466*4882a593Smuzhiyun struct of_overlay_notify_data {
1467*4882a593Smuzhiyun 	struct device_node *overlay;
1468*4882a593Smuzhiyun 	struct device_node *target;
1469*4882a593Smuzhiyun };
1470*4882a593Smuzhiyun 
1471*4882a593Smuzhiyun #ifdef CONFIG_OF_OVERLAY
1472*4882a593Smuzhiyun 
1473*4882a593Smuzhiyun int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
1474*4882a593Smuzhiyun 			 int *ovcs_id);
1475*4882a593Smuzhiyun int of_overlay_remove(int *ovcs_id);
1476*4882a593Smuzhiyun int of_overlay_remove_all(void);
1477*4882a593Smuzhiyun 
1478*4882a593Smuzhiyun int of_overlay_notifier_register(struct notifier_block *nb);
1479*4882a593Smuzhiyun int of_overlay_notifier_unregister(struct notifier_block *nb);
1480*4882a593Smuzhiyun 
1481*4882a593Smuzhiyun #else
1482*4882a593Smuzhiyun 
of_overlay_fdt_apply(void * overlay_fdt,u32 overlay_fdt_size,int * ovcs_id)1483*4882a593Smuzhiyun static inline int of_overlay_fdt_apply(void *overlay_fdt, u32 overlay_fdt_size,
1484*4882a593Smuzhiyun 				       int *ovcs_id)
1485*4882a593Smuzhiyun {
1486*4882a593Smuzhiyun 	return -ENOTSUPP;
1487*4882a593Smuzhiyun }
1488*4882a593Smuzhiyun 
of_overlay_remove(int * ovcs_id)1489*4882a593Smuzhiyun static inline int of_overlay_remove(int *ovcs_id)
1490*4882a593Smuzhiyun {
1491*4882a593Smuzhiyun 	return -ENOTSUPP;
1492*4882a593Smuzhiyun }
1493*4882a593Smuzhiyun 
of_overlay_remove_all(void)1494*4882a593Smuzhiyun static inline int of_overlay_remove_all(void)
1495*4882a593Smuzhiyun {
1496*4882a593Smuzhiyun 	return -ENOTSUPP;
1497*4882a593Smuzhiyun }
1498*4882a593Smuzhiyun 
of_overlay_notifier_register(struct notifier_block * nb)1499*4882a593Smuzhiyun static inline int of_overlay_notifier_register(struct notifier_block *nb)
1500*4882a593Smuzhiyun {
1501*4882a593Smuzhiyun 	return 0;
1502*4882a593Smuzhiyun }
1503*4882a593Smuzhiyun 
of_overlay_notifier_unregister(struct notifier_block * nb)1504*4882a593Smuzhiyun static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
1505*4882a593Smuzhiyun {
1506*4882a593Smuzhiyun 	return 0;
1507*4882a593Smuzhiyun }
1508*4882a593Smuzhiyun 
1509*4882a593Smuzhiyun #endif
1510*4882a593Smuzhiyun 
1511*4882a593Smuzhiyun #endif /* _LINUX_OF_H */
1512