2 * Video capture interface for Linux version 2
4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
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.
12 * Authors: Alan Cox, <alan@redhat.com> (version 1)
13 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15 * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
16 * - Added procfs support
19 #define dbgarg(cmd, fmt, arg...) \
20 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
21 printk(KERN_DEBUG "%s: ", vfd->name); \
22 v4l_printk_ioctl(cmd); \
23 printk(" " fmt, ## arg); \
26 #define dbgarg2(fmt, arg...) \
27 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
28 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);
30 #include <linux/module.h>
31 #include <linux/types.h>
32 #include <linux/kernel.h>
34 #include <linux/string.h>
35 #include <linux/errno.h>
36 #include <linux/init.h>
37 #include <linux/kmod.h>
38 #include <linux/slab.h>
39 #include <asm/uaccess.h>
40 #include <asm/system.h>
42 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
43 #include <linux/videodev2.h>
45 #ifdef CONFIG_VIDEO_V4L1
46 #include <linux/videodev.h>
48 #include <media/v4l2-common.h>
49 #include <linux/video_decoder.h>
51 #define VIDEO_NUM_DEVICES 256
52 #define VIDEO_NAME "video4linux"
59 static const struct std_descr standards[] = {
60 { V4L2_STD_NTSC, "NTSC" },
61 { V4L2_STD_NTSC_M, "NTSC-M" },
62 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
63 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
64 { V4L2_STD_NTSC_443, "NTSC-443" },
65 { V4L2_STD_PAL, "PAL" },
66 { V4L2_STD_PAL_BG, "PAL-BG" },
67 { V4L2_STD_PAL_B, "PAL-B" },
68 { V4L2_STD_PAL_B1, "PAL-B1" },
69 { V4L2_STD_PAL_G, "PAL-G" },
70 { V4L2_STD_PAL_H, "PAL-H" },
71 { V4L2_STD_PAL_I, "PAL-I" },
72 { V4L2_STD_PAL_DK, "PAL-DK" },
73 { V4L2_STD_PAL_D, "PAL-D" },
74 { V4L2_STD_PAL_D1, "PAL-D1" },
75 { V4L2_STD_PAL_K, "PAL-K" },
76 { V4L2_STD_PAL_M, "PAL-M" },
77 { V4L2_STD_PAL_N, "PAL-N" },
78 { V4L2_STD_PAL_Nc, "PAL-Nc" },
79 { V4L2_STD_PAL_60, "PAL-60" },
80 { V4L2_STD_SECAM, "SECAM" },
81 { V4L2_STD_SECAM_B, "SECAM-B" },
82 { V4L2_STD_SECAM_G, "SECAM-G" },
83 { V4L2_STD_SECAM_H, "SECAM-H" },
84 { V4L2_STD_SECAM_DK, "SECAM-DK" },
85 { V4L2_STD_SECAM_D, "SECAM-D" },
86 { V4L2_STD_SECAM_K, "SECAM-K" },
87 { V4L2_STD_SECAM_K1, "SECAM-K1" },
88 { V4L2_STD_SECAM_L, "SECAM-L" },
89 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
93 /* video4linux standard ID conversion to standard name
95 const char *v4l2_norm_to_name(v4l2_std_id id)
100 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
101 64 bit comparations. So, on that architecture, with some gcc
102 variants, compilation fails. Currently, the max value is 30bit wide.
106 for (i = 0; standards[i].std; i++)
107 if (myid == standards[i].std)
109 return standards[i].descr;
111 EXPORT_SYMBOL(v4l2_norm_to_name);
113 /* Fill in the fields of a v4l2_standard structure according to the
114 'id' and 'transmission' parameters. Returns negative on error. */
115 int v4l2_video_std_construct(struct v4l2_standard *vs,
116 int id, const char *name)
118 u32 index = vs->index;
120 memset(vs, 0, sizeof(struct v4l2_standard));
123 if (id & V4L2_STD_525_60) {
124 vs->frameperiod.numerator = 1001;
125 vs->frameperiod.denominator = 30000;
126 vs->framelines = 525;
128 vs->frameperiod.numerator = 1;
129 vs->frameperiod.denominator = 25;
130 vs->framelines = 625;
132 strlcpy(vs->name, name, sizeof(vs->name));
135 EXPORT_SYMBOL(v4l2_video_std_construct);
137 /* ----------------------------------------------------------------- */
138 /* some arrays for pretty-printing debug messages of enum types */
140 char *v4l2_field_names[] = {
141 [V4L2_FIELD_ANY] = "any",
142 [V4L2_FIELD_NONE] = "none",
143 [V4L2_FIELD_TOP] = "top",
144 [V4L2_FIELD_BOTTOM] = "bottom",
145 [V4L2_FIELD_INTERLACED] = "interlaced",
146 [V4L2_FIELD_SEQ_TB] = "seq-tb",
147 [V4L2_FIELD_SEQ_BT] = "seq-bt",
148 [V4L2_FIELD_ALTERNATE] = "alternate",
149 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
150 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
152 EXPORT_SYMBOL(v4l2_field_names);
154 char *v4l2_type_names[] = {
155 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
156 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
157 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
158 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
159 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
160 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
161 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
162 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
164 EXPORT_SYMBOL(v4l2_type_names);
166 static char *v4l2_memory_names[] = {
167 [V4L2_MEMORY_MMAP] = "mmap",
168 [V4L2_MEMORY_USERPTR] = "userptr",
169 [V4L2_MEMORY_OVERLAY] = "overlay",
172 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
175 /* ------------------------------------------------------------------ */
176 /* debug help functions */
178 #ifdef CONFIG_VIDEO_V4L1_COMPAT
179 static const char *v4l1_ioctls[] = {
180 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
181 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
182 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
183 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
184 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
185 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
186 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
187 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
188 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
189 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
190 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
191 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
192 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
193 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
194 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
195 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
196 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
197 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
198 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
199 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
200 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
201 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
202 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
203 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
204 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
205 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
206 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
207 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
208 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
210 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
213 static const char *v4l2_ioctls[] = {
214 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
215 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
216 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
217 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
218 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
219 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
220 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
221 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
222 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
223 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
224 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
225 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
226 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
227 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
228 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
229 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
230 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
231 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
232 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
233 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
234 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
235 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
236 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
237 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
238 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
239 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
240 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
241 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
242 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
243 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
244 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
245 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
246 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
247 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
248 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
249 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
250 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
251 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
252 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
253 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
254 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
255 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
256 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
257 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
258 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
259 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
260 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
261 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
262 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
263 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
264 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
265 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
266 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
267 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
268 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
270 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
271 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
272 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
273 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
274 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
276 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
277 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
279 [_IOC_NR(VIDIOC_G_CHIP_IDENT)] = "VIDIOC_G_CHIP_IDENT",
282 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
284 static const char *v4l2_int_ioctls[] = {
285 #ifdef CONFIG_VIDEO_V4L1_COMPAT
286 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
287 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
288 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
289 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
290 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
291 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
292 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
293 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
294 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
295 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
296 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
298 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
300 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
301 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
302 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
304 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
305 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
306 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
307 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
308 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
309 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
310 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
311 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
312 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
313 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
314 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
315 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
316 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
317 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
318 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
319 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
321 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
323 /* Common ioctl debug function. This function can be used by
324 external ioctl messages as well as internal V4L ioctl */
325 void v4l_printk_ioctl(unsigned int cmd)
329 switch (_IOC_TYPE(cmd)) {
331 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
335 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
337 #ifdef CONFIG_VIDEO_V4L1_COMPAT
339 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
343 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
347 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
351 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
357 switch (_IOC_DIR(cmd)) {
358 case _IOC_NONE: dir = "--"; break;
359 case _IOC_READ: dir = "r-"; break;
360 case _IOC_WRITE: dir = "-w"; break;
361 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
362 default: dir = "*ERR*"; break;
364 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
365 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
367 EXPORT_SYMBOL(v4l_printk_ioctl);
373 static ssize_t show_name(struct device *cd,
374 struct device_attribute *attr, char *buf)
376 struct video_device *vfd = container_of(cd, struct video_device,
378 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
381 struct video_device *video_device_alloc(void)
383 struct video_device *vfd;
385 vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
388 EXPORT_SYMBOL(video_device_alloc);
390 void video_device_release(struct video_device *vfd)
394 EXPORT_SYMBOL(video_device_release);
396 static void video_release(struct device *cd)
398 struct video_device *vfd = container_of(cd, struct video_device,
402 /* needed until all drivers are fixed */
409 static struct device_attribute video_device_attrs[] = {
410 __ATTR(name, S_IRUGO, show_name, NULL),
414 static struct class video_class = {
416 .dev_attrs = video_device_attrs,
417 .dev_release = video_release,
424 static struct video_device *video_device[VIDEO_NUM_DEVICES];
425 static DEFINE_MUTEX(videodev_lock);
427 struct video_device* video_devdata(struct file *file)
429 return video_device[iminor(file->f_path.dentry->d_inode)];
431 EXPORT_SYMBOL(video_devdata);
434 * Open a video device - FIXME: Obsoleted
436 static int video_open(struct inode *inode, struct file *file)
438 unsigned int minor = iminor(inode);
440 struct video_device *vfl;
441 const struct file_operations *old_fops;
443 if(minor>=VIDEO_NUM_DEVICES)
445 mutex_lock(&videodev_lock);
446 vfl=video_device[minor];
448 mutex_unlock(&videodev_lock);
449 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
450 mutex_lock(&videodev_lock);
451 vfl=video_device[minor];
453 mutex_unlock(&videodev_lock);
457 old_fops = file->f_op;
458 file->f_op = fops_get(vfl->fops);
460 err = file->f_op->open(inode,file);
462 fops_put(file->f_op);
463 file->f_op = fops_get(old_fops);
466 mutex_unlock(&videodev_lock);
471 * helper function -- handles userspace copying for ioctl arguments
476 video_fix_command(unsigned int cmd)
479 case VIDIOC_OVERLAY_OLD:
480 cmd = VIDIOC_OVERLAY;
482 case VIDIOC_S_PARM_OLD:
485 case VIDIOC_S_CTRL_OLD:
488 case VIDIOC_G_AUDIO_OLD:
489 cmd = VIDIOC_G_AUDIO;
491 case VIDIOC_G_AUDOUT_OLD:
492 cmd = VIDIOC_G_AUDOUT;
494 case VIDIOC_CROPCAP_OLD:
495 cmd = VIDIOC_CROPCAP;
503 * Obsolete usercopy function - Should be removed soon
506 video_usercopy(struct inode *inode, struct file *file,
507 unsigned int cmd, unsigned long arg,
508 int (*func)(struct inode *inode, struct file *file,
509 unsigned int cmd, void *arg))
516 size_t ctrls_size = 0;
517 void __user *user_ptr = NULL;
520 cmd = video_fix_command(cmd);
522 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
523 cmd == VIDIOC_TRY_EXT_CTRLS);
525 /* Copy arguments into temp kernel buffer */
526 switch (_IOC_DIR(cmd)) {
532 case (_IOC_WRITE | _IOC_READ):
533 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
536 /* too big to allocate from stack */
537 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
544 if (_IOC_DIR(cmd) & _IOC_WRITE)
545 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
550 struct v4l2_ext_controls *p = parg;
552 /* In case of an error, tell the caller that it wasn't
553 a specific control that caused it. */
554 p->error_idx = p->count;
555 user_ptr = (void __user *)p->controls;
557 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
558 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
559 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
564 if (copy_from_user(mbuf, user_ptr, ctrls_size))
571 err = func(inode, file, cmd, parg);
572 if (err == -ENOIOCTLCMD)
575 struct v4l2_ext_controls *p = parg;
577 p->controls = (void *)user_ptr;
578 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
586 /* Copy results into user buffer */
587 switch (_IOC_DIR(cmd))
590 case (_IOC_WRITE | _IOC_READ):
591 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
600 EXPORT_SYMBOL(video_usercopy);
603 * open/release helper functions -- handle exclusive opens
604 * Should be removed soon
606 int video_exclusive_open(struct inode *inode, struct file *file)
608 struct video_device *vfl = video_devdata(file);
611 mutex_lock(&vfl->lock);
617 mutex_unlock(&vfl->lock);
620 EXPORT_SYMBOL(video_exclusive_open);
622 int video_exclusive_release(struct inode *inode, struct file *file)
624 struct video_device *vfl = video_devdata(file);
629 EXPORT_SYMBOL(video_exclusive_release);
631 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
632 struct v4l2_buffer *p)
634 struct v4l2_timecode *tc=&p->timecode;
636 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
637 "bytesused=%d, flags=0x%08d, "
638 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
639 (p->timestamp.tv_sec/3600),
640 (int)(p->timestamp.tv_sec/60)%60,
641 (int)(p->timestamp.tv_sec%60),
642 p->timestamp.tv_usec,
644 prt_names(p->type, v4l2_type_names),
645 p->bytesused, p->flags,
646 p->field, p->sequence,
647 prt_names(p->memory, v4l2_memory_names),
648 p->m.userptr, p->length);
649 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
650 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
651 tc->hours,tc->minutes,tc->seconds,
652 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
655 static inline void dbgrect(struct video_device *vfd, char *s,
658 dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
659 r->width, r->height);
662 static inline void v4l_print_pix_fmt (struct video_device *vfd,
663 struct v4l2_pix_format *fmt)
665 dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
666 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
667 fmt->width,fmt->height,
668 (fmt->pixelformat & 0xff),
669 (fmt->pixelformat >> 8) & 0xff,
670 (fmt->pixelformat >> 16) & 0xff,
671 (fmt->pixelformat >> 24) & 0xff,
672 prt_names(fmt->field, v4l2_field_names),
673 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
677 static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
680 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
681 if (vfd->vidioc_try_fmt_cap)
684 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
685 if (vfd->vidioc_try_fmt_overlay)
688 case V4L2_BUF_TYPE_VBI_CAPTURE:
689 if (vfd->vidioc_try_fmt_vbi)
692 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
693 if (vfd->vidioc_try_fmt_vbi_output)
696 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
697 if (vfd->vidioc_try_fmt_vbi_capture)
700 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
701 if (vfd->vidioc_try_fmt_video_output)
704 case V4L2_BUF_TYPE_VBI_OUTPUT:
705 if (vfd->vidioc_try_fmt_vbi_output)
708 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
709 if (vfd->vidioc_try_fmt_output_overlay)
712 case V4L2_BUF_TYPE_PRIVATE:
713 if (vfd->vidioc_try_fmt_type_private)
720 static int __video_do_ioctl(struct inode *inode, struct file *file,
721 unsigned int cmd, void *arg)
723 struct video_device *vfd = video_devdata(file);
724 void *fh = file->private_data;
727 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
728 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
729 v4l_print_ioctl(vfd->name, cmd);
733 #ifdef CONFIG_VIDEO_V4L1_COMPAT
734 /***********************************************************
735 Handles calls to the obsoleted V4L1 API
736 Due to the nature of VIDIOCGMBUF, each driver that supports
737 V4L1 should implement its own handler for this ioctl.
738 ***********************************************************/
740 /* --- streaming capture ------------------------------------- */
741 if (cmd == VIDIOCGMBUF) {
742 struct video_mbuf *p=arg;
744 memset(p, 0, sizeof(*p));
746 if (!vfd->vidiocgmbuf)
748 ret=vfd->vidiocgmbuf(file, fh, p);
750 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
752 (unsigned long)p->offsets);
756 /********************************************************
757 All other V4L1 calls are handled by v4l1_compat module.
758 Those calls will be translated into V4L2 calls, and
759 __video_do_ioctl will be called again, with one or more
761 ********************************************************/
762 if (_IOC_TYPE(cmd)=='v')
763 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
768 /* --- capabilities ------------------------------------------ */
769 case VIDIOC_QUERYCAP:
771 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
772 memset(cap, 0, sizeof(*cap));
774 if (!vfd->vidioc_querycap)
777 ret=vfd->vidioc_querycap(file, fh, cap);
779 dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
781 "capabilities=0x%08x\n",
782 cap->driver,cap->card,cap->bus_info,
788 /* --- priority ------------------------------------------ */
789 case VIDIOC_G_PRIORITY:
791 enum v4l2_priority *p=arg;
793 if (!vfd->vidioc_g_priority)
795 ret=vfd->vidioc_g_priority(file, fh, p);
797 dbgarg(cmd, "priority is %d\n", *p);
800 case VIDIOC_S_PRIORITY:
802 enum v4l2_priority *p=arg;
804 if (!vfd->vidioc_s_priority)
806 dbgarg(cmd, "setting priority to %d\n", *p);
807 ret=vfd->vidioc_s_priority(file, fh, *p);
811 /* --- capture ioctls ---------------------------------------- */
812 case VIDIOC_ENUM_FMT:
814 struct v4l2_fmtdesc *f = arg;
815 enum v4l2_buf_type type;
820 memset(f,0,sizeof(*f));
825 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
826 if (vfd->vidioc_enum_fmt_cap)
827 ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
829 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
830 if (vfd->vidioc_enum_fmt_overlay)
831 ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
833 case V4L2_BUF_TYPE_VBI_CAPTURE:
834 if (vfd->vidioc_enum_fmt_vbi)
835 ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
837 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
838 if (vfd->vidioc_enum_fmt_vbi_output)
839 ret=vfd->vidioc_enum_fmt_vbi_output(file,
842 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
843 if (vfd->vidioc_enum_fmt_vbi_capture)
844 ret=vfd->vidioc_enum_fmt_vbi_capture(file,
847 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
848 if (vfd->vidioc_enum_fmt_video_output)
849 ret=vfd->vidioc_enum_fmt_video_output(file,
852 case V4L2_BUF_TYPE_VBI_OUTPUT:
853 if (vfd->vidioc_enum_fmt_vbi_output)
854 ret=vfd->vidioc_enum_fmt_vbi_output(file,
857 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
858 if (vfd->vidioc_enum_fmt_output_overlay)
859 ret=vfd->vidioc_enum_fmt_output_overlay(file, fh, f);
861 case V4L2_BUF_TYPE_PRIVATE:
862 if (vfd->vidioc_enum_fmt_type_private)
863 ret=vfd->vidioc_enum_fmt_type_private(file,
868 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
869 "pixelformat=%c%c%c%c, description='%s'\n",
870 f->index, f->type, f->flags,
871 (f->pixelformat & 0xff),
872 (f->pixelformat >> 8) & 0xff,
873 (f->pixelformat >> 16) & 0xff,
874 (f->pixelformat >> 24) & 0xff,
880 struct v4l2_format *f = (struct v4l2_format *)arg;
881 enum v4l2_buf_type type=f->type;
883 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
886 /* FIXME: Should be one dump per type */
887 dbgarg (cmd, "type=%s\n", prt_names(type,
891 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
892 if (vfd->vidioc_g_fmt_cap)
893 ret=vfd->vidioc_g_fmt_cap(file, fh, f);
895 v4l_print_pix_fmt(vfd,&f->fmt.pix);
897 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
898 if (vfd->vidioc_g_fmt_overlay)
899 ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
901 case V4L2_BUF_TYPE_VBI_CAPTURE:
902 if (vfd->vidioc_g_fmt_vbi)
903 ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
905 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
906 if (vfd->vidioc_g_fmt_vbi_output)
907 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
909 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
910 if (vfd->vidioc_g_fmt_vbi_capture)
911 ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
913 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
914 if (vfd->vidioc_g_fmt_video_output)
915 ret=vfd->vidioc_g_fmt_video_output(file,
918 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
919 if (vfd->vidioc_g_fmt_output_overlay)
920 ret=vfd->vidioc_g_fmt_output_overlay(file, fh, f);
922 case V4L2_BUF_TYPE_VBI_OUTPUT:
923 if (vfd->vidioc_g_fmt_vbi_output)
924 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
926 case V4L2_BUF_TYPE_PRIVATE:
927 if (vfd->vidioc_g_fmt_type_private)
928 ret=vfd->vidioc_g_fmt_type_private(file,
937 struct v4l2_format *f = (struct v4l2_format *)arg;
939 /* FIXME: Should be one dump per type */
940 dbgarg (cmd, "type=%s\n", prt_names(f->type,
944 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
945 v4l_print_pix_fmt(vfd,&f->fmt.pix);
946 if (vfd->vidioc_s_fmt_cap)
947 ret=vfd->vidioc_s_fmt_cap(file, fh, f);
949 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
950 if (vfd->vidioc_s_fmt_overlay)
951 ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
953 case V4L2_BUF_TYPE_VBI_CAPTURE:
954 if (vfd->vidioc_s_fmt_vbi)
955 ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
957 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
958 if (vfd->vidioc_s_fmt_vbi_output)
959 ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
961 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
962 if (vfd->vidioc_s_fmt_vbi_capture)
963 ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
965 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
966 if (vfd->vidioc_s_fmt_video_output)
967 ret=vfd->vidioc_s_fmt_video_output(file,
970 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
971 if (vfd->vidioc_s_fmt_output_overlay)
972 ret=vfd->vidioc_s_fmt_output_overlay(file, fh, f);
974 case V4L2_BUF_TYPE_VBI_OUTPUT:
975 if (vfd->vidioc_s_fmt_vbi_output)
976 ret=vfd->vidioc_s_fmt_vbi_output(file,
979 case V4L2_BUF_TYPE_PRIVATE:
980 if (vfd->vidioc_s_fmt_type_private)
981 ret=vfd->vidioc_s_fmt_type_private(file,
989 struct v4l2_format *f = (struct v4l2_format *)arg;
991 /* FIXME: Should be one dump per type */
992 dbgarg (cmd, "type=%s\n", prt_names(f->type,
995 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
996 if (vfd->vidioc_try_fmt_cap)
997 ret=vfd->vidioc_try_fmt_cap(file, fh, f);
999 v4l_print_pix_fmt(vfd,&f->fmt.pix);
1001 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1002 if (vfd->vidioc_try_fmt_overlay)
1003 ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
1005 case V4L2_BUF_TYPE_VBI_CAPTURE:
1006 if (vfd->vidioc_try_fmt_vbi)
1007 ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
1009 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1010 if (vfd->vidioc_try_fmt_vbi_output)
1011 ret=vfd->vidioc_try_fmt_vbi_output(file,
1014 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1015 if (vfd->vidioc_try_fmt_vbi_capture)
1016 ret=vfd->vidioc_try_fmt_vbi_capture(file,
1019 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1020 if (vfd->vidioc_try_fmt_video_output)
1021 ret=vfd->vidioc_try_fmt_video_output(file,
1024 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1025 if (vfd->vidioc_try_fmt_output_overlay)
1026 ret=vfd->vidioc_try_fmt_output_overlay(file, fh, f);
1028 case V4L2_BUF_TYPE_VBI_OUTPUT:
1029 if (vfd->vidioc_try_fmt_vbi_output)
1030 ret=vfd->vidioc_try_fmt_vbi_output(file,
1033 case V4L2_BUF_TYPE_PRIVATE:
1034 if (vfd->vidioc_try_fmt_type_private)
1035 ret=vfd->vidioc_try_fmt_type_private(file,
1042 /* FIXME: Those buf reqs could be handled here,
1043 with some changes on videobuf to allow its header to be included at
1044 videodev2.h or being merged at videodev2.
1046 case VIDIOC_REQBUFS:
1048 struct v4l2_requestbuffers *p=arg;
1050 if (!vfd->vidioc_reqbufs)
1052 ret = check_fmt (vfd, p->type);
1056 ret=vfd->vidioc_reqbufs(file, fh, p);
1057 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
1059 prt_names(p->type, v4l2_type_names),
1060 prt_names(p->memory, v4l2_memory_names));
1063 case VIDIOC_QUERYBUF:
1065 struct v4l2_buffer *p=arg;
1067 if (!vfd->vidioc_querybuf)
1069 ret = check_fmt (vfd, p->type);
1073 ret=vfd->vidioc_querybuf(file, fh, p);
1080 struct v4l2_buffer *p=arg;
1082 if (!vfd->vidioc_qbuf)
1084 ret = check_fmt (vfd, p->type);
1088 ret=vfd->vidioc_qbuf(file, fh, p);
1095 struct v4l2_buffer *p=arg;
1096 if (!vfd->vidioc_dqbuf)
1098 ret = check_fmt (vfd, p->type);
1102 ret=vfd->vidioc_dqbuf(file, fh, p);
1107 case VIDIOC_OVERLAY:
1111 if (!vfd->vidioc_overlay)
1113 dbgarg (cmd, "value=%d\n",*i);
1114 ret=vfd->vidioc_overlay(file, fh, *i);
1119 struct v4l2_framebuffer *p=arg;
1120 if (!vfd->vidioc_g_fbuf)
1122 ret=vfd->vidioc_g_fbuf(file, fh, arg);
1124 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
1125 p->capability,p->flags,
1126 (unsigned long)p->base);
1127 v4l_print_pix_fmt (vfd, &p->fmt);
1133 struct v4l2_framebuffer *p=arg;
1134 if (!vfd->vidioc_s_fbuf)
1137 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
1138 p->capability,p->flags,(unsigned long)p->base);
1139 v4l_print_pix_fmt (vfd, &p->fmt);
1140 ret=vfd->vidioc_s_fbuf(file, fh, arg);
1144 case VIDIOC_STREAMON:
1146 enum v4l2_buf_type i = *(int *)arg;
1147 if (!vfd->vidioc_streamon)
1149 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1150 ret=vfd->vidioc_streamon(file, fh,i);
1153 case VIDIOC_STREAMOFF:
1155 enum v4l2_buf_type i = *(int *)arg;
1157 if (!vfd->vidioc_streamoff)
1159 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1160 ret=vfd->vidioc_streamoff(file, fh, i);
1163 /* ---------- tv norms ---------- */
1164 case VIDIOC_ENUMSTD:
1166 struct v4l2_standard *p = arg;
1167 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1168 unsigned int index = p->index, i, j = 0;
1169 const char *descr = "";
1171 /* Return norm array in a canonical way */
1172 for (i = 0; i <= index && id; i++) {
1173 /* last std value in the standards array is 0, so this
1174 while always ends there since (id & 0) == 0. */
1175 while ((id & standards[j].std) != standards[j].std)
1177 curr_id = standards[j].std;
1178 descr = standards[j].descr;
1182 if (curr_id != V4L2_STD_PAL &&
1183 curr_id != V4L2_STD_SECAM &&
1184 curr_id != V4L2_STD_NTSC)
1190 v4l2_video_std_construct(p, curr_id, descr);
1193 dbgarg(cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
1194 "framelines=%d\n", p->index,
1195 (unsigned long long)p->id, p->name,
1196 p->frameperiod.numerator,
1197 p->frameperiod.denominator,
1205 v4l2_std_id *id = arg;
1207 *id = vfd->current_norm;
1209 dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
1216 v4l2_std_id *id = arg,norm;
1218 dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
1220 norm = (*id) & vfd->tvnorms;
1221 if ( vfd->tvnorms && !norm) /* Check if std is supported */
1224 /* Calls the specific handler */
1225 if (vfd->vidioc_s_std)
1226 ret=vfd->vidioc_s_std(file, fh, &norm);
1230 /* Updates standard information */
1232 vfd->current_norm=norm;
1236 case VIDIOC_QUERYSTD:
1240 if (!vfd->vidioc_querystd)
1242 ret=vfd->vidioc_querystd(file, fh, arg);
1244 dbgarg (cmd, "detected std=%08Lx\n",
1245 (unsigned long long)*p);
1248 /* ------ input switching ---------- */
1249 /* FIXME: Inputs can be handled inside videodev2 */
1250 case VIDIOC_ENUMINPUT:
1252 struct v4l2_input *p=arg;
1255 if (!vfd->vidioc_enum_input)
1257 memset(p, 0, sizeof(*p));
1260 ret=vfd->vidioc_enum_input(file, fh, p);
1262 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1264 "tuner=%d, std=%08Lx, status=%d\n",
1265 p->index,p->name,p->type,p->audioset,
1267 (unsigned long long)p->std,
1271 case VIDIOC_G_INPUT:
1273 unsigned int *i = arg;
1275 if (!vfd->vidioc_g_input)
1277 ret=vfd->vidioc_g_input(file, fh, i);
1279 dbgarg (cmd, "value=%d\n",*i);
1282 case VIDIOC_S_INPUT:
1284 unsigned int *i = arg;
1286 if (!vfd->vidioc_s_input)
1288 dbgarg (cmd, "value=%d\n",*i);
1289 ret=vfd->vidioc_s_input(file, fh, *i);
1293 /* ------ output switching ---------- */
1294 case VIDIOC_G_OUTPUT:
1296 unsigned int *i = arg;
1298 if (!vfd->vidioc_g_output)
1300 ret=vfd->vidioc_g_output(file, fh, i);
1302 dbgarg (cmd, "value=%d\n",*i);
1305 case VIDIOC_S_OUTPUT:
1307 unsigned int *i = arg;
1309 if (!vfd->vidioc_s_output)
1311 dbgarg (cmd, "value=%d\n",*i);
1312 ret=vfd->vidioc_s_output(file, fh, *i);
1316 /* --- controls ---------------------------------------------- */
1317 case VIDIOC_QUERYCTRL:
1319 struct v4l2_queryctrl *p=arg;
1321 if (!vfd->vidioc_queryctrl)
1323 ret=vfd->vidioc_queryctrl(file, fh, p);
1326 dbgarg (cmd, "id=%d, type=%d, name=%s, "
1328 " step=%d, default=%d, flags=0x%08x\n",
1329 p->id,p->type,p->name,p->minimum,
1330 p->maximum,p->step,p->default_value,
1336 struct v4l2_control *p = arg;
1338 if (!vfd->vidioc_g_ctrl)
1340 dbgarg(cmd, "Enum for index=%d\n", p->id);
1342 ret=vfd->vidioc_g_ctrl(file, fh, p);
1344 dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
1349 struct v4l2_control *p = arg;
1351 if (!vfd->vidioc_s_ctrl)
1353 dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
1355 ret=vfd->vidioc_s_ctrl(file, fh, p);
1358 case VIDIOC_G_EXT_CTRLS:
1360 struct v4l2_ext_controls *p = arg;
1362 if (vfd->vidioc_g_ext_ctrls) {
1363 dbgarg(cmd, "count=%d\n", p->count);
1365 ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
1369 case VIDIOC_S_EXT_CTRLS:
1371 struct v4l2_ext_controls *p = arg;
1373 if (vfd->vidioc_s_ext_ctrls) {
1374 dbgarg(cmd, "count=%d\n", p->count);
1376 ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
1380 case VIDIOC_TRY_EXT_CTRLS:
1382 struct v4l2_ext_controls *p = arg;
1384 if (vfd->vidioc_try_ext_ctrls) {
1385 dbgarg(cmd, "count=%d\n", p->count);
1387 ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
1391 case VIDIOC_QUERYMENU:
1393 struct v4l2_querymenu *p=arg;
1394 if (!vfd->vidioc_querymenu)
1396 ret=vfd->vidioc_querymenu(file, fh, p);
1398 dbgarg (cmd, "id=%d, index=%d, name=%s\n",
1399 p->id,p->index,p->name);
1402 /* --- audio ---------------------------------------------- */
1403 case VIDIOC_ENUMAUDIO:
1405 struct v4l2_audio *p=arg;
1407 if (!vfd->vidioc_enumaudio)
1409 dbgarg(cmd, "Enum for index=%d\n", p->index);
1410 ret=vfd->vidioc_enumaudio(file, fh, p);
1412 dbgarg2("index=%d, name=%s, capability=%d, "
1413 "mode=%d\n",p->index,p->name,
1414 p->capability, p->mode);
1417 case VIDIOC_G_AUDIO:
1419 struct v4l2_audio *p=arg;
1420 __u32 index=p->index;
1422 if (!vfd->vidioc_g_audio)
1425 memset(p,0,sizeof(*p));
1427 dbgarg(cmd, "Get for index=%d\n", p->index);
1428 ret=vfd->vidioc_g_audio(file, fh, p);
1430 dbgarg2("index=%d, name=%s, capability=%d, "
1431 "mode=%d\n",p->index,
1432 p->name,p->capability, p->mode);
1435 case VIDIOC_S_AUDIO:
1437 struct v4l2_audio *p=arg;
1439 if (!vfd->vidioc_s_audio)
1441 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1442 "mode=%d\n", p->index, p->name,
1443 p->capability, p->mode);
1444 ret=vfd->vidioc_s_audio(file, fh, p);
1447 case VIDIOC_ENUMAUDOUT:
1449 struct v4l2_audioout *p=arg;
1451 if (!vfd->vidioc_enumaudout)
1453 dbgarg(cmd, "Enum for index=%d\n", p->index);
1454 ret=vfd->vidioc_enumaudout(file, fh, p);
1456 dbgarg2("index=%d, name=%s, capability=%d, "
1457 "mode=%d\n", p->index, p->name,
1458 p->capability,p->mode);
1461 case VIDIOC_G_AUDOUT:
1463 struct v4l2_audioout *p=arg;
1465 if (!vfd->vidioc_g_audout)
1467 dbgarg(cmd, "Enum for index=%d\n", p->index);
1468 ret=vfd->vidioc_g_audout(file, fh, p);
1470 dbgarg2("index=%d, name=%s, capability=%d, "
1471 "mode=%d\n", p->index, p->name,
1472 p->capability,p->mode);
1475 case VIDIOC_S_AUDOUT:
1477 struct v4l2_audioout *p=arg;
1479 if (!vfd->vidioc_s_audout)
1481 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1482 "mode=%d\n", p->index, p->name,
1483 p->capability,p->mode);
1485 ret=vfd->vidioc_s_audout(file, fh, p);
1488 case VIDIOC_G_MODULATOR:
1490 struct v4l2_modulator *p=arg;
1491 if (!vfd->vidioc_g_modulator)
1493 ret=vfd->vidioc_g_modulator(file, fh, p);
1495 dbgarg(cmd, "index=%d, name=%s, "
1496 "capability=%d, rangelow=%d,"
1497 " rangehigh=%d, txsubchans=%d\n",
1498 p->index, p->name,p->capability,
1499 p->rangelow, p->rangehigh,
1503 case VIDIOC_S_MODULATOR:
1505 struct v4l2_modulator *p=arg;
1506 if (!vfd->vidioc_s_modulator)
1508 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1509 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1510 p->index, p->name,p->capability,p->rangelow,
1511 p->rangehigh,p->txsubchans);
1512 ret=vfd->vidioc_s_modulator(file, fh, p);
1517 struct v4l2_crop *p=arg;
1518 if (!vfd->vidioc_g_crop)
1520 ret=vfd->vidioc_g_crop(file, fh, p);
1522 dbgarg(cmd, "type=%d\n", p->type);
1523 dbgrect(vfd, "", &p->c);
1529 struct v4l2_crop *p=arg;
1530 if (!vfd->vidioc_s_crop)
1532 dbgarg(cmd, "type=%d\n", p->type);
1533 dbgrect(vfd, "", &p->c);
1534 ret=vfd->vidioc_s_crop(file, fh, p);
1537 case VIDIOC_CROPCAP:
1539 struct v4l2_cropcap *p=arg;
1540 /*FIXME: Should also show v4l2_fract pixelaspect */
1541 if (!vfd->vidioc_cropcap)
1543 dbgarg(cmd, "type=%d\n", p->type);
1544 dbgrect(vfd, "bounds ", &p->bounds);
1545 dbgrect(vfd, "defrect ", &p->defrect);
1546 ret=vfd->vidioc_cropcap(file, fh, p);
1549 case VIDIOC_G_JPEGCOMP:
1551 struct v4l2_jpegcompression *p=arg;
1552 if (!vfd->vidioc_g_jpegcomp)
1554 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1556 dbgarg (cmd, "quality=%d, APPn=%d, "
1557 "APP_len=%d, COM_len=%d, "
1558 "jpeg_markers=%d\n",
1559 p->quality,p->APPn,p->APP_len,
1560 p->COM_len,p->jpeg_markers);
1563 case VIDIOC_S_JPEGCOMP:
1565 struct v4l2_jpegcompression *p=arg;
1566 if (!vfd->vidioc_g_jpegcomp)
1568 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1569 "COM_len=%d, jpeg_markers=%d\n",
1570 p->quality,p->APPn,p->APP_len,
1571 p->COM_len,p->jpeg_markers);
1572 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1575 case VIDIOC_G_ENC_INDEX:
1577 struct v4l2_enc_idx *p=arg;
1579 if (!vfd->vidioc_g_enc_index)
1581 ret=vfd->vidioc_g_enc_index(file, fh, p);
1583 dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1584 p->entries,p->entries_cap);
1587 case VIDIOC_ENCODER_CMD:
1589 struct v4l2_encoder_cmd *p=arg;
1591 if (!vfd->vidioc_encoder_cmd)
1593 ret=vfd->vidioc_encoder_cmd(file, fh, p);
1595 dbgarg (cmd, "cmd=%d, flags=%d\n",
1599 case VIDIOC_TRY_ENCODER_CMD:
1601 struct v4l2_encoder_cmd *p=arg;
1603 if (!vfd->vidioc_try_encoder_cmd)
1605 ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
1607 dbgarg (cmd, "cmd=%d, flags=%d\n",
1613 struct v4l2_streamparm *p=arg;
1616 memset(p,0,sizeof(*p));
1619 if (vfd->vidioc_g_parm) {
1620 ret=vfd->vidioc_g_parm(file, fh, p);
1622 struct v4l2_standard s;
1624 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1627 v4l2_video_std_construct(&s, vfd->current_norm,
1628 v4l2_norm_to_name(vfd->current_norm));
1630 p->parm.capture.timeperframe = s.frameperiod;
1634 dbgarg (cmd, "type=%d\n", p->type);
1639 struct v4l2_streamparm *p=arg;
1640 if (!vfd->vidioc_s_parm)
1642 dbgarg (cmd, "type=%d\n", p->type);
1643 ret=vfd->vidioc_s_parm(file, fh, p);
1646 case VIDIOC_G_TUNER:
1648 struct v4l2_tuner *p=arg;
1649 __u32 index=p->index;
1651 if (!vfd->vidioc_g_tuner)
1654 memset(p,0,sizeof(*p));
1657 ret=vfd->vidioc_g_tuner(file, fh, p);
1659 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1660 "capability=%d, rangelow=%d, "
1661 "rangehigh=%d, signal=%d, afc=%d, "
1662 "rxsubchans=%d, audmode=%d\n",
1663 p->index, p->name, p->type,
1664 p->capability, p->rangelow,
1665 p->rangehigh, p->rxsubchans,
1666 p->audmode, p->signal, p->afc);
1669 case VIDIOC_S_TUNER:
1671 struct v4l2_tuner *p=arg;
1672 if (!vfd->vidioc_s_tuner)
1674 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1675 "capability=%d, rangelow=%d, rangehigh=%d, "
1676 "signal=%d, afc=%d, rxsubchans=%d, "
1677 "audmode=%d\n",p->index, p->name, p->type,
1678 p->capability, p->rangelow,p->rangehigh,
1679 p->rxsubchans, p->audmode, p->signal,
1681 ret=vfd->vidioc_s_tuner(file, fh, p);
1684 case VIDIOC_G_FREQUENCY:
1686 struct v4l2_frequency *p=arg;
1687 if (!vfd->vidioc_g_frequency)
1690 memset(p,0,sizeof(*p));
1692 ret=vfd->vidioc_g_frequency(file, fh, p);
1694 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1695 p->tuner,p->type,p->frequency);
1698 case VIDIOC_S_FREQUENCY:
1700 struct v4l2_frequency *p=arg;
1701 if (!vfd->vidioc_s_frequency)
1703 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1704 p->tuner,p->type,p->frequency);
1705 ret=vfd->vidioc_s_frequency(file, fh, p);
1708 case VIDIOC_G_SLICED_VBI_CAP:
1710 struct v4l2_sliced_vbi_cap *p=arg;
1711 if (!vfd->vidioc_g_sliced_vbi_cap)
1713 ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1715 dbgarg (cmd, "service_set=%d\n", p->service_set);
1718 case VIDIOC_LOG_STATUS:
1720 if (!vfd->vidioc_log_status)
1722 ret=vfd->vidioc_log_status(file, fh);
1725 #ifdef CONFIG_VIDEO_ADV_DEBUG
1726 case VIDIOC_DBG_G_REGISTER:
1728 struct v4l2_register *p=arg;
1729 if (!capable(CAP_SYS_ADMIN))
1731 else if (vfd->vidioc_g_register)
1732 ret=vfd->vidioc_g_register(file, fh, p);
1735 case VIDIOC_DBG_S_REGISTER:
1737 struct v4l2_register *p=arg;
1738 if (!capable(CAP_SYS_ADMIN))
1740 else if (vfd->vidioc_s_register)
1741 ret=vfd->vidioc_s_register(file, fh, p);
1745 case VIDIOC_G_CHIP_IDENT:
1747 struct v4l2_chip_ident *p=arg;
1748 if (!vfd->vidioc_g_chip_ident)
1750 ret=vfd->vidioc_g_chip_ident(file, fh, p);
1752 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1757 if (!vfd->vidioc_default)
1759 ret = vfd->vidioc_default(file, fh, cmd, arg);
1764 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1766 printk("%s: err: on ", vfd->name);
1767 v4l_print_ioctl(vfd->name, cmd);
1775 int video_ioctl2 (struct inode *inode, struct file *file,
1776 unsigned int cmd, unsigned long arg)
1783 size_t ctrls_size = 0;
1784 void __user *user_ptr = NULL;
1786 #ifdef __OLD_VIDIOC_
1787 cmd = video_fix_command(cmd);
1789 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1790 cmd == VIDIOC_TRY_EXT_CTRLS);
1792 /* Copy arguments into temp kernel buffer */
1793 switch (_IOC_DIR(cmd)) {
1799 case (_IOC_WRITE | _IOC_READ):
1800 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1803 /* too big to allocate from stack */
1804 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1811 if (_IOC_DIR(cmd) & _IOC_WRITE)
1812 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1818 struct v4l2_ext_controls *p = parg;
1820 /* In case of an error, tell the caller that it wasn't
1821 a specific control that caused it. */
1822 p->error_idx = p->count;
1823 user_ptr = (void __user *)p->controls;
1825 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1826 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1827 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1832 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1839 err = __video_do_ioctl(inode, file, cmd, parg);
1840 if (err == -ENOIOCTLCMD)
1843 struct v4l2_ext_controls *p = parg;
1845 p->controls = (void *)user_ptr;
1846 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1854 /* Copy results into user buffer */
1855 switch (_IOC_DIR(cmd))
1858 case (_IOC_WRITE | _IOC_READ):
1859 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1868 EXPORT_SYMBOL(video_ioctl2);
1870 static const struct file_operations video_fops;
1873 * video_register_device - register video4linux devices
1874 * @vfd: video device structure we want to register
1875 * @type: type of device to register
1876 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
1879 * The registration code assigns minor numbers based on the type
1880 * requested. -ENFILE is returned in all the device slots for this
1881 * category are full. If not then the minor field is set and the
1882 * driver initialize function is called (if non %NULL).
1884 * Zero is returned on success.
1888 * %VFL_TYPE_GRABBER - A frame grabber
1890 * %VFL_TYPE_VTX - A teletext device
1892 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
1894 * %VFL_TYPE_RADIO - A radio card
1897 int video_register_device(struct video_device *vfd, int type, int nr)
1907 case VFL_TYPE_GRABBER:
1908 base=MINOR_VFL_TYPE_GRABBER_MIN;
1909 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
1910 name_base = "video";
1913 base=MINOR_VFL_TYPE_VTX_MIN;
1914 end=MINOR_VFL_TYPE_VTX_MAX+1;
1918 base=MINOR_VFL_TYPE_VBI_MIN;
1919 end=MINOR_VFL_TYPE_VBI_MAX+1;
1922 case VFL_TYPE_RADIO:
1923 base=MINOR_VFL_TYPE_RADIO_MIN;
1924 end=MINOR_VFL_TYPE_RADIO_MAX+1;
1925 name_base = "radio";
1928 printk(KERN_ERR "%s called with unknown type: %d\n",
1933 /* pick a minor number */
1934 mutex_lock(&videodev_lock);
1935 if (nr >= 0 && nr < end-base) {
1936 /* use the one the driver asked for */
1938 if (NULL != video_device[i]) {
1939 mutex_unlock(&videodev_lock);
1943 /* use first free */
1944 for(i=base;i<end;i++)
1945 if (NULL == video_device[i])
1948 mutex_unlock(&videodev_lock);
1952 video_device[i]=vfd;
1954 mutex_unlock(&videodev_lock);
1955 mutex_init(&vfd->lock);
1958 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
1960 vfd->class_dev.parent = vfd->dev;
1961 vfd->class_dev.class = &video_class;
1962 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
1963 sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
1964 ret = device_register(&vfd->class_dev);
1966 printk(KERN_ERR "%s: device_register failed\n",
1972 /* needed until all drivers are fixed */
1974 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
1975 "Please fix your driver for proper sysfs support, see "
1976 "http://lwn.net/Articles/36850/\n", vfd->name);
1981 mutex_lock(&videodev_lock);
1982 video_device[vfd->minor] = NULL;
1984 mutex_unlock(&videodev_lock);
1987 EXPORT_SYMBOL(video_register_device);
1990 * video_unregister_device - unregister a video4linux device
1991 * @vfd: the device to unregister
1993 * This unregisters the passed device and deassigns the minor
1994 * number. Future open calls will be met with errors.
1997 void video_unregister_device(struct video_device *vfd)
1999 mutex_lock(&videodev_lock);
2000 if(video_device[vfd->minor]!=vfd)
2001 panic("videodev: bad unregister");
2003 video_device[vfd->minor]=NULL;
2004 device_unregister(&vfd->class_dev);
2005 mutex_unlock(&videodev_lock);
2007 EXPORT_SYMBOL(video_unregister_device);
2010 * Video fs operations
2012 static const struct file_operations video_fops=
2014 .owner = THIS_MODULE,
2015 .llseek = no_llseek,
2020 * Initialise video for linux
2023 static int __init videodev_init(void)
2027 printk(KERN_INFO "Linux video capture interface: v2.00\n");
2028 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
2029 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
2033 ret = class_register(&video_class);
2035 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2036 printk(KERN_WARNING "video_dev: class_register failed\n");
2043 static void __exit videodev_exit(void)
2045 class_unregister(&video_class);
2046 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2049 module_init(videodev_init)
2050 module_exit(videodev_exit)
2052 MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
2053 MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
2054 MODULE_LICENSE("GPL");