/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* V4L2 controls support header.3*4* Copyright (C) 2010 Hans Verkuil <[email protected]>5*/67#ifndef _V4L2_CTRLS_H8#define _V4L2_CTRLS_H910#include <linux/list.h>11#include <linux/mutex.h>12#include <linux/videodev2.h>13#include <media/media-request.h>1415/* forward references */16struct file;17struct poll_table_struct;18struct v4l2_ctrl;19struct v4l2_ctrl_handler;20struct v4l2_ctrl_helper;21struct v4l2_fh;22struct v4l2_fwnode_device_properties;23struct v4l2_subdev;24struct v4l2_subscribed_event;25struct video_device;2627/**28* union v4l2_ctrl_ptr - A pointer to a control value.29* @p_s32: Pointer to a 32-bit signed value.30* @p_s64: Pointer to a 64-bit signed value.31* @p_u8: Pointer to a 8-bit unsigned value.32* @p_u16: Pointer to a 16-bit unsigned value.33* @p_u32: Pointer to a 32-bit unsigned value.34* @p_char: Pointer to a string.35* @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure.36* @p_mpeg2_picture: Pointer to a MPEG2 picture structure.37* @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure.38* @p_fwht_params: Pointer to a FWHT stateless parameters structure.39* @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.40* @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.41* @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.42* @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.43* @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.44* @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.45* @p_vp8_frame: Pointer to a VP8 frame params structure.46* @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.47* @p_vp9_frame: Pointer to a VP9 frame params structure.48* @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.49* @p_hevc_pps: Pointer to an HEVC picture parameter set structure.50* @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.51* @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure.52* @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure.53* @p_area: Pointer to an area.54* @p_av1_sequence: Pointer to an AV1 sequence structure.55* @p_av1_tile_group_entry: Pointer to an AV1 tile group entry structure.56* @p_av1_frame: Pointer to an AV1 frame structure.57* @p_av1_film_grain: Pointer to an AV1 film grain structure.58* @p_rect: Pointer to a rectangle.59* @p: Pointer to a compound value.60* @p_const: Pointer to a constant compound value.61*/62union v4l2_ctrl_ptr {63s32 *p_s32;64s64 *p_s64;65u8 *p_u8;66u16 *p_u16;67u32 *p_u32;68char *p_char;69struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence;70struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture;71struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation;72struct v4l2_ctrl_fwht_params *p_fwht_params;73struct v4l2_ctrl_h264_sps *p_h264_sps;74struct v4l2_ctrl_h264_pps *p_h264_pps;75struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;76struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;77struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;78struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;79struct v4l2_ctrl_vp8_frame *p_vp8_frame;80struct v4l2_ctrl_hevc_sps *p_hevc_sps;81struct v4l2_ctrl_hevc_pps *p_hevc_pps;82struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;83struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs;84struct v4l2_ctrl_vp9_frame *p_vp9_frame;85struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;86struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;87struct v4l2_area *p_area;88struct v4l2_ctrl_av1_sequence *p_av1_sequence;89struct v4l2_ctrl_av1_tile_group_entry *p_av1_tile_group_entry;90struct v4l2_ctrl_av1_frame *p_av1_frame;91struct v4l2_ctrl_av1_film_grain *p_av1_film_grain;92struct v4l2_rect *p_rect;93void *p;94const void *p_const;95};9697/**98* v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a99* void pointer100* @ptr: The void pointer101*/102static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)103{104union v4l2_ctrl_ptr p = { .p = ptr };105106return p;107}108109/**110* struct v4l2_ctrl_ops - The control operations that the driver has to provide.111*112* @g_volatile_ctrl: Get a new value for this control. Generally only relevant113* for volatile (and usually read-only) controls such as a control114* that returns the current signal strength which changes115* continuously.116* If not set, then the currently cached value will be returned.117* @try_ctrl: Test whether the control's value is valid. Only relevant when118* the usual min/max/step checks are not sufficient.119* @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The120* ctrl->handler->lock is held when these ops are called, so no121* one else can access controls owned by that handler.122*/123struct v4l2_ctrl_ops {124int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);125int (*try_ctrl)(struct v4l2_ctrl *ctrl);126int (*s_ctrl)(struct v4l2_ctrl *ctrl);127};128129/**130* struct v4l2_ctrl_type_ops - The control type operations that the driver131* has to provide.132*133* @equal: return true if all ctrl->elems array elements are equal.134* @init: initialize the value for array elements from from_idx to ctrl->elems.135* @minimum: set the value to the minimum value of the control.136* @maximum: set the value to the maximum value of the control.137* @log: log the value.138* @validate: validate the value for ctrl->new_elems array elements.139* Return 0 on success and a negative value otherwise.140*/141struct v4l2_ctrl_type_ops {142bool (*equal)(const struct v4l2_ctrl *ctrl,143union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2);144void (*init)(const struct v4l2_ctrl *ctrl, u32 from_idx,145union v4l2_ctrl_ptr ptr);146void (*minimum)(const struct v4l2_ctrl *ctrl, u32 idx,147union v4l2_ctrl_ptr ptr);148void (*maximum)(const struct v4l2_ctrl *ctrl, u32 idx,149union v4l2_ctrl_ptr ptr);150void (*log)(const struct v4l2_ctrl *ctrl);151int (*validate)(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);152};153154/**155* typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function156* that should be called when a control value has changed.157*158* @ctrl: pointer to struct &v4l2_ctrl159* @priv: control private data160*161* This typedef definition is used as an argument to v4l2_ctrl_notify()162* and as an argument at struct &v4l2_ctrl_handler.163*/164typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);165166/**167* struct v4l2_ctrl - The control structure.168*169* @node: The list node.170* @ev_subs: The list of control event subscriptions.171* @handler: The handler that owns the control.172* @cluster: Point to start of cluster array.173* @ncontrols: Number of controls in cluster array.174* @done: Internal flag: set for each processed control.175* @is_new: Set when the user specified a new value for this control. It176* is also set when called from v4l2_ctrl_handler_setup(). Drivers177* should never set this flag.178* @has_changed: Set when the current value differs from the new value. Drivers179* should never use this flag.180* @is_private: If set, then this control is private to its handler and it181* will not be added to any other handlers. Drivers can set182* this flag.183* @is_auto: If set, then this control selects whether the other cluster184* members are in 'automatic' mode or 'manual' mode. This is185* used for autogain/gain type clusters. Drivers should never186* set this flag directly.187* @is_int: If set, then this control has a simple integer value (i.e. it188* uses ctrl->val).189* @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.190* @is_ptr: If set, then this control is an array and/or has type >=191* %V4L2_CTRL_COMPOUND_TYPES192* and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct193* v4l2_ext_control uses field p to point to the data.194* @is_array: If set, then this control contains an N-dimensional array.195* @is_dyn_array: If set, then this control contains a dynamically sized 1-dimensional array.196* If this is set, then @is_array is also set.197* @has_volatiles: If set, then one or more members of the cluster are volatile.198* Drivers should never touch this flag.199* @call_notify: If set, then call the handler's notify function whenever the200* control's value changes.201* @manual_mode_value: If the is_auto flag is set, then this is the value202* of the auto control that determines if that control is in203* manual mode. So if the value of the auto control equals this204* value, then the whole cluster is in manual mode. Drivers should205* never set this flag directly.206* @ops: The control ops.207* @type_ops: The control type ops.208* @id: The control ID.209* @name: The control name.210* @type: The control type.211* @minimum: The control's minimum value.212* @maximum: The control's maximum value.213* @default_value: The control's default value.214* @step: The control's step value for non-menu controls.215* @elems: The number of elements in the N-dimensional array.216* @elem_size: The size in bytes of the control.217* @new_elems: The number of elements in p_new. This is the same as @elems,218* except for dynamic arrays. In that case it is in the range of219* 1 to @p_array_alloc_elems.220* @dims: The size of each dimension.221* @nr_of_dims:The number of dimensions in @dims.222* @menu_skip_mask: The control's skip mask for menu controls. This makes it223* easy to skip menu items that are not valid. If bit X is set,224* then menu item X is skipped. Of course, this only works for225* menus with <= 32 menu items. There are no menus that come226* close to that number, so this is OK. Should we ever need more,227* then this will have to be extended to a u64 or a bit array.228* @qmenu: A const char * array for all menu items. Array entries that are229* empty strings ("") correspond to non-existing menu items (this230* is in addition to the menu_skip_mask above). The last entry231* must be NULL.232* Used only if the @type is %V4L2_CTRL_TYPE_MENU.233* @qmenu_int: A 64-bit integer array for with integer menu items.234* The size of array must be equal to the menu size, e. g.:235* :math:`ceil(\frac{maximum - minimum}{step}) + 1`.236* Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.237* @flags: The control's flags.238* @priv: The control's private pointer. For use by the driver. It is239* untouched by the control framework. Note that this pointer is240* not freed when the control is deleted. Should this be needed241* then a new internal bitfield can be added to tell the framework242* to free this pointer.243* @p_array: Pointer to the allocated array. Only valid if @is_array is true.244* @p_array_alloc_elems: The number of elements in the allocated245* array for both the cur and new values. So @p_array is actually246* sized for 2 * @p_array_alloc_elems * @elem_size. Only valid if247* @is_array is true.248* @cur: Structure to store the current value.249* @cur.val: The control's current value, if the @type is represented via250* a u32 integer (see &enum v4l2_ctrl_type).251* @val: The control's new s32 value.252* @p_def: The control's default value represented via a union which253* provides a standard way of accessing control types254* through a pointer (for compound controls only).255* @p_min: The control's minimum value represented via a union which256* provides a standard way of accessing control types257* through a pointer (for compound controls only).258* @p_max: The control's maximum value represented via a union which259* provides a standard way of accessing control types260* through a pointer (for compound controls only).261* @p_cur: The control's current value represented via a union which262* provides a standard way of accessing control types263* through a pointer.264* @p_new: The control's new value represented via a union which provides265* a standard way of accessing control types266* through a pointer.267*/268struct v4l2_ctrl {269/* Administrative fields */270struct list_head node;271struct list_head ev_subs;272struct v4l2_ctrl_handler *handler;273struct v4l2_ctrl **cluster;274unsigned int ncontrols;275276unsigned int done:1;277278unsigned int is_new:1;279unsigned int has_changed:1;280unsigned int is_private:1;281unsigned int is_auto:1;282unsigned int is_int:1;283unsigned int is_string:1;284unsigned int is_ptr:1;285unsigned int is_array:1;286unsigned int is_dyn_array:1;287unsigned int has_volatiles:1;288unsigned int call_notify:1;289unsigned int manual_mode_value:8;290291const struct v4l2_ctrl_ops *ops;292const struct v4l2_ctrl_type_ops *type_ops;293u32 id;294const char *name;295enum v4l2_ctrl_type type;296s64 minimum, maximum, default_value;297u32 elems;298u32 elem_size;299u32 new_elems;300u32 dims[V4L2_CTRL_MAX_DIMS];301u32 nr_of_dims;302union {303u64 step;304u64 menu_skip_mask;305};306union {307const char * const *qmenu;308const s64 *qmenu_int;309};310unsigned long flags;311void *priv;312void *p_array;313u32 p_array_alloc_elems;314s32 val;315struct {316s32 val;317} cur;318319union v4l2_ctrl_ptr p_def;320union v4l2_ctrl_ptr p_min;321union v4l2_ctrl_ptr p_max;322union v4l2_ctrl_ptr p_new;323union v4l2_ctrl_ptr p_cur;324};325326/**327* struct v4l2_ctrl_ref - The control reference.328*329* @node: List node for the sorted list.330* @next: Single-link list node for the hash.331* @ctrl: The actual control information.332* @helper: Pointer to helper struct. Used internally in333* ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.334* @from_other_dev: If true, then @ctrl was defined in another335* device than the &struct v4l2_ctrl_handler.336* @req_done: Internal flag: if the control handler containing this control337* reference is bound to a media request, then this is set when338* the control has been applied. This prevents applying controls339* from a cluster with multiple controls twice (when the first340* control of a cluster is applied, they all are).341* @p_req_valid: If set, then p_req contains the control value for the request.342* @p_req_array_enomem: If set, then p_req is invalid since allocating space for343* an array failed. Attempting to read this value shall344* result in ENOMEM. Only valid if ctrl->is_array is true.345* @p_req_array_alloc_elems: The number of elements allocated for the346* array. Only valid if @p_req_valid and ctrl->is_array are347* true.348* @p_req_elems: The number of elements in @p_req. This is the same as349* ctrl->elems, except for dynamic arrays. In that case it is in350* the range of 1 to @p_req_array_alloc_elems. Only valid if351* @p_req_valid is true.352* @p_req: If the control handler containing this control reference353* is bound to a media request, then this points to the354* value of the control that must be applied when the request355* is executed, or to the value of the control at the time356* that the request was completed. If @p_req_valid is false,357* then this control was never set for this request and the358* control will not be updated when this request is applied.359*360* Each control handler has a list of these refs. The list_head is used to361* keep a sorted-by-control-ID list of all controls, while the next pointer362* is used to link the control in the hash's bucket.363*/364struct v4l2_ctrl_ref {365struct list_head node;366struct v4l2_ctrl_ref *next;367struct v4l2_ctrl *ctrl;368struct v4l2_ctrl_helper *helper;369bool from_other_dev;370bool req_done;371bool p_req_valid;372bool p_req_array_enomem;373u32 p_req_array_alloc_elems;374u32 p_req_elems;375union v4l2_ctrl_ptr p_req;376};377378/**379* struct v4l2_ctrl_handler - The control handler keeps track of all the380* controls: both the controls owned by the handler and those inherited381* from other handlers.382*383* @_lock: Default for "lock".384* @lock: Lock to control access to this handler and its controls.385* May be replaced by the user right after init.386* @ctrls: The list of controls owned by this handler.387* @ctrl_refs: The list of control references.388* @cached: The last found control reference. It is common that the same389* control is needed multiple times, so this is a simple390* optimization.391* @buckets: Buckets for the hashing. Allows for quick control lookup.392* @notify: A notify callback that is called whenever the control changes393* value.394* Note that the handler's lock is held when the notify function395* is called!396* @notify_priv: Passed as argument to the v4l2_ctrl notify callback.397* @nr_of_buckets: Total number of buckets in the array.398* @error: The error code of the first failed control addition.399* @request_is_queued: True if the request was queued.400* @requests: List to keep track of open control handler request objects.401* For the parent control handler (@req_obj.ops == NULL) this402* is the list header. When the parent control handler is403* removed, it has to unbind and put all these requests since404* they refer to the parent.405* @requests_queued: List of the queued requests. This determines the order406* in which these controls are applied. Once the request is407* completed it is removed from this list.408* @req_obj: The &struct media_request_object, used to link into a409* &struct media_request. This request object has a refcount.410*/411struct v4l2_ctrl_handler {412struct mutex _lock;413struct mutex *lock;414struct list_head ctrls;415struct list_head ctrl_refs;416struct v4l2_ctrl_ref *cached;417struct v4l2_ctrl_ref **buckets;418v4l2_ctrl_notify_fnc notify;419void *notify_priv;420u16 nr_of_buckets;421int error;422bool request_is_queued;423struct list_head requests;424struct list_head requests_queued;425struct media_request_object req_obj;426};427428/**429* struct v4l2_ctrl_config - Control configuration structure.430*431* @ops: The control ops.432* @type_ops: The control type ops. Only needed for compound controls.433* @id: The control ID.434* @name: The control name.435* @type: The control type.436* @min: The control's minimum value.437* @max: The control's maximum value.438* @step: The control's step value for non-menu controls.439* @def: The control's default value.440* @p_def: The control's default value for compound controls.441* @p_min: The control's minimum value for compound controls.442* @p_max: The control's maximum value for compound controls.443* @dims: The size of each dimension.444* @elem_size: The size in bytes of the control.445* @flags: The control's flags.446* @menu_skip_mask: The control's skip mask for menu controls. This makes it447* easy to skip menu items that are not valid. If bit X is set,448* then menu item X is skipped. Of course, this only works for449* menus with <= 64 menu items. There are no menus that come450* close to that number, so this is OK. Should we ever need more,451* then this will have to be extended to a bit array.452* @qmenu: A const char * array for all menu items. Array entries that are453* empty strings ("") correspond to non-existing menu items (this454* is in addition to the menu_skip_mask above). The last entry455* must be NULL.456* @qmenu_int: A const s64 integer array for all menu items of the type457* V4L2_CTRL_TYPE_INTEGER_MENU.458* @is_private: If set, then this control is private to its handler and it459* will not be added to any other handlers.460*/461struct v4l2_ctrl_config {462const struct v4l2_ctrl_ops *ops;463const struct v4l2_ctrl_type_ops *type_ops;464u32 id;465const char *name;466enum v4l2_ctrl_type type;467s64 min;468s64 max;469u64 step;470s64 def;471union v4l2_ctrl_ptr p_def;472union v4l2_ctrl_ptr p_min;473union v4l2_ctrl_ptr p_max;474u32 dims[V4L2_CTRL_MAX_DIMS];475u32 elem_size;476u32 flags;477u64 menu_skip_mask;478const char * const *qmenu;479const s64 *qmenu_int;480unsigned int is_private:1;481};482483/**484* v4l2_ctrl_fill - Fill in the control fields based on the control ID.485*486* @id: ID of the control487* @name: pointer to be filled with a string with the name of the control488* @type: pointer for storing the type of the control489* @min: pointer for storing the minimum value for the control490* @max: pointer for storing the maximum value for the control491* @step: pointer for storing the control step492* @def: pointer for storing the default value for the control493* @flags: pointer for storing the flags to be used on the control494*495* This works for all standard V4L2 controls.496* For non-standard controls it will only fill in the given arguments497* and @name content will be set to %NULL.498*499* This function will overwrite the contents of @name, @type and @flags.500* The contents of @min, @max, @step and @def may be modified depending on501* the type.502*503* .. note::504*505* Do not use in drivers! It is used internally for backwards compatibility506* control handling only. Once all drivers are converted to use the new507* control framework this function will no longer be exported.508*/509void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,510s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);511512513/**514* v4l2_ctrl_handler_init_class() - Initialize the control handler.515* @hdl: The control handler.516* @nr_of_controls_hint: A hint of how many controls this handler is517* expected to refer to. This is the total number, so including518* any inherited controls. It doesn't have to be precise, but if519* it is way off, then you either waste memory (too many buckets520* are allocated) or the control lookup becomes slower (not enough521* buckets are allocated, so there are more slow list lookups).522* It will always work, though.523* @key: Used by the lock validator if CONFIG_LOCKDEP is set.524* @name: Used by the lock validator if CONFIG_LOCKDEP is set.525*526* .. attention::527*528* Never use this call directly, always use the v4l2_ctrl_handler_init()529* macro that hides the @key and @name arguments.530*531* Return: returns an error if the buckets could not be allocated. This532* error will also be stored in @hdl->error.533*/534int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,535unsigned int nr_of_controls_hint,536struct lock_class_key *key, const char *name);537538#ifdef CONFIG_LOCKDEP539540/**541* v4l2_ctrl_handler_init - helper function to create a static struct542* &lock_class_key and calls v4l2_ctrl_handler_init_class()543*544* @hdl: The control handler.545* @nr_of_controls_hint: A hint of how many controls this handler is546* expected to refer to. This is the total number, so including547* any inherited controls. It doesn't have to be precise, but if548* it is way off, then you either waste memory (too many buckets549* are allocated) or the control lookup becomes slower (not enough550* buckets are allocated, so there are more slow list lookups).551* It will always work, though.552*553* This helper function creates a static struct &lock_class_key and554* calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock555* validador.556*557* Use this helper function to initialize a control handler.558*/559#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \560( \561({ \562static struct lock_class_key _key; \563v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \564&_key, \565KBUILD_BASENAME ":" \566__stringify(__LINE__) ":" \567"(" #hdl ")->_lock"); \568}) \569)570#else571#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \572v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)573#endif574575/**576* v4l2_ctrl_handler_free() - Free all controls owned by the handler and free577* the control list.578* @hdl: The control handler.579*580* Does nothing if @hdl == NULL.581*582* Return: @hdl's error field or 0 if @hdl is NULL.583*/584int v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);585586/**587* v4l2_ctrl_lock() - Helper function to lock the handler588* associated with the control.589* @ctrl: The control to lock.590*/591static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)592{593mutex_lock(ctrl->handler->lock);594}595596/**597* v4l2_ctrl_unlock() - Helper function to unlock the handler598* associated with the control.599* @ctrl: The control to unlock.600*/601static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)602{603mutex_unlock(ctrl->handler->lock);604}605606/**607* __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging608* to the handler to initialize the hardware to the current control values. The609* caller is responsible for acquiring the control handler mutex on behalf of610* __v4l2_ctrl_handler_setup().611* @hdl: The control handler.612*613* Button controls will be skipped, as are read-only controls.614*615* If @hdl == NULL, then this just returns 0.616*/617int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);618619/**620* v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging621* to the handler to initialize the hardware to the current control values.622* @hdl: The control handler.623*624* Button controls will be skipped, as are read-only controls.625*626* If @hdl == NULL, then this just returns 0.627*/628int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);629630/**631* v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.632* @hdl: The control handler.633* @prefix: The prefix to use when logging the control values. If the634* prefix does not end with a space, then ": " will be added635* after the prefix. If @prefix == NULL, then no prefix will be636* used.637*638* For use with VIDIOC_LOG_STATUS.639*640* Does nothing if @hdl == NULL.641*/642void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,643const char *prefix);644645/**646* v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2647* control.648*649* @hdl: The control handler.650* @cfg: The control's configuration data.651* @priv: The control's driver-specific private data.652*653* If the &v4l2_ctrl struct could not be allocated then NULL is returned654* and @hdl->error is set to the error code (if it wasn't set already).655*/656struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,657const struct v4l2_ctrl_config *cfg,658void *priv);659660/**661* v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu662* control.663*664* @hdl: The control handler.665* @ops: The control ops.666* @id: The control ID.667* @min: The control's minimum value.668* @max: The control's maximum value.669* @step: The control's step value670* @def: The control's default value.671*672* If the &v4l2_ctrl struct could not be allocated, or the control673* ID is not known, then NULL is returned and @hdl->error is set to the674* appropriate error code (if it wasn't set already).675*676* If @id refers to a menu control, then this function will return NULL.677*678* Use v4l2_ctrl_new_std_menu() when adding menu controls.679*/680struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,681const struct v4l2_ctrl_ops *ops,682u32 id, s64 min, s64 max, u64 step,683s64 def);684685/**686* v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2687* menu control.688*689* @hdl: The control handler.690* @ops: The control ops.691* @id: The control ID.692* @max: The control's maximum value.693* @mask: The control's skip mask for menu controls. This makes it694* easy to skip menu items that are not valid. If bit X is set,695* then menu item X is skipped. Of course, this only works for696* menus with <= 64 menu items. There are no menus that come697* close to that number, so this is OK. Should we ever need more,698* then this will have to be extended to a bit array.699* @def: The control's default value.700*701* Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value702* determines which menu items are to be skipped.703*704* If @id refers to a non-menu control, then this function will return NULL.705*/706struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,707const struct v4l2_ctrl_ops *ops,708u32 id, u8 max, u64 mask, u8 def);709710/**711* v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control712* with driver specific menu.713*714* @hdl: The control handler.715* @ops: The control ops.716* @id: The control ID.717* @max: The control's maximum value.718* @mask: The control's skip mask for menu controls. This makes it719* easy to skip menu items that are not valid. If bit X is set,720* then menu item X is skipped. Of course, this only works for721* menus with <= 64 menu items. There are no menus that come722* close to that number, so this is OK. Should we ever need more,723* then this will have to be extended to a bit array.724* @def: The control's default value.725* @qmenu: The new menu.726*727* Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific728* menu of this control.729*730*/731struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,732const struct v4l2_ctrl_ops *ops,733u32 id, u8 max,734u64 mask, u8 def,735const char * const *qmenu);736737/**738* v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2739* compound control.740*741* @hdl: The control handler.742* @ops: The control ops.743* @id: The control ID.744* @p_def: The control's default value.745* @p_min: The control's minimum value.746* @p_max: The control's maximum value.747*748* Same as v4l2_ctrl_new_std(), but with support for compound controls.749* To fill in the @p_def, @p_min and @p_max fields, use v4l2_ctrl_ptr_create()750* to convert a pointer to a const union v4l2_ctrl_ptr.751* Use v4l2_ctrl_ptr_create(NULL) if you want the default, minimum or maximum752* value of the compound control to be all zeroes.753* If the compound control does not set the ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX``754* flag, then it does not has minimum and maximum values. In that case just use755* v4l2_ctrl_ptr_create(NULL) for the @p_min and @p_max arguments.756*757*/758struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,759const struct v4l2_ctrl_ops *ops,760u32 id,761const union v4l2_ctrl_ptr p_def,762const union v4l2_ctrl_ptr p_min,763const union v4l2_ctrl_ptr p_max);764765/**766* v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.767*768* @hdl: The control handler.769* @ops: The control ops.770* @id: The control ID.771* @max: The control's maximum value.772* @def: The control's default value.773* @qmenu_int: The control's menu entries.774*775* Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally776* takes as an argument an array of integers determining the menu items.777*778* If @id refers to a non-integer-menu control, then this function will779* return %NULL.780*/781struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,782const struct v4l2_ctrl_ops *ops,783u32 id, u8 max, u8 def,784const s64 *qmenu_int);785786/**787* typedef v4l2_ctrl_filter - Typedef to define the filter function to be788* used when adding a control handler.789*790* @ctrl: pointer to struct &v4l2_ctrl.791*/792793typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);794795/**796* v4l2_ctrl_add_handler() - Add all controls from handler @add to797* handler @hdl.798*799* @hdl: The control handler.800* @add: The control handler whose controls you want to add to801* the @hdl control handler.802* @filter: This function will filter which controls should be added.803* @from_other_dev: If true, then the controls in @add were defined in another804* device than @hdl.805*806* Does nothing if either of the two handlers is a NULL pointer.807* If @filter is NULL, then all controls are added. Otherwise only those808* controls for which @filter returns true will be added.809* In case of an error @hdl->error will be set to the error code (if it810* wasn't set already).811*/812int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,813struct v4l2_ctrl_handler *add,814v4l2_ctrl_filter filter,815bool from_other_dev);816817/**818* v4l2_ctrl_radio_filter() - Standard filter for radio controls.819*820* @ctrl: The control that is filtered.821*822* This will return true for any controls that are valid for radio device823* nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM824* transmitter class controls.825*826* This function is to be used with v4l2_ctrl_add_handler().827*/828bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);829830/**831* v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging832* to that cluster.833*834* @ncontrols: The number of controls in this cluster.835* @controls: The cluster control array of size @ncontrols.836*/837void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);838839840/**841* v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging842* to that cluster and set it up for autofoo/foo-type handling.843*844* @ncontrols: The number of controls in this cluster.845* @controls: The cluster control array of size @ncontrols. The first control846* must be the 'auto' control (e.g. autogain, autoexposure, etc.)847* @manual_val: The value for the first control in the cluster that equals the848* manual setting.849* @set_volatile: If true, then all controls except the first auto control will850* be volatile.851*852* Use for control groups where one control selects some automatic feature and853* the other controls are only active whenever the automatic feature is turned854* off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs855* red and blue balance, etc.856*857* The behavior of such controls is as follows:858*859* When the autofoo control is set to automatic, then any manual controls860* are set to inactive and any reads will call g_volatile_ctrl (if the control861* was marked volatile).862*863* When the autofoo control is set to manual, then any manual controls will864* be marked active, and any reads will just return the current value without865* going through g_volatile_ctrl.866*867* In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag868* on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)869* if autofoo is in auto mode.870*/871void v4l2_ctrl_auto_cluster(unsigned int ncontrols,872struct v4l2_ctrl **controls,873u8 manual_val, bool set_volatile);874875876/**877* v4l2_ctrl_find() - Find a control with the given ID.878*879* @hdl: The control handler.880* @id: The control ID to find.881*882* If @hdl == NULL this will return NULL as well. Will lock the handler so883* do not use from inside &v4l2_ctrl_ops.884*/885struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);886887/**888* v4l2_ctrl_activate() - Make the control active or inactive.889* @ctrl: The control to (de)activate.890* @active: True if the control should become active.891*892* This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.893* Does nothing if @ctrl == NULL.894* This will usually be called from within the s_ctrl op.895* The V4L2_EVENT_CTRL event will be generated afterwards.896*897* This function assumes that the control handler is locked.898*/899void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);900901/**902* __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.903*904* @ctrl: The control to (de)activate.905* @grabbed: True if the control should become grabbed.906*907* This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.908* Does nothing if @ctrl == NULL.909* The V4L2_EVENT_CTRL event will be generated afterwards.910* This will usually be called when starting or stopping streaming in the911* driver.912*913* This function assumes that the control handler is locked by the caller.914*/915void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);916917/**918* v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.919*920* @ctrl: The control to (de)activate.921* @grabbed: True if the control should become grabbed.922*923* This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.924* Does nothing if @ctrl == NULL.925* The V4L2_EVENT_CTRL event will be generated afterwards.926* This will usually be called when starting or stopping streaming in the927* driver.928*929* This function assumes that the control handler is not locked and will930* take the lock itself.931*/932static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)933{934if (!ctrl)935return;936937v4l2_ctrl_lock(ctrl);938__v4l2_ctrl_grab(ctrl, grabbed);939v4l2_ctrl_unlock(ctrl);940}941942/**943*__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()944*945* @ctrl: The control to update.946* @min: The control's minimum value.947* @max: The control's maximum value.948* @step: The control's step value949* @def: The control's default value.950*951* Update the range of a control on the fly. This works for control types952* INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the953* @step value is interpreted as a menu_skip_mask.954*955* An error is returned if one of the range arguments is invalid for this956* control type.957*958* The caller is responsible for acquiring the control handler mutex on behalf959* of __v4l2_ctrl_modify_range().960*/961int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,962s64 min, s64 max, u64 step, s64 def);963964/**965* v4l2_ctrl_modify_range() - Update the range of a control.966*967* @ctrl: The control to update.968* @min: The control's minimum value.969* @max: The control's maximum value.970* @step: The control's step value971* @def: The control's default value.972*973* Update the range of a control on the fly. This works for control types974* INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the975* @step value is interpreted as a menu_skip_mask.976*977* An error is returned if one of the range arguments is invalid for this978* control type.979*980* This function assumes that the control handler is not locked and will981* take the lock itself.982*/983static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,984s64 min, s64 max, u64 step, s64 def)985{986int rval;987988v4l2_ctrl_lock(ctrl);989rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);990v4l2_ctrl_unlock(ctrl);991992return rval;993}994995/**996*__v4l2_ctrl_modify_dimensions() - Unlocked variant of v4l2_ctrl_modify_dimensions()997*998* @ctrl: The control to update.999* @dims: The control's new dimensions.1000*1001* Update the dimensions of an array control on the fly. The elements of the1002* array are reset to their default value, even if the dimensions are1003* unchanged.1004*1005* An error is returned if @dims is invalid for this control.1006*1007* The caller is responsible for acquiring the control handler mutex on behalf1008* of __v4l2_ctrl_modify_dimensions().1009*1010* Note: calling this function when the same control is used in pending requests1011* is untested. It should work (a request with the wrong size of the control1012* will drop that control silently), but it will be very confusing.1013*/1014int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,1015u32 dims[V4L2_CTRL_MAX_DIMS]);10161017/**1018* v4l2_ctrl_modify_dimensions() - Update the dimensions of an array control.1019*1020* @ctrl: The control to update.1021* @dims: The control's new dimensions.1022*1023* Update the dimensions of an array control on the fly. The elements of the1024* array are reset to their default value, even if the dimensions are1025* unchanged.1026*1027* An error is returned if @dims is invalid for this control type.1028*1029* This function assumes that the control handler is not locked and will1030* take the lock itself.1031*1032* Note: calling this function when the same control is used in pending requests1033* is untested. It should work (a request with the wrong size of the control1034* will drop that control silently), but it will be very confusing.1035*/1036static inline int v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,1037u32 dims[V4L2_CTRL_MAX_DIMS])1038{1039int rval;10401041v4l2_ctrl_lock(ctrl);1042rval = __v4l2_ctrl_modify_dimensions(ctrl, dims);1043v4l2_ctrl_unlock(ctrl);10441045return rval;1046}10471048/**1049* v4l2_ctrl_notify() - Function to set a notify callback for a control.1050*1051* @ctrl: The control.1052* @notify: The callback function.1053* @priv: The callback private handle, passed as argument to the callback.1054*1055* This function sets a callback function for the control. If @ctrl is NULL,1056* then it will do nothing. If @notify is NULL, then the notify callback will1057* be removed.1058*1059* There can be only one notify. If another already exists, then a WARN_ON1060* will be issued and the function will do nothing.1061*/1062void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,1063void *priv);10641065/**1066* v4l2_ctrl_get_name() - Get the name of the control1067*1068* @id: The control ID.1069*1070* This function returns the name of the given control ID or NULL if it isn't1071* a known control.1072*/1073const char *v4l2_ctrl_get_name(u32 id);10741075/**1076* v4l2_ctrl_get_menu() - Get the menu string array of the control1077*1078* @id: The control ID.1079*1080* This function returns the NULL-terminated menu string array name of the1081* given control ID or NULL if it isn't a known menu control.1082*/1083const char * const *v4l2_ctrl_get_menu(u32 id);10841085/**1086* v4l2_ctrl_get_int_menu() - Get the integer menu array of the control1087*1088* @id: The control ID.1089* @len: The size of the integer array.1090*1091* This function returns the integer array of the given control ID or NULL if it1092* if it isn't a known integer menu control.1093*/1094const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);10951096/**1097* v4l2_ctrl_g_ctrl() - Helper function to get the control's value from1098* within a driver.1099*1100* @ctrl: The control.1101*1102* This returns the control's value safely by going through the control1103* framework. This function will lock the control's handler, so it cannot be1104* used from within the &v4l2_ctrl_ops functions.1105*1106* This function is for integer type controls only.1107*/1108s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);11091110/**1111* __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().1112*1113* @ctrl: The control.1114* @val: The new value.1115*1116* This sets the control's new value safely by going through the control1117* framework. This function assumes the control's handler is already locked,1118* allowing it to be used from within the &v4l2_ctrl_ops functions.1119*1120* This function is for integer type controls only.1121*/1122int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);11231124/**1125* v4l2_ctrl_s_ctrl() - Helper function to set the control's value from1126* within a driver.1127* @ctrl: The control.1128* @val: The new value.1129*1130* This sets the control's new value safely by going through the control1131* framework. This function will lock the control's handler, so it cannot be1132* used from within the &v4l2_ctrl_ops functions.1133*1134* This function is for integer type controls only.1135*/1136static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)1137{1138int rval;11391140v4l2_ctrl_lock(ctrl);1141rval = __v4l2_ctrl_s_ctrl(ctrl, val);1142v4l2_ctrl_unlock(ctrl);11431144return rval;1145}11461147/**1148* v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value1149* from within a driver.1150*1151* @ctrl: The control.1152*1153* This returns the control's value safely by going through the control1154* framework. This function will lock the control's handler, so it cannot be1155* used from within the &v4l2_ctrl_ops functions.1156*1157* This function is for 64-bit integer type controls only.1158*/1159s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);11601161/**1162* __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().1163*1164* @ctrl: The control.1165* @val: The new value.1166*1167* This sets the control's new value safely by going through the control1168* framework. This function assumes the control's handler is already locked,1169* allowing it to be used from within the &v4l2_ctrl_ops functions.1170*1171* This function is for 64-bit integer type controls only.1172*/1173int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);11741175/**1176* v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value1177* from within a driver.1178*1179* @ctrl: The control.1180* @val: The new value.1181*1182* This sets the control's new value safely by going through the control1183* framework. This function will lock the control's handler, so it cannot be1184* used from within the &v4l2_ctrl_ops functions.1185*1186* This function is for 64-bit integer type controls only.1187*/1188static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)1189{1190int rval;11911192v4l2_ctrl_lock(ctrl);1193rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);1194v4l2_ctrl_unlock(ctrl);11951196return rval;1197}11981199/**1200* __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().1201*1202* @ctrl: The control.1203* @s: The new string.1204*1205* This sets the control's new string safely by going through the control1206* framework. This function assumes the control's handler is already locked,1207* allowing it to be used from within the &v4l2_ctrl_ops functions.1208*1209* This function is for string type controls only.1210*/1211int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);12121213/**1214* v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value1215* from within a driver.1216*1217* @ctrl: The control.1218* @s: The new string.1219*1220* This sets the control's new string safely by going through the control1221* framework. This function will lock the control's handler, so it cannot be1222* used from within the &v4l2_ctrl_ops functions.1223*1224* This function is for string type controls only.1225*/1226static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)1227{1228int rval;12291230v4l2_ctrl_lock(ctrl);1231rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);1232v4l2_ctrl_unlock(ctrl);12331234return rval;1235}12361237/**1238* __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control1239*1240* @ctrl: The control.1241* @type: The type of the data.1242* @p: The new compound payload.1243*1244* This sets the control's new compound payload safely by going through the1245* control framework. This function assumes the control's handler is already1246* locked, allowing it to be used from within the &v4l2_ctrl_ops functions.1247*1248* This function is for compound type controls only.1249*/1250int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,1251enum v4l2_ctrl_type type, const void *p);12521253/**1254* v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control1255* from within a driver.1256*1257* @ctrl: The control.1258* @type: The type of the data.1259* @p: The new compound payload.1260*1261* This sets the control's new compound payload safely by going through the1262* control framework. This function will lock the control's handler, so it1263* cannot be used from within the &v4l2_ctrl_ops functions.1264*1265* This function is for compound type controls only.1266*/1267static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,1268enum v4l2_ctrl_type type,1269const void *p)1270{1271int rval;12721273v4l2_ctrl_lock(ctrl);1274rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);1275v4l2_ctrl_unlock(ctrl);12761277return rval;1278}12791280/* Helper defines for area type controls */1281#define __v4l2_ctrl_s_ctrl_area(ctrl, area) \1282__v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))1283#define v4l2_ctrl_s_ctrl_area(ctrl, area) \1284v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))12851286/* Internal helper functions that deal with control events. */1287extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;12881289/**1290* v4l2_ctrl_replace - Function to be used as a callback to1291* &struct v4l2_subscribed_event_ops replace\(\)1292*1293* @old: pointer to struct &v4l2_event with the reported1294* event;1295* @new: pointer to struct &v4l2_event with the modified1296* event;1297*/1298void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);12991300/**1301* v4l2_ctrl_merge - Function to be used as a callback to1302* &struct v4l2_subscribed_event_ops merge(\)1303*1304* @old: pointer to struct &v4l2_event with the reported1305* event;1306* @new: pointer to struct &v4l2_event with the merged1307* event;1308*/1309void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);13101311/**1312* v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl1313*1314* @file: pointer to struct file1315* @fh: unused. Kept just to be compatible to the arguments expected by1316* &struct v4l2_ioctl_ops.vidioc_log_status.1317*1318* Can be used as a vidioc_log_status function that just dumps all controls1319* associated with the filehandle.1320*/1321int v4l2_ctrl_log_status(struct file *file, void *fh);13221323/**1324* v4l2_ctrl_subscribe_event - Subscribes to an event1325*1326*1327* @fh: pointer to struct v4l2_fh1328* @sub: pointer to &struct v4l2_event_subscription1329*1330* Can be used as a vidioc_subscribe_event function that just subscribes1331* control events.1332*/1333int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,1334const struct v4l2_event_subscription *sub);13351336/**1337* v4l2_ctrl_poll - function to be used as a callback to the poll()1338* That just polls for control events.1339*1340* @file: pointer to struct file1341* @wait: pointer to struct poll_table_struct1342*/1343__poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);13441345/**1346* v4l2_ctrl_request_setup - helper function to apply control values in a request1347*1348* @req: The request1349* @parent: The parent control handler ('priv' in media_request_object_find())1350*1351* This is a helper function to call the control handler's s_ctrl callback with1352* the control values contained in the request. Do note that this approach of1353* applying control values in a request is only applicable to memory-to-memory1354* devices.1355*/1356int v4l2_ctrl_request_setup(struct media_request *req,1357struct v4l2_ctrl_handler *parent);13581359/**1360* v4l2_ctrl_request_complete - Complete a control handler request object1361*1362* @req: The request1363* @parent: The parent control handler ('priv' in media_request_object_find())1364*1365* This function is to be called on each control handler that may have had a1366* request object associated with it, i.e. control handlers of a driver that1367* supports requests.1368*1369* The function first obtains the values of any volatile controls in the control1370* handler and attach them to the request. Then, the function completes the1371* request object.1372*/1373void v4l2_ctrl_request_complete(struct media_request *req,1374struct v4l2_ctrl_handler *parent);13751376/**1377* v4l2_ctrl_request_hdl_find - Find the control handler in the request1378*1379* @req: The request1380* @parent: The parent control handler ('priv' in media_request_object_find())1381*1382* This function finds the control handler in the request. It may return1383* NULL if not found. When done, you must call v4l2_ctrl_request_hdl_put()1384* with the returned handler pointer.1385*1386* If the request is not in state VALIDATING or QUEUED, then this function1387* will always return NULL.1388*1389* Note that in state VALIDATING the req_queue_mutex is held, so1390* no objects can be added or deleted from the request.1391*1392* In state QUEUED it is the driver that will have to ensure this.1393*/1394struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,1395struct v4l2_ctrl_handler *parent);13961397/**1398* v4l2_ctrl_request_hdl_put - Put the control handler1399*1400* @hdl: Put this control handler1401*1402* This function released the control handler previously obtained from'1403* v4l2_ctrl_request_hdl_find().1404*/1405static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)1406{1407if (hdl)1408media_request_object_put(&hdl->req_obj);1409}14101411/**1412* v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID.1413*1414* @hdl: The control handler from the request.1415* @id: The ID of the control to find.1416*1417* This function returns a pointer to the control if this control is1418* part of the request or NULL otherwise.1419*/1420struct v4l2_ctrl *1421v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);14221423/* Helpers for ioctl_ops */14241425/**1426* v4l2_queryctrl - Helper function to implement1427* :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl1428*1429* @hdl: pointer to &struct v4l2_ctrl_handler1430* @qc: pointer to &struct v4l2_queryctrl1431*1432* If hdl == NULL then they will all return -EINVAL.1433*/1434int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);14351436/**1437* v4l2_query_ext_ctrl_to_v4l2_queryctrl - Convert a qec to qe.1438*1439* @to: The v4l2_queryctrl to write to.1440* @from: The v4l2_query_ext_ctrl to read from.1441*1442* This function is a helper to convert a v4l2_query_ext_ctrl into a1443* v4l2_queryctrl.1444*/1445void v4l2_query_ext_ctrl_to_v4l2_queryctrl(struct v4l2_queryctrl *to,1446const struct v4l2_query_ext_ctrl *from);14471448/**1449* v4l2_query_ext_ctrl - Helper function to implement1450* :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl1451*1452* @hdl: pointer to &struct v4l2_ctrl_handler1453* @qc: pointer to &struct v4l2_query_ext_ctrl1454*1455* If hdl == NULL then they will all return -EINVAL.1456*/1457int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,1458struct v4l2_query_ext_ctrl *qc);14591460/**1461* v4l2_querymenu - Helper function to implement1462* :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl1463*1464* @hdl: pointer to &struct v4l2_ctrl_handler1465* @qm: pointer to &struct v4l2_querymenu1466*1467* If hdl == NULL then they will all return -EINVAL.1468*/1469int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);14701471/**1472* v4l2_g_ctrl - Helper function to implement1473* :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl1474*1475* @hdl: pointer to &struct v4l2_ctrl_handler1476* @ctrl: pointer to &struct v4l2_control1477*1478* If hdl == NULL then they will all return -EINVAL.1479*/1480int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);14811482/**1483* v4l2_s_ctrl - Helper function to implement1484* :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl1485*1486* @fh: pointer to &struct v4l2_fh1487* @hdl: pointer to &struct v4l2_ctrl_handler1488*1489* @ctrl: pointer to &struct v4l2_control1490*1491* If hdl == NULL then they will all return -EINVAL.1492*/1493int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,1494struct v4l2_control *ctrl);14951496/**1497* v4l2_g_ext_ctrls - Helper function to implement1498* :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl1499*1500* @hdl: pointer to &struct v4l2_ctrl_handler1501* @vdev: pointer to &struct video_device1502* @mdev: pointer to &struct media_device1503* @c: pointer to &struct v4l2_ext_controls1504*1505* If hdl == NULL then they will all return -EINVAL.1506*/1507int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,1508struct media_device *mdev, struct v4l2_ext_controls *c);15091510/**1511* v4l2_try_ext_ctrls - Helper function to implement1512* :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl1513*1514* @hdl: pointer to &struct v4l2_ctrl_handler1515* @vdev: pointer to &struct video_device1516* @mdev: pointer to &struct media_device1517* @c: pointer to &struct v4l2_ext_controls1518*1519* If hdl == NULL then they will all return -EINVAL.1520*/1521int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,1522struct video_device *vdev,1523struct media_device *mdev,1524struct v4l2_ext_controls *c);15251526/**1527* v4l2_s_ext_ctrls - Helper function to implement1528* :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl1529*1530* @fh: pointer to &struct v4l2_fh1531* @hdl: pointer to &struct v4l2_ctrl_handler1532* @vdev: pointer to &struct video_device1533* @mdev: pointer to &struct media_device1534* @c: pointer to &struct v4l2_ext_controls1535*1536* If hdl == NULL then they will all return -EINVAL.1537*/1538int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,1539struct video_device *vdev,1540struct media_device *mdev,1541struct v4l2_ext_controls *c);15421543/**1544* v4l2_ctrl_subdev_subscribe_event - Helper function to implement1545* as a &struct v4l2_subdev_core_ops subscribe_event function1546* that just subscribes control events.1547*1548* @sd: pointer to &struct v4l2_subdev1549* @fh: pointer to &struct v4l2_fh1550* @sub: pointer to &struct v4l2_event_subscription1551*/1552int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,1553struct v4l2_event_subscription *sub);15541555/**1556* v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control1557* handler.1558*1559* @sd: pointer to &struct v4l2_subdev1560*/1561int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);15621563/**1564* v4l2_ctrl_new_fwnode_properties() - Register controls for the device1565* properties1566*1567* @hdl: pointer to &struct v4l2_ctrl_handler to register controls on1568* @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with1569* @p: pointer to &struct v4l2_fwnode_device_properties1570*1571* This function registers controls associated to device properties, using the1572* property values contained in @p parameter, if the property has been set to1573* a value.1574*1575* Currently the following v4l2 controls are parsed and registered:1576* - V4L2_CID_CAMERA_ORIENTATION1577* - V4L2_CID_CAMERA_SENSOR_ROTATION;1578*1579* Controls already registered by the caller with the @hdl control handler are1580* not overwritten. Callers should register the controls they want to handle1581* themselves before calling this function.1582*1583* Return: 0 on success, a negative error code on failure.1584*/1585int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,1586const struct v4l2_ctrl_ops *ctrl_ops,1587const struct v4l2_fwnode_device_properties *p);15881589/**1590* v4l2_ctrl_type_op_equal - Default v4l2_ctrl_type_ops equal callback.1591*1592* @ctrl: The v4l2_ctrl pointer.1593* @ptr1: A v4l2 control value.1594* @ptr2: A v4l2 control value.1595*1596* Return: true if values are equal, otherwise false.1597*/1598bool v4l2_ctrl_type_op_equal(const struct v4l2_ctrl *ctrl,1599union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2);16001601/**1602* v4l2_ctrl_type_op_init - Default v4l2_ctrl_type_ops init callback.1603*1604* @ctrl: The v4l2_ctrl pointer.1605* @from_idx: Starting element index.1606* @ptr: The v4l2 control value.1607*1608* Return: void1609*/1610void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx,1611union v4l2_ctrl_ptr ptr);16121613/**1614* v4l2_ctrl_type_op_log - Default v4l2_ctrl_type_ops log callback.1615*1616* @ctrl: The v4l2_ctrl pointer.1617*1618* Return: void1619*/1620void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl);16211622/**1623* v4l2_ctrl_type_op_validate - Default v4l2_ctrl_type_ops validate callback.1624*1625* @ctrl: The v4l2_ctrl pointer.1626* @ptr: The v4l2 control value.1627*1628* Return: 0 on success, a negative error code on failure.1629*/1630int v4l2_ctrl_type_op_validate(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);16311632#endif163316341635