18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  V4L2 controls support header.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2010  Hans Verkuil <hverkuil@xs4all.nl>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _V4L2_CTRLS_H
98c2ecf20Sopenharmony_ci#define _V4L2_CTRLS_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/list.h>
128c2ecf20Sopenharmony_ci#include <linux/mutex.h>
138c2ecf20Sopenharmony_ci#include <linux/videodev2.h>
148c2ecf20Sopenharmony_ci#include <media/media-request.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*
178c2ecf20Sopenharmony_ci * Include the stateless codec compound control definitions.
188c2ecf20Sopenharmony_ci * This will move to the public headers once this API is fully stable.
198c2ecf20Sopenharmony_ci */
208c2ecf20Sopenharmony_ci#include <media/mpeg2-ctrls.h>
218c2ecf20Sopenharmony_ci#include <media/fwht-ctrls.h>
228c2ecf20Sopenharmony_ci#include <media/h264-ctrls.h>
238c2ecf20Sopenharmony_ci#include <media/vp8-ctrls.h>
248c2ecf20Sopenharmony_ci#include <media/hevc-ctrls.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* forward references */
278c2ecf20Sopenharmony_cistruct file;
288c2ecf20Sopenharmony_cistruct poll_table_struct;
298c2ecf20Sopenharmony_cistruct v4l2_ctrl;
308c2ecf20Sopenharmony_cistruct v4l2_ctrl_handler;
318c2ecf20Sopenharmony_cistruct v4l2_ctrl_helper;
328c2ecf20Sopenharmony_cistruct v4l2_fh;
338c2ecf20Sopenharmony_cistruct v4l2_fwnode_device_properties;
348c2ecf20Sopenharmony_cistruct v4l2_subdev;
358c2ecf20Sopenharmony_cistruct v4l2_subscribed_event;
368c2ecf20Sopenharmony_cistruct video_device;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/**
398c2ecf20Sopenharmony_ci * union v4l2_ctrl_ptr - A pointer to a control value.
408c2ecf20Sopenharmony_ci * @p_s32:			Pointer to a 32-bit signed value.
418c2ecf20Sopenharmony_ci * @p_s64:			Pointer to a 64-bit signed value.
428c2ecf20Sopenharmony_ci * @p_u8:			Pointer to a 8-bit unsigned value.
438c2ecf20Sopenharmony_ci * @p_u16:			Pointer to a 16-bit unsigned value.
448c2ecf20Sopenharmony_ci * @p_u32:			Pointer to a 32-bit unsigned value.
458c2ecf20Sopenharmony_ci * @p_char:			Pointer to a string.
468c2ecf20Sopenharmony_ci * @p_mpeg2_slice_params:	Pointer to a MPEG2 slice parameters structure.
478c2ecf20Sopenharmony_ci * @p_mpeg2_quantization:	Pointer to a MPEG2 quantization data structure.
488c2ecf20Sopenharmony_ci * @p_fwht_params:		Pointer to a FWHT stateless parameters structure.
498c2ecf20Sopenharmony_ci * @p_h264_sps:			Pointer to a struct v4l2_ctrl_h264_sps.
508c2ecf20Sopenharmony_ci * @p_h264_pps:			Pointer to a struct v4l2_ctrl_h264_pps.
518c2ecf20Sopenharmony_ci * @p_h264_scaling_matrix:	Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
528c2ecf20Sopenharmony_ci * @p_h264_slice_params:	Pointer to a struct v4l2_ctrl_h264_slice_params.
538c2ecf20Sopenharmony_ci * @p_h264_decode_params:	Pointer to a struct v4l2_ctrl_h264_decode_params.
548c2ecf20Sopenharmony_ci * @p_h264_pred_weights:	Pointer to a struct v4l2_ctrl_h264_pred_weights.
558c2ecf20Sopenharmony_ci * @p_vp8_frame_header:		Pointer to a VP8 frame header structure.
568c2ecf20Sopenharmony_ci * @p_hevc_sps:			Pointer to an HEVC sequence parameter set structure.
578c2ecf20Sopenharmony_ci * @p_hevc_pps:			Pointer to an HEVC picture parameter set structure.
588c2ecf20Sopenharmony_ci * @p_hevc_slice_params:	Pointer to an HEVC slice parameters structure.
598c2ecf20Sopenharmony_ci * @p_area:			Pointer to an area.
608c2ecf20Sopenharmony_ci * @p:				Pointer to a compound value.
618c2ecf20Sopenharmony_ci * @p_const:			Pointer to a constant compound value.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ciunion v4l2_ctrl_ptr {
648c2ecf20Sopenharmony_ci	s32 *p_s32;
658c2ecf20Sopenharmony_ci	s64 *p_s64;
668c2ecf20Sopenharmony_ci	u8 *p_u8;
678c2ecf20Sopenharmony_ci	u16 *p_u16;
688c2ecf20Sopenharmony_ci	u32 *p_u32;
698c2ecf20Sopenharmony_ci	char *p_char;
708c2ecf20Sopenharmony_ci	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
718c2ecf20Sopenharmony_ci	struct v4l2_ctrl_mpeg2_quantization *p_mpeg2_quantization;
728c2ecf20Sopenharmony_ci	struct v4l2_ctrl_fwht_params *p_fwht_params;
738c2ecf20Sopenharmony_ci	struct v4l2_ctrl_h264_sps *p_h264_sps;
748c2ecf20Sopenharmony_ci	struct v4l2_ctrl_h264_pps *p_h264_pps;
758c2ecf20Sopenharmony_ci	struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
768c2ecf20Sopenharmony_ci	struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
778c2ecf20Sopenharmony_ci	struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
788c2ecf20Sopenharmony_ci	struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
798c2ecf20Sopenharmony_ci	struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
808c2ecf20Sopenharmony_ci	struct v4l2_ctrl_hevc_sps *p_hevc_sps;
818c2ecf20Sopenharmony_ci	struct v4l2_ctrl_hevc_pps *p_hevc_pps;
828c2ecf20Sopenharmony_ci	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
838c2ecf20Sopenharmony_ci	struct v4l2_area *p_area;
848c2ecf20Sopenharmony_ci	void *p;
858c2ecf20Sopenharmony_ci	const void *p_const;
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/**
898c2ecf20Sopenharmony_ci * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
908c2ecf20Sopenharmony_ci * void pointer
918c2ecf20Sopenharmony_ci * @ptr:	The void pointer
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistatic inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	union v4l2_ctrl_ptr p = { .p = ptr };
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	return p;
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/**
1018c2ecf20Sopenharmony_ci * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
1048c2ecf20Sopenharmony_ci *		for volatile (and usually read-only) controls such as a control
1058c2ecf20Sopenharmony_ci *		that returns the current signal strength which changes
1068c2ecf20Sopenharmony_ci *		continuously.
1078c2ecf20Sopenharmony_ci *		If not set, then the currently cached value will be returned.
1088c2ecf20Sopenharmony_ci * @try_ctrl:	Test whether the control's value is valid. Only relevant when
1098c2ecf20Sopenharmony_ci *		the usual min/max/step checks are not sufficient.
1108c2ecf20Sopenharmony_ci * @s_ctrl:	Actually set the new control value. s_ctrl is compulsory. The
1118c2ecf20Sopenharmony_ci *		ctrl->handler->lock is held when these ops are called, so no
1128c2ecf20Sopenharmony_ci *		one else can access controls owned by that handler.
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_cistruct v4l2_ctrl_ops {
1158c2ecf20Sopenharmony_ci	int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
1168c2ecf20Sopenharmony_ci	int (*try_ctrl)(struct v4l2_ctrl *ctrl);
1178c2ecf20Sopenharmony_ci	int (*s_ctrl)(struct v4l2_ctrl *ctrl);
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/**
1218c2ecf20Sopenharmony_ci * struct v4l2_ctrl_type_ops - The control type operations that the driver
1228c2ecf20Sopenharmony_ci *			       has to provide.
1238c2ecf20Sopenharmony_ci *
1248c2ecf20Sopenharmony_ci * @equal: return true if both values are equal.
1258c2ecf20Sopenharmony_ci * @init: initialize the value.
1268c2ecf20Sopenharmony_ci * @log: log the value.
1278c2ecf20Sopenharmony_ci * @validate: validate the value. Return 0 on success and a negative value
1288c2ecf20Sopenharmony_ci *	otherwise.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_cistruct v4l2_ctrl_type_ops {
1318c2ecf20Sopenharmony_ci	bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
1328c2ecf20Sopenharmony_ci		      union v4l2_ctrl_ptr ptr1,
1338c2ecf20Sopenharmony_ci		      union v4l2_ctrl_ptr ptr2);
1348c2ecf20Sopenharmony_ci	void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
1358c2ecf20Sopenharmony_ci		     union v4l2_ctrl_ptr ptr);
1368c2ecf20Sopenharmony_ci	void (*log)(const struct v4l2_ctrl *ctrl);
1378c2ecf20Sopenharmony_ci	int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
1388c2ecf20Sopenharmony_ci			union v4l2_ctrl_ptr ptr);
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/**
1428c2ecf20Sopenharmony_ci * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
1438c2ecf20Sopenharmony_ci *	that should be called when a control value has changed.
1448c2ecf20Sopenharmony_ci *
1458c2ecf20Sopenharmony_ci * @ctrl: pointer to struct &v4l2_ctrl
1468c2ecf20Sopenharmony_ci * @priv: control private data
1478c2ecf20Sopenharmony_ci *
1488c2ecf20Sopenharmony_ci * This typedef definition is used as an argument to v4l2_ctrl_notify()
1498c2ecf20Sopenharmony_ci * and as an argument at struct &v4l2_ctrl_handler.
1508c2ecf20Sopenharmony_ci */
1518c2ecf20Sopenharmony_citypedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/**
1548c2ecf20Sopenharmony_ci * struct v4l2_ctrl - The control structure.
1558c2ecf20Sopenharmony_ci *
1568c2ecf20Sopenharmony_ci * @node:	The list node.
1578c2ecf20Sopenharmony_ci * @ev_subs:	The list of control event subscriptions.
1588c2ecf20Sopenharmony_ci * @handler:	The handler that owns the control.
1598c2ecf20Sopenharmony_ci * @cluster:	Point to start of cluster array.
1608c2ecf20Sopenharmony_ci * @ncontrols:	Number of controls in cluster array.
1618c2ecf20Sopenharmony_ci * @done:	Internal flag: set for each processed control.
1628c2ecf20Sopenharmony_ci * @is_new:	Set when the user specified a new value for this control. It
1638c2ecf20Sopenharmony_ci *		is also set when called from v4l2_ctrl_handler_setup(). Drivers
1648c2ecf20Sopenharmony_ci *		should never set this flag.
1658c2ecf20Sopenharmony_ci * @has_changed: Set when the current value differs from the new value. Drivers
1668c2ecf20Sopenharmony_ci *		should never use this flag.
1678c2ecf20Sopenharmony_ci * @is_private: If set, then this control is private to its handler and it
1688c2ecf20Sopenharmony_ci *		will not be added to any other handlers. Drivers can set
1698c2ecf20Sopenharmony_ci *		this flag.
1708c2ecf20Sopenharmony_ci * @is_auto:   If set, then this control selects whether the other cluster
1718c2ecf20Sopenharmony_ci *		members are in 'automatic' mode or 'manual' mode. This is
1728c2ecf20Sopenharmony_ci *		used for autogain/gain type clusters. Drivers should never
1738c2ecf20Sopenharmony_ci *		set this flag directly.
1748c2ecf20Sopenharmony_ci * @is_int:    If set, then this control has a simple integer value (i.e. it
1758c2ecf20Sopenharmony_ci *		uses ctrl->val).
1768c2ecf20Sopenharmony_ci * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
1778c2ecf20Sopenharmony_ci * @is_ptr:	If set, then this control is an array and/or has type >=
1788c2ecf20Sopenharmony_ci *		%V4L2_CTRL_COMPOUND_TYPES
1798c2ecf20Sopenharmony_ci *		and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
1808c2ecf20Sopenharmony_ci *		v4l2_ext_control uses field p to point to the data.
1818c2ecf20Sopenharmony_ci * @is_array: If set, then this control contains an N-dimensional array.
1828c2ecf20Sopenharmony_ci * @has_volatiles: If set, then one or more members of the cluster are volatile.
1838c2ecf20Sopenharmony_ci *		Drivers should never touch this flag.
1848c2ecf20Sopenharmony_ci * @call_notify: If set, then call the handler's notify function whenever the
1858c2ecf20Sopenharmony_ci *		control's value changes.
1868c2ecf20Sopenharmony_ci * @manual_mode_value: If the is_auto flag is set, then this is the value
1878c2ecf20Sopenharmony_ci *		of the auto control that determines if that control is in
1888c2ecf20Sopenharmony_ci *		manual mode. So if the value of the auto control equals this
1898c2ecf20Sopenharmony_ci *		value, then the whole cluster is in manual mode. Drivers should
1908c2ecf20Sopenharmony_ci *		never set this flag directly.
1918c2ecf20Sopenharmony_ci * @ops:	The control ops.
1928c2ecf20Sopenharmony_ci * @type_ops:	The control type ops.
1938c2ecf20Sopenharmony_ci * @id:	The control ID.
1948c2ecf20Sopenharmony_ci * @name:	The control name.
1958c2ecf20Sopenharmony_ci * @type:	The control type.
1968c2ecf20Sopenharmony_ci * @minimum:	The control's minimum value.
1978c2ecf20Sopenharmony_ci * @maximum:	The control's maximum value.
1988c2ecf20Sopenharmony_ci * @default_value: The control's default value.
1998c2ecf20Sopenharmony_ci * @step:	The control's step value for non-menu controls.
2008c2ecf20Sopenharmony_ci * @elems:	The number of elements in the N-dimensional array.
2018c2ecf20Sopenharmony_ci * @elem_size:	The size in bytes of the control.
2028c2ecf20Sopenharmony_ci * @dims:	The size of each dimension.
2038c2ecf20Sopenharmony_ci * @nr_of_dims:The number of dimensions in @dims.
2048c2ecf20Sopenharmony_ci * @menu_skip_mask: The control's skip mask for menu controls. This makes it
2058c2ecf20Sopenharmony_ci *		easy to skip menu items that are not valid. If bit X is set,
2068c2ecf20Sopenharmony_ci *		then menu item X is skipped. Of course, this only works for
2078c2ecf20Sopenharmony_ci *		menus with <= 32 menu items. There are no menus that come
2088c2ecf20Sopenharmony_ci *		close to that number, so this is OK. Should we ever need more,
2098c2ecf20Sopenharmony_ci *		then this will have to be extended to a u64 or a bit array.
2108c2ecf20Sopenharmony_ci * @qmenu:	A const char * array for all menu items. Array entries that are
2118c2ecf20Sopenharmony_ci *		empty strings ("") correspond to non-existing menu items (this
2128c2ecf20Sopenharmony_ci *		is in addition to the menu_skip_mask above). The last entry
2138c2ecf20Sopenharmony_ci *		must be NULL.
2148c2ecf20Sopenharmony_ci *		Used only if the @type is %V4L2_CTRL_TYPE_MENU.
2158c2ecf20Sopenharmony_ci * @qmenu_int:	A 64-bit integer array for with integer menu items.
2168c2ecf20Sopenharmony_ci *		The size of array must be equal to the menu size, e. g.:
2178c2ecf20Sopenharmony_ci *		:math:`ceil(\frac{maximum - minimum}{step}) + 1`.
2188c2ecf20Sopenharmony_ci *		Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
2198c2ecf20Sopenharmony_ci * @flags:	The control's flags.
2208c2ecf20Sopenharmony_ci * @cur:	Structure to store the current value.
2218c2ecf20Sopenharmony_ci * @cur.val:	The control's current value, if the @type is represented via
2228c2ecf20Sopenharmony_ci *		a u32 integer (see &enum v4l2_ctrl_type).
2238c2ecf20Sopenharmony_ci * @val:	The control's new s32 value.
2248c2ecf20Sopenharmony_ci * @priv:	The control's private pointer. For use by the driver. It is
2258c2ecf20Sopenharmony_ci *		untouched by the control framework. Note that this pointer is
2268c2ecf20Sopenharmony_ci *		not freed when the control is deleted. Should this be needed
2278c2ecf20Sopenharmony_ci *		then a new internal bitfield can be added to tell the framework
2288c2ecf20Sopenharmony_ci *		to free this pointer.
2298c2ecf20Sopenharmony_ci * @p_def:	The control's default value represented via a union which
2308c2ecf20Sopenharmony_ci *		provides a standard way of accessing control types
2318c2ecf20Sopenharmony_ci *		through a pointer (for compound controls only).
2328c2ecf20Sopenharmony_ci * @p_cur:	The control's current value represented via a union which
2338c2ecf20Sopenharmony_ci *		provides a standard way of accessing control types
2348c2ecf20Sopenharmony_ci *		through a pointer.
2358c2ecf20Sopenharmony_ci * @p_new:	The control's new value represented via a union which provides
2368c2ecf20Sopenharmony_ci *		a standard way of accessing control types
2378c2ecf20Sopenharmony_ci *		through a pointer.
2388c2ecf20Sopenharmony_ci */
2398c2ecf20Sopenharmony_cistruct v4l2_ctrl {
2408c2ecf20Sopenharmony_ci	/* Administrative fields */
2418c2ecf20Sopenharmony_ci	struct list_head node;
2428c2ecf20Sopenharmony_ci	struct list_head ev_subs;
2438c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler *handler;
2448c2ecf20Sopenharmony_ci	struct v4l2_ctrl **cluster;
2458c2ecf20Sopenharmony_ci	unsigned int ncontrols;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	unsigned int done:1;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	unsigned int is_new:1;
2508c2ecf20Sopenharmony_ci	unsigned int has_changed:1;
2518c2ecf20Sopenharmony_ci	unsigned int is_private:1;
2528c2ecf20Sopenharmony_ci	unsigned int is_auto:1;
2538c2ecf20Sopenharmony_ci	unsigned int is_int:1;
2548c2ecf20Sopenharmony_ci	unsigned int is_string:1;
2558c2ecf20Sopenharmony_ci	unsigned int is_ptr:1;
2568c2ecf20Sopenharmony_ci	unsigned int is_array:1;
2578c2ecf20Sopenharmony_ci	unsigned int has_volatiles:1;
2588c2ecf20Sopenharmony_ci	unsigned int call_notify:1;
2598c2ecf20Sopenharmony_ci	unsigned int manual_mode_value:8;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	const struct v4l2_ctrl_ops *ops;
2628c2ecf20Sopenharmony_ci	const struct v4l2_ctrl_type_ops *type_ops;
2638c2ecf20Sopenharmony_ci	u32 id;
2648c2ecf20Sopenharmony_ci	const char *name;
2658c2ecf20Sopenharmony_ci	enum v4l2_ctrl_type type;
2668c2ecf20Sopenharmony_ci	s64 minimum, maximum, default_value;
2678c2ecf20Sopenharmony_ci	u32 elems;
2688c2ecf20Sopenharmony_ci	u32 elem_size;
2698c2ecf20Sopenharmony_ci	u32 dims[V4L2_CTRL_MAX_DIMS];
2708c2ecf20Sopenharmony_ci	u32 nr_of_dims;
2718c2ecf20Sopenharmony_ci	union {
2728c2ecf20Sopenharmony_ci		u64 step;
2738c2ecf20Sopenharmony_ci		u64 menu_skip_mask;
2748c2ecf20Sopenharmony_ci	};
2758c2ecf20Sopenharmony_ci	union {
2768c2ecf20Sopenharmony_ci		const char * const *qmenu;
2778c2ecf20Sopenharmony_ci		const s64 *qmenu_int;
2788c2ecf20Sopenharmony_ci	};
2798c2ecf20Sopenharmony_ci	unsigned long flags;
2808c2ecf20Sopenharmony_ci	void *priv;
2818c2ecf20Sopenharmony_ci	s32 val;
2828c2ecf20Sopenharmony_ci	struct {
2838c2ecf20Sopenharmony_ci		s32 val;
2848c2ecf20Sopenharmony_ci	} cur;
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	union v4l2_ctrl_ptr p_def;
2878c2ecf20Sopenharmony_ci	union v4l2_ctrl_ptr p_new;
2888c2ecf20Sopenharmony_ci	union v4l2_ctrl_ptr p_cur;
2898c2ecf20Sopenharmony_ci};
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/**
2928c2ecf20Sopenharmony_ci * struct v4l2_ctrl_ref - The control reference.
2938c2ecf20Sopenharmony_ci *
2948c2ecf20Sopenharmony_ci * @node:	List node for the sorted list.
2958c2ecf20Sopenharmony_ci * @next:	Single-link list node for the hash.
2968c2ecf20Sopenharmony_ci * @ctrl:	The actual control information.
2978c2ecf20Sopenharmony_ci * @helper:	Pointer to helper struct. Used internally in
2988c2ecf20Sopenharmony_ci *		``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
2998c2ecf20Sopenharmony_ci * @from_other_dev: If true, then @ctrl was defined in another
3008c2ecf20Sopenharmony_ci *		device than the &struct v4l2_ctrl_handler.
3018c2ecf20Sopenharmony_ci * @req_done:	Internal flag: if the control handler containing this control
3028c2ecf20Sopenharmony_ci *		reference is bound to a media request, then this is set when
3038c2ecf20Sopenharmony_ci *		the control has been applied. This prevents applying controls
3048c2ecf20Sopenharmony_ci *		from a cluster with multiple controls twice (when the first
3058c2ecf20Sopenharmony_ci *		control of a cluster is applied, they all are).
3068c2ecf20Sopenharmony_ci * @valid_p_req: If set, then p_req contains the control value for the request.
3078c2ecf20Sopenharmony_ci * @p_req:	If the control handler containing this control reference
3088c2ecf20Sopenharmony_ci *		is bound to a media request, then this points to the
3098c2ecf20Sopenharmony_ci *		value of the control that must be applied when the request
3108c2ecf20Sopenharmony_ci *		is executed, or to the value of the control at the time
3118c2ecf20Sopenharmony_ci *		that the request was completed. If @valid_p_req is false,
3128c2ecf20Sopenharmony_ci *		then this control was never set for this request and the
3138c2ecf20Sopenharmony_ci *		control will not be updated when this request is applied.
3148c2ecf20Sopenharmony_ci *
3158c2ecf20Sopenharmony_ci * Each control handler has a list of these refs. The list_head is used to
3168c2ecf20Sopenharmony_ci * keep a sorted-by-control-ID list of all controls, while the next pointer
3178c2ecf20Sopenharmony_ci * is used to link the control in the hash's bucket.
3188c2ecf20Sopenharmony_ci */
3198c2ecf20Sopenharmony_cistruct v4l2_ctrl_ref {
3208c2ecf20Sopenharmony_ci	struct list_head node;
3218c2ecf20Sopenharmony_ci	struct v4l2_ctrl_ref *next;
3228c2ecf20Sopenharmony_ci	struct v4l2_ctrl *ctrl;
3238c2ecf20Sopenharmony_ci	struct v4l2_ctrl_helper *helper;
3248c2ecf20Sopenharmony_ci	bool from_other_dev;
3258c2ecf20Sopenharmony_ci	bool req_done;
3268c2ecf20Sopenharmony_ci	bool valid_p_req;
3278c2ecf20Sopenharmony_ci	union v4l2_ctrl_ptr p_req;
3288c2ecf20Sopenharmony_ci};
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci/**
3318c2ecf20Sopenharmony_ci * struct v4l2_ctrl_handler - The control handler keeps track of all the
3328c2ecf20Sopenharmony_ci *	controls: both the controls owned by the handler and those inherited
3338c2ecf20Sopenharmony_ci *	from other handlers.
3348c2ecf20Sopenharmony_ci *
3358c2ecf20Sopenharmony_ci * @_lock:	Default for "lock".
3368c2ecf20Sopenharmony_ci * @lock:	Lock to control access to this handler and its controls.
3378c2ecf20Sopenharmony_ci *		May be replaced by the user right after init.
3388c2ecf20Sopenharmony_ci * @ctrls:	The list of controls owned by this handler.
3398c2ecf20Sopenharmony_ci * @ctrl_refs:	The list of control references.
3408c2ecf20Sopenharmony_ci * @cached:	The last found control reference. It is common that the same
3418c2ecf20Sopenharmony_ci *		control is needed multiple times, so this is a simple
3428c2ecf20Sopenharmony_ci *		optimization.
3438c2ecf20Sopenharmony_ci * @buckets:	Buckets for the hashing. Allows for quick control lookup.
3448c2ecf20Sopenharmony_ci * @notify:	A notify callback that is called whenever the control changes
3458c2ecf20Sopenharmony_ci *		value.
3468c2ecf20Sopenharmony_ci *		Note that the handler's lock is held when the notify function
3478c2ecf20Sopenharmony_ci *		is called!
3488c2ecf20Sopenharmony_ci * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
3498c2ecf20Sopenharmony_ci * @nr_of_buckets: Total number of buckets in the array.
3508c2ecf20Sopenharmony_ci * @error:	The error code of the first failed control addition.
3518c2ecf20Sopenharmony_ci * @request_is_queued: True if the request was queued.
3528c2ecf20Sopenharmony_ci * @requests:	List to keep track of open control handler request objects.
3538c2ecf20Sopenharmony_ci *		For the parent control handler (@req_obj.ops == NULL) this
3548c2ecf20Sopenharmony_ci *		is the list header. When the parent control handler is
3558c2ecf20Sopenharmony_ci *		removed, it has to unbind and put all these requests since
3568c2ecf20Sopenharmony_ci *		they refer to the parent.
3578c2ecf20Sopenharmony_ci * @requests_queued: List of the queued requests. This determines the order
3588c2ecf20Sopenharmony_ci *		in which these controls are applied. Once the request is
3598c2ecf20Sopenharmony_ci *		completed it is removed from this list.
3608c2ecf20Sopenharmony_ci * @req_obj:	The &struct media_request_object, used to link into a
3618c2ecf20Sopenharmony_ci *		&struct media_request. This request object has a refcount.
3628c2ecf20Sopenharmony_ci */
3638c2ecf20Sopenharmony_cistruct v4l2_ctrl_handler {
3648c2ecf20Sopenharmony_ci	struct mutex _lock;
3658c2ecf20Sopenharmony_ci	struct mutex *lock;
3668c2ecf20Sopenharmony_ci	struct list_head ctrls;
3678c2ecf20Sopenharmony_ci	struct list_head ctrl_refs;
3688c2ecf20Sopenharmony_ci	struct v4l2_ctrl_ref *cached;
3698c2ecf20Sopenharmony_ci	struct v4l2_ctrl_ref **buckets;
3708c2ecf20Sopenharmony_ci	v4l2_ctrl_notify_fnc notify;
3718c2ecf20Sopenharmony_ci	void *notify_priv;
3728c2ecf20Sopenharmony_ci	u16 nr_of_buckets;
3738c2ecf20Sopenharmony_ci	int error;
3748c2ecf20Sopenharmony_ci	bool request_is_queued;
3758c2ecf20Sopenharmony_ci	struct list_head requests;
3768c2ecf20Sopenharmony_ci	struct list_head requests_queued;
3778c2ecf20Sopenharmony_ci	struct media_request_object req_obj;
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci/**
3818c2ecf20Sopenharmony_ci * struct v4l2_ctrl_config - Control configuration structure.
3828c2ecf20Sopenharmony_ci *
3838c2ecf20Sopenharmony_ci * @ops:	The control ops.
3848c2ecf20Sopenharmony_ci * @type_ops:	The control type ops. Only needed for compound controls.
3858c2ecf20Sopenharmony_ci * @id:	The control ID.
3868c2ecf20Sopenharmony_ci * @name:	The control name.
3878c2ecf20Sopenharmony_ci * @type:	The control type.
3888c2ecf20Sopenharmony_ci * @min:	The control's minimum value.
3898c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
3908c2ecf20Sopenharmony_ci * @step:	The control's step value for non-menu controls.
3918c2ecf20Sopenharmony_ci * @def:	The control's default value.
3928c2ecf20Sopenharmony_ci * @p_def:	The control's default value for compound controls.
3938c2ecf20Sopenharmony_ci * @dims:	The size of each dimension.
3948c2ecf20Sopenharmony_ci * @elem_size:	The size in bytes of the control.
3958c2ecf20Sopenharmony_ci * @flags:	The control's flags.
3968c2ecf20Sopenharmony_ci * @menu_skip_mask: The control's skip mask for menu controls. This makes it
3978c2ecf20Sopenharmony_ci *		easy to skip menu items that are not valid. If bit X is set,
3988c2ecf20Sopenharmony_ci *		then menu item X is skipped. Of course, this only works for
3998c2ecf20Sopenharmony_ci *		menus with <= 64 menu items. There are no menus that come
4008c2ecf20Sopenharmony_ci *		close to that number, so this is OK. Should we ever need more,
4018c2ecf20Sopenharmony_ci *		then this will have to be extended to a bit array.
4028c2ecf20Sopenharmony_ci * @qmenu:	A const char * array for all menu items. Array entries that are
4038c2ecf20Sopenharmony_ci *		empty strings ("") correspond to non-existing menu items (this
4048c2ecf20Sopenharmony_ci *		is in addition to the menu_skip_mask above). The last entry
4058c2ecf20Sopenharmony_ci *		must be NULL.
4068c2ecf20Sopenharmony_ci * @qmenu_int:	A const s64 integer array for all menu items of the type
4078c2ecf20Sopenharmony_ci *		V4L2_CTRL_TYPE_INTEGER_MENU.
4088c2ecf20Sopenharmony_ci * @is_private: If set, then this control is private to its handler and it
4098c2ecf20Sopenharmony_ci *		will not be added to any other handlers.
4108c2ecf20Sopenharmony_ci */
4118c2ecf20Sopenharmony_cistruct v4l2_ctrl_config {
4128c2ecf20Sopenharmony_ci	const struct v4l2_ctrl_ops *ops;
4138c2ecf20Sopenharmony_ci	const struct v4l2_ctrl_type_ops *type_ops;
4148c2ecf20Sopenharmony_ci	u32 id;
4158c2ecf20Sopenharmony_ci	const char *name;
4168c2ecf20Sopenharmony_ci	enum v4l2_ctrl_type type;
4178c2ecf20Sopenharmony_ci	s64 min;
4188c2ecf20Sopenharmony_ci	s64 max;
4198c2ecf20Sopenharmony_ci	u64 step;
4208c2ecf20Sopenharmony_ci	s64 def;
4218c2ecf20Sopenharmony_ci	union v4l2_ctrl_ptr p_def;
4228c2ecf20Sopenharmony_ci	u32 dims[V4L2_CTRL_MAX_DIMS];
4238c2ecf20Sopenharmony_ci	u32 elem_size;
4248c2ecf20Sopenharmony_ci	u32 flags;
4258c2ecf20Sopenharmony_ci	u64 menu_skip_mask;
4268c2ecf20Sopenharmony_ci	const char * const *qmenu;
4278c2ecf20Sopenharmony_ci	const s64 *qmenu_int;
4288c2ecf20Sopenharmony_ci	unsigned int is_private:1;
4298c2ecf20Sopenharmony_ci};
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/**
4328c2ecf20Sopenharmony_ci * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
4338c2ecf20Sopenharmony_ci *
4348c2ecf20Sopenharmony_ci * @id: ID of the control
4358c2ecf20Sopenharmony_ci * @name: pointer to be filled with a string with the name of the control
4368c2ecf20Sopenharmony_ci * @type: pointer for storing the type of the control
4378c2ecf20Sopenharmony_ci * @min: pointer for storing the minimum value for the control
4388c2ecf20Sopenharmony_ci * @max: pointer for storing the maximum value for the control
4398c2ecf20Sopenharmony_ci * @step: pointer for storing the control step
4408c2ecf20Sopenharmony_ci * @def: pointer for storing the default value for the control
4418c2ecf20Sopenharmony_ci * @flags: pointer for storing the flags to be used on the control
4428c2ecf20Sopenharmony_ci *
4438c2ecf20Sopenharmony_ci * This works for all standard V4L2 controls.
4448c2ecf20Sopenharmony_ci * For non-standard controls it will only fill in the given arguments
4458c2ecf20Sopenharmony_ci * and @name content will be set to %NULL.
4468c2ecf20Sopenharmony_ci *
4478c2ecf20Sopenharmony_ci * This function will overwrite the contents of @name, @type and @flags.
4488c2ecf20Sopenharmony_ci * The contents of @min, @max, @step and @def may be modified depending on
4498c2ecf20Sopenharmony_ci * the type.
4508c2ecf20Sopenharmony_ci *
4518c2ecf20Sopenharmony_ci * .. note::
4528c2ecf20Sopenharmony_ci *
4538c2ecf20Sopenharmony_ci *    Do not use in drivers! It is used internally for backwards compatibility
4548c2ecf20Sopenharmony_ci *    control handling only. Once all drivers are converted to use the new
4558c2ecf20Sopenharmony_ci *    control framework this function will no longer be exported.
4568c2ecf20Sopenharmony_ci */
4578c2ecf20Sopenharmony_civoid v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
4588c2ecf20Sopenharmony_ci		    s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci/**
4628c2ecf20Sopenharmony_ci * v4l2_ctrl_handler_init_class() - Initialize the control handler.
4638c2ecf20Sopenharmony_ci * @hdl:	The control handler.
4648c2ecf20Sopenharmony_ci * @nr_of_controls_hint: A hint of how many controls this handler is
4658c2ecf20Sopenharmony_ci *		expected to refer to. This is the total number, so including
4668c2ecf20Sopenharmony_ci *		any inherited controls. It doesn't have to be precise, but if
4678c2ecf20Sopenharmony_ci *		it is way off, then you either waste memory (too many buckets
4688c2ecf20Sopenharmony_ci *		are allocated) or the control lookup becomes slower (not enough
4698c2ecf20Sopenharmony_ci *		buckets are allocated, so there are more slow list lookups).
4708c2ecf20Sopenharmony_ci *		It will always work, though.
4718c2ecf20Sopenharmony_ci * @key:	Used by the lock validator if CONFIG_LOCKDEP is set.
4728c2ecf20Sopenharmony_ci * @name:	Used by the lock validator if CONFIG_LOCKDEP is set.
4738c2ecf20Sopenharmony_ci *
4748c2ecf20Sopenharmony_ci * .. attention::
4758c2ecf20Sopenharmony_ci *
4768c2ecf20Sopenharmony_ci *    Never use this call directly, always use the v4l2_ctrl_handler_init()
4778c2ecf20Sopenharmony_ci *    macro that hides the @key and @name arguments.
4788c2ecf20Sopenharmony_ci *
4798c2ecf20Sopenharmony_ci * Return: returns an error if the buckets could not be allocated. This
4808c2ecf20Sopenharmony_ci * error will also be stored in @hdl->error.
4818c2ecf20Sopenharmony_ci */
4828c2ecf20Sopenharmony_ciint v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
4838c2ecf20Sopenharmony_ci				 unsigned int nr_of_controls_hint,
4848c2ecf20Sopenharmony_ci				 struct lock_class_key *key, const char *name);
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci#ifdef CONFIG_LOCKDEP
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci/**
4898c2ecf20Sopenharmony_ci * v4l2_ctrl_handler_init - helper function to create a static struct
4908c2ecf20Sopenharmony_ci *	 &lock_class_key and calls v4l2_ctrl_handler_init_class()
4918c2ecf20Sopenharmony_ci *
4928c2ecf20Sopenharmony_ci * @hdl:	The control handler.
4938c2ecf20Sopenharmony_ci * @nr_of_controls_hint: A hint of how many controls this handler is
4948c2ecf20Sopenharmony_ci *		expected to refer to. This is the total number, so including
4958c2ecf20Sopenharmony_ci *		any inherited controls. It doesn't have to be precise, but if
4968c2ecf20Sopenharmony_ci *		it is way off, then you either waste memory (too many buckets
4978c2ecf20Sopenharmony_ci *		are allocated) or the control lookup becomes slower (not enough
4988c2ecf20Sopenharmony_ci *		buckets are allocated, so there are more slow list lookups).
4998c2ecf20Sopenharmony_ci *		It will always work, though.
5008c2ecf20Sopenharmony_ci *
5018c2ecf20Sopenharmony_ci * This helper function creates a static struct &lock_class_key and
5028c2ecf20Sopenharmony_ci * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
5038c2ecf20Sopenharmony_ci * validador.
5048c2ecf20Sopenharmony_ci *
5058c2ecf20Sopenharmony_ci * Use this helper function to initialize a control handler.
5068c2ecf20Sopenharmony_ci */
5078c2ecf20Sopenharmony_ci#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint)		\
5088c2ecf20Sopenharmony_ci(									\
5098c2ecf20Sopenharmony_ci	({								\
5108c2ecf20Sopenharmony_ci		static struct lock_class_key _key;			\
5118c2ecf20Sopenharmony_ci		v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint,	\
5128c2ecf20Sopenharmony_ci					&_key,				\
5138c2ecf20Sopenharmony_ci					KBUILD_BASENAME ":"		\
5148c2ecf20Sopenharmony_ci					__stringify(__LINE__) ":"	\
5158c2ecf20Sopenharmony_ci					"(" #hdl ")->_lock");		\
5168c2ecf20Sopenharmony_ci	})								\
5178c2ecf20Sopenharmony_ci)
5188c2ecf20Sopenharmony_ci#else
5198c2ecf20Sopenharmony_ci#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint)		\
5208c2ecf20Sopenharmony_ci	v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
5218c2ecf20Sopenharmony_ci#endif
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci/**
5248c2ecf20Sopenharmony_ci * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
5258c2ecf20Sopenharmony_ci * the control list.
5268c2ecf20Sopenharmony_ci * @hdl:	The control handler.
5278c2ecf20Sopenharmony_ci *
5288c2ecf20Sopenharmony_ci * Does nothing if @hdl == NULL.
5298c2ecf20Sopenharmony_ci */
5308c2ecf20Sopenharmony_civoid v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci/**
5338c2ecf20Sopenharmony_ci * v4l2_ctrl_lock() - Helper function to lock the handler
5348c2ecf20Sopenharmony_ci * associated with the control.
5358c2ecf20Sopenharmony_ci * @ctrl:	The control to lock.
5368c2ecf20Sopenharmony_ci */
5378c2ecf20Sopenharmony_cistatic inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
5388c2ecf20Sopenharmony_ci{
5398c2ecf20Sopenharmony_ci	mutex_lock(ctrl->handler->lock);
5408c2ecf20Sopenharmony_ci}
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci/**
5438c2ecf20Sopenharmony_ci * v4l2_ctrl_unlock() - Helper function to unlock the handler
5448c2ecf20Sopenharmony_ci * associated with the control.
5458c2ecf20Sopenharmony_ci * @ctrl:	The control to unlock.
5468c2ecf20Sopenharmony_ci */
5478c2ecf20Sopenharmony_cistatic inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
5488c2ecf20Sopenharmony_ci{
5498c2ecf20Sopenharmony_ci	mutex_unlock(ctrl->handler->lock);
5508c2ecf20Sopenharmony_ci}
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci/**
5538c2ecf20Sopenharmony_ci * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
5548c2ecf20Sopenharmony_ci * to the handler to initialize the hardware to the current control values. The
5558c2ecf20Sopenharmony_ci * caller is responsible for acquiring the control handler mutex on behalf of
5568c2ecf20Sopenharmony_ci * __v4l2_ctrl_handler_setup().
5578c2ecf20Sopenharmony_ci * @hdl:	The control handler.
5588c2ecf20Sopenharmony_ci *
5598c2ecf20Sopenharmony_ci * Button controls will be skipped, as are read-only controls.
5608c2ecf20Sopenharmony_ci *
5618c2ecf20Sopenharmony_ci * If @hdl == NULL, then this just returns 0.
5628c2ecf20Sopenharmony_ci */
5638c2ecf20Sopenharmony_ciint __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci/**
5668c2ecf20Sopenharmony_ci * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
5678c2ecf20Sopenharmony_ci * to the handler to initialize the hardware to the current control values.
5688c2ecf20Sopenharmony_ci * @hdl:	The control handler.
5698c2ecf20Sopenharmony_ci *
5708c2ecf20Sopenharmony_ci * Button controls will be skipped, as are read-only controls.
5718c2ecf20Sopenharmony_ci *
5728c2ecf20Sopenharmony_ci * If @hdl == NULL, then this just returns 0.
5738c2ecf20Sopenharmony_ci */
5748c2ecf20Sopenharmony_ciint v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci/**
5778c2ecf20Sopenharmony_ci * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
5788c2ecf20Sopenharmony_ci * @hdl:	The control handler.
5798c2ecf20Sopenharmony_ci * @prefix:	The prefix to use when logging the control values. If the
5808c2ecf20Sopenharmony_ci *		prefix does not end with a space, then ": " will be added
5818c2ecf20Sopenharmony_ci *		after the prefix. If @prefix == NULL, then no prefix will be
5828c2ecf20Sopenharmony_ci *		used.
5838c2ecf20Sopenharmony_ci *
5848c2ecf20Sopenharmony_ci * For use with VIDIOC_LOG_STATUS.
5858c2ecf20Sopenharmony_ci *
5868c2ecf20Sopenharmony_ci * Does nothing if @hdl == NULL.
5878c2ecf20Sopenharmony_ci */
5888c2ecf20Sopenharmony_civoid v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
5898c2ecf20Sopenharmony_ci				  const char *prefix);
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci/**
5928c2ecf20Sopenharmony_ci * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
5938c2ecf20Sopenharmony_ci *	control.
5948c2ecf20Sopenharmony_ci *
5958c2ecf20Sopenharmony_ci * @hdl:	The control handler.
5968c2ecf20Sopenharmony_ci * @cfg:	The control's configuration data.
5978c2ecf20Sopenharmony_ci * @priv:	The control's driver-specific private data.
5988c2ecf20Sopenharmony_ci *
5998c2ecf20Sopenharmony_ci * If the &v4l2_ctrl struct could not be allocated then NULL is returned
6008c2ecf20Sopenharmony_ci * and @hdl->error is set to the error code (if it wasn't set already).
6018c2ecf20Sopenharmony_ci */
6028c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
6038c2ecf20Sopenharmony_ci				       const struct v4l2_ctrl_config *cfg,
6048c2ecf20Sopenharmony_ci				       void *priv);
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci/**
6078c2ecf20Sopenharmony_ci * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
6088c2ecf20Sopenharmony_ci *	control.
6098c2ecf20Sopenharmony_ci *
6108c2ecf20Sopenharmony_ci * @hdl:	The control handler.
6118c2ecf20Sopenharmony_ci * @ops:	The control ops.
6128c2ecf20Sopenharmony_ci * @id:		The control ID.
6138c2ecf20Sopenharmony_ci * @min:	The control's minimum value.
6148c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
6158c2ecf20Sopenharmony_ci * @step:	The control's step value
6168c2ecf20Sopenharmony_ci * @def:	The control's default value.
6178c2ecf20Sopenharmony_ci *
6188c2ecf20Sopenharmony_ci * If the &v4l2_ctrl struct could not be allocated, or the control
6198c2ecf20Sopenharmony_ci * ID is not known, then NULL is returned and @hdl->error is set to the
6208c2ecf20Sopenharmony_ci * appropriate error code (if it wasn't set already).
6218c2ecf20Sopenharmony_ci *
6228c2ecf20Sopenharmony_ci * If @id refers to a menu control, then this function will return NULL.
6238c2ecf20Sopenharmony_ci *
6248c2ecf20Sopenharmony_ci * Use v4l2_ctrl_new_std_menu() when adding menu controls.
6258c2ecf20Sopenharmony_ci */
6268c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
6278c2ecf20Sopenharmony_ci				    const struct v4l2_ctrl_ops *ops,
6288c2ecf20Sopenharmony_ci				    u32 id, s64 min, s64 max, u64 step,
6298c2ecf20Sopenharmony_ci				    s64 def);
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci/**
6328c2ecf20Sopenharmony_ci * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
6338c2ecf20Sopenharmony_ci *	menu control.
6348c2ecf20Sopenharmony_ci *
6358c2ecf20Sopenharmony_ci * @hdl:	The control handler.
6368c2ecf20Sopenharmony_ci * @ops:	The control ops.
6378c2ecf20Sopenharmony_ci * @id:		The control ID.
6388c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
6398c2ecf20Sopenharmony_ci * @mask:	The control's skip mask for menu controls. This makes it
6408c2ecf20Sopenharmony_ci *		easy to skip menu items that are not valid. If bit X is set,
6418c2ecf20Sopenharmony_ci *		then menu item X is skipped. Of course, this only works for
6428c2ecf20Sopenharmony_ci *		menus with <= 64 menu items. There are no menus that come
6438c2ecf20Sopenharmony_ci *		close to that number, so this is OK. Should we ever need more,
6448c2ecf20Sopenharmony_ci *		then this will have to be extended to a bit array.
6458c2ecf20Sopenharmony_ci * @def:	The control's default value.
6468c2ecf20Sopenharmony_ci *
6478c2ecf20Sopenharmony_ci * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
6488c2ecf20Sopenharmony_ci * determines which menu items are to be skipped.
6498c2ecf20Sopenharmony_ci *
6508c2ecf20Sopenharmony_ci * If @id refers to a non-menu control, then this function will return NULL.
6518c2ecf20Sopenharmony_ci */
6528c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
6538c2ecf20Sopenharmony_ci					 const struct v4l2_ctrl_ops *ops,
6548c2ecf20Sopenharmony_ci					 u32 id, u8 max, u64 mask, u8 def);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci/**
6578c2ecf20Sopenharmony_ci * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
6588c2ecf20Sopenharmony_ci *	with driver specific menu.
6598c2ecf20Sopenharmony_ci *
6608c2ecf20Sopenharmony_ci * @hdl:	The control handler.
6618c2ecf20Sopenharmony_ci * @ops:	The control ops.
6628c2ecf20Sopenharmony_ci * @id:	The control ID.
6638c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
6648c2ecf20Sopenharmony_ci * @mask:	The control's skip mask for menu controls. This makes it
6658c2ecf20Sopenharmony_ci *		easy to skip menu items that are not valid. If bit X is set,
6668c2ecf20Sopenharmony_ci *		then menu item X is skipped. Of course, this only works for
6678c2ecf20Sopenharmony_ci *		menus with <= 64 menu items. There are no menus that come
6688c2ecf20Sopenharmony_ci *		close to that number, so this is OK. Should we ever need more,
6698c2ecf20Sopenharmony_ci *		then this will have to be extended to a bit array.
6708c2ecf20Sopenharmony_ci * @def:	The control's default value.
6718c2ecf20Sopenharmony_ci * @qmenu:	The new menu.
6728c2ecf20Sopenharmony_ci *
6738c2ecf20Sopenharmony_ci * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
6748c2ecf20Sopenharmony_ci * menu of this control.
6758c2ecf20Sopenharmony_ci *
6768c2ecf20Sopenharmony_ci */
6778c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
6788c2ecf20Sopenharmony_ci					       const struct v4l2_ctrl_ops *ops,
6798c2ecf20Sopenharmony_ci					       u32 id, u8 max,
6808c2ecf20Sopenharmony_ci					       u64 mask, u8 def,
6818c2ecf20Sopenharmony_ci					       const char * const *qmenu);
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci/**
6848c2ecf20Sopenharmony_ci * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
6858c2ecf20Sopenharmony_ci *      compound control.
6868c2ecf20Sopenharmony_ci *
6878c2ecf20Sopenharmony_ci * @hdl:       The control handler.
6888c2ecf20Sopenharmony_ci * @ops:       The control ops.
6898c2ecf20Sopenharmony_ci * @id:        The control ID.
6908c2ecf20Sopenharmony_ci * @p_def:     The control's default value.
6918c2ecf20Sopenharmony_ci *
6928c2ecf20Sopenharmony_ci * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
6938c2ecf20Sopenharmony_ci * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
6948c2ecf20Sopenharmony_ci * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
6958c2ecf20Sopenharmony_ci * compound control should be all zeroes.
6968c2ecf20Sopenharmony_ci *
6978c2ecf20Sopenharmony_ci */
6988c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
6998c2ecf20Sopenharmony_ci					     const struct v4l2_ctrl_ops *ops,
7008c2ecf20Sopenharmony_ci					     u32 id,
7018c2ecf20Sopenharmony_ci					     const union v4l2_ctrl_ptr p_def);
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci/**
7048c2ecf20Sopenharmony_ci * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
7058c2ecf20Sopenharmony_ci *
7068c2ecf20Sopenharmony_ci * @hdl:	The control handler.
7078c2ecf20Sopenharmony_ci * @ops:	The control ops.
7088c2ecf20Sopenharmony_ci * @id:	The control ID.
7098c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
7108c2ecf20Sopenharmony_ci * @def:	The control's default value.
7118c2ecf20Sopenharmony_ci * @qmenu_int:	The control's menu entries.
7128c2ecf20Sopenharmony_ci *
7138c2ecf20Sopenharmony_ci * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
7148c2ecf20Sopenharmony_ci * takes as an argument an array of integers determining the menu items.
7158c2ecf20Sopenharmony_ci *
7168c2ecf20Sopenharmony_ci * If @id refers to a non-integer-menu control, then this function will
7178c2ecf20Sopenharmony_ci * return %NULL.
7188c2ecf20Sopenharmony_ci */
7198c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
7208c2ecf20Sopenharmony_ci					 const struct v4l2_ctrl_ops *ops,
7218c2ecf20Sopenharmony_ci					 u32 id, u8 max, u8 def,
7228c2ecf20Sopenharmony_ci					 const s64 *qmenu_int);
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci/**
7258c2ecf20Sopenharmony_ci * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
7268c2ecf20Sopenharmony_ci *	used when adding a control handler.
7278c2ecf20Sopenharmony_ci *
7288c2ecf20Sopenharmony_ci * @ctrl: pointer to struct &v4l2_ctrl.
7298c2ecf20Sopenharmony_ci */
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_citypedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci/**
7348c2ecf20Sopenharmony_ci * v4l2_ctrl_add_handler() - Add all controls from handler @add to
7358c2ecf20Sopenharmony_ci *	handler @hdl.
7368c2ecf20Sopenharmony_ci *
7378c2ecf20Sopenharmony_ci * @hdl:	The control handler.
7388c2ecf20Sopenharmony_ci * @add:	The control handler whose controls you want to add to
7398c2ecf20Sopenharmony_ci *		the @hdl control handler.
7408c2ecf20Sopenharmony_ci * @filter:	This function will filter which controls should be added.
7418c2ecf20Sopenharmony_ci * @from_other_dev: If true, then the controls in @add were defined in another
7428c2ecf20Sopenharmony_ci *		device than @hdl.
7438c2ecf20Sopenharmony_ci *
7448c2ecf20Sopenharmony_ci * Does nothing if either of the two handlers is a NULL pointer.
7458c2ecf20Sopenharmony_ci * If @filter is NULL, then all controls are added. Otherwise only those
7468c2ecf20Sopenharmony_ci * controls for which @filter returns true will be added.
7478c2ecf20Sopenharmony_ci * In case of an error @hdl->error will be set to the error code (if it
7488c2ecf20Sopenharmony_ci * wasn't set already).
7498c2ecf20Sopenharmony_ci */
7508c2ecf20Sopenharmony_ciint v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
7518c2ecf20Sopenharmony_ci			  struct v4l2_ctrl_handler *add,
7528c2ecf20Sopenharmony_ci			  v4l2_ctrl_filter filter,
7538c2ecf20Sopenharmony_ci			  bool from_other_dev);
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci/**
7568c2ecf20Sopenharmony_ci * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
7578c2ecf20Sopenharmony_ci *
7588c2ecf20Sopenharmony_ci * @ctrl:	The control that is filtered.
7598c2ecf20Sopenharmony_ci *
7608c2ecf20Sopenharmony_ci * This will return true for any controls that are valid for radio device
7618c2ecf20Sopenharmony_ci * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
7628c2ecf20Sopenharmony_ci * transmitter class controls.
7638c2ecf20Sopenharmony_ci *
7648c2ecf20Sopenharmony_ci * This function is to be used with v4l2_ctrl_add_handler().
7658c2ecf20Sopenharmony_ci */
7668c2ecf20Sopenharmony_cibool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci/**
7698c2ecf20Sopenharmony_ci * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
7708c2ecf20Sopenharmony_ci *	to that cluster.
7718c2ecf20Sopenharmony_ci *
7728c2ecf20Sopenharmony_ci * @ncontrols:	The number of controls in this cluster.
7738c2ecf20Sopenharmony_ci * @controls:	The cluster control array of size @ncontrols.
7748c2ecf20Sopenharmony_ci */
7758c2ecf20Sopenharmony_civoid v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci/**
7798c2ecf20Sopenharmony_ci * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
7808c2ecf20Sopenharmony_ci *	to that cluster and set it up for autofoo/foo-type handling.
7818c2ecf20Sopenharmony_ci *
7828c2ecf20Sopenharmony_ci * @ncontrols:	The number of controls in this cluster.
7838c2ecf20Sopenharmony_ci * @controls:	The cluster control array of size @ncontrols. The first control
7848c2ecf20Sopenharmony_ci *		must be the 'auto' control (e.g. autogain, autoexposure, etc.)
7858c2ecf20Sopenharmony_ci * @manual_val: The value for the first control in the cluster that equals the
7868c2ecf20Sopenharmony_ci *		manual setting.
7878c2ecf20Sopenharmony_ci * @set_volatile: If true, then all controls except the first auto control will
7888c2ecf20Sopenharmony_ci *		be volatile.
7898c2ecf20Sopenharmony_ci *
7908c2ecf20Sopenharmony_ci * Use for control groups where one control selects some automatic feature and
7918c2ecf20Sopenharmony_ci * the other controls are only active whenever the automatic feature is turned
7928c2ecf20Sopenharmony_ci * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
7938c2ecf20Sopenharmony_ci * red and blue balance, etc.
7948c2ecf20Sopenharmony_ci *
7958c2ecf20Sopenharmony_ci * The behavior of such controls is as follows:
7968c2ecf20Sopenharmony_ci *
7978c2ecf20Sopenharmony_ci * When the autofoo control is set to automatic, then any manual controls
7988c2ecf20Sopenharmony_ci * are set to inactive and any reads will call g_volatile_ctrl (if the control
7998c2ecf20Sopenharmony_ci * was marked volatile).
8008c2ecf20Sopenharmony_ci *
8018c2ecf20Sopenharmony_ci * When the autofoo control is set to manual, then any manual controls will
8028c2ecf20Sopenharmony_ci * be marked active, and any reads will just return the current value without
8038c2ecf20Sopenharmony_ci * going through g_volatile_ctrl.
8048c2ecf20Sopenharmony_ci *
8058c2ecf20Sopenharmony_ci * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
8068c2ecf20Sopenharmony_ci * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
8078c2ecf20Sopenharmony_ci * if autofoo is in auto mode.
8088c2ecf20Sopenharmony_ci */
8098c2ecf20Sopenharmony_civoid v4l2_ctrl_auto_cluster(unsigned int ncontrols,
8108c2ecf20Sopenharmony_ci			    struct v4l2_ctrl **controls,
8118c2ecf20Sopenharmony_ci			    u8 manual_val, bool set_volatile);
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci/**
8158c2ecf20Sopenharmony_ci * v4l2_ctrl_find() - Find a control with the given ID.
8168c2ecf20Sopenharmony_ci *
8178c2ecf20Sopenharmony_ci * @hdl:	The control handler.
8188c2ecf20Sopenharmony_ci * @id:	The control ID to find.
8198c2ecf20Sopenharmony_ci *
8208c2ecf20Sopenharmony_ci * If @hdl == NULL this will return NULL as well. Will lock the handler so
8218c2ecf20Sopenharmony_ci * do not use from inside &v4l2_ctrl_ops.
8228c2ecf20Sopenharmony_ci */
8238c2ecf20Sopenharmony_cistruct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci/**
8268c2ecf20Sopenharmony_ci * v4l2_ctrl_activate() - Make the control active or inactive.
8278c2ecf20Sopenharmony_ci * @ctrl:	The control to (de)activate.
8288c2ecf20Sopenharmony_ci * @active:	True if the control should become active.
8298c2ecf20Sopenharmony_ci *
8308c2ecf20Sopenharmony_ci * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
8318c2ecf20Sopenharmony_ci * Does nothing if @ctrl == NULL.
8328c2ecf20Sopenharmony_ci * This will usually be called from within the s_ctrl op.
8338c2ecf20Sopenharmony_ci * The V4L2_EVENT_CTRL event will be generated afterwards.
8348c2ecf20Sopenharmony_ci *
8358c2ecf20Sopenharmony_ci * This function assumes that the control handler is locked.
8368c2ecf20Sopenharmony_ci */
8378c2ecf20Sopenharmony_civoid v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci/**
8408c2ecf20Sopenharmony_ci * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
8418c2ecf20Sopenharmony_ci *
8428c2ecf20Sopenharmony_ci * @ctrl:	The control to (de)activate.
8438c2ecf20Sopenharmony_ci * @grabbed:	True if the control should become grabbed.
8448c2ecf20Sopenharmony_ci *
8458c2ecf20Sopenharmony_ci * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
8468c2ecf20Sopenharmony_ci * Does nothing if @ctrl == NULL.
8478c2ecf20Sopenharmony_ci * The V4L2_EVENT_CTRL event will be generated afterwards.
8488c2ecf20Sopenharmony_ci * This will usually be called when starting or stopping streaming in the
8498c2ecf20Sopenharmony_ci * driver.
8508c2ecf20Sopenharmony_ci *
8518c2ecf20Sopenharmony_ci * This function assumes that the control handler is locked by the caller.
8528c2ecf20Sopenharmony_ci */
8538c2ecf20Sopenharmony_civoid __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci/**
8568c2ecf20Sopenharmony_ci * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
8578c2ecf20Sopenharmony_ci *
8588c2ecf20Sopenharmony_ci * @ctrl:	The control to (de)activate.
8598c2ecf20Sopenharmony_ci * @grabbed:	True if the control should become grabbed.
8608c2ecf20Sopenharmony_ci *
8618c2ecf20Sopenharmony_ci * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
8628c2ecf20Sopenharmony_ci * Does nothing if @ctrl == NULL.
8638c2ecf20Sopenharmony_ci * The V4L2_EVENT_CTRL event will be generated afterwards.
8648c2ecf20Sopenharmony_ci * This will usually be called when starting or stopping streaming in the
8658c2ecf20Sopenharmony_ci * driver.
8668c2ecf20Sopenharmony_ci *
8678c2ecf20Sopenharmony_ci * This function assumes that the control handler is not locked and will
8688c2ecf20Sopenharmony_ci * take the lock itself.
8698c2ecf20Sopenharmony_ci */
8708c2ecf20Sopenharmony_cistatic inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
8718c2ecf20Sopenharmony_ci{
8728c2ecf20Sopenharmony_ci	if (!ctrl)
8738c2ecf20Sopenharmony_ci		return;
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ci	v4l2_ctrl_lock(ctrl);
8768c2ecf20Sopenharmony_ci	__v4l2_ctrl_grab(ctrl, grabbed);
8778c2ecf20Sopenharmony_ci	v4l2_ctrl_unlock(ctrl);
8788c2ecf20Sopenharmony_ci}
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci/**
8818c2ecf20Sopenharmony_ci *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
8828c2ecf20Sopenharmony_ci *
8838c2ecf20Sopenharmony_ci * @ctrl:	The control to update.
8848c2ecf20Sopenharmony_ci * @min:	The control's minimum value.
8858c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
8868c2ecf20Sopenharmony_ci * @step:	The control's step value
8878c2ecf20Sopenharmony_ci * @def:	The control's default value.
8888c2ecf20Sopenharmony_ci *
8898c2ecf20Sopenharmony_ci * Update the range of a control on the fly. This works for control types
8908c2ecf20Sopenharmony_ci * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
8918c2ecf20Sopenharmony_ci * @step value is interpreted as a menu_skip_mask.
8928c2ecf20Sopenharmony_ci *
8938c2ecf20Sopenharmony_ci * An error is returned if one of the range arguments is invalid for this
8948c2ecf20Sopenharmony_ci * control type.
8958c2ecf20Sopenharmony_ci *
8968c2ecf20Sopenharmony_ci * The caller is responsible for acquiring the control handler mutex on behalf
8978c2ecf20Sopenharmony_ci * of __v4l2_ctrl_modify_range().
8988c2ecf20Sopenharmony_ci */
8998c2ecf20Sopenharmony_ciint __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
9008c2ecf20Sopenharmony_ci			     s64 min, s64 max, u64 step, s64 def);
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci/**
9038c2ecf20Sopenharmony_ci * v4l2_ctrl_modify_range() - Update the range of a control.
9048c2ecf20Sopenharmony_ci *
9058c2ecf20Sopenharmony_ci * @ctrl:	The control to update.
9068c2ecf20Sopenharmony_ci * @min:	The control's minimum value.
9078c2ecf20Sopenharmony_ci * @max:	The control's maximum value.
9088c2ecf20Sopenharmony_ci * @step:	The control's step value
9098c2ecf20Sopenharmony_ci * @def:	The control's default value.
9108c2ecf20Sopenharmony_ci *
9118c2ecf20Sopenharmony_ci * Update the range of a control on the fly. This works for control types
9128c2ecf20Sopenharmony_ci * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
9138c2ecf20Sopenharmony_ci * @step value is interpreted as a menu_skip_mask.
9148c2ecf20Sopenharmony_ci *
9158c2ecf20Sopenharmony_ci * An error is returned if one of the range arguments is invalid for this
9168c2ecf20Sopenharmony_ci * control type.
9178c2ecf20Sopenharmony_ci *
9188c2ecf20Sopenharmony_ci * This function assumes that the control handler is not locked and will
9198c2ecf20Sopenharmony_ci * take the lock itself.
9208c2ecf20Sopenharmony_ci */
9218c2ecf20Sopenharmony_cistatic inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
9228c2ecf20Sopenharmony_ci					 s64 min, s64 max, u64 step, s64 def)
9238c2ecf20Sopenharmony_ci{
9248c2ecf20Sopenharmony_ci	int rval;
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	v4l2_ctrl_lock(ctrl);
9278c2ecf20Sopenharmony_ci	rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
9288c2ecf20Sopenharmony_ci	v4l2_ctrl_unlock(ctrl);
9298c2ecf20Sopenharmony_ci
9308c2ecf20Sopenharmony_ci	return rval;
9318c2ecf20Sopenharmony_ci}
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci/**
9348c2ecf20Sopenharmony_ci * v4l2_ctrl_notify() - Function to set a notify callback for a control.
9358c2ecf20Sopenharmony_ci *
9368c2ecf20Sopenharmony_ci * @ctrl:	The control.
9378c2ecf20Sopenharmony_ci * @notify:	The callback function.
9388c2ecf20Sopenharmony_ci * @priv:	The callback private handle, passed as argument to the callback.
9398c2ecf20Sopenharmony_ci *
9408c2ecf20Sopenharmony_ci * This function sets a callback function for the control. If @ctrl is NULL,
9418c2ecf20Sopenharmony_ci * then it will do nothing. If @notify is NULL, then the notify callback will
9428c2ecf20Sopenharmony_ci * be removed.
9438c2ecf20Sopenharmony_ci *
9448c2ecf20Sopenharmony_ci * There can be only one notify. If another already exists, then a WARN_ON
9458c2ecf20Sopenharmony_ci * will be issued and the function will do nothing.
9468c2ecf20Sopenharmony_ci */
9478c2ecf20Sopenharmony_civoid v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
9488c2ecf20Sopenharmony_ci		      void *priv);
9498c2ecf20Sopenharmony_ci
9508c2ecf20Sopenharmony_ci/**
9518c2ecf20Sopenharmony_ci * v4l2_ctrl_get_name() - Get the name of the control
9528c2ecf20Sopenharmony_ci *
9538c2ecf20Sopenharmony_ci * @id:		The control ID.
9548c2ecf20Sopenharmony_ci *
9558c2ecf20Sopenharmony_ci * This function returns the name of the given control ID or NULL if it isn't
9568c2ecf20Sopenharmony_ci * a known control.
9578c2ecf20Sopenharmony_ci */
9588c2ecf20Sopenharmony_ciconst char *v4l2_ctrl_get_name(u32 id);
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_ci/**
9618c2ecf20Sopenharmony_ci * v4l2_ctrl_get_menu() - Get the menu string array of the control
9628c2ecf20Sopenharmony_ci *
9638c2ecf20Sopenharmony_ci * @id:		The control ID.
9648c2ecf20Sopenharmony_ci *
9658c2ecf20Sopenharmony_ci * This function returns the NULL-terminated menu string array name of the
9668c2ecf20Sopenharmony_ci * given control ID or NULL if it isn't a known menu control.
9678c2ecf20Sopenharmony_ci */
9688c2ecf20Sopenharmony_ciconst char * const *v4l2_ctrl_get_menu(u32 id);
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci/**
9718c2ecf20Sopenharmony_ci * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
9728c2ecf20Sopenharmony_ci *
9738c2ecf20Sopenharmony_ci * @id:		The control ID.
9748c2ecf20Sopenharmony_ci * @len:	The size of the integer array.
9758c2ecf20Sopenharmony_ci *
9768c2ecf20Sopenharmony_ci * This function returns the integer array of the given control ID or NULL if it
9778c2ecf20Sopenharmony_ci * if it isn't a known integer menu control.
9788c2ecf20Sopenharmony_ci */
9798c2ecf20Sopenharmony_ciconst s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
9808c2ecf20Sopenharmony_ci
9818c2ecf20Sopenharmony_ci/**
9828c2ecf20Sopenharmony_ci * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
9838c2ecf20Sopenharmony_ci *	within a driver.
9848c2ecf20Sopenharmony_ci *
9858c2ecf20Sopenharmony_ci * @ctrl:	The control.
9868c2ecf20Sopenharmony_ci *
9878c2ecf20Sopenharmony_ci * This returns the control's value safely by going through the control
9888c2ecf20Sopenharmony_ci * framework. This function will lock the control's handler, so it cannot be
9898c2ecf20Sopenharmony_ci * used from within the &v4l2_ctrl_ops functions.
9908c2ecf20Sopenharmony_ci *
9918c2ecf20Sopenharmony_ci * This function is for integer type controls only.
9928c2ecf20Sopenharmony_ci */
9938c2ecf20Sopenharmony_cis32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci/**
9968c2ecf20Sopenharmony_ci * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
9978c2ecf20Sopenharmony_ci *
9988c2ecf20Sopenharmony_ci * @ctrl:	The control.
9998c2ecf20Sopenharmony_ci * @val:	The new value.
10008c2ecf20Sopenharmony_ci *
10018c2ecf20Sopenharmony_ci * This sets the control's new value safely by going through the control
10028c2ecf20Sopenharmony_ci * framework. This function assumes the control's handler is already locked,
10038c2ecf20Sopenharmony_ci * allowing it to be used from within the &v4l2_ctrl_ops functions.
10048c2ecf20Sopenharmony_ci *
10058c2ecf20Sopenharmony_ci * This function is for integer type controls only.
10068c2ecf20Sopenharmony_ci */
10078c2ecf20Sopenharmony_ciint __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci/**
10108c2ecf20Sopenharmony_ci * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
10118c2ecf20Sopenharmony_ci *	within a driver.
10128c2ecf20Sopenharmony_ci * @ctrl:	The control.
10138c2ecf20Sopenharmony_ci * @val:	The new value.
10148c2ecf20Sopenharmony_ci *
10158c2ecf20Sopenharmony_ci * This sets the control's new value safely by going through the control
10168c2ecf20Sopenharmony_ci * framework. This function will lock the control's handler, so it cannot be
10178c2ecf20Sopenharmony_ci * used from within the &v4l2_ctrl_ops functions.
10188c2ecf20Sopenharmony_ci *
10198c2ecf20Sopenharmony_ci * This function is for integer type controls only.
10208c2ecf20Sopenharmony_ci */
10218c2ecf20Sopenharmony_cistatic inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
10228c2ecf20Sopenharmony_ci{
10238c2ecf20Sopenharmony_ci	int rval;
10248c2ecf20Sopenharmony_ci
10258c2ecf20Sopenharmony_ci	v4l2_ctrl_lock(ctrl);
10268c2ecf20Sopenharmony_ci	rval = __v4l2_ctrl_s_ctrl(ctrl, val);
10278c2ecf20Sopenharmony_ci	v4l2_ctrl_unlock(ctrl);
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci	return rval;
10308c2ecf20Sopenharmony_ci}
10318c2ecf20Sopenharmony_ci
10328c2ecf20Sopenharmony_ci/**
10338c2ecf20Sopenharmony_ci * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
10348c2ecf20Sopenharmony_ci *	from within a driver.
10358c2ecf20Sopenharmony_ci *
10368c2ecf20Sopenharmony_ci * @ctrl:	The control.
10378c2ecf20Sopenharmony_ci *
10388c2ecf20Sopenharmony_ci * This returns the control's value safely by going through the control
10398c2ecf20Sopenharmony_ci * framework. This function will lock the control's handler, so it cannot be
10408c2ecf20Sopenharmony_ci * used from within the &v4l2_ctrl_ops functions.
10418c2ecf20Sopenharmony_ci *
10428c2ecf20Sopenharmony_ci * This function is for 64-bit integer type controls only.
10438c2ecf20Sopenharmony_ci */
10448c2ecf20Sopenharmony_cis64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci/**
10478c2ecf20Sopenharmony_ci * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
10488c2ecf20Sopenharmony_ci *
10498c2ecf20Sopenharmony_ci * @ctrl:	The control.
10508c2ecf20Sopenharmony_ci * @val:	The new value.
10518c2ecf20Sopenharmony_ci *
10528c2ecf20Sopenharmony_ci * This sets the control's new value safely by going through the control
10538c2ecf20Sopenharmony_ci * framework. This function assumes the control's handler is already locked,
10548c2ecf20Sopenharmony_ci * allowing it to be used from within the &v4l2_ctrl_ops functions.
10558c2ecf20Sopenharmony_ci *
10568c2ecf20Sopenharmony_ci * This function is for 64-bit integer type controls only.
10578c2ecf20Sopenharmony_ci */
10588c2ecf20Sopenharmony_ciint __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
10598c2ecf20Sopenharmony_ci
10608c2ecf20Sopenharmony_ci/**
10618c2ecf20Sopenharmony_ci * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
10628c2ecf20Sopenharmony_ci *	from within a driver.
10638c2ecf20Sopenharmony_ci *
10648c2ecf20Sopenharmony_ci * @ctrl:	The control.
10658c2ecf20Sopenharmony_ci * @val:	The new value.
10668c2ecf20Sopenharmony_ci *
10678c2ecf20Sopenharmony_ci * This sets the control's new value safely by going through the control
10688c2ecf20Sopenharmony_ci * framework. This function will lock the control's handler, so it cannot be
10698c2ecf20Sopenharmony_ci * used from within the &v4l2_ctrl_ops functions.
10708c2ecf20Sopenharmony_ci *
10718c2ecf20Sopenharmony_ci * This function is for 64-bit integer type controls only.
10728c2ecf20Sopenharmony_ci */
10738c2ecf20Sopenharmony_cistatic inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
10748c2ecf20Sopenharmony_ci{
10758c2ecf20Sopenharmony_ci	int rval;
10768c2ecf20Sopenharmony_ci
10778c2ecf20Sopenharmony_ci	v4l2_ctrl_lock(ctrl);
10788c2ecf20Sopenharmony_ci	rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
10798c2ecf20Sopenharmony_ci	v4l2_ctrl_unlock(ctrl);
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci	return rval;
10828c2ecf20Sopenharmony_ci}
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci/**
10858c2ecf20Sopenharmony_ci * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
10868c2ecf20Sopenharmony_ci *
10878c2ecf20Sopenharmony_ci * @ctrl:	The control.
10888c2ecf20Sopenharmony_ci * @s:		The new string.
10898c2ecf20Sopenharmony_ci *
10908c2ecf20Sopenharmony_ci * This sets the control's new string safely by going through the control
10918c2ecf20Sopenharmony_ci * framework. This function assumes the control's handler is already locked,
10928c2ecf20Sopenharmony_ci * allowing it to be used from within the &v4l2_ctrl_ops functions.
10938c2ecf20Sopenharmony_ci *
10948c2ecf20Sopenharmony_ci * This function is for string type controls only.
10958c2ecf20Sopenharmony_ci */
10968c2ecf20Sopenharmony_ciint __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ci/**
10998c2ecf20Sopenharmony_ci * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
11008c2ecf20Sopenharmony_ci *	 from within a driver.
11018c2ecf20Sopenharmony_ci *
11028c2ecf20Sopenharmony_ci * @ctrl:	The control.
11038c2ecf20Sopenharmony_ci * @s:		The new string.
11048c2ecf20Sopenharmony_ci *
11058c2ecf20Sopenharmony_ci * This sets the control's new string safely by going through the control
11068c2ecf20Sopenharmony_ci * framework. This function will lock the control's handler, so it cannot be
11078c2ecf20Sopenharmony_ci * used from within the &v4l2_ctrl_ops functions.
11088c2ecf20Sopenharmony_ci *
11098c2ecf20Sopenharmony_ci * This function is for string type controls only.
11108c2ecf20Sopenharmony_ci */
11118c2ecf20Sopenharmony_cistatic inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
11128c2ecf20Sopenharmony_ci{
11138c2ecf20Sopenharmony_ci	int rval;
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	v4l2_ctrl_lock(ctrl);
11168c2ecf20Sopenharmony_ci	rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
11178c2ecf20Sopenharmony_ci	v4l2_ctrl_unlock(ctrl);
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci	return rval;
11208c2ecf20Sopenharmony_ci}
11218c2ecf20Sopenharmony_ci
11228c2ecf20Sopenharmony_ci/**
11238c2ecf20Sopenharmony_ci * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
11248c2ecf20Sopenharmony_ci *
11258c2ecf20Sopenharmony_ci * @ctrl: The control.
11268c2ecf20Sopenharmony_ci * @type: The type of the data.
11278c2ecf20Sopenharmony_ci * @p:    The new compound payload.
11288c2ecf20Sopenharmony_ci *
11298c2ecf20Sopenharmony_ci * This sets the control's new compound payload safely by going through the
11308c2ecf20Sopenharmony_ci * control framework. This function assumes the control's handler is already
11318c2ecf20Sopenharmony_ci * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
11328c2ecf20Sopenharmony_ci *
11338c2ecf20Sopenharmony_ci * This function is for compound type controls only.
11348c2ecf20Sopenharmony_ci */
11358c2ecf20Sopenharmony_ciint __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
11368c2ecf20Sopenharmony_ci				enum v4l2_ctrl_type type, const void *p);
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci/**
11398c2ecf20Sopenharmony_ci * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
11408c2ecf20Sopenharmony_ci *	from within a driver.
11418c2ecf20Sopenharmony_ci *
11428c2ecf20Sopenharmony_ci * @ctrl: The control.
11438c2ecf20Sopenharmony_ci * @type: The type of the data.
11448c2ecf20Sopenharmony_ci * @p:    The new compound payload.
11458c2ecf20Sopenharmony_ci *
11468c2ecf20Sopenharmony_ci * This sets the control's new compound payload safely by going through the
11478c2ecf20Sopenharmony_ci * control framework. This function will lock the control's handler, so it
11488c2ecf20Sopenharmony_ci * cannot be used from within the &v4l2_ctrl_ops functions.
11498c2ecf20Sopenharmony_ci *
11508c2ecf20Sopenharmony_ci * This function is for compound type controls only.
11518c2ecf20Sopenharmony_ci */
11528c2ecf20Sopenharmony_cistatic inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
11538c2ecf20Sopenharmony_ci					    enum v4l2_ctrl_type type,
11548c2ecf20Sopenharmony_ci					    const void *p)
11558c2ecf20Sopenharmony_ci{
11568c2ecf20Sopenharmony_ci	int rval;
11578c2ecf20Sopenharmony_ci
11588c2ecf20Sopenharmony_ci	v4l2_ctrl_lock(ctrl);
11598c2ecf20Sopenharmony_ci	rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
11608c2ecf20Sopenharmony_ci	v4l2_ctrl_unlock(ctrl);
11618c2ecf20Sopenharmony_ci
11628c2ecf20Sopenharmony_ci	return rval;
11638c2ecf20Sopenharmony_ci}
11648c2ecf20Sopenharmony_ci
11658c2ecf20Sopenharmony_ci/* Helper defines for area type controls */
11668c2ecf20Sopenharmony_ci#define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
11678c2ecf20Sopenharmony_ci	__v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
11688c2ecf20Sopenharmony_ci#define v4l2_ctrl_s_ctrl_area(ctrl, area) \
11698c2ecf20Sopenharmony_ci	v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_ci/* Internal helper functions that deal with control events. */
11728c2ecf20Sopenharmony_ciextern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
11738c2ecf20Sopenharmony_ci
11748c2ecf20Sopenharmony_ci/**
11758c2ecf20Sopenharmony_ci * v4l2_ctrl_replace - Function to be used as a callback to
11768c2ecf20Sopenharmony_ci *	&struct v4l2_subscribed_event_ops replace\(\)
11778c2ecf20Sopenharmony_ci *
11788c2ecf20Sopenharmony_ci * @old: pointer to struct &v4l2_event with the reported
11798c2ecf20Sopenharmony_ci *	 event;
11808c2ecf20Sopenharmony_ci * @new: pointer to struct &v4l2_event with the modified
11818c2ecf20Sopenharmony_ci *	 event;
11828c2ecf20Sopenharmony_ci */
11838c2ecf20Sopenharmony_civoid v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
11848c2ecf20Sopenharmony_ci
11858c2ecf20Sopenharmony_ci/**
11868c2ecf20Sopenharmony_ci * v4l2_ctrl_merge - Function to be used as a callback to
11878c2ecf20Sopenharmony_ci *	&struct v4l2_subscribed_event_ops merge(\)
11888c2ecf20Sopenharmony_ci *
11898c2ecf20Sopenharmony_ci * @old: pointer to struct &v4l2_event with the reported
11908c2ecf20Sopenharmony_ci *	 event;
11918c2ecf20Sopenharmony_ci * @new: pointer to struct &v4l2_event with the merged
11928c2ecf20Sopenharmony_ci *	 event;
11938c2ecf20Sopenharmony_ci */
11948c2ecf20Sopenharmony_civoid v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci/**
11978c2ecf20Sopenharmony_ci * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
11988c2ecf20Sopenharmony_ci *
11998c2ecf20Sopenharmony_ci * @file: pointer to struct file
12008c2ecf20Sopenharmony_ci * @fh: unused. Kept just to be compatible to the arguments expected by
12018c2ecf20Sopenharmony_ci *	&struct v4l2_ioctl_ops.vidioc_log_status.
12028c2ecf20Sopenharmony_ci *
12038c2ecf20Sopenharmony_ci * Can be used as a vidioc_log_status function that just dumps all controls
12048c2ecf20Sopenharmony_ci * associated with the filehandle.
12058c2ecf20Sopenharmony_ci */
12068c2ecf20Sopenharmony_ciint v4l2_ctrl_log_status(struct file *file, void *fh);
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ci/**
12098c2ecf20Sopenharmony_ci * v4l2_ctrl_subscribe_event - Subscribes to an event
12108c2ecf20Sopenharmony_ci *
12118c2ecf20Sopenharmony_ci *
12128c2ecf20Sopenharmony_ci * @fh: pointer to struct v4l2_fh
12138c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription
12148c2ecf20Sopenharmony_ci *
12158c2ecf20Sopenharmony_ci * Can be used as a vidioc_subscribe_event function that just subscribes
12168c2ecf20Sopenharmony_ci * control events.
12178c2ecf20Sopenharmony_ci */
12188c2ecf20Sopenharmony_ciint v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
12198c2ecf20Sopenharmony_ci				const struct v4l2_event_subscription *sub);
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci/**
12228c2ecf20Sopenharmony_ci * v4l2_ctrl_poll - function to be used as a callback to the poll()
12238c2ecf20Sopenharmony_ci *	That just polls for control events.
12248c2ecf20Sopenharmony_ci *
12258c2ecf20Sopenharmony_ci * @file: pointer to struct file
12268c2ecf20Sopenharmony_ci * @wait: pointer to struct poll_table_struct
12278c2ecf20Sopenharmony_ci */
12288c2ecf20Sopenharmony_ci__poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
12298c2ecf20Sopenharmony_ci
12308c2ecf20Sopenharmony_ci/**
12318c2ecf20Sopenharmony_ci * v4l2_ctrl_request_setup - helper function to apply control values in a request
12328c2ecf20Sopenharmony_ci *
12338c2ecf20Sopenharmony_ci * @req: The request
12348c2ecf20Sopenharmony_ci * @parent: The parent control handler ('priv' in media_request_object_find())
12358c2ecf20Sopenharmony_ci *
12368c2ecf20Sopenharmony_ci * This is a helper function to call the control handler's s_ctrl callback with
12378c2ecf20Sopenharmony_ci * the control values contained in the request. Do note that this approach of
12388c2ecf20Sopenharmony_ci * applying control values in a request is only applicable to memory-to-memory
12398c2ecf20Sopenharmony_ci * devices.
12408c2ecf20Sopenharmony_ci */
12418c2ecf20Sopenharmony_ciint v4l2_ctrl_request_setup(struct media_request *req,
12428c2ecf20Sopenharmony_ci			     struct v4l2_ctrl_handler *parent);
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci/**
12458c2ecf20Sopenharmony_ci * v4l2_ctrl_request_complete - Complete a control handler request object
12468c2ecf20Sopenharmony_ci *
12478c2ecf20Sopenharmony_ci * @req: The request
12488c2ecf20Sopenharmony_ci * @parent: The parent control handler ('priv' in media_request_object_find())
12498c2ecf20Sopenharmony_ci *
12508c2ecf20Sopenharmony_ci * This function is to be called on each control handler that may have had a
12518c2ecf20Sopenharmony_ci * request object associated with it, i.e. control handlers of a driver that
12528c2ecf20Sopenharmony_ci * supports requests.
12538c2ecf20Sopenharmony_ci *
12548c2ecf20Sopenharmony_ci * The function first obtains the values of any volatile controls in the control
12558c2ecf20Sopenharmony_ci * handler and attach them to the request. Then, the function completes the
12568c2ecf20Sopenharmony_ci * request object.
12578c2ecf20Sopenharmony_ci */
12588c2ecf20Sopenharmony_civoid v4l2_ctrl_request_complete(struct media_request *req,
12598c2ecf20Sopenharmony_ci				struct v4l2_ctrl_handler *parent);
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ci/**
12628c2ecf20Sopenharmony_ci * v4l2_ctrl_request_hdl_find - Find the control handler in the request
12638c2ecf20Sopenharmony_ci *
12648c2ecf20Sopenharmony_ci * @req: The request
12658c2ecf20Sopenharmony_ci * @parent: The parent control handler ('priv' in media_request_object_find())
12668c2ecf20Sopenharmony_ci *
12678c2ecf20Sopenharmony_ci * This function finds the control handler in the request. It may return
12688c2ecf20Sopenharmony_ci * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl()
12698c2ecf20Sopenharmony_ci * with the returned handler pointer.
12708c2ecf20Sopenharmony_ci *
12718c2ecf20Sopenharmony_ci * If the request is not in state VALIDATING or QUEUED, then this function
12728c2ecf20Sopenharmony_ci * will always return NULL.
12738c2ecf20Sopenharmony_ci *
12748c2ecf20Sopenharmony_ci * Note that in state VALIDATING the req_queue_mutex is held, so
12758c2ecf20Sopenharmony_ci * no objects can be added or deleted from the request.
12768c2ecf20Sopenharmony_ci *
12778c2ecf20Sopenharmony_ci * In state QUEUED it is the driver that will have to ensure this.
12788c2ecf20Sopenharmony_ci */
12798c2ecf20Sopenharmony_cistruct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
12808c2ecf20Sopenharmony_ci					struct v4l2_ctrl_handler *parent);
12818c2ecf20Sopenharmony_ci
12828c2ecf20Sopenharmony_ci/**
12838c2ecf20Sopenharmony_ci * v4l2_ctrl_request_hdl_put - Put the control handler
12848c2ecf20Sopenharmony_ci *
12858c2ecf20Sopenharmony_ci * @hdl: Put this control handler
12868c2ecf20Sopenharmony_ci *
12878c2ecf20Sopenharmony_ci * This function released the control handler previously obtained from'
12888c2ecf20Sopenharmony_ci * v4l2_ctrl_request_hdl_find().
12898c2ecf20Sopenharmony_ci */
12908c2ecf20Sopenharmony_cistatic inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
12918c2ecf20Sopenharmony_ci{
12928c2ecf20Sopenharmony_ci	if (hdl)
12938c2ecf20Sopenharmony_ci		media_request_object_put(&hdl->req_obj);
12948c2ecf20Sopenharmony_ci}
12958c2ecf20Sopenharmony_ci
12968c2ecf20Sopenharmony_ci/**
12978c2ecf20Sopenharmony_ci * v4l2_ctrl_request_ctrl_find() - Find a control with the given ID.
12988c2ecf20Sopenharmony_ci *
12998c2ecf20Sopenharmony_ci * @hdl: The control handler from the request.
13008c2ecf20Sopenharmony_ci * @id: The ID of the control to find.
13018c2ecf20Sopenharmony_ci *
13028c2ecf20Sopenharmony_ci * This function returns a pointer to the control if this control is
13038c2ecf20Sopenharmony_ci * part of the request or NULL otherwise.
13048c2ecf20Sopenharmony_ci */
13058c2ecf20Sopenharmony_cistruct v4l2_ctrl *
13068c2ecf20Sopenharmony_civ4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci/* Helpers for ioctl_ops */
13098c2ecf20Sopenharmony_ci
13108c2ecf20Sopenharmony_ci/**
13118c2ecf20Sopenharmony_ci * v4l2_queryctrl - Helper function to implement
13128c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
13138c2ecf20Sopenharmony_ci *
13148c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13158c2ecf20Sopenharmony_ci * @qc: pointer to &struct v4l2_queryctrl
13168c2ecf20Sopenharmony_ci *
13178c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13188c2ecf20Sopenharmony_ci */
13198c2ecf20Sopenharmony_ciint v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
13208c2ecf20Sopenharmony_ci
13218c2ecf20Sopenharmony_ci/**
13228c2ecf20Sopenharmony_ci * v4l2_query_ext_ctrl - Helper function to implement
13238c2ecf20Sopenharmony_ci *	 :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
13248c2ecf20Sopenharmony_ci *
13258c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13268c2ecf20Sopenharmony_ci * @qc: pointer to &struct v4l2_query_ext_ctrl
13278c2ecf20Sopenharmony_ci *
13288c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13298c2ecf20Sopenharmony_ci */
13308c2ecf20Sopenharmony_ciint v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
13318c2ecf20Sopenharmony_ci			struct v4l2_query_ext_ctrl *qc);
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci/**
13348c2ecf20Sopenharmony_ci * v4l2_querymenu - Helper function to implement
13358c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
13368c2ecf20Sopenharmony_ci *
13378c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13388c2ecf20Sopenharmony_ci * @qm: pointer to &struct v4l2_querymenu
13398c2ecf20Sopenharmony_ci *
13408c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13418c2ecf20Sopenharmony_ci */
13428c2ecf20Sopenharmony_ciint v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
13438c2ecf20Sopenharmony_ci
13448c2ecf20Sopenharmony_ci/**
13458c2ecf20Sopenharmony_ci * v4l2_g_ctrl - Helper function to implement
13468c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
13478c2ecf20Sopenharmony_ci *
13488c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13498c2ecf20Sopenharmony_ci * @ctrl: pointer to &struct v4l2_control
13508c2ecf20Sopenharmony_ci *
13518c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13528c2ecf20Sopenharmony_ci */
13538c2ecf20Sopenharmony_ciint v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
13548c2ecf20Sopenharmony_ci
13558c2ecf20Sopenharmony_ci/**
13568c2ecf20Sopenharmony_ci * v4l2_s_ctrl - Helper function to implement
13578c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
13588c2ecf20Sopenharmony_ci *
13598c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh
13608c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13618c2ecf20Sopenharmony_ci *
13628c2ecf20Sopenharmony_ci * @ctrl: pointer to &struct v4l2_control
13638c2ecf20Sopenharmony_ci *
13648c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13658c2ecf20Sopenharmony_ci */
13668c2ecf20Sopenharmony_ciint v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
13678c2ecf20Sopenharmony_ci		struct v4l2_control *ctrl);
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci/**
13708c2ecf20Sopenharmony_ci * v4l2_g_ext_ctrls - Helper function to implement
13718c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
13728c2ecf20Sopenharmony_ci *
13738c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13748c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device
13758c2ecf20Sopenharmony_ci * @mdev: pointer to &struct media_device
13768c2ecf20Sopenharmony_ci * @c: pointer to &struct v4l2_ext_controls
13778c2ecf20Sopenharmony_ci *
13788c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13798c2ecf20Sopenharmony_ci */
13808c2ecf20Sopenharmony_ciint v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
13818c2ecf20Sopenharmony_ci		     struct media_device *mdev, struct v4l2_ext_controls *c);
13828c2ecf20Sopenharmony_ci
13838c2ecf20Sopenharmony_ci/**
13848c2ecf20Sopenharmony_ci * v4l2_try_ext_ctrls - Helper function to implement
13858c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
13868c2ecf20Sopenharmony_ci *
13878c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
13888c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device
13898c2ecf20Sopenharmony_ci * @mdev: pointer to &struct media_device
13908c2ecf20Sopenharmony_ci * @c: pointer to &struct v4l2_ext_controls
13918c2ecf20Sopenharmony_ci *
13928c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
13938c2ecf20Sopenharmony_ci */
13948c2ecf20Sopenharmony_ciint v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
13958c2ecf20Sopenharmony_ci		       struct video_device *vdev,
13968c2ecf20Sopenharmony_ci		       struct media_device *mdev,
13978c2ecf20Sopenharmony_ci		       struct v4l2_ext_controls *c);
13988c2ecf20Sopenharmony_ci
13998c2ecf20Sopenharmony_ci/**
14008c2ecf20Sopenharmony_ci * v4l2_s_ext_ctrls - Helper function to implement
14018c2ecf20Sopenharmony_ci *	:ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
14028c2ecf20Sopenharmony_ci *
14038c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh
14048c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler
14058c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device
14068c2ecf20Sopenharmony_ci * @mdev: pointer to &struct media_device
14078c2ecf20Sopenharmony_ci * @c: pointer to &struct v4l2_ext_controls
14088c2ecf20Sopenharmony_ci *
14098c2ecf20Sopenharmony_ci * If hdl == NULL then they will all return -EINVAL.
14108c2ecf20Sopenharmony_ci */
14118c2ecf20Sopenharmony_ciint v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
14128c2ecf20Sopenharmony_ci		     struct video_device *vdev,
14138c2ecf20Sopenharmony_ci		     struct media_device *mdev,
14148c2ecf20Sopenharmony_ci		     struct v4l2_ext_controls *c);
14158c2ecf20Sopenharmony_ci
14168c2ecf20Sopenharmony_ci/**
14178c2ecf20Sopenharmony_ci * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
14188c2ecf20Sopenharmony_ci *	as a &struct v4l2_subdev_core_ops subscribe_event function
14198c2ecf20Sopenharmony_ci *	that just subscribes control events.
14208c2ecf20Sopenharmony_ci *
14218c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
14228c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh
14238c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription
14248c2ecf20Sopenharmony_ci */
14258c2ecf20Sopenharmony_ciint v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
14268c2ecf20Sopenharmony_ci				     struct v4l2_event_subscription *sub);
14278c2ecf20Sopenharmony_ci
14288c2ecf20Sopenharmony_ci/**
14298c2ecf20Sopenharmony_ci * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
14308c2ecf20Sopenharmony_ci *	 handler.
14318c2ecf20Sopenharmony_ci *
14328c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
14338c2ecf20Sopenharmony_ci */
14348c2ecf20Sopenharmony_ciint v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
14358c2ecf20Sopenharmony_ci
14368c2ecf20Sopenharmony_ci/**
14378c2ecf20Sopenharmony_ci * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
14388c2ecf20Sopenharmony_ci *				       properties
14398c2ecf20Sopenharmony_ci *
14408c2ecf20Sopenharmony_ci * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
14418c2ecf20Sopenharmony_ci * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
14428c2ecf20Sopenharmony_ci * @p: pointer to &struct v4l2_fwnode_device_properties
14438c2ecf20Sopenharmony_ci *
14448c2ecf20Sopenharmony_ci * This function registers controls associated to device properties, using the
14458c2ecf20Sopenharmony_ci * property values contained in @p parameter, if the property has been set to
14468c2ecf20Sopenharmony_ci * a value.
14478c2ecf20Sopenharmony_ci *
14488c2ecf20Sopenharmony_ci * Currently the following v4l2 controls are parsed and registered:
14498c2ecf20Sopenharmony_ci * - V4L2_CID_CAMERA_ORIENTATION
14508c2ecf20Sopenharmony_ci * - V4L2_CID_CAMERA_SENSOR_ROTATION;
14518c2ecf20Sopenharmony_ci *
14528c2ecf20Sopenharmony_ci * Controls already registered by the caller with the @hdl control handler are
14538c2ecf20Sopenharmony_ci * not overwritten. Callers should register the controls they want to handle
14548c2ecf20Sopenharmony_ci * themselves before calling this function.
14558c2ecf20Sopenharmony_ci *
14568c2ecf20Sopenharmony_ci * Return: 0 on success, a negative error code on failure.
14578c2ecf20Sopenharmony_ci */
14588c2ecf20Sopenharmony_ciint v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
14598c2ecf20Sopenharmony_ci				    const struct v4l2_ctrl_ops *ctrl_ops,
14608c2ecf20Sopenharmony_ci				    const struct v4l2_fwnode_device_properties *p);
14618c2ecf20Sopenharmony_ci#endif
1462