drm: bridge: dw-hdmi: enable 3d mode
[firefly-linux-kernel-4.4.55.git] / include / media / v4l2-ctrls.h
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>
25 #include <linux/mutex.h>
26 #include <linux/videodev2.h>
27
28 /* forward references */
29 struct file;
30 struct v4l2_ctrl_handler;
31 struct v4l2_ctrl_helper;
32 struct v4l2_ctrl;
33 struct video_device;
34 struct v4l2_subdev;
35 struct v4l2_subscribed_event;
36 struct v4l2_fh;
37 struct poll_table_struct;
38
39 /**
40  * union v4l2_ctrl_ptr - A pointer to a control value.
41  * @p_s32:      Pointer to a 32-bit signed value.
42  * @p_s64:      Pointer to a 64-bit signed value.
43  * @p_u8:       Pointer to a 8-bit unsigned value.
44  * @p_u16:      Pointer to a 16-bit unsigned value.
45  * @p_u32:      Pointer to a 32-bit unsigned value.
46  * @p_char:     Pointer to a string.
47  * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
48  * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
49  * @p_h264_scal_mtrx:   Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
50  * @p_h264_slice_param: Pointer to a struct v4l2_ctrl_h264_slice_param.
51  * @p_h264_decode_param: Pointer to a struct v4l2_ctrl_h264_decode_param.
52  * @p_vp8_frame_hdr:    Pointer to a struct v4l2_ctrl_vp8_frame_hdr.
53  * @p:          Pointer to a compound value.
54  */
55 union v4l2_ctrl_ptr {
56         s32 *p_s32;
57         s64 *p_s64;
58         u8 *p_u8;
59         u16 *p_u16;
60         u32 *p_u32;
61         char *p_char;
62         struct v4l2_ctrl_h264_sps *p_h264_sps;
63         struct v4l2_ctrl_h264_pps *p_h264_pps;
64         struct v4l2_ctrl_h264_scaling_matrix *p_h264_scal_mtrx;
65         struct v4l2_ctrl_h264_slice_param *p_h264_slice_param;
66         struct v4l2_ctrl_h264_decode_param *p_h264_decode_param;
67         struct v4l2_ctrl_vp8_frame_hdr *p_vp8_frame_hdr;
68         void *p;
69 };
70
71 /**
72  * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
73  * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
74  *              for volatile (and usually read-only) controls such as a control
75  *              that returns the current signal strength which changes
76  *              continuously.
77  *              If not set, then the currently cached value will be returned.
78  * @try_ctrl:   Test whether the control's value is valid. Only relevant when
79  *              the usual min/max/step checks are not sufficient.
80  * @s_ctrl:     Actually set the new control value. s_ctrl is compulsory. The
81  *              ctrl->handler->lock is held when these ops are called, so no
82  *              one else can access controls owned by that handler.
83  */
84 struct v4l2_ctrl_ops {
85         int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
86         int (*try_ctrl)(struct v4l2_ctrl *ctrl);
87         int (*s_ctrl)(struct v4l2_ctrl *ctrl);
88 };
89
90 /**
91  * struct v4l2_ctrl_type_ops - The control type operations that the driver
92  *                             has to provide.
93  *
94  * @equal: return true if both values are equal.
95  * @init: initialize the value.
96  * @log: log the value.
97  * @validate: validate the value. Return 0 on success and a negative value otherwise.
98  */
99 struct v4l2_ctrl_type_ops {
100         bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
101                       union v4l2_ctrl_ptr ptr1,
102                       union v4l2_ctrl_ptr ptr2);
103         void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
104                      union v4l2_ctrl_ptr ptr);
105         void (*log)(const struct v4l2_ctrl *ctrl);
106         int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
107                         union v4l2_ctrl_ptr ptr);
108 };
109
110 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
111
112 /**
113  * struct v4l2_ctrl - The control structure.
114  * @node:       The list node.
115  * @ev_subs:    The list of control event subscriptions.
116  * @handler:    The handler that owns the control.
117  * @cluster:    Point to start of cluster array.
118  * @ncontrols:  Number of controls in cluster array.
119  * @done:       Internal flag: set for each processed control.
120  * @is_new:     Set when the user specified a new value for this control. It
121  *              is also set when called from v4l2_ctrl_handler_setup. Drivers
122  *              should never set this flag.
123  * @has_changed: Set when the current value differs from the new value. Drivers
124  *              should never use this flag.
125  * @is_private: If set, then this control is private to its handler and it
126  *              will not be added to any other handlers. Drivers can set
127  *              this flag.
128  * @is_auto:   If set, then this control selects whether the other cluster
129  *              members are in 'automatic' mode or 'manual' mode. This is
130  *              used for autogain/gain type clusters. Drivers should never
131  *              set this flag directly.
132  * @is_int:    If set, then this control has a simple integer value (i.e. it
133  *              uses ctrl->val).
134  * @is_string: If set, then this control has type V4L2_CTRL_TYPE_STRING.
135  * @is_ptr:     If set, then this control is an array and/or has type >= V4L2_CTRL_COMPOUND_TYPES
136  *              and/or has type V4L2_CTRL_TYPE_STRING. In other words, struct
137  *              v4l2_ext_control uses field p to point to the data.
138  * @is_array: If set, then this control contains an N-dimensional array.
139  * @has_volatiles: If set, then one or more members of the cluster are volatile.
140  *              Drivers should never touch this flag.
141  * @call_notify: If set, then call the handler's notify function whenever the
142  *              control's value changes.
143  * @manual_mode_value: If the is_auto flag is set, then this is the value
144  *              of the auto control that determines if that control is in
145  *              manual mode. So if the value of the auto control equals this
146  *              value, then the whole cluster is in manual mode. Drivers should
147  *              never set this flag directly.
148  * @ops:        The control ops.
149  * @type_ops:   The control type ops.
150  * @id: The control ID.
151  * @name:       The control name.
152  * @type:       The control type.
153  * @minimum:    The control's minimum value.
154  * @maximum:    The control's maximum value.
155  * @default_value: The control's default value.
156  * @step:       The control's step value for non-menu controls.
157  * @elems:      The number of elements in the N-dimensional array.
158  * @elem_size:  The size in bytes of the control.
159  * @dims:       The size of each dimension.
160  * @nr_of_dims:The number of dimensions in @dims.
161  * @max_stores:The maximum number of configuration stores of this control.
162  * @nr_of_stores: The number of allocated configuration stores of this control.
163  * @store:      The configuration store that the control op operates on.
164  * @menu_skip_mask: The control's skip mask for menu controls. This makes it
165  *              easy to skip menu items that are not valid. If bit X is set,
166  *              then menu item X is skipped. Of course, this only works for
167  *              menus with <= 32 menu items. There are no menus that come
168  *              close to that number, so this is OK. Should we ever need more,
169  *              then this will have to be extended to a u64 or a bit array.
170  * @qmenu:      A const char * array for all menu items. Array entries that are
171  *              empty strings ("") correspond to non-existing menu items (this
172  *              is in addition to the menu_skip_mask above). The last entry
173  *              must be NULL.
174  * @flags:      The control's flags.
175  * @cur:        The control's current value.
176  * @val:        The control's new s32 value.
177  * @priv:       The control's private pointer. For use by the driver. It is
178  *              untouched by the control framework. Note that this pointer is
179  *              not freed when the control is deleted. Should this be needed
180  *              then a new internal bitfield can be added to tell the framework
181  *              to free this pointer.
182  * @p_cur:      The control's current value represented via an union with
183  *              provides a standard way of accessing control types
184  *              through a pointer.
185  * @p_new:      The control's new value represented via an union with provides
186  *              a standard way of accessing control types
187  *              through a pointer.
188  */
189 struct v4l2_ctrl {
190         /* Administrative fields */
191         struct list_head node;
192         struct list_head ev_subs;
193         struct v4l2_ctrl_handler *handler;
194         struct v4l2_ctrl **cluster;
195         unsigned ncontrols;
196         unsigned int done:1;
197
198         unsigned int is_new:1;
199         unsigned int has_changed:1;
200         unsigned int is_private:1;
201         unsigned int is_auto:1;
202         unsigned int is_int:1;
203         unsigned int is_string:1;
204         unsigned int is_ptr:1;
205         unsigned int is_array:1;
206         unsigned int has_volatiles:1;
207         unsigned int call_notify:1;
208         unsigned int manual_mode_value:8;
209
210         const struct v4l2_ctrl_ops *ops;
211         const struct v4l2_ctrl_type_ops *type_ops;
212         u32 id;
213         const char *name;
214         enum v4l2_ctrl_type type;
215         s64 minimum, maximum, default_value;
216         u32 elems;
217         u32 elem_size;
218         u32 dims[V4L2_CTRL_MAX_DIMS];
219         u32 nr_of_dims;
220         u16 max_stores;
221         u16 nr_of_stores;
222         u16 store;
223         union {
224                 u64 step;
225                 u64 menu_skip_mask;
226         };
227         union {
228                 const char * const *qmenu;
229                 const s64 *qmenu_int;
230         };
231         unsigned long flags;
232         void *priv;
233         s32 val;
234         struct {
235                 s32 val;
236         } cur;
237
238         union v4l2_ctrl_ptr p_new;
239         union v4l2_ctrl_ptr p_cur;
240         union v4l2_ctrl_ptr *p_stores;
241 };
242
243 /**
244  * struct v4l2_ctrl_ref - The control reference.
245  * @node:       List node for the sorted list.
246  * @next:       Single-link list node for the hash.
247  * @ctrl:       The actual control information.
248  * @helper:     Pointer to helper struct. Used internally in prepare_ext_ctrls().
249  *
250  * Each control handler has a list of these refs. The list_head is used to
251  * keep a sorted-by-control-ID list of all controls, while the next pointer
252  * is used to link the control in the hash's bucket.
253  */
254 struct v4l2_ctrl_ref {
255         struct list_head node;
256         struct v4l2_ctrl_ref *next;
257         struct v4l2_ctrl *ctrl;
258         struct v4l2_ctrl_helper *helper;
259 };
260
261 /**
262  * struct v4l2_ctrl_handler - The control handler keeps track of all the
263  * controls: both the controls owned by the handler and those inherited
264  * from other handlers.
265  * @_lock:      Default for "lock".
266  * @lock:       Lock to control access to this handler and its controls.
267  *              May be replaced by the user right after init.
268  * @ctrls:      The list of controls owned by this handler.
269  * @ctrl_refs:  The list of control references.
270  * @cached:     The last found control reference. It is common that the same
271  *              control is needed multiple times, so this is a simple
272  *              optimization.
273  * @buckets:    Buckets for the hashing. Allows for quick control lookup.
274  * @notify:     A notify callback that is called whenever the control changes value.
275  *              Note that the handler's lock is held when the notify function
276  *              is called!
277  * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
278  * @nr_of_buckets: Total number of buckets in the array.
279  * @error:      The error code of the first failed control addition.
280  */
281 struct v4l2_ctrl_handler {
282         struct mutex _lock;
283         struct mutex *lock;
284         struct list_head ctrls;
285         struct list_head ctrl_refs;
286         struct v4l2_ctrl_ref *cached;
287         struct v4l2_ctrl_ref **buckets;
288         v4l2_ctrl_notify_fnc notify;
289         void *notify_priv;
290         u16 nr_of_buckets;
291         int error;
292 };
293
294 /**
295  * struct v4l2_ctrl_config - Control configuration structure.
296  * @ops:        The control ops.
297  * @type_ops:   The control type ops. Only needed for compound controls.
298  * @id: The control ID.
299  * @name:       The control name.
300  * @type:       The control type.
301  * @min:        The control's minimum value.
302  * @max:        The control's maximum value.
303  * @step:       The control's step value for non-menu controls.
304  * @def:        The control's default value.
305  * @dims:       The size of each dimension.
306  * @elem_size:  The size in bytes of the control.
307  * @max_stores: The maximum number of stores allowed.
308  * @flags:      The control's flags.
309  * @menu_skip_mask: The control's skip mask for menu controls. This makes it
310  *              easy to skip menu items that are not valid. If bit X is set,
311  *              then menu item X is skipped. Of course, this only works for
312  *              menus with <= 64 menu items. There are no menus that come
313  *              close to that number, so this is OK. Should we ever need more,
314  *              then this will have to be extended to a bit array.
315  * @qmenu:      A const char * array for all menu items. Array entries that are
316  *              empty strings ("") correspond to non-existing menu items (this
317  *              is in addition to the menu_skip_mask above). The last entry
318  *              must be NULL.
319  * @qmenu_int:  A const s64 integer array for all menu items of the type
320  *              V4L2_CTRL_TYPE_INTEGER_MENU.
321  * @is_private: If set, then this control is private to its handler and it
322  *              will not be added to any other handlers.
323  */
324 struct v4l2_ctrl_config {
325         const struct v4l2_ctrl_ops *ops;
326         const struct v4l2_ctrl_type_ops *type_ops;
327         u32 id;
328         const char *name;
329         enum v4l2_ctrl_type type;
330         s64 min;
331         s64 max;
332         u64 step;
333         s64 def;
334         u32 dims[V4L2_CTRL_MAX_DIMS];
335         u32 elem_size;
336         u16 max_stores;
337         u32 flags;
338         u64 menu_skip_mask;
339         const char * const *qmenu;
340         const s64 *qmenu_int;
341         unsigned int is_private:1;
342 };
343
344 /*
345  * v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
346  *
347  * This works for all standard V4L2 controls.
348  * For non-standard controls it will only fill in the given arguments
349  * and @name will be NULL.
350  *
351  * This function will overwrite the contents of @name, @type and @flags.
352  * The contents of @min, @max, @step and @def may be modified depending on
353  * the type.
354  *
355  * Do not use in drivers! It is used internally for backwards compatibility
356  * control handling only. Once all drivers are converted to use the new
357  * control framework this function will no longer be exported.
358  */
359 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
360                     s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
361
362
363 /**
364  * v4l2_ctrl_handler_init_class() - Initialize the control handler.
365  * @hdl:        The control handler.
366  * @nr_of_controls_hint: A hint of how many controls this handler is
367  *              expected to refer to. This is the total number, so including
368  *              any inherited controls. It doesn't have to be precise, but if
369  *              it is way off, then you either waste memory (too many buckets
370  *              are allocated) or the control lookup becomes slower (not enough
371  *              buckets are allocated, so there are more slow list lookups).
372  *              It will always work, though.
373  * @key:        Used by the lock validator if CONFIG_LOCKDEP is set.
374  * @name:       Used by the lock validator if CONFIG_LOCKDEP is set.
375  *
376  * Returns an error if the buckets could not be allocated. This error will
377  * also be stored in @hdl->error.
378  *
379  * Never use this call directly, always use the v4l2_ctrl_handler_init
380  * macro that hides the @key and @name arguments.
381  */
382 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
383                                  unsigned nr_of_controls_hint,
384                                  struct lock_class_key *key, const char *name);
385
386 #ifdef CONFIG_LOCKDEP
387 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint)                \
388 (                                                                       \
389         ({                                                              \
390                 static struct lock_class_key _key;                      \
391                 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint,  \
392                                         &_key,                          \
393                                         KBUILD_BASENAME ":"             \
394                                         __stringify(__LINE__) ":"       \
395                                         "(" #hdl ")->_lock");           \
396         })                                                              \
397 )
398 #else
399 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint)                \
400         v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
401 #endif
402
403 /**
404  * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
405  * the control list.
406  * @hdl:        The control handler.
407  *
408  * Does nothing if @hdl == NULL.
409  */
410 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
411
412 /**
413  * v4l2_ctrl_lock() - Helper function to lock the handler
414  * associated with the control.
415  * @ctrl:       The control to lock.
416  */
417 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
418 {
419         mutex_lock(ctrl->handler->lock);
420 }
421
422 /**
423  * v4l2_ctrl_unlock() - Helper function to unlock the handler
424  * associated with the control.
425  * @ctrl:       The control to unlock.
426  */
427 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
428 {
429         mutex_unlock(ctrl->handler->lock);
430 }
431
432 /**
433  * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
434  * to the handler to initialize the hardware to the current control values.
435  * @hdl:        The control handler.
436  *
437  * Button controls will be skipped, as are read-only controls.
438  *
439  * If @hdl == NULL, then this just returns 0.
440  */
441 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
442
443 /**
444  * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
445  * @hdl:        The control handler.
446  * @prefix:     The prefix to use when logging the control values. If the
447  *              prefix does not end with a space, then ": " will be added
448  *              after the prefix. If @prefix == NULL, then no prefix will be
449  *              used.
450  *
451  * For use with VIDIOC_LOG_STATUS.
452  *
453  * Does nothing if @hdl == NULL.
454  */
455 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
456                                   const char *prefix);
457
458 /**
459  * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
460  * control.
461  * @hdl:        The control handler.
462  * @cfg:        The control's configuration data.
463  * @priv:       The control's driver-specific private data.
464  *
465  * If the &v4l2_ctrl struct could not be allocated then NULL is returned
466  * and @hdl->error is set to the error code (if it wasn't set already).
467  */
468 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
469                         const struct v4l2_ctrl_config *cfg, void *priv);
470
471 /**
472  * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu 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.
480  *
481  * If the &v4l2_ctrl struct could not be allocated, or the control
482  * ID is not known, then NULL is returned and @hdl->error is set to the
483  * appropriate error code (if it wasn't set already).
484  *
485  * If @id refers to a menu control, then this function will return NULL.
486  *
487  * Use v4l2_ctrl_new_std_menu() when adding menu controls.
488  */
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, s64 def);
492
493 /**
494  * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control.
495  * @hdl:        The control handler.
496  * @ops:        The control ops.
497  * @id: The control ID.
498  * @max:        The control's maximum value.
499  * @mask:       The control's skip mask for menu controls. This makes it
500  *              easy to skip menu items that are not valid. If bit X is set,
501  *              then menu item X is skipped. Of course, this only works for
502  *              menus with <= 64 menu items. There are no menus that come
503  *              close to that number, so this is OK. Should we ever need more,
504  *              then this will have to be extended to a bit array.
505  * @def:        The control's default value.
506  *
507  * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
508  * determines which menu items are to be skipped.
509  *
510  * If @id refers to a non-menu control, then this function will return NULL.
511  */
512 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
513                         const struct v4l2_ctrl_ops *ops,
514                         u32 id, u8 max, u64 mask, u8 def);
515
516 /**
517  * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
518  * with driver specific menu.
519  * @hdl:        The control handler.
520  * @ops:        The control ops.
521  * @id: The control ID.
522  * @max:        The control's maximum value.
523  * @mask:       The control's skip mask for menu controls. This makes it
524  *              easy to skip menu items that are not valid. If bit X is set,
525  *              then menu item X is skipped. Of course, this only works for
526  *              menus with <= 64 menu items. There are no menus that come
527  *              close to that number, so this is OK. Should we ever need more,
528  *              then this will have to be extended to a bit array.
529  * @def:        The control's default value.
530  * @qmenu:      The new menu.
531  *
532  * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
533  * menu of this control.
534  *
535  */
536 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
537                         const struct v4l2_ctrl_ops *ops, u32 id, u8 max,
538                         u64 mask, u8 def, const char * const *qmenu);
539
540 /**
541  * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
542  * @hdl:        The control handler.
543  * @ops:        The control ops.
544  * @id: The control ID.
545  * @max:        The control's maximum value.
546  * @def:        The control's default value.
547  * @qmenu_int:  The control's menu entries.
548  *
549  * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
550  * takes as an argument an array of integers determining the menu items.
551  *
552  * If @id refers to a non-integer-menu control, then this function will return NULL.
553  */
554 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
555                         const struct v4l2_ctrl_ops *ops,
556                         u32 id, u8 max, u8 def, const s64 *qmenu_int);
557
558 /**
559  * v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
560  * @hdl:        The control handler.
561  * @ctrl:       The control to add.
562  *
563  * It will return NULL if it was unable to add the control reference.
564  * If the control already belonged to the handler, then it will do
565  * nothing and just return @ctrl.
566  */
567 struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
568                                           struct v4l2_ctrl *ctrl);
569
570 /**
571  * v4l2_ctrl_add_handler() - Add all controls from handler @add to
572  * 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.
577  *
578  * Does nothing if either of the two handlers is a NULL pointer.
579  * If @filter is NULL, then all controls are added. Otherwise only those
580  * controls for which @filter returns true will be added.
581  * In case of an error @hdl->error will be set to the error code (if it
582  * wasn't set already).
583  */
584 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
585                           struct v4l2_ctrl_handler *add,
586                           bool (*filter)(const struct v4l2_ctrl *ctrl));
587
588 /**
589  * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
590  * @ctrl:       The control that is filtered.
591  *
592  * This will return true for any controls that are valid for radio device
593  * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
594  * transmitter class controls.
595  *
596  * This function is to be used with v4l2_ctrl_add_handler().
597  */
598 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
599
600 /**
601  * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
602  * @ncontrols:  The number of controls in this cluster.
603  * @controls:   The cluster control array of size @ncontrols.
604  */
605 void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
606
607
608 /**
609  * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to
610  * that cluster and set it up for autofoo/foo-type handling.
611  * @ncontrols:  The number of controls in this cluster.
612  * @controls:   The cluster control array of size @ncontrols. The first control
613  *              must be the 'auto' control (e.g. autogain, autoexposure, etc.)
614  * @manual_val: The value for the first control in the cluster that equals the
615  *              manual setting.
616  * @set_volatile: If true, then all controls except the first auto control will
617  *              be volatile.
618  *
619  * Use for control groups where one control selects some automatic feature and
620  * the other controls are only active whenever the automatic feature is turned
621  * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
622  * red and blue balance, etc.
623  *
624  * The behavior of such controls is as follows:
625  *
626  * When the autofoo control is set to automatic, then any manual controls
627  * are set to inactive and any reads will call g_volatile_ctrl (if the control
628  * was marked volatile).
629  *
630  * When the autofoo control is set to manual, then any manual controls will
631  * be marked active, and any reads will just return the current value without
632  * going through g_volatile_ctrl.
633  *
634  * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag
635  * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
636  * if autofoo is in auto mode.
637  */
638 void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
639                         u8 manual_val, bool set_volatile);
640
641
642 /**
643  * v4l2_ctrl_find() - Find a control with the given ID.
644  * @hdl:        The control handler.
645  * @id: The control ID to find.
646  *
647  * If @hdl == NULL this will return NULL as well. Will lock the handler so
648  * do not use from inside &v4l2_ctrl_ops.
649  */
650 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
651
652 /**
653  * v4l2_ctrl_activate() - Make the control active or inactive.
654  * @ctrl:       The control to (de)activate.
655  * @active:     True if the control should become active.
656  *
657  * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
658  * Does nothing if @ctrl == NULL.
659  * This will usually be called from within the s_ctrl op.
660  * The V4L2_EVENT_CTRL event will be generated afterwards.
661  *
662  * This function assumes that the control handler is locked.
663  */
664 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
665
666 /**
667  * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
668  * @ctrl:       The control to (de)activate.
669  * @grabbed:    True if the control should become grabbed.
670  *
671  * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
672  * Does nothing if @ctrl == NULL.
673  * The V4L2_EVENT_CTRL event will be generated afterwards.
674  * This will usually be called when starting or stopping streaming in the
675  * driver.
676  *
677  * This function assumes that the control handler is not locked and will
678  * take the lock itself.
679  */
680 void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
681
682
683 /**
684  *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
685  *
686  * @ctrl:       The control to update.
687  * @min:        The control's minimum value.
688  * @max:        The control's maximum value.
689  * @step:       The control's step value
690  * @def:        The control's default value.
691  *
692  * Update the range of a control on the fly. This works for control types
693  * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
694  * @step value is interpreted as a menu_skip_mask.
695  *
696  * An error is returned if one of the range arguments is invalid for this
697  * control type.
698  *
699  * This function assumes that the control handler is not locked and will
700  * take the lock itself.
701  */
702 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
703                              s64 min, s64 max, u64 step, s64 def);
704
705 /**
706  * v4l2_ctrl_modify_range() - Update the range of a control.
707  * @ctrl:       The control to update.
708  * @min:        The control's minimum value.
709  * @max:        The control's maximum value.
710  * @step:       The control's step value
711  * @def:        The control's default value.
712  *
713  * Update the range of a control on the fly. This works for control types
714  * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
715  * @step value is interpreted as a menu_skip_mask.
716  *
717  * An error is returned if one of the range arguments is invalid for this
718  * control type.
719  *
720  * This function assumes that the control handler is not locked and will
721  * take the lock itself.
722  */
723 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
724                                          s64 min, s64 max, u64 step, s64 def)
725 {
726         int rval;
727
728         v4l2_ctrl_lock(ctrl);
729         rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
730         v4l2_ctrl_unlock(ctrl);
731
732         return rval;
733 }
734
735 /**
736  * v4l2_ctrl_notify() - Function to set a notify callback for a control.
737  * @ctrl:       The control.
738  * @notify:     The callback function.
739  * @priv:       The callback private handle, passed as argument to the callback.
740  *
741  * This function sets a callback function for the control. If @ctrl is NULL,
742  * then it will do nothing. If @notify is NULL, then the notify callback will
743  * be removed.
744  *
745  * There can be only one notify. If another already exists, then a WARN_ON
746  * will be issued and the function will do nothing.
747  */
748 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv);
749
750 /**
751  * v4l2_ctrl_get_name() - Get the name of the control
752  * @id:         The control ID.
753  *
754  * This function returns the name of the given control ID or NULL if it isn't
755  * a known control.
756  */
757 const char *v4l2_ctrl_get_name(u32 id);
758
759 /**
760  * v4l2_ctrl_get_menu() - Get the menu string array of the control
761  * @id:         The control ID.
762  *
763  * This function returns the NULL-terminated menu string array name of the
764  * given control ID or NULL if it isn't a known menu control.
765  */
766 const char * const *v4l2_ctrl_get_menu(u32 id);
767
768 /**
769  * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
770  * @id:         The control ID.
771  * @len:        The size of the integer array.
772  *
773  * This function returns the integer array of the given control ID or NULL if it
774  * if it isn't a known integer menu control.
775  */
776 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
777
778 /**
779  * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
780  * @ctrl:       The control.
781  *
782  * This returns the control's value safely by going through the control
783  * framework. This function will lock the control's handler, so it cannot be
784  * used from within the &v4l2_ctrl_ops functions.
785  *
786  * This function is for integer type controls only.
787  */
788 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
789
790 /**
791  * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
792  * @ctrl:       The control.
793  * @val:        The new value.
794  *
795  * This set the control's new value safely by going through the control
796  * framework. This function will lock the control's handler, so it cannot be
797  * used from within the &v4l2_ctrl_ops functions.
798  *
799  * This function is for integer type controls only.
800  */
801 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
802
803 /** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver.
804  * @ctrl:       The control.
805  * @val:        The new value.
806  *
807  * This set the control's new value safely by going through the control
808  * framework. This function will lock the control's handler, so it cannot be
809  * used from within the &v4l2_ctrl_ops functions.
810  *
811  * This function is for integer type controls only.
812  */
813 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
814 {
815         int rval;
816
817         v4l2_ctrl_lock(ctrl);
818         rval = __v4l2_ctrl_s_ctrl(ctrl, val);
819         v4l2_ctrl_unlock(ctrl);
820
821         return rval;
822 }
823
824 /**
825  * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
826  *      from within a driver.
827  * @ctrl:       The control.
828  *
829  * This returns the control's value safely by going through the control
830  * framework. This function will lock the control's handler, so it cannot be
831  * used from within the &v4l2_ctrl_ops functions.
832  *
833  * This function is for 64-bit integer type controls only.
834  */
835 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
836
837 /**
838  * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
839  *
840  * @ctrl:       The control.
841  * @val:        The new value.
842  *
843  * This set the control's new value safely by going through the control
844  * framework. This function will lock the control's handler, so it cannot be
845  * used from within the &v4l2_ctrl_ops functions.
846  *
847  * This function is for 64-bit integer type controls only.
848  */
849 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
850
851 /** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
852  *      from within a driver.
853  *
854  * @ctrl:       The control.
855  * @val:        The new value.
856  *
857  * This set the control's new value safely by going through the control
858  * framework. This function will lock the control's handler, so it cannot be
859  * used from within the &v4l2_ctrl_ops functions.
860  *
861  * This function is for 64-bit integer type controls only.
862  */
863 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
864 {
865         int rval;
866
867         v4l2_ctrl_lock(ctrl);
868         rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
869         v4l2_ctrl_unlock(ctrl);
870
871         return rval;
872 }
873
874 /** __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
875  *
876  * @ctrl:       The control.
877  * @s:          The new string.
878  *
879  * This set the control's new string safely by going through the control
880  * framework. This function will lock the control's handler, so it cannot be
881  * used from within the &v4l2_ctrl_ops functions.
882  *
883  * This function is for string type controls only.
884  */
885 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
886
887 /** v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
888  *       from within a driver.
889  *
890  * @ctrl:       The control.
891  * @s:          The new string.
892  *
893  * This set the control's new string safely by going through the control
894  * framework. This function will lock the control's handler, so it cannot be
895  * used from within the &v4l2_ctrl_ops functions.
896  *
897  * This function is for string type controls only.
898  */
899 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
900 {
901         int rval;
902
903         v4l2_ctrl_lock(ctrl);
904         rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
905         v4l2_ctrl_unlock(ctrl);
906
907         return rval;
908 }
909
910 static inline void v4l2_ctrl_set_max_stores(struct v4l2_ctrl *ctrl, u16 max_stores)
911 {
912         ctrl->max_stores = max_stores;
913 }
914
915 int v4l2_ctrl_apply_store(struct v4l2_ctrl_handler *hdl, unsigned store);
916
917 /* Internal helper functions that deal with control events. */
918 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
919 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
920 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
921
922 /* Can be used as a vidioc_log_status function that just dumps all controls
923    associated with the filehandle. */
924 int v4l2_ctrl_log_status(struct file *file, void *fh);
925
926 /* Can be used as a vidioc_subscribe_event function that just subscribes
927    control events. */
928 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
929                                 const struct v4l2_event_subscription *sub);
930
931 /* Can be used as a poll function that just polls for control events. */
932 unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
933
934 /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
935 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
936 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc);
937 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
938 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
939 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
940                                                 struct v4l2_control *ctrl);
941 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
942 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
943 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
944                                                 struct v4l2_ext_controls *c);
945
946 /* Helpers for subdevices. If the associated ctrl_handler == NULL then they
947    will all return -EINVAL. */
948 int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
949 int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
950 int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
951 int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
952 int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
953 int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
954 int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
955
956 /* Can be used as a subscribe_event function that just subscribes control
957    events. */
958 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
959                                      struct v4l2_event_subscription *sub);
960
961 /* Log all controls owned by subdev's control handler. */
962 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
963
964 #endif