xref: /linux/include/media/v4l2-ctrls.h (revision 56fb34d86e875dbb0d3e6a81c5d3d035db373031)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  V4L2 controls support header.
4  *
5  *  Copyright (C) 2010  Hans Verkuil <hverkuil@xs4all.nl>
6  */
7 
8 #ifndef _V4L2_CTRLS_H
9 #define _V4L2_CTRLS_H
10 
11 #include <linux/list.h>
12 #include <linux/mutex.h>
13 #include <linux/videodev2.h>
14 #include <media/media-request.h>
15 
16 /*
17  * Include the stateless codec compound control definitions.
18  * This will move to the public headers once this API is fully stable.
19  */
20 #include <media/mpeg2-ctrls.h>
21 #include <media/fwht-ctrls.h>
22 #include <media/h264-ctrls.h>
23 #include <media/vp8-ctrls.h>
24 
25 /* forward references */
26 struct file;
27 struct v4l2_ctrl_handler;
28 struct v4l2_ctrl_helper;
29 struct v4l2_ctrl;
30 struct video_device;
31 struct v4l2_subdev;
32 struct v4l2_subscribed_event;
33 struct v4l2_fh;
34 struct poll_table_struct;
35 
36 /**
37  * union v4l2_ctrl_ptr - A pointer to a control value.
38  * @p_s32:			Pointer to a 32-bit signed value.
39  * @p_s64:			Pointer to a 64-bit signed value.
40  * @p_u8:			Pointer to a 8-bit unsigned value.
41  * @p_u16:			Pointer to a 16-bit unsigned value.
42  * @p_u32:			Pointer to a 32-bit unsigned value.
43  * @p_char:			Pointer to a string.
44  * @p_mpeg2_slice_params:	Pointer to a MPEG2 slice parameters structure.
45  * @p_mpeg2_quantization:	Pointer to a MPEG2 quantization data structure.
46  * @p_fwht_params:		Pointer to a FWHT stateless parameters structure.
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_scaling_matrix:	Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
50  * @p_h264_slice_params:	Pointer to a struct v4l2_ctrl_h264_slice_params.
51  * @p_h264_decode_params:	Pointer to a struct v4l2_ctrl_h264_decode_params.
52  * @p_vp8_frame_header:		Pointer to a VP8 frame header structure.
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_mpeg2_slice_params *p_mpeg2_slice_params;
63 	struct v4l2_ctrl_mpeg2_quantization *p_mpeg2_quantization;
64 	struct v4l2_ctrl_fwht_params *p_fwht_params;
65 	struct v4l2_ctrl_h264_sps *p_h264_sps;
66 	struct v4l2_ctrl_h264_pps *p_h264_pps;
67 	struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
68 	struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
69 	struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
70 	struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
71 	void *p;
72 };
73 
74 /**
75  * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
76  *
77  * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
78  *		for volatile (and usually read-only) controls such as a control
79  *		that returns the current signal strength which changes
80  *		continuously.
81  *		If not set, then the currently cached value will be returned.
82  * @try_ctrl:	Test whether the control's value is valid. Only relevant when
83  *		the usual min/max/step checks are not sufficient.
84  * @s_ctrl:	Actually set the new control value. s_ctrl is compulsory. The
85  *		ctrl->handler->lock is held when these ops are called, so no
86  *		one else can access controls owned by that handler.
87  */
88 struct v4l2_ctrl_ops {
89 	int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
90 	int (*try_ctrl)(struct v4l2_ctrl *ctrl);
91 	int (*s_ctrl)(struct v4l2_ctrl *ctrl);
92 };
93 
94 /**
95  * struct v4l2_ctrl_type_ops - The control type operations that the driver
96  *			       has to provide.
97  *
98  * @equal: return true if both values are equal.
99  * @init: initialize the value.
100  * @log: log the value.
101  * @validate: validate the value. Return 0 on success and a negative value
102  *	otherwise.
103  */
104 struct v4l2_ctrl_type_ops {
105 	bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
106 		      union v4l2_ctrl_ptr ptr1,
107 		      union v4l2_ctrl_ptr ptr2);
108 	void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
109 		     union v4l2_ctrl_ptr ptr);
110 	void (*log)(const struct v4l2_ctrl *ctrl);
111 	int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
112 			union v4l2_ctrl_ptr ptr);
113 };
114 
115 /**
116  * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
117  *	that should be called when a control value has changed.
118  *
119  * @ctrl: pointer to struct &v4l2_ctrl
120  * @priv: control private data
121  *
122  * This typedef definition is used as an argument to v4l2_ctrl_notify()
123  * and as an argument at struct &v4l2_ctrl_handler.
124  */
125 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
126 
127 /**
128  * struct v4l2_ctrl - The control structure.
129  *
130  * @node:	The list node.
131  * @ev_subs:	The list of control event subscriptions.
132  * @handler:	The handler that owns the control.
133  * @cluster:	Point to start of cluster array.
134  * @ncontrols:	Number of controls in cluster array.
135  * @done:	Internal flag: set for each processed control.
136  * @is_new:	Set when the user specified a new value for this control. It
137  *		is also set when called from v4l2_ctrl_handler_setup(). Drivers
138  *		should never set this flag.
139  * @has_changed: Set when the current value differs from the new value. Drivers
140  *		should never use this flag.
141  * @is_private: If set, then this control is private to its handler and it
142  *		will not be added to any other handlers. Drivers can set
143  *		this flag.
144  * @is_auto:   If set, then this control selects whether the other cluster
145  *		members are in 'automatic' mode or 'manual' mode. This is
146  *		used for autogain/gain type clusters. Drivers should never
147  *		set this flag directly.
148  * @is_int:    If set, then this control has a simple integer value (i.e. it
149  *		uses ctrl->val).
150  * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
151  * @is_ptr:	If set, then this control is an array and/or has type >=
152  *		%V4L2_CTRL_COMPOUND_TYPES
153  *		and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
154  *		v4l2_ext_control uses field p to point to the data.
155  * @is_array: If set, then this control contains an N-dimensional array.
156  * @has_volatiles: If set, then one or more members of the cluster are volatile.
157  *		Drivers should never touch this flag.
158  * @call_notify: If set, then call the handler's notify function whenever the
159  *		control's value changes.
160  * @manual_mode_value: If the is_auto flag is set, then this is the value
161  *		of the auto control that determines if that control is in
162  *		manual mode. So if the value of the auto control equals this
163  *		value, then the whole cluster is in manual mode. Drivers should
164  *		never set this flag directly.
165  * @ops:	The control ops.
166  * @type_ops:	The control type ops.
167  * @id:	The control ID.
168  * @name:	The control name.
169  * @type:	The control type.
170  * @minimum:	The control's minimum value.
171  * @maximum:	The control's maximum value.
172  * @default_value: The control's default value.
173  * @step:	The control's step value for non-menu controls.
174  * @elems:	The number of elements in the N-dimensional array.
175  * @elem_size:	The size in bytes of the control.
176  * @dims:	The size of each dimension.
177  * @nr_of_dims:The number of dimensions in @dims.
178  * @menu_skip_mask: The control's skip mask for menu controls. This makes it
179  *		easy to skip menu items that are not valid. If bit X is set,
180  *		then menu item X is skipped. Of course, this only works for
181  *		menus with <= 32 menu items. There are no menus that come
182  *		close to that number, so this is OK. Should we ever need more,
183  *		then this will have to be extended to a u64 or a bit array.
184  * @qmenu:	A const char * array for all menu items. Array entries that are
185  *		empty strings ("") correspond to non-existing menu items (this
186  *		is in addition to the menu_skip_mask above). The last entry
187  *		must be NULL.
188  *		Used only if the @type is %V4L2_CTRL_TYPE_MENU.
189  * @qmenu_int:	A 64-bit integer array for with integer menu items.
190  *		The size of array must be equal to the menu size, e. g.:
191  *		:math:`ceil(\frac{maximum - minimum}{step}) + 1`.
192  *		Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
193  * @flags:	The control's flags.
194  * @cur:	Structure to store the current value.
195  * @cur.val:	The control's current value, if the @type is represented via
196  *		a u32 integer (see &enum v4l2_ctrl_type).
197  * @val:	The control's new s32 value.
198  * @priv:	The control's private pointer. For use by the driver. It is
199  *		untouched by the control framework. Note that this pointer is
200  *		not freed when the control is deleted. Should this be needed
201  *		then a new internal bitfield can be added to tell the framework
202  *		to free this pointer.
203  * @p_cur:	The control's current value represented via a union which
204  *		provides a standard way of accessing control types
205  *		through a pointer.
206  * @p_new:	The control's new value represented via a union which provides
207  *		a standard way of accessing control types
208  *		through a pointer.
209  */
210 struct v4l2_ctrl {
211 	/* Administrative fields */
212 	struct list_head node;
213 	struct list_head ev_subs;
214 	struct v4l2_ctrl_handler *handler;
215 	struct v4l2_ctrl **cluster;
216 	unsigned int ncontrols;
217 
218 	unsigned int done:1;
219 
220 	unsigned int is_new:1;
221 	unsigned int has_changed:1;
222 	unsigned int is_private:1;
223 	unsigned int is_auto:1;
224 	unsigned int is_int:1;
225 	unsigned int is_string:1;
226 	unsigned int is_ptr:1;
227 	unsigned int is_array:1;
228 	unsigned int has_volatiles:1;
229 	unsigned int call_notify:1;
230 	unsigned int manual_mode_value:8;
231 
232 	const struct v4l2_ctrl_ops *ops;
233 	const struct v4l2_ctrl_type_ops *type_ops;
234 	u32 id;
235 	const char *name;
236 	enum v4l2_ctrl_type type;
237 	s64 minimum, maximum, default_value;
238 	u32 elems;
239 	u32 elem_size;
240 	u32 dims[V4L2_CTRL_MAX_DIMS];
241 	u32 nr_of_dims;
242 	union {
243 		u64 step;
244 		u64 menu_skip_mask;
245 	};
246 	union {
247 		const char * const *qmenu;
248 		const s64 *qmenu_int;
249 	};
250 	unsigned long flags;
251 	void *priv;
252 	s32 val;
253 	struct {
254 		s32 val;
255 	} cur;
256 
257 	union v4l2_ctrl_ptr p_new;
258 	union v4l2_ctrl_ptr p_cur;
259 };
260 
261 /**
262  * struct v4l2_ctrl_ref - The control reference.
263  *
264  * @node:	List node for the sorted list.
265  * @next:	Single-link list node for the hash.
266  * @ctrl:	The actual control information.
267  * @helper:	Pointer to helper struct. Used internally in
268  *		``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
269  * @from_other_dev: If true, then @ctrl was defined in another
270  *		device than the &struct v4l2_ctrl_handler.
271  * @req_done:	Internal flag: if the control handler containing this control
272  *		reference is bound to a media request, then this is set when
273  *		the control has been applied. This prevents applying controls
274  *		from a cluster with multiple controls twice (when the first
275  *		control of a cluster is applied, they all are).
276  * @req:	If set, this refers to another request that sets this control.
277  * @p_req:	If the control handler containing this control reference
278  *		is bound to a media request, then this points to the
279  *		value of the control that should be applied when the request
280  *		is executed, or to the value of the control at the time
281  *		that the request was completed.
282  *
283  * Each control handler has a list of these refs. The list_head is used to
284  * keep a sorted-by-control-ID list of all controls, while the next pointer
285  * is used to link the control in the hash's bucket.
286  */
287 struct v4l2_ctrl_ref {
288 	struct list_head node;
289 	struct v4l2_ctrl_ref *next;
290 	struct v4l2_ctrl *ctrl;
291 	struct v4l2_ctrl_helper *helper;
292 	bool from_other_dev;
293 	bool req_done;
294 	struct v4l2_ctrl_ref *req;
295 	union v4l2_ctrl_ptr p_req;
296 };
297 
298 /**
299  * struct v4l2_ctrl_handler - The control handler keeps track of all the
300  *	controls: both the controls owned by the handler and those inherited
301  *	from other handlers.
302  *
303  * @_lock:	Default for "lock".
304  * @lock:	Lock to control access to this handler and its controls.
305  *		May be replaced by the user right after init.
306  * @ctrls:	The list of controls owned by this handler.
307  * @ctrl_refs:	The list of control references.
308  * @cached:	The last found control reference. It is common that the same
309  *		control is needed multiple times, so this is a simple
310  *		optimization.
311  * @buckets:	Buckets for the hashing. Allows for quick control lookup.
312  * @notify:	A notify callback that is called whenever the control changes
313  *		value.
314  *		Note that the handler's lock is held when the notify function
315  *		is called!
316  * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
317  * @nr_of_buckets: Total number of buckets in the array.
318  * @error:	The error code of the first failed control addition.
319  * @request_is_queued: True if the request was queued.
320  * @requests:	List to keep track of open control handler request objects.
321  *		For the parent control handler (@req_obj.req == NULL) this
322  *		is the list header. When the parent control handler is
323  *		removed, it has to unbind and put all these requests since
324  *		they refer to the parent.
325  * @requests_queued: List of the queued requests. This determines the order
326  *		in which these controls are applied. Once the request is
327  *		completed it is removed from this list.
328  * @req_obj:	The &struct media_request_object, used to link into a
329  *		&struct media_request. This request object has a refcount.
330  */
331 struct v4l2_ctrl_handler {
332 	struct mutex _lock;
333 	struct mutex *lock;
334 	struct list_head ctrls;
335 	struct list_head ctrl_refs;
336 	struct v4l2_ctrl_ref *cached;
337 	struct v4l2_ctrl_ref **buckets;
338 	v4l2_ctrl_notify_fnc notify;
339 	void *notify_priv;
340 	u16 nr_of_buckets;
341 	int error;
342 	bool request_is_queued;
343 	struct list_head requests;
344 	struct list_head requests_queued;
345 	struct media_request_object req_obj;
346 };
347 
348 /**
349  * struct v4l2_ctrl_config - Control configuration structure.
350  *
351  * @ops:	The control ops.
352  * @type_ops:	The control type ops. Only needed for compound controls.
353  * @id:	The control ID.
354  * @name:	The control name.
355  * @type:	The control type.
356  * @min:	The control's minimum value.
357  * @max:	The control's maximum value.
358  * @step:	The control's step value for non-menu controls.
359  * @def:	The control's default value.
360  * @dims:	The size of each dimension.
361  * @elem_size:	The size in bytes of the control.
362  * @flags:	The control's flags.
363  * @menu_skip_mask: The control's skip mask for menu controls. This makes it
364  *		easy to skip menu items that are not valid. If bit X is set,
365  *		then menu item X is skipped. Of course, this only works for
366  *		menus with <= 64 menu items. There are no menus that come
367  *		close to that number, so this is OK. Should we ever need more,
368  *		then this will have to be extended to a bit array.
369  * @qmenu:	A const char * array for all menu items. Array entries that are
370  *		empty strings ("") correspond to non-existing menu items (this
371  *		is in addition to the menu_skip_mask above). The last entry
372  *		must be NULL.
373  * @qmenu_int:	A const s64 integer array for all menu items of the type
374  *		V4L2_CTRL_TYPE_INTEGER_MENU.
375  * @is_private: If set, then this control is private to its handler and it
376  *		will not be added to any other handlers.
377  */
378 struct v4l2_ctrl_config {
379 	const struct v4l2_ctrl_ops *ops;
380 	const struct v4l2_ctrl_type_ops *type_ops;
381 	u32 id;
382 	const char *name;
383 	enum v4l2_ctrl_type type;
384 	s64 min;
385 	s64 max;
386 	u64 step;
387 	s64 def;
388 	u32 dims[V4L2_CTRL_MAX_DIMS];
389 	u32 elem_size;
390 	u32 flags;
391 	u64 menu_skip_mask;
392 	const char * const *qmenu;
393 	const s64 *qmenu_int;
394 	unsigned int is_private:1;
395 };
396 
397 /**
398  * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
399  *
400  * @id: ID of the control
401  * @name: pointer to be filled with a string with the name of the control
402  * @type: pointer for storing the type of the control
403  * @min: pointer for storing the minimum value for the control
404  * @max: pointer for storing the maximum value for the control
405  * @step: pointer for storing the control step
406  * @def: pointer for storing the default value for the control
407  * @flags: pointer for storing the flags to be used on the control
408  *
409  * This works for all standard V4L2 controls.
410  * For non-standard controls it will only fill in the given arguments
411  * and @name content will be set to %NULL.
412  *
413  * This function will overwrite the contents of @name, @type and @flags.
414  * The contents of @min, @max, @step and @def may be modified depending on
415  * the type.
416  *
417  * .. note::
418  *
419  *    Do not use in drivers! It is used internally for backwards compatibility
420  *    control handling only. Once all drivers are converted to use the new
421  *    control framework this function will no longer be exported.
422  */
423 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
424 		    s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
425 
426 
427 /**
428  * v4l2_ctrl_handler_init_class() - Initialize the control handler.
429  * @hdl:	The control handler.
430  * @nr_of_controls_hint: A hint of how many controls this handler is
431  *		expected to refer to. This is the total number, so including
432  *		any inherited controls. It doesn't have to be precise, but if
433  *		it is way off, then you either waste memory (too many buckets
434  *		are allocated) or the control lookup becomes slower (not enough
435  *		buckets are allocated, so there are more slow list lookups).
436  *		It will always work, though.
437  * @key:	Used by the lock validator if CONFIG_LOCKDEP is set.
438  * @name:	Used by the lock validator if CONFIG_LOCKDEP is set.
439  *
440  * .. attention::
441  *
442  *    Never use this call directly, always use the v4l2_ctrl_handler_init()
443  *    macro that hides the @key and @name arguments.
444  *
445  * Return: returns an error if the buckets could not be allocated. This
446  * error will also be stored in @hdl->error.
447  */
448 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
449 				 unsigned int nr_of_controls_hint,
450 				 struct lock_class_key *key, const char *name);
451 
452 #ifdef CONFIG_LOCKDEP
453 
454 /**
455  * v4l2_ctrl_handler_init - helper function to create a static struct
456  *	 &lock_class_key and calls v4l2_ctrl_handler_init_class()
457  *
458  * @hdl:	The control handler.
459  * @nr_of_controls_hint: A hint of how many controls this handler is
460  *		expected to refer to. This is the total number, so including
461  *		any inherited controls. It doesn't have to be precise, but if
462  *		it is way off, then you either waste memory (too many buckets
463  *		are allocated) or the control lookup becomes slower (not enough
464  *		buckets are allocated, so there are more slow list lookups).
465  *		It will always work, though.
466  *
467  * This helper function creates a static struct &lock_class_key and
468  * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
469  * validador.
470  *
471  * Use this helper function to initialize a control handler.
472  */
473 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint)		\
474 (									\
475 	({								\
476 		static struct lock_class_key _key;			\
477 		v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint,	\
478 					&_key,				\
479 					KBUILD_BASENAME ":"		\
480 					__stringify(__LINE__) ":"	\
481 					"(" #hdl ")->_lock");		\
482 	})								\
483 )
484 #else
485 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint)		\
486 	v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
487 #endif
488 
489 /**
490  * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
491  * the control list.
492  * @hdl:	The control handler.
493  *
494  * Does nothing if @hdl == NULL.
495  */
496 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
497 
498 /**
499  * v4l2_ctrl_lock() - Helper function to lock the handler
500  * associated with the control.
501  * @ctrl:	The control to lock.
502  */
503 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
504 {
505 	mutex_lock(ctrl->handler->lock);
506 }
507 
508 /**
509  * v4l2_ctrl_unlock() - Helper function to unlock the handler
510  * associated with the control.
511  * @ctrl:	The control to unlock.
512  */
513 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
514 {
515 	mutex_unlock(ctrl->handler->lock);
516 }
517 
518 /**
519  * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
520  * to the handler to initialize the hardware to the current control values. The
521  * caller is responsible for acquiring the control handler mutex on behalf of
522  * __v4l2_ctrl_handler_setup().
523  * @hdl:	The control handler.
524  *
525  * Button controls will be skipped, as are read-only controls.
526  *
527  * If @hdl == NULL, then this just returns 0.
528  */
529 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
530 
531 /**
532  * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
533  * to the handler to initialize the hardware to the current control values.
534  * @hdl:	The control handler.
535  *
536  * Button controls will be skipped, as are read-only controls.
537  *
538  * If @hdl == NULL, then this just returns 0.
539  */
540 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
541 
542 /**
543  * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
544  * @hdl:	The control handler.
545  * @prefix:	The prefix to use when logging the control values. If the
546  *		prefix does not end with a space, then ": " will be added
547  *		after the prefix. If @prefix == NULL, then no prefix will be
548  *		used.
549  *
550  * For use with VIDIOC_LOG_STATUS.
551  *
552  * Does nothing if @hdl == NULL.
553  */
554 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
555 				  const char *prefix);
556 
557 /**
558  * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
559  *	control.
560  *
561  * @hdl:	The control handler.
562  * @cfg:	The control's configuration data.
563  * @priv:	The control's driver-specific private data.
564  *
565  * If the &v4l2_ctrl struct could not be allocated then NULL is returned
566  * and @hdl->error is set to the error code (if it wasn't set already).
567  */
568 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
569 				       const struct v4l2_ctrl_config *cfg,
570 				       void *priv);
571 
572 /**
573  * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
574  *	control.
575  *
576  * @hdl:	The control handler.
577  * @ops:	The control ops.
578  * @id:		The control ID.
579  * @min:	The control's minimum value.
580  * @max:	The control's maximum value.
581  * @step:	The control's step value
582  * @def:	The control's default value.
583  *
584  * If the &v4l2_ctrl struct could not be allocated, or the control
585  * ID is not known, then NULL is returned and @hdl->error is set to the
586  * appropriate error code (if it wasn't set already).
587  *
588  * If @id refers to a menu control, then this function will return NULL.
589  *
590  * Use v4l2_ctrl_new_std_menu() when adding menu controls.
591  */
592 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
593 				    const struct v4l2_ctrl_ops *ops,
594 				    u32 id, s64 min, s64 max, u64 step,
595 				    s64 def);
596 
597 /**
598  * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
599  *	menu control.
600  *
601  * @hdl:	The control handler.
602  * @ops:	The control ops.
603  * @id:		The control ID.
604  * @max:	The control's maximum value.
605  * @mask:	The control's skip mask for menu controls. This makes it
606  *		easy to skip menu items that are not valid. If bit X is set,
607  *		then menu item X is skipped. Of course, this only works for
608  *		menus with <= 64 menu items. There are no menus that come
609  *		close to that number, so this is OK. Should we ever need more,
610  *		then this will have to be extended to a bit array.
611  * @def:	The control's default value.
612  *
613  * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
614  * determines which menu items are to be skipped.
615  *
616  * If @id refers to a non-menu control, then this function will return NULL.
617  */
618 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
619 					 const struct v4l2_ctrl_ops *ops,
620 					 u32 id, u8 max, u64 mask, u8 def);
621 
622 /**
623  * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
624  *	with driver specific menu.
625  *
626  * @hdl:	The control handler.
627  * @ops:	The control ops.
628  * @id:	The control ID.
629  * @max:	The control's maximum value.
630  * @mask:	The control's skip mask for menu controls. This makes it
631  *		easy to skip menu items that are not valid. If bit X is set,
632  *		then menu item X is skipped. Of course, this only works for
633  *		menus with <= 64 menu items. There are no menus that come
634  *		close to that number, so this is OK. Should we ever need more,
635  *		then this will have to be extended to a bit array.
636  * @def:	The control's default value.
637  * @qmenu:	The new menu.
638  *
639  * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
640  * menu of this control.
641  *
642  */
643 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
644 					       const struct v4l2_ctrl_ops *ops,
645 					       u32 id, u8 max,
646 					       u64 mask, u8 def,
647 					       const char * const *qmenu);
648 
649 /**
650  * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
651  *
652  * @hdl:	The control handler.
653  * @ops:	The control ops.
654  * @id:	The control ID.
655  * @max:	The control's maximum value.
656  * @def:	The control's default value.
657  * @qmenu_int:	The control's menu entries.
658  *
659  * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
660  * takes as an argument an array of integers determining the menu items.
661  *
662  * If @id refers to a non-integer-menu control, then this function will
663  * return %NULL.
664  */
665 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
666 					 const struct v4l2_ctrl_ops *ops,
667 					 u32 id, u8 max, u8 def,
668 					 const s64 *qmenu_int);
669 
670 /**
671  * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
672  *	used when adding a control handler.
673  *
674  * @ctrl: pointer to struct &v4l2_ctrl.
675  */
676 
677 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
678 
679 /**
680  * v4l2_ctrl_add_handler() - Add all controls from handler @add to
681  *	handler @hdl.
682  *
683  * @hdl:	The control handler.
684  * @add:	The control handler whose controls you want to add to
685  *		the @hdl control handler.
686  * @filter:	This function will filter which controls should be added.
687  * @from_other_dev: If true, then the controls in @add were defined in another
688  *		device than @hdl.
689  *
690  * Does nothing if either of the two handlers is a NULL pointer.
691  * If @filter is NULL, then all controls are added. Otherwise only those
692  * controls for which @filter returns true will be added.
693  * In case of an error @hdl->error will be set to the error code (if it
694  * wasn't set already).
695  */
696 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
697 			  struct v4l2_ctrl_handler *add,
698 			  v4l2_ctrl_filter filter,
699 			  bool from_other_dev);
700 
701 /**
702  * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
703  *
704  * @ctrl:	The control that is filtered.
705  *
706  * This will return true for any controls that are valid for radio device
707  * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
708  * transmitter class controls.
709  *
710  * This function is to be used with v4l2_ctrl_add_handler().
711  */
712 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
713 
714 /**
715  * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
716  *	to that cluster.
717  *
718  * @ncontrols:	The number of controls in this cluster.
719  * @controls:	The cluster control array of size @ncontrols.
720  */
721 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
722 
723 
724 /**
725  * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
726  *	to that cluster and set it up for autofoo/foo-type handling.
727  *
728  * @ncontrols:	The number of controls in this cluster.
729  * @controls:	The cluster control array of size @ncontrols. The first control
730  *		must be the 'auto' control (e.g. autogain, autoexposure, etc.)
731  * @manual_val: The value for the first control in the cluster that equals the
732  *		manual setting.
733  * @set_volatile: If true, then all controls except the first auto control will
734  *		be volatile.
735  *
736  * Use for control groups where one control selects some automatic feature and
737  * the other controls are only active whenever the automatic feature is turned
738  * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
739  * red and blue balance, etc.
740  *
741  * The behavior of such controls is as follows:
742  *
743  * When the autofoo control is set to automatic, then any manual controls
744  * are set to inactive and any reads will call g_volatile_ctrl (if the control
745  * was marked volatile).
746  *
747  * When the autofoo control is set to manual, then any manual controls will
748  * be marked active, and any reads will just return the current value without
749  * going through g_volatile_ctrl.
750  *
751  * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
752  * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
753  * if autofoo is in auto mode.
754  */
755 void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
756 			    struct v4l2_ctrl **controls,
757 			    u8 manual_val, bool set_volatile);
758 
759 
760 /**
761  * v4l2_ctrl_find() - Find a control with the given ID.
762  *
763  * @hdl:	The control handler.
764  * @id:	The control ID to find.
765  *
766  * If @hdl == NULL this will return NULL as well. Will lock the handler so
767  * do not use from inside &v4l2_ctrl_ops.
768  */
769 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
770 
771 /**
772  * v4l2_ctrl_activate() - Make the control active or inactive.
773  * @ctrl:	The control to (de)activate.
774  * @active:	True if the control should become active.
775  *
776  * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
777  * Does nothing if @ctrl == NULL.
778  * This will usually be called from within the s_ctrl op.
779  * The V4L2_EVENT_CTRL event will be generated afterwards.
780  *
781  * This function assumes that the control handler is locked.
782  */
783 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
784 
785 /**
786  * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
787  *
788  * @ctrl:	The control to (de)activate.
789  * @grabbed:	True if the control should become grabbed.
790  *
791  * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
792  * Does nothing if @ctrl == NULL.
793  * The V4L2_EVENT_CTRL event will be generated afterwards.
794  * This will usually be called when starting or stopping streaming in the
795  * driver.
796  *
797  * This function assumes that the control handler is locked by the caller.
798  */
799 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
800 
801 /**
802  * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
803  *
804  * @ctrl:	The control to (de)activate.
805  * @grabbed:	True if the control should become grabbed.
806  *
807  * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
808  * Does nothing if @ctrl == NULL.
809  * The V4L2_EVENT_CTRL event will be generated afterwards.
810  * This will usually be called when starting or stopping streaming in the
811  * driver.
812  *
813  * This function assumes that the control handler is not locked and will
814  * take the lock itself.
815  */
816 static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
817 {
818 	if (!ctrl)
819 		return;
820 
821 	v4l2_ctrl_lock(ctrl);
822 	__v4l2_ctrl_grab(ctrl, grabbed);
823 	v4l2_ctrl_unlock(ctrl);
824 }
825 
826 /**
827  *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
828  *
829  * @ctrl:	The control to update.
830  * @min:	The control's minimum value.
831  * @max:	The control's maximum value.
832  * @step:	The control's step value
833  * @def:	The control's default value.
834  *
835  * Update the range of a control on the fly. This works for control types
836  * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
837  * @step value is interpreted as a menu_skip_mask.
838  *
839  * An error is returned if one of the range arguments is invalid for this
840  * control type.
841  *
842  * The caller is responsible for acquiring the control handler mutex on behalf
843  * of __v4l2_ctrl_modify_range().
844  */
845 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
846 			     s64 min, s64 max, u64 step, s64 def);
847 
848 /**
849  * v4l2_ctrl_modify_range() - Update the range of a control.
850  *
851  * @ctrl:	The control to update.
852  * @min:	The control's minimum value.
853  * @max:	The control's maximum value.
854  * @step:	The control's step value
855  * @def:	The control's default value.
856  *
857  * Update the range of a control on the fly. This works for control types
858  * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
859  * @step value is interpreted as a menu_skip_mask.
860  *
861  * An error is returned if one of the range arguments is invalid for this
862  * control type.
863  *
864  * This function assumes that the control handler is not locked and will
865  * take the lock itself.
866  */
867 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
868 					 s64 min, s64 max, u64 step, s64 def)
869 {
870 	int rval;
871 
872 	v4l2_ctrl_lock(ctrl);
873 	rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
874 	v4l2_ctrl_unlock(ctrl);
875 
876 	return rval;
877 }
878 
879 /**
880  * v4l2_ctrl_notify() - Function to set a notify callback for a control.
881  *
882  * @ctrl:	The control.
883  * @notify:	The callback function.
884  * @priv:	The callback private handle, passed as argument to the callback.
885  *
886  * This function sets a callback function for the control. If @ctrl is NULL,
887  * then it will do nothing. If @notify is NULL, then the notify callback will
888  * be removed.
889  *
890  * There can be only one notify. If another already exists, then a WARN_ON
891  * will be issued and the function will do nothing.
892  */
893 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
894 		      void *priv);
895 
896 /**
897  * v4l2_ctrl_get_name() - Get the name of the control
898  *
899  * @id:		The control ID.
900  *
901  * This function returns the name of the given control ID or NULL if it isn't
902  * a known control.
903  */
904 const char *v4l2_ctrl_get_name(u32 id);
905 
906 /**
907  * v4l2_ctrl_get_menu() - Get the menu string array of the control
908  *
909  * @id:		The control ID.
910  *
911  * This function returns the NULL-terminated menu string array name of the
912  * given control ID or NULL if it isn't a known menu control.
913  */
914 const char * const *v4l2_ctrl_get_menu(u32 id);
915 
916 /**
917  * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
918  *
919  * @id:		The control ID.
920  * @len:	The size of the integer array.
921  *
922  * This function returns the integer array of the given control ID or NULL if it
923  * if it isn't a known integer menu control.
924  */
925 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
926 
927 /**
928  * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
929  *	within a driver.
930  *
931  * @ctrl:	The control.
932  *
933  * This returns the control's value safely by going through the control
934  * framework. This function will lock the control's handler, so it cannot be
935  * used from within the &v4l2_ctrl_ops functions.
936  *
937  * This function is for integer type controls only.
938  */
939 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
940 
941 /**
942  * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
943  *
944  * @ctrl:	The control.
945  * @val:	The new value.
946  *
947  * This sets the control's new value safely by going through the control
948  * framework. This function assumes the control's handler is already locked,
949  * allowing it to be used from within the &v4l2_ctrl_ops functions.
950  *
951  * This function is for integer type controls only.
952  */
953 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
954 
955 /**
956  * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
957  *	within a driver.
958  * @ctrl:	The control.
959  * @val:	The new value.
960  *
961  * This sets the control's new value safely by going through the control
962  * framework. This function will lock the control's handler, so it cannot be
963  * used from within the &v4l2_ctrl_ops functions.
964  *
965  * This function is for integer type controls only.
966  */
967 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
968 {
969 	int rval;
970 
971 	v4l2_ctrl_lock(ctrl);
972 	rval = __v4l2_ctrl_s_ctrl(ctrl, val);
973 	v4l2_ctrl_unlock(ctrl);
974 
975 	return rval;
976 }
977 
978 /**
979  * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
980  *	from within a driver.
981  *
982  * @ctrl:	The control.
983  *
984  * This returns the control's value safely by going through the control
985  * framework. This function will lock the control's handler, so it cannot be
986  * used from within the &v4l2_ctrl_ops functions.
987  *
988  * This function is for 64-bit integer type controls only.
989  */
990 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
991 
992 /**
993  * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
994  *
995  * @ctrl:	The control.
996  * @val:	The new value.
997  *
998  * This sets the control's new value safely by going through the control
999  * framework. This function assumes the control's handler is already locked,
1000  * allowing it to be used from within the &v4l2_ctrl_ops functions.
1001  *
1002  * This function is for 64-bit integer type controls only.
1003  */
1004 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
1005 
1006 /**
1007  * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
1008  *	from within a driver.
1009  *
1010  * @ctrl:	The control.
1011  * @val:	The new value.
1012  *
1013  * This sets the control's new value safely by going through the control
1014  * framework. This function will lock the control's handler, so it cannot be
1015  * used from within the &v4l2_ctrl_ops functions.
1016  *
1017  * This function is for 64-bit integer type controls only.
1018  */
1019 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
1020 {
1021 	int rval;
1022 
1023 	v4l2_ctrl_lock(ctrl);
1024 	rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
1025 	v4l2_ctrl_unlock(ctrl);
1026 
1027 	return rval;
1028 }
1029 
1030 /**
1031  * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
1032  *
1033  * @ctrl:	The control.
1034  * @s:		The new string.
1035  *
1036  * This sets the control's new string safely by going through the control
1037  * framework. This function assumes the control's handler is already locked,
1038  * allowing it to be used from within the &v4l2_ctrl_ops functions.
1039  *
1040  * This function is for string type controls only.
1041  */
1042 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
1043 
1044 /**
1045  * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
1046  *	 from within a driver.
1047  *
1048  * @ctrl:	The control.
1049  * @s:		The new string.
1050  *
1051  * This sets the control's new string safely by going through the control
1052  * framework. This function will lock the control's handler, so it cannot be
1053  * used from within the &v4l2_ctrl_ops functions.
1054  *
1055  * This function is for string type controls only.
1056  */
1057 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
1058 {
1059 	int rval;
1060 
1061 	v4l2_ctrl_lock(ctrl);
1062 	rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
1063 	v4l2_ctrl_unlock(ctrl);
1064 
1065 	return rval;
1066 }
1067 
1068 /* Internal helper functions that deal with control events. */
1069 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
1070 
1071 /**
1072  * v4l2_ctrl_replace - Function to be used as a callback to
1073  *	&struct v4l2_subscribed_event_ops replace\(\)
1074  *
1075  * @old: pointer to struct &v4l2_event with the reported
1076  *	 event;
1077  * @new: pointer to struct &v4l2_event with the modified
1078  *	 event;
1079  */
1080 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
1081 
1082 /**
1083  * v4l2_ctrl_merge - Function to be used as a callback to
1084  *	&struct v4l2_subscribed_event_ops merge(\)
1085  *
1086  * @old: pointer to struct &v4l2_event with the reported
1087  *	 event;
1088  * @new: pointer to struct &v4l2_event with the merged
1089  *	 event;
1090  */
1091 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
1092 
1093 /**
1094  * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
1095  *
1096  * @file: pointer to struct file
1097  * @fh: unused. Kept just to be compatible to the arguments expected by
1098  *	&struct v4l2_ioctl_ops.vidioc_log_status.
1099  *
1100  * Can be used as a vidioc_log_status function that just dumps all controls
1101  * associated with the filehandle.
1102  */
1103 int v4l2_ctrl_log_status(struct file *file, void *fh);
1104 
1105 /**
1106  * v4l2_ctrl_subscribe_event - Subscribes to an event
1107  *
1108  *
1109  * @fh: pointer to struct v4l2_fh
1110  * @sub: pointer to &struct v4l2_event_subscription
1111  *
1112  * Can be used as a vidioc_subscribe_event function that just subscribes
1113  * control events.
1114  */
1115 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
1116 				const struct v4l2_event_subscription *sub);
1117 
1118 /**
1119  * v4l2_ctrl_poll - function to be used as a callback to the poll()
1120  *	That just polls for control events.
1121  *
1122  * @file: pointer to struct file
1123  * @wait: pointer to struct poll_table_struct
1124  */
1125 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
1126 
1127 /**
1128  * v4l2_ctrl_request_setup - helper function to apply control values in a request
1129  *
1130  * @req: The request
1131  * @parent: The parent control handler ('priv' in media_request_object_find())
1132  *
1133  * This is a helper function to call the control handler's s_ctrl callback with
1134  * the control values contained in the request. Do note that this approach of
1135  * applying control values in a request is only applicable to memory-to-memory
1136  * devices.
1137  */
1138 int v4l2_ctrl_request_setup(struct media_request *req,
1139 			     struct v4l2_ctrl_handler *parent);
1140 
1141 /**
1142  * v4l2_ctrl_request_complete - Complete a control handler request object
1143  *
1144  * @req: The request
1145  * @parent: The parent control handler ('priv' in media_request_object_find())
1146  *
1147  * This function is to be called on each control handler that may have had a
1148  * request object associated with it, i.e. control handlers of a driver that
1149  * supports requests.
1150  *
1151  * The function first obtains the values of any volatile controls in the control
1152  * handler and attach them to the request. Then, the function completes the
1153  * request object.
1154  */
1155 void v4l2_ctrl_request_complete(struct media_request *req,
1156 				struct v4l2_ctrl_handler *parent);
1157 
1158 /**
1159  * v4l2_ctrl_request_hdl_find - Find the control handler in the request
1160  *
1161  * @req: The request
1162  * @parent: The parent control handler ('priv' in media_request_object_find())
1163  *
1164  * This function finds the control handler in the request. It may return
1165  * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
1166  * with the returned handler pointer.
1167  *
1168  * If the request is not in state VALIDATING or QUEUED, then this function
1169  * will always return NULL.
1170  *
1171  * Note that in state VALIDATING the req_queue_mutex is held, so
1172  * no objects can be added or deleted from the request.
1173  *
1174  * In state QUEUED it is the driver that will have to ensure this.
1175  */
1176 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
1177 					struct v4l2_ctrl_handler *parent);
1178 
1179 /**
1180  * v4l2_ctrl_request_hdl_put - Put the control handler
1181  *
1182  * @hdl: Put this control handler
1183  *
1184  * This function released the control handler previously obtained from'
1185  * v4l2_ctrl_request_hdl_find().
1186  */
1187 static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
1188 {
1189 	if (hdl)
1190 		media_request_object_put(&hdl->req_obj);
1191 }
1192 
1193 /**
1194  * v4l2_ctrl_request_ctrl_find() - Find a control with the given ID.
1195  *
1196  * @hdl: The control handler from the request.
1197  * @id: The ID of the control to find.
1198  *
1199  * This function returns a pointer to the control if this control is
1200  * part of the request or NULL otherwise.
1201  */
1202 struct v4l2_ctrl *
1203 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
1204 
1205 /* Helpers for ioctl_ops */
1206 
1207 /**
1208  * v4l2_queryctrl - Helper function to implement
1209  *	:ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
1210  *
1211  * @hdl: pointer to &struct v4l2_ctrl_handler
1212  * @qc: pointer to &struct v4l2_queryctrl
1213  *
1214  * If hdl == NULL then they will all return -EINVAL.
1215  */
1216 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
1217 
1218 /**
1219  * v4l2_query_ext_ctrl - Helper function to implement
1220  *	 :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
1221  *
1222  * @hdl: pointer to &struct v4l2_ctrl_handler
1223  * @qc: pointer to &struct v4l2_query_ext_ctrl
1224  *
1225  * If hdl == NULL then they will all return -EINVAL.
1226  */
1227 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
1228 			struct v4l2_query_ext_ctrl *qc);
1229 
1230 /**
1231  * v4l2_querymenu - Helper function to implement
1232  *	:ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
1233  *
1234  * @hdl: pointer to &struct v4l2_ctrl_handler
1235  * @qm: pointer to &struct v4l2_querymenu
1236  *
1237  * If hdl == NULL then they will all return -EINVAL.
1238  */
1239 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
1240 
1241 /**
1242  * v4l2_g_ctrl - Helper function to implement
1243  *	:ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
1244  *
1245  * @hdl: pointer to &struct v4l2_ctrl_handler
1246  * @ctrl: pointer to &struct v4l2_control
1247  *
1248  * If hdl == NULL then they will all return -EINVAL.
1249  */
1250 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
1251 
1252 /**
1253  * v4l2_s_ctrl - Helper function to implement
1254  *	:ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
1255  *
1256  * @fh: pointer to &struct v4l2_fh
1257  * @hdl: pointer to &struct v4l2_ctrl_handler
1258  *
1259  * @ctrl: pointer to &struct v4l2_control
1260  *
1261  * If hdl == NULL then they will all return -EINVAL.
1262  */
1263 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1264 		struct v4l2_control *ctrl);
1265 
1266 /**
1267  * v4l2_g_ext_ctrls - Helper function to implement
1268  *	:ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1269  *
1270  * @hdl: pointer to &struct v4l2_ctrl_handler
1271  * @vdev: pointer to &struct video_device
1272  * @mdev: pointer to &struct media_device
1273  * @c: pointer to &struct v4l2_ext_controls
1274  *
1275  * If hdl == NULL then they will all return -EINVAL.
1276  */
1277 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
1278 		     struct media_device *mdev, struct v4l2_ext_controls *c);
1279 
1280 /**
1281  * v4l2_try_ext_ctrls - Helper function to implement
1282  *	:ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1283  *
1284  * @hdl: pointer to &struct v4l2_ctrl_handler
1285  * @vdev: pointer to &struct video_device
1286  * @mdev: pointer to &struct media_device
1287  * @c: pointer to &struct v4l2_ext_controls
1288  *
1289  * If hdl == NULL then they will all return -EINVAL.
1290  */
1291 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1292 		       struct video_device *vdev,
1293 		       struct media_device *mdev,
1294 		       struct v4l2_ext_controls *c);
1295 
1296 /**
1297  * v4l2_s_ext_ctrls - Helper function to implement
1298  *	:ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
1299  *
1300  * @fh: pointer to &struct v4l2_fh
1301  * @hdl: pointer to &struct v4l2_ctrl_handler
1302  * @vdev: pointer to &struct video_device
1303  * @mdev: pointer to &struct media_device
1304  * @c: pointer to &struct v4l2_ext_controls
1305  *
1306  * If hdl == NULL then they will all return -EINVAL.
1307  */
1308 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
1309 		     struct video_device *vdev,
1310 		     struct media_device *mdev,
1311 		     struct v4l2_ext_controls *c);
1312 
1313 /**
1314  * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
1315  *	as a &struct v4l2_subdev_core_ops subscribe_event function
1316  *	that just subscribes control events.
1317  *
1318  * @sd: pointer to &struct v4l2_subdev
1319  * @fh: pointer to &struct v4l2_fh
1320  * @sub: pointer to &struct v4l2_event_subscription
1321  */
1322 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1323 				     struct v4l2_event_subscription *sub);
1324 
1325 /**
1326  * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
1327  *	 handler.
1328  *
1329  * @sd: pointer to &struct v4l2_subdev
1330  */
1331 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
1332 
1333 #endif
1334