]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
ce793486 RW |
2 | /* |
3 | * fwnode.h - Firmware device node object handle type definition. | |
4 | * | |
5 | * Copyright (C) 2015, Intel Corporation | |
6 | * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | |
ce793486 RW |
7 | */ |
8 | ||
9 | #ifndef _LINUX_FWNODE_H_ | |
10 | #define _LINUX_FWNODE_H_ | |
11 | ||
3708184a | 12 | #include <linux/types.h> |
7b337cb3 | 13 | #include <linux/list.h> |
74c782cf | 14 | #include <linux/err.h> |
3708184a | 15 | |
3708184a | 16 | struct fwnode_operations; |
b283f157 | 17 | struct device; |
3708184a | 18 | |
c2c724c8 SK |
19 | /* |
20 | * fwnode link flags | |
21 | * | |
74c782cf SK |
22 | * LINKS_ADDED: The fwnode has already be parsed to add fwnode links. |
23 | * NOT_DEVICE: The fwnode will never be populated as a struct device. | |
24 | * INITIALIZED: The hardware corresponding to fwnode has been initialized. | |
5501765a SK |
25 | * NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its |
26 | * driver needs its child devices to be bound with | |
27 | * their respective drivers as soon as they are | |
28 | * added. | |
c2c724c8 | 29 | */ |
5501765a SK |
30 | #define FWNODE_FLAG_LINKS_ADDED BIT(0) |
31 | #define FWNODE_FLAG_NOT_DEVICE BIT(1) | |
32 | #define FWNODE_FLAG_INITIALIZED BIT(2) | |
33 | #define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3) | |
c2c724c8 | 34 | |
ce793486 | 35 | struct fwnode_handle { |
97badf87 | 36 | struct fwnode_handle *secondary; |
3708184a | 37 | const struct fwnode_operations *ops; |
372a67c0 | 38 | struct device *dev; |
7b337cb3 SK |
39 | struct list_head suppliers; |
40 | struct list_head consumers; | |
c2c724c8 | 41 | u8 flags; |
7b337cb3 SK |
42 | }; |
43 | ||
44 | struct fwnode_link { | |
45 | struct fwnode_handle *supplier; | |
46 | struct list_head s_hook; | |
47 | struct fwnode_handle *consumer; | |
48 | struct list_head c_hook; | |
ce793486 RW |
49 | }; |
50 | ||
2bd5452d SA |
51 | /** |
52 | * struct fwnode_endpoint - Fwnode graph endpoint | |
53 | * @port: Port number | |
54 | * @id: Endpoint id | |
55 | * @local_fwnode: reference to the related fwnode | |
56 | */ | |
57 | struct fwnode_endpoint { | |
58 | unsigned int port; | |
59 | unsigned int id; | |
60 | const struct fwnode_handle *local_fwnode; | |
61 | }; | |
62 | ||
529b56a8 DS |
63 | /* |
64 | * ports and endpoints defined as software_nodes should all follow a common | |
65 | * naming scheme; use these macros to ensure commonality. | |
66 | */ | |
67 | #define SWNODE_GRAPH_PORT_NAME_FMT "port@%u" | |
68 | #define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u" | |
69 | ||
3e3119d3 SA |
70 | #define NR_FWNODE_REFERENCE_ARGS 8 |
71 | ||
72 | /** | |
73 | * struct fwnode_reference_args - Fwnode reference with additional arguments | |
74 | * @fwnode:- A reference to the base fwnode | |
75 | * @nargs: Number of elements in @args array | |
76 | * @args: Integer arguments on the fwnode | |
77 | */ | |
78 | struct fwnode_reference_args { | |
79 | struct fwnode_handle *fwnode; | |
80 | unsigned int nargs; | |
977d5ad3 | 81 | u64 args[NR_FWNODE_REFERENCE_ARGS]; |
3e3119d3 SA |
82 | }; |
83 | ||
3708184a SA |
84 | /** |
85 | * struct fwnode_operations - Operations for fwnode interface | |
86 | * @get: Get a reference to an fwnode. | |
87 | * @put: Put a reference to an fwnode. | |
8ed61d36 | 88 | * @device_is_available: Return true if the device is available. |
b283f157 | 89 | * @device_get_match_data: Return the device driver match data. |
3708184a | 90 | * @property_present: Return true if a property is present. |
8ed61d36 HK |
91 | * @property_read_int_array: Read an array of integer properties. Return zero on |
92 | * success, a negative error code otherwise. | |
3708184a SA |
93 | * @property_read_string_array: Read an array of string properties. Return zero |
94 | * on success, a negative error code otherwise. | |
bc0500c1 | 95 | * @get_name: Return the name of an fwnode. |
e7e242bc | 96 | * @get_name_prefix: Get a prefix for a node (for printing purposes). |
3708184a SA |
97 | * @get_parent: Return the parent of an fwnode. |
98 | * @get_next_child_node: Return the next child node in an iteration. | |
99 | * @get_named_child_node: Return a child node with a given name. | |
3e3119d3 | 100 | * @get_reference_args: Return a reference pointed to by a property, with args |
3b27d00e SA |
101 | * @graph_get_next_endpoint: Return an endpoint node in an iteration. |
102 | * @graph_get_remote_endpoint: Return the remote endpoint node of a local | |
103 | * endpoint node. | |
104 | * @graph_get_port_parent: Return the parent node of a port node. | |
105 | * @graph_parse_endpoint: Parse endpoint for port and endpoint id. | |
04f63c21 SK |
106 | * @add_links: Create fwnode links to all the suppliers of the fwnode. Return |
107 | * zero on success, a negative error code otherwise. | |
3708184a SA |
108 | */ |
109 | struct fwnode_operations { | |
cf89a31c | 110 | struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); |
3708184a | 111 | void (*put)(struct fwnode_handle *fwnode); |
37ba983c | 112 | bool (*device_is_available)(const struct fwnode_handle *fwnode); |
67dcc26d AS |
113 | const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, |
114 | const struct device *dev); | |
37ba983c | 115 | bool (*property_present)(const struct fwnode_handle *fwnode, |
3708184a | 116 | const char *propname); |
37ba983c | 117 | int (*property_read_int_array)(const struct fwnode_handle *fwnode, |
3708184a SA |
118 | const char *propname, |
119 | unsigned int elem_size, void *val, | |
120 | size_t nval); | |
37ba983c SA |
121 | int |
122 | (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, | |
123 | const char *propname, const char **val, | |
124 | size_t nval); | |
bc0500c1 | 125 | const char *(*get_name)(const struct fwnode_handle *fwnode); |
e7e242bc | 126 | const char *(*get_name_prefix)(const struct fwnode_handle *fwnode); |
37ba983c | 127 | struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); |
3708184a | 128 | struct fwnode_handle * |
37ba983c | 129 | (*get_next_child_node)(const struct fwnode_handle *fwnode, |
3708184a SA |
130 | struct fwnode_handle *child); |
131 | struct fwnode_handle * | |
37ba983c SA |
132 | (*get_named_child_node)(const struct fwnode_handle *fwnode, |
133 | const char *name); | |
3e3119d3 SA |
134 | int (*get_reference_args)(const struct fwnode_handle *fwnode, |
135 | const char *prop, const char *nargs_prop, | |
136 | unsigned int nargs, unsigned int index, | |
137 | struct fwnode_reference_args *args); | |
3b27d00e | 138 | struct fwnode_handle * |
37ba983c | 139 | (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, |
3b27d00e SA |
140 | struct fwnode_handle *prev); |
141 | struct fwnode_handle * | |
37ba983c | 142 | (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); |
3b27d00e SA |
143 | struct fwnode_handle * |
144 | (*graph_get_port_parent)(struct fwnode_handle *fwnode); | |
37ba983c | 145 | int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, |
3b27d00e | 146 | struct fwnode_endpoint *endpoint); |
2d09e6eb | 147 | int (*add_links)(struct fwnode_handle *fwnode); |
3708184a SA |
148 | }; |
149 | ||
150 | #define fwnode_has_op(fwnode, op) \ | |
151 | ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) | |
152 | #define fwnode_call_int_op(fwnode, op, ...) \ | |
153 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ | |
154 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ | |
155 | -EINVAL) | |
149f3b87 AS |
156 | |
157 | #define fwnode_call_bool_op(fwnode, op, ...) \ | |
158 | (fwnode_has_op(fwnode, op) ? \ | |
159 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) | |
160 | ||
3708184a SA |
161 | #define fwnode_call_ptr_op(fwnode, op, ...) \ |
162 | (fwnode_has_op(fwnode, op) ? \ | |
163 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) | |
164 | #define fwnode_call_void_op(fwnode, op, ...) \ | |
165 | do { \ | |
166 | if (fwnode_has_op(fwnode, op)) \ | |
167 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ | |
168 | } while (false) | |
372a67c0 | 169 | #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) |
3708184a | 170 | |
01bb86b3 SK |
171 | static inline void fwnode_init(struct fwnode_handle *fwnode, |
172 | const struct fwnode_operations *ops) | |
173 | { | |
174 | fwnode->ops = ops; | |
7b337cb3 SK |
175 | INIT_LIST_HEAD(&fwnode->consumers); |
176 | INIT_LIST_HEAD(&fwnode->suppliers); | |
01bb86b3 SK |
177 | } |
178 | ||
74c782cf SK |
179 | static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode, |
180 | bool initialized) | |
181 | { | |
182 | if (IS_ERR_OR_NULL(fwnode)) | |
183 | return; | |
184 | ||
185 | if (initialized) | |
186 | fwnode->flags |= FWNODE_FLAG_INITIALIZED; | |
187 | else | |
188 | fwnode->flags &= ~FWNODE_FLAG_INITIALIZED; | |
189 | } | |
190 | ||
8375e74f | 191 | extern u32 fw_devlink_get_flags(void); |
19d0f5f6 | 192 | extern bool fw_devlink_is_strict(void); |
7b337cb3 SK |
193 | int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup); |
194 | void fwnode_links_purge(struct fwnode_handle *fwnode); | |
28ec344b | 195 | void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode); |
8375e74f | 196 | |
ce793486 | 197 | #endif |