xref: /linux-6.15/include/linux/of.h (revision fd958299)
1af6074fcSRob Herring /* SPDX-License-Identifier: GPL-2.0+ */
276c1ce78SStephen Rothwell #ifndef _LINUX_OF_H
376c1ce78SStephen Rothwell #define _LINUX_OF_H
476c1ce78SStephen Rothwell /*
576c1ce78SStephen Rothwell  * Definitions for talking to the Open Firmware PROM on
676c1ce78SStephen Rothwell  * Power Macintosh and other computers.
776c1ce78SStephen Rothwell  *
876c1ce78SStephen Rothwell  * Copyright (C) 1996-2005 Paul Mackerras.
976c1ce78SStephen Rothwell  *
1076c1ce78SStephen Rothwell  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
1176c1ce78SStephen Rothwell  * Updates for SPARC64 by David S. Miller
1276c1ce78SStephen Rothwell  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
1376c1ce78SStephen Rothwell  */
1476c1ce78SStephen Rothwell #include <linux/types.h>
151977f032SJiri Slaby #include <linux/bitops.h>
169448e55dSJonathan Cameron #include <linux/cleanup.h>
17e51130c0SKalle Valo #include <linux/errno.h>
1875b57ecfSGrant Likely #include <linux/kobject.h>
19283029d1SGrant Likely #include <linux/mod_devicetable.h>
20b31384faSRafael J. Wysocki #include <linux/property.h>
217518b589SPantelis Antoniou #include <linux/list.h>
2276c1ce78SStephen Rothwell 
232e89e685SJeremy Kerr #include <asm/byteorder.h>
242e89e685SJeremy Kerr 
25731581e6SGrant Likely typedef u32 phandle;
26731581e6SGrant Likely typedef u32 ihandle;
27731581e6SGrant Likely 
28731581e6SGrant Likely struct property {
29731581e6SGrant Likely 	char	*name;
30731581e6SGrant Likely 	int	length;
31731581e6SGrant Likely 	void	*value;
32731581e6SGrant Likely 	struct property *next;
3316bba30eSRob Herring #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
34731581e6SGrant Likely 	unsigned long _flags;
3516bba30eSRob Herring #endif
3636689ecdSRob Herring #if defined(CONFIG_OF_PROMTREE)
37731581e6SGrant Likely 	unsigned int unique_id;
3836689ecdSRob Herring #endif
39b56b5528SRob Herring #if defined(CONFIG_OF_KOBJ)
4075b57ecfSGrant Likely 	struct bin_attribute attr;
41b56b5528SRob Herring #endif
42731581e6SGrant Likely };
43731581e6SGrant Likely 
446f192492SGrant Likely #if defined(CONFIG_SPARC)
456f192492SGrant Likely struct of_irq_controller;
466f192492SGrant Likely #endif
476f192492SGrant Likely 
486f192492SGrant Likely struct device_node {
496f192492SGrant Likely 	const char *name;
506016a363SGrant Likely 	phandle phandle;
51c22618a1SGrant Likely 	const char *full_name;
528a0662d9SRafael J. Wysocki 	struct fwnode_handle fwnode;
536f192492SGrant Likely 
546f192492SGrant Likely 	struct	property *properties;
556f192492SGrant Likely 	struct	property *deadprops;	/* removed properties */
566f192492SGrant Likely 	struct	device_node *parent;
576f192492SGrant Likely 	struct	device_node *child;
586f192492SGrant Likely 	struct	device_node *sibling;
59b56b5528SRob Herring #if defined(CONFIG_OF_KOBJ)
6075b57ecfSGrant Likely 	struct	kobject kobj;
61b56b5528SRob Herring #endif
626f192492SGrant Likely 	unsigned long _flags;
636f192492SGrant Likely 	void	*data;
646f192492SGrant Likely #if defined(CONFIG_SPARC)
656f192492SGrant Likely 	unsigned int unique_id;
666f192492SGrant Likely 	struct of_irq_controller *irq_trans;
676f192492SGrant Likely #endif
686f192492SGrant Likely };
696f192492SGrant Likely 
70b66548e2SAndreas Herrmann #define MAX_PHANDLE_ARGS NR_FWNODE_REFERENCE_ARGS
7115c9a0acSGrant Likely struct of_phandle_args {
7215c9a0acSGrant Likely 	struct device_node *np;
7315c9a0acSGrant Likely 	int args_count;
7415c9a0acSGrant Likely 	uint32_t args[MAX_PHANDLE_ARGS];
7515c9a0acSGrant Likely };
7615c9a0acSGrant Likely 
7774e1fbb1SJoerg Roedel struct of_phandle_iterator {
7874e1fbb1SJoerg Roedel 	/* Common iterator information */
7974e1fbb1SJoerg Roedel 	const char *cells_name;
8074e1fbb1SJoerg Roedel 	int cell_count;
8174e1fbb1SJoerg Roedel 	const struct device_node *parent;
8274e1fbb1SJoerg Roedel 
8374e1fbb1SJoerg Roedel 	/* List size information */
8474e1fbb1SJoerg Roedel 	const __be32 *list_end;
8574e1fbb1SJoerg Roedel 	const __be32 *phandle_end;
8674e1fbb1SJoerg Roedel 
8774e1fbb1SJoerg Roedel 	/* Current position state */
8874e1fbb1SJoerg Roedel 	const __be32 *cur;
8974e1fbb1SJoerg Roedel 	uint32_t cur_count;
9074e1fbb1SJoerg Roedel 	phandle phandle;
9174e1fbb1SJoerg Roedel 	struct device_node *node;
9274e1fbb1SJoerg Roedel };
9374e1fbb1SJoerg Roedel 
94f5242e5aSGrant Likely struct of_reconfig_data {
95f5242e5aSGrant Likely 	struct device_node	*dn;
96f5242e5aSGrant Likely 	struct property		*prop;
97f5242e5aSGrant Likely 	struct property		*old_prop;
98f5242e5aSGrant Likely };
99f5242e5aSGrant Likely 
1002582c531SStephen Rothwell extern const struct kobj_type of_node_ktype;
1012582c531SStephen Rothwell extern const struct fwnode_operations of_fwnode_ops;
1022582c531SStephen Rothwell 
103d9194e00SFrank Rowand /**
104d9194e00SFrank Rowand  * of_node_init - initialize a devicetree node
105d9194e00SFrank Rowand  * @node: Pointer to device node that has been created by kzalloc()
106d9194e00SFrank Rowand  *
107d9194e00SFrank Rowand  * On return the device_node refcount is set to one.  Use of_node_put()
108d9194e00SFrank Rowand  * on @node when done to free the memory allocated for it.  If the node
109d9194e00SFrank Rowand  * is NOT a dynamic node the memory will not be freed. The decision of
110d9194e00SFrank Rowand  * whether to free the memory will be done by node->release(), which is
111d9194e00SFrank Rowand  * of_node_release().
112d9194e00SFrank Rowand  */
of_node_init(struct device_node * node)1130829f6d1SPantelis Antoniou static inline void of_node_init(struct device_node *node)
1140829f6d1SPantelis Antoniou {
115b56b5528SRob Herring #if defined(CONFIG_OF_KOBJ)
1160829f6d1SPantelis Antoniou 	kobject_init(&node->kobj, &of_node_ktype);
117b56b5528SRob Herring #endif
11801bb86b3SSaravana Kannan 	fwnode_init(&node->fwnode, &of_fwnode_ops);
1190829f6d1SPantelis Antoniou }
1200829f6d1SPantelis Antoniou 
121b56b5528SRob Herring #if defined(CONFIG_OF_KOBJ)
1220c3c234bSRob Herring #define of_node_kobj(n) (&(n)->kobj)
123b56b5528SRob Herring #else
124b56b5528SRob Herring #define of_node_kobj(n) NULL
125b56b5528SRob Herring #endif
1260829f6d1SPantelis Antoniou 
1270f22dd39SGrant Likely #ifdef CONFIG_OF_DYNAMIC
1280f22dd39SGrant Likely extern struct device_node *of_node_get(struct device_node *node);
1290f22dd39SGrant Likely extern void of_node_put(struct device_node *node);
1300f22dd39SGrant Likely #else /* CONFIG_OF_DYNAMIC */
1313ecdd051SRob Herring /* Dummy ref counting routines - to be implemented later */
of_node_get(struct device_node * node)1323ecdd051SRob Herring static inline struct device_node *of_node_get(struct device_node *node)
1333ecdd051SRob Herring {
1343ecdd051SRob Herring 	return node;
1353ecdd051SRob Herring }
of_node_put(struct device_node * node)1360f22dd39SGrant Likely static inline void of_node_put(struct device_node *node) { }
1370f22dd39SGrant Likely #endif /* !CONFIG_OF_DYNAMIC */
1389448e55dSJonathan Cameron DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))
1393ecdd051SRob Herring 
14041f88009SGrant Likely /* Pointer for first entry in chain of all nodes. */
1415063e25aSGrant Likely extern struct device_node *of_root;
142fc0bdae4SGrant Likely extern struct device_node *of_chosen;
143611cad72SShawn Guo extern struct device_node *of_aliases;
144a752ee56SGrant Likely extern struct device_node *of_stdout;
14541f88009SGrant Likely 
146144552c7SFrank Rowand /*
147144552c7SFrank Rowand  * struct device_node flag descriptions
148144552c7SFrank Rowand  * (need to be visible even when !CONFIG_OF)
149144552c7SFrank Rowand  */
150144552c7SFrank Rowand #define OF_DYNAMIC		1 /* (and properties) allocated via kmalloc */
151144552c7SFrank Rowand #define OF_DETACHED		2 /* detached from the device tree */
152144552c7SFrank Rowand #define OF_POPULATED		3 /* device already created */
153144552c7SFrank Rowand #define OF_POPULATED_BUS	4 /* platform bus created for children */
154144552c7SFrank Rowand #define OF_OVERLAY		5 /* allocated for an overlay */
155144552c7SFrank Rowand #define OF_OVERLAY_FREE_CSET	6 /* in overlay cset being freed */
156391b459dSPantelis Antoniou 
157b1d06b60SGuenter Roeck #define OF_BAD_ADDR	((u64)-1)
158b1d06b60SGuenter Roeck 
1596d09dc6bSHans de Goede #ifdef CONFIG_OF
160194ec936SSudeep Holla void of_core_init(void);
161194ec936SSudeep Holla 
is_of_node(const struct fwnode_handle * fwnode)162d20dc149SSakari Ailus static inline bool is_of_node(const struct fwnode_handle *fwnode)
1638a0662d9SRafael J. Wysocki {
164db3e50f3SSakari Ailus 	return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
1658a0662d9SRafael J. Wysocki }
1668a0662d9SRafael J. Wysocki 
167d20dc149SSakari Ailus #define to_of_node(__fwnode)						\
168d20dc149SSakari Ailus 	({								\
169d20dc149SSakari Ailus 		typeof(__fwnode) __to_of_node_fwnode = (__fwnode);	\
170d20dc149SSakari Ailus 									\
171d20dc149SSakari Ailus 		is_of_node(__to_of_node_fwnode) ?			\
172d20dc149SSakari Ailus 			container_of(__to_of_node_fwnode,		\
173d20dc149SSakari Ailus 				     struct device_node, fwnode) :	\
174d20dc149SSakari Ailus 			NULL;						\
175d20dc149SSakari Ailus 	})
1768a0662d9SRafael J. Wysocki 
177debd3a3bSSakari Ailus #define of_fwnode_handle(node)						\
178debd3a3bSSakari Ailus 	({								\
179debd3a3bSSakari Ailus 		typeof(node) __of_fwnode_handle_node = (node);		\
180debd3a3bSSakari Ailus 									\
181debd3a3bSSakari Ailus 		__of_fwnode_handle_node ?				\
182debd3a3bSSakari Ailus 			&__of_fwnode_handle_node->fwnode : NULL;	\
183debd3a3bSSakari Ailus 	})
18467831837SSakari Ailus 
of_node_is_root(const struct device_node * node)185035ebefcSAndres Salomon static inline bool of_node_is_root(const struct device_node *node)
186035ebefcSAndres Salomon {
187035ebefcSAndres Salomon 	return node && (node->parent == NULL);
188035ebefcSAndres Salomon }
189035ebefcSAndres Salomon 
of_node_check_flag(const struct device_node * n,unsigned long flag)190a3c85b2eSNathan Lynch static inline int of_node_check_flag(const struct device_node *n, unsigned long flag)
19150436312SGrant Likely {
19250436312SGrant Likely 	return test_bit(flag, &n->_flags);
19350436312SGrant Likely }
19450436312SGrant Likely 
of_node_test_and_set_flag(struct device_node * n,unsigned long flag)195c6e126deSPawel Moll static inline int of_node_test_and_set_flag(struct device_node *n,
196c6e126deSPawel Moll 					    unsigned long flag)
197c6e126deSPawel Moll {
198c6e126deSPawel Moll 	return test_and_set_bit(flag, &n->_flags);
199c6e126deSPawel Moll }
200c6e126deSPawel Moll 
of_node_set_flag(struct device_node * n,unsigned long flag)20150436312SGrant Likely static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
20250436312SGrant Likely {
20350436312SGrant Likely 	set_bit(flag, &n->_flags);
20450436312SGrant Likely }
20550436312SGrant Likely 
of_node_clear_flag(struct device_node * n,unsigned long flag)206588453c6SPantelis Antoniou static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
207588453c6SPantelis Antoniou {
208588453c6SPantelis Antoniou 	clear_bit(flag, &n->_flags);
209588453c6SPantelis Antoniou }
210588453c6SPantelis Antoniou 
21116bba30eSRob Herring #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
of_property_check_flag(const struct property * p,unsigned long flag)21239d64960SClément Léger static inline int of_property_check_flag(const struct property *p, unsigned long flag)
213588453c6SPantelis Antoniou {
214588453c6SPantelis Antoniou 	return test_bit(flag, &p->_flags);
215588453c6SPantelis Antoniou }
216588453c6SPantelis Antoniou 
of_property_set_flag(struct property * p,unsigned long flag)217588453c6SPantelis Antoniou static inline void of_property_set_flag(struct property *p, unsigned long flag)
218588453c6SPantelis Antoniou {
219588453c6SPantelis Antoniou 	set_bit(flag, &p->_flags);
220588453c6SPantelis Antoniou }
221588453c6SPantelis Antoniou 
of_property_clear_flag(struct property * p,unsigned long flag)222588453c6SPantelis Antoniou static inline void of_property_clear_flag(struct property *p, unsigned long flag)
223588453c6SPantelis Antoniou {
224588453c6SPantelis Antoniou 	clear_bit(flag, &p->_flags);
225588453c6SPantelis Antoniou }
22616bba30eSRob Herring #endif
227588453c6SPantelis Antoniou 
2285063e25aSGrant Likely extern struct device_node *__of_find_all_nodes(struct device_node *prev);
229e91edcf5SGrant Likely extern struct device_node *of_find_all_nodes(struct device_node *prev);
230e91edcf5SGrant Likely 
231b6caf2adSGrant Likely /*
2323d6b8828SLennert Buytenhek  * OF address retrieval & translation
233b6caf2adSGrant Likely  */
234b6caf2adSGrant Likely 
235b6caf2adSGrant Likely /* Helper to read a big number; size is in cells (not bytes) */
of_read_number(const __be32 * cell,int size)2362e89e685SJeremy Kerr static inline u64 of_read_number(const __be32 *cell, int size)
237b6caf2adSGrant Likely {
238b6caf2adSGrant Likely 	u64 r = 0;
23944086866SPhong Tran 	for (; size--; cell++)
24044086866SPhong Tran 		r = (r << 32) | be32_to_cpu(*cell);
241b6caf2adSGrant Likely 	return r;
242b6caf2adSGrant Likely }
243b6caf2adSGrant Likely 
244b6caf2adSGrant Likely /* Like of_read_number, but we want an unsigned long result */
of_read_ulong(const __be32 * cell,int size)2452e89e685SJeremy Kerr static inline unsigned long of_read_ulong(const __be32 *cell, int size)
246b6caf2adSGrant Likely {
2472be09cb9SGrant Likely 	/* toss away upper bits if unsigned long is smaller than u64 */
2482be09cb9SGrant Likely 	return of_read_number(cell, size);
249b6caf2adSGrant Likely }
250b6caf2adSGrant Likely 
251b5b4bb3fSRob Herring #if defined(CONFIG_SPARC)
25276c1ce78SStephen Rothwell #include <asm/prom.h>
253b5b4bb3fSRob Herring #endif
25476c1ce78SStephen Rothwell 
25561e955dbSGrant Likely #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
25661e955dbSGrant Likely #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
25761e955dbSGrant Likely 
258f42b0e18SRob Herring extern bool of_node_name_eq(const struct device_node *np, const char *name);
259f42b0e18SRob Herring extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
260f42b0e18SRob Herring 
of_node_full_name(const struct device_node * np)261c0a05bf0SSteffen Trumtrar static inline const char *of_node_full_name(const struct device_node *np)
26274a7f084SGrant Likely {
26374a7f084SGrant Likely 	return np ? np->full_name : "<no-node>";
26474a7f084SGrant Likely }
26574a7f084SGrant Likely 
2665063e25aSGrant Likely #define for_each_of_allnodes_from(from, dn) \
2675063e25aSGrant Likely 	for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
2685063e25aSGrant Likely #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
26976c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_name(struct device_node *from,
27076c1ce78SStephen Rothwell 	const char *name);
27176c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_type(struct device_node *from,
27276c1ce78SStephen Rothwell 	const char *type);
27376c1ce78SStephen Rothwell extern struct device_node *of_find_compatible_node(struct device_node *from,
27476c1ce78SStephen Rothwell 	const char *type, const char *compat);
27550c8af4cSStephen Warren extern struct device_node *of_find_matching_node_and_match(
27650c8af4cSStephen Warren 	struct device_node *from,
27750c8af4cSStephen Warren 	const struct of_device_id *matches,
27850c8af4cSStephen Warren 	const struct of_device_id **match);
279662372e4SRob Herring 
28075c28c09SLeif Lindholm extern struct device_node *of_find_node_opts_by_path(const char *path,
28175c28c09SLeif Lindholm 	const char **opts);
of_find_node_by_path(const char * path)28275c28c09SLeif Lindholm static inline struct device_node *of_find_node_by_path(const char *path)
28375c28c09SLeif Lindholm {
28475c28c09SLeif Lindholm 	return of_find_node_opts_by_path(path, NULL);
28575c28c09SLeif Lindholm }
28675c28c09SLeif Lindholm 
28776c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_phandle(phandle handle);
28876c1ce78SStephen Rothwell extern struct device_node *of_get_parent(const struct device_node *node);
289f4eb0107SMichael Ellerman extern struct device_node *of_get_next_parent(struct device_node *node);
29076c1ce78SStephen Rothwell extern struct device_node *of_get_next_child(const struct device_node *node,
29176c1ce78SStephen Rothwell 					     struct device_node *prev);
2921fcc67e3SChen-Yu Tsai extern struct device_node *of_get_next_child_with_prefix(const struct device_node *node,
2931fcc67e3SChen-Yu Tsai 							 struct device_node *prev,
2941fcc67e3SChen-Yu Tsai 							 const char *prefix);
2953296193dSTimur Tabi extern struct device_node *of_get_next_available_child(
2963296193dSTimur Tabi 	const struct device_node *node, struct device_node *prev);
29728c5d4e4SKuninori Morimoto extern struct device_node *of_get_next_reserved_child(
29828c5d4e4SKuninori Morimoto 	const struct device_node *node, struct device_node *prev);
2993296193dSTimur Tabi 
30036156f92SJohan Hovold extern struct device_node *of_get_compatible_child(const struct device_node *parent,
30136156f92SJohan Hovold 					const char *compatible);
3029c19761aSSrinivas Kandagatla extern struct device_node *of_get_child_by_name(const struct device_node *node,
3039c19761aSSrinivas Kandagatla 					const char *name);
304954e04b9SBryan Wu extern struct device_node *of_get_available_child_by_name(const struct device_node *node,
305a3e31b45SSudeep KarkadaNagesha 							  const char *name);
306a3e31b45SSudeep KarkadaNagesha 
3075fa23530SSudeep Holla /* cache lookup */
3081e291b14SMichael Ellerman extern struct device_node *of_find_next_cache_node(const struct device_node *);
3091e291b14SMichael Ellerman extern int of_find_last_cache_level(unsigned int cpu);
3101e291b14SMichael Ellerman extern struct device_node *of_find_node_with_property(
31176c1ce78SStephen Rothwell 	struct device_node *from, const char *prop_name);
31276c1ce78SStephen Rothwell 
31376c1ce78SStephen Rothwell extern struct property *of_find_property(const struct device_node *np,
314c141ecc3SRob Herring (Arm) 					 const char *name,
315ad54a0cfSHeiko Stuebner 					 int *lenp);
316ad54a0cfSHeiko Stuebner extern bool of_property_read_bool(const struct device_node *np, const char *propname);
317*fd958299SErnest Van Hoecke extern int of_property_count_elems_of_size(const struct device_node *np,
318*fd958299SErnest Van Hoecke 				const char *propname, int elem_size);
319*fd958299SErnest Van Hoecke extern int of_property_read_u16_index(const struct device_node *np,
3203daf3726STony Prisk 				       const char *propname,
3213daf3726STony Prisk 				       u32 index, u16 *out_value);
3223daf3726STony Prisk extern int of_property_read_u32_index(const struct device_node *np,
3232475a2b6SAlistair Popple 				       const char *propname,
3242475a2b6SAlistair Popple 				       u32 index, u32 *out_value);
3252475a2b6SAlistair Popple extern int of_property_read_u64_index(const struct device_node *np,
326a67e9472SRichard Fitzgerald 				       const char *propname,
327a67e9472SRichard Fitzgerald 				       u32 index, u64 *out_value);
328a67e9472SRichard Fitzgerald extern int of_property_read_variable_u8_array(const struct device_node *np,
329a67e9472SRichard Fitzgerald 					const char *propname, u8 *out_values,
330a67e9472SRichard Fitzgerald 					size_t sz_min, size_t sz_max);
331a67e9472SRichard Fitzgerald extern int of_property_read_variable_u16_array(const struct device_node *np,
332a67e9472SRichard Fitzgerald 					const char *propname, u16 *out_values,
333aac285c6SJamie Iles 					size_t sz_min, size_t sz_max);
3340e373639SRob Herring extern int of_property_read_variable_u32_array(const struct device_node *np,
335a67e9472SRichard Fitzgerald 					const char *propname,
336a67e9472SRichard Fitzgerald 					u32 *out_values,
3374cd7f7a3SJamie Iles 					size_t sz_min,
3384cd7f7a3SJamie Iles 					size_t sz_max);
339a67e9472SRichard Fitzgerald extern int of_property_read_u64(const struct device_node *np,
340b31384faSRafael J. Wysocki 				const char *propname, u64 *out_value);
341b31384faSRafael J. Wysocki extern int of_property_read_variable_u64_array(const struct device_node *np,
342a67e9472SRichard Fitzgerald 					const char *propname,
343a67e9472SRichard Fitzgerald 					u64 *out_values,
3440e373639SRob Herring 					size_t sz_min,
345fe99c707SDavid Rivshin 					size_t sz_max);
346aac285c6SJamie Iles 
347f09bc831SShawn Guo extern int of_property_read_string(const struct device_node *np,
348fe99c707SDavid Rivshin 				   const char *propname,
3497aff0fe3SGrant Likely 				   const char **out_string);
3507aff0fe3SGrant Likely extern int of_property_match_string(const struct device_node *np,
351fe99c707SDavid Rivshin 				    const char *propname,
352a87fa1d8SGrant Likely 				    const char *string);
353a87fa1d8SGrant Likely extern int of_property_read_string_helper(const struct device_node *np,
35476c1ce78SStephen Rothwell 					      const char *propname,
35576c1ce78SStephen Rothwell 					      const char **out_strs, size_t sz, int index);
35688269151SDmitry Torokhov extern int of_device_is_compatible(const struct device_node *device,
357b9c13fe3SBenjamin Herrenschmidt 				   const char *);
35853a4ab96SKevin Cernekee extern int of_device_compatible_match(const struct device_node *device,
35937786c7fSKevin Cernekee 				      const char *const *compat);
36076c1ce78SStephen Rothwell extern bool of_device_is_available(const struct device_node *device);
36176c1ce78SStephen Rothwell extern bool of_device_is_big_endian(const struct device_node *device);
36276c1ce78SStephen Rothwell extern const void *of_get_property(const struct device_node *node,
363183912d3SSudeep KarkadaNagesha 				const char *name,
364b58fa269SRob Herring 				int *lenp);
365b58fa269SRob Herring extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
366f1f207e4SRob Herring extern struct device_node *of_cpu_device_node_get(int cpu);
367ec8c2329SRob Herring (Arm) extern int of_cpu_node_to_id(struct device_node *np);
368b9f8c26aSUlf Hansson extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
369795e92ecSRob Herring extern struct device_node *of_get_cpu_state_node(const struct device_node *cpu_node,
370f1f207e4SRob Herring 						 int index);
37176c1ce78SStephen Rothwell extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread);
37276c1ce78SStephen Rothwell 
373283029d1SGrant Likely extern int of_n_addr_cells(struct device_node *np);
374283029d1SGrant Likely extern int of_n_size_cells(struct device_node *np);
37582174a0aSRob Herring extern const struct of_device_id *of_match_node(
376673aa1edSMiquel Raynal 	const struct of_device_id *matches, const struct device_node *node);
377673aa1edSMiquel Raynal extern const void *of_device_get_match_data(const struct device *dev);
378624cfca5SGrant Likely extern int of_alias_from_compatible(const struct device_node *node, char *alias,
37966a8f7f0SMichael Walle 				    int len);
38066a8f7f0SMichael Walle extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
38166a8f7f0SMichael Walle extern int __of_parse_phandle_with_args(const struct device_node *np,
382bd6f2fd5SStephen Boyd 	const char *list_name, const char *cells_name, int cell_count,
383bd6f2fd5SStephen Boyd 	int index, struct of_phandle_args *out_args);
384bd6f2fd5SStephen Boyd extern int of_parse_phandle_with_args_map(const struct device_node *np,
385bd69f73fSGrant Likely 	const char *list_name, const char *stem_name, int index,
386bd69f73fSGrant Likely 	struct of_phandle_args *out_args);
38776c1ce78SStephen Rothwell extern int of_count_phandle_with_args(const struct device_node *np,
388bd7a7ed7SMiquel Raynal 	const char *list_name, const char *cells_name);
389bd7a7ed7SMiquel Raynal 
390e6506f06SMiquel Raynal /* module functions */
391bd7a7ed7SMiquel Raynal extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len);
39274e1fbb1SJoerg Roedel extern int of_request_module(const struct device_node *np);
39374e1fbb1SJoerg Roedel 
39474e1fbb1SJoerg Roedel /* phandle iterator functions */
39574e1fbb1SJoerg Roedel extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
39674e1fbb1SJoerg Roedel 				    const struct device_node *np,
39774e1fbb1SJoerg Roedel 				    const char *list_name,
39874e1fbb1SJoerg Roedel 				    const char *cells_name,
399cd209b41SJoerg Roedel 				    int cell_count);
400abdaa77bSJoerg Roedel 
401abdaa77bSJoerg Roedel extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
402abdaa77bSJoerg Roedel extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
403cd209b41SJoerg Roedel 				    uint32_t *args,
404ec8c2329SRob Herring (Arm) 				    int size);
405351d224fSWolfram Sang 
406611cad72SShawn Guo extern int of_alias_get_id(const struct device_node *np, const char *stem);
407c029b22fSMichael Ellerman extern int of_alias_get_highest_id(const char *stem);
40821b082ecSGrant Likely 
4091ac8205fSChristophe Leroy bool of_machine_compatible_match(const char *const *compats);
4101ac8205fSChristophe Leroy 
4111ac8205fSChristophe Leroy /**
4121ac8205fSChristophe Leroy  * of_machine_is_compatible - Test root of device tree for a given compatible value
4131ac8205fSChristophe Leroy  * @compat: compatible string to look for in root node's compatible property.
4141ac8205fSChristophe Leroy  *
4151ac8205fSChristophe Leroy  * Return: true if the root node has the given value in its compatible property.
4161ac8205fSChristophe Leroy  */
of_machine_is_compatible(const char * compat)4171ac8205fSChristophe Leroy static inline bool of_machine_is_compatible(const char *compat)
4181ac8205fSChristophe Leroy {
4191ac8205fSChristophe Leroy 	const char *compats[] = { compat, NULL };
4201ac8205fSChristophe Leroy 
42121b082ecSGrant Likely 	return of_machine_compatible_match(compats);
42279d1c712SNathan Fontenot }
42379d1c712SNathan Fontenot 
42479d1c712SNathan Fontenot extern int of_add_property(struct device_node *np, struct property *prop);
42521b082ecSGrant Likely extern int of_remove_property(struct device_node *np, struct property *prop);
426fcdeb7feSGrant Likely extern int of_update_property(struct device_node *np, struct property *newprop);
4271cf3d8b3SNathan Fontenot 
4281cf3d8b3SNathan Fontenot /* For updating the device tree at runtime */
4291cf3d8b3SNathan Fontenot #define OF_RECONFIG_ATTACH_NODE		0x0001
4301cf3d8b3SNathan Fontenot #define OF_RECONFIG_DETACH_NODE		0x0002
4311cf3d8b3SNathan Fontenot #define OF_RECONFIG_ADD_PROPERTY	0x0003
4321cf3d8b3SNathan Fontenot #define OF_RECONFIG_REMOVE_PROPERTY	0x0004
4331cf3d8b3SNathan Fontenot #define OF_RECONFIG_UPDATE_PROPERTY	0x0005
4341cf3d8b3SNathan Fontenot 
435fcdeb7feSGrant Likely extern int of_attach_node(struct device_node *);
4363a1e362eSBen Dooks extern int of_detach_node(struct device_node *);
437c541adc6SStephen Warren 
438c541adc6SStephen Warren #define of_match_ptr(_ptr)	(_ptr)
439c541adc6SStephen Warren 
440c541adc6SStephen Warren /*
4419722c3b6SLuca Ceresoli  * u32 u;
442c541adc6SStephen Warren  *
443c541adc6SStephen Warren  * of_property_for_each_u32(np, "propname", u)
4449c63fea9SRob Herring (Arm)  *         printk("U32 value: %x\n", u);
445c541adc6SStephen Warren  */
446c541adc6SStephen Warren const __be32 *of_prop_next_u32(const struct property *prop, const __be32 *cur,
447c541adc6SStephen Warren 			       u32 *pu);
448c541adc6SStephen Warren /*
449c541adc6SStephen Warren  * struct property *prop;
450c541adc6SStephen Warren  * const char *s;
451c541adc6SStephen Warren  *
452c541adc6SStephen Warren  * of_property_for_each_string(np, "propname", prop, s)
4539c63fea9SRob Herring (Arm)  *         printk("String value: %s\n", s);
454c541adc6SStephen Warren  */
455ec8c2329SRob Herring (Arm) const char *of_prop_next_string(const struct property *prop, const char *cur);
4565c19e952SSascha Hauer 
457ec8c2329SRob Herring (Arm) bool of_console_check(const struct device_node *dn, char *name, int index);
4582a6db719SNipun Gupta 
4592a6db719SNipun Gupta int of_map_id(const struct device_node *np, u32 id,
4602a6db719SNipun Gupta 	       const char *map_name, const char *map_mask_name,
461964db79dSNicolas Saenz Julienne 	       struct device_node **target, u32 *id_out);
462964db79dSNicolas Saenz Julienne 
463b30be4dcSRob Herring phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
464b30be4dcSRob Herring 
465b30be4dcSRob Herring struct kimage;
466b30be4dcSRob Herring void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
467b30be4dcSRob Herring 				   unsigned long initrd_load_addr,
468b98c0239SShawn Guo 				   unsigned long initrd_len,
4693bcbaf6eSSebastian Andrzej Siewior 				   const char *cmdline, size_t extra_fdt_size);
470194ec936SSudeep Holla #else /* CONFIG_OF */
471194ec936SSudeep Holla 
of_core_init(void)472194ec936SSudeep Holla static inline void of_core_init(void)
473194ec936SSudeep Holla {
474d20dc149SSakari Ailus }
4758a0662d9SRafael J. Wysocki 
is_of_node(const struct fwnode_handle * fwnode)4768a0662d9SRafael J. Wysocki static inline bool is_of_node(const struct fwnode_handle *fwnode)
4778a0662d9SRafael J. Wysocki {
4788a0662d9SRafael J. Wysocki 	return false;
479d20dc149SSakari Ailus }
4808a0662d9SRafael J. Wysocki 
to_of_node(const struct fwnode_handle * fwnode)4818a0662d9SRafael J. Wysocki static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
4828a0662d9SRafael J. Wysocki {
4838a0662d9SRafael J. Wysocki 	return NULL;
484f42b0e18SRob Herring }
485f42b0e18SRob Herring 
of_node_name_eq(const struct device_node * np,const char * name)486f42b0e18SRob Herring static inline bool of_node_name_eq(const struct device_node *np, const char *name)
487f42b0e18SRob Herring {
488f42b0e18SRob Herring 	return false;
489f42b0e18SRob Herring }
490f42b0e18SRob Herring 
of_node_name_prefix(const struct device_node * np,const char * prefix)491f42b0e18SRob Herring static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
492f42b0e18SRob Herring {
493f42b0e18SRob Herring 	return false;
4944c358e15SStephen Rothwell }
49574a7f084SGrant Likely 
of_node_full_name(const struct device_node * np)49674a7f084SGrant Likely static inline const char* of_node_full_name(const struct device_node *np)
49774a7f084SGrant Likely {
49874a7f084SGrant Likely 	return "<no-node>";
4991cc44f43SPeter Ujfalusi }
5001cc44f43SPeter Ujfalusi 
of_find_node_by_name(struct device_node * from,const char * name)5011cc44f43SPeter Ujfalusi static inline struct device_node *of_find_node_by_name(struct device_node *from,
5021cc44f43SPeter Ujfalusi 	const char *name)
5031cc44f43SPeter Ujfalusi {
5041cc44f43SPeter Ujfalusi 	return NULL;
505662372e4SRob Herring }
506662372e4SRob Herring 
of_find_node_by_type(struct device_node * from,const char * type)507662372e4SRob Herring static inline struct device_node *of_find_node_by_type(struct device_node *from,
508662372e4SRob Herring 	const char *type)
509662372e4SRob Herring {
510662372e4SRob Herring 	return NULL;
511662372e4SRob Herring }
512662372e4SRob Herring 
of_find_matching_node_and_match(struct device_node * from,const struct of_device_id * matches,const struct of_device_id ** match)513662372e4SRob Herring static inline struct device_node *of_find_matching_node_and_match(
514662372e4SRob Herring 	struct device_node *from,
515662372e4SRob Herring 	const struct of_device_id *matches,
516662372e4SRob Herring 	const struct of_device_id **match)
517662372e4SRob Herring {
518662372e4SRob Herring 	return NULL;
51920cd477cSAlexander Shiyan }
52020cd477cSAlexander Shiyan 
of_find_node_by_path(const char * path)52120cd477cSAlexander Shiyan static inline struct device_node *of_find_node_by_path(const char *path)
52220cd477cSAlexander Shiyan {
52320cd477cSAlexander Shiyan 	return NULL;
52475c28c09SLeif Lindholm }
52575c28c09SLeif Lindholm 
of_find_node_opts_by_path(const char * path,const char ** opts)52675c28c09SLeif Lindholm static inline struct device_node *of_find_node_opts_by_path(const char *path,
52775c28c09SLeif Lindholm 	const char **opts)
52875c28c09SLeif Lindholm {
52975c28c09SLeif Lindholm 	return NULL;
530ce16b9d2SSuman Anna }
531ce16b9d2SSuman Anna 
of_find_node_by_phandle(phandle handle)532ce16b9d2SSuman Anna static inline struct device_node *of_find_node_by_phandle(phandle handle)
533ce16b9d2SSuman Anna {
534ce16b9d2SSuman Anna 	return NULL;
535066ec1ddSAlexander Shiyan }
536066ec1ddSAlexander Shiyan 
of_get_parent(const struct device_node * node)537066ec1ddSAlexander Shiyan static inline struct device_node *of_get_parent(const struct device_node *node)
538066ec1ddSAlexander Shiyan {
539066ec1ddSAlexander Shiyan 	return NULL;
540943c8a80SRandy Dunlap }
541943c8a80SRandy Dunlap 
of_get_next_parent(struct device_node * node)542943c8a80SRandy Dunlap static inline struct device_node *of_get_next_parent(struct device_node *node)
543943c8a80SRandy Dunlap {
544943c8a80SRandy Dunlap 	return NULL;
545662372e4SRob Herring }
546662372e4SRob Herring 
of_get_next_child(const struct device_node * node,struct device_node * prev)547662372e4SRob Herring static inline struct device_node *of_get_next_child(
548662372e4SRob Herring 	const struct device_node *node, struct device_node *prev)
549662372e4SRob Herring {
550662372e4SRob Herring 	return NULL;
551662372e4SRob Herring }
552662372e4SRob Herring 
of_get_next_available_child(const struct device_node * node,struct device_node * prev)553662372e4SRob Herring static inline struct device_node *of_get_next_available_child(
554662372e4SRob Herring 	const struct device_node *node, struct device_node *prev)
555662372e4SRob Herring {
556662372e4SRob Herring 	return NULL;
55728c5d4e4SKuninori Morimoto }
55828c5d4e4SKuninori Morimoto 
of_get_next_reserved_child(const struct device_node * node,struct device_node * prev)55928c5d4e4SKuninori Morimoto static inline struct device_node *of_get_next_reserved_child(
56028c5d4e4SKuninori Morimoto 	const struct device_node *node, struct device_node *prev)
56128c5d4e4SKuninori Morimoto {
56228c5d4e4SKuninori Morimoto 	return NULL;
563662372e4SRob Herring }
564662372e4SRob Herring 
of_find_node_with_property(struct device_node * from,const char * prop_name)565662372e4SRob Herring static inline struct device_node *of_find_node_with_property(
566662372e4SRob Herring 	struct device_node *from, const char *prop_name)
567662372e4SRob Herring {
568662372e4SRob Herring 	return NULL;
56967831837SSakari Ailus }
57067831837SSakari Ailus 
57136156f92SJohan Hovold #define of_fwnode_handle(node) NULL
57236156f92SJohan Hovold 
of_get_compatible_child(const struct device_node * parent,const char * compatible)57336156f92SJohan Hovold static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
57436156f92SJohan Hovold 					const char *compatible)
57536156f92SJohan Hovold {
57636156f92SJohan Hovold 	return NULL;
57725c040c9SOlof Johansson }
57825c040c9SOlof Johansson 
of_get_child_by_name(const struct device_node * node,const char * name)57925c040c9SOlof Johansson static inline struct device_node *of_get_child_by_name(
58025c040c9SOlof Johansson 					const struct device_node *node,
58125c040c9SOlof Johansson 					const char *name)
58225c040c9SOlof Johansson {
58325c040c9SOlof Johansson 	return NULL;
58436a0904eSRajendra Nayak }
58536a0904eSRajendra Nayak 
of_get_available_child_by_name(const struct device_node * node,const char * name)58636a0904eSRajendra Nayak static inline struct device_node *of_get_available_child_by_name(
58736a0904eSRajendra Nayak 					const struct device_node *node,
58836a0904eSRajendra Nayak 					const char *name)
58936a0904eSRajendra Nayak {
59088269151SDmitry Torokhov 	return NULL;
5913bc16307SGeert Uytterhoeven }
5923bc16307SGeert Uytterhoeven 
of_device_is_compatible(const struct device_node * device,const char * name)5933bc16307SGeert Uytterhoeven static inline int of_device_is_compatible(const struct device_node *device,
5943bc16307SGeert Uytterhoeven 					  const char *name)
5953bc16307SGeert Uytterhoeven {
59653a4ab96SKevin Cernekee 	return 0;
597d7195696SRob Herring }
59853a4ab96SKevin Cernekee 
of_device_compatible_match(const struct device_node * device,const char * const * compat)599d7195696SRob Herring static inline  int of_device_compatible_match(const struct device_node *device,
600d7195696SRob Herring 					      const char *const *compat)
60137786c7fSKevin Cernekee {
60237786c7fSKevin Cernekee 	return 0;
60337786c7fSKevin Cernekee }
60437786c7fSKevin Cernekee 
of_device_is_available(const struct device_node * device)60537786c7fSKevin Cernekee static inline bool of_device_is_available(const struct device_node *device)
606aba3dfffSStephen Warren {
607aba3dfffSStephen Warren 	return false;
608aba3dfffSStephen Warren }
609aba3dfffSStephen Warren 
of_device_is_big_endian(const struct device_node * device)610aba3dfffSStephen Warren static inline bool of_device_is_big_endian(const struct device_node *device)
611aba3dfffSStephen Warren {
612aba3dfffSStephen Warren 	return false;
6132261cc62SShawn Guo }
6142261cc62SShawn Guo 
of_find_property(const struct device_node * np,const char * name,int * lenp)6152261cc62SShawn Guo static inline struct property *of_find_property(const struct device_node *np,
6162261cc62SShawn Guo 						const char *name,
6172261cc62SShawn Guo 						int *lenp)
6182261cc62SShawn Guo {
6192261cc62SShawn Guo 	return NULL;
6202261cc62SShawn Guo }
621c141ecc3SRob Herring (Arm) 
of_find_compatible_node(struct device_node * from,const char * type,const char * compat)622c141ecc3SRob Herring (Arm) static inline struct device_node *of_find_compatible_node(
623c141ecc3SRob Herring (Arm) 						struct device_node *from,
624c141ecc3SRob Herring (Arm) 						const char *type,
625c141ecc3SRob Herring (Arm) 						const char *compat)
626c141ecc3SRob Herring (Arm) {
627ad54a0cfSHeiko Stuebner 	return NULL;
628ad54a0cfSHeiko Stuebner }
629ad54a0cfSHeiko Stuebner 
of_property_read_bool(const struct device_node * np,const char * propname)630ad54a0cfSHeiko Stuebner static inline bool of_property_read_bool(const struct device_node *np,
631ad54a0cfSHeiko Stuebner 					const char *propname)
632ad54a0cfSHeiko Stuebner {
633*fd958299SErnest Van Hoecke 	return false;
634*fd958299SErnest Van Hoecke }
635*fd958299SErnest Van Hoecke 
of_property_count_elems_of_size(const struct device_node * np,const char * propname,int elem_size)636*fd958299SErnest Van Hoecke static inline int of_property_count_elems_of_size(const struct device_node *np,
637*fd958299SErnest Van Hoecke 			const char *propname, int elem_size)
638*fd958299SErnest Van Hoecke {
63996c623e5SArnd Bergmann 	return -ENOSYS;
64096c623e5SArnd Bergmann }
641b98c0239SShawn Guo 
of_property_read_u16_index(const struct device_node * np,const char * propname,u32 index,u16 * out_value)642b98c0239SShawn Guo static inline int of_property_read_u16_index(const struct device_node *np,
643b98c0239SShawn Guo 			const char *propname, u32 index, u16 *out_value)
644b98c0239SShawn Guo {
64596c623e5SArnd Bergmann 	return -ENOSYS;
64696c623e5SArnd Bergmann }
6474fcd15a0SBenoit Cousson 
of_property_read_u32_index(const struct device_node * np,const char * propname,u32 index,u32 * out_value)6484fcd15a0SBenoit Cousson static inline int of_property_read_u32_index(const struct device_node *np,
6494fcd15a0SBenoit Cousson 			const char *propname, u32 index, u32 *out_value)
6504fcd15a0SBenoit Cousson {
65189272b8cSStephen Warren 	return -ENOSYS;
65289272b8cSStephen Warren }
65389272b8cSStephen Warren 
of_property_read_u64_index(const struct device_node * np,const char * propname,u32 index,u64 * out_value)65489272b8cSStephen Warren static inline int of_property_read_u64_index(const struct device_node *np,
65589272b8cSStephen Warren 			const char *propname, u32 index, u64 *out_value)
65689272b8cSStephen Warren {
65789272b8cSStephen Warren 	return -ENOSYS;
658183912d3SSudeep KarkadaNagesha }
659183912d3SSudeep KarkadaNagesha 
of_get_property(const struct device_node * node,const char * name,int * lenp)660183912d3SSudeep KarkadaNagesha static inline const void *of_get_property(const struct device_node *node,
661183912d3SSudeep KarkadaNagesha 				const char *name,
662183912d3SSudeep KarkadaNagesha 				int *lenp)
663183912d3SSudeep KarkadaNagesha {
664b58fa269SRob Herring 	return NULL;
665b58fa269SRob Herring }
666b58fa269SRob Herring 
of_get_cpu_node(int cpu,unsigned int * thread)667b58fa269SRob Herring static inline struct device_node *of_get_cpu_node(int cpu,
668b58fa269SRob Herring 					unsigned int *thread)
669b58fa269SRob Herring {
670b58fa269SRob Herring 	return NULL;
671b58fa269SRob Herring }
672b58fa269SRob Herring 
of_cpu_device_node_get(int cpu)673b58fa269SRob Herring static inline struct device_node *of_cpu_device_node_get(int cpu)
674f1f207e4SRob Herring {
675f1f207e4SRob Herring 	return NULL;
676f1f207e4SRob Herring }
677f1f207e4SRob Herring 
of_cpu_node_to_id(struct device_node * np)678f1f207e4SRob Herring static inline int of_cpu_node_to_id(struct device_node *np)
679b9f8c26aSUlf Hansson {
680b9f8c26aSUlf Hansson 	return -ENODEV;
681b9f8c26aSUlf Hansson }
682b9f8c26aSUlf Hansson 
of_get_next_cpu_node(struct device_node * prev)683b9f8c26aSUlf Hansson static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
684b9f8c26aSUlf Hansson {
6858a1ac5dcSArnd Bergmann 	return NULL;
6868a1ac5dcSArnd Bergmann }
6878a1ac5dcSArnd Bergmann 
of_get_cpu_state_node(struct device_node * cpu_node,int index)6888a1ac5dcSArnd Bergmann static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
6898a1ac5dcSArnd Bergmann 					int index)
6908a1ac5dcSArnd Bergmann {
6918a1ac5dcSArnd Bergmann 	return NULL;
6928a1ac5dcSArnd Bergmann }
6938a1ac5dcSArnd Bergmann 
of_n_addr_cells(struct device_node * np)6948a1ac5dcSArnd Bergmann static inline int of_n_addr_cells(struct device_node *np)
69596c623e5SArnd Bergmann {
69696c623e5SArnd Bergmann 	return 0;
69796c623e5SArnd Bergmann 
69896c623e5SArnd Bergmann }
of_n_size_cells(struct device_node * np)69996c623e5SArnd Bergmann static inline int of_n_size_cells(struct device_node *np)
70096c623e5SArnd Bergmann {
70196c623e5SArnd Bergmann 	return 0;
70296c623e5SArnd Bergmann }
70396c623e5SArnd Bergmann 
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)70496c623e5SArnd Bergmann static inline int of_property_read_variable_u8_array(const struct device_node *np,
70596c623e5SArnd Bergmann 					const char *propname, u8 *out_values,
70696c623e5SArnd Bergmann 					size_t sz_min, size_t sz_max)
70796c623e5SArnd Bergmann {
70896c623e5SArnd Bergmann 	return -ENOSYS;
70996c623e5SArnd Bergmann }
71096c623e5SArnd Bergmann 
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)71196c623e5SArnd Bergmann static inline int of_property_read_variable_u16_array(const struct device_node *np,
71296c623e5SArnd Bergmann 					const char *propname, u16 *out_values,
71396c623e5SArnd Bergmann 					size_t sz_min, size_t sz_max)
71496c623e5SArnd Bergmann {
71596c623e5SArnd Bergmann 	return -ENOSYS;
71696c623e5SArnd Bergmann }
71796c623e5SArnd Bergmann 
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)7184cd7f7a3SJamie Iles static inline int of_property_read_variable_u32_array(const struct device_node *np,
7194cd7f7a3SJamie Iles 					const char *propname,
7204cd7f7a3SJamie Iles 					u32 *out_values,
7214cd7f7a3SJamie Iles 					size_t sz_min,
7224cd7f7a3SJamie Iles 					size_t sz_max)
7234cd7f7a3SJamie Iles {
72496c623e5SArnd Bergmann 	return -ENOSYS;
72596c623e5SArnd Bergmann }
72696c623e5SArnd Bergmann 
of_property_read_u64(const struct device_node * np,const char * propname,u64 * out_value)72796c623e5SArnd Bergmann static inline int of_property_read_u64(const struct device_node *np,
72896c623e5SArnd Bergmann 				       const char *propname, u64 *out_value)
72996c623e5SArnd Bergmann {
73096c623e5SArnd Bergmann 	return -ENOSYS;
73196c623e5SArnd Bergmann }
73296c623e5SArnd Bergmann 
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)73396c623e5SArnd Bergmann static inline int of_property_read_variable_u64_array(const struct device_node *np,
73496c623e5SArnd Bergmann 					const char *propname,
73596c623e5SArnd Bergmann 					u64 *out_values,
73696c623e5SArnd Bergmann 					size_t sz_min,
73796c623e5SArnd Bergmann 					size_t sz_max)
73896c623e5SArnd Bergmann {
73996c623e5SArnd Bergmann 	return -ENOSYS;
740fe99c707SDavid Rivshin }
741bd3d5500SThierry Reding 
of_property_read_string(const struct device_node * np,const char * propname,const char ** out_string)742bd3d5500SThierry Reding static inline int of_property_read_string(const struct device_node *np,
743bd3d5500SThierry Reding 					  const char *propname,
744bd3d5500SThierry Reding 					  const char **out_string)
745bd3d5500SThierry Reding {
746bd3d5500SThierry Reding 	return -ENOSYS;
74796c623e5SArnd Bergmann }
74896c623e5SArnd Bergmann 
of_property_match_string(const struct device_node * np,const char * propname,const char * string)74996c623e5SArnd Bergmann static inline int of_property_match_string(const struct device_node *np,
75096c623e5SArnd Bergmann 					   const char *propname,
75196c623e5SArnd Bergmann 					   const char *string)
75296c623e5SArnd Bergmann {
75396c623e5SArnd Bergmann 	return -ENOSYS;
75466a8f7f0SMichael Walle }
755e05e5070SThierry Reding 
of_property_read_string_helper(const struct device_node * np,const char * propname,const char ** out_strs,size_t sz,int index)756e05e5070SThierry Reding static inline int of_property_read_string_helper(const struct device_node *np,
75766a8f7f0SMichael Walle 						 const char *propname,
758e05e5070SThierry Reding 						 const char **out_strs, size_t sz, int index)
759e05e5070SThierry Reding {
760e05e5070SThierry Reding 	return -ENOSYS;
761e05e5070SThierry Reding }
762e05e5070SThierry Reding 
__of_parse_phandle_with_args(const struct device_node * np,const char * list_name,const char * cells_name,int cell_count,int index,struct of_phandle_args * out_args)763e05e5070SThierry Reding static inline int __of_parse_phandle_with_args(const struct device_node *np,
764bd6f2fd5SStephen Boyd 					       const char *list_name,
765bd6f2fd5SStephen Boyd 					       const char *cells_name,
766bd6f2fd5SStephen Boyd 					       int cell_count,
767bd6f2fd5SStephen Boyd 					       int index,
768bd6f2fd5SStephen Boyd 					       struct of_phandle_args *out_args)
769bd6f2fd5SStephen Boyd {
770bd6f2fd5SStephen Boyd 	return -ENOSYS;
771bd6f2fd5SStephen Boyd }
772bd6f2fd5SStephen Boyd 
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)773a065d561SKrzysztof Kozlowski static inline int of_parse_phandle_with_args_map(const struct device_node *np,
774bd69f73fSGrant Likely 						 const char *list_name,
775bd69f73fSGrant Likely 						 const char *stem_name,
776bd69f73fSGrant Likely 						 int index,
777bd69f73fSGrant Likely 						 struct of_phandle_args *out_args)
778bd69f73fSGrant Likely {
779bd69f73fSGrant Likely 	return -ENOSYS;
780bd7a7ed7SMiquel Raynal }
781bd7a7ed7SMiquel Raynal 
of_count_phandle_with_args(const struct device_node * np,const char * list_name,const char * cells_name)782bd7a7ed7SMiquel Raynal static inline int of_count_phandle_with_args(const struct device_node *np,
783bd7a7ed7SMiquel Raynal 					     const char *list_name,
784bd7a7ed7SMiquel Raynal 					     const char *cells_name)
785bd7a7ed7SMiquel Raynal {
786e6506f06SMiquel Raynal 	return -ENOSYS;
787e6506f06SMiquel Raynal }
788e6506f06SMiquel Raynal 
of_modalias(const struct device_node * np,char * str,ssize_t len)789e6506f06SMiquel Raynal static inline ssize_t of_modalias(const struct device_node *np, char *str,
790e6506f06SMiquel Raynal 				  ssize_t len)
79174e1fbb1SJoerg Roedel {
79274e1fbb1SJoerg Roedel 	return -ENODEV;
79374e1fbb1SJoerg Roedel }
79474e1fbb1SJoerg Roedel 
of_request_module(const struct device_node * np)79574e1fbb1SJoerg Roedel static inline int of_request_module(const struct device_node *np)
79674e1fbb1SJoerg Roedel {
79774e1fbb1SJoerg Roedel 	return -ENODEV;
79874e1fbb1SJoerg Roedel }
79974e1fbb1SJoerg Roedel 
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)800cd209b41SJoerg Roedel static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
801cd209b41SJoerg Roedel 					   const struct device_node *np,
802cd209b41SJoerg Roedel 					   const char *list_name,
803cd209b41SJoerg Roedel 					   const char *cells_name,
804cd209b41SJoerg Roedel 					   int cell_count)
805abdaa77bSJoerg Roedel {
806abdaa77bSJoerg Roedel 	return -ENOSYS;
807abdaa77bSJoerg Roedel }
808abdaa77bSJoerg Roedel 
of_phandle_iterator_next(struct of_phandle_iterator * it)809abdaa77bSJoerg Roedel static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
810abdaa77bSJoerg Roedel {
811abdaa77bSJoerg Roedel 	return -ENOSYS;
812ed5f886dSNicolas Ferre }
813ed5f886dSNicolas Ferre 
of_phandle_iterator_args(struct of_phandle_iterator * it,uint32_t * args,int size)814ed5f886dSNicolas Ferre static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
815ed5f886dSNicolas Ferre 					   uint32_t *args,
816ed5f886dSNicolas Ferre 					   int size)
817351d224fSWolfram Sang {
818351d224fSWolfram Sang 	return 0;
819351d224fSWolfram Sang }
820351d224fSWolfram Sang 
of_alias_get_id(struct device_node * np,const char * stem)821351d224fSWolfram Sang static inline int of_alias_get_id(struct device_node *np, const char *stem)
82250e07f88SStephen Warren {
82350e07f88SStephen Warren 	return -ENOSYS;
82450e07f88SStephen Warren }
82550e07f88SStephen Warren 
of_alias_get_highest_id(const char * stem)82650e07f88SStephen Warren static inline int of_alias_get_highest_id(const char *stem)
827fe794e39SWesley Cheng {
828fe794e39SWesley Cheng 	return -ENOSYS;
829fe794e39SWesley Cheng }
830fe794e39SWesley Cheng 
of_machine_is_compatible(const char * compat)831fe794e39SWesley Cheng static inline int of_machine_is_compatible(const char *compat)
8320f7c5317SFlorian Fainelli {
8330f7c5317SFlorian Fainelli 	return 0;
8340f7c5317SFlorian Fainelli }
8350f7c5317SFlorian Fainelli 
of_add_property(struct device_node * np,struct property * prop)8360f7c5317SFlorian Fainelli static inline int of_add_property(struct device_node *np, struct property *prop)
837c029b22fSMichael Ellerman {
838c029b22fSMichael Ellerman 	return 0;
839c029b22fSMichael Ellerman }
840c029b22fSMichael Ellerman 
of_remove_property(struct device_node * np,struct property * prop)841c029b22fSMichael Ellerman static inline int of_remove_property(struct device_node *np, struct property *prop)
8423482f2c5SGrant Likely {
8435c19e952SSascha Hauer 	return 0;
8443482f2c5SGrant Likely }
8455c19e952SSascha Hauer 
of_machine_compatible_match(const char * const * compats)8465c19e952SSascha Hauer static inline bool of_machine_compatible_match(const char *const *compats)
8479c63fea9SRob Herring (Arm) {
8482adfffa2SSebastian Andrzej Siewior 	return false;
8492adfffa2SSebastian Andrzej Siewior }
8502adfffa2SSebastian Andrzej Siewior 
of_console_check(const struct device_node * dn,const char * name,int index)8512adfffa2SSebastian Andrzej Siewior static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
8522adfffa2SSebastian Andrzej Siewior {
8539c63fea9SRob Herring (Arm) 	return false;
8542adfffa2SSebastian Andrzej Siewior }
8552adfffa2SSebastian Andrzej Siewior 
of_prop_next_u32(const struct property * prop,const __be32 * cur,u32 * pu)8562adfffa2SSebastian Andrzej Siewior static inline const __be32 *of_prop_next_u32(const struct property *prop,
8572adfffa2SSebastian Andrzej Siewior 		const __be32 *cur, u32 *pu)
8582adfffa2SSebastian Andrzej Siewior {
8590384e8c6SPantelis Antoniou 	return NULL;
8600384e8c6SPantelis Antoniou }
8610384e8c6SPantelis Antoniou 
of_prop_next_string(const struct property * prop,const char * cur)8620384e8c6SPantelis Antoniou static inline const char *of_prop_next_string(const struct property *prop,
8630384e8c6SPantelis Antoniou 		const char *cur)
8640384e8c6SPantelis Antoniou {
8650384e8c6SPantelis Antoniou 	return NULL;
8660384e8c6SPantelis Antoniou }
8670384e8c6SPantelis Antoniou 
of_node_check_flag(struct device_node * n,unsigned long flag)8680384e8c6SPantelis Antoniou static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
8690384e8c6SPantelis Antoniou {
8700384e8c6SPantelis Antoniou 	return 0;
8710384e8c6SPantelis Antoniou }
8720384e8c6SPantelis Antoniou 
of_node_test_and_set_flag(struct device_node * n,unsigned long flag)8730384e8c6SPantelis Antoniou static inline int of_node_test_and_set_flag(struct device_node *n,
8740384e8c6SPantelis Antoniou 					    unsigned long flag)
8750384e8c6SPantelis Antoniou {
8760384e8c6SPantelis Antoniou 	return 0;
8770384e8c6SPantelis Antoniou }
87839d64960SClément Léger 
of_node_set_flag(struct device_node * n,unsigned long flag)87939d64960SClément Léger static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
8800384e8c6SPantelis Antoniou {
8810384e8c6SPantelis Antoniou }
8820384e8c6SPantelis Antoniou 
of_node_clear_flag(struct device_node * n,unsigned long flag)8830384e8c6SPantelis Antoniou static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
8840384e8c6SPantelis Antoniou {
8850384e8c6SPantelis Antoniou }
8860384e8c6SPantelis Antoniou 
of_property_check_flag(const struct property * p,unsigned long flag)8870384e8c6SPantelis Antoniou static inline int of_property_check_flag(const struct property *p,
8880384e8c6SPantelis Antoniou 					 unsigned long flag)
8890384e8c6SPantelis Antoniou {
8900384e8c6SPantelis Antoniou 	return 0;
8910384e8c6SPantelis Antoniou }
892ec8c2329SRob Herring (Arm) 
of_property_set_flag(struct property * p,unsigned long flag)8932a6db719SNipun Gupta static inline void of_property_set_flag(struct property *p, unsigned long flag)
8942a6db719SNipun Gupta {
8952a6db719SNipun Gupta }
8962a6db719SNipun Gupta 
of_property_clear_flag(struct property * p,unsigned long flag)8972a6db719SNipun Gupta static inline void of_property_clear_flag(struct property *p, unsigned long flag)
8982a6db719SNipun Gupta {
899964db79dSNicolas Saenz Julienne }
900964db79dSNicolas Saenz Julienne 
of_map_id(const struct device_node * np,u32 id,const char * map_name,const char * map_mask_name,struct device_node ** target,u32 * id_out)901964db79dSNicolas Saenz Julienne static inline int of_map_id(const struct device_node *np, u32 id,
902964db79dSNicolas Saenz Julienne 			     const char *map_name, const char *map_mask_name,
903964db79dSNicolas Saenz Julienne 			     struct device_node **target, u32 *id_out)
90482174a0aSRob Herring {
90582174a0aSRob Herring 	return -EINVAL;
90682174a0aSRob Herring }
90782174a0aSRob Herring 
of_dma_get_max_cpu_address(struct device_node * np)90882174a0aSRob Herring static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
9093a1e362eSBen Dooks {
9105762c205SNicolas Ferre 	return PHYS_ADDR_MAX;
9119dfbf207SJeremy Kerr }
912b98c0239SShawn Guo 
of_device_get_match_data(const struct device * dev)913613e9721SAdam Thomson static inline const void *of_device_get_match_data(const struct device *dev)
914613e9721SAdam Thomson {
915613e9721SAdam Thomson 	return NULL;
916613e9721SAdam Thomson }
917613e9721SAdam Thomson 
918613e9721SAdam Thomson #define of_match_ptr(_ptr)	NULL
919613e9721SAdam Thomson #define of_match_node(_matches, _node)	NULL
9209c63fea9SRob Herring (Arm) #endif /* CONFIG_OF */
9216f751188SFrank Rowand 
9226f751188SFrank Rowand /* Default string compare functions, Allow arch asm/prom.h to override */
9236f751188SFrank Rowand #if !defined(of_compat_cmp)
9246f751188SFrank Rowand #define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
9256f751188SFrank Rowand #define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
926ad8ee969SBartosz Golaszewski #define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
927ad8ee969SBartosz Golaszewski #endif
928ad8ee969SBartosz Golaszewski 
9290c3f061cSRob Herring #define for_each_property_of_node(dn, pp) \
9300c3f061cSRob Herring 	for (pp = dn->properties; pp != NULL; pp = pp->next)
9310c3f061cSRob Herring 
932c8fff7bcSKonstantin Khlebnikov #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
933c8fff7bcSKonstantin Khlebnikov extern int of_node_to_nid(struct device_node *np);
934c8fff7bcSKonstantin Khlebnikov #else
of_node_to_nid(struct device_node * device)935c8fff7bcSKonstantin Khlebnikov static inline int of_node_to_nid(struct device_node *device)
9365ca4db61SPaul Mundt {
9375ca4db61SPaul Mundt 	return NUMA_NO_NODE;
938298535c0SDavid Daney }
939298535c0SDavid Daney #endif
940298535c0SDavid Daney 
941298535c0SDavid Daney #ifdef CONFIG_OF_NUMA
942298535c0SDavid Daney extern int of_numa_init(void);
943298535c0SDavid Daney #else
of_numa_init(void)944298535c0SDavid Daney static inline int of_numa_init(void)
945298535c0SDavid Daney {
946298535c0SDavid Daney 	return -ENOSYS;
947662372e4SRob Herring }
948662372e4SRob Herring #endif
949662372e4SRob Herring 
of_find_matching_node(struct device_node * from,const struct of_device_id * matches)950662372e4SRob Herring static inline struct device_node *of_find_matching_node(
951662372e4SRob Herring 	struct device_node *from,
952662372e4SRob Herring 	const struct of_device_id *matches)
953662372e4SRob Herring {
9540413bedaSRob Herring 	return of_find_matching_node_and_match(from, matches, NULL);
9550413bedaSRob Herring }
9565d5a0ab1SRob Herring 
of_node_get_device_type(const struct device_node * np)9570413bedaSRob Herring static inline const char *of_node_get_device_type(const struct device_node *np)
9580413bedaSRob Herring {
9590413bedaSRob Herring 	return of_get_property(np, "device_type", NULL);
9600413bedaSRob Herring }
9610413bedaSRob Herring 
of_node_is_type(const struct device_node * np,const char * type)9620413bedaSRob Herring static inline bool of_node_is_type(const struct device_node *np, const char *type)
9630413bedaSRob Herring {
9640413bedaSRob Herring 	const char *match = of_node_get_device_type(np);
9650413bedaSRob Herring 
966fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 	return np && match && type && !strcmp(match, type);
96766a8f7f0SMichael Walle }
96866a8f7f0SMichael Walle 
96966a8f7f0SMichael Walle /**
97066a8f7f0SMichael Walle  * of_parse_phandle - Resolve a phandle property to a device_node pointer
97166a8f7f0SMichael Walle  * @np: Pointer to device node holding phandle property
97266a8f7f0SMichael Walle  * @phandle_name: Name of property holding a phandle value
97366a8f7f0SMichael Walle  * @index: For properties holding a table of phandles, this is the index into
97466a8f7f0SMichael Walle  *         the table
97566a8f7f0SMichael Walle  *
97666a8f7f0SMichael Walle  * Return: The device_node pointer with refcount incremented.  Use
97766a8f7f0SMichael Walle  * of_node_put() on it when done.
97866a8f7f0SMichael Walle  */
of_parse_phandle(const struct device_node * np,const char * phandle_name,int index)97966a8f7f0SMichael Walle static inline struct device_node *of_parse_phandle(const struct device_node *np,
98066a8f7f0SMichael Walle 						   const char *phandle_name,
98166a8f7f0SMichael Walle 						   int index)
98266a8f7f0SMichael Walle {
98366a8f7f0SMichael Walle 	struct of_phandle_args args;
98466a8f7f0SMichael Walle 
98566a8f7f0SMichael Walle 	if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
98666a8f7f0SMichael Walle 					 index, &args))
98766a8f7f0SMichael Walle 		return NULL;
98866a8f7f0SMichael Walle 
98966a8f7f0SMichael Walle 	return args.np;
99066a8f7f0SMichael Walle }
99166a8f7f0SMichael Walle 
99266a8f7f0SMichael Walle /**
99366a8f7f0SMichael Walle  * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
99466a8f7f0SMichael Walle  * @np:		pointer to a device tree node containing a list
99566a8f7f0SMichael Walle  * @list_name:	property name that contains a list
99666a8f7f0SMichael Walle  * @cells_name:	property name that specifies phandles' arguments count
99766a8f7f0SMichael Walle  * @index:	index of a phandle to parse out
99866a8f7f0SMichael Walle  * @out_args:	optional pointer to output arguments structure (will be filled)
99966a8f7f0SMichael Walle  *
100066a8f7f0SMichael Walle  * This function is useful to parse lists of phandles and their arguments.
100166a8f7f0SMichael Walle  * Returns 0 on success and fills out_args, on error returns appropriate
100266a8f7f0SMichael Walle  * errno value.
100366a8f7f0SMichael Walle  *
100466a8f7f0SMichael Walle  * Caller is responsible to call of_node_put() on the returned out_args->np
100566a8f7f0SMichael Walle  * pointer.
100666a8f7f0SMichael Walle  *
100766a8f7f0SMichael Walle  * Example::
100866a8f7f0SMichael Walle  *
100966a8f7f0SMichael Walle  *  phandle1: node1 {
101066a8f7f0SMichael Walle  *	#list-cells = <2>;
101166a8f7f0SMichael Walle  *  };
101266a8f7f0SMichael Walle  *
101366a8f7f0SMichael Walle  *  phandle2: node2 {
101466a8f7f0SMichael Walle  *	#list-cells = <1>;
101566a8f7f0SMichael Walle  *  };
101666a8f7f0SMichael Walle  *
101766a8f7f0SMichael Walle  *  node3 {
101866a8f7f0SMichael Walle  *	list = <&phandle1 1 2 &phandle2 3>;
101966a8f7f0SMichael Walle  *  };
102066a8f7f0SMichael Walle  *
102166a8f7f0SMichael Walle  * To get a device_node of the ``node2`` node you may call this:
102266a8f7f0SMichael Walle  * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
102366a8f7f0SMichael Walle  */
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)102466a8f7f0SMichael Walle static inline int of_parse_phandle_with_args(const struct device_node *np,
102566a8f7f0SMichael Walle 					     const char *list_name,
102666a8f7f0SMichael Walle 					     const char *cells_name,
102766a8f7f0SMichael Walle 					     int index,
102866a8f7f0SMichael Walle 					     struct of_phandle_args *out_args)
102966a8f7f0SMichael Walle {
103066a8f7f0SMichael Walle 	int cell_count = -1;
103166a8f7f0SMichael Walle 
103266a8f7f0SMichael Walle 	/* If cells_name is NULL we assume a cell count of 0 */
103366a8f7f0SMichael Walle 	if (!cells_name)
103466a8f7f0SMichael Walle 		cell_count = 0;
103566a8f7f0SMichael Walle 
103666a8f7f0SMichael Walle 	return __of_parse_phandle_with_args(np, list_name, cells_name,
103766a8f7f0SMichael Walle 					    cell_count, index, out_args);
103866a8f7f0SMichael Walle }
103966a8f7f0SMichael Walle 
104066a8f7f0SMichael Walle /**
104166a8f7f0SMichael Walle  * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
104266a8f7f0SMichael Walle  * @np:		pointer to a device tree node containing a list
104366a8f7f0SMichael Walle  * @list_name:	property name that contains a list
104466a8f7f0SMichael Walle  * @cell_count: number of argument cells following the phandle
104566a8f7f0SMichael Walle  * @index:	index of a phandle to parse out
104666a8f7f0SMichael Walle  * @out_args:	optional pointer to output arguments structure (will be filled)
104766a8f7f0SMichael Walle  *
104866a8f7f0SMichael Walle  * This function is useful to parse lists of phandles and their arguments.
104966a8f7f0SMichael Walle  * Returns 0 on success and fills out_args, on error returns appropriate
105066a8f7f0SMichael Walle  * errno value.
105166a8f7f0SMichael Walle  *
105266a8f7f0SMichael Walle  * Caller is responsible to call of_node_put() on the returned out_args->np
105366a8f7f0SMichael Walle  * pointer.
105466a8f7f0SMichael Walle  *
105566a8f7f0SMichael Walle  * Example::
105666a8f7f0SMichael Walle  *
105766a8f7f0SMichael Walle  *  phandle1: node1 {
105866a8f7f0SMichael Walle  *  };
105966a8f7f0SMichael Walle  *
106066a8f7f0SMichael Walle  *  phandle2: node2 {
106166a8f7f0SMichael Walle  *  };
106266a8f7f0SMichael Walle  *
106366a8f7f0SMichael Walle  *  node3 {
106466a8f7f0SMichael Walle  *	list = <&phandle1 0 2 &phandle2 2 3>;
106566a8f7f0SMichael Walle  *  };
106666a8f7f0SMichael Walle  *
106766a8f7f0SMichael Walle  * To get a device_node of the ``node2`` node you may call this:
106866a8f7f0SMichael Walle  * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
106966a8f7f0SMichael Walle  */
of_parse_phandle_with_fixed_args(const struct device_node * np,const char * list_name,int cell_count,int index,struct of_phandle_args * out_args)107066a8f7f0SMichael Walle static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
107166a8f7f0SMichael Walle 						   const char *list_name,
107266a8f7f0SMichael Walle 						   int cell_count,
107366a8f7f0SMichael Walle 						   int index,
107466a8f7f0SMichael Walle 						   struct of_phandle_args *out_args)
107566a8f7f0SMichael Walle {
107666a8f7f0SMichael Walle 	return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
107766a8f7f0SMichael Walle 					    index, out_args);
1078c5d264d4SMichael Walle }
1079c5d264d4SMichael Walle 
1080c5d264d4SMichael Walle /**
1081c5d264d4SMichael Walle  * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list
1082c5d264d4SMichael Walle  * @np:		pointer to a device tree node containing a list
1083c5d264d4SMichael Walle  * @list_name:	property name that contains a list
1084c5d264d4SMichael Walle  * @cells_name:	property name that specifies phandles' arguments count
1085c5d264d4SMichael Walle  * @index:	index of a phandle to parse out
1086c5d264d4SMichael Walle  * @out_args:	optional pointer to output arguments structure (will be filled)
1087c5d264d4SMichael Walle  *
1088c5d264d4SMichael Walle  * Same as of_parse_phandle_with_args() except that if the cells_name property
1089c5d264d4SMichael Walle  * is not found, cell_count of 0 is assumed.
1090c5d264d4SMichael Walle  *
1091c5d264d4SMichael Walle  * This is used to useful, if you have a phandle which didn't have arguments
1092c5d264d4SMichael Walle  * before and thus doesn't have a '#*-cells' property but is now migrated to
1093c5d264d4SMichael Walle  * having arguments while retaining backwards compatibility.
1094c5d264d4SMichael Walle  */
of_parse_phandle_with_optional_args(const struct device_node * np,const char * list_name,const char * cells_name,int index,struct of_phandle_args * out_args)1095c5d264d4SMichael Walle static inline int of_parse_phandle_with_optional_args(const struct device_node *np,
1096c5d264d4SMichael Walle 						      const char *list_name,
1097c5d264d4SMichael Walle 						      const char *cells_name,
1098c5d264d4SMichael Walle 						      int index,
1099c5d264d4SMichael Walle 						      struct of_phandle_args *out_args)
1100c5d264d4SMichael Walle {
1101c5d264d4SMichael Walle 	return __of_parse_phandle_with_args(np, list_name, cells_name,
1102c5d264d4SMichael Walle 					    0, index, out_args);
110326ea8511SKrzysztof Kozlowski }
110426ea8511SKrzysztof Kozlowski 
110526ea8511SKrzysztof Kozlowski /**
110626ea8511SKrzysztof Kozlowski  * of_phandle_args_equal() - Compare two of_phandle_args
110726ea8511SKrzysztof Kozlowski  * @a1:		First of_phandle_args to compare
110826ea8511SKrzysztof Kozlowski  * @a2:		Second of_phandle_args to compare
110926ea8511SKrzysztof Kozlowski  *
111026ea8511SKrzysztof Kozlowski  * Return: True if a1 and a2 are the same (same node pointer, same phandle
111126ea8511SKrzysztof Kozlowski  * args), false otherwise.
111226ea8511SKrzysztof Kozlowski  */
of_phandle_args_equal(const struct of_phandle_args * a1,const struct of_phandle_args * a2)111326ea8511SKrzysztof Kozlowski static inline bool of_phandle_args_equal(const struct of_phandle_args *a1,
111426ea8511SKrzysztof Kozlowski 					 const struct of_phandle_args *a2)
111526ea8511SKrzysztof Kozlowski {
111626ea8511SKrzysztof Kozlowski 	return a1->np == a2->np &&
111726ea8511SKrzysztof Kozlowski 	       a1->args_count == a2->args_count &&
111826ea8511SKrzysztof Kozlowski 	       !memcmp(a1->args, a2->args, sizeof(a1->args[0]) * a1->args_count);
1119ad54a0cfSHeiko Stuebner }
1120ad54a0cfSHeiko Stuebner 
1121ad54a0cfSHeiko Stuebner /**
1122ad54a0cfSHeiko Stuebner  * of_property_count_u8_elems - Count the number of u8 elements in a property
1123ad54a0cfSHeiko Stuebner  *
1124ad54a0cfSHeiko Stuebner  * @np:		device node from which the property value is to be read.
11258c8239c2SRob Herring  * @propname:	name of the property to be searched.
11268c8239c2SRob Herring  *
11278c8239c2SRob Herring  * Search for a property in a device node and count the number of u8 elements
1128ad54a0cfSHeiko Stuebner  * in it.
1129ad54a0cfSHeiko Stuebner  *
1130ad54a0cfSHeiko Stuebner  * Return: The number of elements on sucess, -EINVAL if the property does
1131ad54a0cfSHeiko Stuebner  * not exist or its length does not match a multiple of u8 and -ENODATA if the
1132ad54a0cfSHeiko Stuebner  * property does not have a value.
1133ad54a0cfSHeiko Stuebner  */
of_property_count_u8_elems(const struct device_node * np,const char * propname)1134ad54a0cfSHeiko Stuebner static inline int of_property_count_u8_elems(const struct device_node *np,
1135ad54a0cfSHeiko Stuebner 				const char *propname)
1136ad54a0cfSHeiko Stuebner {
1137ad54a0cfSHeiko Stuebner 	return of_property_count_elems_of_size(np, propname, sizeof(u8));
1138ad54a0cfSHeiko Stuebner }
1139ad54a0cfSHeiko Stuebner 
1140ad54a0cfSHeiko Stuebner /**
1141ad54a0cfSHeiko Stuebner  * of_property_count_u16_elems - Count the number of u16 elements in a property
1142ad54a0cfSHeiko Stuebner  *
1143ad54a0cfSHeiko Stuebner  * @np:		device node from which the property value is to be read.
11448c8239c2SRob Herring  * @propname:	name of the property to be searched.
11458c8239c2SRob Herring  *
11468c8239c2SRob Herring  * Search for a property in a device node and count the number of u16 elements
1147ad54a0cfSHeiko Stuebner  * in it.
1148ad54a0cfSHeiko Stuebner  *
1149ad54a0cfSHeiko Stuebner  * Return: The number of elements on sucess, -EINVAL if the property does
1150ad54a0cfSHeiko Stuebner  * not exist or its length does not match a multiple of u16 and -ENODATA if the
1151ad54a0cfSHeiko Stuebner  * property does not have a value.
1152ad54a0cfSHeiko Stuebner  */
of_property_count_u16_elems(const struct device_node * np,const char * propname)1153ad54a0cfSHeiko Stuebner static inline int of_property_count_u16_elems(const struct device_node *np,
1154ad54a0cfSHeiko Stuebner 				const char *propname)
1155ad54a0cfSHeiko Stuebner {
1156ad54a0cfSHeiko Stuebner 	return of_property_count_elems_of_size(np, propname, sizeof(u16));
1157ad54a0cfSHeiko Stuebner }
1158ad54a0cfSHeiko Stuebner 
1159ad54a0cfSHeiko Stuebner /**
1160ad54a0cfSHeiko Stuebner  * of_property_count_u32_elems - Count the number of u32 elements in a property
1161ad54a0cfSHeiko Stuebner  *
1162ad54a0cfSHeiko Stuebner  * @np:		device node from which the property value is to be read.
11638c8239c2SRob Herring  * @propname:	name of the property to be searched.
11648c8239c2SRob Herring  *
11658c8239c2SRob Herring  * Search for a property in a device node and count the number of u32 elements
1166ad54a0cfSHeiko Stuebner  * in it.
1167ad54a0cfSHeiko Stuebner  *
1168ad54a0cfSHeiko Stuebner  * Return: The number of elements on sucess, -EINVAL if the property does
1169ad54a0cfSHeiko Stuebner  * not exist or its length does not match a multiple of u32 and -ENODATA if the
1170ad54a0cfSHeiko Stuebner  * property does not have a value.
1171ad54a0cfSHeiko Stuebner  */
of_property_count_u32_elems(const struct device_node * np,const char * propname)1172ad54a0cfSHeiko Stuebner static inline int of_property_count_u32_elems(const struct device_node *np,
1173ad54a0cfSHeiko Stuebner 				const char *propname)
1174ad54a0cfSHeiko Stuebner {
1175ad54a0cfSHeiko Stuebner 	return of_property_count_elems_of_size(np, propname, sizeof(u32));
1176ad54a0cfSHeiko Stuebner }
1177ad54a0cfSHeiko Stuebner 
1178ad54a0cfSHeiko Stuebner /**
1179ad54a0cfSHeiko Stuebner  * of_property_count_u64_elems - Count the number of u64 elements in a property
1180ad54a0cfSHeiko Stuebner  *
1181ad54a0cfSHeiko Stuebner  * @np:		device node from which the property value is to be read.
11828c8239c2SRob Herring  * @propname:	name of the property to be searched.
11838c8239c2SRob Herring  *
11848c8239c2SRob Herring  * Search for a property in a device node and count the number of u64 elements
1185ad54a0cfSHeiko Stuebner  * in it.
1186ad54a0cfSHeiko Stuebner  *
1187ad54a0cfSHeiko Stuebner  * Return: The number of elements on sucess, -EINVAL if the property does
1188ad54a0cfSHeiko Stuebner  * not exist or its length does not match a multiple of u64 and -ENODATA if the
1189ad54a0cfSHeiko Stuebner  * property does not have a value.
1190ad54a0cfSHeiko Stuebner  */
of_property_count_u64_elems(const struct device_node * np,const char * propname)1191ad54a0cfSHeiko Stuebner static inline int of_property_count_u64_elems(const struct device_node *np,
1192ad54a0cfSHeiko Stuebner 				const char *propname)
1193ad54a0cfSHeiko Stuebner {
1194fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 	return of_property_count_elems_of_size(np, propname, sizeof(u64));
1195a87fa1d8SGrant Likely }
1196a87fa1d8SGrant Likely 
1197a87fa1d8SGrant Likely /**
1198a87fa1d8SGrant Likely  * of_property_read_string_array() - Read an array of strings from a multiple
1199a87fa1d8SGrant Likely  * strings property.
1200a87fa1d8SGrant Likely  * @np:		device node from which the property value is to be read.
1201a87fa1d8SGrant Likely  * @propname:	name of the property to be searched.
1202a87fa1d8SGrant Likely  * @out_strs:	output array of string pointers.
1203a87fa1d8SGrant Likely  * @sz:		number of array elements to read.
1204a87fa1d8SGrant Likely  *
12058c8239c2SRob Herring  * Search for a property in a device tree node and retrieve a list of
1206a87fa1d8SGrant Likely  * terminated string values (pointer to data, not a copy) in that property.
1207fe99c707SDavid Rivshin  *
1208a87fa1d8SGrant Likely  * Return: If @out_strs is NULL, the number of strings in the property is returned.
1209a87fa1d8SGrant Likely  */
of_property_read_string_array(const struct device_node * np,const char * propname,const char ** out_strs,size_t sz)1210a87fa1d8SGrant Likely static inline int of_property_read_string_array(const struct device_node *np,
1211a87fa1d8SGrant Likely 						const char *propname, const char **out_strs,
1212a87fa1d8SGrant Likely 						size_t sz)
1213a87fa1d8SGrant Likely {
1214a87fa1d8SGrant Likely 	return of_property_read_string_helper(np, propname, out_strs, sz, 0);
1215a87fa1d8SGrant Likely }
1216a87fa1d8SGrant Likely 
1217a87fa1d8SGrant Likely /**
1218a87fa1d8SGrant Likely  * of_property_count_strings() - Find and return the number of strings from a
1219a87fa1d8SGrant Likely  * multiple strings property.
1220a87fa1d8SGrant Likely  * @np:		device node from which the property value is to be read.
12218c8239c2SRob Herring  * @propname:	name of the property to be searched.
12228c8239c2SRob Herring  *
12238c8239c2SRob Herring  * Search for a property in a device tree node and retrieve the number of null
12248c8239c2SRob Herring  * terminated string contain in it.
12258c8239c2SRob Herring  *
1226a87fa1d8SGrant Likely  * Return: The number of strings on success, -EINVAL if the property does not
1227fe99c707SDavid Rivshin  * exist, -ENODATA if property does not have a value, and -EILSEQ if the string
1228a87fa1d8SGrant Likely  * is not null-terminated within the length of the property data.
1229a87fa1d8SGrant Likely  */
of_property_count_strings(const struct device_node * np,const char * propname)1230a87fa1d8SGrant Likely static inline int of_property_count_strings(const struct device_node *np,
1231a87fa1d8SGrant Likely 					    const char *propname)
1232a87fa1d8SGrant Likely {
1233a87fa1d8SGrant Likely 	return of_property_read_string_helper(np, propname, NULL, 0, 0);
1234a87fa1d8SGrant Likely }
1235a87fa1d8SGrant Likely 
1236a87fa1d8SGrant Likely /**
1237a87fa1d8SGrant Likely  * of_property_read_string_index() - Find and read a string from a multiple
1238a87fa1d8SGrant Likely  * strings property.
1239c968b89aSRandy Dunlap  * @np:		device node from which the property value is to be read.
1240a87fa1d8SGrant Likely  * @propname:	name of the property to be searched.
1241a87fa1d8SGrant Likely  * @index:	index of the string in the list of strings
1242a87fa1d8SGrant Likely  * @output:	pointer to null terminated return string, modified only if
1243a87fa1d8SGrant Likely  *		return value is 0.
1244a87fa1d8SGrant Likely  *
12458c8239c2SRob Herring  * Search for a property in a device tree node and retrieve a null
12468c8239c2SRob Herring  * terminated string value (pointer to data, not a copy) in the list of strings
1247a87fa1d8SGrant Likely  * contained in that property.
1248a87fa1d8SGrant Likely  *
1249a87fa1d8SGrant Likely  * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if
1250a87fa1d8SGrant Likely  * property does not have a value, and -EILSEQ if the string is not
1251a87fa1d8SGrant Likely  * null-terminated within the length of the property data.
1252fe99c707SDavid Rivshin  *
1253a87fa1d8SGrant Likely  * The out_string pointer is modified only if a valid string can be decoded.
1254a87fa1d8SGrant Likely  */
of_property_read_string_index(const struct device_node * np,const char * propname,int index,const char ** output)1255a87fa1d8SGrant Likely static inline int of_property_read_string_index(const struct device_node *np,
1256a87fa1d8SGrant Likely 						const char *propname,
1257a87fa1d8SGrant Likely 						int index, const char **output)
1258a87fa1d8SGrant Likely {
1259a87fa1d8SGrant Likely 	int rc = of_property_read_string_helper(np, propname, output, 1, index);
1260a87fa1d8SGrant Likely 	return rc < 0 ? rc : 0;
12619cbad37cSRob Herring }
12629cbad37cSRob Herring 
12639cbad37cSRob Herring /**
12649cbad37cSRob Herring  * of_property_present - Test if a property is present in a node
12659cbad37cSRob Herring  * @np:		device node to search for the property.
12669cbad37cSRob Herring  * @propname:	name of the property to be searched.
12679cbad37cSRob Herring  *
12689cbad37cSRob Herring  * Test for a property present in a device node.
12699cbad37cSRob Herring  *
12709cbad37cSRob Herring  * Return: true if the property exists false otherwise.
1271bb391410SRob Herring (Arm)  */
of_property_present(const struct device_node * np,const char * propname)1272bb391410SRob Herring (Arm) static inline bool of_property_present(const struct device_node *np, const char *propname)
1273bb391410SRob Herring (Arm) {
12749cbad37cSRob Herring 	struct property *prop = of_find_property(np, propname, NULL);
12759cbad37cSRob Herring 
12769cbad37cSRob Herring 	return prop ? true : false;
12772ca42c3aSMichael Walle }
12782ca42c3aSMichael Walle 
12792ca42c3aSMichael Walle /**
12802ca42c3aSMichael Walle  * of_property_read_u8_array - Find and read an array of u8 from a property.
12812ca42c3aSMichael Walle  *
12822ca42c3aSMichael Walle  * @np:		device node from which the property value is to be read.
12832ca42c3aSMichael Walle  * @propname:	name of the property to be searched.
12842ca42c3aSMichael Walle  * @out_values:	pointer to return value, modified only if return value is 0.
12852ca42c3aSMichael Walle  * @sz:		number of array elements to read
12862ca42c3aSMichael Walle  *
12872ca42c3aSMichael Walle  * Search for a property in a device node and read 8-bit value(s) from
12882ca42c3aSMichael Walle  * it.
12892ca42c3aSMichael Walle  *
12902ca42c3aSMichael Walle  * dts entry of array should be like:
12912ca42c3aSMichael Walle  *  ``property = /bits/ 8 <0x50 0x60 0x70>;``
12922ca42c3aSMichael Walle  *
12932ca42c3aSMichael Walle  * Return: 0 on success, -EINVAL if the property does not exist,
12942ca42c3aSMichael Walle  * -ENODATA if property does not have a value, and -EOVERFLOW if the
12952ca42c3aSMichael Walle  * property data isn't large enough.
12962ca42c3aSMichael Walle  *
12972ca42c3aSMichael Walle  * The out_values is modified only if a valid u8 value can be decoded.
12982ca42c3aSMichael Walle  */
of_property_read_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz)12992ca42c3aSMichael Walle static inline int of_property_read_u8_array(const struct device_node *np,
13002ca42c3aSMichael Walle 					    const char *propname,
13012ca42c3aSMichael Walle 					    u8 *out_values, size_t sz)
13022ca42c3aSMichael Walle {
13032ca42c3aSMichael Walle 	int ret = of_property_read_variable_u8_array(np, propname, out_values,
13042ca42c3aSMichael Walle 						     sz, 0);
13052ca42c3aSMichael Walle 	if (ret >= 0)
13062ca42c3aSMichael Walle 		return 0;
13072ca42c3aSMichael Walle 	else
13082ca42c3aSMichael Walle 		return ret;
13092ca42c3aSMichael Walle }
13102ca42c3aSMichael Walle 
13112ca42c3aSMichael Walle /**
13122ca42c3aSMichael Walle  * of_property_read_u16_array - Find and read an array of u16 from a property.
13132ca42c3aSMichael Walle  *
13142ca42c3aSMichael Walle  * @np:		device node from which the property value is to be read.
13152ca42c3aSMichael Walle  * @propname:	name of the property to be searched.
13162ca42c3aSMichael Walle  * @out_values:	pointer to return value, modified only if return value is 0.
13172ca42c3aSMichael Walle  * @sz:		number of array elements to read
13182ca42c3aSMichael Walle  *
13192ca42c3aSMichael Walle  * Search for a property in a device node and read 16-bit value(s) from
13202ca42c3aSMichael Walle  * it.
13212ca42c3aSMichael Walle  *
13222ca42c3aSMichael Walle  * dts entry of array should be like:
13232ca42c3aSMichael Walle  *  ``property = /bits/ 16 <0x5000 0x6000 0x7000>;``
13242ca42c3aSMichael Walle  *
13252ca42c3aSMichael Walle  * Return: 0 on success, -EINVAL if the property does not exist,
13262ca42c3aSMichael Walle  * -ENODATA if property does not have a value, and -EOVERFLOW if the
13272ca42c3aSMichael Walle  * property data isn't large enough.
13282ca42c3aSMichael Walle  *
13292ca42c3aSMichael Walle  * The out_values is modified only if a valid u16 value can be decoded.
13302ca42c3aSMichael Walle  */
of_property_read_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz)13312ca42c3aSMichael Walle static inline int of_property_read_u16_array(const struct device_node *np,
13322ca42c3aSMichael Walle 					     const char *propname,
13332ca42c3aSMichael Walle 					     u16 *out_values, size_t sz)
13342ca42c3aSMichael Walle {
13352ca42c3aSMichael Walle 	int ret = of_property_read_variable_u16_array(np, propname, out_values,
13362ca42c3aSMichael Walle 						      sz, 0);
13372ca42c3aSMichael Walle 	if (ret >= 0)
13382ca42c3aSMichael Walle 		return 0;
13392ca42c3aSMichael Walle 	else
13402ca42c3aSMichael Walle 		return ret;
13412ca42c3aSMichael Walle }
13422ca42c3aSMichael Walle 
13432ca42c3aSMichael Walle /**
13442ca42c3aSMichael Walle  * of_property_read_u32_array - Find and read an array of 32 bit integers
13452ca42c3aSMichael Walle  * from a property.
13462ca42c3aSMichael Walle  *
13472ca42c3aSMichael Walle  * @np:		device node from which the property value is to be read.
13482ca42c3aSMichael Walle  * @propname:	name of the property to be searched.
13492ca42c3aSMichael Walle  * @out_values:	pointer to return value, modified only if return value is 0.
13502ca42c3aSMichael Walle  * @sz:		number of array elements to read
13512ca42c3aSMichael Walle  *
13522ca42c3aSMichael Walle  * Search for a property in a device node and read 32-bit value(s) from
13532ca42c3aSMichael Walle  * it.
13542ca42c3aSMichael Walle  *
13552ca42c3aSMichael Walle  * Return: 0 on success, -EINVAL if the property does not exist,
13562ca42c3aSMichael Walle  * -ENODATA if property does not have a value, and -EOVERFLOW if the
13572ca42c3aSMichael Walle  * property data isn't large enough.
13582ca42c3aSMichael Walle  *
13592ca42c3aSMichael Walle  * The out_values is modified only if a valid u32 value can be decoded.
13602ca42c3aSMichael Walle  */
of_property_read_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz)13612ca42c3aSMichael Walle static inline int of_property_read_u32_array(const struct device_node *np,
13622ca42c3aSMichael Walle 					     const char *propname,
13632ca42c3aSMichael Walle 					     u32 *out_values, size_t sz)
13642ca42c3aSMichael Walle {
13652ca42c3aSMichael Walle 	int ret = of_property_read_variable_u32_array(np, propname, out_values,
13662ca42c3aSMichael Walle 						      sz, 0);
13672ca42c3aSMichael Walle 	if (ret >= 0)
13682ca42c3aSMichael Walle 		return 0;
13692ca42c3aSMichael Walle 	else
13702ca42c3aSMichael Walle 		return ret;
13712ca42c3aSMichael Walle }
13722ca42c3aSMichael Walle 
13732ca42c3aSMichael Walle /**
13742ca42c3aSMichael Walle  * of_property_read_u64_array - Find and read an array of 64 bit integers
13752ca42c3aSMichael Walle  * from a property.
13762ca42c3aSMichael Walle  *
13772ca42c3aSMichael Walle  * @np:		device node from which the property value is to be read.
13782ca42c3aSMichael Walle  * @propname:	name of the property to be searched.
13792ca42c3aSMichael Walle  * @out_values:	pointer to return value, modified only if return value is 0.
13802ca42c3aSMichael Walle  * @sz:		number of array elements to read
13812ca42c3aSMichael Walle  *
13822ca42c3aSMichael Walle  * Search for a property in a device node and read 64-bit value(s) from
13832ca42c3aSMichael Walle  * it.
13842ca42c3aSMichael Walle  *
13852ca42c3aSMichael Walle  * Return: 0 on success, -EINVAL if the property does not exist,
13862ca42c3aSMichael Walle  * -ENODATA if property does not have a value, and -EOVERFLOW if the
13872ca42c3aSMichael Walle  * property data isn't large enough.
13882ca42c3aSMichael Walle  *
13892ca42c3aSMichael Walle  * The out_values is modified only if a valid u64 value can be decoded.
13902ca42c3aSMichael Walle  */
of_property_read_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz)13912ca42c3aSMichael Walle static inline int of_property_read_u64_array(const struct device_node *np,
13922ca42c3aSMichael Walle 					     const char *propname,
13932ca42c3aSMichael Walle 					     u64 *out_values, size_t sz)
13942ca42c3aSMichael Walle {
13952ca42c3aSMichael Walle 	int ret = of_property_read_variable_u64_array(np, propname, out_values,
13962ca42c3aSMichael Walle 						      sz, 0);
13972ca42c3aSMichael Walle 	if (ret >= 0)
13982ca42c3aSMichael Walle 		return 0;
13992ca42c3aSMichael Walle 	else
1400be193249SViresh Kumar 		return ret;
1401be193249SViresh Kumar }
1402be193249SViresh Kumar 
of_property_read_u8(const struct device_node * np,const char * propname,u8 * out_value)1403be193249SViresh Kumar static inline int of_property_read_u8(const struct device_node *np,
1404be193249SViresh Kumar 				       const char *propname,
1405be193249SViresh Kumar 				       u8 *out_value)
1406be193249SViresh Kumar {
1407be193249SViresh Kumar 	return of_property_read_u8_array(np, propname, out_value, 1);
1408be193249SViresh Kumar }
1409be193249SViresh Kumar 
of_property_read_u16(const struct device_node * np,const char * propname,u16 * out_value)1410be193249SViresh Kumar static inline int of_property_read_u16(const struct device_node *np,
1411be193249SViresh Kumar 				       const char *propname,
1412be193249SViresh Kumar 				       u16 *out_value)
1413be193249SViresh Kumar {
1414b98c0239SShawn Guo 	return of_property_read_u16_array(np, propname, out_value, 1);
1415aac285c6SJamie Iles }
1416b98c0239SShawn Guo 
of_property_read_u32(const struct device_node * np,const char * propname,u32 * out_value)1417b98c0239SShawn Guo static inline int of_property_read_u32(const struct device_node *np,
1418b98c0239SShawn Guo 				       const char *propname,
1419b98c0239SShawn Guo 				       u32 *out_value)
1420b98c0239SShawn Guo {
1421e7a00e42SSebastian Reichel 	return of_property_read_u32_array(np, propname, out_value, 1);
1422e7a00e42SSebastian Reichel }
1423e7a00e42SSebastian Reichel 
of_property_read_s32(const struct device_node * np,const char * propname,s32 * out_value)1424e7a00e42SSebastian Reichel static inline int of_property_read_s32(const struct device_node *np,
1425e7a00e42SSebastian Reichel 				       const char *propname,
1426e7a00e42SSebastian Reichel 				       s32 *out_value)
1427e7a00e42SSebastian Reichel {
1428f623ce95SJoerg Roedel 	return of_property_read_u32(np, propname, (u32*) out_value);
1429f623ce95SJoerg Roedel }
1430f623ce95SJoerg Roedel 
1431f623ce95SJoerg Roedel #define of_for_each_phandle(it, err, np, ln, cn, cc)			\
1432f623ce95SJoerg Roedel 	for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)),	\
1433f623ce95SJoerg Roedel 	     err = of_phandle_iterator_next(it);			\
14349722c3b6SLuca Ceresoli 	     err == 0;							\
14359c63fea9SRob Herring (Arm) 	     err = of_phandle_iterator_next(it))
14369722c3b6SLuca Ceresoli 
14379722c3b6SLuca Ceresoli #define of_property_for_each_u32(np, propname, u)			\
14389722c3b6SLuca Ceresoli 	for (struct {const struct property *prop; const __be32 *item; } _it =	\
14399722c3b6SLuca Ceresoli 		{of_find_property(np, propname, NULL),			\
14402adfffa2SSebastian Andrzej Siewior 		 of_prop_next_u32(_it.prop, NULL, &u)};			\
14412adfffa2SSebastian Andrzej Siewior 	     _it.item;							\
14422adfffa2SSebastian Andrzej Siewior 	     _it.item = of_prop_next_u32(_it.prop, _it.item, &u))
14432adfffa2SSebastian Andrzej Siewior 
14442adfffa2SSebastian Andrzej Siewior #define of_property_for_each_string(np, propname, prop, s)	\
14452adfffa2SSebastian Andrzej Siewior 	for (prop = of_find_property(np, propname, NULL),	\
14462adfffa2SSebastian Andrzej Siewior 		s = of_prop_next_string(prop, NULL);		\
1447662372e4SRob Herring 		s;						\
1448662372e4SRob Herring 		s = of_prop_next_string(prop, s))
1449662372e4SRob Herring 
1450662372e4SRob Herring #define for_each_node_by_name(dn, name) \
1451662372e4SRob Herring 	for (dn = of_find_node_by_name(NULL, name); dn; \
1452662372e4SRob Herring 	     dn = of_find_node_by_name(dn, name))
1453662372e4SRob Herring #define for_each_node_by_type(dn, type) \
1454662372e4SRob Herring 	for (dn = of_find_node_by_type(NULL, type); dn; \
1455662372e4SRob Herring 	     dn = of_find_node_by_type(dn, type))
1456662372e4SRob Herring #define for_each_compatible_node(dn, type, compatible) \
1457662372e4SRob Herring 	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
1458662372e4SRob Herring 	     dn = of_find_compatible_node(dn, type, compatible))
1459662372e4SRob Herring #define for_each_matching_node(dn, matches) \
1460662372e4SRob Herring 	for (dn = of_find_matching_node(NULL, matches); dn; \
1461662372e4SRob Herring 	     dn = of_find_matching_node(dn, matches))
1462662372e4SRob Herring #define for_each_matching_node_and_match(dn, matches, match) \
1463662372e4SRob Herring 	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
1464662372e4SRob Herring 	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
1465662372e4SRob Herring 
146634af4554SJonathan Cameron #define for_each_child_of_node(parent, child) \
146734af4554SJonathan Cameron 	for (child = of_get_next_child(parent, NULL); child != NULL; \
146834af4554SJonathan Cameron 	     child = of_get_next_child(parent, child))
146934af4554SJonathan Cameron 
147034af4554SJonathan Cameron #define for_each_child_of_node_scoped(parent, child) \
147134af4554SJonathan Cameron 	for (struct device_node *child __free(device_node) =		\
147234af4554SJonathan Cameron 	     of_get_next_child(parent, NULL);				\
14731fcc67e3SChen-Yu Tsai 	     child != NULL;						\
14741fcc67e3SChen-Yu Tsai 	     child = of_get_next_child(parent, child))
14751fcc67e3SChen-Yu Tsai 
14761fcc67e3SChen-Yu Tsai #define for_each_child_of_node_with_prefix(parent, child, prefix)	\
14771fcc67e3SChen-Yu Tsai 	for (struct device_node *child __free(device_node) =		\
14781fcc67e3SChen-Yu Tsai 	     of_get_next_child_with_prefix(parent, NULL, prefix);	\
1479662372e4SRob Herring 	     child != NULL;						\
1480662372e4SRob Herring 	     child = of_get_next_child_with_prefix(parent, child, prefix))
1481662372e4SRob Herring 
148228c5d4e4SKuninori Morimoto #define for_each_available_child_of_node(parent, child) \
148328c5d4e4SKuninori Morimoto 	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
148428c5d4e4SKuninori Morimoto 	     child = of_get_next_available_child(parent, child))
1485662372e4SRob Herring #define for_each_reserved_child_of_node(parent, child)			\
148634af4554SJonathan Cameron 	for (child = of_get_next_reserved_child(parent, NULL); child != NULL; \
148734af4554SJonathan Cameron 	     child = of_get_next_reserved_child(parent, child))
148834af4554SJonathan Cameron 
148934af4554SJonathan Cameron #define for_each_available_child_of_node_scoped(parent, child) \
149034af4554SJonathan Cameron 	for (struct device_node *child __free(device_node) =		\
149134af4554SJonathan Cameron 	     of_get_next_available_child(parent, NULL);			\
1492f1f207e4SRob Herring 	     child != NULL;						\
1493f1f207e4SRob Herring 	     child = of_get_next_available_child(parent, child))
1494f1f207e4SRob Herring 
1495f1f207e4SRob Herring #define for_each_of_cpu_node(cpu) \
1496662372e4SRob Herring 	for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
1497662372e4SRob Herring 	     cpu = of_get_next_cpu_node(cpu))
1498662372e4SRob Herring 
1499662372e4SRob Herring #define for_each_node_with_property(dn, prop_name) \
1500662372e4SRob Herring 	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
1501662372e4SRob Herring 	     dn = of_find_node_with_property(dn, prop_name))
1502662372e4SRob Herring 
of_get_child_count(const struct device_node * np)1503662372e4SRob Herring static inline int of_get_child_count(const struct device_node *np)
1504662372e4SRob Herring {
1505662372e4SRob Herring 	struct device_node *child;
1506662372e4SRob Herring 	int num = 0;
1507662372e4SRob Herring 
1508662372e4SRob Herring 	for_each_child_of_node(np, child)
1509662372e4SRob Herring 		num++;
1510662372e4SRob Herring 
1511662372e4SRob Herring 	return num;
1512662372e4SRob Herring }
1513662372e4SRob Herring 
of_get_available_child_count(const struct device_node * np)1514662372e4SRob Herring static inline int of_get_available_child_count(const struct device_node *np)
1515662372e4SRob Herring {
1516662372e4SRob Herring 	struct device_node *child;
1517662372e4SRob Herring 	int num = 0;
1518662372e4SRob Herring 
1519662372e4SRob Herring 	for_each_available_child_of_node(np, child)
1520662372e4SRob Herring 		num++;
1521662372e4SRob Herring 
152267a066b3SDmitry Osipenko 	return num;
152367a066b3SDmitry Osipenko }
152467a066b3SDmitry Osipenko 
152567a066b3SDmitry Osipenko #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type)		\
152667a066b3SDmitry Osipenko 	static const struct of_device_id __of_table_##name		\
152767a066b3SDmitry Osipenko 		__attribute__((unused))					\
152871f50c6dSMasahiro Yamada 		 = { .compatible = compat,				\
152954196ccbSRob Herring 		     .data = (fn == (fn_type)NULL) ? fn : fn }
153054196ccbSRob Herring 
153133def849SJoe Perches #if defined(CONFIG_OF) && !defined(MODULE)
15325812b32eSJohan Hovold #define _OF_DECLARE(table, name, compat, fn, fn_type)			\
153354196ccbSRob Herring 	static const struct of_device_id __of_table_##name		\
153454196ccbSRob Herring 		__used __section("__" #table "_of_table")		\
153554196ccbSRob Herring 		__aligned(__alignof__(struct of_device_id))		\
153654196ccbSRob Herring 		 = { .compatible = compat,				\
153767a066b3SDmitry Osipenko 		     .data = (fn == (fn_type)NULL) ? fn : fn  }
153854196ccbSRob Herring #else
153954196ccbSRob Herring #define _OF_DECLARE(table, name, compat, fn, fn_type)			\
154054196ccbSRob Herring 	_OF_DECLARE_STUB(table, name, compat, fn, fn_type)
1541c35d9292SDaniel Lezcano #endif
154254196ccbSRob Herring 
154354196ccbSRob Herring typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
154454196ccbSRob Herring typedef int (*of_init_fn_1_ret)(struct device_node *);
154554196ccbSRob Herring typedef void (*of_init_fn_1)(struct device_node *);
1546c35d9292SDaniel Lezcano 
1547c35d9292SDaniel Lezcano #define OF_DECLARE_1(table, name, compat, fn) \
154854196ccbSRob Herring 		_OF_DECLARE(table, name, compat, fn, of_init_fn_1)
154954196ccbSRob Herring #define OF_DECLARE_1_RET(table, name, compat, fn) \
155054196ccbSRob Herring 		_OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
1551201c910bSPantelis Antoniou #define OF_DECLARE_2(table, name, compat, fn) \
1552201c910bSPantelis Antoniou 		_OF_DECLARE(table, name, compat, fn, of_init_fn_2)
1553201c910bSPantelis Antoniou 
1554201c910bSPantelis Antoniou /**
1555201c910bSPantelis Antoniou  * struct of_changeset_entry	- Holds a changeset entry
1556201c910bSPantelis Antoniou  *
1557201c910bSPantelis Antoniou  * @node:	list_head for the log list
1558201c910bSPantelis Antoniou  * @action:	notifier action
1559201c910bSPantelis Antoniou  * @np:		pointer to the device node affected
1560201c910bSPantelis Antoniou  * @prop:	pointer to the property affected
1561201c910bSPantelis Antoniou  * @old_prop:	hold a pointer to the original property
1562201c910bSPantelis Antoniou  *
1563201c910bSPantelis Antoniou  * Every modification of the device tree during a changeset
1564201c910bSPantelis Antoniou  * is held in a list of of_changeset_entry structures.
1565201c910bSPantelis Antoniou  * That way we can recover from a partial application, or we can
1566201c910bSPantelis Antoniou  * revert the changeset
1567201c910bSPantelis Antoniou  */
1568201c910bSPantelis Antoniou struct of_changeset_entry {
1569201c910bSPantelis Antoniou 	struct list_head node;
1570201c910bSPantelis Antoniou 	unsigned long action;
1571201c910bSPantelis Antoniou 	struct device_node *np;
1572201c910bSPantelis Antoniou 	struct property *prop;
1573201c910bSPantelis Antoniou 	struct property *old_prop;
1574201c910bSPantelis Antoniou };
1575201c910bSPantelis Antoniou 
1576201c910bSPantelis Antoniou /**
1577201c910bSPantelis Antoniou  * struct of_changeset - changeset tracker structure
1578201c910bSPantelis Antoniou  *
1579201c910bSPantelis Antoniou  * @entries:	list_head for the changeset entries
1580201c910bSPantelis Antoniou  *
1581201c910bSPantelis Antoniou  * changesets are a convenient way to apply bulk changes to the
1582201c910bSPantelis Antoniou  * live tree. In case of an error, changes are rolled-back.
1583201c910bSPantelis Antoniou  * changesets live on after initial application, and if not
1584201c910bSPantelis Antoniou  * destroyed after use, they can be reverted in one single call.
1585201c910bSPantelis Antoniou  */
1586201c910bSPantelis Antoniou struct of_changeset {
1587b53a2340SPantelis Antoniou 	struct list_head entries;
1588b53a2340SPantelis Antoniou };
1589b53a2340SPantelis Antoniou 
1590b53a2340SPantelis Antoniou enum of_reconfig_change {
1591b53a2340SPantelis Antoniou 	OF_RECONFIG_NO_CHANGE = 0,
1592b53a2340SPantelis Antoniou 	OF_RECONFIG_CHANGE_ADD,
15932e8fff66SRob Herring 	OF_RECONFIG_CHANGE_REMOVE,
15942e8fff66SRob Herring };
1595201c910bSPantelis Antoniou 
1596f6892d19SGrant Likely struct notifier_block;
1597f6892d19SGrant Likely 
1598f5242e5aSGrant Likely #ifdef CONFIG_OF_DYNAMIC
1599f5242e5aSGrant Likely extern int of_reconfig_notifier_register(struct notifier_block *);
1600f5242e5aSGrant Likely extern int of_reconfig_notifier_unregister(struct notifier_block *);
1601f6892d19SGrant Likely extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
1602201c910bSPantelis Antoniou extern int of_reconfig_get_state_change(unsigned long action,
1603201c910bSPantelis Antoniou 					struct of_reconfig_data *arg);
1604201c910bSPantelis Antoniou 
1605201c910bSPantelis Antoniou extern void of_changeset_init(struct of_changeset *ocs);
1606201c910bSPantelis Antoniou extern void of_changeset_destroy(struct of_changeset *ocs);
1607201c910bSPantelis Antoniou extern int of_changeset_apply(struct of_changeset *ocs);
1608201c910bSPantelis Antoniou extern int of_changeset_revert(struct of_changeset *ocs);
1609201c910bSPantelis Antoniou extern int of_changeset_action(struct of_changeset *ocs,
1610201c910bSPantelis Antoniou 		unsigned long action, struct device_node *np,
1611201c910bSPantelis Antoniou 		struct property *prop);
1612201c910bSPantelis Antoniou 
of_changeset_attach_node(struct of_changeset * ocs,struct device_node * np)1613201c910bSPantelis Antoniou static inline int of_changeset_attach_node(struct of_changeset *ocs,
1614201c910bSPantelis Antoniou 		struct device_node *np)
1615201c910bSPantelis Antoniou {
1616201c910bSPantelis Antoniou 	return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
1617201c910bSPantelis Antoniou }
1618201c910bSPantelis Antoniou 
of_changeset_detach_node(struct of_changeset * ocs,struct device_node * np)1619201c910bSPantelis Antoniou static inline int of_changeset_detach_node(struct of_changeset *ocs,
1620201c910bSPantelis Antoniou 		struct device_node *np)
1621201c910bSPantelis Antoniou {
1622201c910bSPantelis Antoniou 	return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
1623201c910bSPantelis Antoniou }
1624201c910bSPantelis Antoniou 
of_changeset_add_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1625201c910bSPantelis Antoniou static inline int of_changeset_add_property(struct of_changeset *ocs,
1626201c910bSPantelis Antoniou 		struct device_node *np, struct property *prop)
1627201c910bSPantelis Antoniou {
1628201c910bSPantelis Antoniou 	return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
1629201c910bSPantelis Antoniou }
1630201c910bSPantelis Antoniou 
of_changeset_remove_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1631201c910bSPantelis Antoniou static inline int of_changeset_remove_property(struct of_changeset *ocs,
1632201c910bSPantelis Antoniou 		struct device_node *np, struct property *prop)
1633201c910bSPantelis Antoniou {
1634201c910bSPantelis Antoniou 	return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
1635201c910bSPantelis Antoniou }
1636201c910bSPantelis Antoniou 
of_changeset_update_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1637201c910bSPantelis Antoniou static inline int of_changeset_update_property(struct of_changeset *ocs,
1638201c910bSPantelis Antoniou 		struct device_node *np, struct property *prop)
1639b544fc2bSLizhi Hou {
1640b544fc2bSLizhi Hou 	return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
1641b544fc2bSLizhi Hou }
1642b544fc2bSLizhi Hou 
1643b544fc2bSLizhi Hou struct device_node *of_changeset_create_node(struct of_changeset *ocs,
1644b544fc2bSLizhi Hou 					     struct device_node *parent,
1645b544fc2bSLizhi Hou 					     const char *full_name);
1646b544fc2bSLizhi Hou int of_changeset_add_prop_string(struct of_changeset *ocs,
1647b544fc2bSLizhi Hou 				 struct device_node *np,
1648b544fc2bSLizhi Hou 				 const char *prop_name, const char *str);
16496badc62fSHerve Codina int of_changeset_add_prop_string_array(struct of_changeset *ocs,
1650b544fc2bSLizhi Hou 				       struct device_node *np,
1651b544fc2bSLizhi Hou 				       const char *prop_name,
1652b544fc2bSLizhi Hou 				       const char * const *str_array, size_t sz);
1653b544fc2bSLizhi Hou int of_changeset_add_prop_u32_array(struct of_changeset *ocs,
1654b544fc2bSLizhi Hou 				    struct device_node *np,
1655b544fc2bSLizhi Hou 				    const char *prop_name,
1656b544fc2bSLizhi Hou 				    const u32 *array, size_t sz);
of_changeset_add_prop_u32(struct of_changeset * ocs,struct device_node * np,const char * prop_name,const u32 val)1657b544fc2bSLizhi Hou static inline int of_changeset_add_prop_u32(struct of_changeset *ocs,
1658b544fc2bSLizhi Hou 					    struct device_node *np,
1659b544fc2bSLizhi Hou 					    const char *prop_name,
1660b544fc2bSLizhi Hou 					    const u32 val)
1661b544fc2bSLizhi Hou {
166281de291dSChen-Yu Tsai 	return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1);
166381de291dSChen-Yu Tsai }
166481de291dSChen-Yu Tsai 
166581de291dSChen-Yu Tsai int of_changeset_update_prop_string(struct of_changeset *ocs,
1666f2b388d6SHerve Codina 				    struct device_node *np,
1667f2b388d6SHerve Codina 				    const char *prop_name, const char *str);
1668f2b388d6SHerve Codina 
1669f6892d19SGrant Likely int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np,
1670f6892d19SGrant Likely 			       const char *prop_name);
1671f6892d19SGrant Likely 
1672f6892d19SGrant Likely #else /* CONFIG_OF_DYNAMIC */
of_reconfig_notifier_register(struct notifier_block * nb)1673f6892d19SGrant Likely static inline int of_reconfig_notifier_register(struct notifier_block *nb)
1674f6892d19SGrant Likely {
1675f6892d19SGrant Likely 	return -EINVAL;
1676f6892d19SGrant Likely }
of_reconfig_notifier_unregister(struct notifier_block * nb)1677f6892d19SGrant Likely static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
1678f5242e5aSGrant Likely {
1679f5242e5aSGrant Likely 	return -EINVAL;
1680f6892d19SGrant Likely }
of_reconfig_notify(unsigned long action,struct of_reconfig_data * arg)1681f6892d19SGrant Likely static inline int of_reconfig_notify(unsigned long action,
1682f6892d19SGrant Likely 				     struct of_reconfig_data *arg)
1683f5242e5aSGrant Likely {
1684f5242e5aSGrant Likely 	return -EINVAL;
1685f6892d19SGrant Likely }
of_reconfig_get_state_change(unsigned long action,struct of_reconfig_data * arg)1686f6892d19SGrant Likely static inline int of_reconfig_get_state_change(unsigned long action,
1687f6892d19SGrant Likely 						struct of_reconfig_data *arg)
1688f6892d19SGrant Likely {
1689201c910bSPantelis Antoniou 	return -EINVAL;
1690a4b4e046SRomain Perier }
16918f73110fSRomain Perier #endif /* CONFIG_OF_DYNAMIC */
1692a4b4e046SRomain Perier 
1693a4b4e046SRomain Perier /**
16948c8239c2SRob Herring  * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
1695a4b4e046SRomain Perier  * @np: Pointer to the given device_node
16968f73110fSRomain Perier  *
1697a4b4e046SRomain Perier  * Return: true if present false otherwise
16988f73110fSRomain Perier  */
of_device_is_system_power_controller(const struct device_node * np)1699a4b4e046SRomain Perier static inline bool of_device_is_system_power_controller(const struct device_node *np)
1700a4b4e046SRomain Perier {
17017b937cc2SFrank Rowand 	return of_property_read_bool(np, "system-power-controller");
17027b937cc2SFrank Rowand }
17037b937cc2SFrank Rowand 
17047b937cc2SFrank Rowand /**
17057b937cc2SFrank Rowand  * of_have_populated_dt() - Has DT been populated by bootloader
17067b937cc2SFrank Rowand  *
17077b937cc2SFrank Rowand  * Return: True if a DTB has been populated by the bootloader and it isn't the
17087b937cc2SFrank Rowand  * empty builtin one. False otherwise.
17097b937cc2SFrank Rowand  */
of_have_populated_dt(void)17107b937cc2SFrank Rowand static inline bool of_have_populated_dt(void)
17117b937cc2SFrank Rowand {
17127b937cc2SFrank Rowand #ifdef CONFIG_OF
17137b937cc2SFrank Rowand 	return of_property_present(of_root, "compatible");
17147b937cc2SFrank Rowand #else
17157b937cc2SFrank Rowand 	return false;
1716c968b89aSRandy Dunlap #endif
17177518b589SPantelis Antoniou }
17187518b589SPantelis Antoniou 
17197518b589SPantelis Antoniou /*
172039a842e2SAlan Tull  * Overlay support
1721067c0987SFrank Rowand  */
1722067c0987SFrank Rowand 
172339a842e2SAlan Tull enum of_overlay_notify_action {
172439a842e2SAlan Tull 	OF_OVERLAY_INIT = 0,	/* kzalloc() of ovcs sets this value */
172539a842e2SAlan Tull 	OF_OVERLAY_PRE_APPLY,
172639a842e2SAlan Tull 	OF_OVERLAY_POST_APPLY,
172739a842e2SAlan Tull 	OF_OVERLAY_PRE_REMOVE,
172891924d9bSChristian Göttsche 	OF_OVERLAY_POST_REMOVE,
17291ac17586SFrank Rowand };
173091924d9bSChristian Göttsche 
of_overlay_action_name(enum of_overlay_notify_action action)17311ac17586SFrank Rowand static inline const char *of_overlay_action_name(enum of_overlay_notify_action action)
17321ac17586SFrank Rowand {
17331ac17586SFrank Rowand 	static const char *const of_overlay_action_name[] = {
17341ac17586SFrank Rowand 		"init",
17351ac17586SFrank Rowand 		"pre-apply",
17361ac17586SFrank Rowand 		"post-apply",
17371ac17586SFrank Rowand 		"pre-remove",
17381ac17586SFrank Rowand 		"post-remove",
17391ac17586SFrank Rowand 	};
17401ac17586SFrank Rowand 
174139a842e2SAlan Tull 	return of_overlay_action_name[action];
174239a842e2SAlan Tull }
174339a842e2SAlan Tull 
174439a842e2SAlan Tull struct of_overlay_notify_data {
174539a842e2SAlan Tull 	struct device_node *overlay;
17467518b589SPantelis Antoniou 	struct device_node *target;
17477518b589SPantelis Antoniou };
174839a751a4SFrank Rowand 
1749ec8c2329SRob Herring (Arm) #ifdef CONFIG_OF_OVERLAY
175024789c5cSFrank Rowand 
17510290c4caSFrank Rowand int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
17527518b589SPantelis Antoniou 			 int *ovcs_id, const struct device_node *target_base);
175339a842e2SAlan Tull int of_overlay_remove(int *ovcs_id);
175439a842e2SAlan Tull int of_overlay_remove_all(void);
175539a842e2SAlan Tull 
17567518b589SPantelis Antoniou int of_overlay_notifier_register(struct notifier_block *nb);
17577518b589SPantelis Antoniou int of_overlay_notifier_unregister(struct notifier_block *nb);
1758cf60ce92SPavel Pisa 
1759ec8c2329SRob Herring (Arm) #else
17607518b589SPantelis Antoniou 
of_overlay_fdt_apply(const void * overlay_fdt,u32 overlay_fdt_size,int * ovcs_id,const struct device_node * target_base)17617518b589SPantelis Antoniou static inline int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
17627518b589SPantelis Antoniou 				       int *ovcs_id, const struct device_node *target_base)
17637518b589SPantelis Antoniou {
176424789c5cSFrank Rowand 	return -ENOTSUPP;
17657518b589SPantelis Antoniou }
17667518b589SPantelis Antoniou 
of_overlay_remove(int * ovcs_id)17677518b589SPantelis Antoniou static inline int of_overlay_remove(int *ovcs_id)
17687518b589SPantelis Antoniou {
17690290c4caSFrank Rowand 	return -ENOTSUPP;
17707518b589SPantelis Antoniou }
17717518b589SPantelis Antoniou 
of_overlay_remove_all(void)17727518b589SPantelis Antoniou static inline int of_overlay_remove_all(void)
17737518b589SPantelis Antoniou {
177439a842e2SAlan Tull 	return -ENOTSUPP;
177539a842e2SAlan Tull }
177639a842e2SAlan Tull 
of_overlay_notifier_register(struct notifier_block * nb)177739a842e2SAlan Tull static inline int of_overlay_notifier_register(struct notifier_block *nb)
177839a842e2SAlan Tull {
177939a842e2SAlan Tull 	return 0;
178039a842e2SAlan Tull }
178139a842e2SAlan Tull 
of_overlay_notifier_unregister(struct notifier_block * nb)178239a842e2SAlan Tull static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
178339a842e2SAlan Tull {
17847518b589SPantelis Antoniou 	return 0;
17857518b589SPantelis Antoniou }
178676c1ce78SStephen Rothwell 
1787 #endif
1788 
1789 #endif /* _LINUX_OF_H */
1790