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