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