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 inode *inode,
65 struct v4l2_queryctrl qctrl2;
66 struct v4l2_control ctrl2;
70 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
72 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
73 if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
75 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2);
77 dprintk("VIDIOC_G_CTRL: %d\n", err);
80 return ((ctrl2.value - qctrl2.minimum) * 65535
81 + (qctrl2.maximum - qctrl2.minimum) / 2)
82 / (qctrl2.maximum - qctrl2.minimum);
88 set_v4l_control(struct inode *inode,
94 struct v4l2_queryctrl qctrl2;
95 struct v4l2_control ctrl2;
99 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
101 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
103 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
104 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
109 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
111 ctrl2.id = qctrl2.id;
113 (value * (qctrl2.maximum - qctrl2.minimum)
116 ctrl2.value += qctrl2.minimum;
117 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
119 dprintk("VIDIOC_S_CTRL: %d\n", err);
124 /* ----------------------------------------------------------------- */
126 static const unsigned int palette2pixelformat[] = {
127 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
128 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
129 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
130 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
131 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
132 /* yuv packed pixel */
133 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
134 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
135 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
137 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
138 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
139 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
140 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
141 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
144 static unsigned int __pure
145 palette_to_pixelformat(unsigned int palette)
147 if (palette < ARRAY_SIZE(palette2pixelformat))
148 return palette2pixelformat[palette];
153 static unsigned int __attribute_const__
154 pixelformat_to_palette(unsigned int pixelformat)
157 switch (pixelformat) {
158 case V4L2_PIX_FMT_GREY:
159 palette = VIDEO_PALETTE_GREY;
161 case V4L2_PIX_FMT_RGB555:
162 palette = VIDEO_PALETTE_RGB555;
164 case V4L2_PIX_FMT_RGB565:
165 palette = VIDEO_PALETTE_RGB565;
167 case V4L2_PIX_FMT_BGR24:
168 palette = VIDEO_PALETTE_RGB24;
170 case V4L2_PIX_FMT_BGR32:
171 palette = VIDEO_PALETTE_RGB32;
173 /* yuv packed pixel */
174 case V4L2_PIX_FMT_YUYV:
175 palette = VIDEO_PALETTE_YUYV;
177 case V4L2_PIX_FMT_UYVY:
178 palette = VIDEO_PALETTE_UYVY;
181 case V4L2_PIX_FMT_YUV410:
182 palette = VIDEO_PALETTE_YUV420;
184 case V4L2_PIX_FMT_YUV420:
185 palette = VIDEO_PALETTE_YUV420;
187 case V4L2_PIX_FMT_YUV411P:
188 palette = VIDEO_PALETTE_YUV411P;
190 case V4L2_PIX_FMT_YUV422P:
191 palette = VIDEO_PALETTE_YUV422P;
197 /* ----------------------------------------------------------------- */
199 static int poll_one(struct file *file, struct poll_wqueues *pwq)
208 set_current_state(TASK_INTERRUPTIBLE);
209 mask = file->f_op->poll(file, table);
213 if (signal_pending(current)) {
214 retval = -ERESTARTSYS;
219 set_current_state(TASK_RUNNING);
224 static int count_inputs(
229 struct v4l2_input input2;
233 memset(&input2, 0, sizeof(input2));
235 if (0 != drv(inode, file, VIDIOC_ENUMINPUT, &input2))
241 static int check_size(
248 struct v4l2_fmtdesc desc2;
249 struct v4l2_format fmt2;
251 memset(&desc2, 0, sizeof(desc2));
252 memset(&fmt2, 0, sizeof(fmt2));
254 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
255 if (0 != drv(inode, file, VIDIOC_ENUM_FMT, &desc2))
258 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
259 fmt2.fmt.pix.width = 10000;
260 fmt2.fmt.pix.height = 10000;
261 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
262 if (0 != drv(inode, file, VIDIOC_TRY_FMT, &fmt2))
265 *maxw = fmt2.fmt.pix.width;
266 *maxh = fmt2.fmt.pix.height;
272 /* ----------------------------------------------------------------- */
274 static noinline int v4l1_compat_get_capabilities(
275 struct video_capability *cap,
281 struct v4l2_framebuffer fbuf;
282 struct v4l2_capability *cap2;
284 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
289 memset(cap, 0, sizeof(*cap));
290 memset(&fbuf, 0, sizeof(fbuf));
292 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
294 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
297 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
298 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
300 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
301 memset(&fbuf, 0, sizeof(fbuf));
306 memcpy(cap->name, cap2->card,
307 min(sizeof(cap->name), sizeof(cap2->card)));
308 cap->name[sizeof(cap->name) - 1] = 0;
309 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
310 cap->type |= VID_TYPE_CAPTURE;
311 if (cap2->capabilities & V4L2_CAP_TUNER)
312 cap->type |= VID_TYPE_TUNER;
313 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
314 cap->type |= VID_TYPE_TELETEXT;
315 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
316 cap->type |= VID_TYPE_OVERLAY;
317 if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
318 cap->type |= VID_TYPE_CLIPPING;
320 cap->channels = count_inputs(inode, file, drv);
321 check_size(inode, file, drv,
322 &cap->maxwidth, &cap->maxheight);
323 cap->audios = 0; /* FIXME */
324 cap->minwidth = 48; /* FIXME */
325 cap->minheight = 32; /* FIXME */
332 static noinline int v4l1_compat_get_frame_buffer(
333 struct video_buffer *buffer,
339 struct v4l2_framebuffer fbuf;
341 memset(buffer, 0, sizeof(*buffer));
342 memset(&fbuf, 0, sizeof(fbuf));
344 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
346 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
349 buffer->base = fbuf.base;
350 buffer->height = fbuf.fmt.height;
351 buffer->width = fbuf.fmt.width;
353 switch (fbuf.fmt.pixelformat) {
354 case V4L2_PIX_FMT_RGB332:
357 case V4L2_PIX_FMT_RGB555:
360 case V4L2_PIX_FMT_RGB565:
363 case V4L2_PIX_FMT_BGR24:
366 case V4L2_PIX_FMT_BGR32:
372 if (fbuf.fmt.bytesperline) {
373 buffer->bytesperline = fbuf.fmt.bytesperline;
374 if (!buffer->depth && buffer->width)
375 buffer->depth = ((fbuf.fmt.bytesperline<<3)
379 buffer->bytesperline =
380 (buffer->width * buffer->depth + 7) & 7;
381 buffer->bytesperline >>= 3;
387 static noinline int v4l1_compat_set_frame_buffer(
388 struct video_buffer *buffer,
394 struct v4l2_framebuffer fbuf;
396 memset(&fbuf, 0, sizeof(fbuf));
397 fbuf.base = buffer->base;
398 fbuf.fmt.height = buffer->height;
399 fbuf.fmt.width = buffer->width;
400 switch (buffer->depth) {
402 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
405 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
408 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
411 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
414 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
417 fbuf.fmt.bytesperline = buffer->bytesperline;
418 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
420 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
424 static noinline int v4l1_compat_get_win_cap_dimensions(
425 struct video_window *win,
431 struct v4l2_format *fmt;
433 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
438 memset(win, 0, sizeof(*win));
440 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
441 err = drv(inode, file, VIDIOC_G_FMT, fmt);
443 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
445 win->x = fmt->fmt.win.w.left;
446 win->y = fmt->fmt.win.w.top;
447 win->width = fmt->fmt.win.w.width;
448 win->height = fmt->fmt.win.w.height;
449 win->chromakey = fmt->fmt.win.chromakey;
455 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
456 err = drv(inode, file, VIDIOC_G_FMT, fmt);
458 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
463 win->width = fmt->fmt.pix.width;
464 win->height = fmt->fmt.pix.height;
473 static noinline int v4l1_compat_set_win_cap_dimensions(
474 struct video_window *win,
480 struct v4l2_format *fmt;
482 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
487 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
488 drv(inode, file, VIDIOC_STREAMOFF, &fmt->type);
489 err1 = drv(inode, file, VIDIOC_G_FMT, fmt);
491 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1);
493 fmt->fmt.pix.width = win->width;
494 fmt->fmt.pix.height = win->height;
495 fmt->fmt.pix.field = V4L2_FIELD_ANY;
496 fmt->fmt.pix.bytesperline = 0;
497 err = drv(inode, file, VIDIOC_S_FMT, fmt);
499 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
501 win->width = fmt->fmt.pix.width;
502 win->height = fmt->fmt.pix.height;
505 memset(fmt, 0, sizeof(*fmt));
506 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
507 fmt->fmt.win.w.left = win->x;
508 fmt->fmt.win.w.top = win->y;
509 fmt->fmt.win.w.width = win->width;
510 fmt->fmt.win.w.height = win->height;
511 fmt->fmt.win.chromakey = win->chromakey;
512 fmt->fmt.win.clips = (void __user *)win->clips;
513 fmt->fmt.win.clipcount = win->clipcount;
514 err2 = drv(inode, file, VIDIOC_S_FMT, fmt);
516 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2);
518 if (err1 != 0 && err2 != 0)
526 static noinline int v4l1_compat_turn_preview_on_off(
533 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
536 /* dirty hack time. But v4l1 has no STREAMOFF
537 * equivalent in the API, and this one at
538 * least comes close ... */
539 drv(inode, file, VIDIOC_STREAMOFF, &captype);
541 err = drv(inode, file, VIDIOC_OVERLAY, on);
543 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
547 static noinline int v4l1_compat_get_input_info(
548 struct video_channel *chan,
554 struct v4l2_input input2;
557 memset(&input2, 0, sizeof(input2));
558 input2.index = chan->channel;
559 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
561 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
562 "channel=%d err=%d\n", chan->channel, err);
565 chan->channel = input2.index;
566 memcpy(chan->name, input2.name,
567 min(sizeof(chan->name), sizeof(input2.name)));
568 chan->name[sizeof(chan->name) - 1] = 0;
569 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
570 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
571 switch (input2.type) {
572 case V4L2_INPUT_TYPE_TUNER:
573 chan->type = VIDEO_TYPE_TV;
576 case V4L2_INPUT_TYPE_CAMERA:
577 chan->type = VIDEO_TYPE_CAMERA;
581 err = drv(inode, file, VIDIOC_G_STD, &sid);
583 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
585 if (sid & V4L2_STD_PAL)
586 chan->norm = VIDEO_MODE_PAL;
587 if (sid & V4L2_STD_NTSC)
588 chan->norm = VIDEO_MODE_NTSC;
589 if (sid & V4L2_STD_SECAM)
590 chan->norm = VIDEO_MODE_SECAM;
596 static noinline int v4l1_compat_set_input(
597 struct video_channel *chan,
605 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
607 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
608 switch (chan->norm) {
612 case VIDEO_MODE_NTSC:
615 case VIDEO_MODE_SECAM:
616 sid = V4L2_STD_SECAM;
620 err = drv(inode, file, VIDIOC_S_STD, &sid);
622 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
627 static noinline int v4l1_compat_get_picture(
628 struct video_picture *pict,
634 struct v4l2_format *fmt;
636 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
642 pict->brightness = get_v4l_control(inode, file,
643 V4L2_CID_BRIGHTNESS, drv);
644 pict->hue = get_v4l_control(inode, file,
646 pict->contrast = get_v4l_control(inode, file,
647 V4L2_CID_CONTRAST, drv);
648 pict->colour = get_v4l_control(inode, file,
649 V4L2_CID_SATURATION, drv);
650 pict->whiteness = get_v4l_control(inode, file,
651 V4L2_CID_WHITENESS, drv);
653 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
654 err = drv(inode, file, VIDIOC_G_FMT, fmt);
656 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
660 pict->depth = ((fmt->fmt.pix.bytesperline << 3)
661 + (fmt->fmt.pix.width - 1))
662 / fmt->fmt.pix.width;
663 pict->palette = pixelformat_to_palette(
664 fmt->fmt.pix.pixelformat);
670 static noinline int v4l1_compat_set_picture(
671 struct video_picture *pict,
677 struct v4l2_framebuffer fbuf;
678 int mem_err = 0, ovl_err = 0;
679 struct v4l2_format *fmt;
681 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
686 memset(&fbuf, 0, sizeof(fbuf));
688 set_v4l_control(inode, file,
689 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
690 set_v4l_control(inode, file,
691 V4L2_CID_HUE, pict->hue, drv);
692 set_v4l_control(inode, file,
693 V4L2_CID_CONTRAST, pict->contrast, drv);
694 set_v4l_control(inode, file,
695 V4L2_CID_SATURATION, pict->colour, drv);
696 set_v4l_control(inode, file,
697 V4L2_CID_WHITENESS, pict->whiteness, drv);
699 * V4L1 uses this ioctl to set both memory capture and overlay
700 * pixel format, while V4L2 has two different ioctls for this.
701 * Some cards may not support one or the other, and may support
702 * different pixel formats for memory vs overlay.
705 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
706 err = drv(inode, file, VIDIOC_G_FMT, fmt);
707 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
708 support memory capture. Trying to set the memory capture
709 parameters would be pointless. */
711 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
712 mem_err = -1000; /* didn't even try */
713 } else if (fmt->fmt.pix.pixelformat !=
714 palette_to_pixelformat(pict->palette)) {
715 fmt->fmt.pix.pixelformat = palette_to_pixelformat(
717 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt);
719 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
723 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
724 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
725 support overlay. Trying to set the overlay parameters
726 would be quite pointless. */
728 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
729 ovl_err = -1000; /* didn't even try */
730 } else if (fbuf.fmt.pixelformat !=
731 palette_to_pixelformat(pict->palette)) {
732 fbuf.fmt.pixelformat = palette_to_pixelformat(
734 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
736 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
739 if (ovl_err < 0 && mem_err < 0) {
740 /* ioctl failed, couldn't set either parameter */
741 if (mem_err != -1000)
743 else if (ovl_err == -EPERM)
753 static noinline int v4l1_compat_get_tuner(
754 struct video_tuner *tun,
760 struct v4l2_tuner tun2;
761 struct v4l2_standard std2;
764 memset(&tun2, 0, sizeof(tun2));
765 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
767 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
770 memcpy(tun->name, tun2.name,
771 min(sizeof(tun->name), sizeof(tun2.name)));
772 tun->name[sizeof(tun->name) - 1] = 0;
773 tun->rangelow = tun2.rangelow;
774 tun->rangehigh = tun2.rangehigh;
776 tun->mode = VIDEO_MODE_AUTO;
778 for (i = 0; i < 64; i++) {
779 memset(&std2, 0, sizeof(std2));
781 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
783 if (std2.id & V4L2_STD_PAL)
784 tun->flags |= VIDEO_TUNER_PAL;
785 if (std2.id & V4L2_STD_NTSC)
786 tun->flags |= VIDEO_TUNER_NTSC;
787 if (std2.id & V4L2_STD_SECAM)
788 tun->flags |= VIDEO_TUNER_SECAM;
791 err = drv(inode, file, VIDIOC_G_STD, &sid);
793 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
795 if (sid & V4L2_STD_PAL)
796 tun->mode = VIDEO_MODE_PAL;
797 if (sid & V4L2_STD_NTSC)
798 tun->mode = VIDEO_MODE_NTSC;
799 if (sid & V4L2_STD_SECAM)
800 tun->mode = VIDEO_MODE_SECAM;
803 if (tun2.capability & V4L2_TUNER_CAP_LOW)
804 tun->flags |= VIDEO_TUNER_LOW;
805 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
806 tun->flags |= VIDEO_TUNER_STEREO_ON;
807 tun->signal = tun2.signal;
812 static noinline int v4l1_compat_select_tuner(
813 struct video_tuner *tun,
819 struct v4l2_tuner t;/*84 bytes on x86_64*/
820 memset(&t, 0, sizeof(t));
822 t.index = tun->tuner;
824 err = drv(inode, file, VIDIOC_S_INPUT, &t);
826 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
830 static noinline int v4l1_compat_get_frequency(
837 struct v4l2_frequency freq2;
838 memset(&freq2, 0, sizeof(freq2));
841 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
843 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
845 *freq = freq2.frequency;
849 static noinline int v4l1_compat_set_frequency(
856 struct v4l2_frequency freq2;
857 memset(&freq2, 0, sizeof(freq2));
859 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
860 freq2.frequency = *freq;
861 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
863 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
867 static noinline int v4l1_compat_get_audio(
868 struct video_audio *aud,
874 struct v4l2_queryctrl qctrl2;
875 struct v4l2_audio aud2;
876 struct v4l2_tuner tun2;
877 memset(&aud2, 0, sizeof(aud2));
879 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
881 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err);
884 memcpy(aud->name, aud2.name,
885 min(sizeof(aud->name), sizeof(aud2.name)));
886 aud->name[sizeof(aud->name) - 1] = 0;
887 aud->audio = aud2.index;
889 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
892 aud->flags |= VIDEO_AUDIO_VOLUME;
894 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
897 aud->flags |= VIDEO_AUDIO_BASS;
899 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
902 aud->flags |= VIDEO_AUDIO_TREBLE;
904 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
907 aud->flags |= VIDEO_AUDIO_BALANCE;
909 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
912 aud->flags |= VIDEO_AUDIO_MUTE;
913 aud->flags |= VIDEO_AUDIO_MUTABLE;
916 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
917 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
918 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
919 aud->step = qctrl2.step;
922 memset(&tun2, 0, sizeof(tun2));
923 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
925 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err);
930 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
931 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
932 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
933 aud->mode = VIDEO_SOUND_STEREO;
934 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
935 aud->mode = VIDEO_SOUND_MONO;
940 static noinline int v4l1_compat_set_audio(
941 struct video_audio *aud,
947 struct v4l2_audio aud2;
948 struct v4l2_tuner tun2;
950 memset(&aud2, 0, sizeof(aud2));
951 memset(&tun2, 0, sizeof(tun2));
953 aud2.index = aud->audio;
954 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
956 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err);
960 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
962 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
964 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
966 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
968 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
969 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
971 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
973 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err);
977 case VIDEO_SOUND_MONO:
978 case VIDEO_SOUND_LANG1:
979 tun2.audmode = V4L2_TUNER_MODE_MONO;
981 case VIDEO_SOUND_STEREO:
982 tun2.audmode = V4L2_TUNER_MODE_STEREO;
984 case VIDEO_SOUND_LANG2:
985 tun2.audmode = V4L2_TUNER_MODE_LANG2;
988 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
990 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err);
997 static noinline int v4l1_compat_capture_frame(
998 struct video_mmap *mm,
1004 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1005 struct v4l2_buffer buf;
1006 struct v4l2_format *fmt;
1008 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
1013 memset(&buf, 0, sizeof(buf));
1015 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1016 err = drv(inode, file, VIDIOC_G_FMT, fmt);
1018 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err);
1021 if (mm->width != fmt->fmt.pix.width ||
1022 mm->height != fmt->fmt.pix.height ||
1023 palette_to_pixelformat(mm->format) !=
1024 fmt->fmt.pix.pixelformat) {
1025 /* New capture format... */
1026 fmt->fmt.pix.width = mm->width;
1027 fmt->fmt.pix.height = mm->height;
1028 fmt->fmt.pix.pixelformat =
1029 palette_to_pixelformat(mm->format);
1030 fmt->fmt.pix.field = V4L2_FIELD_ANY;
1031 fmt->fmt.pix.bytesperline = 0;
1032 err = drv(inode, file, VIDIOC_S_FMT, fmt);
1034 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err);
1038 buf.index = mm->frame;
1039 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1040 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1042 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err);
1045 err = drv(inode, file, VIDIOC_QBUF, &buf);
1047 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
1050 err = drv(inode, file, VIDIOC_STREAMON, &captype);
1052 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
1058 static noinline int v4l1_compat_sync(
1060 struct inode *inode,
1065 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1066 struct v4l2_buffer buf;
1067 struct poll_wqueues *pwq;
1069 memset(&buf, 0, sizeof(buf));
1071 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1072 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1074 /* No such buffer */
1075 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1078 if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
1079 /* Buffer is not mapped */
1084 /* make sure capture actually runs so we don't block forever */
1085 err = drv(inode, file, VIDIOC_STREAMON, &captype);
1087 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err);
1091 pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
1092 /* Loop as long as the buffer is queued, but not done */
1093 while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
1094 == V4L2_BUF_FLAG_QUEUED) {
1095 err = poll_one(file, pwq);
1096 if (err < 0 || /* error or sleep was interrupted */
1097 err == 0) /* timeout? Shouldn't occur. */
1099 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1101 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1104 if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1107 err = drv(inode, file, VIDIOC_DQBUF, &buf);
1109 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err);
1110 } while (err == 0 && buf.index != *i);
1115 static noinline int v4l1_compat_get_vbi_format(
1116 struct vbi_format *fmt,
1117 struct inode *inode,
1122 struct v4l2_format *fmt2;
1124 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1129 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1131 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
1133 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
1136 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1140 memset(fmt, 0, sizeof(*fmt));
1141 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1142 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1143 fmt->sample_format = VIDEO_PALETTE_RAW;
1144 fmt->start[0] = fmt2->fmt.vbi.start[0];
1145 fmt->count[0] = fmt2->fmt.vbi.count[0];
1146 fmt->start[1] = fmt2->fmt.vbi.start[1];
1147 fmt->count[1] = fmt2->fmt.vbi.count[1];
1148 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1154 static noinline int v4l1_compat_set_vbi_format(
1155 struct vbi_format *fmt,
1156 struct inode *inode,
1161 struct v4l2_format *fmt2 = NULL;
1163 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1168 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1173 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1174 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1175 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1176 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1177 fmt2->fmt.vbi.start[0] = fmt->start[0];
1178 fmt2->fmt.vbi.count[0] = fmt->count[0];
1179 fmt2->fmt.vbi.start[1] = fmt->start[1];
1180 fmt2->fmt.vbi.count[1] = fmt->count[1];
1181 fmt2->fmt.vbi.flags = fmt->flags;
1182 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1184 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1188 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1189 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1190 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1191 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1192 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1193 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1194 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1195 fmt2->fmt.vbi.flags != fmt->flags) {
1199 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1201 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1208 * This function is exported.
1211 v4l_compat_translate_ioctl(struct inode *inode,
1220 case VIDIOCGCAP: /* capability */
1221 err = v4l1_compat_get_capabilities(arg, inode, file, drv);
1223 case VIDIOCGFBUF: /* get frame buffer */
1224 err = v4l1_compat_get_frame_buffer(arg, inode, file, drv);
1226 case VIDIOCSFBUF: /* set frame buffer */
1227 err = v4l1_compat_set_frame_buffer(arg, inode, file, drv);
1229 case VIDIOCGWIN: /* get window or capture dimensions */
1230 err = v4l1_compat_get_win_cap_dimensions(arg, inode, file, drv);
1232 case VIDIOCSWIN: /* set window and/or capture dimensions */
1233 err = v4l1_compat_set_win_cap_dimensions(arg, inode, file, drv);
1235 case VIDIOCCAPTURE: /* turn on/off preview */
1236 err = v4l1_compat_turn_preview_on_off(arg, inode, file, drv);
1238 case VIDIOCGCHAN: /* get input information */
1239 err = v4l1_compat_get_input_info(arg, inode, file, drv);
1241 case VIDIOCSCHAN: /* set input */
1242 err = v4l1_compat_set_input(arg, inode, file, drv);
1244 case VIDIOCGPICT: /* get tone controls & partial capture format */
1245 err = v4l1_compat_get_picture(arg, inode, file, drv);
1247 case VIDIOCSPICT: /* set tone controls & partial capture format */
1248 err = v4l1_compat_set_picture(arg, inode, file, drv);
1250 case VIDIOCGTUNER: /* get tuner information */
1251 err = v4l1_compat_get_tuner(arg, inode, file, drv);
1253 case VIDIOCSTUNER: /* select a tuner input */
1254 err = v4l1_compat_select_tuner(arg, inode, file, drv);
1256 case VIDIOCGFREQ: /* get frequency */
1257 err = v4l1_compat_get_frequency(arg, inode, file, drv);
1259 case VIDIOCSFREQ: /* set frequency */
1260 err = v4l1_compat_set_frequency(arg, inode, file, drv);
1262 case VIDIOCGAUDIO: /* get audio properties/controls */
1263 err = v4l1_compat_get_audio(arg, inode, file, drv);
1265 case VIDIOCSAUDIO: /* set audio controls */
1266 err = v4l1_compat_set_audio(arg, inode, file, drv);
1268 case VIDIOCMCAPTURE: /* capture a frame */
1269 err = v4l1_compat_capture_frame(arg, inode, file, drv);
1271 case VIDIOCSYNC: /* wait for a frame */
1272 err = v4l1_compat_sync(arg, inode, file, drv);
1274 case VIDIOCGVBIFMT: /* query VBI data capture format */
1275 err = v4l1_compat_get_vbi_format(arg, inode, file, drv);
1278 err = v4l1_compat_set_vbi_format(arg, inode, file, drv);
1287 EXPORT_SYMBOL(v4l_compat_translate_ioctl);