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