V4L/DVB (4065): Several improvements at videodev.c
[linux-2.6.git] / 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/config.h>
48 #include <linux/module.h>
49 #include <linux/types.h>
50 #include <linux/kernel.h>
51 #include <linux/sched.h>
52 #include <linux/smp_lock.h>
53 #include <linux/mm.h>
54 #include <linux/string.h>
55 #include <linux/errno.h>
56 #include <asm/uaccess.h>
57 #include <asm/system.h>
58 #include <asm/pgtable.h>
59 #include <asm/io.h>
60 #include <asm/div64.h>
61 #include <linux/video_decoder.h>
62 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
63 #include <media/v4l2-common.h>
64
65 #ifdef CONFIG_KMOD
66 #include <linux/kmod.h>
67 #endif
68
69 #if defined(CONFIG_UST) || defined(CONFIG_UST_MODULE)
70 #include <linux/ust.h>
71 #endif
72
73
74 #include <linux/videodev.h>
75
76 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
77 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
78 MODULE_LICENSE("GPL");
79
80 /*
81  *
82  *      V 4 L 2   D R I V E R   H E L P E R   A P I
83  *
84  */
85
86 /*
87  *  Video Standard Operations (contributed by Michael Schimek)
88  */
89
90
91 /* Fill in the fields of a v4l2_standard structure according to the
92    'id' and 'transmission' parameters.  Returns negative on error.  */
93 int v4l2_video_std_construct(struct v4l2_standard *vs,
94                              int id, char *name)
95 {
96         u32 index = vs->index;
97
98         memset(vs, 0, sizeof(struct v4l2_standard));
99         vs->index = index;
100         vs->id    = id;
101         if (id & V4L2_STD_525_60) {
102                 vs->frameperiod.numerator = 1001;
103                 vs->frameperiod.denominator = 30000;
104                 vs->framelines = 525;
105         } else {
106                 vs->frameperiod.numerator = 1;
107                 vs->frameperiod.denominator = 25;
108                 vs->framelines = 625;
109         }
110         strlcpy(vs->name,name,sizeof(vs->name));
111         return 0;
112 }
113
114 /* ----------------------------------------------------------------- */
115 /* priority handling                                                 */
116
117 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND   || \
118                               val == V4L2_PRIORITY_INTERACTIVE  || \
119                               val == V4L2_PRIORITY_RECORD)
120
121 int v4l2_prio_init(struct v4l2_prio_state *global)
122 {
123         memset(global,0,sizeof(*global));
124         return 0;
125 }
126
127 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
128                      enum v4l2_priority new)
129 {
130         if (!V4L2_PRIO_VALID(new))
131                 return -EINVAL;
132         if (*local == new)
133                 return 0;
134
135         atomic_inc(&global->prios[new]);
136         if (V4L2_PRIO_VALID(*local))
137                 atomic_dec(&global->prios[*local]);
138         *local = new;
139         return 0;
140 }
141
142 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
143 {
144         return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
145 }
146
147 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
148 {
149         if (V4L2_PRIO_VALID(*local))
150                 atomic_dec(&global->prios[*local]);
151         return 0;
152 }
153
154 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
155 {
156         if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
157                 return V4L2_PRIORITY_RECORD;
158         if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
159                 return V4L2_PRIORITY_INTERACTIVE;
160         if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
161                 return V4L2_PRIORITY_BACKGROUND;
162         return V4L2_PRIORITY_UNSET;
163 }
164
165 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
166 {
167         if (*local < v4l2_prio_max(global))
168                 return -EBUSY;
169         return 0;
170 }
171
172
173 /* ----------------------------------------------------------------- */
174 /* some arrays for pretty-printing debug messages of enum types      */
175
176 char *v4l2_field_names[] = {
177         [V4L2_FIELD_ANY]        = "any",
178         [V4L2_FIELD_NONE]       = "none",
179         [V4L2_FIELD_TOP]        = "top",
180         [V4L2_FIELD_BOTTOM]     = "bottom",
181         [V4L2_FIELD_INTERLACED] = "interlaced",
182         [V4L2_FIELD_SEQ_TB]     = "seq-tb",
183         [V4L2_FIELD_SEQ_BT]     = "seq-bt",
184         [V4L2_FIELD_ALTERNATE]  = "alternate",
185 };
186
187 char *v4l2_type_names[] = {
188         [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
189         [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
190         [V4L2_BUF_TYPE_VIDEO_OUTPUT]  = "video-out",
191         [V4L2_BUF_TYPE_VBI_CAPTURE]   = "vbi-cap",
192         [V4L2_BUF_TYPE_VBI_OUTPUT]    = "vbi-out",
193 };
194
195 static char *v4l2_memory_names[] = {
196         [V4L2_MEMORY_MMAP]    = "mmap",
197         [V4L2_MEMORY_USERPTR] = "userptr",
198         [V4L2_MEMORY_OVERLAY] = "overlay",
199 };
200
201 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
202
203 /* ------------------------------------------------------------------ */
204 /* debug help functions                                               */
205
206 #ifdef HAVE_V4L1
207 static const char *v4l1_ioctls[] = {
208         [_IOC_NR(VIDIOCGCAP)]       = "VIDIOCGCAP",
209         [_IOC_NR(VIDIOCGCHAN)]      = "VIDIOCGCHAN",
210         [_IOC_NR(VIDIOCSCHAN)]      = "VIDIOCSCHAN",
211         [_IOC_NR(VIDIOCGTUNER)]     = "VIDIOCGTUNER",
212         [_IOC_NR(VIDIOCSTUNER)]     = "VIDIOCSTUNER",
213         [_IOC_NR(VIDIOCGPICT)]      = "VIDIOCGPICT",
214         [_IOC_NR(VIDIOCSPICT)]      = "VIDIOCSPICT",
215         [_IOC_NR(VIDIOCCAPTURE)]    = "VIDIOCCAPTURE",
216         [_IOC_NR(VIDIOCGWIN)]       = "VIDIOCGWIN",
217         [_IOC_NR(VIDIOCSWIN)]       = "VIDIOCSWIN",
218         [_IOC_NR(VIDIOCGFBUF)]      = "VIDIOCGFBUF",
219         [_IOC_NR(VIDIOCSFBUF)]      = "VIDIOCSFBUF",
220         [_IOC_NR(VIDIOCKEY)]        = "VIDIOCKEY",
221         [_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
222         [_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
223         [_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
224         [_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
225         [_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
226         [_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
227         [_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
228         [_IOC_NR(VIDIOCGUNIT)]      = "VIDIOCGUNIT",
229         [_IOC_NR(VIDIOCGCAPTURE)]   = "VIDIOCGCAPTURE",
230         [_IOC_NR(VIDIOCSCAPTURE)]   = "VIDIOCSCAPTURE",
231         [_IOC_NR(VIDIOCSPLAYMODE)]  = "VIDIOCSPLAYMODE",
232         [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
233         [_IOC_NR(VIDIOCGPLAYINFO)]  = "VIDIOCGPLAYINFO",
234         [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
235         [_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
236         [_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT"
237 };
238 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
239 #endif
240
241 static const char *v4l2_ioctls[] = {
242         [_IOC_NR(VIDIOC_QUERYCAP)]         = "VIDIOC_QUERYCAP",
243         [_IOC_NR(VIDIOC_RESERVED)]         = "VIDIOC_RESERVED",
244         [_IOC_NR(VIDIOC_ENUM_FMT)]         = "VIDIOC_ENUM_FMT",
245         [_IOC_NR(VIDIOC_G_FMT)]            = "VIDIOC_G_FMT",
246         [_IOC_NR(VIDIOC_S_FMT)]            = "VIDIOC_S_FMT",
247         [_IOC_NR(VIDIOC_G_MPEGCOMP)]       = "VIDIOC_G_MPEGCOMP",
248         [_IOC_NR(VIDIOC_S_MPEGCOMP)]       = "VIDIOC_S_MPEGCOMP",
249         [_IOC_NR(VIDIOC_REQBUFS)]          = "VIDIOC_REQBUFS",
250         [_IOC_NR(VIDIOC_QUERYBUF)]         = "VIDIOC_QUERYBUF",
251         [_IOC_NR(VIDIOC_G_FBUF)]           = "VIDIOC_G_FBUF",
252         [_IOC_NR(VIDIOC_S_FBUF)]           = "VIDIOC_S_FBUF",
253         [_IOC_NR(VIDIOC_OVERLAY)]          = "VIDIOC_OVERLAY",
254         [_IOC_NR(VIDIOC_QBUF)]             = "VIDIOC_QBUF",
255         [_IOC_NR(VIDIOC_DQBUF)]            = "VIDIOC_DQBUF",
256         [_IOC_NR(VIDIOC_STREAMON)]         = "VIDIOC_STREAMON",
257         [_IOC_NR(VIDIOC_STREAMOFF)]        = "VIDIOC_STREAMOFF",
258         [_IOC_NR(VIDIOC_G_PARM)]           = "VIDIOC_G_PARM",
259         [_IOC_NR(VIDIOC_S_PARM)]           = "VIDIOC_S_PARM",
260         [_IOC_NR(VIDIOC_G_STD)]            = "VIDIOC_G_STD",
261         [_IOC_NR(VIDIOC_S_STD)]            = "VIDIOC_S_STD",
262         [_IOC_NR(VIDIOC_ENUMSTD)]          = "VIDIOC_ENUMSTD",
263         [_IOC_NR(VIDIOC_ENUMINPUT)]        = "VIDIOC_ENUMINPUT",
264         [_IOC_NR(VIDIOC_G_CTRL)]           = "VIDIOC_G_CTRL",
265         [_IOC_NR(VIDIOC_S_CTRL)]           = "VIDIOC_S_CTRL",
266         [_IOC_NR(VIDIOC_G_TUNER)]          = "VIDIOC_G_TUNER",
267         [_IOC_NR(VIDIOC_S_TUNER)]          = "VIDIOC_S_TUNER",
268         [_IOC_NR(VIDIOC_G_AUDIO)]          = "VIDIOC_G_AUDIO",
269         [_IOC_NR(VIDIOC_S_AUDIO)]          = "VIDIOC_S_AUDIO",
270         [_IOC_NR(VIDIOC_QUERYCTRL)]        = "VIDIOC_QUERYCTRL",
271         [_IOC_NR(VIDIOC_QUERYMENU)]        = "VIDIOC_QUERYMENU",
272         [_IOC_NR(VIDIOC_G_INPUT)]          = "VIDIOC_G_INPUT",
273         [_IOC_NR(VIDIOC_S_INPUT)]          = "VIDIOC_S_INPUT",
274         [_IOC_NR(VIDIOC_G_OUTPUT)]         = "VIDIOC_G_OUTPUT",
275         [_IOC_NR(VIDIOC_S_OUTPUT)]         = "VIDIOC_S_OUTPUT",
276         [_IOC_NR(VIDIOC_ENUMOUTPUT)]       = "VIDIOC_ENUMOUTPUT",
277         [_IOC_NR(VIDIOC_G_AUDOUT)]         = "VIDIOC_G_AUDOUT",
278         [_IOC_NR(VIDIOC_S_AUDOUT)]         = "VIDIOC_S_AUDOUT",
279         [_IOC_NR(VIDIOC_G_MODULATOR)]      = "VIDIOC_G_MODULATOR",
280         [_IOC_NR(VIDIOC_S_MODULATOR)]      = "VIDIOC_S_MODULATOR",
281         [_IOC_NR(VIDIOC_G_FREQUENCY)]      = "VIDIOC_G_FREQUENCY",
282         [_IOC_NR(VIDIOC_S_FREQUENCY)]      = "VIDIOC_S_FREQUENCY",
283         [_IOC_NR(VIDIOC_CROPCAP)]          = "VIDIOC_CROPCAP",
284         [_IOC_NR(VIDIOC_G_CROP)]           = "VIDIOC_G_CROP",
285         [_IOC_NR(VIDIOC_S_CROP)]           = "VIDIOC_S_CROP",
286         [_IOC_NR(VIDIOC_G_JPEGCOMP)]       = "VIDIOC_G_JPEGCOMP",
287         [_IOC_NR(VIDIOC_S_JPEGCOMP)]       = "VIDIOC_S_JPEGCOMP",
288         [_IOC_NR(VIDIOC_QUERYSTD)]         = "VIDIOC_QUERYSTD",
289         [_IOC_NR(VIDIOC_TRY_FMT)]          = "VIDIOC_TRY_FMT",
290         [_IOC_NR(VIDIOC_ENUMAUDIO)]        = "VIDIOC_ENUMAUDIO",
291         [_IOC_NR(VIDIOC_ENUMAUDOUT)]       = "VIDIOC_ENUMAUDOUT",
292         [_IOC_NR(VIDIOC_G_PRIORITY)]       = "VIDIOC_G_PRIORITY",
293         [_IOC_NR(VIDIOC_S_PRIORITY)]       = "VIDIOC_S_PRIORITY",
294 #if 1
295         [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
296 #endif
297         [_IOC_NR(VIDIOC_LOG_STATUS)]       = "VIDIOC_LOG_STATUS"
298 };
299 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
300
301 static const char *v4l2_int_ioctls[] = {
302 #ifdef HAVE_VIDEO_DECODER
303         [_IOC_NR(DECODER_GET_CAPABILITIES)]    = "DECODER_GET_CAPABILITIES",
304         [_IOC_NR(DECODER_GET_STATUS)]          = "DECODER_GET_STATUS",
305         [_IOC_NR(DECODER_SET_NORM)]            = "DECODER_SET_NORM",
306         [_IOC_NR(DECODER_SET_INPUT)]           = "DECODER_SET_INPUT",
307         [_IOC_NR(DECODER_SET_OUTPUT)]          = "DECODER_SET_OUTPUT",
308         [_IOC_NR(DECODER_ENABLE_OUTPUT)]       = "DECODER_ENABLE_OUTPUT",
309         [_IOC_NR(DECODER_SET_PICTURE)]         = "DECODER_SET_PICTURE",
310         [_IOC_NR(DECODER_SET_GPIO)]            = "DECODER_SET_GPIO",
311         [_IOC_NR(DECODER_INIT)]                = "DECODER_INIT",
312         [_IOC_NR(DECODER_SET_VBI_BYPASS)]      = "DECODER_SET_VBI_BYPASS",
313         [_IOC_NR(DECODER_DUMP)]                = "DECODER_DUMP",
314 #endif
315         [_IOC_NR(AUDC_SET_RADIO)]              = "AUDC_SET_RADIO",
316
317         [_IOC_NR(TUNER_SET_TYPE_ADDR)]         = "TUNER_SET_TYPE_ADDR",
318         [_IOC_NR(TUNER_SET_STANDBY)]           = "TUNER_SET_STANDBY",
319         [_IOC_NR(TDA9887_SET_CONFIG)]          = "TDA9887_SET_CONFIG",
320
321         [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)]     = "VIDIOC_INT_S_TUNER_MODE",
322         [_IOC_NR(VIDIOC_INT_S_REGISTER)]       = "VIDIOC_INT_S_REGISTER",
323         [_IOC_NR(VIDIOC_INT_G_REGISTER)]       = "VIDIOC_INT_G_REGISTER",
324         [_IOC_NR(VIDIOC_INT_RESET)]            = "VIDIOC_INT_RESET",
325         [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
326         [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)]  = "VIDIOC_INT_DECODE_VBI_LINE",
327         [_IOC_NR(VIDIOC_INT_S_VBI_DATA)]       = "VIDIOC_INT_S_VBI_DATA",
328         [_IOC_NR(VIDIOC_INT_G_VBI_DATA)]       = "VIDIOC_INT_G_VBI_DATA",
329         [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)]     = "VIDIOC_INT_G_CHIP_IDENT",
330         [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)]   = "VIDIOC_INT_I2S_CLOCK_FREQ",
331         [_IOC_NR(VIDIOC_INT_S_STANDBY)]        = "VIDIOC_INT_S_STANDBY",
332         [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)]  = "VIDIOC_INT_S_AUDIO_ROUTING",
333         [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)]  = "VIDIOC_INT_G_AUDIO_ROUTING",
334         [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)]  = "VIDIOC_INT_S_VIDEO_ROUTING",
335         [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)]  = "VIDIOC_INT_G_VIDEO_ROUTING",
336         [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)]   = "VIDIOC_INT_S_CRYSTAL_FREQ"
337 };
338 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
339
340 static void v4l_print_pix_fmt (char *s, struct v4l2_pix_format *fmt)
341 {
342         printk ("%s: width=%d, height=%d, format=%d, field=%s, "
343                 "bytesperline=%d sizeimage=%d, colorspace=%d\n", s,
344                 fmt->width,fmt->height,fmt->pixelformat,
345                 prt_names(fmt->field,v4l2_field_names),
346                 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
347 };
348
349 /* Common ioctl debug function. This function can be used by
350    external ioctl messages as well as internal V4L ioctl */
351 void v4l_printk_ioctl(unsigned int cmd)
352 {
353         char *dir;
354
355         switch (_IOC_DIR(cmd)) {
356         case _IOC_NONE:              dir = "--"; break;
357         case _IOC_READ:              dir = "r-"; break;
358         case _IOC_WRITE:             dir = "-w"; break;
359         case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
360         default:                     dir = "*ERR*"; break;
361         }
362         switch (_IOC_TYPE(cmd)) {
363         case 'd':
364                 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n",
365                        (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
366                        v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
367                 break;
368 #ifdef HAVE_V4L1
369         case 'v':
370                 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
371                        (_IOC_NR(cmd) < V4L1_IOCTLS) ?
372                        v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
373                 break;
374 #endif
375         case 'V':
376                 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n",
377                        (_IOC_NR(cmd) < V4L2_IOCTLS) ?
378                        v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
379                 break;
380
381         default:
382                 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n",
383                        _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
384         }
385 }
386
387 /* Common ioctl debug function. This function can be used by
388    external ioctl messages as well as internal V4L ioctl and its
389    arguments */
390 void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
391 {
392         printk(s);
393         printk(": ");
394         v4l_printk_ioctl(cmd);
395         switch (cmd) {
396         case VIDIOC_INT_G_CHIP_IDENT:
397         {
398                 enum v4l2_chip_ident  *p=arg;
399                 printk ("%s: chip ident=%d\n", s, *p);
400                 break;
401         }
402         case VIDIOC_G_PRIORITY:
403         case VIDIOC_S_PRIORITY:
404         {
405                 enum v4l2_priority *p=arg;
406                 printk ("%s: priority=%d\n", s, *p);
407                 break;
408         }
409         case VIDIOC_INT_S_TUNER_MODE:
410         {
411                 enum v4l2_tuner_type *p=arg;
412                 printk ("%s: tuner type=%d\n", s, *p);
413                 break;
414         }
415         case DECODER_SET_VBI_BYPASS:
416         case DECODER_ENABLE_OUTPUT:
417         case DECODER_GET_STATUS:
418         case DECODER_SET_OUTPUT:
419         case DECODER_SET_INPUT:
420         case DECODER_SET_GPIO:
421         case DECODER_SET_NORM:
422         case VIDIOCCAPTURE:
423         case VIDIOCSYNC:
424         case VIDIOCSWRITEMODE:
425         case TUNER_SET_TYPE_ADDR:
426         case TUNER_SET_STANDBY:
427         case TDA9887_SET_CONFIG:
428 #ifdef __OLD_VIDIOC_
429         case VIDIOC_OVERLAY_OLD:
430 #endif
431         case VIDIOC_STREAMOFF:
432         case VIDIOC_G_OUTPUT:
433         case VIDIOC_S_OUTPUT:
434         case VIDIOC_STREAMON:
435         case VIDIOC_G_INPUT:
436         case VIDIOC_OVERLAY:
437         case VIDIOC_S_INPUT:
438         {
439                 int *p=arg;
440                 printk ("%s: value=%d\n", s, *p);
441                 break;
442         }
443         case VIDIOC_G_AUDIO:
444         case VIDIOC_S_AUDIO:
445         case VIDIOC_ENUMAUDIO:
446 #ifdef __OLD_VIDIOC_
447         case VIDIOC_G_AUDIO_OLD:
448 #endif
449         {
450                 struct v4l2_audio *p=arg;
451
452                 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n",
453                         s,p->index, p->name,p->capability, p->mode);
454                 break;
455         }
456         case VIDIOC_G_AUDOUT:
457         case VIDIOC_S_AUDOUT:
458         case VIDIOC_ENUMAUDOUT:
459 #ifdef __OLD_VIDIOC_
460         case VIDIOC_G_AUDOUT_OLD:
461 #endif
462         {
463                 struct v4l2_audioout *p=arg;
464                 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n", s,
465                                 p->index, p->name, p->capability,p->mode);
466                 break;
467         }
468         case VIDIOC_QBUF:
469         case VIDIOC_DQBUF:
470         case VIDIOC_QUERYBUF:
471         {
472                 struct v4l2_buffer *p=arg;
473                 struct v4l2_timecode *tc=&p->timecode;
474                 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
475                         "bytesused=%d, flags=0x%08x, "
476                         "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
477                                 s,
478                                 (p->timestamp.tv_sec/3600),
479                                 (int)(p->timestamp.tv_sec/60)%60,
480                                 (int)(p->timestamp.tv_sec%60),
481                                 p->timestamp.tv_usec,
482                                 p->index,
483                                 prt_names(p->type,v4l2_type_names),
484                                 p->bytesused,p->flags,
485                                 p->field,p->sequence,
486                                 prt_names(p->memory,v4l2_memory_names),
487                                 p->m.userptr);
488                 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
489                         "flags=0x%08x, frames=%d, userbits=0x%p\n",
490                                 s,tc->hours,tc->minutes,tc->seconds,
491                                 tc->type, tc->flags, tc->frames, tc->userbits);
492                 break;
493         }
494         case VIDIOC_QUERYCAP:
495         {
496                 struct v4l2_capability *p=arg;
497                 printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, "
498                         "capabilities=0x%08x\n", s,
499                                 p->driver,p->card,p->bus_info,
500                                 p->version,
501                                 p->capabilities);
502                 break;
503         }
504         case VIDIOC_G_CTRL:
505         case VIDIOC_S_CTRL:
506 #ifdef __OLD_VIDIOC_
507         case VIDIOC_S_CTRL_OLD:
508 #endif
509         {
510                 struct v4l2_control *p=arg;
511                 printk ("%s: id=%d, value=%d\n", s, p->id, p->value);
512                 break;
513         }
514         case VIDIOC_G_CROP:
515         case VIDIOC_S_CROP:
516         {
517                 struct v4l2_crop *p=arg;
518                 /*FIXME: Should also show rect structs */
519                 printk ("%s: type=%d\n", s, p->type);
520                 break;
521         }
522         case VIDIOC_CROPCAP:
523 #ifdef __OLD_VIDIOC_
524         case VIDIOC_CROPCAP_OLD:
525 #endif
526         {
527                 struct v4l2_cropcap *p=arg;
528                 /*FIXME: Should also show rect structs */
529                 printk ("%s: type=%d\n", s, p->type);
530                 break;
531         }
532         case VIDIOC_INT_DECODE_VBI_LINE:
533         {
534                 struct v4l2_decode_vbi_line *p=arg;
535                 printk ("%s: is_second_field=%d, ptr=0x%08lx, line=%d, "
536                         "type=%d\n", s,
537                                 p->is_second_field,(unsigned long)p->p,p->line,p->type);
538                 break;
539         }
540         case VIDIOC_ENUM_FMT:
541         {
542                 struct v4l2_fmtdesc *p=arg;
543                 printk ("%s: index=%d, type=%d, flags=%d, description=%s,"
544                         " pixelformat=%d\n", s,
545                                 p->index, p->type, p->flags,p->description,
546                                 p->pixelformat);
547
548                 break;
549         }
550         case VIDIOC_G_FMT:
551         case VIDIOC_S_FMT:
552         case VIDIOC_TRY_FMT:
553         {
554                 struct v4l2_format *p=arg;
555                 printk ("%s: type=%s\n", s,
556                                 prt_names(p->type,v4l2_type_names));
557                 switch (p->type) {
558                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
559                         v4l_print_pix_fmt (s, &p->fmt.pix);
560                         break;
561                 default:
562                         break;
563                 }
564         }
565         case VIDIOC_G_FBUF:
566         case VIDIOC_S_FBUF:
567         {
568                 struct v4l2_framebuffer *p=arg;
569                 printk ("%s: capability=%d, flags=%d, base=0x%08lx\n", s,
570                                 p->capability,p->flags, (unsigned long)p->base);
571                 v4l_print_pix_fmt (s, &p->fmt);
572                 break;
573         }
574         case VIDIOC_G_FREQUENCY:
575         case VIDIOC_S_FREQUENCY:
576         {
577                 struct v4l2_frequency *p=arg;
578                 printk ("%s: tuner=%d, type=%d, frequency=%d\n", s,
579                                 p->tuner,p->type,p->frequency);
580                 break;
581         }
582         case VIDIOC_ENUMINPUT:
583         {
584                 struct v4l2_input *p=arg;
585                 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
586                         "tuner=%d, std=%Ld, status=%d\n", s,
587                                 p->index,p->name,p->type,p->audioset,
588                                 p->tuner,
589                                 (unsigned long long)p->std,
590                                 p->status);
591                 break;
592         }
593         case VIDIOC_G_JPEGCOMP:
594         case VIDIOC_S_JPEGCOMP:
595         {
596                 struct v4l2_jpegcompression *p=arg;
597                 printk ("%s: quality=%d, APPn=%d, APP_len=%d, COM_len=%d,"
598                         " jpeg_markers=%d\n", s,
599                                 p->quality,p->APPn,p->APP_len,
600                                 p->COM_len,p->jpeg_markers);
601                 break;
602         }
603         case VIDIOC_G_MODULATOR:
604         case VIDIOC_S_MODULATOR:
605         {
606                 struct v4l2_modulator *p=arg;
607                 printk ("%s: index=%d, name=%s, capability=%d, rangelow=%d,"
608                         " rangehigh=%d, txsubchans=%d\n", s,
609                                 p->index, p->name,p->capability,p->rangelow,
610                                 p->rangehigh,p->txsubchans);
611                 break;
612         }
613         case VIDIOC_G_MPEGCOMP:
614         case VIDIOC_S_MPEGCOMP:
615         {
616                 struct v4l2_mpeg_compression *p=arg;
617                 /*FIXME: Several fields not shown */
618                 printk ("%s: ts_pid_pmt=%d, ts_pid_audio=%d, ts_pid_video=%d, "
619                         "ts_pid_pcr=%d, ps_size=%d, au_sample_rate=%d, "
620                         "au_pesid=%c, vi_frame_rate=%d, vi_frames_per_gop=%d, "
621                         "vi_bframes_count=%d, vi_pesid=%c\n", s,
622                                 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
623                                 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
624                                 p->au_pesid, p->vi_frame_rate,
625                                 p->vi_frames_per_gop, p->vi_bframes_count,
626                                 p->vi_pesid);
627                 break;
628         }
629         case VIDIOC_ENUMOUTPUT:
630         {
631                 struct v4l2_output *p=arg;
632                 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
633                         "modulator=%d, std=%Ld\n",
634                                 s,p->index,p->name,p->type,p->audioset,
635                                 p->modulator,
636                                 (unsigned long long)p->std);
637                 break;
638         }
639         case VIDIOC_QUERYCTRL:
640         {
641                 struct v4l2_queryctrl *p=arg;
642                 printk ("%s: id=%d, type=%d, name=%s, min/max=%d/%d,"
643                         " step=%d, default=%d, flags=0x%08x\n", s,
644                                 p->id,p->type,p->name,p->minimum,p->maximum,
645                                 p->step,p->default_value,p->flags);
646                 break;
647         }
648         case VIDIOC_QUERYMENU:
649         {
650                 struct v4l2_querymenu *p=arg;
651                 printk ("%s: id=%d, index=%d, name=%s\n", s,
652                                 p->id,p->index,p->name);
653                 break;
654         }
655         case VIDIOC_INT_G_REGISTER:
656         case VIDIOC_INT_S_REGISTER:
657         {
658                 struct v4l2_register *p=arg;
659                 printk ("%s: i2c_id=%d, reg=%lu, val=%d\n", s,
660                                 p->i2c_id,p->reg,p->val);
661
662                 break;
663         }
664         case VIDIOC_REQBUFS:
665         {
666                 struct v4l2_requestbuffers *p=arg;
667                 printk ("%s: count=%d, type=%s, memory=%s\n", s,
668                                 p->count,
669                                 prt_names(p->type,v4l2_type_names),
670                                 prt_names(p->memory,v4l2_memory_names));
671                 break;
672         }
673         case VIDIOC_INT_S_AUDIO_ROUTING:
674         case VIDIOC_INT_S_VIDEO_ROUTING:
675         case VIDIOC_INT_G_AUDIO_ROUTING:
676         case VIDIOC_INT_G_VIDEO_ROUTING:
677         {
678                 struct v4l2_routing  *p=arg;
679                 printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output);
680                 break;
681         }
682         case VIDIOC_INT_S_CRYSTAL_FREQ:
683         {
684                 struct v4l2_crystal_freq *p=arg;
685                 printk ("%s: freq=%u, flags=0x%x\n", s, p->freq, p->flags);
686                 break;
687         }
688         case VIDIOC_G_SLICED_VBI_CAP:
689         {
690                 struct v4l2_sliced_vbi_cap *p=arg;
691                 printk ("%s: service_set=%d\n", s,
692                                 p->service_set);
693                 break;
694         }
695         case VIDIOC_INT_S_VBI_DATA:
696         case VIDIOC_INT_G_VBI_DATA:
697         {
698                 struct v4l2_sliced_vbi_data  *p=arg;
699                 printk ("%s: id=%d, field=%d, line=%d\n", s,
700                                 p->id, p->field, p->line);
701                 break;
702         }
703         case VIDIOC_ENUMSTD:
704         {
705                 struct v4l2_standard *p=arg;
706                 printk ("%s: index=%d, id=%Ld, name=%s, fps=%d/%d, "
707                         "framelines=%d\n", s, p->index,
708                                 (unsigned long long)p->id, p->name,
709                                 p->frameperiod.numerator,
710                                 p->frameperiod.denominator,
711                                 p->framelines);
712
713                 break;
714         }
715         case VIDIOC_G_PARM:
716         case VIDIOC_S_PARM:
717 #ifdef __OLD_VIDIOC_
718         case VIDIOC_S_PARM_OLD:
719 #endif
720         {
721                 struct v4l2_streamparm *p=arg;
722                 printk ("%s: type=%d\n", s, p->type);
723
724                 break;
725         }
726         case VIDIOC_G_TUNER:
727         case VIDIOC_S_TUNER:
728         {
729                 struct v4l2_tuner *p=arg;
730                 printk ("%s: index=%d, name=%s, type=%d, capability=%d, "
731                         "rangelow=%d, rangehigh=%d, signal=%d, afc=%d, "
732                         "rxsubchans=%d, audmode=%d\n", s,
733                                 p->index, p->name, p->type,
734                                 p->capability, p->rangelow,p->rangehigh,
735                                 p->rxsubchans, p->audmode, p->signal,
736                                 p->afc);
737                 break;
738         }
739         case VIDIOCGVBIFMT:
740         case VIDIOCSVBIFMT:
741         {
742                 struct vbi_format *p=arg;
743                 printk ("%s: sampling_rate=%d, samples_per_line=%d, "
744                         "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", s,
745                                 p->sampling_rate,p->samples_per_line,
746                                 p->sample_format,p->start[0],p->start[1],
747                                 p->count[0],p->count[1],p->flags);
748                 break;
749         }
750         case VIDIOCGAUDIO:
751         case VIDIOCSAUDIO:
752         {
753                 struct video_audio *p=arg;
754                 printk ("%s: audio=%d, volume=%d, bass=%d, treble=%d, "
755                         "flags=%d, name=%s, mode=%d, balance=%d, step=%d\n",
756                                 s,p->audio,p->volume,p->bass, p->treble,
757                                 p->flags,p->name,p->mode,p->balance,p->step);
758                 break;
759         }
760         case VIDIOCGFBUF:
761         case VIDIOCSFBUF:
762         {
763                 struct video_buffer *p=arg;
764                 printk ("%s: base=%08lx, height=%d, width=%d, depth=%d, "
765                         "bytesperline=%d\n", s,
766                                 (unsigned long) p->base, p->height, p->width,
767                                 p->depth,p->bytesperline);
768                 break;
769         }
770         case VIDIOCGCAP:
771         {
772                 struct video_capability *p=arg;
773                 printk ("%s: name=%s, type=%d, channels=%d, audios=%d, "
774                         "maxwidth=%d, maxheight=%d, minwidth=%d, minheight=%d\n",
775                                 s,p->name,p->type,p->channels,p->audios,
776                                 p->maxwidth,p->maxheight,p->minwidth,
777                                 p->minheight);
778
779                 break;
780         }
781         case VIDIOCGCAPTURE:
782         case VIDIOCSCAPTURE:
783         {
784                 struct video_capture *p=arg;
785                 printk ("%s: x=%d, y=%d, width=%d, height=%d, decimation=%d,"
786                         " flags=%d\n", s,
787                                 p->x, p->y,p->width, p->height,
788                                 p->decimation,p->flags);
789                 break;
790         }
791         case VIDIOCGCHAN:
792         case VIDIOCSCHAN:
793         {
794                 struct video_channel *p=arg;
795                 printk ("%s: channel=%d, name=%s, tuners=%d, flags=%d, "
796                         "type=%d, norm=%d\n", s,
797                                 p->channel,p->name,p->tuners,
798                                 p->flags,p->type,p->norm);
799
800                 break;
801         }
802         case VIDIOCSMICROCODE:
803         {
804                 struct video_code *p=arg;
805                 printk ("%s: loadwhat=%s, datasize=%d\n", s,
806                                 p->loadwhat,p->datasize);
807                 break;
808         }
809         case DECODER_GET_CAPABILITIES:
810         {
811                 struct video_decoder_capability *p=arg;
812                 printk ("%s: flags=%d, inputs=%d, outputs=%d\n", s,
813                                 p->flags,p->inputs,p->outputs);
814                 break;
815         }
816         case DECODER_INIT:
817         {
818                 struct video_decoder_init *p=arg;
819                 printk ("%s: len=%c\n", s, p->len);
820                 break;
821         }
822         case VIDIOCGPLAYINFO:
823         {
824                 struct video_info *p=arg;
825                 printk ("%s: frame_count=%d, h_size=%d, v_size=%d, "
826                         "smpte_timecode=%d, picture_type=%d, "
827                         "temporal_reference=%d, user_data=%s\n", s,
828                                 p->frame_count, p->h_size,
829                                 p->v_size, p->smpte_timecode,
830                                 p->picture_type, p->temporal_reference,
831                                 p->user_data);
832                 break;
833         }
834         case VIDIOCKEY:
835         {
836                 struct video_key *p=arg;
837                 printk ("%s: key=%s, flags=%d\n", s,
838                                 p->key, p->flags);
839                 break;
840         }
841         case VIDIOCGMBUF:
842         {
843                 struct video_mbuf *p=arg;
844                 printk ("%s: size=%d, frames=%d, offsets=0x%08lx\n", s,
845                                 p->size,
846                                 p->frames,
847                                 (unsigned long)p->offsets);
848                 break;
849         }
850         case VIDIOCMCAPTURE:
851         {
852                 struct video_mmap *p=arg;
853                 printk ("%s: frame=%d, height=%d, width=%d, format=%d\n", s,
854                                 p->frame,
855                                 p->height, p->width,
856                                 p->format);
857                 break;
858         }
859         case VIDIOCGPICT:
860         case VIDIOCSPICT:
861         case DECODER_SET_PICTURE:
862         {
863                 struct video_picture *p=arg;
864
865                 printk ("%s: brightness=%d, hue=%d, colour=%d, contrast=%d,"
866                         " whiteness=%d, depth=%d, palette=%d\n", s,
867                                 p->brightness, p->hue, p->colour,
868                                 p->contrast, p->whiteness, p->depth,
869                                 p->palette);
870                 break;
871         }
872         case VIDIOCSPLAYMODE:
873         {
874                 struct video_play_mode *p=arg;
875                 printk ("%s: mode=%d, p1=%d, p2=%d\n", s,
876                                 p->mode,p->p1,p->p2);
877                 break;
878         }
879         case VIDIOCGTUNER:
880         case VIDIOCSTUNER:
881         {
882                 struct video_tuner *p=arg;
883                 printk ("%s: tuner=%d, name=%s, rangelow=%ld, rangehigh=%ld, "
884                         "flags=%d, mode=%d, signal=%d\n", s,
885                                 p->tuner, p->name,p->rangelow, p->rangehigh,
886                                 p->flags,p->mode, p->signal);
887                 break;
888         }
889         case VIDIOCGUNIT:
890         {
891                 struct video_unit *p=arg;
892                 printk ("%s: video=%d, vbi=%d, radio=%d, audio=%d, "
893                         "teletext=%d\n", s,
894                                 p->video,p->vbi,p->radio,p->audio,p->teletext);
895                 break;
896         }
897         case VIDIOCGWIN:
898         case VIDIOCSWIN:
899         {
900                 struct video_window *p=arg;
901                 printk ("%s: x=%d, y=%d, width=%d, height=%d, chromakey=%d,"
902                         " flags=%d, clipcount=%d\n", s,
903                                 p->x, p->y,p->width, p->height,
904                                 p->chromakey,p->flags,
905                                 p->clipcount);
906                 break;
907         }
908         case VIDIOC_INT_AUDIO_CLOCK_FREQ:
909         case VIDIOC_INT_I2S_CLOCK_FREQ:
910         case VIDIOC_INT_S_STANDBY:
911         {
912                 u32 *p=arg;
913
914                 printk ("%s: value=%d\n", s, *p);
915                 break;
916         }
917         case VIDIOCGFREQ:
918         case VIDIOCSFREQ:
919         {
920                 unsigned long *p=arg;
921                 printk ("%s: value=%lu\n", s, *p);
922                 break;
923         }
924         case VIDIOC_G_STD:
925         case VIDIOC_S_STD:
926         case VIDIOC_QUERYSTD:
927         {
928                 v4l2_std_id *p=arg;
929
930                 printk ("%s: value=%Lu\n", s, (unsigned long long)*p);
931                 break;
932         }
933         }
934 }
935
936 /* ----------------------------------------------------------------- */
937
938 EXPORT_SYMBOL(v4l2_video_std_construct);
939
940 EXPORT_SYMBOL(v4l2_prio_init);
941 EXPORT_SYMBOL(v4l2_prio_change);
942 EXPORT_SYMBOL(v4l2_prio_open);
943 EXPORT_SYMBOL(v4l2_prio_close);
944 EXPORT_SYMBOL(v4l2_prio_max);
945 EXPORT_SYMBOL(v4l2_prio_check);
946
947 EXPORT_SYMBOL(v4l2_field_names);
948 EXPORT_SYMBOL(v4l2_type_names);
949 EXPORT_SYMBOL(v4l_printk_ioctl);
950 EXPORT_SYMBOL(v4l_printk_ioctl_arg);
951
952 /*
953  * Local variables:
954  * c-basic-offset: 8
955  * End:
956  */