1
2
3
4
5
6
7
8
9 #ifndef _LINUX_FWNODE_H_
10 #define _LINUX_FWNODE_H_
11
12 #include <linux/types.h>
13
14 struct fwnode_operations;
15 struct device;
16
17 struct fwnode_handle {
18 struct fwnode_handle *secondary;
19 const struct fwnode_operations *ops;
20 };
21
22
23
24
25
26
27
28 struct fwnode_endpoint {
29 unsigned int port;
30 unsigned int id;
31 const struct fwnode_handle *local_fwnode;
32 };
33
34 #define NR_FWNODE_REFERENCE_ARGS 8
35
36
37
38
39
40
41
42 struct fwnode_reference_args {
43 struct fwnode_handle *fwnode;
44 unsigned int nargs;
45 u64 args[NR_FWNODE_REFERENCE_ARGS];
46 };
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 struct fwnode_operations {
70 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
71 void (*put)(struct fwnode_handle *fwnode);
72 bool (*device_is_available)(const struct fwnode_handle *fwnode);
73 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
74 const struct device *dev);
75 bool (*property_present)(const struct fwnode_handle *fwnode,
76 const char *propname);
77 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
78 const char *propname,
79 unsigned int elem_size, void *val,
80 size_t nval);
81 int
82 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
83 const char *propname, const char **val,
84 size_t nval);
85 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
86 struct fwnode_handle *
87 (*get_next_child_node)(const struct fwnode_handle *fwnode,
88 struct fwnode_handle *child);
89 struct fwnode_handle *
90 (*get_named_child_node)(const struct fwnode_handle *fwnode,
91 const char *name);
92 int (*get_reference_args)(const struct fwnode_handle *fwnode,
93 const char *prop, const char *nargs_prop,
94 unsigned int nargs, unsigned int index,
95 struct fwnode_reference_args *args);
96 struct fwnode_handle *
97 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
98 struct fwnode_handle *prev);
99 struct fwnode_handle *
100 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
101 struct fwnode_handle *
102 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
103 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
104 struct fwnode_endpoint *endpoint);
105 };
106
107 #define fwnode_has_op(fwnode, op) \
108 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
109 #define fwnode_call_int_op(fwnode, op, ...) \
110 (fwnode ? (fwnode_has_op(fwnode, op) ? \
111 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
112 -EINVAL)
113
114 #define fwnode_call_bool_op(fwnode, op, ...) \
115 (fwnode_has_op(fwnode, op) ? \
116 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
117
118 #define fwnode_call_ptr_op(fwnode, op, ...) \
119 (fwnode_has_op(fwnode, op) ? \
120 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
121 #define fwnode_call_void_op(fwnode, op, ...) \
122 do { \
123 if (fwnode_has_op(fwnode, op)) \
124 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
125 } while (false)
126
127 #endif