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 (KERN_DEBUG "%s: " fmt, vfd->name, ## 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>
50 #define VIDEO_NUM_DEVICES 256
51 #define VIDEO_NAME "video4linux"
57 static ssize_t show_name(struct device *cd,
58 struct device_attribute *attr, char *buf)
60 struct video_device *vfd = container_of(cd, struct video_device,
62 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
65 struct video_device *video_device_alloc(void)
67 struct video_device *vfd;
69 vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
73 void video_device_release(struct video_device *vfd)
78 static void video_release(struct device *cd)
80 struct video_device *vfd = container_of(cd, struct video_device, class_dev);
83 /* needed until all drivers are fixed */
90 static struct device_attribute video_device_attrs[] = {
91 __ATTR(name, S_IRUGO, show_name, NULL),
95 static struct class video_class = {
97 .dev_attrs = video_device_attrs,
98 .dev_release = video_release,
105 static struct video_device *video_device[VIDEO_NUM_DEVICES];
106 static DEFINE_MUTEX(videodev_lock);
108 struct video_device* video_devdata(struct file *file)
110 return video_device[iminor(file->f_path.dentry->d_inode)];
114 * Open a video device - FIXME: Obsoleted
116 static int video_open(struct inode *inode, struct file *file)
118 unsigned int minor = iminor(inode);
120 struct video_device *vfl;
121 const struct file_operations *old_fops;
123 if(minor>=VIDEO_NUM_DEVICES)
125 mutex_lock(&videodev_lock);
126 vfl=video_device[minor];
128 mutex_unlock(&videodev_lock);
129 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
130 mutex_lock(&videodev_lock);
131 vfl=video_device[minor];
133 mutex_unlock(&videodev_lock);
137 old_fops = file->f_op;
138 file->f_op = fops_get(vfl->fops);
140 err = file->f_op->open(inode,file);
142 fops_put(file->f_op);
143 file->f_op = fops_get(old_fops);
146 mutex_unlock(&videodev_lock);
151 * helper function -- handles userspace copying for ioctl arguments
156 video_fix_command(unsigned int cmd)
159 case VIDIOC_OVERLAY_OLD:
160 cmd = VIDIOC_OVERLAY;
162 case VIDIOC_S_PARM_OLD:
165 case VIDIOC_S_CTRL_OLD:
168 case VIDIOC_G_AUDIO_OLD:
169 cmd = VIDIOC_G_AUDIO;
171 case VIDIOC_G_AUDOUT_OLD:
172 cmd = VIDIOC_G_AUDOUT;
174 case VIDIOC_CROPCAP_OLD:
175 cmd = VIDIOC_CROPCAP;
183 * Obsolete usercopy function - Should be removed soon
186 video_usercopy(struct inode *inode, struct file *file,
187 unsigned int cmd, unsigned long arg,
188 int (*func)(struct inode *inode, struct file *file,
189 unsigned int cmd, void *arg))
196 size_t ctrls_size = 0;
197 void __user *user_ptr = NULL;
200 cmd = video_fix_command(cmd);
202 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
203 cmd == VIDIOC_TRY_EXT_CTRLS);
205 /* Copy arguments into temp kernel buffer */
206 switch (_IOC_DIR(cmd)) {
212 case (_IOC_WRITE | _IOC_READ):
213 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
216 /* too big to allocate from stack */
217 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
224 if (_IOC_DIR(cmd) & _IOC_WRITE)
225 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
230 struct v4l2_ext_controls *p = parg;
232 /* In case of an error, tell the caller that it wasn't
233 a specific control that caused it. */
234 p->error_idx = p->count;
235 user_ptr = (void __user *)p->controls;
237 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
238 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
239 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
244 if (copy_from_user(mbuf, user_ptr, ctrls_size))
251 err = func(inode, file, cmd, parg);
252 if (err == -ENOIOCTLCMD)
255 struct v4l2_ext_controls *p = parg;
257 p->controls = (void *)user_ptr;
258 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
266 /* Copy results into user buffer */
267 switch (_IOC_DIR(cmd))
270 case (_IOC_WRITE | _IOC_READ):
271 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
282 * open/release helper functions -- handle exclusive opens
283 * Should be removed soon
285 int video_exclusive_open(struct inode *inode, struct file *file)
287 struct video_device *vfl = video_devdata(file);
290 mutex_lock(&vfl->lock);
296 mutex_unlock(&vfl->lock);
300 int video_exclusive_release(struct inode *inode, struct file *file)
302 struct video_device *vfl = video_devdata(file);
308 static char *v4l2_memory_names[] = {
309 [V4L2_MEMORY_MMAP] = "mmap",
310 [V4L2_MEMORY_USERPTR] = "userptr",
311 [V4L2_MEMORY_OVERLAY] = "overlay",
315 /* FIXME: Those stuff are replicated also on v4l2-common.c */
316 static char *v4l2_type_names_FIXME[] = {
317 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
318 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
319 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
320 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
321 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
322 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
323 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture",
324 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
325 [V4L2_BUF_TYPE_PRIVATE] = "private",
328 static char *v4l2_field_names_FIXME[] = {
329 [V4L2_FIELD_ANY] = "any",
330 [V4L2_FIELD_NONE] = "none",
331 [V4L2_FIELD_TOP] = "top",
332 [V4L2_FIELD_BOTTOM] = "bottom",
333 [V4L2_FIELD_INTERLACED] = "interlaced",
334 [V4L2_FIELD_SEQ_TB] = "seq-tb",
335 [V4L2_FIELD_SEQ_BT] = "seq-bt",
336 [V4L2_FIELD_ALTERNATE] = "alternate",
337 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
338 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
341 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
343 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
344 struct v4l2_buffer *p)
346 struct v4l2_timecode *tc=&p->timecode;
348 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
349 "bytesused=%d, flags=0x%08d, "
350 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
351 (p->timestamp.tv_sec/3600),
352 (int)(p->timestamp.tv_sec/60)%60,
353 (int)(p->timestamp.tv_sec%60),
354 p->timestamp.tv_usec,
356 prt_names(p->type,v4l2_type_names_FIXME),
357 p->bytesused,p->flags,
358 p->field,p->sequence,
359 prt_names(p->memory,v4l2_memory_names),
360 p->m.userptr, p->length);
361 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
362 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
363 tc->hours,tc->minutes,tc->seconds,
364 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
367 static inline void dbgrect(struct video_device *vfd, char *s,
370 dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
371 r->width, r->height);
374 static inline void v4l_print_pix_fmt (struct video_device *vfd,
375 struct v4l2_pix_format *fmt)
377 dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
378 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
379 fmt->width,fmt->height,
380 (fmt->pixelformat & 0xff),
381 (fmt->pixelformat >> 8) & 0xff,
382 (fmt->pixelformat >> 16) & 0xff,
383 (fmt->pixelformat >> 24) & 0xff,
384 prt_names(fmt->field,v4l2_field_names_FIXME),
385 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
389 static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
392 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
393 if (vfd->vidioc_try_fmt_cap)
396 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
397 if (vfd->vidioc_try_fmt_overlay)
400 case V4L2_BUF_TYPE_VBI_CAPTURE:
401 if (vfd->vidioc_try_fmt_vbi)
404 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
405 if (vfd->vidioc_try_fmt_vbi_output)
408 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
409 if (vfd->vidioc_try_fmt_vbi_capture)
412 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
413 if (vfd->vidioc_try_fmt_video_output)
416 case V4L2_BUF_TYPE_VBI_OUTPUT:
417 if (vfd->vidioc_try_fmt_vbi_output)
420 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
421 if (vfd->vidioc_try_fmt_output_overlay)
424 case V4L2_BUF_TYPE_PRIVATE:
425 if (vfd->vidioc_try_fmt_type_private)
432 static int __video_do_ioctl(struct inode *inode, struct file *file,
433 unsigned int cmd, void *arg)
435 struct video_device *vfd = video_devdata(file);
436 void *fh = file->private_data;
439 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
440 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
441 v4l_print_ioctl(vfd->name, cmd);
444 #ifdef CONFIG_VIDEO_V4L1_COMPAT
445 /***********************************************************
446 Handles calls to the obsoleted V4L1 API
447 Due to the nature of VIDIOCGMBUF, each driver that supports
448 V4L1 should implement its own handler for this ioctl.
449 ***********************************************************/
451 /* --- streaming capture ------------------------------------- */
452 if (cmd == VIDIOCGMBUF) {
453 struct video_mbuf *p=arg;
455 memset(p, 0, sizeof(*p));
457 if (!vfd->vidiocgmbuf)
459 ret=vfd->vidiocgmbuf(file, fh, p);
461 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
463 (unsigned long)p->offsets);
467 /********************************************************
468 All other V4L1 calls are handled by v4l1_compat module.
469 Those calls will be translated into V4L2 calls, and
470 __video_do_ioctl will be called again, with one or more
472 ********************************************************/
473 if (_IOC_TYPE(cmd)=='v')
474 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
479 /* --- capabilities ------------------------------------------ */
480 case VIDIOC_QUERYCAP:
482 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
483 memset(cap, 0, sizeof(*cap));
485 if (!vfd->vidioc_querycap)
488 ret=vfd->vidioc_querycap(file, fh, cap);
490 dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
492 "capabilities=0x%08x\n",
493 cap->driver,cap->card,cap->bus_info,
499 /* --- priority ------------------------------------------ */
500 case VIDIOC_G_PRIORITY:
502 enum v4l2_priority *p=arg;
504 if (!vfd->vidioc_g_priority)
506 ret=vfd->vidioc_g_priority(file, fh, p);
508 dbgarg(cmd, "priority is %d\n", *p);
511 case VIDIOC_S_PRIORITY:
513 enum v4l2_priority *p=arg;
515 if (!vfd->vidioc_s_priority)
517 dbgarg(cmd, "setting priority to %d\n", *p);
518 ret=vfd->vidioc_s_priority(file, fh, *p);
522 /* --- capture ioctls ---------------------------------------- */
523 case VIDIOC_ENUM_FMT:
525 struct v4l2_fmtdesc *f = arg;
526 enum v4l2_buf_type type;
531 memset(f,0,sizeof(*f));
536 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
537 if (vfd->vidioc_enum_fmt_cap)
538 ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
540 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
541 if (vfd->vidioc_enum_fmt_overlay)
542 ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
544 case V4L2_BUF_TYPE_VBI_CAPTURE:
545 if (vfd->vidioc_enum_fmt_vbi)
546 ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
548 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
549 if (vfd->vidioc_enum_fmt_vbi_output)
550 ret=vfd->vidioc_enum_fmt_vbi_output(file,
553 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
554 if (vfd->vidioc_enum_fmt_vbi_capture)
555 ret=vfd->vidioc_enum_fmt_vbi_capture(file,
558 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
559 if (vfd->vidioc_enum_fmt_video_output)
560 ret=vfd->vidioc_enum_fmt_video_output(file,
563 case V4L2_BUF_TYPE_VBI_OUTPUT:
564 if (vfd->vidioc_enum_fmt_vbi_output)
565 ret=vfd->vidioc_enum_fmt_vbi_output(file,
568 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
569 if (vfd->vidioc_enum_fmt_output_overlay)
570 ret=vfd->vidioc_enum_fmt_output_overlay(file, fh, f);
572 case V4L2_BUF_TYPE_PRIVATE:
573 if (vfd->vidioc_enum_fmt_type_private)
574 ret=vfd->vidioc_enum_fmt_type_private(file,
579 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
580 "pixelformat=%c%c%c%c, description='%s'\n",
581 f->index, f->type, f->flags,
582 (f->pixelformat & 0xff),
583 (f->pixelformat >> 8) & 0xff,
584 (f->pixelformat >> 16) & 0xff,
585 (f->pixelformat >> 24) & 0xff,
591 struct v4l2_format *f = (struct v4l2_format *)arg;
592 enum v4l2_buf_type type=f->type;
594 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
597 /* FIXME: Should be one dump per type */
598 dbgarg (cmd, "type=%s\n", prt_names(type,
599 v4l2_type_names_FIXME));
602 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
603 if (vfd->vidioc_g_fmt_cap)
604 ret=vfd->vidioc_g_fmt_cap(file, fh, f);
606 v4l_print_pix_fmt(vfd,&f->fmt.pix);
608 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
609 if (vfd->vidioc_g_fmt_overlay)
610 ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
612 case V4L2_BUF_TYPE_VBI_CAPTURE:
613 if (vfd->vidioc_g_fmt_vbi)
614 ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
616 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
617 if (vfd->vidioc_g_fmt_vbi_output)
618 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
620 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
621 if (vfd->vidioc_g_fmt_vbi_capture)
622 ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
624 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
625 if (vfd->vidioc_g_fmt_video_output)
626 ret=vfd->vidioc_g_fmt_video_output(file,
629 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
630 if (vfd->vidioc_g_fmt_output_overlay)
631 ret=vfd->vidioc_g_fmt_output_overlay(file, fh, f);
633 case V4L2_BUF_TYPE_VBI_OUTPUT:
634 if (vfd->vidioc_g_fmt_vbi_output)
635 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
637 case V4L2_BUF_TYPE_PRIVATE:
638 if (vfd->vidioc_g_fmt_type_private)
639 ret=vfd->vidioc_g_fmt_type_private(file,
648 struct v4l2_format *f = (struct v4l2_format *)arg;
650 /* FIXME: Should be one dump per type */
651 dbgarg (cmd, "type=%s\n", prt_names(f->type,
652 v4l2_type_names_FIXME));
655 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
656 v4l_print_pix_fmt(vfd,&f->fmt.pix);
657 if (vfd->vidioc_s_fmt_cap)
658 ret=vfd->vidioc_s_fmt_cap(file, fh, f);
660 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
661 if (vfd->vidioc_s_fmt_overlay)
662 ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
664 case V4L2_BUF_TYPE_VBI_CAPTURE:
665 if (vfd->vidioc_s_fmt_vbi)
666 ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
668 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
669 if (vfd->vidioc_s_fmt_vbi_output)
670 ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
672 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
673 if (vfd->vidioc_s_fmt_vbi_capture)
674 ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
676 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
677 if (vfd->vidioc_s_fmt_video_output)
678 ret=vfd->vidioc_s_fmt_video_output(file,
681 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
682 if (vfd->vidioc_s_fmt_output_overlay)
683 ret=vfd->vidioc_s_fmt_output_overlay(file, fh, f);
685 case V4L2_BUF_TYPE_VBI_OUTPUT:
686 if (vfd->vidioc_s_fmt_vbi_output)
687 ret=vfd->vidioc_s_fmt_vbi_output(file,
690 case V4L2_BUF_TYPE_PRIVATE:
691 if (vfd->vidioc_s_fmt_type_private)
692 ret=vfd->vidioc_s_fmt_type_private(file,
700 struct v4l2_format *f = (struct v4l2_format *)arg;
702 /* FIXME: Should be one dump per type */
703 dbgarg (cmd, "type=%s\n", prt_names(f->type,
704 v4l2_type_names_FIXME));
706 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
707 if (vfd->vidioc_try_fmt_cap)
708 ret=vfd->vidioc_try_fmt_cap(file, fh, f);
710 v4l_print_pix_fmt(vfd,&f->fmt.pix);
712 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
713 if (vfd->vidioc_try_fmt_overlay)
714 ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
716 case V4L2_BUF_TYPE_VBI_CAPTURE:
717 if (vfd->vidioc_try_fmt_vbi)
718 ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
720 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
721 if (vfd->vidioc_try_fmt_vbi_output)
722 ret=vfd->vidioc_try_fmt_vbi_output(file,
725 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
726 if (vfd->vidioc_try_fmt_vbi_capture)
727 ret=vfd->vidioc_try_fmt_vbi_capture(file,
730 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
731 if (vfd->vidioc_try_fmt_video_output)
732 ret=vfd->vidioc_try_fmt_video_output(file,
735 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
736 if (vfd->vidioc_try_fmt_output_overlay)
737 ret=vfd->vidioc_try_fmt_output_overlay(file, fh, f);
739 case V4L2_BUF_TYPE_VBI_OUTPUT:
740 if (vfd->vidioc_try_fmt_vbi_output)
741 ret=vfd->vidioc_try_fmt_vbi_output(file,
744 case V4L2_BUF_TYPE_PRIVATE:
745 if (vfd->vidioc_try_fmt_type_private)
746 ret=vfd->vidioc_try_fmt_type_private(file,
753 /* FIXME: Those buf reqs could be handled here,
754 with some changes on videobuf to allow its header to be included at
755 videodev2.h or being merged at videodev2.
759 struct v4l2_requestbuffers *p=arg;
761 if (!vfd->vidioc_reqbufs)
763 ret = check_fmt (vfd, p->type);
767 ret=vfd->vidioc_reqbufs(file, fh, p);
768 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
770 prt_names(p->type,v4l2_type_names_FIXME),
771 prt_names(p->memory,v4l2_memory_names));
774 case VIDIOC_QUERYBUF:
776 struct v4l2_buffer *p=arg;
778 if (!vfd->vidioc_querybuf)
780 ret = check_fmt (vfd, p->type);
784 ret=vfd->vidioc_querybuf(file, fh, p);
791 struct v4l2_buffer *p=arg;
793 if (!vfd->vidioc_qbuf)
795 ret = check_fmt (vfd, p->type);
799 ret=vfd->vidioc_qbuf(file, fh, p);
806 struct v4l2_buffer *p=arg;
807 if (!vfd->vidioc_dqbuf)
809 ret = check_fmt (vfd, p->type);
813 ret=vfd->vidioc_dqbuf(file, fh, p);
822 if (!vfd->vidioc_overlay)
824 dbgarg (cmd, "value=%d\n",*i);
825 ret=vfd->vidioc_overlay(file, fh, *i);
830 struct v4l2_framebuffer *p=arg;
831 if (!vfd->vidioc_g_fbuf)
833 ret=vfd->vidioc_g_fbuf(file, fh, arg);
835 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
836 p->capability,p->flags,
837 (unsigned long)p->base);
838 v4l_print_pix_fmt (vfd, &p->fmt);
844 struct v4l2_framebuffer *p=arg;
845 if (!vfd->vidioc_s_fbuf)
848 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
849 p->capability,p->flags,(unsigned long)p->base);
850 v4l_print_pix_fmt (vfd, &p->fmt);
851 ret=vfd->vidioc_s_fbuf(file, fh, arg);
855 case VIDIOC_STREAMON:
857 enum v4l2_buf_type i = *(int *)arg;
858 if (!vfd->vidioc_streamon)
860 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
861 ret=vfd->vidioc_streamon(file, fh,i);
864 case VIDIOC_STREAMOFF:
866 enum v4l2_buf_type i = *(int *)arg;
868 if (!vfd->vidioc_streamoff)
870 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
871 ret=vfd->vidioc_streamoff(file, fh, i);
874 /* ---------- tv norms ---------- */
877 struct v4l2_standard *p = arg;
878 v4l2_std_id id = vfd->tvnorms,curr_id=0;
879 unsigned int index = p->index,i;
886 /* Return norm array on a canonical way */
887 for (i=0;i<= index && id; i++) {
888 if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) {
889 curr_id = V4L2_STD_PAL;
890 } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) {
891 curr_id = V4L2_STD_PAL_BG;
892 } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) {
893 curr_id = V4L2_STD_PAL_DK;
894 } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) {
895 curr_id = V4L2_STD_PAL_B;
896 } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) {
897 curr_id = V4L2_STD_PAL_B1;
898 } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) {
899 curr_id = V4L2_STD_PAL_G;
900 } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) {
901 curr_id = V4L2_STD_PAL_H;
902 } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) {
903 curr_id = V4L2_STD_PAL_I;
904 } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) {
905 curr_id = V4L2_STD_PAL_D;
906 } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) {
907 curr_id = V4L2_STD_PAL_D1;
908 } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) {
909 curr_id = V4L2_STD_PAL_K;
910 } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) {
911 curr_id = V4L2_STD_PAL_M;
912 } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) {
913 curr_id = V4L2_STD_PAL_N;
914 } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) {
915 curr_id = V4L2_STD_PAL_Nc;
916 } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) {
917 curr_id = V4L2_STD_PAL_60;
918 } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
919 curr_id = V4L2_STD_NTSC;
920 } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) {
921 curr_id = V4L2_STD_NTSC_M;
922 } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) {
923 curr_id = V4L2_STD_NTSC_M_JP;
924 } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) {
925 curr_id = V4L2_STD_NTSC_443;
926 } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) {
927 curr_id = V4L2_STD_NTSC_M_KR;
928 } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
929 curr_id = V4L2_STD_SECAM;
930 } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) {
931 curr_id = V4L2_STD_SECAM_DK;
932 } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) {
933 curr_id = V4L2_STD_SECAM_B;
934 } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) {
935 curr_id = V4L2_STD_SECAM_D;
936 } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) {
937 curr_id = V4L2_STD_SECAM_G;
938 } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) {
939 curr_id = V4L2_STD_SECAM_H;
940 } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) {
941 curr_id = V4L2_STD_SECAM_K;
942 } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) {
943 curr_id = V4L2_STD_SECAM_K1;
944 } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) {
945 curr_id = V4L2_STD_SECAM_L;
946 } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) {
947 curr_id = V4L2_STD_SECAM_LC;
956 v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id));
959 dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
960 "framelines=%d\n", p->index,
961 (unsigned long long)p->id, p->name,
962 p->frameperiod.numerator,
963 p->frameperiod.denominator,
971 v4l2_std_id *id = arg;
973 *id = vfd->current_norm;
975 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
982 v4l2_std_id *id = arg,norm;
984 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
986 norm = (*id) & vfd->tvnorms;
987 if ( vfd->tvnorms && !norm) /* Check if std is supported */
990 /* Calls the specific handler */
991 if (vfd->vidioc_s_std)
992 ret=vfd->vidioc_s_std(file, fh, &norm);
996 /* Updates standard information */
998 vfd->current_norm=norm;
1002 case VIDIOC_QUERYSTD:
1006 if (!vfd->vidioc_querystd)
1008 ret=vfd->vidioc_querystd(file, fh, arg);
1010 dbgarg (cmd, "detected std=%Lu\n",
1011 (unsigned long long)*p);
1014 /* ------ input switching ---------- */
1015 /* FIXME: Inputs can be handled inside videodev2 */
1016 case VIDIOC_ENUMINPUT:
1018 struct v4l2_input *p=arg;
1021 if (!vfd->vidioc_enum_input)
1023 memset(p, 0, sizeof(*p));
1026 ret=vfd->vidioc_enum_input(file, fh, p);
1028 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1030 "tuner=%d, std=%Ld, status=%d\n",
1031 p->index,p->name,p->type,p->audioset,
1033 (unsigned long long)p->std,
1037 case VIDIOC_G_INPUT:
1039 unsigned int *i = arg;
1041 if (!vfd->vidioc_g_input)
1043 ret=vfd->vidioc_g_input(file, fh, i);
1045 dbgarg (cmd, "value=%d\n",*i);
1048 case VIDIOC_S_INPUT:
1050 unsigned int *i = arg;
1052 if (!vfd->vidioc_s_input)
1054 dbgarg (cmd, "value=%d\n",*i);
1055 ret=vfd->vidioc_s_input(file, fh, *i);
1059 /* ------ output switching ---------- */
1060 case VIDIOC_G_OUTPUT:
1062 unsigned int *i = arg;
1064 if (!vfd->vidioc_g_output)
1066 ret=vfd->vidioc_g_output(file, fh, i);
1068 dbgarg (cmd, "value=%d\n",*i);
1071 case VIDIOC_S_OUTPUT:
1073 unsigned int *i = arg;
1075 if (!vfd->vidioc_s_output)
1077 dbgarg (cmd, "value=%d\n",*i);
1078 ret=vfd->vidioc_s_output(file, fh, *i);
1082 /* --- controls ---------------------------------------------- */
1083 case VIDIOC_QUERYCTRL:
1085 struct v4l2_queryctrl *p=arg;
1087 if (!vfd->vidioc_queryctrl)
1089 ret=vfd->vidioc_queryctrl(file, fh, p);
1092 dbgarg (cmd, "id=%d, type=%d, name=%s, "
1094 " step=%d, default=%d, flags=0x%08x\n",
1095 p->id,p->type,p->name,p->minimum,
1096 p->maximum,p->step,p->default_value,
1102 struct v4l2_control *p = arg;
1104 if (!vfd->vidioc_g_ctrl)
1106 dbgarg(cmd, "Enum for index=%d\n", p->id);
1108 ret=vfd->vidioc_g_ctrl(file, fh, p);
1110 dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
1115 struct v4l2_control *p = arg;
1117 if (!vfd->vidioc_s_ctrl)
1119 dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
1121 ret=vfd->vidioc_s_ctrl(file, fh, p);
1124 case VIDIOC_G_EXT_CTRLS:
1126 struct v4l2_ext_controls *p = arg;
1128 if (vfd->vidioc_g_ext_ctrls) {
1129 dbgarg(cmd, "count=%d\n", p->count);
1131 ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
1135 case VIDIOC_S_EXT_CTRLS:
1137 struct v4l2_ext_controls *p = arg;
1139 if (vfd->vidioc_s_ext_ctrls) {
1140 dbgarg(cmd, "count=%d\n", p->count);
1142 ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
1146 case VIDIOC_TRY_EXT_CTRLS:
1148 struct v4l2_ext_controls *p = arg;
1150 if (vfd->vidioc_try_ext_ctrls) {
1151 dbgarg(cmd, "count=%d\n", p->count);
1153 ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
1157 case VIDIOC_QUERYMENU:
1159 struct v4l2_querymenu *p=arg;
1160 if (!vfd->vidioc_querymenu)
1162 ret=vfd->vidioc_querymenu(file, fh, p);
1164 dbgarg (cmd, "id=%d, index=%d, name=%s\n",
1165 p->id,p->index,p->name);
1168 /* --- audio ---------------------------------------------- */
1169 case VIDIOC_ENUMAUDIO:
1171 struct v4l2_audio *p=arg;
1173 if (!vfd->vidioc_enumaudio)
1175 dbgarg(cmd, "Enum for index=%d\n", p->index);
1176 ret=vfd->vidioc_enumaudio(file, fh, p);
1178 dbgarg2("index=%d, name=%s, capability=%d, "
1179 "mode=%d\n",p->index,p->name,
1180 p->capability, p->mode);
1183 case VIDIOC_G_AUDIO:
1185 struct v4l2_audio *p=arg;
1186 __u32 index=p->index;
1188 if (!vfd->vidioc_g_audio)
1191 memset(p,0,sizeof(*p));
1193 dbgarg(cmd, "Get for index=%d\n", p->index);
1194 ret=vfd->vidioc_g_audio(file, fh, p);
1196 dbgarg2("index=%d, name=%s, capability=%d, "
1197 "mode=%d\n",p->index,
1198 p->name,p->capability, p->mode);
1201 case VIDIOC_S_AUDIO:
1203 struct v4l2_audio *p=arg;
1205 if (!vfd->vidioc_s_audio)
1207 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1208 "mode=%d\n", p->index, p->name,
1209 p->capability, p->mode);
1210 ret=vfd->vidioc_s_audio(file, fh, p);
1213 case VIDIOC_ENUMAUDOUT:
1215 struct v4l2_audioout *p=arg;
1217 if (!vfd->vidioc_enumaudout)
1219 dbgarg(cmd, "Enum for index=%d\n", p->index);
1220 ret=vfd->vidioc_enumaudout(file, fh, p);
1222 dbgarg2("index=%d, name=%s, capability=%d, "
1223 "mode=%d\n", p->index, p->name,
1224 p->capability,p->mode);
1227 case VIDIOC_G_AUDOUT:
1229 struct v4l2_audioout *p=arg;
1231 if (!vfd->vidioc_g_audout)
1233 dbgarg(cmd, "Enum for index=%d\n", p->index);
1234 ret=vfd->vidioc_g_audout(file, fh, p);
1236 dbgarg2("index=%d, name=%s, capability=%d, "
1237 "mode=%d\n", p->index, p->name,
1238 p->capability,p->mode);
1241 case VIDIOC_S_AUDOUT:
1243 struct v4l2_audioout *p=arg;
1245 if (!vfd->vidioc_s_audout)
1247 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1248 "mode=%d\n", p->index, p->name,
1249 p->capability,p->mode);
1251 ret=vfd->vidioc_s_audout(file, fh, p);
1254 case VIDIOC_G_MODULATOR:
1256 struct v4l2_modulator *p=arg;
1257 if (!vfd->vidioc_g_modulator)
1259 ret=vfd->vidioc_g_modulator(file, fh, p);
1261 dbgarg(cmd, "index=%d, name=%s, "
1262 "capability=%d, rangelow=%d,"
1263 " rangehigh=%d, txsubchans=%d\n",
1264 p->index, p->name,p->capability,
1265 p->rangelow, p->rangehigh,
1269 case VIDIOC_S_MODULATOR:
1271 struct v4l2_modulator *p=arg;
1272 if (!vfd->vidioc_s_modulator)
1274 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1275 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1276 p->index, p->name,p->capability,p->rangelow,
1277 p->rangehigh,p->txsubchans);
1278 ret=vfd->vidioc_s_modulator(file, fh, p);
1283 struct v4l2_crop *p=arg;
1284 if (!vfd->vidioc_g_crop)
1286 ret=vfd->vidioc_g_crop(file, fh, p);
1288 dbgarg(cmd, "type=%d\n", p->type);
1289 dbgrect(vfd, "", &p->c);
1295 struct v4l2_crop *p=arg;
1296 if (!vfd->vidioc_s_crop)
1298 dbgarg(cmd, "type=%d\n", p->type);
1299 dbgrect(vfd, "", &p->c);
1300 ret=vfd->vidioc_s_crop(file, fh, p);
1303 case VIDIOC_CROPCAP:
1305 struct v4l2_cropcap *p=arg;
1306 /*FIXME: Should also show v4l2_fract pixelaspect */
1307 if (!vfd->vidioc_cropcap)
1309 dbgarg(cmd, "type=%d\n", p->type);
1310 dbgrect(vfd, "bounds ", &p->bounds);
1311 dbgrect(vfd, "defrect ", &p->defrect);
1312 ret=vfd->vidioc_cropcap(file, fh, p);
1315 case VIDIOC_G_MPEGCOMP:
1317 struct v4l2_mpeg_compression *p=arg;
1319 /*FIXME: Several fields not shown */
1320 if (!vfd->vidioc_g_mpegcomp)
1322 ret=vfd->vidioc_g_mpegcomp(file, fh, p);
1324 dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d,"
1325 " ts_pid_video=%d, ts_pid_pcr=%d, "
1326 "ps_size=%d, au_sample_rate=%d, "
1327 "au_pesid=%c, vi_frame_rate=%d, "
1328 "vi_frames_per_gop=%d, "
1329 "vi_bframes_count=%d, vi_pesid=%c\n",
1330 p->ts_pid_pmt,p->ts_pid_audio,
1331 p->ts_pid_video,p->ts_pid_pcr,
1332 p->ps_size, p->au_sample_rate,
1333 p->au_pesid, p->vi_frame_rate,
1334 p->vi_frames_per_gop,
1335 p->vi_bframes_count, p->vi_pesid);
1338 case VIDIOC_S_MPEGCOMP:
1340 struct v4l2_mpeg_compression *p=arg;
1341 /*FIXME: Several fields not shown */
1342 if (!vfd->vidioc_s_mpegcomp)
1344 dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d, "
1345 "ts_pid_video=%d, ts_pid_pcr=%d, ps_size=%d, "
1346 "au_sample_rate=%d, au_pesid=%c, "
1347 "vi_frame_rate=%d, vi_frames_per_gop=%d, "
1348 "vi_bframes_count=%d, vi_pesid=%c\n",
1349 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
1350 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
1351 p->au_pesid, p->vi_frame_rate,
1352 p->vi_frames_per_gop, p->vi_bframes_count,
1354 ret=vfd->vidioc_s_mpegcomp(file, fh, p);
1357 case VIDIOC_G_JPEGCOMP:
1359 struct v4l2_jpegcompression *p=arg;
1360 if (!vfd->vidioc_g_jpegcomp)
1362 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1364 dbgarg (cmd, "quality=%d, APPn=%d, "
1365 "APP_len=%d, COM_len=%d, "
1366 "jpeg_markers=%d\n",
1367 p->quality,p->APPn,p->APP_len,
1368 p->COM_len,p->jpeg_markers);
1371 case VIDIOC_S_JPEGCOMP:
1373 struct v4l2_jpegcompression *p=arg;
1374 if (!vfd->vidioc_g_jpegcomp)
1376 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1377 "COM_len=%d, jpeg_markers=%d\n",
1378 p->quality,p->APPn,p->APP_len,
1379 p->COM_len,p->jpeg_markers);
1380 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1383 case VIDIOC_G_ENC_INDEX:
1385 struct v4l2_enc_idx *p=arg;
1387 if (!vfd->vidioc_g_enc_index)
1389 ret=vfd->vidioc_g_enc_index(file, fh, p);
1391 dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1392 p->entries,p->entries_cap);
1395 case VIDIOC_ENCODER_CMD:
1397 struct v4l2_encoder_cmd *p=arg;
1399 if (!vfd->vidioc_encoder_cmd)
1401 ret=vfd->vidioc_encoder_cmd(file, fh, p);
1403 dbgarg (cmd, "cmd=%d, flags=%d\n",
1407 case VIDIOC_TRY_ENCODER_CMD:
1409 struct v4l2_encoder_cmd *p=arg;
1411 if (!vfd->vidioc_try_encoder_cmd)
1413 ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
1415 dbgarg (cmd, "cmd=%d, flags=%d\n",
1421 struct v4l2_streamparm *p=arg;
1424 memset(p,0,sizeof(*p));
1427 if (vfd->vidioc_g_parm) {
1428 ret=vfd->vidioc_g_parm(file, fh, p);
1430 struct v4l2_standard s;
1432 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1435 v4l2_video_std_construct(&s, vfd->current_norm,
1436 v4l2_norm_to_name(vfd->current_norm));
1438 p->parm.capture.timeperframe = s.frameperiod;
1442 dbgarg (cmd, "type=%d\n", p->type);
1447 struct v4l2_streamparm *p=arg;
1448 if (!vfd->vidioc_s_parm)
1450 dbgarg (cmd, "type=%d\n", p->type);
1451 ret=vfd->vidioc_s_parm(file, fh, p);
1454 case VIDIOC_G_TUNER:
1456 struct v4l2_tuner *p=arg;
1457 __u32 index=p->index;
1459 if (!vfd->vidioc_g_tuner)
1462 memset(p,0,sizeof(*p));
1465 ret=vfd->vidioc_g_tuner(file, fh, p);
1467 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1468 "capability=%d, rangelow=%d, "
1469 "rangehigh=%d, signal=%d, afc=%d, "
1470 "rxsubchans=%d, audmode=%d\n",
1471 p->index, p->name, p->type,
1472 p->capability, p->rangelow,
1473 p->rangehigh, p->rxsubchans,
1474 p->audmode, p->signal, p->afc);
1477 case VIDIOC_S_TUNER:
1479 struct v4l2_tuner *p=arg;
1480 if (!vfd->vidioc_s_tuner)
1482 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1483 "capability=%d, rangelow=%d, rangehigh=%d, "
1484 "signal=%d, afc=%d, rxsubchans=%d, "
1485 "audmode=%d\n",p->index, p->name, p->type,
1486 p->capability, p->rangelow,p->rangehigh,
1487 p->rxsubchans, p->audmode, p->signal,
1489 ret=vfd->vidioc_s_tuner(file, fh, p);
1492 case VIDIOC_G_FREQUENCY:
1494 struct v4l2_frequency *p=arg;
1495 if (!vfd->vidioc_g_frequency)
1498 memset(p,0,sizeof(*p));
1500 ret=vfd->vidioc_g_frequency(file, fh, p);
1502 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1503 p->tuner,p->type,p->frequency);
1506 case VIDIOC_S_FREQUENCY:
1508 struct v4l2_frequency *p=arg;
1509 if (!vfd->vidioc_s_frequency)
1511 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1512 p->tuner,p->type,p->frequency);
1513 ret=vfd->vidioc_s_frequency(file, fh, p);
1516 case VIDIOC_G_SLICED_VBI_CAP:
1518 struct v4l2_sliced_vbi_cap *p=arg;
1519 if (!vfd->vidioc_g_sliced_vbi_cap)
1521 ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1523 dbgarg (cmd, "service_set=%d\n", p->service_set);
1526 case VIDIOC_LOG_STATUS:
1528 if (!vfd->vidioc_log_status)
1530 ret=vfd->vidioc_log_status(file, fh);
1533 #ifdef CONFIG_VIDEO_ADV_DEBUG
1534 case VIDIOC_DBG_G_REGISTER:
1536 struct v4l2_register *p=arg;
1537 if (!capable(CAP_SYS_ADMIN))
1539 else if (vfd->vidioc_g_register)
1540 ret=vfd->vidioc_g_register(file, fh, p);
1543 case VIDIOC_DBG_S_REGISTER:
1545 struct v4l2_register *p=arg;
1546 if (!capable(CAP_SYS_ADMIN))
1548 else if (vfd->vidioc_s_register)
1549 ret=vfd->vidioc_s_register(file, fh, p);
1553 case VIDIOC_G_CHIP_IDENT:
1555 struct v4l2_chip_ident *p=arg;
1556 if (!vfd->vidioc_g_chip_ident)
1558 ret=vfd->vidioc_g_chip_ident(file, fh, p);
1560 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1565 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1567 printk ("%s: err:\n", vfd->name);
1568 v4l_print_ioctl(vfd->name, cmd);
1575 int video_ioctl2 (struct inode *inode, struct file *file,
1576 unsigned int cmd, unsigned long arg)
1583 size_t ctrls_size = 0;
1584 void __user *user_ptr = NULL;
1586 #ifdef __OLD_VIDIOC_
1587 cmd = video_fix_command(cmd);
1589 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1590 cmd == VIDIOC_TRY_EXT_CTRLS);
1592 /* Copy arguments into temp kernel buffer */
1593 switch (_IOC_DIR(cmd)) {
1599 case (_IOC_WRITE | _IOC_READ):
1600 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1603 /* too big to allocate from stack */
1604 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1611 if (_IOC_DIR(cmd) & _IOC_WRITE)
1612 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1618 struct v4l2_ext_controls *p = parg;
1620 /* In case of an error, tell the caller that it wasn't
1621 a specific control that caused it. */
1622 p->error_idx = p->count;
1623 user_ptr = (void __user *)p->controls;
1625 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1626 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1627 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1632 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1639 err = __video_do_ioctl(inode, file, cmd, parg);
1640 if (err == -ENOIOCTLCMD)
1643 struct v4l2_ext_controls *p = parg;
1645 p->controls = (void *)user_ptr;
1646 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1654 /* Copy results into user buffer */
1655 switch (_IOC_DIR(cmd))
1658 case (_IOC_WRITE | _IOC_READ):
1659 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1670 static const struct file_operations video_fops;
1673 * video_register_device - register video4linux devices
1674 * @vfd: video device structure we want to register
1675 * @type: type of device to register
1676 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
1679 * The registration code assigns minor numbers based on the type
1680 * requested. -ENFILE is returned in all the device slots for this
1681 * category are full. If not then the minor field is set and the
1682 * driver initialize function is called (if non %NULL).
1684 * Zero is returned on success.
1688 * %VFL_TYPE_GRABBER - A frame grabber
1690 * %VFL_TYPE_VTX - A teletext device
1692 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
1694 * %VFL_TYPE_RADIO - A radio card
1697 int video_register_device(struct video_device *vfd, int type, int nr)
1707 case VFL_TYPE_GRABBER:
1708 base=MINOR_VFL_TYPE_GRABBER_MIN;
1709 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
1710 name_base = "video";
1713 base=MINOR_VFL_TYPE_VTX_MIN;
1714 end=MINOR_VFL_TYPE_VTX_MAX+1;
1718 base=MINOR_VFL_TYPE_VBI_MIN;
1719 end=MINOR_VFL_TYPE_VBI_MAX+1;
1722 case VFL_TYPE_RADIO:
1723 base=MINOR_VFL_TYPE_RADIO_MIN;
1724 end=MINOR_VFL_TYPE_RADIO_MAX+1;
1725 name_base = "radio";
1728 printk(KERN_ERR "%s called with unknown type: %d\n",
1729 __FUNCTION__, type);
1733 /* pick a minor number */
1734 mutex_lock(&videodev_lock);
1735 if (nr >= 0 && nr < end-base) {
1736 /* use the one the driver asked for */
1738 if (NULL != video_device[i]) {
1739 mutex_unlock(&videodev_lock);
1743 /* use first free */
1744 for(i=base;i<end;i++)
1745 if (NULL == video_device[i])
1748 mutex_unlock(&videodev_lock);
1752 video_device[i]=vfd;
1754 mutex_unlock(&videodev_lock);
1755 mutex_init(&vfd->lock);
1758 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
1760 vfd->class_dev.parent = vfd->dev;
1761 vfd->class_dev.class = &video_class;
1762 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
1763 sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
1764 ret = device_register(&vfd->class_dev);
1766 printk(KERN_ERR "%s: device_register failed\n",
1772 /* needed until all drivers are fixed */
1774 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
1775 "Please fix your driver for proper sysfs support, see "
1776 "http://lwn.net/Articles/36850/\n", vfd->name);
1781 mutex_lock(&videodev_lock);
1782 video_device[vfd->minor] = NULL;
1784 mutex_unlock(&videodev_lock);
1789 * video_unregister_device - unregister a video4linux device
1790 * @vfd: the device to unregister
1792 * This unregisters the passed device and deassigns the minor
1793 * number. Future open calls will be met with errors.
1796 void video_unregister_device(struct video_device *vfd)
1798 mutex_lock(&videodev_lock);
1799 if(video_device[vfd->minor]!=vfd)
1800 panic("videodev: bad unregister");
1802 video_device[vfd->minor]=NULL;
1803 device_unregister(&vfd->class_dev);
1804 mutex_unlock(&videodev_lock);
1808 * Video fs operations
1810 static const struct file_operations video_fops=
1812 .owner = THIS_MODULE,
1813 .llseek = no_llseek,
1818 * Initialise video for linux
1821 static int __init videodev_init(void)
1825 printk(KERN_INFO "Linux video capture interface: v2.00\n");
1826 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
1827 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
1831 ret = class_register(&video_class);
1833 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
1834 printk(KERN_WARNING "video_dev: class_register failed\n");
1841 static void __exit videodev_exit(void)
1843 class_unregister(&video_class);
1844 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
1847 module_init(videodev_init)
1848 module_exit(videodev_exit)
1850 EXPORT_SYMBOL(video_register_device);
1851 EXPORT_SYMBOL(video_unregister_device);
1852 EXPORT_SYMBOL(video_devdata);
1853 EXPORT_SYMBOL(video_usercopy);
1854 EXPORT_SYMBOL(video_exclusive_open);
1855 EXPORT_SYMBOL(video_exclusive_release);
1856 EXPORT_SYMBOL(video_ioctl2);
1857 EXPORT_SYMBOL(video_device_alloc);
1858 EXPORT_SYMBOL(video_device_release);
1860 MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
1861 MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
1862 MODULE_LICENSE("GPL");