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 - connection descriptor, as known to a bridge
67 * @match: struct of match type and per-bus type matching data sets
68 * @asc_entry: used to add struct v4l2_async_connection objects to the
69 * notifier @waiting_list or @done_list
70 * @sd: the related sub-device
72 * When this struct is used as a member in a driver specific struct,
73 * the driver specific struct shall contain the &struct
74 * v4l2_async_connection as its first member.
76 struct v4l2_async_connection {
77 struct v4l2_async_match_desc match;
78 struct list_head asc_entry;
79 struct v4l2_subdev *sd;
83 * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
84 * @bound: a subdevice driver has successfully probed one of the subdevices
85 * @complete: All subdevices have been probed successfully. The complete
86 * callback is only executed for the root notifier.
87 * @unbind: a subdevice is leaving
88 * @destroy: the asc is about to be freed
90 struct v4l2_async_notifier_operations {
91 int (*bound)(struct v4l2_async_notifier *notifier,
92 struct v4l2_subdev *subdev,
93 struct v4l2_async_connection *asc);
94 int (*complete)(struct v4l2_async_notifier *notifier);
95 void (*unbind)(struct v4l2_async_notifier *notifier,
96 struct v4l2_subdev *subdev,
97 struct v4l2_async_connection *asc);
98 void (*destroy)(struct v4l2_async_connection *asc);
102 * struct v4l2_async_notifier - v4l2_device notifier data
104 * @ops: notifier operations
105 * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
106 * @sd: sub-device that registered the notifier, NULL otherwise
107 * @parent: parent notifier
108 * @waiting_list: list of struct v4l2_async_connection, waiting for their
110 * @done_list: list of struct v4l2_subdev, already probed
111 * @notifier_entry: member in a global list of notifiers
113 struct v4l2_async_notifier {
114 const struct v4l2_async_notifier_operations *ops;
115 struct v4l2_device *v4l2_dev;
116 struct v4l2_subdev *sd;
117 struct v4l2_async_notifier *parent;
118 struct list_head waiting_list;
119 struct list_head done_list;
120 struct list_head notifier_entry;
124 * v4l2_async_debug_init - Initialize debugging tools.
126 * @debugfs_dir: pointer to the parent debugfs &struct dentry
128 void v4l2_async_debug_init(struct dentry *debugfs_dir);
131 * v4l2_async_nf_init - Initialize a notifier.
133 * @notifier: pointer to &struct v4l2_async_notifier
135 * This function initializes the notifier @asc_list. It must be called
136 * before adding a subdevice to a notifier, using one of:
137 * v4l2_async_nf_add_fwnode_remote(), v4l2_async_nf_add_fwnode() or
138 * v4l2_async_nf_add_i2c().
140 void v4l2_async_nf_init(struct v4l2_async_notifier *notifier);
142 struct v4l2_async_connection *
143 __v4l2_async_nf_add_fwnode(struct v4l2_async_notifier *notifier,
144 struct fwnode_handle *fwnode,
145 unsigned int asc_struct_size);
147 * v4l2_async_nf_add_fwnode - Allocate and add a fwnode async
148 * subdev to the notifier's master asc_list.
150 * @notifier: pointer to &struct v4l2_async_notifier
151 * @fwnode: fwnode handle of the sub-device to be matched, pointer to
152 * &struct fwnode_handle
153 * @type: Type of the driver's async sub-device or connection struct. The
154 * &struct v4l2_async_connection shall be the first member of the
155 * driver's async struct, i.e. both begin at the same memory address.
157 * Allocate a fwnode-matched asc of size asc_struct_size, and add it to the
158 * notifiers @asc_list. The function also gets a reference of the fwnode which
159 * is released later at notifier cleanup time.
161 #define v4l2_async_nf_add_fwnode(notifier, fwnode, type) \
162 ((type *)__v4l2_async_nf_add_fwnode(notifier, fwnode, sizeof(type)))
164 struct v4l2_async_connection *
165 __v4l2_async_nf_add_fwnode_remote(struct v4l2_async_notifier *notif,
166 struct fwnode_handle *endpoint,
167 unsigned int asc_struct_size);
169 * v4l2_async_nf_add_fwnode_remote - Allocate and add a fwnode
170 * remote async subdev to the
171 * notifier's master asc_list.
173 * @notifier: pointer to &struct v4l2_async_notifier
174 * @ep: local endpoint pointing to the remote connection to be matched,
175 * pointer to &struct fwnode_handle
176 * @type: Type of the driver's async connection struct. The &struct
177 * v4l2_async_connection shall be the first member of the driver's async
178 * connection struct, i.e. both begin at the same memory address.
180 * Gets the remote endpoint of a given local endpoint, set it up for fwnode
181 * matching and adds the async connection to the notifier's @asc_list. The
182 * function also gets a reference of the fwnode which is released later at
183 * notifier cleanup time.
185 * This is just like v4l2_async_nf_add_fwnode(), but with the
186 * exception that the fwnode refers to a local endpoint, not the remote one.
188 #define v4l2_async_nf_add_fwnode_remote(notifier, ep, type) \
189 ((type *)__v4l2_async_nf_add_fwnode_remote(notifier, ep, sizeof(type)))
191 struct v4l2_async_connection *
192 __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier,
193 int adapter_id, unsigned short address,
194 unsigned int asc_struct_size);
196 * v4l2_async_nf_add_i2c - Allocate and add an i2c async
197 * subdev to the notifier's master asc_list.
199 * @notifier: pointer to &struct v4l2_async_notifier
200 * @adapter: I2C adapter ID to be matched
201 * @address: I2C address of connection to be matched
202 * @type: Type of the driver's async connection struct. The &struct
203 * v4l2_async_connection shall be the first member of the driver's async
204 * connection struct, i.e. both begin at the same memory address.
206 * Same as v4l2_async_nf_add_fwnode() but for I2C matched
209 #define v4l2_async_nf_add_i2c(notifier, adapter, address, type) \
210 ((type *)__v4l2_async_nf_add_i2c(notifier, adapter, address, \
214 * v4l2_async_nf_register - registers a subdevice asynchronous notifier
216 * @v4l2_dev: pointer to &struct v4l2_device
217 * @notifier: pointer to &struct v4l2_async_notifier
219 int v4l2_async_nf_register(struct v4l2_device *v4l2_dev,
220 struct v4l2_async_notifier *notifier);
223 * v4l2_async_subdev_nf_register - registers a subdevice asynchronous
224 * notifier for a sub-device
226 * @sd: pointer to &struct v4l2_subdev
227 * @notifier: pointer to &struct v4l2_async_notifier
229 int v4l2_async_subdev_nf_register(struct v4l2_subdev *sd,
230 struct v4l2_async_notifier *notifier);
233 * v4l2_async_nf_unregister - unregisters a subdevice
234 * asynchronous notifier
236 * @notifier: pointer to &struct v4l2_async_notifier
238 void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier);
241 * v4l2_async_nf_cleanup - clean up notifier resources
242 * @notifier: the notifier the resources of which are to be cleaned up
244 * Release memory resources related to a notifier, including the async
245 * connections allocated for the purposes of the notifier but not the notifier
246 * itself. The user is responsible for calling this function to clean up the
247 * notifier after calling v4l2_async_nf_add_fwnode_remote(),
248 * v4l2_async_nf_add_fwnode() or v4l2_async_nf_add_i2c().
250 * There is no harm from calling v4l2_async_nf_cleanup() in other
251 * cases as long as its memory has been zeroed after it has been
254 void v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier);
257 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
258 * subdevice framework
260 * @sd: pointer to &struct v4l2_subdev
262 int v4l2_async_register_subdev(struct v4l2_subdev *sd);
265 * v4l2_async_register_subdev_sensor - registers a sensor sub-device to the
266 * asynchronous sub-device framework and
267 * parse set up common sensor related
270 * @sd: pointer to struct &v4l2_subdev
272 * This function is just like v4l2_async_register_subdev() with the exception
273 * that calling it will also parse firmware interfaces for remote references
274 * using v4l2_async_nf_parse_fwnode_sensor() and registers the
275 * async sub-devices. The sub-device is similarly unregistered by calling
276 * v4l2_async_unregister_subdev().
278 * While registered, the subdev module is marked as in-use.
280 * An error is returned if the module is no longer loaded on any attempts
284 v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
287 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
288 * subdevice framework
290 * @sd: pointer to &struct v4l2_subdev
292 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);