1/* Public domain. */
2
3#ifndef _LINUX_OF_H
4#define _LINUX_OF_H
5
6#ifdef __macppc__
7static inline int
8of_machine_is_compatible(const char *model)
9{
10	extern char *hw_prod;
11	return (strcmp(model, hw_prod) == 0);
12}
13#endif
14
15struct device_node {
16	const char *full_name;
17};
18
19#define of_node	dv_cfdata
20
21struct device_node *__of_get_compatible_child(void *, const char *);
22#define of_get_compatible_child(d, n) \
23	__of_get_compatible_child(&(d), (n))
24
25struct device_node *__of_get_child_by_name(void *, const char *);
26#define of_get_child_by_name(d, n) \
27	__of_get_child_by_name(&(d), (n))
28
29#define of_node_put(p)
30
31struct device_node *__of_devnode(void *);
32#define __of_node(arg) \
33	__builtin_types_compatible_p(typeof(arg), struct device_node *) ? \
34		(struct device_node *)arg : __of_devnode(&arg)
35
36int	__of_property_present(struct device_node *, const char *);
37#define of_property_present(n, p) \
38	__of_property_present(__of_node(n), (p))
39
40int	__of_property_read_variable_u32_array(struct device_node *,
41	    const char *, uint32_t *, size_t, size_t);
42#define of_property_read_u32(n, p, o) \
43	__of_property_read_variable_u32_array(__of_node(n), (p), (o), 1, 1)
44#define of_property_read_variable_u32_array(n, p, o, l, h) \
45	__of_property_read_variable_u32_array(__of_node(n), (p), (o), (l), (h))
46
47int	__of_property_read_variable_u64_array(struct device_node *,
48	    const char *, uint64_t *, size_t, size_t);
49#define of_property_read_u64(n, p, o) \
50	__of_property_read_variable_u64_array(__of_node(n), (p), (o), 1, 1)
51
52int	__of_property_match_string(struct device_node *,
53	    const char *, const char *);
54#define of_property_match_string(n, a, b) \
55	__of_property_match_string(__of_node(n), (a), (b))
56
57struct device_node *__of_parse_phandle(struct device_node *,
58	    const char *, int);
59#define of_parse_phandle(n, a, b) \
60	__of_parse_phandle(__of_node(n), (a), (b))
61
62struct of_phandle_args {
63	struct device_node *np;
64	int args_count;
65	uint32_t args[5];
66};
67
68int	__of_parse_phandle_with_args(struct device_node *,
69	    const char *, const char *, int, struct of_phandle_args *);
70#define of_parse_phandle_with_args(n, a, b, c, d)			\
71	__of_parse_phandle_with_args(__of_node(n), (a), (b), (c), (d))
72
73int	of_device_is_available(struct device_node *);
74
75struct of_device_id {
76	const char *compatible;
77	const void *data;
78};
79
80struct device_node *__matching_node(struct device_node *,
81	    const struct of_device_id *);
82#define for_each_matching_node(a, b) \
83	for (a = __matching_node(NULL, b); a; a = __matching_node(a, b))
84
85#endif
86