1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * V4L2 controls support header.
5 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
11 #include <linux/list.h>
12 #include <linux/mutex.h>
13 #include <linux/videodev2.h>
14 #include <media/media-request.h>
17 * Include the stateless codec compound control definitions.
18 * This will move to the public headers once this API is fully stable.
20 #include <media/hevc-ctrls.h>
22 /* forward references */
24 struct poll_table_struct;
26 struct v4l2_ctrl_handler;
27 struct v4l2_ctrl_helper;
29 struct v4l2_fwnode_device_properties;
31 struct v4l2_subscribed_event;
35 * union v4l2_ctrl_ptr - A pointer to a control value.
36 * @p_s32: Pointer to a 32-bit signed value.
37 * @p_s64: Pointer to a 64-bit signed value.
38 * @p_u8: Pointer to a 8-bit unsigned value.
39 * @p_u16: Pointer to a 16-bit unsigned value.
40 * @p_u32: Pointer to a 32-bit unsigned value.
41 * @p_char: Pointer to a string.
42 * @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure.
43 * @p_mpeg2_picture: Pointer to a MPEG2 picture structure.
44 * @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure.
45 * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
46 * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
47 * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
48 * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
49 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
50 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
51 * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
52 * @p_vp8_frame: Pointer to a VP8 frame params structure.
53 * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.
54 * @p_vp9_frame: Pointer to a VP9 frame params structure.
55 * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
56 * @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
57 * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
58 * @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure.
59 * @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure.
60 * @p_area: Pointer to an area.
61 * @p: Pointer to a compound value.
62 * @p_const: Pointer to a constant compound value.
71 struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence;
72 struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture;
73 struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation;
74 struct v4l2_ctrl_fwht_params *p_fwht_params;
75 struct v4l2_ctrl_h264_sps *p_h264_sps;
76 struct v4l2_ctrl_h264_pps *p_h264_pps;
77 struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
78 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
79 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
80 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
81 struct v4l2_ctrl_vp8_frame *p_vp8_frame;
82 struct v4l2_ctrl_hevc_sps *p_hevc_sps;
83 struct v4l2_ctrl_hevc_pps *p_hevc_pps;
84 struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
85 struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs;
86 struct v4l2_ctrl_vp9_frame *p_vp9_frame;
87 struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
88 struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
89 struct v4l2_area *p_area;
95 * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
97 * @ptr: The void pointer
99 static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
101 union v4l2_ctrl_ptr p = { .p = ptr };
107 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
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
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.
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);
127 * struct v4l2_ctrl_type_ops - The control type operations that the driver
130 * @equal: return true if both values are equal.
131 * @init: initialize the value.
132 * @log: log the value.
133 * @validate: validate the value. Return 0 on success and a negative value
136 struct v4l2_ctrl_type_ops {
137 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
138 union v4l2_ctrl_ptr ptr1,
139 union v4l2_ctrl_ptr ptr2);
140 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
141 union v4l2_ctrl_ptr ptr);
142 void (*log)(const struct v4l2_ctrl *ctrl);
143 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
144 union v4l2_ctrl_ptr ptr);
148 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
149 * that should be called when a control value has changed.
151 * @ctrl: pointer to struct &v4l2_ctrl
152 * @priv: control private data
154 * This typedef definition is used as an argument to v4l2_ctrl_notify()
155 * and as an argument at struct &v4l2_ctrl_handler.
157 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
160 * struct v4l2_ctrl - The control structure.
162 * @node: The list node.
163 * @ev_subs: The list of control event subscriptions.
164 * @handler: The handler that owns the control.
165 * @cluster: Point to start of cluster array.
166 * @ncontrols: Number of controls in cluster array.
167 * @done: Internal flag: set for each processed control.
168 * @is_new: Set when the user specified a new value for this control. It
169 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
170 * should never set this flag.
171 * @has_changed: Set when the current value differs from the new value. Drivers
172 * should never use this flag.
173 * @is_private: If set, then this control is private to its handler and it
174 * will not be added to any other handlers. Drivers can set
176 * @is_auto: If set, then this control selects whether the other cluster
177 * members are in 'automatic' mode or 'manual' mode. This is
178 * used for autogain/gain type clusters. Drivers should never
179 * set this flag directly.
180 * @is_int: If set, then this control has a simple integer value (i.e. it
182 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
183 * @is_ptr: If set, then this control is an array and/or has type >=
184 * %V4L2_CTRL_COMPOUND_TYPES
185 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
186 * v4l2_ext_control uses field p to point to the data.
187 * @is_array: If set, then this control contains an N-dimensional array.
188 * @is_dyn_array: If set, then this control contains a dynamically sized 1-dimensional array.
189 * If this is set, then @is_array is also set.
190 * @has_volatiles: If set, then one or more members of the cluster are volatile.
191 * Drivers should never touch this flag.
192 * @call_notify: If set, then call the handler's notify function whenever the
193 * control's value changes.
194 * @manual_mode_value: If the is_auto flag is set, then this is the value
195 * of the auto control that determines if that control is in
196 * manual mode. So if the value of the auto control equals this
197 * value, then the whole cluster is in manual mode. Drivers should
198 * never set this flag directly.
199 * @ops: The control ops.
200 * @type_ops: The control type ops.
201 * @id: The control ID.
202 * @name: The control name.
203 * @type: The control type.
204 * @minimum: The control's minimum value.
205 * @maximum: The control's maximum value.
206 * @default_value: The control's default value.
207 * @step: The control's step value for non-menu controls.
208 * @elems: The number of elements in the N-dimensional array.
209 * @elem_size: The size in bytes of the control.
210 * @new_elems: The number of elements in p_new. This is the same as @elems,
211 * except for dynamic arrays. In that case it is in the range of
212 * 1 to @p_dyn_alloc_elems.
213 * @dims: The size of each dimension.
214 * @nr_of_dims:The number of dimensions in @dims.
215 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
216 * easy to skip menu items that are not valid. If bit X is set,
217 * then menu item X is skipped. Of course, this only works for
218 * menus with <= 32 menu items. There are no menus that come
219 * close to that number, so this is OK. Should we ever need more,
220 * then this will have to be extended to a u64 or a bit array.
221 * @qmenu: A const char * array for all menu items. Array entries that are
222 * empty strings ("") correspond to non-existing menu items (this
223 * is in addition to the menu_skip_mask above). The last entry
225 * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
226 * @qmenu_int: A 64-bit integer array for with integer menu items.
227 * The size of array must be equal to the menu size, e. g.:
228 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
229 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
230 * @flags: The control's flags.
231 * @priv: The control's private pointer. For use by the driver. It is
232 * untouched by the control framework. Note that this pointer is
233 * not freed when the control is deleted. Should this be needed
234 * then a new internal bitfield can be added to tell the framework
235 * to free this pointer.
236 * @p_dyn: Pointer to the dynamically allocated array. Only valid if
237 * @is_dyn_array is true.
238 * @p_dyn_alloc_elems: The number of elements in the dynamically allocated
239 * array for both the cur and new values. So @p_dyn is actually
240 * sized for 2 * @p_dyn_alloc_elems * @elem_size. Only valid if
241 * @is_dyn_array is true.
242 * @cur: Structure to store the current value.
243 * @cur.val: The control's current value, if the @type is represented via
244 * a u32 integer (see &enum v4l2_ctrl_type).
245 * @val: The control's new s32 value.
246 * @p_def: The control's default value represented via a union which
247 * provides a standard way of accessing control types
248 * through a pointer (for compound controls only).
249 * @p_cur: The control's current value represented via a union which
250 * provides a standard way of accessing control types
252 * @p_new: The control's new value represented via a union which provides
253 * a standard way of accessing control types
257 /* Administrative fields */
258 struct list_head node;
259 struct list_head ev_subs;
260 struct v4l2_ctrl_handler *handler;
261 struct v4l2_ctrl **cluster;
262 unsigned int ncontrols;
266 unsigned int is_new:1;
267 unsigned int has_changed:1;
268 unsigned int is_private:1;
269 unsigned int is_auto:1;
270 unsigned int is_int:1;
271 unsigned int is_string:1;
272 unsigned int is_ptr:1;
273 unsigned int is_array:1;
274 unsigned int is_dyn_array:1;
275 unsigned int has_volatiles:1;
276 unsigned int call_notify:1;
277 unsigned int manual_mode_value:8;
279 const struct v4l2_ctrl_ops *ops;
280 const struct v4l2_ctrl_type_ops *type_ops;
283 enum v4l2_ctrl_type type;
284 s64 minimum, maximum, default_value;
288 u32 dims[V4L2_CTRL_MAX_DIMS];
295 const char * const *qmenu;
296 const s64 *qmenu_int;
301 u32 p_dyn_alloc_elems;
307 union v4l2_ctrl_ptr p_def;
308 union v4l2_ctrl_ptr p_new;
309 union v4l2_ctrl_ptr p_cur;
313 * struct v4l2_ctrl_ref - The control reference.
315 * @node: List node for the sorted list.
316 * @next: Single-link list node for the hash.
317 * @ctrl: The actual control information.
318 * @helper: Pointer to helper struct. Used internally in
319 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
320 * @from_other_dev: If true, then @ctrl was defined in another
321 * device than the &struct v4l2_ctrl_handler.
322 * @req_done: Internal flag: if the control handler containing this control
323 * reference is bound to a media request, then this is set when
324 * the control has been applied. This prevents applying controls
325 * from a cluster with multiple controls twice (when the first
326 * control of a cluster is applied, they all are).
327 * @p_req_valid: If set, then p_req contains the control value for the request.
328 * @p_req_dyn_enomem: If set, then p_req is invalid since allocating space for
329 * a dynamic array failed. Attempting to read this value shall
330 * result in ENOMEM. Only valid if ctrl->is_dyn_array is true.
331 * @p_req_dyn_alloc_elems: The number of elements allocated for the dynamic
332 * array. Only valid if @p_req_valid and ctrl->is_dyn_array are
334 * @p_req_elems: The number of elements in @p_req. This is the same as
335 * ctrl->elems, except for dynamic arrays. In that case it is in
336 * the range of 1 to @p_req_dyn_alloc_elems. Only valid if
337 * @p_req_valid is true.
338 * @p_req: If the control handler containing this control reference
339 * is bound to a media request, then this points to the
340 * value of the control that must be applied when the request
341 * is executed, or to the value of the control at the time
342 * that the request was completed. If @p_req_valid is false,
343 * then this control was never set for this request and the
344 * control will not be updated when this request is applied.
346 * Each control handler has a list of these refs. The list_head is used to
347 * keep a sorted-by-control-ID list of all controls, while the next pointer
348 * is used to link the control in the hash's bucket.
350 struct v4l2_ctrl_ref {
351 struct list_head node;
352 struct v4l2_ctrl_ref *next;
353 struct v4l2_ctrl *ctrl;
354 struct v4l2_ctrl_helper *helper;
358 bool p_req_dyn_enomem;
359 u32 p_req_dyn_alloc_elems;
361 union v4l2_ctrl_ptr p_req;
365 * struct v4l2_ctrl_handler - The control handler keeps track of all the
366 * controls: both the controls owned by the handler and those inherited
367 * from other handlers.
369 * @_lock: Default for "lock".
370 * @lock: Lock to control access to this handler and its controls.
371 * May be replaced by the user right after init.
372 * @ctrls: The list of controls owned by this handler.
373 * @ctrl_refs: The list of control references.
374 * @cached: The last found control reference. It is common that the same
375 * control is needed multiple times, so this is a simple
377 * @buckets: Buckets for the hashing. Allows for quick control lookup.
378 * @notify: A notify callback that is called whenever the control changes
380 * Note that the handler's lock is held when the notify function
382 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
383 * @nr_of_buckets: Total number of buckets in the array.
384 * @error: The error code of the first failed control addition.
385 * @request_is_queued: True if the request was queued.
386 * @requests: List to keep track of open control handler request objects.
387 * For the parent control handler (@req_obj.ops == NULL) this
388 * is the list header. When the parent control handler is
389 * removed, it has to unbind and put all these requests since
390 * they refer to the parent.
391 * @requests_queued: List of the queued requests. This determines the order
392 * in which these controls are applied. Once the request is
393 * completed it is removed from this list.
394 * @req_obj: The &struct media_request_object, used to link into a
395 * &struct media_request. This request object has a refcount.
397 struct v4l2_ctrl_handler {
400 struct list_head ctrls;
401 struct list_head ctrl_refs;
402 struct v4l2_ctrl_ref *cached;
403 struct v4l2_ctrl_ref **buckets;
404 v4l2_ctrl_notify_fnc notify;
408 bool request_is_queued;
409 struct list_head requests;
410 struct list_head requests_queued;
411 struct media_request_object req_obj;
415 * struct v4l2_ctrl_config - Control configuration structure.
417 * @ops: The control ops.
418 * @type_ops: The control type ops. Only needed for compound controls.
419 * @id: The control ID.
420 * @name: The control name.
421 * @type: The control type.
422 * @min: The control's minimum value.
423 * @max: The control's maximum value.
424 * @step: The control's step value for non-menu controls.
425 * @def: The control's default value.
426 * @p_def: The control's default value for compound controls.
427 * @dims: The size of each dimension.
428 * @elem_size: The size in bytes of the control.
429 * @flags: The control's flags.
430 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
431 * easy to skip menu items that are not valid. If bit X is set,
432 * then menu item X is skipped. Of course, this only works for
433 * menus with <= 64 menu items. There are no menus that come
434 * close to that number, so this is OK. Should we ever need more,
435 * then this will have to be extended to a bit array.
436 * @qmenu: A const char * array for all menu items. Array entries that are
437 * empty strings ("") correspond to non-existing menu items (this
438 * is in addition to the menu_skip_mask above). The last entry
440 * @qmenu_int: A const s64 integer array for all menu items of the type
441 * V4L2_CTRL_TYPE_INTEGER_MENU.
442 * @is_private: If set, then this control is private to its handler and it
443 * will not be added to any other handlers.
445 struct v4l2_ctrl_config {
446 const struct v4l2_ctrl_ops *ops;
447 const struct v4l2_ctrl_type_ops *type_ops;
450 enum v4l2_ctrl_type type;
455 union v4l2_ctrl_ptr p_def;
456 u32 dims[V4L2_CTRL_MAX_DIMS];
460 const char * const *qmenu;
461 const s64 *qmenu_int;
462 unsigned int is_private:1;
466 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
468 * @id: ID of the control
469 * @name: pointer to be filled with a string with the name of the control
470 * @type: pointer for storing the type of the control
471 * @min: pointer for storing the minimum value for the control
472 * @max: pointer for storing the maximum value for the control
473 * @step: pointer for storing the control step
474 * @def: pointer for storing the default value for the control
475 * @flags: pointer for storing the flags to be used on the control
477 * This works for all standard V4L2 controls.
478 * For non-standard controls it will only fill in the given arguments
479 * and @name content will be set to %NULL.
481 * This function will overwrite the contents of @name, @type and @flags.
482 * The contents of @min, @max, @step and @def may be modified depending on
487 * Do not use in drivers! It is used internally for backwards compatibility
488 * control handling only. Once all drivers are converted to use the new
489 * control framework this function will no longer be exported.
491 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
492 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
496 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
497 * @hdl: The control handler.
498 * @nr_of_controls_hint: A hint of how many controls this handler is
499 * expected to refer to. This is the total number, so including
500 * any inherited controls. It doesn't have to be precise, but if
501 * it is way off, then you either waste memory (too many buckets
502 * are allocated) or the control lookup becomes slower (not enough
503 * buckets are allocated, so there are more slow list lookups).
504 * It will always work, though.
505 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
506 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
510 * Never use this call directly, always use the v4l2_ctrl_handler_init()
511 * macro that hides the @key and @name arguments.
513 * Return: returns an error if the buckets could not be allocated. This
514 * error will also be stored in @hdl->error.
516 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
517 unsigned int nr_of_controls_hint,
518 struct lock_class_key *key, const char *name);
520 #ifdef CONFIG_LOCKDEP
523 * v4l2_ctrl_handler_init - helper function to create a static struct
524 * &lock_class_key and calls v4l2_ctrl_handler_init_class()
526 * @hdl: The control handler.
527 * @nr_of_controls_hint: A hint of how many controls this handler is
528 * expected to refer to. This is the total number, so including
529 * any inherited controls. It doesn't have to be precise, but if
530 * it is way off, then you either waste memory (too many buckets
531 * are allocated) or the control lookup becomes slower (not enough
532 * buckets are allocated, so there are more slow list lookups).
533 * It will always work, though.
535 * This helper function creates a static struct &lock_class_key and
536 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
539 * Use this helper function to initialize a control handler.
541 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
544 static struct lock_class_key _key; \
545 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
547 KBUILD_BASENAME ":" \
548 __stringify(__LINE__) ":" \
549 "(" #hdl ")->_lock"); \
553 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
554 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
558 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
560 * @hdl: The control handler.
562 * Does nothing if @hdl == NULL.
564 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
567 * v4l2_ctrl_lock() - Helper function to lock the handler
568 * associated with the control.
569 * @ctrl: The control to lock.
571 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
573 mutex_lock(ctrl->handler->lock);
577 * v4l2_ctrl_unlock() - Helper function to unlock the handler
578 * associated with the control.
579 * @ctrl: The control to unlock.
581 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
583 mutex_unlock(ctrl->handler->lock);
587 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
588 * to the handler to initialize the hardware to the current control values. The
589 * caller is responsible for acquiring the control handler mutex on behalf of
590 * __v4l2_ctrl_handler_setup().
591 * @hdl: The control handler.
593 * Button controls will be skipped, as are read-only controls.
595 * If @hdl == NULL, then this just returns 0.
597 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
600 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
601 * to the handler to initialize the hardware to the current control values.
602 * @hdl: The control handler.
604 * Button controls will be skipped, as are read-only controls.
606 * If @hdl == NULL, then this just returns 0.
608 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
611 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
612 * @hdl: The control handler.
613 * @prefix: The prefix to use when logging the control values. If the
614 * prefix does not end with a space, then ": " will be added
615 * after the prefix. If @prefix == NULL, then no prefix will be
618 * For use with VIDIOC_LOG_STATUS.
620 * Does nothing if @hdl == NULL.
622 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
626 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
629 * @hdl: The control handler.
630 * @cfg: The control's configuration data.
631 * @priv: The control's driver-specific private data.
633 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
634 * and @hdl->error is set to the error code (if it wasn't set already).
636 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
637 const struct v4l2_ctrl_config *cfg,
641 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
644 * @hdl: The control handler.
645 * @ops: The control ops.
646 * @id: The control ID.
647 * @min: The control's minimum value.
648 * @max: The control's maximum value.
649 * @step: The control's step value
650 * @def: The control's default value.
652 * If the &v4l2_ctrl struct could not be allocated, or the control
653 * ID is not known, then NULL is returned and @hdl->error is set to the
654 * appropriate error code (if it wasn't set already).
656 * If @id refers to a menu control, then this function will return NULL.
658 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
660 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
661 const struct v4l2_ctrl_ops *ops,
662 u32 id, s64 min, s64 max, u64 step,
666 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
669 * @hdl: The control handler.
670 * @ops: The control ops.
671 * @id: The control ID.
672 * @max: The control's maximum value.
673 * @mask: The control's skip mask for menu controls. This makes it
674 * easy to skip menu items that are not valid. If bit X is set,
675 * then menu item X is skipped. Of course, this only works for
676 * menus with <= 64 menu items. There are no menus that come
677 * close to that number, so this is OK. Should we ever need more,
678 * then this will have to be extended to a bit array.
679 * @def: The control's default value.
681 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
682 * determines which menu items are to be skipped.
684 * If @id refers to a non-menu control, then this function will return NULL.
686 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
687 const struct v4l2_ctrl_ops *ops,
688 u32 id, u8 max, u64 mask, u8 def);
691 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
692 * with driver specific menu.
694 * @hdl: The control handler.
695 * @ops: The control ops.
696 * @id: The control ID.
697 * @max: The control's maximum value.
698 * @mask: The control's skip mask for menu controls. This makes it
699 * easy to skip menu items that are not valid. If bit X is set,
700 * then menu item X is skipped. Of course, this only works for
701 * menus with <= 64 menu items. There are no menus that come
702 * close to that number, so this is OK. Should we ever need more,
703 * then this will have to be extended to a bit array.
704 * @def: The control's default value.
705 * @qmenu: The new menu.
707 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
708 * menu of this control.
711 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
712 const struct v4l2_ctrl_ops *ops,
715 const char * const *qmenu);
718 * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
721 * @hdl: The control handler.
722 * @ops: The control ops.
723 * @id: The control ID.
724 * @p_def: The control's default value.
726 * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
727 * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
728 * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
729 * compound control should be all zeroes.
732 struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
733 const struct v4l2_ctrl_ops *ops,
735 const union v4l2_ctrl_ptr p_def);
738 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
740 * @hdl: The control handler.
741 * @ops: The control ops.
742 * @id: The control ID.
743 * @max: The control's maximum value.
744 * @def: The control's default value.
745 * @qmenu_int: The control's menu entries.
747 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
748 * takes as an argument an array of integers determining the menu items.
750 * If @id refers to a non-integer-menu control, then this function will
753 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
754 const struct v4l2_ctrl_ops *ops,
755 u32 id, u8 max, u8 def,
756 const s64 *qmenu_int);
759 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
760 * used when adding a control handler.
762 * @ctrl: pointer to struct &v4l2_ctrl.
765 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
768 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
771 * @hdl: The control handler.
772 * @add: The control handler whose controls you want to add to
773 * the @hdl control handler.
774 * @filter: This function will filter which controls should be added.
775 * @from_other_dev: If true, then the controls in @add were defined in another
778 * Does nothing if either of the two handlers is a NULL pointer.
779 * If @filter is NULL, then all controls are added. Otherwise only those
780 * controls for which @filter returns true will be added.
781 * In case of an error @hdl->error will be set to the error code (if it
782 * wasn't set already).
784 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
785 struct v4l2_ctrl_handler *add,
786 v4l2_ctrl_filter filter,
787 bool from_other_dev);
790 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
792 * @ctrl: The control that is filtered.
794 * This will return true for any controls that are valid for radio device
795 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
796 * transmitter class controls.
798 * This function is to be used with v4l2_ctrl_add_handler().
800 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
803 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
806 * @ncontrols: The number of controls in this cluster.
807 * @controls: The cluster control array of size @ncontrols.
809 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
813 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
814 * to that cluster and set it up for autofoo/foo-type handling.
816 * @ncontrols: The number of controls in this cluster.
817 * @controls: The cluster control array of size @ncontrols. The first control
818 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
819 * @manual_val: The value for the first control in the cluster that equals the
821 * @set_volatile: If true, then all controls except the first auto control will
824 * Use for control groups where one control selects some automatic feature and
825 * the other controls are only active whenever the automatic feature is turned
826 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
827 * red and blue balance, etc.
829 * The behavior of such controls is as follows:
831 * When the autofoo control is set to automatic, then any manual controls
832 * are set to inactive and any reads will call g_volatile_ctrl (if the control
833 * was marked volatile).
835 * When the autofoo control is set to manual, then any manual controls will
836 * be marked active, and any reads will just return the current value without
837 * going through g_volatile_ctrl.
839 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
840 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
841 * if autofoo is in auto mode.
843 void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
844 struct v4l2_ctrl **controls,
845 u8 manual_val, bool set_volatile);
849 * v4l2_ctrl_find() - Find a control with the given ID.
851 * @hdl: The control handler.
852 * @id: The control ID to find.
854 * If @hdl == NULL this will return NULL as well. Will lock the handler so
855 * do not use from inside &v4l2_ctrl_ops.
857 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
860 * v4l2_ctrl_activate() - Make the control active or inactive.
861 * @ctrl: The control to (de)activate.
862 * @active: True if the control should become active.
864 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
865 * Does nothing if @ctrl == NULL.
866 * This will usually be called from within the s_ctrl op.
867 * The V4L2_EVENT_CTRL event will be generated afterwards.
869 * This function assumes that the control handler is locked.
871 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
874 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
876 * @ctrl: The control to (de)activate.
877 * @grabbed: True if the control should become grabbed.
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
885 * This function assumes that the control handler is locked by the caller.
887 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
890 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
892 * @ctrl: The control to (de)activate.
893 * @grabbed: True if the control should become grabbed.
895 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
896 * Does nothing if @ctrl == NULL.
897 * The V4L2_EVENT_CTRL event will be generated afterwards.
898 * This will usually be called when starting or stopping streaming in the
901 * This function assumes that the control handler is not locked and will
902 * take the lock itself.
904 static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
909 v4l2_ctrl_lock(ctrl);
910 __v4l2_ctrl_grab(ctrl, grabbed);
911 v4l2_ctrl_unlock(ctrl);
915 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
917 * @ctrl: The control to update.
918 * @min: The control's minimum value.
919 * @max: The control's maximum value.
920 * @step: The control's step value
921 * @def: The control's default value.
923 * Update the range of a control on the fly. This works for control types
924 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
925 * @step value is interpreted as a menu_skip_mask.
927 * An error is returned if one of the range arguments is invalid for this
930 * The caller is responsible for acquiring the control handler mutex on behalf
931 * of __v4l2_ctrl_modify_range().
933 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
934 s64 min, s64 max, u64 step, s64 def);
937 * v4l2_ctrl_modify_range() - Update the range of a control.
939 * @ctrl: The control to update.
940 * @min: The control's minimum value.
941 * @max: The control's maximum value.
942 * @step: The control's step value
943 * @def: The control's default value.
945 * Update the range of a control on the fly. This works for control types
946 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
947 * @step value is interpreted as a menu_skip_mask.
949 * An error is returned if one of the range arguments is invalid for this
952 * This function assumes that the control handler is not locked and will
953 * take the lock itself.
955 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
956 s64 min, s64 max, u64 step, s64 def)
960 v4l2_ctrl_lock(ctrl);
961 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
962 v4l2_ctrl_unlock(ctrl);
968 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
970 * @ctrl: The control.
971 * @notify: The callback function.
972 * @priv: The callback private handle, passed as argument to the callback.
974 * This function sets a callback function for the control. If @ctrl is NULL,
975 * then it will do nothing. If @notify is NULL, then the notify callback will
978 * There can be only one notify. If another already exists, then a WARN_ON
979 * will be issued and the function will do nothing.
981 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
985 * v4l2_ctrl_get_name() - Get the name of the control
987 * @id: The control ID.
989 * This function returns the name of the given control ID or NULL if it isn't
992 const char *v4l2_ctrl_get_name(u32 id);
995 * v4l2_ctrl_get_menu() - Get the menu string array of the control
997 * @id: The control ID.
999 * This function returns the NULL-terminated menu string array name of the
1000 * given control ID or NULL if it isn't a known menu control.
1002 const char * const *v4l2_ctrl_get_menu(u32 id);
1005 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
1007 * @id: The control ID.
1008 * @len: The size of the integer array.
1010 * This function returns the integer array of the given control ID or NULL if it
1011 * if it isn't a known integer menu control.
1013 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
1016 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
1019 * @ctrl: The control.
1021 * This returns the control's value safely by going through the control
1022 * framework. This function will lock the control's handler, so it cannot be
1023 * used from within the &v4l2_ctrl_ops functions.
1025 * This function is for integer type controls only.
1027 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
1030 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
1032 * @ctrl: The control.
1033 * @val: The new value.
1035 * This sets the control's new value safely by going through the control
1036 * framework. This function assumes the control's handler is already locked,
1037 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1039 * This function is for integer type controls only.
1041 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
1044 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
1046 * @ctrl: The control.
1047 * @val: The new value.
1049 * This sets the control's new value safely by going through the control
1050 * framework. This function will lock the control's handler, so it cannot be
1051 * used from within the &v4l2_ctrl_ops functions.
1053 * This function is for integer type controls only.
1055 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
1059 v4l2_ctrl_lock(ctrl);
1060 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
1061 v4l2_ctrl_unlock(ctrl);
1067 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
1068 * from within a driver.
1070 * @ctrl: The control.
1072 * This returns the control's value safely by going through the control
1073 * framework. This function will lock the control's handler, so it cannot be
1074 * used from within the &v4l2_ctrl_ops functions.
1076 * This function is for 64-bit integer type controls only.
1078 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
1081 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
1083 * @ctrl: The control.
1084 * @val: The new value.
1086 * This sets the control's new value safely by going through the control
1087 * framework. This function assumes the control's handler is already locked,
1088 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1090 * This function is for 64-bit integer type controls only.
1092 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1095 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
1096 * from within a driver.
1098 * @ctrl: The control.
1099 * @val: The new value.
1101 * This sets the control's new value safely by going through the control
1102 * framework. This function will lock the control's handler, so it cannot be
1103 * used from within the &v4l2_ctrl_ops functions.
1105 * This function is for 64-bit integer type controls only.
1107 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
1111 v4l2_ctrl_lock(ctrl);
1112 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
1113 v4l2_ctrl_unlock(ctrl);
1119 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
1121 * @ctrl: The control.
1122 * @s: The new string.
1124 * This sets the control's new string safely by going through the control
1125 * framework. This function assumes the control's handler is already locked,
1126 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1128 * This function is for string type controls only.
1130 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1133 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
1134 * from within a driver.
1136 * @ctrl: The control.
1137 * @s: The new string.
1139 * This sets the control's new string safely by going through the control
1140 * framework. This function will lock the control's handler, so it cannot be
1141 * used from within the &v4l2_ctrl_ops functions.
1143 * This function is for string type controls only.
1145 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
1149 v4l2_ctrl_lock(ctrl);
1150 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1151 v4l2_ctrl_unlock(ctrl);
1157 * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
1159 * @ctrl: The control.
1160 * @type: The type of the data.
1161 * @p: The new compound payload.
1163 * This sets the control's new compound payload safely by going through the
1164 * control framework. This function assumes the control's handler is already
1165 * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
1167 * This function is for compound type controls only.
1169 int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1170 enum v4l2_ctrl_type type, const void *p);
1173 * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
1174 * from within a driver.
1176 * @ctrl: The control.
1177 * @type: The type of the data.
1178 * @p: The new compound payload.
1180 * This sets the control's new compound payload safely by going through the
1181 * control framework. This function will lock the control's handler, so it
1182 * cannot be used from within the &v4l2_ctrl_ops functions.
1184 * This function is for compound type controls only.
1186 static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1187 enum v4l2_ctrl_type type,
1192 v4l2_ctrl_lock(ctrl);
1193 rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
1194 v4l2_ctrl_unlock(ctrl);
1199 /* Helper defines for area type controls */
1200 #define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
1201 __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1202 #define v4l2_ctrl_s_ctrl_area(ctrl, area) \
1203 v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1205 /* Internal helper functions that deal with control events. */
1206 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
1209 * v4l2_ctrl_replace - Function to be used as a callback to
1210 * &struct v4l2_subscribed_event_ops replace\(\)
1212 * @old: pointer to struct &v4l2_event with the reported
1214 * @new: pointer to struct &v4l2_event with the modified
1217 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
1220 * v4l2_ctrl_merge - Function to be used as a callback to
1221 * &struct v4l2_subscribed_event_ops merge(\)
1223 * @old: pointer to struct &v4l2_event with the reported
1225 * @new: pointer to struct &v4l2_event with the merged
1228 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
1231 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1233 * @file: pointer to struct file
1234 * @fh: unused. Kept just to be compatible to the arguments expected by
1235 * &struct v4l2_ioctl_ops.vidioc_log_status.
1237 * Can be used as a vidioc_log_status function that just dumps all controls
1238 * associated with the filehandle.
1240 int v4l2_ctrl_log_status(struct file *file, void *fh);
1243 * v4l2_ctrl_subscribe_event - Subscribes to an event
1246 * @fh: pointer to struct v4l2_fh
1247 * @sub: pointer to &struct v4l2_event_subscription
1249 * Can be used as a vidioc_subscribe_event function that just subscribes
1252 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
1253 const struct v4l2_event_subscription *sub);
1256 * v4l2_ctrl_poll - function to be used as a callback to the poll()
1257 * That just polls for control events.
1259 * @file: pointer to struct file
1260 * @wait: pointer to struct poll_table_struct
1262 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
1265 * v4l2_ctrl_request_setup - helper function to apply control values in a request
1268 * @parent: The parent control handler ('priv' in media_request_object_find())
1270 * This is a helper function to call the control handler's s_ctrl callback with
1271 * the control values contained in the request. Do note that this approach of
1272 * applying control values in a request is only applicable to memory-to-memory
1275 int v4l2_ctrl_request_setup(struct media_request *req,
1276 struct v4l2_ctrl_handler *parent);
1279 * v4l2_ctrl_request_complete - Complete a control handler request object
1282 * @parent: The parent control handler ('priv' in media_request_object_find())
1284 * This function is to be called on each control handler that may have had a
1285 * request object associated with it, i.e. control handlers of a driver that
1286 * supports requests.
1288 * The function first obtains the values of any volatile controls in the control
1289 * handler and attach them to the request. Then, the function completes the
1292 void v4l2_ctrl_request_complete(struct media_request *req,
1293 struct v4l2_ctrl_handler *parent);
1296 * v4l2_ctrl_request_hdl_find - Find the control handler in the request
1299 * @parent: The parent control handler ('priv' in media_request_object_find())
1301 * This function finds the control handler in the request. It may return
1302 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
1303 * with the returned handler pointer.
1305 * If the request is not in state VALIDATING or QUEUED, then this function
1306 * will always return NULL.
1308 * Note that in state VALIDATING the req_queue_mutex is held, so
1309 * no objects can be added or deleted from the request.
1311 * In state QUEUED it is the driver that will have to ensure this.
1313 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
1314 struct v4l2_ctrl_handler *parent);
1317 * v4l2_ctrl_request_hdl_put - Put the control handler
1319 * @hdl: Put this control handler
1321 * This function released the control handler previously obtained from'
1322 * v4l2_ctrl_request_hdl_find().
1324 static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
1327 media_request_object_put(&hdl->req_obj);
1331 * v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID.
1333 * @hdl: The control handler from the request.
1334 * @id: The ID of the control to find.
1336 * This function returns a pointer to the control if this control is
1337 * part of the request or NULL otherwise.
1340 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
1342 /* Helpers for ioctl_ops */
1345 * v4l2_queryctrl - Helper function to implement
1346 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1348 * @hdl: pointer to &struct v4l2_ctrl_handler
1349 * @qc: pointer to &struct v4l2_queryctrl
1351 * If hdl == NULL then they will all return -EINVAL.
1353 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1356 * v4l2_query_ext_ctrl - Helper function to implement
1357 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1359 * @hdl: pointer to &struct v4l2_ctrl_handler
1360 * @qc: pointer to &struct v4l2_query_ext_ctrl
1362 * If hdl == NULL then they will all return -EINVAL.
1364 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1365 struct v4l2_query_ext_ctrl *qc);
1368 * v4l2_querymenu - Helper function to implement
1369 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1371 * @hdl: pointer to &struct v4l2_ctrl_handler
1372 * @qm: pointer to &struct v4l2_querymenu
1374 * If hdl == NULL then they will all return -EINVAL.
1376 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1379 * v4l2_g_ctrl - Helper function to implement
1380 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1382 * @hdl: pointer to &struct v4l2_ctrl_handler
1383 * @ctrl: pointer to &struct v4l2_control
1385 * If hdl == NULL then they will all return -EINVAL.
1387 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1390 * v4l2_s_ctrl - Helper function to implement
1391 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1393 * @fh: pointer to &struct v4l2_fh
1394 * @hdl: pointer to &struct v4l2_ctrl_handler
1396 * @ctrl: pointer to &struct v4l2_control
1398 * If hdl == NULL then they will all return -EINVAL.
1400 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1401 struct v4l2_control *ctrl);
1404 * v4l2_g_ext_ctrls - Helper function to implement
1405 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1407 * @hdl: pointer to &struct v4l2_ctrl_handler
1408 * @vdev: pointer to &struct video_device
1409 * @mdev: pointer to &struct media_device
1410 * @c: pointer to &struct v4l2_ext_controls
1412 * If hdl == NULL then they will all return -EINVAL.
1414 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
1415 struct media_device *mdev, struct v4l2_ext_controls *c);
1418 * v4l2_try_ext_ctrls - Helper function to implement
1419 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1421 * @hdl: pointer to &struct v4l2_ctrl_handler
1422 * @vdev: pointer to &struct video_device
1423 * @mdev: pointer to &struct media_device
1424 * @c: pointer to &struct v4l2_ext_controls
1426 * If hdl == NULL then they will all return -EINVAL.
1428 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1429 struct video_device *vdev,
1430 struct media_device *mdev,
1431 struct v4l2_ext_controls *c);
1434 * v4l2_s_ext_ctrls - Helper function to implement
1435 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1437 * @fh: pointer to &struct v4l2_fh
1438 * @hdl: pointer to &struct v4l2_ctrl_handler
1439 * @vdev: pointer to &struct video_device
1440 * @mdev: pointer to &struct media_device
1441 * @c: pointer to &struct v4l2_ext_controls
1443 * If hdl == NULL then they will all return -EINVAL.
1445 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1446 struct video_device *vdev,
1447 struct media_device *mdev,
1448 struct v4l2_ext_controls *c);
1451 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
1452 * as a &struct v4l2_subdev_core_ops subscribe_event function
1453 * that just subscribes control events.
1455 * @sd: pointer to &struct v4l2_subdev
1456 * @fh: pointer to &struct v4l2_fh
1457 * @sub: pointer to &struct v4l2_event_subscription
1459 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1460 struct v4l2_event_subscription *sub);
1463 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1466 * @sd: pointer to &struct v4l2_subdev
1468 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1471 * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
1474 * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
1475 * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
1476 * @p: pointer to &struct v4l2_fwnode_device_properties
1478 * This function registers controls associated to device properties, using the
1479 * property values contained in @p parameter, if the property has been set to
1482 * Currently the following v4l2 controls are parsed and registered:
1483 * - V4L2_CID_CAMERA_ORIENTATION
1484 * - V4L2_CID_CAMERA_SENSOR_ROTATION;
1486 * Controls already registered by the caller with the @hdl control handler are
1487 * not overwritten. Callers should register the controls they want to handle
1488 * themselves before calling this function.
1490 * Return: 0 on success, a negative error code on failure.
1492 int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
1493 const struct v4l2_ctrl_ops *ctrl_ops,
1494 const struct v4l2_fwnode_device_properties *p);