blob: 16f7f2606516982d8cf60ef18c3c953e15ac0526 [file] [log] [blame]
Hans Verkuil09965172010-08-01 14:32:42 -03001/*
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>
Andrzej Hajdaa19dec62013-06-28 05:44:22 -030025#include <linux/mutex.h>
Laurent Pinchart01c40c02010-11-19 11:20:06 -030026#include <linux/videodev2.h>
Hans Verkuil09965172010-08-01 14:32:42 -030027
28/* forward references */
Laurent Pinchart528f0f72012-04-23 08:20:35 -030029struct file;
Hans Verkuil09965172010-08-01 14:32:42 -030030struct v4l2_ctrl_handler;
Hans Verkuileb5b16e2011-06-14 10:04:06 -030031struct v4l2_ctrl_helper;
Hans Verkuil09965172010-08-01 14:32:42 -030032struct v4l2_ctrl;
33struct video_device;
34struct v4l2_subdev;
Hans Verkuil77068d32011-06-13 18:55:58 -030035struct v4l2_subscribed_event;
Hans Verkuil6e239392011-06-07 11:13:44 -030036struct v4l2_fh;
Hans Verkuila26243b2012-01-27 16:18:42 -030037struct poll_table_struct;
Hans Verkuil09965172010-08-01 14:32:42 -030038
39/** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
40 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
41 * for volatile (and usually read-only) controls such as a control
42 * that returns the current signal strength which changes
43 * continuously.
44 * If not set, then the currently cached value will be returned.
45 * @try_ctrl: Test whether the control's value is valid. Only relevant when
46 * the usual min/max/step checks are not sufficient.
47 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
48 * ctrl->handler->lock is held when these ops are called, so no
49 * one else can access controls owned by that handler.
50 */
51struct v4l2_ctrl_ops {
52 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
53 int (*try_ctrl)(struct v4l2_ctrl *ctrl);
54 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
55};
56
Hans Verkuil8ac7a942012-09-07 04:46:39 -030057typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
58
Hans Verkuil09965172010-08-01 14:32:42 -030059/** struct v4l2_ctrl - The control structure.
60 * @node: The list node.
Hans Verkuil77068d32011-06-13 18:55:58 -030061 * @ev_subs: The list of control event subscriptions.
Hans Verkuil09965172010-08-01 14:32:42 -030062 * @handler: The handler that owns the control.
63 * @cluster: Point to start of cluster array.
64 * @ncontrols: Number of controls in cluster array.
Hans Verkuil09965172010-08-01 14:32:42 -030065 * @done: Internal flag: set for each processed control.
Hans Verkuil2a863792011-01-11 14:45:03 -030066 * @is_new: Set when the user specified a new value for this control. It
67 * is also set when called from v4l2_ctrl_handler_setup. Drivers
68 * should never set this flag.
Hans Verkuil09965172010-08-01 14:32:42 -030069 * @is_private: If set, then this control is private to its handler and it
70 * will not be added to any other handlers. Drivers can set
71 * this flag.
Hans Verkuil72d877c2011-06-10 05:44:36 -030072 * @is_auto: If set, then this control selects whether the other cluster
73 * members are in 'automatic' mode or 'manual' mode. This is
74 * used for autogain/gain type clusters. Drivers should never
75 * set this flag directly.
Hans Verkuil5626b8c2011-08-26 07:53:53 -030076 * @has_volatiles: If set, then one or more members of the cluster are volatile.
77 * Drivers should never touch this flag.
Hans Verkuil8ac7a942012-09-07 04:46:39 -030078 * @call_notify: If set, then call the handler's notify function whenever the
79 * control's value changes.
Hans Verkuil72d877c2011-06-10 05:44:36 -030080 * @manual_mode_value: If the is_auto flag is set, then this is the value
81 * of the auto control that determines if that control is in
82 * manual mode. So if the value of the auto control equals this
83 * value, then the whole cluster is in manual mode. Drivers should
84 * never set this flag directly.
Hans Verkuil09965172010-08-01 14:32:42 -030085 * @ops: The control ops.
86 * @id: The control ID.
87 * @name: The control name.
88 * @type: The control type.
89 * @minimum: The control's minimum value.
90 * @maximum: The control's maximum value.
91 * @default_value: The control's default value.
92 * @step: The control's step value for non-menu controls.
93 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
94 * easy to skip menu items that are not valid. If bit X is set,
95 * then menu item X is skipped. Of course, this only works for
96 * menus with <= 32 menu items. There are no menus that come
97 * close to that number, so this is OK. Should we ever need more,
98 * then this will have to be extended to a u64 or a bit array.
99 * @qmenu: A const char * array for all menu items. Array entries that are
100 * empty strings ("") correspond to non-existing menu items (this
101 * is in addition to the menu_skip_mask above). The last entry
102 * must be NULL.
103 * @flags: The control's flags.
104 * @cur: The control's current value.
105 * @val: The control's new s32 value.
106 * @val64: The control's new s64 value.
107 * @string: The control's new string value.
108 * @priv: The control's private pointer. For use by the driver. It is
109 * untouched by the control framework. Note that this pointer is
110 * not freed when the control is deleted. Should this be needed
111 * then a new internal bitfield can be added to tell the framework
112 * to free this pointer.
113 */
114struct v4l2_ctrl {
115 /* Administrative fields */
116 struct list_head node;
Hans Verkuil77068d32011-06-13 18:55:58 -0300117 struct list_head ev_subs;
Hans Verkuil09965172010-08-01 14:32:42 -0300118 struct v4l2_ctrl_handler *handler;
119 struct v4l2_ctrl **cluster;
120 unsigned ncontrols;
Hans Verkuil09965172010-08-01 14:32:42 -0300121 unsigned int done:1;
122
Hans Verkuil2a863792011-01-11 14:45:03 -0300123 unsigned int is_new:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300124 unsigned int is_private:1;
Hans Verkuil72d877c2011-06-10 05:44:36 -0300125 unsigned int is_auto:1;
Hans Verkuil5626b8c2011-08-26 07:53:53 -0300126 unsigned int has_volatiles:1;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300127 unsigned int call_notify:1;
Hans Verkuil82a7c042011-06-28 10:43:13 -0300128 unsigned int manual_mode_value:8;
Hans Verkuil09965172010-08-01 14:32:42 -0300129
130 const struct v4l2_ctrl_ops *ops;
131 u32 id;
132 const char *name;
133 enum v4l2_ctrl_type type;
134 s32 minimum, maximum, default_value;
135 union {
136 u32 step;
137 u32 menu_skip_mask;
138 };
Sakari Ailusce580fe2011-08-04 13:51:11 -0300139 union {
140 const char * const *qmenu;
141 const s64 *qmenu_int;
142 };
Hans Verkuil09965172010-08-01 14:32:42 -0300143 unsigned long flags;
144 union {
145 s32 val;
146 s64 val64;
147 char *string;
148 } cur;
149 union {
150 s32 val;
151 s64 val64;
152 char *string;
153 };
154 void *priv;
155};
156
157/** struct v4l2_ctrl_ref - The control reference.
158 * @node: List node for the sorted list.
159 * @next: Single-link list node for the hash.
160 * @ctrl: The actual control information.
Hans Verkuileb5b16e2011-06-14 10:04:06 -0300161 * @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls().
Hans Verkuil09965172010-08-01 14:32:42 -0300162 *
163 * Each control handler has a list of these refs. The list_head is used to
164 * keep a sorted-by-control-ID list of all controls, while the next pointer
165 * is used to link the control in the hash's bucket.
166 */
167struct v4l2_ctrl_ref {
168 struct list_head node;
169 struct v4l2_ctrl_ref *next;
170 struct v4l2_ctrl *ctrl;
Hans Verkuileb5b16e2011-06-14 10:04:06 -0300171 struct v4l2_ctrl_helper *helper;
Hans Verkuil09965172010-08-01 14:32:42 -0300172};
173
174/** struct v4l2_ctrl_handler - The control handler keeps track of all the
175 * controls: both the controls owned by the handler and those inherited
176 * from other handlers.
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300177 * @_lock: Default for "lock".
Hans Verkuil09965172010-08-01 14:32:42 -0300178 * @lock: Lock to control access to this handler and its controls.
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300179 * May be replaced by the user right after init.
Hans Verkuil09965172010-08-01 14:32:42 -0300180 * @ctrls: The list of controls owned by this handler.
181 * @ctrl_refs: The list of control references.
182 * @cached: The last found control reference. It is common that the same
183 * control is needed multiple times, so this is a simple
184 * optimization.
185 * @buckets: Buckets for the hashing. Allows for quick control lookup.
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300186 * @notify: A notify callback that is called whenever the control changes value.
187 * Note that the handler's lock is held when the notify function
188 * is called!
189 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
Hans Verkuil09965172010-08-01 14:32:42 -0300190 * @nr_of_buckets: Total number of buckets in the array.
191 * @error: The error code of the first failed control addition.
192 */
193struct v4l2_ctrl_handler {
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300194 struct mutex _lock;
195 struct mutex *lock;
Hans Verkuil09965172010-08-01 14:32:42 -0300196 struct list_head ctrls;
197 struct list_head ctrl_refs;
198 struct v4l2_ctrl_ref *cached;
199 struct v4l2_ctrl_ref **buckets;
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300200 v4l2_ctrl_notify_fnc notify;
201 void *notify_priv;
Hans Verkuil09965172010-08-01 14:32:42 -0300202 u16 nr_of_buckets;
203 int error;
204};
205
206/** struct v4l2_ctrl_config - Control configuration structure.
207 * @ops: The control ops.
208 * @id: The control ID.
209 * @name: The control name.
210 * @type: The control type.
211 * @min: The control's minimum value.
212 * @max: The control's maximum value.
213 * @step: The control's step value for non-menu controls.
214 * @def: The control's default value.
215 * @flags: The control's flags.
216 * @menu_skip_mask: The control's skip mask for menu controls. This makes it
217 * easy to skip menu items that are not valid. If bit X is set,
218 * then menu item X is skipped. Of course, this only works for
219 * menus with <= 32 menu items. There are no menus that come
220 * close to that number, so this is OK. Should we ever need more,
221 * then this will have to be extended to a u64 or a bit array.
222 * @qmenu: A const char * array for all menu items. Array entries that are
223 * empty strings ("") correspond to non-existing menu items (this
224 * is in addition to the menu_skip_mask above). The last entry
225 * must be NULL.
226 * @is_private: If set, then this control is private to its handler and it
227 * will not be added to any other handlers.
Hans Verkuil09965172010-08-01 14:32:42 -0300228 */
229struct v4l2_ctrl_config {
230 const struct v4l2_ctrl_ops *ops;
231 u32 id;
232 const char *name;
233 enum v4l2_ctrl_type type;
234 s32 min;
235 s32 max;
236 u32 step;
237 s32 def;
238 u32 flags;
239 u32 menu_skip_mask;
Hans Verkuil513521e2010-12-29 14:25:52 -0300240 const char * const *qmenu;
Sakari Ailusce580fe2011-08-04 13:51:11 -0300241 const s64 *qmenu_int;
Hans Verkuil09965172010-08-01 14:32:42 -0300242 unsigned int is_private:1;
Hans Verkuil09965172010-08-01 14:32:42 -0300243};
244
245/** v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
246 *
247 * This works for all standard V4L2 controls.
248 * For non-standard controls it will only fill in the given arguments
249 * and @name will be NULL.
250 *
251 * This function will overwrite the contents of @name, @type and @flags.
252 * The contents of @min, @max, @step and @def may be modified depending on
253 * the type.
254 *
255 * Do not use in drivers! It is used internally for backwards compatibility
256 * control handling only. Once all drivers are converted to use the new
257 * control framework this function will no longer be exported.
258 */
259void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
260 s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags);
261
262
Andy Walls6cd247e2013-03-09 05:55:11 -0300263/** v4l2_ctrl_handler_init_class() - Initialize the control handler.
Hans Verkuil09965172010-08-01 14:32:42 -0300264 * @hdl: The control handler.
265 * @nr_of_controls_hint: A hint of how many controls this handler is
266 * expected to refer to. This is the total number, so including
267 * any inherited controls. It doesn't have to be precise, but if
268 * it is way off, then you either waste memory (too many buckets
269 * are allocated) or the control lookup becomes slower (not enough
270 * buckets are allocated, so there are more slow list lookups).
271 * It will always work, though.
Andy Walls6cd247e2013-03-09 05:55:11 -0300272 * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
273 * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
Hans Verkuil09965172010-08-01 14:32:42 -0300274 *
275 * Returns an error if the buckets could not be allocated. This error will
276 * also be stored in @hdl->error.
Andy Walls6cd247e2013-03-09 05:55:11 -0300277 *
278 * Never use this call directly, always use the v4l2_ctrl_handler_init
279 * macro that hides the @key and @name arguments.
Hans Verkuil09965172010-08-01 14:32:42 -0300280 */
Andy Walls6cd247e2013-03-09 05:55:11 -0300281int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
282 unsigned nr_of_controls_hint,
283 struct lock_class_key *key, const char *name);
284
285#ifdef CONFIG_LOCKDEP
286#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
287( \
288 ({ \
289 static struct lock_class_key _key; \
290 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
291 &_key, \
292 KBUILD_BASENAME ":" \
293 __stringify(__LINE__) ":" \
294 "(" #hdl ")->_lock"); \
295 }) \
296)
297#else
298#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
299 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
300#endif
Hans Verkuil09965172010-08-01 14:32:42 -0300301
302/** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
303 * the control list.
304 * @hdl: The control handler.
305 *
306 * Does nothing if @hdl == NULL.
307 */
308void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
309
310/** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
311 * to the handler to initialize the hardware to the current control values.
312 * @hdl: The control handler.
313 *
314 * Button controls will be skipped, as are read-only controls.
315 *
316 * If @hdl == NULL, then this just returns 0.
317 */
318int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
319
320/** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
321 * @hdl: The control handler.
322 * @prefix: The prefix to use when logging the control values. If the
323 * prefix does not end with a space, then ": " will be added
324 * after the prefix. If @prefix == NULL, then no prefix will be
325 * used.
326 *
327 * For use with VIDIOC_LOG_STATUS.
328 *
329 * Does nothing if @hdl == NULL.
330 */
331void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
332 const char *prefix);
333
334/** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
335 * control.
336 * @hdl: The control handler.
337 * @cfg: The control's configuration data.
338 * @priv: The control's driver-specific private data.
339 *
340 * If the &v4l2_ctrl struct could not be allocated then NULL is returned
341 * and @hdl->error is set to the error code (if it wasn't set already).
342 */
343struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
344 const struct v4l2_ctrl_config *cfg, void *priv);
345
346/** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control.
347 * @hdl: The control handler.
348 * @ops: The control ops.
349 * @id: The control ID.
350 * @min: The control's minimum value.
351 * @max: The control's maximum value.
352 * @step: The control's step value
353 * @def: The control's default value.
354 *
355 * If the &v4l2_ctrl struct could not be allocated, or the control
356 * ID is not known, then NULL is returned and @hdl->error is set to the
357 * appropriate error code (if it wasn't set already).
358 *
359 * If @id refers to a menu control, then this function will return NULL.
360 *
361 * Use v4l2_ctrl_new_std_menu() when adding menu controls.
362 */
363struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
364 const struct v4l2_ctrl_ops *ops,
365 u32 id, s32 min, s32 max, u32 step, s32 def);
366
367/** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control.
368 * @hdl: The control handler.
369 * @ops: The control ops.
370 * @id: The control ID.
371 * @max: The control's maximum value.
372 * @mask: The control's skip mask for menu controls. This makes it
373 * easy to skip menu items that are not valid. If bit X is set,
374 * then menu item X is skipped. Of course, this only works for
375 * menus with <= 32 menu items. There are no menus that come
376 * close to that number, so this is OK. Should we ever need more,
377 * then this will have to be extended to a u64 or a bit array.
378 * @def: The control's default value.
379 *
380 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
381 * determines which menu items are to be skipped.
382 *
383 * If @id refers to a non-menu control, then this function will return NULL.
384 */
385struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
386 const struct v4l2_ctrl_ops *ops,
387 u32 id, s32 max, s32 mask, s32 def);
388
Lad, Prabhakar117a7112012-09-18 15:54:38 -0300389/** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
390 * with driver specific menu.
391 * @hdl: The control handler.
392 * @ops: The control ops.
393 * @id: The control ID.
394 * @max: The control's maximum value.
395 * @mask: The control's skip mask for menu controls. This makes it
396 * easy to skip menu items that are not valid. If bit X is set,
397 * then menu item X is skipped. Of course, this only works for
398 * menus with <= 32 menu items. There are no menus that come
399 * close to that number, so this is OK. Should we ever need more,
400 * then this will have to be extended to a u64 or a bit array.
401 * @def: The control's default value.
402 * @qmenu: The new menu.
403 *
404 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
405 * menu of this control.
406 *
407 */
408struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
409 const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
410 s32 mask, s32 def, const char * const *qmenu);
411
Sylwester Nawrocki515f3282012-05-06 15:30:44 -0300412/** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
413 * @hdl: The control handler.
414 * @ops: The control ops.
415 * @id: The control ID.
416 * @max: The control's maximum value.
417 * @def: The control's default value.
418 * @qmenu_int: The control's menu entries.
419 *
420 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
421 * takes as an argument an array of integers determining the menu items.
422 *
423 * If @id refers to a non-integer-menu control, then this function will return NULL.
424 */
425struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
426 const struct v4l2_ctrl_ops *ops,
427 u32 id, s32 max, s32 def, const s64 *qmenu_int);
428
Hans Verkuil09965172010-08-01 14:32:42 -0300429/** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
430 * @hdl: The control handler.
431 * @ctrl: The control to add.
432 *
433 * It will return NULL if it was unable to add the control reference.
434 * If the control already belonged to the handler, then it will do
435 * nothing and just return @ctrl.
436 */
437struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
438 struct v4l2_ctrl *ctrl);
439
440/** v4l2_ctrl_add_handler() - Add all controls from handler @add to
441 * handler @hdl.
442 * @hdl: The control handler.
443 * @add: The control handler whose controls you want to add to
444 * the @hdl control handler.
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300445 * @filter: This function will filter which controls should be added.
Hans Verkuil09965172010-08-01 14:32:42 -0300446 *
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300447 * Does nothing if either of the two handlers is a NULL pointer.
448 * If @filter is NULL, then all controls are added. Otherwise only those
449 * controls for which @filter returns true will be added.
Hans Verkuil09965172010-08-01 14:32:42 -0300450 * In case of an error @hdl->error will be set to the error code (if it
451 * wasn't set already).
452 */
453int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300454 struct v4l2_ctrl_handler *add,
455 bool (*filter)(const struct v4l2_ctrl *ctrl));
Hans Verkuil09965172010-08-01 14:32:42 -0300456
Hans Verkuil34a6b7d2012-09-14 07:15:03 -0300457/** v4l2_ctrl_radio_filter() - Standard filter for radio controls.
458 * @ctrl: The control that is filtered.
459 *
460 * This will return true for any controls that are valid for radio device
461 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
462 * transmitter class controls.
463 *
464 * This function is to be used with v4l2_ctrl_add_handler().
465 */
466bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
Hans Verkuil09965172010-08-01 14:32:42 -0300467
468/** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
469 * @ncontrols: The number of controls in this cluster.
470 * @controls: The cluster control array of size @ncontrols.
471 */
472void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
473
474
Hans Verkuil72d877c2011-06-10 05:44:36 -0300475/** v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to
476 * that cluster and set it up for autofoo/foo-type handling.
477 * @ncontrols: The number of controls in this cluster.
478 * @controls: The cluster control array of size @ncontrols. The first control
479 * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
480 * @manual_val: The value for the first control in the cluster that equals the
481 * manual setting.
482 * @set_volatile: If true, then all controls except the first auto control will
Hans Verkuil88365102011-08-26 07:35:14 -0300483 * be volatile.
Hans Verkuil72d877c2011-06-10 05:44:36 -0300484 *
485 * Use for control groups where one control selects some automatic feature and
486 * the other controls are only active whenever the automatic feature is turned
487 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
488 * red and blue balance, etc.
489 *
490 * The behavior of such controls is as follows:
491 *
492 * When the autofoo control is set to automatic, then any manual controls
493 * are set to inactive and any reads will call g_volatile_ctrl (if the control
494 * was marked volatile).
495 *
496 * When the autofoo control is set to manual, then any manual controls will
497 * be marked active, and any reads will just return the current value without
498 * going through g_volatile_ctrl.
499 *
500 * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag
501 * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
502 * if autofoo is in auto mode.
503 */
504void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
505 u8 manual_val, bool set_volatile);
506
507
Hans Verkuil09965172010-08-01 14:32:42 -0300508/** v4l2_ctrl_find() - Find a control with the given ID.
509 * @hdl: The control handler.
510 * @id: The control ID to find.
511 *
512 * If @hdl == NULL this will return NULL as well. Will lock the handler so
513 * do not use from inside &v4l2_ctrl_ops.
514 */
515struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
516
517/** v4l2_ctrl_activate() - Make the control active or inactive.
518 * @ctrl: The control to (de)activate.
519 * @active: True if the control should become active.
520 *
521 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
522 * Does nothing if @ctrl == NULL.
523 * This will usually be called from within the s_ctrl op.
Hans Verkuil6e239392011-06-07 11:13:44 -0300524 * The V4L2_EVENT_CTRL event will be generated afterwards.
Hans Verkuil09965172010-08-01 14:32:42 -0300525 *
Hans Verkuil6e239392011-06-07 11:13:44 -0300526 * This function assumes that the control handler is locked.
Hans Verkuil09965172010-08-01 14:32:42 -0300527 */
528void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
529
530/** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
531 * @ctrl: The control to (de)activate.
532 * @grabbed: True if the control should become grabbed.
533 *
534 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
535 * Does nothing if @ctrl == NULL.
Hans Verkuil6e239392011-06-07 11:13:44 -0300536 * The V4L2_EVENT_CTRL event will be generated afterwards.
Hans Verkuil09965172010-08-01 14:32:42 -0300537 * This will usually be called when starting or stopping streaming in the
538 * driver.
539 *
Hans Verkuil6e239392011-06-07 11:13:44 -0300540 * This function assumes that the control handler is not locked and will
541 * take the lock itself.
Hans Verkuil09965172010-08-01 14:32:42 -0300542 */
543void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
544
Sylwester Nawrocki2ccbe772013-01-19 15:51:55 -0300545/** v4l2_ctrl_modify_range() - Update the range of a control.
546 * @ctrl: The control to update.
547 * @min: The control's minimum value.
548 * @max: The control's maximum value.
549 * @step: The control's step value
550 * @def: The control's default value.
551 *
552 * Update the range of a control on the fly. This works for control types
553 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
554 * @step value is interpreted as a menu_skip_mask.
555 *
556 * An error is returned if one of the range arguments is invalid for this
557 * control type.
558 *
559 * This function assumes that the control handler is not locked and will
560 * take the lock itself.
561 */
562int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
563 s32 min, s32 max, u32 step, s32 def);
564
Hans Verkuil09965172010-08-01 14:32:42 -0300565/** v4l2_ctrl_lock() - Helper function to lock the handler
566 * associated with the control.
567 * @ctrl: The control to lock.
568 */
569static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
570{
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300571 mutex_lock(ctrl->handler->lock);
Hans Verkuil09965172010-08-01 14:32:42 -0300572}
573
Frank Schaeferb594a752013-10-10 14:21:32 -0300574/** v4l2_ctrl_unlock() - Helper function to unlock the handler
Hans Verkuil09965172010-08-01 14:32:42 -0300575 * associated with the control.
576 * @ctrl: The control to unlock.
577 */
578static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
579{
Sakari Ailus77e7c4e2012-01-24 21:05:34 -0300580 mutex_unlock(ctrl->handler->lock);
Hans Verkuil09965172010-08-01 14:32:42 -0300581}
582
Hans Verkuil8ac7a942012-09-07 04:46:39 -0300583/** v4l2_ctrl_notify() - Function to set a notify callback for a control.
584 * @ctrl: The control.
585 * @notify: The callback function.
586 * @priv: The callback private handle, passed as argument to the callback.
587 *
588 * This function sets a callback function for the control. If @ctrl is NULL,
589 * then it will do nothing. If @notify is NULL, then the notify callback will
590 * be removed.
591 *
592 * There can be only one notify. If another already exists, then a WARN_ON
593 * will be issued and the function will do nothing.
594 */
595void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv);
596
Hans Verkuil09965172010-08-01 14:32:42 -0300597/** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
598 * @ctrl: The control.
599 *
600 * This returns the control's value safely by going through the control
601 * framework. This function will lock the control's handler, so it cannot be
602 * used from within the &v4l2_ctrl_ops functions.
603 *
604 * This function is for integer type controls only.
605 */
606s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
607
608/** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver.
609 * @ctrl: The control.
610 * @val: The new value.
611 *
612 * This set the control's new value safely by going through the control
613 * framework. This function will lock the control's handler, so it cannot be
614 * used from within the &v4l2_ctrl_ops functions.
615 *
616 * This function is for integer type controls only.
617 */
618int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
619
Laurent Pinchart03d52852012-07-23 09:15:21 -0300620/** v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value from within a driver.
621 * @ctrl: The control.
622 *
623 * This returns the control's value safely by going through the control
624 * framework. This function will lock the control's handler, so it cannot be
625 * used from within the &v4l2_ctrl_ops functions.
626 *
627 * This function is for 64-bit integer type controls only.
628 */
629s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
630
631/** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value from within a driver.
632 * @ctrl: The control.
633 * @val: The new value.
634 *
635 * This set the control's new value safely by going through the control
636 * framework. This function will lock the control's handler, so it cannot be
637 * used from within the &v4l2_ctrl_ops functions.
638 *
639 * This function is for 64-bit integer type controls only.
640 */
641int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
642
Hans Verkuilce727572011-06-10 05:56:39 -0300643/* Internal helper functions that deal with control events. */
Hans de Goede3e3661492012-04-08 12:59:47 -0300644extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
645void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
646void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
Hans Verkuil6e239392011-06-07 11:13:44 -0300647
Hans Verkuile2ecb252012-02-02 08:20:53 -0300648/* Can be used as a vidioc_log_status function that just dumps all controls
649 associated with the filehandle. */
650int v4l2_ctrl_log_status(struct file *file, void *fh);
651
Hans Verkuila26243b2012-01-27 16:18:42 -0300652/* Can be used as a vidioc_subscribe_event function that just subscribes
653 control events. */
654int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
Hans Verkuil85f5fe32012-09-04 11:46:09 -0300655 const struct v4l2_event_subscription *sub);
Hans Verkuila26243b2012-01-27 16:18:42 -0300656
657/* Can be used as a poll function that just polls for control events. */
658unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
659
Hans Verkuil09965172010-08-01 14:32:42 -0300660/* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
661int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
662int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
663int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
Hans Verkuilab892ba2011-06-07 06:47:18 -0300664int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
665 struct v4l2_control *ctrl);
Hans Verkuil09965172010-08-01 14:32:42 -0300666int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
667int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
Hans Verkuilab892ba2011-06-07 06:47:18 -0300668int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
669 struct v4l2_ext_controls *c);
Hans Verkuil09965172010-08-01 14:32:42 -0300670
671/* Helpers for subdevices. If the associated ctrl_handler == NULL then they
672 will all return -EINVAL. */
673int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
674int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
675int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
676int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
677int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
678int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
679int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
680
Sylwester Nawrocki22fa4272013-01-22 19:00:23 -0300681/* Can be used as a subscribe_event function that just subscribes control
682 events. */
683int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
684 struct v4l2_event_subscription *sub);
685
Sylwester Nawrockiffa9b9f2013-01-22 19:01:02 -0300686/* Log all controls owned by subdev's control handler. */
687int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
688
Hans Verkuil09965172010-08-01 14:32:42 -0300689#endif