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