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 class_device *cd, char *buf)
59 struct video_device *vfd = container_of(cd, struct video_device,
61 return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
64 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
66 struct video_device *video_device_alloc(void)
68 struct video_device *vfd;
70 vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
74 void video_device_release(struct video_device *vfd)
79 static void video_release(struct class_device *cd)
81 struct video_device *vfd = container_of(cd, struct video_device,
85 /* needed until all drivers are fixed */
92 static struct class video_class = {
94 .release = video_release,
101 static struct video_device *video_device[VIDEO_NUM_DEVICES];
102 static DEFINE_MUTEX(videodev_lock);
104 struct video_device* video_devdata(struct file *file)
106 return video_device[iminor(file->f_path.dentry->d_inode)];
110 * Open a video device - FIXME: Obsoleted
112 static int video_open(struct inode *inode, struct file *file)
114 unsigned int minor = iminor(inode);
116 struct video_device *vfl;
117 const struct file_operations *old_fops;
119 if(minor>=VIDEO_NUM_DEVICES)
121 mutex_lock(&videodev_lock);
122 vfl=video_device[minor];
124 mutex_unlock(&videodev_lock);
125 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
126 mutex_lock(&videodev_lock);
127 vfl=video_device[minor];
129 mutex_unlock(&videodev_lock);
133 old_fops = file->f_op;
134 file->f_op = fops_get(vfl->fops);
136 err = file->f_op->open(inode,file);
138 fops_put(file->f_op);
139 file->f_op = fops_get(old_fops);
142 mutex_unlock(&videodev_lock);
147 * helper function -- handles userspace copying for ioctl arguments
152 video_fix_command(unsigned int cmd)
155 case VIDIOC_OVERLAY_OLD:
156 cmd = VIDIOC_OVERLAY;
158 case VIDIOC_S_PARM_OLD:
161 case VIDIOC_S_CTRL_OLD:
164 case VIDIOC_G_AUDIO_OLD:
165 cmd = VIDIOC_G_AUDIO;
167 case VIDIOC_G_AUDOUT_OLD:
168 cmd = VIDIOC_G_AUDOUT;
170 case VIDIOC_CROPCAP_OLD:
171 cmd = VIDIOC_CROPCAP;
179 * Obsolete usercopy function - Should be removed soon
182 video_usercopy(struct inode *inode, struct file *file,
183 unsigned int cmd, unsigned long arg,
184 int (*func)(struct inode *inode, struct file *file,
185 unsigned int cmd, void *arg))
192 size_t ctrls_size = 0;
193 void __user *user_ptr = NULL;
196 cmd = video_fix_command(cmd);
198 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
199 cmd == VIDIOC_TRY_EXT_CTRLS);
201 /* Copy arguments into temp kernel buffer */
202 switch (_IOC_DIR(cmd)) {
208 case (_IOC_WRITE | _IOC_READ):
209 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
212 /* too big to allocate from stack */
213 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
220 if (_IOC_DIR(cmd) & _IOC_WRITE)
221 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
226 struct v4l2_ext_controls *p = parg;
228 /* In case of an error, tell the caller that it wasn't
229 a specific control that caused it. */
230 p->error_idx = p->count;
231 user_ptr = (void __user *)p->controls;
233 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
234 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
235 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
240 if (copy_from_user(mbuf, user_ptr, ctrls_size))
247 err = func(inode, file, cmd, parg);
248 if (err == -ENOIOCTLCMD)
251 struct v4l2_ext_controls *p = parg;
253 p->controls = (void *)user_ptr;
254 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
262 /* Copy results into user buffer */
263 switch (_IOC_DIR(cmd))
266 case (_IOC_WRITE | _IOC_READ):
267 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
278 * open/release helper functions -- handle exclusive opens
279 * Should be removed soon
281 int video_exclusive_open(struct inode *inode, struct file *file)
283 struct video_device *vfl = video_devdata(file);
286 mutex_lock(&vfl->lock);
292 mutex_unlock(&vfl->lock);
296 int video_exclusive_release(struct inode *inode, struct file *file)
298 struct video_device *vfl = video_devdata(file);
304 static char *v4l2_memory_names[] = {
305 [V4L2_MEMORY_MMAP] = "mmap",
306 [V4L2_MEMORY_USERPTR] = "userptr",
307 [V4L2_MEMORY_OVERLAY] = "overlay",
311 /* FIXME: Those stuff are replicated also on v4l2-common.c */
312 static char *v4l2_type_names_FIXME[] = {
313 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
314 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
315 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
316 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
317 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
318 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
319 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture",
320 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
321 [V4L2_BUF_TYPE_PRIVATE] = "private",
324 static char *v4l2_field_names_FIXME[] = {
325 [V4L2_FIELD_ANY] = "any",
326 [V4L2_FIELD_NONE] = "none",
327 [V4L2_FIELD_TOP] = "top",
328 [V4L2_FIELD_BOTTOM] = "bottom",
329 [V4L2_FIELD_INTERLACED] = "interlaced",
330 [V4L2_FIELD_SEQ_TB] = "seq-tb",
331 [V4L2_FIELD_SEQ_BT] = "seq-bt",
332 [V4L2_FIELD_ALTERNATE] = "alternate",
333 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
334 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
337 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
339 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
340 struct v4l2_buffer *p)
342 struct v4l2_timecode *tc=&p->timecode;
344 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
345 "bytesused=%d, flags=0x%08d, "
346 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
347 (p->timestamp.tv_sec/3600),
348 (int)(p->timestamp.tv_sec/60)%60,
349 (int)(p->timestamp.tv_sec%60),
350 p->timestamp.tv_usec,
352 prt_names(p->type,v4l2_type_names_FIXME),
353 p->bytesused,p->flags,
354 p->field,p->sequence,
355 prt_names(p->memory,v4l2_memory_names),
356 p->m.userptr, p->length);
357 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
358 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
359 tc->hours,tc->minutes,tc->seconds,
360 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
363 static inline void dbgrect(struct video_device *vfd, char *s,
366 dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
367 r->width, r->height);
370 static inline void v4l_print_pix_fmt (struct video_device *vfd,
371 struct v4l2_pix_format *fmt)
373 dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
374 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
375 fmt->width,fmt->height,
376 (fmt->pixelformat & 0xff),
377 (fmt->pixelformat >> 8) & 0xff,
378 (fmt->pixelformat >> 16) & 0xff,
379 (fmt->pixelformat >> 24) & 0xff,
380 prt_names(fmt->field,v4l2_field_names_FIXME),
381 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
385 static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
388 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
389 if (vfd->vidioc_try_fmt_cap)
392 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
393 if (vfd->vidioc_try_fmt_overlay)
396 case V4L2_BUF_TYPE_VBI_CAPTURE:
397 if (vfd->vidioc_try_fmt_vbi)
400 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
401 if (vfd->vidioc_try_fmt_vbi_output)
404 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
405 if (vfd->vidioc_try_fmt_vbi_capture)
408 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
409 if (vfd->vidioc_try_fmt_video_output)
412 case V4L2_BUF_TYPE_VBI_OUTPUT:
413 if (vfd->vidioc_try_fmt_vbi_output)
416 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
417 if (vfd->vidioc_try_fmt_output_overlay)
420 case V4L2_BUF_TYPE_PRIVATE:
421 if (vfd->vidioc_try_fmt_type_private)
428 static int __video_do_ioctl(struct inode *inode, struct file *file,
429 unsigned int cmd, void *arg)
431 struct video_device *vfd = video_devdata(file);
432 void *fh = file->private_data;
435 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
436 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
437 v4l_print_ioctl(vfd->name, cmd);
440 #ifdef CONFIG_VIDEO_V4L1_COMPAT
441 /***********************************************************
442 Handles calls to the obsoleted V4L1 API
443 Due to the nature of VIDIOCGMBUF, each driver that supports
444 V4L1 should implement its own handler for this ioctl.
445 ***********************************************************/
447 /* --- streaming capture ------------------------------------- */
448 if (cmd == VIDIOCGMBUF) {
449 struct video_mbuf *p=arg;
451 memset(p,0,sizeof(p));
453 if (!vfd->vidiocgmbuf)
455 ret=vfd->vidiocgmbuf(file, fh, p);
457 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
459 (unsigned long)p->offsets);
463 /********************************************************
464 All other V4L1 calls are handled by v4l1_compat module.
465 Those calls will be translated into V4L2 calls, and
466 __video_do_ioctl will be called again, with one or more
468 ********************************************************/
469 if (_IOC_TYPE(cmd)=='v')
470 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
475 /* --- capabilities ------------------------------------------ */
476 case VIDIOC_QUERYCAP:
478 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
479 memset(cap, 0, sizeof(*cap));
481 if (!vfd->vidioc_querycap)
484 ret=vfd->vidioc_querycap(file, fh, cap);
486 dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
488 "capabilities=0x%08x\n",
489 cap->driver,cap->card,cap->bus_info,
495 /* --- priority ------------------------------------------ */
496 case VIDIOC_G_PRIORITY:
498 enum v4l2_priority *p=arg;
500 if (!vfd->vidioc_g_priority)
502 ret=vfd->vidioc_g_priority(file, fh, p);
504 dbgarg(cmd, "priority is %d\n", *p);
507 case VIDIOC_S_PRIORITY:
509 enum v4l2_priority *p=arg;
511 if (!vfd->vidioc_s_priority)
513 dbgarg(cmd, "setting priority to %d\n", *p);
514 ret=vfd->vidioc_s_priority(file, fh, *p);
518 /* --- capture ioctls ---------------------------------------- */
519 case VIDIOC_ENUM_FMT:
521 struct v4l2_fmtdesc *f = arg;
522 enum v4l2_buf_type type;
527 memset(f,0,sizeof(*f));
532 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
533 if (vfd->vidioc_enum_fmt_cap)
534 ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
536 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
537 if (vfd->vidioc_enum_fmt_overlay)
538 ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
540 case V4L2_BUF_TYPE_VBI_CAPTURE:
541 if (vfd->vidioc_enum_fmt_vbi)
542 ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
544 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
545 if (vfd->vidioc_enum_fmt_vbi_output)
546 ret=vfd->vidioc_enum_fmt_vbi_output(file,
549 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
550 if (vfd->vidioc_enum_fmt_vbi_capture)
551 ret=vfd->vidioc_enum_fmt_vbi_capture(file,
554 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
555 if (vfd->vidioc_enum_fmt_video_output)
556 ret=vfd->vidioc_enum_fmt_video_output(file,
559 case V4L2_BUF_TYPE_VBI_OUTPUT:
560 if (vfd->vidioc_enum_fmt_vbi_output)
561 ret=vfd->vidioc_enum_fmt_vbi_output(file,
564 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
565 if (vfd->vidioc_enum_fmt_output_overlay)
566 ret=vfd->vidioc_enum_fmt_output_overlay(file, fh, f);
568 case V4L2_BUF_TYPE_PRIVATE:
569 if (vfd->vidioc_enum_fmt_type_private)
570 ret=vfd->vidioc_enum_fmt_type_private(file,
575 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
576 "pixelformat=%c%c%c%c, description='%s'\n",
577 f->index, f->type, f->flags,
578 (f->pixelformat & 0xff),
579 (f->pixelformat >> 8) & 0xff,
580 (f->pixelformat >> 16) & 0xff,
581 (f->pixelformat >> 24) & 0xff,
587 struct v4l2_format *f = (struct v4l2_format *)arg;
588 enum v4l2_buf_type type=f->type;
590 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
593 /* FIXME: Should be one dump per type */
594 dbgarg (cmd, "type=%s\n", prt_names(type,
595 v4l2_type_names_FIXME));
598 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
599 if (vfd->vidioc_g_fmt_cap)
600 ret=vfd->vidioc_g_fmt_cap(file, fh, f);
602 v4l_print_pix_fmt(vfd,&f->fmt.pix);
604 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
605 if (vfd->vidioc_g_fmt_overlay)
606 ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
608 case V4L2_BUF_TYPE_VBI_CAPTURE:
609 if (vfd->vidioc_g_fmt_vbi)
610 ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
612 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
613 if (vfd->vidioc_g_fmt_vbi_output)
614 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
616 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
617 if (vfd->vidioc_g_fmt_vbi_capture)
618 ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
620 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
621 if (vfd->vidioc_g_fmt_video_output)
622 ret=vfd->vidioc_g_fmt_video_output(file,
625 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
626 if (vfd->vidioc_g_fmt_output_overlay)
627 ret=vfd->vidioc_g_fmt_output_overlay(file, fh, f);
629 case V4L2_BUF_TYPE_VBI_OUTPUT:
630 if (vfd->vidioc_g_fmt_vbi_output)
631 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
633 case V4L2_BUF_TYPE_PRIVATE:
634 if (vfd->vidioc_g_fmt_type_private)
635 ret=vfd->vidioc_g_fmt_type_private(file,
644 struct v4l2_format *f = (struct v4l2_format *)arg;
646 /* FIXME: Should be one dump per type */
647 dbgarg (cmd, "type=%s\n", prt_names(f->type,
648 v4l2_type_names_FIXME));
651 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
652 v4l_print_pix_fmt(vfd,&f->fmt.pix);
653 if (vfd->vidioc_s_fmt_cap)
654 ret=vfd->vidioc_s_fmt_cap(file, fh, f);
656 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
657 if (vfd->vidioc_s_fmt_overlay)
658 ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
660 case V4L2_BUF_TYPE_VBI_CAPTURE:
661 if (vfd->vidioc_s_fmt_vbi)
662 ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
664 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
665 if (vfd->vidioc_s_fmt_vbi_output)
666 ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
668 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
669 if (vfd->vidioc_s_fmt_vbi_capture)
670 ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
672 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
673 if (vfd->vidioc_s_fmt_video_output)
674 ret=vfd->vidioc_s_fmt_video_output(file,
677 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
678 if (vfd->vidioc_s_fmt_output_overlay)
679 ret=vfd->vidioc_s_fmt_output_overlay(file, fh, f);
681 case V4L2_BUF_TYPE_VBI_OUTPUT:
682 if (vfd->vidioc_s_fmt_vbi_output)
683 ret=vfd->vidioc_s_fmt_vbi_output(file,
686 case V4L2_BUF_TYPE_PRIVATE:
687 if (vfd->vidioc_s_fmt_type_private)
688 ret=vfd->vidioc_s_fmt_type_private(file,
696 struct v4l2_format *f = (struct v4l2_format *)arg;
698 /* FIXME: Should be one dump per type */
699 dbgarg (cmd, "type=%s\n", prt_names(f->type,
700 v4l2_type_names_FIXME));
702 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
703 if (vfd->vidioc_try_fmt_cap)
704 ret=vfd->vidioc_try_fmt_cap(file, fh, f);
706 v4l_print_pix_fmt(vfd,&f->fmt.pix);
708 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
709 if (vfd->vidioc_try_fmt_overlay)
710 ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
712 case V4L2_BUF_TYPE_VBI_CAPTURE:
713 if (vfd->vidioc_try_fmt_vbi)
714 ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
716 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
717 if (vfd->vidioc_try_fmt_vbi_output)
718 ret=vfd->vidioc_try_fmt_vbi_output(file,
721 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
722 if (vfd->vidioc_try_fmt_vbi_capture)
723 ret=vfd->vidioc_try_fmt_vbi_capture(file,
726 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
727 if (vfd->vidioc_try_fmt_video_output)
728 ret=vfd->vidioc_try_fmt_video_output(file,
731 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
732 if (vfd->vidioc_try_fmt_output_overlay)
733 ret=vfd->vidioc_try_fmt_output_overlay(file, fh, f);
735 case V4L2_BUF_TYPE_VBI_OUTPUT:
736 if (vfd->vidioc_try_fmt_vbi_output)
737 ret=vfd->vidioc_try_fmt_vbi_output(file,
740 case V4L2_BUF_TYPE_PRIVATE:
741 if (vfd->vidioc_try_fmt_type_private)
742 ret=vfd->vidioc_try_fmt_type_private(file,
749 /* FIXME: Those buf reqs could be handled here,
750 with some changes on videobuf to allow its header to be included at
751 videodev2.h or being merged at videodev2.
755 struct v4l2_requestbuffers *p=arg;
757 if (!vfd->vidioc_reqbufs)
759 ret = check_fmt (vfd, p->type);
763 ret=vfd->vidioc_reqbufs(file, fh, p);
764 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
766 prt_names(p->type,v4l2_type_names_FIXME),
767 prt_names(p->memory,v4l2_memory_names));
770 case VIDIOC_QUERYBUF:
772 struct v4l2_buffer *p=arg;
774 if (!vfd->vidioc_querybuf)
776 ret = check_fmt (vfd, p->type);
780 ret=vfd->vidioc_querybuf(file, fh, p);
787 struct v4l2_buffer *p=arg;
789 if (!vfd->vidioc_qbuf)
791 ret = check_fmt (vfd, p->type);
795 ret=vfd->vidioc_qbuf(file, fh, p);
802 struct v4l2_buffer *p=arg;
803 if (!vfd->vidioc_dqbuf)
805 ret = check_fmt (vfd, p->type);
809 ret=vfd->vidioc_dqbuf(file, fh, p);
818 if (!vfd->vidioc_overlay)
820 dbgarg (cmd, "value=%d\n",*i);
821 ret=vfd->vidioc_overlay(file, fh, *i);
826 struct v4l2_framebuffer *p=arg;
827 if (!vfd->vidioc_g_fbuf)
829 ret=vfd->vidioc_g_fbuf(file, fh, arg);
831 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
832 p->capability,p->flags,
833 (unsigned long)p->base);
834 v4l_print_pix_fmt (vfd, &p->fmt);
840 struct v4l2_framebuffer *p=arg;
841 if (!vfd->vidioc_s_fbuf)
844 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
845 p->capability,p->flags,(unsigned long)p->base);
846 v4l_print_pix_fmt (vfd, &p->fmt);
847 ret=vfd->vidioc_s_fbuf(file, fh, arg);
851 case VIDIOC_STREAMON:
853 enum v4l2_buf_type i = *(int *)arg;
854 if (!vfd->vidioc_streamon)
856 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
857 ret=vfd->vidioc_streamon(file, fh,i);
860 case VIDIOC_STREAMOFF:
862 enum v4l2_buf_type i = *(int *)arg;
864 if (!vfd->vidioc_streamoff)
866 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
867 ret=vfd->vidioc_streamoff(file, fh, i);
870 /* ---------- tv norms ---------- */
873 struct v4l2_standard *p = arg;
874 v4l2_std_id id = vfd->tvnorms,curr_id=0;
875 unsigned int index = p->index,i;
882 /* Return norm array on a canonical way */
883 for (i=0;i<= index && id; i++) {
884 if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) {
885 curr_id = V4L2_STD_PAL;
886 } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) {
887 curr_id = V4L2_STD_PAL_BG;
888 } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) {
889 curr_id = V4L2_STD_PAL_DK;
890 } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) {
891 curr_id = V4L2_STD_PAL_B;
892 } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) {
893 curr_id = V4L2_STD_PAL_B1;
894 } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) {
895 curr_id = V4L2_STD_PAL_G;
896 } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) {
897 curr_id = V4L2_STD_PAL_H;
898 } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) {
899 curr_id = V4L2_STD_PAL_I;
900 } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) {
901 curr_id = V4L2_STD_PAL_D;
902 } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) {
903 curr_id = V4L2_STD_PAL_D1;
904 } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) {
905 curr_id = V4L2_STD_PAL_K;
906 } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) {
907 curr_id = V4L2_STD_PAL_M;
908 } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) {
909 curr_id = V4L2_STD_PAL_N;
910 } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) {
911 curr_id = V4L2_STD_PAL_Nc;
912 } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) {
913 curr_id = V4L2_STD_PAL_60;
914 } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
915 curr_id = V4L2_STD_NTSC;
916 } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) {
917 curr_id = V4L2_STD_NTSC_M;
918 } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) {
919 curr_id = V4L2_STD_NTSC_M_JP;
920 } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) {
921 curr_id = V4L2_STD_NTSC_443;
922 } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) {
923 curr_id = V4L2_STD_NTSC_M_KR;
924 } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
925 curr_id = V4L2_STD_SECAM;
926 } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) {
927 curr_id = V4L2_STD_SECAM_DK;
928 } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) {
929 curr_id = V4L2_STD_SECAM_B;
930 } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) {
931 curr_id = V4L2_STD_SECAM_D;
932 } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) {
933 curr_id = V4L2_STD_SECAM_G;
934 } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) {
935 curr_id = V4L2_STD_SECAM_H;
936 } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) {
937 curr_id = V4L2_STD_SECAM_K;
938 } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) {
939 curr_id = V4L2_STD_SECAM_K1;
940 } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) {
941 curr_id = V4L2_STD_SECAM_L;
942 } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) {
943 curr_id = V4L2_STD_SECAM_LC;
952 v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id));
955 dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
956 "framelines=%d\n", p->index,
957 (unsigned long long)p->id, p->name,
958 p->frameperiod.numerator,
959 p->frameperiod.denominator,
967 v4l2_std_id *id = arg;
969 *id = vfd->current_norm;
971 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
978 v4l2_std_id *id = arg,norm;
980 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
982 norm = (*id) & vfd->tvnorms;
983 if ( vfd->tvnorms && !norm) /* Check if std is supported */
986 /* Calls the specific handler */
987 if (vfd->vidioc_s_std)
988 ret=vfd->vidioc_s_std(file, fh, &norm);
992 /* Updates standard information */
994 vfd->current_norm=norm;
998 case VIDIOC_QUERYSTD:
1002 if (!vfd->vidioc_querystd)
1004 ret=vfd->vidioc_querystd(file, fh, arg);
1006 dbgarg (cmd, "detected std=%Lu\n",
1007 (unsigned long long)*p);
1010 /* ------ input switching ---------- */
1011 /* FIXME: Inputs can be handled inside videodev2 */
1012 case VIDIOC_ENUMINPUT:
1014 struct v4l2_input *p=arg;
1017 if (!vfd->vidioc_enum_input)
1019 memset(p, 0, sizeof(*p));
1022 ret=vfd->vidioc_enum_input(file, fh, p);
1024 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1026 "tuner=%d, std=%Ld, status=%d\n",
1027 p->index,p->name,p->type,p->audioset,
1029 (unsigned long long)p->std,
1033 case VIDIOC_G_INPUT:
1035 unsigned int *i = arg;
1037 if (!vfd->vidioc_g_input)
1039 ret=vfd->vidioc_g_input(file, fh, i);
1041 dbgarg (cmd, "value=%d\n",*i);
1044 case VIDIOC_S_INPUT:
1046 unsigned int *i = arg;
1048 if (!vfd->vidioc_s_input)
1050 dbgarg (cmd, "value=%d\n",*i);
1051 ret=vfd->vidioc_s_input(file, fh, *i);
1055 /* ------ output switching ---------- */
1056 case VIDIOC_G_OUTPUT:
1058 unsigned int *i = arg;
1060 if (!vfd->vidioc_g_output)
1062 ret=vfd->vidioc_g_output(file, fh, i);
1064 dbgarg (cmd, "value=%d\n",*i);
1067 case VIDIOC_S_OUTPUT:
1069 unsigned int *i = arg;
1071 if (!vfd->vidioc_s_output)
1073 dbgarg (cmd, "value=%d\n",*i);
1074 ret=vfd->vidioc_s_output(file, fh, *i);
1078 /* --- controls ---------------------------------------------- */
1079 case VIDIOC_QUERYCTRL:
1081 struct v4l2_queryctrl *p=arg;
1083 if (!vfd->vidioc_queryctrl)
1085 ret=vfd->vidioc_queryctrl(file, fh, p);
1088 dbgarg (cmd, "id=%d, type=%d, name=%s, "
1090 " step=%d, default=%d, flags=0x%08x\n",
1091 p->id,p->type,p->name,p->minimum,
1092 p->maximum,p->step,p->default_value,
1098 struct v4l2_control *p = arg;
1100 if (!vfd->vidioc_g_ctrl)
1102 dbgarg(cmd, "Enum for index=%d\n", p->id);
1104 ret=vfd->vidioc_g_ctrl(file, fh, p);
1106 dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
1111 struct v4l2_control *p = arg;
1113 if (!vfd->vidioc_s_ctrl)
1115 dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
1117 ret=vfd->vidioc_s_ctrl(file, fh, p);
1120 case VIDIOC_G_EXT_CTRLS:
1122 struct v4l2_ext_controls *p = arg;
1124 if (vfd->vidioc_g_ext_ctrls) {
1125 dbgarg(cmd, "count=%d\n", p->count);
1127 ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
1131 case VIDIOC_S_EXT_CTRLS:
1133 struct v4l2_ext_controls *p = arg;
1135 if (vfd->vidioc_s_ext_ctrls) {
1136 dbgarg(cmd, "count=%d\n", p->count);
1138 ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
1142 case VIDIOC_TRY_EXT_CTRLS:
1144 struct v4l2_ext_controls *p = arg;
1146 if (vfd->vidioc_try_ext_ctrls) {
1147 dbgarg(cmd, "count=%d\n", p->count);
1149 ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
1153 case VIDIOC_QUERYMENU:
1155 struct v4l2_querymenu *p=arg;
1156 if (!vfd->vidioc_querymenu)
1158 ret=vfd->vidioc_querymenu(file, fh, p);
1160 dbgarg (cmd, "id=%d, index=%d, name=%s\n",
1161 p->id,p->index,p->name);
1164 /* --- audio ---------------------------------------------- */
1165 case VIDIOC_ENUMAUDIO:
1167 struct v4l2_audio *p=arg;
1169 if (!vfd->vidioc_enumaudio)
1171 dbgarg(cmd, "Enum for index=%d\n", p->index);
1172 ret=vfd->vidioc_enumaudio(file, fh, p);
1174 dbgarg2("index=%d, name=%s, capability=%d, "
1175 "mode=%d\n",p->index,p->name,
1176 p->capability, p->mode);
1179 case VIDIOC_G_AUDIO:
1181 struct v4l2_audio *p=arg;
1182 __u32 index=p->index;
1184 if (!vfd->vidioc_g_audio)
1187 memset(p,0,sizeof(*p));
1189 dbgarg(cmd, "Get for index=%d\n", p->index);
1190 ret=vfd->vidioc_g_audio(file, fh, p);
1192 dbgarg2("index=%d, name=%s, capability=%d, "
1193 "mode=%d\n",p->index,
1194 p->name,p->capability, p->mode);
1197 case VIDIOC_S_AUDIO:
1199 struct v4l2_audio *p=arg;
1201 if (!vfd->vidioc_s_audio)
1203 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1204 "mode=%d\n", p->index, p->name,
1205 p->capability, p->mode);
1206 ret=vfd->vidioc_s_audio(file, fh, p);
1209 case VIDIOC_ENUMAUDOUT:
1211 struct v4l2_audioout *p=arg;
1213 if (!vfd->vidioc_enumaudout)
1215 dbgarg(cmd, "Enum for index=%d\n", p->index);
1216 ret=vfd->vidioc_enumaudout(file, fh, p);
1218 dbgarg2("index=%d, name=%s, capability=%d, "
1219 "mode=%d\n", p->index, p->name,
1220 p->capability,p->mode);
1223 case VIDIOC_G_AUDOUT:
1225 struct v4l2_audioout *p=arg;
1227 if (!vfd->vidioc_g_audout)
1229 dbgarg(cmd, "Enum for index=%d\n", p->index);
1230 ret=vfd->vidioc_g_audout(file, fh, p);
1232 dbgarg2("index=%d, name=%s, capability=%d, "
1233 "mode=%d\n", p->index, p->name,
1234 p->capability,p->mode);
1237 case VIDIOC_S_AUDOUT:
1239 struct v4l2_audioout *p=arg;
1241 if (!vfd->vidioc_s_audout)
1243 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1244 "mode=%d\n", p->index, p->name,
1245 p->capability,p->mode);
1247 ret=vfd->vidioc_s_audout(file, fh, p);
1250 case VIDIOC_G_MODULATOR:
1252 struct v4l2_modulator *p=arg;
1253 if (!vfd->vidioc_g_modulator)
1255 ret=vfd->vidioc_g_modulator(file, fh, p);
1257 dbgarg(cmd, "index=%d, name=%s, "
1258 "capability=%d, rangelow=%d,"
1259 " rangehigh=%d, txsubchans=%d\n",
1260 p->index, p->name,p->capability,
1261 p->rangelow, p->rangehigh,
1265 case VIDIOC_S_MODULATOR:
1267 struct v4l2_modulator *p=arg;
1268 if (!vfd->vidioc_s_modulator)
1270 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1271 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1272 p->index, p->name,p->capability,p->rangelow,
1273 p->rangehigh,p->txsubchans);
1274 ret=vfd->vidioc_s_modulator(file, fh, p);
1279 struct v4l2_crop *p=arg;
1280 if (!vfd->vidioc_g_crop)
1282 ret=vfd->vidioc_g_crop(file, fh, p);
1284 dbgarg(cmd, "type=%d\n", p->type);
1285 dbgrect(vfd, "", &p->c);
1291 struct v4l2_crop *p=arg;
1292 if (!vfd->vidioc_s_crop)
1294 dbgarg(cmd, "type=%d\n", p->type);
1295 dbgrect(vfd, "", &p->c);
1296 ret=vfd->vidioc_s_crop(file, fh, p);
1299 case VIDIOC_CROPCAP:
1301 struct v4l2_cropcap *p=arg;
1302 /*FIXME: Should also show v4l2_fract pixelaspect */
1303 if (!vfd->vidioc_cropcap)
1305 dbgarg(cmd, "type=%d\n", p->type);
1306 dbgrect(vfd, "bounds ", &p->bounds);
1307 dbgrect(vfd, "defrect ", &p->defrect);
1308 ret=vfd->vidioc_cropcap(file, fh, p);
1311 case VIDIOC_G_MPEGCOMP:
1313 struct v4l2_mpeg_compression *p=arg;
1315 /*FIXME: Several fields not shown */
1316 if (!vfd->vidioc_g_mpegcomp)
1318 ret=vfd->vidioc_g_mpegcomp(file, fh, p);
1320 dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d,"
1321 " ts_pid_video=%d, ts_pid_pcr=%d, "
1322 "ps_size=%d, au_sample_rate=%d, "
1323 "au_pesid=%c, vi_frame_rate=%d, "
1324 "vi_frames_per_gop=%d, "
1325 "vi_bframes_count=%d, vi_pesid=%c\n",
1326 p->ts_pid_pmt,p->ts_pid_audio,
1327 p->ts_pid_video,p->ts_pid_pcr,
1328 p->ps_size, p->au_sample_rate,
1329 p->au_pesid, p->vi_frame_rate,
1330 p->vi_frames_per_gop,
1331 p->vi_bframes_count, p->vi_pesid);
1334 case VIDIOC_S_MPEGCOMP:
1336 struct v4l2_mpeg_compression *p=arg;
1337 /*FIXME: Several fields not shown */
1338 if (!vfd->vidioc_s_mpegcomp)
1340 dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d, "
1341 "ts_pid_video=%d, ts_pid_pcr=%d, ps_size=%d, "
1342 "au_sample_rate=%d, au_pesid=%c, "
1343 "vi_frame_rate=%d, vi_frames_per_gop=%d, "
1344 "vi_bframes_count=%d, vi_pesid=%c\n",
1345 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
1346 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
1347 p->au_pesid, p->vi_frame_rate,
1348 p->vi_frames_per_gop, p->vi_bframes_count,
1350 ret=vfd->vidioc_s_mpegcomp(file, fh, p);
1353 case VIDIOC_G_JPEGCOMP:
1355 struct v4l2_jpegcompression *p=arg;
1356 if (!vfd->vidioc_g_jpegcomp)
1358 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1360 dbgarg (cmd, "quality=%d, APPn=%d, "
1361 "APP_len=%d, COM_len=%d, "
1362 "jpeg_markers=%d\n",
1363 p->quality,p->APPn,p->APP_len,
1364 p->COM_len,p->jpeg_markers);
1367 case VIDIOC_S_JPEGCOMP:
1369 struct v4l2_jpegcompression *p=arg;
1370 if (!vfd->vidioc_g_jpegcomp)
1372 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1373 "COM_len=%d, jpeg_markers=%d\n",
1374 p->quality,p->APPn,p->APP_len,
1375 p->COM_len,p->jpeg_markers);
1376 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1379 case VIDIOC_G_ENC_INDEX:
1381 struct v4l2_enc_idx *p=arg;
1383 if (!vfd->vidioc_g_enc_index)
1385 ret=vfd->vidioc_g_enc_index(file, fh, p);
1387 dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1388 p->entries,p->entries_cap);
1391 case VIDIOC_ENCODER_CMD:
1393 struct v4l2_encoder_cmd *p=arg;
1395 if (!vfd->vidioc_encoder_cmd)
1397 ret=vfd->vidioc_encoder_cmd(file, fh, p);
1399 dbgarg (cmd, "cmd=%d, flags=%d\n",
1403 case VIDIOC_TRY_ENCODER_CMD:
1405 struct v4l2_encoder_cmd *p=arg;
1407 if (!vfd->vidioc_try_encoder_cmd)
1409 ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
1411 dbgarg (cmd, "cmd=%d, flags=%d\n",
1417 struct v4l2_streamparm *p=arg;
1420 memset(p,0,sizeof(*p));
1423 if (vfd->vidioc_g_parm) {
1424 ret=vfd->vidioc_g_parm(file, fh, p);
1426 struct v4l2_standard s;
1428 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1431 v4l2_video_std_construct(&s, vfd->current_norm,
1432 v4l2_norm_to_name(vfd->current_norm));
1434 p->parm.capture.timeperframe = s.frameperiod;
1438 dbgarg (cmd, "type=%d\n", p->type);
1443 struct v4l2_streamparm *p=arg;
1444 if (!vfd->vidioc_s_parm)
1446 dbgarg (cmd, "type=%d\n", p->type);
1447 ret=vfd->vidioc_s_parm(file, fh, p);
1450 case VIDIOC_G_TUNER:
1452 struct v4l2_tuner *p=arg;
1453 __u32 index=p->index;
1455 if (!vfd->vidioc_g_tuner)
1458 memset(p,0,sizeof(*p));
1461 ret=vfd->vidioc_g_tuner(file, fh, p);
1463 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1464 "capability=%d, rangelow=%d, "
1465 "rangehigh=%d, signal=%d, afc=%d, "
1466 "rxsubchans=%d, audmode=%d\n",
1467 p->index, p->name, p->type,
1468 p->capability, p->rangelow,
1469 p->rangehigh, p->rxsubchans,
1470 p->audmode, p->signal, p->afc);
1473 case VIDIOC_S_TUNER:
1475 struct v4l2_tuner *p=arg;
1476 if (!vfd->vidioc_s_tuner)
1478 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1479 "capability=%d, rangelow=%d, rangehigh=%d, "
1480 "signal=%d, afc=%d, rxsubchans=%d, "
1481 "audmode=%d\n",p->index, p->name, p->type,
1482 p->capability, p->rangelow,p->rangehigh,
1483 p->rxsubchans, p->audmode, p->signal,
1485 ret=vfd->vidioc_s_tuner(file, fh, p);
1488 case VIDIOC_G_FREQUENCY:
1490 struct v4l2_frequency *p=arg;
1491 if (!vfd->vidioc_g_frequency)
1494 memset(p,0,sizeof(*p));
1496 ret=vfd->vidioc_g_frequency(file, fh, p);
1498 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1499 p->tuner,p->type,p->frequency);
1502 case VIDIOC_S_FREQUENCY:
1504 struct v4l2_frequency *p=arg;
1505 if (!vfd->vidioc_s_frequency)
1507 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1508 p->tuner,p->type,p->frequency);
1509 ret=vfd->vidioc_s_frequency(file, fh, p);
1512 case VIDIOC_G_SLICED_VBI_CAP:
1514 struct v4l2_sliced_vbi_cap *p=arg;
1515 if (!vfd->vidioc_g_sliced_vbi_cap)
1517 ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1519 dbgarg (cmd, "service_set=%d\n", p->service_set);
1522 case VIDIOC_LOG_STATUS:
1524 if (!vfd->vidioc_log_status)
1526 ret=vfd->vidioc_log_status(file, fh);
1529 #ifdef CONFIG_VIDEO_ADV_DEBUG
1530 case VIDIOC_DBG_G_REGISTER:
1532 struct v4l2_register *p=arg;
1533 if (!capable(CAP_SYS_ADMIN))
1535 else if (vfd->vidioc_g_register)
1536 ret=vfd->vidioc_g_register(file, fh, p);
1539 case VIDIOC_DBG_S_REGISTER:
1541 struct v4l2_register *p=arg;
1542 if (!capable(CAP_SYS_ADMIN))
1544 else if (vfd->vidioc_s_register)
1545 ret=vfd->vidioc_s_register(file, fh, p);
1549 case VIDIOC_G_CHIP_IDENT:
1551 struct v4l2_chip_ident *p=arg;
1552 if (!vfd->vidioc_g_chip_ident)
1554 ret=vfd->vidioc_g_chip_ident(file, fh, p);
1556 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1561 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1563 printk ("%s: err:\n", vfd->name);
1564 v4l_print_ioctl(vfd->name, cmd);
1571 int video_ioctl2 (struct inode *inode, struct file *file,
1572 unsigned int cmd, unsigned long arg)
1579 size_t ctrls_size = 0;
1580 void __user *user_ptr = NULL;
1582 #ifdef __OLD_VIDIOC_
1583 cmd = video_fix_command(cmd);
1585 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1586 cmd == VIDIOC_TRY_EXT_CTRLS);
1588 /* Copy arguments into temp kernel buffer */
1589 switch (_IOC_DIR(cmd)) {
1595 case (_IOC_WRITE | _IOC_READ):
1596 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1599 /* too big to allocate from stack */
1600 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1607 if (_IOC_DIR(cmd) & _IOC_WRITE)
1608 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1614 struct v4l2_ext_controls *p = parg;
1616 /* In case of an error, tell the caller that it wasn't
1617 a specific control that caused it. */
1618 p->error_idx = p->count;
1619 user_ptr = (void __user *)p->controls;
1621 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1622 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1623 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1628 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1635 err = __video_do_ioctl(inode, file, cmd, parg);
1636 if (err == -ENOIOCTLCMD)
1639 struct v4l2_ext_controls *p = parg;
1641 p->controls = (void *)user_ptr;
1642 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1650 /* Copy results into user buffer */
1651 switch (_IOC_DIR(cmd))
1654 case (_IOC_WRITE | _IOC_READ):
1655 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1666 static const struct file_operations video_fops;
1669 * video_register_device - register video4linux devices
1670 * @vfd: video device structure we want to register
1671 * @type: type of device to register
1672 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
1675 * The registration code assigns minor numbers based on the type
1676 * requested. -ENFILE is returned in all the device slots for this
1677 * category are full. If not then the minor field is set and the
1678 * driver initialize function is called (if non %NULL).
1680 * Zero is returned on success.
1684 * %VFL_TYPE_GRABBER - A frame grabber
1686 * %VFL_TYPE_VTX - A teletext device
1688 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
1690 * %VFL_TYPE_RADIO - A radio card
1693 int video_register_device(struct video_device *vfd, int type, int nr)
1703 case VFL_TYPE_GRABBER:
1704 base=MINOR_VFL_TYPE_GRABBER_MIN;
1705 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
1706 name_base = "video";
1709 base=MINOR_VFL_TYPE_VTX_MIN;
1710 end=MINOR_VFL_TYPE_VTX_MAX+1;
1714 base=MINOR_VFL_TYPE_VBI_MIN;
1715 end=MINOR_VFL_TYPE_VBI_MAX+1;
1718 case VFL_TYPE_RADIO:
1719 base=MINOR_VFL_TYPE_RADIO_MIN;
1720 end=MINOR_VFL_TYPE_RADIO_MAX+1;
1721 name_base = "radio";
1724 printk(KERN_ERR "%s called with unknown type: %d\n",
1725 __FUNCTION__, type);
1729 /* pick a minor number */
1730 mutex_lock(&videodev_lock);
1731 if (nr >= 0 && nr < end-base) {
1732 /* use the one the driver asked for */
1734 if (NULL != video_device[i]) {
1735 mutex_unlock(&videodev_lock);
1739 /* use first free */
1740 for(i=base;i<end;i++)
1741 if (NULL == video_device[i])
1744 mutex_unlock(&videodev_lock);
1748 video_device[i]=vfd;
1750 mutex_unlock(&videodev_lock);
1751 mutex_init(&vfd->lock);
1754 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
1756 vfd->class_dev.dev = vfd->dev;
1757 vfd->class_dev.class = &video_class;
1758 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
1759 sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
1760 ret = class_device_register(&vfd->class_dev);
1762 printk(KERN_ERR "%s: class_device_register failed\n",
1766 ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
1768 printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
1774 /* needed until all drivers are fixed */
1776 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
1777 "Please fix your driver for proper sysfs support, see "
1778 "http://lwn.net/Articles/36850/\n", vfd->name);
1783 class_device_unregister(&vfd->class_dev);
1785 mutex_lock(&videodev_lock);
1786 video_device[vfd->minor] = NULL;
1788 mutex_unlock(&videodev_lock);
1793 * video_unregister_device - unregister a video4linux device
1794 * @vfd: the device to unregister
1796 * This unregisters the passed device and deassigns the minor
1797 * number. Future open calls will be met with errors.
1800 void video_unregister_device(struct video_device *vfd)
1802 mutex_lock(&videodev_lock);
1803 if(video_device[vfd->minor]!=vfd)
1804 panic("videodev: bad unregister");
1806 video_device[vfd->minor]=NULL;
1807 class_device_unregister(&vfd->class_dev);
1808 mutex_unlock(&videodev_lock);
1812 * Video fs operations
1814 static const struct file_operations video_fops=
1816 .owner = THIS_MODULE,
1817 .llseek = no_llseek,
1822 * Initialise video for linux
1825 static int __init videodev_init(void)
1829 printk(KERN_INFO "Linux video capture interface: v2.00\n");
1830 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
1831 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
1835 ret = class_register(&video_class);
1837 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
1838 printk(KERN_WARNING "video_dev: class_register failed\n");
1845 static void __exit videodev_exit(void)
1847 class_unregister(&video_class);
1848 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
1851 module_init(videodev_init)
1852 module_exit(videodev_exit)
1854 EXPORT_SYMBOL(video_register_device);
1855 EXPORT_SYMBOL(video_unregister_device);
1856 EXPORT_SYMBOL(video_devdata);
1857 EXPORT_SYMBOL(video_usercopy);
1858 EXPORT_SYMBOL(video_exclusive_open);
1859 EXPORT_SYMBOL(video_exclusive_release);
1860 EXPORT_SYMBOL(video_ioctl2);
1861 EXPORT_SYMBOL(video_device_alloc);
1862 EXPORT_SYMBOL(video_device_release);
1864 MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
1865 MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
1866 MODULE_LICENSE("GPL");