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>
40 #include <linux/kmod.h>
43 static unsigned int debug
;
44 module_param(debug
, int, 0644);
45 MODULE_PARM_DESC(debug
, "enable debug messages");
46 MODULE_AUTHOR("Bill Dirks");
47 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
48 MODULE_LICENSE("GPL");
50 #define dprintk(fmt, arg...) \
53 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\
57 * I O C T L T R A N S L A T I O N
59 * From here on down is the code for translating the numerous
60 * ioctl commands from the old API to the new API.
64 get_v4l_control(struct inode
*inode
,
69 struct v4l2_queryctrl qctrl2
;
70 struct v4l2_control ctrl2
;
74 err
= drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
);
76 dprintk("VIDIOC_QUERYCTRL: %d\n", err
);
77 if (err
== 0 && !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
)) {
79 err
= drv(inode
, file
, VIDIOC_G_CTRL
, &ctrl2
);
81 dprintk("VIDIOC_G_CTRL: %d\n", err
);
84 return ((ctrl2
.value
- qctrl2
.minimum
) * 65535
85 + (qctrl2
.maximum
- qctrl2
.minimum
) / 2)
86 / (qctrl2
.maximum
- qctrl2
.minimum
);
92 set_v4l_control(struct inode
*inode
,
98 struct v4l2_queryctrl qctrl2
;
99 struct v4l2_control ctrl2
;
103 err
= drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
);
105 dprintk("VIDIOC_QUERYCTRL: %d\n", err
);
107 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
) &&
108 !(qctrl2
.flags
& V4L2_CTRL_FLAG_GRABBED
)) {
113 if (value
&& qctrl2
.type
== V4L2_CTRL_TYPE_BOOLEAN
)
115 ctrl2
.id
= qctrl2
.id
;
117 (value
* (qctrl2
.maximum
- qctrl2
.minimum
)
120 ctrl2
.value
+= qctrl2
.minimum
;
121 err
= drv(inode
, file
, VIDIOC_S_CTRL
, &ctrl2
);
123 dprintk("VIDIOC_S_CTRL: %d\n", err
);
128 /* ----------------------------------------------------------------- */
130 static const unsigned int palette2pixelformat
[] = {
131 [VIDEO_PALETTE_GREY
] = V4L2_PIX_FMT_GREY
,
132 [VIDEO_PALETTE_RGB555
] = V4L2_PIX_FMT_RGB555
,
133 [VIDEO_PALETTE_RGB565
] = V4L2_PIX_FMT_RGB565
,
134 [VIDEO_PALETTE_RGB24
] = V4L2_PIX_FMT_BGR24
,
135 [VIDEO_PALETTE_RGB32
] = V4L2_PIX_FMT_BGR32
,
136 /* yuv packed pixel */
137 [VIDEO_PALETTE_YUYV
] = V4L2_PIX_FMT_YUYV
,
138 [VIDEO_PALETTE_YUV422
] = V4L2_PIX_FMT_YUYV
,
139 [VIDEO_PALETTE_UYVY
] = V4L2_PIX_FMT_UYVY
,
141 [VIDEO_PALETTE_YUV410P
] = V4L2_PIX_FMT_YUV410
,
142 [VIDEO_PALETTE_YUV420
] = V4L2_PIX_FMT_YUV420
,
143 [VIDEO_PALETTE_YUV420P
] = V4L2_PIX_FMT_YUV420
,
144 [VIDEO_PALETTE_YUV411P
] = V4L2_PIX_FMT_YUV411P
,
145 [VIDEO_PALETTE_YUV422P
] = V4L2_PIX_FMT_YUV422P
,
148 static unsigned int __pure
149 palette_to_pixelformat(unsigned int palette
)
151 if (palette
< ARRAY_SIZE(palette2pixelformat
))
152 return palette2pixelformat
[palette
];
157 static unsigned int __attribute_const__
158 pixelformat_to_palette(unsigned int pixelformat
)
161 switch (pixelformat
) {
162 case V4L2_PIX_FMT_GREY
:
163 palette
= VIDEO_PALETTE_GREY
;
165 case V4L2_PIX_FMT_RGB555
:
166 palette
= VIDEO_PALETTE_RGB555
;
168 case V4L2_PIX_FMT_RGB565
:
169 palette
= VIDEO_PALETTE_RGB565
;
171 case V4L2_PIX_FMT_BGR24
:
172 palette
= VIDEO_PALETTE_RGB24
;
174 case V4L2_PIX_FMT_BGR32
:
175 palette
= VIDEO_PALETTE_RGB32
;
177 /* yuv packed pixel */
178 case V4L2_PIX_FMT_YUYV
:
179 palette
= VIDEO_PALETTE_YUYV
;
181 case V4L2_PIX_FMT_UYVY
:
182 palette
= VIDEO_PALETTE_UYVY
;
185 case V4L2_PIX_FMT_YUV410
:
186 palette
= VIDEO_PALETTE_YUV420
;
188 case V4L2_PIX_FMT_YUV420
:
189 palette
= VIDEO_PALETTE_YUV420
;
191 case V4L2_PIX_FMT_YUV411P
:
192 palette
= VIDEO_PALETTE_YUV411P
;
194 case V4L2_PIX_FMT_YUV422P
:
195 palette
= VIDEO_PALETTE_YUV422P
;
201 /* ----------------------------------------------------------------- */
203 static int poll_one(struct file
*file
, struct poll_wqueues
*pwq
)
212 set_current_state(TASK_INTERRUPTIBLE
);
213 mask
= file
->f_op
->poll(file
, table
);
217 if (signal_pending(current
)) {
218 retval
= -ERESTARTSYS
;
223 set_current_state(TASK_RUNNING
);
228 static int count_inputs(
233 struct v4l2_input input2
;
237 memset(&input2
, 0, sizeof(input2
));
239 if (0 != drv(inode
, file
, VIDIOC_ENUMINPUT
, &input2
))
245 static int check_size(
252 struct v4l2_fmtdesc desc2
;
253 struct v4l2_format fmt2
;
255 memset(&desc2
, 0, sizeof(desc2
));
256 memset(&fmt2
, 0, sizeof(fmt2
));
258 desc2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
259 if (0 != drv(inode
, file
, VIDIOC_ENUM_FMT
, &desc2
))
262 fmt2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
263 fmt2
.fmt
.pix
.width
= 10000;
264 fmt2
.fmt
.pix
.height
= 10000;
265 fmt2
.fmt
.pix
.pixelformat
= desc2
.pixelformat
;
266 if (0 != drv(inode
, file
, VIDIOC_TRY_FMT
, &fmt2
))
269 *maxw
= fmt2
.fmt
.pix
.width
;
270 *maxh
= fmt2
.fmt
.pix
.height
;
276 /* ----------------------------------------------------------------- */
278 static noinline
int v4l1_compat_get_capabilities(
279 struct video_capability
*cap
,
285 struct v4l2_framebuffer fbuf
;
286 struct v4l2_capability
*cap2
;
288 cap2
= kzalloc(sizeof(*cap2
), GFP_KERNEL
);
293 memset(cap
, 0, sizeof(*cap
));
294 memset(&fbuf
, 0, sizeof(fbuf
));
296 err
= drv(inode
, file
, VIDIOC_QUERYCAP
, cap2
);
298 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err
);
301 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
) {
302 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf
);
304 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err
);
305 memset(&fbuf
, 0, sizeof(fbuf
));
310 memcpy(cap
->name
, cap2
->card
,
311 min(sizeof(cap
->name
), sizeof(cap2
->card
)));
312 cap
->name
[sizeof(cap
->name
) - 1] = 0;
313 if (cap2
->capabilities
& V4L2_CAP_VIDEO_CAPTURE
)
314 cap
->type
|= VID_TYPE_CAPTURE
;
315 if (cap2
->capabilities
& V4L2_CAP_TUNER
)
316 cap
->type
|= VID_TYPE_TUNER
;
317 if (cap2
->capabilities
& V4L2_CAP_VBI_CAPTURE
)
318 cap
->type
|= VID_TYPE_TELETEXT
;
319 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
)
320 cap
->type
|= VID_TYPE_OVERLAY
;
321 if (fbuf
.capability
& V4L2_FBUF_CAP_LIST_CLIPPING
)
322 cap
->type
|= VID_TYPE_CLIPPING
;
324 cap
->channels
= count_inputs(inode
, file
, drv
);
325 check_size(inode
, file
, drv
,
326 &cap
->maxwidth
, &cap
->maxheight
);
327 cap
->audios
= 0; /* FIXME */
328 cap
->minwidth
= 48; /* FIXME */
329 cap
->minheight
= 32; /* FIXME */
336 static noinline
int v4l1_compat_get_frame_buffer(
337 struct video_buffer
*buffer
,
343 struct v4l2_framebuffer fbuf
;
345 memset(buffer
, 0, sizeof(*buffer
));
346 memset(&fbuf
, 0, sizeof(fbuf
));
348 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf
);
350 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err
);
353 buffer
->base
= fbuf
.base
;
354 buffer
->height
= fbuf
.fmt
.height
;
355 buffer
->width
= fbuf
.fmt
.width
;
357 switch (fbuf
.fmt
.pixelformat
) {
358 case V4L2_PIX_FMT_RGB332
:
361 case V4L2_PIX_FMT_RGB555
:
364 case V4L2_PIX_FMT_RGB565
:
367 case V4L2_PIX_FMT_BGR24
:
370 case V4L2_PIX_FMT_BGR32
:
376 if (fbuf
.fmt
.bytesperline
) {
377 buffer
->bytesperline
= fbuf
.fmt
.bytesperline
;
378 if (!buffer
->depth
&& buffer
->width
)
379 buffer
->depth
= ((fbuf
.fmt
.bytesperline
<<3)
383 buffer
->bytesperline
=
384 (buffer
->width
* buffer
->depth
+ 7) & 7;
385 buffer
->bytesperline
>>= 3;
391 static noinline
int v4l1_compat_set_frame_buffer(
392 struct video_buffer
*buffer
,
398 struct v4l2_framebuffer fbuf
;
400 memset(&fbuf
, 0, sizeof(fbuf
));
401 fbuf
.base
= buffer
->base
;
402 fbuf
.fmt
.height
= buffer
->height
;
403 fbuf
.fmt
.width
= buffer
->width
;
404 switch (buffer
->depth
) {
406 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB332
;
409 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB555
;
412 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB565
;
415 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR24
;
418 fbuf
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR32
;
421 fbuf
.fmt
.bytesperline
= buffer
->bytesperline
;
422 err
= drv(inode
, file
, VIDIOC_S_FBUF
, &fbuf
);
424 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err
);
428 static noinline
int v4l1_compat_get_win_cap_dimensions(
429 struct video_window
*win
,
435 struct v4l2_format
*fmt
;
437 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
442 memset(win
, 0, sizeof(*win
));
444 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
445 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt
);
447 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err
);
449 win
->x
= fmt
->fmt
.win
.w
.left
;
450 win
->y
= fmt
->fmt
.win
.w
.top
;
451 win
->width
= fmt
->fmt
.win
.w
.width
;
452 win
->height
= fmt
->fmt
.win
.w
.height
;
453 win
->chromakey
= fmt
->fmt
.win
.chromakey
;
459 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
460 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt
);
462 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err
);
467 win
->width
= fmt
->fmt
.pix
.width
;
468 win
->height
= fmt
->fmt
.pix
.height
;
477 static noinline
int v4l1_compat_set_win_cap_dimensions(
478 struct video_window
*win
,
484 struct v4l2_format
*fmt
;
486 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
491 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
492 drv(inode
, file
, VIDIOC_STREAMOFF
, &fmt
->type
);
493 err1
= drv(inode
, file
, VIDIOC_G_FMT
, fmt
);
495 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1
);
497 fmt
->fmt
.pix
.width
= win
->width
;
498 fmt
->fmt
.pix
.height
= win
->height
;
499 fmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
500 fmt
->fmt
.pix
.bytesperline
= 0;
501 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt
);
503 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
505 win
->width
= fmt
->fmt
.pix
.width
;
506 win
->height
= fmt
->fmt
.pix
.height
;
509 memset(fmt
, 0, sizeof(*fmt
));
510 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
511 fmt
->fmt
.win
.w
.left
= win
->x
;
512 fmt
->fmt
.win
.w
.top
= win
->y
;
513 fmt
->fmt
.win
.w
.width
= win
->width
;
514 fmt
->fmt
.win
.w
.height
= win
->height
;
515 fmt
->fmt
.win
.chromakey
= win
->chromakey
;
516 fmt
->fmt
.win
.clips
= (void __user
*)win
->clips
;
517 fmt
->fmt
.win
.clipcount
= win
->clipcount
;
518 err2
= drv(inode
, file
, VIDIOC_S_FMT
, fmt
);
520 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2
);
522 if (err1
!= 0 && err2
!= 0)
530 static noinline
int v4l1_compat_turn_preview_on_off(
537 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
540 /* dirty hack time. But v4l1 has no STREAMOFF
541 * equivalent in the API, and this one at
542 * least comes close ... */
543 drv(inode
, file
, VIDIOC_STREAMOFF
, &captype
);
545 err
= drv(inode
, file
, VIDIOC_OVERLAY
, on
);
547 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err
);
551 static noinline
int v4l1_compat_get_input_info(
552 struct video_channel
*chan
,
558 struct v4l2_input input2
;
561 memset(&input2
, 0, sizeof(input2
));
562 input2
.index
= chan
->channel
;
563 err
= drv(inode
, file
, VIDIOC_ENUMINPUT
, &input2
);
565 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
566 "channel=%d err=%d\n", chan
->channel
, err
);
569 chan
->channel
= input2
.index
;
570 memcpy(chan
->name
, input2
.name
,
571 min(sizeof(chan
->name
), sizeof(input2
.name
)));
572 chan
->name
[sizeof(chan
->name
) - 1] = 0;
573 chan
->tuners
= (input2
.type
== V4L2_INPUT_TYPE_TUNER
) ? 1 : 0;
574 chan
->flags
= (chan
->tuners
) ? VIDEO_VC_TUNER
: 0;
575 switch (input2
.type
) {
576 case V4L2_INPUT_TYPE_TUNER
:
577 chan
->type
= VIDEO_TYPE_TV
;
580 case V4L2_INPUT_TYPE_CAMERA
:
581 chan
->type
= VIDEO_TYPE_CAMERA
;
585 err
= drv(inode
, file
, VIDIOC_G_STD
, &sid
);
587 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err
);
589 if (sid
& V4L2_STD_PAL
)
590 chan
->norm
= VIDEO_MODE_PAL
;
591 if (sid
& V4L2_STD_NTSC
)
592 chan
->norm
= VIDEO_MODE_NTSC
;
593 if (sid
& V4L2_STD_SECAM
)
594 chan
->norm
= VIDEO_MODE_SECAM
;
600 static noinline
int v4l1_compat_set_input(
601 struct video_channel
*chan
,
609 err
= drv(inode
, file
, VIDIOC_S_INPUT
, &chan
->channel
);
611 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err
);
612 switch (chan
->norm
) {
616 case VIDEO_MODE_NTSC
:
619 case VIDEO_MODE_SECAM
:
620 sid
= V4L2_STD_SECAM
;
624 err
= drv(inode
, file
, VIDIOC_S_STD
, &sid
);
626 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err
);
631 static noinline
int v4l1_compat_get_picture(
632 struct video_picture
*pict
,
638 struct v4l2_format
*fmt
;
640 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
646 pict
->brightness
= get_v4l_control(inode
, file
,
647 V4L2_CID_BRIGHTNESS
, drv
);
648 pict
->hue
= get_v4l_control(inode
, file
,
650 pict
->contrast
= get_v4l_control(inode
, file
,
651 V4L2_CID_CONTRAST
, drv
);
652 pict
->colour
= get_v4l_control(inode
, file
,
653 V4L2_CID_SATURATION
, drv
);
654 pict
->whiteness
= get_v4l_control(inode
, file
,
655 V4L2_CID_WHITENESS
, drv
);
657 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
658 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt
);
660 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err
);
664 pict
->depth
= ((fmt
->fmt
.pix
.bytesperline
<< 3)
665 + (fmt
->fmt
.pix
.width
- 1))
666 / fmt
->fmt
.pix
.width
;
667 pict
->palette
= pixelformat_to_palette(
668 fmt
->fmt
.pix
.pixelformat
);
674 static noinline
int v4l1_compat_set_picture(
675 struct video_picture
*pict
,
681 struct v4l2_framebuffer fbuf
;
682 int mem_err
= 0, ovl_err
= 0;
683 struct v4l2_format
*fmt
;
685 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
690 memset(&fbuf
, 0, sizeof(fbuf
));
692 set_v4l_control(inode
, file
,
693 V4L2_CID_BRIGHTNESS
, pict
->brightness
, drv
);
694 set_v4l_control(inode
, file
,
695 V4L2_CID_HUE
, pict
->hue
, drv
);
696 set_v4l_control(inode
, file
,
697 V4L2_CID_CONTRAST
, pict
->contrast
, drv
);
698 set_v4l_control(inode
, file
,
699 V4L2_CID_SATURATION
, pict
->colour
, drv
);
700 set_v4l_control(inode
, file
,
701 V4L2_CID_WHITENESS
, pict
->whiteness
, drv
);
703 * V4L1 uses this ioctl to set both memory capture and overlay
704 * pixel format, while V4L2 has two different ioctls for this.
705 * Some cards may not support one or the other, and may support
706 * different pixel formats for memory vs overlay.
709 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
710 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt
);
711 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
712 support memory capture. Trying to set the memory capture
713 parameters would be pointless. */
715 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err
);
716 mem_err
= -1000; /* didn't even try */
717 } else if (fmt
->fmt
.pix
.pixelformat
!=
718 palette_to_pixelformat(pict
->palette
)) {
719 fmt
->fmt
.pix
.pixelformat
= palette_to_pixelformat(
721 mem_err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt
);
723 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
727 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf
);
728 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
729 support overlay. Trying to set the overlay parameters
730 would be quite pointless. */
732 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err
);
733 ovl_err
= -1000; /* didn't even try */
734 } else if (fbuf
.fmt
.pixelformat
!=
735 palette_to_pixelformat(pict
->palette
)) {
736 fbuf
.fmt
.pixelformat
= palette_to_pixelformat(
738 ovl_err
= drv(inode
, file
, VIDIOC_S_FBUF
, &fbuf
);
740 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
743 if (ovl_err
< 0 && mem_err
< 0) {
744 /* ioctl failed, couldn't set either parameter */
745 if (mem_err
!= -1000)
747 else if (ovl_err
== -EPERM
)
757 static noinline
int v4l1_compat_get_tuner(
758 struct video_tuner
*tun
,
764 struct v4l2_tuner tun2
;
765 struct v4l2_standard std2
;
768 memset(&tun2
, 0, sizeof(tun2
));
769 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
771 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err
);
774 memcpy(tun
->name
, tun2
.name
,
775 min(sizeof(tun
->name
), sizeof(tun2
.name
)));
776 tun
->name
[sizeof(tun
->name
) - 1] = 0;
777 tun
->rangelow
= tun2
.rangelow
;
778 tun
->rangehigh
= tun2
.rangehigh
;
780 tun
->mode
= VIDEO_MODE_AUTO
;
782 for (i
= 0; i
< 64; i
++) {
783 memset(&std2
, 0, sizeof(std2
));
785 if (0 != drv(inode
, file
, VIDIOC_ENUMSTD
, &std2
))
787 if (std2
.id
& V4L2_STD_PAL
)
788 tun
->flags
|= VIDEO_TUNER_PAL
;
789 if (std2
.id
& V4L2_STD_NTSC
)
790 tun
->flags
|= VIDEO_TUNER_NTSC
;
791 if (std2
.id
& V4L2_STD_SECAM
)
792 tun
->flags
|= VIDEO_TUNER_SECAM
;
795 err
= drv(inode
, file
, VIDIOC_G_STD
, &sid
);
797 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err
);
799 if (sid
& V4L2_STD_PAL
)
800 tun
->mode
= VIDEO_MODE_PAL
;
801 if (sid
& V4L2_STD_NTSC
)
802 tun
->mode
= VIDEO_MODE_NTSC
;
803 if (sid
& V4L2_STD_SECAM
)
804 tun
->mode
= VIDEO_MODE_SECAM
;
807 if (tun2
.capability
& V4L2_TUNER_CAP_LOW
)
808 tun
->flags
|= VIDEO_TUNER_LOW
;
809 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
810 tun
->flags
|= VIDEO_TUNER_STEREO_ON
;
811 tun
->signal
= tun2
.signal
;
816 static noinline
int v4l1_compat_select_tuner(
817 struct video_tuner
*tun
,
823 struct v4l2_tuner t
;/*84 bytes on x86_64*/
824 memset(&t
, 0, sizeof(t
));
826 t
.index
= tun
->tuner
;
828 err
= drv(inode
, file
, VIDIOC_S_INPUT
, &t
);
830 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err
);
834 static noinline
int v4l1_compat_get_frequency(
841 struct v4l2_frequency freq2
;
842 memset(&freq2
, 0, sizeof(freq2
));
845 err
= drv(inode
, file
, VIDIOC_G_FREQUENCY
, &freq2
);
847 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err
);
849 *freq
= freq2
.frequency
;
853 static noinline
int v4l1_compat_set_frequency(
860 struct v4l2_frequency freq2
;
861 memset(&freq2
, 0, sizeof(freq2
));
863 drv(inode
, file
, VIDIOC_G_FREQUENCY
, &freq2
);
864 freq2
.frequency
= *freq
;
865 err
= drv(inode
, file
, VIDIOC_S_FREQUENCY
, &freq2
);
867 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err
);
871 static noinline
int v4l1_compat_get_audio(
872 struct video_audio
*aud
,
878 struct v4l2_queryctrl qctrl2
;
879 struct v4l2_audio aud2
;
880 struct v4l2_tuner tun2
;
881 memset(&aud2
, 0, sizeof(aud2
));
883 err
= drv(inode
, file
, VIDIOC_G_AUDIO
, &aud2
);
885 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err
);
888 memcpy(aud
->name
, aud2
.name
,
889 min(sizeof(aud
->name
), sizeof(aud2
.name
)));
890 aud
->name
[sizeof(aud
->name
) - 1] = 0;
891 aud
->audio
= aud2
.index
;
893 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_VOLUME
, drv
);
896 aud
->flags
|= VIDEO_AUDIO_VOLUME
;
898 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_BASS
, drv
);
901 aud
->flags
|= VIDEO_AUDIO_BASS
;
903 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_TREBLE
, drv
);
906 aud
->flags
|= VIDEO_AUDIO_TREBLE
;
908 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_BALANCE
, drv
);
911 aud
->flags
|= VIDEO_AUDIO_BALANCE
;
913 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_MUTE
, drv
);
916 aud
->flags
|= VIDEO_AUDIO_MUTE
;
917 aud
->flags
|= VIDEO_AUDIO_MUTABLE
;
920 qctrl2
.id
= V4L2_CID_AUDIO_VOLUME
;
921 if (drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
) == 0 &&
922 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
923 aud
->step
= qctrl2
.step
;
926 memset(&tun2
, 0, sizeof(tun2
));
927 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
929 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err
);
934 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_LANG2
)
935 aud
->mode
= VIDEO_SOUND_LANG1
| VIDEO_SOUND_LANG2
;
936 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
937 aud
->mode
= VIDEO_SOUND_STEREO
;
938 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_MONO
)
939 aud
->mode
= VIDEO_SOUND_MONO
;
944 static noinline
int v4l1_compat_set_audio(
945 struct video_audio
*aud
,
951 struct v4l2_audio aud2
;
952 struct v4l2_tuner tun2
;
954 memset(&aud2
, 0, sizeof(aud2
));
955 memset(&tun2
, 0, sizeof(tun2
));
957 aud2
.index
= aud
->audio
;
958 err
= drv(inode
, file
, VIDIOC_S_AUDIO
, &aud2
);
960 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err
);
964 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_VOLUME
,
966 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_BASS
,
968 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_TREBLE
,
970 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_BALANCE
,
972 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_MUTE
,
973 !!(aud
->flags
& VIDEO_AUDIO_MUTE
), drv
);
975 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
977 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err
);
981 case VIDEO_SOUND_MONO
:
982 case VIDEO_SOUND_LANG1
:
983 tun2
.audmode
= V4L2_TUNER_MODE_MONO
;
985 case VIDEO_SOUND_STEREO
:
986 tun2
.audmode
= V4L2_TUNER_MODE_STEREO
;
988 case VIDEO_SOUND_LANG2
:
989 tun2
.audmode
= V4L2_TUNER_MODE_LANG2
;
992 err
= drv(inode
, file
, VIDIOC_S_TUNER
, &tun2
);
994 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err
);
1001 static noinline
int v4l1_compat_capture_frame(
1002 struct video_mmap
*mm
,
1003 struct inode
*inode
,
1008 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1009 struct v4l2_buffer buf
;
1010 struct v4l2_format
*fmt
;
1012 fmt
= kzalloc(sizeof(*fmt
), GFP_KERNEL
);
1017 memset(&buf
, 0, sizeof(buf
));
1019 fmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1020 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt
);
1022 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err
);
1025 if (mm
->width
!= fmt
->fmt
.pix
.width
||
1026 mm
->height
!= fmt
->fmt
.pix
.height
||
1027 palette_to_pixelformat(mm
->format
) !=
1028 fmt
->fmt
.pix
.pixelformat
) {
1029 /* New capture format... */
1030 fmt
->fmt
.pix
.width
= mm
->width
;
1031 fmt
->fmt
.pix
.height
= mm
->height
;
1032 fmt
->fmt
.pix
.pixelformat
=
1033 palette_to_pixelformat(mm
->format
);
1034 fmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
1035 fmt
->fmt
.pix
.bytesperline
= 0;
1036 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt
);
1038 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err
);
1042 buf
.index
= mm
->frame
;
1043 buf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1044 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf
);
1046 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err
);
1049 err
= drv(inode
, file
, VIDIOC_QBUF
, &buf
);
1051 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err
);
1054 err
= drv(inode
, file
, VIDIOC_STREAMON
, &captype
);
1056 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err
);
1062 static noinline
int v4l1_compat_sync(
1064 struct inode
*inode
,
1069 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1070 struct v4l2_buffer buf
;
1071 struct poll_wqueues
*pwq
;
1073 memset(&buf
, 0, sizeof(buf
));
1075 buf
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1076 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf
);
1078 /* No such buffer */
1079 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err
);
1082 if (!(buf
.flags
& V4L2_BUF_FLAG_MAPPED
)) {
1083 /* Buffer is not mapped */
1088 /* make sure capture actually runs so we don't block forever */
1089 err
= drv(inode
, file
, VIDIOC_STREAMON
, &captype
);
1091 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err
);
1095 pwq
= kmalloc(sizeof(*pwq
), GFP_KERNEL
);
1096 /* Loop as long as the buffer is queued, but not done */
1097 while ((buf
.flags
& (V4L2_BUF_FLAG_QUEUED
| V4L2_BUF_FLAG_DONE
))
1098 == V4L2_BUF_FLAG_QUEUED
) {
1099 err
= poll_one(file
, pwq
);
1100 if (err
< 0 || /* error or sleep was interrupted */
1101 err
== 0) /* timeout? Shouldn't occur. */
1103 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf
);
1105 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err
);
1108 if (!(buf
.flags
& V4L2_BUF_FLAG_DONE
)) /* not done */
1111 err
= drv(inode
, file
, VIDIOC_DQBUF
, &buf
);
1113 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err
);
1114 } while (err
== 0 && buf
.index
!= *i
);
1119 static noinline
int v4l1_compat_get_vbi_format(
1120 struct vbi_format
*fmt
,
1121 struct inode
*inode
,
1126 struct v4l2_format
*fmt2
;
1128 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1133 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1135 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
1137 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err
);
1140 if (fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
) {
1144 memset(fmt
, 0, sizeof(*fmt
));
1145 fmt
->samples_per_line
= fmt2
->fmt
.vbi
.samples_per_line
;
1146 fmt
->sampling_rate
= fmt2
->fmt
.vbi
.sampling_rate
;
1147 fmt
->sample_format
= VIDEO_PALETTE_RAW
;
1148 fmt
->start
[0] = fmt2
->fmt
.vbi
.start
[0];
1149 fmt
->count
[0] = fmt2
->fmt
.vbi
.count
[0];
1150 fmt
->start
[1] = fmt2
->fmt
.vbi
.start
[1];
1151 fmt
->count
[1] = fmt2
->fmt
.vbi
.count
[1];
1152 fmt
->flags
= fmt2
->fmt
.vbi
.flags
& 0x03;
1158 static noinline
int v4l1_compat_set_vbi_format(
1159 struct vbi_format
*fmt
,
1160 struct inode
*inode
,
1165 struct v4l2_format
*fmt2
= NULL
;
1167 if (VIDEO_PALETTE_RAW
!= fmt
->sample_format
) {
1172 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1177 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1178 fmt2
->fmt
.vbi
.samples_per_line
= fmt
->samples_per_line
;
1179 fmt2
->fmt
.vbi
.sampling_rate
= fmt
->sampling_rate
;
1180 fmt2
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1181 fmt2
->fmt
.vbi
.start
[0] = fmt
->start
[0];
1182 fmt2
->fmt
.vbi
.count
[0] = fmt
->count
[0];
1183 fmt2
->fmt
.vbi
.start
[1] = fmt
->start
[1];
1184 fmt2
->fmt
.vbi
.count
[1] = fmt
->count
[1];
1185 fmt2
->fmt
.vbi
.flags
= fmt
->flags
;
1186 err
= drv(inode
, file
, VIDIOC_TRY_FMT
, fmt2
);
1188 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err
);
1192 if (fmt2
->fmt
.vbi
.samples_per_line
!= fmt
->samples_per_line
||
1193 fmt2
->fmt
.vbi
.sampling_rate
!= fmt
->sampling_rate
||
1194 fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
||
1195 fmt2
->fmt
.vbi
.start
[0] != fmt
->start
[0] ||
1196 fmt2
->fmt
.vbi
.count
[0] != fmt
->count
[0] ||
1197 fmt2
->fmt
.vbi
.start
[1] != fmt
->start
[1] ||
1198 fmt2
->fmt
.vbi
.count
[1] != fmt
->count
[1] ||
1199 fmt2
->fmt
.vbi
.flags
!= fmt
->flags
) {
1203 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
1205 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err
);
1212 * This function is exported.
1215 v4l_compat_translate_ioctl(struct inode
*inode
,
1224 case VIDIOCGCAP
: /* capability */
1225 err
= v4l1_compat_get_capabilities(arg
, inode
, file
, drv
);
1227 case VIDIOCGFBUF
: /* get frame buffer */
1228 err
= v4l1_compat_get_frame_buffer(arg
, inode
, file
, drv
);
1230 case VIDIOCSFBUF
: /* set frame buffer */
1231 err
= v4l1_compat_set_frame_buffer(arg
, inode
, file
, drv
);
1233 case VIDIOCGWIN
: /* get window or capture dimensions */
1234 err
= v4l1_compat_get_win_cap_dimensions(arg
, inode
, file
, drv
);
1236 case VIDIOCSWIN
: /* set window and/or capture dimensions */
1237 err
= v4l1_compat_set_win_cap_dimensions(arg
, inode
, file
, drv
);
1239 case VIDIOCCAPTURE
: /* turn on/off preview */
1240 err
= v4l1_compat_turn_preview_on_off(arg
, inode
, file
, drv
);
1242 case VIDIOCGCHAN
: /* get input information */
1243 err
= v4l1_compat_get_input_info(arg
, inode
, file
, drv
);
1245 case VIDIOCSCHAN
: /* set input */
1246 err
= v4l1_compat_set_input(arg
, inode
, file
, drv
);
1248 case VIDIOCGPICT
: /* get tone controls & partial capture format */
1249 err
= v4l1_compat_get_picture(arg
, inode
, file
, drv
);
1251 case VIDIOCSPICT
: /* set tone controls & partial capture format */
1252 err
= v4l1_compat_set_picture(arg
, inode
, file
, drv
);
1254 case VIDIOCGTUNER
: /* get tuner information */
1255 err
= v4l1_compat_get_tuner(arg
, inode
, file
, drv
);
1257 case VIDIOCSTUNER
: /* select a tuner input */
1258 err
= v4l1_compat_select_tuner(arg
, inode
, file
, drv
);
1260 case VIDIOCGFREQ
: /* get frequency */
1261 err
= v4l1_compat_get_frequency(arg
, inode
, file
, drv
);
1263 case VIDIOCSFREQ
: /* set frequency */
1264 err
= v4l1_compat_set_frequency(arg
, inode
, file
, drv
);
1266 case VIDIOCGAUDIO
: /* get audio properties/controls */
1267 err
= v4l1_compat_get_audio(arg
, inode
, file
, drv
);
1269 case VIDIOCSAUDIO
: /* set audio controls */
1270 err
= v4l1_compat_set_audio(arg
, inode
, file
, drv
);
1272 case VIDIOCMCAPTURE
: /* capture a frame */
1273 err
= v4l1_compat_capture_frame(arg
, inode
, file
, drv
);
1275 case VIDIOCSYNC
: /* wait for a frame */
1276 err
= v4l1_compat_sync(arg
, inode
, file
, drv
);
1278 case VIDIOCGVBIFMT
: /* query VBI data capture format */
1279 err
= v4l1_compat_get_vbi_format(arg
, inode
, file
, drv
);
1282 err
= v4l1_compat_set_vbi_format(arg
, inode
, file
, drv
);
1291 EXPORT_SYMBOL(v4l_compat_translate_ioctl
);