1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * V4L2 asynchronous subdevice registration API
5 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
11 #include <linux/list.h>
12 #include <linux/mutex.h>
19 struct v4l2_async_notifier;
22 * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used
23 * in order to identify a match
25 * @V4L2_ASYNC_MATCH_TYPE_I2C: Match will check for I2C adapter ID and address
26 * @V4L2_ASYNC_MATCH_TYPE_FWNODE: Match will use firmware node
28 * This enum is used by the asynchronous connection logic to define the
29 * algorithm that will be used to match an asynchronous device.
31 enum v4l2_async_match_type {
32 V4L2_ASYNC_MATCH_TYPE_I2C,
33 V4L2_ASYNC_MATCH_TYPE_FWNODE,
37 * struct v4l2_async_match_desc - async connection match information
39 * @type: type of match that will be used
40 * @fwnode: pointer to &struct fwnode_handle to be matched.
41 * Used if @match_type is %V4L2_ASYNC_MATCH_TYPE_FWNODE.
42 * @i2c: embedded struct with I2C parameters to be matched.
43 * Both @match.i2c.adapter_id and @match.i2c.address
45 * Used if @match_type is %V4L2_ASYNC_MATCH_TYPE_I2C.
47 * I2C adapter ID to be matched.
48 * Used if @match_type is %V4L2_ASYNC_MATCH_TYPE_I2C.
50 * I2C address to be matched.
51 * Used if @match_type is %V4L2_ASYNC_MATCH_TYPE_I2C.
53 struct v4l2_async_match_desc {
54 enum v4l2_async_match_type type;
56 struct fwnode_handle *fwnode;
59 unsigned short address;
65 * struct v4l2_async_connection - sub-device connection descriptor, as known to
68 * @match: struct of match type and per-bus type matching data sets
69 * @notifier: the async notifier the connection is related to
70 * @asc_entry: used to add struct v4l2_async_connection objects to the
71 * notifier @waiting_list or @done_list
72 * @asc_subdev_entry: entry in struct v4l2_async_subdev.asc_list list
73 * @sd: the related sub-device
75 * When this struct is used as a member in a driver specific struct, the driver
76 * specific struct shall contain the &struct v4l2_async_connection as its first
79 struct v4l2_async_connection {
80 struct v4l2_async_match_desc match;
81 struct v4l2_async_notifier *notifier;
82 struct list_head asc_entry;
83 struct list_head asc_subdev_entry;
84 struct v4l2_subdev *sd;
88 * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
89 * @bound: a sub-device has been bound by the given connection
90 * @complete: All connections have been bound successfully. The complete
91 * callback is only executed for the root notifier.
92 * @unbind: a subdevice is leaving
93 * @destroy: the asc is about to be freed
95 struct v4l2_async_notifier_operations {
96 int (*bound)(struct v4l2_async_notifier *notifier,
97 struct v4l2_subdev *subdev,
98 struct v4l2_async_connection *asc);
99 int (*complete)(struct v4l2_async_notifier *notifier);
100 void (*unbind)(struct v4l2_async_notifier *notifier,
101 struct v4l2_subdev *subdev,
102 struct v4l2_async_connection *asc);
103 void (*destroy)(struct v4l2_async_connection *asc);
107 * struct v4l2_async_notifier - v4l2_device notifier data
109 * @ops: notifier operations
110 * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
111 * @sd: sub-device that registered the notifier, NULL otherwise
112 * @parent: parent notifier
113 * @waiting_list: list of struct v4l2_async_connection, waiting for their
115 * @done_list: list of struct v4l2_subdev, already probed
116 * @notifier_entry: member in a global list of notifiers
118 struct v4l2_async_notifier {
119 const struct v4l2_async_notifier_operations *ops;
120 struct v4l2_device *v4l2_dev;
121 struct v4l2_subdev *sd;
122 struct v4l2_async_notifier *parent;
123 struct list_head waiting_list;
124 struct list_head done_list;
125 struct list_head notifier_entry;
129 * struct v4l2_async_subdev_endpoint - Entry in sub-device's fwnode list
131 * @async_subdev_endpoint_entry: An entry in async_subdev_endpoint_list of
132 * &struct v4l2_subdev
133 * @endpoint: Endpoint fwnode agains which to match the sub-device
135 struct v4l2_async_subdev_endpoint {
136 struct list_head async_subdev_endpoint_entry;
137 struct fwnode_handle *endpoint;
141 * v4l2_async_debug_init - Initialize debugging tools.
143 * @debugfs_dir: pointer to the parent debugfs &struct dentry
145 void v4l2_async_debug_init(struct dentry *debugfs_dir);
148 * v4l2_async_nf_init - Initialize a notifier.
150 * @notifier: pointer to &struct v4l2_async_notifier
152 * This function initializes the notifier @asc_list. It must be called
153 * before adding a subdevice to a notifier, using one of:
154 * v4l2_async_nf_add_fwnode_remote(), v4l2_async_nf_add_fwnode() or
155 * v4l2_async_nf_add_i2c().
157 void v4l2_async_nf_init(struct v4l2_async_notifier *notifier);
159 struct v4l2_async_connection *
160 __v4l2_async_nf_add_fwnode(struct v4l2_async_notifier *notifier,
161 struct fwnode_handle *fwnode,
162 unsigned int asc_struct_size);
164 * v4l2_async_nf_add_fwnode - Allocate and add a fwnode async
165 * subdev to the notifier's master asc_list.
167 * @notifier: pointer to &struct v4l2_async_notifier
168 * @fwnode: fwnode handle of the sub-device to be matched, pointer to
169 * &struct fwnode_handle
170 * @type: Type of the driver's async sub-device or connection struct. The
171 * &struct v4l2_async_connection shall be the first member of the
172 * driver's async struct, i.e. both begin at the same memory address.
174 * Allocate a fwnode-matched asc of size asc_struct_size, and add it to the
175 * notifiers @asc_list. The function also gets a reference of the fwnode which
176 * is released later at notifier cleanup time.
178 #define v4l2_async_nf_add_fwnode(notifier, fwnode, type) \
179 ((type *)__v4l2_async_nf_add_fwnode(notifier, fwnode, sizeof(type)))
181 struct v4l2_async_connection *
182 __v4l2_async_nf_add_fwnode_remote(struct v4l2_async_notifier *notif,
183 struct fwnode_handle *endpoint,
184 unsigned int asc_struct_size);
186 * v4l2_async_nf_add_fwnode_remote - Allocate and add a fwnode
187 * remote async subdev to the
188 * notifier's master asc_list.
190 * @notifier: pointer to &struct v4l2_async_notifier
191 * @ep: local endpoint pointing to the remote connection to be matched,
192 * pointer to &struct fwnode_handle
193 * @type: Type of the driver's async connection struct. The &struct
194 * v4l2_async_connection shall be the first member of the driver's async
195 * connection struct, i.e. both begin at the same memory address.
197 * Gets the remote endpoint of a given local endpoint, set it up for fwnode
198 * matching and adds the async connection to the notifier's @asc_list. The
199 * function also gets a reference of the fwnode which is released later at
200 * notifier cleanup time.
202 * This is just like v4l2_async_nf_add_fwnode(), but with the
203 * exception that the fwnode refers to a local endpoint, not the remote one.
205 #define v4l2_async_nf_add_fwnode_remote(notifier, ep, type) \
206 ((type *)__v4l2_async_nf_add_fwnode_remote(notifier, ep, sizeof(type)))
208 struct v4l2_async_connection *
209 __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier,
210 int adapter_id, unsigned short address,
211 unsigned int asc_struct_size);
213 * v4l2_async_nf_add_i2c - Allocate and add an i2c async
214 * subdev to the notifier's master asc_list.
216 * @notifier: pointer to &struct v4l2_async_notifier
217 * @adapter: I2C adapter ID to be matched
218 * @address: I2C address of connection to be matched
219 * @type: Type of the driver's async connection struct. The &struct
220 * v4l2_async_connection shall be the first member of the driver's async
221 * connection struct, i.e. both begin at the same memory address.
223 * Same as v4l2_async_nf_add_fwnode() but for I2C matched
226 #define v4l2_async_nf_add_i2c(notifier, adapter, address, type) \
227 ((type *)__v4l2_async_nf_add_i2c(notifier, adapter, address, \
231 * v4l2_async_subdev_endpoint_add - Add an endpoint fwnode to async sub-device
234 * @sd: the sub-device
235 * @fwnode: the endpoint fwnode to match
237 * Add a fwnode to the async sub-device's matching list. This allows registering
238 * multiple async sub-devices from a single device.
240 * Note that calling v4l2_subdev_cleanup() as part of the sub-device's cleanup
241 * if endpoints have been added to the sub-device's fwnode matching list.
243 * Returns an error on failure, 0 on success.
245 int v4l2_async_subdev_endpoint_add(struct v4l2_subdev *sd,
246 struct fwnode_handle *fwnode);
249 * v4l2_async_connection_unique - return a unique &struct v4l2_async_connection
251 * @sd: the sub-device
253 * Return an async connection for a sub-device, when there is a single
256 struct v4l2_async_connection *
257 v4l2_async_connection_unique(struct v4l2_subdev *sd);
260 * v4l2_async_nf_register - registers a subdevice asynchronous notifier
262 * @v4l2_dev: pointer to &struct v4l2_device
263 * @notifier: pointer to &struct v4l2_async_notifier
265 int v4l2_async_nf_register(struct v4l2_device *v4l2_dev,
266 struct v4l2_async_notifier *notifier);
269 * v4l2_async_subdev_nf_register - registers a subdevice asynchronous
270 * notifier for a sub-device
272 * @sd: pointer to &struct v4l2_subdev
273 * @notifier: pointer to &struct v4l2_async_notifier
275 int v4l2_async_subdev_nf_register(struct v4l2_subdev *sd,
276 struct v4l2_async_notifier *notifier);
279 * v4l2_async_nf_unregister - unregisters a subdevice
280 * asynchronous notifier
282 * @notifier: pointer to &struct v4l2_async_notifier
284 void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier);
287 * v4l2_async_nf_cleanup - clean up notifier resources
288 * @notifier: the notifier the resources of which are to be cleaned up
290 * Release memory resources related to a notifier, including the async
291 * connections allocated for the purposes of the notifier but not the notifier
292 * itself. The user is responsible for calling this function to clean up the
293 * notifier after calling v4l2_async_nf_add_fwnode_remote(),
294 * v4l2_async_nf_add_fwnode() or v4l2_async_nf_add_i2c().
296 * There is no harm from calling v4l2_async_nf_cleanup() in other
297 * cases as long as its memory has been zeroed after it has been
300 void v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier);
303 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
304 * subdevice framework
306 * @sd: pointer to &struct v4l2_subdev
308 int v4l2_async_register_subdev(struct v4l2_subdev *sd);
311 * v4l2_async_register_subdev_sensor - registers a sensor sub-device to the
312 * asynchronous sub-device framework and
313 * parse set up common sensor related
316 * @sd: pointer to struct &v4l2_subdev
318 * This function is just like v4l2_async_register_subdev() with the exception
319 * that calling it will also parse firmware interfaces for remote references
320 * using v4l2_async_nf_parse_fwnode_sensor() and registers the
321 * async sub-devices. The sub-device is similarly unregistered by calling
322 * v4l2_async_unregister_subdev().
324 * While registered, the subdev module is marked as in-use.
326 * An error is returned if the module is no longer loaded on any attempts
330 v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
333 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
334 * subdevice framework
336 * @sd: pointer to &struct v4l2_subdev
338 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);