blob: b3ce438f1329788e7f281aa427c40d6737ed3e10 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Hans Verkuil09965172010-08-01 14:32:42 -03002/*
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03003 * V4L2 controls support header.
4 *
5 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
Hans Verkuil09965172010-08-01 14:32:42 -03006 */
7
8#ifndef _V4L2_CTRLS_H
9#define _V4L2_CTRLS_H
10
11#include <linux/list.h>
Andrzej Hajdaa19dec62013-06-28 05:44:22 -030012#include <linux/mutex.h>
Laurent Pinchart01c40c02010-11-19 11:20:06 -030013#include <linux/videodev2.h>
Hans Verkuil52beedd2018-05-21 04:54:37 -040014#include <media/media-request.h>
Hans Verkuil09965172010-08-01 14:32:42 -030015
Hans Verkuil95140632018-12-05 06:28:20 -050016/*
Pawel Osciak1f0545d2019-05-24 05:20:28 -040017 * Include the stateless codec compound control definitions.
Hans Verkuil95140632018-12-05 06:28:20 -050018 * This will move to the public headers once this API is fully stable.
19 */
Paul Kocialkowski256fa392019-10-22 12:26:52 -030020#include <media/hevc-ctrls.h>
Hans Verkuil95140632018-12-05 06:28:20 -050021
Hans Verkuil09965172010-08-01 14:32:42 -030022/* forward references */
Laurent Pinchart528f0f72012-04-23 08:20:35 -030023struct file;
Jacopo Mondiae6ff162020-05-09 11:04:50 +020024struct poll_table_struct;
25struct v4l2_ctrl;
Hans Verkuil09965172010-08-01 14:32:42 -030026struct v4l2_ctrl_handler;
Hans Verkuileb5b16e2011-06-14 10:04:06 -030027struct v4l2_ctrl_helper;
Jacopo Mondiae6ff162020-05-09 11:04:50 +020028struct v4l2_fh;
Jacopo Mondie0a36062020-05-09 11:04:52 +020029struct v4l2_fwnode_device_properties;
Hans Verkuil09965172010-08-01 14:32:42 -030030struct v4l2_subdev;
Hans Verkuil77068d32011-06-13 18:55:58 -030031struct v4l2_subscribed_event;
Jacopo Mondiae6ff162020-05-09 11:04:50 +020032struct video_device;
Hans Verkuil09965172010-08-01 14:32:42 -030033
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030034/**
35 * union v4l2_ctrl_ptr - A pointer to a control value.
Paul Kocialkowskic27bb302018-09-13 10:51:52 -040036 * @p_s32: Pointer to a 32-bit signed value.
37 * @p_s64: Pointer to a 64-bit signed value.
38 * @p_u8: Pointer to a 8-bit unsigned value.
39 * @p_u16: Pointer to a 16-bit unsigned value.
40 * @p_u32: Pointer to a 32-bit unsigned value.
41 * @p_char: Pointer to a string.
Ezequiel Garciaf329e212021-04-29 16:48:12 +020042 * @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure.
43 * @p_mpeg2_picture: Pointer to a MPEG2 picture structure.
Ezequiel Garcia118f3e152021-04-29 16:48:09 +020044 * @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure.
Dafna Hirschfeld2495f392019-03-06 16:13:40 -050045 * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
Pawel Osciak1f0545d2019-05-24 05:20:28 -040046 * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
47 * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
48 * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
49 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
50 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
Ezequiel Garciaeb44c6c2020-08-25 05:52:29 +020051 * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
Ezequiel Garciad04c1142021-03-04 15:07:48 +010052 * @p_vp8_frame: Pointer to a VP8 frame params structure.
Andrzej Pietrasiewiczb88dbe32021-11-16 14:38:35 +000053 * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.
54 * @p_vp9_frame: Pointer to a VP9 frame params structure.
Paul Kocialkowski256fa392019-10-22 12:26:52 -030055 * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
56 * @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
57 * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
Stanimir Varbanov1ad0de72021-01-19 16:06:42 +010058 * @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure.
59 * @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -030060 * @p_area: Pointer to an area.
Paul Kocialkowskic27bb302018-09-13 10:51:52 -040061 * @p: Pointer to a compound value.
Ricardo Ribalda Delgadof1bd5ea2019-11-04 14:09:19 +010062 * @p_const: Pointer to a constant compound value.
Hans Verkuil01760772014-04-27 03:22:17 -030063 */
64union v4l2_ctrl_ptr {
65 s32 *p_s32;
66 s64 *p_s64;
Hans Verkuildda4a4d2014-06-10 07:30:04 -030067 u8 *p_u8;
68 u16 *p_u16;
Hans Verkuil811c5082014-07-21 10:45:37 -030069 u32 *p_u32;
Hans Verkuil01760772014-04-27 03:22:17 -030070 char *p_char;
Ezequiel Garciaf329e212021-04-29 16:48:12 +020071 struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence;
72 struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture;
Ezequiel Garcia118f3e152021-04-29 16:48:09 +020073 struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation;
Dafna Hirschfeld2495f392019-03-06 16:13:40 -050074 struct v4l2_ctrl_fwht_params *p_fwht_params;
Pawel Osciak1f0545d2019-05-24 05:20:28 -040075 struct v4l2_ctrl_h264_sps *p_h264_sps;
76 struct v4l2_ctrl_h264_pps *p_h264_pps;
77 struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
78 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
79 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
Ezequiel Garciaeb44c6c2020-08-25 05:52:29 +020080 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
Ezequiel Garciad04c1142021-03-04 15:07:48 +010081 struct v4l2_ctrl_vp8_frame *p_vp8_frame;
Paul Kocialkowski256fa392019-10-22 12:26:52 -030082 struct v4l2_ctrl_hevc_sps *p_hevc_sps;
83 struct v4l2_ctrl_hevc_pps *p_hevc_pps;
84 struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
Andrzej Pietrasiewiczb88dbe32021-11-16 14:38:35 +000085 struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs;
86 struct v4l2_ctrl_vp9_frame *p_vp9_frame;
Stanimir Varbanov1ad0de72021-01-19 16:06:42 +010087 struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
88 struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -030089 struct v4l2_area *p_area;
Hans Verkuil01760772014-04-27 03:22:17 -030090 void *p;
Ricardo Ribalda Delgadof1bd5ea2019-11-04 14:09:19 +010091 const void *p_const;
Hans Verkuil01760772014-04-27 03:22:17 -030092};
93
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030094/**
Ricardo Ribalda Delgado2e8db632019-10-07 12:06:35 -030095 * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
96 * void pointer
97 * @ptr: The void pointer
98 */
99static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
100{
101 union v4l2_ctrl_ptr p = { .p = ptr };
102
103 return p;
104}
105
106/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300107 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300108 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300109 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
110 * for volatile (and usually read-only) controls such as a control
111 * that returns the current signal strength which changes
112 * continuously.
113 * If not set, then the currently cached value will be returned.
114 * @try_ctrl: Test whether the control's value is valid. Only relevant when
115 * the usual min/max/step checks are not sufficient.
116 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
117 * ctrl->handler->lock is held when these ops are called, so no
118 * one else can access controls owned by that handler.
119 */
Hans Verkuil09965172010-08-01 14:32:42 -0300120struct v4l2_ctrl_ops {
121 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
122 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
123 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
124};
125
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300126/**
127 * struct v4l2_ctrl_type_ops - The control type operations that the driver
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300128 * has to provide.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300129 *
130 * @equal: return true if both values are equal.
131 * @init: initialize the value.
132 * @log: log the value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300133 * @validate: validate the value. Return 0 on success and a negative value
134 * otherwise.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300135 */
Hans Verkuil01760772014-04-27 03:22:17 -0300136struct v4l2_ctrl_type_ops {
Hans Verkuil998e7652014-06-10 07:55:00 -0300137 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -0300138 union v4l2_ctrl_ptr ptr1,
139 union v4l2_ctrl_ptr ptr2);
Hans Verkuil998e7652014-06-10 07:55:00 -0300140 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -0300141 union v4l2_ctrl_ptr ptr);
142 void (*log)(const struct v4l2_ctrl *ctrl);
Hans Verkuil998e7652014-06-10 07:55:00 -0300143 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -0300144 union v4l2_ctrl_ptr ptr);
145};
146
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300147/**
148 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
149 * that should be called when a control value has changed.
150 *
151 * @ctrl: pointer to struct &v4l2_ctrl
152 * @priv: control private data
153 *
154 * This typedef definition is used as an argument to v4l2_ctrl_notify()
155 * and as an argument at struct &v4l2_ctrl_handler.
156 */
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300157typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
158
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300159/**
160 * struct v4l2_ctrl - The control structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300161 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300162 * @node: The list node.
163 * @ev_subs: The list of control event subscriptions.
164 * @handler: The handler that owns the control.
165 * @cluster: Point to start of cluster array.
166 * @ncontrols: Number of controls in cluster array.
167 * @done: Internal flag: set for each processed control.
168 * @is_new: Set when the user specified a new value for this control. It
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300169 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300170 * should never set this flag.
171 * @has_changed: Set when the current value differs from the new value. Drivers
172 * should never use this flag.
173 * @is_private: If set, then this control is private to its handler and it
174 * will not be added to any other handlers. Drivers can set
175 * this flag.
176 * @is_auto: If set, then this control selects whether the other cluster
177 * members are in 'automatic' mode or 'manual' mode. This is
178 * used for autogain/gain type clusters. Drivers should never
179 * set this flag directly.
180 * @is_int: If set, then this control has a simple integer value (i.e. it
181 * uses ctrl->val).
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300182 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
183 * @is_ptr: If set, then this control is an array and/or has type >=
184 * %V4L2_CTRL_COMPOUND_TYPES
185 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300186 * v4l2_ext_control uses field p to point to the data.
187 * @is_array: If set, then this control contains an N-dimensional array.
188 * @has_volatiles: If set, then one or more members of the cluster are volatile.
189 * Drivers should never touch this flag.
190 * @call_notify: If set, then call the handler's notify function whenever the
191 * control's value changes.
192 * @manual_mode_value: If the is_auto flag is set, then this is the value
193 * of the auto control that determines if that control is in
194 * manual mode. So if the value of the auto control equals this
195 * value, then the whole cluster is in manual mode. Drivers should
196 * never set this flag directly.
197 * @ops: The control ops.
198 * @type_ops: The control type ops.
199 * @id: The control ID.
200 * @name: The control name.
201 * @type: The control type.
202 * @minimum: The control's minimum value.
203 * @maximum: The control's maximum value.
204 * @default_value: The control's default value.
205 * @step: The control's step value for non-menu controls.
206 * @elems: The number of elements in the N-dimensional array.
207 * @elem_size: The size in bytes of the control.
208 * @dims: The size of each dimension.
209 * @nr_of_dims:The number of dimensions in @dims.
210 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
211 * easy to skip menu items that are not valid. If bit X is set,
212 * then menu item X is skipped. Of course, this only works for
213 * menus with <= 32 menu items. There are no menus that come
214 * close to that number, so this is OK. Should we ever need more,
215 * then this will have to be extended to a u64 or a bit array.
216 * @qmenu: A const char * array for all menu items. Array entries that are
217 * empty strings ("") correspond to non-existing menu items (this
218 * is in addition to the menu_skip_mask above). The last entry
219 * must be NULL.
Mauro Carvalho Chehab20139f12017-09-27 12:25:21 -0400220 * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
221 * @qmenu_int: A 64-bit integer array for with integer menu items.
222 * The size of array must be equal to the menu size, e. g.:
223 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
224 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300225 * @flags: The control's flags.
Mauro Carvalho Chehab20139f12017-09-27 12:25:21 -0400226 * @cur: Structure to store the current value.
227 * @cur.val: The control's current value, if the @type is represented via
228 * a u32 integer (see &enum v4l2_ctrl_type).
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300229 * @val: The control's new s32 value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300230 * @priv: The control's private pointer. For use by the driver. It is
231 * untouched by the control framework. Note that this pointer is
232 * not freed when the control is deleted. Should this be needed
233 * then a new internal bitfield can be added to tell the framework
234 * to free this pointer.
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300235 * @p_def: The control's default value represented via a union which
236 * provides a standard way of accessing control types
237 * through a pointer (for compound controls only).
Baruch Siachbf7b7042018-07-05 05:38:00 -0400238 * @p_cur: The control's current value represented via a union which
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300239 * provides a standard way of accessing control types
240 * through a pointer.
Baruch Siachbf7b7042018-07-05 05:38:00 -0400241 * @p_new: The control's new value represented via a union which provides
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300242 * a standard way of accessing control types
243 * through a pointer.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300244 */
Hans Verkuil09965172010-08-01 14:32:42 -0300245struct v4l2_ctrl {
246 /* Administrative fields */
247 struct list_head node;
Hans Verkuil77068d32011-06-13 18:55:58 -0300248 struct list_head ev_subs;
Hans Verkuil09965172010-08-01 14:32:42 -0300249 struct v4l2_ctrl_handler *handler;
250 struct v4l2_ctrl **cluster;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300251 unsigned int ncontrols;
252
Hans Verkuil09965172010-08-01 14:32:42 -0300253 unsigned int done:1;
254
Hans Verkuil2a863792011-01-11 14:45:03 -0300255 unsigned int is_new:1;
Hans Verkuil9ea1b7a2014-01-17 08:25:26 -0300256 unsigned int has_changed:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300257 unsigned int is_private:1;
Hans Verkuil72d877c2011-06-10 05:44:36 -0300258 unsigned int is_auto:1;
Hans Verkuild9a25472014-06-12 07:54:16 -0300259 unsigned int is_int:1;
260 unsigned int is_string:1;
261 unsigned int is_ptr:1;
Hans Verkuil998e7652014-06-10 07:55:00 -0300262 unsigned int is_array:1;
Hans Verkuil5626b8c2011-08-26 07:53:53 -0300263 unsigned int has_volatiles:1;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300264 unsigned int call_notify:1;
Hans Verkuil82a7c042011-06-28 10:43:13 -0300265 unsigned int manual_mode_value:8;
Hans Verkuil09965172010-08-01 14:32:42 -0300266
267 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300268 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300269 u32 id;
270 const char *name;
271 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300272 s64 minimum, maximum, default_value;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300273 u32 elems;
Hans Verkuild9a25472014-06-12 07:54:16 -0300274 u32 elem_size;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300275 u32 dims[V4L2_CTRL_MAX_DIMS];
276 u32 nr_of_dims;
Hans Verkuil09965172010-08-01 14:32:42 -0300277 union {
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300278 u64 step;
279 u64 menu_skip_mask;
Hans Verkuil09965172010-08-01 14:32:42 -0300280 };
Sakari Ailusce580fe2011-08-04 13:51:11 -0300281 union {
282 const char * const *qmenu;
283 const s64 *qmenu_int;
284 };
Hans Verkuil09965172010-08-01 14:32:42 -0300285 unsigned long flags;
Hans Verkuil09965172010-08-01 14:32:42 -0300286 void *priv;
Hans Verkuil2a9ec372014-04-27 03:38:13 -0300287 s32 val;
288 struct {
Hans Verkuild9a25472014-06-12 07:54:16 -0300289 s32 val;
Hans Verkuild9a25472014-06-12 07:54:16 -0300290 } cur;
Hans Verkuil01760772014-04-27 03:22:17 -0300291
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300292 union v4l2_ctrl_ptr p_def;
Hans Verkuil01760772014-04-27 03:22:17 -0300293 union v4l2_ctrl_ptr p_new;
294 union v4l2_ctrl_ptr p_cur;
Hans Verkuil09965172010-08-01 14:32:42 -0300295};
296
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300297/**
298 * struct v4l2_ctrl_ref - The control reference.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300299 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300300 * @node: List node for the sorted list.
301 * @next: Single-link list node for the hash.
302 * @ctrl: The actual control information.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300303 * @helper: Pointer to helper struct. Used internally in
Mauro Carvalho Chehabfb911612016-08-29 18:43:02 -0300304 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400305 * @from_other_dev: If true, then @ctrl was defined in another
306 * device than the &struct v4l2_ctrl_handler.
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400307 * @req_done: Internal flag: if the control handler containing this control
308 * reference is bound to a media request, then this is set when
309 * the control has been applied. This prevents applying controls
310 * from a cluster with multiple controls twice (when the first
311 * control of a cluster is applied, they all are).
Hans Verkuilac34b792021-04-12 13:51:23 +0200312 * @valid_p_req: If set, then p_req contains the control value for the request.
Hans Verkuil52beedd2018-05-21 04:54:37 -0400313 * @p_req: If the control handler containing this control reference
314 * is bound to a media request, then this points to the
Hans Verkuilac34b792021-04-12 13:51:23 +0200315 * value of the control that must be applied when the request
Hans Verkuil52beedd2018-05-21 04:54:37 -0400316 * is executed, or to the value of the control at the time
Hans Verkuilac34b792021-04-12 13:51:23 +0200317 * that the request was completed. If @valid_p_req is false,
318 * then this control was never set for this request and the
319 * control will not be updated when this request is applied.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300320 *
321 * Each control handler has a list of these refs. The list_head is used to
322 * keep a sorted-by-control-ID list of all controls, while the next pointer
323 * is used to link the control in the hash's bucket.
324 */
Hans Verkuil09965172010-08-01 14:32:42 -0300325struct v4l2_ctrl_ref {
326 struct list_head node;
327 struct v4l2_ctrl_ref *next;
328 struct v4l2_ctrl *ctrl;
Hans Verkuileb5b16e2011-06-14 10:04:06 -0300329 struct v4l2_ctrl_helper *helper;
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400330 bool from_other_dev;
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400331 bool req_done;
Hans Verkuilac34b792021-04-12 13:51:23 +0200332 bool valid_p_req;
Hans Verkuil52beedd2018-05-21 04:54:37 -0400333 union v4l2_ctrl_ptr p_req;
Hans Verkuil09965172010-08-01 14:32:42 -0300334};
335
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300336/**
337 * struct v4l2_ctrl_handler - The control handler keeps track of all the
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300338 * controls: both the controls owned by the handler and those inherited
339 * from other handlers.
340 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300341 * @_lock: Default for "lock".
342 * @lock: Lock to control access to this handler and its controls.
343 * May be replaced by the user right after init.
344 * @ctrls: The list of controls owned by this handler.
345 * @ctrl_refs: The list of control references.
346 * @cached: The last found control reference. It is common that the same
347 * control is needed multiple times, so this is a simple
348 * optimization.
349 * @buckets: Buckets for the hashing. Allows for quick control lookup.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300350 * @notify: A notify callback that is called whenever the control changes
351 * value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300352 * Note that the handler's lock is held when the notify function
353 * is called!
354 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
355 * @nr_of_buckets: Total number of buckets in the array.
356 * @error: The error code of the first failed control addition.
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400357 * @request_is_queued: True if the request was queued.
358 * @requests: List to keep track of open control handler request objects.
Hans Verkuilac34b792021-04-12 13:51:23 +0200359 * For the parent control handler (@req_obj.ops == NULL) this
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400360 * is the list header. When the parent control handler is
361 * removed, it has to unbind and put all these requests since
362 * they refer to the parent.
363 * @requests_queued: List of the queued requests. This determines the order
364 * in which these controls are applied. Once the request is
365 * completed it is removed from this list.
Hans Verkuil52beedd2018-05-21 04:54:37 -0400366 * @req_obj: The &struct media_request_object, used to link into a
367 * &struct media_request. This request object has a refcount.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300368 */
Hans Verkuil09965172010-08-01 14:32:42 -0300369struct v4l2_ctrl_handler {
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300370 struct mutex _lock;
371 struct mutex *lock;
Hans Verkuil09965172010-08-01 14:32:42 -0300372 struct list_head ctrls;
373 struct list_head ctrl_refs;
374 struct v4l2_ctrl_ref *cached;
375 struct v4l2_ctrl_ref **buckets;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300376 v4l2_ctrl_notify_fnc notify;
377 void *notify_priv;
Hans Verkuil09965172010-08-01 14:32:42 -0300378 u16 nr_of_buckets;
379 int error;
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400380 bool request_is_queued;
381 struct list_head requests;
382 struct list_head requests_queued;
Hans Verkuil52beedd2018-05-21 04:54:37 -0400383 struct media_request_object req_obj;
Hans Verkuil09965172010-08-01 14:32:42 -0300384};
385
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300386/**
387 * struct v4l2_ctrl_config - Control configuration structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300388 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300389 * @ops: The control ops.
390 * @type_ops: The control type ops. Only needed for compound controls.
391 * @id: The control ID.
392 * @name: The control name.
393 * @type: The control type.
394 * @min: The control's minimum value.
395 * @max: The control's maximum value.
396 * @step: The control's step value for non-menu controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300397 * @def: The control's default value.
Ricardo Ribalda Delgado3b98a212019-11-04 14:09:18 +0100398 * @p_def: The control's default value for compound controls.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300399 * @dims: The size of each dimension.
400 * @elem_size: The size in bytes of the control.
401 * @flags: The control's flags.
402 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
403 * easy to skip menu items that are not valid. If bit X is set,
404 * then menu item X is skipped. Of course, this only works for
405 * menus with <= 64 menu items. There are no menus that come
406 * close to that number, so this is OK. Should we ever need more,
407 * then this will have to be extended to a bit array.
408 * @qmenu: A const char * array for all menu items. Array entries that are
409 * empty strings ("") correspond to non-existing menu items (this
410 * is in addition to the menu_skip_mask above). The last entry
411 * must be NULL.
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300412 * @qmenu_int: A const s64 integer array for all menu items of the type
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300413 * V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300414 * @is_private: If set, then this control is private to its handler and it
415 * will not be added to any other handlers.
416 */
Hans Verkuil09965172010-08-01 14:32:42 -0300417struct v4l2_ctrl_config {
418 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300419 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300420 u32 id;
421 const char *name;
422 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300423 s64 min;
424 s64 max;
425 u64 step;
426 s64 def;
Ricardo Ribalda Delgado3b98a212019-11-04 14:09:18 +0100427 union v4l2_ctrl_ptr p_def;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300428 u32 dims[V4L2_CTRL_MAX_DIMS];
Hans Verkuild9a25472014-06-12 07:54:16 -0300429 u32 elem_size;
Hans Verkuil09965172010-08-01 14:32:42 -0300430 u32 flags;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300431 u64 menu_skip_mask;
Hans Verkuil513521e2010-12-29 14:25:52 -0300432 const char * const *qmenu;
Sakari Ailusce580fe2011-08-04 13:51:11 -0300433 const s64 *qmenu_int;
Hans Verkuil09965172010-08-01 14:32:42 -0300434 unsigned int is_private:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300435};
436
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300437/**
438 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
439 *
440 * @id: ID of the control
Mauro Carvalho Chehab67c672e2017-08-12 05:57:05 -0400441 * @name: pointer to be filled with a string with the name of the control
442 * @type: pointer for storing the type of the control
443 * @min: pointer for storing the minimum value for the control
444 * @max: pointer for storing the maximum value for the control
445 * @step: pointer for storing the control step
446 * @def: pointer for storing the default value for the control
447 * @flags: pointer for storing the flags to be used on the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300448 *
449 * This works for all standard V4L2 controls.
450 * For non-standard controls it will only fill in the given arguments
Mauro Carvalho Chehab67c672e2017-08-12 05:57:05 -0400451 * and @name content will be set to %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300452 *
453 * This function will overwrite the contents of @name, @type and @flags.
454 * The contents of @min, @max, @step and @def may be modified depending on
455 * the type.
456 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300457 * .. note::
458 *
459 * Do not use in drivers! It is used internally for backwards compatibility
460 * control handling only. Once all drivers are converted to use the new
461 * control framework this function will no longer be exported.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300462 */
Hans Verkuil09965172010-08-01 14:32:42 -0300463void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300464 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
Hans Verkuil09965172010-08-01 14:32:42 -0300465
466
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300467/**
468 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
469 * @hdl: The control handler.
470 * @nr_of_controls_hint: A hint of how many controls this handler is
471 * expected to refer to. This is the total number, so including
472 * any inherited controls. It doesn't have to be precise, but if
473 * it is way off, then you either waste memory (too many buckets
474 * are allocated) or the control lookup becomes slower (not enough
475 * buckets are allocated, so there are more slow list lookups).
476 * It will always work, though.
477 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
478 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
479 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300480 * .. attention::
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300481 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300482 * Never use this call directly, always use the v4l2_ctrl_handler_init()
483 * macro that hides the @key and @name arguments.
484 *
485 * Return: returns an error if the buckets could not be allocated. This
486 * error will also be stored in @hdl->error.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300487 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300488int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300489 unsigned int nr_of_controls_hint,
Andy Walls6cd247e2013-03-09 05:55:11 -0300490 struct lock_class_key *key, const char *name);
491
492#ifdef CONFIG_LOCKDEP
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300493
494/**
Mauro Carvalho Chehabe383ce02016-09-22 07:59:03 -0300495 * v4l2_ctrl_handler_init - helper function to create a static struct
496 * &lock_class_key and calls v4l2_ctrl_handler_init_class()
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300497 *
498 * @hdl: The control handler.
499 * @nr_of_controls_hint: A hint of how many controls this handler is
500 * expected to refer to. This is the total number, so including
501 * any inherited controls. It doesn't have to be precise, but if
502 * it is way off, then you either waste memory (too many buckets
503 * are allocated) or the control lookup becomes slower (not enough
504 * buckets are allocated, so there are more slow list lookups).
505 * It will always work, though.
506 *
507 * This helper function creates a static struct &lock_class_key and
508 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
509 * validador.
510 *
511 * Use this helper function to initialize a control handler.
512 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300513#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
514( \
515 ({ \
516 static struct lock_class_key _key; \
517 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
518 &_key, \
519 KBUILD_BASENAME ":" \
520 __stringify(__LINE__) ":" \
521 "(" #hdl ")->_lock"); \
522 }) \
523)
524#else
525#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
526 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
527#endif
Hans Verkuil09965172010-08-01 14:32:42 -0300528
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300529/**
530 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
531 * the control list.
532 * @hdl: The control handler.
533 *
534 * Does nothing if @hdl == NULL.
535 */
Hans Verkuil09965172010-08-01 14:32:42 -0300536void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
537
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300538/**
539 * v4l2_ctrl_lock() - Helper function to lock the handler
540 * associated with the control.
541 * @ctrl: The control to lock.
542 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300543static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
544{
545 mutex_lock(ctrl->handler->lock);
546}
547
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300548/**
549 * v4l2_ctrl_unlock() - Helper function to unlock the handler
550 * associated with the control.
551 * @ctrl: The control to unlock.
552 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300553static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
554{
555 mutex_unlock(ctrl->handler->lock);
556}
557
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300558/**
Sakari Ailuscc0140e2017-05-26 05:21:37 -0300559 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
560 * to the handler to initialize the hardware to the current control values. The
561 * caller is responsible for acquiring the control handler mutex on behalf of
562 * __v4l2_ctrl_handler_setup().
563 * @hdl: The control handler.
564 *
565 * Button controls will be skipped, as are read-only controls.
566 *
567 * If @hdl == NULL, then this just returns 0.
568 */
569int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
570
571/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300572 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
573 * to the handler to initialize the hardware to the current control values.
574 * @hdl: The control handler.
575 *
576 * Button controls will be skipped, as are read-only controls.
577 *
578 * If @hdl == NULL, then this just returns 0.
579 */
Hans Verkuil09965172010-08-01 14:32:42 -0300580int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
581
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300582/**
583 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
584 * @hdl: The control handler.
585 * @prefix: The prefix to use when logging the control values. If the
586 * prefix does not end with a space, then ": " will be added
587 * after the prefix. If @prefix == NULL, then no prefix will be
588 * used.
589 *
590 * For use with VIDIOC_LOG_STATUS.
591 *
592 * Does nothing if @hdl == NULL.
593 */
Hans Verkuil09965172010-08-01 14:32:42 -0300594void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
595 const char *prefix);
596
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300597/**
598 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300599 * control.
600 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300601 * @hdl: The control handler.
602 * @cfg: The control's configuration data.
603 * @priv: The control's driver-specific private data.
604 *
605 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
606 * and @hdl->error is set to the error code (if it wasn't set already).
607 */
Hans Verkuil09965172010-08-01 14:32:42 -0300608struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300609 const struct v4l2_ctrl_config *cfg,
610 void *priv);
Hans Verkuil09965172010-08-01 14:32:42 -0300611
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300612/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300613 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
614 * control.
615 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300616 * @hdl: The control handler.
617 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300618 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300619 * @min: The control's minimum value.
620 * @max: The control's maximum value.
621 * @step: The control's step value
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300622 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300623 *
624 * If the &v4l2_ctrl struct could not be allocated, or the control
625 * ID is not known, then NULL is returned and @hdl->error is set to the
626 * appropriate error code (if it wasn't set already).
627 *
628 * If @id refers to a menu control, then this function will return NULL.
629 *
630 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
631 */
Hans Verkuil09965172010-08-01 14:32:42 -0300632struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300633 const struct v4l2_ctrl_ops *ops,
634 u32 id, s64 min, s64 max, u64 step,
635 s64 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300636
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300637/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300638 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
639 * menu control.
640 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300641 * @hdl: The control handler.
642 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300643 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300644 * @max: The control's maximum value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300645 * @mask: The control's skip mask for menu controls. This makes it
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300646 * easy to skip menu items that are not valid. If bit X is set,
647 * then menu item X is skipped. Of course, this only works for
648 * menus with <= 64 menu items. There are no menus that come
649 * close to that number, so this is OK. Should we ever need more,
650 * then this will have to be extended to a bit array.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300651 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300652 *
653 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
654 * determines which menu items are to be skipped.
655 *
656 * If @id refers to a non-menu control, then this function will return NULL.
657 */
Hans Verkuil09965172010-08-01 14:32:42 -0300658struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300659 const struct v4l2_ctrl_ops *ops,
660 u32 id, u8 max, u64 mask, u8 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300661
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300662/**
663 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300664 * with driver specific menu.
665 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300666 * @hdl: The control handler.
667 * @ops: The control ops.
668 * @id: The control ID.
669 * @max: The control's maximum value.
670 * @mask: The control's skip mask for menu controls. This makes it
671 * easy to skip menu items that are not valid. If bit X is set,
672 * then menu item X is skipped. Of course, this only works for
673 * menus with <= 64 menu items. There are no menus that come
674 * close to that number, so this is OK. Should we ever need more,
675 * then this will have to be extended to a bit array.
676 * @def: The control's default value.
677 * @qmenu: The new menu.
678 *
679 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
680 * menu of this control.
681 *
682 */
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300683struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300684 const struct v4l2_ctrl_ops *ops,
685 u32 id, u8 max,
686 u64 mask, u8 def,
687 const char * const *qmenu);
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300688
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300689/**
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300690 * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
691 * compound control.
692 *
693 * @hdl: The control handler.
694 * @ops: The control ops.
695 * @id: The control ID.
696 * @p_def: The control's default value.
697 *
698 * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
Hans Verkuile51759f2020-04-23 13:42:32 +0200699 * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
700 * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
701 * compound control should be all zeroes.
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300702 *
703 */
704struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
705 const struct v4l2_ctrl_ops *ops,
706 u32 id,
707 const union v4l2_ctrl_ptr p_def);
708
709/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300710 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300711 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300712 * @hdl: The control handler.
713 * @ops: The control ops.
714 * @id: The control ID.
715 * @max: The control's maximum value.
716 * @def: The control's default value.
717 * @qmenu_int: The control's menu entries.
718 *
Mauro Carvalho Chehabe907bf32019-02-18 14:29:06 -0500719 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300720 * takes as an argument an array of integers determining the menu items.
721 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300722 * If @id refers to a non-integer-menu control, then this function will
723 * return %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300724 */
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300725struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300726 const struct v4l2_ctrl_ops *ops,
727 u32 id, u8 max, u8 def,
728 const s64 *qmenu_int);
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300729
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300730/**
731 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
732 * used when adding a control handler.
733 *
734 * @ctrl: pointer to struct &v4l2_ctrl.
735 */
736
Mauro Carvalho Chehab6d85d7d2016-07-22 10:58:03 -0300737typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
738
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300739/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300740 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300741 * handler @hdl.
742 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300743 * @hdl: The control handler.
744 * @add: The control handler whose controls you want to add to
745 * the @hdl control handler.
746 * @filter: This function will filter which controls should be added.
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400747 * @from_other_dev: If true, then the controls in @add were defined in another
748 * device than @hdl.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300749 *
750 * Does nothing if either of the two handlers is a NULL pointer.
751 * If @filter is NULL, then all controls are added. Otherwise only those
752 * controls for which @filter returns true will be added.
753 * In case of an error @hdl->error will be set to the error code (if it
754 * wasn't set already).
755 */
Hans Verkuil09965172010-08-01 14:32:42 -0300756int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300757 struct v4l2_ctrl_handler *add,
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400758 v4l2_ctrl_filter filter,
759 bool from_other_dev);
Hans Verkuil09965172010-08-01 14:32:42 -0300760
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300761/**
762 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300763 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300764 * @ctrl: The control that is filtered.
765 *
766 * This will return true for any controls that are valid for radio device
767 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
768 * transmitter class controls.
769 *
770 * This function is to be used with v4l2_ctrl_add_handler().
771 */
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300772bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
Hans Verkuil09965172010-08-01 14:32:42 -0300773
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300774/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300775 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
776 * to that cluster.
777 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300778 * @ncontrols: The number of controls in this cluster.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300779 * @controls: The cluster control array of size @ncontrols.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300780 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300781void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
Hans Verkuil09965172010-08-01 14:32:42 -0300782
783
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300784/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300785 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
786 * to that cluster and set it up for autofoo/foo-type handling.
787 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300788 * @ncontrols: The number of controls in this cluster.
789 * @controls: The cluster control array of size @ncontrols. The first control
790 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
791 * @manual_val: The value for the first control in the cluster that equals the
792 * manual setting.
793 * @set_volatile: If true, then all controls except the first auto control will
794 * be volatile.
795 *
796 * Use for control groups where one control selects some automatic feature and
797 * the other controls are only active whenever the automatic feature is turned
798 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
799 * red and blue balance, etc.
800 *
801 * The behavior of such controls is as follows:
802 *
803 * When the autofoo control is set to automatic, then any manual controls
804 * are set to inactive and any reads will call g_volatile_ctrl (if the control
805 * was marked volatile).
806 *
807 * When the autofoo control is set to manual, then any manual controls will
808 * be marked active, and any reads will just return the current value without
809 * going through g_volatile_ctrl.
810 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300811 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
812 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300813 * if autofoo is in auto mode.
814 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300815void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
816 struct v4l2_ctrl **controls,
817 u8 manual_val, bool set_volatile);
Hans Verkuil72d877c2011-06-10 05:44:36 -0300818
819
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300820/**
821 * v4l2_ctrl_find() - Find a control with the given ID.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300822 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300823 * @hdl: The control handler.
824 * @id: The control ID to find.
825 *
826 * If @hdl == NULL this will return NULL as well. Will lock the handler so
827 * do not use from inside &v4l2_ctrl_ops.
828 */
Hans Verkuil09965172010-08-01 14:32:42 -0300829struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
830
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300831/**
832 * v4l2_ctrl_activate() - Make the control active or inactive.
833 * @ctrl: The control to (de)activate.
834 * @active: True if the control should become active.
835 *
836 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
837 * Does nothing if @ctrl == NULL.
838 * This will usually be called from within the s_ctrl op.
839 * The V4L2_EVENT_CTRL event will be generated afterwards.
840 *
841 * This function assumes that the control handler is locked.
842 */
Hans Verkuil09965172010-08-01 14:32:42 -0300843void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
844
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300845/**
Sakari Ailus7a9b1092018-07-19 07:11:40 -0400846 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
847 *
848 * @ctrl: The control to (de)activate.
849 * @grabbed: True if the control should become grabbed.
850 *
851 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
852 * Does nothing if @ctrl == NULL.
853 * The V4L2_EVENT_CTRL event will be generated afterwards.
854 * This will usually be called when starting or stopping streaming in the
855 * driver.
856 *
857 * This function assumes that the control handler is locked by the caller.
858 */
859void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
860
861/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300862 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300863 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300864 * @ctrl: The control to (de)activate.
865 * @grabbed: True if the control should become grabbed.
866 *
867 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
868 * Does nothing if @ctrl == NULL.
869 * The V4L2_EVENT_CTRL event will be generated afterwards.
870 * This will usually be called when starting or stopping streaming in the
871 * driver.
872 *
873 * This function assumes that the control handler is not locked and will
874 * take the lock itself.
875 */
Sakari Ailus7a9b1092018-07-19 07:11:40 -0400876static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
877{
878 if (!ctrl)
879 return;
880
881 v4l2_ctrl_lock(ctrl);
882 __v4l2_ctrl_grab(ctrl, grabbed);
883 v4l2_ctrl_unlock(ctrl);
884}
Hans Verkuil09965172010-08-01 14:32:42 -0300885
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300886/**
887 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
888 *
889 * @ctrl: The control to update.
890 * @min: The control's minimum value.
891 * @max: The control's maximum value.
892 * @step: The control's step value
893 * @def: The control's default value.
894 *
895 * Update the range of a control on the fly. This works for control types
896 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
897 * @step value is interpreted as a menu_skip_mask.
898 *
899 * An error is returned if one of the range arguments is invalid for this
900 * control type.
901 *
Hans Verkuil97eee232018-02-03 08:18:14 -0500902 * The caller is responsible for acquiring the control handler mutex on behalf
903 * of __v4l2_ctrl_modify_range().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300904 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300905int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
906 s64 min, s64 max, u64 step, s64 def);
907
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300908/**
909 * v4l2_ctrl_modify_range() - Update the range of a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300910 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300911 * @ctrl: The control to update.
912 * @min: The control's minimum value.
913 * @max: The control's maximum value.
914 * @step: The control's step value
915 * @def: The control's default value.
916 *
917 * Update the range of a control on the fly. This works for control types
918 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
919 * @step value is interpreted as a menu_skip_mask.
920 *
921 * An error is returned if one of the range arguments is invalid for this
922 * control type.
923 *
924 * This function assumes that the control handler is not locked and will
925 * take the lock itself.
926 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300927static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
928 s64 min, s64 max, u64 step, s64 def)
929{
930 int rval;
931
932 v4l2_ctrl_lock(ctrl);
933 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
934 v4l2_ctrl_unlock(ctrl);
935
936 return rval;
937}
Sylwester Nawrocki2ccbe772013-01-19 15:51:55 -0300938
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300939/**
940 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300941 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300942 * @ctrl: The control.
943 * @notify: The callback function.
944 * @priv: The callback private handle, passed as argument to the callback.
945 *
946 * This function sets a callback function for the control. If @ctrl is NULL,
947 * then it will do nothing. If @notify is NULL, then the notify callback will
948 * be removed.
949 *
950 * There can be only one notify. If another already exists, then a WARN_ON
951 * will be issued and the function will do nothing.
952 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300953void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
954 void *priv);
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300955
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300956/**
957 * v4l2_ctrl_get_name() - Get the name of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300958 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300959 * @id: The control ID.
960 *
961 * This function returns the name of the given control ID or NULL if it isn't
962 * a known control.
963 */
964const char *v4l2_ctrl_get_name(u32 id);
965
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300966/**
967 * v4l2_ctrl_get_menu() - Get the menu string array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300968 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300969 * @id: The control ID.
970 *
971 * This function returns the NULL-terminated menu string array name of the
972 * given control ID or NULL if it isn't a known menu control.
973 */
974const char * const *v4l2_ctrl_get_menu(u32 id);
975
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300976/**
977 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300978 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300979 * @id: The control ID.
980 * @len: The size of the integer array.
981 *
982 * This function returns the integer array of the given control ID or NULL if it
983 * if it isn't a known integer menu control.
984 */
985const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
986
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300987/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300988 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
989 * within a driver.
990 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300991 * @ctrl: The control.
992 *
993 * This returns the control's value safely by going through the control
994 * framework. This function will lock the control's handler, so it cannot be
995 * used from within the &v4l2_ctrl_ops functions.
996 *
997 * This function is for integer type controls only.
998 */
Hans Verkuil09965172010-08-01 14:32:42 -0300999s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
1000
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001001/**
1002 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001003 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001004 * @ctrl: The control.
Hans Verkuilc4d1de72019-04-01 03:42:05 -04001005 * @val: The new value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001006 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001007 * This sets the control's new value safely by going through the control
1008 * framework. This function assumes the control's handler is already locked,
1009 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001010 *
1011 * This function is for integer type controls only.
1012 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001013int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001014
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001015/**
1016 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
1017 * within a driver.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001018 * @ctrl: The control.
1019 * @val: The new value.
1020 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001021 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001022 * framework. This function will lock the control's handler, so it cannot be
1023 * used from within the &v4l2_ctrl_ops functions.
1024 *
1025 * This function is for integer type controls only.
1026 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001027static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
1028{
1029 int rval;
1030
1031 v4l2_ctrl_lock(ctrl);
1032 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
1033 v4l2_ctrl_unlock(ctrl);
1034
1035 return rval;
1036}
Hans Verkuil09965172010-08-01 14:32:42 -03001037
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001038/**
1039 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
1040 * from within a driver.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001041 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001042 * @ctrl: The control.
1043 *
1044 * This returns the control's value safely by going through the control
1045 * framework. This function will lock the control's handler, so it cannot be
1046 * used from within the &v4l2_ctrl_ops functions.
1047 *
1048 * This function is for 64-bit integer type controls only.
1049 */
Laurent Pinchart03d52852012-07-23 09:15:21 -03001050s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
1051
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001052/**
1053 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
1054 *
1055 * @ctrl: The control.
1056 * @val: The new value.
1057 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001058 * This sets the control's new value safely by going through the control
1059 * framework. This function assumes the control's handler is already locked,
1060 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001061 *
1062 * This function is for 64-bit integer type controls only.
1063 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001064int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1065
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001066/**
1067 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001068 * from within a driver.
1069 *
1070 * @ctrl: The control.
1071 * @val: The new value.
1072 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001073 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001074 * framework. This function will lock the control's handler, so it cannot be
1075 * used from within the &v4l2_ctrl_ops functions.
1076 *
1077 * This function is for 64-bit integer type controls only.
1078 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001079static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
1080{
1081 int rval;
1082
1083 v4l2_ctrl_lock(ctrl);
1084 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
1085 v4l2_ctrl_unlock(ctrl);
1086
1087 return rval;
1088}
Laurent Pinchart03d52852012-07-23 09:15:21 -03001089
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001090/**
1091 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001092 *
1093 * @ctrl: The control.
1094 * @s: The new string.
1095 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001096 * This sets the control's new string safely by going through the control
1097 * framework. This function assumes the control's handler is already locked,
1098 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001099 *
1100 * This function is for string type controls only.
1101 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -03001102int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1103
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001104/**
1105 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001106 * from within a driver.
1107 *
1108 * @ctrl: The control.
1109 * @s: The new string.
Hans Verkuilc4d1de72019-04-01 03:42:05 -04001110 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001111 * This sets the control's new string safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001112 * framework. This function will lock the control's handler, so it cannot be
1113 * used from within the &v4l2_ctrl_ops functions.
1114 *
1115 * This function is for string type controls only.
1116 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -03001117static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
1118{
1119 int rval;
1120
1121 v4l2_ctrl_lock(ctrl);
1122 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1123 v4l2_ctrl_unlock(ctrl);
1124
1125 return rval;
1126}
1127
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001128/**
Hans Verkuilb2b10462020-03-03 12:02:00 +01001129 * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001130 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001131 * @ctrl: The control.
1132 * @type: The type of the data.
1133 * @p: The new compound payload.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001134 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001135 * This sets the control's new compound payload safely by going through the
1136 * control framework. This function assumes the control's handler is already
1137 * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001138 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001139 * This function is for compound type controls only.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001140 */
Hans Verkuilb2b10462020-03-03 12:02:00 +01001141int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1142 enum v4l2_ctrl_type type, const void *p);
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001143
1144/**
Hans Verkuilb2b10462020-03-03 12:02:00 +01001145 * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
1146 * from within a driver.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001147 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001148 * @ctrl: The control.
1149 * @type: The type of the data.
1150 * @p: The new compound payload.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001151 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001152 * This sets the control's new compound payload safely by going through the
1153 * control framework. This function will lock the control's handler, so it
1154 * cannot be used from within the &v4l2_ctrl_ops functions.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001155 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001156 * This function is for compound type controls only.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001157 */
Hans Verkuilb2b10462020-03-03 12:02:00 +01001158static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1159 enum v4l2_ctrl_type type,
1160 const void *p)
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001161{
1162 int rval;
1163
1164 v4l2_ctrl_lock(ctrl);
Hans Verkuilb2b10462020-03-03 12:02:00 +01001165 rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001166 v4l2_ctrl_unlock(ctrl);
1167
1168 return rval;
1169}
1170
Hans Verkuilb2b10462020-03-03 12:02:00 +01001171/* Helper defines for area type controls */
1172#define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
1173 __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1174#define v4l2_ctrl_s_ctrl_area(ctrl, area) \
1175 v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1176
Hans Verkuilce727572011-06-10 05:56:39 -03001177/* Internal helper functions that deal with control events. */
Hans de Goede3e3661492012-04-08 12:59:47 -03001178extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001179
1180/**
1181 * v4l2_ctrl_replace - Function to be used as a callback to
1182 * &struct v4l2_subscribed_event_ops replace\(\)
1183 *
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001184 * @old: pointer to struct &v4l2_event with the reported
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001185 * event;
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001186 * @new: pointer to struct &v4l2_event with the modified
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001187 * event;
1188 */
Hans de Goede3e3661492012-04-08 12:59:47 -03001189void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001190
1191/**
1192 * v4l2_ctrl_merge - Function to be used as a callback to
1193 * &struct v4l2_subscribed_event_ops merge(\)
1194 *
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001195 * @old: pointer to struct &v4l2_event with the reported
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001196 * event;
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001197 * @new: pointer to struct &v4l2_event with the merged
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001198 * event;
1199 */
Hans de Goede3e3661492012-04-08 12:59:47 -03001200void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
Hans Verkuil6e239392011-06-07 11:13:44 -03001201
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001202/**
1203 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1204 *
1205 * @file: pointer to struct file
1206 * @fh: unused. Kept just to be compatible to the arguments expected by
1207 * &struct v4l2_ioctl_ops.vidioc_log_status.
1208 *
1209 * Can be used as a vidioc_log_status function that just dumps all controls
1210 * associated with the filehandle.
1211 */
Hans Verkuile2ecb252012-02-02 08:20:53 -03001212int v4l2_ctrl_log_status(struct file *file, void *fh);
1213
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001214/**
1215 * v4l2_ctrl_subscribe_event - Subscribes to an event
1216 *
1217 *
1218 * @fh: pointer to struct v4l2_fh
1219 * @sub: pointer to &struct v4l2_event_subscription
1220 *
1221 * Can be used as a vidioc_subscribe_event function that just subscribes
1222 * control events.
1223 */
Hans Verkuila26243b2012-01-27 16:18:42 -03001224int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
Hans Verkuil85f5fe32012-09-04 11:46:09 -03001225 const struct v4l2_event_subscription *sub);
Hans Verkuila26243b2012-01-27 16:18:42 -03001226
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001227/**
1228 * v4l2_ctrl_poll - function to be used as a callback to the poll()
1229 * That just polls for control events.
1230 *
1231 * @file: pointer to struct file
1232 * @wait: pointer to struct poll_table_struct
1233 */
Al Viroc23e0cb2017-07-03 03:02:56 -04001234__poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
Hans Verkuila26243b2012-01-27 16:18:42 -03001235
Hans Verkuil6fa6f832018-05-21 04:54:40 -04001236/**
1237 * v4l2_ctrl_request_setup - helper function to apply control values in a request
1238 *
1239 * @req: The request
1240 * @parent: The parent control handler ('priv' in media_request_object_find())
1241 *
1242 * This is a helper function to call the control handler's s_ctrl callback with
1243 * the control values contained in the request. Do note that this approach of
1244 * applying control values in a request is only applicable to memory-to-memory
1245 * devices.
1246 */
Dafna Hirschfeld09ca38a2019-03-06 16:13:26 -05001247int v4l2_ctrl_request_setup(struct media_request *req,
Hans Verkuil6fa6f832018-05-21 04:54:40 -04001248 struct v4l2_ctrl_handler *parent);
1249
1250/**
1251 * v4l2_ctrl_request_complete - Complete a control handler request object
1252 *
1253 * @req: The request
1254 * @parent: The parent control handler ('priv' in media_request_object_find())
1255 *
1256 * This function is to be called on each control handler that may have had a
1257 * request object associated with it, i.e. control handlers of a driver that
1258 * supports requests.
1259 *
1260 * The function first obtains the values of any volatile controls in the control
1261 * handler and attach them to the request. Then, the function completes the
1262 * request object.
1263 */
1264void v4l2_ctrl_request_complete(struct media_request *req,
Hans Verkuil5f611d72018-07-10 04:00:53 -04001265 struct v4l2_ctrl_handler *parent);
1266
1267/**
1268 * v4l2_ctrl_request_hdl_find - Find the control handler in the request
1269 *
1270 * @req: The request
1271 * @parent: The parent control handler ('priv' in media_request_object_find())
1272 *
1273 * This function finds the control handler in the request. It may return
1274 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
1275 * with the returned handler pointer.
1276 *
1277 * If the request is not in state VALIDATING or QUEUED, then this function
1278 * will always return NULL.
1279 *
1280 * Note that in state VALIDATING the req_queue_mutex is held, so
1281 * no objects can be added or deleted from the request.
1282 *
1283 * In state QUEUED it is the driver that will have to ensure this.
1284 */
1285struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
1286 struct v4l2_ctrl_handler *parent);
1287
1288/**
1289 * v4l2_ctrl_request_hdl_put - Put the control handler
1290 *
1291 * @hdl: Put this control handler
1292 *
1293 * This function released the control handler previously obtained from'
1294 * v4l2_ctrl_request_hdl_find().
1295 */
1296static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
1297{
1298 if (hdl)
1299 media_request_object_put(&hdl->req_obj);
1300}
1301
1302/**
Mauro Carvalho Chehabb0649452020-10-23 16:08:10 +02001303 * v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID.
Hans Verkuil5f611d72018-07-10 04:00:53 -04001304 *
1305 * @hdl: The control handler from the request.
1306 * @id: The ID of the control to find.
1307 *
1308 * This function returns a pointer to the control if this control is
1309 * part of the request or NULL otherwise.
1310 */
1311struct v4l2_ctrl *
1312v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
Hans Verkuil6fa6f832018-05-21 04:54:40 -04001313
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001314/* Helpers for ioctl_ops */
Hans Verkuil09965172010-08-01 14:32:42 -03001315
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001316/**
1317 * v4l2_queryctrl - Helper function to implement
1318 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1319 *
1320 * @hdl: pointer to &struct v4l2_ctrl_handler
1321 * @qc: pointer to &struct v4l2_queryctrl
1322 *
1323 * If hdl == NULL then they will all return -EINVAL.
1324 */
1325int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1326
1327/**
1328 * v4l2_query_ext_ctrl - Helper function to implement
1329 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1330 *
1331 * @hdl: pointer to &struct v4l2_ctrl_handler
1332 * @qc: pointer to &struct v4l2_query_ext_ctrl
1333 *
1334 * If hdl == NULL then they will all return -EINVAL.
1335 */
1336int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1337 struct v4l2_query_ext_ctrl *qc);
1338
1339/**
1340 * v4l2_querymenu - Helper function to implement
1341 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1342 *
1343 * @hdl: pointer to &struct v4l2_ctrl_handler
1344 * @qm: pointer to &struct v4l2_querymenu
1345 *
1346 * If hdl == NULL then they will all return -EINVAL.
1347 */
1348int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1349
1350/**
1351 * v4l2_g_ctrl - Helper function to implement
1352 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1353 *
1354 * @hdl: pointer to &struct v4l2_ctrl_handler
1355 * @ctrl: pointer to &struct v4l2_control
1356 *
1357 * If hdl == NULL then they will all return -EINVAL.
1358 */
1359int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1360
1361/**
1362 * v4l2_s_ctrl - Helper function to implement
1363 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1364 *
1365 * @fh: pointer to &struct v4l2_fh
1366 * @hdl: pointer to &struct v4l2_ctrl_handler
1367 *
1368 * @ctrl: pointer to &struct v4l2_control
1369 *
1370 * If hdl == NULL then they will all return -EINVAL.
1371 */
1372int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1373 struct v4l2_control *ctrl);
1374
1375/**
1376 * v4l2_g_ext_ctrls - Helper function to implement
1377 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1378 *
1379 * @hdl: pointer to &struct v4l2_ctrl_handler
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001380 * @vdev: pointer to &struct video_device
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001381 * @mdev: pointer to &struct media_device
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001382 * @c: pointer to &struct v4l2_ext_controls
1383 *
1384 * If hdl == NULL then they will all return -EINVAL.
1385 */
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001386int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
1387 struct media_device *mdev, struct v4l2_ext_controls *c);
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001388
1389/**
1390 * v4l2_try_ext_ctrls - Helper function to implement
1391 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1392 *
1393 * @hdl: pointer to &struct v4l2_ctrl_handler
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001394 * @vdev: pointer to &struct video_device
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001395 * @mdev: pointer to &struct media_device
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001396 * @c: pointer to &struct v4l2_ext_controls
1397 *
1398 * If hdl == NULL then they will all return -EINVAL.
1399 */
1400int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001401 struct video_device *vdev,
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001402 struct media_device *mdev,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001403 struct v4l2_ext_controls *c);
1404
1405/**
1406 * v4l2_s_ext_ctrls - Helper function to implement
1407 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1408 *
1409 * @fh: pointer to &struct v4l2_fh
1410 * @hdl: pointer to &struct v4l2_ctrl_handler
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001411 * @vdev: pointer to &struct video_device
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001412 * @mdev: pointer to &struct media_device
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001413 * @c: pointer to &struct v4l2_ext_controls
1414 *
1415 * If hdl == NULL then they will all return -EINVAL.
1416 */
1417int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001418 struct video_device *vdev,
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001419 struct media_device *mdev,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001420 struct v4l2_ext_controls *c);
1421
1422/**
1423 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
Mauro Carvalho Chehab4a3fad72018-01-04 06:47:28 -05001424 * as a &struct v4l2_subdev_core_ops subscribe_event function
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001425 * that just subscribes control events.
1426 *
1427 * @sd: pointer to &struct v4l2_subdev
1428 * @fh: pointer to &struct v4l2_fh
1429 * @sub: pointer to &struct v4l2_event_subscription
1430 */
Sylwester Nawrocki22fa4272013-01-22 19:00:23 -03001431int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1432 struct v4l2_event_subscription *sub);
1433
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001434/**
1435 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1436 * handler.
1437 *
1438 * @sd: pointer to &struct v4l2_subdev
1439 */
Sylwester Nawrockiffa9b9f2013-01-22 19:01:02 -03001440int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1441
Jacopo Mondie0a36062020-05-09 11:04:52 +02001442/**
1443 * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
1444 * properties
1445 *
1446 * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
1447 * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
1448 * @p: pointer to &struct v4l2_fwnode_device_properties
1449 *
1450 * This function registers controls associated to device properties, using the
1451 * property values contained in @p parameter, if the property has been set to
1452 * a value.
1453 *
1454 * Currently the following v4l2 controls are parsed and registered:
1455 * - V4L2_CID_CAMERA_ORIENTATION
1456 * - V4L2_CID_CAMERA_SENSOR_ROTATION;
1457 *
1458 * Controls already registered by the caller with the @hdl control handler are
1459 * not overwritten. Callers should register the controls they want to handle
1460 * themselves before calling this function.
1461 *
1462 * Return: 0 on success, a negative error code on failure.
1463 */
1464int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
1465 const struct v4l2_ctrl_ops *ctrl_ops,
1466 const struct v4l2_fwnode_device_properties *p);
Hans Verkuil09965172010-08-01 14:32:42 -03001467#endif