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 * master notifier @asc_list
70 * @waiting_entry: used to link struct v4l2_async_connection objects, waiting to
71 * be probed, to a notifier->waiting_list list
73 * When this struct is used as a member in a driver specific struct,
74 * the driver specific struct shall contain the &struct
75 * v4l2_async_connection as its first member.
77 struct v4l2_async_connection {
78 struct v4l2_async_match_desc match;
79 struct list_head asc_entry;
80 struct list_head waiting_entry;
84 * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
85 * @bound: a subdevice driver has successfully probed one of the subdevices
86 * @complete: All subdevices have been probed successfully. The complete
87 * callback is only executed for the root notifier.
88 * @unbind: a subdevice is leaving
89 * @destroy: the asc is about to be freed
91 struct v4l2_async_notifier_operations {
92 int (*bound)(struct v4l2_async_notifier *notifier,
93 struct v4l2_subdev *subdev,
94 struct v4l2_async_connection *asc);
95 int (*complete)(struct v4l2_async_notifier *notifier);
96 void (*unbind)(struct v4l2_async_notifier *notifier,
97 struct v4l2_subdev *subdev,
98 struct v4l2_async_connection *asc);
99 void (*destroy)(struct v4l2_async_connection *asc);
103 * struct v4l2_async_notifier - v4l2_device notifier data
105 * @ops: notifier operations
106 * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
107 * @sd: sub-device that registered the notifier, NULL otherwise
108 * @parent: parent notifier
109 * @asc_list: master list of struct v4l2_async_connection
110 * @waiting_list: list of struct v4l2_async_connection, waiting for their
112 * @done_list: list of struct v4l2_subdev, already probed
113 * @notifier_entry: member in a global list of notifiers
115 struct v4l2_async_notifier {
116 const struct v4l2_async_notifier_operations *ops;
117 struct v4l2_device *v4l2_dev;
118 struct v4l2_subdev *sd;
119 struct v4l2_async_notifier *parent;
120 struct list_head asc_list;
121 struct list_head waiting_list;
122 struct list_head done_list;
123 struct list_head notifier_entry;
127 * v4l2_async_debug_init - Initialize debugging tools.
129 * @debugfs_dir: pointer to the parent debugfs &struct dentry
131 void v4l2_async_debug_init(struct dentry *debugfs_dir);
134 * v4l2_async_nf_init - Initialize a notifier.
136 * @notifier: pointer to &struct v4l2_async_notifier
138 * This function initializes the notifier @asc_list. It must be called
139 * before adding a subdevice to a notifier, using one of:
140 * v4l2_async_nf_add_fwnode_remote(), v4l2_async_nf_add_fwnode() or
141 * v4l2_async_nf_add_i2c().
143 void v4l2_async_nf_init(struct v4l2_async_notifier *notifier);
145 struct v4l2_async_connection *
146 __v4l2_async_nf_add_fwnode(struct v4l2_async_notifier *notifier,
147 struct fwnode_handle *fwnode,
148 unsigned int asc_struct_size);
150 * v4l2_async_nf_add_fwnode - Allocate and add a fwnode async
151 * subdev to the notifier's master asc_list.
153 * @notifier: pointer to &struct v4l2_async_notifier
154 * @fwnode: fwnode handle of the sub-device to be matched, pointer to
155 * &struct fwnode_handle
156 * @type: Type of the driver's async sub-device or connection struct. The
157 * &struct v4l2_async_connection shall be the first member of the
158 * driver's async struct, i.e. both begin at the same memory address.
160 * Allocate a fwnode-matched asc of size asc_struct_size, and add it to the
161 * notifiers @asc_list. The function also gets a reference of the fwnode which
162 * is released later at notifier cleanup time.
164 #define v4l2_async_nf_add_fwnode(notifier, fwnode, type) \
165 ((type *)__v4l2_async_nf_add_fwnode(notifier, fwnode, sizeof(type)))
167 struct v4l2_async_connection *
168 __v4l2_async_nf_add_fwnode_remote(struct v4l2_async_notifier *notif,
169 struct fwnode_handle *endpoint,
170 unsigned int asc_struct_size);
172 * v4l2_async_nf_add_fwnode_remote - Allocate and add a fwnode
173 * remote async subdev to the
174 * notifier's master asc_list.
176 * @notifier: pointer to &struct v4l2_async_notifier
177 * @ep: local endpoint pointing to the remote connection to be matched,
178 * pointer to &struct fwnode_handle
179 * @type: Type of the driver's async connection struct. The &struct
180 * v4l2_async_connection shall be the first member of the driver's async
181 * connection struct, i.e. both begin at the same memory address.
183 * Gets the remote endpoint of a given local endpoint, set it up for fwnode
184 * matching and adds the async connection to the notifier's @asc_list. The
185 * function also gets a reference of the fwnode which is released later at
186 * notifier cleanup time.
188 * This is just like v4l2_async_nf_add_fwnode(), but with the
189 * exception that the fwnode refers to a local endpoint, not the remote one.
191 #define v4l2_async_nf_add_fwnode_remote(notifier, ep, type) \
192 ((type *)__v4l2_async_nf_add_fwnode_remote(notifier, ep, sizeof(type)))
194 struct v4l2_async_connection *
195 __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier,
196 int adapter_id, unsigned short address,
197 unsigned int asc_struct_size);
199 * v4l2_async_nf_add_i2c - Allocate and add an i2c async
200 * subdev to the notifier's master asc_list.
202 * @notifier: pointer to &struct v4l2_async_notifier
203 * @adapter: I2C adapter ID to be matched
204 * @address: I2C address of connection to be matched
205 * @type: Type of the driver's async connection struct. The &struct
206 * v4l2_async_connection shall be the first member of the driver's async
207 * connection struct, i.e. both begin at the same memory address.
209 * Same as v4l2_async_nf_add_fwnode() but for I2C matched
212 #define v4l2_async_nf_add_i2c(notifier, adapter, address, type) \
213 ((type *)__v4l2_async_nf_add_i2c(notifier, adapter, address, \
217 * v4l2_async_nf_register - registers a subdevice asynchronous notifier
219 * @v4l2_dev: pointer to &struct v4l2_device
220 * @notifier: pointer to &struct v4l2_async_notifier
222 int v4l2_async_nf_register(struct v4l2_device *v4l2_dev,
223 struct v4l2_async_notifier *notifier);
226 * v4l2_async_subdev_nf_register - registers a subdevice asynchronous
227 * notifier for a sub-device
229 * @sd: pointer to &struct v4l2_subdev
230 * @notifier: pointer to &struct v4l2_async_notifier
232 int v4l2_async_subdev_nf_register(struct v4l2_subdev *sd,
233 struct v4l2_async_notifier *notifier);
236 * v4l2_async_nf_unregister - unregisters a subdevice
237 * asynchronous notifier
239 * @notifier: pointer to &struct v4l2_async_notifier
241 void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier);
244 * v4l2_async_nf_cleanup - clean up notifier resources
245 * @notifier: the notifier the resources of which are to be cleaned up
247 * Release memory resources related to a notifier, including the async
248 * connections allocated for the purposes of the notifier but not the notifier
249 * itself. The user is responsible for calling this function to clean up the
250 * notifier after calling v4l2_async_nf_add_fwnode_remote(),
251 * v4l2_async_nf_add_fwnode() or v4l2_async_nf_add_i2c().
253 * There is no harm from calling v4l2_async_nf_cleanup() in other
254 * cases as long as its memory has been zeroed after it has been
257 void v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier);
260 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
261 * subdevice framework
263 * @sd: pointer to &struct v4l2_subdev
265 int v4l2_async_register_subdev(struct v4l2_subdev *sd);
268 * v4l2_async_register_subdev_sensor - registers a sensor sub-device to the
269 * asynchronous sub-device framework and
270 * parse set up common sensor related
273 * @sd: pointer to struct &v4l2_subdev
275 * This function is just like v4l2_async_register_subdev() with the exception
276 * that calling it will also parse firmware interfaces for remote references
277 * using v4l2_async_nf_parse_fwnode_sensor() and registers the
278 * async sub-devices. The sub-device is similarly unregistered by calling
279 * v4l2_async_unregister_subdev().
281 * While registered, the subdev module is marked as in-use.
283 * An error is returned if the module is no longer loaded on any attempts
287 v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
290 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
291 * subdevice framework
293 * @sd: pointer to &struct v4l2_subdev
295 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);