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