Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
[linux-2.6] / drivers / media / video / v4l2-common.c
1 /*
2  *      Video for Linux Two
3  *
4  *      A generic video device interface for the LINUX operating system
5  *      using a set of device structures/vectors for low level operations.
6  *
7  *      This file replaces the videodev.c file that comes with the
8  *      regular kernel distribution.
9  *
10  *      This program is free software; you can redistribute it and/or
11  *      modify it under the terms of the GNU General Public License
12  *      as published by the Free Software Foundation; either version
13  *      2 of the License, or (at your option) any later version.
14  *
15  * Author:      Bill Dirks <bdirks@pacbell.net>
16  *              based on code by Alan Cox, <alan@cymru.net>
17  *
18  */
19
20 /*
21  * Video capture interface for Linux
22  *
23  *      A generic video device interface for the LINUX operating system
24  *      using a set of device structures/vectors for low level operations.
25  *
26  *              This program is free software; you can redistribute it and/or
27  *              modify it under the terms of the GNU General Public License
28  *              as published by the Free Software Foundation; either version
29  *              2 of the License, or (at your option) any later version.
30  *
31  * Author:      Alan Cox, <alan@redhat.com>
32  *
33  * Fixes:
34  */
35
36 /*
37  * Video4linux 1/2 integration by Justin Schoeman
38  * <justin@suntiger.ee.up.ac.za>
39  * 2.4 PROCFS support ported from 2.4 kernels by
40  *  Iñaki García Etxebarria <garetxe@euskalnet.net>
41  * Makefile fix by "W. Michael Petullo" <mike@flyn.org>
42  * 2.4 devfs support ported from 2.4 kernels by
43  *  Dan Merillat <dan@merillat.org>
44  * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
45  */
46
47 #include <linux/module.h>
48 #include <linux/types.h>
49 #include <linux/kernel.h>
50 #include <linux/sched.h>
51 #include <linux/smp_lock.h>
52 #include <linux/mm.h>
53 #include <linux/string.h>
54 #include <linux/errno.h>
55 #include <asm/uaccess.h>
56 #include <asm/system.h>
57 #include <asm/pgtable.h>
58 #include <asm/io.h>
59 #include <asm/div64.h>
60 #include <linux/video_decoder.h>
61 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
62 #include <media/v4l2-common.h>
63
64 #ifdef CONFIG_KMOD
65 #include <linux/kmod.h>
66 #endif
67
68 #if defined(CONFIG_UST) || defined(CONFIG_UST_MODULE)
69 #include <linux/ust.h>
70 #endif
71
72
73 #include <linux/videodev.h>
74
75 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
76 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
77 MODULE_LICENSE("GPL");
78
79 /*
80  *
81  *      V 4 L 2   D R I V E R   H E L P E R   A P I
82  *
83  */
84
85 /*
86  *  Video Standard Operations (contributed by Michael Schimek)
87  */
88
89
90 char *v4l2_norm_to_name(v4l2_std_id id)
91 {
92         char *name;
93
94         switch (id) {
95         case V4L2_STD_PAL:
96                 name="PAL";             break;
97         case V4L2_STD_PAL_BG:
98                 name="PAL-BG";          break;
99         case V4L2_STD_PAL_DK:
100                 name="PAL-DK";          break;
101         case V4L2_STD_PAL_B:
102                 name="PAL-B";           break;
103         case V4L2_STD_PAL_B1:
104                 name="PAL-B1";          break;
105         case V4L2_STD_PAL_G:
106                 name="PAL-G";           break;
107         case V4L2_STD_PAL_H:
108                 name="PAL-H";           break;
109         case V4L2_STD_PAL_I:
110                 name="PAL-I";           break;
111         case V4L2_STD_PAL_D:
112                 name="PAL-D";           break;
113         case V4L2_STD_PAL_D1:
114                 name="PAL-D1";          break;
115         case V4L2_STD_PAL_K:
116                 name="PAL-K";           break;
117         case V4L2_STD_PAL_M:
118                 name="PAL-M";           break;
119         case V4L2_STD_PAL_N:
120                 name="PAL-N";           break;
121         case V4L2_STD_PAL_Nc:
122                 name="PAL-Nc";          break;
123         case V4L2_STD_PAL_60:
124                 name="PAL-60";          break;
125         case V4L2_STD_NTSC:
126                 name="NTSC";            break;
127         case V4L2_STD_NTSC_M:
128                 name="NTSC-M";          break;
129         case V4L2_STD_NTSC_M_JP:
130                 name="NTSC-M-JP";       break;
131         case V4L2_STD_NTSC_443:
132                 name="NTSC-443";        break;
133         case V4L2_STD_NTSC_M_KR:
134                 name="NTSC-M-KR";       break;
135         case V4L2_STD_SECAM:
136                 name="SECAM";           break;
137         case V4L2_STD_SECAM_DK:
138                 name="SECAM-DK";        break;
139         case V4L2_STD_SECAM_B:
140                 name="SECAM-B";         break;
141         case V4L2_STD_SECAM_D:
142                 name="SECAM-D";         break;
143         case V4L2_STD_SECAM_G:
144                 name="SECAM-G";         break;
145         case V4L2_STD_SECAM_H:
146                 name="SECAM-H";         break;
147         case V4L2_STD_SECAM_K:
148                 name="SECAM-K";         break;
149         case V4L2_STD_SECAM_K1:
150                 name="SECAM-K1";        break;
151         case V4L2_STD_SECAM_L:
152                 name="SECAM-L";         break;
153         case V4L2_STD_SECAM_LC:
154                 name="SECAM-LC";        break;
155         default:
156                 name="Unknown";         break;
157         }
158
159         return name;
160 }
161
162 /* Fill in the fields of a v4l2_standard structure according to the
163    'id' and 'transmission' parameters.  Returns negative on error.  */
164 int v4l2_video_std_construct(struct v4l2_standard *vs,
165                              int id, char *name)
166 {
167         u32 index = vs->index;
168
169         memset(vs, 0, sizeof(struct v4l2_standard));
170         vs->index = index;
171         vs->id    = id;
172         if (id & V4L2_STD_525_60) {
173                 vs->frameperiod.numerator = 1001;
174                 vs->frameperiod.denominator = 30000;
175                 vs->framelines = 525;
176         } else {
177                 vs->frameperiod.numerator = 1;
178                 vs->frameperiod.denominator = 25;
179                 vs->framelines = 625;
180         }
181         strlcpy(vs->name,name,sizeof(vs->name));
182         return 0;
183 }
184
185 /* ----------------------------------------------------------------- */
186 /* priority handling                                                 */
187
188 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND   || \
189                               val == V4L2_PRIORITY_INTERACTIVE  || \
190                               val == V4L2_PRIORITY_RECORD)
191
192 int v4l2_prio_init(struct v4l2_prio_state *global)
193 {
194         memset(global,0,sizeof(*global));
195         return 0;
196 }
197
198 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
199                      enum v4l2_priority new)
200 {
201         if (!V4L2_PRIO_VALID(new))
202                 return -EINVAL;
203         if (*local == new)
204                 return 0;
205
206         atomic_inc(&global->prios[new]);
207         if (V4L2_PRIO_VALID(*local))
208                 atomic_dec(&global->prios[*local]);
209         *local = new;
210         return 0;
211 }
212
213 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
214 {
215         return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
216 }
217
218 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
219 {
220         if (V4L2_PRIO_VALID(*local))
221                 atomic_dec(&global->prios[*local]);
222         return 0;
223 }
224
225 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
226 {
227         if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
228                 return V4L2_PRIORITY_RECORD;
229         if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
230                 return V4L2_PRIORITY_INTERACTIVE;
231         if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
232                 return V4L2_PRIORITY_BACKGROUND;
233         return V4L2_PRIORITY_UNSET;
234 }
235
236 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
237 {
238         if (*local < v4l2_prio_max(global))
239                 return -EBUSY;
240         return 0;
241 }
242
243
244 /* ----------------------------------------------------------------- */
245 /* some arrays for pretty-printing debug messages of enum types      */
246
247 char *v4l2_field_names[] = {
248         [V4L2_FIELD_ANY]        = "any",
249         [V4L2_FIELD_NONE]       = "none",
250         [V4L2_FIELD_TOP]        = "top",
251         [V4L2_FIELD_BOTTOM]     = "bottom",
252         [V4L2_FIELD_INTERLACED] = "interlaced",
253         [V4L2_FIELD_SEQ_TB]     = "seq-tb",
254         [V4L2_FIELD_SEQ_BT]     = "seq-bt",
255         [V4L2_FIELD_ALTERNATE]  = "alternate",
256 };
257
258 char *v4l2_type_names[] = {
259         [V4L2_BUF_TYPE_VIDEO_CAPTURE]      = "video-cap",
260         [V4L2_BUF_TYPE_VIDEO_OVERLAY]      = "video-over",
261         [V4L2_BUF_TYPE_VIDEO_OUTPUT]       = "video-out",
262         [V4L2_BUF_TYPE_VBI_CAPTURE]        = "vbi-cap",
263         [V4L2_BUF_TYPE_VBI_OUTPUT]         = "vbi-out",
264         [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
265         [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]  = "slicec-vbi-out",
266 };
267
268 static char *v4l2_memory_names[] = {
269         [V4L2_MEMORY_MMAP]    = "mmap",
270         [V4L2_MEMORY_USERPTR] = "userptr",
271         [V4L2_MEMORY_OVERLAY] = "overlay",
272 };
273
274 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
275
276 /* ------------------------------------------------------------------ */
277 /* debug help functions                                               */
278
279 #ifdef CONFIG_VIDEO_V4L1_COMPAT
280 static const char *v4l1_ioctls[] = {
281         [_IOC_NR(VIDIOCGCAP)]       = "VIDIOCGCAP",
282         [_IOC_NR(VIDIOCGCHAN)]      = "VIDIOCGCHAN",
283         [_IOC_NR(VIDIOCSCHAN)]      = "VIDIOCSCHAN",
284         [_IOC_NR(VIDIOCGTUNER)]     = "VIDIOCGTUNER",
285         [_IOC_NR(VIDIOCSTUNER)]     = "VIDIOCSTUNER",
286         [_IOC_NR(VIDIOCGPICT)]      = "VIDIOCGPICT",
287         [_IOC_NR(VIDIOCSPICT)]      = "VIDIOCSPICT",
288         [_IOC_NR(VIDIOCCAPTURE)]    = "VIDIOCCAPTURE",
289         [_IOC_NR(VIDIOCGWIN)]       = "VIDIOCGWIN",
290         [_IOC_NR(VIDIOCSWIN)]       = "VIDIOCSWIN",
291         [_IOC_NR(VIDIOCGFBUF)]      = "VIDIOCGFBUF",
292         [_IOC_NR(VIDIOCSFBUF)]      = "VIDIOCSFBUF",
293         [_IOC_NR(VIDIOCKEY)]        = "VIDIOCKEY",
294         [_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
295         [_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
296         [_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
297         [_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
298         [_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
299         [_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
300         [_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
301         [_IOC_NR(VIDIOCGUNIT)]      = "VIDIOCGUNIT",
302         [_IOC_NR(VIDIOCGCAPTURE)]   = "VIDIOCGCAPTURE",
303         [_IOC_NR(VIDIOCSCAPTURE)]   = "VIDIOCSCAPTURE",
304         [_IOC_NR(VIDIOCSPLAYMODE)]  = "VIDIOCSPLAYMODE",
305         [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
306         [_IOC_NR(VIDIOCGPLAYINFO)]  = "VIDIOCGPLAYINFO",
307         [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
308         [_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
309         [_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT"
310 };
311 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
312 #endif
313
314 static const char *v4l2_ioctls[] = {
315         [_IOC_NR(VIDIOC_QUERYCAP)]         = "VIDIOC_QUERYCAP",
316         [_IOC_NR(VIDIOC_RESERVED)]         = "VIDIOC_RESERVED",
317         [_IOC_NR(VIDIOC_ENUM_FMT)]         = "VIDIOC_ENUM_FMT",
318         [_IOC_NR(VIDIOC_G_FMT)]            = "VIDIOC_G_FMT",
319         [_IOC_NR(VIDIOC_S_FMT)]            = "VIDIOC_S_FMT",
320         [_IOC_NR(VIDIOC_G_MPEGCOMP)]       = "VIDIOC_G_MPEGCOMP",
321         [_IOC_NR(VIDIOC_S_MPEGCOMP)]       = "VIDIOC_S_MPEGCOMP",
322         [_IOC_NR(VIDIOC_REQBUFS)]          = "VIDIOC_REQBUFS",
323         [_IOC_NR(VIDIOC_QUERYBUF)]         = "VIDIOC_QUERYBUF",
324         [_IOC_NR(VIDIOC_G_FBUF)]           = "VIDIOC_G_FBUF",
325         [_IOC_NR(VIDIOC_S_FBUF)]           = "VIDIOC_S_FBUF",
326         [_IOC_NR(VIDIOC_OVERLAY)]          = "VIDIOC_OVERLAY",
327         [_IOC_NR(VIDIOC_QBUF)]             = "VIDIOC_QBUF",
328         [_IOC_NR(VIDIOC_DQBUF)]            = "VIDIOC_DQBUF",
329         [_IOC_NR(VIDIOC_STREAMON)]         = "VIDIOC_STREAMON",
330         [_IOC_NR(VIDIOC_STREAMOFF)]        = "VIDIOC_STREAMOFF",
331         [_IOC_NR(VIDIOC_G_PARM)]           = "VIDIOC_G_PARM",
332         [_IOC_NR(VIDIOC_S_PARM)]           = "VIDIOC_S_PARM",
333         [_IOC_NR(VIDIOC_G_STD)]            = "VIDIOC_G_STD",
334         [_IOC_NR(VIDIOC_S_STD)]            = "VIDIOC_S_STD",
335         [_IOC_NR(VIDIOC_ENUMSTD)]          = "VIDIOC_ENUMSTD",
336         [_IOC_NR(VIDIOC_ENUMINPUT)]        = "VIDIOC_ENUMINPUT",
337         [_IOC_NR(VIDIOC_G_CTRL)]           = "VIDIOC_G_CTRL",
338         [_IOC_NR(VIDIOC_S_CTRL)]           = "VIDIOC_S_CTRL",
339         [_IOC_NR(VIDIOC_G_TUNER)]          = "VIDIOC_G_TUNER",
340         [_IOC_NR(VIDIOC_S_TUNER)]          = "VIDIOC_S_TUNER",
341         [_IOC_NR(VIDIOC_G_AUDIO)]          = "VIDIOC_G_AUDIO",
342         [_IOC_NR(VIDIOC_S_AUDIO)]          = "VIDIOC_S_AUDIO",
343         [_IOC_NR(VIDIOC_QUERYCTRL)]        = "VIDIOC_QUERYCTRL",
344         [_IOC_NR(VIDIOC_QUERYMENU)]        = "VIDIOC_QUERYMENU",
345         [_IOC_NR(VIDIOC_G_INPUT)]          = "VIDIOC_G_INPUT",
346         [_IOC_NR(VIDIOC_S_INPUT)]          = "VIDIOC_S_INPUT",
347         [_IOC_NR(VIDIOC_G_OUTPUT)]         = "VIDIOC_G_OUTPUT",
348         [_IOC_NR(VIDIOC_S_OUTPUT)]         = "VIDIOC_S_OUTPUT",
349         [_IOC_NR(VIDIOC_ENUMOUTPUT)]       = "VIDIOC_ENUMOUTPUT",
350         [_IOC_NR(VIDIOC_G_AUDOUT)]         = "VIDIOC_G_AUDOUT",
351         [_IOC_NR(VIDIOC_S_AUDOUT)]         = "VIDIOC_S_AUDOUT",
352         [_IOC_NR(VIDIOC_G_MODULATOR)]      = "VIDIOC_G_MODULATOR",
353         [_IOC_NR(VIDIOC_S_MODULATOR)]      = "VIDIOC_S_MODULATOR",
354         [_IOC_NR(VIDIOC_G_FREQUENCY)]      = "VIDIOC_G_FREQUENCY",
355         [_IOC_NR(VIDIOC_S_FREQUENCY)]      = "VIDIOC_S_FREQUENCY",
356         [_IOC_NR(VIDIOC_CROPCAP)]          = "VIDIOC_CROPCAP",
357         [_IOC_NR(VIDIOC_G_CROP)]           = "VIDIOC_G_CROP",
358         [_IOC_NR(VIDIOC_S_CROP)]           = "VIDIOC_S_CROP",
359         [_IOC_NR(VIDIOC_G_JPEGCOMP)]       = "VIDIOC_G_JPEGCOMP",
360         [_IOC_NR(VIDIOC_S_JPEGCOMP)]       = "VIDIOC_S_JPEGCOMP",
361         [_IOC_NR(VIDIOC_QUERYSTD)]         = "VIDIOC_QUERYSTD",
362         [_IOC_NR(VIDIOC_TRY_FMT)]          = "VIDIOC_TRY_FMT",
363         [_IOC_NR(VIDIOC_ENUMAUDIO)]        = "VIDIOC_ENUMAUDIO",
364         [_IOC_NR(VIDIOC_ENUMAUDOUT)]       = "VIDIOC_ENUMAUDOUT",
365         [_IOC_NR(VIDIOC_G_PRIORITY)]       = "VIDIOC_G_PRIORITY",
366         [_IOC_NR(VIDIOC_S_PRIORITY)]       = "VIDIOC_S_PRIORITY",
367 #if 1
368         [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
369 #endif
370         [_IOC_NR(VIDIOC_LOG_STATUS)]       = "VIDIOC_LOG_STATUS",
371         [_IOC_NR(VIDIOC_G_EXT_CTRLS)]      = "VIDIOC_G_EXT_CTRLS",
372         [_IOC_NR(VIDIOC_S_EXT_CTRLS)]      = "VIDIOC_S_EXT_CTRLS",
373         [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)]    = "VIDIOC_TRY_EXT_CTRLS"
374 };
375 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
376
377 static const char *v4l2_int_ioctls[] = {
378 #ifdef CONFIG_VIDEO_V4L1_COMPAT
379         [_IOC_NR(DECODER_GET_CAPABILITIES)]    = "DECODER_GET_CAPABILITIES",
380         [_IOC_NR(DECODER_GET_STATUS)]          = "DECODER_GET_STATUS",
381         [_IOC_NR(DECODER_SET_NORM)]            = "DECODER_SET_NORM",
382         [_IOC_NR(DECODER_SET_INPUT)]           = "DECODER_SET_INPUT",
383         [_IOC_NR(DECODER_SET_OUTPUT)]          = "DECODER_SET_OUTPUT",
384         [_IOC_NR(DECODER_ENABLE_OUTPUT)]       = "DECODER_ENABLE_OUTPUT",
385         [_IOC_NR(DECODER_SET_PICTURE)]         = "DECODER_SET_PICTURE",
386         [_IOC_NR(DECODER_SET_GPIO)]            = "DECODER_SET_GPIO",
387         [_IOC_NR(DECODER_INIT)]                = "DECODER_INIT",
388         [_IOC_NR(DECODER_SET_VBI_BYPASS)]      = "DECODER_SET_VBI_BYPASS",
389         [_IOC_NR(DECODER_DUMP)]                = "DECODER_DUMP",
390 #endif
391         [_IOC_NR(AUDC_SET_RADIO)]              = "AUDC_SET_RADIO",
392
393         [_IOC_NR(TUNER_SET_TYPE_ADDR)]         = "TUNER_SET_TYPE_ADDR",
394         [_IOC_NR(TUNER_SET_STANDBY)]           = "TUNER_SET_STANDBY",
395         [_IOC_NR(TDA9887_SET_CONFIG)]          = "TDA9887_SET_CONFIG",
396
397         [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)]     = "VIDIOC_INT_S_TUNER_MODE",
398         [_IOC_NR(VIDIOC_INT_S_REGISTER)]       = "VIDIOC_INT_S_REGISTER",
399         [_IOC_NR(VIDIOC_INT_G_REGISTER)]       = "VIDIOC_INT_G_REGISTER",
400         [_IOC_NR(VIDIOC_INT_RESET)]            = "VIDIOC_INT_RESET",
401         [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
402         [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)]  = "VIDIOC_INT_DECODE_VBI_LINE",
403         [_IOC_NR(VIDIOC_INT_S_VBI_DATA)]       = "VIDIOC_INT_S_VBI_DATA",
404         [_IOC_NR(VIDIOC_INT_G_VBI_DATA)]       = "VIDIOC_INT_G_VBI_DATA",
405         [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)]     = "VIDIOC_INT_G_CHIP_IDENT",
406         [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)]   = "VIDIOC_INT_I2S_CLOCK_FREQ",
407         [_IOC_NR(VIDIOC_INT_S_STANDBY)]        = "VIDIOC_INT_S_STANDBY",
408         [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)]  = "VIDIOC_INT_S_AUDIO_ROUTING",
409         [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)]  = "VIDIOC_INT_G_AUDIO_ROUTING",
410         [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)]  = "VIDIOC_INT_S_VIDEO_ROUTING",
411         [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)]  = "VIDIOC_INT_G_VIDEO_ROUTING",
412         [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)]   = "VIDIOC_INT_S_CRYSTAL_FREQ"
413 };
414 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
415
416 static void v4l_print_pix_fmt (char *s, struct v4l2_pix_format *fmt)
417 {
418         printk ("%s: width=%d, height=%d, format=%d, field=%s, "
419                 "bytesperline=%d sizeimage=%d, colorspace=%d\n", s,
420                 fmt->width,fmt->height,fmt->pixelformat,
421                 prt_names(fmt->field,v4l2_field_names),
422                 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
423 };
424
425 /* Common ioctl debug function. This function can be used by
426    external ioctl messages as well as internal V4L ioctl */
427 void v4l_printk_ioctl(unsigned int cmd)
428 {
429         char *dir;
430
431         switch (_IOC_DIR(cmd)) {
432         case _IOC_NONE:              dir = "--"; break;
433         case _IOC_READ:              dir = "r-"; break;
434         case _IOC_WRITE:             dir = "-w"; break;
435         case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
436         default:                     dir = "*ERR*"; break;
437         }
438         switch (_IOC_TYPE(cmd)) {
439         case 'd':
440                 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n",
441                        (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
442                        v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
443                 break;
444 #ifdef CONFIG_VIDEO_V4L1_COMPAT
445         case 'v':
446                 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
447                        (_IOC_NR(cmd) < V4L1_IOCTLS) ?
448                        v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
449                 break;
450 #endif
451         case 'V':
452                 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n",
453                        (_IOC_NR(cmd) < V4L2_IOCTLS) ?
454                        v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
455                 break;
456
457         default:
458                 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n",
459                        _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
460         }
461 }
462
463 /* Common ioctl debug function. This function can be used by
464    external ioctl messages as well as internal V4L ioctl and its
465    arguments */
466 void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
467 {
468         printk(s);
469         printk(": ");
470         v4l_printk_ioctl(cmd);
471         switch (cmd) {
472         case VIDIOC_INT_G_CHIP_IDENT:
473         {
474                 enum v4l2_chip_ident  *p=arg;
475                 printk ("%s: chip ident=%d\n", s, *p);
476                 break;
477         }
478         case VIDIOC_G_PRIORITY:
479         case VIDIOC_S_PRIORITY:
480         {
481                 enum v4l2_priority *p=arg;
482                 printk ("%s: priority=%d\n", s, *p);
483                 break;
484         }
485         case VIDIOC_INT_S_TUNER_MODE:
486         {
487                 enum v4l2_tuner_type *p=arg;
488                 printk ("%s: tuner type=%d\n", s, *p);
489                 break;
490         }
491 #ifdef CONFIG_VIDEO_V4L1_COMPAT
492         case DECODER_SET_VBI_BYPASS:
493         case DECODER_ENABLE_OUTPUT:
494         case DECODER_GET_STATUS:
495         case DECODER_SET_OUTPUT:
496         case DECODER_SET_INPUT:
497         case DECODER_SET_GPIO:
498         case DECODER_SET_NORM:
499         case VIDIOCCAPTURE:
500         case VIDIOCSYNC:
501         case VIDIOCSWRITEMODE:
502 #endif
503         case TUNER_SET_TYPE_ADDR:
504         case TUNER_SET_STANDBY:
505         case TDA9887_SET_CONFIG:
506 #ifdef __OLD_VIDIOC_
507         case VIDIOC_OVERLAY_OLD:
508 #endif
509         case VIDIOC_STREAMOFF:
510         case VIDIOC_G_OUTPUT:
511         case VIDIOC_S_OUTPUT:
512         case VIDIOC_STREAMON:
513         case VIDIOC_G_INPUT:
514         case VIDIOC_OVERLAY:
515         case VIDIOC_S_INPUT:
516         {
517                 int *p=arg;
518                 printk ("%s: value=%d\n", s, *p);
519                 break;
520         }
521         case VIDIOC_G_AUDIO:
522         case VIDIOC_S_AUDIO:
523         case VIDIOC_ENUMAUDIO:
524 #ifdef __OLD_VIDIOC_
525         case VIDIOC_G_AUDIO_OLD:
526 #endif
527         {
528                 struct v4l2_audio *p=arg;
529
530                 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n",
531                         s,p->index, p->name,p->capability, p->mode);
532                 break;
533         }
534         case VIDIOC_G_AUDOUT:
535         case VIDIOC_S_AUDOUT:
536         case VIDIOC_ENUMAUDOUT:
537 #ifdef __OLD_VIDIOC_
538         case VIDIOC_G_AUDOUT_OLD:
539 #endif
540         {
541                 struct v4l2_audioout *p=arg;
542                 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n", s,
543                                 p->index, p->name, p->capability,p->mode);
544                 break;
545         }
546         case VIDIOC_QBUF:
547         case VIDIOC_DQBUF:
548         case VIDIOC_QUERYBUF:
549         {
550                 struct v4l2_buffer *p=arg;
551                 struct v4l2_timecode *tc=&p->timecode;
552                 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
553                         "bytesused=%d, flags=0x%08x, "
554                         "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
555                                 s,
556                                 (p->timestamp.tv_sec/3600),
557                                 (int)(p->timestamp.tv_sec/60)%60,
558                                 (int)(p->timestamp.tv_sec%60),
559                                 p->timestamp.tv_usec,
560                                 p->index,
561                                 prt_names(p->type,v4l2_type_names),
562                                 p->bytesused,p->flags,
563                                 p->field,p->sequence,
564                                 prt_names(p->memory,v4l2_memory_names),
565                                 p->m.userptr);
566                 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
567                         "flags=0x%08x, frames=%d, userbits=0x%08x\n",
568                                 s,tc->hours,tc->minutes,tc->seconds,
569                                 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
570                 break;
571         }
572         case VIDIOC_QUERYCAP:
573         {
574                 struct v4l2_capability *p=arg;
575                 printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, "
576                         "capabilities=0x%08x\n", s,
577                                 p->driver,p->card,p->bus_info,
578                                 p->version,
579                                 p->capabilities);
580                 break;
581         }
582         case VIDIOC_G_CTRL:
583         case VIDIOC_S_CTRL:
584 #ifdef __OLD_VIDIOC_
585         case VIDIOC_S_CTRL_OLD:
586 #endif
587         {
588                 struct v4l2_control *p=arg;
589                 printk ("%s: id=%d, value=%d\n", s, p->id, p->value);
590                 break;
591         }
592         case VIDIOC_G_EXT_CTRLS:
593         case VIDIOC_S_EXT_CTRLS:
594         case VIDIOC_TRY_EXT_CTRLS:
595         {
596                 struct v4l2_ext_controls *p = arg;
597                 int i;
598
599                 printk("%s: ctrl_class=%d, count=%d\n", s, p->ctrl_class, p->count);
600                 for (i = 0; i < p->count; i++) {
601                         struct v4l2_ext_control *c = &p->controls[i];
602                         if (cmd == VIDIOC_G_EXT_CTRLS)
603                                 printk("%s: id=%d\n", s, c->id);
604                         else
605                                 printk("%s: id=%d, value=%d\n", s, c->id, c->value);
606                 }
607                 break;
608         }
609         case VIDIOC_G_CROP:
610         case VIDIOC_S_CROP:
611         {
612                 struct v4l2_crop *p=arg;
613                 /*FIXME: Should also show rect structs */
614                 printk ("%s: type=%d\n", s, p->type);
615                 break;
616         }
617         case VIDIOC_CROPCAP:
618 #ifdef __OLD_VIDIOC_
619         case VIDIOC_CROPCAP_OLD:
620 #endif
621         {
622                 struct v4l2_cropcap *p=arg;
623                 /*FIXME: Should also show rect structs */
624                 printk ("%s: type=%d\n", s, p->type);
625                 break;
626         }
627         case VIDIOC_INT_DECODE_VBI_LINE:
628         {
629                 struct v4l2_decode_vbi_line *p=arg;
630                 printk ("%s: is_second_field=%d, ptr=0x%08lx, line=%d, "
631                         "type=%d\n", s,
632                                 p->is_second_field,(unsigned long)p->p,p->line,p->type);
633                 break;
634         }
635         case VIDIOC_ENUM_FMT:
636         {
637                 struct v4l2_fmtdesc *p=arg;
638                 printk ("%s: index=%d, type=%d, flags=%d, description=%s,"
639                         " pixelformat=%d\n", s,
640                                 p->index, p->type, p->flags,p->description,
641                                 p->pixelformat);
642
643                 break;
644         }
645         case VIDIOC_G_FMT:
646         case VIDIOC_S_FMT:
647         case VIDIOC_TRY_FMT:
648         {
649                 struct v4l2_format *p=arg;
650                 printk ("%s: type=%s\n", s,
651                                 prt_names(p->type,v4l2_type_names));
652                 switch (p->type) {
653                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
654                         v4l_print_pix_fmt (s, &p->fmt.pix);
655                         break;
656                 default:
657                         break;
658                 }
659         }
660         case VIDIOC_G_FBUF:
661         case VIDIOC_S_FBUF:
662         {
663                 struct v4l2_framebuffer *p=arg;
664                 printk ("%s: capability=%d, flags=%d, base=0x%08lx\n", s,
665                                 p->capability,p->flags, (unsigned long)p->base);
666                 v4l_print_pix_fmt (s, &p->fmt);
667                 break;
668         }
669         case VIDIOC_G_FREQUENCY:
670         case VIDIOC_S_FREQUENCY:
671         {
672                 struct v4l2_frequency *p=arg;
673                 printk ("%s: tuner=%d, type=%d, frequency=%d\n", s,
674                                 p->tuner,p->type,p->frequency);
675                 break;
676         }
677         case VIDIOC_ENUMINPUT:
678         {
679                 struct v4l2_input *p=arg;
680                 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
681                         "tuner=%d, std=%Ld, status=%d\n", s,
682                                 p->index,p->name,p->type,p->audioset,
683                                 p->tuner,
684                                 (unsigned long long)p->std,
685                                 p->status);
686                 break;
687         }
688         case VIDIOC_G_JPEGCOMP:
689         case VIDIOC_S_JPEGCOMP:
690         {
691                 struct v4l2_jpegcompression *p=arg;
692                 printk ("%s: quality=%d, APPn=%d, APP_len=%d, COM_len=%d,"
693                         " jpeg_markers=%d\n", s,
694                                 p->quality,p->APPn,p->APP_len,
695                                 p->COM_len,p->jpeg_markers);
696                 break;
697         }
698         case VIDIOC_G_MODULATOR:
699         case VIDIOC_S_MODULATOR:
700         {
701                 struct v4l2_modulator *p=arg;
702                 printk ("%s: index=%d, name=%s, capability=%d, rangelow=%d,"
703                         " rangehigh=%d, txsubchans=%d\n", s,
704                                 p->index, p->name,p->capability,p->rangelow,
705                                 p->rangehigh,p->txsubchans);
706                 break;
707         }
708         case VIDIOC_G_MPEGCOMP:
709         case VIDIOC_S_MPEGCOMP:
710         {
711                 struct v4l2_mpeg_compression *p=arg;
712                 /*FIXME: Several fields not shown */
713                 printk ("%s: ts_pid_pmt=%d, ts_pid_audio=%d, ts_pid_video=%d, "
714                         "ts_pid_pcr=%d, ps_size=%d, au_sample_rate=%d, "
715                         "au_pesid=%c, vi_frame_rate=%d, vi_frames_per_gop=%d, "
716                         "vi_bframes_count=%d, vi_pesid=%c\n", s,
717                                 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
718                                 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
719                                 p->au_pesid, p->vi_frame_rate,
720                                 p->vi_frames_per_gop, p->vi_bframes_count,
721                                 p->vi_pesid);
722                 break;
723         }
724         case VIDIOC_ENUMOUTPUT:
725         {
726                 struct v4l2_output *p=arg;
727                 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
728                         "modulator=%d, std=%Ld\n",
729                                 s,p->index,p->name,p->type,p->audioset,
730                                 p->modulator,
731                                 (unsigned long long)p->std);
732                 break;
733         }
734         case VIDIOC_QUERYCTRL:
735         {
736                 struct v4l2_queryctrl *p=arg;
737                 printk ("%s: id=%d, type=%d, name=%s, min/max=%d/%d,"
738                         " step=%d, default=%d, flags=0x%08x\n", s,
739                                 p->id,p->type,p->name,p->minimum,p->maximum,
740                                 p->step,p->default_value,p->flags);
741                 break;
742         }
743         case VIDIOC_QUERYMENU:
744         {
745                 struct v4l2_querymenu *p=arg;
746                 printk ("%s: id=%d, index=%d, name=%s\n", s,
747                                 p->id,p->index,p->name);
748                 break;
749         }
750         case VIDIOC_INT_G_REGISTER:
751         case VIDIOC_INT_S_REGISTER:
752         {
753                 struct v4l2_register *p=arg;
754                 printk ("%s: i2c_id=%d, reg=%lu, val=%d\n", s,
755                                 p->i2c_id,p->reg,p->val);
756
757                 break;
758         }
759         case VIDIOC_REQBUFS:
760         {
761                 struct v4l2_requestbuffers *p=arg;
762                 printk ("%s: count=%d, type=%s, memory=%s\n", s,
763                                 p->count,
764                                 prt_names(p->type,v4l2_type_names),
765                                 prt_names(p->memory,v4l2_memory_names));
766                 break;
767         }
768         case VIDIOC_INT_S_AUDIO_ROUTING:
769         case VIDIOC_INT_S_VIDEO_ROUTING:
770         case VIDIOC_INT_G_AUDIO_ROUTING:
771         case VIDIOC_INT_G_VIDEO_ROUTING:
772         {
773                 struct v4l2_routing  *p=arg;
774                 printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output);
775                 break;
776         }
777         case VIDIOC_INT_S_CRYSTAL_FREQ:
778         {
779                 struct v4l2_crystal_freq *p=arg;
780                 printk ("%s: freq=%u, flags=0x%x\n", s, p->freq, p->flags);
781                 break;
782         }
783         case VIDIOC_G_SLICED_VBI_CAP:
784         {
785                 struct v4l2_sliced_vbi_cap *p=arg;
786                 printk ("%s: service_set=%d\n", s,
787                                 p->service_set);
788                 break;
789         }
790         case VIDIOC_INT_S_VBI_DATA:
791         case VIDIOC_INT_G_VBI_DATA:
792         {
793                 struct v4l2_sliced_vbi_data  *p=arg;
794                 printk ("%s: id=%d, field=%d, line=%d\n", s,
795                                 p->id, p->field, p->line);
796                 break;
797         }
798         case VIDIOC_ENUMSTD:
799         {
800                 struct v4l2_standard *p=arg;
801                 printk ("%s: index=%d, id=%Ld, name=%s, fps=%d/%d, "
802                         "framelines=%d\n", s, p->index,
803                                 (unsigned long long)p->id, p->name,
804                                 p->frameperiod.numerator,
805                                 p->frameperiod.denominator,
806                                 p->framelines);
807
808                 break;
809         }
810         case VIDIOC_G_PARM:
811         case VIDIOC_S_PARM:
812 #ifdef __OLD_VIDIOC_
813         case VIDIOC_S_PARM_OLD:
814 #endif
815         {
816                 struct v4l2_streamparm *p=arg;
817                 printk ("%s: type=%d\n", s, p->type);
818
819                 break;
820         }
821         case VIDIOC_G_TUNER:
822         case VIDIOC_S_TUNER:
823         {
824                 struct v4l2_tuner *p=arg;
825                 printk ("%s: index=%d, name=%s, type=%d, capability=%d, "
826                         "rangelow=%d, rangehigh=%d, signal=%d, afc=%d, "
827                         "rxsubchans=%d, audmode=%d\n", s,
828                                 p->index, p->name, p->type,
829                                 p->capability, p->rangelow,p->rangehigh,
830                                 p->rxsubchans, p->audmode, p->signal,
831                                 p->afc);
832                 break;
833         }
834 #ifdef CONFIG_VIDEO_V4L1_COMPAT
835         case VIDIOCGVBIFMT:
836         case VIDIOCSVBIFMT:
837         {
838                 struct vbi_format *p=arg;
839                 printk ("%s: sampling_rate=%d, samples_per_line=%d, "
840                         "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", s,
841                                 p->sampling_rate,p->samples_per_line,
842                                 p->sample_format,p->start[0],p->start[1],
843                                 p->count[0],p->count[1],p->flags);
844                 break;
845         }
846         case VIDIOCGAUDIO:
847         case VIDIOCSAUDIO:
848         {
849                 struct video_audio *p=arg;
850                 printk ("%s: audio=%d, volume=%d, bass=%d, treble=%d, "
851                         "flags=%d, name=%s, mode=%d, balance=%d, step=%d\n",
852                                 s,p->audio,p->volume,p->bass, p->treble,
853                                 p->flags,p->name,p->mode,p->balance,p->step);
854                 break;
855         }
856         case VIDIOCGFBUF:
857         case VIDIOCSFBUF:
858         {
859                 struct video_buffer *p=arg;
860                 printk ("%s: base=%08lx, height=%d, width=%d, depth=%d, "
861                         "bytesperline=%d\n", s,
862                                 (unsigned long) p->base, p->height, p->width,
863                                 p->depth,p->bytesperline);
864                 break;
865         }
866         case VIDIOCGCAP:
867         {
868                 struct video_capability *p=arg;
869                 printk ("%s: name=%s, type=%d, channels=%d, audios=%d, "
870                         "maxwidth=%d, maxheight=%d, minwidth=%d, minheight=%d\n",
871                                 s,p->name,p->type,p->channels,p->audios,
872                                 p->maxwidth,p->maxheight,p->minwidth,
873                                 p->minheight);
874
875                 break;
876         }
877         case VIDIOCGCAPTURE:
878         case VIDIOCSCAPTURE:
879         {
880                 struct video_capture *p=arg;
881                 printk ("%s: x=%d, y=%d, width=%d, height=%d, decimation=%d,"
882                         " flags=%d\n", s,
883                                 p->x, p->y,p->width, p->height,
884                                 p->decimation,p->flags);
885                 break;
886         }
887         case VIDIOCGCHAN:
888         case VIDIOCSCHAN:
889         {
890                 struct video_channel *p=arg;
891                 printk ("%s: channel=%d, name=%s, tuners=%d, flags=%d, "
892                         "type=%d, norm=%d\n", s,
893                                 p->channel,p->name,p->tuners,
894                                 p->flags,p->type,p->norm);
895
896                 break;
897         }
898         case VIDIOCSMICROCODE:
899         {
900                 struct video_code *p=arg;
901                 printk ("%s: loadwhat=%s, datasize=%d\n", s,
902                                 p->loadwhat,p->datasize);
903                 break;
904         }
905         case DECODER_GET_CAPABILITIES:
906         {
907                 struct video_decoder_capability *p=arg;
908                 printk ("%s: flags=%d, inputs=%d, outputs=%d\n", s,
909                                 p->flags,p->inputs,p->outputs);
910                 break;
911         }
912         case DECODER_INIT:
913         {
914                 struct video_decoder_init *p=arg;
915                 printk ("%s: len=%c\n", s, p->len);
916                 break;
917         }
918         case VIDIOCGPLAYINFO:
919         {
920                 struct video_info *p=arg;
921                 printk ("%s: frame_count=%d, h_size=%d, v_size=%d, "
922                         "smpte_timecode=%d, picture_type=%d, "
923                         "temporal_reference=%d, user_data=%s\n", s,
924                                 p->frame_count, p->h_size,
925                                 p->v_size, p->smpte_timecode,
926                                 p->picture_type, p->temporal_reference,
927                                 p->user_data);
928                 break;
929         }
930         case VIDIOCKEY:
931         {
932                 struct video_key *p=arg;
933                 printk ("%s: key=%s, flags=%d\n", s,
934                                 p->key, p->flags);
935                 break;
936         }
937         case VIDIOCGMBUF:
938         {
939                 struct video_mbuf *p=arg;
940                 printk ("%s: size=%d, frames=%d, offsets=0x%08lx\n", s,
941                                 p->size,
942                                 p->frames,
943                                 (unsigned long)p->offsets);
944                 break;
945         }
946         case VIDIOCMCAPTURE:
947         {
948                 struct video_mmap *p=arg;
949                 printk ("%s: frame=%d, height=%d, width=%d, format=%d\n", s,
950                                 p->frame,
951                                 p->height, p->width,
952                                 p->format);
953                 break;
954         }
955         case VIDIOCGPICT:
956         case VIDIOCSPICT:
957         case DECODER_SET_PICTURE:
958         {
959                 struct video_picture *p=arg;
960
961                 printk ("%s: brightness=%d, hue=%d, colour=%d, contrast=%d,"
962                         " whiteness=%d, depth=%d, palette=%d\n", s,
963                                 p->brightness, p->hue, p->colour,
964                                 p->contrast, p->whiteness, p->depth,
965                                 p->palette);
966                 break;
967         }
968         case VIDIOCSPLAYMODE:
969         {
970                 struct video_play_mode *p=arg;
971                 printk ("%s: mode=%d, p1=%d, p2=%d\n", s,
972                                 p->mode,p->p1,p->p2);
973                 break;
974         }
975         case VIDIOCGTUNER:
976         case VIDIOCSTUNER:
977         {
978                 struct video_tuner *p=arg;
979                 printk ("%s: tuner=%d, name=%s, rangelow=%ld, rangehigh=%ld, "
980                         "flags=%d, mode=%d, signal=%d\n", s,
981                                 p->tuner, p->name,p->rangelow, p->rangehigh,
982                                 p->flags,p->mode, p->signal);
983                 break;
984         }
985         case VIDIOCGUNIT:
986         {
987                 struct video_unit *p=arg;
988                 printk ("%s: video=%d, vbi=%d, radio=%d, audio=%d, "
989                         "teletext=%d\n", s,
990                                 p->video,p->vbi,p->radio,p->audio,p->teletext);
991                 break;
992         }
993         case VIDIOCGWIN:
994         case VIDIOCSWIN:
995         {
996                 struct video_window *p=arg;
997                 printk ("%s: x=%d, y=%d, width=%d, height=%d, chromakey=%d,"
998                         " flags=%d, clipcount=%d\n", s,
999                                 p->x, p->y,p->width, p->height,
1000                                 p->chromakey,p->flags,
1001                                 p->clipcount);
1002                 break;
1003         }
1004         case VIDIOCGFREQ:
1005         case VIDIOCSFREQ:
1006         {
1007                 unsigned long *p=arg;
1008                 printk ("%s: value=%lu\n", s, *p);
1009                 break;
1010         }
1011 #endif
1012         case VIDIOC_INT_AUDIO_CLOCK_FREQ:
1013         case VIDIOC_INT_I2S_CLOCK_FREQ:
1014         case VIDIOC_INT_S_STANDBY:
1015         case VIDIOC_INT_RESET:
1016         {
1017                 u32 *p=arg;
1018
1019                 printk ("%s: value=%d\n", s, *p);
1020                 break;
1021         }
1022         case VIDIOC_G_STD:
1023         case VIDIOC_S_STD:
1024         case VIDIOC_QUERYSTD:
1025         {
1026                 v4l2_std_id *p=arg;
1027
1028                 printk ("%s: value=%Lu\n", s, (unsigned long long)*p);
1029                 break;
1030         }
1031         }
1032 }
1033
1034 /* ----------------------------------------------------------------- */
1035
1036 /* Helper functions for control handling                             */
1037
1038 /* Check for correctness of the ctrl's value based on the data from
1039    struct v4l2_queryctrl and the available menu items. Note that
1040    menu_items may be NULL, in that case it is ignored. */
1041 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
1042                 const char **menu_items)
1043 {
1044         if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
1045                 return -EINVAL;
1046         if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
1047                 return -EBUSY;
1048         if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
1049             qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
1050             qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
1051                 return 0;
1052         if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
1053                 return -ERANGE;
1054         if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
1055                 if (menu_items[ctrl->value] == NULL ||
1056                     menu_items[ctrl->value][0] == '\0')
1057                         return -EINVAL;
1058         }
1059         return 0;
1060 }
1061
1062 /* Returns NULL or a character pointer array containing the menu for
1063    the given control ID. The pointer array ends with a NULL pointer.
1064    An empty string signifies a menu entry that is invalid. This allows
1065    drivers to disable certain options if it is not supported. */
1066 const char **v4l2_ctrl_get_menu(u32 id)
1067 {
1068         static const char *mpeg_audio_sampling_freq[] = {
1069                 "44.1 kHz",
1070                 "48 kHz",
1071                 "32 kHz",
1072                 NULL
1073         };
1074         static const char *mpeg_audio_encoding[] = {
1075                 "Layer I",
1076                 "Layer II",
1077                 "Layer III",
1078                 NULL
1079         };
1080         static const char *mpeg_audio_l1_bitrate[] = {
1081                 "32 kbps",
1082                 "64 kbps",
1083                 "96 kbps",
1084                 "128 kbps",
1085                 "160 kbps",
1086                 "192 kbps",
1087                 "224 kbps",
1088                 "256 kbps",
1089                 "288 kbps",
1090                 "320 kbps",
1091                 "352 kbps",
1092                 "384 kbps",
1093                 "416 kbps",
1094                 "448 kbps",
1095                 NULL
1096         };
1097         static const char *mpeg_audio_l2_bitrate[] = {
1098                 "32 kbps",
1099                 "48 kbps",
1100                 "56 kbps",
1101                 "64 kbps",
1102                 "80 kbps",
1103                 "96 kbps",
1104                 "112 kbps",
1105                 "128 kbps",
1106                 "160 kbps",
1107                 "192 kbps",
1108                 "224 kbps",
1109                 "256 kbps",
1110                 "320 kbps",
1111                 "384 kbps",
1112                 NULL
1113         };
1114         static const char *mpeg_audio_l3_bitrate[] = {
1115                 "32 kbps",
1116                 "40 kbps",
1117                 "48 kbps",
1118                 "56 kbps",
1119                 "64 kbps",
1120                 "80 kbps",
1121                 "96 kbps",
1122                 "112 kbps",
1123                 "128 kbps",
1124                 "160 kbps",
1125                 "192 kbps",
1126                 "224 kbps",
1127                 "256 kbps",
1128                 "320 kbps",
1129                 NULL
1130         };
1131         static const char *mpeg_audio_mode[] = {
1132                 "Stereo",
1133                 "Joint Stereo",
1134                 "Dual",
1135                 "Mono",
1136                 NULL
1137         };
1138         static const char *mpeg_audio_mode_extension[] = {
1139                 "Bound 4",
1140                 "Bound 8",
1141                 "Bound 12",
1142                 "Bound 16",
1143                 NULL
1144         };
1145         static const char *mpeg_audio_emphasis[] = {
1146                 "No Emphasis",
1147                 "50/15 us",
1148                 "CCITT J17",
1149                 NULL
1150         };
1151         static const char *mpeg_audio_crc[] = {
1152                 "No CRC",
1153                 "16-bit CRC",
1154                 NULL
1155         };
1156         static const char *mpeg_video_encoding[] = {
1157                 "MPEG-1",
1158                 "MPEG-2",
1159                 NULL
1160         };
1161         static const char *mpeg_video_aspect[] = {
1162                 "1x1",
1163                 "4x3",
1164                 "16x9",
1165                 "2.21x1",
1166                 NULL
1167         };
1168         static const char *mpeg_video_bitrate_mode[] = {
1169                 "Variable Bitrate",
1170                 "Constant Bitrate",
1171                 NULL
1172         };
1173         static const char *mpeg_stream_type[] = {
1174                 "MPEG-2 Program Stream",
1175                 "MPEG-2 Transport Stream",
1176                 "MPEG-1 System Stream",
1177                 "MPEG-2 DVD-compatible Stream",
1178                 "MPEG-1 VCD-compatible Stream",
1179                 "MPEG-2 SVCD-compatible Stream",
1180                 NULL
1181         };
1182         static const char *mpeg_stream_vbi_fmt[] = {
1183                 "No VBI",
1184                 "Private packet, IVTV format",
1185                 NULL
1186         };
1187
1188         switch (id) {
1189                 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1190                         return mpeg_audio_sampling_freq;
1191                 case V4L2_CID_MPEG_AUDIO_ENCODING:
1192                         return mpeg_audio_encoding;
1193                 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1194                         return mpeg_audio_l1_bitrate;
1195                 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1196                         return mpeg_audio_l2_bitrate;
1197                 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1198                         return mpeg_audio_l3_bitrate;
1199                 case V4L2_CID_MPEG_AUDIO_MODE:
1200                         return mpeg_audio_mode;
1201                 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1202                         return mpeg_audio_mode_extension;
1203                 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1204                         return mpeg_audio_emphasis;
1205                 case V4L2_CID_MPEG_AUDIO_CRC:
1206                         return mpeg_audio_crc;
1207                 case V4L2_CID_MPEG_VIDEO_ENCODING:
1208                         return mpeg_video_encoding;
1209                 case V4L2_CID_MPEG_VIDEO_ASPECT:
1210                         return mpeg_video_aspect;
1211                 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1212                         return mpeg_video_bitrate_mode;
1213                 case V4L2_CID_MPEG_STREAM_TYPE:
1214                         return mpeg_stream_type;
1215                 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1216                         return mpeg_stream_vbi_fmt;
1217                 default:
1218                         return NULL;
1219         }
1220 }
1221
1222 /* Fill in a struct v4l2_queryctrl */
1223 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
1224 {
1225         const char *name;
1226
1227         qctrl->flags = 0;
1228         switch (qctrl->id) {
1229         /* USER controls */
1230         case V4L2_CID_USER_CLASS:       name = "User Controls"; break;
1231         case V4L2_CID_AUDIO_VOLUME:     name = "Volume"; break;
1232         case V4L2_CID_AUDIO_MUTE:       name = "Mute"; break;
1233         case V4L2_CID_AUDIO_BALANCE:    name = "Balance"; break;
1234         case V4L2_CID_AUDIO_BASS:       name = "Bass"; break;
1235         case V4L2_CID_AUDIO_TREBLE:     name = "Treble"; break;
1236         case V4L2_CID_AUDIO_LOUDNESS:   name = "Loudness"; break;
1237         case V4L2_CID_BRIGHTNESS:       name = "Brightness"; break;
1238         case V4L2_CID_CONTRAST:         name = "Contrast"; break;
1239         case V4L2_CID_SATURATION:       name = "Saturation"; break;
1240         case V4L2_CID_HUE:              name = "Hue"; break;
1241
1242         /* MPEG controls */
1243         case V4L2_CID_MPEG_CLASS:               name = "MPEG Encoder Controls"; break;
1244         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break;
1245         case V4L2_CID_MPEG_AUDIO_ENCODING:      name = "Audio Encoding Layer"; break;
1246         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:    name = "Audio Layer I Bitrate"; break;
1247         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:    name = "Audio Layer II Bitrate"; break;
1248         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:    name = "Audio Layer III Bitrate"; break;
1249         case V4L2_CID_MPEG_AUDIO_MODE:          name = "Audio Stereo Mode"; break;
1250         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break;
1251         case V4L2_CID_MPEG_AUDIO_EMPHASIS:      name = "Audio Emphasis"; break;
1252         case V4L2_CID_MPEG_AUDIO_CRC:           name = "Audio CRC"; break;
1253         case V4L2_CID_MPEG_VIDEO_ENCODING:      name = "Video Encoding"; break;
1254         case V4L2_CID_MPEG_VIDEO_ASPECT:        name = "Video Aspect"; break;
1255         case V4L2_CID_MPEG_VIDEO_B_FRAMES:      name = "Video B Frames"; break;
1256         case V4L2_CID_MPEG_VIDEO_GOP_SIZE:      name = "Video GOP Size"; break;
1257         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:   name = "Video GOP Closure"; break;
1258         case V4L2_CID_MPEG_VIDEO_PULLDOWN:      name = "Video Pulldown"; break;
1259         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:  name = "Video Bitrate Mode"; break;
1260         case V4L2_CID_MPEG_VIDEO_BITRATE:       name = "Video Bitrate"; break;
1261         case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:  name = "Video Peak Bitrate"; break;
1262         case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break;
1263         case V4L2_CID_MPEG_STREAM_TYPE:         name = "Stream Type"; break;
1264         case V4L2_CID_MPEG_STREAM_PID_PMT:      name = "Stream PMT Program ID"; break;
1265         case V4L2_CID_MPEG_STREAM_PID_AUDIO:    name = "Stream Audio Program ID"; break;
1266         case V4L2_CID_MPEG_STREAM_PID_VIDEO:    name = "Stream Video Program ID"; break;
1267         case V4L2_CID_MPEG_STREAM_PID_PCR:      name = "Stream PCR Program ID"; break;
1268         case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break;
1269         case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break;
1270         case V4L2_CID_MPEG_STREAM_VBI_FMT:      name = "Stream VBI Format"; break;
1271
1272         default:
1273                 return -EINVAL;
1274         }
1275         switch (qctrl->id) {
1276         case V4L2_CID_AUDIO_MUTE:
1277         case V4L2_CID_AUDIO_LOUDNESS:
1278         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1279         case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1280                 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
1281                 min = 0;
1282                 max = step = 1;
1283                 break;
1284         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1285         case V4L2_CID_MPEG_AUDIO_ENCODING:
1286         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1287         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1288         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1289         case V4L2_CID_MPEG_AUDIO_MODE:
1290         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1291         case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1292         case V4L2_CID_MPEG_AUDIO_CRC:
1293         case V4L2_CID_MPEG_VIDEO_ENCODING:
1294         case V4L2_CID_MPEG_VIDEO_ASPECT:
1295         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1296         case V4L2_CID_MPEG_STREAM_TYPE:
1297         case V4L2_CID_MPEG_STREAM_VBI_FMT:
1298                 qctrl->type = V4L2_CTRL_TYPE_MENU;
1299                 step = 1;
1300                 break;
1301         case V4L2_CID_USER_CLASS:
1302         case V4L2_CID_MPEG_CLASS:
1303                 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
1304                 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1305                 min = max = step = def = 0;
1306                 break;
1307         default:
1308                 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
1309                 break;
1310         }
1311         switch (qctrl->id) {
1312         case V4L2_CID_MPEG_AUDIO_ENCODING:
1313         case V4L2_CID_MPEG_AUDIO_MODE:
1314         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1315         case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1316         case V4L2_CID_MPEG_STREAM_TYPE:
1317                 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
1318                 break;
1319         case V4L2_CID_AUDIO_VOLUME:
1320         case V4L2_CID_AUDIO_BALANCE:
1321         case V4L2_CID_AUDIO_BASS:
1322         case V4L2_CID_AUDIO_TREBLE:
1323         case V4L2_CID_BRIGHTNESS:
1324         case V4L2_CID_CONTRAST:
1325         case V4L2_CID_SATURATION:
1326         case V4L2_CID_HUE:
1327                 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
1328                 break;
1329         }
1330         qctrl->minimum = min;
1331         qctrl->maximum = max;
1332         qctrl->step = step;
1333         qctrl->default_value = def;
1334         qctrl->reserved[0] = qctrl->reserved[1] = 0;
1335         snprintf(qctrl->name, sizeof(qctrl->name), name);
1336         return 0;
1337 }
1338
1339 /* Fill in a struct v4l2_queryctrl with standard values based on
1340    the control ID. */
1341 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
1342 {
1343         switch (qctrl->id) {
1344         /* USER controls */
1345         case V4L2_CID_USER_CLASS:
1346         case V4L2_CID_MPEG_CLASS:
1347                 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
1348         case V4L2_CID_AUDIO_VOLUME:
1349                 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
1350         case V4L2_CID_AUDIO_MUTE:
1351         case V4L2_CID_AUDIO_LOUDNESS:
1352                 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
1353         case V4L2_CID_AUDIO_BALANCE:
1354         case V4L2_CID_AUDIO_BASS:
1355         case V4L2_CID_AUDIO_TREBLE:
1356                 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
1357         case V4L2_CID_BRIGHTNESS:
1358                 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
1359         case V4L2_CID_CONTRAST:
1360         case V4L2_CID_SATURATION:
1361                 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
1362         case V4L2_CID_HUE:
1363                 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
1364
1365         /* MPEG controls */
1366         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1367                 return v4l2_ctrl_query_fill(qctrl,
1368                                 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
1369                                 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
1370                                 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
1371         case V4L2_CID_MPEG_AUDIO_ENCODING:
1372                 return v4l2_ctrl_query_fill(qctrl,
1373                                 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
1374                                 V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1,
1375                                 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
1376         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1377                 return v4l2_ctrl_query_fill(qctrl,
1378                                 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
1379                                 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
1380                                 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
1381         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1382                 return v4l2_ctrl_query_fill(qctrl,
1383                                 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
1384                                 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
1385                                 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
1386         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1387                 return v4l2_ctrl_query_fill(qctrl,
1388                                 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
1389                                 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
1390                                 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
1391         case V4L2_CID_MPEG_AUDIO_MODE:
1392                 return v4l2_ctrl_query_fill(qctrl,
1393                                 V4L2_MPEG_AUDIO_MODE_STEREO,
1394                                 V4L2_MPEG_AUDIO_MODE_MONO, 1,
1395                                 V4L2_MPEG_AUDIO_MODE_STEREO);
1396         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1397                 return v4l2_ctrl_query_fill(qctrl,
1398                                 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
1399                                 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
1400                                 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
1401         case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1402                 return v4l2_ctrl_query_fill(qctrl,
1403                                 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
1404                                 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
1405                                 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
1406         case V4L2_CID_MPEG_AUDIO_CRC:
1407                 return v4l2_ctrl_query_fill(qctrl,
1408                                 V4L2_MPEG_AUDIO_CRC_NONE,
1409                                 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
1410                                 V4L2_MPEG_AUDIO_CRC_NONE);
1411         case V4L2_CID_MPEG_VIDEO_ENCODING:
1412                 return v4l2_ctrl_query_fill(qctrl,
1413                                 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
1414                                 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
1415                                 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
1416         case V4L2_CID_MPEG_VIDEO_ASPECT:
1417                 return v4l2_ctrl_query_fill(qctrl,
1418                                 V4L2_MPEG_VIDEO_ASPECT_1x1,
1419                                 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
1420                                 V4L2_MPEG_VIDEO_ASPECT_4x3);
1421         case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1422                 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
1423         case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1424                 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
1425         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1426                 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
1427         case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1428                 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
1429         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1430                 return v4l2_ctrl_query_fill(qctrl,
1431                                 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
1432                                 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
1433                                 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
1434         case V4L2_CID_MPEG_VIDEO_BITRATE:
1435                 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
1436         case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
1437                 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
1438         case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
1439                 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1440         case V4L2_CID_MPEG_STREAM_TYPE:
1441                 return v4l2_ctrl_query_fill(qctrl,
1442                                 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
1443                                 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
1444                                 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
1445         case V4L2_CID_MPEG_STREAM_PID_PMT:
1446                 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
1447         case V4L2_CID_MPEG_STREAM_PID_AUDIO:
1448                 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
1449         case V4L2_CID_MPEG_STREAM_PID_VIDEO:
1450                 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
1451         case V4L2_CID_MPEG_STREAM_PID_PCR:
1452                 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
1453         case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
1454                 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1455         case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
1456                 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1457         case V4L2_CID_MPEG_STREAM_VBI_FMT:
1458                 return v4l2_ctrl_query_fill(qctrl,
1459                                 V4L2_MPEG_STREAM_VBI_FMT_NONE,
1460                                 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
1461                                 V4L2_MPEG_STREAM_VBI_FMT_NONE);
1462         default:
1463                 return -EINVAL;
1464         }
1465 }
1466
1467 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
1468    the menu. The qctrl pointer may be NULL, in which case it is ignored. */
1469 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
1470                const char **menu_items)
1471 {
1472         int i;
1473
1474         if (menu_items == NULL ||
1475             (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
1476                 return -EINVAL;
1477         for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
1478         if (menu_items[i] == NULL || menu_items[i][0] == '\0')
1479                 return -EINVAL;
1480         snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
1481         qmenu->reserved = 0;
1482         return 0;
1483 }
1484
1485 /* ctrl_classes points to an array of u32 pointers, the last element is
1486    a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
1487    Each array must be sorted low to high and belong to the same control
1488    class. The array of u32 pointer must also be sorted, from low class IDs
1489    to high class IDs.
1490
1491    This function returns the first ID that follows after the given ID.
1492    When no more controls are available 0 is returned. */
1493 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
1494 {
1495         u32 ctrl_class;
1496         const u32 *pctrl;
1497
1498         /* if no query is desired, then just return the control ID */
1499         if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0)
1500                 return id;
1501         if (ctrl_classes == NULL)
1502                 return 0;
1503         id &= V4L2_CTRL_ID_MASK;
1504         ctrl_class = V4L2_CTRL_ID2CLASS(id);
1505         id++;   /* select next control */
1506         /* find first class that matches (or is greater than) the class of
1507            the ID */
1508         while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
1509                 ctrl_classes++;
1510         /* no more classes */
1511         if (*ctrl_classes == NULL)
1512                 return 0;
1513         pctrl = *ctrl_classes;
1514         /* find first ctrl within the class that is >= ID */
1515         while (*pctrl && *pctrl < id) pctrl++;
1516         if (*pctrl)
1517                 return *pctrl;
1518         /* we are at the end of the controls of the current class. */
1519         /* continue with next class if available */
1520         ctrl_classes++;
1521         if (*ctrl_classes == NULL)
1522                 return 0;
1523         return **ctrl_classes;
1524 }
1525
1526 /* ----------------------------------------------------------------- */
1527
1528 EXPORT_SYMBOL(v4l2_norm_to_name);
1529 EXPORT_SYMBOL(v4l2_video_std_construct);
1530
1531 EXPORT_SYMBOL(v4l2_prio_init);
1532 EXPORT_SYMBOL(v4l2_prio_change);
1533 EXPORT_SYMBOL(v4l2_prio_open);
1534 EXPORT_SYMBOL(v4l2_prio_close);
1535 EXPORT_SYMBOL(v4l2_prio_max);
1536 EXPORT_SYMBOL(v4l2_prio_check);
1537
1538 EXPORT_SYMBOL(v4l2_field_names);
1539 EXPORT_SYMBOL(v4l2_type_names);
1540 EXPORT_SYMBOL(v4l_printk_ioctl);
1541 EXPORT_SYMBOL(v4l_printk_ioctl_arg);
1542
1543 EXPORT_SYMBOL(v4l2_ctrl_next);
1544 EXPORT_SYMBOL(v4l2_ctrl_check);
1545 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
1546 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
1547 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
1548 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
1549
1550 /*
1551  * Local variables:
1552  * c-basic-offset: 8
1553  * End:
1554  */