hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/media/v4l2-async.h
....@@ -1,11 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * V4L2 asynchronous subdevice registration API
34 *
45 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107
118 #ifndef V4L2_ASYNC_H
....@@ -19,9 +16,6 @@
1916 struct v4l2_device;
2017 struct v4l2_subdev;
2118 struct v4l2_async_notifier;
22
-
23
-/* A random max subdevice number, used to allocate an array on stack */
24
-#define V4L2_MAX_SUBDEVS 128U
2519
2620 /**
2721 * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used
....@@ -73,6 +67,8 @@
7367 * @match.custom.priv:
7468 * Driver-specific private struct with match parameters
7569 * to be used if %V4L2_ASYNC_MATCH_CUSTOM.
70
+ * @asd_list: used to add struct v4l2_async_subdev objects to the
71
+ * master notifier @asd_list
7672 * @list: used to link struct v4l2_async_subdev objects, waiting to be
7773 * probed, to a notifier->waiting list
7874 *
....@@ -90,14 +86,15 @@
9086 unsigned short address;
9187 } i2c;
9288 struct {
93
- bool (*match)(struct device *,
94
- struct v4l2_async_subdev *);
89
+ bool (*match)(struct device *dev,
90
+ struct v4l2_async_subdev *sd);
9591 void *priv;
9692 } custom;
9793 } match;
9894
9995 /* v4l2-async core private: not to be used by drivers */
10096 struct list_head list;
97
+ struct list_head asd_list;
10198 };
10299
103100 /**
....@@ -121,28 +118,134 @@
121118 * struct v4l2_async_notifier - v4l2_device notifier data
122119 *
123120 * @ops: notifier operations
124
- * @num_subdevs: number of subdevices used in the subdevs array
125
- * @max_subdevs: number of subdevices allocated in the subdevs array
126
- * @subdevs: array of pointers to subdevice descriptors
127121 * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
128122 * @sd: sub-device that registered the notifier, NULL otherwise
129123 * @parent: parent notifier
124
+ * @asd_list: master list of struct v4l2_async_subdev
130125 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
131126 * @done: list of struct v4l2_subdev, already probed
132127 * @list: member in a global list of notifiers
133128 */
134129 struct v4l2_async_notifier {
135130 const struct v4l2_async_notifier_operations *ops;
136
- unsigned int num_subdevs;
137
- unsigned int max_subdevs;
138
- struct v4l2_async_subdev **subdevs;
139131 struct v4l2_device *v4l2_dev;
140132 struct v4l2_subdev *sd;
141133 struct v4l2_async_notifier *parent;
134
+ struct list_head asd_list;
142135 struct list_head waiting;
143136 struct list_head done;
144137 struct list_head list;
145138 };
139
+
140
+/**
141
+ * v4l2_async_notifier_init - Initialize a notifier.
142
+ *
143
+ * @notifier: pointer to &struct v4l2_async_notifier
144
+ *
145
+ * This function initializes the notifier @asd_list. It must be called
146
+ * before the first call to @v4l2_async_notifier_add_subdev.
147
+ */
148
+void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier);
149
+
150
+/**
151
+ * v4l2_async_notifier_add_subdev - Add an async subdev to the
152
+ * notifier's master asd list.
153
+ *
154
+ * @notifier: pointer to &struct v4l2_async_notifier
155
+ * @asd: pointer to &struct v4l2_async_subdev
156
+ *
157
+ * Call this function before registering a notifier to link the provided @asd to
158
+ * the notifiers master @asd_list. The @asd must be allocated with k*alloc() as
159
+ * it will be freed by the framework when the notifier is destroyed.
160
+ */
161
+int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
162
+ struct v4l2_async_subdev *asd);
163
+
164
+/**
165
+ * v4l2_async_notifier_add_fwnode_subdev - Allocate and add a fwnode async
166
+ * subdev to the notifier's master asd_list.
167
+ *
168
+ * @notifier: pointer to &struct v4l2_async_notifier
169
+ * @fwnode: fwnode handle of the sub-device to be matched
170
+ * @asd_struct_size: size of the driver's async sub-device struct, including
171
+ * sizeof(struct v4l2_async_subdev). The &struct
172
+ * v4l2_async_subdev shall be the first member of
173
+ * the driver's async sub-device struct, i.e. both
174
+ * begin at the same memory address.
175
+ *
176
+ * Allocate a fwnode-matched asd of size asd_struct_size, and add it to the
177
+ * notifiers @asd_list. The function also gets a reference of the fwnode which
178
+ * is released later at notifier cleanup time.
179
+ */
180
+struct v4l2_async_subdev *
181
+v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
182
+ struct fwnode_handle *fwnode,
183
+ unsigned int asd_struct_size);
184
+
185
+/**
186
+ * v4l2_async_notifier_add_fwnode_remote_subdev - Allocate and add a fwnode
187
+ * remote async subdev to the
188
+ * notifier's master asd_list.
189
+ *
190
+ * @notif: pointer to &struct v4l2_async_notifier
191
+ * @endpoint: local endpoint pointing to the remote sub-device to be matched
192
+ * @asd_struct_size: size of the driver's async sub-device struct, including
193
+ * sizeof(struct v4l2_async_subdev). The &struct
194
+ * v4l2_async_subdev shall be the first member of
195
+ * the driver's async sub-device struct, i.e. both
196
+ * begin at the same memory address.
197
+ *
198
+ * Gets the remote endpoint of a given local endpoint, set it up for fwnode
199
+ * matching and adds the async sub-device to the notifier's @asd_list. The
200
+ * function also gets a reference of the fwnode which is released later at
201
+ * notifier cleanup time.
202
+ *
203
+ * This is just like @v4l2_async_notifier_add_fwnode_subdev, but with the
204
+ * exception that the fwnode refers to a local endpoint, not the remote one.
205
+ */
206
+struct v4l2_async_subdev *
207
+v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif,
208
+ struct fwnode_handle *endpoint,
209
+ unsigned int asd_struct_size);
210
+
211
+/**
212
+ * v4l2_async_notifier_add_i2c_subdev - Allocate and add an i2c async
213
+ * subdev to the notifier's master asd_list.
214
+ *
215
+ * @notifier: pointer to &struct v4l2_async_notifier
216
+ * @adapter_id: I2C adapter ID to be matched
217
+ * @address: I2C address of sub-device to be matched
218
+ * @asd_struct_size: size of the driver's async sub-device struct, including
219
+ * sizeof(struct v4l2_async_subdev). The &struct
220
+ * v4l2_async_subdev shall be the first member of
221
+ * the driver's async sub-device struct, i.e. both
222
+ * begin at the same memory address.
223
+ *
224
+ * Same as above but for I2C matched sub-devices.
225
+ */
226
+struct v4l2_async_subdev *
227
+v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier,
228
+ int adapter_id, unsigned short address,
229
+ unsigned int asd_struct_size);
230
+
231
+/**
232
+ * v4l2_async_notifier_add_devname_subdev - Allocate and add a device-name
233
+ * async subdev to the notifier's master asd_list.
234
+ *
235
+ * @notifier: pointer to &struct v4l2_async_notifier
236
+ * @device_name: device name string to be matched
237
+ * @asd_struct_size: size of the driver's async sub-device struct, including
238
+ * sizeof(struct v4l2_async_subdev). The &struct
239
+ * v4l2_async_subdev shall be the first member of
240
+ * the driver's async sub-device struct, i.e. both
241
+ * begin at the same memory address.
242
+ *
243
+ * Same as above but for device-name matched sub-devices.
244
+ */
245
+struct v4l2_async_subdev *
246
+v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier,
247
+ const char *device_name,
248
+ unsigned int asd_struct_size);
146249
147250 /**
148251 * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
....@@ -168,11 +271,19 @@
168271 *
169272 * @notifier: pointer to &struct v4l2_async_notifier
170273 */
171
-
274
+#if IS_ENABLED(CONFIG_NO_GKI)
172275 int v4l2_async_notifier_clr_unready_dev(struct v4l2_async_notifier *notifier);
276
+#else
277
+static inline int
278
+v4l2_async_notifier_clr_unready_dev(struct v4l2_async_notifier *notifier)
279
+{
280
+ return 0;
281
+}
282
+#endif
173283
174284 /**
175
- * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
285
+ * v4l2_async_notifier_unregister - unregisters a subdevice
286
+ * asynchronous notifier
176287 *
177288 * @notifier: pointer to &struct v4l2_async_notifier
178289 */
....@@ -185,7 +296,9 @@
185296 * Release memory resources related to a notifier, including the async
186297 * sub-devices allocated for the purposes of the notifier but not the notifier
187298 * itself. The user is responsible for calling this function to clean up the
188
- * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or
299
+ * notifier after calling
300
+ * @v4l2_async_notifier_add_subdev,
301
+ * @v4l2_async_notifier_parse_fwnode_endpoints or
189302 * @v4l2_fwnode_reference_parse_sensor_common.
190303 *
191304 * There is no harm from calling v4l2_async_notifier_cleanup in other
....@@ -221,8 +334,8 @@
221334 * An error is returned if the module is no longer loaded on any attempts
222335 * to register it.
223336 */
224
-int __must_check v4l2_async_register_subdev_sensor_common(
225
- struct v4l2_subdev *sd);
337
+int __must_check
338
+v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd);
226339
227340 /**
228341 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous