4 * Backward Compatibility Layer
6 * Support subroutines for providing V4L2 drivers with backward
7 * compatibility with applications using the old API.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * Author: Bill Dirks <bdirks@pacbell.net>
19 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/smp_lock.h>
30 #include <linux/file.h>
31 #include <linux/string.h>
32 #include <linux/errno.h>
33 #include <linux/slab.h>
34 #include <linux/videodev.h>
35 #include <media/v4l2-common.h>
37 #include <asm/uaccess.h>
38 #include <asm/system.h>
39 #include <asm/pgtable.h>
42 #include <linux/kmod.h>
45 static unsigned int debug = 0;
46 module_param(debug, int, 0644);
47 MODULE_PARM_DESC(debug,"enable debug messages");
48 MODULE_AUTHOR("Bill Dirks");
49 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
50 MODULE_LICENSE("GPL");
52 #define dprintk(fmt, arg...) if (debug) \
53 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg)
56 * I O C T L T R A N S L A T I O N
58 * From here on down is the code for translating the numerous
59 * ioctl commands from the old API to the new API.
63 get_v4l_control(struct inode *inode,
68 struct v4l2_queryctrl qctrl2;
69 struct v4l2_control ctrl2;
73 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
75 dprintk("VIDIOC_QUERYCTRL: %d\n",err);
77 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
80 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2);
82 dprintk("VIDIOC_G_CTRL: %d\n",err);
85 return ((ctrl2.value - qctrl2.minimum) * 65535
86 + (qctrl2.maximum - qctrl2.minimum) / 2)
87 / (qctrl2.maximum - qctrl2.minimum);
93 set_v4l_control(struct inode *inode,
99 struct v4l2_queryctrl qctrl2;
100 struct v4l2_control ctrl2;
104 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
106 dprintk("VIDIOC_QUERYCTRL: %d\n",err);
108 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
109 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED))
115 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
117 ctrl2.id = qctrl2.id;
119 (value * (qctrl2.maximum - qctrl2.minimum)
122 ctrl2.value += qctrl2.minimum;
123 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
125 dprintk("VIDIOC_S_CTRL: %d\n",err);
130 /* ----------------------------------------------------------------- */
132 static int palette2pixelformat[] = {
133 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
134 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
135 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
136 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
137 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
138 /* yuv packed pixel */
139 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
140 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
141 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
143 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
144 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
145 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
146 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
147 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
151 palette_to_pixelformat(unsigned int palette)
153 if (palette < ARRAY_SIZE(palette2pixelformat))
154 return palette2pixelformat[palette];
160 pixelformat_to_palette(int pixelformat)
165 case V4L2_PIX_FMT_GREY:
166 palette = VIDEO_PALETTE_GREY;
168 case V4L2_PIX_FMT_RGB555:
169 palette = VIDEO_PALETTE_RGB555;
171 case V4L2_PIX_FMT_RGB565:
172 palette = VIDEO_PALETTE_RGB565;
174 case V4L2_PIX_FMT_BGR24:
175 palette = VIDEO_PALETTE_RGB24;
177 case V4L2_PIX_FMT_BGR32:
178 palette = VIDEO_PALETTE_RGB32;
180 /* yuv packed pixel */
181 case V4L2_PIX_FMT_YUYV:
182 palette = VIDEO_PALETTE_YUYV;
184 case V4L2_PIX_FMT_UYVY:
185 palette = VIDEO_PALETTE_UYVY;
188 case V4L2_PIX_FMT_YUV410:
189 palette = VIDEO_PALETTE_YUV420;
191 case V4L2_PIX_FMT_YUV420:
192 palette = VIDEO_PALETTE_YUV420;
194 case V4L2_PIX_FMT_YUV411P:
195 palette = VIDEO_PALETTE_YUV411P;
197 case V4L2_PIX_FMT_YUV422P:
198 palette = VIDEO_PALETTE_YUV422P;
204 /* ----------------------------------------------------------------- */
206 static int poll_one(struct file *file)
210 struct poll_wqueues pwq;
216 set_current_state(TASK_INTERRUPTIBLE);
217 mask = file->f_op->poll(file, table);
221 if (signal_pending(current)) {
222 retval = -ERESTARTSYS;
227 set_current_state(TASK_RUNNING);
232 static int count_inputs(struct inode *inode,
236 struct v4l2_input input2;
240 memset(&input2,0,sizeof(input2));
242 if (0 != drv(inode,file,VIDIOC_ENUMINPUT, &input2))
248 static int check_size(struct inode *inode,
251 int *maxw, int *maxh)
253 struct v4l2_fmtdesc desc2;
254 struct v4l2_format fmt2;
256 memset(&desc2,0,sizeof(desc2));
257 memset(&fmt2,0,sizeof(fmt2));
259 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
260 if (0 != drv(inode,file,VIDIOC_ENUM_FMT, &desc2))
263 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
264 fmt2.fmt.pix.width = 10000;
265 fmt2.fmt.pix.height = 10000;
266 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
267 if (0 != drv(inode,file,VIDIOC_TRY_FMT, &fmt2))
270 *maxw = fmt2.fmt.pix.width;
271 *maxh = fmt2.fmt.pix.height;
277 /* ----------------------------------------------------------------- */
280 * This function is exported.
283 v4l_compat_translate_ioctl(struct inode *inode,
289 struct v4l2_capability *cap2 = NULL;
290 struct v4l2_format *fmt2 = NULL;
291 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
293 struct v4l2_framebuffer fbuf2;
294 struct v4l2_input input2;
295 struct v4l2_tuner tun2;
296 struct v4l2_standard std2;
297 struct v4l2_frequency freq2;
298 struct v4l2_audio aud2;
299 struct v4l2_queryctrl qctrl2;
300 struct v4l2_buffer buf2;
305 case VIDIOCGCAP: /* capability */
307 struct video_capability *cap = arg;
309 cap2 = kzalloc(sizeof(*cap2),GFP_KERNEL);
310 memset(cap, 0, sizeof(*cap));
311 memset(&fbuf2, 0, sizeof(fbuf2));
313 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
315 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n",err);
318 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
319 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
321 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n",err);
322 memset(&fbuf2, 0, sizeof(fbuf2));
327 memcpy(cap->name, cap2->card,
328 min(sizeof(cap->name), sizeof(cap2->card)));
329 cap->name[sizeof(cap->name) - 1] = 0;
330 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
331 cap->type |= VID_TYPE_CAPTURE;
332 if (cap2->capabilities & V4L2_CAP_TUNER)
333 cap->type |= VID_TYPE_TUNER;
334 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
335 cap->type |= VID_TYPE_TELETEXT;
336 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
337 cap->type |= VID_TYPE_OVERLAY;
338 if (fbuf2.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
339 cap->type |= VID_TYPE_CLIPPING;
341 cap->channels = count_inputs(inode,file,drv);
342 check_size(inode,file,drv,
343 &cap->maxwidth,&cap->maxheight);
344 cap->audios = 0; /* FIXME */
345 cap->minwidth = 48; /* FIXME */
346 cap->minheight = 32; /* FIXME */
349 case VIDIOCGFBUF: /* get frame buffer */
351 struct video_buffer *buffer = arg;
353 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
355 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err);
358 buffer->base = fbuf2.base;
359 buffer->height = fbuf2.fmt.height;
360 buffer->width = fbuf2.fmt.width;
362 switch (fbuf2.fmt.pixelformat) {
363 case V4L2_PIX_FMT_RGB332:
366 case V4L2_PIX_FMT_RGB555:
369 case V4L2_PIX_FMT_RGB565:
372 case V4L2_PIX_FMT_BGR24:
375 case V4L2_PIX_FMT_BGR32:
381 if (0 != fbuf2.fmt.bytesperline)
382 buffer->bytesperline = fbuf2.fmt.bytesperline;
384 buffer->bytesperline =
385 (buffer->width * buffer->depth + 7) & 7;
386 buffer->bytesperline >>= 3;
390 case VIDIOCSFBUF: /* set frame buffer */
392 struct video_buffer *buffer = arg;
394 memset(&fbuf2, 0, sizeof(fbuf2));
395 fbuf2.base = buffer->base;
396 fbuf2.fmt.height = buffer->height;
397 fbuf2.fmt.width = buffer->width;
398 switch (buffer->depth) {
400 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
403 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
406 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
409 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
412 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
415 fbuf2.fmt.bytesperline = buffer->bytesperline;
416 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
418 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err);
421 case VIDIOCGWIN: /* get window or capture dimensions */
423 struct video_window *win = arg;
425 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
426 memset(win,0,sizeof(*win));
428 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
429 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
431 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err);
433 win->x = fmt2->fmt.win.w.left;
434 win->y = fmt2->fmt.win.w.top;
435 win->width = fmt2->fmt.win.w.width;
436 win->height = fmt2->fmt.win.w.height;
437 win->chromakey = fmt2->fmt.win.chromakey;
443 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
444 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
446 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err);
451 win->width = fmt2->fmt.pix.width;
452 win->height = fmt2->fmt.pix.height;
458 case VIDIOCSWIN: /* set window and/or capture dimensions */
460 struct video_window *win = arg;
463 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
464 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
465 drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
466 err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
468 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err);
470 fmt2->fmt.pix.width = win->width;
471 fmt2->fmt.pix.height = win->height;
472 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
473 fmt2->fmt.pix.bytesperline = 0;
474 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
476 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
478 win->width = fmt2->fmt.pix.width;
479 win->height = fmt2->fmt.pix.height;
482 memset(fmt2,0,sizeof(*fmt2));
483 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
484 fmt2->fmt.win.w.left = win->x;
485 fmt2->fmt.win.w.top = win->y;
486 fmt2->fmt.win.w.width = win->width;
487 fmt2->fmt.win.w.height = win->height;
488 fmt2->fmt.win.chromakey = win->chromakey;
489 fmt2->fmt.win.clips = (void __user *)win->clips;
490 fmt2->fmt.win.clipcount = win->clipcount;
491 err2 = drv(inode, file, VIDIOC_S_FMT, fmt2);
493 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err);
495 if (err1 != 0 && err2 != 0)
499 case VIDIOCCAPTURE: /* turn on/off preview */
504 /* dirty hack time. But v4l1 has no STREAMOFF
505 * equivalent in the API, and this one at
506 * least comes close ... */
507 drv(inode, file, VIDIOC_STREAMOFF, &captype);
509 err = drv(inode, file, VIDIOC_OVERLAY, arg);
511 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err);
514 case VIDIOCGCHAN: /* get input information */
516 struct video_channel *chan = arg;
518 memset(&input2,0,sizeof(input2));
519 input2.index = chan->channel;
520 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
522 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
523 "channel=%d err=%d\n",chan->channel,err);
526 chan->channel = input2.index;
527 memcpy(chan->name, input2.name,
528 min(sizeof(chan->name), sizeof(input2.name)));
529 chan->name[sizeof(chan->name) - 1] = 0;
530 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
531 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
532 switch (input2.type) {
533 case V4L2_INPUT_TYPE_TUNER:
534 chan->type = VIDEO_TYPE_TV;
537 case V4L2_INPUT_TYPE_CAMERA:
538 chan->type = VIDEO_TYPE_CAMERA;
542 err = drv(inode, file, VIDIOC_G_STD, &sid);
544 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err);
546 if (sid & V4L2_STD_PAL)
547 chan->norm = VIDEO_MODE_PAL;
548 if (sid & V4L2_STD_NTSC)
549 chan->norm = VIDEO_MODE_NTSC;
550 if (sid & V4L2_STD_SECAM)
551 chan->norm = VIDEO_MODE_SECAM;
555 case VIDIOCSCHAN: /* set input */
557 struct video_channel *chan = arg;
560 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
562 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err);
563 switch (chan->norm) {
567 case VIDEO_MODE_NTSC:
570 case VIDEO_MODE_SECAM:
571 sid = V4L2_STD_SECAM;
575 err = drv(inode, file, VIDIOC_S_STD, &sid);
577 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err);
581 case VIDIOCGPICT: /* get tone controls & partial capture format */
583 struct video_picture *pict = arg;
585 pict->brightness = get_v4l_control(inode, file,
586 V4L2_CID_BRIGHTNESS,drv);
587 pict->hue = get_v4l_control(inode, file,
589 pict->contrast = get_v4l_control(inode, file,
590 V4L2_CID_CONTRAST, drv);
591 pict->colour = get_v4l_control(inode, file,
592 V4L2_CID_SATURATION, drv);
593 pict->whiteness = get_v4l_control(inode, file,
594 V4L2_CID_WHITENESS, drv);
596 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
597 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
598 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
600 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
603 pict->palette = pixelformat_to_palette(
604 fmt2->fmt.pix.pixelformat);
607 case VIDIOCSPICT: /* set tone controls & partial capture format */
609 struct video_picture *pict = arg;
611 set_v4l_control(inode, file,
612 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
613 set_v4l_control(inode, file,
614 V4L2_CID_HUE, pict->hue, drv);
615 set_v4l_control(inode, file,
616 V4L2_CID_CONTRAST, pict->contrast, drv);
617 set_v4l_control(inode, file,
618 V4L2_CID_SATURATION, pict->colour, drv);
619 set_v4l_control(inode, file,
620 V4L2_CID_WHITENESS, pict->whiteness, drv);
622 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
623 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
624 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
626 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err);
627 if (fmt2->fmt.pix.pixelformat !=
628 palette_to_pixelformat(pict->palette)) {
629 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
631 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
633 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",err);
636 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
638 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err);
639 if (fbuf2.fmt.pixelformat !=
640 palette_to_pixelformat(pict->palette)) {
641 fbuf2.fmt.pixelformat = palette_to_pixelformat(
643 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
645 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",err);
646 err = 0; /* likely fails for non-root */
650 case VIDIOCGTUNER: /* get tuner information */
652 struct video_tuner *tun = arg;
654 memset(&tun2,0,sizeof(tun2));
655 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
657 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err);
660 memcpy(tun->name, tun2.name,
661 min(sizeof(tun->name), sizeof(tun2.name)));
662 tun->name[sizeof(tun->name) - 1] = 0;
663 tun->rangelow = tun2.rangelow;
664 tun->rangehigh = tun2.rangehigh;
666 tun->mode = VIDEO_MODE_AUTO;
668 for (i = 0; i < 64; i++) {
669 memset(&std2,0,sizeof(std2));
671 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
673 if (std2.id & V4L2_STD_PAL)
674 tun->flags |= VIDEO_TUNER_PAL;
675 if (std2.id & V4L2_STD_NTSC)
676 tun->flags |= VIDEO_TUNER_NTSC;
677 if (std2.id & V4L2_STD_SECAM)
678 tun->flags |= VIDEO_TUNER_SECAM;
681 err = drv(inode, file, VIDIOC_G_STD, &sid);
683 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err);
685 if (sid & V4L2_STD_PAL)
686 tun->mode = VIDEO_MODE_PAL;
687 if (sid & V4L2_STD_NTSC)
688 tun->mode = VIDEO_MODE_NTSC;
689 if (sid & V4L2_STD_SECAM)
690 tun->mode = VIDEO_MODE_SECAM;
693 if (tun2.capability & V4L2_TUNER_CAP_LOW)
694 tun->flags |= VIDEO_TUNER_LOW;
695 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
696 tun->flags |= VIDEO_TUNER_STEREO_ON;
697 tun->signal = tun2.signal;
700 case VIDIOCSTUNER: /* select a tuner input */
705 case VIDIOCGFREQ: /* get frequency */
707 unsigned long *freq = arg;
710 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
712 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err);
714 *freq = freq2.frequency;
717 case VIDIOCSFREQ: /* set frequency */
719 unsigned long *freq = arg;
722 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
723 freq2.frequency = *freq;
724 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
726 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err);
729 case VIDIOCGAUDIO: /* get audio properties/controls */
731 struct video_audio *aud = arg;
733 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
735 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err);
738 memcpy(aud->name, aud2.name,
739 min(sizeof(aud->name), sizeof(aud2.name)));
740 aud->name[sizeof(aud->name) - 1] = 0;
741 aud->audio = aud2.index;
743 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
746 aud->flags |= VIDEO_AUDIO_VOLUME;
748 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
751 aud->flags |= VIDEO_AUDIO_BASS;
753 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
756 aud->flags |= VIDEO_AUDIO_TREBLE;
758 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
761 aud->flags |= VIDEO_AUDIO_BALANCE;
763 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
766 aud->flags |= VIDEO_AUDIO_MUTE;
767 aud->flags |= VIDEO_AUDIO_MUTABLE;
770 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
771 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
772 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
773 aud->step = qctrl2.step;
776 memset(&tun2,0,sizeof(tun2));
777 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
779 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err);
784 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
785 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
786 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
787 aud->mode = VIDEO_SOUND_STEREO;
788 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
789 aud->mode = VIDEO_SOUND_MONO;
792 case VIDIOCSAUDIO: /* set audio controls */
794 struct video_audio *aud = arg;
796 memset(&aud2,0,sizeof(aud2));
797 memset(&tun2,0,sizeof(tun2));
799 aud2.index = aud->audio;
800 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
802 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err);
806 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
808 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
810 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
812 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
814 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
815 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
817 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
819 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err);
823 case VIDEO_SOUND_MONO:
824 case VIDEO_SOUND_LANG1:
825 tun2.audmode = V4L2_TUNER_MODE_MONO;
827 case VIDEO_SOUND_STEREO:
828 tun2.audmode = V4L2_TUNER_MODE_STEREO;
830 case VIDEO_SOUND_LANG2:
831 tun2.audmode = V4L2_TUNER_MODE_LANG2;
834 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
836 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err);
841 case VIDIOCMCAPTURE: /* capture a frame */
843 struct video_mmap *mm = arg;
845 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
846 memset(&buf2,0,sizeof(buf2));
848 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
849 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
851 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err);
854 if (mm->width != fmt2->fmt.pix.width ||
855 mm->height != fmt2->fmt.pix.height ||
856 palette_to_pixelformat(mm->format) !=
857 fmt2->fmt.pix.pixelformat)
858 {/* New capture format... */
859 fmt2->fmt.pix.width = mm->width;
860 fmt2->fmt.pix.height = mm->height;
861 fmt2->fmt.pix.pixelformat =
862 palette_to_pixelformat(mm->format);
863 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
864 fmt2->fmt.pix.bytesperline = 0;
865 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
867 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err);
871 buf2.index = mm->frame;
872 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
873 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
875 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err);
878 err = drv(inode, file, VIDIOC_QBUF, &buf2);
880 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err);
883 err = drv(inode, file, VIDIOC_STREAMON, &captype);
885 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err);
888 case VIDIOCSYNC: /* wait for a frame */
893 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
894 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
897 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
900 if (!(buf2.flags & V4L2_BUF_FLAG_MAPPED)) {
901 /* Buffer is not mapped */
906 /* make sure capture actually runs so we don't block forever */
907 err = drv(inode, file, VIDIOC_STREAMON, &captype);
909 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err);
913 /* Loop as long as the buffer is queued, but not done */
915 (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
916 == V4L2_BUF_FLAG_QUEUED)
918 err = poll_one(file);
919 if (err < 0 || /* error or sleep was interrupted */
920 err == 0) /* timeout? Shouldn't occur. */
922 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
924 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
926 if (!(buf2.flags & V4L2_BUF_FLAG_DONE)) /* not done */
929 err = drv(inode, file, VIDIOC_DQBUF, &buf2);
931 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err);
932 } while (err == 0 && buf2.index != *i);
936 case VIDIOCGVBIFMT: /* query VBI data capture format */
938 struct vbi_format *fmt = arg;
940 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
941 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
943 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
945 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
948 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
952 memset(fmt, 0, sizeof(*fmt));
953 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
954 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
955 fmt->sample_format = VIDEO_PALETTE_RAW;
956 fmt->start[0] = fmt2->fmt.vbi.start[0];
957 fmt->count[0] = fmt2->fmt.vbi.count[0];
958 fmt->start[1] = fmt2->fmt.vbi.start[1];
959 fmt->count[1] = fmt2->fmt.vbi.count[1];
960 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
965 struct vbi_format *fmt = arg;
967 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
972 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
974 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
975 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
976 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
977 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
978 fmt2->fmt.vbi.start[0] = fmt->start[0];
979 fmt2->fmt.vbi.count[0] = fmt->count[0];
980 fmt2->fmt.vbi.start[1] = fmt->start[1];
981 fmt2->fmt.vbi.count[1] = fmt->count[1];
982 fmt2->fmt.vbi.flags = fmt->flags;
983 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
985 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
989 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
990 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
991 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
992 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
993 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
994 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
995 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
996 fmt2->fmt.vbi.flags != fmt->flags) {
1000 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1002 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1016 EXPORT_SYMBOL(v4l_compat_translate_ioctl);