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 <bill@thedirks.org>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
27 #include <linux/file.h>
28 #include <linux/string.h>
29 #include <linux/errno.h>
30 #include <linux/slab.h>
31 #include <linux/videodev.h>
32 #include <media/v4l2-common.h>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/pgtable.h>
39 #include <linux/kmod.h>
42 static unsigned int debug;
43 module_param(debug, int, 0644);
44 MODULE_PARM_DESC(debug, "enable debug messages");
45 MODULE_AUTHOR("Bill Dirks");
46 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
47 MODULE_LICENSE("GPL");
49 #define dprintk(fmt, arg...) \
52 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);
76 if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
78 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2);
80 dprintk("VIDIOC_G_CTRL: %d\n", err);
83 return ((ctrl2.value - qctrl2.minimum) * 65535
84 + (qctrl2.maximum - qctrl2.minimum) / 2)
85 / (qctrl2.maximum - qctrl2.minimum);
91 set_v4l_control(struct inode *inode,
97 struct v4l2_queryctrl qctrl2;
98 struct v4l2_control ctrl2;
102 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
104 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
106 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
107 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
112 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
114 ctrl2.id = qctrl2.id;
116 (value * (qctrl2.maximum - qctrl2.minimum)
119 ctrl2.value += qctrl2.minimum;
120 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
122 dprintk("VIDIOC_S_CTRL: %d\n", err);
127 /* ----------------------------------------------------------------- */
129 static const unsigned int palette2pixelformat[] = {
130 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
131 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
132 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
133 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
134 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
135 /* yuv packed pixel */
136 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
137 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
138 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
140 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
141 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
142 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
143 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
144 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
147 static unsigned int __pure
148 palette_to_pixelformat(unsigned int palette)
150 if (palette < ARRAY_SIZE(palette2pixelformat))
151 return palette2pixelformat[palette];
156 static unsigned int __attribute_const__
157 pixelformat_to_palette(unsigned int pixelformat)
160 switch (pixelformat) {
161 case V4L2_PIX_FMT_GREY:
162 palette = VIDEO_PALETTE_GREY;
164 case V4L2_PIX_FMT_RGB555:
165 palette = VIDEO_PALETTE_RGB555;
167 case V4L2_PIX_FMT_RGB565:
168 palette = VIDEO_PALETTE_RGB565;
170 case V4L2_PIX_FMT_BGR24:
171 palette = VIDEO_PALETTE_RGB24;
173 case V4L2_PIX_FMT_BGR32:
174 palette = VIDEO_PALETTE_RGB32;
176 /* yuv packed pixel */
177 case V4L2_PIX_FMT_YUYV:
178 palette = VIDEO_PALETTE_YUYV;
180 case V4L2_PIX_FMT_UYVY:
181 palette = VIDEO_PALETTE_UYVY;
184 case V4L2_PIX_FMT_YUV410:
185 palette = VIDEO_PALETTE_YUV420;
187 case V4L2_PIX_FMT_YUV420:
188 palette = VIDEO_PALETTE_YUV420;
190 case V4L2_PIX_FMT_YUV411P:
191 palette = VIDEO_PALETTE_YUV411P;
193 case V4L2_PIX_FMT_YUV422P:
194 palette = VIDEO_PALETTE_YUV422P;
200 /* ----------------------------------------------------------------- */
202 static int poll_one(struct file *file, struct poll_wqueues *pwq)
211 set_current_state(TASK_INTERRUPTIBLE);
212 mask = file->f_op->poll(file, table);
216 if (signal_pending(current)) {
217 retval = -ERESTARTSYS;
222 set_current_state(TASK_RUNNING);
227 static int count_inputs(
232 struct v4l2_input input2;
236 memset(&input2, 0, sizeof(input2));
238 if (0 != drv(inode, file, VIDIOC_ENUMINPUT, &input2))
244 static int check_size(
251 struct v4l2_fmtdesc desc2;
252 struct v4l2_format fmt2;
254 memset(&desc2, 0, sizeof(desc2));
255 memset(&fmt2, 0, sizeof(fmt2));
257 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
258 if (0 != drv(inode, file, VIDIOC_ENUM_FMT, &desc2))
261 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
262 fmt2.fmt.pix.width = 10000;
263 fmt2.fmt.pix.height = 10000;
264 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
265 if (0 != drv(inode, file, VIDIOC_TRY_FMT, &fmt2))
268 *maxw = fmt2.fmt.pix.width;
269 *maxh = fmt2.fmt.pix.height;
275 /* ----------------------------------------------------------------- */
277 static noinline int v4l1_compat_get_capabilities(
278 struct video_capability *cap,
284 struct v4l2_framebuffer fbuf;
285 struct v4l2_capability *cap2;
287 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
292 memset(cap, 0, sizeof(*cap));
293 memset(&fbuf, 0, sizeof(fbuf));
295 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
297 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
300 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
301 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
303 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
304 memset(&fbuf, 0, sizeof(fbuf));
309 memcpy(cap->name, cap2->card,
310 min(sizeof(cap->name), sizeof(cap2->card)));
311 cap->name[sizeof(cap->name) - 1] = 0;
312 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
313 cap->type |= VID_TYPE_CAPTURE;
314 if (cap2->capabilities & V4L2_CAP_TUNER)
315 cap->type |= VID_TYPE_TUNER;
316 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
317 cap->type |= VID_TYPE_TELETEXT;
318 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
319 cap->type |= VID_TYPE_OVERLAY;
320 if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
321 cap->type |= VID_TYPE_CLIPPING;
323 cap->channels = count_inputs(inode, file, drv);
324 check_size(inode, file, drv,
325 &cap->maxwidth, &cap->maxheight);
326 cap->audios = 0; /* FIXME */
327 cap->minwidth = 48; /* FIXME */
328 cap->minheight = 32; /* FIXME */
335 static noinline int v4l1_compat_get_frame_buffer(
336 struct video_buffer *buffer,
342 struct v4l2_framebuffer fbuf;
344 memset(buffer, 0, sizeof(*buffer));
345 memset(&fbuf, 0, sizeof(fbuf));
347 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
349 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
352 buffer->base = fbuf.base;
353 buffer->height = fbuf.fmt.height;
354 buffer->width = fbuf.fmt.width;
356 switch (fbuf.fmt.pixelformat) {
357 case V4L2_PIX_FMT_RGB332:
360 case V4L2_PIX_FMT_RGB555:
363 case V4L2_PIX_FMT_RGB565:
366 case V4L2_PIX_FMT_BGR24:
369 case V4L2_PIX_FMT_BGR32:
375 if (fbuf.fmt.bytesperline) {
376 buffer->bytesperline = fbuf.fmt.bytesperline;
377 if (!buffer->depth && buffer->width)
378 buffer->depth = ((fbuf.fmt.bytesperline<<3)
382 buffer->bytesperline =
383 (buffer->width * buffer->depth + 7) & 7;
384 buffer->bytesperline >>= 3;
390 static noinline int v4l1_compat_set_frame_buffer(
391 struct video_buffer *buffer,
397 struct v4l2_framebuffer fbuf;
399 memset(&fbuf, 0, sizeof(fbuf));
400 fbuf.base = buffer->base;
401 fbuf.fmt.height = buffer->height;
402 fbuf.fmt.width = buffer->width;
403 switch (buffer->depth) {
405 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
408 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
411 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
414 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
417 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
420 fbuf.fmt.bytesperline = buffer->bytesperline;
421 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
423 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
427 static noinline int v4l1_compat_get_win_cap_dimensions(
428 struct video_window *win,
434 struct v4l2_format *fmt;
436 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
441 memset(win, 0, sizeof(*win));
443 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
444 err = drv(inode, file, VIDIOC_G_FMT, fmt);
446 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
448 win->x = fmt->fmt.win.w.left;
449 win->y = fmt->fmt.win.w.top;
450 win->width = fmt->fmt.win.w.width;
451 win->height = fmt->fmt.win.w.height;
452 win->chromakey = fmt->fmt.win.chromakey;
458 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
459 err = drv(inode, file, VIDIOC_G_FMT, fmt);
461 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
466 win->width = fmt->fmt.pix.width;
467 win->height = fmt->fmt.pix.height;
476 static noinline int v4l1_compat_set_win_cap_dimensions(
477 struct video_window *win,
483 struct v4l2_format *fmt;
485 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
490 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
491 drv(inode, file, VIDIOC_STREAMOFF, &fmt->type);
492 err1 = drv(inode, file, VIDIOC_G_FMT, fmt);
494 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1);
496 fmt->fmt.pix.width = win->width;
497 fmt->fmt.pix.height = win->height;
498 fmt->fmt.pix.field = V4L2_FIELD_ANY;
499 fmt->fmt.pix.bytesperline = 0;
500 err = drv(inode, file, VIDIOC_S_FMT, fmt);
502 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
504 win->width = fmt->fmt.pix.width;
505 win->height = fmt->fmt.pix.height;
508 memset(fmt, 0, sizeof(*fmt));
509 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
510 fmt->fmt.win.w.left = win->x;
511 fmt->fmt.win.w.top = win->y;
512 fmt->fmt.win.w.width = win->width;
513 fmt->fmt.win.w.height = win->height;
514 fmt->fmt.win.chromakey = win->chromakey;
515 fmt->fmt.win.clips = (void __user *)win->clips;
516 fmt->fmt.win.clipcount = win->clipcount;
517 err2 = drv(inode, file, VIDIOC_S_FMT, fmt);
519 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2);
521 if (err1 != 0 && err2 != 0)
529 static noinline int v4l1_compat_turn_preview_on_off(
536 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
539 /* dirty hack time. But v4l1 has no STREAMOFF
540 * equivalent in the API, and this one at
541 * least comes close ... */
542 drv(inode, file, VIDIOC_STREAMOFF, &captype);
544 err = drv(inode, file, VIDIOC_OVERLAY, on);
546 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
550 static noinline int v4l1_compat_get_input_info(
551 struct video_channel *chan,
557 struct v4l2_input input2;
560 memset(&input2, 0, sizeof(input2));
561 input2.index = chan->channel;
562 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
564 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
565 "channel=%d err=%d\n", chan->channel, err);
568 chan->channel = input2.index;
569 memcpy(chan->name, input2.name,
570 min(sizeof(chan->name), sizeof(input2.name)));
571 chan->name[sizeof(chan->name) - 1] = 0;
572 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
573 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
574 switch (input2.type) {
575 case V4L2_INPUT_TYPE_TUNER:
576 chan->type = VIDEO_TYPE_TV;
579 case V4L2_INPUT_TYPE_CAMERA:
580 chan->type = VIDEO_TYPE_CAMERA;
584 err = drv(inode, file, VIDIOC_G_STD, &sid);
586 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
588 if (sid & V4L2_STD_PAL)
589 chan->norm = VIDEO_MODE_PAL;
590 if (sid & V4L2_STD_NTSC)
591 chan->norm = VIDEO_MODE_NTSC;
592 if (sid & V4L2_STD_SECAM)
593 chan->norm = VIDEO_MODE_SECAM;
599 static noinline int v4l1_compat_set_input(
600 struct video_channel *chan,
608 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
610 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
611 switch (chan->norm) {
615 case VIDEO_MODE_NTSC:
618 case VIDEO_MODE_SECAM:
619 sid = V4L2_STD_SECAM;
623 err = drv(inode, file, VIDIOC_S_STD, &sid);
625 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
630 static noinline int v4l1_compat_get_picture(
631 struct video_picture *pict,
637 struct v4l2_format *fmt;
639 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
645 pict->brightness = get_v4l_control(inode, file,
646 V4L2_CID_BRIGHTNESS, drv);
647 pict->hue = get_v4l_control(inode, file,
649 pict->contrast = get_v4l_control(inode, file,
650 V4L2_CID_CONTRAST, drv);
651 pict->colour = get_v4l_control(inode, file,
652 V4L2_CID_SATURATION, drv);
653 pict->whiteness = get_v4l_control(inode, file,
654 V4L2_CID_WHITENESS, drv);
656 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
657 err = drv(inode, file, VIDIOC_G_FMT, fmt);
659 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
663 pict->depth = ((fmt->fmt.pix.bytesperline << 3)
664 + (fmt->fmt.pix.width - 1))
665 / fmt->fmt.pix.width;
666 pict->palette = pixelformat_to_palette(
667 fmt->fmt.pix.pixelformat);
673 static noinline int v4l1_compat_set_picture(
674 struct video_picture *pict,
680 struct v4l2_framebuffer fbuf;
681 int mem_err = 0, ovl_err = 0;
682 struct v4l2_format *fmt;
684 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
689 memset(&fbuf, 0, sizeof(fbuf));
691 set_v4l_control(inode, file,
692 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
693 set_v4l_control(inode, file,
694 V4L2_CID_HUE, pict->hue, drv);
695 set_v4l_control(inode, file,
696 V4L2_CID_CONTRAST, pict->contrast, drv);
697 set_v4l_control(inode, file,
698 V4L2_CID_SATURATION, pict->colour, drv);
699 set_v4l_control(inode, file,
700 V4L2_CID_WHITENESS, pict->whiteness, drv);
702 * V4L1 uses this ioctl to set both memory capture and overlay
703 * pixel format, while V4L2 has two different ioctls for this.
704 * Some cards may not support one or the other, and may support
705 * different pixel formats for memory vs overlay.
708 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
709 err = drv(inode, file, VIDIOC_G_FMT, fmt);
710 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
711 support memory capture. Trying to set the memory capture
712 parameters would be pointless. */
714 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
715 mem_err = -1000; /* didn't even try */
716 } else if (fmt->fmt.pix.pixelformat !=
717 palette_to_pixelformat(pict->palette)) {
718 fmt->fmt.pix.pixelformat = palette_to_pixelformat(
720 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt);
722 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
726 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
727 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
728 support overlay. Trying to set the overlay parameters
729 would be quite pointless. */
731 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
732 ovl_err = -1000; /* didn't even try */
733 } else if (fbuf.fmt.pixelformat !=
734 palette_to_pixelformat(pict->palette)) {
735 fbuf.fmt.pixelformat = palette_to_pixelformat(
737 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
739 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
742 if (ovl_err < 0 && mem_err < 0) {
743 /* ioctl failed, couldn't set either parameter */
744 if (mem_err != -1000)
746 else if (ovl_err == -EPERM)
756 static noinline int v4l1_compat_get_tuner(
757 struct video_tuner *tun,
763 struct v4l2_tuner tun2;
764 struct v4l2_standard std2;
767 memset(&tun2, 0, sizeof(tun2));
768 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
770 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
773 memcpy(tun->name, tun2.name,
774 min(sizeof(tun->name), sizeof(tun2.name)));
775 tun->name[sizeof(tun->name) - 1] = 0;
776 tun->rangelow = tun2.rangelow;
777 tun->rangehigh = tun2.rangehigh;
779 tun->mode = VIDEO_MODE_AUTO;
781 for (i = 0; i < 64; i++) {
782 memset(&std2, 0, sizeof(std2));
784 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
786 if (std2.id & V4L2_STD_PAL)
787 tun->flags |= VIDEO_TUNER_PAL;
788 if (std2.id & V4L2_STD_NTSC)
789 tun->flags |= VIDEO_TUNER_NTSC;
790 if (std2.id & V4L2_STD_SECAM)
791 tun->flags |= VIDEO_TUNER_SECAM;
794 err = drv(inode, file, VIDIOC_G_STD, &sid);
796 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
798 if (sid & V4L2_STD_PAL)
799 tun->mode = VIDEO_MODE_PAL;
800 if (sid & V4L2_STD_NTSC)
801 tun->mode = VIDEO_MODE_NTSC;
802 if (sid & V4L2_STD_SECAM)
803 tun->mode = VIDEO_MODE_SECAM;
806 if (tun2.capability & V4L2_TUNER_CAP_LOW)
807 tun->flags |= VIDEO_TUNER_LOW;
808 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
809 tun->flags |= VIDEO_TUNER_STEREO_ON;
810 tun->signal = tun2.signal;
815 static noinline int v4l1_compat_select_tuner(
816 struct video_tuner *tun,
822 struct v4l2_tuner t;/*84 bytes on x86_64*/
823 memset(&t, 0, sizeof(t));
825 t.index = tun->tuner;
827 err = drv(inode, file, VIDIOC_S_INPUT, &t);
829 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
833 static noinline int v4l1_compat_get_frequency(
840 struct v4l2_frequency freq2;
841 memset(&freq2, 0, sizeof(freq2));
844 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
846 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
848 *freq = freq2.frequency;
852 static noinline int v4l1_compat_set_frequency(
859 struct v4l2_frequency freq2;
860 memset(&freq2, 0, sizeof(freq2));
862 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
863 freq2.frequency = *freq;
864 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
866 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
870 static noinline int v4l1_compat_get_audio(
871 struct video_audio *aud,
877 struct v4l2_queryctrl qctrl2;
878 struct v4l2_audio aud2;
879 struct v4l2_tuner tun2;
880 memset(&aud2, 0, sizeof(aud2));
882 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
884 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err);
887 memcpy(aud->name, aud2.name,
888 min(sizeof(aud->name), sizeof(aud2.name)));
889 aud->name[sizeof(aud->name) - 1] = 0;
890 aud->audio = aud2.index;
892 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
895 aud->flags |= VIDEO_AUDIO_VOLUME;
897 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
900 aud->flags |= VIDEO_AUDIO_BASS;
902 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
905 aud->flags |= VIDEO_AUDIO_TREBLE;
907 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
910 aud->flags |= VIDEO_AUDIO_BALANCE;
912 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
915 aud->flags |= VIDEO_AUDIO_MUTE;
916 aud->flags |= VIDEO_AUDIO_MUTABLE;
919 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
920 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
921 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
922 aud->step = qctrl2.step;
925 memset(&tun2, 0, sizeof(tun2));
926 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
928 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err);
933 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
934 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
935 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
936 aud->mode = VIDEO_SOUND_STEREO;
937 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
938 aud->mode = VIDEO_SOUND_MONO;
943 static noinline int v4l1_compat_set_audio(
944 struct video_audio *aud,
950 struct v4l2_audio aud2;
951 struct v4l2_tuner tun2;
953 memset(&aud2, 0, sizeof(aud2));
954 memset(&tun2, 0, sizeof(tun2));
956 aud2.index = aud->audio;
957 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
959 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err);
963 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
965 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
967 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
969 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
971 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
972 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
974 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
976 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err);
980 case VIDEO_SOUND_MONO:
981 case VIDEO_SOUND_LANG1:
982 tun2.audmode = V4L2_TUNER_MODE_MONO;
984 case VIDEO_SOUND_STEREO:
985 tun2.audmode = V4L2_TUNER_MODE_STEREO;
987 case VIDEO_SOUND_LANG2:
988 tun2.audmode = V4L2_TUNER_MODE_LANG2;
991 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
993 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err);
1000 static noinline int v4l1_compat_capture_frame(
1001 struct video_mmap *mm,
1002 struct inode *inode,
1007 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1008 struct v4l2_buffer buf;
1009 struct v4l2_format *fmt;
1011 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
1016 memset(&buf, 0, sizeof(buf));
1018 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1019 err = drv(inode, file, VIDIOC_G_FMT, fmt);
1021 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err);
1024 if (mm->width != fmt->fmt.pix.width ||
1025 mm->height != fmt->fmt.pix.height ||
1026 palette_to_pixelformat(mm->format) !=
1027 fmt->fmt.pix.pixelformat) {
1028 /* New capture format... */
1029 fmt->fmt.pix.width = mm->width;
1030 fmt->fmt.pix.height = mm->height;
1031 fmt->fmt.pix.pixelformat =
1032 palette_to_pixelformat(mm->format);
1033 fmt->fmt.pix.field = V4L2_FIELD_ANY;
1034 fmt->fmt.pix.bytesperline = 0;
1035 err = drv(inode, file, VIDIOC_S_FMT, fmt);
1037 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err);
1041 buf.index = mm->frame;
1042 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1043 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1045 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err);
1048 err = drv(inode, file, VIDIOC_QBUF, &buf);
1050 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
1053 err = drv(inode, file, VIDIOC_STREAMON, &captype);
1055 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
1061 static noinline int v4l1_compat_sync(
1063 struct inode *inode,
1068 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1069 struct v4l2_buffer buf;
1070 struct poll_wqueues *pwq;
1072 memset(&buf, 0, sizeof(buf));
1074 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1075 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1077 /* No such buffer */
1078 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1081 if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
1082 /* Buffer is not mapped */
1087 /* make sure capture actually runs so we don't block forever */
1088 err = drv(inode, file, VIDIOC_STREAMON, &captype);
1090 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err);
1094 pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
1095 /* Loop as long as the buffer is queued, but not done */
1096 while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
1097 == V4L2_BUF_FLAG_QUEUED) {
1098 err = poll_one(file, pwq);
1099 if (err < 0 || /* error or sleep was interrupted */
1100 err == 0) /* timeout? Shouldn't occur. */
1102 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1104 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1107 if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1110 err = drv(inode, file, VIDIOC_DQBUF, &buf);
1112 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err);
1113 } while (err == 0 && buf.index != *i);
1118 static noinline int v4l1_compat_get_vbi_format(
1119 struct vbi_format *fmt,
1120 struct inode *inode,
1125 struct v4l2_format *fmt2;
1127 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1132 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1134 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
1136 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
1139 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1143 memset(fmt, 0, sizeof(*fmt));
1144 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1145 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1146 fmt->sample_format = VIDEO_PALETTE_RAW;
1147 fmt->start[0] = fmt2->fmt.vbi.start[0];
1148 fmt->count[0] = fmt2->fmt.vbi.count[0];
1149 fmt->start[1] = fmt2->fmt.vbi.start[1];
1150 fmt->count[1] = fmt2->fmt.vbi.count[1];
1151 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1157 static noinline int v4l1_compat_set_vbi_format(
1158 struct vbi_format *fmt,
1159 struct inode *inode,
1164 struct v4l2_format *fmt2 = NULL;
1166 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1171 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1176 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1177 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1178 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1179 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1180 fmt2->fmt.vbi.start[0] = fmt->start[0];
1181 fmt2->fmt.vbi.count[0] = fmt->count[0];
1182 fmt2->fmt.vbi.start[1] = fmt->start[1];
1183 fmt2->fmt.vbi.count[1] = fmt->count[1];
1184 fmt2->fmt.vbi.flags = fmt->flags;
1185 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1187 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1191 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1192 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1193 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1194 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1195 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1196 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1197 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1198 fmt2->fmt.vbi.flags != fmt->flags) {
1202 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1204 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1211 * This function is exported.
1214 v4l_compat_translate_ioctl(struct inode *inode,
1223 case VIDIOCGCAP: /* capability */
1224 err = v4l1_compat_get_capabilities(arg, inode, file, drv);
1226 case VIDIOCGFBUF: /* get frame buffer */
1227 err = v4l1_compat_get_frame_buffer(arg, inode, file, drv);
1229 case VIDIOCSFBUF: /* set frame buffer */
1230 err = v4l1_compat_set_frame_buffer(arg, inode, file, drv);
1232 case VIDIOCGWIN: /* get window or capture dimensions */
1233 err = v4l1_compat_get_win_cap_dimensions(arg, inode, file, drv);
1235 case VIDIOCSWIN: /* set window and/or capture dimensions */
1236 err = v4l1_compat_set_win_cap_dimensions(arg, inode, file, drv);
1238 case VIDIOCCAPTURE: /* turn on/off preview */
1239 err = v4l1_compat_turn_preview_on_off(arg, inode, file, drv);
1241 case VIDIOCGCHAN: /* get input information */
1242 err = v4l1_compat_get_input_info(arg, inode, file, drv);
1244 case VIDIOCSCHAN: /* set input */
1245 err = v4l1_compat_set_input(arg, inode, file, drv);
1247 case VIDIOCGPICT: /* get tone controls & partial capture format */
1248 err = v4l1_compat_get_picture(arg, inode, file, drv);
1250 case VIDIOCSPICT: /* set tone controls & partial capture format */
1251 err = v4l1_compat_set_picture(arg, inode, file, drv);
1253 case VIDIOCGTUNER: /* get tuner information */
1254 err = v4l1_compat_get_tuner(arg, inode, file, drv);
1256 case VIDIOCSTUNER: /* select a tuner input */
1257 err = v4l1_compat_select_tuner(arg, inode, file, drv);
1259 case VIDIOCGFREQ: /* get frequency */
1260 err = v4l1_compat_get_frequency(arg, inode, file, drv);
1262 case VIDIOCSFREQ: /* set frequency */
1263 err = v4l1_compat_set_frequency(arg, inode, file, drv);
1265 case VIDIOCGAUDIO: /* get audio properties/controls */
1266 err = v4l1_compat_get_audio(arg, inode, file, drv);
1268 case VIDIOCSAUDIO: /* set audio controls */
1269 err = v4l1_compat_set_audio(arg, inode, file, drv);
1271 case VIDIOCMCAPTURE: /* capture a frame */
1272 err = v4l1_compat_capture_frame(arg, inode, file, drv);
1274 case VIDIOCSYNC: /* wait for a frame */
1275 err = v4l1_compat_sync(arg, inode, file, drv);
1277 case VIDIOCGVBIFMT: /* query VBI data capture format */
1278 err = v4l1_compat_get_vbi_format(arg, inode, file, drv);
1281 err = v4l1_compat_set_vbi_format(arg, inode, file, drv);
1290 EXPORT_SYMBOL(v4l_compat_translate_ioctl);