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