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 sub-device 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 sub-device 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_subdev - sub-device descriptor, as known to a bridge
67 * @match: struct of match type and per-bus type matching data sets
68 * @asd_entry: used to add struct v4l2_async_subdev objects to the
69 * master notifier @asd_list
70 * @waiting_entry: used to link struct v4l2_async_subdev objects, waiting to be
71 * 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_subdev as its first member.
77 struct v4l2_async_subdev {
78 struct v4l2_async_match_desc match;
79 struct list_head asd_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 asd 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_subdev *asd);
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_subdev *asd);
99 void (*destroy)(struct v4l2_async_subdev *asd);
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 * @asd_list: master list of struct v4l2_async_subdev
110 * @waiting_list: list of struct v4l2_async_subdev, waiting for their drivers
111 * @done_list: list of struct v4l2_subdev, already probed
112 * @notifier_entry: member in a global list of notifiers
114 struct v4l2_async_notifier {
115 const struct v4l2_async_notifier_operations *ops;
116 struct v4l2_device *v4l2_dev;
117 struct v4l2_subdev *sd;
118 struct v4l2_async_notifier *parent;
119 struct list_head asd_list;
120 struct list_head waiting_list;
121 struct list_head done_list;
122 struct list_head notifier_entry;
126 * v4l2_async_debug_init - Initialize debugging tools.
128 * @debugfs_dir: pointer to the parent debugfs &struct dentry
130 void v4l2_async_debug_init(struct dentry *debugfs_dir);
133 * v4l2_async_nf_init - Initialize a notifier.
135 * @notifier: pointer to &struct v4l2_async_notifier
137 * This function initializes the notifier @asd_list. It must be called
138 * before adding a subdevice to a notifier, using one of:
139 * v4l2_async_nf_add_fwnode_remote(), v4l2_async_nf_add_fwnode() or
140 * v4l2_async_nf_add_i2c().
142 void v4l2_async_nf_init(struct v4l2_async_notifier *notifier);
144 struct v4l2_async_subdev *
145 __v4l2_async_nf_add_fwnode(struct v4l2_async_notifier *notifier,
146 struct fwnode_handle *fwnode,
147 unsigned int asd_struct_size);
149 * v4l2_async_nf_add_fwnode - Allocate and add a fwnode async
150 * subdev to the notifier's master asd_list.
152 * @notifier: pointer to &struct v4l2_async_notifier
153 * @fwnode: fwnode handle of the sub-device to be matched, pointer to
154 * &struct fwnode_handle
155 * @type: Type of the driver's async sub-device struct. The &struct
156 * v4l2_async_subdev shall be the first member of the driver's async
157 * sub-device struct, i.e. both begin at the same memory address.
159 * Allocate a fwnode-matched asd of size asd_struct_size, and add it to the
160 * notifiers @asd_list. The function also gets a reference of the fwnode which
161 * is released later at notifier cleanup time.
163 #define v4l2_async_nf_add_fwnode(notifier, fwnode, type) \
164 ((type *)__v4l2_async_nf_add_fwnode(notifier, fwnode, sizeof(type)))
166 struct v4l2_async_subdev *
167 __v4l2_async_nf_add_fwnode_remote(struct v4l2_async_notifier *notif,
168 struct fwnode_handle *endpoint,
169 unsigned int asd_struct_size);
171 * v4l2_async_nf_add_fwnode_remote - Allocate and add a fwnode
172 * remote async subdev to the
173 * notifier's master asd_list.
175 * @notifier: pointer to &struct v4l2_async_notifier
176 * @ep: local endpoint pointing to the remote sub-device to be matched,
177 * pointer to &struct fwnode_handle
178 * @type: Type of the driver's async sub-device struct. The &struct
179 * v4l2_async_subdev shall be the first member of the driver's async
180 * sub-device struct, i.e. both begin at the same memory address.
182 * Gets the remote endpoint of a given local endpoint, set it up for fwnode
183 * matching and adds the async sub-device to the notifier's @asd_list. The
184 * function also gets a reference of the fwnode which is released later at
185 * notifier cleanup time.
187 * This is just like v4l2_async_nf_add_fwnode(), but with the
188 * exception that the fwnode refers to a local endpoint, not the remote one.
190 #define v4l2_async_nf_add_fwnode_remote(notifier, ep, type) \
191 ((type *)__v4l2_async_nf_add_fwnode_remote(notifier, ep, sizeof(type)))
193 struct v4l2_async_subdev *
194 __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier,
195 int adapter_id, unsigned short address,
196 unsigned int asd_struct_size);
198 * v4l2_async_nf_add_i2c - Allocate and add an i2c async
199 * subdev to the notifier's master asd_list.
201 * @notifier: pointer to &struct v4l2_async_notifier
202 * @adapter: I2C adapter ID to be matched
203 * @address: I2C address of sub-device to be matched
204 * @type: Type of the driver's async sub-device struct. The &struct
205 * v4l2_async_subdev shall be the first member of the driver's async
206 * sub-device struct, i.e. both begin at the same memory address.
208 * Same as v4l2_async_nf_add_fwnode() but for I2C matched
211 #define v4l2_async_nf_add_i2c(notifier, adapter, address, type) \
212 ((type *)__v4l2_async_nf_add_i2c(notifier, adapter, address, \
216 * v4l2_async_nf_register - registers a subdevice asynchronous notifier
218 * @v4l2_dev: pointer to &struct v4l2_device
219 * @notifier: pointer to &struct v4l2_async_notifier
221 int v4l2_async_nf_register(struct v4l2_device *v4l2_dev,
222 struct v4l2_async_notifier *notifier);
225 * v4l2_async_subdev_nf_register - registers a subdevice asynchronous
226 * notifier for a sub-device
228 * @sd: pointer to &struct v4l2_subdev
229 * @notifier: pointer to &struct v4l2_async_notifier
231 int v4l2_async_subdev_nf_register(struct v4l2_subdev *sd,
232 struct v4l2_async_notifier *notifier);
235 * v4l2_async_nf_unregister - unregisters a subdevice
236 * asynchronous notifier
238 * @notifier: pointer to &struct v4l2_async_notifier
240 void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier);
243 * v4l2_async_nf_cleanup - clean up notifier resources
244 * @notifier: the notifier the resources of which are to be cleaned up
246 * Release memory resources related to a notifier, including the async
247 * sub-devices allocated for the purposes of the notifier but not the notifier
248 * itself. The user is responsible for calling this function to clean up the
249 * notifier after calling v4l2_async_nf_add_fwnode_remote(),
250 * v4l2_async_nf_add_fwnode() or v4l2_async_nf_add_i2c().
252 * There is no harm from calling v4l2_async_nf_cleanup() in other
253 * cases as long as its memory has been zeroed after it has been
256 void v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier);
259 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
260 * subdevice framework
262 * @sd: pointer to &struct v4l2_subdev
264 int v4l2_async_register_subdev(struct v4l2_subdev *sd);
267 * v4l2_async_register_subdev_sensor - registers a sensor sub-device to the
268 * asynchronous sub-device framework and
269 * parse set up common sensor related
272 * @sd: pointer to struct &v4l2_subdev
274 * This function is just like v4l2_async_register_subdev() with the exception
275 * that calling it will also parse firmware interfaces for remote references
276 * using v4l2_async_nf_parse_fwnode_sensor() and registers the
277 * async sub-devices. The sub-device is similarly unregistered by calling
278 * v4l2_async_unregister_subdev().
280 * While registered, the subdev module is marked as in-use.
282 * An error is returned if the module is no longer loaded on any attempts
286 v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
289 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
290 * subdevice framework
292 * @sd: pointer to &struct v4l2_subdev
294 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);