xref: /linux-6.15/include/linux/of.h (revision 5c19e952)
176c1ce78SStephen Rothwell #ifndef _LINUX_OF_H
276c1ce78SStephen Rothwell #define _LINUX_OF_H
376c1ce78SStephen Rothwell /*
476c1ce78SStephen Rothwell  * Definitions for talking to the Open Firmware PROM on
576c1ce78SStephen Rothwell  * Power Macintosh and other computers.
676c1ce78SStephen Rothwell  *
776c1ce78SStephen Rothwell  * Copyright (C) 1996-2005 Paul Mackerras.
876c1ce78SStephen Rothwell  *
976c1ce78SStephen Rothwell  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
1076c1ce78SStephen Rothwell  * Updates for SPARC64 by David S. Miller
1176c1ce78SStephen Rothwell  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
1276c1ce78SStephen Rothwell  *
1376c1ce78SStephen Rothwell  * This program is free software; you can redistribute it and/or
1476c1ce78SStephen Rothwell  * modify it under the terms of the GNU General Public License
1576c1ce78SStephen Rothwell  * as published by the Free Software Foundation; either version
1676c1ce78SStephen Rothwell  * 2 of the License, or (at your option) any later version.
1776c1ce78SStephen Rothwell  */
1876c1ce78SStephen Rothwell #include <linux/types.h>
191977f032SJiri Slaby #include <linux/bitops.h>
20e51130c0SKalle Valo #include <linux/errno.h>
216f192492SGrant Likely #include <linux/kref.h>
22283029d1SGrant Likely #include <linux/mod_devicetable.h>
230d351c3eSGrant Likely #include <linux/spinlock.h>
245ca4db61SPaul Mundt #include <linux/topology.h>
251cf3d8b3SNathan Fontenot #include <linux/notifier.h>
2676c1ce78SStephen Rothwell 
272e89e685SJeremy Kerr #include <asm/byteorder.h>
28d0a99402SPaul Gortmaker #include <asm/errno.h>
292e89e685SJeremy Kerr 
30731581e6SGrant Likely typedef u32 phandle;
31731581e6SGrant Likely typedef u32 ihandle;
32731581e6SGrant Likely 
33731581e6SGrant Likely struct property {
34731581e6SGrant Likely 	char	*name;
35731581e6SGrant Likely 	int	length;
36731581e6SGrant Likely 	void	*value;
37731581e6SGrant Likely 	struct property *next;
38731581e6SGrant Likely 	unsigned long _flags;
39731581e6SGrant Likely 	unsigned int unique_id;
40731581e6SGrant Likely };
41731581e6SGrant Likely 
426f192492SGrant Likely #if defined(CONFIG_SPARC)
436f192492SGrant Likely struct of_irq_controller;
446f192492SGrant Likely #endif
456f192492SGrant Likely 
466f192492SGrant Likely struct device_node {
476f192492SGrant Likely 	const char *name;
486f192492SGrant Likely 	const char *type;
496016a363SGrant Likely 	phandle phandle;
50c22618a1SGrant Likely 	const char *full_name;
516f192492SGrant Likely 
526f192492SGrant Likely 	struct	property *properties;
536f192492SGrant Likely 	struct	property *deadprops;	/* removed properties */
546f192492SGrant Likely 	struct	device_node *parent;
556f192492SGrant Likely 	struct	device_node *child;
566f192492SGrant Likely 	struct	device_node *sibling;
576f192492SGrant Likely 	struct	device_node *next;	/* next device of same type */
586f192492SGrant Likely 	struct	device_node *allnext;	/* next in list of all nodes */
596f192492SGrant Likely 	struct	proc_dir_entry *pde;	/* this node's proc directory */
606f192492SGrant Likely 	struct	kref kref;
616f192492SGrant Likely 	unsigned long _flags;
626f192492SGrant Likely 	void	*data;
636f192492SGrant Likely #if defined(CONFIG_SPARC)
64c22618a1SGrant Likely 	const char *path_component_name;
656f192492SGrant Likely 	unsigned int unique_id;
666f192492SGrant Likely 	struct of_irq_controller *irq_trans;
676f192492SGrant Likely #endif
686f192492SGrant Likely };
696f192492SGrant Likely 
7015c9a0acSGrant Likely #define MAX_PHANDLE_ARGS 8
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 
770f22dd39SGrant Likely #ifdef CONFIG_OF_DYNAMIC
780f22dd39SGrant Likely extern struct device_node *of_node_get(struct device_node *node);
790f22dd39SGrant Likely extern void of_node_put(struct device_node *node);
800f22dd39SGrant Likely #else /* CONFIG_OF_DYNAMIC */
813ecdd051SRob Herring /* Dummy ref counting routines - to be implemented later */
823ecdd051SRob Herring static inline struct device_node *of_node_get(struct device_node *node)
833ecdd051SRob Herring {
843ecdd051SRob Herring 	return node;
853ecdd051SRob Herring }
860f22dd39SGrant Likely static inline void of_node_put(struct device_node *node) { }
870f22dd39SGrant Likely #endif /* !CONFIG_OF_DYNAMIC */
883ecdd051SRob Herring 
89c9e358dfSGrant Likely #ifdef CONFIG_OF
90c9e358dfSGrant Likely 
9141f88009SGrant Likely /* Pointer for first entry in chain of all nodes. */
92465aac6dSRandy Dunlap extern struct device_node *of_allnodes;
93fc0bdae4SGrant Likely extern struct device_node *of_chosen;
94611cad72SShawn Guo extern struct device_node *of_aliases;
95d6d3c4e6SThomas Gleixner extern raw_spinlock_t devtree_lock;
9641f88009SGrant Likely 
973bcbaf6eSSebastian Andrzej Siewior static inline bool of_have_populated_dt(void)
983bcbaf6eSSebastian Andrzej Siewior {
99465aac6dSRandy Dunlap 	return of_allnodes != NULL;
1003bcbaf6eSSebastian Andrzej Siewior }
1013bcbaf6eSSebastian Andrzej Siewior 
102035ebefcSAndres Salomon static inline bool of_node_is_root(const struct device_node *node)
103035ebefcSAndres Salomon {
104035ebefcSAndres Salomon 	return node && (node->parent == NULL);
105035ebefcSAndres Salomon }
106035ebefcSAndres Salomon 
10750436312SGrant Likely static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
10850436312SGrant Likely {
10950436312SGrant Likely 	return test_bit(flag, &n->_flags);
11050436312SGrant Likely }
11150436312SGrant Likely 
11250436312SGrant Likely static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
11350436312SGrant Likely {
11450436312SGrant Likely 	set_bit(flag, &n->_flags);
11550436312SGrant Likely }
11650436312SGrant Likely 
117e91edcf5SGrant Likely extern struct device_node *of_find_all_nodes(struct device_node *prev);
118e91edcf5SGrant Likely 
119b6caf2adSGrant Likely /*
1203d6b8828SLennert Buytenhek  * OF address retrieval & translation
121b6caf2adSGrant Likely  */
122b6caf2adSGrant Likely 
123b6caf2adSGrant Likely /* Helper to read a big number; size is in cells (not bytes) */
1242e89e685SJeremy Kerr static inline u64 of_read_number(const __be32 *cell, int size)
125b6caf2adSGrant Likely {
126b6caf2adSGrant Likely 	u64 r = 0;
127b6caf2adSGrant Likely 	while (size--)
1282e89e685SJeremy Kerr 		r = (r << 32) | be32_to_cpu(*(cell++));
129b6caf2adSGrant Likely 	return r;
130b6caf2adSGrant Likely }
131b6caf2adSGrant Likely 
132b6caf2adSGrant Likely /* Like of_read_number, but we want an unsigned long result */
1332e89e685SJeremy Kerr static inline unsigned long of_read_ulong(const __be32 *cell, int size)
134b6caf2adSGrant Likely {
1352be09cb9SGrant Likely 	/* toss away upper bits if unsigned long is smaller than u64 */
1362be09cb9SGrant Likely 	return of_read_number(cell, size);
137b6caf2adSGrant Likely }
138b6caf2adSGrant Likely 
13976c1ce78SStephen Rothwell #include <asm/prom.h>
14076c1ce78SStephen Rothwell 
1417c7b60cbSGrant Likely /* Default #address and #size cells.  Allow arch asm/prom.h to override */
1427c7b60cbSGrant Likely #if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT)
1437c7b60cbSGrant Likely #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
1447c7b60cbSGrant Likely #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
1457c7b60cbSGrant Likely #endif
1467c7b60cbSGrant Likely 
1477c7b60cbSGrant Likely /* Default string compare functions, Allow arch asm/prom.h to override */
1487c7b60cbSGrant Likely #if !defined(of_compat_cmp)
1491976152fSGrant Likely #define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
1507c7b60cbSGrant Likely #define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
1517c7b60cbSGrant Likely #define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
1527c7b60cbSGrant Likely #endif
1537c7b60cbSGrant Likely 
15476c1ce78SStephen Rothwell /* flag descriptions */
15576c1ce78SStephen Rothwell #define OF_DYNAMIC	1 /* node and properties were allocated via kmalloc */
15676c1ce78SStephen Rothwell #define OF_DETACHED	2 /* node has been detached from the device tree */
15776c1ce78SStephen Rothwell 
15861e955dbSGrant Likely #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
15961e955dbSGrant Likely #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
16061e955dbSGrant Likely 
16176c1ce78SStephen Rothwell #define OF_BAD_ADDR	((u64)-1)
16276c1ce78SStephen Rothwell 
163c0a05bf0SSteffen Trumtrar static inline const char *of_node_full_name(const struct device_node *np)
16474a7f084SGrant Likely {
16574a7f084SGrant Likely 	return np ? np->full_name : "<no-node>";
16674a7f084SGrant Likely }
16774a7f084SGrant Likely 
16876c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_name(struct device_node *from,
16976c1ce78SStephen Rothwell 	const char *name);
17076c1ce78SStephen Rothwell #define for_each_node_by_name(dn, name) \
17176c1ce78SStephen Rothwell 	for (dn = of_find_node_by_name(NULL, name); dn; \
17276c1ce78SStephen Rothwell 	     dn = of_find_node_by_name(dn, name))
17376c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_type(struct device_node *from,
17476c1ce78SStephen Rothwell 	const char *type);
17576c1ce78SStephen Rothwell #define for_each_node_by_type(dn, type) \
17676c1ce78SStephen Rothwell 	for (dn = of_find_node_by_type(NULL, type); dn; \
17776c1ce78SStephen Rothwell 	     dn = of_find_node_by_type(dn, type))
17876c1ce78SStephen Rothwell extern struct device_node *of_find_compatible_node(struct device_node *from,
17976c1ce78SStephen Rothwell 	const char *type, const char *compat);
18076c1ce78SStephen Rothwell #define for_each_compatible_node(dn, type, compatible) \
18176c1ce78SStephen Rothwell 	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
18276c1ce78SStephen Rothwell 	     dn = of_find_compatible_node(dn, type, compatible))
18350c8af4cSStephen Warren extern struct device_node *of_find_matching_node_and_match(
18450c8af4cSStephen Warren 	struct device_node *from,
18550c8af4cSStephen Warren 	const struct of_device_id *matches,
18650c8af4cSStephen Warren 	const struct of_device_id **match);
18750c8af4cSStephen Warren static inline struct device_node *of_find_matching_node(
18850c8af4cSStephen Warren 	struct device_node *from,
18950c8af4cSStephen Warren 	const struct of_device_id *matches)
19050c8af4cSStephen Warren {
19150c8af4cSStephen Warren 	return of_find_matching_node_and_match(from, matches, NULL);
19250c8af4cSStephen Warren }
193283029d1SGrant Likely #define for_each_matching_node(dn, matches) \
194283029d1SGrant Likely 	for (dn = of_find_matching_node(NULL, matches); dn; \
195283029d1SGrant Likely 	     dn = of_find_matching_node(dn, matches))
19650c8af4cSStephen Warren #define for_each_matching_node_and_match(dn, matches, match) \
19750c8af4cSStephen Warren 	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
19850c8af4cSStephen Warren 	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
19976c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_path(const char *path);
20076c1ce78SStephen Rothwell extern struct device_node *of_find_node_by_phandle(phandle handle);
20176c1ce78SStephen Rothwell extern struct device_node *of_get_parent(const struct device_node *node);
202f4eb0107SMichael Ellerman extern struct device_node *of_get_next_parent(struct device_node *node);
20376c1ce78SStephen Rothwell extern struct device_node *of_get_next_child(const struct device_node *node,
20476c1ce78SStephen Rothwell 					     struct device_node *prev);
2053296193dSTimur Tabi extern struct device_node *of_get_next_available_child(
2063296193dSTimur Tabi 	const struct device_node *node, struct device_node *prev);
2073296193dSTimur Tabi 
2089c19761aSSrinivas Kandagatla extern struct device_node *of_get_child_by_name(const struct device_node *node,
2099c19761aSSrinivas Kandagatla 					const char *name);
210aabc08dcSMichael Ellerman #define for_each_child_of_node(parent, child) \
211aabc08dcSMichael Ellerman 	for (child = of_get_next_child(parent, NULL); child != NULL; \
212aabc08dcSMichael Ellerman 	     child = of_get_next_child(parent, child))
213aabc08dcSMichael Ellerman 
2143296193dSTimur Tabi #define for_each_available_child_of_node(parent, child) \
2153296193dSTimur Tabi 	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
2163296193dSTimur Tabi 	     child = of_get_next_available_child(parent, child))
2173296193dSTimur Tabi 
218183f1d0cSDong Aisheng static inline int of_get_child_count(const struct device_node *np)
219183f1d0cSDong Aisheng {
220183f1d0cSDong Aisheng 	struct device_node *child;
221183f1d0cSDong Aisheng 	int num = 0;
222183f1d0cSDong Aisheng 
223183f1d0cSDong Aisheng 	for_each_child_of_node(np, child)
224183f1d0cSDong Aisheng 		num++;
225183f1d0cSDong Aisheng 
226183f1d0cSDong Aisheng 	return num;
227183f1d0cSDong Aisheng }
228183f1d0cSDong Aisheng 
2291e291b14SMichael Ellerman extern struct device_node *of_find_node_with_property(
2301e291b14SMichael Ellerman 	struct device_node *from, const char *prop_name);
2311e291b14SMichael Ellerman #define for_each_node_with_property(dn, prop_name) \
2321e291b14SMichael Ellerman 	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
2331e291b14SMichael Ellerman 	     dn = of_find_node_with_property(dn, prop_name))
2341e291b14SMichael Ellerman 
23576c1ce78SStephen Rothwell extern struct property *of_find_property(const struct device_node *np,
23676c1ce78SStephen Rothwell 					 const char *name,
23776c1ce78SStephen Rothwell 					 int *lenp);
2383daf3726STony Prisk extern int of_property_read_u32_index(const struct device_node *np,
2393daf3726STony Prisk 				       const char *propname,
2403daf3726STony Prisk 				       u32 index, u32 *out_value);
241be193249SViresh Kumar extern int of_property_read_u8_array(const struct device_node *np,
242be193249SViresh Kumar 			const char *propname, u8 *out_values, size_t sz);
243be193249SViresh Kumar extern int of_property_read_u16_array(const struct device_node *np,
244be193249SViresh Kumar 			const char *propname, u16 *out_values, size_t sz);
2450e373639SRob Herring extern int of_property_read_u32_array(const struct device_node *np,
246aac285c6SJamie Iles 				      const char *propname,
2470e373639SRob Herring 				      u32 *out_values,
2480e373639SRob Herring 				      size_t sz);
2494cd7f7a3SJamie Iles extern int of_property_read_u64(const struct device_node *np,
2504cd7f7a3SJamie Iles 				const char *propname, u64 *out_value);
2510e373639SRob Herring 
252aac285c6SJamie Iles extern int of_property_read_string(struct device_node *np,
253aac285c6SJamie Iles 				   const char *propname,
254f09bc831SShawn Guo 				   const char **out_string);
2554fcd15a0SBenoit Cousson extern int of_property_read_string_index(struct device_node *np,
2564fcd15a0SBenoit Cousson 					 const char *propname,
2574fcd15a0SBenoit Cousson 					 int index, const char **output);
2587aff0fe3SGrant Likely extern int of_property_match_string(struct device_node *np,
2597aff0fe3SGrant Likely 				    const char *propname,
2607aff0fe3SGrant Likely 				    const char *string);
2614fcd15a0SBenoit Cousson extern int of_property_count_strings(struct device_node *np,
2624fcd15a0SBenoit Cousson 				     const char *propname);
26376c1ce78SStephen Rothwell extern int of_device_is_compatible(const struct device_node *device,
26476c1ce78SStephen Rothwell 				   const char *);
265834d97d4SJosh Boyer extern int of_device_is_available(const struct device_node *device);
26676c1ce78SStephen Rothwell extern const void *of_get_property(const struct device_node *node,
26776c1ce78SStephen Rothwell 				const char *name,
26876c1ce78SStephen Rothwell 				int *lenp);
2698af0da93SDong Aisheng #define for_each_property_of_node(dn, pp) \
2708af0da93SDong Aisheng 	for (pp = dn->properties; pp != NULL; pp = pp->next)
271611cad72SShawn Guo 
27276c1ce78SStephen Rothwell extern int of_n_addr_cells(struct device_node *np);
27376c1ce78SStephen Rothwell extern int of_n_size_cells(struct device_node *np);
274283029d1SGrant Likely extern const struct of_device_id *of_match_node(
275283029d1SGrant Likely 	const struct of_device_id *matches, const struct device_node *node);
2763f07af49SGrant Likely extern int of_modalias_node(struct device_node *node, char *modalias, int len);
277b8fbdc42SSteffen Trumtrar extern struct device_node *of_parse_phandle(const struct device_node *np,
278739649c5SGrant Likely 					    const char *phandle_name,
279739649c5SGrant Likely 					    int index);
28093c667caSGuennadi Liakhovetski extern int of_parse_phandle_with_args(const struct device_node *np,
28164b60e09SAnton Vorontsov 	const char *list_name, const char *cells_name, int index,
28215c9a0acSGrant Likely 	struct of_phandle_args *out_args);
283bd69f73fSGrant Likely extern int of_count_phandle_with_args(const struct device_node *np,
284bd69f73fSGrant Likely 	const char *list_name, const char *cells_name);
28576c1ce78SStephen Rothwell 
286611cad72SShawn Guo extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
287611cad72SShawn Guo extern int of_alias_get_id(struct device_node *np, const char *stem);
288611cad72SShawn Guo 
28921b082ecSGrant Likely extern int of_machine_is_compatible(const char *compat);
29021b082ecSGrant Likely 
29179d1c712SNathan Fontenot extern int of_add_property(struct device_node *np, struct property *prop);
29279d1c712SNathan Fontenot extern int of_remove_property(struct device_node *np, struct property *prop);
29379d1c712SNathan Fontenot extern int of_update_property(struct device_node *np, struct property *newprop);
29421b082ecSGrant Likely 
295fcdeb7feSGrant Likely /* For updating the device tree at runtime */
2961cf3d8b3SNathan Fontenot #define OF_RECONFIG_ATTACH_NODE		0x0001
2971cf3d8b3SNathan Fontenot #define OF_RECONFIG_DETACH_NODE		0x0002
2981cf3d8b3SNathan Fontenot #define OF_RECONFIG_ADD_PROPERTY	0x0003
2991cf3d8b3SNathan Fontenot #define OF_RECONFIG_REMOVE_PROPERTY	0x0004
3001cf3d8b3SNathan Fontenot #define OF_RECONFIG_UPDATE_PROPERTY	0x0005
3011cf3d8b3SNathan Fontenot 
3021cf3d8b3SNathan Fontenot struct of_prop_reconfig {
3031cf3d8b3SNathan Fontenot 	struct device_node	*dn;
3041cf3d8b3SNathan Fontenot 	struct property		*prop;
3051cf3d8b3SNathan Fontenot };
3061cf3d8b3SNathan Fontenot 
3071cf3d8b3SNathan Fontenot extern int of_reconfig_notifier_register(struct notifier_block *);
3081cf3d8b3SNathan Fontenot extern int of_reconfig_notifier_unregister(struct notifier_block *);
3091cf3d8b3SNathan Fontenot extern int of_reconfig_notify(unsigned long, void *);
3101cf3d8b3SNathan Fontenot 
3111cf3d8b3SNathan Fontenot extern int of_attach_node(struct device_node *);
3121cf3d8b3SNathan Fontenot extern int of_detach_node(struct device_node *);
313fcdeb7feSGrant Likely 
3143a1e362eSBen Dooks #define of_match_ptr(_ptr)	(_ptr)
315c541adc6SStephen Warren 
316c541adc6SStephen Warren /*
317c541adc6SStephen Warren  * struct property *prop;
318c541adc6SStephen Warren  * const __be32 *p;
319c541adc6SStephen Warren  * u32 u;
320c541adc6SStephen Warren  *
321c541adc6SStephen Warren  * of_property_for_each_u32(np, "propname", prop, p, u)
322c541adc6SStephen Warren  *         printk("U32 value: %x\n", u);
323c541adc6SStephen Warren  */
324c541adc6SStephen Warren const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
325c541adc6SStephen Warren 			       u32 *pu);
326c541adc6SStephen Warren #define of_property_for_each_u32(np, propname, prop, p, u)	\
327c541adc6SStephen Warren 	for (prop = of_find_property(np, propname, NULL),	\
328c541adc6SStephen Warren 		p = of_prop_next_u32(prop, NULL, &u);		\
329c541adc6SStephen Warren 		p;						\
330c541adc6SStephen Warren 		p = of_prop_next_u32(prop, p, &u))
331c541adc6SStephen Warren 
332c541adc6SStephen Warren /*
333c541adc6SStephen Warren  * struct property *prop;
334c541adc6SStephen Warren  * const char *s;
335c541adc6SStephen Warren  *
336c541adc6SStephen Warren  * of_property_for_each_string(np, "propname", prop, s)
337c541adc6SStephen Warren  *         printk("String value: %s\n", s);
338c541adc6SStephen Warren  */
339c541adc6SStephen Warren const char *of_prop_next_string(struct property *prop, const char *cur);
340c541adc6SStephen Warren #define of_property_for_each_string(np, propname, prop, s)	\
341c541adc6SStephen Warren 	for (prop = of_find_property(np, propname, NULL),	\
342c541adc6SStephen Warren 		s = of_prop_next_string(prop, NULL);		\
343c541adc6SStephen Warren 		s;						\
344c541adc6SStephen Warren 		s = of_prop_next_string(prop, s))
345c541adc6SStephen Warren 
346*5c19e952SSascha Hauer int of_device_is_stdout_path(struct device_node *dn);
347*5c19e952SSascha Hauer 
348b98c0239SShawn Guo #else /* CONFIG_OF */
3493bcbaf6eSSebastian Andrzej Siewior 
35074a7f084SGrant Likely static inline const char* of_node_full_name(struct device_node *np)
35174a7f084SGrant Likely {
35274a7f084SGrant Likely 	return "<no-node>";
35374a7f084SGrant Likely }
35474a7f084SGrant Likely 
3551cc44f43SPeter Ujfalusi static inline struct device_node *of_find_node_by_name(struct device_node *from,
3561cc44f43SPeter Ujfalusi 	const char *name)
3571cc44f43SPeter Ujfalusi {
3581cc44f43SPeter Ujfalusi 	return NULL;
3591cc44f43SPeter Ujfalusi }
3601cc44f43SPeter Ujfalusi 
361066ec1ddSAlexander Shiyan static inline struct device_node *of_get_parent(const struct device_node *node)
362066ec1ddSAlexander Shiyan {
363066ec1ddSAlexander Shiyan 	return NULL;
364066ec1ddSAlexander Shiyan }
365066ec1ddSAlexander Shiyan 
3663bcbaf6eSSebastian Andrzej Siewior static inline bool of_have_populated_dt(void)
3673bcbaf6eSSebastian Andrzej Siewior {
3683bcbaf6eSSebastian Andrzej Siewior 	return false;
3693bcbaf6eSSebastian Andrzej Siewior }
3703bcbaf6eSSebastian Andrzej Siewior 
371aba3dfffSStephen Warren #define for_each_child_of_node(parent, child) \
372aba3dfffSStephen Warren 	while (0)
373aba3dfffSStephen Warren 
37425c040c9SOlof Johansson static inline struct device_node *of_get_child_by_name(
37525c040c9SOlof Johansson 					const struct device_node *node,
37625c040c9SOlof Johansson 					const char *name)
37725c040c9SOlof Johansson {
37825c040c9SOlof Johansson 	return NULL;
37925c040c9SOlof Johansson }
38025c040c9SOlof Johansson 
381183f1d0cSDong Aisheng static inline int of_get_child_count(const struct device_node *np)
382183f1d0cSDong Aisheng {
383183f1d0cSDong Aisheng 	return 0;
384183f1d0cSDong Aisheng }
385183f1d0cSDong Aisheng 
38636a0904eSRajendra Nayak static inline int of_device_is_compatible(const struct device_node *device,
38736a0904eSRajendra Nayak 					  const char *name)
38836a0904eSRajendra Nayak {
38936a0904eSRajendra Nayak 	return 0;
39036a0904eSRajendra Nayak }
39136a0904eSRajendra Nayak 
392d7195696SRob Herring static inline int of_device_is_available(const struct device_node *device)
393d7195696SRob Herring {
394d7195696SRob Herring 	return 0;
395d7195696SRob Herring }
396d7195696SRob Herring 
397aba3dfffSStephen Warren static inline struct property *of_find_property(const struct device_node *np,
398aba3dfffSStephen Warren 						const char *name,
399aba3dfffSStephen Warren 						int *lenp)
400aba3dfffSStephen Warren {
401aba3dfffSStephen Warren 	return NULL;
402aba3dfffSStephen Warren }
403aba3dfffSStephen Warren 
4042261cc62SShawn Guo static inline struct device_node *of_find_compatible_node(
4052261cc62SShawn Guo 						struct device_node *from,
4062261cc62SShawn Guo 						const char *type,
4072261cc62SShawn Guo 						const char *compat)
4082261cc62SShawn Guo {
4092261cc62SShawn Guo 	return NULL;
4102261cc62SShawn Guo }
4112261cc62SShawn Guo 
4123daf3726STony Prisk static inline int of_property_read_u32_index(const struct device_node *np,
4133daf3726STony Prisk 			const char *propname, u32 index, u32 *out_value)
4143daf3726STony Prisk {
4153daf3726STony Prisk 	return -ENOSYS;
4163daf3726STony Prisk }
4173daf3726STony Prisk 
418be193249SViresh Kumar static inline int of_property_read_u8_array(const struct device_node *np,
419be193249SViresh Kumar 			const char *propname, u8 *out_values, size_t sz)
420be193249SViresh Kumar {
421be193249SViresh Kumar 	return -ENOSYS;
422be193249SViresh Kumar }
423be193249SViresh Kumar 
424be193249SViresh Kumar static inline int of_property_read_u16_array(const struct device_node *np,
425be193249SViresh Kumar 			const char *propname, u16 *out_values, size_t sz)
426be193249SViresh Kumar {
427be193249SViresh Kumar 	return -ENOSYS;
428be193249SViresh Kumar }
429be193249SViresh Kumar 
430b98c0239SShawn Guo static inline int of_property_read_u32_array(const struct device_node *np,
431aac285c6SJamie Iles 					     const char *propname,
432aac285c6SJamie Iles 					     u32 *out_values, size_t sz)
433b98c0239SShawn Guo {
434b98c0239SShawn Guo 	return -ENOSYS;
435b98c0239SShawn Guo }
436b98c0239SShawn Guo 
437b98c0239SShawn Guo static inline int of_property_read_string(struct device_node *np,
438aac285c6SJamie Iles 					  const char *propname,
439aac285c6SJamie Iles 					  const char **out_string)
440b98c0239SShawn Guo {
441b98c0239SShawn Guo 	return -ENOSYS;
442b98c0239SShawn Guo }
443b98c0239SShawn Guo 
4444fcd15a0SBenoit Cousson static inline int of_property_read_string_index(struct device_node *np,
4454fcd15a0SBenoit Cousson 						const char *propname, int index,
4464fcd15a0SBenoit Cousson 						const char **out_string)
4474fcd15a0SBenoit Cousson {
4484fcd15a0SBenoit Cousson 	return -ENOSYS;
4494fcd15a0SBenoit Cousson }
4504fcd15a0SBenoit Cousson 
4514fcd15a0SBenoit Cousson static inline int of_property_count_strings(struct device_node *np,
4524fcd15a0SBenoit Cousson 					    const char *propname)
4534fcd15a0SBenoit Cousson {
4544fcd15a0SBenoit Cousson 	return -ENOSYS;
4554fcd15a0SBenoit Cousson }
4564fcd15a0SBenoit Cousson 
45789272b8cSStephen Warren static inline const void *of_get_property(const struct device_node *node,
45889272b8cSStephen Warren 				const char *name,
45989272b8cSStephen Warren 				int *lenp)
46089272b8cSStephen Warren {
46189272b8cSStephen Warren 	return NULL;
46289272b8cSStephen Warren }
46389272b8cSStephen Warren 
4644cd7f7a3SJamie Iles static inline int of_property_read_u64(const struct device_node *np,
4654cd7f7a3SJamie Iles 				       const char *propname, u64 *out_value)
4664cd7f7a3SJamie Iles {
4674cd7f7a3SJamie Iles 	return -ENOSYS;
4684cd7f7a3SJamie Iles }
4694cd7f7a3SJamie Iles 
470bd3d5500SThierry Reding static inline int of_property_match_string(struct device_node *np,
471bd3d5500SThierry Reding 					   const char *propname,
472bd3d5500SThierry Reding 					   const char *string)
473bd3d5500SThierry Reding {
474bd3d5500SThierry Reding 	return -ENOSYS;
475bd3d5500SThierry Reding }
476bd3d5500SThierry Reding 
477b8fbdc42SSteffen Trumtrar static inline struct device_node *of_parse_phandle(const struct device_node *np,
47836a0904eSRajendra Nayak 						   const char *phandle_name,
47936a0904eSRajendra Nayak 						   int index)
48036a0904eSRajendra Nayak {
48136a0904eSRajendra Nayak 	return NULL;
48236a0904eSRajendra Nayak }
48336a0904eSRajendra Nayak 
484e05e5070SThierry Reding static inline int of_parse_phandle_with_args(struct device_node *np,
485e05e5070SThierry Reding 					     const char *list_name,
486e05e5070SThierry Reding 					     const char *cells_name,
487e05e5070SThierry Reding 					     int index,
488e05e5070SThierry Reding 					     struct of_phandle_args *out_args)
489e05e5070SThierry Reding {
490e05e5070SThierry Reding 	return -ENOSYS;
491e05e5070SThierry Reding }
492e05e5070SThierry Reding 
493bd69f73fSGrant Likely static inline int of_count_phandle_with_args(struct device_node *np,
494bd69f73fSGrant Likely 					     const char *list_name,
495bd69f73fSGrant Likely 					     const char *cells_name)
496bd69f73fSGrant Likely {
497bd69f73fSGrant Likely 	return -ENOSYS;
498bd69f73fSGrant Likely }
499bd69f73fSGrant Likely 
500ed5f886dSNicolas Ferre static inline int of_alias_get_id(struct device_node *np, const char *stem)
501ed5f886dSNicolas Ferre {
502ed5f886dSNicolas Ferre 	return -ENOSYS;
503ed5f886dSNicolas Ferre }
504ed5f886dSNicolas Ferre 
50550e07f88SStephen Warren static inline int of_machine_is_compatible(const char *compat)
50650e07f88SStephen Warren {
50750e07f88SStephen Warren 	return 0;
50850e07f88SStephen Warren }
50950e07f88SStephen Warren 
510*5c19e952SSascha Hauer static inline int of_device_is_stdout_path(struct device_node *dn)
511*5c19e952SSascha Hauer {
512*5c19e952SSascha Hauer 	return 0;
513*5c19e952SSascha Hauer }
514*5c19e952SSascha Hauer 
5153a1e362eSBen Dooks #define of_match_ptr(_ptr)	NULL
5165762c205SNicolas Ferre #define of_match_node(_matches, _node)	NULL
517c541adc6SStephen Warren #define of_property_for_each_u32(np, propname, prop, p, u) \
518c541adc6SStephen Warren 	while (0)
519c541adc6SStephen Warren #define of_property_for_each_string(np, propname, prop, s) \
520c541adc6SStephen Warren 	while (0)
5219dfbf207SJeremy Kerr #endif /* CONFIG_OF */
522b98c0239SShawn Guo 
5235ca4db61SPaul Mundt #ifndef of_node_to_nid
5245ca4db61SPaul Mundt static inline int of_node_to_nid(struct device_node *np)
5255ca4db61SPaul Mundt {
5265ca4db61SPaul Mundt 	return numa_node_id();
5275ca4db61SPaul Mundt }
5285ca4db61SPaul Mundt 
5295ca4db61SPaul Mundt #define of_node_to_nid of_node_to_nid
5305ca4db61SPaul Mundt #endif
5315ca4db61SPaul Mundt 
532fa4d34ccSJean-Christophe PLAGNIOL-VILLARD /**
533fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  * of_property_read_bool - Findfrom a property
534fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  * @np:		device node from which the property value is to be read.
535fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  * @propname:	name of the property to be searched.
536fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  *
537fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  * Search for a property in a device node.
538fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  * Returns true if the property exist false otherwise.
539fa4d34ccSJean-Christophe PLAGNIOL-VILLARD  */
540fa4d34ccSJean-Christophe PLAGNIOL-VILLARD static inline bool of_property_read_bool(const struct device_node *np,
541fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 					 const char *propname)
542fa4d34ccSJean-Christophe PLAGNIOL-VILLARD {
543fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 	struct property *prop = of_find_property(np, propname, NULL);
544fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 
545fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 	return prop ? true : false;
546fa4d34ccSJean-Christophe PLAGNIOL-VILLARD }
547fa4d34ccSJean-Christophe PLAGNIOL-VILLARD 
548be193249SViresh Kumar static inline int of_property_read_u8(const struct device_node *np,
549be193249SViresh Kumar 				       const char *propname,
550be193249SViresh Kumar 				       u8 *out_value)
551be193249SViresh Kumar {
552be193249SViresh Kumar 	return of_property_read_u8_array(np, propname, out_value, 1);
553be193249SViresh Kumar }
554be193249SViresh Kumar 
555be193249SViresh Kumar static inline int of_property_read_u16(const struct device_node *np,
556be193249SViresh Kumar 				       const char *propname,
557be193249SViresh Kumar 				       u16 *out_value)
558be193249SViresh Kumar {
559be193249SViresh Kumar 	return of_property_read_u16_array(np, propname, out_value, 1);
560be193249SViresh Kumar }
561be193249SViresh Kumar 
562b98c0239SShawn Guo static inline int of_property_read_u32(const struct device_node *np,
563aac285c6SJamie Iles 				       const char *propname,
564b98c0239SShawn Guo 				       u32 *out_value)
565b98c0239SShawn Guo {
566b98c0239SShawn Guo 	return of_property_read_u32_array(np, propname, out_value, 1);
567b98c0239SShawn Guo }
568b98c0239SShawn Guo 
56934db8aafSDavid Howells #if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
57034db8aafSDavid Howells extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
57134db8aafSDavid Howells extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
57234db8aafSDavid Howells extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
57334db8aafSDavid Howells 					 struct property *prop);
57434db8aafSDavid Howells extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
57534db8aafSDavid Howells 					 struct property *newprop,
57634db8aafSDavid Howells 					 struct property *oldprop);
57734db8aafSDavid Howells #endif
57834db8aafSDavid Howells 
57976c1ce78SStephen Rothwell #endif /* _LINUX_OF_H */
580