]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/media/v4l2-ctrls.h
[media] v4l2: integrate support for VIDIOC_QUERY_EXT_CTRL
[mirror_ubuntu-bionic-kernel.git] / include / media / v4l2-ctrls.h
CommitLineData
0996517c
HV
1/*
2 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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _V4L2_CTRLS_H
22#define _V4L2_CTRLS_H
23
24#include <linux/list.h>
a19dec6e 25#include <linux/mutex.h>
01c40c04 26#include <linux/videodev2.h>
0996517c
HV
27
28/* forward references */
528f0f78 29struct file;
0996517c 30struct v4l2_ctrl_handler;
eb5b16ef 31struct v4l2_ctrl_helper;
0996517c
HV
32struct v4l2_ctrl;
33struct video_device;
34struct v4l2_subdev;
77068d36 35struct v4l2_subscribed_event;
6e239399 36struct v4l2_fh;
a26243b0 37struct poll_table_struct;
0996517c
HV
38
39/** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
40 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
41 * for volatile (and usually read-only) controls such as a control
42 * that returns the current signal strength which changes
43 * continuously.
44 * If not set, then the currently cached value will be returned.
45 * @try_ctrl: Test whether the control's value is valid. Only relevant when
46 * the usual min/max/step checks are not sufficient.
47 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
48 * ctrl->handler->lock is held when these ops are called, so no
49 * one else can access controls owned by that handler.
50 */
51struct v4l2_ctrl_ops {
52 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
53 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
54 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
55};
56
8ac7a949
HV
57typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
58
0996517c
HV
59/** struct v4l2_ctrl - The control structure.
60 * @node: The list node.
77068d36 61 * @ev_subs: The list of control event subscriptions.
0996517c
HV
62 * @handler: The handler that owns the control.
63 * @cluster: Point to start of cluster array.
64 * @ncontrols: Number of controls in cluster array.
0996517c 65 * @done: Internal flag: set for each processed control.
2a863793
HV
66 * @is_new: Set when the user specified a new value for this control. It
67 * is also set when called from v4l2_ctrl_handler_setup. Drivers
68 * should never set this flag.
0996517c
HV
69 * @is_private: If set, then this control is private to its handler and it
70 * will not be added to any other handlers. Drivers can set
71 * this flag.
72d877ca
HV
72 * @is_auto: If set, then this control selects whether the other cluster
73 * members are in 'automatic' mode or 'manual' mode. This is
74 * used for autogain/gain type clusters. Drivers should never
75 * set this flag directly.
d9a25471
HV
76 * @is_int: If set, then this control has a simple integer value (i.e. it
77 * uses ctrl->val).
78 * @is_string: If set, then this control has type V4L2_CTRL_TYPE_STRING.
79 * @is_ptr: If set, then this control is an array and/or has type >= V4L2_CTRL_COMPOUND_TYPES
80 * and/or has type V4L2_CTRL_TYPE_STRING. In other words, struct
81 * v4l2_ext_control uses field p to point to the data.
5626b8c7
HV
82 * @has_volatiles: If set, then one or more members of the cluster are volatile.
83 * Drivers should never touch this flag.
8ac7a949
HV
84 * @call_notify: If set, then call the handler's notify function whenever the
85 * control's value changes.
72d877ca
HV
86 * @manual_mode_value: If the is_auto flag is set, then this is the value
87 * of the auto control that determines if that control is in
88 * manual mode. So if the value of the auto control equals this
89 * value, then the whole cluster is in manual mode. Drivers should
90 * never set this flag directly.
0996517c
HV
91 * @ops: The control ops.
92 * @id: The control ID.
93 * @name: The control name.
94 * @type: The control type.
95 * @minimum: The control's minimum value.
96 * @maximum: The control's maximum value.
97 * @default_value: The control's default value.
98 * @step: The control's step value for non-menu controls.
d9a25471 99 * @elem_size: The size in bytes of the control.
0996517c
HV
100 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
101 * easy to skip menu items that are not valid. If bit X is set,
102 * then menu item X is skipped. Of course, this only works for
103 * menus with <= 32 menu items. There are no menus that come
104 * close to that number, so this is OK. Should we ever need more,
105 * then this will have to be extended to a u64 or a bit array.
106 * @qmenu: A const char * array for all menu items. Array entries that are
107 * empty strings ("") correspond to non-existing menu items (this
108 * is in addition to the menu_skip_mask above). The last entry
109 * must be NULL.
110 * @flags: The control's flags.
111 * @cur: The control's current value.
112 * @val: The control's new s32 value.
113 * @val64: The control's new s64 value.
0996517c
HV
114 * @priv: The control's private pointer. For use by the driver. It is
115 * untouched by the control framework. Note that this pointer is
116 * not freed when the control is deleted. Should this be needed
117 * then a new internal bitfield can be added to tell the framework
118 * to free this pointer.
119 */
120struct v4l2_ctrl {
121 /* Administrative fields */
122 struct list_head node;
77068d36 123 struct list_head ev_subs;
0996517c
HV
124 struct v4l2_ctrl_handler *handler;
125 struct v4l2_ctrl **cluster;
126 unsigned ncontrols;
0996517c
HV
127 unsigned int done:1;
128
2a863793 129 unsigned int is_new:1;
0996517c 130 unsigned int is_private:1;
72d877ca 131 unsigned int is_auto:1;
d9a25471
HV
132 unsigned int is_int:1;
133 unsigned int is_string:1;
134 unsigned int is_ptr:1;
5626b8c7 135 unsigned int has_volatiles:1;
8ac7a949 136 unsigned int call_notify:1;
82a7c049 137 unsigned int manual_mode_value:8;
0996517c
HV
138
139 const struct v4l2_ctrl_ops *ops;
140 u32 id;
141 const char *name;
142 enum v4l2_ctrl_type type;
0ba2aeb6 143 s64 minimum, maximum, default_value;
d9a25471 144 u32 elem_size;
0996517c 145 union {
0ba2aeb6
HV
146 u64 step;
147 u64 menu_skip_mask;
0996517c 148 };
ce580fe5
SA
149 union {
150 const char * const *qmenu;
151 const s64 *qmenu_int;
152 };
0996517c 153 unsigned long flags;
d9a25471 154 void *priv;
0996517c
HV
155 union {
156 s32 val;
157 s64 val64;
158 char *string;
d9a25471
HV
159 void *p;
160 };
0996517c
HV
161 union {
162 s32 val;
163 s64 val64;
164 char *string;
d9a25471
HV
165 void *p;
166 } cur;
0996517c
HV
167};
168
169/** struct v4l2_ctrl_ref - The control reference.
170 * @node: List node for the sorted list.
171 * @next: Single-link list node for the hash.
172 * @ctrl: The actual control information.
eb5b16ef 173 * @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls().
0996517c
HV
174 *
175 * Each control handler has a list of these refs. The list_head is used to
176 * keep a sorted-by-control-ID list of all controls, while the next pointer
177 * is used to link the control in the hash's bucket.
178 */
179struct v4l2_ctrl_ref {
180 struct list_head node;
181 struct v4l2_ctrl_ref *next;
182 struct v4l2_ctrl *ctrl;
eb5b16ef 183 struct v4l2_ctrl_helper *helper;
0996517c
HV
184};
185
186/** struct v4l2_ctrl_handler - The control handler keeps track of all the
187 * controls: both the controls owned by the handler and those inherited
188 * from other handlers.
77e7c4e6 189 * @_lock: Default for "lock".
0996517c 190 * @lock: Lock to control access to this handler and its controls.
77e7c4e6 191 * May be replaced by the user right after init.
0996517c
HV
192 * @ctrls: The list of controls owned by this handler.
193 * @ctrl_refs: The list of control references.
194 * @cached: The last found control reference. It is common that the same
195 * control is needed multiple times, so this is a simple
196 * optimization.
197 * @buckets: Buckets for the hashing. Allows for quick control lookup.
8ac7a949
HV
198 * @notify: A notify callback that is called whenever the control changes value.
199 * Note that the handler's lock is held when the notify function
200 * is called!
201 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
0996517c
HV
202 * @nr_of_buckets: Total number of buckets in the array.
203 * @error: The error code of the first failed control addition.
204 */
205struct v4l2_ctrl_handler {
77e7c4e6
SA
206 struct mutex _lock;
207 struct mutex *lock;
0996517c
HV
208 struct list_head ctrls;
209 struct list_head ctrl_refs;
210 struct v4l2_ctrl_ref *cached;
211 struct v4l2_ctrl_ref **buckets;
8ac7a949
HV
212 v4l2_ctrl_notify_fnc notify;
213 void *notify_priv;
0996517c
HV
214 u16 nr_of_buckets;
215 int error;
216};
217
218/** struct v4l2_ctrl_config - Control configuration structure.
219 * @ops: The control ops.
220 * @id: The control ID.
221 * @name: The control name.
222 * @type: The control type.
223 * @min: The control's minimum value.
224 * @max: The control's maximum value.
225 * @step: The control's step value for non-menu controls.
226 * @def: The control's default value.
d9a25471 227 * @elem_size: The size in bytes of the control.
0996517c
HV
228 * @flags: The control's flags.
229 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
230 * easy to skip menu items that are not valid. If bit X is set,
231 * then menu item X is skipped. Of course, this only works for
0ba2aeb6 232 * menus with <= 64 menu items. There are no menus that come
0996517c 233 * close to that number, so this is OK. Should we ever need more,
0ba2aeb6 234 * then this will have to be extended to a bit array.
0996517c
HV
235 * @qmenu: A const char * array for all menu items. Array entries that are
236 * empty strings ("") correspond to non-existing menu items (this
237 * is in addition to the menu_skip_mask above). The last entry
238 * must be NULL.
239 * @is_private: If set, then this control is private to its handler and it
240 * will not be added to any other handlers.
0996517c
HV
241 */
242struct v4l2_ctrl_config {
243 const struct v4l2_ctrl_ops *ops;
244 u32 id;
245 const char *name;
246 enum v4l2_ctrl_type type;
0ba2aeb6
HV
247 s64 min;
248 s64 max;
249 u64 step;
250 s64 def;
d9a25471 251 u32 elem_size;
0996517c 252 u32 flags;
0ba2aeb6 253 u64 menu_skip_mask;
513521ea 254 const char * const *qmenu;
ce580fe5 255 const s64 *qmenu_int;
0996517c 256 unsigned int is_private:1;
0996517c
HV
257};
258
259/** v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
260 *
261 * This works for all standard V4L2 controls.
262 * For non-standard controls it will only fill in the given arguments
263 * and @name will be NULL.
264 *
265 * This function will overwrite the contents of @name, @type and @flags.
266 * The contents of @min, @max, @step and @def may be modified depending on
267 * the type.
268 *
269 * Do not use in drivers! It is used internally for backwards compatibility
270 * control handling only. Once all drivers are converted to use the new
271 * control framework this function will no longer be exported.
272 */
273void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
0ba2aeb6 274 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
0996517c
HV
275
276
6cd247ef 277/** v4l2_ctrl_handler_init_class() - Initialize the control handler.
0996517c
HV
278 * @hdl: The control handler.
279 * @nr_of_controls_hint: A hint of how many controls this handler is
280 * expected to refer to. This is the total number, so including
281 * any inherited controls. It doesn't have to be precise, but if
282 * it is way off, then you either waste memory (too many buckets
283 * are allocated) or the control lookup becomes slower (not enough
284 * buckets are allocated, so there are more slow list lookups).
285 * It will always work, though.
6cd247ef
AW
286 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
287 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
0996517c
HV
288 *
289 * Returns an error if the buckets could not be allocated. This error will
290 * also be stored in @hdl->error.
6cd247ef
AW
291 *
292 * Never use this call directly, always use the v4l2_ctrl_handler_init
293 * macro that hides the @key and @name arguments.
0996517c 294 */
6cd247ef
AW
295int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
296 unsigned nr_of_controls_hint,
297 struct lock_class_key *key, const char *name);
298
299#ifdef CONFIG_LOCKDEP
300#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
301( \
302 ({ \
303 static struct lock_class_key _key; \
304 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
305 &_key, \
306 KBUILD_BASENAME ":" \
307 __stringify(__LINE__) ":" \
308 "(" #hdl ")->_lock"); \
309 }) \
310)
311#else
312#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
313 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
314#endif
0996517c
HV
315
316/** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
317 * the control list.
318 * @hdl: The control handler.
319 *
320 * Does nothing if @hdl == NULL.
321 */
322void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
323
324/** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
325 * to the handler to initialize the hardware to the current control values.
326 * @hdl: The control handler.
327 *
328 * Button controls will be skipped, as are read-only controls.
329 *
330 * If @hdl == NULL, then this just returns 0.
331 */
332int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
333
334/** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
335 * @hdl: The control handler.
336 * @prefix: The prefix to use when logging the control values. If the
337 * prefix does not end with a space, then ": " will be added
338 * after the prefix. If @prefix == NULL, then no prefix will be
339 * used.
340 *
341 * For use with VIDIOC_LOG_STATUS.
342 *
343 * Does nothing if @hdl == NULL.
344 */
345void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
346 const char *prefix);
347
348/** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
349 * control.
350 * @hdl: The control handler.
351 * @cfg: The control's configuration data.
352 * @priv: The control's driver-specific private data.
353 *
354 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
355 * and @hdl->error is set to the error code (if it wasn't set already).
356 */
357struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
358 const struct v4l2_ctrl_config *cfg, void *priv);
359
360/** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control.
361 * @hdl: The control handler.
362 * @ops: The control ops.
363 * @id: The control ID.
364 * @min: The control's minimum value.
365 * @max: The control's maximum value.
366 * @step: The control's step value
367 * @def: The control's default value.
368 *
369 * If the &v4l2_ctrl struct could not be allocated, or the control
370 * ID is not known, then NULL is returned and @hdl->error is set to the
371 * appropriate error code (if it wasn't set already).
372 *
373 * If @id refers to a menu control, then this function will return NULL.
374 *
375 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
376 */
377struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
378 const struct v4l2_ctrl_ops *ops,
0ba2aeb6 379 u32 id, s64 min, s64 max, u64 step, s64 def);
0996517c
HV
380
381/** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control.
382 * @hdl: The control handler.
383 * @ops: The control ops.
384 * @id: The control ID.
385 * @max: The control's maximum value.
386 * @mask: The control's skip mask for menu controls. This makes it
387 * easy to skip menu items that are not valid. If bit X is set,
388 * then menu item X is skipped. Of course, this only works for
0ba2aeb6 389 * menus with <= 64 menu items. There are no menus that come
0996517c 390 * close to that number, so this is OK. Should we ever need more,
0ba2aeb6 391 * then this will have to be extended to a bit array.
0996517c
HV
392 * @def: The control's default value.
393 *
394 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
395 * determines which menu items are to be skipped.
396 *
397 * If @id refers to a non-menu control, then this function will return NULL.
398 */
399struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
400 const struct v4l2_ctrl_ops *ops,
0ba2aeb6 401 u32 id, u8 max, u64 mask, u8 def);
0996517c 402
117a711a
LP
403/** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
404 * with driver specific menu.
405 * @hdl: The control handler.
406 * @ops: The control ops.
407 * @id: The control ID.
408 * @max: The control's maximum value.
409 * @mask: The control's skip mask for menu controls. This makes it
410 * easy to skip menu items that are not valid. If bit X is set,
411 * then menu item X is skipped. Of course, this only works for
0ba2aeb6 412 * menus with <= 64 menu items. There are no menus that come
117a711a 413 * close to that number, so this is OK. Should we ever need more,
0ba2aeb6 414 * then this will have to be extended to a bit array.
117a711a
LP
415 * @def: The control's default value.
416 * @qmenu: The new menu.
417 *
418 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
419 * menu of this control.
420 *
421 */
422struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
0ba2aeb6
HV
423 const struct v4l2_ctrl_ops *ops, u32 id, u8 max,
424 u64 mask, u8 def, const char * const *qmenu);
117a711a 425
515f3287
SN
426/** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
427 * @hdl: The control handler.
428 * @ops: The control ops.
429 * @id: The control ID.
430 * @max: The control's maximum value.
431 * @def: The control's default value.
432 * @qmenu_int: The control's menu entries.
433 *
434 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
435 * takes as an argument an array of integers determining the menu items.
436 *
437 * If @id refers to a non-integer-menu control, then this function will return NULL.
438 */
439struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
440 const struct v4l2_ctrl_ops *ops,
0ba2aeb6 441 u32 id, u8 max, u8 def, const s64 *qmenu_int);
515f3287 442
0996517c
HV
443/** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
444 * @hdl: The control handler.
445 * @ctrl: The control to add.
446 *
447 * It will return NULL if it was unable to add the control reference.
448 * If the control already belonged to the handler, then it will do
449 * nothing and just return @ctrl.
450 */
451struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
452 struct v4l2_ctrl *ctrl);
453
454/** v4l2_ctrl_add_handler() - Add all controls from handler @add to
455 * handler @hdl.
456 * @hdl: The control handler.
457 * @add: The control handler whose controls you want to add to
458 * the @hdl control handler.
34a6b7d0 459 * @filter: This function will filter which controls should be added.
0996517c 460 *
34a6b7d0
HV
461 * Does nothing if either of the two handlers is a NULL pointer.
462 * If @filter is NULL, then all controls are added. Otherwise only those
463 * controls for which @filter returns true will be added.
0996517c
HV
464 * In case of an error @hdl->error will be set to the error code (if it
465 * wasn't set already).
466 */
467int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
34a6b7d0
HV
468 struct v4l2_ctrl_handler *add,
469 bool (*filter)(const struct v4l2_ctrl *ctrl));
0996517c 470
34a6b7d0
HV
471/** v4l2_ctrl_radio_filter() - Standard filter for radio controls.
472 * @ctrl: The control that is filtered.
473 *
474 * This will return true for any controls that are valid for radio device
475 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
476 * transmitter class controls.
477 *
478 * This function is to be used with v4l2_ctrl_add_handler().
479 */
480bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
0996517c
HV
481
482/** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
483 * @ncontrols: The number of controls in this cluster.
484 * @controls: The cluster control array of size @ncontrols.
485 */
486void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
487
488
72d877ca
HV
489/** v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to
490 * that cluster and set it up for autofoo/foo-type handling.
491 * @ncontrols: The number of controls in this cluster.
492 * @controls: The cluster control array of size @ncontrols. The first control
493 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
494 * @manual_val: The value for the first control in the cluster that equals the
495 * manual setting.
496 * @set_volatile: If true, then all controls except the first auto control will
88365105 497 * be volatile.
72d877ca
HV
498 *
499 * Use for control groups where one control selects some automatic feature and
500 * the other controls are only active whenever the automatic feature is turned
501 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
502 * red and blue balance, etc.
503 *
504 * The behavior of such controls is as follows:
505 *
506 * When the autofoo control is set to automatic, then any manual controls
507 * are set to inactive and any reads will call g_volatile_ctrl (if the control
508 * was marked volatile).
509 *
510 * When the autofoo control is set to manual, then any manual controls will
511 * be marked active, and any reads will just return the current value without
512 * going through g_volatile_ctrl.
513 *
514 * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag
515 * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
516 * if autofoo is in auto mode.
517 */
518void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
519 u8 manual_val, bool set_volatile);
520
521
0996517c
HV
522/** v4l2_ctrl_find() - Find a control with the given ID.
523 * @hdl: The control handler.
524 * @id: The control ID to find.
525 *
526 * If @hdl == NULL this will return NULL as well. Will lock the handler so
527 * do not use from inside &v4l2_ctrl_ops.
528 */
529struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
530
531/** v4l2_ctrl_activate() - Make the control active or inactive.
532 * @ctrl: The control to (de)activate.
533 * @active: True if the control should become active.
534 *
535 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
536 * Does nothing if @ctrl == NULL.
537 * This will usually be called from within the s_ctrl op.
6e239399 538 * The V4L2_EVENT_CTRL event will be generated afterwards.
0996517c 539 *
6e239399 540 * This function assumes that the control handler is locked.
0996517c
HV
541 */
542void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
543
544/** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
545 * @ctrl: The control to (de)activate.
546 * @grabbed: True if the control should become grabbed.
547 *
548 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
549 * Does nothing if @ctrl == NULL.
6e239399 550 * The V4L2_EVENT_CTRL event will be generated afterwards.
0996517c
HV
551 * This will usually be called when starting or stopping streaming in the
552 * driver.
553 *
6e239399
HV
554 * This function assumes that the control handler is not locked and will
555 * take the lock itself.
0996517c
HV
556 */
557void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
558
2ccbe779
SN
559/** v4l2_ctrl_modify_range() - Update the range of a control.
560 * @ctrl: The control to update.
561 * @min: The control's minimum value.
562 * @max: The control's maximum value.
563 * @step: The control's step value
564 * @def: The control's default value.
565 *
566 * Update the range of a control on the fly. This works for control types
567 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
568 * @step value is interpreted as a menu_skip_mask.
569 *
570 * An error is returned if one of the range arguments is invalid for this
571 * control type.
572 *
573 * This function assumes that the control handler is not locked and will
574 * take the lock itself.
575 */
576int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
0ba2aeb6 577 s64 min, s64 max, u64 step, s64 def);
2ccbe779 578
0996517c
HV
579/** v4l2_ctrl_lock() - Helper function to lock the handler
580 * associated with the control.
581 * @ctrl: The control to lock.
582 */
583static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
584{
77e7c4e6 585 mutex_lock(ctrl->handler->lock);
0996517c
HV
586}
587
b594a75e 588/** v4l2_ctrl_unlock() - Helper function to unlock the handler
0996517c
HV
589 * associated with the control.
590 * @ctrl: The control to unlock.
591 */
592static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
593{
77e7c4e6 594 mutex_unlock(ctrl->handler->lock);
0996517c
HV
595}
596
8ac7a949
HV
597/** v4l2_ctrl_notify() - Function to set a notify callback for a control.
598 * @ctrl: The control.
599 * @notify: The callback function.
600 * @priv: The callback private handle, passed as argument to the callback.
601 *
602 * This function sets a callback function for the control. If @ctrl is NULL,
603 * then it will do nothing. If @notify is NULL, then the notify callback will
604 * be removed.
605 *
606 * There can be only one notify. If another already exists, then a WARN_ON
607 * will be issued and the function will do nothing.
608 */
609void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv);
610
0996517c
HV
611/** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
612 * @ctrl: The control.
613 *
614 * This returns the control's value safely by going through the control
615 * framework. This function will lock the control's handler, so it cannot be
616 * used from within the &v4l2_ctrl_ops functions.
617 *
618 * This function is for integer type controls only.
619 */
620s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
621
622/** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver.
623 * @ctrl: The control.
624 * @val: The new value.
625 *
626 * This set the control's new value safely by going through the control
627 * framework. This function will lock the control's handler, so it cannot be
628 * used from within the &v4l2_ctrl_ops functions.
629 *
630 * This function is for integer type controls only.
631 */
632int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
633
03d5285b
LP
634/** v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value from within a driver.
635 * @ctrl: The control.
636 *
637 * This returns the control's value safely by going through the control
638 * framework. This function will lock the control's handler, so it cannot be
639 * used from within the &v4l2_ctrl_ops functions.
640 *
641 * This function is for 64-bit integer type controls only.
642 */
643s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
644
645/** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value from within a driver.
646 * @ctrl: The control.
647 * @val: The new value.
648 *
649 * This set the control's new value safely by going through the control
650 * framework. This function will lock the control's handler, so it cannot be
651 * used from within the &v4l2_ctrl_ops functions.
652 *
653 * This function is for 64-bit integer type controls only.
654 */
655int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
656
ce727574 657/* Internal helper functions that deal with control events. */
3e366149
HG
658extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
659void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
660void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
6e239399 661
e2ecb257
HV
662/* Can be used as a vidioc_log_status function that just dumps all controls
663 associated with the filehandle. */
664int v4l2_ctrl_log_status(struct file *file, void *fh);
665
a26243b0
HV
666/* Can be used as a vidioc_subscribe_event function that just subscribes
667 control events. */
668int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
85f5fe39 669 const struct v4l2_event_subscription *sub);
a26243b0
HV
670
671/* Can be used as a poll function that just polls for control events. */
672unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
673
0996517c
HV
674/* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
675int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
d9a25471 676int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc);
0996517c
HV
677int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
678int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
ab892bac
HV
679int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
680 struct v4l2_control *ctrl);
0996517c
HV
681int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
682int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
ab892bac
HV
683int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
684 struct v4l2_ext_controls *c);
0996517c
HV
685
686/* Helpers for subdevices. If the associated ctrl_handler == NULL then they
687 will all return -EINVAL. */
688int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
689int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
690int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
691int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
692int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
693int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
694int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
695
22fa4279
SN
696/* Can be used as a subscribe_event function that just subscribes control
697 events. */
698int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
699 struct v4l2_event_subscription *sub);
700
ffa9b9f0
SN
701/* Log all controls owned by subdev's control handler. */
702int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
703
0996517c 704#endif