Linux 4.8.3
[linux/fpc-iii.git] / include / media / v4l2-ctrls.h
blob178a88d45aea0c1a303a61259dd5390029f60cd7
1 /*
2 * V4L2 controls support header.
4 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
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.
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.
17 #ifndef _V4L2_CTRLS_H
18 #define _V4L2_CTRLS_H
20 #include <linux/list.h>
21 #include <linux/mutex.h>
22 #include <linux/videodev2.h>
24 /* forward references */
25 struct file;
26 struct v4l2_ctrl_handler;
27 struct v4l2_ctrl_helper;
28 struct v4l2_ctrl;
29 struct video_device;
30 struct v4l2_subdev;
31 struct v4l2_subscribed_event;
32 struct v4l2_fh;
33 struct poll_table_struct;
35 /**
36 * union v4l2_ctrl_ptr - A pointer to a control value.
37 * @p_s32: Pointer to a 32-bit signed value.
38 * @p_s64: Pointer to a 64-bit signed value.
39 * @p_u8: Pointer to a 8-bit unsigned value.
40 * @p_u16: Pointer to a 16-bit unsigned value.
41 * @p_u32: Pointer to a 32-bit unsigned value.
42 * @p_char: Pointer to a string.
43 * @p: Pointer to a compound value.
45 union v4l2_ctrl_ptr {
46 s32 *p_s32;
47 s64 *p_s64;
48 u8 *p_u8;
49 u16 *p_u16;
50 u32 *p_u32;
51 char *p_char;
52 void *p;
55 /**
56 * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
58 * @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.
69 struct 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);
75 /**
76 * struct v4l2_ctrl_type_ops - The control type operations that the driver
77 * has to provide.
79 * @equal: return true if both values are equal.
80 * @init: initialize the value.
81 * @log: log the value.
82 * @validate: validate the value. Return 0 on success and a negative value
83 * otherwise.
85 struct v4l2_ctrl_type_ops {
86 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
87 union v4l2_ctrl_ptr ptr1,
88 union v4l2_ctrl_ptr ptr2);
89 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
90 union v4l2_ctrl_ptr ptr);
91 void (*log)(const struct v4l2_ctrl *ctrl);
92 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
93 union v4l2_ctrl_ptr ptr);
96 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
98 /**
99 * struct v4l2_ctrl - The control structure.
101 * @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
108 * is also set when called from v4l2_ctrl_handler_setup(). Drivers
109 * 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).
121 * @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
125 * 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.
162 * @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.
167 * @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.
174 struct v4l2_ctrl {
175 /* Administrative fields */
176 struct list_head node;
177 struct list_head ev_subs;
178 struct v4l2_ctrl_handler *handler;
179 struct v4l2_ctrl **cluster;
180 unsigned int ncontrols;
182 unsigned int done:1;
184 unsigned int is_new:1;
185 unsigned int has_changed:1;
186 unsigned int is_private:1;
187 unsigned int is_auto:1;
188 unsigned int is_int:1;
189 unsigned int is_string:1;
190 unsigned int is_ptr:1;
191 unsigned int is_array:1;
192 unsigned int has_volatiles:1;
193 unsigned int call_notify:1;
194 unsigned int manual_mode_value:8;
196 const struct v4l2_ctrl_ops *ops;
197 const struct v4l2_ctrl_type_ops *type_ops;
198 u32 id;
199 const char *name;
200 enum v4l2_ctrl_type type;
201 s64 minimum, maximum, default_value;
202 u32 elems;
203 u32 elem_size;
204 u32 dims[V4L2_CTRL_MAX_DIMS];
205 u32 nr_of_dims;
206 union {
207 u64 step;
208 u64 menu_skip_mask;
210 union {
211 const char * const *qmenu;
212 const s64 *qmenu_int;
214 unsigned long flags;
215 void *priv;
216 s32 val;
217 struct {
218 s32 val;
219 } cur;
221 union v4l2_ctrl_ptr p_new;
222 union v4l2_ctrl_ptr p_cur;
226 * struct v4l2_ctrl_ref - The control reference.
228 * @node: List node for the sorted list.
229 * @next: Single-link list node for the hash.
230 * @ctrl: The actual control information.
231 * @helper: Pointer to helper struct. Used internally in
232 * prepare_ext_ctrls().
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.
238 struct v4l2_ctrl_ref {
239 struct list_head node;
240 struct v4l2_ctrl_ref *next;
241 struct v4l2_ctrl *ctrl;
242 struct v4l2_ctrl_helper *helper;
246 * struct v4l2_ctrl_handler - The control handler keeps track of all the
247 * controls: both the controls owned by the handler and those inherited
248 * from other handlers.
250 * @_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.
259 * @notify: A notify callback that is called whenever the control changes
260 * value.
261 * 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.
267 struct v4l2_ctrl_handler {
268 struct mutex _lock;
269 struct mutex *lock;
270 struct list_head ctrls;
271 struct list_head ctrl_refs;
272 struct v4l2_ctrl_ref *cached;
273 struct v4l2_ctrl_ref **buckets;
274 v4l2_ctrl_notify_fnc notify;
275 void *notify_priv;
276 u16 nr_of_buckets;
277 int error;
281 * struct v4l2_ctrl_config - Control configuration structure.
283 * @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.
291 * @def: The control's default value.
292 * @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.
305 * @qmenu_int: A const s64 integer array for all menu items of the type
306 * V4L2_CTRL_TYPE_INTEGER_MENU.
307 * @is_private: If set, then this control is private to its handler and it
308 * will not be added to any other handlers.
310 struct v4l2_ctrl_config {
311 const struct v4l2_ctrl_ops *ops;
312 const struct v4l2_ctrl_type_ops *type_ops;
313 u32 id;
314 const char *name;
315 enum v4l2_ctrl_type type;
316 s64 min;
317 s64 max;
318 u64 step;
319 s64 def;
320 u32 dims[V4L2_CTRL_MAX_DIMS];
321 u32 elem_size;
322 u32 flags;
323 u64 menu_skip_mask;
324 const char * const *qmenu;
325 const s64 *qmenu_int;
326 unsigned int is_private:1;
330 * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
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
341 * This works for all standard V4L2 controls.
342 * For non-standard controls it will only fill in the given arguments
343 * and @name will be %NULL.
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.
349 * .. note::
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.
355 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
356 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
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.
372 * Returns an error if the buckets could not be allocated. This error will
373 * also be stored in @hdl->error.
375 * Never use this call directly, always use the v4l2_ctrl_handler_init
376 * macro that hides the @key and @name arguments.
378 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
379 unsigned int nr_of_controls_hint,
380 struct lock_class_key *key, const char *name);
382 #ifdef CONFIG_LOCKDEP
383 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
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 }) \
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
400 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
401 * the control list.
402 * @hdl: The control handler.
404 * Does nothing if @hdl == NULL.
406 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
409 * v4l2_ctrl_lock() - Helper function to lock the handler
410 * associated with the control.
411 * @ctrl: The control to lock.
413 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
415 mutex_lock(ctrl->handler->lock);
419 * v4l2_ctrl_unlock() - Helper function to unlock the handler
420 * associated with the control.
421 * @ctrl: The control to unlock.
423 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
425 mutex_unlock(ctrl->handler->lock);
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.
433 * Button controls will be skipped, as are read-only controls.
435 * If @hdl == NULL, then this just returns 0.
437 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
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.
447 * For use with VIDIOC_LOG_STATUS.
449 * Does nothing if @hdl == NULL.
451 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
452 const char *prefix);
455 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
456 * control.
458 * @hdl: The control handler.
459 * @cfg: The control's configuration data.
460 * @priv: The control's driver-specific private data.
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).
465 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
466 const struct v4l2_ctrl_config *cfg,
467 void *priv);
470 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
471 * control.
473 * @hdl: The control handler.
474 * @ops: The control ops.
475 * @id: The control ID.
476 * @min: The control's minimum value.
477 * @max: The control's maximum value.
478 * @step: The control's step value
479 * @def: The control's default value.
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).
485 * If @id refers to a menu control, then this function will return NULL.
487 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
489 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
490 const struct v4l2_ctrl_ops *ops,
491 u32 id, s64 min, s64 max, u64 step,
492 s64 def);
495 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
496 * menu control.
498 * @hdl: The control handler.
499 * @ops: The control ops.
500 * @id: The control ID.
501 * @max: The control's maximum value.
502 * @mask: The control's skip mask for menu controls. This makes it
503 * 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.
508 * @def: The control's default value.
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.
513 * If @id refers to a non-menu control, then this function will return NULL.
515 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
516 const struct v4l2_ctrl_ops *ops,
517 u32 id, u8 max, u64 mask, u8 def);
520 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
521 * with driver specific menu.
523 * @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.
536 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
537 * menu of this control.
540 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
541 const struct v4l2_ctrl_ops *ops,
542 u32 id, u8 max,
543 u64 mask, u8 def,
544 const char * const *qmenu);
547 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
549 * @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.
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.
559 * If @id refers to a non-integer-menu control, then this function will
560 * return %NULL.
562 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
563 const struct v4l2_ctrl_ops *ops,
564 u32 id, u8 max, u8 def,
565 const s64 *qmenu_int);
567 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
570 * v4l2_ctrl_add_handler() - Add all controls from handler @add to
571 * handler @hdl.
573 * @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.
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).
584 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
585 struct v4l2_ctrl_handler *add,
586 v4l2_ctrl_filter filter);
589 * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
591 * @ctrl: The control that is filtered.
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.
597 * This function is to be used with v4l2_ctrl_add_handler().
599 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
602 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
603 * to that cluster.
605 * @ncontrols: The number of controls in this cluster.
606 * @controls: The cluster control array of size @ncontrols.
608 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
612 * 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.
615 * @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.
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.
628 * The behavior of such controls is as follows:
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).
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.
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.
642 void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
643 struct v4l2_ctrl **controls,
644 u8 manual_val, bool set_volatile);
648 * v4l2_ctrl_find() - Find a control with the given ID.
650 * @hdl: The control handler.
651 * @id: The control ID to find.
653 * If @hdl == NULL this will return NULL as well. Will lock the handler so
654 * do not use from inside &v4l2_ctrl_ops.
656 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
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.
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.
668 * This function assumes that the control handler is locked.
670 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
673 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
675 * @ctrl: The control to (de)activate.
676 * @grabbed: True if the control should become grabbed.
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.
684 * This function assumes that the control handler is not locked and will
685 * take the lock itself.
687 void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
691 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
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.
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.
703 * An error is returned if one of the range arguments is invalid for this
704 * control type.
706 * This function assumes that the control handler is not locked and will
707 * take the lock itself.
709 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
710 s64 min, s64 max, u64 step, s64 def);
713 * v4l2_ctrl_modify_range() - Update the range of a control.
715 * @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.
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.
725 * An error is returned if one of the range arguments is invalid for this
726 * control type.
728 * This function assumes that the control handler is not locked and will
729 * take the lock itself.
731 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
732 s64 min, s64 max, u64 step, s64 def)
734 int rval;
736 v4l2_ctrl_lock(ctrl);
737 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
738 v4l2_ctrl_unlock(ctrl);
740 return rval;
744 * v4l2_ctrl_notify() - Function to set a notify callback for a control.
746 * @ctrl: The control.
747 * @notify: The callback function.
748 * @priv: The callback private handle, passed as argument to the callback.
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.
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.
757 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
758 void *priv);
761 * v4l2_ctrl_get_name() - Get the name of the control
763 * @id: The control ID.
765 * This function returns the name of the given control ID or NULL if it isn't
766 * a known control.
768 const char *v4l2_ctrl_get_name(u32 id);
771 * v4l2_ctrl_get_menu() - Get the menu string array of the control
773 * @id: The control ID.
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.
778 const char * const *v4l2_ctrl_get_menu(u32 id);
781 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
783 * @id: The control ID.
784 * @len: The size of the integer array.
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.
789 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
792 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
793 * within a driver.
795 * @ctrl: The control.
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.
801 * This function is for integer type controls only.
803 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
806 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
808 * @ctrl: The control.
809 * @val: TheControls name new value.
811 * 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.
815 * This function is for integer type controls only.
817 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
820 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
821 * within a driver.
822 * @ctrl: The control.
823 * @val: The new value.
825 * This sets the control's new value safely by going through the control
826 * framework. This function will lock the control's handler, so it cannot be
827 * used from within the &v4l2_ctrl_ops functions.
829 * This function is for integer type controls only.
831 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
833 int rval;
835 v4l2_ctrl_lock(ctrl);
836 rval = __v4l2_ctrl_s_ctrl(ctrl, val);
837 v4l2_ctrl_unlock(ctrl);
839 return rval;
843 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
844 * from within a driver.
846 * @ctrl: The control.
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.
852 * This function is for 64-bit integer type controls only.
854 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
857 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
859 * @ctrl: The control.
860 * @val: The new value.
862 * 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.
866 * This function is for 64-bit integer type controls only.
868 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
871 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
872 * from within a driver.
874 * @ctrl: The control.
875 * @val: The new value.
877 * This sets the control's new value safely by going through the control
878 * framework. This function will lock the control's handler, so it cannot be
879 * used from within the &v4l2_ctrl_ops functions.
881 * This function is for 64-bit integer type controls only.
883 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
885 int rval;
887 v4l2_ctrl_lock(ctrl);
888 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
889 v4l2_ctrl_unlock(ctrl);
891 return rval;
895 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
897 * @ctrl: The control.
898 * @s: The new string.
900 * 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.
904 * This function is for string type controls only.
906 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
909 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
910 * from within a driver.
912 * @ctrl: The control.
913 * @s: The new string.
914 *Controls name
915 * This sets the control's new string safely by going through the control
916 * framework. This function will lock the control's handler, so it cannot be
917 * used from within the &v4l2_ctrl_ops functions.
919 * This function is for string type controls only.
921 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
923 int rval;
925 v4l2_ctrl_lock(ctrl);
926 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
927 v4l2_ctrl_unlock(ctrl);
929 return rval;
932 /* Internal helper functions that deal with control events. */
933 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
936 * v4l2_ctrl_replace - Function to be used as a callback to
937 * &struct v4l2_subscribed_event_ops replace\(\)
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;
944 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
947 * v4l2_ctrl_merge - Function to be used as a callback to
948 * &struct v4l2_subscribed_event_ops merge(\)
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;
955 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
958 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
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.
964 * Can be used as a vidioc_log_status function that just dumps all controls
965 * associated with the filehandle.
967 int v4l2_ctrl_log_status(struct file *file, void *fh);
970 * v4l2_ctrl_subscribe_event - Subscribes to an event
973 * @fh: pointer to struct v4l2_fh
974 * @sub: pointer to &struct v4l2_event_subscription
976 * Can be used as a vidioc_subscribe_event function that just subscribes
977 * control events.
979 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
980 const struct v4l2_event_subscription *sub);
983 * v4l2_ctrl_poll - function to be used as a callback to the poll()
984 * That just polls for control events.
986 * @file: pointer to struct file
987 * @wait: pointer to struct poll_table_struct
989 unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
991 /* Helpers for ioctl_ops */
994 * v4l2_queryctrl - Helper function to implement
995 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
997 * @hdl: pointer to &struct v4l2_ctrl_handler
998 * @qc: pointer to &struct v4l2_queryctrl
1000 * If hdl == NULL then they will all return -EINVAL.
1002 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1005 * v4l2_query_ext_ctrl - Helper function to implement
1006 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1008 * @hdl: pointer to &struct v4l2_ctrl_handler
1009 * @qc: pointer to &struct v4l2_query_ext_ctrl
1011 * If hdl == NULL then they will all return -EINVAL.
1013 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1014 struct v4l2_query_ext_ctrl *qc);
1017 * v4l2_querymenu - Helper function to implement
1018 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1020 * @hdl: pointer to &struct v4l2_ctrl_handler
1021 * @qm: pointer to &struct v4l2_querymenu
1023 * If hdl == NULL then they will all return -EINVAL.
1025 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1028 * v4l2_g_ctrl - Helper function to implement
1029 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1031 * @hdl: pointer to &struct v4l2_ctrl_handler
1032 * @ctrl: pointer to &struct v4l2_control
1034 * If hdl == NULL then they will all return -EINVAL.
1036 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1039 * v4l2_s_ctrl - Helper function to implement
1040 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1042 * @fh: pointer to &struct v4l2_fh
1043 * @hdl: pointer to &struct v4l2_ctrl_handler
1045 * @ctrl: pointer to &struct v4l2_control
1047 * If hdl == NULL then they will all return -EINVAL.
1049 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1050 struct v4l2_control *ctrl);
1053 * v4l2_g_ext_ctrls - Helper function to implement
1054 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1056 * @hdl: pointer to &struct v4l2_ctrl_handler
1057 * @c: pointer to &struct v4l2_ext_controls
1059 * If hdl == NULL then they will all return -EINVAL.
1061 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1062 struct v4l2_ext_controls *c);
1065 * v4l2_try_ext_ctrls - Helper function to implement
1066 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1068 * @hdl: pointer to &struct v4l2_ctrl_handler
1069 * @c: pointer to &struct v4l2_ext_controls
1071 * If hdl == NULL then they will all return -EINVAL.
1073 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1074 struct v4l2_ext_controls *c);
1077 * v4l2_s_ext_ctrls - Helper function to implement
1078 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1080 * @fh: pointer to &struct v4l2_fh
1081 * @hdl: pointer to &struct v4l2_ctrl_handler
1082 * @c: pointer to &struct v4l2_ext_controls
1084 * If hdl == NULL then they will all return -EINVAL.
1086 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1087 struct v4l2_ext_controls *c);
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.
1094 * @sd: pointer to &struct v4l2_subdev
1095 * @fh: pointer to &struct v4l2_fh
1096 * @sub: pointer to &struct v4l2_event_subscription
1098 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1099 struct v4l2_event_subscription *sub);
1102 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1103 * handler.
1105 * @sd: pointer to &struct v4l2_subdev
1107 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1109 #endif