blob: 9ecbb98908f05efc9460e9fd1437f7fc3ee0b0b4 [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 */
20#include <media/mpeg2-ctrls.h>
Dafna Hirschfeld2495f392019-03-06 16:13:40 -050021#include <media/fwht-ctrls.h>
Pawel Osciak1f0545d2019-05-24 05:20:28 -040022#include <media/h264-ctrls.h>
Pawel Osciaka57d6ac2019-07-11 16:26:42 -040023#include <media/vp8-ctrls.h>
Paul Kocialkowski256fa392019-10-22 12:26:52 -030024#include <media/hevc-ctrls.h>
Hans Verkuil95140632018-12-05 06:28:20 -050025
Hans Verkuil09965172010-08-01 14:32:42 -030026/* forward references */
Laurent Pinchart528f0f72012-04-23 08:20:35 -030027struct file;
Jacopo Mondiae6ff162020-05-09 11:04:50 +020028struct poll_table_struct;
29struct v4l2_ctrl;
Hans Verkuil09965172010-08-01 14:32:42 -030030struct v4l2_ctrl_handler;
Hans Verkuileb5b16e2011-06-14 10:04:06 -030031struct v4l2_ctrl_helper;
Jacopo Mondiae6ff162020-05-09 11:04:50 +020032struct v4l2_fh;
Jacopo Mondie0a36062020-05-09 11:04:52 +020033struct v4l2_fwnode_device_properties;
Hans Verkuil09965172010-08-01 14:32:42 -030034struct v4l2_subdev;
Hans Verkuil77068d32011-06-13 18:55:58 -030035struct v4l2_subscribed_event;
Jacopo Mondiae6ff162020-05-09 11:04:50 +020036struct video_device;
Hans Verkuil09965172010-08-01 14:32:42 -030037
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030038/**
39 * union v4l2_ctrl_ptr - A pointer to a control value.
Paul Kocialkowskic27bb302018-09-13 10:51:52 -040040 * @p_s32: Pointer to a 32-bit signed value.
41 * @p_s64: Pointer to a 64-bit signed value.
42 * @p_u8: Pointer to a 8-bit unsigned value.
43 * @p_u16: Pointer to a 16-bit unsigned value.
44 * @p_u32: Pointer to a 32-bit unsigned value.
45 * @p_char: Pointer to a string.
46 * @p_mpeg2_slice_params: Pointer to a MPEG2 slice parameters structure.
47 * @p_mpeg2_quantization: Pointer to a MPEG2 quantization data structure.
Dafna Hirschfeld2495f392019-03-06 16:13:40 -050048 * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
Pawel Osciak1f0545d2019-05-24 05:20:28 -040049 * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
50 * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
51 * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
52 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
53 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
Ezequiel Garciaeb44c6c2020-08-25 05:52:29 +020054 * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
Pawel Osciaka57d6ac2019-07-11 16:26:42 -040055 * @p_vp8_frame_header: Pointer to a VP8 frame header structure.
Paul Kocialkowski256fa392019-10-22 12:26:52 -030056 * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
57 * @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
58 * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -030059 * @p_area: Pointer to an area.
Paul Kocialkowskic27bb302018-09-13 10:51:52 -040060 * @p: Pointer to a compound value.
Ricardo Ribalda Delgadof1bd5ea2019-11-04 14:09:19 +010061 * @p_const: Pointer to a constant compound value.
Hans Verkuil01760772014-04-27 03:22:17 -030062 */
63union v4l2_ctrl_ptr {
64 s32 *p_s32;
65 s64 *p_s64;
Hans Verkuildda4a4d2014-06-10 07:30:04 -030066 u8 *p_u8;
67 u16 *p_u16;
Hans Verkuil811c5082014-07-21 10:45:37 -030068 u32 *p_u32;
Hans Verkuil01760772014-04-27 03:22:17 -030069 char *p_char;
Paul Kocialkowskic27bb302018-09-13 10:51:52 -040070 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
71 struct v4l2_ctrl_mpeg2_quantization *p_mpeg2_quantization;
Dafna Hirschfeld2495f392019-03-06 16:13:40 -050072 struct v4l2_ctrl_fwht_params *p_fwht_params;
Pawel Osciak1f0545d2019-05-24 05:20:28 -040073 struct v4l2_ctrl_h264_sps *p_h264_sps;
74 struct v4l2_ctrl_h264_pps *p_h264_pps;
75 struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
76 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
77 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
Ezequiel Garciaeb44c6c2020-08-25 05:52:29 +020078 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
Pawel Osciaka57d6ac2019-07-11 16:26:42 -040079 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
Paul Kocialkowski256fa392019-10-22 12:26:52 -030080 struct v4l2_ctrl_hevc_sps *p_hevc_sps;
81 struct v4l2_ctrl_hevc_pps *p_hevc_pps;
82 struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -030083 struct v4l2_area *p_area;
Hans Verkuil01760772014-04-27 03:22:17 -030084 void *p;
Ricardo Ribalda Delgadof1bd5ea2019-11-04 14:09:19 +010085 const void *p_const;
Hans Verkuil01760772014-04-27 03:22:17 -030086};
87
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030088/**
Ricardo Ribalda Delgado2e8db632019-10-07 12:06:35 -030089 * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
90 * void pointer
91 * @ptr: The void pointer
92 */
93static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
94{
95 union v4l2_ctrl_ptr p = { .p = ptr };
96
97 return p;
98}
99
100/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300101 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300102 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300103 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
104 * for volatile (and usually read-only) controls such as a control
105 * that returns the current signal strength which changes
106 * continuously.
107 * If not set, then the currently cached value will be returned.
108 * @try_ctrl: Test whether the control's value is valid. Only relevant when
109 * the usual min/max/step checks are not sufficient.
110 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
111 * ctrl->handler->lock is held when these ops are called, so no
112 * one else can access controls owned by that handler.
113 */
Hans Verkuil09965172010-08-01 14:32:42 -0300114struct v4l2_ctrl_ops {
115 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
116 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
117 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
118};
119
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300120/**
121 * struct v4l2_ctrl_type_ops - The control type operations that the driver
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300122 * has to provide.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300123 *
124 * @equal: return true if both values are equal.
125 * @init: initialize the value.
126 * @log: log the value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300127 * @validate: validate the value. Return 0 on success and a negative value
128 * otherwise.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300129 */
Hans Verkuil01760772014-04-27 03:22:17 -0300130struct v4l2_ctrl_type_ops {
Hans Verkuil998e7652014-06-10 07:55:00 -0300131 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -0300132 union v4l2_ctrl_ptr ptr1,
133 union v4l2_ctrl_ptr ptr2);
Hans Verkuil998e7652014-06-10 07:55:00 -0300134 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -0300135 union v4l2_ctrl_ptr ptr);
136 void (*log)(const struct v4l2_ctrl *ctrl);
Hans Verkuil998e7652014-06-10 07:55:00 -0300137 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -0300138 union v4l2_ctrl_ptr ptr);
139};
140
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300141/**
142 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
143 * that should be called when a control value has changed.
144 *
145 * @ctrl: pointer to struct &v4l2_ctrl
146 * @priv: control private data
147 *
148 * This typedef definition is used as an argument to v4l2_ctrl_notify()
149 * and as an argument at struct &v4l2_ctrl_handler.
150 */
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300151typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
152
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300153/**
154 * struct v4l2_ctrl - The control structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300155 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300156 * @node: The list node.
157 * @ev_subs: The list of control event subscriptions.
158 * @handler: The handler that owns the control.
159 * @cluster: Point to start of cluster array.
160 * @ncontrols: Number of controls in cluster array.
161 * @done: Internal flag: set for each processed control.
162 * @is_new: Set when the user specified a new value for this control. It
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300163 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300164 * should never set this flag.
165 * @has_changed: Set when the current value differs from the new value. Drivers
166 * should never use this flag.
167 * @is_private: If set, then this control is private to its handler and it
168 * will not be added to any other handlers. Drivers can set
169 * this flag.
170 * @is_auto: If set, then this control selects whether the other cluster
171 * members are in 'automatic' mode or 'manual' mode. This is
172 * used for autogain/gain type clusters. Drivers should never
173 * set this flag directly.
174 * @is_int: If set, then this control has a simple integer value (i.e. it
175 * uses ctrl->val).
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300176 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
177 * @is_ptr: If set, then this control is an array and/or has type >=
178 * %V4L2_CTRL_COMPOUND_TYPES
179 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300180 * v4l2_ext_control uses field p to point to the data.
181 * @is_array: If set, then this control contains an N-dimensional array.
182 * @has_volatiles: If set, then one or more members of the cluster are volatile.
183 * Drivers should never touch this flag.
184 * @call_notify: If set, then call the handler's notify function whenever the
185 * control's value changes.
186 * @manual_mode_value: If the is_auto flag is set, then this is the value
187 * of the auto control that determines if that control is in
188 * manual mode. So if the value of the auto control equals this
189 * value, then the whole cluster is in manual mode. Drivers should
190 * never set this flag directly.
191 * @ops: The control ops.
192 * @type_ops: The control type ops.
193 * @id: The control ID.
194 * @name: The control name.
195 * @type: The control type.
196 * @minimum: The control's minimum value.
197 * @maximum: The control's maximum value.
198 * @default_value: The control's default value.
199 * @step: The control's step value for non-menu controls.
200 * @elems: The number of elements in the N-dimensional array.
201 * @elem_size: The size in bytes of the control.
202 * @dims: The size of each dimension.
203 * @nr_of_dims:The number of dimensions in @dims.
204 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
205 * easy to skip menu items that are not valid. If bit X is set,
206 * then menu item X is skipped. Of course, this only works for
207 * menus with <= 32 menu items. There are no menus that come
208 * close to that number, so this is OK. Should we ever need more,
209 * then this will have to be extended to a u64 or a bit array.
210 * @qmenu: A const char * array for all menu items. Array entries that are
211 * empty strings ("") correspond to non-existing menu items (this
212 * is in addition to the menu_skip_mask above). The last entry
213 * must be NULL.
Mauro Carvalho Chehab20139f12017-09-27 12:25:21 -0400214 * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
215 * @qmenu_int: A 64-bit integer array for with integer menu items.
216 * The size of array must be equal to the menu size, e. g.:
217 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
218 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300219 * @flags: The control's flags.
Mauro Carvalho Chehab20139f12017-09-27 12:25:21 -0400220 * @cur: Structure to store the current value.
221 * @cur.val: The control's current value, if the @type is represented via
222 * a u32 integer (see &enum v4l2_ctrl_type).
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300223 * @val: The control's new s32 value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300224 * @priv: The control's private pointer. For use by the driver. It is
225 * untouched by the control framework. Note that this pointer is
226 * not freed when the control is deleted. Should this be needed
227 * then a new internal bitfield can be added to tell the framework
228 * to free this pointer.
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300229 * @p_def: The control's default value represented via a union which
230 * provides a standard way of accessing control types
231 * through a pointer (for compound controls only).
Baruch Siachbf7b7042018-07-05 05:38:00 -0400232 * @p_cur: The control's current value represented via a union which
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300233 * provides a standard way of accessing control types
234 * through a pointer.
Baruch Siachbf7b7042018-07-05 05:38:00 -0400235 * @p_new: The control's new value represented via a union which provides
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300236 * a standard way of accessing control types
237 * through a pointer.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300238 */
Hans Verkuil09965172010-08-01 14:32:42 -0300239struct v4l2_ctrl {
240 /* Administrative fields */
241 struct list_head node;
Hans Verkuil77068d32011-06-13 18:55:58 -0300242 struct list_head ev_subs;
Hans Verkuil09965172010-08-01 14:32:42 -0300243 struct v4l2_ctrl_handler *handler;
244 struct v4l2_ctrl **cluster;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300245 unsigned int ncontrols;
246
Hans Verkuil09965172010-08-01 14:32:42 -0300247 unsigned int done:1;
248
Hans Verkuil2a863792011-01-11 14:45:03 -0300249 unsigned int is_new:1;
Hans Verkuil9ea1b7a2014-01-17 08:25:26 -0300250 unsigned int has_changed:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300251 unsigned int is_private:1;
Hans Verkuil72d877c2011-06-10 05:44:36 -0300252 unsigned int is_auto:1;
Hans Verkuild9a25472014-06-12 07:54:16 -0300253 unsigned int is_int:1;
254 unsigned int is_string:1;
255 unsigned int is_ptr:1;
Hans Verkuil998e7652014-06-10 07:55:00 -0300256 unsigned int is_array:1;
Hans Verkuil5626b8c2011-08-26 07:53:53 -0300257 unsigned int has_volatiles:1;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300258 unsigned int call_notify:1;
Hans Verkuil82a7c042011-06-28 10:43:13 -0300259 unsigned int manual_mode_value:8;
Hans Verkuil09965172010-08-01 14:32:42 -0300260
261 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300262 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300263 u32 id;
264 const char *name;
265 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300266 s64 minimum, maximum, default_value;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300267 u32 elems;
Hans Verkuild9a25472014-06-12 07:54:16 -0300268 u32 elem_size;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300269 u32 dims[V4L2_CTRL_MAX_DIMS];
270 u32 nr_of_dims;
Hans Verkuil09965172010-08-01 14:32:42 -0300271 union {
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300272 u64 step;
273 u64 menu_skip_mask;
Hans Verkuil09965172010-08-01 14:32:42 -0300274 };
Sakari Ailusce580fe2011-08-04 13:51:11 -0300275 union {
276 const char * const *qmenu;
277 const s64 *qmenu_int;
278 };
Hans Verkuil09965172010-08-01 14:32:42 -0300279 unsigned long flags;
Hans Verkuil09965172010-08-01 14:32:42 -0300280 void *priv;
Hans Verkuil2a9ec372014-04-27 03:38:13 -0300281 s32 val;
282 struct {
Hans Verkuild9a25472014-06-12 07:54:16 -0300283 s32 val;
Hans Verkuild9a25472014-06-12 07:54:16 -0300284 } cur;
Hans Verkuil01760772014-04-27 03:22:17 -0300285
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300286 union v4l2_ctrl_ptr p_def;
Hans Verkuil01760772014-04-27 03:22:17 -0300287 union v4l2_ctrl_ptr p_new;
288 union v4l2_ctrl_ptr p_cur;
Hans Verkuil09965172010-08-01 14:32:42 -0300289};
290
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300291/**
292 * struct v4l2_ctrl_ref - The control reference.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300293 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300294 * @node: List node for the sorted list.
295 * @next: Single-link list node for the hash.
296 * @ctrl: The actual control information.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300297 * @helper: Pointer to helper struct. Used internally in
Mauro Carvalho Chehabfb911612016-08-29 18:43:02 -0300298 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400299 * @from_other_dev: If true, then @ctrl was defined in another
300 * device than the &struct v4l2_ctrl_handler.
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400301 * @req_done: Internal flag: if the control handler containing this control
302 * reference is bound to a media request, then this is set when
303 * the control has been applied. This prevents applying controls
304 * from a cluster with multiple controls twice (when the first
305 * control of a cluster is applied, they all are).
Hans Verkuil5d0f6f52021-04-12 13:51:23 +0200306 * @valid_p_req: If set, then p_req contains the control value for the request.
Hans Verkuil52beedd2018-05-21 04:54:37 -0400307 * @p_req: If the control handler containing this control reference
308 * is bound to a media request, then this points to the
Hans Verkuil5d0f6f52021-04-12 13:51:23 +0200309 * value of the control that must be applied when the request
Hans Verkuil52beedd2018-05-21 04:54:37 -0400310 * is executed, or to the value of the control at the time
Hans Verkuil5d0f6f52021-04-12 13:51:23 +0200311 * that the request was completed. If @valid_p_req is false,
312 * then this control was never set for this request and the
313 * control will not be updated when this request is applied.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300314 *
315 * Each control handler has a list of these refs. The list_head is used to
316 * keep a sorted-by-control-ID list of all controls, while the next pointer
317 * is used to link the control in the hash's bucket.
318 */
Hans Verkuil09965172010-08-01 14:32:42 -0300319struct v4l2_ctrl_ref {
320 struct list_head node;
321 struct v4l2_ctrl_ref *next;
322 struct v4l2_ctrl *ctrl;
Hans Verkuileb5b16e2011-06-14 10:04:06 -0300323 struct v4l2_ctrl_helper *helper;
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400324 bool from_other_dev;
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400325 bool req_done;
Hans Verkuil5d0f6f52021-04-12 13:51:23 +0200326 bool valid_p_req;
Hans Verkuil52beedd2018-05-21 04:54:37 -0400327 union v4l2_ctrl_ptr p_req;
Hans Verkuil09965172010-08-01 14:32:42 -0300328};
329
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300330/**
331 * struct v4l2_ctrl_handler - The control handler keeps track of all the
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300332 * controls: both the controls owned by the handler and those inherited
333 * from other handlers.
334 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300335 * @_lock: Default for "lock".
336 * @lock: Lock to control access to this handler and its controls.
337 * May be replaced by the user right after init.
338 * @ctrls: The list of controls owned by this handler.
339 * @ctrl_refs: The list of control references.
340 * @cached: The last found control reference. It is common that the same
341 * control is needed multiple times, so this is a simple
342 * optimization.
343 * @buckets: Buckets for the hashing. Allows for quick control lookup.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300344 * @notify: A notify callback that is called whenever the control changes
345 * value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300346 * Note that the handler's lock is held when the notify function
347 * is called!
348 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
349 * @nr_of_buckets: Total number of buckets in the array.
350 * @error: The error code of the first failed control addition.
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400351 * @request_is_queued: True if the request was queued.
352 * @requests: List to keep track of open control handler request objects.
Hans Verkuil5d0f6f52021-04-12 13:51:23 +0200353 * For the parent control handler (@req_obj.ops == NULL) this
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400354 * is the list header. When the parent control handler is
355 * removed, it has to unbind and put all these requests since
356 * they refer to the parent.
357 * @requests_queued: List of the queued requests. This determines the order
358 * in which these controls are applied. Once the request is
359 * completed it is removed from this list.
Hans Verkuil52beedd2018-05-21 04:54:37 -0400360 * @req_obj: The &struct media_request_object, used to link into a
361 * &struct media_request. This request object has a refcount.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300362 */
Hans Verkuil09965172010-08-01 14:32:42 -0300363struct v4l2_ctrl_handler {
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300364 struct mutex _lock;
365 struct mutex *lock;
Hans Verkuil09965172010-08-01 14:32:42 -0300366 struct list_head ctrls;
367 struct list_head ctrl_refs;
368 struct v4l2_ctrl_ref *cached;
369 struct v4l2_ctrl_ref **buckets;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300370 v4l2_ctrl_notify_fnc notify;
371 void *notify_priv;
Hans Verkuil09965172010-08-01 14:32:42 -0300372 u16 nr_of_buckets;
373 int error;
Hans Verkuil6fa6f832018-05-21 04:54:40 -0400374 bool request_is_queued;
375 struct list_head requests;
376 struct list_head requests_queued;
Hans Verkuil52beedd2018-05-21 04:54:37 -0400377 struct media_request_object req_obj;
Hans Verkuil09965172010-08-01 14:32:42 -0300378};
379
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300380/**
381 * struct v4l2_ctrl_config - Control configuration structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300382 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300383 * @ops: The control ops.
384 * @type_ops: The control type ops. Only needed for compound controls.
385 * @id: The control ID.
386 * @name: The control name.
387 * @type: The control type.
388 * @min: The control's minimum value.
389 * @max: The control's maximum value.
390 * @step: The control's step value for non-menu controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300391 * @def: The control's default value.
Ricardo Ribalda Delgado3b98a212019-11-04 14:09:18 +0100392 * @p_def: The control's default value for compound controls.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300393 * @dims: The size of each dimension.
394 * @elem_size: The size in bytes of the control.
395 * @flags: The control's flags.
396 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
397 * easy to skip menu items that are not valid. If bit X is set,
398 * then menu item X is skipped. Of course, this only works for
399 * menus with <= 64 menu items. There are no menus that come
400 * close to that number, so this is OK. Should we ever need more,
401 * then this will have to be extended to a bit array.
402 * @qmenu: A const char * array for all menu items. Array entries that are
403 * empty strings ("") correspond to non-existing menu items (this
404 * is in addition to the menu_skip_mask above). The last entry
405 * must be NULL.
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300406 * @qmenu_int: A const s64 integer array for all menu items of the type
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300407 * V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300408 * @is_private: If set, then this control is private to its handler and it
409 * will not be added to any other handlers.
410 */
Hans Verkuil09965172010-08-01 14:32:42 -0300411struct v4l2_ctrl_config {
412 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300413 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300414 u32 id;
415 const char *name;
416 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300417 s64 min;
418 s64 max;
419 u64 step;
420 s64 def;
Ricardo Ribalda Delgado3b98a212019-11-04 14:09:18 +0100421 union v4l2_ctrl_ptr p_def;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300422 u32 dims[V4L2_CTRL_MAX_DIMS];
Hans Verkuild9a25472014-06-12 07:54:16 -0300423 u32 elem_size;
Hans Verkuil09965172010-08-01 14:32:42 -0300424 u32 flags;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300425 u64 menu_skip_mask;
Hans Verkuil513521e2010-12-29 14:25:52 -0300426 const char * const *qmenu;
Sakari Ailusce580fe2011-08-04 13:51:11 -0300427 const s64 *qmenu_int;
Hans Verkuil09965172010-08-01 14:32:42 -0300428 unsigned int is_private:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300429};
430
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300431/**
432 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
433 *
434 * @id: ID of the control
Mauro Carvalho Chehab67c672e2017-08-12 05:57:05 -0400435 * @name: pointer to be filled with a string with the name of the control
436 * @type: pointer for storing the type of the control
437 * @min: pointer for storing the minimum value for the control
438 * @max: pointer for storing the maximum value for the control
439 * @step: pointer for storing the control step
440 * @def: pointer for storing the default value for the control
441 * @flags: pointer for storing the flags to be used on the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300442 *
443 * This works for all standard V4L2 controls.
444 * For non-standard controls it will only fill in the given arguments
Mauro Carvalho Chehab67c672e2017-08-12 05:57:05 -0400445 * and @name content will be set to %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300446 *
447 * This function will overwrite the contents of @name, @type and @flags.
448 * The contents of @min, @max, @step and @def may be modified depending on
449 * the type.
450 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300451 * .. note::
452 *
453 * Do not use in drivers! It is used internally for backwards compatibility
454 * control handling only. Once all drivers are converted to use the new
455 * control framework this function will no longer be exported.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300456 */
Hans Verkuil09965172010-08-01 14:32:42 -0300457void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300458 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
Hans Verkuil09965172010-08-01 14:32:42 -0300459
460
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300461/**
462 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
463 * @hdl: The control handler.
464 * @nr_of_controls_hint: A hint of how many controls this handler is
465 * expected to refer to. This is the total number, so including
466 * any inherited controls. It doesn't have to be precise, but if
467 * it is way off, then you either waste memory (too many buckets
468 * are allocated) or the control lookup becomes slower (not enough
469 * buckets are allocated, so there are more slow list lookups).
470 * It will always work, though.
471 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
472 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
473 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300474 * .. attention::
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300475 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300476 * Never use this call directly, always use the v4l2_ctrl_handler_init()
477 * macro that hides the @key and @name arguments.
478 *
479 * Return: returns an error if the buckets could not be allocated. This
480 * error will also be stored in @hdl->error.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300481 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300482int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300483 unsigned int nr_of_controls_hint,
Andy Walls6cd247e2013-03-09 05:55:11 -0300484 struct lock_class_key *key, const char *name);
485
486#ifdef CONFIG_LOCKDEP
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300487
488/**
Mauro Carvalho Chehabe383ce02016-09-22 07:59:03 -0300489 * v4l2_ctrl_handler_init - helper function to create a static struct
490 * &lock_class_key and calls v4l2_ctrl_handler_init_class()
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300491 *
492 * @hdl: The control handler.
493 * @nr_of_controls_hint: A hint of how many controls this handler is
494 * expected to refer to. This is the total number, so including
495 * any inherited controls. It doesn't have to be precise, but if
496 * it is way off, then you either waste memory (too many buckets
497 * are allocated) or the control lookup becomes slower (not enough
498 * buckets are allocated, so there are more slow list lookups).
499 * It will always work, though.
500 *
501 * This helper function creates a static struct &lock_class_key and
502 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
503 * validador.
504 *
505 * Use this helper function to initialize a control handler.
506 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300507#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
508( \
509 ({ \
510 static struct lock_class_key _key; \
511 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
512 &_key, \
513 KBUILD_BASENAME ":" \
514 __stringify(__LINE__) ":" \
515 "(" #hdl ")->_lock"); \
516 }) \
517)
518#else
519#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
520 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
521#endif
Hans Verkuil09965172010-08-01 14:32:42 -0300522
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300523/**
524 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
525 * the control list.
526 * @hdl: The control handler.
527 *
528 * Does nothing if @hdl == NULL.
529 */
Hans Verkuil09965172010-08-01 14:32:42 -0300530void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
531
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300532/**
533 * v4l2_ctrl_lock() - Helper function to lock the handler
534 * associated with the control.
535 * @ctrl: The control to lock.
536 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300537static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
538{
539 mutex_lock(ctrl->handler->lock);
540}
541
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300542/**
543 * v4l2_ctrl_unlock() - Helper function to unlock the handler
544 * associated with the control.
545 * @ctrl: The control to unlock.
546 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300547static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
548{
549 mutex_unlock(ctrl->handler->lock);
550}
551
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300552/**
Sakari Ailuscc0140e2017-05-26 05:21:37 -0300553 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
554 * to the handler to initialize the hardware to the current control values. The
555 * caller is responsible for acquiring the control handler mutex on behalf of
556 * __v4l2_ctrl_handler_setup().
557 * @hdl: The control handler.
558 *
559 * Button controls will be skipped, as are read-only controls.
560 *
561 * If @hdl == NULL, then this just returns 0.
562 */
563int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
564
565/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300566 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
567 * to the handler to initialize the hardware to the current control values.
568 * @hdl: The control handler.
569 *
570 * Button controls will be skipped, as are read-only controls.
571 *
572 * If @hdl == NULL, then this just returns 0.
573 */
Hans Verkuil09965172010-08-01 14:32:42 -0300574int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
575
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300576/**
577 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
578 * @hdl: The control handler.
579 * @prefix: The prefix to use when logging the control values. If the
580 * prefix does not end with a space, then ": " will be added
581 * after the prefix. If @prefix == NULL, then no prefix will be
582 * used.
583 *
584 * For use with VIDIOC_LOG_STATUS.
585 *
586 * Does nothing if @hdl == NULL.
587 */
Hans Verkuil09965172010-08-01 14:32:42 -0300588void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
589 const char *prefix);
590
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300591/**
592 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300593 * control.
594 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300595 * @hdl: The control handler.
596 * @cfg: The control's configuration data.
597 * @priv: The control's driver-specific private data.
598 *
599 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
600 * and @hdl->error is set to the error code (if it wasn't set already).
601 */
Hans Verkuil09965172010-08-01 14:32:42 -0300602struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300603 const struct v4l2_ctrl_config *cfg,
604 void *priv);
Hans Verkuil09965172010-08-01 14:32:42 -0300605
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300606/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300607 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
608 * control.
609 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300610 * @hdl: The control handler.
611 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300612 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300613 * @min: The control's minimum value.
614 * @max: The control's maximum value.
615 * @step: The control's step value
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300616 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300617 *
618 * If the &v4l2_ctrl struct could not be allocated, or the control
619 * ID is not known, then NULL is returned and @hdl->error is set to the
620 * appropriate error code (if it wasn't set already).
621 *
622 * If @id refers to a menu control, then this function will return NULL.
623 *
624 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
625 */
Hans Verkuil09965172010-08-01 14:32:42 -0300626struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300627 const struct v4l2_ctrl_ops *ops,
628 u32 id, s64 min, s64 max, u64 step,
629 s64 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300630
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300631/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300632 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
633 * menu control.
634 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300635 * @hdl: The control handler.
636 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300637 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300638 * @max: The control's maximum value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300639 * @mask: The control's skip mask for menu controls. This makes it
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300640 * easy to skip menu items that are not valid. If bit X is set,
641 * then menu item X is skipped. Of course, this only works for
642 * menus with <= 64 menu items. There are no menus that come
643 * close to that number, so this is OK. Should we ever need more,
644 * then this will have to be extended to a bit array.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300645 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300646 *
647 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
648 * determines which menu items are to be skipped.
649 *
650 * If @id refers to a non-menu control, then this function will return NULL.
651 */
Hans Verkuil09965172010-08-01 14:32:42 -0300652struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300653 const struct v4l2_ctrl_ops *ops,
654 u32 id, u8 max, u64 mask, u8 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300655
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300656/**
657 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300658 * with driver specific menu.
659 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300660 * @hdl: The control handler.
661 * @ops: The control ops.
662 * @id: The control ID.
663 * @max: The control's maximum value.
664 * @mask: The control's skip mask for menu controls. This makes it
665 * easy to skip menu items that are not valid. If bit X is set,
666 * then menu item X is skipped. Of course, this only works for
667 * menus with <= 64 menu items. There are no menus that come
668 * close to that number, so this is OK. Should we ever need more,
669 * then this will have to be extended to a bit array.
670 * @def: The control's default value.
671 * @qmenu: The new menu.
672 *
673 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
674 * menu of this control.
675 *
676 */
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300677struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300678 const struct v4l2_ctrl_ops *ops,
679 u32 id, u8 max,
680 u64 mask, u8 def,
681 const char * const *qmenu);
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300682
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300683/**
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300684 * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
685 * compound control.
686 *
687 * @hdl: The control handler.
688 * @ops: The control ops.
689 * @id: The control ID.
690 * @p_def: The control's default value.
691 *
692 * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
Hans Verkuile51759f2020-04-23 13:42:32 +0200693 * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
694 * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
695 * compound control should be all zeroes.
Ricardo Ribalda Delgadob35d6c02019-10-07 12:06:29 -0300696 *
697 */
698struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
699 const struct v4l2_ctrl_ops *ops,
700 u32 id,
701 const union v4l2_ctrl_ptr p_def);
702
703/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300704 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300705 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300706 * @hdl: The control handler.
707 * @ops: The control ops.
708 * @id: The control ID.
709 * @max: The control's maximum value.
710 * @def: The control's default value.
711 * @qmenu_int: The control's menu entries.
712 *
Mauro Carvalho Chehabe907bf32019-02-18 14:29:06 -0500713 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300714 * takes as an argument an array of integers determining the menu items.
715 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300716 * If @id refers to a non-integer-menu control, then this function will
717 * return %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300718 */
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300719struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300720 const struct v4l2_ctrl_ops *ops,
721 u32 id, u8 max, u8 def,
722 const s64 *qmenu_int);
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300723
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300724/**
725 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
726 * used when adding a control handler.
727 *
728 * @ctrl: pointer to struct &v4l2_ctrl.
729 */
730
Mauro Carvalho Chehab6d85d7d2016-07-22 10:58:03 -0300731typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
732
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300733/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300734 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300735 * handler @hdl.
736 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300737 * @hdl: The control handler.
738 * @add: The control handler whose controls you want to add to
739 * the @hdl control handler.
740 * @filter: This function will filter which controls should be added.
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400741 * @from_other_dev: If true, then the controls in @add were defined in another
742 * device than @hdl.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300743 *
744 * Does nothing if either of the two handlers is a NULL pointer.
745 * If @filter is NULL, then all controls are added. Otherwise only those
746 * controls for which @filter returns true will be added.
747 * In case of an error @hdl->error will be set to the error code (if it
748 * wasn't set already).
749 */
Hans Verkuil09965172010-08-01 14:32:42 -0300750int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300751 struct v4l2_ctrl_handler *add,
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400752 v4l2_ctrl_filter filter,
753 bool from_other_dev);
Hans Verkuil09965172010-08-01 14:32:42 -0300754
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300755/**
756 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300757 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300758 * @ctrl: The control that is filtered.
759 *
760 * This will return true for any controls that are valid for radio device
761 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
762 * transmitter class controls.
763 *
764 * This function is to be used with v4l2_ctrl_add_handler().
765 */
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300766bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
Hans Verkuil09965172010-08-01 14:32:42 -0300767
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300768/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300769 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
770 * to that cluster.
771 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300772 * @ncontrols: The number of controls in this cluster.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300773 * @controls: The cluster control array of size @ncontrols.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300774 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300775void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
Hans Verkuil09965172010-08-01 14:32:42 -0300776
777
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300778/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300779 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
780 * to that cluster and set it up for autofoo/foo-type handling.
781 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300782 * @ncontrols: The number of controls in this cluster.
783 * @controls: The cluster control array of size @ncontrols. The first control
784 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
785 * @manual_val: The value for the first control in the cluster that equals the
786 * manual setting.
787 * @set_volatile: If true, then all controls except the first auto control will
788 * be volatile.
789 *
790 * Use for control groups where one control selects some automatic feature and
791 * the other controls are only active whenever the automatic feature is turned
792 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
793 * red and blue balance, etc.
794 *
795 * The behavior of such controls is as follows:
796 *
797 * When the autofoo control is set to automatic, then any manual controls
798 * are set to inactive and any reads will call g_volatile_ctrl (if the control
799 * was marked volatile).
800 *
801 * When the autofoo control is set to manual, then any manual controls will
802 * be marked active, and any reads will just return the current value without
803 * going through g_volatile_ctrl.
804 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300805 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
806 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300807 * if autofoo is in auto mode.
808 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300809void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
810 struct v4l2_ctrl **controls,
811 u8 manual_val, bool set_volatile);
Hans Verkuil72d877c2011-06-10 05:44:36 -0300812
813
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300814/**
815 * v4l2_ctrl_find() - Find a control with the given ID.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300816 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300817 * @hdl: The control handler.
818 * @id: The control ID to find.
819 *
820 * If @hdl == NULL this will return NULL as well. Will lock the handler so
821 * do not use from inside &v4l2_ctrl_ops.
822 */
Hans Verkuil09965172010-08-01 14:32:42 -0300823struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
824
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300825/**
826 * v4l2_ctrl_activate() - Make the control active or inactive.
827 * @ctrl: The control to (de)activate.
828 * @active: True if the control should become active.
829 *
830 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
831 * Does nothing if @ctrl == NULL.
832 * This will usually be called from within the s_ctrl op.
833 * The V4L2_EVENT_CTRL event will be generated afterwards.
834 *
835 * This function assumes that the control handler is locked.
836 */
Hans Verkuil09965172010-08-01 14:32:42 -0300837void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
838
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300839/**
Sakari Ailus7a9b1092018-07-19 07:11:40 -0400840 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
841 *
842 * @ctrl: The control to (de)activate.
843 * @grabbed: True if the control should become grabbed.
844 *
845 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
846 * Does nothing if @ctrl == NULL.
847 * The V4L2_EVENT_CTRL event will be generated afterwards.
848 * This will usually be called when starting or stopping streaming in the
849 * driver.
850 *
851 * This function assumes that the control handler is locked by the caller.
852 */
853void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
854
855/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300856 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300857 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300858 * @ctrl: The control to (de)activate.
859 * @grabbed: True if the control should become grabbed.
860 *
861 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
862 * Does nothing if @ctrl == NULL.
863 * The V4L2_EVENT_CTRL event will be generated afterwards.
864 * This will usually be called when starting or stopping streaming in the
865 * driver.
866 *
867 * This function assumes that the control handler is not locked and will
868 * take the lock itself.
869 */
Sakari Ailus7a9b1092018-07-19 07:11:40 -0400870static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
871{
872 if (!ctrl)
873 return;
874
875 v4l2_ctrl_lock(ctrl);
876 __v4l2_ctrl_grab(ctrl, grabbed);
877 v4l2_ctrl_unlock(ctrl);
878}
Hans Verkuil09965172010-08-01 14:32:42 -0300879
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300880/**
881 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
882 *
883 * @ctrl: The control to update.
884 * @min: The control's minimum value.
885 * @max: The control's maximum value.
886 * @step: The control's step value
887 * @def: The control's default value.
888 *
889 * Update the range of a control on the fly. This works for control types
890 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
891 * @step value is interpreted as a menu_skip_mask.
892 *
893 * An error is returned if one of the range arguments is invalid for this
894 * control type.
895 *
Hans Verkuil97eee232018-02-03 08:18:14 -0500896 * The caller is responsible for acquiring the control handler mutex on behalf
897 * of __v4l2_ctrl_modify_range().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300898 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300899int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
900 s64 min, s64 max, u64 step, s64 def);
901
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300902/**
903 * v4l2_ctrl_modify_range() - Update the range of a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300904 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300905 * @ctrl: The control to update.
906 * @min: The control's minimum value.
907 * @max: The control's maximum value.
908 * @step: The control's step value
909 * @def: The control's default value.
910 *
911 * Update the range of a control on the fly. This works for control types
912 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
913 * @step value is interpreted as a menu_skip_mask.
914 *
915 * An error is returned if one of the range arguments is invalid for this
916 * control type.
917 *
918 * This function assumes that the control handler is not locked and will
919 * take the lock itself.
920 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300921static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
922 s64 min, s64 max, u64 step, s64 def)
923{
924 int rval;
925
926 v4l2_ctrl_lock(ctrl);
927 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
928 v4l2_ctrl_unlock(ctrl);
929
930 return rval;
931}
Sylwester Nawrocki2ccbe772013-01-19 15:51:55 -0300932
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300933/**
934 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300935 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300936 * @ctrl: The control.
937 * @notify: The callback function.
938 * @priv: The callback private handle, passed as argument to the callback.
939 *
940 * This function sets a callback function for the control. If @ctrl is NULL,
941 * then it will do nothing. If @notify is NULL, then the notify callback will
942 * be removed.
943 *
944 * There can be only one notify. If another already exists, then a WARN_ON
945 * will be issued and the function will do nothing.
946 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300947void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
948 void *priv);
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300949
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300950/**
951 * v4l2_ctrl_get_name() - Get the name of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300952 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300953 * @id: The control ID.
954 *
955 * This function returns the name of the given control ID or NULL if it isn't
956 * a known control.
957 */
958const char *v4l2_ctrl_get_name(u32 id);
959
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300960/**
961 * v4l2_ctrl_get_menu() - Get the menu string array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300962 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300963 * @id: The control ID.
964 *
965 * This function returns the NULL-terminated menu string array name of the
966 * given control ID or NULL if it isn't a known menu control.
967 */
968const char * const *v4l2_ctrl_get_menu(u32 id);
969
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300970/**
971 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300972 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300973 * @id: The control ID.
974 * @len: The size of the integer array.
975 *
976 * This function returns the integer array of the given control ID or NULL if it
977 * if it isn't a known integer menu control.
978 */
979const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
980
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300981/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300982 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
983 * within a driver.
984 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300985 * @ctrl: The control.
986 *
987 * This returns the control's value safely by going through the control
988 * framework. This function will lock the control's handler, so it cannot be
989 * used from within the &v4l2_ctrl_ops functions.
990 *
991 * This function is for integer type controls only.
992 */
Hans Verkuil09965172010-08-01 14:32:42 -0300993s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
994
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300995/**
996 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300997 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300998 * @ctrl: The control.
Hans Verkuilc4d1de72019-04-01 03:42:05 -0400999 * @val: The new value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001000 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001001 * This sets the control's new value safely by going through the control
1002 * framework. This function assumes the control's handler is already locked,
1003 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001004 *
1005 * This function is for integer type controls only.
1006 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001007int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001008
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001009/**
1010 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
1011 * within a driver.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001012 * @ctrl: The control.
1013 * @val: The new value.
1014 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001015 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001016 * framework. This function will lock the control's handler, so it cannot be
1017 * used from within the &v4l2_ctrl_ops functions.
1018 *
1019 * This function is for integer type controls only.
1020 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001021static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
1022{
1023 int rval;
1024
1025 v4l2_ctrl_lock(ctrl);
1026 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
1027 v4l2_ctrl_unlock(ctrl);
1028
1029 return rval;
1030}
Hans Verkuil09965172010-08-01 14:32:42 -03001031
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001032/**
1033 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
1034 * from within a driver.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001035 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001036 * @ctrl: The control.
1037 *
1038 * This returns the control's value safely by going through the control
1039 * framework. This function will lock the control's handler, so it cannot be
1040 * used from within the &v4l2_ctrl_ops functions.
1041 *
1042 * This function is for 64-bit integer type controls only.
1043 */
Laurent Pinchart03d52852012-07-23 09:15:21 -03001044s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
1045
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001046/**
1047 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
1048 *
1049 * @ctrl: The control.
1050 * @val: The new value.
1051 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001052 * This sets the control's new value safely by going through the control
1053 * framework. This function assumes the control's handler is already locked,
1054 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001055 *
1056 * This function is for 64-bit integer type controls only.
1057 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001058int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1059
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001060/**
1061 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001062 * from within a driver.
1063 *
1064 * @ctrl: The control.
1065 * @val: The new value.
1066 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001067 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001068 * framework. This function will lock the control's handler, so it cannot be
1069 * used from within the &v4l2_ctrl_ops functions.
1070 *
1071 * This function is for 64-bit integer type controls only.
1072 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -03001073static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
1074{
1075 int rval;
1076
1077 v4l2_ctrl_lock(ctrl);
1078 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
1079 v4l2_ctrl_unlock(ctrl);
1080
1081 return rval;
1082}
Laurent Pinchart03d52852012-07-23 09:15:21 -03001083
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001084/**
1085 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001086 *
1087 * @ctrl: The control.
1088 * @s: The new string.
1089 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001090 * This sets the control's new string safely by going through the control
1091 * framework. This function assumes the control's handler is already locked,
1092 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001093 *
1094 * This function is for string type controls only.
1095 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -03001096int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1097
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001098/**
1099 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001100 * from within a driver.
1101 *
1102 * @ctrl: The control.
1103 * @s: The new string.
Hans Verkuilc4d1de72019-04-01 03:42:05 -04001104 *
Hans Verkuil904aef02016-06-15 09:57:48 -03001105 * This sets the control's new string safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -03001106 * framework. This function will lock the control's handler, so it cannot be
1107 * used from within the &v4l2_ctrl_ops functions.
1108 *
1109 * This function is for string type controls only.
1110 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -03001111static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
1112{
1113 int rval;
1114
1115 v4l2_ctrl_lock(ctrl);
1116 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1117 v4l2_ctrl_unlock(ctrl);
1118
1119 return rval;
1120}
1121
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001122/**
Hans Verkuilb2b10462020-03-03 12:02:00 +01001123 * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001124 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001125 * @ctrl: The control.
1126 * @type: The type of the data.
1127 * @p: The new compound payload.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001128 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001129 * This sets the control's new compound payload safely by going through the
1130 * control framework. This function assumes the control's handler is already
1131 * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001132 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001133 * This function is for compound type controls only.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001134 */
Hans Verkuilb2b10462020-03-03 12:02:00 +01001135int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1136 enum v4l2_ctrl_type type, const void *p);
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001137
1138/**
Hans Verkuilb2b10462020-03-03 12:02:00 +01001139 * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
1140 * from within a driver.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001141 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001142 * @ctrl: The control.
1143 * @type: The type of the data.
1144 * @p: The new compound payload.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001145 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001146 * This sets the control's new compound payload safely by going through the
1147 * control framework. This function will lock the control's handler, so it
1148 * cannot be used from within the &v4l2_ctrl_ops functions.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001149 *
Hans Verkuilb2b10462020-03-03 12:02:00 +01001150 * This function is for compound type controls only.
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001151 */
Hans Verkuilb2b10462020-03-03 12:02:00 +01001152static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
1153 enum v4l2_ctrl_type type,
1154 const void *p)
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001155{
1156 int rval;
1157
1158 v4l2_ctrl_lock(ctrl);
Hans Verkuilb2b10462020-03-03 12:02:00 +01001159 rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
Ricardo Ribalda Delgadod1dc4932019-10-07 12:06:31 -03001160 v4l2_ctrl_unlock(ctrl);
1161
1162 return rval;
1163}
1164
Hans Verkuilb2b10462020-03-03 12:02:00 +01001165/* Helper defines for area type controls */
1166#define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
1167 __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1168#define v4l2_ctrl_s_ctrl_area(ctrl, area) \
1169 v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
1170
Hans Verkuilce727572011-06-10 05:56:39 -03001171/* Internal helper functions that deal with control events. */
Hans de Goede3e3661492012-04-08 12:59:47 -03001172extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001173
1174/**
1175 * v4l2_ctrl_replace - Function to be used as a callback to
1176 * &struct v4l2_subscribed_event_ops replace\(\)
1177 *
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001178 * @old: pointer to struct &v4l2_event with the reported
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001179 * event;
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001180 * @new: pointer to struct &v4l2_event with the modified
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001181 * event;
1182 */
Hans de Goede3e3661492012-04-08 12:59:47 -03001183void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001184
1185/**
1186 * v4l2_ctrl_merge - Function to be used as a callback to
1187 * &struct v4l2_subscribed_event_ops merge(\)
1188 *
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001189 * @old: pointer to struct &v4l2_event with the reported
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001190 * event;
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001191 * @new: pointer to struct &v4l2_event with the merged
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001192 * event;
1193 */
Hans de Goede3e3661492012-04-08 12:59:47 -03001194void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
Hans Verkuil6e239392011-06-07 11:13:44 -03001195
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001196/**
1197 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1198 *
1199 * @file: pointer to struct file
1200 * @fh: unused. Kept just to be compatible to the arguments expected by
1201 * &struct v4l2_ioctl_ops.vidioc_log_status.
1202 *
1203 * Can be used as a vidioc_log_status function that just dumps all controls
1204 * associated with the filehandle.
1205 */
Hans Verkuile2ecb252012-02-02 08:20:53 -03001206int v4l2_ctrl_log_status(struct file *file, void *fh);
1207
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001208/**
1209 * v4l2_ctrl_subscribe_event - Subscribes to an event
1210 *
1211 *
1212 * @fh: pointer to struct v4l2_fh
1213 * @sub: pointer to &struct v4l2_event_subscription
1214 *
1215 * Can be used as a vidioc_subscribe_event function that just subscribes
1216 * control events.
1217 */
Hans Verkuila26243b2012-01-27 16:18:42 -03001218int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
Hans Verkuil85f5fe32012-09-04 11:46:09 -03001219 const struct v4l2_event_subscription *sub);
Hans Verkuila26243b2012-01-27 16:18:42 -03001220
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001221/**
1222 * v4l2_ctrl_poll - function to be used as a callback to the poll()
1223 * That just polls for control events.
1224 *
1225 * @file: pointer to struct file
1226 * @wait: pointer to struct poll_table_struct
1227 */
Al Viroc23e0cb2017-07-03 03:02:56 -04001228__poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
Hans Verkuila26243b2012-01-27 16:18:42 -03001229
Hans Verkuil6fa6f832018-05-21 04:54:40 -04001230/**
1231 * v4l2_ctrl_request_setup - helper function to apply control values in a request
1232 *
1233 * @req: The request
1234 * @parent: The parent control handler ('priv' in media_request_object_find())
1235 *
1236 * This is a helper function to call the control handler's s_ctrl callback with
1237 * the control values contained in the request. Do note that this approach of
1238 * applying control values in a request is only applicable to memory-to-memory
1239 * devices.
1240 */
Dafna Hirschfeld09ca38a2019-03-06 16:13:26 -05001241int v4l2_ctrl_request_setup(struct media_request *req,
Hans Verkuil6fa6f832018-05-21 04:54:40 -04001242 struct v4l2_ctrl_handler *parent);
1243
1244/**
1245 * v4l2_ctrl_request_complete - Complete a control handler request object
1246 *
1247 * @req: The request
1248 * @parent: The parent control handler ('priv' in media_request_object_find())
1249 *
1250 * This function is to be called on each control handler that may have had a
1251 * request object associated with it, i.e. control handlers of a driver that
1252 * supports requests.
1253 *
1254 * The function first obtains the values of any volatile controls in the control
1255 * handler and attach them to the request. Then, the function completes the
1256 * request object.
1257 */
1258void v4l2_ctrl_request_complete(struct media_request *req,
Hans Verkuil5f611d72018-07-10 04:00:53 -04001259 struct v4l2_ctrl_handler *parent);
1260
1261/**
1262 * v4l2_ctrl_request_hdl_find - Find the control handler in the request
1263 *
1264 * @req: The request
1265 * @parent: The parent control handler ('priv' in media_request_object_find())
1266 *
1267 * This function finds the control handler in the request. It may return
1268 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
1269 * with the returned handler pointer.
1270 *
1271 * If the request is not in state VALIDATING or QUEUED, then this function
1272 * will always return NULL.
1273 *
1274 * Note that in state VALIDATING the req_queue_mutex is held, so
1275 * no objects can be added or deleted from the request.
1276 *
1277 * In state QUEUED it is the driver that will have to ensure this.
1278 */
1279struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
1280 struct v4l2_ctrl_handler *parent);
1281
1282/**
1283 * v4l2_ctrl_request_hdl_put - Put the control handler
1284 *
1285 * @hdl: Put this control handler
1286 *
1287 * This function released the control handler previously obtained from'
1288 * v4l2_ctrl_request_hdl_find().
1289 */
1290static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
1291{
1292 if (hdl)
1293 media_request_object_put(&hdl->req_obj);
1294}
1295
1296/**
1297 * v4l2_ctrl_request_ctrl_find() - Find a control with the given ID.
1298 *
1299 * @hdl: The control handler from the request.
1300 * @id: The ID of the control to find.
1301 *
1302 * This function returns a pointer to the control if this control is
1303 * part of the request or NULL otherwise.
1304 */
1305struct v4l2_ctrl *
1306v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
Hans Verkuil6fa6f832018-05-21 04:54:40 -04001307
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001308/* Helpers for ioctl_ops */
Hans Verkuil09965172010-08-01 14:32:42 -03001309
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001310/**
1311 * v4l2_queryctrl - Helper function to implement
1312 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1313 *
1314 * @hdl: pointer to &struct v4l2_ctrl_handler
1315 * @qc: pointer to &struct v4l2_queryctrl
1316 *
1317 * If hdl == NULL then they will all return -EINVAL.
1318 */
1319int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1320
1321/**
1322 * v4l2_query_ext_ctrl - Helper function to implement
1323 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1324 *
1325 * @hdl: pointer to &struct v4l2_ctrl_handler
1326 * @qc: pointer to &struct v4l2_query_ext_ctrl
1327 *
1328 * If hdl == NULL then they will all return -EINVAL.
1329 */
1330int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1331 struct v4l2_query_ext_ctrl *qc);
1332
1333/**
1334 * v4l2_querymenu - Helper function to implement
1335 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1336 *
1337 * @hdl: pointer to &struct v4l2_ctrl_handler
1338 * @qm: pointer to &struct v4l2_querymenu
1339 *
1340 * If hdl == NULL then they will all return -EINVAL.
1341 */
1342int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1343
1344/**
1345 * v4l2_g_ctrl - Helper function to implement
1346 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1347 *
1348 * @hdl: pointer to &struct v4l2_ctrl_handler
1349 * @ctrl: pointer to &struct v4l2_control
1350 *
1351 * If hdl == NULL then they will all return -EINVAL.
1352 */
1353int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1354
1355/**
1356 * v4l2_s_ctrl - Helper function to implement
1357 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1358 *
1359 * @fh: pointer to &struct v4l2_fh
1360 * @hdl: pointer to &struct v4l2_ctrl_handler
1361 *
1362 * @ctrl: pointer to &struct v4l2_control
1363 *
1364 * If hdl == NULL then they will all return -EINVAL.
1365 */
1366int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1367 struct v4l2_control *ctrl);
1368
1369/**
1370 * v4l2_g_ext_ctrls - Helper function to implement
1371 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1372 *
1373 * @hdl: pointer to &struct v4l2_ctrl_handler
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001374 * @vdev: pointer to &struct video_device
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001375 * @mdev: pointer to &struct media_device
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001376 * @c: pointer to &struct v4l2_ext_controls
1377 *
1378 * If hdl == NULL then they will all return -EINVAL.
1379 */
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001380int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
1381 struct media_device *mdev, struct v4l2_ext_controls *c);
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001382
1383/**
1384 * v4l2_try_ext_ctrls - Helper function to implement
1385 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1386 *
1387 * @hdl: pointer to &struct v4l2_ctrl_handler
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001388 * @vdev: pointer to &struct video_device
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001389 * @mdev: pointer to &struct media_device
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001390 * @c: pointer to &struct v4l2_ext_controls
1391 *
1392 * If hdl == NULL then they will all return -EINVAL.
1393 */
1394int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001395 struct video_device *vdev,
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001396 struct media_device *mdev,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001397 struct v4l2_ext_controls *c);
1398
1399/**
1400 * v4l2_s_ext_ctrls - Helper function to implement
1401 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1402 *
1403 * @fh: pointer to &struct v4l2_fh
1404 * @hdl: pointer to &struct v4l2_ctrl_handler
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001405 * @vdev: pointer to &struct video_device
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001406 * @mdev: pointer to &struct media_device
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001407 * @c: pointer to &struct v4l2_ext_controls
1408 *
1409 * If hdl == NULL then they will all return -EINVAL.
1410 */
1411int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
Ezequiel Garcia173f6ea2019-07-20 07:47:07 -04001412 struct video_device *vdev,
Hans Verkuilc41e9cf2018-05-21 04:54:42 -04001413 struct media_device *mdev,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001414 struct v4l2_ext_controls *c);
1415
1416/**
1417 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
Mauro Carvalho Chehab4a3fad72018-01-04 06:47:28 -05001418 * as a &struct v4l2_subdev_core_ops subscribe_event function
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001419 * that just subscribes control events.
1420 *
1421 * @sd: pointer to &struct v4l2_subdev
1422 * @fh: pointer to &struct v4l2_fh
1423 * @sub: pointer to &struct v4l2_event_subscription
1424 */
Sylwester Nawrocki22fa4272013-01-22 19:00:23 -03001425int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1426 struct v4l2_event_subscription *sub);
1427
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001428/**
1429 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1430 * handler.
1431 *
1432 * @sd: pointer to &struct v4l2_subdev
1433 */
Sylwester Nawrockiffa9b9f2013-01-22 19:01:02 -03001434int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1435
Jacopo Mondie0a36062020-05-09 11:04:52 +02001436/**
1437 * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
1438 * properties
1439 *
1440 * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
1441 * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
1442 * @p: pointer to &struct v4l2_fwnode_device_properties
1443 *
1444 * This function registers controls associated to device properties, using the
1445 * property values contained in @p parameter, if the property has been set to
1446 * a value.
1447 *
1448 * Currently the following v4l2 controls are parsed and registered:
1449 * - V4L2_CID_CAMERA_ORIENTATION
1450 * - V4L2_CID_CAMERA_SENSOR_ROTATION;
1451 *
1452 * Controls already registered by the caller with the @hdl control handler are
1453 * not overwritten. Callers should register the controls they want to handle
1454 * themselves before calling this function.
1455 *
1456 * Return: 0 on success, a negative error code on failure.
1457 */
1458int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
1459 const struct v4l2_ctrl_ops *ctrl_ops,
1460 const struct v4l2_fwnode_device_properties *p);
Hans Verkuil09965172010-08-01 14:32:42 -03001461#endif