blob: 178a88d45aea0c1a303a61259dd5390029f60cd7 [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 Verkuil09965172010-08-01 14:32:42 -030023
24/* forward references */
Laurent Pinchart528f0f72012-04-23 08:20:35 -030025struct file;
Hans Verkuil09965172010-08-01 14:32:42 -030026struct v4l2_ctrl_handler;
Hans Verkuileb5b16e2011-06-14 10:04:06 -030027struct v4l2_ctrl_helper;
Hans Verkuil09965172010-08-01 14:32:42 -030028struct v4l2_ctrl;
29struct video_device;
30struct v4l2_subdev;
Hans Verkuil77068d32011-06-13 18:55:58 -030031struct v4l2_subscribed_event;
Hans Verkuil6e239392011-06-07 11:13:44 -030032struct v4l2_fh;
Hans Verkuila26243b2012-01-27 16:18:42 -030033struct poll_table_struct;
Hans Verkuil09965172010-08-01 14:32:42 -030034
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030035/**
36 * union v4l2_ctrl_ptr - A pointer to a control value.
Hans Verkuil01760772014-04-27 03:22:17 -030037 * @p_s32: Pointer to a 32-bit signed value.
38 * @p_s64: Pointer to a 64-bit signed value.
Hans Verkuildda4a4d2014-06-10 07:30:04 -030039 * @p_u8: Pointer to a 8-bit unsigned value.
40 * @p_u16: Pointer to a 16-bit unsigned value.
Hans Verkuil811c5082014-07-21 10:45:37 -030041 * @p_u32: Pointer to a 32-bit unsigned value.
Hans Verkuil01760772014-04-27 03:22:17 -030042 * @p_char: Pointer to a string.
43 * @p: Pointer to a compound value.
44 */
45union v4l2_ctrl_ptr {
46 s32 *p_s32;
47 s64 *p_s64;
Hans Verkuildda4a4d2014-06-10 07:30:04 -030048 u8 *p_u8;
49 u16 *p_u16;
Hans Verkuil811c5082014-07-21 10:45:37 -030050 u32 *p_u32;
Hans Verkuil01760772014-04-27 03:22:17 -030051 char *p_char;
52 void *p;
53};
54
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030055/**
56 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -030057 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030058 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
59 * for volatile (and usually read-only) controls such as a control
60 * that returns the current signal strength which changes
61 * continuously.
62 * If not set, then the currently cached value will be returned.
63 * @try_ctrl: Test whether the control's value is valid. Only relevant when
64 * the usual min/max/step checks are not sufficient.
65 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
66 * ctrl->handler->lock is held when these ops are called, so no
67 * one else can access controls owned by that handler.
68 */
Hans Verkuil09965172010-08-01 14:32:42 -030069struct v4l2_ctrl_ops {
70 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
71 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
72 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
73};
74
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030075/**
76 * struct v4l2_ctrl_type_ops - The control type operations that the driver
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -030077 * has to provide.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030078 *
79 * @equal: return true if both values are equal.
80 * @init: initialize the value.
81 * @log: log the value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -030082 * @validate: validate the value. Return 0 on success and a negative value
83 * otherwise.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030084 */
Hans Verkuil01760772014-04-27 03:22:17 -030085struct v4l2_ctrl_type_ops {
Hans Verkuil998e7652014-06-10 07:55:00 -030086 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -030087 union v4l2_ctrl_ptr ptr1,
88 union v4l2_ctrl_ptr ptr2);
Hans Verkuil998e7652014-06-10 07:55:00 -030089 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -030090 union v4l2_ctrl_ptr ptr);
91 void (*log)(const struct v4l2_ctrl *ctrl);
Hans Verkuil998e7652014-06-10 07:55:00 -030092 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
Hans Verkuil01760772014-04-27 03:22:17 -030093 union v4l2_ctrl_ptr ptr);
94};
95
Hans Verkuil8ac7a942012-09-07 04:46:39 -030096typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
97
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -030098/**
99 * struct v4l2_ctrl - The control structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300100 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300101 * @node: The list node.
102 * @ev_subs: The list of control event subscriptions.
103 * @handler: The handler that owns the control.
104 * @cluster: Point to start of cluster array.
105 * @ncontrols: Number of controls in cluster array.
106 * @done: Internal flag: set for each processed control.
107 * @is_new: Set when the user specified a new value for this control. It
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300108 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300109 * should never set this flag.
110 * @has_changed: Set when the current value differs from the new value. Drivers
111 * should never use this flag.
112 * @is_private: If set, then this control is private to its handler and it
113 * will not be added to any other handlers. Drivers can set
114 * this flag.
115 * @is_auto: If set, then this control selects whether the other cluster
116 * members are in 'automatic' mode or 'manual' mode. This is
117 * used for autogain/gain type clusters. Drivers should never
118 * set this flag directly.
119 * @is_int: If set, then this control has a simple integer value (i.e. it
120 * uses ctrl->val).
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300121 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
122 * @is_ptr: If set, then this control is an array and/or has type >=
123 * %V4L2_CTRL_COMPOUND_TYPES
124 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300125 * v4l2_ext_control uses field p to point to the data.
126 * @is_array: If set, then this control contains an N-dimensional array.
127 * @has_volatiles: If set, then one or more members of the cluster are volatile.
128 * Drivers should never touch this flag.
129 * @call_notify: If set, then call the handler's notify function whenever the
130 * control's value changes.
131 * @manual_mode_value: If the is_auto flag is set, then this is the value
132 * of the auto control that determines if that control is in
133 * manual mode. So if the value of the auto control equals this
134 * value, then the whole cluster is in manual mode. Drivers should
135 * never set this flag directly.
136 * @ops: The control ops.
137 * @type_ops: The control type ops.
138 * @id: The control ID.
139 * @name: The control name.
140 * @type: The control type.
141 * @minimum: The control's minimum value.
142 * @maximum: The control's maximum value.
143 * @default_value: The control's default value.
144 * @step: The control's step value for non-menu controls.
145 * @elems: The number of elements in the N-dimensional array.
146 * @elem_size: The size in bytes of the control.
147 * @dims: The size of each dimension.
148 * @nr_of_dims:The number of dimensions in @dims.
149 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
150 * easy to skip menu items that are not valid. If bit X is set,
151 * then menu item X is skipped. Of course, this only works for
152 * menus with <= 32 menu items. There are no menus that come
153 * close to that number, so this is OK. Should we ever need more,
154 * then this will have to be extended to a u64 or a bit array.
155 * @qmenu: A const char * array for all menu items. Array entries that are
156 * empty strings ("") correspond to non-existing menu items (this
157 * is in addition to the menu_skip_mask above). The last entry
158 * must be NULL.
159 * @flags: The control's flags.
160 * @cur: The control's current value.
161 * @val: The control's new s32 value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300162 * @priv: The control's private pointer. For use by the driver. It is
163 * untouched by the control framework. Note that this pointer is
164 * not freed when the control is deleted. Should this be needed
165 * then a new internal bitfield can be added to tell the framework
166 * to free this pointer.
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300167 * @p_cur: The control's current value represented via an union with
168 * provides a standard way of accessing control types
169 * through a pointer.
170 * @p_new: The control's new value represented via an union with provides
171 * a standard way of accessing control types
172 * through a pointer.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300173 */
Hans Verkuil09965172010-08-01 14:32:42 -0300174struct v4l2_ctrl {
175 /* Administrative fields */
176 struct list_head node;
Hans Verkuil77068d32011-06-13 18:55:58 -0300177 struct list_head ev_subs;
Hans Verkuil09965172010-08-01 14:32:42 -0300178 struct v4l2_ctrl_handler *handler;
179 struct v4l2_ctrl **cluster;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300180 unsigned int ncontrols;
181
Hans Verkuil09965172010-08-01 14:32:42 -0300182 unsigned int done:1;
183
Hans Verkuil2a863792011-01-11 14:45:03 -0300184 unsigned int is_new:1;
Hans Verkuil9ea1b7a2014-01-17 08:25:26 -0300185 unsigned int has_changed:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300186 unsigned int is_private:1;
Hans Verkuil72d877c2011-06-10 05:44:36 -0300187 unsigned int is_auto:1;
Hans Verkuild9a25472014-06-12 07:54:16 -0300188 unsigned int is_int:1;
189 unsigned int is_string:1;
190 unsigned int is_ptr:1;
Hans Verkuil998e7652014-06-10 07:55:00 -0300191 unsigned int is_array:1;
Hans Verkuil5626b8c2011-08-26 07:53:53 -0300192 unsigned int has_volatiles:1;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300193 unsigned int call_notify:1;
Hans Verkuil82a7c042011-06-28 10:43:13 -0300194 unsigned int manual_mode_value:8;
Hans Verkuil09965172010-08-01 14:32:42 -0300195
196 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300197 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300198 u32 id;
199 const char *name;
200 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300201 s64 minimum, maximum, default_value;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300202 u32 elems;
Hans Verkuild9a25472014-06-12 07:54:16 -0300203 u32 elem_size;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300204 u32 dims[V4L2_CTRL_MAX_DIMS];
205 u32 nr_of_dims;
Hans Verkuil09965172010-08-01 14:32:42 -0300206 union {
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300207 u64 step;
208 u64 menu_skip_mask;
Hans Verkuil09965172010-08-01 14:32:42 -0300209 };
Sakari Ailusce580fe2011-08-04 13:51:11 -0300210 union {
211 const char * const *qmenu;
212 const s64 *qmenu_int;
213 };
Hans Verkuil09965172010-08-01 14:32:42 -0300214 unsigned long flags;
Hans Verkuil09965172010-08-01 14:32:42 -0300215 void *priv;
Hans Verkuil2a9ec372014-04-27 03:38:13 -0300216 s32 val;
217 struct {
Hans Verkuild9a25472014-06-12 07:54:16 -0300218 s32 val;
Hans Verkuild9a25472014-06-12 07:54:16 -0300219 } cur;
Hans Verkuil01760772014-04-27 03:22:17 -0300220
221 union v4l2_ctrl_ptr p_new;
222 union v4l2_ctrl_ptr p_cur;
Hans Verkuil09965172010-08-01 14:32:42 -0300223};
224
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300225/**
226 * struct v4l2_ctrl_ref - The control reference.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300227 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300228 * @node: List node for the sorted list.
229 * @next: Single-link list node for the hash.
230 * @ctrl: The actual control information.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300231 * @helper: Pointer to helper struct. Used internally in
232 * prepare_ext_ctrls().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300233 *
234 * Each control handler has a list of these refs. The list_head is used to
235 * keep a sorted-by-control-ID list of all controls, while the next pointer
236 * is used to link the control in the hash's bucket.
237 */
Hans Verkuil09965172010-08-01 14:32:42 -0300238struct v4l2_ctrl_ref {
239 struct list_head node;
240 struct v4l2_ctrl_ref *next;
241 struct v4l2_ctrl *ctrl;
Hans Verkuileb5b16e2011-06-14 10:04:06 -0300242 struct v4l2_ctrl_helper *helper;
Hans Verkuil09965172010-08-01 14:32:42 -0300243};
244
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300245/**
246 * struct v4l2_ctrl_handler - The control handler keeps track of all the
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300247 * controls: both the controls owned by the handler and those inherited
248 * from other handlers.
249 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300250 * @_lock: Default for "lock".
251 * @lock: Lock to control access to this handler and its controls.
252 * May be replaced by the user right after init.
253 * @ctrls: The list of controls owned by this handler.
254 * @ctrl_refs: The list of control references.
255 * @cached: The last found control reference. It is common that the same
256 * control is needed multiple times, so this is a simple
257 * optimization.
258 * @buckets: Buckets for the hashing. Allows for quick control lookup.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300259 * @notify: A notify callback that is called whenever the control changes
260 * value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300261 * Note that the handler's lock is held when the notify function
262 * is called!
263 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
264 * @nr_of_buckets: Total number of buckets in the array.
265 * @error: The error code of the first failed control addition.
266 */
Hans Verkuil09965172010-08-01 14:32:42 -0300267struct v4l2_ctrl_handler {
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300268 struct mutex _lock;
269 struct mutex *lock;
Hans Verkuil09965172010-08-01 14:32:42 -0300270 struct list_head ctrls;
271 struct list_head ctrl_refs;
272 struct v4l2_ctrl_ref *cached;
273 struct v4l2_ctrl_ref **buckets;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300274 v4l2_ctrl_notify_fnc notify;
275 void *notify_priv;
Hans Verkuil09965172010-08-01 14:32:42 -0300276 u16 nr_of_buckets;
277 int error;
278};
279
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300280/**
281 * struct v4l2_ctrl_config - Control configuration structure.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300282 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300283 * @ops: The control ops.
284 * @type_ops: The control type ops. Only needed for compound controls.
285 * @id: The control ID.
286 * @name: The control name.
287 * @type: The control type.
288 * @min: The control's minimum value.
289 * @max: The control's maximum value.
290 * @step: The control's step value for non-menu controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300291 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300292 * @dims: The size of each dimension.
293 * @elem_size: The size in bytes of the control.
294 * @flags: The control's flags.
295 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
296 * easy to skip menu items that are not valid. If bit X is set,
297 * then menu item X is skipped. Of course, this only works for
298 * menus with <= 64 menu items. There are no menus that come
299 * close to that number, so this is OK. Should we ever need more,
300 * then this will have to be extended to a bit array.
301 * @qmenu: A const char * array for all menu items. Array entries that are
302 * empty strings ("") correspond to non-existing menu items (this
303 * is in addition to the menu_skip_mask above). The last entry
304 * must be NULL.
Mauro Carvalho Chehab7dc87912015-08-22 08:22:03 -0300305 * @qmenu_int: A const s64 integer array for all menu items of the type
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300306 * V4L2_CTRL_TYPE_INTEGER_MENU.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300307 * @is_private: If set, then this control is private to its handler and it
308 * will not be added to any other handlers.
309 */
Hans Verkuil09965172010-08-01 14:32:42 -0300310struct v4l2_ctrl_config {
311 const struct v4l2_ctrl_ops *ops;
Hans Verkuil01760772014-04-27 03:22:17 -0300312 const struct v4l2_ctrl_type_ops *type_ops;
Hans Verkuil09965172010-08-01 14:32:42 -0300313 u32 id;
314 const char *name;
315 enum v4l2_ctrl_type type;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300316 s64 min;
317 s64 max;
318 u64 step;
319 s64 def;
Hans Verkuil20d88ee2014-06-12 07:55:21 -0300320 u32 dims[V4L2_CTRL_MAX_DIMS];
Hans Verkuild9a25472014-06-12 07:54:16 -0300321 u32 elem_size;
Hans Verkuil09965172010-08-01 14:32:42 -0300322 u32 flags;
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300323 u64 menu_skip_mask;
Hans Verkuil513521e2010-12-29 14:25:52 -0300324 const char * const *qmenu;
Sakari Ailusce580fe2011-08-04 13:51:11 -0300325 const s64 *qmenu_int;
Hans Verkuil09965172010-08-01 14:32:42 -0300326 unsigned int is_private:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300327};
328
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300329/**
330 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
331 *
332 * @id: ID of the control
333 * @name: name of the control
334 * @type: type of the control
335 * @min: minimum value for the control
336 * @max: maximum value for the control
337 * @step: control step
338 * @def: default value for the control
339 * @flags: flags to be used on the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300340 *
341 * This works for all standard V4L2 controls.
342 * For non-standard controls it will only fill in the given arguments
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300343 * and @name will be %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300344 *
345 * This function will overwrite the contents of @name, @type and @flags.
346 * The contents of @min, @max, @step and @def may be modified depending on
347 * the type.
348 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300349 * .. note::
350 *
351 * Do not use in drivers! It is used internally for backwards compatibility
352 * control handling only. Once all drivers are converted to use the new
353 * control framework this function will no longer be exported.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300354 */
Hans Verkuil09965172010-08-01 14:32:42 -0300355void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
Hans Verkuil0ba2aeb2014-04-16 09:41:25 -0300356 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
Hans Verkuil09965172010-08-01 14:32:42 -0300357
358
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300359/**
360 * v4l2_ctrl_handler_init_class() - Initialize the control handler.
361 * @hdl: The control handler.
362 * @nr_of_controls_hint: A hint of how many controls this handler is
363 * expected to refer to. This is the total number, so including
364 * any inherited controls. It doesn't have to be precise, but if
365 * it is way off, then you either waste memory (too many buckets
366 * are allocated) or the control lookup becomes slower (not enough
367 * buckets are allocated, so there are more slow list lookups).
368 * It will always work, though.
369 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
370 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
371 *
372 * Returns an error if the buckets could not be allocated. This error will
373 * also be stored in @hdl->error.
374 *
375 * Never use this call directly, always use the v4l2_ctrl_handler_init
376 * macro that hides the @key and @name arguments.
377 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300378int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300379 unsigned int nr_of_controls_hint,
Andy Walls6cd247e2013-03-09 05:55:11 -0300380 struct lock_class_key *key, const char *name);
381
382#ifdef CONFIG_LOCKDEP
383#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
384( \
385 ({ \
386 static struct lock_class_key _key; \
387 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
388 &_key, \
389 KBUILD_BASENAME ":" \
390 __stringify(__LINE__) ":" \
391 "(" #hdl ")->_lock"); \
392 }) \
393)
394#else
395#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
396 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
397#endif
Hans Verkuil09965172010-08-01 14:32:42 -0300398
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300399/**
400 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
401 * the control list.
402 * @hdl: The control handler.
403 *
404 * Does nothing if @hdl == NULL.
405 */
Hans Verkuil09965172010-08-01 14:32:42 -0300406void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
407
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300408/**
409 * v4l2_ctrl_lock() - Helper function to lock the handler
410 * associated with the control.
411 * @ctrl: The control to lock.
412 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300413static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
414{
415 mutex_lock(ctrl->handler->lock);
416}
417
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300418/**
419 * v4l2_ctrl_unlock() - Helper function to unlock the handler
420 * associated with the control.
421 * @ctrl: The control to unlock.
422 */
Sakari Ailus605b3842014-06-12 13:09:39 -0300423static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
424{
425 mutex_unlock(ctrl->handler->lock);
426}
427
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300428/**
429 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
430 * to the handler to initialize the hardware to the current control values.
431 * @hdl: The control handler.
432 *
433 * Button controls will be skipped, as are read-only controls.
434 *
435 * If @hdl == NULL, then this just returns 0.
436 */
Hans Verkuil09965172010-08-01 14:32:42 -0300437int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
438
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300439/**
440 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
441 * @hdl: The control handler.
442 * @prefix: The prefix to use when logging the control values. If the
443 * prefix does not end with a space, then ": " will be added
444 * after the prefix. If @prefix == NULL, then no prefix will be
445 * used.
446 *
447 * For use with VIDIOC_LOG_STATUS.
448 *
449 * Does nothing if @hdl == NULL.
450 */
Hans Verkuil09965172010-08-01 14:32:42 -0300451void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
452 const char *prefix);
453
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300454/**
455 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300456 * control.
457 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300458 * @hdl: The control handler.
459 * @cfg: The control's configuration data.
460 * @priv: The control's driver-specific private data.
461 *
462 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
463 * and @hdl->error is set to the error code (if it wasn't set already).
464 */
Hans Verkuil09965172010-08-01 14:32:42 -0300465struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300466 const struct v4l2_ctrl_config *cfg,
467 void *priv);
Hans Verkuil09965172010-08-01 14:32:42 -0300468
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300469/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300470 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
471 * control.
472 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300473 * @hdl: The control handler.
474 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300475 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300476 * @min: The control's minimum value.
477 * @max: The control's maximum value.
478 * @step: The control's step value
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300479 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300480 *
481 * If the &v4l2_ctrl struct could not be allocated, or the control
482 * ID is not known, then NULL is returned and @hdl->error is set to the
483 * appropriate error code (if it wasn't set already).
484 *
485 * If @id refers to a menu control, then this function will return NULL.
486 *
487 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
488 */
Hans Verkuil09965172010-08-01 14:32:42 -0300489struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300490 const struct v4l2_ctrl_ops *ops,
491 u32 id, s64 min, s64 max, u64 step,
492 s64 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300493
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300494/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300495 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
496 * menu control.
497 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300498 * @hdl: The control handler.
499 * @ops: The control ops.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300500 * @id: The control ID.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300501 * @max: The control's maximum value.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300502 * @mask: The control's skip mask for menu controls. This makes it
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300503 * easy to skip menu items that are not valid. If bit X is set,
504 * then menu item X is skipped. Of course, this only works for
505 * menus with <= 64 menu items. There are no menus that come
506 * close to that number, so this is OK. Should we ever need more,
507 * then this will have to be extended to a bit array.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300508 * @def: The control's default value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300509 *
510 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
511 * determines which menu items are to be skipped.
512 *
513 * If @id refers to a non-menu control, then this function will return NULL.
514 */
Hans Verkuil09965172010-08-01 14:32:42 -0300515struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300516 const struct v4l2_ctrl_ops *ops,
517 u32 id, u8 max, u64 mask, u8 def);
Hans Verkuil09965172010-08-01 14:32:42 -0300518
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300519/**
520 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300521 * with driver specific menu.
522 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300523 * @hdl: The control handler.
524 * @ops: The control ops.
525 * @id: The control ID.
526 * @max: The control's maximum value.
527 * @mask: The control's skip mask for menu controls. This makes it
528 * easy to skip menu items that are not valid. If bit X is set,
529 * then menu item X is skipped. Of course, this only works for
530 * menus with <= 64 menu items. There are no menus that come
531 * close to that number, so this is OK. Should we ever need more,
532 * then this will have to be extended to a bit array.
533 * @def: The control's default value.
534 * @qmenu: The new menu.
535 *
536 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
537 * menu of this control.
538 *
539 */
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300540struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300541 const struct v4l2_ctrl_ops *ops,
542 u32 id, u8 max,
543 u64 mask, u8 def,
544 const char * const *qmenu);
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300545
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300546/**
547 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300548 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300549 * @hdl: The control handler.
550 * @ops: The control ops.
551 * @id: The control ID.
552 * @max: The control's maximum value.
553 * @def: The control's default value.
554 * @qmenu_int: The control's menu entries.
555 *
556 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
557 * takes as an argument an array of integers determining the menu items.
558 *
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300559 * If @id refers to a non-integer-menu control, then this function will
560 * return %NULL.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300561 */
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300562struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300563 const struct v4l2_ctrl_ops *ops,
564 u32 id, u8 max, u8 def,
565 const s64 *qmenu_int);
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300566
Mauro Carvalho Chehab6d85d7d2016-07-22 10:58:03 -0300567typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
568
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300569/**
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300570 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300571 * handler @hdl.
572 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300573 * @hdl: The control handler.
574 * @add: The control handler whose controls you want to add to
575 * the @hdl control handler.
576 * @filter: This function will filter which controls should be added.
577 *
578 * Does nothing if either of the two handlers is a NULL pointer.
579 * If @filter is NULL, then all controls are added. Otherwise only those
580 * controls for which @filter returns true will be added.
581 * In case of an error @hdl->error will be set to the error code (if it
582 * wasn't set already).
583 */
Hans Verkuil09965172010-08-01 14:32:42 -0300584int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300585 struct v4l2_ctrl_handler *add,
Mauro Carvalho Chehab6d85d7d2016-07-22 10:58:03 -0300586 v4l2_ctrl_filter filter);
Hans Verkuil09965172010-08-01 14:32:42 -0300587
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300588/**
589 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300590 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300591 * @ctrl: The control that is filtered.
592 *
593 * This will return true for any controls that are valid for radio device
594 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
595 * transmitter class controls.
596 *
597 * This function is to be used with v4l2_ctrl_add_handler().
598 */
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300599bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
Hans Verkuil09965172010-08-01 14:32:42 -0300600
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300601/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300602 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
603 * to that cluster.
604 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300605 * @ncontrols: The number of controls in this cluster.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300606 * @controls: The cluster control array of size @ncontrols.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300607 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300608void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
Hans Verkuil09965172010-08-01 14:32:42 -0300609
610
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300611/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300612 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
613 * to that cluster and set it up for autofoo/foo-type handling.
614 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300615 * @ncontrols: The number of controls in this cluster.
616 * @controls: The cluster control array of size @ncontrols. The first control
617 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
618 * @manual_val: The value for the first control in the cluster that equals the
619 * manual setting.
620 * @set_volatile: If true, then all controls except the first auto control will
621 * be volatile.
622 *
623 * Use for control groups where one control selects some automatic feature and
624 * the other controls are only active whenever the automatic feature is turned
625 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
626 * red and blue balance, etc.
627 *
628 * The behavior of such controls is as follows:
629 *
630 * When the autofoo control is set to automatic, then any manual controls
631 * are set to inactive and any reads will call g_volatile_ctrl (if the control
632 * was marked volatile).
633 *
634 * When the autofoo control is set to manual, then any manual controls will
635 * be marked active, and any reads will just return the current value without
636 * going through g_volatile_ctrl.
637 *
638 * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag
639 * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
640 * if autofoo is in auto mode.
641 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300642void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
643 struct v4l2_ctrl **controls,
644 u8 manual_val, bool set_volatile);
Hans Verkuil72d877c2011-06-10 05:44:36 -0300645
646
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300647/**
648 * v4l2_ctrl_find() - Find a control with the given ID.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300649 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300650 * @hdl: The control handler.
651 * @id: The control ID to find.
652 *
653 * If @hdl == NULL this will return NULL as well. Will lock the handler so
654 * do not use from inside &v4l2_ctrl_ops.
655 */
Hans Verkuil09965172010-08-01 14:32:42 -0300656struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
657
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300658/**
659 * v4l2_ctrl_activate() - Make the control active or inactive.
660 * @ctrl: The control to (de)activate.
661 * @active: True if the control should become active.
662 *
663 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
664 * Does nothing if @ctrl == NULL.
665 * This will usually be called from within the s_ctrl op.
666 * The V4L2_EVENT_CTRL event will be generated afterwards.
667 *
668 * This function assumes that the control handler is locked.
669 */
Hans Verkuil09965172010-08-01 14:32:42 -0300670void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
671
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300672/**
673 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300674 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300675 * @ctrl: The control to (de)activate.
676 * @grabbed: True if the control should become grabbed.
677 *
678 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
679 * Does nothing if @ctrl == NULL.
680 * The V4L2_EVENT_CTRL event will be generated afterwards.
681 * This will usually be called when starting or stopping streaming in the
682 * driver.
683 *
684 * This function assumes that the control handler is not locked and will
685 * take the lock itself.
686 */
Hans Verkuil09965172010-08-01 14:32:42 -0300687void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
688
Sakari Ailus5a573922014-06-12 13:09:40 -0300689
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300690/**
691 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
692 *
693 * @ctrl: The control to update.
694 * @min: The control's minimum value.
695 * @max: The control's maximum value.
696 * @step: The control's step value
697 * @def: The control's default value.
698 *
699 * Update the range of a control on the fly. This works for control types
700 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
701 * @step value is interpreted as a menu_skip_mask.
702 *
703 * An error is returned if one of the range arguments is invalid for this
704 * control type.
705 *
706 * This function assumes that the control handler is not locked and will
707 * take the lock itself.
708 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300709int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
710 s64 min, s64 max, u64 step, s64 def);
711
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300712/**
713 * v4l2_ctrl_modify_range() - Update the range of a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300714 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300715 * @ctrl: The control to update.
716 * @min: The control's minimum value.
717 * @max: The control's maximum value.
718 * @step: The control's step value
719 * @def: The control's default value.
720 *
721 * Update the range of a control on the fly. This works for control types
722 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
723 * @step value is interpreted as a menu_skip_mask.
724 *
725 * An error is returned if one of the range arguments is invalid for this
726 * control type.
727 *
728 * This function assumes that the control handler is not locked and will
729 * take the lock itself.
730 */
Sakari Ailus5a573922014-06-12 13:09:40 -0300731static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
732 s64 min, s64 max, u64 step, s64 def)
733{
734 int rval;
735
736 v4l2_ctrl_lock(ctrl);
737 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
738 v4l2_ctrl_unlock(ctrl);
739
740 return rval;
741}
Sylwester Nawrocki2ccbe772013-01-19 15:51:55 -0300742
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300743/**
744 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300745 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300746 * @ctrl: The control.
747 * @notify: The callback function.
748 * @priv: The callback private handle, passed as argument to the callback.
749 *
750 * This function sets a callback function for the control. If @ctrl is NULL,
751 * then it will do nothing. If @notify is NULL, then the notify callback will
752 * be removed.
753 *
754 * There can be only one notify. If another already exists, then a WARN_ON
755 * will be issued and the function will do nothing.
756 */
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300757void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
758 void *priv);
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300759
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300760/**
761 * v4l2_ctrl_get_name() - Get the name of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300762 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300763 * @id: The control ID.
764 *
765 * This function returns the name of the given control ID or NULL if it isn't
766 * a known control.
767 */
768const char *v4l2_ctrl_get_name(u32 id);
769
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300770/**
771 * v4l2_ctrl_get_menu() - Get the menu string array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300772 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300773 * @id: The control ID.
774 *
775 * This function returns the NULL-terminated menu string array name of the
776 * given control ID or NULL if it isn't a known menu control.
777 */
778const char * const *v4l2_ctrl_get_menu(u32 id);
779
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300780/**
781 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300782 *
Hans Verkuil79fbc202014-11-23 09:39:54 -0300783 * @id: The control ID.
784 * @len: The size of the integer array.
785 *
786 * This function returns the integer array of the given control ID or NULL if it
787 * if it isn't a known integer menu control.
788 */
789const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
790
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300791/**
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300792 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
793 * within a driver.
794 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300795 * @ctrl: The control.
796 *
797 * This returns the control's value safely by going through the control
798 * framework. This function will lock the control's handler, so it cannot be
799 * used from within the &v4l2_ctrl_ops functions.
800 *
801 * This function is for integer type controls only.
802 */
Hans Verkuil09965172010-08-01 14:32:42 -0300803s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
804
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300805/**
806 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300807 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300808 * @ctrl: The control.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300809 * @val: TheControls name new value.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300810 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300811 * This sets the control's new value safely by going through the control
812 * framework. This function assumes the control's handler is already locked,
813 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300814 *
815 * This function is for integer type controls only.
816 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300817int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300818
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300819/**
820 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
821 * within a driver.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300822 * @ctrl: The control.
823 * @val: The new value.
824 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300825 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300826 * framework. This function will lock the control's handler, so it cannot be
827 * used from within the &v4l2_ctrl_ops functions.
828 *
829 * This function is for integer type controls only.
830 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300831static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
832{
833 int rval;
834
835 v4l2_ctrl_lock(ctrl);
836 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
837 v4l2_ctrl_unlock(ctrl);
838
839 return rval;
840}
Hans Verkuil09965172010-08-01 14:32:42 -0300841
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300842/**
843 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
844 * from within a driver.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300845 *
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300846 * @ctrl: The control.
847 *
848 * This returns the control's value safely by going through the control
849 * framework. This function will lock the control's handler, so it cannot be
850 * used from within the &v4l2_ctrl_ops functions.
851 *
852 * This function is for 64-bit integer type controls only.
853 */
Laurent Pinchart03d52852012-07-23 09:15:21 -0300854s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
855
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300856/**
857 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
858 *
859 * @ctrl: The control.
860 * @val: The new value.
861 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300862 * This sets the control's new value safely by going through the control
863 * framework. This function assumes the control's handler is already locked,
864 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300865 *
866 * This function is for 64-bit integer type controls only.
867 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300868int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
869
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300870/**
871 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300872 * from within a driver.
873 *
874 * @ctrl: The control.
875 * @val: The new value.
876 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300877 * This sets the control's new value safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300878 * framework. This function will lock the control's handler, so it cannot be
879 * used from within the &v4l2_ctrl_ops functions.
880 *
881 * This function is for 64-bit integer type controls only.
882 */
Sakari Ailus0c4348a2014-06-12 13:09:42 -0300883static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
884{
885 int rval;
886
887 v4l2_ctrl_lock(ctrl);
888 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
889 v4l2_ctrl_unlock(ctrl);
890
891 return rval;
892}
Laurent Pinchart03d52852012-07-23 09:15:21 -0300893
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300894/**
895 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300896 *
897 * @ctrl: The control.
898 * @s: The new string.
899 *
Hans Verkuil904aef02016-06-15 09:57:48 -0300900 * This sets the control's new string safely by going through the control
901 * framework. This function assumes the control's handler is already locked,
902 * allowing it to be used from within the &v4l2_ctrl_ops functions.
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300903 *
904 * This function is for string type controls only.
905 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -0300906int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
907
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300908/**
909 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300910 * from within a driver.
911 *
912 * @ctrl: The control.
913 * @s: The new string.
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300914 *Controls name
Hans Verkuil904aef02016-06-15 09:57:48 -0300915 * This sets the control's new string safely by going through the control
Mauro Carvalho Chehab8c2721d2015-08-22 08:03:49 -0300916 * framework. This function will lock the control's handler, so it cannot be
917 * used from within the &v4l2_ctrl_ops functions.
918 *
919 * This function is for string type controls only.
920 */
Hans Verkuil5d0360a2014-07-21 10:45:42 -0300921static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
922{
923 int rval;
924
925 v4l2_ctrl_lock(ctrl);
926 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
927 v4l2_ctrl_unlock(ctrl);
928
929 return rval;
930}
931
Hans Verkuilce727572011-06-10 05:56:39 -0300932/* Internal helper functions that deal with control events. */
Hans de Goede3e3661492012-04-08 12:59:47 -0300933extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300934
935/**
936 * v4l2_ctrl_replace - Function to be used as a callback to
937 * &struct v4l2_subscribed_event_ops replace\(\)
938 *
939 * @old: pointer to :ref:`struct v4l2_event <v4l2-event>` with the reported
940 * event;
941 * @new: pointer to :ref:`struct v4l2_event <v4l2-event>` with the modified
942 * event;
943 */
Hans de Goede3e3661492012-04-08 12:59:47 -0300944void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300945
946/**
947 * v4l2_ctrl_merge - Function to be used as a callback to
948 * &struct v4l2_subscribed_event_ops merge(\)
949 *
950 * @old: pointer to :ref:`struct v4l2_event <v4l2-event>` with the reported
951 * event;
952 * @new: pointer to :ref:`struct v4l2_event <v4l2-event>` with the merged
953 * event;
954 */
Hans de Goede3e3661492012-04-08 12:59:47 -0300955void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
Hans Verkuil6e239392011-06-07 11:13:44 -0300956
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300957/**
958 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
959 *
960 * @file: pointer to struct file
961 * @fh: unused. Kept just to be compatible to the arguments expected by
962 * &struct v4l2_ioctl_ops.vidioc_log_status.
963 *
964 * Can be used as a vidioc_log_status function that just dumps all controls
965 * associated with the filehandle.
966 */
Hans Verkuile2ecb252012-02-02 08:20:53 -0300967int v4l2_ctrl_log_status(struct file *file, void *fh);
968
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300969/**
970 * v4l2_ctrl_subscribe_event - Subscribes to an event
971 *
972 *
973 * @fh: pointer to struct v4l2_fh
974 * @sub: pointer to &struct v4l2_event_subscription
975 *
976 * Can be used as a vidioc_subscribe_event function that just subscribes
977 * control events.
978 */
Hans Verkuila26243b2012-01-27 16:18:42 -0300979int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
Hans Verkuil85f5fe32012-09-04 11:46:09 -0300980 const struct v4l2_event_subscription *sub);
Hans Verkuila26243b2012-01-27 16:18:42 -0300981
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300982/**
983 * v4l2_ctrl_poll - function to be used as a callback to the poll()
984 * That just polls for control events.
985 *
986 * @file: pointer to struct file
987 * @wait: pointer to struct poll_table_struct
988 */
Hans Verkuila26243b2012-01-27 16:18:42 -0300989unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
990
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300991/* Helpers for ioctl_ops */
Hans Verkuil09965172010-08-01 14:32:42 -0300992
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -0300993/**
994 * v4l2_queryctrl - Helper function to implement
995 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
996 *
997 * @hdl: pointer to &struct v4l2_ctrl_handler
998 * @qc: pointer to &struct v4l2_queryctrl
999 *
1000 * If hdl == NULL then they will all return -EINVAL.
1001 */
1002int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1003
1004/**
1005 * v4l2_query_ext_ctrl - Helper function to implement
1006 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1007 *
1008 * @hdl: pointer to &struct v4l2_ctrl_handler
1009 * @qc: pointer to &struct v4l2_query_ext_ctrl
1010 *
1011 * If hdl == NULL then they will all return -EINVAL.
1012 */
1013int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1014 struct v4l2_query_ext_ctrl *qc);
1015
1016/**
1017 * v4l2_querymenu - Helper function to implement
1018 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1019 *
1020 * @hdl: pointer to &struct v4l2_ctrl_handler
1021 * @qm: pointer to &struct v4l2_querymenu
1022 *
1023 * If hdl == NULL then they will all return -EINVAL.
1024 */
1025int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1026
1027/**
1028 * v4l2_g_ctrl - Helper function to implement
1029 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1030 *
1031 * @hdl: pointer to &struct v4l2_ctrl_handler
1032 * @ctrl: pointer to &struct v4l2_control
1033 *
1034 * If hdl == NULL then they will all return -EINVAL.
1035 */
1036int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1037
1038/**
1039 * v4l2_s_ctrl - Helper function to implement
1040 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1041 *
1042 * @fh: pointer to &struct v4l2_fh
1043 * @hdl: pointer to &struct v4l2_ctrl_handler
1044 *
1045 * @ctrl: pointer to &struct v4l2_control
1046 *
1047 * If hdl == NULL then they will all return -EINVAL.
1048 */
1049int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1050 struct v4l2_control *ctrl);
1051
1052/**
1053 * v4l2_g_ext_ctrls - Helper function to implement
1054 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1055 *
1056 * @hdl: pointer to &struct v4l2_ctrl_handler
1057 * @c: pointer to &struct v4l2_ext_controls
1058 *
1059 * If hdl == NULL then they will all return -EINVAL.
1060 */
1061int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1062 struct v4l2_ext_controls *c);
1063
1064/**
1065 * v4l2_try_ext_ctrls - Helper function to implement
1066 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1067 *
1068 * @hdl: pointer to &struct v4l2_ctrl_handler
1069 * @c: pointer to &struct v4l2_ext_controls
1070 *
1071 * If hdl == NULL then they will all return -EINVAL.
1072 */
1073int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1074 struct v4l2_ext_controls *c);
1075
1076/**
1077 * v4l2_s_ext_ctrls - Helper function to implement
1078 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1079 *
1080 * @fh: pointer to &struct v4l2_fh
1081 * @hdl: pointer to &struct v4l2_ctrl_handler
1082 * @c: pointer to &struct v4l2_ext_controls
1083 *
1084 * If hdl == NULL then they will all return -EINVAL.
1085 */
1086int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1087 struct v4l2_ext_controls *c);
1088
1089/**
1090 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
1091 * as a &struct v4l2_subdev_core_ops subscribe_event function
1092 * that just subscribes control events.
1093 *
1094 * @sd: pointer to &struct v4l2_subdev
1095 * @fh: pointer to &struct v4l2_fh
1096 * @sub: pointer to &struct v4l2_event_subscription
1097 */
Sylwester Nawrocki22fa4272013-01-22 19:00:23 -03001098int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1099 struct v4l2_event_subscription *sub);
1100
Mauro Carvalho Chehab8ec4bee2016-07-22 13:57:29 -03001101/**
1102 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1103 * handler.
1104 *
1105 * @sd: pointer to &struct v4l2_subdev
1106 */
Sylwester Nawrockiffa9b9f2013-01-22 19:01:02 -03001107int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1108
Hans Verkuil09965172010-08-01 14:32:42 -03001109#endif