V4L/DVB (8112): videodev: improve extended control support in video_ioctl2()
[pandora-kernel.git] / drivers / media / video / videodev.c
1 /*
2  * Video capture interface for Linux version 2
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 program is free software; you can redistribute it and/or
8  *      modify it under the terms of the GNU General Public License
9  *      as published by the Free Software Foundation; either version
10  *      2 of the License, or (at your option) any later version.
11  *
12  * Authors:     Alan Cox, <alan@redhat.com> (version 1)
13  *              Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
14  *
15  * Fixes:       20000516  Claudio Matsuoka <claudio@conectiva.com>
16  *              - Added procfs support
17  */
18
19 #define dbgarg(cmd, fmt, arg...) \
20                 do {                                                    \
21                     if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {            \
22                         printk(KERN_DEBUG "%s: ",  vfd->name);          \
23                         v4l_printk_ioctl(cmd);                          \
24                         printk(" " fmt,  ## arg);                       \
25                     }                                                   \
26                 } while (0)
27
28 #define dbgarg2(fmt, arg...) \
29                 do {                                                    \
30                     if (vfd->debug & V4L2_DEBUG_IOCTL_ARG)              \
31                         printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
32                 } while (0)
33
34 #include <linux/module.h>
35 #include <linux/types.h>
36 #include <linux/kernel.h>
37 #include <linux/mm.h>
38 #include <linux/string.h>
39 #include <linux/errno.h>
40 #include <linux/init.h>
41 #include <linux/kmod.h>
42 #include <linux/slab.h>
43 #include <linux/smp_lock.h>
44 #include <asm/uaccess.h>
45 #include <asm/system.h>
46
47 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
48 #include <linux/videodev2.h>
49
50 #ifdef CONFIG_VIDEO_V4L1
51 #include <linux/videodev.h>
52 #endif
53 #include <media/v4l2-common.h>
54 #include <linux/video_decoder.h>
55
56 #define VIDEO_NUM_DEVICES       256
57 #define VIDEO_NAME              "video4linux"
58
59 struct std_descr {
60         v4l2_std_id std;
61         const char *descr;
62 };
63
64 static const struct std_descr standards[] = {
65         { V4L2_STD_NTSC,        "NTSC"      },
66         { V4L2_STD_NTSC_M,      "NTSC-M"    },
67         { V4L2_STD_NTSC_M_JP,   "NTSC-M-JP" },
68         { V4L2_STD_NTSC_M_KR,   "NTSC-M-KR" },
69         { V4L2_STD_NTSC_443,    "NTSC-443"  },
70         { V4L2_STD_PAL,         "PAL"       },
71         { V4L2_STD_PAL_BG,      "PAL-BG"    },
72         { V4L2_STD_PAL_B,       "PAL-B"     },
73         { V4L2_STD_PAL_B1,      "PAL-B1"    },
74         { V4L2_STD_PAL_G,       "PAL-G"     },
75         { V4L2_STD_PAL_H,       "PAL-H"     },
76         { V4L2_STD_PAL_I,       "PAL-I"     },
77         { V4L2_STD_PAL_DK,      "PAL-DK"    },
78         { V4L2_STD_PAL_D,       "PAL-D"     },
79         { V4L2_STD_PAL_D1,      "PAL-D1"    },
80         { V4L2_STD_PAL_K,       "PAL-K"     },
81         { V4L2_STD_PAL_M,       "PAL-M"     },
82         { V4L2_STD_PAL_N,       "PAL-N"     },
83         { V4L2_STD_PAL_Nc,      "PAL-Nc"    },
84         { V4L2_STD_PAL_60,      "PAL-60"    },
85         { V4L2_STD_SECAM,       "SECAM"     },
86         { V4L2_STD_SECAM_B,     "SECAM-B"   },
87         { V4L2_STD_SECAM_G,     "SECAM-G"   },
88         { V4L2_STD_SECAM_H,     "SECAM-H"   },
89         { V4L2_STD_SECAM_DK,    "SECAM-DK"  },
90         { V4L2_STD_SECAM_D,     "SECAM-D"   },
91         { V4L2_STD_SECAM_K,     "SECAM-K"   },
92         { V4L2_STD_SECAM_K1,    "SECAM-K1"  },
93         { V4L2_STD_SECAM_L,     "SECAM-L"   },
94         { V4L2_STD_SECAM_LC,    "SECAM-Lc"  },
95         { 0,                    "Unknown"   }
96 };
97
98 /* video4linux standard ID conversion to standard name
99  */
100 const char *v4l2_norm_to_name(v4l2_std_id id)
101 {
102         u32 myid = id;
103         int i;
104
105         /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
106            64 bit comparations. So, on that architecture, with some gcc
107            variants, compilation fails. Currently, the max value is 30bit wide.
108          */
109         BUG_ON(myid != id);
110
111         for (i = 0; standards[i].std; i++)
112                 if (myid == standards[i].std)
113                         break;
114         return standards[i].descr;
115 }
116 EXPORT_SYMBOL(v4l2_norm_to_name);
117
118 /* Fill in the fields of a v4l2_standard structure according to the
119    'id' and 'transmission' parameters.  Returns negative on error.  */
120 int v4l2_video_std_construct(struct v4l2_standard *vs,
121                              int id, const char *name)
122 {
123         u32 index = vs->index;
124
125         memset(vs, 0, sizeof(struct v4l2_standard));
126         vs->index = index;
127         vs->id    = id;
128         if (id & V4L2_STD_525_60) {
129                 vs->frameperiod.numerator = 1001;
130                 vs->frameperiod.denominator = 30000;
131                 vs->framelines = 525;
132         } else {
133                 vs->frameperiod.numerator = 1;
134                 vs->frameperiod.denominator = 25;
135                 vs->framelines = 625;
136         }
137         strlcpy(vs->name, name, sizeof(vs->name));
138         return 0;
139 }
140 EXPORT_SYMBOL(v4l2_video_std_construct);
141
142 /* ----------------------------------------------------------------- */
143 /* some arrays for pretty-printing debug messages of enum types      */
144
145 const char *v4l2_field_names[] = {
146         [V4L2_FIELD_ANY]        = "any",
147         [V4L2_FIELD_NONE]       = "none",
148         [V4L2_FIELD_TOP]        = "top",
149         [V4L2_FIELD_BOTTOM]     = "bottom",
150         [V4L2_FIELD_INTERLACED] = "interlaced",
151         [V4L2_FIELD_SEQ_TB]     = "seq-tb",
152         [V4L2_FIELD_SEQ_BT]     = "seq-bt",
153         [V4L2_FIELD_ALTERNATE]  = "alternate",
154         [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
155         [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
156 };
157 EXPORT_SYMBOL(v4l2_field_names);
158
159 const char *v4l2_type_names[] = {
160         [V4L2_BUF_TYPE_VIDEO_CAPTURE]      = "vid-cap",
161         [V4L2_BUF_TYPE_VIDEO_OVERLAY]      = "vid-overlay",
162         [V4L2_BUF_TYPE_VIDEO_OUTPUT]       = "vid-out",
163         [V4L2_BUF_TYPE_VBI_CAPTURE]        = "vbi-cap",
164         [V4L2_BUF_TYPE_VBI_OUTPUT]         = "vbi-out",
165         [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
166         [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]  = "sliced-vbi-out",
167         [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
168 };
169 EXPORT_SYMBOL(v4l2_type_names);
170
171 static const char *v4l2_memory_names[] = {
172         [V4L2_MEMORY_MMAP]    = "mmap",
173         [V4L2_MEMORY_USERPTR] = "userptr",
174         [V4L2_MEMORY_OVERLAY] = "overlay",
175 };
176
177 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
178                            arr[a] : "unknown")
179
180 /* ------------------------------------------------------------------ */
181 /* debug help functions                                               */
182
183 #ifdef CONFIG_VIDEO_V4L1_COMPAT
184 static const char *v4l1_ioctls[] = {
185         [_IOC_NR(VIDIOCGCAP)]       = "VIDIOCGCAP",
186         [_IOC_NR(VIDIOCGCHAN)]      = "VIDIOCGCHAN",
187         [_IOC_NR(VIDIOCSCHAN)]      = "VIDIOCSCHAN",
188         [_IOC_NR(VIDIOCGTUNER)]     = "VIDIOCGTUNER",
189         [_IOC_NR(VIDIOCSTUNER)]     = "VIDIOCSTUNER",
190         [_IOC_NR(VIDIOCGPICT)]      = "VIDIOCGPICT",
191         [_IOC_NR(VIDIOCSPICT)]      = "VIDIOCSPICT",
192         [_IOC_NR(VIDIOCCAPTURE)]    = "VIDIOCCAPTURE",
193         [_IOC_NR(VIDIOCGWIN)]       = "VIDIOCGWIN",
194         [_IOC_NR(VIDIOCSWIN)]       = "VIDIOCSWIN",
195         [_IOC_NR(VIDIOCGFBUF)]      = "VIDIOCGFBUF",
196         [_IOC_NR(VIDIOCSFBUF)]      = "VIDIOCSFBUF",
197         [_IOC_NR(VIDIOCKEY)]        = "VIDIOCKEY",
198         [_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
199         [_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
200         [_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
201         [_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
202         [_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
203         [_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
204         [_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
205         [_IOC_NR(VIDIOCGUNIT)]      = "VIDIOCGUNIT",
206         [_IOC_NR(VIDIOCGCAPTURE)]   = "VIDIOCGCAPTURE",
207         [_IOC_NR(VIDIOCSCAPTURE)]   = "VIDIOCSCAPTURE",
208         [_IOC_NR(VIDIOCSPLAYMODE)]  = "VIDIOCSPLAYMODE",
209         [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
210         [_IOC_NR(VIDIOCGPLAYINFO)]  = "VIDIOCGPLAYINFO",
211         [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
212         [_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
213         [_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT"
214 };
215 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
216 #endif
217
218 static const char *v4l2_ioctls[] = {
219         [_IOC_NR(VIDIOC_QUERYCAP)]         = "VIDIOC_QUERYCAP",
220         [_IOC_NR(VIDIOC_RESERVED)]         = "VIDIOC_RESERVED",
221         [_IOC_NR(VIDIOC_ENUM_FMT)]         = "VIDIOC_ENUM_FMT",
222         [_IOC_NR(VIDIOC_G_FMT)]            = "VIDIOC_G_FMT",
223         [_IOC_NR(VIDIOC_S_FMT)]            = "VIDIOC_S_FMT",
224         [_IOC_NR(VIDIOC_REQBUFS)]          = "VIDIOC_REQBUFS",
225         [_IOC_NR(VIDIOC_QUERYBUF)]         = "VIDIOC_QUERYBUF",
226         [_IOC_NR(VIDIOC_G_FBUF)]           = "VIDIOC_G_FBUF",
227         [_IOC_NR(VIDIOC_S_FBUF)]           = "VIDIOC_S_FBUF",
228         [_IOC_NR(VIDIOC_OVERLAY)]          = "VIDIOC_OVERLAY",
229         [_IOC_NR(VIDIOC_QBUF)]             = "VIDIOC_QBUF",
230         [_IOC_NR(VIDIOC_DQBUF)]            = "VIDIOC_DQBUF",
231         [_IOC_NR(VIDIOC_STREAMON)]         = "VIDIOC_STREAMON",
232         [_IOC_NR(VIDIOC_STREAMOFF)]        = "VIDIOC_STREAMOFF",
233         [_IOC_NR(VIDIOC_G_PARM)]           = "VIDIOC_G_PARM",
234         [_IOC_NR(VIDIOC_S_PARM)]           = "VIDIOC_S_PARM",
235         [_IOC_NR(VIDIOC_G_STD)]            = "VIDIOC_G_STD",
236         [_IOC_NR(VIDIOC_S_STD)]            = "VIDIOC_S_STD",
237         [_IOC_NR(VIDIOC_ENUMSTD)]          = "VIDIOC_ENUMSTD",
238         [_IOC_NR(VIDIOC_ENUMINPUT)]        = "VIDIOC_ENUMINPUT",
239         [_IOC_NR(VIDIOC_G_CTRL)]           = "VIDIOC_G_CTRL",
240         [_IOC_NR(VIDIOC_S_CTRL)]           = "VIDIOC_S_CTRL",
241         [_IOC_NR(VIDIOC_G_TUNER)]          = "VIDIOC_G_TUNER",
242         [_IOC_NR(VIDIOC_S_TUNER)]          = "VIDIOC_S_TUNER",
243         [_IOC_NR(VIDIOC_G_AUDIO)]          = "VIDIOC_G_AUDIO",
244         [_IOC_NR(VIDIOC_S_AUDIO)]          = "VIDIOC_S_AUDIO",
245         [_IOC_NR(VIDIOC_QUERYCTRL)]        = "VIDIOC_QUERYCTRL",
246         [_IOC_NR(VIDIOC_QUERYMENU)]        = "VIDIOC_QUERYMENU",
247         [_IOC_NR(VIDIOC_G_INPUT)]          = "VIDIOC_G_INPUT",
248         [_IOC_NR(VIDIOC_S_INPUT)]          = "VIDIOC_S_INPUT",
249         [_IOC_NR(VIDIOC_G_OUTPUT)]         = "VIDIOC_G_OUTPUT",
250         [_IOC_NR(VIDIOC_S_OUTPUT)]         = "VIDIOC_S_OUTPUT",
251         [_IOC_NR(VIDIOC_ENUMOUTPUT)]       = "VIDIOC_ENUMOUTPUT",
252         [_IOC_NR(VIDIOC_G_AUDOUT)]         = "VIDIOC_G_AUDOUT",
253         [_IOC_NR(VIDIOC_S_AUDOUT)]         = "VIDIOC_S_AUDOUT",
254         [_IOC_NR(VIDIOC_G_MODULATOR)]      = "VIDIOC_G_MODULATOR",
255         [_IOC_NR(VIDIOC_S_MODULATOR)]      = "VIDIOC_S_MODULATOR",
256         [_IOC_NR(VIDIOC_G_FREQUENCY)]      = "VIDIOC_G_FREQUENCY",
257         [_IOC_NR(VIDIOC_S_FREQUENCY)]      = "VIDIOC_S_FREQUENCY",
258         [_IOC_NR(VIDIOC_CROPCAP)]          = "VIDIOC_CROPCAP",
259         [_IOC_NR(VIDIOC_G_CROP)]           = "VIDIOC_G_CROP",
260         [_IOC_NR(VIDIOC_S_CROP)]           = "VIDIOC_S_CROP",
261         [_IOC_NR(VIDIOC_G_JPEGCOMP)]       = "VIDIOC_G_JPEGCOMP",
262         [_IOC_NR(VIDIOC_S_JPEGCOMP)]       = "VIDIOC_S_JPEGCOMP",
263         [_IOC_NR(VIDIOC_QUERYSTD)]         = "VIDIOC_QUERYSTD",
264         [_IOC_NR(VIDIOC_TRY_FMT)]          = "VIDIOC_TRY_FMT",
265         [_IOC_NR(VIDIOC_ENUMAUDIO)]        = "VIDIOC_ENUMAUDIO",
266         [_IOC_NR(VIDIOC_ENUMAUDOUT)]       = "VIDIOC_ENUMAUDOUT",
267         [_IOC_NR(VIDIOC_G_PRIORITY)]       = "VIDIOC_G_PRIORITY",
268         [_IOC_NR(VIDIOC_S_PRIORITY)]       = "VIDIOC_S_PRIORITY",
269         [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
270         [_IOC_NR(VIDIOC_LOG_STATUS)]       = "VIDIOC_LOG_STATUS",
271         [_IOC_NR(VIDIOC_G_EXT_CTRLS)]      = "VIDIOC_G_EXT_CTRLS",
272         [_IOC_NR(VIDIOC_S_EXT_CTRLS)]      = "VIDIOC_S_EXT_CTRLS",
273         [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)]    = "VIDIOC_TRY_EXT_CTRLS",
274 #if 1
275         [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)]  = "VIDIOC_ENUM_FRAMESIZES",
276         [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
277         [_IOC_NR(VIDIOC_G_ENC_INDEX)]      = "VIDIOC_G_ENC_INDEX",
278         [_IOC_NR(VIDIOC_ENCODER_CMD)]      = "VIDIOC_ENCODER_CMD",
279         [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)]  = "VIDIOC_TRY_ENCODER_CMD",
280
281         [_IOC_NR(VIDIOC_DBG_S_REGISTER)]   = "VIDIOC_DBG_S_REGISTER",
282         [_IOC_NR(VIDIOC_DBG_G_REGISTER)]   = "VIDIOC_DBG_G_REGISTER",
283
284         [_IOC_NR(VIDIOC_G_CHIP_IDENT)]     = "VIDIOC_G_CHIP_IDENT",
285         [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)]   = "VIDIOC_S_HW_FREQ_SEEK",
286 #endif
287 };
288 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
289
290 static const char *v4l2_int_ioctls[] = {
291 #ifdef CONFIG_VIDEO_V4L1_COMPAT
292         [_IOC_NR(DECODER_GET_CAPABILITIES)]    = "DECODER_GET_CAPABILITIES",
293         [_IOC_NR(DECODER_GET_STATUS)]          = "DECODER_GET_STATUS",
294         [_IOC_NR(DECODER_SET_NORM)]            = "DECODER_SET_NORM",
295         [_IOC_NR(DECODER_SET_INPUT)]           = "DECODER_SET_INPUT",
296         [_IOC_NR(DECODER_SET_OUTPUT)]          = "DECODER_SET_OUTPUT",
297         [_IOC_NR(DECODER_ENABLE_OUTPUT)]       = "DECODER_ENABLE_OUTPUT",
298         [_IOC_NR(DECODER_SET_PICTURE)]         = "DECODER_SET_PICTURE",
299         [_IOC_NR(DECODER_SET_GPIO)]            = "DECODER_SET_GPIO",
300         [_IOC_NR(DECODER_INIT)]                = "DECODER_INIT",
301         [_IOC_NR(DECODER_SET_VBI_BYPASS)]      = "DECODER_SET_VBI_BYPASS",
302         [_IOC_NR(DECODER_DUMP)]                = "DECODER_DUMP",
303 #endif
304         [_IOC_NR(AUDC_SET_RADIO)]              = "AUDC_SET_RADIO",
305
306         [_IOC_NR(TUNER_SET_TYPE_ADDR)]         = "TUNER_SET_TYPE_ADDR",
307         [_IOC_NR(TUNER_SET_STANDBY)]           = "TUNER_SET_STANDBY",
308         [_IOC_NR(TUNER_SET_CONFIG)]            = "TUNER_SET_CONFIG",
309
310         [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)]     = "VIDIOC_INT_S_TUNER_MODE",
311         [_IOC_NR(VIDIOC_INT_RESET)]            = "VIDIOC_INT_RESET",
312         [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
313         [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)]  = "VIDIOC_INT_DECODE_VBI_LINE",
314         [_IOC_NR(VIDIOC_INT_S_VBI_DATA)]       = "VIDIOC_INT_S_VBI_DATA",
315         [_IOC_NR(VIDIOC_INT_G_VBI_DATA)]       = "VIDIOC_INT_G_VBI_DATA",
316         [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)]   = "VIDIOC_INT_I2S_CLOCK_FREQ",
317         [_IOC_NR(VIDIOC_INT_S_STANDBY)]        = "VIDIOC_INT_S_STANDBY",
318         [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)]  = "VIDIOC_INT_S_AUDIO_ROUTING",
319         [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)]  = "VIDIOC_INT_G_AUDIO_ROUTING",
320         [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)]  = "VIDIOC_INT_S_VIDEO_ROUTING",
321         [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)]  = "VIDIOC_INT_G_VIDEO_ROUTING",
322         [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)]   = "VIDIOC_INT_S_CRYSTAL_FREQ",
323         [_IOC_NR(VIDIOC_INT_INIT)]             = "VIDIOC_INT_INIT",
324         [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)]     = "VIDIOC_INT_G_STD_OUTPUT",
325         [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)]     = "VIDIOC_INT_S_STD_OUTPUT",
326 };
327 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
328
329 /* Common ioctl debug function. This function can be used by
330    external ioctl messages as well as internal V4L ioctl */
331 void v4l_printk_ioctl(unsigned int cmd)
332 {
333         char *dir, *type;
334
335         switch (_IOC_TYPE(cmd)) {
336         case 'd':
337                 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
338                         type = "v4l2_int";
339                         break;
340                 }
341                 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
342                 return;
343 #ifdef CONFIG_VIDEO_V4L1_COMPAT
344         case 'v':
345                 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
346                         type = "v4l1";
347                         break;
348                 }
349                 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
350                 return;
351 #endif
352         case 'V':
353                 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
354                         type = "v4l2";
355                         break;
356                 }
357                 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
358                 return;
359         default:
360                 type = "unknown";
361         }
362
363         switch (_IOC_DIR(cmd)) {
364         case _IOC_NONE:              dir = "--"; break;
365         case _IOC_READ:              dir = "r-"; break;
366         case _IOC_WRITE:             dir = "-w"; break;
367         case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
368         default:                     dir = "*ERR*"; break;
369         }
370         printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
371                 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
372 }
373 EXPORT_SYMBOL(v4l_printk_ioctl);
374
375 /*
376  *      sysfs stuff
377  */
378
379 static ssize_t show_index(struct device *cd,
380                          struct device_attribute *attr, char *buf)
381 {
382         struct video_device *vfd = container_of(cd, struct video_device,
383                                                 class_dev);
384         return sprintf(buf, "%i\n", vfd->index);
385 }
386
387 static ssize_t show_name(struct device *cd,
388                          struct device_attribute *attr, char *buf)
389 {
390         struct video_device *vfd = container_of(cd, struct video_device,
391                                                 class_dev);
392         return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
393 }
394
395 struct video_device *video_device_alloc(void)
396 {
397         struct video_device *vfd;
398
399         vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
400         return vfd;
401 }
402 EXPORT_SYMBOL(video_device_alloc);
403
404 void video_device_release(struct video_device *vfd)
405 {
406         kfree(vfd);
407 }
408 EXPORT_SYMBOL(video_device_release);
409
410 static void video_release(struct device *cd)
411 {
412         struct video_device *vfd = container_of(cd, struct video_device,
413                                                                 class_dev);
414
415 #if 1
416         /* needed until all drivers are fixed */
417         if (!vfd->release)
418                 return;
419 #endif
420         vfd->release(vfd);
421 }
422
423 static struct device_attribute video_device_attrs[] = {
424         __ATTR(name, S_IRUGO, show_name, NULL),
425         __ATTR(index, S_IRUGO, show_index, NULL),
426         __ATTR_NULL
427 };
428
429 static struct class video_class = {
430         .name    = VIDEO_NAME,
431         .dev_attrs = video_device_attrs,
432         .dev_release = video_release,
433 };
434
435 /*
436  *      Active devices
437  */
438
439 static struct video_device *video_device[VIDEO_NUM_DEVICES];
440 static DEFINE_MUTEX(videodev_lock);
441
442 struct video_device* video_devdata(struct file *file)
443 {
444         return video_device[iminor(file->f_path.dentry->d_inode)];
445 }
446 EXPORT_SYMBOL(video_devdata);
447
448 /*
449  *      Open a video device - FIXME: Obsoleted
450  */
451 static int video_open(struct inode *inode, struct file *file)
452 {
453         unsigned int minor = iminor(inode);
454         int err = 0;
455         struct video_device *vfl;
456         const struct file_operations *old_fops;
457
458         if(minor>=VIDEO_NUM_DEVICES)
459                 return -ENODEV;
460         lock_kernel();
461         mutex_lock(&videodev_lock);
462         vfl=video_device[minor];
463         if(vfl==NULL) {
464                 mutex_unlock(&videodev_lock);
465                 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
466                 mutex_lock(&videodev_lock);
467                 vfl=video_device[minor];
468                 if (vfl==NULL) {
469                         mutex_unlock(&videodev_lock);
470                         unlock_kernel();
471                         return -ENODEV;
472                 }
473         }
474         old_fops = file->f_op;
475         file->f_op = fops_get(vfl->fops);
476         if(file->f_op->open)
477                 err = file->f_op->open(inode,file);
478         if (err) {
479                 fops_put(file->f_op);
480                 file->f_op = fops_get(old_fops);
481         }
482         fops_put(old_fops);
483         mutex_unlock(&videodev_lock);
484         unlock_kernel();
485         return err;
486 }
487
488 /*
489  * helper function -- handles userspace copying for ioctl arguments
490  */
491
492 #ifdef __OLD_VIDIOC_
493 static unsigned int
494 video_fix_command(unsigned int cmd)
495 {
496         switch (cmd) {
497         case VIDIOC_OVERLAY_OLD:
498                 cmd = VIDIOC_OVERLAY;
499                 break;
500         case VIDIOC_S_PARM_OLD:
501                 cmd = VIDIOC_S_PARM;
502                 break;
503         case VIDIOC_S_CTRL_OLD:
504                 cmd = VIDIOC_S_CTRL;
505                 break;
506         case VIDIOC_G_AUDIO_OLD:
507                 cmd = VIDIOC_G_AUDIO;
508                 break;
509         case VIDIOC_G_AUDOUT_OLD:
510                 cmd = VIDIOC_G_AUDOUT;
511                 break;
512         case VIDIOC_CROPCAP_OLD:
513                 cmd = VIDIOC_CROPCAP;
514                 break;
515         }
516         return cmd;
517 }
518 #endif
519
520 /*
521  * Obsolete usercopy function - Should be removed soon
522  */
523 int
524 video_usercopy(struct inode *inode, struct file *file,
525                unsigned int cmd, unsigned long arg,
526                int (*func)(struct inode *inode, struct file *file,
527                            unsigned int cmd, void *arg))
528 {
529         char    sbuf[128];
530         void    *mbuf = NULL;
531         void    *parg = NULL;
532         int     err  = -EINVAL;
533         int     is_ext_ctrl;
534         size_t  ctrls_size = 0;
535         void __user *user_ptr = NULL;
536
537 #ifdef __OLD_VIDIOC_
538         cmd = video_fix_command(cmd);
539 #endif
540         is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
541                        cmd == VIDIOC_TRY_EXT_CTRLS);
542
543         /*  Copy arguments into temp kernel buffer  */
544         switch (_IOC_DIR(cmd)) {
545         case _IOC_NONE:
546                 parg = NULL;
547                 break;
548         case _IOC_READ:
549         case _IOC_WRITE:
550         case (_IOC_WRITE | _IOC_READ):
551                 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
552                         parg = sbuf;
553                 } else {
554                         /* too big to allocate from stack */
555                         mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
556                         if (NULL == mbuf)
557                                 return -ENOMEM;
558                         parg = mbuf;
559                 }
560
561                 err = -EFAULT;
562                 if (_IOC_DIR(cmd) & _IOC_WRITE)
563                         if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
564                                 goto out;
565                 break;
566         }
567         if (is_ext_ctrl) {
568                 struct v4l2_ext_controls *p = parg;
569
570                 /* In case of an error, tell the caller that it wasn't
571                    a specific control that caused it. */
572                 p->error_idx = p->count;
573                 user_ptr = (void __user *)p->controls;
574                 if (p->count) {
575                         ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
576                         /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
577                         mbuf = kmalloc(ctrls_size, GFP_KERNEL);
578                         err = -ENOMEM;
579                         if (NULL == mbuf)
580                                 goto out_ext_ctrl;
581                         err = -EFAULT;
582                         if (copy_from_user(mbuf, user_ptr, ctrls_size))
583                                 goto out_ext_ctrl;
584                         p->controls = mbuf;
585                 }
586         }
587
588         /* call driver */
589         err = func(inode, file, cmd, parg);
590         if (err == -ENOIOCTLCMD)
591                 err = -EINVAL;
592         if (is_ext_ctrl) {
593                 struct v4l2_ext_controls *p = parg;
594
595                 p->controls = (void *)user_ptr;
596                 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
597                         err = -EFAULT;
598                 goto out_ext_ctrl;
599         }
600         if (err < 0)
601                 goto out;
602
603 out_ext_ctrl:
604         /*  Copy results into user buffer  */
605         switch (_IOC_DIR(cmd))
606         {
607         case _IOC_READ:
608         case (_IOC_WRITE | _IOC_READ):
609                 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
610                         err = -EFAULT;
611                 break;
612         }
613
614 out:
615         kfree(mbuf);
616         return err;
617 }
618 EXPORT_SYMBOL(video_usercopy);
619
620 /*
621  * open/release helper functions -- handle exclusive opens
622  * Should be removed soon
623  */
624 int video_exclusive_open(struct inode *inode, struct file *file)
625 {
626         struct  video_device *vfl = video_devdata(file);
627         int retval = 0;
628
629         mutex_lock(&vfl->lock);
630         if (vfl->users) {
631                 retval = -EBUSY;
632         } else {
633                 vfl->users++;
634         }
635         mutex_unlock(&vfl->lock);
636         return retval;
637 }
638 EXPORT_SYMBOL(video_exclusive_open);
639
640 int video_exclusive_release(struct inode *inode, struct file *file)
641 {
642         struct  video_device *vfl = video_devdata(file);
643
644         vfl->users--;
645         return 0;
646 }
647 EXPORT_SYMBOL(video_exclusive_release);
648
649 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
650                                         struct v4l2_buffer *p)
651 {
652         struct v4l2_timecode *tc=&p->timecode;
653
654         dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
655                 "bytesused=%d, flags=0x%08d, "
656                 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
657                         (p->timestamp.tv_sec/3600),
658                         (int)(p->timestamp.tv_sec/60)%60,
659                         (int)(p->timestamp.tv_sec%60),
660                         p->timestamp.tv_usec,
661                         p->index,
662                         prt_names(p->type, v4l2_type_names),
663                         p->bytesused, p->flags,
664                         p->field, p->sequence,
665                         prt_names(p->memory, v4l2_memory_names),
666                         p->m.userptr, p->length);
667         dbgarg2("timecode=%02d:%02d:%02d type=%d, "
668                 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
669                         tc->hours,tc->minutes,tc->seconds,
670                         tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
671 }
672
673 static inline void dbgrect(struct video_device *vfd, char *s,
674                                                         struct v4l2_rect *r)
675 {
676         dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
677                                                 r->width, r->height);
678 };
679
680 static inline void v4l_print_pix_fmt (struct video_device *vfd,
681                                                 struct v4l2_pix_format *fmt)
682 {
683         dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
684                 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
685                 fmt->width,fmt->height,
686                 (fmt->pixelformat & 0xff),
687                 (fmt->pixelformat >>  8) & 0xff,
688                 (fmt->pixelformat >> 16) & 0xff,
689                 (fmt->pixelformat >> 24) & 0xff,
690                 prt_names(fmt->field, v4l2_field_names),
691                 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
692 };
693
694 static inline void v4l_print_ext_ctrls(unsigned int cmd,
695         struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
696 {
697         __u32 i;
698
699         if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
700                 return;
701         dbgarg(cmd, "");
702         printk(KERN_CONT "class=0x%x", c->ctrl_class);
703         for (i = 0; i < c->count; i++) {
704                 if (show_vals)
705                         printk(KERN_CONT " id/val=0x%x/0x%x",
706                                 c->controls[i].id, c->controls[i].value);
707                 else
708                         printk(KERN_CONT " id=0x%x", c->controls[i].id);
709         }
710         printk(KERN_CONT "\n");
711 };
712
713 static inline int check_ext_ctrls(struct v4l2_ext_controls *c)
714 {
715         __u32 i;
716
717         /* zero the reserved fields */
718         c->reserved[0] = c->reserved[1] = 0;
719         for (i = 0; i < c->count; i++) {
720                 c->controls[i].reserved2[0] = 0;
721                 c->controls[i].reserved2[1] = 0;
722         }
723         /* V4L2_CID_PRIVATE_BASE cannot be used as control class
724          * when using extended controls. */
725         if (c->ctrl_class == V4L2_CID_PRIVATE_BASE)
726                 return 0;
727         /* Check that all controls are from the same control class. */
728         for (i = 0; i < c->count; i++) {
729                 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
730                         c->error_idx = i;
731                         return 0;
732                 }
733         }
734         return 1;
735 }
736
737 static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
738 {
739         switch (type) {
740         case V4L2_BUF_TYPE_VIDEO_CAPTURE:
741                 if (vfd->vidioc_try_fmt_vid_cap)
742                         return (0);
743                 break;
744         case V4L2_BUF_TYPE_VIDEO_OVERLAY:
745                 if (vfd->vidioc_try_fmt_vid_overlay)
746                         return (0);
747                 break;
748         case V4L2_BUF_TYPE_VIDEO_OUTPUT:
749                 if (vfd->vidioc_try_fmt_vid_out)
750                         return (0);
751                 break;
752         case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
753                 if (vfd->vidioc_try_fmt_vid_out_overlay)
754                         return (0);
755                 break;
756         case V4L2_BUF_TYPE_VBI_CAPTURE:
757                 if (vfd->vidioc_try_fmt_vbi_cap)
758                         return (0);
759                 break;
760         case V4L2_BUF_TYPE_VBI_OUTPUT:
761                 if (vfd->vidioc_try_fmt_vbi_out)
762                         return (0);
763                 break;
764         case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
765                 if (vfd->vidioc_try_fmt_sliced_vbi_cap)
766                         return (0);
767                 break;
768         case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
769                 if (vfd->vidioc_try_fmt_sliced_vbi_out)
770                         return (0);
771                 break;
772         case V4L2_BUF_TYPE_PRIVATE:
773                 if (vfd->vidioc_try_fmt_type_private)
774                         return (0);
775                 break;
776         }
777         return (-EINVAL);
778 }
779
780 static int __video_do_ioctl(struct inode *inode, struct file *file,
781                 unsigned int cmd, void *arg)
782 {
783         struct video_device *vfd = video_devdata(file);
784         void                 *fh = file->private_data;
785         int                  ret = -EINVAL;
786
787         if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
788                                 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
789                 v4l_print_ioctl(vfd->name, cmd);
790                 printk("\n");
791         }
792
793 #ifdef CONFIG_VIDEO_V4L1_COMPAT
794         /***********************************************************
795          Handles calls to the obsoleted V4L1 API
796          Due to the nature of VIDIOCGMBUF, each driver that supports
797          V4L1 should implement its own handler for this ioctl.
798          ***********************************************************/
799
800         /* --- streaming capture ------------------------------------- */
801         if (cmd == VIDIOCGMBUF) {
802                 struct video_mbuf *p=arg;
803
804                 memset(p, 0, sizeof(*p));
805
806                 if (!vfd->vidiocgmbuf)
807                         return ret;
808                 ret=vfd->vidiocgmbuf(file, fh, p);
809                 if (!ret)
810                         dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
811                                                 p->size, p->frames,
812                                                 (unsigned long)p->offsets);
813                 return ret;
814         }
815
816         /********************************************************
817          All other V4L1 calls are handled by v4l1_compat module.
818          Those calls will be translated into V4L2 calls, and
819          __video_do_ioctl will be called again, with one or more
820          V4L2 ioctls.
821          ********************************************************/
822         if (_IOC_TYPE(cmd)=='v')
823                 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
824                                                 __video_do_ioctl);
825 #endif
826
827         switch(cmd) {
828         /* --- capabilities ------------------------------------------ */
829         case VIDIOC_QUERYCAP:
830         {
831                 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
832                 memset(cap, 0, sizeof(*cap));
833
834                 if (!vfd->vidioc_querycap)
835                         break;
836
837                 ret=vfd->vidioc_querycap(file, fh, cap);
838                 if (!ret)
839                         dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
840                                         "version=0x%08x, "
841                                         "capabilities=0x%08x\n",
842                                         cap->driver,cap->card,cap->bus_info,
843                                         cap->version,
844                                         cap->capabilities);
845                 break;
846         }
847
848         /* --- priority ------------------------------------------ */
849         case VIDIOC_G_PRIORITY:
850         {
851                 enum v4l2_priority *p=arg;
852
853                 if (!vfd->vidioc_g_priority)
854                         break;
855                 ret=vfd->vidioc_g_priority(file, fh, p);
856                 if (!ret)
857                         dbgarg(cmd, "priority is %d\n", *p);
858                 break;
859         }
860         case VIDIOC_S_PRIORITY:
861         {
862                 enum v4l2_priority *p=arg;
863
864                 if (!vfd->vidioc_s_priority)
865                         break;
866                 dbgarg(cmd, "setting priority to %d\n", *p);
867                 ret=vfd->vidioc_s_priority(file, fh, *p);
868                 break;
869         }
870
871         /* --- capture ioctls ---------------------------------------- */
872         case VIDIOC_ENUM_FMT:
873         {
874                 struct v4l2_fmtdesc *f = arg;
875                 enum v4l2_buf_type type;
876                 unsigned int index;
877
878                 index = f->index;
879                 type  = f->type;
880                 memset(f,0,sizeof(*f));
881                 f->index = index;
882                 f->type  = type;
883
884                 switch (type) {
885                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
886                         if (vfd->vidioc_enum_fmt_vid_cap)
887                                 ret = vfd->vidioc_enum_fmt_vid_cap(file, fh, f);
888                         break;
889                 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
890                         if (vfd->vidioc_enum_fmt_vid_overlay)
891                                 ret = vfd->vidioc_enum_fmt_vid_overlay(file,
892                                         fh, f);
893                         break;
894 #if 1
895                 /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
896                  * according to the spec. The bttv and saa7134 drivers support
897                  * it though, so just warn that this is deprecated and will be
898                  * removed in the near future. */
899                 case V4L2_BUF_TYPE_VBI_CAPTURE:
900                         if (vfd->vidioc_enum_fmt_vbi_cap) {
901                                 printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
902                                 ret = vfd->vidioc_enum_fmt_vbi_cap(file, fh, f);
903                         }
904                         break;
905 #endif
906                 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
907                         if (vfd->vidioc_enum_fmt_vid_out)
908                                 ret = vfd->vidioc_enum_fmt_vid_out(file, fh, f);
909                         break;
910                 case V4L2_BUF_TYPE_PRIVATE:
911                         if (vfd->vidioc_enum_fmt_type_private)
912                                 ret = vfd->vidioc_enum_fmt_type_private(file,
913                                                                 fh, f);
914                         break;
915                 default:
916                         break;
917                 }
918                 if (!ret)
919                         dbgarg (cmd, "index=%d, type=%d, flags=%d, "
920                                         "pixelformat=%c%c%c%c, description='%s'\n",
921                                         f->index, f->type, f->flags,
922                                         (f->pixelformat & 0xff),
923                                         (f->pixelformat >>  8) & 0xff,
924                                         (f->pixelformat >> 16) & 0xff,
925                                         (f->pixelformat >> 24) & 0xff,
926                                         f->description);
927                 break;
928         }
929         case VIDIOC_G_FMT:
930         {
931                 struct v4l2_format *f = (struct v4l2_format *)arg;
932
933                 memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
934
935                 /* FIXME: Should be one dump per type */
936                 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
937
938                 switch (f->type) {
939                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
940                         if (vfd->vidioc_g_fmt_vid_cap)
941                                 ret = vfd->vidioc_g_fmt_vid_cap(file, fh, f);
942                         if (!ret)
943                                 v4l_print_pix_fmt(vfd, &f->fmt.pix);
944                         break;
945                 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
946                         if (vfd->vidioc_g_fmt_vid_overlay)
947                                 ret = vfd->vidioc_g_fmt_vid_overlay(file,
948                                                                     fh, f);
949                         break;
950                 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
951                         if (vfd->vidioc_g_fmt_vid_out)
952                                 ret = vfd->vidioc_g_fmt_vid_out(file, fh, f);
953                         if (!ret)
954                                 v4l_print_pix_fmt(vfd, &f->fmt.pix);
955                         break;
956                 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
957                         if (vfd->vidioc_g_fmt_vid_out_overlay)
958                                 ret = vfd->vidioc_g_fmt_vid_out_overlay(file,
959                                        fh, f);
960                         break;
961                 case V4L2_BUF_TYPE_VBI_CAPTURE:
962                         if (vfd->vidioc_g_fmt_vbi_cap)
963                                 ret = vfd->vidioc_g_fmt_vbi_cap(file, fh, f);
964                         break;
965                 case V4L2_BUF_TYPE_VBI_OUTPUT:
966                         if (vfd->vidioc_g_fmt_vbi_out)
967                                 ret = vfd->vidioc_g_fmt_vbi_out(file, fh, f);
968                         break;
969                 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
970                         if (vfd->vidioc_g_fmt_sliced_vbi_cap)
971                                 ret = vfd->vidioc_g_fmt_sliced_vbi_cap(file,
972                                                                         fh, f);
973                         break;
974                 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
975                         if (vfd->vidioc_g_fmt_sliced_vbi_out)
976                                 ret = vfd->vidioc_g_fmt_sliced_vbi_out(file,
977                                                                         fh, f);
978                         break;
979                 case V4L2_BUF_TYPE_PRIVATE:
980                         if (vfd->vidioc_g_fmt_type_private)
981                                 ret = vfd->vidioc_g_fmt_type_private(file,
982                                                                 fh, f);
983                         break;
984                 }
985
986                 break;
987         }
988         case VIDIOC_S_FMT:
989         {
990                 struct v4l2_format *f = (struct v4l2_format *)arg;
991
992                 /* FIXME: Should be one dump per type */
993                 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
994
995                 switch (f->type) {
996                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
997                         v4l_print_pix_fmt(vfd, &f->fmt.pix);
998                         if (vfd->vidioc_s_fmt_vid_cap)
999                                 ret = vfd->vidioc_s_fmt_vid_cap(file, fh, f);
1000                         break;
1001                 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1002                         if (vfd->vidioc_s_fmt_vid_overlay)
1003                                 ret = vfd->vidioc_s_fmt_vid_overlay(file,
1004                                                                     fh, f);
1005                         break;
1006                 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1007                         v4l_print_pix_fmt(vfd, &f->fmt.pix);
1008                         if (vfd->vidioc_s_fmt_vid_out)
1009                                 ret = vfd->vidioc_s_fmt_vid_out(file, fh, f);
1010                         break;
1011                 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1012                         if (vfd->vidioc_s_fmt_vid_out_overlay)
1013                                 ret = vfd->vidioc_s_fmt_vid_out_overlay(file,
1014                                         fh, f);
1015                         break;
1016                 case V4L2_BUF_TYPE_VBI_CAPTURE:
1017                         if (vfd->vidioc_s_fmt_vbi_cap)
1018                                 ret = vfd->vidioc_s_fmt_vbi_cap(file, fh, f);
1019                         break;
1020                 case V4L2_BUF_TYPE_VBI_OUTPUT:
1021                         if (vfd->vidioc_s_fmt_vbi_out)
1022                                 ret = vfd->vidioc_s_fmt_vbi_out(file, fh, f);
1023                         break;
1024                 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1025                         if (vfd->vidioc_s_fmt_sliced_vbi_cap)
1026                                 ret = vfd->vidioc_s_fmt_sliced_vbi_cap(file,
1027                                                                         fh, f);
1028                         break;
1029                 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1030                         if (vfd->vidioc_s_fmt_sliced_vbi_out)
1031                                 ret = vfd->vidioc_s_fmt_sliced_vbi_out(file,
1032                                                                         fh, f);
1033                         break;
1034                 case V4L2_BUF_TYPE_PRIVATE:
1035                         if (vfd->vidioc_s_fmt_type_private)
1036                                 ret = vfd->vidioc_s_fmt_type_private(file,
1037                                                                 fh, f);
1038                         break;
1039                 }
1040                 break;
1041         }
1042         case VIDIOC_TRY_FMT:
1043         {
1044                 struct v4l2_format *f = (struct v4l2_format *)arg;
1045
1046                 /* FIXME: Should be one dump per type */
1047                 dbgarg (cmd, "type=%s\n", prt_names(f->type,
1048                                                 v4l2_type_names));
1049                 switch (f->type) {
1050                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1051                         if (vfd->vidioc_try_fmt_vid_cap)
1052                                 ret = vfd->vidioc_try_fmt_vid_cap(file, fh, f);
1053                         if (!ret)
1054                                 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1055                         break;
1056                 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1057                         if (vfd->vidioc_try_fmt_vid_overlay)
1058                                 ret = vfd->vidioc_try_fmt_vid_overlay(file,
1059                                         fh, f);
1060                         break;
1061                 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1062                         if (vfd->vidioc_try_fmt_vid_out)
1063                                 ret = vfd->vidioc_try_fmt_vid_out(file, fh, f);
1064                         if (!ret)
1065                                 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1066                         break;
1067                 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1068                         if (vfd->vidioc_try_fmt_vid_out_overlay)
1069                                 ret = vfd->vidioc_try_fmt_vid_out_overlay(file,
1070                                        fh, f);
1071                         break;
1072                 case V4L2_BUF_TYPE_VBI_CAPTURE:
1073                         if (vfd->vidioc_try_fmt_vbi_cap)
1074                                 ret = vfd->vidioc_try_fmt_vbi_cap(file, fh, f);
1075                         break;
1076                 case V4L2_BUF_TYPE_VBI_OUTPUT:
1077                         if (vfd->vidioc_try_fmt_vbi_out)
1078                                 ret = vfd->vidioc_try_fmt_vbi_out(file, fh, f);
1079                         break;
1080                 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1081                         if (vfd->vidioc_try_fmt_sliced_vbi_cap)
1082                                 ret = vfd->vidioc_try_fmt_sliced_vbi_cap(file,
1083                                                                 fh, f);
1084                         break;
1085                 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1086                         if (vfd->vidioc_try_fmt_sliced_vbi_out)
1087                                 ret = vfd->vidioc_try_fmt_sliced_vbi_out(file,
1088                                                                 fh, f);
1089                         break;
1090                 case V4L2_BUF_TYPE_PRIVATE:
1091                         if (vfd->vidioc_try_fmt_type_private)
1092                                 ret = vfd->vidioc_try_fmt_type_private(file,
1093                                                                 fh, f);
1094                         break;
1095                 }
1096
1097                 break;
1098         }
1099         /* FIXME: Those buf reqs could be handled here,
1100            with some changes on videobuf to allow its header to be included at
1101            videodev2.h or being merged at videodev2.
1102          */
1103         case VIDIOC_REQBUFS:
1104         {
1105                 struct v4l2_requestbuffers *p=arg;
1106
1107                 if (!vfd->vidioc_reqbufs)
1108                         break;
1109                 ret = check_fmt (vfd, p->type);
1110                 if (ret)
1111                         break;
1112
1113                 ret=vfd->vidioc_reqbufs(file, fh, p);
1114                 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
1115                                 p->count,
1116                                 prt_names(p->type, v4l2_type_names),
1117                                 prt_names(p->memory, v4l2_memory_names));
1118                 break;
1119         }
1120         case VIDIOC_QUERYBUF:
1121         {
1122                 struct v4l2_buffer *p=arg;
1123
1124                 if (!vfd->vidioc_querybuf)
1125                         break;
1126                 ret = check_fmt (vfd, p->type);
1127                 if (ret)
1128                         break;
1129
1130                 ret=vfd->vidioc_querybuf(file, fh, p);
1131                 if (!ret)
1132                         dbgbuf(cmd,vfd,p);
1133                 break;
1134         }
1135         case VIDIOC_QBUF:
1136         {
1137                 struct v4l2_buffer *p=arg;
1138
1139                 if (!vfd->vidioc_qbuf)
1140                         break;
1141                 ret = check_fmt (vfd, p->type);
1142                 if (ret)
1143                         break;
1144
1145                 ret=vfd->vidioc_qbuf(file, fh, p);
1146                 if (!ret)
1147                         dbgbuf(cmd,vfd,p);
1148                 break;
1149         }
1150         case VIDIOC_DQBUF:
1151         {
1152                 struct v4l2_buffer *p=arg;
1153                 if (!vfd->vidioc_dqbuf)
1154                         break;
1155                 ret = check_fmt (vfd, p->type);
1156                 if (ret)
1157                         break;
1158
1159                 ret=vfd->vidioc_dqbuf(file, fh, p);
1160                 if (!ret)
1161                         dbgbuf(cmd,vfd,p);
1162                 break;
1163         }
1164         case VIDIOC_OVERLAY:
1165         {
1166                 int *i = arg;
1167
1168                 if (!vfd->vidioc_overlay)
1169                         break;
1170                 dbgarg (cmd, "value=%d\n",*i);
1171                 ret=vfd->vidioc_overlay(file, fh, *i);
1172                 break;
1173         }
1174         case VIDIOC_G_FBUF:
1175         {
1176                 struct v4l2_framebuffer *p = arg;
1177
1178                 if (!vfd->vidioc_g_fbuf)
1179                         break;
1180                 ret = vfd->vidioc_g_fbuf(file, fh, arg);
1181                 if (!ret) {
1182                         dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1183                                         p->capability, p->flags,
1184                                         (unsigned long)p->base);
1185                         v4l_print_pix_fmt(vfd, &p->fmt);
1186                 }
1187                 break;
1188         }
1189         case VIDIOC_S_FBUF:
1190         {
1191                 struct v4l2_framebuffer *p = arg;
1192
1193                 if (!vfd->vidioc_s_fbuf)
1194                         break;
1195                 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1196                         p->capability, p->flags, (unsigned long)p->base);
1197                 v4l_print_pix_fmt(vfd, &p->fmt);
1198                 ret = vfd->vidioc_s_fbuf(file, fh, arg);
1199                 break;
1200         }
1201         case VIDIOC_STREAMON:
1202         {
1203                 enum v4l2_buf_type i = *(int *)arg;
1204                 if (!vfd->vidioc_streamon)
1205                         break;
1206                 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1207                 ret=vfd->vidioc_streamon(file, fh,i);
1208                 break;
1209         }
1210         case VIDIOC_STREAMOFF:
1211         {
1212                 enum v4l2_buf_type i = *(int *)arg;
1213
1214                 if (!vfd->vidioc_streamoff)
1215                         break;
1216                 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1217                 ret=vfd->vidioc_streamoff(file, fh, i);
1218                 break;
1219         }
1220         /* ---------- tv norms ---------- */
1221         case VIDIOC_ENUMSTD:
1222         {
1223                 struct v4l2_standard *p = arg;
1224                 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1225                 unsigned int index = p->index, i, j = 0;
1226                 const char *descr = "";
1227
1228                 /* Return norm array in a canonical way */
1229                 for (i = 0; i <= index && id; i++) {
1230                         /* last std value in the standards array is 0, so this
1231                            while always ends there since (id & 0) == 0. */
1232                         while ((id & standards[j].std) != standards[j].std)
1233                                 j++;
1234                         curr_id = standards[j].std;
1235                         descr = standards[j].descr;
1236                         j++;
1237                         if (curr_id == 0)
1238                                 break;
1239                         if (curr_id != V4L2_STD_PAL &&
1240                             curr_id != V4L2_STD_SECAM &&
1241                             curr_id != V4L2_STD_NTSC)
1242                                 id &= ~curr_id;
1243                 }
1244                 if (i <= index)
1245                         return -EINVAL;
1246
1247                 v4l2_video_std_construct(p, curr_id, descr);
1248                 p->index = index;
1249
1250                 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1251                                 "framelines=%d\n", p->index,
1252                                 (unsigned long long)p->id, p->name,
1253                                 p->frameperiod.numerator,
1254                                 p->frameperiod.denominator,
1255                                 p->framelines);
1256
1257                 ret = 0;
1258                 break;
1259         }
1260         case VIDIOC_G_STD:
1261         {
1262                 v4l2_std_id *id = arg;
1263
1264                 ret = 0;
1265                 /* Calls the specific handler */
1266                 if (vfd->vidioc_g_std)
1267                         ret = vfd->vidioc_g_std(file, fh, id);
1268                 else
1269                         *id = vfd->current_norm;
1270
1271                 if (!ret)
1272                         dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1273                 break;
1274         }
1275         case VIDIOC_S_STD:
1276         {
1277                 v4l2_std_id *id = arg,norm;
1278
1279                 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1280
1281                 norm = (*id) & vfd->tvnorms;
1282                 if ( vfd->tvnorms && !norm)     /* Check if std is supported */
1283                         break;
1284
1285                 /* Calls the specific handler */
1286                 if (vfd->vidioc_s_std)
1287                         ret=vfd->vidioc_s_std(file, fh, &norm);
1288                 else
1289                         ret=-EINVAL;
1290
1291                 /* Updates standard information */
1292                 if (ret>=0)
1293                         vfd->current_norm=norm;
1294
1295                 break;
1296         }
1297         case VIDIOC_QUERYSTD:
1298         {
1299                 v4l2_std_id *p=arg;
1300
1301                 if (!vfd->vidioc_querystd)
1302                         break;
1303                 ret=vfd->vidioc_querystd(file, fh, arg);
1304                 if (!ret)
1305                         dbgarg (cmd, "detected std=%08Lx\n",
1306                                                 (unsigned long long)*p);
1307                 break;
1308         }
1309         /* ------ input switching ---------- */
1310         /* FIXME: Inputs can be handled inside videodev2 */
1311         case VIDIOC_ENUMINPUT:
1312         {
1313                 struct v4l2_input *p=arg;
1314                 int i=p->index;
1315
1316                 if (!vfd->vidioc_enum_input)
1317                         break;
1318                 memset(p, 0, sizeof(*p));
1319                 p->index=i;
1320
1321                 ret=vfd->vidioc_enum_input(file, fh, p);
1322                 if (!ret)
1323                         dbgarg (cmd, "index=%d, name=%s, type=%d, "
1324                                         "audioset=%d, "
1325                                         "tuner=%d, std=%08Lx, status=%d\n",
1326                                         p->index,p->name,p->type,p->audioset,
1327                                         p->tuner,
1328                                         (unsigned long long)p->std,
1329                                         p->status);
1330                 break;
1331         }
1332         case VIDIOC_G_INPUT:
1333         {
1334                 unsigned int *i = arg;
1335
1336                 if (!vfd->vidioc_g_input)
1337                         break;
1338                 ret=vfd->vidioc_g_input(file, fh, i);
1339                 if (!ret)
1340                         dbgarg (cmd, "value=%d\n",*i);
1341                 break;
1342         }
1343         case VIDIOC_S_INPUT:
1344         {
1345                 unsigned int *i = arg;
1346
1347                 if (!vfd->vidioc_s_input)
1348                         break;
1349                 dbgarg (cmd, "value=%d\n",*i);
1350                 ret=vfd->vidioc_s_input(file, fh, *i);
1351                 break;
1352         }
1353
1354         /* ------ output switching ---------- */
1355         case VIDIOC_ENUMOUTPUT:
1356         {
1357                 struct v4l2_output *p = arg;
1358                 int i = p->index;
1359
1360                 if (!vfd->vidioc_enum_output)
1361                         break;
1362                 memset(p, 0, sizeof(*p));
1363                 p->index = i;
1364
1365                 ret = vfd->vidioc_enum_output(file, fh, p);
1366                 if (!ret)
1367                         dbgarg(cmd, "index=%d, name=%s, type=%d, "
1368                                 "audioset=0x%x, "
1369                                 "modulator=%d, std=0x%08Lx\n",
1370                                 p->index, p->name, p->type, p->audioset,
1371                                 p->modulator, (unsigned long long)p->std);
1372                 break;
1373         }
1374         case VIDIOC_G_OUTPUT:
1375         {
1376                 unsigned int *i = arg;
1377
1378                 if (!vfd->vidioc_g_output)
1379                         break;
1380                 ret=vfd->vidioc_g_output(file, fh, i);
1381                 if (!ret)
1382                         dbgarg (cmd, "value=%d\n",*i);
1383                 break;
1384         }
1385         case VIDIOC_S_OUTPUT:
1386         {
1387                 unsigned int *i = arg;
1388
1389                 if (!vfd->vidioc_s_output)
1390                         break;
1391                 dbgarg (cmd, "value=%d\n",*i);
1392                 ret=vfd->vidioc_s_output(file, fh, *i);
1393                 break;
1394         }
1395
1396         /* --- controls ---------------------------------------------- */
1397         case VIDIOC_QUERYCTRL:
1398         {
1399                 struct v4l2_queryctrl *p = arg;
1400
1401                 if (!vfd->vidioc_queryctrl)
1402                         break;
1403                 ret = vfd->vidioc_queryctrl(file, fh, p);
1404                 if (!ret)
1405                         dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1406                                         "step=%d, default=%d, flags=0x%08x\n",
1407                                         p->id, p->type, p->name,
1408                                         p->minimum, p->maximum,
1409                                         p->step, p->default_value, p->flags);
1410                 else
1411                         dbgarg(cmd, "id=0x%x\n", p->id);
1412                 break;
1413         }
1414         case VIDIOC_G_CTRL:
1415         {
1416                 struct v4l2_control *p = arg;
1417
1418                 if (vfd->vidioc_g_ctrl)
1419                         ret = vfd->vidioc_g_ctrl(file, fh, p);
1420                 else if (vfd->vidioc_g_ext_ctrls) {
1421                         struct v4l2_ext_controls ctrls;
1422                         struct v4l2_ext_control ctrl;
1423
1424                         ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1425                         ctrls.count = 1;
1426                         ctrls.controls = &ctrl;
1427                         ctrl.id = p->id;
1428                         ctrl.value = p->value;
1429                         if (check_ext_ctrls(&ctrls)) {
1430                                 ret = vfd->vidioc_g_ext_ctrls(file, fh, &ctrls);
1431                                 if (ret == 0)
1432                                         p->value = ctrl.value;
1433                         }
1434                 } else
1435                         break;
1436                 if (!ret)
1437                         dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1438                 else
1439                         dbgarg(cmd, "id=0x%x\n", p->id);
1440                 break;
1441         }
1442         case VIDIOC_S_CTRL:
1443         {
1444                 struct v4l2_control *p = arg;
1445                 struct v4l2_ext_controls ctrls;
1446                 struct v4l2_ext_control ctrl;
1447
1448                 if (!vfd->vidioc_s_ctrl && !vfd->vidioc_s_ext_ctrls)
1449                         break;
1450
1451                 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1452
1453                 if (vfd->vidioc_s_ctrl) {
1454                         ret = vfd->vidioc_s_ctrl(file, fh, p);
1455                         break;
1456                 }
1457                 if (!vfd->vidioc_s_ext_ctrls)
1458                         break;
1459
1460                 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1461                 ctrls.count = 1;
1462                 ctrls.controls = &ctrl;
1463                 ctrl.id = p->id;
1464                 ctrl.value = p->value;
1465                 if (check_ext_ctrls(&ctrls))
1466                         ret = vfd->vidioc_s_ext_ctrls(file, fh, &ctrls);
1467                 break;
1468         }
1469         case VIDIOC_G_EXT_CTRLS:
1470         {
1471                 struct v4l2_ext_controls *p = arg;
1472
1473                 p->error_idx = p->count;
1474                 if (!vfd->vidioc_g_ext_ctrls)
1475                         break;
1476                 if (check_ext_ctrls(p))
1477                         ret = vfd->vidioc_g_ext_ctrls(file, fh, p);
1478                 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1479                 break;
1480         }
1481         case VIDIOC_S_EXT_CTRLS:
1482         {
1483                 struct v4l2_ext_controls *p = arg;
1484
1485                 p->error_idx = p->count;
1486                 if (!vfd->vidioc_s_ext_ctrls)
1487                         break;
1488                 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1489                 if (check_ext_ctrls(p))
1490                         ret = vfd->vidioc_s_ext_ctrls(file, fh, p);
1491                 break;
1492         }
1493         case VIDIOC_TRY_EXT_CTRLS:
1494         {
1495                 struct v4l2_ext_controls *p = arg;
1496
1497                 p->error_idx = p->count;
1498                 if (!vfd->vidioc_try_ext_ctrls)
1499                         break;
1500                 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1501                 if (check_ext_ctrls(p))
1502                         ret = vfd->vidioc_try_ext_ctrls(file, fh, p);
1503                 break;
1504         }
1505         case VIDIOC_QUERYMENU:
1506         {
1507                 struct v4l2_querymenu *p = arg;
1508
1509                 if (!vfd->vidioc_querymenu)
1510                         break;
1511                 ret = vfd->vidioc_querymenu(file, fh, p);
1512                 if (!ret)
1513                         dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1514                                 p->id, p->index, p->name);
1515                 else
1516                         dbgarg(cmd, "id=0x%x, index=%d\n",
1517                                 p->id, p->index);
1518                 break;
1519         }
1520         /* --- audio ---------------------------------------------- */
1521         case VIDIOC_ENUMAUDIO:
1522         {
1523                 struct v4l2_audio *p = arg;
1524
1525                 if (!vfd->vidioc_enumaudio)
1526                         break;
1527                 ret = vfd->vidioc_enumaudio(file, fh, p);
1528                 if (!ret)
1529                         dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1530                                         "mode=0x%x\n", p->index, p->name,
1531                                         p->capability, p->mode);
1532                 else
1533                         dbgarg(cmd, "index=%d\n", p->index);
1534                 break;
1535         }
1536         case VIDIOC_G_AUDIO:
1537         {
1538                 struct v4l2_audio *p = arg;
1539                 __u32 index = p->index;
1540
1541                 if (!vfd->vidioc_g_audio)
1542                         break;
1543
1544                 memset(p, 0, sizeof(*p));
1545                 p->index = index;
1546                 ret = vfd->vidioc_g_audio(file, fh, p);
1547                 if (!ret)
1548                         dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1549                                         "mode=0x%x\n", p->index,
1550                                         p->name, p->capability, p->mode);
1551                 else
1552                         dbgarg(cmd, "index=%d\n", p->index);
1553                 break;
1554         }
1555         case VIDIOC_S_AUDIO:
1556         {
1557                 struct v4l2_audio *p = arg;
1558
1559                 if (!vfd->vidioc_s_audio)
1560                         break;
1561                 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1562                                         "mode=0x%x\n", p->index, p->name,
1563                                         p->capability, p->mode);
1564                 ret = vfd->vidioc_s_audio(file, fh, p);
1565                 break;
1566         }
1567         case VIDIOC_ENUMAUDOUT:
1568         {
1569                 struct v4l2_audioout *p=arg;
1570
1571                 if (!vfd->vidioc_enumaudout)
1572                         break;
1573                 dbgarg(cmd, "Enum for index=%d\n", p->index);
1574                 ret=vfd->vidioc_enumaudout(file, fh, p);
1575                 if (!ret)
1576                         dbgarg2("index=%d, name=%s, capability=%d, "
1577                                         "mode=%d\n", p->index, p->name,
1578                                         p->capability,p->mode);
1579                 break;
1580         }
1581         case VIDIOC_G_AUDOUT:
1582         {
1583                 struct v4l2_audioout *p=arg;
1584
1585                 if (!vfd->vidioc_g_audout)
1586                         break;
1587                 dbgarg(cmd, "Enum for index=%d\n", p->index);
1588                 ret=vfd->vidioc_g_audout(file, fh, p);
1589                 if (!ret)
1590                         dbgarg2("index=%d, name=%s, capability=%d, "
1591                                         "mode=%d\n", p->index, p->name,
1592                                         p->capability,p->mode);
1593                 break;
1594         }
1595         case VIDIOC_S_AUDOUT:
1596         {
1597                 struct v4l2_audioout *p=arg;
1598
1599                 if (!vfd->vidioc_s_audout)
1600                         break;
1601                 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1602                                         "mode=%d\n", p->index, p->name,
1603                                         p->capability,p->mode);
1604
1605                 ret=vfd->vidioc_s_audout(file, fh, p);
1606                 break;
1607         }
1608         case VIDIOC_G_MODULATOR:
1609         {
1610                 struct v4l2_modulator *p=arg;
1611                 if (!vfd->vidioc_g_modulator)
1612                         break;
1613                 ret=vfd->vidioc_g_modulator(file, fh, p);
1614                 if (!ret)
1615                         dbgarg(cmd, "index=%d, name=%s, "
1616                                         "capability=%d, rangelow=%d,"
1617                                         " rangehigh=%d, txsubchans=%d\n",
1618                                         p->index, p->name,p->capability,
1619                                         p->rangelow, p->rangehigh,
1620                                         p->txsubchans);
1621                 break;
1622         }
1623         case VIDIOC_S_MODULATOR:
1624         {
1625                 struct v4l2_modulator *p=arg;
1626                 if (!vfd->vidioc_s_modulator)
1627                         break;
1628                 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1629                                 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1630                                 p->index, p->name,p->capability,p->rangelow,
1631                                 p->rangehigh,p->txsubchans);
1632                         ret=vfd->vidioc_s_modulator(file, fh, p);
1633                 break;
1634         }
1635         case VIDIOC_G_CROP:
1636         {
1637                 struct v4l2_crop *p=arg;
1638                 if (!vfd->vidioc_g_crop)
1639                         break;
1640                 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1641                 ret=vfd->vidioc_g_crop(file, fh, p);
1642                 if (!ret) {
1643                         dbgrect(vfd, "", &p->c);
1644                 }
1645                 break;
1646         }
1647         case VIDIOC_S_CROP:
1648         {
1649                 struct v4l2_crop *p=arg;
1650                 if (!vfd->vidioc_s_crop)
1651                         break;
1652                 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1653                 dbgrect(vfd, "", &p->c);
1654                 ret=vfd->vidioc_s_crop(file, fh, p);
1655                 break;
1656         }
1657         case VIDIOC_CROPCAP:
1658         {
1659                 struct v4l2_cropcap *p = arg;
1660
1661                 /*FIXME: Should also show v4l2_fract pixelaspect */
1662                 if (!vfd->vidioc_cropcap)
1663                         break;
1664                 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1665                 ret = vfd->vidioc_cropcap(file, fh, p);
1666                 if (!ret) {
1667                         dbgrect(vfd, "bounds ", &p->bounds);
1668                         dbgrect(vfd, "defrect ", &p->defrect);
1669                 }
1670                 break;
1671         }
1672         case VIDIOC_G_JPEGCOMP:
1673         {
1674                 struct v4l2_jpegcompression *p=arg;
1675                 if (!vfd->vidioc_g_jpegcomp)
1676                         break;
1677                 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1678                 if (!ret)
1679                         dbgarg (cmd, "quality=%d, APPn=%d, "
1680                                                 "APP_len=%d, COM_len=%d, "
1681                                                 "jpeg_markers=%d\n",
1682                                                 p->quality,p->APPn,p->APP_len,
1683                                                 p->COM_len,p->jpeg_markers);
1684                 break;
1685         }
1686         case VIDIOC_S_JPEGCOMP:
1687         {
1688                 struct v4l2_jpegcompression *p=arg;
1689                 if (!vfd->vidioc_g_jpegcomp)
1690                         break;
1691                 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1692                                         "COM_len=%d, jpeg_markers=%d\n",
1693                                         p->quality,p->APPn,p->APP_len,
1694                                         p->COM_len,p->jpeg_markers);
1695                         ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1696                 break;
1697         }
1698         case VIDIOC_G_ENC_INDEX:
1699         {
1700                 struct v4l2_enc_idx *p=arg;
1701
1702                 if (!vfd->vidioc_g_enc_index)
1703                         break;
1704                 ret=vfd->vidioc_g_enc_index(file, fh, p);
1705                 if (!ret)
1706                         dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1707                                         p->entries,p->entries_cap);
1708                 break;
1709         }
1710         case VIDIOC_ENCODER_CMD:
1711         {
1712                 struct v4l2_encoder_cmd *p = arg;
1713
1714                 if (!vfd->vidioc_encoder_cmd)
1715                         break;
1716                 memset(&p->raw, 0, sizeof(p->raw));
1717                 ret = vfd->vidioc_encoder_cmd(file, fh, p);
1718                 if (!ret)
1719                         dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1720                 break;
1721         }
1722         case VIDIOC_TRY_ENCODER_CMD:
1723         {
1724                 struct v4l2_encoder_cmd *p = arg;
1725
1726                 if (!vfd->vidioc_try_encoder_cmd)
1727                         break;
1728                 memset(&p->raw, 0, sizeof(p->raw));
1729                 ret = vfd->vidioc_try_encoder_cmd(file, fh, p);
1730                 if (!ret)
1731                         dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1732                 break;
1733         }
1734         case VIDIOC_G_PARM:
1735         {
1736                 struct v4l2_streamparm *p=arg;
1737                 __u32 type=p->type;
1738
1739                 memset(p,0,sizeof(*p));
1740                 p->type=type;
1741
1742                 if (vfd->vidioc_g_parm) {
1743                         ret=vfd->vidioc_g_parm(file, fh, p);
1744                 } else {
1745                         struct v4l2_standard s;
1746
1747                         if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1748                                 return -EINVAL;
1749
1750                         v4l2_video_std_construct(&s, vfd->current_norm,
1751                                                  v4l2_norm_to_name(vfd->current_norm));
1752
1753                         p->parm.capture.timeperframe = s.frameperiod;
1754                         ret=0;
1755                 }
1756
1757                 dbgarg (cmd, "type=%d\n", p->type);
1758                 break;
1759         }
1760         case VIDIOC_S_PARM:
1761         {
1762                 struct v4l2_streamparm *p=arg;
1763                 if (!vfd->vidioc_s_parm)
1764                         break;
1765                 dbgarg (cmd, "type=%d\n", p->type);
1766                 ret=vfd->vidioc_s_parm(file, fh, p);
1767                 break;
1768         }
1769         case VIDIOC_G_TUNER:
1770         {
1771                 struct v4l2_tuner *p = arg;
1772                 __u32 index = p->index;
1773
1774                 if (!vfd->vidioc_g_tuner)
1775                         break;
1776
1777                 memset(p, 0, sizeof(*p));
1778                 p->index = index;
1779
1780                 ret = vfd->vidioc_g_tuner(file, fh, p);
1781                 if (!ret)
1782                         dbgarg(cmd, "index=%d, name=%s, type=%d, "
1783                                         "capability=0x%x, rangelow=%d, "
1784                                         "rangehigh=%d, signal=%d, afc=%d, "
1785                                         "rxsubchans=0x%x, audmode=%d\n",
1786                                         p->index, p->name, p->type,
1787                                         p->capability, p->rangelow,
1788                                         p->rangehigh, p->signal, p->afc,
1789                                         p->rxsubchans, p->audmode);
1790                 break;
1791         }
1792         case VIDIOC_S_TUNER:
1793         {
1794                 struct v4l2_tuner *p = arg;
1795
1796                 if (!vfd->vidioc_s_tuner)
1797                         break;
1798                 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1799                                 "capability=0x%x, rangelow=%d, "
1800                                 "rangehigh=%d, signal=%d, afc=%d, "
1801                                 "rxsubchans=0x%x, audmode=%d\n",
1802                                 p->index, p->name, p->type,
1803                                 p->capability, p->rangelow,
1804                                 p->rangehigh, p->signal, p->afc,
1805                                 p->rxsubchans, p->audmode);
1806                 ret = vfd->vidioc_s_tuner(file, fh, p);
1807                 break;
1808         }
1809         case VIDIOC_G_FREQUENCY:
1810         {
1811                 struct v4l2_frequency *p = arg;
1812
1813                 if (!vfd->vidioc_g_frequency)
1814                         break;
1815
1816                 memset(p->reserved, 0, sizeof(p->reserved));
1817
1818                 ret = vfd->vidioc_g_frequency(file, fh, p);
1819                 if (!ret)
1820                         dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1821                                         p->tuner, p->type, p->frequency);
1822                 break;
1823         }
1824         case VIDIOC_S_FREQUENCY:
1825         {
1826                 struct v4l2_frequency *p=arg;
1827                 if (!vfd->vidioc_s_frequency)
1828                         break;
1829                 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1830                                 p->tuner,p->type,p->frequency);
1831                 ret=vfd->vidioc_s_frequency(file, fh, p);
1832                 break;
1833         }
1834         case VIDIOC_G_SLICED_VBI_CAP:
1835         {
1836                 struct v4l2_sliced_vbi_cap *p = arg;
1837                 __u32 type = p->type;
1838
1839                 if (!vfd->vidioc_g_sliced_vbi_cap)
1840                         break;
1841                 memset(p, 0, sizeof(*p));
1842                 p->type = type;
1843                 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1844                 ret = vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1845                 if (!ret)
1846                         dbgarg2("service_set=%d\n", p->service_set);
1847                 break;
1848         }
1849         case VIDIOC_LOG_STATUS:
1850         {
1851                 if (!vfd->vidioc_log_status)
1852                         break;
1853                 ret=vfd->vidioc_log_status(file, fh);
1854                 break;
1855         }
1856 #ifdef CONFIG_VIDEO_ADV_DEBUG
1857         case VIDIOC_DBG_G_REGISTER:
1858         {
1859                 struct v4l2_register *p=arg;
1860                 if (!capable(CAP_SYS_ADMIN))
1861                         ret=-EPERM;
1862                 else if (vfd->vidioc_g_register)
1863                         ret=vfd->vidioc_g_register(file, fh, p);
1864                 break;
1865         }
1866         case VIDIOC_DBG_S_REGISTER:
1867         {
1868                 struct v4l2_register *p=arg;
1869                 if (!capable(CAP_SYS_ADMIN))
1870                         ret=-EPERM;
1871                 else if (vfd->vidioc_s_register)
1872                         ret=vfd->vidioc_s_register(file, fh, p);
1873                 break;
1874         }
1875 #endif
1876         case VIDIOC_G_CHIP_IDENT:
1877         {
1878                 struct v4l2_chip_ident *p=arg;
1879                 if (!vfd->vidioc_g_chip_ident)
1880                         break;
1881                 ret=vfd->vidioc_g_chip_ident(file, fh, p);
1882                 if (!ret)
1883                         dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1884                 break;
1885         }
1886         default:
1887         {
1888                 if (!vfd->vidioc_default)
1889                         break;
1890                 ret = vfd->vidioc_default(file, fh, cmd, arg);
1891                 break;
1892         }
1893         case VIDIOC_S_HW_FREQ_SEEK:
1894         {
1895                 struct v4l2_hw_freq_seek *p = arg;
1896                 if (!vfd->vidioc_s_hw_freq_seek)
1897                         break;
1898                 dbgarg(cmd,
1899                         "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1900                         p->tuner, p->type, p->seek_upward, p->wrap_around);
1901                 ret = vfd->vidioc_s_hw_freq_seek(file, fh, p);
1902                 break;
1903         }
1904         } /* switch */
1905
1906         if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1907                 if (ret < 0) {
1908                         v4l_print_ioctl(vfd->name, cmd);
1909                         printk(KERN_CONT " error %d\n", ret);
1910                 }
1911         }
1912
1913         return ret;
1914 }
1915
1916 int video_ioctl2 (struct inode *inode, struct file *file,
1917                unsigned int cmd, unsigned long arg)
1918 {
1919         char    sbuf[128];
1920         void    *mbuf = NULL;
1921         void    *parg = NULL;
1922         int     err  = -EINVAL;
1923         int     is_ext_ctrl;
1924         size_t  ctrls_size = 0;
1925         void __user *user_ptr = NULL;
1926
1927 #ifdef __OLD_VIDIOC_
1928         cmd = video_fix_command(cmd);
1929 #endif
1930         is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1931                        cmd == VIDIOC_TRY_EXT_CTRLS);
1932
1933         /*  Copy arguments into temp kernel buffer  */
1934         switch (_IOC_DIR(cmd)) {
1935         case _IOC_NONE:
1936                 parg = NULL;
1937                 break;
1938         case _IOC_READ:
1939         case _IOC_WRITE:
1940         case (_IOC_WRITE | _IOC_READ):
1941                 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1942                         parg = sbuf;
1943                 } else {
1944                         /* too big to allocate from stack */
1945                         mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1946                         if (NULL == mbuf)
1947                                 return -ENOMEM;
1948                         parg = mbuf;
1949                 }
1950
1951                 err = -EFAULT;
1952                 if (_IOC_DIR(cmd) & _IOC_WRITE)
1953                         if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1954                                 goto out;
1955                 break;
1956         }
1957
1958         if (is_ext_ctrl) {
1959                 struct v4l2_ext_controls *p = parg;
1960
1961                 /* In case of an error, tell the caller that it wasn't
1962                    a specific control that caused it. */
1963                 p->error_idx = p->count;
1964                 user_ptr = (void __user *)p->controls;
1965                 if (p->count) {
1966                         ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1967                         /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1968                         mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1969                         err = -ENOMEM;
1970                         if (NULL == mbuf)
1971                                 goto out_ext_ctrl;
1972                         err = -EFAULT;
1973                         if (copy_from_user(mbuf, user_ptr, ctrls_size))
1974                                 goto out_ext_ctrl;
1975                         p->controls = mbuf;
1976                 }
1977         }
1978
1979         /* Handles IOCTL */
1980         err = __video_do_ioctl(inode, file, cmd, parg);
1981         if (err == -ENOIOCTLCMD)
1982                 err = -EINVAL;
1983         if (is_ext_ctrl) {
1984                 struct v4l2_ext_controls *p = parg;
1985
1986                 p->controls = (void *)user_ptr;
1987                 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1988                         err = -EFAULT;
1989                 goto out_ext_ctrl;
1990         }
1991         if (err < 0)
1992                 goto out;
1993
1994 out_ext_ctrl:
1995         /*  Copy results into user buffer  */
1996         switch (_IOC_DIR(cmd))
1997         {
1998         case _IOC_READ:
1999         case (_IOC_WRITE | _IOC_READ):
2000                 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2001                         err = -EFAULT;
2002                 break;
2003         }
2004
2005 out:
2006         kfree(mbuf);
2007         return err;
2008 }
2009 EXPORT_SYMBOL(video_ioctl2);
2010
2011 struct index_info {
2012         struct device *dev;
2013         unsigned int used[VIDEO_NUM_DEVICES];
2014 };
2015
2016 static int __fill_index_info(struct device *cd, void *data)
2017 {
2018         struct index_info *info = data;
2019         struct video_device *vfd = container_of(cd, struct video_device,
2020                                                 class_dev);
2021
2022         if (info->dev == vfd->dev)
2023                 info->used[vfd->index] = 1;
2024
2025         return 0;
2026 }
2027
2028 /**
2029  * assign_index - assign stream number based on parent device
2030  * @vdev: video_device to assign index number to, vdev->dev should be assigned
2031  * @num: -1 if auto assign, requested number otherwise
2032  *
2033  *
2034  * returns -ENFILE if num is already in use, a free index number if
2035  * successful.
2036  */
2037 static int get_index(struct video_device *vdev, int num)
2038 {
2039         struct index_info *info;
2040         int i;
2041         int ret = 0;
2042
2043         if (num >= VIDEO_NUM_DEVICES)
2044                 return -EINVAL;
2045
2046         info = kzalloc(sizeof(*info), GFP_KERNEL);
2047         if (!info)
2048                 return -ENOMEM;
2049
2050         info->dev = vdev->dev;
2051
2052         ret = class_for_each_device(&video_class, info,
2053                                         __fill_index_info);
2054
2055         if (ret < 0)
2056                 goto out;
2057
2058         if (num >= 0) {
2059                 if (!info->used[num])
2060                         ret = num;
2061                 else
2062                         ret = -ENFILE;
2063
2064                 goto out;
2065         }
2066
2067         for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
2068                 if (info->used[i])
2069                         continue;
2070                 ret = i;
2071                 goto out;
2072         }
2073
2074 out:
2075         kfree(info);
2076         return ret;
2077 }
2078
2079 static const struct file_operations video_fops;
2080
2081 int video_register_device(struct video_device *vfd, int type, int nr)
2082 {
2083         return video_register_device_index(vfd, type, nr, -1);
2084 }
2085 EXPORT_SYMBOL(video_register_device);
2086
2087 /**
2088  *      video_register_device - register video4linux devices
2089  *      @vfd:  video device structure we want to register
2090  *      @type: type of device to register
2091  *      @nr:   which device number (0 == /dev/video0, 1 == /dev/video1, ...
2092  *             -1 == first free)
2093  *
2094  *      The registration code assigns minor numbers based on the type
2095  *      requested. -ENFILE is returned in all the device slots for this
2096  *      category are full. If not then the minor field is set and the
2097  *      driver initialize function is called (if non %NULL).
2098  *
2099  *      Zero is returned on success.
2100  *
2101  *      Valid types are
2102  *
2103  *      %VFL_TYPE_GRABBER - A frame grabber
2104  *
2105  *      %VFL_TYPE_VTX - A teletext device
2106  *
2107  *      %VFL_TYPE_VBI - Vertical blank data (undecoded)
2108  *
2109  *      %VFL_TYPE_RADIO - A radio card
2110  */
2111
2112 int video_register_device_index(struct video_device *vfd, int type, int nr,
2113                                         int index)
2114 {
2115         int i=0;
2116         int base;
2117         int end;
2118         int ret;
2119         char *name_base;
2120
2121         switch(type)
2122         {
2123                 case VFL_TYPE_GRABBER:
2124                         base=MINOR_VFL_TYPE_GRABBER_MIN;
2125                         end=MINOR_VFL_TYPE_GRABBER_MAX+1;
2126                         name_base = "video";
2127                         break;
2128                 case VFL_TYPE_VTX:
2129                         base=MINOR_VFL_TYPE_VTX_MIN;
2130                         end=MINOR_VFL_TYPE_VTX_MAX+1;
2131                         name_base = "vtx";
2132                         break;
2133                 case VFL_TYPE_VBI:
2134                         base=MINOR_VFL_TYPE_VBI_MIN;
2135                         end=MINOR_VFL_TYPE_VBI_MAX+1;
2136                         name_base = "vbi";
2137                         break;
2138                 case VFL_TYPE_RADIO:
2139                         base=MINOR_VFL_TYPE_RADIO_MIN;
2140                         end=MINOR_VFL_TYPE_RADIO_MAX+1;
2141                         name_base = "radio";
2142                         break;
2143                 default:
2144                         printk(KERN_ERR "%s called with unknown type: %d\n",
2145                                __func__, type);
2146                         return -1;
2147         }
2148
2149         /* pick a minor number */
2150         mutex_lock(&videodev_lock);
2151         if (nr >= 0  &&  nr < end-base) {
2152                 /* use the one the driver asked for */
2153                 i = base+nr;
2154                 if (NULL != video_device[i]) {
2155                         mutex_unlock(&videodev_lock);
2156                         return -ENFILE;
2157                 }
2158         } else {
2159                 /* use first free */
2160                 for(i=base;i<end;i++)
2161                         if (NULL == video_device[i])
2162                                 break;
2163                 if (i == end) {
2164                         mutex_unlock(&videodev_lock);
2165                         return -ENFILE;
2166                 }
2167         }
2168         video_device[i]=vfd;
2169         vfd->minor=i;
2170
2171         ret = get_index(vfd, index);
2172         if (ret < 0) {
2173                 printk(KERN_ERR "%s: get_index failed\n",
2174                        __func__);
2175                 goto fail_minor;
2176         }
2177
2178         vfd->index = ret;
2179
2180         mutex_unlock(&videodev_lock);
2181         mutex_init(&vfd->lock);
2182
2183         /* sysfs class */
2184         memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
2185         if (vfd->dev)
2186                 vfd->class_dev.parent = vfd->dev;
2187         vfd->class_dev.class       = &video_class;
2188         vfd->class_dev.devt        = MKDEV(VIDEO_MAJOR, vfd->minor);
2189         sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
2190         ret = device_register(&vfd->class_dev);
2191         if (ret < 0) {
2192                 printk(KERN_ERR "%s: device_register failed\n",
2193                        __func__);
2194                 goto fail_minor;
2195         }
2196
2197 #if 1
2198         /* needed until all drivers are fixed */
2199         if (!vfd->release)
2200                 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
2201                        "Please fix your driver for proper sysfs support, see "
2202                        "http://lwn.net/Articles/36850/\n", vfd->name);
2203 #endif
2204         return 0;
2205
2206 fail_minor:
2207         mutex_lock(&videodev_lock);
2208         video_device[vfd->minor] = NULL;
2209         vfd->minor = -1;
2210         mutex_unlock(&videodev_lock);
2211         return ret;
2212 }
2213 EXPORT_SYMBOL(video_register_device_index);
2214
2215 /**
2216  *      video_unregister_device - unregister a video4linux device
2217  *      @vfd: the device to unregister
2218  *
2219  *      This unregisters the passed device and deassigns the minor
2220  *      number. Future open calls will be met with errors.
2221  */
2222
2223 void video_unregister_device(struct video_device *vfd)
2224 {
2225         mutex_lock(&videodev_lock);
2226         if(video_device[vfd->minor]!=vfd)
2227                 panic("videodev: bad unregister");
2228
2229         video_device[vfd->minor]=NULL;
2230         device_unregister(&vfd->class_dev);
2231         mutex_unlock(&videodev_lock);
2232 }
2233 EXPORT_SYMBOL(video_unregister_device);
2234
2235 /*
2236  * Video fs operations
2237  */
2238 static const struct file_operations video_fops=
2239 {
2240         .owner          = THIS_MODULE,
2241         .llseek         = no_llseek,
2242         .open           = video_open,
2243 };
2244
2245 /*
2246  *      Initialise video for linux
2247  */
2248
2249 static int __init videodev_init(void)
2250 {
2251         int ret;
2252
2253         printk(KERN_INFO "Linux video capture interface: v2.00\n");
2254         if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
2255                 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
2256                 return -EIO;
2257         }
2258
2259         ret = class_register(&video_class);
2260         if (ret < 0) {
2261                 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2262                 printk(KERN_WARNING "video_dev: class_register failed\n");
2263                 return -EIO;
2264         }
2265
2266         return 0;
2267 }
2268
2269 static void __exit videodev_exit(void)
2270 {
2271         class_unregister(&video_class);
2272         unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2273 }
2274
2275 module_init(videodev_init)
2276 module_exit(videodev_exit)
2277
2278 MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
2279 MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
2280 MODULE_LICENSE("GPL");
2281
2282
2283 /*
2284  * Local variables:
2285  * c-basic-offset: 8
2286  * End:
2287  */