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>
33 #include <media/v4l2-ioctl.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
37 #include <asm/pgtable.h>
39 static unsigned int debug;
40 module_param(debug, int, 0644);
41 MODULE_PARM_DESC(debug, "enable debug messages");
42 MODULE_AUTHOR("Bill Dirks");
43 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
44 MODULE_LICENSE("GPL");
46 #define dprintk(fmt, arg...) \
49 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\
53 * I O C T L T R A N S L A T I O N
55 * From here on down is the code for translating the numerous
56 * ioctl commands from the old API to the new API.
60 get_v4l_control(struct file *file,
64 struct v4l2_queryctrl qctrl2;
65 struct v4l2_control ctrl2;
69 err = drv(file, VIDIOC_QUERYCTRL, &qctrl2);
71 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
72 if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
74 err = drv(file, VIDIOC_G_CTRL, &ctrl2);
76 dprintk("VIDIOC_G_CTRL: %d\n", err);
79 return ((ctrl2.value - qctrl2.minimum) * 65535
80 + (qctrl2.maximum - qctrl2.minimum) / 2)
81 / (qctrl2.maximum - qctrl2.minimum);
87 set_v4l_control(struct file *file,
92 struct v4l2_queryctrl qctrl2;
93 struct v4l2_control ctrl2;
97 err = drv(file, VIDIOC_QUERYCTRL, &qctrl2);
99 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
101 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
102 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
107 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
109 ctrl2.id = qctrl2.id;
111 (value * (qctrl2.maximum - qctrl2.minimum)
114 ctrl2.value += qctrl2.minimum;
115 err = drv(file, VIDIOC_S_CTRL, &ctrl2);
117 dprintk("VIDIOC_S_CTRL: %d\n", err);
122 /* ----------------------------------------------------------------- */
124 static const unsigned int palette2pixelformat[] = {
125 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
126 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
127 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
128 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
129 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
130 /* yuv packed pixel */
131 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
132 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
133 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
135 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
136 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
137 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
138 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
139 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
142 static unsigned int __pure
143 palette_to_pixelformat(unsigned int palette)
145 if (palette < ARRAY_SIZE(palette2pixelformat))
146 return palette2pixelformat[palette];
151 static unsigned int __attribute_const__
152 pixelformat_to_palette(unsigned int pixelformat)
155 switch (pixelformat) {
156 case V4L2_PIX_FMT_GREY:
157 palette = VIDEO_PALETTE_GREY;
159 case V4L2_PIX_FMT_RGB555:
160 palette = VIDEO_PALETTE_RGB555;
162 case V4L2_PIX_FMT_RGB565:
163 palette = VIDEO_PALETTE_RGB565;
165 case V4L2_PIX_FMT_BGR24:
166 palette = VIDEO_PALETTE_RGB24;
168 case V4L2_PIX_FMT_BGR32:
169 palette = VIDEO_PALETTE_RGB32;
171 /* yuv packed pixel */
172 case V4L2_PIX_FMT_YUYV:
173 palette = VIDEO_PALETTE_YUYV;
175 case V4L2_PIX_FMT_UYVY:
176 palette = VIDEO_PALETTE_UYVY;
179 case V4L2_PIX_FMT_YUV410:
180 palette = VIDEO_PALETTE_YUV420;
182 case V4L2_PIX_FMT_YUV420:
183 palette = VIDEO_PALETTE_YUV420;
185 case V4L2_PIX_FMT_YUV411P:
186 palette = VIDEO_PALETTE_YUV411P;
188 case V4L2_PIX_FMT_YUV422P:
189 palette = VIDEO_PALETTE_YUV422P;
195 /* ----------------------------------------------------------------- */
197 static int poll_one(struct file *file, struct poll_wqueues *pwq)
206 set_current_state(TASK_INTERRUPTIBLE);
207 mask = file->f_op->poll(file, table);
211 if (signal_pending(current)) {
212 retval = -ERESTARTSYS;
217 set_current_state(TASK_RUNNING);
222 static int count_inputs(
226 struct v4l2_input input2;
230 memset(&input2, 0, sizeof(input2));
232 if (0 != drv(file, VIDIOC_ENUMINPUT, &input2))
238 static int check_size(
244 struct v4l2_fmtdesc desc2;
245 struct v4l2_format fmt2;
247 memset(&desc2, 0, sizeof(desc2));
248 memset(&fmt2, 0, sizeof(fmt2));
250 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
251 if (0 != drv(file, VIDIOC_ENUM_FMT, &desc2))
254 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
255 fmt2.fmt.pix.width = 10000;
256 fmt2.fmt.pix.height = 10000;
257 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
258 if (0 != drv(file, VIDIOC_TRY_FMT, &fmt2))
261 *maxw = fmt2.fmt.pix.width;
262 *maxh = fmt2.fmt.pix.height;
268 /* ----------------------------------------------------------------- */
270 static noinline int v4l1_compat_get_capabilities(
271 struct video_capability *cap,
276 struct v4l2_framebuffer fbuf;
277 struct v4l2_capability *cap2;
279 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
284 memset(cap, 0, sizeof(*cap));
285 memset(&fbuf, 0, sizeof(fbuf));
287 err = drv(file, VIDIOC_QUERYCAP, cap2);
289 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
292 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
293 err = drv(file, VIDIOC_G_FBUF, &fbuf);
295 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
296 memset(&fbuf, 0, sizeof(fbuf));
301 memcpy(cap->name, cap2->card,
302 min(sizeof(cap->name), sizeof(cap2->card)));
303 cap->name[sizeof(cap->name) - 1] = 0;
304 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
305 cap->type |= VID_TYPE_CAPTURE;
306 if (cap2->capabilities & V4L2_CAP_TUNER)
307 cap->type |= VID_TYPE_TUNER;
308 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
309 cap->type |= VID_TYPE_TELETEXT;
310 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
311 cap->type |= VID_TYPE_OVERLAY;
312 if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
313 cap->type |= VID_TYPE_CLIPPING;
315 cap->channels = count_inputs(file, drv);
316 check_size(file, drv,
317 &cap->maxwidth, &cap->maxheight);
318 cap->audios = 0; /* FIXME */
319 cap->minwidth = 48; /* FIXME */
320 cap->minheight = 32; /* FIXME */
327 static noinline int v4l1_compat_get_frame_buffer(
328 struct video_buffer *buffer,
333 struct v4l2_framebuffer fbuf;
335 memset(buffer, 0, sizeof(*buffer));
336 memset(&fbuf, 0, sizeof(fbuf));
338 err = drv(file, VIDIOC_G_FBUF, &fbuf);
340 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
343 buffer->base = fbuf.base;
344 buffer->height = fbuf.fmt.height;
345 buffer->width = fbuf.fmt.width;
347 switch (fbuf.fmt.pixelformat) {
348 case V4L2_PIX_FMT_RGB332:
351 case V4L2_PIX_FMT_RGB555:
354 case V4L2_PIX_FMT_RGB565:
357 case V4L2_PIX_FMT_BGR24:
360 case V4L2_PIX_FMT_BGR32:
366 if (fbuf.fmt.bytesperline) {
367 buffer->bytesperline = fbuf.fmt.bytesperline;
368 if (!buffer->depth && buffer->width)
369 buffer->depth = ((fbuf.fmt.bytesperline<<3)
373 buffer->bytesperline =
374 (buffer->width * buffer->depth + 7) & 7;
375 buffer->bytesperline >>= 3;
381 static noinline int v4l1_compat_set_frame_buffer(
382 struct video_buffer *buffer,
387 struct v4l2_framebuffer fbuf;
389 memset(&fbuf, 0, sizeof(fbuf));
390 fbuf.base = buffer->base;
391 fbuf.fmt.height = buffer->height;
392 fbuf.fmt.width = buffer->width;
393 switch (buffer->depth) {
395 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
398 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
401 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
404 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
407 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
410 fbuf.fmt.bytesperline = buffer->bytesperline;
411 err = drv(file, VIDIOC_S_FBUF, &fbuf);
413 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
417 static noinline int v4l1_compat_get_win_cap_dimensions(
418 struct video_window *win,
423 struct v4l2_format *fmt;
425 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
430 memset(win, 0, sizeof(*win));
432 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
433 err = drv(file, VIDIOC_G_FMT, fmt);
435 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
437 win->x = fmt->fmt.win.w.left;
438 win->y = fmt->fmt.win.w.top;
439 win->width = fmt->fmt.win.w.width;
440 win->height = fmt->fmt.win.w.height;
441 win->chromakey = fmt->fmt.win.chromakey;
447 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
448 err = drv(file, VIDIOC_G_FMT, fmt);
450 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
455 win->width = fmt->fmt.pix.width;
456 win->height = fmt->fmt.pix.height;
465 static noinline int v4l1_compat_set_win_cap_dimensions(
466 struct video_window *win,
471 struct v4l2_format *fmt;
473 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
478 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
479 drv(file, VIDIOC_STREAMOFF, &fmt->type);
480 err1 = drv(file, VIDIOC_G_FMT, fmt);
482 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1);
484 fmt->fmt.pix.width = win->width;
485 fmt->fmt.pix.height = win->height;
486 fmt->fmt.pix.field = V4L2_FIELD_ANY;
487 fmt->fmt.pix.bytesperline = 0;
488 err = drv(file, VIDIOC_S_FMT, fmt);
490 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
492 win->width = fmt->fmt.pix.width;
493 win->height = fmt->fmt.pix.height;
496 memset(fmt, 0, sizeof(*fmt));
497 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
498 fmt->fmt.win.w.left = win->x;
499 fmt->fmt.win.w.top = win->y;
500 fmt->fmt.win.w.width = win->width;
501 fmt->fmt.win.w.height = win->height;
502 fmt->fmt.win.chromakey = win->chromakey;
503 fmt->fmt.win.clips = (void __user *)win->clips;
504 fmt->fmt.win.clipcount = win->clipcount;
505 err2 = drv(file, VIDIOC_S_FMT, fmt);
507 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2);
509 if (err1 != 0 && err2 != 0)
517 static noinline int v4l1_compat_turn_preview_on_off(
523 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
526 /* dirty hack time. But v4l1 has no STREAMOFF
527 * equivalent in the API, and this one at
528 * least comes close ... */
529 drv(file, VIDIOC_STREAMOFF, &captype);
531 err = drv(file, VIDIOC_OVERLAY, on);
533 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
537 static noinline int v4l1_compat_get_input_info(
538 struct video_channel *chan,
543 struct v4l2_input input2;
546 memset(&input2, 0, sizeof(input2));
547 input2.index = chan->channel;
548 err = drv(file, VIDIOC_ENUMINPUT, &input2);
550 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
551 "channel=%d err=%d\n", chan->channel, err);
554 chan->channel = input2.index;
555 memcpy(chan->name, input2.name,
556 min(sizeof(chan->name), sizeof(input2.name)));
557 chan->name[sizeof(chan->name) - 1] = 0;
558 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
559 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
560 switch (input2.type) {
561 case V4L2_INPUT_TYPE_TUNER:
562 chan->type = VIDEO_TYPE_TV;
565 case V4L2_INPUT_TYPE_CAMERA:
566 chan->type = VIDEO_TYPE_CAMERA;
570 err = drv(file, VIDIOC_G_STD, &sid);
572 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
574 if (sid & V4L2_STD_PAL)
575 chan->norm = VIDEO_MODE_PAL;
576 if (sid & V4L2_STD_NTSC)
577 chan->norm = VIDEO_MODE_NTSC;
578 if (sid & V4L2_STD_SECAM)
579 chan->norm = VIDEO_MODE_SECAM;
585 static noinline int v4l1_compat_set_input(
586 struct video_channel *chan,
593 err = drv(file, VIDIOC_S_INPUT, &chan->channel);
595 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
596 switch (chan->norm) {
600 case VIDEO_MODE_NTSC:
603 case VIDEO_MODE_SECAM:
604 sid = V4L2_STD_SECAM;
608 err = drv(file, VIDIOC_S_STD, &sid);
610 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
615 static noinline int v4l1_compat_get_picture(
616 struct video_picture *pict,
621 struct v4l2_format *fmt;
623 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
629 pict->brightness = get_v4l_control(file,
630 V4L2_CID_BRIGHTNESS, drv);
631 pict->hue = get_v4l_control(file,
633 pict->contrast = get_v4l_control(file,
634 V4L2_CID_CONTRAST, drv);
635 pict->colour = get_v4l_control(file,
636 V4L2_CID_SATURATION, drv);
637 pict->whiteness = get_v4l_control(file,
638 V4L2_CID_WHITENESS, drv);
640 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
641 err = drv(file, VIDIOC_G_FMT, fmt);
643 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
647 pict->depth = ((fmt->fmt.pix.bytesperline << 3)
648 + (fmt->fmt.pix.width - 1))
649 / fmt->fmt.pix.width;
650 pict->palette = pixelformat_to_palette(
651 fmt->fmt.pix.pixelformat);
657 static noinline int v4l1_compat_set_picture(
658 struct video_picture *pict,
663 struct v4l2_framebuffer fbuf;
664 int mem_err = 0, ovl_err = 0;
665 struct v4l2_format *fmt;
667 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
672 memset(&fbuf, 0, sizeof(fbuf));
674 set_v4l_control(file,
675 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
676 set_v4l_control(file,
677 V4L2_CID_HUE, pict->hue, drv);
678 set_v4l_control(file,
679 V4L2_CID_CONTRAST, pict->contrast, drv);
680 set_v4l_control(file,
681 V4L2_CID_SATURATION, pict->colour, drv);
682 set_v4l_control(file,
683 V4L2_CID_WHITENESS, pict->whiteness, drv);
685 * V4L1 uses this ioctl to set both memory capture and overlay
686 * pixel format, while V4L2 has two different ioctls for this.
687 * Some cards may not support one or the other, and may support
688 * different pixel formats for memory vs overlay.
691 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
692 err = drv(file, VIDIOC_G_FMT, fmt);
693 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
694 support memory capture. Trying to set the memory capture
695 parameters would be pointless. */
697 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
698 mem_err = -1000; /* didn't even try */
699 } else if (fmt->fmt.pix.pixelformat !=
700 palette_to_pixelformat(pict->palette)) {
701 fmt->fmt.pix.pixelformat = palette_to_pixelformat(
703 mem_err = drv(file, VIDIOC_S_FMT, fmt);
705 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
709 err = drv(file, VIDIOC_G_FBUF, &fbuf);
710 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
711 support overlay. Trying to set the overlay parameters
712 would be quite pointless. */
714 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
715 ovl_err = -1000; /* didn't even try */
716 } else if (fbuf.fmt.pixelformat !=
717 palette_to_pixelformat(pict->palette)) {
718 fbuf.fmt.pixelformat = palette_to_pixelformat(
720 ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf);
722 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
725 if (ovl_err < 0 && mem_err < 0) {
726 /* ioctl failed, couldn't set either parameter */
727 if (mem_err != -1000)
729 else if (ovl_err == -EPERM)
739 static noinline int v4l1_compat_get_tuner(
740 struct video_tuner *tun,
745 struct v4l2_tuner tun2;
746 struct v4l2_standard std2;
749 memset(&tun2, 0, sizeof(tun2));
750 err = drv(file, VIDIOC_G_TUNER, &tun2);
752 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
755 memcpy(tun->name, tun2.name,
756 min(sizeof(tun->name), sizeof(tun2.name)));
757 tun->name[sizeof(tun->name) - 1] = 0;
758 tun->rangelow = tun2.rangelow;
759 tun->rangehigh = tun2.rangehigh;
761 tun->mode = VIDEO_MODE_AUTO;
763 for (i = 0; i < 64; i++) {
764 memset(&std2, 0, sizeof(std2));
766 if (0 != drv(file, VIDIOC_ENUMSTD, &std2))
768 if (std2.id & V4L2_STD_PAL)
769 tun->flags |= VIDEO_TUNER_PAL;
770 if (std2.id & V4L2_STD_NTSC)
771 tun->flags |= VIDEO_TUNER_NTSC;
772 if (std2.id & V4L2_STD_SECAM)
773 tun->flags |= VIDEO_TUNER_SECAM;
776 err = drv(file, VIDIOC_G_STD, &sid);
778 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
780 if (sid & V4L2_STD_PAL)
781 tun->mode = VIDEO_MODE_PAL;
782 if (sid & V4L2_STD_NTSC)
783 tun->mode = VIDEO_MODE_NTSC;
784 if (sid & V4L2_STD_SECAM)
785 tun->mode = VIDEO_MODE_SECAM;
788 if (tun2.capability & V4L2_TUNER_CAP_LOW)
789 tun->flags |= VIDEO_TUNER_LOW;
790 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
791 tun->flags |= VIDEO_TUNER_STEREO_ON;
792 tun->signal = tun2.signal;
797 static noinline int v4l1_compat_select_tuner(
798 struct video_tuner *tun,
803 struct v4l2_tuner t;/*84 bytes on x86_64*/
804 memset(&t, 0, sizeof(t));
806 t.index = tun->tuner;
808 err = drv(file, VIDIOC_S_INPUT, &t);
810 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
814 static noinline int v4l1_compat_get_frequency(
820 struct v4l2_frequency freq2;
821 memset(&freq2, 0, sizeof(freq2));
824 err = drv(file, VIDIOC_G_FREQUENCY, &freq2);
826 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
828 *freq = freq2.frequency;
832 static noinline int v4l1_compat_set_frequency(
838 struct v4l2_frequency freq2;
839 memset(&freq2, 0, sizeof(freq2));
841 drv(file, VIDIOC_G_FREQUENCY, &freq2);
842 freq2.frequency = *freq;
843 err = drv(file, VIDIOC_S_FREQUENCY, &freq2);
845 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
849 static noinline int v4l1_compat_get_audio(
850 struct video_audio *aud,
855 struct v4l2_queryctrl qctrl2;
856 struct v4l2_audio aud2;
857 struct v4l2_tuner tun2;
858 memset(&aud2, 0, sizeof(aud2));
860 err = drv(file, VIDIOC_G_AUDIO, &aud2);
862 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err);
865 memcpy(aud->name, aud2.name,
866 min(sizeof(aud->name), sizeof(aud2.name)));
867 aud->name[sizeof(aud->name) - 1] = 0;
868 aud->audio = aud2.index;
870 i = get_v4l_control(file, V4L2_CID_AUDIO_VOLUME, drv);
873 aud->flags |= VIDEO_AUDIO_VOLUME;
875 i = get_v4l_control(file, V4L2_CID_AUDIO_BASS, drv);
878 aud->flags |= VIDEO_AUDIO_BASS;
880 i = get_v4l_control(file, V4L2_CID_AUDIO_TREBLE, drv);
883 aud->flags |= VIDEO_AUDIO_TREBLE;
885 i = get_v4l_control(file, V4L2_CID_AUDIO_BALANCE, drv);
888 aud->flags |= VIDEO_AUDIO_BALANCE;
890 i = get_v4l_control(file, V4L2_CID_AUDIO_MUTE, drv);
893 aud->flags |= VIDEO_AUDIO_MUTE;
894 aud->flags |= VIDEO_AUDIO_MUTABLE;
897 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
898 if (drv(file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
899 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
900 aud->step = qctrl2.step;
903 memset(&tun2, 0, sizeof(tun2));
904 err = drv(file, VIDIOC_G_TUNER, &tun2);
906 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err);
911 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
912 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
913 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
914 aud->mode = VIDEO_SOUND_STEREO;
915 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
916 aud->mode = VIDEO_SOUND_MONO;
921 static noinline int v4l1_compat_set_audio(
922 struct video_audio *aud,
927 struct v4l2_audio aud2;
928 struct v4l2_tuner tun2;
930 memset(&aud2, 0, sizeof(aud2));
931 memset(&tun2, 0, sizeof(tun2));
933 aud2.index = aud->audio;
934 err = drv(file, VIDIOC_S_AUDIO, &aud2);
936 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err);
940 set_v4l_control(file, V4L2_CID_AUDIO_VOLUME,
942 set_v4l_control(file, V4L2_CID_AUDIO_BASS,
944 set_v4l_control(file, V4L2_CID_AUDIO_TREBLE,
946 set_v4l_control(file, V4L2_CID_AUDIO_BALANCE,
948 set_v4l_control(file, V4L2_CID_AUDIO_MUTE,
949 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
951 err = drv(file, VIDIOC_G_TUNER, &tun2);
953 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err);
957 case VIDEO_SOUND_MONO:
958 case VIDEO_SOUND_LANG1:
959 tun2.audmode = V4L2_TUNER_MODE_MONO;
961 case VIDEO_SOUND_STEREO:
962 tun2.audmode = V4L2_TUNER_MODE_STEREO;
964 case VIDEO_SOUND_LANG2:
965 tun2.audmode = V4L2_TUNER_MODE_LANG2;
968 err = drv(file, VIDIOC_S_TUNER, &tun2);
970 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err);
977 static noinline int v4l1_compat_capture_frame(
978 struct video_mmap *mm,
983 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
984 struct v4l2_buffer buf;
985 struct v4l2_format *fmt;
987 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
992 memset(&buf, 0, sizeof(buf));
994 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
995 err = drv(file, VIDIOC_G_FMT, fmt);
997 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err);
1000 if (mm->width != fmt->fmt.pix.width ||
1001 mm->height != fmt->fmt.pix.height ||
1002 palette_to_pixelformat(mm->format) !=
1003 fmt->fmt.pix.pixelformat) {
1004 /* New capture format... */
1005 fmt->fmt.pix.width = mm->width;
1006 fmt->fmt.pix.height = mm->height;
1007 fmt->fmt.pix.pixelformat =
1008 palette_to_pixelformat(mm->format);
1009 fmt->fmt.pix.field = V4L2_FIELD_ANY;
1010 fmt->fmt.pix.bytesperline = 0;
1011 err = drv(file, VIDIOC_S_FMT, fmt);
1013 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err);
1017 buf.index = mm->frame;
1018 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1019 err = drv(file, VIDIOC_QUERYBUF, &buf);
1021 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err);
1024 err = drv(file, VIDIOC_QBUF, &buf);
1026 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
1029 err = drv(file, VIDIOC_STREAMON, &captype);
1031 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
1037 static noinline int v4l1_compat_sync(
1043 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1044 struct v4l2_buffer buf;
1045 struct poll_wqueues *pwq;
1047 memset(&buf, 0, sizeof(buf));
1049 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1050 err = drv(file, VIDIOC_QUERYBUF, &buf);
1052 /* No such buffer */
1053 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1056 if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
1057 /* Buffer is not mapped */
1062 /* make sure capture actually runs so we don't block forever */
1063 err = drv(file, VIDIOC_STREAMON, &captype);
1065 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err);
1069 pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
1070 /* Loop as long as the buffer is queued, but not done */
1071 while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
1072 == V4L2_BUF_FLAG_QUEUED) {
1073 err = poll_one(file, pwq);
1074 if (err < 0 || /* error or sleep was interrupted */
1075 err == 0) /* timeout? Shouldn't occur. */
1077 err = drv(file, VIDIOC_QUERYBUF, &buf);
1079 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1082 if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1085 err = drv(file, VIDIOC_DQBUF, &buf);
1087 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err);
1088 } while (err == 0 && buf.index != *i);
1093 static noinline int v4l1_compat_get_vbi_format(
1094 struct vbi_format *fmt,
1099 struct v4l2_format *fmt2;
1101 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1106 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1108 err = drv(file, VIDIOC_G_FMT, fmt2);
1110 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
1113 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1117 memset(fmt, 0, sizeof(*fmt));
1118 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1119 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1120 fmt->sample_format = VIDEO_PALETTE_RAW;
1121 fmt->start[0] = fmt2->fmt.vbi.start[0];
1122 fmt->count[0] = fmt2->fmt.vbi.count[0];
1123 fmt->start[1] = fmt2->fmt.vbi.start[1];
1124 fmt->count[1] = fmt2->fmt.vbi.count[1];
1125 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1131 static noinline int v4l1_compat_set_vbi_format(
1132 struct vbi_format *fmt,
1137 struct v4l2_format *fmt2 = NULL;
1139 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1144 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1149 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1150 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1151 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1152 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1153 fmt2->fmt.vbi.start[0] = fmt->start[0];
1154 fmt2->fmt.vbi.count[0] = fmt->count[0];
1155 fmt2->fmt.vbi.start[1] = fmt->start[1];
1156 fmt2->fmt.vbi.count[1] = fmt->count[1];
1157 fmt2->fmt.vbi.flags = fmt->flags;
1158 err = drv(file, VIDIOC_TRY_FMT, fmt2);
1160 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1164 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1165 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1166 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1167 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1168 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1169 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1170 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1171 fmt2->fmt.vbi.flags != fmt->flags) {
1175 err = drv(file, VIDIOC_S_FMT, fmt2);
1177 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1184 * This function is exported.
1187 v4l_compat_translate_ioctl(struct file *file,
1195 case VIDIOCGCAP: /* capability */
1196 err = v4l1_compat_get_capabilities(arg, file, drv);
1198 case VIDIOCGFBUF: /* get frame buffer */
1199 err = v4l1_compat_get_frame_buffer(arg, file, drv);
1201 case VIDIOCSFBUF: /* set frame buffer */
1202 err = v4l1_compat_set_frame_buffer(arg, file, drv);
1204 case VIDIOCGWIN: /* get window or capture dimensions */
1205 err = v4l1_compat_get_win_cap_dimensions(arg, file, drv);
1207 case VIDIOCSWIN: /* set window and/or capture dimensions */
1208 err = v4l1_compat_set_win_cap_dimensions(arg, file, drv);
1210 case VIDIOCCAPTURE: /* turn on/off preview */
1211 err = v4l1_compat_turn_preview_on_off(arg, file, drv);
1213 case VIDIOCGCHAN: /* get input information */
1214 err = v4l1_compat_get_input_info(arg, file, drv);
1216 case VIDIOCSCHAN: /* set input */
1217 err = v4l1_compat_set_input(arg, file, drv);
1219 case VIDIOCGPICT: /* get tone controls & partial capture format */
1220 err = v4l1_compat_get_picture(arg, file, drv);
1222 case VIDIOCSPICT: /* set tone controls & partial capture format */
1223 err = v4l1_compat_set_picture(arg, file, drv);
1225 case VIDIOCGTUNER: /* get tuner information */
1226 err = v4l1_compat_get_tuner(arg, file, drv);
1228 case VIDIOCSTUNER: /* select a tuner input */
1229 err = v4l1_compat_select_tuner(arg, file, drv);
1231 case VIDIOCGFREQ: /* get frequency */
1232 err = v4l1_compat_get_frequency(arg, file, drv);
1234 case VIDIOCSFREQ: /* set frequency */
1235 err = v4l1_compat_set_frequency(arg, file, drv);
1237 case VIDIOCGAUDIO: /* get audio properties/controls */
1238 err = v4l1_compat_get_audio(arg, file, drv);
1240 case VIDIOCSAUDIO: /* set audio controls */
1241 err = v4l1_compat_set_audio(arg, file, drv);
1243 case VIDIOCMCAPTURE: /* capture a frame */
1244 err = v4l1_compat_capture_frame(arg, file, drv);
1246 case VIDIOCSYNC: /* wait for a frame */
1247 err = v4l1_compat_sync(arg, file, drv);
1249 case VIDIOCGVBIFMT: /* query VBI data capture format */
1250 err = v4l1_compat_get_vbi_format(arg, file, drv);
1253 err = v4l1_compat_set_vbi_format(arg, file, drv);
1262 EXPORT_SYMBOL(v4l_compat_translate_ioctl);