xref: /openbmc/linux/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst (revision 54f38fcae536ea202ce7d6a359521492fba30c1f)
1*54f38fcaSMauro Carvalho Chehab.. Permission is granted to copy, distribute and/or modify this
2*54f38fcaSMauro Carvalho Chehab.. document under the terms of the GNU Free Documentation License,
3*54f38fcaSMauro Carvalho Chehab.. Version 1.1 or any later version published by the Free Software
4*54f38fcaSMauro Carvalho Chehab.. Foundation, with no Invariant Sections, no Front-Cover Texts
5*54f38fcaSMauro Carvalho Chehab.. and no Back-Cover Texts. A copy of the license is included at
6*54f38fcaSMauro Carvalho Chehab.. Documentation/userspace-api/media/fdl-appendix.rst.
7*54f38fcaSMauro Carvalho Chehab..
8*54f38fcaSMauro Carvalho Chehab.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9*54f38fcaSMauro Carvalho Chehab
10*54f38fcaSMauro Carvalho Chehab.. _VIDIOC_G_EXT_CTRLS:
11*54f38fcaSMauro Carvalho Chehab
12*54f38fcaSMauro Carvalho Chehab******************************************************************
13*54f38fcaSMauro Carvalho Chehabioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS
14*54f38fcaSMauro Carvalho Chehab******************************************************************
15*54f38fcaSMauro Carvalho Chehab
16*54f38fcaSMauro Carvalho ChehabName
17*54f38fcaSMauro Carvalho Chehab====
18*54f38fcaSMauro Carvalho Chehab
19*54f38fcaSMauro Carvalho ChehabVIDIOC_G_EXT_CTRLS - VIDIOC_S_EXT_CTRLS - VIDIOC_TRY_EXT_CTRLS - Get or set the value of several controls, try control values
20*54f38fcaSMauro Carvalho Chehab
21*54f38fcaSMauro Carvalho Chehab
22*54f38fcaSMauro Carvalho ChehabSynopsis
23*54f38fcaSMauro Carvalho Chehab========
24*54f38fcaSMauro Carvalho Chehab
25*54f38fcaSMauro Carvalho Chehab.. c:function:: int ioctl( int fd, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp )
26*54f38fcaSMauro Carvalho Chehab    :name: VIDIOC_G_EXT_CTRLS
27*54f38fcaSMauro Carvalho Chehab
28*54f38fcaSMauro Carvalho Chehab
29*54f38fcaSMauro Carvalho Chehab.. c:function:: int ioctl( int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp )
30*54f38fcaSMauro Carvalho Chehab    :name: VIDIOC_S_EXT_CTRLS
31*54f38fcaSMauro Carvalho Chehab
32*54f38fcaSMauro Carvalho Chehab
33*54f38fcaSMauro Carvalho Chehab.. c:function:: int ioctl( int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp )
34*54f38fcaSMauro Carvalho Chehab    :name: VIDIOC_TRY_EXT_CTRLS
35*54f38fcaSMauro Carvalho Chehab
36*54f38fcaSMauro Carvalho Chehab
37*54f38fcaSMauro Carvalho ChehabArguments
38*54f38fcaSMauro Carvalho Chehab=========
39*54f38fcaSMauro Carvalho Chehab
40*54f38fcaSMauro Carvalho Chehab``fd``
41*54f38fcaSMauro Carvalho Chehab    File descriptor returned by :ref:`open() <func-open>`.
42*54f38fcaSMauro Carvalho Chehab
43*54f38fcaSMauro Carvalho Chehab``argp``
44*54f38fcaSMauro Carvalho Chehab    Pointer to struct :c:type:`v4l2_ext_controls`.
45*54f38fcaSMauro Carvalho Chehab
46*54f38fcaSMauro Carvalho Chehab
47*54f38fcaSMauro Carvalho ChehabDescription
48*54f38fcaSMauro Carvalho Chehab===========
49*54f38fcaSMauro Carvalho Chehab
50*54f38fcaSMauro Carvalho ChehabThese ioctls allow the caller to get or set multiple controls
51*54f38fcaSMauro Carvalho Chehabatomically. Control IDs are grouped into control classes (see
52*54f38fcaSMauro Carvalho Chehab:ref:`ctrl-class`) and all controls in the control array must belong
53*54f38fcaSMauro Carvalho Chehabto the same control class.
54*54f38fcaSMauro Carvalho Chehab
55*54f38fcaSMauro Carvalho ChehabApplications must always fill in the ``count``, ``which``, ``controls``
56*54f38fcaSMauro Carvalho Chehaband ``reserved`` fields of struct
57*54f38fcaSMauro Carvalho Chehab:c:type:`v4l2_ext_controls`, and initialize the
58*54f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_ext_control` array pointed to
59*54f38fcaSMauro Carvalho Chehabby the ``controls`` fields.
60*54f38fcaSMauro Carvalho Chehab
61*54f38fcaSMauro Carvalho ChehabTo get the current value of a set of controls applications initialize
62*54f38fcaSMauro Carvalho Chehabthe ``id``, ``size`` and ``reserved2`` fields of each struct
63*54f38fcaSMauro Carvalho Chehab:c:type:`v4l2_ext_control` and call the
64*54f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. String controls controls must also set the
65*54f38fcaSMauro Carvalho Chehab``string`` field. Controls of compound types
66*54f38fcaSMauro Carvalho Chehab(``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set) must set the ``ptr`` field.
67*54f38fcaSMauro Carvalho Chehab
68*54f38fcaSMauro Carvalho ChehabIf the ``size`` is too small to receive the control result (only
69*54f38fcaSMauro Carvalho Chehabrelevant for pointer-type controls like strings), then the driver will
70*54f38fcaSMauro Carvalho Chehabset ``size`` to a valid value and return an ``ENOSPC`` error code. You
71*54f38fcaSMauro Carvalho Chehabshould re-allocate the memory to this new size and try again. For the
72*54f38fcaSMauro Carvalho Chehabstring type it is possible that the same issue occurs again if the
73*54f38fcaSMauro Carvalho Chehabstring has grown in the meantime. It is recommended to call
74*54f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_QUERYCTRL` first and use
75*54f38fcaSMauro Carvalho Chehab``maximum``\ +1 as the new ``size`` value. It is guaranteed that that is
76*54f38fcaSMauro Carvalho Chehabsufficient memory.
77*54f38fcaSMauro Carvalho Chehab
78*54f38fcaSMauro Carvalho ChehabN-dimensional arrays are set and retrieved row-by-row. You cannot set a
79*54f38fcaSMauro Carvalho Chehabpartial array, all elements have to be set or retrieved. The total size
80*54f38fcaSMauro Carvalho Chehabis calculated as ``elems`` * ``elem_size``. These values can be obtained
81*54f38fcaSMauro Carvalho Chehabby calling :ref:`VIDIOC_QUERY_EXT_CTRL <VIDIOC_QUERYCTRL>`.
82*54f38fcaSMauro Carvalho Chehab
83*54f38fcaSMauro Carvalho ChehabTo change the value of a set of controls applications initialize the
84*54f38fcaSMauro Carvalho Chehab``id``, ``size``, ``reserved2`` and ``value/value64/string/ptr`` fields
85*54f38fcaSMauro Carvalho Chehabof each struct :c:type:`v4l2_ext_control` and call
86*54f38fcaSMauro Carvalho Chehabthe :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. The controls will only be set if *all*
87*54f38fcaSMauro Carvalho Chehabcontrol values are valid.
88*54f38fcaSMauro Carvalho Chehab
89*54f38fcaSMauro Carvalho ChehabTo check if a set of controls have correct values applications
90*54f38fcaSMauro Carvalho Chehabinitialize the ``id``, ``size``, ``reserved2`` and
91*54f38fcaSMauro Carvalho Chehab``value/value64/string/ptr`` fields of each struct
92*54f38fcaSMauro Carvalho Chehab:c:type:`v4l2_ext_control` and call the
93*54f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. It is up to the driver whether wrong
94*54f38fcaSMauro Carvalho Chehabvalues are automatically adjusted to a valid value or if an error is
95*54f38fcaSMauro Carvalho Chehabreturned.
96*54f38fcaSMauro Carvalho Chehab
97*54f38fcaSMauro Carvalho ChehabWhen the ``id`` or ``which`` is invalid drivers return an ``EINVAL`` error
98*54f38fcaSMauro Carvalho Chehabcode. When the value is out of bounds drivers can choose to take the
99*54f38fcaSMauro Carvalho Chehabclosest valid value or return an ``ERANGE`` error code, whatever seems more
100*54f38fcaSMauro Carvalho Chehabappropriate. In the first case the new value is set in struct
101*54f38fcaSMauro Carvalho Chehab:c:type:`v4l2_ext_control`. If the new control value
102*54f38fcaSMauro Carvalho Chehabis inappropriate (e.g. the given menu index is not supported by the menu
103*54f38fcaSMauro Carvalho Chehabcontrol), then this will also result in an ``EINVAL`` error code error.
104*54f38fcaSMauro Carvalho Chehab
105*54f38fcaSMauro Carvalho ChehabIf ``request_fd`` is set to a not-yet-queued :ref:`request <media-request-api>`
106*54f38fcaSMauro Carvalho Chehabfile descriptor and ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``,
107*54f38fcaSMauro Carvalho Chehabthen the controls are not applied immediately when calling
108*54f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, but instead are applied by
109*54f38fcaSMauro Carvalho Chehabthe driver for the buffer associated with the same request.
110*54f38fcaSMauro Carvalho ChehabIf the device does not support requests, then ``EACCES`` will be returned.
111*54f38fcaSMauro Carvalho ChehabIf requests are supported but an invalid request file descriptor is given,
112*54f38fcaSMauro Carvalho Chehabthen ``EINVAL`` will be returned.
113*54f38fcaSMauro Carvalho Chehab
114*54f38fcaSMauro Carvalho ChehabAn attempt to call :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` for a
115*54f38fcaSMauro Carvalho Chehabrequest that has already been queued will result in an ``EBUSY`` error.
116*54f38fcaSMauro Carvalho Chehab
117*54f38fcaSMauro Carvalho ChehabIf ``request_fd`` is specified and ``which`` is set to
118*54f38fcaSMauro Carvalho Chehab``V4L2_CTRL_WHICH_REQUEST_VAL`` during a call to
119*54f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then it will return the
120*54f38fcaSMauro Carvalho Chehabvalues of the controls at the time of request completion.
121*54f38fcaSMauro Carvalho ChehabIf the request is not yet completed, then this will result in an
122*54f38fcaSMauro Carvalho Chehab``EACCES`` error.
123*54f38fcaSMauro Carvalho Chehab
124*54f38fcaSMauro Carvalho ChehabThe driver will only set/get these controls if all control values are
125*54f38fcaSMauro Carvalho Chehabcorrect. This prevents the situation where only some of the controls
126*54f38fcaSMauro Carvalho Chehabwere set/get. Only low-level errors (e. g. a failed i2c command) can
127*54f38fcaSMauro Carvalho Chehabstill cause this situation.
128*54f38fcaSMauro Carvalho Chehab
129*54f38fcaSMauro Carvalho Chehab
130*54f38fcaSMauro Carvalho Chehab.. tabularcolumns:: |p{1.2cm}|p{3.0cm}|p{1.5cm}|p{11.8cm}|
131*54f38fcaSMauro Carvalho Chehab
132*54f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_ext_control
133*54f38fcaSMauro Carvalho Chehab
134*54f38fcaSMauro Carvalho Chehab.. cssclass: longtable
135*54f38fcaSMauro Carvalho Chehab
136*54f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_ext_control
137*54f38fcaSMauro Carvalho Chehab    :header-rows:  0
138*54f38fcaSMauro Carvalho Chehab    :stub-columns: 0
139*54f38fcaSMauro Carvalho Chehab    :widths:       1 1 2
140*54f38fcaSMauro Carvalho Chehab
141*54f38fcaSMauro Carvalho Chehab    * - __u32
142*54f38fcaSMauro Carvalho Chehab      - ``id``
143*54f38fcaSMauro Carvalho Chehab      - Identifies the control, set by the application.
144*54f38fcaSMauro Carvalho Chehab    * - __u32
145*54f38fcaSMauro Carvalho Chehab      - ``size``
146*54f38fcaSMauro Carvalho Chehab      - The total size in bytes of the payload of this control. This is
147*54f38fcaSMauro Carvalho Chehab	normally 0, but for pointer controls this should be set to the
148*54f38fcaSMauro Carvalho Chehab	size of the memory containing the payload, or that will receive
149*54f38fcaSMauro Carvalho Chehab	the payload. If :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` finds that this value is
150*54f38fcaSMauro Carvalho Chehab	less than is required to store the payload result, then it is set
151*54f38fcaSMauro Carvalho Chehab	to a value large enough to store the payload result and ``ENOSPC`` is
152*54f38fcaSMauro Carvalho Chehab	returned.
153*54f38fcaSMauro Carvalho Chehab
154*54f38fcaSMauro Carvalho Chehab	.. note::
155*54f38fcaSMauro Carvalho Chehab
156*54f38fcaSMauro Carvalho Chehab	   For string controls, this ``size`` field should
157*54f38fcaSMauro Carvalho Chehab	   not be confused with the length of the string. This field refers
158*54f38fcaSMauro Carvalho Chehab	   to the size of the memory that contains the string. The actual
159*54f38fcaSMauro Carvalho Chehab	   *length* of the string may well be much smaller.
160*54f38fcaSMauro Carvalho Chehab    * - __u32
161*54f38fcaSMauro Carvalho Chehab      - ``reserved2``\ [1]
162*54f38fcaSMauro Carvalho Chehab      - Reserved for future extensions. Drivers and applications must set
163*54f38fcaSMauro Carvalho Chehab	the array to zero.
164*54f38fcaSMauro Carvalho Chehab    * - union {
165*54f38fcaSMauro Carvalho Chehab      - (anonymous)
166*54f38fcaSMauro Carvalho Chehab    * - __s32
167*54f38fcaSMauro Carvalho Chehab      - ``value``
168*54f38fcaSMauro Carvalho Chehab      - New value or current value. Valid if this control is not of type
169*54f38fcaSMauro Carvalho Chehab	``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
170*54f38fcaSMauro Carvalho Chehab	not set.
171*54f38fcaSMauro Carvalho Chehab    * - __s64
172*54f38fcaSMauro Carvalho Chehab      - ``value64``
173*54f38fcaSMauro Carvalho Chehab      - New value or current value. Valid if this control is of type
174*54f38fcaSMauro Carvalho Chehab	``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
175*54f38fcaSMauro Carvalho Chehab	not set.
176*54f38fcaSMauro Carvalho Chehab    * - char *
177*54f38fcaSMauro Carvalho Chehab      - ``string``
178*54f38fcaSMauro Carvalho Chehab      - A pointer to a string. Valid if this control is of type
179*54f38fcaSMauro Carvalho Chehab	``V4L2_CTRL_TYPE_STRING``.
180*54f38fcaSMauro Carvalho Chehab    * - __u8 *
181*54f38fcaSMauro Carvalho Chehab      - ``p_u8``
182*54f38fcaSMauro Carvalho Chehab      - A pointer to a matrix control of unsigned 8-bit values. Valid if
183*54f38fcaSMauro Carvalho Chehab	this control is of type ``V4L2_CTRL_TYPE_U8``.
184*54f38fcaSMauro Carvalho Chehab    * - __u16 *
185*54f38fcaSMauro Carvalho Chehab      - ``p_u16``
186*54f38fcaSMauro Carvalho Chehab      - A pointer to a matrix control of unsigned 16-bit values. Valid if
187*54f38fcaSMauro Carvalho Chehab	this control is of type ``V4L2_CTRL_TYPE_U16``.
188*54f38fcaSMauro Carvalho Chehab    * - __u32 *
189*54f38fcaSMauro Carvalho Chehab      - ``p_u32``
190*54f38fcaSMauro Carvalho Chehab      - A pointer to a matrix control of unsigned 32-bit values. Valid if
191*54f38fcaSMauro Carvalho Chehab	this control is of type ``V4L2_CTRL_TYPE_U32``.
192*54f38fcaSMauro Carvalho Chehab    * - :c:type:`v4l2_area` *
193*54f38fcaSMauro Carvalho Chehab      - ``p_area``
194*54f38fcaSMauro Carvalho Chehab      - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
195*54f38fcaSMauro Carvalho Chehab        of type ``V4L2_CTRL_TYPE_AREA``.
196*54f38fcaSMauro Carvalho Chehab    * - void *
197*54f38fcaSMauro Carvalho Chehab      - ``ptr``
198*54f38fcaSMauro Carvalho Chehab      - A pointer to a compound type which can be an N-dimensional array
199*54f38fcaSMauro Carvalho Chehab	and/or a compound type (the control's type is >=
200*54f38fcaSMauro Carvalho Chehab	``V4L2_CTRL_COMPOUND_TYPES``). Valid if
201*54f38fcaSMauro Carvalho Chehab	``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set for this control.
202*54f38fcaSMauro Carvalho Chehab    * - }
203*54f38fcaSMauro Carvalho Chehab      -
204*54f38fcaSMauro Carvalho Chehab
205*54f38fcaSMauro Carvalho Chehab
206*54f38fcaSMauro Carvalho Chehab.. tabularcolumns:: |p{4.0cm}|p{2.2cm}|p{2.1cm}|p{8.2cm}|
207*54f38fcaSMauro Carvalho Chehab
208*54f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_ext_controls
209*54f38fcaSMauro Carvalho Chehab
210*54f38fcaSMauro Carvalho Chehab.. cssclass:: longtable
211*54f38fcaSMauro Carvalho Chehab
212*54f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_ext_controls
213*54f38fcaSMauro Carvalho Chehab    :header-rows:  0
214*54f38fcaSMauro Carvalho Chehab    :stub-columns: 0
215*54f38fcaSMauro Carvalho Chehab    :widths:       1 1 2
216*54f38fcaSMauro Carvalho Chehab
217*54f38fcaSMauro Carvalho Chehab    * - union {
218*54f38fcaSMauro Carvalho Chehab      - (anonymous)
219*54f38fcaSMauro Carvalho Chehab    * - __u32
220*54f38fcaSMauro Carvalho Chehab      - ``ctrl_class``
221*54f38fcaSMauro Carvalho Chehab      - The control class to which all controls belong, see
222*54f38fcaSMauro Carvalho Chehab	:ref:`ctrl-class`. Drivers that use a kernel framework for
223*54f38fcaSMauro Carvalho Chehab	handling controls will also accept a value of 0 here, meaning that
224*54f38fcaSMauro Carvalho Chehab	the controls can belong to any control class. Whether drivers
225*54f38fcaSMauro Carvalho Chehab	support this can be tested by setting ``ctrl_class`` to 0 and
226*54f38fcaSMauro Carvalho Chehab	calling :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` with a ``count`` of 0. If that
227*54f38fcaSMauro Carvalho Chehab	succeeds, then the driver supports this feature.
228*54f38fcaSMauro Carvalho Chehab    * - __u32
229*54f38fcaSMauro Carvalho Chehab      - ``which``
230*54f38fcaSMauro Carvalho Chehab      - Which value of the control to get/set/try.
231*54f38fcaSMauro Carvalho Chehab	``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the
232*54f38fcaSMauro Carvalho Chehab	control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default
233*54f38fcaSMauro Carvalho Chehab	value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that
234*54f38fcaSMauro Carvalho Chehab	these controls have to be retrieved from a request or tried/set for
235*54f38fcaSMauro Carvalho Chehab	a request. In the latter case the ``request_fd`` field contains the
236*54f38fcaSMauro Carvalho Chehab	file descriptor of the request that should be used. If the device
237*54f38fcaSMauro Carvalho Chehab	does not support requests, then ``EACCES`` will be returned.
238*54f38fcaSMauro Carvalho Chehab
239*54f38fcaSMauro Carvalho Chehab	.. note::
240*54f38fcaSMauro Carvalho Chehab
241*54f38fcaSMauro Carvalho Chehab	   When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only
242*54f38fcaSMauro Carvalho Chehab	   get the default value of the control, you cannot set or try it.
243*54f38fcaSMauro Carvalho Chehab
244*54f38fcaSMauro Carvalho Chehab	For backwards compatibility you can also use a control class here
245*54f38fcaSMauro Carvalho Chehab	(see :ref:`ctrl-class`). In that case all controls have to
246*54f38fcaSMauro Carvalho Chehab	belong to that control class. This usage is deprecated, instead
247*54f38fcaSMauro Carvalho Chehab	just use ``V4L2_CTRL_WHICH_CUR_VAL``. There are some very old
248*54f38fcaSMauro Carvalho Chehab	drivers that do not yet support ``V4L2_CTRL_WHICH_CUR_VAL`` and
249*54f38fcaSMauro Carvalho Chehab	that require a control class here. You can test for such drivers
250*54f38fcaSMauro Carvalho Chehab	by setting ctrl_class to ``V4L2_CTRL_WHICH_CUR_VAL`` and calling
251*54f38fcaSMauro Carvalho Chehab	VIDIOC_TRY_EXT_CTRLS with a count of 0. If that fails, then the
252*54f38fcaSMauro Carvalho Chehab	driver does not support ``V4L2_CTRL_WHICH_CUR_VAL``.
253*54f38fcaSMauro Carvalho Chehab    * - }
254*54f38fcaSMauro Carvalho Chehab      -
255*54f38fcaSMauro Carvalho Chehab    * - __u32
256*54f38fcaSMauro Carvalho Chehab      - ``count``
257*54f38fcaSMauro Carvalho Chehab      - The number of controls in the controls array. May also be zero.
258*54f38fcaSMauro Carvalho Chehab    * - __u32
259*54f38fcaSMauro Carvalho Chehab      - ``error_idx``
260*54f38fcaSMauro Carvalho Chehab      - Set by the driver in case of an error. If the error is associated
261*54f38fcaSMauro Carvalho Chehab	with a particular control, then ``error_idx`` is set to the index
262*54f38fcaSMauro Carvalho Chehab	of that control. If the error is not related to a specific
263*54f38fcaSMauro Carvalho Chehab	control, or the validation step failed (see below), then
264*54f38fcaSMauro Carvalho Chehab	``error_idx`` is set to ``count``. The value is undefined if the
265*54f38fcaSMauro Carvalho Chehab	ioctl returned 0 (success).
266*54f38fcaSMauro Carvalho Chehab
267*54f38fcaSMauro Carvalho Chehab	Before controls are read from/written to hardware a validation
268*54f38fcaSMauro Carvalho Chehab	step takes place: this checks if all controls in the list are
269*54f38fcaSMauro Carvalho Chehab	valid controls, if no attempt is made to write to a read-only
270*54f38fcaSMauro Carvalho Chehab	control or read from a write-only control, and any other up-front
271*54f38fcaSMauro Carvalho Chehab	checks that can be done without accessing the hardware. The exact
272*54f38fcaSMauro Carvalho Chehab	validations done during this step are driver dependent since some
273*54f38fcaSMauro Carvalho Chehab	checks might require hardware access for some devices, thus making
274*54f38fcaSMauro Carvalho Chehab	it impossible to do those checks up-front. However, drivers should
275*54f38fcaSMauro Carvalho Chehab	make a best-effort to do as many up-front checks as possible.
276*54f38fcaSMauro Carvalho Chehab
277*54f38fcaSMauro Carvalho Chehab	This check is done to avoid leaving the hardware in an
278*54f38fcaSMauro Carvalho Chehab	inconsistent state due to easy-to-avoid problems. But it leads to
279*54f38fcaSMauro Carvalho Chehab	another problem: the application needs to know whether an error
280*54f38fcaSMauro Carvalho Chehab	came from the validation step (meaning that the hardware was not
281*54f38fcaSMauro Carvalho Chehab	touched) or from an error during the actual reading from/writing
282*54f38fcaSMauro Carvalho Chehab	to hardware.
283*54f38fcaSMauro Carvalho Chehab
284*54f38fcaSMauro Carvalho Chehab	The, in hindsight quite poor, solution for that is to set
285*54f38fcaSMauro Carvalho Chehab	``error_idx`` to ``count`` if the validation failed. This has the
286*54f38fcaSMauro Carvalho Chehab	unfortunate side-effect that it is not possible to see which
287*54f38fcaSMauro Carvalho Chehab	control failed the validation. If the validation was successful
288*54f38fcaSMauro Carvalho Chehab	and the error happened while accessing the hardware, then
289*54f38fcaSMauro Carvalho Chehab	``error_idx`` is less than ``count`` and only the controls up to
290*54f38fcaSMauro Carvalho Chehab	``error_idx-1`` were read or written correctly, and the state of
291*54f38fcaSMauro Carvalho Chehab	the remaining controls is undefined.
292*54f38fcaSMauro Carvalho Chehab
293*54f38fcaSMauro Carvalho Chehab	Since :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` does not access hardware there is
294*54f38fcaSMauro Carvalho Chehab	also no need to handle the validation step in this special way, so
295*54f38fcaSMauro Carvalho Chehab	``error_idx`` will just be set to the control that failed the
296*54f38fcaSMauro Carvalho Chehab	validation step instead of to ``count``. This means that if
297*54f38fcaSMauro Carvalho Chehab	:ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` fails with ``error_idx`` set to ``count``,
298*54f38fcaSMauro Carvalho Chehab	then you can call :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` to try to discover the
299*54f38fcaSMauro Carvalho Chehab	actual control that failed the validation step. Unfortunately,
300*54f38fcaSMauro Carvalho Chehab	there is no ``TRY`` equivalent for :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`.
301*54f38fcaSMauro Carvalho Chehab    * - __s32
302*54f38fcaSMauro Carvalho Chehab      - ``request_fd``
303*54f38fcaSMauro Carvalho Chehab      - File descriptor of the request to be used by this operation. Only
304*54f38fcaSMauro Carvalho Chehab	valid if ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``.
305*54f38fcaSMauro Carvalho Chehab	If the device does not support requests, then ``EACCES`` will be returned.
306*54f38fcaSMauro Carvalho Chehab	If requests are supported but an invalid request file descriptor is
307*54f38fcaSMauro Carvalho Chehab	given, then ``EINVAL`` will be returned.
308*54f38fcaSMauro Carvalho Chehab    * - __u32
309*54f38fcaSMauro Carvalho Chehab      - ``reserved``\ [1]
310*54f38fcaSMauro Carvalho Chehab      - Reserved for future extensions.
311*54f38fcaSMauro Carvalho Chehab
312*54f38fcaSMauro Carvalho Chehab	Drivers and applications must set the array to zero.
313*54f38fcaSMauro Carvalho Chehab    * - struct :c:type:`v4l2_ext_control` *
314*54f38fcaSMauro Carvalho Chehab      - ``controls``
315*54f38fcaSMauro Carvalho Chehab      - Pointer to an array of ``count`` v4l2_ext_control structures.
316*54f38fcaSMauro Carvalho Chehab
317*54f38fcaSMauro Carvalho Chehab	Ignored if ``count`` equals zero.
318*54f38fcaSMauro Carvalho Chehab
319*54f38fcaSMauro Carvalho Chehab
320*54f38fcaSMauro Carvalho Chehab.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
321*54f38fcaSMauro Carvalho Chehab
322*54f38fcaSMauro Carvalho Chehab.. _ctrl-class:
323*54f38fcaSMauro Carvalho Chehab
324*54f38fcaSMauro Carvalho Chehab.. flat-table:: Control classes
325*54f38fcaSMauro Carvalho Chehab    :header-rows:  0
326*54f38fcaSMauro Carvalho Chehab    :stub-columns: 0
327*54f38fcaSMauro Carvalho Chehab    :widths:       3 1 4
328*54f38fcaSMauro Carvalho Chehab
329*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_USER``
330*54f38fcaSMauro Carvalho Chehab      - 0x980000
331*54f38fcaSMauro Carvalho Chehab      - The class containing user controls. These controls are described
332*54f38fcaSMauro Carvalho Chehab	in :ref:`control`. All controls that can be set using the
333*54f38fcaSMauro Carvalho Chehab	:ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` and
334*54f38fcaSMauro Carvalho Chehab	:ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` ioctl belong to this
335*54f38fcaSMauro Carvalho Chehab	class.
336*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_MPEG``
337*54f38fcaSMauro Carvalho Chehab      - 0x990000
338*54f38fcaSMauro Carvalho Chehab      - The class containing MPEG compression controls. These controls are
339*54f38fcaSMauro Carvalho Chehab	described in :ref:`mpeg-controls`.
340*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_CAMERA``
341*54f38fcaSMauro Carvalho Chehab      - 0x9a0000
342*54f38fcaSMauro Carvalho Chehab      - The class containing camera controls. These controls are described
343*54f38fcaSMauro Carvalho Chehab	in :ref:`camera-controls`.
344*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_FM_TX``
345*54f38fcaSMauro Carvalho Chehab      - 0x9b0000
346*54f38fcaSMauro Carvalho Chehab      - The class containing FM Transmitter (FM TX) controls. These
347*54f38fcaSMauro Carvalho Chehab	controls are described in :ref:`fm-tx-controls`.
348*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_FLASH``
349*54f38fcaSMauro Carvalho Chehab      - 0x9c0000
350*54f38fcaSMauro Carvalho Chehab      - The class containing flash device controls. These controls are
351*54f38fcaSMauro Carvalho Chehab	described in :ref:`flash-controls`.
352*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_JPEG``
353*54f38fcaSMauro Carvalho Chehab      - 0x9d0000
354*54f38fcaSMauro Carvalho Chehab      - The class containing JPEG compression controls. These controls are
355*54f38fcaSMauro Carvalho Chehab	described in :ref:`jpeg-controls`.
356*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_IMAGE_SOURCE``
357*54f38fcaSMauro Carvalho Chehab      - 0x9e0000
358*54f38fcaSMauro Carvalho Chehab      - The class containing image source controls. These controls are
359*54f38fcaSMauro Carvalho Chehab	described in :ref:`image-source-controls`.
360*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_IMAGE_PROC``
361*54f38fcaSMauro Carvalho Chehab      - 0x9f0000
362*54f38fcaSMauro Carvalho Chehab      - The class containing image processing controls. These controls are
363*54f38fcaSMauro Carvalho Chehab	described in :ref:`image-process-controls`.
364*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_FM_RX``
365*54f38fcaSMauro Carvalho Chehab      - 0xa10000
366*54f38fcaSMauro Carvalho Chehab      - The class containing FM Receiver (FM RX) controls. These controls
367*54f38fcaSMauro Carvalho Chehab	are described in :ref:`fm-rx-controls`.
368*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_CTRL_CLASS_RF_TUNER``
369*54f38fcaSMauro Carvalho Chehab      - 0xa20000
370*54f38fcaSMauro Carvalho Chehab      - The class containing RF tuner controls. These controls are
371*54f38fcaSMauro Carvalho Chehab	described in :ref:`rf-tuner-controls`.
372*54f38fcaSMauro Carvalho Chehab
373*54f38fcaSMauro Carvalho Chehab
374*54f38fcaSMauro Carvalho ChehabReturn Value
375*54f38fcaSMauro Carvalho Chehab============
376*54f38fcaSMauro Carvalho Chehab
377*54f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set
378*54f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the
379*54f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter.
380*54f38fcaSMauro Carvalho Chehab
381*54f38fcaSMauro Carvalho ChehabEINVAL
382*54f38fcaSMauro Carvalho Chehab    The struct :c:type:`v4l2_ext_control` ``id`` is
383*54f38fcaSMauro Carvalho Chehab    invalid, or the struct :c:type:`v4l2_ext_controls`
384*54f38fcaSMauro Carvalho Chehab    ``which`` is invalid, or the struct
385*54f38fcaSMauro Carvalho Chehab    :c:type:`v4l2_ext_control` ``value`` was
386*54f38fcaSMauro Carvalho Chehab    inappropriate (e.g. the given menu index is not supported by the
387*54f38fcaSMauro Carvalho Chehab    driver), or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL``
388*54f38fcaSMauro Carvalho Chehab    but the given ``request_fd`` was invalid or ``V4L2_CTRL_WHICH_REQUEST_VAL``
389*54f38fcaSMauro Carvalho Chehab    is not supported by the kernel.
390*54f38fcaSMauro Carvalho Chehab    This error code is also returned by the
391*54f38fcaSMauro Carvalho Chehab    :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` and :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctls if two or
392*54f38fcaSMauro Carvalho Chehab    more control values are in conflict.
393*54f38fcaSMauro Carvalho Chehab
394*54f38fcaSMauro Carvalho ChehabERANGE
395*54f38fcaSMauro Carvalho Chehab    The struct :c:type:`v4l2_ext_control` ``value``
396*54f38fcaSMauro Carvalho Chehab    is out of bounds.
397*54f38fcaSMauro Carvalho Chehab
398*54f38fcaSMauro Carvalho ChehabEBUSY
399*54f38fcaSMauro Carvalho Chehab    The control is temporarily not changeable, possibly because another
400*54f38fcaSMauro Carvalho Chehab    applications took over control of the device function this control
401*54f38fcaSMauro Carvalho Chehab    belongs to, or (if the ``which`` field was set to
402*54f38fcaSMauro Carvalho Chehab    ``V4L2_CTRL_WHICH_REQUEST_VAL``) the request was queued but not yet
403*54f38fcaSMauro Carvalho Chehab    completed.
404*54f38fcaSMauro Carvalho Chehab
405*54f38fcaSMauro Carvalho ChehabENOSPC
406*54f38fcaSMauro Carvalho Chehab    The space reserved for the control's payload is insufficient. The
407*54f38fcaSMauro Carvalho Chehab    field ``size`` is set to a value that is enough to store the payload
408*54f38fcaSMauro Carvalho Chehab    and this error code is returned.
409*54f38fcaSMauro Carvalho Chehab
410*54f38fcaSMauro Carvalho ChehabEACCES
411*54f38fcaSMauro Carvalho Chehab    Attempt to try or set a read-only control, or to get a write-only
412*54f38fcaSMauro Carvalho Chehab    control, or to get a control from a request that has not yet been
413*54f38fcaSMauro Carvalho Chehab    completed.
414*54f38fcaSMauro Carvalho Chehab
415*54f38fcaSMauro Carvalho Chehab    Or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL`` but the
416*54f38fcaSMauro Carvalho Chehab    device does not support requests.
417