blob: 3f4e062d4e3d1a75d5133214088d0be622ce97b8 [file] [log] [blame]
Hans Verkuil09965172010-08-01 14:32:42 -03001/*
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03002 * V4L2 controls support header.
3 *
4 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Hans Verkuil09965172010-08-01 14:32:42 -030015 */
16
17#ifndef _V4L2_CTRLS_H
18#define _V4L2_CTRLS_H
19
20#include <linux/list.h>
Andrzej Hajdaa19dec62013-06-28 05:44:22 -030021#include <linux/mutex.h>
Laurent Pinchart01c40c02010-11-19 11:20:06 -030022#include <linux/videodev2.h>
Hans Verkuil52beedd2018-05-21 04:54:37 -040023#include <media/media-request.h>
Hans Verkuil09965172010-08-01 14:32:42 -030024
25/* forward references */
Laurent Pinchart528f0f72012-04-23 08:20:35 -030026struct file;
Hans Verkuil09965172010-08-01 14:32:42 -030027struct v4l2_ctrl_handler;
Hans Verkuileb5b16e2011-06-14 10:04:06 -030028struct v4l2_ctrl_helper;
Hans Verkuil09965172010-08-01 14:32:42 -030029struct v4l2_ctrl;
30struct video_device;
31struct v4l2_subdev;
Hans Verkuil77068d32011-06-13 18:55:58 -030032struct v4l2_subscribed_event;
Hans Verkuil6e239392011-06-07 11:13:44 -030033struct v4l2_fh;
Hans Verkuila26243b2012-01-27 16:18:42 -030034struct poll_table_struct;
Hans Verkuil09965172010-08-01 14:32:42 -030035
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030036/**
37 * union v4l2_ctrl_ptr - A pointer to a control value.
Hans Verkuil01760772014-04-27 03:22:17 -030038 * @p_s32: Pointer to a 32-bit signed value.
39 * @p_s64: Pointer to a 64-bit signed value.
Hans Verkuildda4a4d2014-06-10 07:30:04 -030040 * @p_u8: Pointer to a 8-bit unsigned value.
41 * @p_u16: Pointer to a 16-bit unsigned value.
Hans Verkuil811c5082014-07-21 10:45:37 -030042 * @p_u32: Pointer to a 32-bit unsigned value.
Hans Verkuil01760772014-04-27 03:22:17 -030043 * @p_char: Pointer to a string.
44 * @p: Pointer to a compound value.
45 */
46union v4l2_ctrl_ptr {
47 s32 *p_s32;
48 s64 *p_s64;
Hans Verkuildda4a4d2014-06-10 07:30:04 -030049 u8 *p_u8;
50 u16 *p_u16;
Hans Verkuil811c5082014-07-21 10:45:37 -030051 u32 *p_u32;
Hans Verkuil01760772014-04-27 03:22:17 -030052 char *p_char;
53 void *p;
54};
55
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030056/**
57 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -030058 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030059 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
60 * for volatile (and usually read-only) controls such as a control
61 * that returns the current signal strength which changes
62 * continuously.
63 * If not set, then the currently cached value will be returned.
64 * @try_ctrl: Test whether the control's value is valid. Only relevant when
65 * the usual min/max/step checks are not sufficient.
66 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
67 * ctrl->handler->lock is held when these ops are called, so no
68 * one else can access controls owned by that handler.
69 */
Hans Verkuil09965172010-08-01 14:32:42 -030070struct v4l2_ctrl_ops {
71 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
72 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
73 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
74};
75
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030076/**
77 * struct v4l2_ctrl_type_ops - The control type operations that the driver
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -030078 * has to provide.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030079 *
80 * @equal: return true if both values are equal.
81 * @init: initialize the value.
82 * @log: log the value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -030083 * @validate: validate the value. Return 0 on success and a negative value
84 * otherwise.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030085 */
Hans Verkuil01760772014-04-27 03:22:17 -030086struct v4l2_ctrl_type_ops {
Hans Verkuil998e7652014-06-10 07:55:00 -030087 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -030088 union v4l2_ctrl_ptr ptr1,
89 union v4l2_ctrl_ptr ptr2);
Hans Verkuil998e7652014-06-10 07:55:00 -030090 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -030091 union v4l2_ctrl_ptr ptr);
92 void (*log)(const struct v4l2_ctrl *ctrl);
Hans Verkuil998e7652014-06-10 07:55:00 -030093 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -030094 union v4l2_ctrl_ptr ptr);
95};
96
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -030097/**
98 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
99 * that should be called when a control value has changed.
100 *
101 * @ctrl: pointer to struct &v4l2_ctrl
102 * @priv: control private data
103 *
104 * This typedef definition is used as an argument to v4l2_ctrl_notify()
105 * and as an argument at struct &v4l2_ctrl_handler.
106 */
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300107typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
108
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300109/**
110 * struct v4l2_ctrl - The control structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300111 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300112 * @node: The list node.
113 * @ev_subs: The list of control event subscriptions.
114 * @handler: The handler that owns the control.
115 * @cluster: Point to start of cluster array.
116 * @ncontrols: Number of controls in cluster array.
117 * @done: Internal flag: set for each processed control.
118 * @is_new: Set when the user specified a new value for this control. It
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300119 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300120 * should never set this flag.
121 * @has_changed: Set when the current value differs from the new value. Drivers
122 * should never use this flag.
123 * @is_private: If set, then this control is private to its handler and it
124 * will not be added to any other handlers. Drivers can set
125 * this flag.
126 * @is_auto: If set, then this control selects whether the other cluster
127 * members are in 'automatic' mode or 'manual' mode. This is
128 * used for autogain/gain type clusters. Drivers should never
129 * set this flag directly.
130 * @is_int: If set, then this control has a simple integer value (i.e. it
131 * uses ctrl->val).
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300132 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
133 * @is_ptr: If set, then this control is an array and/or has type >=
134 * %V4L2_CTRL_COMPOUND_TYPES
135 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300136 * v4l2_ext_control uses field p to point to the data.
137 * @is_array: If set, then this control contains an N-dimensional array.
138 * @has_volatiles: If set, then one or more members of the cluster are volatile.
139 * Drivers should never touch this flag.
140 * @call_notify: If set, then call the handler's notify function whenever the
141 * control's value changes.
142 * @manual_mode_value: If the is_auto flag is set, then this is the value
143 * of the auto control that determines if that control is in
144 * manual mode. So if the value of the auto control equals this
145 * value, then the whole cluster is in manual mode. Drivers should
146 * never set this flag directly.
147 * @ops: The control ops.
148 * @type_ops: The control type ops.
149 * @id: The control ID.
150 * @name: The control name.
151 * @type: The control type.
152 * @minimum: The control's minimum value.
153 * @maximum: The control's maximum value.
154 * @default_value: The control's default value.
155 * @step: The control's step value for non-menu controls.
156 * @elems: The number of elements in the N-dimensional array.
157 * @elem_size: The size in bytes of the control.
158 * @dims: The size of each dimension.
159 * @nr_of_dims:The number of dimensions in @dims.
160 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
161 * easy to skip menu items that are not valid. If bit X is set,
162 * then menu item X is skipped. Of course, this only works for
163 * menus with <= 32 menu items. There are no menus that come
164 * close to that number, so this is OK. Should we ever need more,
165 * then this will have to be extended to a u64 or a bit array.
166 * @qmenu: A const char * array for all menu items. Array entries that are
167 * empty strings ("") correspond to non-existing menu items (this
168 * is in addition to the menu_skip_mask above). The last entry
169 * must be NULL.
Mauro Carvalho Chehab20139f12017-09-27 12:25:21 -0400170 * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
171 * @qmenu_int: A 64-bit integer array for with integer menu items.
172 * The size of array must be equal to the menu size, e. g.:
173 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
174 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300175 * @flags: The control's flags.
Mauro Carvalho Chehab20139f12017-09-27 12:25:21 -0400176 * @cur: Structure to store the current value.
177 * @cur.val: The control's current value, if the @type is represented via
178 * a u32 integer (see &enum v4l2_ctrl_type).
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300179 * @val: The control's new s32 value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300180 * @priv: The control's private pointer. For use by the driver. It is
181 * untouched by the control framework. Note that this pointer is
182 * not freed when the control is deleted. Should this be needed
183 * then a new internal bitfield can be added to tell the framework
184 * to free this pointer.
Baruch Siachbf7b7042018-07-05 05:38:00 -0400185 * @p_cur: The control's current value represented via a union which
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300186 * provides a standard way of accessing control types
187 * through a pointer.
Baruch Siachbf7b7042018-07-05 05:38:00 -0400188 * @p_new: The control's new value represented via a union which provides
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300189 * a standard way of accessing control types
190 * through a pointer.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300191 */
Hans Verkuil09965172010-08-01 14:32:42 -0300192struct v4l2_ctrl {
193 /* Administrative fields */
194 struct list_head node;
Hans Verkuil77068d32011-06-13 18:55:58 -0300195 struct list_head ev_subs;
Hans Verkuil09965172010-08-01 14:32:42 -0300196 struct v4l2_ctrl_handler *handler;
197 struct v4l2_ctrl **cluster;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300198 unsigned int ncontrols;
199
Hans Verkuil09965172010-08-01 14:32:42 -0300200 unsigned int done:1;
201
Hans Verkuil2a863792011-01-11 14:45:03 -0300202 unsigned int is_new:1;
Hans Verkuil9ea1b7a2014-01-17 08:25:26 -0300203 unsigned int has_changed:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300204 unsigned int is_private:1;
Hans Verkuil72d877c2011-06-10 05:44:36 -0300205 unsigned int is_auto:1;
Hans Verkuild9a25472014-06-12 07:54:16 -0300206 unsigned int is_int:1;
207 unsigned int is_string:1;
208 unsigned int is_ptr:1;
Hans Verkuil998e7652014-06-10 07:55:00 -0300209 unsigned int is_array:1;
Hans Verkuil5626b8c2011-08-26 07:53:53 -0300210 unsigned int has_volatiles:1;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300211 unsigned int call_notify:1;
Hans Verkuil82a7c042011-06-28 10:43:13 -0300212 unsigned int manual_mode_value:8;
Hans Verkuil09965172010-08-01 14:32:42 -0300213
214 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300215 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300216 u32 id;
217 const char *name;
218 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300219 s64 minimum, maximum, default_value;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300220 u32 elems;
Hans Verkuild9a25472014-06-12 07:54:16 -0300221 u32 elem_size;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300222 u32 dims[V4L2_CTRL_MAX_DIMS];
223 u32 nr_of_dims;
Hans Verkuil09965172010-08-01 14:32:42 -0300224 union {
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300225 u64 step;
226 u64 menu_skip_mask;
Hans Verkuil09965172010-08-01 14:32:42 -0300227 };
Sakari Ailusce580fe2011-08-04 13:51:11 -0300228 union {
229 const char * const *qmenu;
230 const s64 *qmenu_int;
231 };
Hans Verkuil09965172010-08-01 14:32:42 -0300232 unsigned long flags;
Hans Verkuil09965172010-08-01 14:32:42 -0300233 void *priv;
Hans Verkuil2a9ec372014-04-27 03:38:13 -0300234 s32 val;
235 struct {
Hans Verkuild9a25472014-06-12 07:54:16 -0300236 s32 val;
Hans Verkuild9a25472014-06-12 07:54:16 -0300237 } cur;
Hans Verkuil01760772014-04-27 03:22:17 -0300238
239 union v4l2_ctrl_ptr p_new;
240 union v4l2_ctrl_ptr p_cur;
Hans Verkuil09965172010-08-01 14:32:42 -0300241};
242
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300243/**
244 * struct v4l2_ctrl_ref - The control reference.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300245 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300246 * @node: List node for the sorted list.
247 * @next: Single-link list node for the hash.
248 * @ctrl: The actual control information.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300249 * @helper: Pointer to helper struct. Used internally in
Mauro Carvalho Chehabfb911612016-08-29 18:43:02 -0300250 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400251 * @from_other_dev: If true, then @ctrl was defined in another
252 * device than the &struct v4l2_ctrl_handler.
Hans Verkuil52beedd2018-05-21 04:54:37 -0400253 * @p_req: If the control handler containing this control reference
254 * is bound to a media request, then this points to the
255 * value of the control that should be applied when the request
256 * is executed, or to the value of the control at the time
257 * that the request was completed.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300258 *
259 * Each control handler has a list of these refs. The list_head is used to
260 * keep a sorted-by-control-ID list of all controls, while the next pointer
261 * is used to link the control in the hash's bucket.
262 */
Hans Verkuil09965172010-08-01 14:32:42 -0300263struct v4l2_ctrl_ref {
264 struct list_head node;
265 struct v4l2_ctrl_ref *next;
266 struct v4l2_ctrl *ctrl;
Hans Verkuileb5b16e2011-06-14 10:04:06 -0300267 struct v4l2_ctrl_helper *helper;
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400268 bool from_other_dev;
Hans Verkuil52beedd2018-05-21 04:54:37 -0400269 union v4l2_ctrl_ptr p_req;
Hans Verkuil09965172010-08-01 14:32:42 -0300270};
271
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300272/**
273 * struct v4l2_ctrl_handler - The control handler keeps track of all the
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300274 * controls: both the controls owned by the handler and those inherited
275 * from other handlers.
276 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300277 * @_lock: Default for "lock".
278 * @lock: Lock to control access to this handler and its controls.
279 * May be replaced by the user right after init.
280 * @ctrls: The list of controls owned by this handler.
281 * @ctrl_refs: The list of control references.
282 * @cached: The last found control reference. It is common that the same
283 * control is needed multiple times, so this is a simple
284 * optimization.
285 * @buckets: Buckets for the hashing. Allows for quick control lookup.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300286 * @notify: A notify callback that is called whenever the control changes
287 * value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300288 * Note that the handler's lock is held when the notify function
289 * is called!
290 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
291 * @nr_of_buckets: Total number of buckets in the array.
292 * @error: The error code of the first failed control addition.
Hans Verkuil52beedd2018-05-21 04:54:37 -0400293 * @req_obj: The &struct media_request_object, used to link into a
294 * &struct media_request. This request object has a refcount.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300295 */
Hans Verkuil09965172010-08-01 14:32:42 -0300296struct v4l2_ctrl_handler {
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300297 struct mutex _lock;
298 struct mutex *lock;
Hans Verkuil09965172010-08-01 14:32:42 -0300299 struct list_head ctrls;
300 struct list_head ctrl_refs;
301 struct v4l2_ctrl_ref *cached;
302 struct v4l2_ctrl_ref **buckets;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300303 v4l2_ctrl_notify_fnc notify;
304 void *notify_priv;
Hans Verkuil09965172010-08-01 14:32:42 -0300305 u16 nr_of_buckets;
306 int error;
Hans Verkuil52beedd2018-05-21 04:54:37 -0400307 struct media_request_object req_obj;
Hans Verkuil09965172010-08-01 14:32:42 -0300308};
309
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300310/**
311 * struct v4l2_ctrl_config - Control configuration structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300312 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300313 * @ops: The control ops.
314 * @type_ops: The control type ops. Only needed for compound controls.
315 * @id: The control ID.
316 * @name: The control name.
317 * @type: The control type.
318 * @min: The control's minimum value.
319 * @max: The control's maximum value.
320 * @step: The control's step value for non-menu controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300321 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300322 * @dims: The size of each dimension.
323 * @elem_size: The size in bytes of the control.
324 * @flags: The control's flags.
325 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
326 * easy to skip menu items that are not valid. If bit X is set,
327 * then menu item X is skipped. Of course, this only works for
328 * menus with <= 64 menu items. There are no menus that come
329 * close to that number, so this is OK. Should we ever need more,
330 * then this will have to be extended to a bit array.
331 * @qmenu: A const char * array for all menu items. Array entries that are
332 * empty strings ("") correspond to non-existing menu items (this
333 * is in addition to the menu_skip_mask above). The last entry
334 * must be NULL.
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300335 * @qmenu_int: A const s64 integer array for all menu items of the type
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300336 * V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300337 * @is_private: If set, then this control is private to its handler and it
338 * will not be added to any other handlers.
339 */
Hans Verkuil09965172010-08-01 14:32:42 -0300340struct v4l2_ctrl_config {
341 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300342 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300343 u32 id;
344 const char *name;
345 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300346 s64 min;
347 s64 max;
348 u64 step;
349 s64 def;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300350 u32 dims[V4L2_CTRL_MAX_DIMS];
Hans Verkuild9a25472014-06-12 07:54:16 -0300351 u32 elem_size;
Hans Verkuil09965172010-08-01 14:32:42 -0300352 u32 flags;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300353 u64 menu_skip_mask;
Hans Verkuil513521e2010-12-29 14:25:52 -0300354 const char * const *qmenu;
Sakari Ailusce580fe2011-08-04 13:51:11 -0300355 const s64 *qmenu_int;
Hans Verkuil09965172010-08-01 14:32:42 -0300356 unsigned int is_private:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300357};
358
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300359/**
360 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
361 *
362 * @id: ID of the control
Mauro Carvalho Chehab67c672e2017-08-12 05:57:05 -0400363 * @name: pointer to be filled with a string with the name of the control
364 * @type: pointer for storing the type of the control
365 * @min: pointer for storing the minimum value for the control
366 * @max: pointer for storing the maximum value for the control
367 * @step: pointer for storing the control step
368 * @def: pointer for storing the default value for the control
369 * @flags: pointer for storing the flags to be used on the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300370 *
371 * This works for all standard V4L2 controls.
372 * For non-standard controls it will only fill in the given arguments
Mauro Carvalho Chehab67c672e2017-08-12 05:57:05 -0400373 * and @name content will be set to %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300374 *
375 * This function will overwrite the contents of @name, @type and @flags.
376 * The contents of @min, @max, @step and @def may be modified depending on
377 * the type.
378 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300379 * .. note::
380 *
381 * Do not use in drivers! It is used internally for backwards compatibility
382 * control handling only. Once all drivers are converted to use the new
383 * control framework this function will no longer be exported.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300384 */
Hans Verkuil09965172010-08-01 14:32:42 -0300385void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300386 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
Hans Verkuil09965172010-08-01 14:32:42 -0300387
388
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300389/**
390 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
391 * @hdl: The control handler.
392 * @nr_of_controls_hint: A hint of how many controls this handler is
393 * expected to refer to. This is the total number, so including
394 * any inherited controls. It doesn't have to be precise, but if
395 * it is way off, then you either waste memory (too many buckets
396 * are allocated) or the control lookup becomes slower (not enough
397 * buckets are allocated, so there are more slow list lookups).
398 * It will always work, though.
399 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
400 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
401 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300402 * .. attention::
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300403 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300404 * Never use this call directly, always use the v4l2_ctrl_handler_init()
405 * macro that hides the @key and @name arguments.
406 *
407 * Return: returns an error if the buckets could not be allocated. This
408 * error will also be stored in @hdl->error.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300409 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300410int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300411 unsigned int nr_of_controls_hint,
Andy Walls6cd247e2013-03-09 05:55:11 -0300412 struct lock_class_key *key, const char *name);
413
414#ifdef CONFIG_LOCKDEP
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300415
416/**
Mauro Carvalho Chehabe383ce02016-09-22 07:59:03 -0300417 * v4l2_ctrl_handler_init - helper function to create a static struct
418 * &lock_class_key and calls v4l2_ctrl_handler_init_class()
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300419 *
420 * @hdl: The control handler.
421 * @nr_of_controls_hint: A hint of how many controls this handler is
422 * expected to refer to. This is the total number, so including
423 * any inherited controls. It doesn't have to be precise, but if
424 * it is way off, then you either waste memory (too many buckets
425 * are allocated) or the control lookup becomes slower (not enough
426 * buckets are allocated, so there are more slow list lookups).
427 * It will always work, though.
428 *
429 * This helper function creates a static struct &lock_class_key and
430 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
431 * validador.
432 *
433 * Use this helper function to initialize a control handler.
434 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300435#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
436( \
437 ({ \
438 static struct lock_class_key _key; \
439 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
440 &_key, \
441 KBUILD_BASENAME ":" \
442 __stringify(__LINE__) ":" \
443 "(" #hdl ")->_lock"); \
444 }) \
445)
446#else
447#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
448 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
449#endif
Hans Verkuil09965172010-08-01 14:32:42 -0300450
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300451/**
452 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
453 * the control list.
454 * @hdl: The control handler.
455 *
456 * Does nothing if @hdl == NULL.
457 */
Hans Verkuil09965172010-08-01 14:32:42 -0300458void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
459
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300460/**
461 * v4l2_ctrl_lock() - Helper function to lock the handler
462 * associated with the control.
463 * @ctrl: The control to lock.
464 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300465static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
466{
467 mutex_lock(ctrl->handler->lock);
468}
469
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300470/**
471 * v4l2_ctrl_unlock() - Helper function to unlock the handler
472 * associated with the control.
473 * @ctrl: The control to unlock.
474 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300475static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
476{
477 mutex_unlock(ctrl->handler->lock);
478}
479
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300480/**
Sakari Ailuscc0140e2017-05-26 05:21:37 -0300481 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
482 * to the handler to initialize the hardware to the current control values. The
483 * caller is responsible for acquiring the control handler mutex on behalf of
484 * __v4l2_ctrl_handler_setup().
485 * @hdl: The control handler.
486 *
487 * Button controls will be skipped, as are read-only controls.
488 *
489 * If @hdl == NULL, then this just returns 0.
490 */
491int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
492
493/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300494 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
495 * to the handler to initialize the hardware to the current control values.
496 * @hdl: The control handler.
497 *
498 * Button controls will be skipped, as are read-only controls.
499 *
500 * If @hdl == NULL, then this just returns 0.
501 */
Hans Verkuil09965172010-08-01 14:32:42 -0300502int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
503
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300504/**
505 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
506 * @hdl: The control handler.
507 * @prefix: The prefix to use when logging the control values. If the
508 * prefix does not end with a space, then ": " will be added
509 * after the prefix. If @prefix == NULL, then no prefix will be
510 * used.
511 *
512 * For use with VIDIOC_LOG_STATUS.
513 *
514 * Does nothing if @hdl == NULL.
515 */
Hans Verkuil09965172010-08-01 14:32:42 -0300516void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
517 const char *prefix);
518
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300519/**
520 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300521 * control.
522 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300523 * @hdl: The control handler.
524 * @cfg: The control's configuration data.
525 * @priv: The control's driver-specific private data.
526 *
527 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
528 * and @hdl->error is set to the error code (if it wasn't set already).
529 */
Hans Verkuil09965172010-08-01 14:32:42 -0300530struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300531 const struct v4l2_ctrl_config *cfg,
532 void *priv);
Hans Verkuil09965172010-08-01 14:32:42 -0300533
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300534/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300535 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
536 * control.
537 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300538 * @hdl: The control handler.
539 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300540 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300541 * @min: The control's minimum value.
542 * @max: The control's maximum value.
543 * @step: The control's step value
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300544 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300545 *
546 * If the &v4l2_ctrl struct could not be allocated, or the control
547 * ID is not known, then NULL is returned and @hdl->error is set to the
548 * appropriate error code (if it wasn't set already).
549 *
550 * If @id refers to a menu control, then this function will return NULL.
551 *
552 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
553 */
Hans Verkuil09965172010-08-01 14:32:42 -0300554struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300555 const struct v4l2_ctrl_ops *ops,
556 u32 id, s64 min, s64 max, u64 step,
557 s64 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300558
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300559/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300560 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
561 * menu control.
562 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300563 * @hdl: The control handler.
564 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300565 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300566 * @max: The control's maximum value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300567 * @mask: The control's skip mask for menu controls. This makes it
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300568 * easy to skip menu items that are not valid. If bit X is set,
569 * then menu item X is skipped. Of course, this only works for
570 * menus with <= 64 menu items. There are no menus that come
571 * close to that number, so this is OK. Should we ever need more,
572 * then this will have to be extended to a bit array.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300573 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300574 *
575 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
576 * determines which menu items are to be skipped.
577 *
578 * If @id refers to a non-menu control, then this function will return NULL.
579 */
Hans Verkuil09965172010-08-01 14:32:42 -0300580struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300581 const struct v4l2_ctrl_ops *ops,
582 u32 id, u8 max, u64 mask, u8 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300583
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300584/**
585 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300586 * with driver specific menu.
587 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300588 * @hdl: The control handler.
589 * @ops: The control ops.
590 * @id: The control ID.
591 * @max: The control's maximum value.
592 * @mask: The control's skip mask for menu controls. This makes it
593 * easy to skip menu items that are not valid. If bit X is set,
594 * then menu item X is skipped. Of course, this only works for
595 * menus with <= 64 menu items. There are no menus that come
596 * close to that number, so this is OK. Should we ever need more,
597 * then this will have to be extended to a bit array.
598 * @def: The control's default value.
599 * @qmenu: The new menu.
600 *
601 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
602 * menu of this control.
603 *
604 */
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300605struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300606 const struct v4l2_ctrl_ops *ops,
607 u32 id, u8 max,
608 u64 mask, u8 def,
609 const char * const *qmenu);
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300610
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300611/**
612 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300613 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300614 * @hdl: The control handler.
615 * @ops: The control ops.
616 * @id: The control ID.
617 * @max: The control's maximum value.
618 * @def: The control's default value.
619 * @qmenu_int: The control's menu entries.
620 *
621 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
622 * takes as an argument an array of integers determining the menu items.
623 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300624 * If @id refers to a non-integer-menu control, then this function will
625 * return %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300626 */
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300627struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300628 const struct v4l2_ctrl_ops *ops,
629 u32 id, u8 max, u8 def,
630 const s64 *qmenu_int);
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300631
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300632/**
633 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
634 * used when adding a control handler.
635 *
636 * @ctrl: pointer to struct &v4l2_ctrl.
637 */
638
Mauro Carvalho Chehab6d85d7d2016-07-22 10:58:03 -0300639typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
640
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300641/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300642 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300643 * handler @hdl.
644 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300645 * @hdl: The control handler.
646 * @add: The control handler whose controls you want to add to
647 * the @hdl control handler.
648 * @filter: This function will filter which controls should be added.
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400649 * @from_other_dev: If true, then the controls in @add were defined in another
650 * device than @hdl.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300651 *
652 * Does nothing if either of the two handlers is a NULL pointer.
653 * If @filter is NULL, then all controls are added. Otherwise only those
654 * controls for which @filter returns true will be added.
655 * In case of an error @hdl->error will be set to the error code (if it
656 * wasn't set already).
657 */
Hans Verkuil09965172010-08-01 14:32:42 -0300658int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300659 struct v4l2_ctrl_handler *add,
Hans Verkuilda1b1ae2018-05-21 04:54:36 -0400660 v4l2_ctrl_filter filter,
661 bool from_other_dev);
Hans Verkuil09965172010-08-01 14:32:42 -0300662
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300663/**
664 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300665 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300666 * @ctrl: The control that is filtered.
667 *
668 * This will return true for any controls that are valid for radio device
669 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
670 * transmitter class controls.
671 *
672 * This function is to be used with v4l2_ctrl_add_handler().
673 */
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300674bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
Hans Verkuil09965172010-08-01 14:32:42 -0300675
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300676/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300677 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
678 * to that cluster.
679 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300680 * @ncontrols: The number of controls in this cluster.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300681 * @controls: The cluster control array of size @ncontrols.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300682 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300683void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
Hans Verkuil09965172010-08-01 14:32:42 -0300684
685
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300686/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300687 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
688 * to that cluster and set it up for autofoo/foo-type handling.
689 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300690 * @ncontrols: The number of controls in this cluster.
691 * @controls: The cluster control array of size @ncontrols. The first control
692 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
693 * @manual_val: The value for the first control in the cluster that equals the
694 * manual setting.
695 * @set_volatile: If true, then all controls except the first auto control will
696 * be volatile.
697 *
698 * Use for control groups where one control selects some automatic feature and
699 * the other controls are only active whenever the automatic feature is turned
700 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
701 * red and blue balance, etc.
702 *
703 * The behavior of such controls is as follows:
704 *
705 * When the autofoo control is set to automatic, then any manual controls
706 * are set to inactive and any reads will call g_volatile_ctrl (if the control
707 * was marked volatile).
708 *
709 * When the autofoo control is set to manual, then any manual controls will
710 * be marked active, and any reads will just return the current value without
711 * going through g_volatile_ctrl.
712 *
Mauro Carvalho Chehab2257e182016-08-29 17:26:15 -0300713 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
714 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300715 * if autofoo is in auto mode.
716 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300717void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
718 struct v4l2_ctrl **controls,
719 u8 manual_val, bool set_volatile);
Hans Verkuil72d877c2011-06-10 05:44:36 -0300720
721
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300722/**
723 * v4l2_ctrl_find() - Find a control with the given ID.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300724 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300725 * @hdl: The control handler.
726 * @id: The control ID to find.
727 *
728 * If @hdl == NULL this will return NULL as well. Will lock the handler so
729 * do not use from inside &v4l2_ctrl_ops.
730 */
Hans Verkuil09965172010-08-01 14:32:42 -0300731struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
732
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300733/**
734 * v4l2_ctrl_activate() - Make the control active or inactive.
735 * @ctrl: The control to (de)activate.
736 * @active: True if the control should become active.
737 *
738 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
739 * Does nothing if @ctrl == NULL.
740 * This will usually be called from within the s_ctrl op.
741 * The V4L2_EVENT_CTRL event will be generated afterwards.
742 *
743 * This function assumes that the control handler is locked.
744 */
Hans Verkuil09965172010-08-01 14:32:42 -0300745void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
746
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300747/**
748 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300749 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300750 * @ctrl: The control to (de)activate.
751 * @grabbed: True if the control should become grabbed.
752 *
753 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
754 * Does nothing if @ctrl == NULL.
755 * The V4L2_EVENT_CTRL event will be generated afterwards.
756 * This will usually be called when starting or stopping streaming in the
757 * driver.
758 *
759 * This function assumes that the control handler is not locked and will
760 * take the lock itself.
761 */
Hans Verkuil09965172010-08-01 14:32:42 -0300762void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
763
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300764/**
765 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
766 *
767 * @ctrl: The control to update.
768 * @min: The control's minimum value.
769 * @max: The control's maximum value.
770 * @step: The control's step value
771 * @def: The control's default value.
772 *
773 * Update the range of a control on the fly. This works for control types
774 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
775 * @step value is interpreted as a menu_skip_mask.
776 *
777 * An error is returned if one of the range arguments is invalid for this
778 * control type.
779 *
Hans Verkuil97eee232018-02-03 08:18:14 -0500780 * The caller is responsible for acquiring the control handler mutex on behalf
781 * of __v4l2_ctrl_modify_range().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300782 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300783int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
784 s64 min, s64 max, u64 step, s64 def);
785
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300786/**
787 * v4l2_ctrl_modify_range() - Update the range of a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300788 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300789 * @ctrl: The control to update.
790 * @min: The control's minimum value.
791 * @max: The control's maximum value.
792 * @step: The control's step value
793 * @def: The control's default value.
794 *
795 * Update the range of a control on the fly. This works for control types
796 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
797 * @step value is interpreted as a menu_skip_mask.
798 *
799 * An error is returned if one of the range arguments is invalid for this
800 * control type.
801 *
802 * This function assumes that the control handler is not locked and will
803 * take the lock itself.
804 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300805static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
806 s64 min, s64 max, u64 step, s64 def)
807{
808 int rval;
809
810 v4l2_ctrl_lock(ctrl);
811 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
812 v4l2_ctrl_unlock(ctrl);
813
814 return rval;
815}
Sylwester Nawrocki2ccbe772013-01-19 15:51:55 -0300816
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300817/**
818 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300819 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300820 * @ctrl: The control.
821 * @notify: The callback function.
822 * @priv: The callback private handle, passed as argument to the callback.
823 *
824 * This function sets a callback function for the control. If @ctrl is NULL,
825 * then it will do nothing. If @notify is NULL, then the notify callback will
826 * be removed.
827 *
828 * There can be only one notify. If another already exists, then a WARN_ON
829 * will be issued and the function will do nothing.
830 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300831void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
832 void *priv);
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300833
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300834/**
835 * v4l2_ctrl_get_name() - Get the name of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300836 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300837 * @id: The control ID.
838 *
839 * This function returns the name of the given control ID or NULL if it isn't
840 * a known control.
841 */
842const char *v4l2_ctrl_get_name(u32 id);
843
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300844/**
845 * v4l2_ctrl_get_menu() - Get the menu string array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300846 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300847 * @id: The control ID.
848 *
849 * This function returns the NULL-terminated menu string array name of the
850 * given control ID or NULL if it isn't a known menu control.
851 */
852const char * const *v4l2_ctrl_get_menu(u32 id);
853
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300854/**
855 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300856 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300857 * @id: The control ID.
858 * @len: The size of the integer array.
859 *
860 * This function returns the integer array of the given control ID or NULL if it
861 * if it isn't a known integer menu control.
862 */
863const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
864
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300865/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300866 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
867 * within a driver.
868 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300869 * @ctrl: The control.
870 *
871 * This returns the control's value safely by going through the control
872 * framework. This function will lock the control's handler, so it cannot be
873 * used from within the &v4l2_ctrl_ops functions.
874 *
875 * This function is for integer type controls only.
876 */
Hans Verkuil09965172010-08-01 14:32:42 -0300877s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
878
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300879/**
880 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300881 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300882 * @ctrl: The control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300883 * @val: TheControls name new value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300884 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300885 * This sets the control's new value safely by going through the control
886 * framework. This function assumes the control's handler is already locked,
887 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300888 *
889 * This function is for integer type controls only.
890 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300891int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300892
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300893/**
894 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
895 * within a driver.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300896 * @ctrl: The control.
897 * @val: The new value.
898 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300899 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300900 * framework. This function will lock the control's handler, so it cannot be
901 * used from within the &v4l2_ctrl_ops functions.
902 *
903 * This function is for integer type controls only.
904 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300905static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
906{
907 int rval;
908
909 v4l2_ctrl_lock(ctrl);
910 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
911 v4l2_ctrl_unlock(ctrl);
912
913 return rval;
914}
Hans Verkuil09965172010-08-01 14:32:42 -0300915
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300916/**
917 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
918 * from within a driver.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300919 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300920 * @ctrl: The control.
921 *
922 * This returns the control's value safely by going through the control
923 * framework. This function will lock the control's handler, so it cannot be
924 * used from within the &v4l2_ctrl_ops functions.
925 *
926 * This function is for 64-bit integer type controls only.
927 */
Laurent Pinchart03d52852012-07-23 09:15:21 -0300928s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
929
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300930/**
931 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
932 *
933 * @ctrl: The control.
934 * @val: The new value.
935 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300936 * This sets the control's new value safely by going through the control
937 * framework. This function assumes the control's handler is already locked,
938 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300939 *
940 * This function is for 64-bit integer type controls only.
941 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300942int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
943
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300944/**
945 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300946 * from within a driver.
947 *
948 * @ctrl: The control.
949 * @val: The new value.
950 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300951 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300952 * framework. This function will lock the control's handler, so it cannot be
953 * used from within the &v4l2_ctrl_ops functions.
954 *
955 * This function is for 64-bit integer type controls only.
956 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300957static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
958{
959 int rval;
960
961 v4l2_ctrl_lock(ctrl);
962 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
963 v4l2_ctrl_unlock(ctrl);
964
965 return rval;
966}
Laurent Pinchart03d52852012-07-23 09:15:21 -0300967
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300968/**
969 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300970 *
971 * @ctrl: The control.
972 * @s: The new string.
973 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300974 * This sets the control's new string safely by going through the control
975 * framework. This function assumes the control's handler is already locked,
976 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300977 *
978 * This function is for string type controls only.
979 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -0300980int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
981
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300982/**
983 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300984 * from within a driver.
985 *
986 * @ctrl: The control.
987 * @s: The new string.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300988 *Controls name
Hans Verkuil904aef02016-06-15 09:57:48 -0300989 * This sets the control's new string safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300990 * framework. This function will lock the control's handler, so it cannot be
991 * used from within the &v4l2_ctrl_ops functions.
992 *
993 * This function is for string type controls only.
994 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -0300995static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
996{
997 int rval;
998
999 v4l2_ctrl_lock(ctrl);
1000 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1001 v4l2_ctrl_unlock(ctrl);
1002
1003 return rval;
1004}
1005
Hans Verkuilce727572011-06-10 05:56:39 -03001006/* Internal helper functions that deal with control events. */
Hans de Goede3e3661492012-04-08 12:59:47 -03001007extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001008
1009/**
1010 * v4l2_ctrl_replace - Function to be used as a callback to
1011 * &struct v4l2_subscribed_event_ops replace\(\)
1012 *
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001013 * @old: pointer to struct &v4l2_event with the reported
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001014 * event;
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001015 * @new: pointer to struct &v4l2_event with the modified
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001016 * event;
1017 */
Hans de Goede3e3661492012-04-08 12:59:47 -03001018void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001019
1020/**
1021 * v4l2_ctrl_merge - Function to be used as a callback to
1022 * &struct v4l2_subscribed_event_ops merge(\)
1023 *
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001024 * @old: pointer to struct &v4l2_event with the reported
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001025 * event;
Mauro Carvalho Chehabf8441a42016-08-29 19:29:58 -03001026 * @new: pointer to struct &v4l2_event with the merged
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001027 * event;
1028 */
Hans de Goede3e3661492012-04-08 12:59:47 -03001029void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
Hans Verkuil6e239392011-06-07 11:13:44 -03001030
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001031/**
1032 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1033 *
1034 * @file: pointer to struct file
1035 * @fh: unused. Kept just to be compatible to the arguments expected by
1036 * &struct v4l2_ioctl_ops.vidioc_log_status.
1037 *
1038 * Can be used as a vidioc_log_status function that just dumps all controls
1039 * associated with the filehandle.
1040 */
Hans Verkuile2ecb252012-02-02 08:20:53 -03001041int v4l2_ctrl_log_status(struct file *file, void *fh);
1042
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001043/**
1044 * v4l2_ctrl_subscribe_event - Subscribes to an event
1045 *
1046 *
1047 * @fh: pointer to struct v4l2_fh
1048 * @sub: pointer to &struct v4l2_event_subscription
1049 *
1050 * Can be used as a vidioc_subscribe_event function that just subscribes
1051 * control events.
1052 */
Hans Verkuila26243b2012-01-27 16:18:42 -03001053int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
Hans Verkuil85f5fe32012-09-04 11:46:09 -03001054 const struct v4l2_event_subscription *sub);
Hans Verkuila26243b2012-01-27 16:18:42 -03001055
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001056/**
1057 * v4l2_ctrl_poll - function to be used as a callback to the poll()
1058 * That just polls for control events.
1059 *
1060 * @file: pointer to struct file
1061 * @wait: pointer to struct poll_table_struct
1062 */
Al Viroc23e0cb2017-07-03 03:02:56 -04001063__poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
Hans Verkuila26243b2012-01-27 16:18:42 -03001064
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001065/* Helpers for ioctl_ops */
Hans Verkuil09965172010-08-01 14:32:42 -03001066
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001067/**
1068 * v4l2_queryctrl - Helper function to implement
1069 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1070 *
1071 * @hdl: pointer to &struct v4l2_ctrl_handler
1072 * @qc: pointer to &struct v4l2_queryctrl
1073 *
1074 * If hdl == NULL then they will all return -EINVAL.
1075 */
1076int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1077
1078/**
1079 * v4l2_query_ext_ctrl - Helper function to implement
1080 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1081 *
1082 * @hdl: pointer to &struct v4l2_ctrl_handler
1083 * @qc: pointer to &struct v4l2_query_ext_ctrl
1084 *
1085 * If hdl == NULL then they will all return -EINVAL.
1086 */
1087int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1088 struct v4l2_query_ext_ctrl *qc);
1089
1090/**
1091 * v4l2_querymenu - Helper function to implement
1092 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1093 *
1094 * @hdl: pointer to &struct v4l2_ctrl_handler
1095 * @qm: pointer to &struct v4l2_querymenu
1096 *
1097 * If hdl == NULL then they will all return -EINVAL.
1098 */
1099int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1100
1101/**
1102 * v4l2_g_ctrl - Helper function to implement
1103 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1104 *
1105 * @hdl: pointer to &struct v4l2_ctrl_handler
1106 * @ctrl: pointer to &struct v4l2_control
1107 *
1108 * If hdl == NULL then they will all return -EINVAL.
1109 */
1110int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1111
1112/**
1113 * v4l2_s_ctrl - Helper function to implement
1114 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1115 *
1116 * @fh: pointer to &struct v4l2_fh
1117 * @hdl: pointer to &struct v4l2_ctrl_handler
1118 *
1119 * @ctrl: pointer to &struct v4l2_control
1120 *
1121 * If hdl == NULL then they will all return -EINVAL.
1122 */
1123int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1124 struct v4l2_control *ctrl);
1125
1126/**
1127 * v4l2_g_ext_ctrls - Helper function to implement
1128 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1129 *
1130 * @hdl: pointer to &struct v4l2_ctrl_handler
1131 * @c: pointer to &struct v4l2_ext_controls
1132 *
1133 * If hdl == NULL then they will all return -EINVAL.
1134 */
1135int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1136 struct v4l2_ext_controls *c);
1137
1138/**
1139 * v4l2_try_ext_ctrls - Helper function to implement
1140 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1141 *
1142 * @hdl: pointer to &struct v4l2_ctrl_handler
1143 * @c: pointer to &struct v4l2_ext_controls
1144 *
1145 * If hdl == NULL then they will all return -EINVAL.
1146 */
1147int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1148 struct v4l2_ext_controls *c);
1149
1150/**
1151 * v4l2_s_ext_ctrls - Helper function to implement
1152 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1153 *
1154 * @fh: pointer to &struct v4l2_fh
1155 * @hdl: pointer to &struct v4l2_ctrl_handler
1156 * @c: pointer to &struct v4l2_ext_controls
1157 *
1158 * If hdl == NULL then they will all return -EINVAL.
1159 */
1160int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1161 struct v4l2_ext_controls *c);
1162
1163/**
1164 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
Mauro Carvalho Chehab4a3fad72018-01-04 06:47:28 -05001165 * as a &struct v4l2_subdev_core_ops subscribe_event function
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001166 * that just subscribes control events.
1167 *
1168 * @sd: pointer to &struct v4l2_subdev
1169 * @fh: pointer to &struct v4l2_fh
1170 * @sub: pointer to &struct v4l2_event_subscription
1171 */
Sylwester Nawrocki22fa4272013-01-22 19:00:23 -03001172int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1173 struct v4l2_event_subscription *sub);
1174
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001175/**
1176 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1177 * handler.
1178 *
1179 * @sd: pointer to &struct v4l2_subdev
1180 */
Sylwester Nawrockiffa9b9f2013-01-22 19:01:02 -03001181int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1182
Hans Verkuil09965172010-08-01 14:32:42 -03001183#endif