2 * V4L2 controls support header.
4 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
20 #include <linux/list.h>
21 #include <linux/mutex.h>
22 #include <linux/videodev2.h>
23 #include <media/media-request.h>
26 * Include the mpeg2 and fwht stateless codec compound control definitions.
27 * This will move to the public headers once this API is fully stable.
29 #include <media/mpeg2-ctrls.h>
30 #include <media/fwht-ctrls.h>
32 /* forward references */
34 struct v4l2_ctrl_handler;
35 struct v4l2_ctrl_helper;
39 struct v4l2_subscribed_event;
41 struct poll_table_struct;
44 * union v4l2_ctrl_ptr - A pointer to a control value.
45 * @p_s32: Pointer to a 32-bit signed value.
46 * @p_s64: Pointer to a 64-bit signed value.
47 * @p_u8: Pointer to a 8-bit unsigned value.
48 * @p_u16: Pointer to a 16-bit unsigned value.
49 * @p_u32: Pointer to a 32-bit unsigned value.
50 * @p_char: Pointer to a string.
51 * @p_mpeg2_slice_params: Pointer to a MPEG2 slice parameters structure.
52 * @p_mpeg2_quantization: Pointer to a MPEG2 quantization data structure.
53 * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
54 * @p: Pointer to a compound value.
63 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
64 struct v4l2_ctrl_mpeg2_quantization *p_mpeg2_quantization;
65 struct v4l2_ctrl_fwht_params *p_fwht_params;
70 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
72 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
73 * for volatile (and usually read-only) controls such as a control
74 * that returns the current signal strength which changes
76 * If not set, then the currently cached value will be returned.
77 * @try_ctrl: Test whether the control's value is valid. Only relevant when
78 * the usual min/max/step checks are not sufficient.
79 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
80 * ctrl->handler->lock is held when these ops are called, so no
81 * one else can access controls owned by that handler.
83 struct v4l2_ctrl_ops {
84 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
85 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
86 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
90 * struct v4l2_ctrl_type_ops - The control type operations that the driver
93 * @equal: return true if both values are equal.
94 * @init: initialize the value.
95 * @log: log the value.
96 * @validate: validate the value. Return 0 on success and a negative value
99 struct v4l2_ctrl_type_ops {
100 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
101 union v4l2_ctrl_ptr ptr1,
102 union v4l2_ctrl_ptr ptr2);
103 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
104 union v4l2_ctrl_ptr ptr);
105 void (*log)(const struct v4l2_ctrl *ctrl);
106 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
107 union v4l2_ctrl_ptr ptr);
111 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
112 * that should be called when a control value has changed.
114 * @ctrl: pointer to struct &v4l2_ctrl
115 * @priv: control private data
117 * This typedef definition is used as an argument to v4l2_ctrl_notify()
118 * and as an argument at struct &v4l2_ctrl_handler.
120 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
123 * struct v4l2_ctrl - The control structure.
125 * @node: The list node.
126 * @ev_subs: The list of control event subscriptions.
127 * @handler: The handler that owns the control.
128 * @cluster: Point to start of cluster array.
129 * @ncontrols: Number of controls in cluster array.
130 * @done: Internal flag: set for each processed control.
131 * @is_new: Set when the user specified a new value for this control. It
132 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
133 * should never set this flag.
134 * @has_changed: Set when the current value differs from the new value. Drivers
135 * should never use this flag.
136 * @is_private: If set, then this control is private to its handler and it
137 * will not be added to any other handlers. Drivers can set
139 * @is_auto: If set, then this control selects whether the other cluster
140 * members are in 'automatic' mode or 'manual' mode. This is
141 * used for autogain/gain type clusters. Drivers should never
142 * set this flag directly.
143 * @is_int: If set, then this control has a simple integer value (i.e. it
145 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
146 * @is_ptr: If set, then this control is an array and/or has type >=
147 * %V4L2_CTRL_COMPOUND_TYPES
148 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
149 * v4l2_ext_control uses field p to point to the data.
150 * @is_array: If set, then this control contains an N-dimensional array.
151 * @has_volatiles: If set, then one or more members of the cluster are volatile.
152 * Drivers should never touch this flag.
153 * @call_notify: If set, then call the handler's notify function whenever the
154 * control's value changes.
155 * @manual_mode_value: If the is_auto flag is set, then this is the value
156 * of the auto control that determines if that control is in
157 * manual mode. So if the value of the auto control equals this
158 * value, then the whole cluster is in manual mode. Drivers should
159 * never set this flag directly.
160 * @ops: The control ops.
161 * @type_ops: The control type ops.
162 * @id: The control ID.
163 * @name: The control name.
164 * @type: The control type.
165 * @minimum: The control's minimum value.
166 * @maximum: The control's maximum value.
167 * @default_value: The control's default value.
168 * @step: The control's step value for non-menu controls.
169 * @elems: The number of elements in the N-dimensional array.
170 * @elem_size: The size in bytes of the control.
171 * @dims: The size of each dimension.
172 * @nr_of_dims:The number of dimensions in @dims.
173 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
174 * easy to skip menu items that are not valid. If bit X is set,
175 * then menu item X is skipped. Of course, this only works for
176 * menus with <= 32 menu items. There are no menus that come
177 * close to that number, so this is OK. Should we ever need more,
178 * then this will have to be extended to a u64 or a bit array.
179 * @qmenu: A const char * array for all menu items. Array entries that are
180 * empty strings ("") correspond to non-existing menu items (this
181 * is in addition to the menu_skip_mask above). The last entry
183 * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
184 * @qmenu_int: A 64-bit integer array for with integer menu items.
185 * The size of array must be equal to the menu size, e. g.:
186 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
187 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
188 * @flags: The control's flags.
189 * @cur: Structure to store the current value.
190 * @cur.val: The control's current value, if the @type is represented via
191 * a u32 integer (see &enum v4l2_ctrl_type).
192 * @val: The control's new s32 value.
193 * @priv: The control's private pointer. For use by the driver. It is
194 * untouched by the control framework. Note that this pointer is
195 * not freed when the control is deleted. Should this be needed
196 * then a new internal bitfield can be added to tell the framework
197 * to free this pointer.
198 * @p_cur: The control's current value represented via a union which
199 * provides a standard way of accessing control types
201 * @p_new: The control's new value represented via a union which provides
202 * a standard way of accessing control types
206 /* Administrative fields */
207 struct list_head node;
208 struct list_head ev_subs;
209 struct v4l2_ctrl_handler *handler;
210 struct v4l2_ctrl **cluster;
211 unsigned int ncontrols;
215 unsigned int is_new:1;
216 unsigned int has_changed:1;
217 unsigned int is_private:1;
218 unsigned int is_auto:1;
219 unsigned int is_int:1;
220 unsigned int is_string:1;
221 unsigned int is_ptr:1;
222 unsigned int is_array:1;
223 unsigned int has_volatiles:1;
224 unsigned int call_notify:1;
225 unsigned int manual_mode_value:8;
227 const struct v4l2_ctrl_ops *ops;
228 const struct v4l2_ctrl_type_ops *type_ops;
231 enum v4l2_ctrl_type type;
232 s64 minimum, maximum, default_value;
235 u32 dims[V4L2_CTRL_MAX_DIMS];
242 const char * const *qmenu;
243 const s64 *qmenu_int;
252 union v4l2_ctrl_ptr p_new;
253 union v4l2_ctrl_ptr p_cur;
257 * struct v4l2_ctrl_ref - The control reference.
259 * @node: List node for the sorted list.
260 * @next: Single-link list node for the hash.
261 * @ctrl: The actual control information.
262 * @helper: Pointer to helper struct. Used internally in
263 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
264 * @from_other_dev: If true, then @ctrl was defined in another
265 * device than the &struct v4l2_ctrl_handler.
266 * @req_done: Internal flag: if the control handler containing this control
267 * reference is bound to a media request, then this is set when
268 * the control has been applied. This prevents applying controls
269 * from a cluster with multiple controls twice (when the first
270 * control of a cluster is applied, they all are).
271 * @req: If set, this refers to another request that sets this control.
272 * @p_req: If the control handler containing this control reference
273 * is bound to a media request, then this points to the
274 * value of the control that should be applied when the request
275 * is executed, or to the value of the control at the time
276 * that the request was completed.
278 * Each control handler has a list of these refs. The list_head is used to
279 * keep a sorted-by-control-ID list of all controls, while the next pointer
280 * is used to link the control in the hash's bucket.
282 struct v4l2_ctrl_ref {
283 struct list_head node;
284 struct v4l2_ctrl_ref *next;
285 struct v4l2_ctrl *ctrl;
286 struct v4l2_ctrl_helper *helper;
289 struct v4l2_ctrl_ref *req;
290 union v4l2_ctrl_ptr p_req;
294 * struct v4l2_ctrl_handler - The control handler keeps track of all the
295 * controls: both the controls owned by the handler and those inherited
296 * from other handlers.
298 * @_lock: Default for "lock".
299 * @lock: Lock to control access to this handler and its controls.
300 * May be replaced by the user right after init.
301 * @ctrls: The list of controls owned by this handler.
302 * @ctrl_refs: The list of control references.
303 * @cached: The last found control reference. It is common that the same
304 * control is needed multiple times, so this is a simple
306 * @buckets: Buckets for the hashing. Allows for quick control lookup.
307 * @notify: A notify callback that is called whenever the control changes
309 * Note that the handler's lock is held when the notify function
311 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
312 * @nr_of_buckets: Total number of buckets in the array.
313 * @error: The error code of the first failed control addition.
314 * @request_is_queued: True if the request was queued.
315 * @requests: List to keep track of open control handler request objects.
316 * For the parent control handler (@req_obj.req == NULL) this
317 * is the list header. When the parent control handler is
318 * removed, it has to unbind and put all these requests since
319 * they refer to the parent.
320 * @requests_queued: List of the queued requests. This determines the order
321 * in which these controls are applied. Once the request is
322 * completed it is removed from this list.
323 * @req_obj: The &struct media_request_object, used to link into a
324 * &struct media_request. This request object has a refcount.
326 struct v4l2_ctrl_handler {
329 struct list_head ctrls;
330 struct list_head ctrl_refs;
331 struct v4l2_ctrl_ref *cached;
332 struct v4l2_ctrl_ref **buckets;
333 v4l2_ctrl_notify_fnc notify;
337 bool request_is_queued;
338 struct list_head requests;
339 struct list_head requests_queued;
340 struct media_request_object req_obj;
344 * struct v4l2_ctrl_config - Control configuration structure.
346 * @ops: The control ops.
347 * @type_ops: The control type ops. Only needed for compound controls.
348 * @id: The control ID.
349 * @name: The control name.
350 * @type: The control type.
351 * @min: The control's minimum value.
352 * @max: The control's maximum value.
353 * @step: The control's step value for non-menu controls.
354 * @def: The control's default value.
355 * @dims: The size of each dimension.
356 * @elem_size: The size in bytes of the control.
357 * @flags: The control's flags.
358 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
359 * easy to skip menu items that are not valid. If bit X is set,
360 * then menu item X is skipped. Of course, this only works for
361 * menus with <= 64 menu items. There are no menus that come
362 * close to that number, so this is OK. Should we ever need more,
363 * then this will have to be extended to a bit array.
364 * @qmenu: A const char * array for all menu items. Array entries that are
365 * empty strings ("") correspond to non-existing menu items (this
366 * is in addition to the menu_skip_mask above). The last entry
368 * @qmenu_int: A const s64 integer array for all menu items of the type
369 * V4L2_CTRL_TYPE_INTEGER_MENU.
370 * @is_private: If set, then this control is private to its handler and it
371 * will not be added to any other handlers.
373 struct v4l2_ctrl_config {
374 const struct v4l2_ctrl_ops *ops;
375 const struct v4l2_ctrl_type_ops *type_ops;
378 enum v4l2_ctrl_type type;
383 u32 dims[V4L2_CTRL_MAX_DIMS];
387 const char * const *qmenu;
388 const s64 *qmenu_int;
389 unsigned int is_private:1;
393 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
395 * @id: ID of the control
396 * @name: pointer to be filled with a string with the name of the control
397 * @type: pointer for storing the type of the control
398 * @min: pointer for storing the minimum value for the control
399 * @max: pointer for storing the maximum value for the control
400 * @step: pointer for storing the control step
401 * @def: pointer for storing the default value for the control
402 * @flags: pointer for storing the flags to be used on the control
404 * This works for all standard V4L2 controls.
405 * For non-standard controls it will only fill in the given arguments
406 * and @name content will be set to %NULL.
408 * This function will overwrite the contents of @name, @type and @flags.
409 * The contents of @min, @max, @step and @def may be modified depending on
414 * Do not use in drivers! It is used internally for backwards compatibility
415 * control handling only. Once all drivers are converted to use the new
416 * control framework this function will no longer be exported.
418 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
419 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
423 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
424 * @hdl: The control handler.
425 * @nr_of_controls_hint: A hint of how many controls this handler is
426 * expected to refer to. This is the total number, so including
427 * any inherited controls. It doesn't have to be precise, but if
428 * it is way off, then you either waste memory (too many buckets
429 * are allocated) or the control lookup becomes slower (not enough
430 * buckets are allocated, so there are more slow list lookups).
431 * It will always work, though.
432 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
433 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
437 * Never use this call directly, always use the v4l2_ctrl_handler_init()
438 * macro that hides the @key and @name arguments.
440 * Return: returns an error if the buckets could not be allocated. This
441 * error will also be stored in @hdl->error.
443 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
444 unsigned int nr_of_controls_hint,
445 struct lock_class_key *key, const char *name);
447 #ifdef CONFIG_LOCKDEP
450 * v4l2_ctrl_handler_init - helper function to create a static struct
451 * &lock_class_key and calls v4l2_ctrl_handler_init_class()
453 * @hdl: The control handler.
454 * @nr_of_controls_hint: A hint of how many controls this handler is
455 * expected to refer to. This is the total number, so including
456 * any inherited controls. It doesn't have to be precise, but if
457 * it is way off, then you either waste memory (too many buckets
458 * are allocated) or the control lookup becomes slower (not enough
459 * buckets are allocated, so there are more slow list lookups).
460 * It will always work, though.
462 * This helper function creates a static struct &lock_class_key and
463 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
466 * Use this helper function to initialize a control handler.
468 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
471 static struct lock_class_key _key; \
472 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
474 KBUILD_BASENAME ":" \
475 __stringify(__LINE__) ":" \
476 "(" #hdl ")->_lock"); \
480 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
481 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
485 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
487 * @hdl: The control handler.
489 * Does nothing if @hdl == NULL.
491 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
494 * v4l2_ctrl_lock() - Helper function to lock the handler
495 * associated with the control.
496 * @ctrl: The control to lock.
498 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
500 mutex_lock(ctrl->handler->lock);
504 * v4l2_ctrl_unlock() - Helper function to unlock the handler
505 * associated with the control.
506 * @ctrl: The control to unlock.
508 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
510 mutex_unlock(ctrl->handler->lock);
514 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
515 * to the handler to initialize the hardware to the current control values. The
516 * caller is responsible for acquiring the control handler mutex on behalf of
517 * __v4l2_ctrl_handler_setup().
518 * @hdl: The control handler.
520 * Button controls will be skipped, as are read-only controls.
522 * If @hdl == NULL, then this just returns 0.
524 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
527 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
528 * to the handler to initialize the hardware to the current control values.
529 * @hdl: The control handler.
531 * Button controls will be skipped, as are read-only controls.
533 * If @hdl == NULL, then this just returns 0.
535 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
538 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
539 * @hdl: The control handler.
540 * @prefix: The prefix to use when logging the control values. If the
541 * prefix does not end with a space, then ": " will be added
542 * after the prefix. If @prefix == NULL, then no prefix will be
545 * For use with VIDIOC_LOG_STATUS.
547 * Does nothing if @hdl == NULL.
549 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
553 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
556 * @hdl: The control handler.
557 * @cfg: The control's configuration data.
558 * @priv: The control's driver-specific private data.
560 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
561 * and @hdl->error is set to the error code (if it wasn't set already).
563 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
564 const struct v4l2_ctrl_config *cfg,
568 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
571 * @hdl: The control handler.
572 * @ops: The control ops.
573 * @id: The control ID.
574 * @min: The control's minimum value.
575 * @max: The control's maximum value.
576 * @step: The control's step value
577 * @def: The control's default value.
579 * If the &v4l2_ctrl struct could not be allocated, or the control
580 * ID is not known, then NULL is returned and @hdl->error is set to the
581 * appropriate error code (if it wasn't set already).
583 * If @id refers to a menu control, then this function will return NULL.
585 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
587 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
588 const struct v4l2_ctrl_ops *ops,
589 u32 id, s64 min, s64 max, u64 step,
593 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
596 * @hdl: The control handler.
597 * @ops: The control ops.
598 * @id: The control ID.
599 * @max: The control's maximum value.
600 * @mask: The control's skip mask for menu controls. This makes it
601 * easy to skip menu items that are not valid. If bit X is set,
602 * then menu item X is skipped. Of course, this only works for
603 * menus with <= 64 menu items. There are no menus that come
604 * close to that number, so this is OK. Should we ever need more,
605 * then this will have to be extended to a bit array.
606 * @def: The control's default value.
608 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
609 * determines which menu items are to be skipped.
611 * If @id refers to a non-menu control, then this function will return NULL.
613 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
614 const struct v4l2_ctrl_ops *ops,
615 u32 id, u8 max, u64 mask, u8 def);
618 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
619 * with driver specific menu.
621 * @hdl: The control handler.
622 * @ops: The control ops.
623 * @id: The control ID.
624 * @max: The control's maximum value.
625 * @mask: The control's skip mask for menu controls. This makes it
626 * easy to skip menu items that are not valid. If bit X is set,
627 * then menu item X is skipped. Of course, this only works for
628 * menus with <= 64 menu items. There are no menus that come
629 * close to that number, so this is OK. Should we ever need more,
630 * then this will have to be extended to a bit array.
631 * @def: The control's default value.
632 * @qmenu: The new menu.
634 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
635 * menu of this control.
638 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
639 const struct v4l2_ctrl_ops *ops,
642 const char * const *qmenu);
645 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
647 * @hdl: The control handler.
648 * @ops: The control ops.
649 * @id: The control ID.
650 * @max: The control's maximum value.
651 * @def: The control's default value.
652 * @qmenu_int: The control's menu entries.
654 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
655 * takes as an argument an array of integers determining the menu items.
657 * If @id refers to a non-integer-menu control, then this function will
660 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
661 const struct v4l2_ctrl_ops *ops,
662 u32 id, u8 max, u8 def,
663 const s64 *qmenu_int);
666 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
667 * used when adding a control handler.
669 * @ctrl: pointer to struct &v4l2_ctrl.
672 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
675 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
678 * @hdl: The control handler.
679 * @add: The control handler whose controls you want to add to
680 * the @hdl control handler.
681 * @filter: This function will filter which controls should be added.
682 * @from_other_dev: If true, then the controls in @add were defined in another
685 * Does nothing if either of the two handlers is a NULL pointer.
686 * If @filter is NULL, then all controls are added. Otherwise only those
687 * controls for which @filter returns true will be added.
688 * In case of an error @hdl->error will be set to the error code (if it
689 * wasn't set already).
691 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
692 struct v4l2_ctrl_handler *add,
693 v4l2_ctrl_filter filter,
694 bool from_other_dev);
697 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
699 * @ctrl: The control that is filtered.
701 * This will return true for any controls that are valid for radio device
702 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
703 * transmitter class controls.
705 * This function is to be used with v4l2_ctrl_add_handler().
707 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
710 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
713 * @ncontrols: The number of controls in this cluster.
714 * @controls: The cluster control array of size @ncontrols.
716 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
720 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
721 * to that cluster and set it up for autofoo/foo-type handling.
723 * @ncontrols: The number of controls in this cluster.
724 * @controls: The cluster control array of size @ncontrols. The first control
725 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
726 * @manual_val: The value for the first control in the cluster that equals the
728 * @set_volatile: If true, then all controls except the first auto control will
731 * Use for control groups where one control selects some automatic feature and
732 * the other controls are only active whenever the automatic feature is turned
733 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
734 * red and blue balance, etc.
736 * The behavior of such controls is as follows:
738 * When the autofoo control is set to automatic, then any manual controls
739 * are set to inactive and any reads will call g_volatile_ctrl (if the control
740 * was marked volatile).
742 * When the autofoo control is set to manual, then any manual controls will
743 * be marked active, and any reads will just return the current value without
744 * going through g_volatile_ctrl.
746 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
747 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
748 * if autofoo is in auto mode.
750 void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
751 struct v4l2_ctrl **controls,
752 u8 manual_val, bool set_volatile);
756 * v4l2_ctrl_find() - Find a control with the given ID.
758 * @hdl: The control handler.
759 * @id: The control ID to find.
761 * If @hdl == NULL this will return NULL as well. Will lock the handler so
762 * do not use from inside &v4l2_ctrl_ops.
764 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
767 * v4l2_ctrl_activate() - Make the control active or inactive.
768 * @ctrl: The control to (de)activate.
769 * @active: True if the control should become active.
771 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
772 * Does nothing if @ctrl == NULL.
773 * This will usually be called from within the s_ctrl op.
774 * The V4L2_EVENT_CTRL event will be generated afterwards.
776 * This function assumes that the control handler is locked.
778 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
781 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
783 * @ctrl: The control to (de)activate.
784 * @grabbed: True if the control should become grabbed.
786 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
787 * Does nothing if @ctrl == NULL.
788 * The V4L2_EVENT_CTRL event will be generated afterwards.
789 * This will usually be called when starting or stopping streaming in the
792 * This function assumes that the control handler is locked by the caller.
794 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
797 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
799 * @ctrl: The control to (de)activate.
800 * @grabbed: True if the control should become grabbed.
802 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
803 * Does nothing if @ctrl == NULL.
804 * The V4L2_EVENT_CTRL event will be generated afterwards.
805 * This will usually be called when starting or stopping streaming in the
808 * This function assumes that the control handler is not locked and will
809 * take the lock itself.
811 static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
816 v4l2_ctrl_lock(ctrl);
817 __v4l2_ctrl_grab(ctrl, grabbed);
818 v4l2_ctrl_unlock(ctrl);
822 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
824 * @ctrl: The control to update.
825 * @min: The control's minimum value.
826 * @max: The control's maximum value.
827 * @step: The control's step value
828 * @def: The control's default value.
830 * Update the range of a control on the fly. This works for control types
831 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
832 * @step value is interpreted as a menu_skip_mask.
834 * An error is returned if one of the range arguments is invalid for this
837 * The caller is responsible for acquiring the control handler mutex on behalf
838 * of __v4l2_ctrl_modify_range().
840 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
841 s64 min, s64 max, u64 step, s64 def);
844 * v4l2_ctrl_modify_range() - Update the range of a control.
846 * @ctrl: The control to update.
847 * @min: The control's minimum value.
848 * @max: The control's maximum value.
849 * @step: The control's step value
850 * @def: The control's default value.
852 * Update the range of a control on the fly. This works for control types
853 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
854 * @step value is interpreted as a menu_skip_mask.
856 * An error is returned if one of the range arguments is invalid for this
859 * This function assumes that the control handler is not locked and will
860 * take the lock itself.
862 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
863 s64 min, s64 max, u64 step, s64 def)
867 v4l2_ctrl_lock(ctrl);
868 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
869 v4l2_ctrl_unlock(ctrl);
875 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
877 * @ctrl: The control.
878 * @notify: The callback function.
879 * @priv: The callback private handle, passed as argument to the callback.
881 * This function sets a callback function for the control. If @ctrl is NULL,
882 * then it will do nothing. If @notify is NULL, then the notify callback will
885 * There can be only one notify. If another already exists, then a WARN_ON
886 * will be issued and the function will do nothing.
888 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
892 * v4l2_ctrl_get_name() - Get the name of the control
894 * @id: The control ID.
896 * This function returns the name of the given control ID or NULL if it isn't
899 const char *v4l2_ctrl_get_name(u32 id);
902 * v4l2_ctrl_get_menu() - Get the menu string array of the control
904 * @id: The control ID.
906 * This function returns the NULL-terminated menu string array name of the
907 * given control ID or NULL if it isn't a known menu control.
909 const char * const *v4l2_ctrl_get_menu(u32 id);
912 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
914 * @id: The control ID.
915 * @len: The size of the integer array.
917 * This function returns the integer array of the given control ID or NULL if it
918 * if it isn't a known integer menu control.
920 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
923 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
926 * @ctrl: The control.
928 * This returns the control's value safely by going through the control
929 * framework. This function will lock the control's handler, so it cannot be
930 * used from within the &v4l2_ctrl_ops functions.
932 * This function is for integer type controls only.
934 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
937 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
939 * @ctrl: The control.
940 * @val: The new value.
942 * This sets the control's new value safely by going through the control
943 * framework. This function assumes the control's handler is already locked,
944 * allowing it to be used from within the &v4l2_ctrl_ops functions.
946 * This function is for integer type controls only.
948 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
951 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
953 * @ctrl: The control.
954 * @val: The new value.
956 * This sets the control's new value safely by going through the control
957 * framework. This function will lock the control's handler, so it cannot be
958 * used from within the &v4l2_ctrl_ops functions.
960 * This function is for integer type controls only.
962 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
966 v4l2_ctrl_lock(ctrl);
967 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
968 v4l2_ctrl_unlock(ctrl);
974 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
975 * from within a driver.
977 * @ctrl: The control.
979 * This returns the control's value safely by going through the control
980 * framework. This function will lock the control's handler, so it cannot be
981 * used from within the &v4l2_ctrl_ops functions.
983 * This function is for 64-bit integer type controls only.
985 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
988 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
990 * @ctrl: The control.
991 * @val: The new value.
993 * This sets the control's new value safely by going through the control
994 * framework. This function assumes the control's handler is already locked,
995 * allowing it to be used from within the &v4l2_ctrl_ops functions.
997 * This function is for 64-bit integer type controls only.
999 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1002 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
1003 * from within a driver.
1005 * @ctrl: The control.
1006 * @val: The new value.
1008 * This sets the control's new value safely by going through the control
1009 * framework. This function will lock the control's handler, so it cannot be
1010 * used from within the &v4l2_ctrl_ops functions.
1012 * This function is for 64-bit integer type controls only.
1014 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
1018 v4l2_ctrl_lock(ctrl);
1019 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
1020 v4l2_ctrl_unlock(ctrl);
1026 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
1028 * @ctrl: The control.
1029 * @s: The new string.
1031 * This sets the control's new string safely by going through the control
1032 * framework. This function assumes the control's handler is already locked,
1033 * allowing it to be used from within the &v4l2_ctrl_ops functions.
1035 * This function is for string type controls only.
1037 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1040 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
1041 * from within a driver.
1043 * @ctrl: The control.
1044 * @s: The new string.
1046 * This sets the control's new string safely by going through the control
1047 * framework. This function will lock the control's handler, so it cannot be
1048 * used from within the &v4l2_ctrl_ops functions.
1050 * This function is for string type controls only.
1052 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
1056 v4l2_ctrl_lock(ctrl);
1057 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1058 v4l2_ctrl_unlock(ctrl);
1063 /* Internal helper functions that deal with control events. */
1064 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
1067 * v4l2_ctrl_replace - Function to be used as a callback to
1068 * &struct v4l2_subscribed_event_ops replace\(\)
1070 * @old: pointer to struct &v4l2_event with the reported
1072 * @new: pointer to struct &v4l2_event with the modified
1075 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
1078 * v4l2_ctrl_merge - Function to be used as a callback to
1079 * &struct v4l2_subscribed_event_ops merge(\)
1081 * @old: pointer to struct &v4l2_event with the reported
1083 * @new: pointer to struct &v4l2_event with the merged
1086 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
1089 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1091 * @file: pointer to struct file
1092 * @fh: unused. Kept just to be compatible to the arguments expected by
1093 * &struct v4l2_ioctl_ops.vidioc_log_status.
1095 * Can be used as a vidioc_log_status function that just dumps all controls
1096 * associated with the filehandle.
1098 int v4l2_ctrl_log_status(struct file *file, void *fh);
1101 * v4l2_ctrl_subscribe_event - Subscribes to an event
1104 * @fh: pointer to struct v4l2_fh
1105 * @sub: pointer to &struct v4l2_event_subscription
1107 * Can be used as a vidioc_subscribe_event function that just subscribes
1110 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
1111 const struct v4l2_event_subscription *sub);
1114 * v4l2_ctrl_poll - function to be used as a callback to the poll()
1115 * That just polls for control events.
1117 * @file: pointer to struct file
1118 * @wait: pointer to struct poll_table_struct
1120 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
1123 * v4l2_ctrl_request_setup - helper function to apply control values in a request
1126 * @parent: The parent control handler ('priv' in media_request_object_find())
1128 * This is a helper function to call the control handler's s_ctrl callback with
1129 * the control values contained in the request. Do note that this approach of
1130 * applying control values in a request is only applicable to memory-to-memory
1133 int v4l2_ctrl_request_setup(struct media_request *req,
1134 struct v4l2_ctrl_handler *parent);
1137 * v4l2_ctrl_request_complete - Complete a control handler request object
1140 * @parent: The parent control handler ('priv' in media_request_object_find())
1142 * This function is to be called on each control handler that may have had a
1143 * request object associated with it, i.e. control handlers of a driver that
1144 * supports requests.
1146 * The function first obtains the values of any volatile controls in the control
1147 * handler and attach them to the request. Then, the function completes the
1150 void v4l2_ctrl_request_complete(struct media_request *req,
1151 struct v4l2_ctrl_handler *parent);
1154 * v4l2_ctrl_request_hdl_find - Find the control handler in the request
1157 * @parent: The parent control handler ('priv' in media_request_object_find())
1159 * This function finds the control handler in the request. It may return
1160 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
1161 * with the returned handler pointer.
1163 * If the request is not in state VALIDATING or QUEUED, then this function
1164 * will always return NULL.
1166 * Note that in state VALIDATING the req_queue_mutex is held, so
1167 * no objects can be added or deleted from the request.
1169 * In state QUEUED it is the driver that will have to ensure this.
1171 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
1172 struct v4l2_ctrl_handler *parent);
1175 * v4l2_ctrl_request_hdl_put - Put the control handler
1177 * @hdl: Put this control handler
1179 * This function released the control handler previously obtained from'
1180 * v4l2_ctrl_request_hdl_find().
1182 static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
1185 media_request_object_put(&hdl->req_obj);
1189 * v4l2_ctrl_request_ctrl_find() - Find a control with the given ID.
1191 * @hdl: The control handler from the request.
1192 * @id: The ID of the control to find.
1194 * This function returns a pointer to the control if this control is
1195 * part of the request or NULL otherwise.
1198 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
1200 /* Helpers for ioctl_ops */
1203 * v4l2_queryctrl - Helper function to implement
1204 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1206 * @hdl: pointer to &struct v4l2_ctrl_handler
1207 * @qc: pointer to &struct v4l2_queryctrl
1209 * If hdl == NULL then they will all return -EINVAL.
1211 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1214 * v4l2_query_ext_ctrl - Helper function to implement
1215 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1217 * @hdl: pointer to &struct v4l2_ctrl_handler
1218 * @qc: pointer to &struct v4l2_query_ext_ctrl
1220 * If hdl == NULL then they will all return -EINVAL.
1222 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1223 struct v4l2_query_ext_ctrl *qc);
1226 * v4l2_querymenu - Helper function to implement
1227 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1229 * @hdl: pointer to &struct v4l2_ctrl_handler
1230 * @qm: pointer to &struct v4l2_querymenu
1232 * If hdl == NULL then they will all return -EINVAL.
1234 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1237 * v4l2_g_ctrl - Helper function to implement
1238 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1240 * @hdl: pointer to &struct v4l2_ctrl_handler
1241 * @ctrl: pointer to &struct v4l2_control
1243 * If hdl == NULL then they will all return -EINVAL.
1245 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1248 * v4l2_s_ctrl - Helper function to implement
1249 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1251 * @fh: pointer to &struct v4l2_fh
1252 * @hdl: pointer to &struct v4l2_ctrl_handler
1254 * @ctrl: pointer to &struct v4l2_control
1256 * If hdl == NULL then they will all return -EINVAL.
1258 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1259 struct v4l2_control *ctrl);
1262 * v4l2_g_ext_ctrls - Helper function to implement
1263 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1265 * @hdl: pointer to &struct v4l2_ctrl_handler
1266 * @mdev: pointer to &struct media_device
1267 * @c: pointer to &struct v4l2_ext_controls
1269 * If hdl == NULL then they will all return -EINVAL.
1271 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct media_device *mdev,
1272 struct v4l2_ext_controls *c);
1275 * v4l2_try_ext_ctrls - Helper function to implement
1276 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1278 * @hdl: pointer to &struct v4l2_ctrl_handler
1279 * @mdev: pointer to &struct media_device
1280 * @c: pointer to &struct v4l2_ext_controls
1282 * If hdl == NULL then they will all return -EINVAL.
1284 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1285 struct media_device *mdev,
1286 struct v4l2_ext_controls *c);
1289 * v4l2_s_ext_ctrls - Helper function to implement
1290 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1292 * @fh: pointer to &struct v4l2_fh
1293 * @hdl: pointer to &struct v4l2_ctrl_handler
1294 * @mdev: pointer to &struct media_device
1295 * @c: pointer to &struct v4l2_ext_controls
1297 * If hdl == NULL then they will all return -EINVAL.
1299 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1300 struct media_device *mdev,
1301 struct v4l2_ext_controls *c);
1304 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
1305 * as a &struct v4l2_subdev_core_ops subscribe_event function
1306 * that just subscribes control events.
1308 * @sd: pointer to &struct v4l2_subdev
1309 * @fh: pointer to &struct v4l2_fh
1310 * @sub: pointer to &struct v4l2_event_subscription
1312 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1313 struct v4l2_event_subscription *sub);
1316 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1319 * @sd: pointer to &struct v4l2_subdev
1321 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);