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 mask
= file
->f_op
->poll(file
, table
);
210 if (signal_pending(current
)) {
211 retval
= -ERESTARTSYS
;
214 poll_schedule(pwq
, TASK_INTERRUPTIBLE
);
220 static int count_inputs(
224 struct v4l2_input input2
;
228 memset(&input2
, 0, sizeof(input2
));
230 if (0 != drv(file
, VIDIOC_ENUMINPUT
, &input2
))
236 static int check_size(
242 struct v4l2_fmtdesc desc2
;
243 struct v4l2_format fmt2
;
245 memset(&desc2
, 0, sizeof(desc2
));
246 memset(&fmt2
, 0, sizeof(fmt2
));
248 desc2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
249 if (0 != drv(file
, VIDIOC_ENUM_FMT
, &desc2
))
252 fmt2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
253 fmt2
.fmt
.pix
.width
= 10000;
254 fmt2
.fmt
.pix
.height
= 10000;
255 fmt2
.fmt
.pix
.pixelformat
= desc2
.pixelformat
;
256 if (0 != drv(file
, VIDIOC_TRY_FMT
, &fmt2
))
259 *maxw
= fmt2
.fmt
.pix
.width
;
260 *maxh
= fmt2
.fmt
.pix
.height
;
266 /* ----------------------------------------------------------------- */
268 static noinline
long v4l1_compat_get_capabilities(
269 struct video_capability
*cap
,
274 struct v4l2_framebuffer fbuf
;
275 struct v4l2_capability
*cap2
;
277 cap2
= kzalloc(sizeof(*cap2
), GFP_KERNEL
);
282 memset(cap
, 0, sizeof(*cap
));
283 memset(&fbuf
, 0, sizeof(fbuf
));
285 err
= drv(file
, VIDIOC_QUERYCAP
, cap2
);
287 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %ld\n", err
);
290 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
) {
291 err
= drv(file
, VIDIOC_G_FBUF
, &fbuf
);
293 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %ld\n", err
);
294 memset(&fbuf
, 0, sizeof(fbuf
));
299 memcpy(cap
->name
, cap2
->card
,
300 min(sizeof(cap
->name
), sizeof(cap2
->card
)));
301 cap
->name
[sizeof(cap
->name
) - 1] = 0;
302 if (cap2
->capabilities
& V4L2_CAP_VIDEO_CAPTURE
)
303 cap
->type
|= VID_TYPE_CAPTURE
;
304 if (cap2
->capabilities
& V4L2_CAP_TUNER
)
305 cap
->type
|= VID_TYPE_TUNER
;
306 if (cap2
->capabilities
& V4L2_CAP_VBI_CAPTURE
)
307 cap
->type
|= VID_TYPE_TELETEXT
;
308 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
)
309 cap
->type
|= VID_TYPE_OVERLAY
;
310 if (fbuf
.capability
& V4L2_FBUF_CAP_LIST_CLIPPING
)
311 cap
->type
|= VID_TYPE_CLIPPING
;
313 cap
->channels
= count_inputs(file
, drv
);
314 check_size(file
, drv
,
315 &cap
->maxwidth
, &cap
->maxheight
);
316 cap
->audios
= 0; /* FIXME */
317 cap
->minwidth
= 48; /* FIXME */
318 cap
->minheight
= 32; /* FIXME */
325 static noinline
long v4l1_compat_get_frame_buffer(
326 struct video_buffer
*buffer
,
331 struct v4l2_framebuffer fbuf
;
333 memset(buffer
, 0, sizeof(*buffer
));
334 memset(&fbuf
, 0, sizeof(fbuf
));
336 err
= drv(file
, VIDIOC_G_FBUF
, &fbuf
);
338 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %ld\n", err
);
341 buffer
->base
= fbuf
.base
;
342 buffer
->height
= fbuf
.fmt
.height
;
343 buffer
->width
= fbuf
.fmt
.width
;
345 switch (fbuf
.fmt
.pixelformat
) {
346 case V4L2_PIX_FMT_RGB332
:
349 case V4L2_PIX_FMT_RGB555
:
352 case V4L2_PIX_FMT_RGB565
:
355 case V4L2_PIX_FMT_BGR24
:
358 case V4L2_PIX_FMT_BGR32
:
364 if (fbuf
.fmt
.bytesperline
) {
365 buffer
->bytesperline
= fbuf
.fmt
.bytesperline
;
366 if (!buffer
->depth
&& buffer
->width
)
367 buffer
->depth
= ((fbuf
.fmt
.bytesperline
<<3)
371 buffer
->bytesperline
=
372 (buffer
->width
* buffer
->depth
+ 7) & 7;
373 buffer
->bytesperline
>>= 3;
379 static noinline
long v4l1_compat_set_frame_buffer(
380 struct video_buffer
*buffer
,
385 struct v4l2_framebuffer fbuf
;
387 memset(&fbuf
, 0, sizeof(fbuf
));
388 fbuf
.base
= buffer
->base
;
389 fbuf
.fmt
.height
= buffer
->height
;
390 fbuf
.fmt
.width
= buffer
->width
;
391 switch (buffer
->depth
) {
393 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB332
;
396 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB555
;
399 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB565
;
402 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR24
;
405 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR32
;
408 fbuf
.fmt
.bytesperline
= buffer
->bytesperline
;
409 err
= drv(file
, VIDIOC_S_FBUF
, &fbuf
);
411 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %ld\n", err
);
415 static noinline
long v4l1_compat_get_win_cap_dimensions(
416 struct video_window
*win
,
421 struct v4l2_format
*fmt
;
423 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
428 memset(win
, 0, sizeof(*win
));
430 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
431 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
433 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %ld\n", err
);
435 win
->x
= fmt
->fmt
.win
.w
.left
;
436 win
->y
= fmt
->fmt
.win
.w
.top
;
437 win
->width
= fmt
->fmt
.win
.w
.width
;
438 win
->height
= fmt
->fmt
.win
.w
.height
;
439 win
->chromakey
= fmt
->fmt
.win
.chromakey
;
445 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
446 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
448 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %ld\n", err
);
453 win
->width
= fmt
->fmt
.pix
.width
;
454 win
->height
= fmt
->fmt
.pix
.height
;
463 static noinline
long v4l1_compat_set_win_cap_dimensions(
464 struct video_window
*win
,
468 long err
, err1
, err2
;
469 struct v4l2_format
*fmt
;
471 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
476 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
477 drv(file
, VIDIOC_STREAMOFF
, &fmt
->type
);
478 err1
= drv(file
, VIDIOC_G_FMT
, fmt
);
480 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %ld\n", err1
);
482 fmt
->fmt
.pix
.width
= win
->width
;
483 fmt
->fmt
.pix
.height
= win
->height
;
484 fmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
485 fmt
->fmt
.pix
.bytesperline
= 0;
486 err
= drv(file
, VIDIOC_S_FMT
, fmt
);
488 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %ld\n",
490 win
->width
= fmt
->fmt
.pix
.width
;
491 win
->height
= fmt
->fmt
.pix
.height
;
494 memset(fmt
, 0, sizeof(*fmt
));
495 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
496 fmt
->fmt
.win
.w
.left
= win
->x
;
497 fmt
->fmt
.win
.w
.top
= win
->y
;
498 fmt
->fmt
.win
.w
.width
= win
->width
;
499 fmt
->fmt
.win
.w
.height
= win
->height
;
500 fmt
->fmt
.win
.chromakey
= win
->chromakey
;
501 fmt
->fmt
.win
.clips
= (void __user
*)win
->clips
;
502 fmt
->fmt
.win
.clipcount
= win
->clipcount
;
503 err2
= drv(file
, VIDIOC_S_FMT
, fmt
);
505 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %ld\n", err2
);
507 if (err1
!= 0 && err2
!= 0)
515 static noinline
long v4l1_compat_turn_preview_on_off(
521 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
524 /* dirty hack time. But v4l1 has no STREAMOFF
525 * equivalent in the API, and this one at
526 * least comes close ... */
527 drv(file
, VIDIOC_STREAMOFF
, &captype
);
529 err
= drv(file
, VIDIOC_OVERLAY
, on
);
531 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %ld\n", err
);
535 static noinline
long v4l1_compat_get_input_info(
536 struct video_channel
*chan
,
541 struct v4l2_input input2
;
544 memset(&input2
, 0, sizeof(input2
));
545 input2
.index
= chan
->channel
;
546 err
= drv(file
, VIDIOC_ENUMINPUT
, &input2
);
548 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
549 "channel=%d err=%ld\n", chan
->channel
, err
);
552 chan
->channel
= input2
.index
;
553 memcpy(chan
->name
, input2
.name
,
554 min(sizeof(chan
->name
), sizeof(input2
.name
)));
555 chan
->name
[sizeof(chan
->name
) - 1] = 0;
556 chan
->tuners
= (input2
.type
== V4L2_INPUT_TYPE_TUNER
) ? 1 : 0;
557 chan
->flags
= (chan
->tuners
) ? VIDEO_VC_TUNER
: 0;
558 switch (input2
.type
) {
559 case V4L2_INPUT_TYPE_TUNER
:
560 chan
->type
= VIDEO_TYPE_TV
;
563 case V4L2_INPUT_TYPE_CAMERA
:
564 chan
->type
= VIDEO_TYPE_CAMERA
;
568 err
= drv(file
, VIDIOC_G_STD
, &sid
);
570 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %ld\n", err
);
572 if (sid
& V4L2_STD_PAL
)
573 chan
->norm
= VIDEO_MODE_PAL
;
574 if (sid
& V4L2_STD_NTSC
)
575 chan
->norm
= VIDEO_MODE_NTSC
;
576 if (sid
& V4L2_STD_SECAM
)
577 chan
->norm
= VIDEO_MODE_SECAM
;
578 if (sid
== V4L2_STD_ALL
)
579 chan
->norm
= VIDEO_MODE_AUTO
;
585 static noinline
long v4l1_compat_set_input(
586 struct video_channel
*chan
,
593 err
= drv(file
, VIDIOC_S_INPUT
, &chan
->channel
);
595 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %ld\n", err
);
596 switch (chan
->norm
) {
600 case VIDEO_MODE_NTSC
:
603 case VIDEO_MODE_SECAM
:
604 sid
= V4L2_STD_SECAM
;
606 case VIDEO_MODE_AUTO
:
611 err
= drv(file
, VIDIOC_S_STD
, &sid
);
613 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err
);
618 static noinline
long v4l1_compat_get_picture(
619 struct video_picture
*pict
,
624 struct v4l2_format
*fmt
;
626 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
632 pict
->brightness
= get_v4l_control(file
,
633 V4L2_CID_BRIGHTNESS
, drv
);
634 pict
->hue
= get_v4l_control(file
,
636 pict
->contrast
= get_v4l_control(file
,
637 V4L2_CID_CONTRAST
, drv
);
638 pict
->colour
= get_v4l_control(file
,
639 V4L2_CID_SATURATION
, drv
);
640 pict
->whiteness
= get_v4l_control(file
,
641 V4L2_CID_WHITENESS
, drv
);
643 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
644 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
646 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %ld\n", err
);
650 pict
->depth
= ((fmt
->fmt
.pix
.bytesperline
<< 3)
651 + (fmt
->fmt
.pix
.width
- 1))
652 / fmt
->fmt
.pix
.width
;
653 pict
->palette
= pixelformat_to_palette(
654 fmt
->fmt
.pix
.pixelformat
);
660 static noinline
long v4l1_compat_set_picture(
661 struct video_picture
*pict
,
666 struct v4l2_framebuffer fbuf
;
667 int mem_err
= 0, ovl_err
= 0;
668 struct v4l2_format
*fmt
;
670 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
675 memset(&fbuf
, 0, sizeof(fbuf
));
677 set_v4l_control(file
,
678 V4L2_CID_BRIGHTNESS
, pict
->brightness
, drv
);
679 set_v4l_control(file
,
680 V4L2_CID_HUE
, pict
->hue
, drv
);
681 set_v4l_control(file
,
682 V4L2_CID_CONTRAST
, pict
->contrast
, drv
);
683 set_v4l_control(file
,
684 V4L2_CID_SATURATION
, pict
->colour
, drv
);
685 set_v4l_control(file
,
686 V4L2_CID_WHITENESS
, pict
->whiteness
, drv
);
688 * V4L1 uses this ioctl to set both memory capture and overlay
689 * pixel format, while V4L2 has two different ioctls for this.
690 * Some cards may not support one or the other, and may support
691 * different pixel formats for memory vs overlay.
694 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
695 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
696 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
697 support memory capture. Trying to set the memory capture
698 parameters would be pointless. */
700 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err
);
701 mem_err
= -1000; /* didn't even try */
702 } else if (fmt
->fmt
.pix
.pixelformat
!=
703 palette_to_pixelformat(pict
->palette
)) {
704 fmt
->fmt
.pix
.pixelformat
= palette_to_pixelformat(
706 mem_err
= drv(file
, VIDIOC_S_FMT
, fmt
);
708 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
712 err
= drv(file
, VIDIOC_G_FBUF
, &fbuf
);
713 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
714 support overlay. Trying to set the overlay parameters
715 would be quite pointless. */
717 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err
);
718 ovl_err
= -1000; /* didn't even try */
719 } else if (fbuf
.fmt
.pixelformat
!=
720 palette_to_pixelformat(pict
->palette
)) {
721 fbuf
.fmt
.pixelformat
= palette_to_pixelformat(
723 ovl_err
= drv(file
, VIDIOC_S_FBUF
, &fbuf
);
725 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
728 if (ovl_err
< 0 && mem_err
< 0) {
729 /* ioctl failed, couldn't set either parameter */
730 if (mem_err
!= -1000)
732 else if (ovl_err
== -EPERM
)
742 static noinline
long v4l1_compat_get_tuner(
743 struct video_tuner
*tun
,
749 struct v4l2_tuner tun2
;
750 struct v4l2_standard std2
;
753 memset(&tun2
, 0, sizeof(tun2
));
754 err
= drv(file
, VIDIOC_G_TUNER
, &tun2
);
756 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err
);
759 memcpy(tun
->name
, tun2
.name
,
760 min(sizeof(tun
->name
), sizeof(tun2
.name
)));
761 tun
->name
[sizeof(tun
->name
) - 1] = 0;
762 tun
->rangelow
= tun2
.rangelow
;
763 tun
->rangehigh
= tun2
.rangehigh
;
765 tun
->mode
= VIDEO_MODE_AUTO
;
767 for (i
= 0; i
< 64; i
++) {
768 memset(&std2
, 0, sizeof(std2
));
770 if (0 != drv(file
, VIDIOC_ENUMSTD
, &std2
))
772 if (std2
.id
& V4L2_STD_PAL
)
773 tun
->flags
|= VIDEO_TUNER_PAL
;
774 if (std2
.id
& V4L2_STD_NTSC
)
775 tun
->flags
|= VIDEO_TUNER_NTSC
;
776 if (std2
.id
& V4L2_STD_SECAM
)
777 tun
->flags
|= VIDEO_TUNER_SECAM
;
780 err
= drv(file
, VIDIOC_G_STD
, &sid
);
782 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %ld\n", err
);
784 if (sid
& V4L2_STD_PAL
)
785 tun
->mode
= VIDEO_MODE_PAL
;
786 if (sid
& V4L2_STD_NTSC
)
787 tun
->mode
= VIDEO_MODE_NTSC
;
788 if (sid
& V4L2_STD_SECAM
)
789 tun
->mode
= VIDEO_MODE_SECAM
;
792 if (tun2
.capability
& V4L2_TUNER_CAP_LOW
)
793 tun
->flags
|= VIDEO_TUNER_LOW
;
794 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
795 tun
->flags
|= VIDEO_TUNER_STEREO_ON
;
796 tun
->signal
= tun2
.signal
;
801 static noinline
long v4l1_compat_select_tuner(
802 struct video_tuner
*tun
,
807 struct v4l2_tuner t
;/*84 bytes on x86_64*/
808 memset(&t
, 0, sizeof(t
));
810 t
.index
= tun
->tuner
;
812 err
= drv(file
, VIDIOC_S_TUNER
, &t
);
814 dprintk("VIDIOCSTUNER / VIDIOC_S_TUNER: %ld\n", err
);
818 static noinline
long v4l1_compat_get_frequency(
824 struct v4l2_frequency freq2
;
825 memset(&freq2
, 0, sizeof(freq2
));
828 err
= drv(file
, VIDIOC_G_FREQUENCY
, &freq2
);
830 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %ld\n", err
);
832 *freq
= freq2
.frequency
;
836 static noinline
long v4l1_compat_set_frequency(
842 struct v4l2_frequency freq2
;
843 memset(&freq2
, 0, sizeof(freq2
));
845 drv(file
, VIDIOC_G_FREQUENCY
, &freq2
);
846 freq2
.frequency
= *freq
;
847 err
= drv(file
, VIDIOC_S_FREQUENCY
, &freq2
);
849 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %ld\n", err
);
853 static noinline
long v4l1_compat_get_audio(
854 struct video_audio
*aud
,
860 struct v4l2_queryctrl qctrl2
;
861 struct v4l2_audio aud2
;
862 struct v4l2_tuner tun2
;
863 memset(&aud2
, 0, sizeof(aud2
));
865 err
= drv(file
, VIDIOC_G_AUDIO
, &aud2
);
867 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %ld\n", err
);
870 memcpy(aud
->name
, aud2
.name
,
871 min(sizeof(aud
->name
), sizeof(aud2
.name
)));
872 aud
->name
[sizeof(aud
->name
) - 1] = 0;
873 aud
->audio
= aud2
.index
;
875 i
= get_v4l_control(file
, V4L2_CID_AUDIO_VOLUME
, drv
);
878 aud
->flags
|= VIDEO_AUDIO_VOLUME
;
880 i
= get_v4l_control(file
, V4L2_CID_AUDIO_BASS
, drv
);
883 aud
->flags
|= VIDEO_AUDIO_BASS
;
885 i
= get_v4l_control(file
, V4L2_CID_AUDIO_TREBLE
, drv
);
888 aud
->flags
|= VIDEO_AUDIO_TREBLE
;
890 i
= get_v4l_control(file
, V4L2_CID_AUDIO_BALANCE
, drv
);
893 aud
->flags
|= VIDEO_AUDIO_BALANCE
;
895 i
= get_v4l_control(file
, V4L2_CID_AUDIO_MUTE
, drv
);
898 aud
->flags
|= VIDEO_AUDIO_MUTE
;
899 aud
->flags
|= VIDEO_AUDIO_MUTABLE
;
902 qctrl2
.id
= V4L2_CID_AUDIO_VOLUME
;
903 if (drv(file
, VIDIOC_QUERYCTRL
, &qctrl2
) == 0 &&
904 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
905 aud
->step
= qctrl2
.step
;
908 memset(&tun2
, 0, sizeof(tun2
));
909 err
= drv(file
, VIDIOC_G_TUNER
, &tun2
);
911 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %ld\n", err
);
916 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_LANG2
)
917 aud
->mode
= VIDEO_SOUND_LANG1
| VIDEO_SOUND_LANG2
;
918 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
919 aud
->mode
= VIDEO_SOUND_STEREO
;
920 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_MONO
)
921 aud
->mode
= VIDEO_SOUND_MONO
;
926 static noinline
long v4l1_compat_set_audio(
927 struct video_audio
*aud
,
932 struct v4l2_audio aud2
;
933 struct v4l2_tuner tun2
;
935 memset(&aud2
, 0, sizeof(aud2
));
936 memset(&tun2
, 0, sizeof(tun2
));
938 aud2
.index
= aud
->audio
;
939 err
= drv(file
, VIDIOC_S_AUDIO
, &aud2
);
941 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %ld\n", err
);
945 set_v4l_control(file
, V4L2_CID_AUDIO_VOLUME
,
947 set_v4l_control(file
, V4L2_CID_AUDIO_BASS
,
949 set_v4l_control(file
, V4L2_CID_AUDIO_TREBLE
,
951 set_v4l_control(file
, V4L2_CID_AUDIO_BALANCE
,
953 set_v4l_control(file
, V4L2_CID_AUDIO_MUTE
,
954 !!(aud
->flags
& VIDEO_AUDIO_MUTE
), drv
);
956 err
= drv(file
, VIDIOC_G_TUNER
, &tun2
);
958 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %ld\n", err
);
962 case VIDEO_SOUND_MONO
:
963 case VIDEO_SOUND_LANG1
:
964 tun2
.audmode
= V4L2_TUNER_MODE_MONO
;
966 case VIDEO_SOUND_STEREO
:
967 tun2
.audmode
= V4L2_TUNER_MODE_STEREO
;
969 case VIDEO_SOUND_LANG2
:
970 tun2
.audmode
= V4L2_TUNER_MODE_LANG2
;
973 err
= drv(file
, VIDIOC_S_TUNER
, &tun2
);
975 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %ld\n", err
);
982 static noinline
long v4l1_compat_capture_frame(
983 struct video_mmap
*mm
,
988 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
989 struct v4l2_buffer buf
;
990 struct v4l2_format
*fmt
;
992 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
997 memset(&buf
, 0, sizeof(buf
));
999 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1000 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
1002 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %ld\n", err
);
1005 if (mm
->width
!= fmt
->fmt
.pix
.width
||
1006 mm
->height
!= fmt
->fmt
.pix
.height
||
1007 palette_to_pixelformat(mm
->format
) !=
1008 fmt
->fmt
.pix
.pixelformat
) {
1009 /* New capture format... */
1010 fmt
->fmt
.pix
.width
= mm
->width
;
1011 fmt
->fmt
.pix
.height
= mm
->height
;
1012 fmt
->fmt
.pix
.pixelformat
=
1013 palette_to_pixelformat(mm
->format
);
1014 fmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
1015 fmt
->fmt
.pix
.bytesperline
= 0;
1016 err
= drv(file
, VIDIOC_S_FMT
, fmt
);
1018 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %ld\n", err
);
1022 buf
.index
= mm
->frame
;
1023 buf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1024 err
= drv(file
, VIDIOC_QUERYBUF
, &buf
);
1026 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %ld\n", err
);
1029 err
= drv(file
, VIDIOC_QBUF
, &buf
);
1031 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %ld\n", err
);
1034 err
= drv(file
, VIDIOC_STREAMON
, &captype
);
1036 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %ld\n", err
);
1042 static noinline
long v4l1_compat_sync(
1048 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1049 struct v4l2_buffer buf
;
1050 struct poll_wqueues
*pwq
;
1052 memset(&buf
, 0, sizeof(buf
));
1054 buf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1055 err
= drv(file
, VIDIOC_QUERYBUF
, &buf
);
1057 /* No such buffer */
1058 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err
);
1061 if (!(buf
.flags
& V4L2_BUF_FLAG_MAPPED
)) {
1062 /* Buffer is not mapped */
1067 /* make sure capture actually runs so we don't block forever */
1068 err
= drv(file
, VIDIOC_STREAMON
, &captype
);
1070 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %ld\n", err
);
1074 pwq
= kmalloc(sizeof(*pwq
), GFP_KERNEL
);
1075 /* Loop as long as the buffer is queued, but not done */
1076 while ((buf
.flags
& (V4L2_BUF_FLAG_QUEUED
| V4L2_BUF_FLAG_DONE
))
1077 == V4L2_BUF_FLAG_QUEUED
) {
1078 err
= poll_one(file
, pwq
);
1079 if (err
< 0 || /* error or sleep was interrupted */
1080 err
== 0) /* timeout? Shouldn't occur. */
1082 err
= drv(file
, VIDIOC_QUERYBUF
, &buf
);
1084 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err
);
1087 if (!(buf
.flags
& V4L2_BUF_FLAG_DONE
)) /* not done */
1090 err
= drv(file
, VIDIOC_DQBUF
, &buf
);
1092 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %ld\n", err
);
1093 } while (err
== 0 && buf
.index
!= *i
);
1098 static noinline
long v4l1_compat_get_vbi_format(
1099 struct vbi_format
*fmt
,
1104 struct v4l2_format
*fmt2
;
1106 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1111 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1113 err
= drv(file
, VIDIOC_G_FMT
, fmt2
);
1115 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %ld\n", err
);
1118 if (fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
) {
1122 memset(fmt
, 0, sizeof(*fmt
));
1123 fmt
->samples_per_line
= fmt2
->fmt
.vbi
.samples_per_line
;
1124 fmt
->sampling_rate
= fmt2
->fmt
.vbi
.sampling_rate
;
1125 fmt
->sample_format
= VIDEO_PALETTE_RAW
;
1126 fmt
->start
[0] = fmt2
->fmt
.vbi
.start
[0];
1127 fmt
->count
[0] = fmt2
->fmt
.vbi
.count
[0];
1128 fmt
->start
[1] = fmt2
->fmt
.vbi
.start
[1];
1129 fmt
->count
[1] = fmt2
->fmt
.vbi
.count
[1];
1130 fmt
->flags
= fmt2
->fmt
.vbi
.flags
& 0x03;
1136 static noinline
long v4l1_compat_set_vbi_format(
1137 struct vbi_format
*fmt
,
1142 struct v4l2_format
*fmt2
= NULL
;
1144 if (VIDEO_PALETTE_RAW
!= fmt
->sample_format
) {
1149 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1154 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1155 fmt2
->fmt
.vbi
.samples_per_line
= fmt
->samples_per_line
;
1156 fmt2
->fmt
.vbi
.sampling_rate
= fmt
->sampling_rate
;
1157 fmt2
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1158 fmt2
->fmt
.vbi
.start
[0] = fmt
->start
[0];
1159 fmt2
->fmt
.vbi
.count
[0] = fmt
->count
[0];
1160 fmt2
->fmt
.vbi
.start
[1] = fmt
->start
[1];
1161 fmt2
->fmt
.vbi
.count
[1] = fmt
->count
[1];
1162 fmt2
->fmt
.vbi
.flags
= fmt
->flags
;
1163 err
= drv(file
, VIDIOC_TRY_FMT
, fmt2
);
1165 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %ld\n", err
);
1169 if (fmt2
->fmt
.vbi
.samples_per_line
!= fmt
->samples_per_line
||
1170 fmt2
->fmt
.vbi
.sampling_rate
!= fmt
->sampling_rate
||
1171 fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
||
1172 fmt2
->fmt
.vbi
.start
[0] != fmt
->start
[0] ||
1173 fmt2
->fmt
.vbi
.count
[0] != fmt
->count
[0] ||
1174 fmt2
->fmt
.vbi
.start
[1] != fmt
->start
[1] ||
1175 fmt2
->fmt
.vbi
.count
[1] != fmt
->count
[1] ||
1176 fmt2
->fmt
.vbi
.flags
!= fmt
->flags
) {
1180 err
= drv(file
, VIDIOC_S_FMT
, fmt2
);
1182 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %ld\n", err
);
1189 * This function is exported.
1192 v4l_compat_translate_ioctl(struct file
*file
,
1200 case VIDIOCGCAP
: /* capability */
1201 err
= v4l1_compat_get_capabilities(arg
, file
, drv
);
1203 case VIDIOCGFBUF
: /* get frame buffer */
1204 err
= v4l1_compat_get_frame_buffer(arg
, file
, drv
);
1206 case VIDIOCSFBUF
: /* set frame buffer */
1207 err
= v4l1_compat_set_frame_buffer(arg
, file
, drv
);
1209 case VIDIOCGWIN
: /* get window or capture dimensions */
1210 err
= v4l1_compat_get_win_cap_dimensions(arg
, file
, drv
);
1212 case VIDIOCSWIN
: /* set window and/or capture dimensions */
1213 err
= v4l1_compat_set_win_cap_dimensions(arg
, file
, drv
);
1215 case VIDIOCCAPTURE
: /* turn on/off preview */
1216 err
= v4l1_compat_turn_preview_on_off(arg
, file
, drv
);
1218 case VIDIOCGCHAN
: /* get input information */
1219 err
= v4l1_compat_get_input_info(arg
, file
, drv
);
1221 case VIDIOCSCHAN
: /* set input */
1222 err
= v4l1_compat_set_input(arg
, file
, drv
);
1224 case VIDIOCGPICT
: /* get tone controls & partial capture format */
1225 err
= v4l1_compat_get_picture(arg
, file
, drv
);
1227 case VIDIOCSPICT
: /* set tone controls & partial capture format */
1228 err
= v4l1_compat_set_picture(arg
, file
, drv
);
1230 case VIDIOCGTUNER
: /* get tuner information */
1231 err
= v4l1_compat_get_tuner(arg
, file
, drv
);
1233 case VIDIOCSTUNER
: /* select a tuner input */
1234 err
= v4l1_compat_select_tuner(arg
, file
, drv
);
1236 case VIDIOCGFREQ
: /* get frequency */
1237 err
= v4l1_compat_get_frequency(arg
, file
, drv
);
1239 case VIDIOCSFREQ
: /* set frequency */
1240 err
= v4l1_compat_set_frequency(arg
, file
, drv
);
1242 case VIDIOCGAUDIO
: /* get audio properties/controls */
1243 err
= v4l1_compat_get_audio(arg
, file
, drv
);
1245 case VIDIOCSAUDIO
: /* set audio controls */
1246 err
= v4l1_compat_set_audio(arg
, file
, drv
);
1248 case VIDIOCMCAPTURE
: /* capture a frame */
1249 err
= v4l1_compat_capture_frame(arg
, file
, drv
);
1251 case VIDIOCSYNC
: /* wait for a frame */
1252 err
= v4l1_compat_sync(arg
, file
, drv
);
1254 case VIDIOCGVBIFMT
: /* query VBI data capture format */
1255 err
= v4l1_compat_get_vbi_format(arg
, file
, drv
);
1258 err
= v4l1_compat_set_vbi_format(arg
, file
, drv
);
1267 EXPORT_SYMBOL(v4l_compat_translate_ioctl
);