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