1c942fddfSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
20996517cSHans Verkuil /*
38ec4bee7SMauro Carvalho Chehab * V4L2 controls support header.
48ec4bee7SMauro Carvalho Chehab *
58ec4bee7SMauro Carvalho Chehab * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
60996517cSHans Verkuil */
70996517cSHans Verkuil
80996517cSHans Verkuil #ifndef _V4L2_CTRLS_H
90996517cSHans Verkuil #define _V4L2_CTRLS_H
100996517cSHans Verkuil
110996517cSHans Verkuil #include <linux/list.h>
12a19dec6eSAndrzej Hajda #include <linux/mutex.h>
1301c40c04SLaurent Pinchart #include <linux/videodev2.h>
1452beeddbSHans Verkuil #include <media/media-request.h>
150996517cSHans Verkuil
160996517cSHans Verkuil /* forward references */
17528f0f78SLaurent Pinchart struct file;
18ae6ff16cSJacopo Mondi struct poll_table_struct;
19ae6ff16cSJacopo Mondi struct v4l2_ctrl;
200996517cSHans Verkuil struct v4l2_ctrl_handler;
21eb5b16efSHans Verkuil struct v4l2_ctrl_helper;
22ae6ff16cSJacopo Mondi struct v4l2_fh;
23e0a36063SJacopo Mondi struct v4l2_fwnode_device_properties;
240996517cSHans Verkuil struct v4l2_subdev;
2577068d36SHans Verkuil struct v4l2_subscribed_event;
26ae6ff16cSJacopo Mondi struct video_device;
270996517cSHans Verkuil
288c2721d5SMauro Carvalho Chehab /**
298c2721d5SMauro Carvalho Chehab * union v4l2_ctrl_ptr - A pointer to a control value.
300176077aSHans Verkuil * @p_s32: Pointer to a 32-bit signed value.
310176077aSHans Verkuil * @p_s64: Pointer to a 64-bit signed value.
32dda4a4d5SHans Verkuil * @p_u8: Pointer to a 8-bit unsigned value.
33dda4a4d5SHans Verkuil * @p_u16: Pointer to a 16-bit unsigned value.
34811c5081SHans Verkuil * @p_u32: Pointer to a 32-bit unsigned value.
350176077aSHans Verkuil * @p_char: Pointer to a string.
36f329e21eSEzequiel Garcia * @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure.
37f329e21eSEzequiel Garcia * @p_mpeg2_picture: Pointer to a MPEG2 picture structure.
38118f3e15SEzequiel Garcia * @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure.
392495f39cSDafna Hirschfeld * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
401f0545d3SPawel Osciak * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
411f0545d3SPawel Osciak * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
421f0545d3SPawel Osciak * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
431f0545d3SPawel Osciak * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
441f0545d3SPawel Osciak * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
45eb44c6c9SEzequiel Garcia * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
46d04c114eSEzequiel Garcia * @p_vp8_frame: Pointer to a VP8 frame params structure.
47b88dbe38SAndrzej Pietrasiewicz * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.
48b88dbe38SAndrzej Pietrasiewicz * @p_vp9_frame: Pointer to a VP9 frame params structure.
49256fa392SPaul Kocialkowski * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
50256fa392SPaul Kocialkowski * @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
51256fa392SPaul Kocialkowski * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
521ad0de78SStanimir Varbanov * @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure.
531ad0de78SStanimir Varbanov * @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure.
54d1dc4937SRicardo Ribalda Delgado * @p_area: Pointer to an area.
550176077aSHans Verkuil * @p_av1_sequence: Pointer to an AV1 sequence structure.
56f1bd5eaeSRicardo Ribalda Delgado * @p_av1_tile_group_entry: Pointer to an AV1 tile group entry structure.
570176077aSHans Verkuil * @p_av1_frame: Pointer to an AV1 frame structure.
580176077aSHans Verkuil * @p_av1_film_grain: Pointer to an AV1 film grain structure.
590176077aSHans Verkuil * @p: Pointer to a compound value.
600176077aSHans Verkuil * @p_const: Pointer to a constant compound value.
61dda4a4d5SHans Verkuil */
62dda4a4d5SHans Verkuil union v4l2_ctrl_ptr {
63811c5081SHans Verkuil s32 *p_s32;
640176077aSHans Verkuil s64 *p_s64;
65f329e21eSEzequiel Garcia u8 *p_u8;
66f329e21eSEzequiel Garcia u16 *p_u16;
67118f3e15SEzequiel Garcia u32 *p_u32;
682495f39cSDafna Hirschfeld char *p_char;
691f0545d3SPawel Osciak struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence;
701f0545d3SPawel Osciak struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture;
711f0545d3SPawel Osciak struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation;
721f0545d3SPawel Osciak struct v4l2_ctrl_fwht_params *p_fwht_params;
731f0545d3SPawel Osciak struct v4l2_ctrl_h264_sps *p_h264_sps;
74eb44c6c9SEzequiel Garcia struct v4l2_ctrl_h264_pps *p_h264_pps;
75d04c114eSEzequiel Garcia struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
76256fa392SPaul Kocialkowski struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
77256fa392SPaul Kocialkowski struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
78256fa392SPaul Kocialkowski struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
79b88dbe38SAndrzej Pietrasiewicz struct v4l2_ctrl_vp8_frame *p_vp8_frame;
80b88dbe38SAndrzej Pietrasiewicz struct v4l2_ctrl_hevc_sps *p_hevc_sps;
811ad0de78SStanimir Varbanov struct v4l2_ctrl_hevc_pps *p_hevc_pps;
821ad0de78SStanimir Varbanov struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
83d1dc4937SRicardo Ribalda Delgado struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs;
840176077aSHans Verkuil struct v4l2_ctrl_vp9_frame *p_vp9_frame;
85f1bd5eaeSRicardo Ribalda Delgado struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
860176077aSHans Verkuil struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
870176077aSHans Verkuil struct v4l2_area *p_area;
888c2721d5SMauro Carvalho Chehab struct v4l2_ctrl_av1_sequence *p_av1_sequence;
892e8db63eSRicardo Ribalda Delgado struct v4l2_ctrl_av1_tile_group_entry *p_av1_tile_group_entry;
902e8db63eSRicardo Ribalda Delgado struct v4l2_ctrl_av1_frame *p_av1_frame;
912e8db63eSRicardo Ribalda Delgado struct v4l2_ctrl_av1_film_grain *p_av1_film_grain;
922e8db63eSRicardo Ribalda Delgado void *p;
932e8db63eSRicardo Ribalda Delgado const void *p_const;
942e8db63eSRicardo Ribalda Delgado };
952e8db63eSRicardo Ribalda Delgado
962e8db63eSRicardo Ribalda Delgado /**
972e8db63eSRicardo Ribalda Delgado * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
982e8db63eSRicardo Ribalda Delgado * void pointer
992e8db63eSRicardo Ribalda Delgado * @ptr: The void pointer
1002e8db63eSRicardo Ribalda Delgado */
v4l2_ctrl_ptr_create(void * ptr)1018c2721d5SMauro Carvalho Chehab static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
1028ec4bee7SMauro Carvalho Chehab {
1030996517cSHans Verkuil union v4l2_ctrl_ptr p = { .p = ptr };
1040996517cSHans Verkuil
1050996517cSHans Verkuil return p;
1060996517cSHans Verkuil }
1070996517cSHans Verkuil
1080996517cSHans Verkuil /**
1090996517cSHans Verkuil * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
1100996517cSHans Verkuil *
1110996517cSHans Verkuil * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
1120996517cSHans Verkuil * for volatile (and usually read-only) controls such as a control
1130996517cSHans Verkuil * that returns the current signal strength which changes
1140996517cSHans Verkuil * continuously.
1150996517cSHans Verkuil * If not set, then the currently cached value will be returned.
1160996517cSHans Verkuil * @try_ctrl: Test whether the control's value is valid. Only relevant when
1170996517cSHans Verkuil * the usual min/max/step checks are not sufficient.
1180996517cSHans Verkuil * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
1190996517cSHans Verkuil * ctrl->handler->lock is held when these ops are called, so no
1208c2721d5SMauro Carvalho Chehab * one else can access controls owned by that handler.
1218c2721d5SMauro Carvalho Chehab */
1228c2721d5SMauro Carvalho Chehab struct v4l2_ctrl_ops {
1238c2721d5SMauro Carvalho Chehab int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
124cd75981eSHans Verkuil int (*try_ctrl)(struct v4l2_ctrl *ctrl);
125cd75981eSHans Verkuil int (*s_ctrl)(struct v4l2_ctrl *ctrl);
1260176077aSHans Verkuil };
127cd75981eSHans Verkuil
128cd75981eSHans Verkuil /**
1290176077aSHans Verkuil * struct v4l2_ctrl_type_ops - The control type operations that the driver
1300176077aSHans Verkuil * has to provide.
131cd75981eSHans Verkuil *
132cd75981eSHans Verkuil * @equal: return true if all ctrl->elems array elements are equal.
133cd75981eSHans Verkuil * @init: initialize the value for array elements from from_idx to ctrl->elems.
1340176077aSHans Verkuil * @log: log the value.
1350176077aSHans Verkuil * @validate: validate the value for ctrl->new_elems array elements.
136cd75981eSHans Verkuil * Return 0 on success and a negative value otherwise.
1370176077aSHans Verkuil */
1380176077aSHans Verkuil struct v4l2_ctrl_type_ops {
1392257e180SMauro Carvalho Chehab bool (*equal)(const struct v4l2_ctrl *ctrl,
1402257e180SMauro Carvalho Chehab union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2);
1412257e180SMauro Carvalho Chehab void (*init)(const struct v4l2_ctrl *ctrl, u32 from_idx,
1422257e180SMauro Carvalho Chehab union v4l2_ctrl_ptr ptr);
1432257e180SMauro Carvalho Chehab void (*log)(const struct v4l2_ctrl *ctrl);
1442257e180SMauro Carvalho Chehab int (*validate)(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);
1452257e180SMauro Carvalho Chehab };
1462257e180SMauro Carvalho Chehab
1472257e180SMauro Carvalho Chehab /**
1482257e180SMauro Carvalho Chehab * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
1498ac7a949SHans Verkuil * that should be called when a control value has changed.
1508ac7a949SHans Verkuil *
1518c2721d5SMauro Carvalho Chehab * @ctrl: pointer to struct &v4l2_ctrl
1528c2721d5SMauro Carvalho Chehab * @priv: control private data
1538ec4bee7SMauro Carvalho Chehab *
1540996517cSHans Verkuil * This typedef definition is used as an argument to v4l2_ctrl_notify()
15577068d36SHans Verkuil * and as an argument at struct &v4l2_ctrl_handler.
1560996517cSHans Verkuil */
1570996517cSHans Verkuil typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
1580996517cSHans Verkuil
1590996517cSHans Verkuil /**
1602a863793SHans Verkuil * struct v4l2_ctrl - The control structure.
1618ec4bee7SMauro Carvalho Chehab *
1622a863793SHans Verkuil * @node: The list node.
1639ea1b7a4SHans Verkuil * @ev_subs: The list of control event subscriptions.
1649ea1b7a4SHans Verkuil * @handler: The handler that owns the control.
1650996517cSHans Verkuil * @cluster: Point to start of cluster array.
1660996517cSHans Verkuil * @ncontrols: Number of controls in cluster array.
1670996517cSHans Verkuil * @done: Internal flag: set for each processed control.
16872d877caSHans Verkuil * @is_new: Set when the user specified a new value for this control. It
16972d877caSHans Verkuil * is also set when called from v4l2_ctrl_handler_setup(). Drivers
17072d877caSHans Verkuil * should never set this flag.
17172d877caSHans Verkuil * @has_changed: Set when the current value differs from the new value. Drivers
172d9a25471SHans Verkuil * should never use this flag.
173d9a25471SHans Verkuil * @is_private: If set, then this control is private to its handler and it
1748ec4bee7SMauro Carvalho Chehab * will not be added to any other handlers. Drivers can set
1758ec4bee7SMauro Carvalho Chehab * this flag.
1768ec4bee7SMauro Carvalho Chehab * @is_auto: If set, then this control selects whether the other cluster
1778ec4bee7SMauro Carvalho Chehab * members are in 'automatic' mode or 'manual' mode. This is
178d9a25471SHans Verkuil * used for autogain/gain type clusters. Drivers should never
179998e7659SHans Verkuil * set this flag directly.
180fb582cbaSHans Verkuil * @is_int: If set, then this control has a simple integer value (i.e. it
181fb582cbaSHans Verkuil * uses ctrl->val).
1825626b8c7SHans Verkuil * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
1835626b8c7SHans Verkuil * @is_ptr: If set, then this control is an array and/or has type >=
1848ac7a949SHans Verkuil * %V4L2_CTRL_COMPOUND_TYPES
1858ac7a949SHans Verkuil * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
18672d877caSHans Verkuil * v4l2_ext_control uses field p to point to the data.
18772d877caSHans Verkuil * @is_array: If set, then this control contains an N-dimensional array.
18872d877caSHans Verkuil * @is_dyn_array: If set, then this control contains a dynamically sized 1-dimensional array.
18972d877caSHans Verkuil * If this is set, then @is_array is also set.
19072d877caSHans Verkuil * @has_volatiles: If set, then one or more members of the cluster are volatile.
1910996517cSHans Verkuil * Drivers should never touch this flag.
1920176077aSHans Verkuil * @call_notify: If set, then call the handler's notify function whenever the
1930996517cSHans Verkuil * control's value changes.
1940996517cSHans Verkuil * @manual_mode_value: If the is_auto flag is set, then this is the value
1950996517cSHans Verkuil * of the auto control that determines if that control is in
1960996517cSHans Verkuil * manual mode. So if the value of the auto control equals this
1970996517cSHans Verkuil * value, then the whole cluster is in manual mode. Drivers should
1980996517cSHans Verkuil * never set this flag directly.
1990996517cSHans Verkuil * @ops: The control ops.
20020d88eefSHans Verkuil * @type_ops: The control type ops.
201d9a25471SHans Verkuil * @id: The control ID.
202fb582cbaSHans Verkuil * @name: The control name.
203fb582cbaSHans Verkuil * @type: The control type.
2045f2c5c69SHans Verkuil * @minimum: The control's minimum value.
20520d88eefSHans Verkuil * @maximum: The control's maximum value.
20620d88eefSHans Verkuil * @default_value: The control's default value.
2070996517cSHans Verkuil * @step: The control's step value for non-menu controls.
2080996517cSHans Verkuil * @elems: The number of elements in the N-dimensional array.
2090996517cSHans Verkuil * @elem_size: The size in bytes of the control.
2100996517cSHans Verkuil * @new_elems: The number of elements in p_new. This is the same as @elems,
2110996517cSHans Verkuil * except for dynamic arrays. In that case it is in the range of
2120996517cSHans Verkuil * 1 to @p_array_alloc_elems.
2130996517cSHans Verkuil * @dims: The size of each dimension.
2140996517cSHans Verkuil * @nr_of_dims:The number of dimensions in @dims.
2150996517cSHans Verkuil * @menu_skip_mask: The control's skip mask for menu controls. This makes it
2160996517cSHans Verkuil * easy to skip menu items that are not valid. If bit X is set,
21720139f18SMauro Carvalho Chehab * then menu item X is skipped. Of course, this only works for
21820139f18SMauro Carvalho Chehab * menus with <= 32 menu items. There are no menus that come
21920139f18SMauro Carvalho Chehab * close to that number, so this is OK. Should we ever need more,
22020139f18SMauro Carvalho Chehab * then this will have to be extended to a u64 or a bit array.
22120139f18SMauro Carvalho Chehab * @qmenu: A const char * array for all menu items. Array entries that are
2220996517cSHans Verkuil * empty strings ("") correspond to non-existing menu items (this
2230996517cSHans Verkuil * is in addition to the menu_skip_mask above). The last entry
2240996517cSHans Verkuil * must be NULL.
2250996517cSHans Verkuil * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
2260996517cSHans Verkuil * @qmenu_int: A 64-bit integer array for with integer menu items.
2270996517cSHans Verkuil * The size of array must be equal to the menu size, e. g.:
2285f2c5c69SHans Verkuil * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
2295f2c5c69SHans Verkuil * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
2305f2c5c69SHans Verkuil * @flags: The control's flags.
2315f2c5c69SHans Verkuil * @priv: The control's private pointer. For use by the driver. It is
2325f2c5c69SHans Verkuil * untouched by the control framework. Note that this pointer is
233fb582cbaSHans Verkuil * not freed when the control is deleted. Should this be needed
234fb582cbaSHans Verkuil * then a new internal bitfield can be added to tell the framework
235fb582cbaSHans Verkuil * to free this pointer.
236fb582cbaSHans Verkuil * @p_array: Pointer to the allocated array. Only valid if @is_array is true.
237b35d6c02SRicardo Ribalda Delgado * @p_array_alloc_elems: The number of elements in the allocated
238b35d6c02SRicardo Ribalda Delgado * array for both the cur and new values. So @p_array is actually
239b35d6c02SRicardo Ribalda Delgado * sized for 2 * @p_array_alloc_elems * @elem_size. Only valid if
240bf7b7048SBaruch Siach * @is_array is true.
2417dc87919SMauro Carvalho Chehab * @cur: Structure to store the current value.
2427dc87919SMauro Carvalho Chehab * @cur.val: The control's current value, if the @type is represented via
243bf7b7048SBaruch Siach * a u32 integer (see &enum v4l2_ctrl_type).
2447dc87919SMauro Carvalho Chehab * @val: The control's new s32 value.
2457dc87919SMauro Carvalho Chehab * @p_def: The control's default value represented via a union which
2460996517cSHans Verkuil * provides a standard way of accessing control types
2470996517cSHans Verkuil * through a pointer (for compound controls only).
2480996517cSHans Verkuil * @p_cur: The control's current value represented via a union which
2490996517cSHans Verkuil * provides a standard way of accessing control types
25077068d36SHans Verkuil * through a pointer.
2510996517cSHans Verkuil * @p_new: The control's new value represented via a union which provides
2520996517cSHans Verkuil * a standard way of accessing control types
2538ec4bee7SMauro Carvalho Chehab * through a pointer.
2548ec4bee7SMauro Carvalho Chehab */
2550996517cSHans Verkuil struct v4l2_ctrl {
2560996517cSHans Verkuil /* Administrative fields */
2572a863793SHans Verkuil struct list_head node;
2589ea1b7a4SHans Verkuil struct list_head ev_subs;
2590996517cSHans Verkuil struct v4l2_ctrl_handler *handler;
26072d877caSHans Verkuil struct v4l2_ctrl **cluster;
261d9a25471SHans Verkuil unsigned int ncontrols;
262d9a25471SHans Verkuil
263d9a25471SHans Verkuil unsigned int done:1;
264998e7659SHans Verkuil
265fb582cbaSHans Verkuil unsigned int is_new:1;
2665626b8c7SHans Verkuil unsigned int has_changed:1;
2678ac7a949SHans Verkuil unsigned int is_private:1;
26882a7c049SHans Verkuil unsigned int is_auto:1;
2690996517cSHans Verkuil unsigned int is_int:1;
2700996517cSHans Verkuil unsigned int is_string:1;
2710176077aSHans Verkuil unsigned int is_ptr:1;
2720996517cSHans Verkuil unsigned int is_array:1;
2730996517cSHans Verkuil unsigned int is_dyn_array:1;
2740996517cSHans Verkuil unsigned int has_volatiles:1;
2750ba2aeb6SHans Verkuil unsigned int call_notify:1;
27620d88eefSHans Verkuil unsigned int manual_mode_value:8;
277d9a25471SHans Verkuil
278fb582cbaSHans Verkuil const struct v4l2_ctrl_ops *ops;
27920d88eefSHans Verkuil const struct v4l2_ctrl_type_ops *type_ops;
28020d88eefSHans Verkuil u32 id;
2810996517cSHans Verkuil const char *name;
2820ba2aeb6SHans Verkuil enum v4l2_ctrl_type type;
2830ba2aeb6SHans Verkuil s64 minimum, maximum, default_value;
2840996517cSHans Verkuil u32 elems;
285ce580fe5SSakari Ailus u32 elem_size;
286513521eaSHans Verkuil u32 new_elems;
287ce580fe5SSakari Ailus u32 dims[V4L2_CTRL_MAX_DIMS];
288ce580fe5SSakari Ailus u32 nr_of_dims;
2890996517cSHans Verkuil union {
2900996517cSHans Verkuil u64 step;
2915f2c5c69SHans Verkuil u64 menu_skip_mask;
2925f2c5c69SHans Verkuil };
293d9a25471SHans Verkuil union {
2942a9ec373SHans Verkuil const char * const *qmenu;
295d9a25471SHans Verkuil const s64 *qmenu_int;
296d9a25471SHans Verkuil };
2970176077aSHans Verkuil unsigned long flags;
298b35d6c02SRicardo Ribalda Delgado void *priv;
2990176077aSHans Verkuil void *p_array;
3000176077aSHans Verkuil u32 p_array_alloc_elems;
3010996517cSHans Verkuil s32 val;
3020996517cSHans Verkuil struct {
3038c2721d5SMauro Carvalho Chehab s32 val;
3048c2721d5SMauro Carvalho Chehab } cur;
3058ec4bee7SMauro Carvalho Chehab
3060996517cSHans Verkuil union v4l2_ctrl_ptr p_def;
3070996517cSHans Verkuil union v4l2_ctrl_ptr p_new;
3080996517cSHans Verkuil union v4l2_ctrl_ptr p_cur;
3098ec4bee7SMauro Carvalho Chehab };
310fb91161aSMauro Carvalho Chehab
311da1b1aeaSHans Verkuil /**
312da1b1aeaSHans Verkuil * struct v4l2_ctrl_ref - The control reference.
3136fa6f831SHans Verkuil *
3146fa6f831SHans Verkuil * @node: List node for the sorted list.
3156fa6f831SHans Verkuil * @next: Single-link list node for the hash.
3166fa6f831SHans Verkuil * @ctrl: The actual control information.
3176fa6f831SHans Verkuil * @helper: Pointer to helper struct. Used internally in
318fb582cbaSHans Verkuil * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
3197392d87aSHans Verkuil * @from_other_dev: If true, then @ctrl was defined in another
3207392d87aSHans Verkuil * device than the &struct v4l2_ctrl_handler.
3217392d87aSHans Verkuil * @req_done: Internal flag: if the control handler containing this control
3227392d87aSHans Verkuil * reference is bound to a media request, then this is set when
3237392d87aSHans Verkuil * the control has been applied. This prevents applying controls
324fb582cbaSHans Verkuil * from a cluster with multiple controls twice (when the first
325fb582cbaSHans Verkuil * control of a cluster is applied, they all are).
326fb582cbaSHans Verkuil * @p_req_valid: If set, then p_req contains the control value for the request.
3277392d87aSHans Verkuil * @p_req_array_enomem: If set, then p_req is invalid since allocating space for
328fb582cbaSHans Verkuil * an array failed. Attempting to read this value shall
32952beeddbSHans Verkuil * result in ENOMEM. Only valid if ctrl->is_array is true.
33052beeddbSHans Verkuil * @p_req_array_alloc_elems: The number of elements allocated for the
331ac34b79dSHans Verkuil * array. Only valid if @p_req_valid and ctrl->is_array are
33252beeddbSHans Verkuil * true.
333fb582cbaSHans Verkuil * @p_req_elems: The number of elements in @p_req. This is the same as
334ac34b79dSHans Verkuil * ctrl->elems, except for dynamic arrays. In that case it is in
335ac34b79dSHans Verkuil * the range of 1 to @p_req_array_alloc_elems. Only valid if
3360996517cSHans Verkuil * @p_req_valid is true.
3370996517cSHans Verkuil * @p_req: If the control handler containing this control reference
3380996517cSHans Verkuil * is bound to a media request, then this points to the
3390996517cSHans Verkuil * value of the control that must be applied when the request
3400996517cSHans Verkuil * is executed, or to the value of the control at the time
3410996517cSHans Verkuil * that the request was completed. If @p_req_valid is false,
3420996517cSHans Verkuil * then this control was never set for this request and the
3430996517cSHans Verkuil * control will not be updated when this request is applied.
3440996517cSHans Verkuil *
345eb5b16efSHans Verkuil * Each control handler has a list of these refs. The list_head is used to
346da1b1aeaSHans Verkuil * keep a sorted-by-control-ID list of all controls, while the next pointer
3476fa6f831SHans Verkuil * is used to link the control in the hash's bucket.
348fb582cbaSHans Verkuil */
3497392d87aSHans Verkuil struct v4l2_ctrl_ref {
3507392d87aSHans Verkuil struct list_head node;
351fb582cbaSHans Verkuil struct v4l2_ctrl_ref *next;
35252beeddbSHans Verkuil struct v4l2_ctrl *ctrl;
3530996517cSHans Verkuil struct v4l2_ctrl_helper *helper;
3540996517cSHans Verkuil bool from_other_dev;
3558c2721d5SMauro Carvalho Chehab bool req_done;
3568c2721d5SMauro Carvalho Chehab bool p_req_valid;
3570996517cSHans Verkuil bool p_req_array_enomem;
3580996517cSHans Verkuil u32 p_req_array_alloc_elems;
3598ec4bee7SMauro Carvalho Chehab u32 p_req_elems;
36077e7c4e6SSakari Ailus union v4l2_ctrl_ptr p_req;
3610996517cSHans Verkuil };
36277e7c4e6SSakari Ailus
3630996517cSHans Verkuil /**
3640996517cSHans Verkuil * struct v4l2_ctrl_handler - The control handler keeps track of all the
3650996517cSHans Verkuil * controls: both the controls owned by the handler and those inherited
3660996517cSHans Verkuil * from other handlers.
3670996517cSHans Verkuil *
3680996517cSHans Verkuil * @_lock: Default for "lock".
3698ec4bee7SMauro Carvalho Chehab * @lock: Lock to control access to this handler and its controls.
3708ec4bee7SMauro Carvalho Chehab * May be replaced by the user right after init.
3718ac7a949SHans Verkuil * @ctrls: The list of controls owned by this handler.
3728ac7a949SHans Verkuil * @ctrl_refs: The list of control references.
3738ac7a949SHans Verkuil * @cached: The last found control reference. It is common that the same
3740996517cSHans Verkuil * control is needed multiple times, so this is a simple
3750996517cSHans Verkuil * optimization.
3766fa6f831SHans Verkuil * @buckets: Buckets for the hashing. Allows for quick control lookup.
3776fa6f831SHans Verkuil * @notify: A notify callback that is called whenever the control changes
378ac34b79dSHans Verkuil * value.
3796fa6f831SHans Verkuil * Note that the handler's lock is held when the notify function
3806fa6f831SHans Verkuil * is called!
3816fa6f831SHans Verkuil * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
3826fa6f831SHans Verkuil * @nr_of_buckets: Total number of buckets in the array.
3836fa6f831SHans Verkuil * @error: The error code of the first failed control addition.
3846fa6f831SHans Verkuil * @request_is_queued: True if the request was queued.
38552beeddbSHans Verkuil * @requests: List to keep track of open control handler request objects.
38652beeddbSHans Verkuil * For the parent control handler (@req_obj.ops == NULL) this
3870996517cSHans Verkuil * is the list header. When the parent control handler is
3880996517cSHans Verkuil * removed, it has to unbind and put all these requests since
38977e7c4e6SSakari Ailus * they refer to the parent.
39077e7c4e6SSakari Ailus * @requests_queued: List of the queued requests. This determines the order
3910996517cSHans Verkuil * in which these controls are applied. Once the request is
3920996517cSHans Verkuil * completed it is removed from this list.
3930996517cSHans Verkuil * @req_obj: The &struct media_request_object, used to link into a
3940996517cSHans Verkuil * &struct media_request. This request object has a refcount.
3958ac7a949SHans Verkuil */
3968ac7a949SHans Verkuil struct v4l2_ctrl_handler {
3970996517cSHans Verkuil struct mutex _lock;
3980996517cSHans Verkuil struct mutex *lock;
3996fa6f831SHans Verkuil struct list_head ctrls;
4006fa6f831SHans Verkuil struct list_head ctrl_refs;
4016fa6f831SHans Verkuil struct v4l2_ctrl_ref *cached;
40252beeddbSHans Verkuil struct v4l2_ctrl_ref **buckets;
4030996517cSHans Verkuil v4l2_ctrl_notify_fnc notify;
4040996517cSHans Verkuil void *notify_priv;
4058c2721d5SMauro Carvalho Chehab u16 nr_of_buckets;
4068c2721d5SMauro Carvalho Chehab int error;
4078ec4bee7SMauro Carvalho Chehab bool request_is_queued;
4080996517cSHans Verkuil struct list_head requests;
4090176077aSHans Verkuil struct list_head requests_queued;
4100996517cSHans Verkuil struct media_request_object req_obj;
4110996517cSHans Verkuil };
4120996517cSHans Verkuil
4130996517cSHans Verkuil /**
4140996517cSHans Verkuil * struct v4l2_ctrl_config - Control configuration structure.
4150996517cSHans Verkuil *
4160996517cSHans Verkuil * @ops: The control ops.
4173b98a21aSRicardo Ribalda Delgado * @type_ops: The control type ops. Only needed for compound controls.
41820d88eefSHans Verkuil * @id: The control ID.
419d9a25471SHans Verkuil * @name: The control name.
4200996517cSHans Verkuil * @type: The control type.
4210996517cSHans Verkuil * @min: The control's minimum value.
4220996517cSHans Verkuil * @max: The control's maximum value.
4230996517cSHans Verkuil * @step: The control's step value for non-menu controls.
4240ba2aeb6SHans Verkuil * @def: The control's default value.
4250996517cSHans Verkuil * @p_def: The control's default value for compound controls.
4260ba2aeb6SHans Verkuil * @dims: The size of each dimension.
4270996517cSHans Verkuil * @elem_size: The size in bytes of the control.
4280996517cSHans Verkuil * @flags: The control's flags.
4290996517cSHans Verkuil * @menu_skip_mask: The control's skip mask for menu controls. This makes it
4300996517cSHans Verkuil * easy to skip menu items that are not valid. If bit X is set,
4317dc87919SMauro Carvalho Chehab * then menu item X is skipped. Of course, this only works for
4327dc87919SMauro Carvalho Chehab * menus with <= 64 menu items. There are no menus that come
4330996517cSHans Verkuil * close to that number, so this is OK. Should we ever need more,
4340996517cSHans Verkuil * then this will have to be extended to a bit array.
4350996517cSHans Verkuil * @qmenu: A const char * array for all menu items. Array entries that are
4360996517cSHans Verkuil * empty strings ("") correspond to non-existing menu items (this
4370996517cSHans Verkuil * is in addition to the menu_skip_mask above). The last entry
4380176077aSHans Verkuil * must be NULL.
4390996517cSHans Verkuil * @qmenu_int: A const s64 integer array for all menu items of the type
4400996517cSHans Verkuil * V4L2_CTRL_TYPE_INTEGER_MENU.
4410996517cSHans Verkuil * @is_private: If set, then this control is private to its handler and it
4420ba2aeb6SHans Verkuil * will not be added to any other handlers.
4430ba2aeb6SHans Verkuil */
4440ba2aeb6SHans Verkuil struct v4l2_ctrl_config {
4450ba2aeb6SHans Verkuil const struct v4l2_ctrl_ops *ops;
4463b98a21aSRicardo Ribalda Delgado const struct v4l2_ctrl_type_ops *type_ops;
44720d88eefSHans Verkuil u32 id;
448d9a25471SHans Verkuil const char *name;
4490996517cSHans Verkuil enum v4l2_ctrl_type type;
4500ba2aeb6SHans Verkuil s64 min;
451513521eaSHans Verkuil s64 max;
452ce580fe5SSakari Ailus u64 step;
4530996517cSHans Verkuil s64 def;
4540996517cSHans Verkuil union v4l2_ctrl_ptr p_def;
4550996517cSHans Verkuil u32 dims[V4L2_CTRL_MAX_DIMS];
4568ec4bee7SMauro Carvalho Chehab u32 elem_size;
4578ec4bee7SMauro Carvalho Chehab u32 flags;
4588ec4bee7SMauro Carvalho Chehab u64 menu_skip_mask;
4598ec4bee7SMauro Carvalho Chehab const char * const *qmenu;
46067c672ecSMauro Carvalho Chehab const s64 *qmenu_int;
46167c672ecSMauro Carvalho Chehab unsigned int is_private:1;
46267c672ecSMauro Carvalho Chehab };
46367c672ecSMauro Carvalho Chehab
46467c672ecSMauro Carvalho Chehab /**
46567c672ecSMauro Carvalho Chehab * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
46667c672ecSMauro Carvalho Chehab *
4670996517cSHans Verkuil * @id: ID of the control
4680996517cSHans Verkuil * @name: pointer to be filled with a string with the name of the control
4690996517cSHans Verkuil * @type: pointer for storing the type of the control
47067c672ecSMauro Carvalho Chehab * @min: pointer for storing the minimum value for the control
4710996517cSHans Verkuil * @max: pointer for storing the maximum value for the control
4720996517cSHans Verkuil * @step: pointer for storing the control step
4730996517cSHans Verkuil * @def: pointer for storing the default value for the control
4740996517cSHans Verkuil * @flags: pointer for storing the flags to be used on the control
4750996517cSHans Verkuil *
4768ec4bee7SMauro Carvalho Chehab * This works for all standard V4L2 controls.
4778ec4bee7SMauro Carvalho Chehab * For non-standard controls it will only fill in the given arguments
4780996517cSHans Verkuil * and @name content will be set to %NULL.
4790996517cSHans Verkuil *
4800996517cSHans Verkuil * This function will overwrite the contents of @name, @type and @flags.
4810996517cSHans Verkuil * The contents of @min, @max, @step and @def may be modified depending on
4820996517cSHans Verkuil * the type.
4830ba2aeb6SHans Verkuil *
4840996517cSHans Verkuil * .. note::
4850996517cSHans Verkuil *
4868c2721d5SMauro Carvalho Chehab * Do not use in drivers! It is used internally for backwards compatibility
4878c2721d5SMauro Carvalho Chehab * control handling only. Once all drivers are converted to use the new
4880996517cSHans Verkuil * control framework this function will no longer be exported.
4890996517cSHans Verkuil */
4900996517cSHans Verkuil void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
4910996517cSHans Verkuil s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
4920996517cSHans Verkuil
4930996517cSHans Verkuil
4940996517cSHans Verkuil /**
4950996517cSHans Verkuil * v4l2_ctrl_handler_init_class() - Initialize the control handler.
4966cd247efSAndy Walls * @hdl: The control handler.
4976cd247efSAndy Walls * @nr_of_controls_hint: A hint of how many controls this handler is
4980996517cSHans Verkuil * expected to refer to. This is the total number, so including
4992257e180SMauro Carvalho Chehab * any inherited controls. It doesn't have to be precise, but if
5006cd247efSAndy Walls * it is way off, then you either waste memory (too many buckets
5012257e180SMauro Carvalho Chehab * are allocated) or the control lookup becomes slower (not enough
5026cd247efSAndy Walls * buckets are allocated, so there are more slow list lookups).
5032257e180SMauro Carvalho Chehab * It will always work, though.
5042257e180SMauro Carvalho Chehab * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
5052257e180SMauro Carvalho Chehab * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
5060996517cSHans Verkuil *
5076cd247efSAndy Walls * .. attention::
5088ec4bee7SMauro Carvalho Chehab *
5096cd247efSAndy Walls * Never use this call directly, always use the v4l2_ctrl_handler_init()
5106cd247efSAndy Walls * macro that hides the @key and @name arguments.
5116cd247efSAndy Walls *
5122257e180SMauro Carvalho Chehab * Return: returns an error if the buckets could not be allocated. This
5132257e180SMauro Carvalho Chehab * error will also be stored in @hdl->error.
514e383ce07SMauro Carvalho Chehab */
515e383ce07SMauro Carvalho Chehab int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
5162257e180SMauro Carvalho Chehab unsigned int nr_of_controls_hint,
5172257e180SMauro Carvalho Chehab struct lock_class_key *key, const char *name);
5182257e180SMauro Carvalho Chehab
5192257e180SMauro Carvalho Chehab #ifdef CONFIG_LOCKDEP
5202257e180SMauro Carvalho Chehab
5212257e180SMauro Carvalho Chehab /**
5222257e180SMauro Carvalho Chehab * v4l2_ctrl_handler_init - helper function to create a static struct
5232257e180SMauro Carvalho Chehab * &lock_class_key and calls v4l2_ctrl_handler_init_class()
5242257e180SMauro Carvalho Chehab *
5252257e180SMauro Carvalho Chehab * @hdl: The control handler.
5262257e180SMauro Carvalho Chehab * @nr_of_controls_hint: A hint of how many controls this handler is
5272257e180SMauro Carvalho Chehab * expected to refer to. This is the total number, so including
5282257e180SMauro Carvalho Chehab * any inherited controls. It doesn't have to be precise, but if
5292257e180SMauro Carvalho Chehab * it is way off, then you either waste memory (too many buckets
5302257e180SMauro Carvalho Chehab * are allocated) or the control lookup becomes slower (not enough
5312257e180SMauro Carvalho Chehab * buckets are allocated, so there are more slow list lookups).
5326cd247efSAndy Walls * It will always work, though.
5336cd247efSAndy Walls *
5346cd247efSAndy Walls * This helper function creates a static struct &lock_class_key and
5356cd247efSAndy Walls * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
5366cd247efSAndy Walls * validador.
5376cd247efSAndy Walls *
5386cd247efSAndy Walls * Use this helper function to initialize a control handler.
5396cd247efSAndy Walls */
5406cd247efSAndy Walls #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
5416cd247efSAndy Walls ( \
5426cd247efSAndy Walls ({ \
5436cd247efSAndy Walls static struct lock_class_key _key; \
5446cd247efSAndy Walls v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
5456cd247efSAndy Walls &_key, \
5466cd247efSAndy Walls KBUILD_BASENAME ":" \
5470996517cSHans Verkuil __stringify(__LINE__) ":" \
5488c2721d5SMauro Carvalho Chehab "(" #hdl ")->_lock"); \
5498c2721d5SMauro Carvalho Chehab }) \
5500996517cSHans Verkuil )
5510996517cSHans Verkuil #else
5520996517cSHans Verkuil #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
5530996517cSHans Verkuil v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
5540996517cSHans Verkuil #endif
5550996517cSHans Verkuil
5560996517cSHans Verkuil /**
5578c2721d5SMauro Carvalho Chehab * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
5588c2721d5SMauro Carvalho Chehab * the control list.
559605b3840SSakari Ailus * @hdl: The control handler.
560605b3840SSakari Ailus *
561605b3840SSakari Ailus * Does nothing if @hdl == NULL.
562605b3840SSakari Ailus */
563605b3840SSakari Ailus void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
564605b3840SSakari Ailus
565605b3840SSakari Ailus /**
566605b3840SSakari Ailus * v4l2_ctrl_lock() - Helper function to lock the handler
5678c2721d5SMauro Carvalho Chehab * associated with the control.
5688c2721d5SMauro Carvalho Chehab * @ctrl: The control to lock.
569605b3840SSakari Ailus */
v4l2_ctrl_lock(struct v4l2_ctrl * ctrl)570605b3840SSakari Ailus static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
571605b3840SSakari Ailus {
572605b3840SSakari Ailus mutex_lock(ctrl->handler->lock);
573605b3840SSakari Ailus }
574605b3840SSakari Ailus
575605b3840SSakari Ailus /**
576605b3840SSakari Ailus * v4l2_ctrl_unlock() - Helper function to unlock the handler
5778c2721d5SMauro Carvalho Chehab * associated with the control.
578cc0140e2SSakari Ailus * @ctrl: The control to unlock.
579cc0140e2SSakari Ailus */
v4l2_ctrl_unlock(struct v4l2_ctrl * ctrl)580cc0140e2SSakari Ailus static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
581cc0140e2SSakari Ailus {
582cc0140e2SSakari Ailus mutex_unlock(ctrl->handler->lock);
583cc0140e2SSakari Ailus }
584cc0140e2SSakari Ailus
585cc0140e2SSakari Ailus /**
586cc0140e2SSakari Ailus * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
587cc0140e2SSakari Ailus * to the handler to initialize the hardware to the current control values. The
588cc0140e2SSakari Ailus * caller is responsible for acquiring the control handler mutex on behalf of
589cc0140e2SSakari Ailus * __v4l2_ctrl_handler_setup().
590cc0140e2SSakari Ailus * @hdl: The control handler.
5918c2721d5SMauro Carvalho Chehab *
5920996517cSHans Verkuil * Button controls will be skipped, as are read-only controls.
5930996517cSHans Verkuil *
5940996517cSHans Verkuil * If @hdl == NULL, then this just returns 0.
5950996517cSHans Verkuil */
5960996517cSHans Verkuil int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
5970996517cSHans Verkuil
5980996517cSHans Verkuil /**
5990996517cSHans Verkuil * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
6000996517cSHans Verkuil * to the handler to initialize the hardware to the current control values.
6018c2721d5SMauro Carvalho Chehab * @hdl: The control handler.
6028c2721d5SMauro Carvalho Chehab *
6030996517cSHans Verkuil * Button controls will be skipped, as are read-only controls.
6040996517cSHans Verkuil *
6050996517cSHans Verkuil * If @hdl == NULL, then this just returns 0.
6060996517cSHans Verkuil */
6070996517cSHans Verkuil int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
6080996517cSHans Verkuil
6090996517cSHans Verkuil /**
6100996517cSHans Verkuil * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
6110996517cSHans Verkuil * @hdl: The control handler.
6120996517cSHans Verkuil * @prefix: The prefix to use when logging the control values. If the
6130996517cSHans Verkuil * prefix does not end with a space, then ": " will be added
6140996517cSHans Verkuil * after the prefix. If @prefix == NULL, then no prefix will be
6150996517cSHans Verkuil * used.
6168c2721d5SMauro Carvalho Chehab *
6178c2721d5SMauro Carvalho Chehab * For use with VIDIOC_LOG_STATUS.
6180996517cSHans Verkuil *
6198ec4bee7SMauro Carvalho Chehab * Does nothing if @hdl == NULL.
6200996517cSHans Verkuil */
6210996517cSHans Verkuil void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
6220996517cSHans Verkuil const char *prefix);
6230996517cSHans Verkuil
6240996517cSHans Verkuil /**
6250996517cSHans Verkuil * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
6260996517cSHans Verkuil * control.
6270996517cSHans Verkuil *
6288ec4bee7SMauro Carvalho Chehab * @hdl: The control handler.
6298ec4bee7SMauro Carvalho Chehab * @cfg: The control's configuration data.
6300996517cSHans Verkuil * @priv: The control's driver-specific private data.
6318c2721d5SMauro Carvalho Chehab *
6328ec4bee7SMauro Carvalho Chehab * If the &v4l2_ctrl struct could not be allocated then NULL is returned
6338ec4bee7SMauro Carvalho Chehab * and @hdl->error is set to the error code (if it wasn't set already).
6348ec4bee7SMauro Carvalho Chehab */
6350996517cSHans Verkuil struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
6360996517cSHans Verkuil const struct v4l2_ctrl_config *cfg,
6370996517cSHans Verkuil void *priv);
6380996517cSHans Verkuil
6390996517cSHans Verkuil /**
6400996517cSHans Verkuil * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
6410996517cSHans Verkuil * control.
6420996517cSHans Verkuil *
6430996517cSHans Verkuil * @hdl: The control handler.
6440996517cSHans Verkuil * @ops: The control ops.
6450996517cSHans Verkuil * @id: The control ID.
6460996517cSHans Verkuil * @min: The control's minimum value.
6470996517cSHans Verkuil * @max: The control's maximum value.
6480996517cSHans Verkuil * @step: The control's step value
6490996517cSHans Verkuil * @def: The control's default value.
6500996517cSHans Verkuil *
6510996517cSHans Verkuil * If the &v4l2_ctrl struct could not be allocated, or the control
6520996517cSHans Verkuil * ID is not known, then NULL is returned and @hdl->error is set to the
6538ec4bee7SMauro Carvalho Chehab * appropriate error code (if it wasn't set already).
6548ec4bee7SMauro Carvalho Chehab *
6550996517cSHans Verkuil * If @id refers to a menu control, then this function will return NULL.
6568c2721d5SMauro Carvalho Chehab *
6578ec4bee7SMauro Carvalho Chehab * Use v4l2_ctrl_new_std_menu() when adding menu controls.
6588ec4bee7SMauro Carvalho Chehab */
6598ec4bee7SMauro Carvalho Chehab struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
6600996517cSHans Verkuil const struct v4l2_ctrl_ops *ops,
6610996517cSHans Verkuil u32 id, s64 min, s64 max, u64 step,
6620996517cSHans Verkuil s64 def);
6630996517cSHans Verkuil
6640996517cSHans Verkuil /**
6650996517cSHans Verkuil * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
6660996517cSHans Verkuil * menu control.
6670ba2aeb6SHans Verkuil *
6680996517cSHans Verkuil * @hdl: The control handler.
6690ba2aeb6SHans Verkuil * @ops: The control ops.
6700996517cSHans Verkuil * @id: The control ID.
6710996517cSHans Verkuil * @max: The control's maximum value.
6720996517cSHans Verkuil * @mask: The control's skip mask for menu controls. This makes it
6730996517cSHans Verkuil * easy to skip menu items that are not valid. If bit X is set,
6740996517cSHans Verkuil * then menu item X is skipped. Of course, this only works for
6750996517cSHans Verkuil * menus with <= 64 menu items. There are no menus that come
6760996517cSHans Verkuil * close to that number, so this is OK. Should we ever need more,
6770996517cSHans Verkuil * then this will have to be extended to a bit array.
6780996517cSHans Verkuil * @def: The control's default value.
6790ba2aeb6SHans Verkuil *
6800996517cSHans Verkuil * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
6818c2721d5SMauro Carvalho Chehab * determines which menu items are to be skipped.
6828c2721d5SMauro Carvalho Chehab *
683117a711aSLad, Prabhakar * If @id refers to a non-menu control, then this function will return NULL.
6848ec4bee7SMauro Carvalho Chehab */
685117a711aSLad, Prabhakar struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
686117a711aSLad, Prabhakar const struct v4l2_ctrl_ops *ops,
687117a711aSLad, Prabhakar u32 id, u8 max, u64 mask, u8 def);
688117a711aSLad, Prabhakar
689117a711aSLad, Prabhakar /**
690117a711aSLad, Prabhakar * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
691117a711aSLad, Prabhakar * with driver specific menu.
6920ba2aeb6SHans Verkuil *
693117a711aSLad, Prabhakar * @hdl: The control handler.
6940ba2aeb6SHans Verkuil * @ops: The control ops.
695117a711aSLad, Prabhakar * @id: The control ID.
696117a711aSLad, Prabhakar * @max: The control's maximum value.
697117a711aSLad, Prabhakar * @mask: The control's skip mask for menu controls. This makes it
698117a711aSLad, Prabhakar * easy to skip menu items that are not valid. If bit X is set,
699117a711aSLad, Prabhakar * then menu item X is skipped. Of course, this only works for
700117a711aSLad, Prabhakar * menus with <= 64 menu items. There are no menus that come
701117a711aSLad, Prabhakar * close to that number, so this is OK. Should we ever need more,
702117a711aSLad, Prabhakar * then this will have to be extended to a bit array.
7038ec4bee7SMauro Carvalho Chehab * @def: The control's default value.
7048ec4bee7SMauro Carvalho Chehab * @qmenu: The new menu.
7058ec4bee7SMauro Carvalho Chehab *
7068ec4bee7SMauro Carvalho Chehab * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
707117a711aSLad, Prabhakar * menu of this control.
7088c2721d5SMauro Carvalho Chehab *
709b35d6c02SRicardo Ribalda Delgado */
710b35d6c02SRicardo Ribalda Delgado struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
711b35d6c02SRicardo Ribalda Delgado const struct v4l2_ctrl_ops *ops,
712b35d6c02SRicardo Ribalda Delgado u32 id, u8 max,
713b35d6c02SRicardo Ribalda Delgado u64 mask, u8 def,
714b35d6c02SRicardo Ribalda Delgado const char * const *qmenu);
715b35d6c02SRicardo Ribalda Delgado
716b35d6c02SRicardo Ribalda Delgado /**
717b35d6c02SRicardo Ribalda Delgado * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
718e51759f5SHans Verkuil * compound control.
719e51759f5SHans Verkuil *
720e51759f5SHans Verkuil * @hdl: The control handler.
721b35d6c02SRicardo Ribalda Delgado * @ops: The control ops.
722b35d6c02SRicardo Ribalda Delgado * @id: The control ID.
723b35d6c02SRicardo Ribalda Delgado * @p_def: The control's default value.
724b35d6c02SRicardo Ribalda Delgado *
725b35d6c02SRicardo Ribalda Delgado * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
726b35d6c02SRicardo Ribalda Delgado * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
727b35d6c02SRicardo Ribalda Delgado * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
728b35d6c02SRicardo Ribalda Delgado * compound control should be all zeroes.
7298c2721d5SMauro Carvalho Chehab *
7308ec4bee7SMauro Carvalho Chehab */
731515f3287SSylwester Nawrocki struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
732515f3287SSylwester Nawrocki const struct v4l2_ctrl_ops *ops,
733515f3287SSylwester Nawrocki u32 id,
734515f3287SSylwester Nawrocki const union v4l2_ctrl_ptr p_def);
735515f3287SSylwester Nawrocki
736515f3287SSylwester Nawrocki /**
737515f3287SSylwester Nawrocki * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
738e907bf3cSMauro Carvalho Chehab *
739515f3287SSylwester Nawrocki * @hdl: The control handler.
740515f3287SSylwester Nawrocki * @ops: The control ops.
7418ec4bee7SMauro Carvalho Chehab * @id: The control ID.
7428ec4bee7SMauro Carvalho Chehab * @max: The control's maximum value.
743515f3287SSylwester Nawrocki * @def: The control's default value.
744515f3287SSylwester Nawrocki * @qmenu_int: The control's menu entries.
745515f3287SSylwester Nawrocki *
7468ec4bee7SMauro Carvalho Chehab * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
7478ec4bee7SMauro Carvalho Chehab * takes as an argument an array of integers determining the menu items.
748515f3287SSylwester Nawrocki *
7492257e180SMauro Carvalho Chehab * If @id refers to a non-integer-menu control, then this function will
7502257e180SMauro Carvalho Chehab * return %NULL.
7512257e180SMauro Carvalho Chehab */
7522257e180SMauro Carvalho Chehab struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
7532257e180SMauro Carvalho Chehab const struct v4l2_ctrl_ops *ops,
7542257e180SMauro Carvalho Chehab u32 id, u8 max, u8 def,
7552257e180SMauro Carvalho Chehab const s64 *qmenu_int);
7566d85d7d7SMauro Carvalho Chehab
7576d85d7d7SMauro Carvalho Chehab /**
7588c2721d5SMauro Carvalho Chehab * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
7598c2721d5SMauro Carvalho Chehab * used when adding a control handler.
7600996517cSHans Verkuil *
7618ec4bee7SMauro Carvalho Chehab * @ctrl: pointer to struct &v4l2_ctrl.
7620996517cSHans Verkuil */
7630996517cSHans Verkuil
7640996517cSHans Verkuil typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
76534a6b7d0SHans Verkuil
766da1b1aeaSHans Verkuil /**
767da1b1aeaSHans Verkuil * v4l2_ctrl_add_handler() - Add all controls from handler @add to
7680996517cSHans Verkuil * handler @hdl.
76934a6b7d0SHans Verkuil *
77034a6b7d0SHans Verkuil * @hdl: The control handler.
77134a6b7d0SHans Verkuil * @add: The control handler whose controls you want to add to
7720996517cSHans Verkuil * the @hdl control handler.
7730996517cSHans Verkuil * @filter: This function will filter which controls should be added.
7740996517cSHans Verkuil * @from_other_dev: If true, then the controls in @add were defined in another
7750996517cSHans Verkuil * device than @hdl.
77634a6b7d0SHans Verkuil *
777da1b1aeaSHans Verkuil * Does nothing if either of the two handlers is a NULL pointer.
778da1b1aeaSHans Verkuil * If @filter is NULL, then all controls are added. Otherwise only those
7790996517cSHans Verkuil * controls for which @filter returns true will be added.
7808c2721d5SMauro Carvalho Chehab * In case of an error @hdl->error will be set to the error code (if it
7818c2721d5SMauro Carvalho Chehab * wasn't set already).
7828ec4bee7SMauro Carvalho Chehab */
78334a6b7d0SHans Verkuil int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
78434a6b7d0SHans Verkuil struct v4l2_ctrl_handler *add,
78534a6b7d0SHans Verkuil v4l2_ctrl_filter filter,
78634a6b7d0SHans Verkuil bool from_other_dev);
78734a6b7d0SHans Verkuil
78834a6b7d0SHans Verkuil /**
78934a6b7d0SHans Verkuil * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
79034a6b7d0SHans Verkuil *
79134a6b7d0SHans Verkuil * @ctrl: The control that is filtered.
7920996517cSHans Verkuil *
7938c2721d5SMauro Carvalho Chehab * This will return true for any controls that are valid for radio device
7948ec4bee7SMauro Carvalho Chehab * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
7958ec4bee7SMauro Carvalho Chehab * transmitter class controls.
7968ec4bee7SMauro Carvalho Chehab *
7970996517cSHans Verkuil * This function is to be used with v4l2_ctrl_add_handler().
7980996517cSHans Verkuil */
7990996517cSHans Verkuil bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
8008ec4bee7SMauro Carvalho Chehab
8010996517cSHans Verkuil /**
8020996517cSHans Verkuil * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
8038c2721d5SMauro Carvalho Chehab * to that cluster.
8048ec4bee7SMauro Carvalho Chehab *
8058ec4bee7SMauro Carvalho Chehab * @ncontrols: The number of controls in this cluster.
8068ec4bee7SMauro Carvalho Chehab * @controls: The cluster control array of size @ncontrols.
80772d877caSHans Verkuil */
80872d877caSHans Verkuil void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
80972d877caSHans Verkuil
81072d877caSHans Verkuil
81172d877caSHans Verkuil /**
81272d877caSHans Verkuil * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
81388365105SHans Verkuil * to that cluster and set it up for autofoo/foo-type handling.
81472d877caSHans Verkuil *
81572d877caSHans Verkuil * @ncontrols: The number of controls in this cluster.
81672d877caSHans Verkuil * @controls: The cluster control array of size @ncontrols. The first control
81772d877caSHans Verkuil * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
81872d877caSHans Verkuil * @manual_val: The value for the first control in the cluster that equals the
81972d877caSHans Verkuil * manual setting.
82072d877caSHans Verkuil * @set_volatile: If true, then all controls except the first auto control will
82172d877caSHans Verkuil * be volatile.
82272d877caSHans Verkuil *
82372d877caSHans Verkuil * Use for control groups where one control selects some automatic feature and
82472d877caSHans Verkuil * the other controls are only active whenever the automatic feature is turned
82572d877caSHans Verkuil * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
82672d877caSHans Verkuil * red and blue balance, etc.
82772d877caSHans Verkuil *
82872d877caSHans Verkuil * The behavior of such controls is as follows:
82972d877caSHans Verkuil *
8302257e180SMauro Carvalho Chehab * When the autofoo control is set to automatic, then any manual controls
8312257e180SMauro Carvalho Chehab * are set to inactive and any reads will call g_volatile_ctrl (if the control
83272d877caSHans Verkuil * was marked volatile).
83372d877caSHans Verkuil *
8348ec4bee7SMauro Carvalho Chehab * When the autofoo control is set to manual, then any manual controls will
8358ec4bee7SMauro Carvalho Chehab * be marked active, and any reads will just return the current value without
83672d877caSHans Verkuil * going through g_volatile_ctrl.
83772d877caSHans Verkuil *
83872d877caSHans Verkuil * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
8398c2721d5SMauro Carvalho Chehab * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
8408c2721d5SMauro Carvalho Chehab * if autofoo is in auto mode.
8418ec4bee7SMauro Carvalho Chehab */
8420996517cSHans Verkuil void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
8430996517cSHans Verkuil struct v4l2_ctrl **controls,
8440996517cSHans Verkuil u8 manual_val, bool set_volatile);
8450996517cSHans Verkuil
8460996517cSHans Verkuil
8470996517cSHans Verkuil /**
8480996517cSHans Verkuil * v4l2_ctrl_find() - Find a control with the given ID.
8490996517cSHans Verkuil *
8508c2721d5SMauro Carvalho Chehab * @hdl: The control handler.
8518c2721d5SMauro Carvalho Chehab * @id: The control ID to find.
8520996517cSHans Verkuil *
8530996517cSHans Verkuil * If @hdl == NULL this will return NULL as well. Will lock the handler so
8540996517cSHans Verkuil * do not use from inside &v4l2_ctrl_ops.
8550996517cSHans Verkuil */
8560996517cSHans Verkuil struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
8570996517cSHans Verkuil
8586e239399SHans Verkuil /**
8590996517cSHans Verkuil * v4l2_ctrl_activate() - Make the control active or inactive.
8606e239399SHans Verkuil * @ctrl: The control to (de)activate.
8610996517cSHans Verkuil * @active: True if the control should become active.
8620996517cSHans Verkuil *
8630996517cSHans Verkuil * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
8648c2721d5SMauro Carvalho Chehab * Does nothing if @ctrl == NULL.
8657a9b109dSSakari Ailus * This will usually be called from within the s_ctrl op.
8667a9b109dSSakari Ailus * The V4L2_EVENT_CTRL event will be generated afterwards.
8677a9b109dSSakari Ailus *
8687a9b109dSSakari Ailus * This function assumes that the control handler is locked.
8697a9b109dSSakari Ailus */
8707a9b109dSSakari Ailus void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
8717a9b109dSSakari Ailus
8727a9b109dSSakari Ailus /**
8737a9b109dSSakari Ailus * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
8747a9b109dSSakari Ailus *
8757a9b109dSSakari Ailus * @ctrl: The control to (de)activate.
8767a9b109dSSakari Ailus * @grabbed: True if the control should become grabbed.
8777a9b109dSSakari Ailus *
8787a9b109dSSakari Ailus * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
8797a9b109dSSakari Ailus * Does nothing if @ctrl == NULL.
8807a9b109dSSakari Ailus * The V4L2_EVENT_CTRL event will be generated afterwards.
8818c2721d5SMauro Carvalho Chehab * This will usually be called when starting or stopping streaming in the
8828ec4bee7SMauro Carvalho Chehab * driver.
8830996517cSHans Verkuil *
8840996517cSHans Verkuil * This function assumes that the control handler is locked by the caller.
8850996517cSHans Verkuil */
8860996517cSHans Verkuil void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
8870996517cSHans Verkuil
8886e239399SHans Verkuil /**
8890996517cSHans Verkuil * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
8900996517cSHans Verkuil *
8910996517cSHans Verkuil * @ctrl: The control to (de)activate.
8926e239399SHans Verkuil * @grabbed: True if the control should become grabbed.
8936e239399SHans Verkuil *
8940996517cSHans Verkuil * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
8957a9b109dSSakari Ailus * Does nothing if @ctrl == NULL.
8967a9b109dSSakari Ailus * The V4L2_EVENT_CTRL event will be generated afterwards.
8977a9b109dSSakari Ailus * This will usually be called when starting or stopping streaming in the
8987a9b109dSSakari Ailus * driver.
8997a9b109dSSakari Ailus *
9007a9b109dSSakari Ailus * This function assumes that the control handler is not locked and will
9017a9b109dSSakari Ailus * take the lock itself.
9027a9b109dSSakari Ailus */
v4l2_ctrl_grab(struct v4l2_ctrl * ctrl,bool grabbed)9037a9b109dSSakari Ailus static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
9040996517cSHans Verkuil {
9058c2721d5SMauro Carvalho Chehab if (!ctrl)
9068c2721d5SMauro Carvalho Chehab return;
9078c2721d5SMauro Carvalho Chehab
9088c2721d5SMauro Carvalho Chehab v4l2_ctrl_lock(ctrl);
9098c2721d5SMauro Carvalho Chehab __v4l2_ctrl_grab(ctrl, grabbed);
9108c2721d5SMauro Carvalho Chehab v4l2_ctrl_unlock(ctrl);
9118c2721d5SMauro Carvalho Chehab }
9128c2721d5SMauro Carvalho Chehab
9138c2721d5SMauro Carvalho Chehab /**
9148c2721d5SMauro Carvalho Chehab *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
9158c2721d5SMauro Carvalho Chehab *
9168c2721d5SMauro Carvalho Chehab * @ctrl: The control to update.
9178c2721d5SMauro Carvalho Chehab * @min: The control's minimum value.
9188c2721d5SMauro Carvalho Chehab * @max: The control's maximum value.
9198c2721d5SMauro Carvalho Chehab * @step: The control's step value
9208c2721d5SMauro Carvalho Chehab * @def: The control's default value.
92197eee23aSHans Verkuil *
92297eee23aSHans Verkuil * Update the range of a control on the fly. This works for control types
9238c2721d5SMauro Carvalho Chehab * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
9245a573925SSakari Ailus * @step value is interpreted as a menu_skip_mask.
9255a573925SSakari Ailus *
9265a573925SSakari Ailus * An error is returned if one of the range arguments is invalid for this
9278c2721d5SMauro Carvalho Chehab * control type.
9288c2721d5SMauro Carvalho Chehab *
9298ec4bee7SMauro Carvalho Chehab * The caller is responsible for acquiring the control handler mutex on behalf
9302ccbe779SSylwester Nawrocki * of __v4l2_ctrl_modify_range().
9312ccbe779SSylwester Nawrocki */
9322ccbe779SSylwester Nawrocki int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
9332ccbe779SSylwester Nawrocki s64 min, s64 max, u64 step, s64 def);
9342ccbe779SSylwester Nawrocki
9352ccbe779SSylwester Nawrocki /**
9362ccbe779SSylwester Nawrocki * v4l2_ctrl_modify_range() - Update the range of a control.
9372ccbe779SSylwester Nawrocki *
9382ccbe779SSylwester Nawrocki * @ctrl: The control to update.
9392ccbe779SSylwester Nawrocki * @min: The control's minimum value.
9402ccbe779SSylwester Nawrocki * @max: The control's maximum value.
9412ccbe779SSylwester Nawrocki * @step: The control's step value
9422ccbe779SSylwester Nawrocki * @def: The control's default value.
9432ccbe779SSylwester Nawrocki *
9442ccbe779SSylwester Nawrocki * Update the range of a control on the fly. This works for control types
9452ccbe779SSylwester Nawrocki * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
9465a573925SSakari Ailus * @step value is interpreted as a menu_skip_mask.
9475a573925SSakari Ailus *
9485a573925SSakari Ailus * An error is returned if one of the range arguments is invalid for this
9495a573925SSakari Ailus * control type.
9505a573925SSakari Ailus *
9515a573925SSakari Ailus * This function assumes that the control handler is not locked and will
9525a573925SSakari Ailus * take the lock itself.
9535a573925SSakari Ailus */
v4l2_ctrl_modify_range(struct v4l2_ctrl * ctrl,s64 min,s64 max,u64 step,s64 def)9545a573925SSakari Ailus static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
9555a573925SSakari Ailus s64 min, s64 max, u64 step, s64 def)
9565a573925SSakari Ailus {
9572ccbe779SSylwester Nawrocki int rval;
9588c2721d5SMauro Carvalho Chehab
95909752745SHans Verkuil v4l2_ctrl_lock(ctrl);
96009752745SHans Verkuil rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
96109752745SHans Verkuil v4l2_ctrl_unlock(ctrl);
96209752745SHans Verkuil
96309752745SHans Verkuil return rval;
96409752745SHans Verkuil }
96509752745SHans Verkuil
96609752745SHans Verkuil /**
96709752745SHans Verkuil *__v4l2_ctrl_modify_dimensions() - Unlocked variant of v4l2_ctrl_modify_dimensions()
96809752745SHans Verkuil *
96909752745SHans Verkuil * @ctrl: The control to update.
97009752745SHans Verkuil * @dims: The control's new dimensions.
97109752745SHans Verkuil *
97209752745SHans Verkuil * Update the dimensions of an array control on the fly. The elements of the
97309752745SHans Verkuil * array are reset to their default value, even if the dimensions are
97409752745SHans Verkuil * unchanged.
97509752745SHans Verkuil *
97609752745SHans Verkuil * An error is returned if @dims is invalid for this control.
97709752745SHans Verkuil *
97809752745SHans Verkuil * The caller is responsible for acquiring the control handler mutex on behalf
97909752745SHans Verkuil * of __v4l2_ctrl_modify_dimensions().
98009752745SHans Verkuil *
98109752745SHans Verkuil * Note: calling this function when the same control is used in pending requests
98209752745SHans Verkuil * is untested. It should work (a request with the wrong size of the control
98309752745SHans Verkuil * will drop that control silently), but it will be very confusing.
98409752745SHans Verkuil */
98509752745SHans Verkuil int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
98609752745SHans Verkuil u32 dims[V4L2_CTRL_MAX_DIMS]);
98709752745SHans Verkuil
98809752745SHans Verkuil /**
98909752745SHans Verkuil * v4l2_ctrl_modify_dimensions() - Update the dimensions of an array control.
99009752745SHans Verkuil *
99109752745SHans Verkuil * @ctrl: The control to update.
99209752745SHans Verkuil * @dims: The control's new dimensions.
99309752745SHans Verkuil *
99409752745SHans Verkuil * Update the dimensions of an array control on the fly. The elements of the
99509752745SHans Verkuil * array are reset to their default value, even if the dimensions are
99609752745SHans Verkuil * unchanged.
99709752745SHans Verkuil *
99809752745SHans Verkuil * An error is returned if @dims is invalid for this control type.
99909752745SHans Verkuil *
100009752745SHans Verkuil * This function assumes that the control handler is not locked and will
100109752745SHans Verkuil * take the lock itself.
100209752745SHans Verkuil *
100309752745SHans Verkuil * Note: calling this function when the same control is used in pending requests
100409752745SHans Verkuil * is untested. It should work (a request with the wrong size of the control
100509752745SHans Verkuil * will drop that control silently), but it will be very confusing.
100609752745SHans Verkuil */
v4l2_ctrl_modify_dimensions(struct v4l2_ctrl * ctrl,u32 dims[V4L2_CTRL_MAX_DIMS])100709752745SHans Verkuil static inline int v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
100809752745SHans Verkuil u32 dims[V4L2_CTRL_MAX_DIMS])
100909752745SHans Verkuil {
101009752745SHans Verkuil int rval;
101109752745SHans Verkuil
10128c2721d5SMauro Carvalho Chehab v4l2_ctrl_lock(ctrl);
10138ec4bee7SMauro Carvalho Chehab rval = __v4l2_ctrl_modify_dimensions(ctrl, dims);
10148ac7a949SHans Verkuil v4l2_ctrl_unlock(ctrl);
10158ac7a949SHans Verkuil
10168ac7a949SHans Verkuil return rval;
10178ac7a949SHans Verkuil }
10188ac7a949SHans Verkuil
10198ac7a949SHans Verkuil /**
10208ac7a949SHans Verkuil * v4l2_ctrl_notify() - Function to set a notify callback for a control.
10218ac7a949SHans Verkuil *
10228ac7a949SHans Verkuil * @ctrl: The control.
10238ac7a949SHans Verkuil * @notify: The callback function.
10248ac7a949SHans Verkuil * @priv: The callback private handle, passed as argument to the callback.
10258ec4bee7SMauro Carvalho Chehab *
10268ec4bee7SMauro Carvalho Chehab * This function sets a callback function for the control. If @ctrl is NULL,
10278ac7a949SHans Verkuil * then it will do nothing. If @notify is NULL, then the notify callback will
10288c2721d5SMauro Carvalho Chehab * be removed.
10298c2721d5SMauro Carvalho Chehab *
10308ec4bee7SMauro Carvalho Chehab * There can be only one notify. If another already exists, then a WARN_ON
103179fbc209SHans Verkuil * will be issued and the function will do nothing.
103279fbc209SHans Verkuil */
103379fbc209SHans Verkuil void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
103479fbc209SHans Verkuil void *priv);
103579fbc209SHans Verkuil
103679fbc209SHans Verkuil /**
103779fbc209SHans Verkuil * v4l2_ctrl_get_name() - Get the name of the control
10388c2721d5SMauro Carvalho Chehab *
10398c2721d5SMauro Carvalho Chehab * @id: The control ID.
10408ec4bee7SMauro Carvalho Chehab *
104179fbc209SHans Verkuil * This function returns the name of the given control ID or NULL if it isn't
104279fbc209SHans Verkuil * a known control.
104379fbc209SHans Verkuil */
104479fbc209SHans Verkuil const char *v4l2_ctrl_get_name(u32 id);
104579fbc209SHans Verkuil
104679fbc209SHans Verkuil /**
104779fbc209SHans Verkuil * v4l2_ctrl_get_menu() - Get the menu string array of the control
10488c2721d5SMauro Carvalho Chehab *
10498c2721d5SMauro Carvalho Chehab * @id: The control ID.
10508ec4bee7SMauro Carvalho Chehab *
105179fbc209SHans Verkuil * This function returns the NULL-terminated menu string array name of the
105279fbc209SHans Verkuil * given control ID or NULL if it isn't a known menu control.
105379fbc209SHans Verkuil */
105479fbc209SHans Verkuil const char * const *v4l2_ctrl_get_menu(u32 id);
105579fbc209SHans Verkuil
105679fbc209SHans Verkuil /**
105779fbc209SHans Verkuil * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
105879fbc209SHans Verkuil *
10598c2721d5SMauro Carvalho Chehab * @id: The control ID.
10608ec4bee7SMauro Carvalho Chehab * @len: The size of the integer array.
10618ec4bee7SMauro Carvalho Chehab *
10628ec4bee7SMauro Carvalho Chehab * This function returns the integer array of the given control ID or NULL if it
10630996517cSHans Verkuil * if it isn't a known integer menu control.
10640996517cSHans Verkuil */
10650996517cSHans Verkuil const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
10660996517cSHans Verkuil
10670996517cSHans Verkuil /**
10680996517cSHans Verkuil * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
10690996517cSHans Verkuil * within a driver.
10700996517cSHans Verkuil *
10710996517cSHans Verkuil * @ctrl: The control.
10720996517cSHans Verkuil *
10738c2721d5SMauro Carvalho Chehab * This returns the control's value safely by going through the control
10748c2721d5SMauro Carvalho Chehab * framework. This function will lock the control's handler, so it cannot be
10758ec4bee7SMauro Carvalho Chehab * used from within the &v4l2_ctrl_ops functions.
10768c2721d5SMauro Carvalho Chehab *
1077c4d1de70SHans Verkuil * This function is for integer type controls only.
10788c2721d5SMauro Carvalho Chehab */
1079904aef0fSHans Verkuil s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
1080904aef0fSHans Verkuil
1081904aef0fSHans Verkuil /**
10828c2721d5SMauro Carvalho Chehab * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
10838c2721d5SMauro Carvalho Chehab *
10848c2721d5SMauro Carvalho Chehab * @ctrl: The control.
10850c4348adSSakari Ailus * @val: The new value.
10868c2721d5SMauro Carvalho Chehab *
10878ec4bee7SMauro Carvalho Chehab * This sets the control's new value safely by going through the control
10888ec4bee7SMauro Carvalho Chehab * framework. This function assumes the control's handler is already locked,
10898ec4bee7SMauro Carvalho Chehab * allowing it to be used from within the &v4l2_ctrl_ops functions.
10900996517cSHans Verkuil *
10910996517cSHans Verkuil * This function is for integer type controls only.
10920996517cSHans Verkuil */
1093904aef0fSHans Verkuil int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
10940996517cSHans Verkuil
10950996517cSHans Verkuil /**
10960996517cSHans Verkuil * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
10970996517cSHans Verkuil * within a driver.
10980996517cSHans Verkuil * @ctrl: The control.
10990c4348adSSakari Ailus * @val: The new value.
11000c4348adSSakari Ailus *
11010c4348adSSakari Ailus * This sets the control's new value safely by going through the control
11020c4348adSSakari Ailus * framework. This function will lock the control's handler, so it cannot be
11030c4348adSSakari Ailus * used from within the &v4l2_ctrl_ops functions.
11040c4348adSSakari Ailus *
11050c4348adSSakari Ailus * This function is for integer type controls only.
11060c4348adSSakari Ailus */
v4l2_ctrl_s_ctrl(struct v4l2_ctrl * ctrl,s32 val)11070c4348adSSakari Ailus static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
11080c4348adSSakari Ailus {
11090996517cSHans Verkuil int rval;
11108c2721d5SMauro Carvalho Chehab
11118c2721d5SMauro Carvalho Chehab v4l2_ctrl_lock(ctrl);
11128c2721d5SMauro Carvalho Chehab rval = __v4l2_ctrl_s_ctrl(ctrl, val);
11138ec4bee7SMauro Carvalho Chehab v4l2_ctrl_unlock(ctrl);
111403d5285bSLaurent Pinchart
111503d5285bSLaurent Pinchart return rval;
111603d5285bSLaurent Pinchart }
111703d5285bSLaurent Pinchart
111803d5285bSLaurent Pinchart /**
111903d5285bSLaurent Pinchart * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
112003d5285bSLaurent Pinchart * from within a driver.
112103d5285bSLaurent Pinchart *
112203d5285bSLaurent Pinchart * @ctrl: The control.
112303d5285bSLaurent Pinchart *
11248c2721d5SMauro Carvalho Chehab * This returns the control's value safely by going through the control
11258c2721d5SMauro Carvalho Chehab * framework. This function will lock the control's handler, so it cannot be
11268c2721d5SMauro Carvalho Chehab * used from within the &v4l2_ctrl_ops functions.
11278c2721d5SMauro Carvalho Chehab *
11288c2721d5SMauro Carvalho Chehab * This function is for 64-bit integer type controls only.
11298c2721d5SMauro Carvalho Chehab */
1130904aef0fSHans Verkuil s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
1131904aef0fSHans Verkuil
1132904aef0fSHans Verkuil /**
11338c2721d5SMauro Carvalho Chehab * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
11348c2721d5SMauro Carvalho Chehab *
11358c2721d5SMauro Carvalho Chehab * @ctrl: The control.
11360c4348adSSakari Ailus * @val: The new value.
11370c4348adSSakari Ailus *
11388ec4bee7SMauro Carvalho Chehab * This sets the control's new value safely by going through the control
11398ec4bee7SMauro Carvalho Chehab * framework. This function assumes the control's handler is already locked,
11408c2721d5SMauro Carvalho Chehab * allowing it to be used from within the &v4l2_ctrl_ops functions.
11418c2721d5SMauro Carvalho Chehab *
114203d5285bSLaurent Pinchart * This function is for 64-bit integer type controls only.
114303d5285bSLaurent Pinchart */
114403d5285bSLaurent Pinchart int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1145904aef0fSHans Verkuil
114603d5285bSLaurent Pinchart /**
114703d5285bSLaurent Pinchart * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
114803d5285bSLaurent Pinchart * from within a driver.
114903d5285bSLaurent Pinchart *
115003d5285bSLaurent Pinchart * @ctrl: The control.
11510c4348adSSakari Ailus * @val: The new value.
11520c4348adSSakari Ailus *
11530c4348adSSakari Ailus * This sets the control's new value safely by going through the control
11540c4348adSSakari Ailus * framework. This function will lock the control's handler, so it cannot be
11550c4348adSSakari Ailus * used from within the &v4l2_ctrl_ops functions.
11560c4348adSSakari Ailus *
11570c4348adSSakari Ailus * This function is for 64-bit integer type controls only.
11580c4348adSSakari Ailus */
v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl * ctrl,s64 val)11590c4348adSSakari Ailus static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
11600c4348adSSakari Ailus {
116103d5285bSLaurent Pinchart int rval;
11628ec4bee7SMauro Carvalho Chehab
11638ec4bee7SMauro Carvalho Chehab v4l2_ctrl_lock(ctrl);
11648c2721d5SMauro Carvalho Chehab rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
11658c2721d5SMauro Carvalho Chehab v4l2_ctrl_unlock(ctrl);
11668c2721d5SMauro Carvalho Chehab
11678c2721d5SMauro Carvalho Chehab return rval;
1168904aef0fSHans Verkuil }
1169904aef0fSHans Verkuil
1170904aef0fSHans Verkuil /**
11718c2721d5SMauro Carvalho Chehab * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
11728c2721d5SMauro Carvalho Chehab *
11738c2721d5SMauro Carvalho Chehab * @ctrl: The control.
11745d0360a4SHans Verkuil * @s: The new string.
11755d0360a4SHans Verkuil *
11768ec4bee7SMauro Carvalho Chehab * This sets the control's new string safely by going through the control
11778ec4bee7SMauro Carvalho Chehab * framework. This function assumes the control's handler is already locked,
11788c2721d5SMauro Carvalho Chehab * allowing it to be used from within the &v4l2_ctrl_ops functions.
11798c2721d5SMauro Carvalho Chehab *
11805d0360a4SHans Verkuil * This function is for string type controls only.
11815d0360a4SHans Verkuil */
1182c4d1de70SHans Verkuil int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1183904aef0fSHans Verkuil
11845d0360a4SHans Verkuil /**
11855d0360a4SHans Verkuil * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
11865d0360a4SHans Verkuil * from within a driver.
11875d0360a4SHans Verkuil *
11885d0360a4SHans Verkuil * @ctrl: The control.
11895d0360a4SHans Verkuil * @s: The new string.
11905d0360a4SHans Verkuil *
11915d0360a4SHans Verkuil * This sets the control's new string safely by going through the control
11925d0360a4SHans Verkuil * framework. This function will lock the control's handler, so it cannot be
11935d0360a4SHans Verkuil * used from within the &v4l2_ctrl_ops functions.
11945d0360a4SHans Verkuil *
11955d0360a4SHans Verkuil * This function is for string type controls only.
11965d0360a4SHans Verkuil */
v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl * ctrl,const char * s)11975d0360a4SHans Verkuil static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
11985d0360a4SHans Verkuil {
11995d0360a4SHans Verkuil int rval;
1200d1dc4937SRicardo Ribalda Delgado
1201b2b1046fSHans Verkuil v4l2_ctrl_lock(ctrl);
1202d1dc4937SRicardo Ribalda Delgado rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1203d1dc4937SRicardo Ribalda Delgado v4l2_ctrl_unlock(ctrl);
1204b2b1046fSHans Verkuil
1205b2b1046fSHans Verkuil return rval;
1206d1dc4937SRicardo Ribalda Delgado }
1207b2b1046fSHans Verkuil
1208b2b1046fSHans Verkuil /**
1209b2b1046fSHans Verkuil * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
1210d1dc4937SRicardo Ribalda Delgado *
1211b2b1046fSHans Verkuil * @ctrl: The control.
1212d1dc4937SRicardo Ribalda Delgado * @type: The type of the data.
1213b2b1046fSHans Verkuil * @p: The new compound payload.
1214b2b1046fSHans Verkuil *
1215d1dc4937SRicardo Ribalda Delgado * This sets the control's new compound payload safely by going through the
1216d1dc4937SRicardo Ribalda Delgado * control framework. This function assumes the control's handler is already
1217b2b1046fSHans Verkuil * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
1218d1dc4937SRicardo Ribalda Delgado *
1219d1dc4937SRicardo Ribalda Delgado * This function is for compound type controls only.
1220d1dc4937SRicardo Ribalda Delgado */
1221b2b1046fSHans Verkuil int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1222b2b1046fSHans Verkuil enum v4l2_ctrl_type type, const void *p);
1223d1dc4937SRicardo Ribalda Delgado
1224b2b1046fSHans Verkuil /**
1225b2b1046fSHans Verkuil * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
1226b2b1046fSHans Verkuil * from within a driver.
1227d1dc4937SRicardo Ribalda Delgado *
1228b2b1046fSHans Verkuil * @ctrl: The control.
1229d1dc4937SRicardo Ribalda Delgado * @type: The type of the data.
1230b2b1046fSHans Verkuil * @p: The new compound payload.
1231b2b1046fSHans Verkuil *
1232b2b1046fSHans Verkuil * This sets the control's new compound payload safely by going through the
1233d1dc4937SRicardo Ribalda Delgado * control framework. This function will lock the control's handler, so it
1234d1dc4937SRicardo Ribalda Delgado * cannot be used from within the &v4l2_ctrl_ops functions.
1235d1dc4937SRicardo Ribalda Delgado *
1236d1dc4937SRicardo Ribalda Delgado * This function is for compound type controls only.
1237b2b1046fSHans Verkuil */
v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl * ctrl,enum v4l2_ctrl_type type,const void * p)1238d1dc4937SRicardo Ribalda Delgado static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1239d1dc4937SRicardo Ribalda Delgado enum v4l2_ctrl_type type,
1240d1dc4937SRicardo Ribalda Delgado const void *p)
1241d1dc4937SRicardo Ribalda Delgado {
1242d1dc4937SRicardo Ribalda Delgado int rval;
1243b2b1046fSHans Verkuil
1244b2b1046fSHans Verkuil v4l2_ctrl_lock(ctrl);
1245b2b1046fSHans Verkuil rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
1246b2b1046fSHans Verkuil v4l2_ctrl_unlock(ctrl);
1247b2b1046fSHans Verkuil
1248b2b1046fSHans Verkuil return rval;
1249ce727574SHans Verkuil }
12503e366149SHans de Goede
12518ec4bee7SMauro Carvalho Chehab /* Helper defines for area type controls */
12528ec4bee7SMauro Carvalho Chehab #define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
12538ec4bee7SMauro Carvalho Chehab __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
12548ec4bee7SMauro Carvalho Chehab #define v4l2_ctrl_s_ctrl_area(ctrl, area) \
12558ec4bee7SMauro Carvalho Chehab v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1256f8441a43SMauro Carvalho Chehab
12578ec4bee7SMauro Carvalho Chehab /* Internal helper functions that deal with control events. */
1258f8441a43SMauro Carvalho Chehab extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
12598ec4bee7SMauro Carvalho Chehab
12608ec4bee7SMauro Carvalho Chehab /**
12613e366149SHans de Goede * v4l2_ctrl_replace - Function to be used as a callback to
12628ec4bee7SMauro Carvalho Chehab * &struct v4l2_subscribed_event_ops replace\(\)
12638ec4bee7SMauro Carvalho Chehab *
12648ec4bee7SMauro Carvalho Chehab * @old: pointer to struct &v4l2_event with the reported
12658ec4bee7SMauro Carvalho Chehab * event;
12668ec4bee7SMauro Carvalho Chehab * @new: pointer to struct &v4l2_event with the modified
1267f8441a43SMauro Carvalho Chehab * event;
12688ec4bee7SMauro Carvalho Chehab */
1269f8441a43SMauro Carvalho Chehab void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
12708ec4bee7SMauro Carvalho Chehab
12718ec4bee7SMauro Carvalho Chehab /**
12723e366149SHans de Goede * v4l2_ctrl_merge - Function to be used as a callback to
12736e239399SHans Verkuil * &struct v4l2_subscribed_event_ops merge(\)
12748ec4bee7SMauro Carvalho Chehab *
12758ec4bee7SMauro Carvalho Chehab * @old: pointer to struct &v4l2_event with the reported
12768ec4bee7SMauro Carvalho Chehab * event;
12778ec4bee7SMauro Carvalho Chehab * @new: pointer to struct &v4l2_event with the merged
12788ec4bee7SMauro Carvalho Chehab * event;
12798ec4bee7SMauro Carvalho Chehab */
12808ec4bee7SMauro Carvalho Chehab void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
12818ec4bee7SMauro Carvalho Chehab
12828ec4bee7SMauro Carvalho Chehab /**
12838ec4bee7SMauro Carvalho Chehab * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1284e2ecb257SHans Verkuil *
1285e2ecb257SHans Verkuil * @file: pointer to struct file
12868ec4bee7SMauro Carvalho Chehab * @fh: unused. Kept just to be compatible to the arguments expected by
12878ec4bee7SMauro Carvalho Chehab * &struct v4l2_ioctl_ops.vidioc_log_status.
12888ec4bee7SMauro Carvalho Chehab *
12898ec4bee7SMauro Carvalho Chehab * Can be used as a vidioc_log_status function that just dumps all controls
12908ec4bee7SMauro Carvalho Chehab * associated with the filehandle.
12918ec4bee7SMauro Carvalho Chehab */
12928ec4bee7SMauro Carvalho Chehab int v4l2_ctrl_log_status(struct file *file, void *fh);
12938ec4bee7SMauro Carvalho Chehab
12948ec4bee7SMauro Carvalho Chehab /**
12958ec4bee7SMauro Carvalho Chehab * v4l2_ctrl_subscribe_event - Subscribes to an event
1296a26243b0SHans Verkuil *
129785f5fe39SHans Verkuil *
1298a26243b0SHans Verkuil * @fh: pointer to struct v4l2_fh
12998ec4bee7SMauro Carvalho Chehab * @sub: pointer to &struct v4l2_event_subscription
13008ec4bee7SMauro Carvalho Chehab *
13018ec4bee7SMauro Carvalho Chehab * Can be used as a vidioc_subscribe_event function that just subscribes
13028ec4bee7SMauro Carvalho Chehab * control events.
13038ec4bee7SMauro Carvalho Chehab */
13048ec4bee7SMauro Carvalho Chehab int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
13058ec4bee7SMauro Carvalho Chehab const struct v4l2_event_subscription *sub);
1306c23e0cb8SAl Viro
1307a26243b0SHans Verkuil /**
13086fa6f831SHans Verkuil * v4l2_ctrl_poll - function to be used as a callback to the poll()
13096fa6f831SHans Verkuil * That just polls for control events.
13106fa6f831SHans Verkuil *
13116fa6f831SHans Verkuil * @file: pointer to struct file
13126fa6f831SHans Verkuil * @wait: pointer to struct poll_table_struct
13136fa6f831SHans Verkuil */
13146fa6f831SHans Verkuil __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
13156fa6f831SHans Verkuil
13166fa6f831SHans Verkuil /**
13176fa6f831SHans Verkuil * v4l2_ctrl_request_setup - helper function to apply control values in a request
13186fa6f831SHans Verkuil *
131909ca38a5SDafna Hirschfeld * @req: The request
13206fa6f831SHans Verkuil * @parent: The parent control handler ('priv' in media_request_object_find())
13216fa6f831SHans Verkuil *
13226fa6f831SHans Verkuil * This is a helper function to call the control handler's s_ctrl callback with
13236fa6f831SHans Verkuil * the control values contained in the request. Do note that this approach of
13246fa6f831SHans Verkuil * applying control values in a request is only applicable to memory-to-memory
13256fa6f831SHans Verkuil * devices.
13266fa6f831SHans Verkuil */
13276fa6f831SHans Verkuil int v4l2_ctrl_request_setup(struct media_request *req,
13286fa6f831SHans Verkuil struct v4l2_ctrl_handler *parent);
13296fa6f831SHans Verkuil
13306fa6f831SHans Verkuil /**
13316fa6f831SHans Verkuil * v4l2_ctrl_request_complete - Complete a control handler request object
13326fa6f831SHans Verkuil *
13336fa6f831SHans Verkuil * @req: The request
13346fa6f831SHans Verkuil * @parent: The parent control handler ('priv' in media_request_object_find())
13356fa6f831SHans Verkuil *
13366fa6f831SHans Verkuil * This function is to be called on each control handler that may have had a
13375f611d74SHans Verkuil * request object associated with it, i.e. control handlers of a driver that
13385f611d74SHans Verkuil * supports requests.
13395f611d74SHans Verkuil *
13405f611d74SHans Verkuil * The function first obtains the values of any volatile controls in the control
13415f611d74SHans Verkuil * handler and attach them to the request. Then, the function completes the
13425f611d74SHans Verkuil * request object.
13435f611d74SHans Verkuil */
13445f611d74SHans Verkuil void v4l2_ctrl_request_complete(struct media_request *req,
13455f611d74SHans Verkuil struct v4l2_ctrl_handler *parent);
1346*7370f639SMiaoqian Lin
13475f611d74SHans Verkuil /**
13485f611d74SHans Verkuil * v4l2_ctrl_request_hdl_find - Find the control handler in the request
13495f611d74SHans Verkuil *
13505f611d74SHans Verkuil * @req: The request
13515f611d74SHans Verkuil * @parent: The parent control handler ('priv' in media_request_object_find())
13525f611d74SHans Verkuil *
13535f611d74SHans Verkuil * This function finds the control handler in the request. It may return
13545f611d74SHans Verkuil * NULL if not found. When done, you must call v4l2_ctrl_request_hdl_put()
13555f611d74SHans Verkuil * with the returned handler pointer.
13565f611d74SHans Verkuil *
13575f611d74SHans Verkuil * If the request is not in state VALIDATING or QUEUED, then this function
13585f611d74SHans Verkuil * will always return NULL.
13595f611d74SHans Verkuil *
13605f611d74SHans Verkuil * Note that in state VALIDATING the req_queue_mutex is held, so
13615f611d74SHans Verkuil * no objects can be added or deleted from the request.
13625f611d74SHans Verkuil *
13635f611d74SHans Verkuil * In state QUEUED it is the driver that will have to ensure this.
13645f611d74SHans Verkuil */
13655f611d74SHans Verkuil struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
13665f611d74SHans Verkuil struct v4l2_ctrl_handler *parent);
13675f611d74SHans Verkuil
13685f611d74SHans Verkuil /**
13695f611d74SHans Verkuil * v4l2_ctrl_request_hdl_put - Put the control handler
13705f611d74SHans Verkuil *
13715f611d74SHans Verkuil * @hdl: Put this control handler
13725f611d74SHans Verkuil *
13735f611d74SHans Verkuil * This function released the control handler previously obtained from'
13745f611d74SHans Verkuil * v4l2_ctrl_request_hdl_find().
1375b0649455SMauro Carvalho Chehab */
v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler * hdl)13765f611d74SHans Verkuil static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
13775f611d74SHans Verkuil {
13785f611d74SHans Verkuil if (hdl)
13795f611d74SHans Verkuil media_request_object_put(&hdl->req_obj);
13805f611d74SHans Verkuil }
13815f611d74SHans Verkuil
13825f611d74SHans Verkuil /**
13835f611d74SHans Verkuil * v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID.
13845f611d74SHans Verkuil *
13856fa6f831SHans Verkuil * @hdl: The control handler from the request.
13868ec4bee7SMauro Carvalho Chehab * @id: The ID of the control to find.
13878ec4bee7SMauro Carvalho Chehab *
13888ec4bee7SMauro Carvalho Chehab * This function returns a pointer to the control if this control is
13898ec4bee7SMauro Carvalho Chehab * part of the request or NULL otherwise.
13908ec4bee7SMauro Carvalho Chehab */
13918ec4bee7SMauro Carvalho Chehab struct v4l2_ctrl *
13928ec4bee7SMauro Carvalho Chehab v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
13938ec4bee7SMauro Carvalho Chehab
13948ec4bee7SMauro Carvalho Chehab /* Helpers for ioctl_ops */
13958ec4bee7SMauro Carvalho Chehab
13968ec4bee7SMauro Carvalho Chehab /**
13970996517cSHans Verkuil * v4l2_queryctrl - Helper function to implement
13988ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
13998ec4bee7SMauro Carvalho Chehab *
14008ec4bee7SMauro Carvalho Chehab * @hdl: pointer to &struct v4l2_ctrl_handler
14018ec4bee7SMauro Carvalho Chehab * @qc: pointer to &struct v4l2_queryctrl
14028ec4bee7SMauro Carvalho Chehab *
14038ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14048ec4bee7SMauro Carvalho Chehab */
14058ec4bee7SMauro Carvalho Chehab int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
14068ec4bee7SMauro Carvalho Chehab
14078ec4bee7SMauro Carvalho Chehab /**
14088ec4bee7SMauro Carvalho Chehab * v4l2_query_ext_ctrl - Helper function to implement
14098ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
14108ec4bee7SMauro Carvalho Chehab *
14118ec4bee7SMauro Carvalho Chehab * @hdl: pointer to &struct v4l2_ctrl_handler
14128ec4bee7SMauro Carvalho Chehab * @qc: pointer to &struct v4l2_query_ext_ctrl
14138ec4bee7SMauro Carvalho Chehab *
14148ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14158ec4bee7SMauro Carvalho Chehab */
14168ec4bee7SMauro Carvalho Chehab int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
14178ec4bee7SMauro Carvalho Chehab struct v4l2_query_ext_ctrl *qc);
14188ec4bee7SMauro Carvalho Chehab
14198ec4bee7SMauro Carvalho Chehab /**
14200996517cSHans Verkuil * v4l2_querymenu - Helper function to implement
14218ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
14228ec4bee7SMauro Carvalho Chehab *
14238ec4bee7SMauro Carvalho Chehab * @hdl: pointer to &struct v4l2_ctrl_handler
14248ec4bee7SMauro Carvalho Chehab * @qm: pointer to &struct v4l2_querymenu
14258ec4bee7SMauro Carvalho Chehab *
14268ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14278ec4bee7SMauro Carvalho Chehab */
14288ec4bee7SMauro Carvalho Chehab int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
14298ec4bee7SMauro Carvalho Chehab
14308ec4bee7SMauro Carvalho Chehab /**
14310996517cSHans Verkuil * v4l2_g_ctrl - Helper function to implement
14328ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
14338ec4bee7SMauro Carvalho Chehab *
14348ec4bee7SMauro Carvalho Chehab * @hdl: pointer to &struct v4l2_ctrl_handler
14358ec4bee7SMauro Carvalho Chehab * @ctrl: pointer to &struct v4l2_control
14368ec4bee7SMauro Carvalho Chehab *
14378ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14388ec4bee7SMauro Carvalho Chehab */
14398ec4bee7SMauro Carvalho Chehab int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
14408ec4bee7SMauro Carvalho Chehab
14418ec4bee7SMauro Carvalho Chehab /**
14428ec4bee7SMauro Carvalho Chehab * v4l2_s_ctrl - Helper function to implement
14438ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1444ab892bacSHans Verkuil *
1445ab892bacSHans Verkuil * @fh: pointer to &struct v4l2_fh
14468ec4bee7SMauro Carvalho Chehab * @hdl: pointer to &struct v4l2_ctrl_handler
14478ec4bee7SMauro Carvalho Chehab *
14488ec4bee7SMauro Carvalho Chehab * @ctrl: pointer to &struct v4l2_control
14498ec4bee7SMauro Carvalho Chehab *
14508ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14518ec4bee7SMauro Carvalho Chehab */
1452173f6eacSEzequiel Garcia int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1453c41e9cffSHans Verkuil struct v4l2_control *ctrl);
14548ec4bee7SMauro Carvalho Chehab
14558ec4bee7SMauro Carvalho Chehab /**
14568ec4bee7SMauro Carvalho Chehab * v4l2_g_ext_ctrls - Helper function to implement
14578ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1458173f6eacSEzequiel Garcia *
1459173f6eacSEzequiel Garcia * @hdl: pointer to &struct v4l2_ctrl_handler
14608ec4bee7SMauro Carvalho Chehab * @vdev: pointer to &struct video_device
14618ec4bee7SMauro Carvalho Chehab * @mdev: pointer to &struct media_device
14628ec4bee7SMauro Carvalho Chehab * @c: pointer to &struct v4l2_ext_controls
14638ec4bee7SMauro Carvalho Chehab *
14648ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14658ec4bee7SMauro Carvalho Chehab */
1466173f6eacSEzequiel Garcia int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
1467c41e9cffSHans Verkuil struct media_device *mdev, struct v4l2_ext_controls *c);
14688ec4bee7SMauro Carvalho Chehab
14698ec4bee7SMauro Carvalho Chehab /**
14708ec4bee7SMauro Carvalho Chehab * v4l2_try_ext_ctrls - Helper function to implement
14718ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
14728ec4bee7SMauro Carvalho Chehab *
1473173f6eacSEzequiel Garcia * @hdl: pointer to &struct v4l2_ctrl_handler
1474c41e9cffSHans Verkuil * @vdev: pointer to &struct video_device
14758ec4bee7SMauro Carvalho Chehab * @mdev: pointer to &struct media_device
14768ec4bee7SMauro Carvalho Chehab * @c: pointer to &struct v4l2_ext_controls
14778ec4bee7SMauro Carvalho Chehab *
14788ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14798ec4bee7SMauro Carvalho Chehab */
14808ec4bee7SMauro Carvalho Chehab int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
14818ec4bee7SMauro Carvalho Chehab struct video_device *vdev,
14828ec4bee7SMauro Carvalho Chehab struct media_device *mdev,
1483173f6eacSEzequiel Garcia struct v4l2_ext_controls *c);
1484c41e9cffSHans Verkuil
14858ec4bee7SMauro Carvalho Chehab /**
14868ec4bee7SMauro Carvalho Chehab * v4l2_s_ext_ctrls - Helper function to implement
14878ec4bee7SMauro Carvalho Chehab * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
14888ec4bee7SMauro Carvalho Chehab *
1489ab892bacSHans Verkuil * @fh: pointer to &struct v4l2_fh
1490173f6eacSEzequiel Garcia * @hdl: pointer to &struct v4l2_ctrl_handler
1491c41e9cffSHans Verkuil * @vdev: pointer to &struct video_device
1492ab892bacSHans Verkuil * @mdev: pointer to &struct media_device
14930996517cSHans Verkuil * @c: pointer to &struct v4l2_ext_controls
14948ec4bee7SMauro Carvalho Chehab *
14958ec4bee7SMauro Carvalho Chehab * If hdl == NULL then they will all return -EINVAL.
14968ec4bee7SMauro Carvalho Chehab */
14978ec4bee7SMauro Carvalho Chehab int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
14988ec4bee7SMauro Carvalho Chehab struct video_device *vdev,
14998ec4bee7SMauro Carvalho Chehab struct media_device *mdev,
15008ec4bee7SMauro Carvalho Chehab struct v4l2_ext_controls *c);
15018ec4bee7SMauro Carvalho Chehab
15028ec4bee7SMauro Carvalho Chehab /**
150322fa4279SSylwester Nawrocki * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
150422fa4279SSylwester Nawrocki * as a &struct v4l2_subdev_core_ops subscribe_event function
150522fa4279SSylwester Nawrocki * that just subscribes control events.
15068ec4bee7SMauro Carvalho Chehab *
15078ec4bee7SMauro Carvalho Chehab * @sd: pointer to &struct v4l2_subdev
15088ec4bee7SMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh
15098ec4bee7SMauro Carvalho Chehab * @sub: pointer to &struct v4l2_event_subscription
15108ec4bee7SMauro Carvalho Chehab */
15118ec4bee7SMauro Carvalho Chehab int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1512ffa9b9f0SSylwester Nawrocki struct v4l2_event_subscription *sub);
1513ffa9b9f0SSylwester Nawrocki
1514e0a36063SJacopo Mondi /**
1515e0a36063SJacopo Mondi * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1516e0a36063SJacopo Mondi * handler.
1517e0a36063SJacopo Mondi *
1518e0a36063SJacopo Mondi * @sd: pointer to &struct v4l2_subdev
1519e0a36063SJacopo Mondi */
1520e0a36063SJacopo Mondi int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1521e0a36063SJacopo Mondi
1522e0a36063SJacopo Mondi /**
1523e0a36063SJacopo Mondi * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
1524e0a36063SJacopo Mondi * properties
1525e0a36063SJacopo Mondi *
1526e0a36063SJacopo Mondi * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
1527e0a36063SJacopo Mondi * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
1528e0a36063SJacopo Mondi * @p: pointer to &struct v4l2_fwnode_device_properties
1529e0a36063SJacopo Mondi *
1530e0a36063SJacopo Mondi * This function registers controls associated to device properties, using the
1531e0a36063SJacopo Mondi * property values contained in @p parameter, if the property has been set to
1532e0a36063SJacopo Mondi * a value.
1533e0a36063SJacopo Mondi *
1534e0a36063SJacopo Mondi * Currently the following v4l2 controls are parsed and registered:
1535e0a36063SJacopo Mondi * - V4L2_CID_CAMERA_ORIENTATION
1536e0a36063SJacopo Mondi * - V4L2_CID_CAMERA_SENSOR_ROTATION;
1537e0a36063SJacopo Mondi *
1538e0a36063SJacopo Mondi * Controls already registered by the caller with the @hdl control handler are
1539f1739ec4SXavier Roumegue * not overwritten. Callers should register the controls they want to handle
1540f1739ec4SXavier Roumegue * themselves before calling this function.
1541f1739ec4SXavier Roumegue *
1542f1739ec4SXavier Roumegue * Return: 0 on success, a negative error code on failure.
1543f1739ec4SXavier Roumegue */
1544f1739ec4SXavier Roumegue int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
1545f1739ec4SXavier Roumegue const struct v4l2_ctrl_ops *ctrl_ops,
1546f1739ec4SXavier Roumegue const struct v4l2_fwnode_device_properties *p);
1547f1739ec4SXavier Roumegue
1548f1739ec4SXavier Roumegue /**
1549cd75981eSHans Verkuil * v4l2_ctrl_type_op_equal - Default v4l2_ctrl_type_ops equal callback.
1550f1739ec4SXavier Roumegue *
1551f1739ec4SXavier Roumegue * @ctrl: The v4l2_ctrl pointer.
1552f1739ec4SXavier Roumegue * @ptr1: A v4l2 control value.
1553f1739ec4SXavier Roumegue * @ptr2: A v4l2 control value.
1554f1739ec4SXavier Roumegue *
1555f1739ec4SXavier Roumegue * Return: true if values are equal, otherwise false.
1556f1739ec4SXavier Roumegue */
1557f1739ec4SXavier Roumegue bool v4l2_ctrl_type_op_equal(const struct v4l2_ctrl *ctrl,
1558f1739ec4SXavier Roumegue union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2);
1559f1739ec4SXavier Roumegue
1560f1739ec4SXavier Roumegue /**
1561f1739ec4SXavier Roumegue * v4l2_ctrl_type_op_init - Default v4l2_ctrl_type_ops init callback.
1562cd75981eSHans Verkuil *
1563f1739ec4SXavier Roumegue * @ctrl: The v4l2_ctrl pointer.
1564f1739ec4SXavier Roumegue * @from_idx: Starting element index.
1565f1739ec4SXavier Roumegue * @ptr: The v4l2 control value.
1566f1739ec4SXavier Roumegue *
1567f1739ec4SXavier Roumegue * Return: void
1568f1739ec4SXavier Roumegue */
1569f1739ec4SXavier Roumegue void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx,
1570f1739ec4SXavier Roumegue union v4l2_ctrl_ptr ptr);
1571f1739ec4SXavier Roumegue
1572f1739ec4SXavier Roumegue /**
1573f1739ec4SXavier Roumegue * v4l2_ctrl_type_op_log - Default v4l2_ctrl_type_ops log callback.
1574f1739ec4SXavier Roumegue *
1575f1739ec4SXavier Roumegue * @ctrl: The v4l2_ctrl pointer.
1576f1739ec4SXavier Roumegue *
1577f1739ec4SXavier Roumegue * Return: void
1578f1739ec4SXavier Roumegue */
1579f1739ec4SXavier Roumegue void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl);
1580f1739ec4SXavier Roumegue
1581cd75981eSHans Verkuil /**
1582f1739ec4SXavier Roumegue * v4l2_ctrl_type_op_validate - Default v4l2_ctrl_type_ops validate callback.
15830996517cSHans Verkuil *
1584 * @ctrl: The v4l2_ctrl pointer.
1585 * @ptr: The v4l2 control value.
1586 *
1587 * Return: 0 on success, a negative error code on failure.
1588 */
1589 int v4l2_ctrl_type_op_validate(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);
1590
1591 #endif
1592