1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * V4L2 controls support header.
4 *
5 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
6 */
7
8 #ifndef _V4L2_CTRLS_H
9 #define _V4L2_CTRLS_H
10
11 #include <linux/list.h>
12 #include <linux/mutex.h>
13 #include <linux/videodev2.h>
14 #include <linux/android_kabi.h>
15 #include <media/media-request.h>
16
17 /*
18 * Include the stateless codec compound control definitions.
19 * This will move to the public headers once this API is fully stable.
20 */
21 #include <media/hevc-ctrls.h>
22
23 /* forward references */
24 struct file;
25 struct poll_table_struct;
26 struct v4l2_ctrl;
27 struct v4l2_ctrl_handler;
28 struct v4l2_ctrl_helper;
29 struct v4l2_fh;
30 struct v4l2_fwnode_device_properties;
31 struct v4l2_subdev;
32 struct v4l2_subscribed_event;
33 struct video_device;
34
35 /**
36 * union v4l2_ctrl_ptr - A pointer to a control value.
37 * @p_s32: Pointer to a 32-bit signed value.
38 * @p_s64: Pointer to a 64-bit signed value.
39 * @p_u8: Pointer to a 8-bit unsigned value.
40 * @p_u16: Pointer to a 16-bit unsigned value.
41 * @p_u32: Pointer to a 32-bit unsigned value.
42 * @p_char: Pointer to a string.
43 * @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure.
44 * @p_mpeg2_picture: Pointer to a MPEG2 picture structure.
45 * @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure.
46 * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
47 * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
48 * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
49 * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
50 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
51 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
52 * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
53 * @p_vp8_frame: Pointer to a VP8 frame params structure.
54 * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
55 * @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
56 * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
57 * @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure.
58 * @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure.
59 * @p_area: Pointer to an area.
60 * @p: Pointer to a compound value.
61 * @p_const: Pointer to a constant compound value.
62 */
63 union v4l2_ctrl_ptr {
64 s32 *p_s32;
65 s64 *p_s64;
66 u8 *p_u8;
67 u16 *p_u16;
68 u32 *p_u32;
69 char *p_char;
70 struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence;
71 struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture;
72 struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation;
73 struct v4l2_ctrl_fwht_params *p_fwht_params;
74 struct v4l2_ctrl_h264_sps *p_h264_sps;
75 struct v4l2_ctrl_h264_pps *p_h264_pps;
76 struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
77 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
78 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
79 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
80 struct v4l2_ctrl_vp8_frame *p_vp8_frame;
81 struct v4l2_ctrl_hevc_sps *p_hevc_sps;
82 struct v4l2_ctrl_hevc_pps *p_hevc_pps;
83 struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
84 struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
85 struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
86 struct v4l2_area *p_area;
87 void *p;
88 const void *p_const;
89
90 ANDROID_KABI_RESERVE(1);
91 ANDROID_KABI_RESERVE(2);
92 };
93
94 /**
95 * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
96 * void pointer
97 * @ptr: The void pointer
98 */
v4l2_ctrl_ptr_create(void * ptr)99 static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
100 {
101 union v4l2_ctrl_ptr p = { .p = ptr };
102
103 return p;
104 }
105
106 /**
107 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
108 *
109 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
110 * for volatile (and usually read-only) controls such as a control
111 * that returns the current signal strength which changes
112 * continuously.
113 * If not set, then the currently cached value will be returned.
114 * @try_ctrl: Test whether the control's value is valid. Only relevant when
115 * the usual min/max/step checks are not sufficient.
116 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
117 * ctrl->handler->lock is held when these ops are called, so no
118 * one else can access controls owned by that handler.
119 */
120 struct v4l2_ctrl_ops {
121 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
122 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
123 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
124
125 ANDROID_KABI_RESERVE(1);
126 };
127
128 /**
129 * struct v4l2_ctrl_type_ops - The control type operations that the driver
130 * has to provide.
131 *
132 * @equal: return true if both values are equal.
133 * @init: initialize the value.
134 * @log: log the value.
135 * @validate: validate the value. Return 0 on success and a negative value
136 * otherwise.
137 */
138 struct v4l2_ctrl_type_ops {
139 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
140 union v4l2_ctrl_ptr ptr1,
141 union v4l2_ctrl_ptr ptr2);
142 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
143 union v4l2_ctrl_ptr ptr);
144 void (*log)(const struct v4l2_ctrl *ctrl);
145 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
146 union v4l2_ctrl_ptr ptr);
147
148 ANDROID_KABI_RESERVE(1);
149 };
150
151 /**
152 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
153 * that should be called when a control value has changed.
154 *
155 * @ctrl: pointer to struct &v4l2_ctrl
156 * @priv: control private data
157 *
158 * This typedef definition is used as an argument to v4l2_ctrl_notify()
159 * and as an argument at struct &v4l2_ctrl_handler.
160 */
161 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
162
163 /**
164 * struct v4l2_ctrl - The control structure.
165 *
166 * @node: The list node.
167 * @ev_subs: The list of control event subscriptions.
168 * @handler: The handler that owns the control.
169 * @cluster: Point to start of cluster array.
170 * @ncontrols: Number of controls in cluster array.
171 * @done: Internal flag: set for each processed control.
172 * @is_new: Set when the user specified a new value for this control. It
173 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
174 * should never set this flag.
175 * @has_changed: Set when the current value differs from the new value. Drivers
176 * should never use this flag.
177 * @is_private: If set, then this control is private to its handler and it
178 * will not be added to any other handlers. Drivers can set
179 * this flag.
180 * @is_auto: If set, then this control selects whether the other cluster
181 * members are in 'automatic' mode or 'manual' mode. This is
182 * used for autogain/gain type clusters. Drivers should never
183 * set this flag directly.
184 * @is_int: If set, then this control has a simple integer value (i.e. it
185 * uses ctrl->val).
186 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
187 * @is_ptr: If set, then this control is an array and/or has type >=
188 * %V4L2_CTRL_COMPOUND_TYPES
189 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
190 * v4l2_ext_control uses field p to point to the data.
191 * @is_array: If set, then this control contains an N-dimensional array.
192 * @has_volatiles: If set, then one or more members of the cluster are volatile.
193 * Drivers should never touch this flag.
194 * @call_notify: If set, then call the handler's notify function whenever the
195 * control's value changes.
196 * @manual_mode_value: If the is_auto flag is set, then this is the value
197 * of the auto control that determines if that control is in
198 * manual mode. So if the value of the auto control equals this
199 * value, then the whole cluster is in manual mode. Drivers should
200 * never set this flag directly.
201 * @ops: The control ops.
202 * @type_ops: The control type ops.
203 * @id: The control ID.
204 * @name: The control name.
205 * @type: The control type.
206 * @minimum: The control's minimum value.
207 * @maximum: The control's maximum value.
208 * @default_value: The control's default value.
209 * @step: The control's step value for non-menu controls.
210 * @elems: The number of elements in the N-dimensional array.
211 * @elem_size: The size in bytes of the control.
212 * @dims: The size of each dimension.
213 * @nr_of_dims:The number of dimensions in @dims.
214 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
215 * easy to skip menu items that are not valid. If bit X is set,
216 * then menu item X is skipped. Of course, this only works for
217 * menus with <= 32 menu items. There are no menus that come
218 * close to that number, so this is OK. Should we ever need more,
219 * then this will have to be extended to a u64 or a bit array.
220 * @qmenu: A const char * array for all menu items. Array entries that are
221 * empty strings ("") correspond to non-existing menu items (this
222 * is in addition to the menu_skip_mask above). The last entry
223 * must be NULL.
224 * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
225 * @qmenu_int: A 64-bit integer array for with integer menu items.
226 * The size of array must be equal to the menu size, e. g.:
227 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
228 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
229 * @flags: The control's flags.
230 * @cur: Structure to store the current value.
231 * @cur.val: The control's current value, if the @type is represented via
232 * a u32 integer (see &enum v4l2_ctrl_type).
233 * @val: The control's new s32 value.
234 * @priv: The control's private pointer. For use by the driver. It is
235 * untouched by the control framework. Note that this pointer is
236 * not freed when the control is deleted. Should this be needed
237 * then a new internal bitfield can be added to tell the framework
238 * to free this pointer.
239 * @p_def: The control's default value represented via a union which
240 * provides a standard way of accessing control types
241 * through a pointer (for compound controls only).
242 * @p_cur: The control's current value represented via a union which
243 * provides a standard way of accessing control types
244 * through a pointer.
245 * @p_new: The control's new value represented via a union which provides
246 * a standard way of accessing control types
247 * through a pointer.
248 */
249 struct v4l2_ctrl {
250 /* Administrative fields */
251 struct list_head node;
252 struct list_head ev_subs;
253 struct v4l2_ctrl_handler *handler;
254 struct v4l2_ctrl **cluster;
255 unsigned int ncontrols;
256
257 unsigned int done:1;
258
259 unsigned int is_new:1;
260 unsigned int has_changed:1;
261 unsigned int is_private:1;
262 unsigned int is_auto:1;
263 unsigned int is_int:1;
264 unsigned int is_string:1;
265 unsigned int is_ptr:1;
266 unsigned int is_array:1;
267 unsigned int has_volatiles:1;
268 unsigned int call_notify:1;
269 unsigned int manual_mode_value:8;
270
271 const struct v4l2_ctrl_ops *ops;
272 const struct v4l2_ctrl_type_ops *type_ops;
273 u32 id;
274 const char *name;
275 enum v4l2_ctrl_type type;
276 s64 minimum, maximum, default_value;
277 u32 elems;
278 u32 elem_size;
279 u32 dims[V4L2_CTRL_MAX_DIMS];
280 u32 nr_of_dims;
281 union {
282 u64 step;
283 u64 menu_skip_mask;
284 };
285 union {
286 const char * const *qmenu;
287 const s64 *qmenu_int;
288 };
289 unsigned long flags;
290 void *priv;
291 s32 val;
292 struct {
293 s32 val;
294 } cur;
295
296 union v4l2_ctrl_ptr p_def;
297 union v4l2_ctrl_ptr p_new;
298 union v4l2_ctrl_ptr p_cur;
299
300 ANDROID_KABI_RESERVE(1);
301 };
302
303 /**
304 * struct v4l2_ctrl_ref - The control reference.
305 *
306 * @node: List node for the sorted list.
307 * @next: Single-link list node for the hash.
308 * @ctrl: The actual control information.
309 * @helper: Pointer to helper struct. Used internally in
310 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
311 * @from_other_dev: If true, then @ctrl was defined in another
312 * device than the &struct v4l2_ctrl_handler.
313 * @req_done: Internal flag: if the control handler containing this control
314 * reference is bound to a media request, then this is set when
315 * the control has been applied. This prevents applying controls
316 * from a cluster with multiple controls twice (when the first
317 * control of a cluster is applied, they all are).
318 * @valid_p_req: If set, then p_req contains the control value for the request.
319 * @p_req: If the control handler containing this control reference
320 * is bound to a media request, then this points to the
321 * value of the control that must be applied when the request
322 * is executed, or to the value of the control at the time
323 * that the request was completed. If @valid_p_req is false,
324 * then this control was never set for this request and the
325 * control will not be updated when this request is applied.
326 *
327 * Each control handler has a list of these refs. The list_head is used to
328 * keep a sorted-by-control-ID list of all controls, while the next pointer
329 * is used to link the control in the hash's bucket.
330 */
331 struct v4l2_ctrl_ref {
332 struct list_head node;
333 struct v4l2_ctrl_ref *next;
334 struct v4l2_ctrl *ctrl;
335 struct v4l2_ctrl_helper *helper;
336 bool from_other_dev;
337 bool req_done;
338 bool valid_p_req;
339 union v4l2_ctrl_ptr p_req;
340
341 ANDROID_KABI_RESERVE(1);
342 };
343
344 /**
345 * struct v4l2_ctrl_handler - The control handler keeps track of all the
346 * controls: both the controls owned by the handler and those inherited
347 * from other handlers.
348 *
349 * @_lock: Default for "lock".
350 * @lock: Lock to control access to this handler and its controls.
351 * May be replaced by the user right after init.
352 * @ctrls: The list of controls owned by this handler.
353 * @ctrl_refs: The list of control references.
354 * @cached: The last found control reference. It is common that the same
355 * control is needed multiple times, so this is a simple
356 * optimization.
357 * @buckets: Buckets for the hashing. Allows for quick control lookup.
358 * @notify: A notify callback that is called whenever the control changes
359 * value.
360 * Note that the handler's lock is held when the notify function
361 * is called!
362 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
363 * @nr_of_buckets: Total number of buckets in the array.
364 * @error: The error code of the first failed control addition.
365 * @request_is_queued: True if the request was queued.
366 * @requests: List to keep track of open control handler request objects.
367 * For the parent control handler (@req_obj.ops == NULL) this
368 * is the list header. When the parent control handler is
369 * removed, it has to unbind and put all these requests since
370 * they refer to the parent.
371 * @requests_queued: List of the queued requests. This determines the order
372 * in which these controls are applied. Once the request is
373 * completed it is removed from this list.
374 * @req_obj: The &struct media_request_object, used to link into a
375 * &struct media_request. This request object has a refcount.
376 */
377 struct v4l2_ctrl_handler {
378 struct mutex _lock;
379 struct mutex *lock;
380 struct list_head ctrls;
381 struct list_head ctrl_refs;
382 struct v4l2_ctrl_ref *cached;
383 struct v4l2_ctrl_ref **buckets;
384 v4l2_ctrl_notify_fnc notify;
385 void *notify_priv;
386 u16 nr_of_buckets;
387 int error;
388 bool request_is_queued;
389 struct list_head requests;
390 struct list_head requests_queued;
391 struct media_request_object req_obj;
392
393 ANDROID_KABI_RESERVE(1);
394 };
395
396 /**
397 * struct v4l2_ctrl_config - Control configuration structure.
398 *
399 * @ops: The control ops.
400 * @type_ops: The control type ops. Only needed for compound controls.
401 * @id: The control ID.
402 * @name: The control name.
403 * @type: The control type.
404 * @min: The control's minimum value.
405 * @max: The control's maximum value.
406 * @step: The control's step value for non-menu controls.
407 * @def: The control's default value.
408 * @p_def: The control's default value for compound controls.
409 * @dims: The size of each dimension.
410 * @elem_size: The size in bytes of the control.
411 * @flags: The control's flags.
412 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
413 * easy to skip menu items that are not valid. If bit X is set,
414 * then menu item X is skipped. Of course, this only works for
415 * menus with <= 64 menu items. There are no menus that come
416 * close to that number, so this is OK. Should we ever need more,
417 * then this will have to be extended to a bit array.
418 * @qmenu: A const char * array for all menu items. Array entries that are
419 * empty strings ("") correspond to non-existing menu items (this
420 * is in addition to the menu_skip_mask above). The last entry
421 * must be NULL.
422 * @qmenu_int: A const s64 integer array for all menu items of the type
423 * V4L2_CTRL_TYPE_INTEGER_MENU.
424 * @is_private: If set, then this control is private to its handler and it
425 * will not be added to any other handlers.
426 */
427 struct v4l2_ctrl_config {
428 const struct v4l2_ctrl_ops *ops;
429 const struct v4l2_ctrl_type_ops *type_ops;
430 u32 id;
431 const char *name;
432 enum v4l2_ctrl_type type;
433 s64 min;
434 s64 max;
435 u64 step;
436 s64 def;
437 union v4l2_ctrl_ptr p_def;
438 u32 dims[V4L2_CTRL_MAX_DIMS];
439 u32 elem_size;
440 u32 flags;
441 u64 menu_skip_mask;
442 const char * const *qmenu;
443 const s64 *qmenu_int;
444 unsigned int is_private:1;
445
446 ANDROID_KABI_RESERVE(1);
447 };
448
449 /**
450 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
451 *
452 * @id: ID of the control
453 * @name: pointer to be filled with a string with the name of the control
454 * @type: pointer for storing the type of the control
455 * @min: pointer for storing the minimum value for the control
456 * @max: pointer for storing the maximum value for the control
457 * @step: pointer for storing the control step
458 * @def: pointer for storing the default value for the control
459 * @flags: pointer for storing the flags to be used on the control
460 *
461 * This works for all standard V4L2 controls.
462 * For non-standard controls it will only fill in the given arguments
463 * and @name content will be set to %NULL.
464 *
465 * This function will overwrite the contents of @name, @type and @flags.
466 * The contents of @min, @max, @step and @def may be modified depending on
467 * the type.
468 *
469 * .. note::
470 *
471 * Do not use in drivers! It is used internally for backwards compatibility
472 * control handling only. Once all drivers are converted to use the new
473 * control framework this function will no longer be exported.
474 */
475 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
476 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
477
478
479 /**
480 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
481 * @hdl: The control handler.
482 * @nr_of_controls_hint: A hint of how many controls this handler is
483 * expected to refer to. This is the total number, so including
484 * any inherited controls. It doesn't have to be precise, but if
485 * it is way off, then you either waste memory (too many buckets
486 * are allocated) or the control lookup becomes slower (not enough
487 * buckets are allocated, so there are more slow list lookups).
488 * It will always work, though.
489 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
490 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
491 *
492 * .. attention::
493 *
494 * Never use this call directly, always use the v4l2_ctrl_handler_init()
495 * macro that hides the @key and @name arguments.
496 *
497 * Return: returns an error if the buckets could not be allocated. This
498 * error will also be stored in @hdl->error.
499 */
500 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
501 unsigned int nr_of_controls_hint,
502 struct lock_class_key *key, const char *name);
503
504 #ifdef CONFIG_LOCKDEP
505
506 /**
507 * v4l2_ctrl_handler_init - helper function to create a static struct
508 * &lock_class_key and calls v4l2_ctrl_handler_init_class()
509 *
510 * @hdl: The control handler.
511 * @nr_of_controls_hint: A hint of how many controls this handler is
512 * expected to refer to. This is the total number, so including
513 * any inherited controls. It doesn't have to be precise, but if
514 * it is way off, then you either waste memory (too many buckets
515 * are allocated) or the control lookup becomes slower (not enough
516 * buckets are allocated, so there are more slow list lookups).
517 * It will always work, though.
518 *
519 * This helper function creates a static struct &lock_class_key and
520 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
521 * validador.
522 *
523 * Use this helper function to initialize a control handler.
524 */
525 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
526 ( \
527 ({ \
528 static struct lock_class_key _key; \
529 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
530 &_key, \
531 KBUILD_BASENAME ":" \
532 __stringify(__LINE__) ":" \
533 "(" #hdl ")->_lock"); \
534 }) \
535 )
536 #else
537 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
538 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
539 #endif
540
541 /**
542 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
543 * the control list.
544 * @hdl: The control handler.
545 *
546 * Does nothing if @hdl == NULL.
547 */
548 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
549
550 /**
551 * v4l2_ctrl_lock() - Helper function to lock the handler
552 * associated with the control.
553 * @ctrl: The control to lock.
554 */
v4l2_ctrl_lock(struct v4l2_ctrl * ctrl)555 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
556 {
557 mutex_lock(ctrl->handler->lock);
558 }
559
560 /**
561 * v4l2_ctrl_unlock() - Helper function to unlock the handler
562 * associated with the control.
563 * @ctrl: The control to unlock.
564 */
v4l2_ctrl_unlock(struct v4l2_ctrl * ctrl)565 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
566 {
567 mutex_unlock(ctrl->handler->lock);
568 }
569
570 /**
571 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
572 * to the handler to initialize the hardware to the current control values. The
573 * caller is responsible for acquiring the control handler mutex on behalf of
574 * __v4l2_ctrl_handler_setup().
575 * @hdl: The control handler.
576 *
577 * Button controls will be skipped, as are read-only controls.
578 *
579 * If @hdl == NULL, then this just returns 0.
580 */
581 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
582
583 /**
584 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
585 * to the handler to initialize the hardware to the current control values.
586 * @hdl: The control handler.
587 *
588 * Button controls will be skipped, as are read-only controls.
589 *
590 * If @hdl == NULL, then this just returns 0.
591 */
592 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
593
594 /**
595 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
596 * @hdl: The control handler.
597 * @prefix: The prefix to use when logging the control values. If the
598 * prefix does not end with a space, then ": " will be added
599 * after the prefix. If @prefix == NULL, then no prefix will be
600 * used.
601 *
602 * For use with VIDIOC_LOG_STATUS.
603 *
604 * Does nothing if @hdl == NULL.
605 */
606 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
607 const char *prefix);
608
609 /**
610 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
611 * control.
612 *
613 * @hdl: The control handler.
614 * @cfg: The control's configuration data.
615 * @priv: The control's driver-specific private data.
616 *
617 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
618 * and @hdl->error is set to the error code (if it wasn't set already).
619 */
620 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
621 const struct v4l2_ctrl_config *cfg,
622 void *priv);
623
624 /**
625 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
626 * control.
627 *
628 * @hdl: The control handler.
629 * @ops: The control ops.
630 * @id: The control ID.
631 * @min: The control's minimum value.
632 * @max: The control's maximum value.
633 * @step: The control's step value
634 * @def: The control's default value.
635 *
636 * If the &v4l2_ctrl struct could not be allocated, or the control
637 * ID is not known, then NULL is returned and @hdl->error is set to the
638 * appropriate error code (if it wasn't set already).
639 *
640 * If @id refers to a menu control, then this function will return NULL.
641 *
642 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
643 */
644 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
645 const struct v4l2_ctrl_ops *ops,
646 u32 id, s64 min, s64 max, u64 step,
647 s64 def);
648
649 /**
650 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
651 * menu control.
652 *
653 * @hdl: The control handler.
654 * @ops: The control ops.
655 * @id: The control ID.
656 * @max: The control's maximum value.
657 * @mask: The control's skip mask for menu controls. This makes it
658 * easy to skip menu items that are not valid. If bit X is set,
659 * then menu item X is skipped. Of course, this only works for
660 * menus with <= 64 menu items. There are no menus that come
661 * close to that number, so this is OK. Should we ever need more,
662 * then this will have to be extended to a bit array.
663 * @def: The control's default value.
664 *
665 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
666 * determines which menu items are to be skipped.
667 *
668 * If @id refers to a non-menu control, then this function will return NULL.
669 */
670 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
671 const struct v4l2_ctrl_ops *ops,
672 u32 id, u8 max, u64 mask, u8 def);
673
674 /**
675 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
676 * with driver specific menu.
677 *
678 * @hdl: The control handler.
679 * @ops: The control ops.
680 * @id: The control ID.
681 * @max: The control's maximum value.
682 * @mask: The control's skip mask for menu controls. This makes it
683 * easy to skip menu items that are not valid. If bit X is set,
684 * then menu item X is skipped. Of course, this only works for
685 * menus with <= 64 menu items. There are no menus that come
686 * close to that number, so this is OK. Should we ever need more,
687 * then this will have to be extended to a bit array.
688 * @def: The control's default value.
689 * @qmenu: The new menu.
690 *
691 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
692 * menu of this control.
693 *
694 */
695 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
696 const struct v4l2_ctrl_ops *ops,
697 u32 id, u8 max,
698 u64 mask, u8 def,
699 const char * const *qmenu);
700
701 /**
702 * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
703 * compound control.
704 *
705 * @hdl: The control handler.
706 * @ops: The control ops.
707 * @id: The control ID.
708 * @p_def: The control's default value.
709 *
710 * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
711 * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
712 * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
713 * compound control should be all zeroes.
714 *
715 */
716 struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
717 const struct v4l2_ctrl_ops *ops,
718 u32 id,
719 const union v4l2_ctrl_ptr p_def);
720
721 /**
722 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
723 *
724 * @hdl: The control handler.
725 * @ops: The control ops.
726 * @id: The control ID.
727 * @max: The control's maximum value.
728 * @def: The control's default value.
729 * @qmenu_int: The control's menu entries.
730 *
731 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
732 * takes as an argument an array of integers determining the menu items.
733 *
734 * If @id refers to a non-integer-menu control, then this function will
735 * return %NULL.
736 */
737 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
738 const struct v4l2_ctrl_ops *ops,
739 u32 id, u8 max, u8 def,
740 const s64 *qmenu_int);
741
742 /**
743 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
744 * used when adding a control handler.
745 *
746 * @ctrl: pointer to struct &v4l2_ctrl.
747 */
748
749 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
750
751 /**
752 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
753 * handler @hdl.
754 *
755 * @hdl: The control handler.
756 * @add: The control handler whose controls you want to add to
757 * the @hdl control handler.
758 * @filter: This function will filter which controls should be added.
759 * @from_other_dev: If true, then the controls in @add were defined in another
760 * device than @hdl.
761 *
762 * Does nothing if either of the two handlers is a NULL pointer.
763 * If @filter is NULL, then all controls are added. Otherwise only those
764 * controls for which @filter returns true will be added.
765 * In case of an error @hdl->error will be set to the error code (if it
766 * wasn't set already).
767 */
768 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
769 struct v4l2_ctrl_handler *add,
770 v4l2_ctrl_filter filter,
771 bool from_other_dev);
772
773 /**
774 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
775 *
776 * @ctrl: The control that is filtered.
777 *
778 * This will return true for any controls that are valid for radio device
779 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
780 * transmitter class controls.
781 *
782 * This function is to be used with v4l2_ctrl_add_handler().
783 */
784 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
785
786 /**
787 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
788 * to that cluster.
789 *
790 * @ncontrols: The number of controls in this cluster.
791 * @controls: The cluster control array of size @ncontrols.
792 */
793 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
794
795
796 /**
797 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
798 * to that cluster and set it up for autofoo/foo-type handling.
799 *
800 * @ncontrols: The number of controls in this cluster.
801 * @controls: The cluster control array of size @ncontrols. The first control
802 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
803 * @manual_val: The value for the first control in the cluster that equals the
804 * manual setting.
805 * @set_volatile: If true, then all controls except the first auto control will
806 * be volatile.
807 *
808 * Use for control groups where one control selects some automatic feature and
809 * the other controls are only active whenever the automatic feature is turned
810 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
811 * red and blue balance, etc.
812 *
813 * The behavior of such controls is as follows:
814 *
815 * When the autofoo control is set to automatic, then any manual controls
816 * are set to inactive and any reads will call g_volatile_ctrl (if the control
817 * was marked volatile).
818 *
819 * When the autofoo control is set to manual, then any manual controls will
820 * be marked active, and any reads will just return the current value without
821 * going through g_volatile_ctrl.
822 *
823 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
824 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
825 * if autofoo is in auto mode.
826 */
827 void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
828 struct v4l2_ctrl **controls,
829 u8 manual_val, bool set_volatile);
830
831
832 /**
833 * v4l2_ctrl_find() - Find a control with the given ID.
834 *
835 * @hdl: The control handler.
836 * @id: The control ID to find.
837 *
838 * If @hdl == NULL this will return NULL as well. Will lock the handler so
839 * do not use from inside &v4l2_ctrl_ops.
840 */
841 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
842
843 /**
844 * v4l2_ctrl_activate() - Make the control active or inactive.
845 * @ctrl: The control to (de)activate.
846 * @active: True if the control should become active.
847 *
848 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
849 * Does nothing if @ctrl == NULL.
850 * This will usually be called from within the s_ctrl op.
851 * The V4L2_EVENT_CTRL event will be generated afterwards.
852 *
853 * This function assumes that the control handler is locked.
854 */
855 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
856
857 /**
858 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
859 *
860 * @ctrl: The control to (de)activate.
861 * @grabbed: True if the control should become grabbed.
862 *
863 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
864 * Does nothing if @ctrl == NULL.
865 * The V4L2_EVENT_CTRL event will be generated afterwards.
866 * This will usually be called when starting or stopping streaming in the
867 * driver.
868 *
869 * This function assumes that the control handler is locked by the caller.
870 */
871 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
872
873 /**
874 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
875 *
876 * @ctrl: The control to (de)activate.
877 * @grabbed: True if the control should become grabbed.
878 *
879 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
880 * Does nothing if @ctrl == NULL.
881 * The V4L2_EVENT_CTRL event will be generated afterwards.
882 * This will usually be called when starting or stopping streaming in the
883 * driver.
884 *
885 * This function assumes that the control handler is not locked and will
886 * take the lock itself.
887 */
v4l2_ctrl_grab(struct v4l2_ctrl * ctrl,bool grabbed)888 static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
889 {
890 if (!ctrl)
891 return;
892
893 v4l2_ctrl_lock(ctrl);
894 __v4l2_ctrl_grab(ctrl, grabbed);
895 v4l2_ctrl_unlock(ctrl);
896 }
897
898 /**
899 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
900 *
901 * @ctrl: The control to update.
902 * @min: The control's minimum value.
903 * @max: The control's maximum value.
904 * @step: The control's step value
905 * @def: The control's default value.
906 *
907 * Update the range of a control on the fly. This works for control types
908 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
909 * @step value is interpreted as a menu_skip_mask.
910 *
911 * An error is returned if one of the range arguments is invalid for this
912 * control type.
913 *
914 * The caller is responsible for acquiring the control handler mutex on behalf
915 * of __v4l2_ctrl_modify_range().
916 */
917 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
918 s64 min, s64 max, u64 step, s64 def);
919
920 /**
921 * v4l2_ctrl_modify_range() - Update the range of a control.
922 *
923 * @ctrl: The control to update.
924 * @min: The control's minimum value.
925 * @max: The control's maximum value.
926 * @step: The control's step value
927 * @def: The control's default value.
928 *
929 * Update the range of a control on the fly. This works for control types
930 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
931 * @step value is interpreted as a menu_skip_mask.
932 *
933 * An error is returned if one of the range arguments is invalid for this
934 * control type.
935 *
936 * This function assumes that the control handler is not locked and will
937 * take the lock itself.
938 */
v4l2_ctrl_modify_range(struct v4l2_ctrl * ctrl,s64 min,s64 max,u64 step,s64 def)939 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
940 s64 min, s64 max, u64 step, s64 def)
941 {
942 int rval;
943
944 v4l2_ctrl_lock(ctrl);
945 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
946 v4l2_ctrl_unlock(ctrl);
947
948 return rval;
949 }
950
951 /**
952 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
953 *
954 * @ctrl: The control.
955 * @notify: The callback function.
956 * @priv: The callback private handle, passed as argument to the callback.
957 *
958 * This function sets a callback function for the control. If @ctrl is NULL,
959 * then it will do nothing. If @notify is NULL, then the notify callback will
960 * be removed.
961 *
962 * There can be only one notify. If another already exists, then a WARN_ON
963 * will be issued and the function will do nothing.
964 */
965 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
966 void *priv);
967
968 /**
969 * v4l2_ctrl_get_name() - Get the name of the control
970 *
971 * @id: The control ID.
972 *
973 * This function returns the name of the given control ID or NULL if it isn't
974 * a known control.
975 */
976 const char *v4l2_ctrl_get_name(u32 id);
977
978 /**
979 * v4l2_ctrl_get_menu() - Get the menu string array of the control
980 *
981 * @id: The control ID.
982 *
983 * This function returns the NULL-terminated menu string array name of the
984 * given control ID or NULL if it isn't a known menu control.
985 */
986 const char * const *v4l2_ctrl_get_menu(u32 id);
987
988 /**
989 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
990 *
991 * @id: The control ID.
992 * @len: The size of the integer array.
993 *
994 * This function returns the integer array of the given control ID or NULL if it
995 * if it isn't a known integer menu control.
996 */
997 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
998
999 /**
1000 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
1001 * within a driver.
1002 *
1003 * @ctrl: The control.
1004 *
1005 * This returns the control's value safely by going through the control
1006 * framework. This function will lock the control's handler, so it cannot be
1007 * used from within the &v4l2_ctrl_ops functions.
1008 *
1009 * This function is for integer type controls only.
1010 */
1011 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
1012
1013 /**
1014 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
1015 *
1016 * @ctrl: The control.
1017 * @val: The new value.
1018 *
1019 * This sets the control's new value safely by going through the control
1020 * framework. This function assumes the control's handler is already locked,
1021 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1022 *
1023 * This function is for integer type controls only.
1024 */
1025 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
1026
1027 /**
1028 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
1029 * within a driver.
1030 * @ctrl: The control.
1031 * @val: The new value.
1032 *
1033 * This sets the control's new value safely by going through the control
1034 * framework. This function will lock the control's handler, so it cannot be
1035 * used from within the &v4l2_ctrl_ops functions.
1036 *
1037 * This function is for integer type controls only.
1038 */
v4l2_ctrl_s_ctrl(struct v4l2_ctrl * ctrl,s32 val)1039 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
1040 {
1041 int rval;
1042
1043 v4l2_ctrl_lock(ctrl);
1044 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
1045 v4l2_ctrl_unlock(ctrl);
1046
1047 return rval;
1048 }
1049
1050 /**
1051 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
1052 * from within a driver.
1053 *
1054 * @ctrl: The control.
1055 *
1056 * This returns the control's value safely by going through the control
1057 * framework. This function will lock the control's handler, so it cannot be
1058 * used from within the &v4l2_ctrl_ops functions.
1059 *
1060 * This function is for 64-bit integer type controls only.
1061 */
1062 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
1063
1064 /**
1065 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
1066 *
1067 * @ctrl: The control.
1068 * @val: The new value.
1069 *
1070 * This sets the control's new value safely by going through the control
1071 * framework. This function assumes the control's handler is already locked,
1072 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1073 *
1074 * This function is for 64-bit integer type controls only.
1075 */
1076 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1077
1078 /**
1079 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
1080 * from within a driver.
1081 *
1082 * @ctrl: The control.
1083 * @val: The new value.
1084 *
1085 * This sets the control's new value safely by going through the control
1086 * framework. This function will lock the control's handler, so it cannot be
1087 * used from within the &v4l2_ctrl_ops functions.
1088 *
1089 * This function is for 64-bit integer type controls only.
1090 */
v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl * ctrl,s64 val)1091 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
1092 {
1093 int rval;
1094
1095 v4l2_ctrl_lock(ctrl);
1096 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
1097 v4l2_ctrl_unlock(ctrl);
1098
1099 return rval;
1100 }
1101
1102 /**
1103 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
1104 *
1105 * @ctrl: The control.
1106 * @s: The new string.
1107 *
1108 * This sets the control's new string safely by going through the control
1109 * framework. This function assumes the control's handler is already locked,
1110 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1111 *
1112 * This function is for string type controls only.
1113 */
1114 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1115
1116 /**
1117 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
1118 * from within a driver.
1119 *
1120 * @ctrl: The control.
1121 * @s: The new string.
1122 *
1123 * This sets the control's new string safely by going through the control
1124 * framework. This function will lock the control's handler, so it cannot be
1125 * used from within the &v4l2_ctrl_ops functions.
1126 *
1127 * This function is for string type controls only.
1128 */
v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl * ctrl,const char * s)1129 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
1130 {
1131 int rval;
1132
1133 v4l2_ctrl_lock(ctrl);
1134 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1135 v4l2_ctrl_unlock(ctrl);
1136
1137 return rval;
1138 }
1139
1140 /**
1141 * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
1142 *
1143 * @ctrl: The control.
1144 * @type: The type of the data.
1145 * @p: The new compound payload.
1146 *
1147 * This sets the control's new compound payload safely by going through the
1148 * control framework. This function assumes the control's handler is already
1149 * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
1150 *
1151 * This function is for compound type controls only.
1152 */
1153 int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1154 enum v4l2_ctrl_type type, const void *p);
1155
1156 /**
1157 * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
1158 * from within a driver.
1159 *
1160 * @ctrl: The control.
1161 * @type: The type of the data.
1162 * @p: The new compound payload.
1163 *
1164 * This sets the control's new compound payload safely by going through the
1165 * control framework. This function will lock the control's handler, so it
1166 * cannot be used from within the &v4l2_ctrl_ops functions.
1167 *
1168 * This function is for compound type controls only.
1169 */
v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl * ctrl,enum v4l2_ctrl_type type,const void * p)1170 static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1171 enum v4l2_ctrl_type type,
1172 const void *p)
1173 {
1174 int rval;
1175
1176 v4l2_ctrl_lock(ctrl);
1177 rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
1178 v4l2_ctrl_unlock(ctrl);
1179
1180 return rval;
1181 }
1182
1183 /* Helper defines for area type controls */
1184 #define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
1185 __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1186 #define v4l2_ctrl_s_ctrl_area(ctrl, area) \
1187 v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1188
1189 /* Internal helper functions that deal with control events. */
1190 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
1191
1192 /**
1193 * v4l2_ctrl_replace - Function to be used as a callback to
1194 * &struct v4l2_subscribed_event_ops replace\(\)
1195 *
1196 * @old: pointer to struct &v4l2_event with the reported
1197 * event;
1198 * @new: pointer to struct &v4l2_event with the modified
1199 * event;
1200 */
1201 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
1202
1203 /**
1204 * v4l2_ctrl_merge - Function to be used as a callback to
1205 * &struct v4l2_subscribed_event_ops merge(\)
1206 *
1207 * @old: pointer to struct &v4l2_event with the reported
1208 * event;
1209 * @new: pointer to struct &v4l2_event with the merged
1210 * event;
1211 */
1212 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
1213
1214 /**
1215 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1216 *
1217 * @file: pointer to struct file
1218 * @fh: unused. Kept just to be compatible to the arguments expected by
1219 * &struct v4l2_ioctl_ops.vidioc_log_status.
1220 *
1221 * Can be used as a vidioc_log_status function that just dumps all controls
1222 * associated with the filehandle.
1223 */
1224 int v4l2_ctrl_log_status(struct file *file, void *fh);
1225
1226 /**
1227 * v4l2_ctrl_subscribe_event - Subscribes to an event
1228 *
1229 *
1230 * @fh: pointer to struct v4l2_fh
1231 * @sub: pointer to &struct v4l2_event_subscription
1232 *
1233 * Can be used as a vidioc_subscribe_event function that just subscribes
1234 * control events.
1235 */
1236 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
1237 const struct v4l2_event_subscription *sub);
1238
1239 /**
1240 * v4l2_ctrl_poll - function to be used as a callback to the poll()
1241 * That just polls for control events.
1242 *
1243 * @file: pointer to struct file
1244 * @wait: pointer to struct poll_table_struct
1245 */
1246 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
1247
1248 /**
1249 * v4l2_ctrl_request_setup - helper function to apply control values in a request
1250 *
1251 * @req: The request
1252 * @parent: The parent control handler ('priv' in media_request_object_find())
1253 *
1254 * This is a helper function to call the control handler's s_ctrl callback with
1255 * the control values contained in the request. Do note that this approach of
1256 * applying control values in a request is only applicable to memory-to-memory
1257 * devices.
1258 */
1259 int v4l2_ctrl_request_setup(struct media_request *req,
1260 struct v4l2_ctrl_handler *parent);
1261
1262 /**
1263 * v4l2_ctrl_request_complete - Complete a control handler request object
1264 *
1265 * @req: The request
1266 * @parent: The parent control handler ('priv' in media_request_object_find())
1267 *
1268 * This function is to be called on each control handler that may have had a
1269 * request object associated with it, i.e. control handlers of a driver that
1270 * supports requests.
1271 *
1272 * The function first obtains the values of any volatile controls in the control
1273 * handler and attach them to the request. Then, the function completes the
1274 * request object.
1275 */
1276 void v4l2_ctrl_request_complete(struct media_request *req,
1277 struct v4l2_ctrl_handler *parent);
1278
1279 /**
1280 * v4l2_ctrl_request_hdl_find - Find the control handler in the request
1281 *
1282 * @req: The request
1283 * @parent: The parent control handler ('priv' in media_request_object_find())
1284 *
1285 * This function finds the control handler in the request. It may return
1286 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
1287 * with the returned handler pointer.
1288 *
1289 * If the request is not in state VALIDATING or QUEUED, then this function
1290 * will always return NULL.
1291 *
1292 * Note that in state VALIDATING the req_queue_mutex is held, so
1293 * no objects can be added or deleted from the request.
1294 *
1295 * In state QUEUED it is the driver that will have to ensure this.
1296 */
1297 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
1298 struct v4l2_ctrl_handler *parent);
1299
1300 /**
1301 * v4l2_ctrl_request_hdl_put - Put the control handler
1302 *
1303 * @hdl: Put this control handler
1304 *
1305 * This function released the control handler previously obtained from'
1306 * v4l2_ctrl_request_hdl_find().
1307 */
v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler * hdl)1308 static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
1309 {
1310 if (hdl)
1311 media_request_object_put(&hdl->req_obj);
1312 }
1313
1314 /**
1315 * v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID.
1316 *
1317 * @hdl: The control handler from the request.
1318 * @id: The ID of the control to find.
1319 *
1320 * This function returns a pointer to the control if this control is
1321 * part of the request or NULL otherwise.
1322 */
1323 struct v4l2_ctrl *
1324 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
1325
1326 /* Helpers for ioctl_ops */
1327
1328 /**
1329 * v4l2_queryctrl - Helper function to implement
1330 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1331 *
1332 * @hdl: pointer to &struct v4l2_ctrl_handler
1333 * @qc: pointer to &struct v4l2_queryctrl
1334 *
1335 * If hdl == NULL then they will all return -EINVAL.
1336 */
1337 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1338
1339 /**
1340 * v4l2_query_ext_ctrl - Helper function to implement
1341 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1342 *
1343 * @hdl: pointer to &struct v4l2_ctrl_handler
1344 * @qc: pointer to &struct v4l2_query_ext_ctrl
1345 *
1346 * If hdl == NULL then they will all return -EINVAL.
1347 */
1348 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1349 struct v4l2_query_ext_ctrl *qc);
1350
1351 /**
1352 * v4l2_querymenu - Helper function to implement
1353 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1354 *
1355 * @hdl: pointer to &struct v4l2_ctrl_handler
1356 * @qm: pointer to &struct v4l2_querymenu
1357 *
1358 * If hdl == NULL then they will all return -EINVAL.
1359 */
1360 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1361
1362 /**
1363 * v4l2_g_ctrl - Helper function to implement
1364 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1365 *
1366 * @hdl: pointer to &struct v4l2_ctrl_handler
1367 * @ctrl: pointer to &struct v4l2_control
1368 *
1369 * If hdl == NULL then they will all return -EINVAL.
1370 */
1371 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1372
1373 /**
1374 * v4l2_s_ctrl - Helper function to implement
1375 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1376 *
1377 * @fh: pointer to &struct v4l2_fh
1378 * @hdl: pointer to &struct v4l2_ctrl_handler
1379 *
1380 * @ctrl: pointer to &struct v4l2_control
1381 *
1382 * If hdl == NULL then they will all return -EINVAL.
1383 */
1384 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1385 struct v4l2_control *ctrl);
1386
1387 /**
1388 * v4l2_g_ext_ctrls - Helper function to implement
1389 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1390 *
1391 * @hdl: pointer to &struct v4l2_ctrl_handler
1392 * @vdev: pointer to &struct video_device
1393 * @mdev: pointer to &struct media_device
1394 * @c: pointer to &struct v4l2_ext_controls
1395 *
1396 * If hdl == NULL then they will all return -EINVAL.
1397 */
1398 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
1399 struct media_device *mdev, struct v4l2_ext_controls *c);
1400
1401 /**
1402 * v4l2_try_ext_ctrls - Helper function to implement
1403 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1404 *
1405 * @hdl: pointer to &struct v4l2_ctrl_handler
1406 * @vdev: pointer to &struct video_device
1407 * @mdev: pointer to &struct media_device
1408 * @c: pointer to &struct v4l2_ext_controls
1409 *
1410 * If hdl == NULL then they will all return -EINVAL.
1411 */
1412 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1413 struct video_device *vdev,
1414 struct media_device *mdev,
1415 struct v4l2_ext_controls *c);
1416
1417 /**
1418 * v4l2_s_ext_ctrls - Helper function to implement
1419 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1420 *
1421 * @fh: pointer to &struct v4l2_fh
1422 * @hdl: pointer to &struct v4l2_ctrl_handler
1423 * @vdev: pointer to &struct video_device
1424 * @mdev: pointer to &struct media_device
1425 * @c: pointer to &struct v4l2_ext_controls
1426 *
1427 * If hdl == NULL then they will all return -EINVAL.
1428 */
1429 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1430 struct video_device *vdev,
1431 struct media_device *mdev,
1432 struct v4l2_ext_controls *c);
1433
1434 /**
1435 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
1436 * as a &struct v4l2_subdev_core_ops subscribe_event function
1437 * that just subscribes control events.
1438 *
1439 * @sd: pointer to &struct v4l2_subdev
1440 * @fh: pointer to &struct v4l2_fh
1441 * @sub: pointer to &struct v4l2_event_subscription
1442 */
1443 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1444 struct v4l2_event_subscription *sub);
1445
1446 /**
1447 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1448 * handler.
1449 *
1450 * @sd: pointer to &struct v4l2_subdev
1451 */
1452 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1453
1454 /**
1455 * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
1456 * properties
1457 *
1458 * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
1459 * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
1460 * @p: pointer to &struct v4l2_fwnode_device_properties
1461 *
1462 * This function registers controls associated to device properties, using the
1463 * property values contained in @p parameter, if the property has been set to
1464 * a value.
1465 *
1466 * Currently the following v4l2 controls are parsed and registered:
1467 * - V4L2_CID_CAMERA_ORIENTATION
1468 * - V4L2_CID_CAMERA_SENSOR_ROTATION;
1469 *
1470 * Controls already registered by the caller with the @hdl control handler are
1471 * not overwritten. Callers should register the controls they want to handle
1472 * themselves before calling this function.
1473 *
1474 * Return: 0 on success, a negative error code on failure.
1475 */
1476 int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
1477 const struct v4l2_ctrl_ops *ctrl_ops,
1478 const struct v4l2_fwnode_device_properties *p);
1479 #endif
1480