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 DIV_ROUND_CLOSEST((ctrl2
.value
-qctrl2
.minimum
) * 65535,
80 qctrl2
.maximum
- qctrl2
.minimum
);
86 set_v4l_control(struct file
*file
,
91 struct v4l2_queryctrl qctrl2
;
92 struct v4l2_control ctrl2
;
96 err
= drv(file
, VIDIOC_QUERYCTRL
, &qctrl2
);
98 dprintk("VIDIOC_QUERYCTRL: %d\n", err
);
100 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
) &&
101 !(qctrl2
.flags
& V4L2_CTRL_FLAG_GRABBED
)) {
106 if (value
&& qctrl2
.type
== V4L2_CTRL_TYPE_BOOLEAN
)
108 ctrl2
.id
= qctrl2
.id
;
110 (value
* (qctrl2
.maximum
- qctrl2
.minimum
)
113 ctrl2
.value
+= qctrl2
.minimum
;
114 err
= drv(file
, VIDIOC_S_CTRL
, &ctrl2
);
116 dprintk("VIDIOC_S_CTRL: %d\n", err
);
121 /* ----------------------------------------------------------------- */
123 static const unsigned int palette2pixelformat
[] = {
124 [VIDEO_PALETTE_GREY
] = V4L2_PIX_FMT_GREY
,
125 [VIDEO_PALETTE_RGB555
] = V4L2_PIX_FMT_RGB555
,
126 [VIDEO_PALETTE_RGB565
] = V4L2_PIX_FMT_RGB565
,
127 [VIDEO_PALETTE_RGB24
] = V4L2_PIX_FMT_BGR24
,
128 [VIDEO_PALETTE_RGB32
] = V4L2_PIX_FMT_BGR32
,
129 /* yuv packed pixel */
130 [VIDEO_PALETTE_YUYV
] = V4L2_PIX_FMT_YUYV
,
131 [VIDEO_PALETTE_YUV422
] = V4L2_PIX_FMT_YUYV
,
132 [VIDEO_PALETTE_UYVY
] = V4L2_PIX_FMT_UYVY
,
134 [VIDEO_PALETTE_YUV410P
] = V4L2_PIX_FMT_YUV410
,
135 [VIDEO_PALETTE_YUV420
] = V4L2_PIX_FMT_YUV420
,
136 [VIDEO_PALETTE_YUV420P
] = V4L2_PIX_FMT_YUV420
,
137 [VIDEO_PALETTE_YUV411P
] = V4L2_PIX_FMT_YUV411P
,
138 [VIDEO_PALETTE_YUV422P
] = V4L2_PIX_FMT_YUV422P
,
141 static unsigned int __pure
142 palette_to_pixelformat(unsigned int palette
)
144 if (palette
< ARRAY_SIZE(palette2pixelformat
))
145 return palette2pixelformat
[palette
];
150 static unsigned int __attribute_const__
151 pixelformat_to_palette(unsigned int pixelformat
)
154 switch (pixelformat
) {
155 case V4L2_PIX_FMT_GREY
:
156 palette
= VIDEO_PALETTE_GREY
;
158 case V4L2_PIX_FMT_RGB555
:
159 palette
= VIDEO_PALETTE_RGB555
;
161 case V4L2_PIX_FMT_RGB565
:
162 palette
= VIDEO_PALETTE_RGB565
;
164 case V4L2_PIX_FMT_BGR24
:
165 palette
= VIDEO_PALETTE_RGB24
;
167 case V4L2_PIX_FMT_BGR32
:
168 palette
= VIDEO_PALETTE_RGB32
;
170 /* yuv packed pixel */
171 case V4L2_PIX_FMT_YUYV
:
172 palette
= VIDEO_PALETTE_YUYV
;
174 case V4L2_PIX_FMT_UYVY
:
175 palette
= VIDEO_PALETTE_UYVY
;
178 case V4L2_PIX_FMT_YUV410
:
179 palette
= VIDEO_PALETTE_YUV420
;
181 case V4L2_PIX_FMT_YUV420
:
182 palette
= VIDEO_PALETTE_YUV420
;
184 case V4L2_PIX_FMT_YUV411P
:
185 palette
= VIDEO_PALETTE_YUV411P
;
187 case V4L2_PIX_FMT_YUV422P
:
188 palette
= VIDEO_PALETTE_YUV422P
;
194 /* ----------------------------------------------------------------- */
196 static int poll_one(struct file
*file
, struct poll_wqueues
*pwq
)
205 mask
= file
->f_op
->poll(file
, table
);
209 if (signal_pending(current
)) {
210 retval
= -ERESTARTSYS
;
213 poll_schedule(pwq
, TASK_INTERRUPTIBLE
);
219 static int count_inputs(
223 struct v4l2_input input2
;
227 memset(&input2
, 0, sizeof(input2
));
229 if (0 != drv(file
, VIDIOC_ENUMINPUT
, &input2
))
235 static int check_size(
241 struct v4l2_fmtdesc desc2
;
242 struct v4l2_format fmt2
;
244 memset(&desc2
, 0, sizeof(desc2
));
245 memset(&fmt2
, 0, sizeof(fmt2
));
247 desc2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
248 if (0 != drv(file
, VIDIOC_ENUM_FMT
, &desc2
))
251 fmt2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
252 fmt2
.fmt
.pix
.width
= 10000;
253 fmt2
.fmt
.pix
.height
= 10000;
254 fmt2
.fmt
.pix
.pixelformat
= desc2
.pixelformat
;
255 if (0 != drv(file
, VIDIOC_TRY_FMT
, &fmt2
))
258 *maxw
= fmt2
.fmt
.pix
.width
;
259 *maxh
= fmt2
.fmt
.pix
.height
;
265 /* ----------------------------------------------------------------- */
267 static noinline
long v4l1_compat_get_capabilities(
268 struct video_capability
*cap
,
273 struct v4l2_framebuffer fbuf
;
274 struct v4l2_capability
*cap2
;
276 cap2
= kzalloc(sizeof(*cap2
), GFP_KERNEL
);
281 memset(cap
, 0, sizeof(*cap
));
282 memset(&fbuf
, 0, sizeof(fbuf
));
284 err
= drv(file
, VIDIOC_QUERYCAP
, cap2
);
286 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %ld\n", err
);
289 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
) {
290 err
= drv(file
, VIDIOC_G_FBUF
, &fbuf
);
292 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %ld\n", err
);
293 memset(&fbuf
, 0, sizeof(fbuf
));
298 memcpy(cap
->name
, cap2
->card
,
299 min(sizeof(cap
->name
), sizeof(cap2
->card
)));
300 cap
->name
[sizeof(cap
->name
) - 1] = 0;
301 if (cap2
->capabilities
& V4L2_CAP_VIDEO_CAPTURE
)
302 cap
->type
|= VID_TYPE_CAPTURE
;
303 if (cap2
->capabilities
& V4L2_CAP_TUNER
)
304 cap
->type
|= VID_TYPE_TUNER
;
305 if (cap2
->capabilities
& V4L2_CAP_VBI_CAPTURE
)
306 cap
->type
|= VID_TYPE_TELETEXT
;
307 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
)
308 cap
->type
|= VID_TYPE_OVERLAY
;
309 if (fbuf
.capability
& V4L2_FBUF_CAP_LIST_CLIPPING
)
310 cap
->type
|= VID_TYPE_CLIPPING
;
312 cap
->channels
= count_inputs(file
, drv
);
313 check_size(file
, drv
,
314 &cap
->maxwidth
, &cap
->maxheight
);
315 cap
->audios
= 0; /* FIXME */
316 cap
->minwidth
= 48; /* FIXME */
317 cap
->minheight
= 32; /* FIXME */
324 static noinline
long v4l1_compat_get_frame_buffer(
325 struct video_buffer
*buffer
,
330 struct v4l2_framebuffer fbuf
;
332 memset(buffer
, 0, sizeof(*buffer
));
333 memset(&fbuf
, 0, sizeof(fbuf
));
335 err
= drv(file
, VIDIOC_G_FBUF
, &fbuf
);
337 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %ld\n", err
);
340 buffer
->base
= fbuf
.base
;
341 buffer
->height
= fbuf
.fmt
.height
;
342 buffer
->width
= fbuf
.fmt
.width
;
344 switch (fbuf
.fmt
.pixelformat
) {
345 case V4L2_PIX_FMT_RGB332
:
348 case V4L2_PIX_FMT_RGB555
:
351 case V4L2_PIX_FMT_RGB565
:
354 case V4L2_PIX_FMT_BGR24
:
357 case V4L2_PIX_FMT_BGR32
:
363 if (fbuf
.fmt
.bytesperline
) {
364 buffer
->bytesperline
= fbuf
.fmt
.bytesperline
;
365 if (!buffer
->depth
&& buffer
->width
)
366 buffer
->depth
= ((fbuf
.fmt
.bytesperline
<<3)
370 buffer
->bytesperline
=
371 (buffer
->width
* buffer
->depth
+ 7) & 7;
372 buffer
->bytesperline
>>= 3;
378 static noinline
long v4l1_compat_set_frame_buffer(
379 struct video_buffer
*buffer
,
384 struct v4l2_framebuffer fbuf
;
386 memset(&fbuf
, 0, sizeof(fbuf
));
387 fbuf
.base
= buffer
->base
;
388 fbuf
.fmt
.height
= buffer
->height
;
389 fbuf
.fmt
.width
= buffer
->width
;
390 switch (buffer
->depth
) {
392 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB332
;
395 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB555
;
398 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB565
;
401 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR24
;
404 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR32
;
407 fbuf
.fmt
.bytesperline
= buffer
->bytesperline
;
408 err
= drv(file
, VIDIOC_S_FBUF
, &fbuf
);
410 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %ld\n", err
);
414 static noinline
long v4l1_compat_get_win_cap_dimensions(
415 struct video_window
*win
,
420 struct v4l2_format
*fmt
;
422 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
427 memset(win
, 0, sizeof(*win
));
429 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
430 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
432 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %ld\n", err
);
434 win
->x
= fmt
->fmt
.win
.w
.left
;
435 win
->y
= fmt
->fmt
.win
.w
.top
;
436 win
->width
= fmt
->fmt
.win
.w
.width
;
437 win
->height
= fmt
->fmt
.win
.w
.height
;
438 win
->chromakey
= fmt
->fmt
.win
.chromakey
;
444 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
445 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
447 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %ld\n", err
);
452 win
->width
= fmt
->fmt
.pix
.width
;
453 win
->height
= fmt
->fmt
.pix
.height
;
462 static noinline
long v4l1_compat_set_win_cap_dimensions(
463 struct video_window
*win
,
467 long err
, err1
, err2
;
468 struct v4l2_format
*fmt
;
470 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
475 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
476 drv(file
, VIDIOC_STREAMOFF
, &fmt
->type
);
477 err1
= drv(file
, VIDIOC_G_FMT
, fmt
);
479 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %ld\n", err1
);
481 fmt
->fmt
.pix
.width
= win
->width
;
482 fmt
->fmt
.pix
.height
= win
->height
;
483 fmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
484 fmt
->fmt
.pix
.bytesperline
= 0;
485 err
= drv(file
, VIDIOC_S_FMT
, fmt
);
487 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %ld\n",
489 win
->width
= fmt
->fmt
.pix
.width
;
490 win
->height
= fmt
->fmt
.pix
.height
;
493 memset(fmt
, 0, sizeof(*fmt
));
494 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
495 fmt
->fmt
.win
.w
.left
= win
->x
;
496 fmt
->fmt
.win
.w
.top
= win
->y
;
497 fmt
->fmt
.win
.w
.width
= win
->width
;
498 fmt
->fmt
.win
.w
.height
= win
->height
;
499 fmt
->fmt
.win
.chromakey
= win
->chromakey
;
500 fmt
->fmt
.win
.clips
= (void __user
*)win
->clips
;
501 fmt
->fmt
.win
.clipcount
= win
->clipcount
;
502 err2
= drv(file
, VIDIOC_S_FMT
, fmt
);
504 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %ld\n", err2
);
506 if (err1
!= 0 && err2
!= 0)
514 static noinline
long v4l1_compat_turn_preview_on_off(
520 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
523 /* dirty hack time. But v4l1 has no STREAMOFF
524 * equivalent in the API, and this one at
525 * least comes close ... */
526 drv(file
, VIDIOC_STREAMOFF
, &captype
);
528 err
= drv(file
, VIDIOC_OVERLAY
, on
);
530 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %ld\n", err
);
534 static noinline
long v4l1_compat_get_input_info(
535 struct video_channel
*chan
,
540 struct v4l2_input input2
;
543 memset(&input2
, 0, sizeof(input2
));
544 input2
.index
= chan
->channel
;
545 err
= drv(file
, VIDIOC_ENUMINPUT
, &input2
);
547 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
548 "channel=%d err=%ld\n", chan
->channel
, err
);
551 chan
->channel
= input2
.index
;
552 memcpy(chan
->name
, input2
.name
,
553 min(sizeof(chan
->name
), sizeof(input2
.name
)));
554 chan
->name
[sizeof(chan
->name
) - 1] = 0;
555 chan
->tuners
= (input2
.type
== V4L2_INPUT_TYPE_TUNER
) ? 1 : 0;
556 chan
->flags
= (chan
->tuners
) ? VIDEO_VC_TUNER
: 0;
557 switch (input2
.type
) {
558 case V4L2_INPUT_TYPE_TUNER
:
559 chan
->type
= VIDEO_TYPE_TV
;
562 case V4L2_INPUT_TYPE_CAMERA
:
563 chan
->type
= VIDEO_TYPE_CAMERA
;
567 /* Note: G_STD might not be present for radio receivers,
568 * so we should ignore any errors. */
569 if (drv(file
, VIDIOC_G_STD
, &sid
) == 0) {
570 if (sid
& V4L2_STD_PAL
)
571 chan
->norm
= VIDEO_MODE_PAL
;
572 if (sid
& V4L2_STD_NTSC
)
573 chan
->norm
= VIDEO_MODE_NTSC
;
574 if (sid
& V4L2_STD_SECAM
)
575 chan
->norm
= VIDEO_MODE_SECAM
;
576 if (sid
== V4L2_STD_ALL
)
577 chan
->norm
= VIDEO_MODE_AUTO
;
583 static noinline
long v4l1_compat_set_input(
584 struct video_channel
*chan
,
591 err
= drv(file
, VIDIOC_S_INPUT
, &chan
->channel
);
593 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %ld\n", err
);
594 switch (chan
->norm
) {
598 case VIDEO_MODE_NTSC
:
601 case VIDEO_MODE_SECAM
:
602 sid
= V4L2_STD_SECAM
;
604 case VIDEO_MODE_AUTO
:
609 err
= drv(file
, VIDIOC_S_STD
, &sid
);
611 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err
);
616 static noinline
long v4l1_compat_get_picture(
617 struct video_picture
*pict
,
622 struct v4l2_format
*fmt
;
624 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
630 pict
->brightness
= get_v4l_control(file
,
631 V4L2_CID_BRIGHTNESS
, drv
);
632 pict
->hue
= get_v4l_control(file
,
634 pict
->contrast
= get_v4l_control(file
,
635 V4L2_CID_CONTRAST
, drv
);
636 pict
->colour
= get_v4l_control(file
,
637 V4L2_CID_SATURATION
, drv
);
638 pict
->whiteness
= get_v4l_control(file
,
639 V4L2_CID_WHITENESS
, drv
);
641 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
642 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
644 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %ld\n", err
);
648 pict
->depth
= ((fmt
->fmt
.pix
.bytesperline
<< 3)
649 + (fmt
->fmt
.pix
.width
- 1))
650 / fmt
->fmt
.pix
.width
;
651 pict
->palette
= pixelformat_to_palette(
652 fmt
->fmt
.pix
.pixelformat
);
658 static noinline
long v4l1_compat_set_picture(
659 struct video_picture
*pict
,
664 struct v4l2_framebuffer fbuf
;
665 int mem_err
= 0, ovl_err
= 0;
666 struct v4l2_format
*fmt
;
668 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
673 memset(&fbuf
, 0, sizeof(fbuf
));
675 set_v4l_control(file
,
676 V4L2_CID_BRIGHTNESS
, pict
->brightness
, drv
);
677 set_v4l_control(file
,
678 V4L2_CID_HUE
, pict
->hue
, drv
);
679 set_v4l_control(file
,
680 V4L2_CID_CONTRAST
, pict
->contrast
, drv
);
681 set_v4l_control(file
,
682 V4L2_CID_SATURATION
, pict
->colour
, drv
);
683 set_v4l_control(file
,
684 V4L2_CID_WHITENESS
, pict
->whiteness
, drv
);
686 * V4L1 uses this ioctl to set both memory capture and overlay
687 * pixel format, while V4L2 has two different ioctls for this.
688 * Some cards may not support one or the other, and may support
689 * different pixel formats for memory vs overlay.
692 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
693 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
694 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
695 support memory capture. Trying to set the memory capture
696 parameters would be pointless. */
698 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err
);
699 mem_err
= -1000; /* didn't even try */
700 } else if (fmt
->fmt
.pix
.pixelformat
!=
701 palette_to_pixelformat(pict
->palette
)) {
702 fmt
->fmt
.pix
.pixelformat
= palette_to_pixelformat(
704 mem_err
= drv(file
, VIDIOC_S_FMT
, fmt
);
706 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
710 err
= drv(file
, VIDIOC_G_FBUF
, &fbuf
);
711 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
712 support overlay. Trying to set the overlay parameters
713 would be quite pointless. */
715 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err
);
716 ovl_err
= -1000; /* didn't even try */
717 } else if (fbuf
.fmt
.pixelformat
!=
718 palette_to_pixelformat(pict
->palette
)) {
719 fbuf
.fmt
.pixelformat
= palette_to_pixelformat(
721 ovl_err
= drv(file
, VIDIOC_S_FBUF
, &fbuf
);
723 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
726 if (ovl_err
< 0 && mem_err
< 0) {
727 /* ioctl failed, couldn't set either parameter */
728 if (mem_err
!= -1000)
730 else if (ovl_err
== -EPERM
)
740 static noinline
long v4l1_compat_get_tuner(
741 struct video_tuner
*tun
,
747 struct v4l2_tuner tun2
;
748 struct v4l2_standard std2
;
751 memset(&tun2
, 0, sizeof(tun2
));
752 err
= drv(file
, VIDIOC_G_TUNER
, &tun2
);
754 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err
);
757 memcpy(tun
->name
, tun2
.name
,
758 min(sizeof(tun
->name
), sizeof(tun2
.name
)));
759 tun
->name
[sizeof(tun
->name
) - 1] = 0;
760 tun
->rangelow
= tun2
.rangelow
;
761 tun
->rangehigh
= tun2
.rangehigh
;
763 tun
->mode
= VIDEO_MODE_AUTO
;
765 for (i
= 0; i
< 64; i
++) {
766 memset(&std2
, 0, sizeof(std2
));
768 if (0 != drv(file
, VIDIOC_ENUMSTD
, &std2
))
770 if (std2
.id
& V4L2_STD_PAL
)
771 tun
->flags
|= VIDEO_TUNER_PAL
;
772 if (std2
.id
& V4L2_STD_NTSC
)
773 tun
->flags
|= VIDEO_TUNER_NTSC
;
774 if (std2
.id
& V4L2_STD_SECAM
)
775 tun
->flags
|= VIDEO_TUNER_SECAM
;
778 /* Note: G_STD might not be present for radio receivers,
779 * so we should ignore any errors. */
780 if (drv(file
, VIDIOC_G_STD
, &sid
) == 0) {
781 if (sid
& V4L2_STD_PAL
)
782 tun
->mode
= VIDEO_MODE_PAL
;
783 if (sid
& V4L2_STD_NTSC
)
784 tun
->mode
= VIDEO_MODE_NTSC
;
785 if (sid
& V4L2_STD_SECAM
)
786 tun
->mode
= VIDEO_MODE_SECAM
;
789 if (tun2
.capability
& V4L2_TUNER_CAP_LOW
)
790 tun
->flags
|= VIDEO_TUNER_LOW
;
791 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
792 tun
->flags
|= VIDEO_TUNER_STEREO_ON
;
793 tun
->signal
= tun2
.signal
;
798 static noinline
long v4l1_compat_select_tuner(
799 struct video_tuner
*tun
,
804 struct v4l2_tuner t
;/*84 bytes on x86_64*/
805 memset(&t
, 0, sizeof(t
));
807 t
.index
= tun
->tuner
;
809 err
= drv(file
, VIDIOC_S_TUNER
, &t
);
811 dprintk("VIDIOCSTUNER / VIDIOC_S_TUNER: %ld\n", err
);
815 static noinline
long v4l1_compat_get_frequency(
821 struct v4l2_frequency freq2
;
822 memset(&freq2
, 0, sizeof(freq2
));
825 err
= drv(file
, VIDIOC_G_FREQUENCY
, &freq2
);
827 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %ld\n", err
);
829 *freq
= freq2
.frequency
;
833 static noinline
long v4l1_compat_set_frequency(
839 struct v4l2_frequency freq2
;
840 memset(&freq2
, 0, sizeof(freq2
));
842 drv(file
, VIDIOC_G_FREQUENCY
, &freq2
);
843 freq2
.frequency
= *freq
;
844 err
= drv(file
, VIDIOC_S_FREQUENCY
, &freq2
);
846 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %ld\n", err
);
850 static noinline
long v4l1_compat_get_audio(
851 struct video_audio
*aud
,
857 struct v4l2_queryctrl qctrl2
;
858 struct v4l2_audio aud2
;
859 struct v4l2_tuner tun2
;
860 memset(&aud2
, 0, sizeof(aud2
));
862 err
= drv(file
, VIDIOC_G_AUDIO
, &aud2
);
864 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %ld\n", err
);
867 memcpy(aud
->name
, aud2
.name
,
868 min(sizeof(aud
->name
), sizeof(aud2
.name
)));
869 aud
->name
[sizeof(aud
->name
) - 1] = 0;
870 aud
->audio
= aud2
.index
;
872 i
= get_v4l_control(file
, V4L2_CID_AUDIO_VOLUME
, drv
);
875 aud
->flags
|= VIDEO_AUDIO_VOLUME
;
877 i
= get_v4l_control(file
, V4L2_CID_AUDIO_BASS
, drv
);
880 aud
->flags
|= VIDEO_AUDIO_BASS
;
882 i
= get_v4l_control(file
, V4L2_CID_AUDIO_TREBLE
, drv
);
885 aud
->flags
|= VIDEO_AUDIO_TREBLE
;
887 i
= get_v4l_control(file
, V4L2_CID_AUDIO_BALANCE
, drv
);
890 aud
->flags
|= VIDEO_AUDIO_BALANCE
;
892 i
= get_v4l_control(file
, V4L2_CID_AUDIO_MUTE
, drv
);
895 aud
->flags
|= VIDEO_AUDIO_MUTE
;
896 aud
->flags
|= VIDEO_AUDIO_MUTABLE
;
899 qctrl2
.id
= V4L2_CID_AUDIO_VOLUME
;
900 if (drv(file
, VIDIOC_QUERYCTRL
, &qctrl2
) == 0 &&
901 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
902 aud
->step
= qctrl2
.step
;
905 memset(&tun2
, 0, sizeof(tun2
));
906 err
= drv(file
, VIDIOC_G_TUNER
, &tun2
);
908 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %ld\n", err
);
913 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_LANG2
)
914 aud
->mode
= VIDEO_SOUND_LANG1
| VIDEO_SOUND_LANG2
;
915 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
916 aud
->mode
= VIDEO_SOUND_STEREO
;
917 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_MONO
)
918 aud
->mode
= VIDEO_SOUND_MONO
;
923 static noinline
long v4l1_compat_set_audio(
924 struct video_audio
*aud
,
929 struct v4l2_audio aud2
;
930 struct v4l2_tuner tun2
;
932 memset(&aud2
, 0, sizeof(aud2
));
933 memset(&tun2
, 0, sizeof(tun2
));
935 aud2
.index
= aud
->audio
;
936 err
= drv(file
, VIDIOC_S_AUDIO
, &aud2
);
938 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %ld\n", err
);
942 set_v4l_control(file
, V4L2_CID_AUDIO_VOLUME
,
944 set_v4l_control(file
, V4L2_CID_AUDIO_BASS
,
946 set_v4l_control(file
, V4L2_CID_AUDIO_TREBLE
,
948 set_v4l_control(file
, V4L2_CID_AUDIO_BALANCE
,
950 set_v4l_control(file
, V4L2_CID_AUDIO_MUTE
,
951 !!(aud
->flags
& VIDEO_AUDIO_MUTE
), drv
);
953 err
= drv(file
, VIDIOC_G_TUNER
, &tun2
);
955 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %ld\n", err
);
959 case VIDEO_SOUND_MONO
:
960 case VIDEO_SOUND_LANG1
:
961 tun2
.audmode
= V4L2_TUNER_MODE_MONO
;
963 case VIDEO_SOUND_STEREO
:
964 tun2
.audmode
= V4L2_TUNER_MODE_STEREO
;
966 case VIDEO_SOUND_LANG2
:
967 tun2
.audmode
= V4L2_TUNER_MODE_LANG2
;
970 err
= drv(file
, VIDIOC_S_TUNER
, &tun2
);
972 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %ld\n", err
);
979 static noinline
long v4l1_compat_capture_frame(
980 struct video_mmap
*mm
,
985 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
986 struct v4l2_buffer buf
;
987 struct v4l2_format
*fmt
;
989 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
994 memset(&buf
, 0, sizeof(buf
));
996 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
997 err
= drv(file
, VIDIOC_G_FMT
, fmt
);
999 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %ld\n", err
);
1002 if (mm
->width
!= fmt
->fmt
.pix
.width
||
1003 mm
->height
!= fmt
->fmt
.pix
.height
||
1004 palette_to_pixelformat(mm
->format
) !=
1005 fmt
->fmt
.pix
.pixelformat
) {
1006 /* New capture format... */
1007 fmt
->fmt
.pix
.width
= mm
->width
;
1008 fmt
->fmt
.pix
.height
= mm
->height
;
1009 fmt
->fmt
.pix
.pixelformat
=
1010 palette_to_pixelformat(mm
->format
);
1011 fmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
1012 fmt
->fmt
.pix
.bytesperline
= 0;
1013 err
= drv(file
, VIDIOC_S_FMT
, fmt
);
1015 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %ld\n", err
);
1019 buf
.index
= mm
->frame
;
1020 buf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1021 err
= drv(file
, VIDIOC_QUERYBUF
, &buf
);
1023 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %ld\n", err
);
1026 err
= drv(file
, VIDIOC_QBUF
, &buf
);
1028 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %ld\n", err
);
1031 err
= drv(file
, VIDIOC_STREAMON
, &captype
);
1033 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %ld\n", err
);
1039 static noinline
long v4l1_compat_sync(
1045 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1046 struct v4l2_buffer buf
;
1047 struct poll_wqueues
*pwq
;
1049 memset(&buf
, 0, sizeof(buf
));
1051 buf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1052 err
= drv(file
, VIDIOC_QUERYBUF
, &buf
);
1054 /* No such buffer */
1055 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err
);
1058 if (!(buf
.flags
& V4L2_BUF_FLAG_MAPPED
)) {
1059 /* Buffer is not mapped */
1064 /* make sure capture actually runs so we don't block forever */
1065 err
= drv(file
, VIDIOC_STREAMON
, &captype
);
1067 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %ld\n", err
);
1071 pwq
= kmalloc(sizeof(*pwq
), GFP_KERNEL
);
1072 /* Loop as long as the buffer is queued, but not done */
1073 while ((buf
.flags
& (V4L2_BUF_FLAG_QUEUED
| V4L2_BUF_FLAG_DONE
))
1074 == V4L2_BUF_FLAG_QUEUED
) {
1075 err
= poll_one(file
, pwq
);
1076 if (err
< 0 || /* error or sleep was interrupted */
1077 err
== 0) /* timeout? Shouldn't occur. */
1079 err
= drv(file
, VIDIOC_QUERYBUF
, &buf
);
1081 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err
);
1084 if (!(buf
.flags
& V4L2_BUF_FLAG_DONE
)) /* not done */
1087 err
= drv(file
, VIDIOC_DQBUF
, &buf
);
1089 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %ld\n", err
);
1090 } while (err
== 0 && buf
.index
!= *i
);
1095 static noinline
long v4l1_compat_get_vbi_format(
1096 struct vbi_format
*fmt
,
1101 struct v4l2_format
*fmt2
;
1103 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1108 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1110 err
= drv(file
, VIDIOC_G_FMT
, fmt2
);
1112 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %ld\n", err
);
1115 if (fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
) {
1119 memset(fmt
, 0, sizeof(*fmt
));
1120 fmt
->samples_per_line
= fmt2
->fmt
.vbi
.samples_per_line
;
1121 fmt
->sampling_rate
= fmt2
->fmt
.vbi
.sampling_rate
;
1122 fmt
->sample_format
= VIDEO_PALETTE_RAW
;
1123 fmt
->start
[0] = fmt2
->fmt
.vbi
.start
[0];
1124 fmt
->count
[0] = fmt2
->fmt
.vbi
.count
[0];
1125 fmt
->start
[1] = fmt2
->fmt
.vbi
.start
[1];
1126 fmt
->count
[1] = fmt2
->fmt
.vbi
.count
[1];
1127 fmt
->flags
= fmt2
->fmt
.vbi
.flags
& 0x03;
1133 static noinline
long v4l1_compat_set_vbi_format(
1134 struct vbi_format
*fmt
,
1139 struct v4l2_format
*fmt2
= NULL
;
1141 if (VIDEO_PALETTE_RAW
!= fmt
->sample_format
) {
1146 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1151 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1152 fmt2
->fmt
.vbi
.samples_per_line
= fmt
->samples_per_line
;
1153 fmt2
->fmt
.vbi
.sampling_rate
= fmt
->sampling_rate
;
1154 fmt2
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1155 fmt2
->fmt
.vbi
.start
[0] = fmt
->start
[0];
1156 fmt2
->fmt
.vbi
.count
[0] = fmt
->count
[0];
1157 fmt2
->fmt
.vbi
.start
[1] = fmt
->start
[1];
1158 fmt2
->fmt
.vbi
.count
[1] = fmt
->count
[1];
1159 fmt2
->fmt
.vbi
.flags
= fmt
->flags
;
1160 err
= drv(file
, VIDIOC_TRY_FMT
, fmt2
);
1162 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %ld\n", err
);
1166 if (fmt2
->fmt
.vbi
.samples_per_line
!= fmt
->samples_per_line
||
1167 fmt2
->fmt
.vbi
.sampling_rate
!= fmt
->sampling_rate
||
1168 fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
||
1169 fmt2
->fmt
.vbi
.start
[0] != fmt
->start
[0] ||
1170 fmt2
->fmt
.vbi
.count
[0] != fmt
->count
[0] ||
1171 fmt2
->fmt
.vbi
.start
[1] != fmt
->start
[1] ||
1172 fmt2
->fmt
.vbi
.count
[1] != fmt
->count
[1] ||
1173 fmt2
->fmt
.vbi
.flags
!= fmt
->flags
) {
1177 err
= drv(file
, VIDIOC_S_FMT
, fmt2
);
1179 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %ld\n", err
);
1186 * This function is exported.
1189 v4l_compat_translate_ioctl(struct file
*file
,
1197 case VIDIOCGCAP
: /* capability */
1198 err
= v4l1_compat_get_capabilities(arg
, file
, drv
);
1200 case VIDIOCGFBUF
: /* get frame buffer */
1201 err
= v4l1_compat_get_frame_buffer(arg
, file
, drv
);
1203 case VIDIOCSFBUF
: /* set frame buffer */
1204 err
= v4l1_compat_set_frame_buffer(arg
, file
, drv
);
1206 case VIDIOCGWIN
: /* get window or capture dimensions */
1207 err
= v4l1_compat_get_win_cap_dimensions(arg
, file
, drv
);
1209 case VIDIOCSWIN
: /* set window and/or capture dimensions */
1210 err
= v4l1_compat_set_win_cap_dimensions(arg
, file
, drv
);
1212 case VIDIOCCAPTURE
: /* turn on/off preview */
1213 err
= v4l1_compat_turn_preview_on_off(arg
, file
, drv
);
1215 case VIDIOCGCHAN
: /* get input information */
1216 err
= v4l1_compat_get_input_info(arg
, file
, drv
);
1218 case VIDIOCSCHAN
: /* set input */
1219 err
= v4l1_compat_set_input(arg
, file
, drv
);
1221 case VIDIOCGPICT
: /* get tone controls & partial capture format */
1222 err
= v4l1_compat_get_picture(arg
, file
, drv
);
1224 case VIDIOCSPICT
: /* set tone controls & partial capture format */
1225 err
= v4l1_compat_set_picture(arg
, file
, drv
);
1227 case VIDIOCGTUNER
: /* get tuner information */
1228 err
= v4l1_compat_get_tuner(arg
, file
, drv
);
1230 case VIDIOCSTUNER
: /* select a tuner input */
1231 err
= v4l1_compat_select_tuner(arg
, file
, drv
);
1233 case VIDIOCGFREQ
: /* get frequency */
1234 err
= v4l1_compat_get_frequency(arg
, file
, drv
);
1236 case VIDIOCSFREQ
: /* set frequency */
1237 err
= v4l1_compat_set_frequency(arg
, file
, drv
);
1239 case VIDIOCGAUDIO
: /* get audio properties/controls */
1240 err
= v4l1_compat_get_audio(arg
, file
, drv
);
1242 case VIDIOCSAUDIO
: /* set audio controls */
1243 err
= v4l1_compat_set_audio(arg
, file
, drv
);
1245 case VIDIOCMCAPTURE
: /* capture a frame */
1246 err
= v4l1_compat_capture_frame(arg
, file
, drv
);
1248 case VIDIOCSYNC
: /* wait for a frame */
1249 err
= v4l1_compat_sync(arg
, file
, drv
);
1251 case VIDIOCGVBIFMT
: /* query VBI data capture format */
1252 err
= v4l1_compat_get_vbi_format(arg
, file
, drv
);
1255 err
= v4l1_compat_set_vbi_format(arg
, file
, drv
);
1264 EXPORT_SYMBOL(v4l_compat_translate_ioctl
);