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