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