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>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/pgtable.h>
39 #include <linux/kmod.h>
42 static unsigned int debug
= 0;
43 module_param(debug
, int, 0644);
44 MODULE_PARM_DESC(debug
,"enable debug messages");
45 MODULE_AUTHOR("Bill Dirks");
46 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
47 MODULE_LICENSE("GPL");
49 #define dprintk(fmt, arg...) if (debug) \
50 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
);
74 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
77 err
= drv(inode
, file
, VIDIOC_G_CTRL
, &ctrl2
);
79 dprintk("VIDIOC_G_CTRL: %d\n",err
);
82 return ((ctrl2
.value
- qctrl2
.minimum
) * 65535
83 + (qctrl2
.maximum
- qctrl2
.minimum
) / 2)
84 / (qctrl2
.maximum
- qctrl2
.minimum
);
90 set_v4l_control(struct inode
*inode
,
96 struct v4l2_queryctrl qctrl2
;
97 struct v4l2_control ctrl2
;
101 err
= drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
);
103 dprintk("VIDIOC_QUERYCTRL: %d\n",err
);
105 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
) &&
106 !(qctrl2
.flags
& V4L2_CTRL_FLAG_GRABBED
))
112 if (value
&& qctrl2
.type
== V4L2_CTRL_TYPE_BOOLEAN
)
114 ctrl2
.id
= qctrl2
.id
;
116 (value
* (qctrl2
.maximum
- qctrl2
.minimum
)
119 ctrl2
.value
+= qctrl2
.minimum
;
120 err
= drv(inode
, file
, VIDIOC_S_CTRL
, &ctrl2
);
122 dprintk("VIDIOC_S_CTRL: %d\n",err
);
127 /* ----------------------------------------------------------------- */
129 const static unsigned int palette2pixelformat
[] = {
130 [VIDEO_PALETTE_GREY
] = V4L2_PIX_FMT_GREY
,
131 [VIDEO_PALETTE_RGB555
] = V4L2_PIX_FMT_RGB555
,
132 [VIDEO_PALETTE_RGB565
] = V4L2_PIX_FMT_RGB565
,
133 [VIDEO_PALETTE_RGB24
] = V4L2_PIX_FMT_BGR24
,
134 [VIDEO_PALETTE_RGB32
] = V4L2_PIX_FMT_BGR32
,
135 /* yuv packed pixel */
136 [VIDEO_PALETTE_YUYV
] = V4L2_PIX_FMT_YUYV
,
137 [VIDEO_PALETTE_YUV422
] = V4L2_PIX_FMT_YUYV
,
138 [VIDEO_PALETTE_UYVY
] = V4L2_PIX_FMT_UYVY
,
140 [VIDEO_PALETTE_YUV410P
] = V4L2_PIX_FMT_YUV410
,
141 [VIDEO_PALETTE_YUV420
] = V4L2_PIX_FMT_YUV420
,
142 [VIDEO_PALETTE_YUV420P
] = V4L2_PIX_FMT_YUV420
,
143 [VIDEO_PALETTE_YUV411P
] = V4L2_PIX_FMT_YUV411P
,
144 [VIDEO_PALETTE_YUV422P
] = V4L2_PIX_FMT_YUV422P
,
147 static unsigned int __pure
148 palette_to_pixelformat(unsigned int palette
)
150 if (palette
< ARRAY_SIZE(palette2pixelformat
))
151 return palette2pixelformat
[palette
];
156 static unsigned int __attribute_const__
157 pixelformat_to_palette(unsigned int 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
)
207 struct poll_wqueues pwq
;
213 set_current_state(TASK_INTERRUPTIBLE
);
214 mask
= file
->f_op
->poll(file
, table
);
218 if (signal_pending(current
)) {
219 retval
= -ERESTARTSYS
;
224 set_current_state(TASK_RUNNING
);
229 static int count_inputs(struct inode
*inode
,
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(struct inode
*inode
,
248 int *maxw
, int *maxh
)
250 struct v4l2_fmtdesc desc2
;
251 struct v4l2_format fmt2
;
253 memset(&desc2
,0,sizeof(desc2
));
254 memset(&fmt2
,0,sizeof(fmt2
));
256 desc2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
257 if (0 != drv(inode
,file
,VIDIOC_ENUM_FMT
, &desc2
))
260 fmt2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
261 fmt2
.fmt
.pix
.width
= 10000;
262 fmt2
.fmt
.pix
.height
= 10000;
263 fmt2
.fmt
.pix
.pixelformat
= desc2
.pixelformat
;
264 if (0 != drv(inode
,file
,VIDIOC_TRY_FMT
, &fmt2
))
267 *maxw
= fmt2
.fmt
.pix
.width
;
268 *maxh
= fmt2
.fmt
.pix
.height
;
274 /* ----------------------------------------------------------------- */
277 * This function is exported.
280 v4l_compat_translate_ioctl(struct inode
*inode
,
286 struct v4l2_capability
*cap2
= NULL
;
287 struct v4l2_format
*fmt2
= NULL
;
288 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
290 struct v4l2_framebuffer fbuf2
;
291 struct v4l2_input input2
;
292 struct v4l2_tuner tun2
;
293 struct v4l2_standard std2
;
294 struct v4l2_frequency freq2
;
295 struct v4l2_audio aud2
;
296 struct v4l2_queryctrl qctrl2
;
297 struct v4l2_buffer buf2
;
302 case VIDIOCGCAP
: /* capability */
304 struct video_capability
*cap
= arg
;
306 cap2
= kzalloc(sizeof(*cap2
), GFP_KERNEL
);
311 memset(cap
, 0, sizeof(*cap
));
312 memset(&fbuf2
, 0, sizeof(fbuf2
));
314 err
= drv(inode
, file
, VIDIOC_QUERYCAP
, cap2
);
316 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n",err
);
319 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
) {
320 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf2
);
322 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n",err
);
323 memset(&fbuf2
, 0, sizeof(fbuf2
));
328 memcpy(cap
->name
, cap2
->card
,
329 min(sizeof(cap
->name
), sizeof(cap2
->card
)));
330 cap
->name
[sizeof(cap
->name
) - 1] = 0;
331 if (cap2
->capabilities
& V4L2_CAP_VIDEO_CAPTURE
)
332 cap
->type
|= VID_TYPE_CAPTURE
;
333 if (cap2
->capabilities
& V4L2_CAP_TUNER
)
334 cap
->type
|= VID_TYPE_TUNER
;
335 if (cap2
->capabilities
& V4L2_CAP_VBI_CAPTURE
)
336 cap
->type
|= VID_TYPE_TELETEXT
;
337 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
)
338 cap
->type
|= VID_TYPE_OVERLAY
;
339 if (fbuf2
.capability
& V4L2_FBUF_CAP_LIST_CLIPPING
)
340 cap
->type
|= VID_TYPE_CLIPPING
;
342 cap
->channels
= count_inputs(inode
,file
,drv
);
343 check_size(inode
,file
,drv
,
344 &cap
->maxwidth
,&cap
->maxheight
);
345 cap
->audios
= 0; /* FIXME */
346 cap
->minwidth
= 48; /* FIXME */
347 cap
->minheight
= 32; /* FIXME */
350 case VIDIOCGFBUF
: /* get frame buffer */
352 struct video_buffer
*buffer
= arg
;
354 memset(buffer
, 0, sizeof(*buffer
));
355 memset(&fbuf2
, 0, sizeof(fbuf2
));
357 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf2
);
359 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err
);
362 buffer
->base
= fbuf2
.base
;
363 buffer
->height
= fbuf2
.fmt
.height
;
364 buffer
->width
= fbuf2
.fmt
.width
;
366 switch (fbuf2
.fmt
.pixelformat
) {
367 case V4L2_PIX_FMT_RGB332
:
370 case V4L2_PIX_FMT_RGB555
:
373 case V4L2_PIX_FMT_RGB565
:
376 case V4L2_PIX_FMT_BGR24
:
379 case V4L2_PIX_FMT_BGR32
:
385 if (fbuf2
.fmt
.bytesperline
) {
386 buffer
->bytesperline
= fbuf2
.fmt
.bytesperline
;
387 if (!buffer
->depth
&& buffer
->width
)
388 buffer
->depth
= ((fbuf2
.fmt
.bytesperline
<<3)
389 + (buffer
->width
-1) )
392 buffer
->bytesperline
=
393 (buffer
->width
* buffer
->depth
+ 7) & 7;
394 buffer
->bytesperline
>>= 3;
398 case VIDIOCSFBUF
: /* set frame buffer */
400 struct video_buffer
*buffer
= arg
;
402 memset(&fbuf2
, 0, sizeof(fbuf2
));
403 fbuf2
.base
= buffer
->base
;
404 fbuf2
.fmt
.height
= buffer
->height
;
405 fbuf2
.fmt
.width
= buffer
->width
;
406 switch (buffer
->depth
) {
408 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB332
;
411 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB555
;
414 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB565
;
417 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR24
;
420 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR32
;
423 fbuf2
.fmt
.bytesperline
= buffer
->bytesperline
;
424 err
= drv(inode
, file
, VIDIOC_S_FBUF
, &fbuf2
);
426 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err
);
429 case VIDIOCGWIN
: /* get window or capture dimensions */
431 struct video_window
*win
= arg
;
433 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
438 memset(win
,0,sizeof(*win
));
440 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
441 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
443 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err
);
445 win
->x
= fmt2
->fmt
.win
.w
.left
;
446 win
->y
= fmt2
->fmt
.win
.w
.top
;
447 win
->width
= fmt2
->fmt
.win
.w
.width
;
448 win
->height
= fmt2
->fmt
.win
.w
.height
;
449 win
->chromakey
= fmt2
->fmt
.win
.chromakey
;
455 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
456 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
458 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err
);
463 win
->width
= fmt2
->fmt
.pix
.width
;
464 win
->height
= fmt2
->fmt
.pix
.height
;
470 case VIDIOCSWIN
: /* set window and/or capture dimensions */
472 struct video_window
*win
= arg
;
475 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
480 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
481 drv(inode
, file
, VIDIOC_STREAMOFF
, &fmt2
->type
);
482 err1
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
484 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err
);
486 fmt2
->fmt
.pix
.width
= win
->width
;
487 fmt2
->fmt
.pix
.height
= win
->height
;
488 fmt2
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
489 fmt2
->fmt
.pix
.bytesperline
= 0;
490 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
492 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
494 win
->width
= fmt2
->fmt
.pix
.width
;
495 win
->height
= fmt2
->fmt
.pix
.height
;
498 memset(fmt2
,0,sizeof(*fmt2
));
499 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
500 fmt2
->fmt
.win
.w
.left
= win
->x
;
501 fmt2
->fmt
.win
.w
.top
= win
->y
;
502 fmt2
->fmt
.win
.w
.width
= win
->width
;
503 fmt2
->fmt
.win
.w
.height
= win
->height
;
504 fmt2
->fmt
.win
.chromakey
= win
->chromakey
;
505 fmt2
->fmt
.win
.clips
= (void __user
*)win
->clips
;
506 fmt2
->fmt
.win
.clipcount
= win
->clipcount
;
507 err2
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
509 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err
);
511 if (err1
!= 0 && err2
!= 0)
515 case VIDIOCCAPTURE
: /* turn on/off preview */
520 /* dirty hack time. But v4l1 has no STREAMOFF
521 * equivalent in the API, and this one at
522 * least comes close ... */
523 drv(inode
, file
, VIDIOC_STREAMOFF
, &captype
);
525 err
= drv(inode
, file
, VIDIOC_OVERLAY
, arg
);
527 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err
);
530 case VIDIOCGCHAN
: /* get input information */
532 struct video_channel
*chan
= arg
;
534 memset(&input2
,0,sizeof(input2
));
535 input2
.index
= chan
->channel
;
536 err
= drv(inode
, file
, VIDIOC_ENUMINPUT
, &input2
);
538 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
539 "channel=%d err=%d\n",chan
->channel
,err
);
542 chan
->channel
= input2
.index
;
543 memcpy(chan
->name
, input2
.name
,
544 min(sizeof(chan
->name
), sizeof(input2
.name
)));
545 chan
->name
[sizeof(chan
->name
) - 1] = 0;
546 chan
->tuners
= (input2
.type
== V4L2_INPUT_TYPE_TUNER
) ? 1 : 0;
547 chan
->flags
= (chan
->tuners
) ? VIDEO_VC_TUNER
: 0;
548 switch (input2
.type
) {
549 case V4L2_INPUT_TYPE_TUNER
:
550 chan
->type
= VIDEO_TYPE_TV
;
553 case V4L2_INPUT_TYPE_CAMERA
:
554 chan
->type
= VIDEO_TYPE_CAMERA
;
558 err
= drv(inode
, file
, VIDIOC_G_STD
, &sid
);
560 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err
);
562 if (sid
& V4L2_STD_PAL
)
563 chan
->norm
= VIDEO_MODE_PAL
;
564 if (sid
& V4L2_STD_NTSC
)
565 chan
->norm
= VIDEO_MODE_NTSC
;
566 if (sid
& V4L2_STD_SECAM
)
567 chan
->norm
= VIDEO_MODE_SECAM
;
571 case VIDIOCSCHAN
: /* set input */
573 struct video_channel
*chan
= arg
;
576 err
= drv(inode
, file
, VIDIOC_S_INPUT
, &chan
->channel
);
578 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err
);
579 switch (chan
->norm
) {
583 case VIDEO_MODE_NTSC
:
586 case VIDEO_MODE_SECAM
:
587 sid
= V4L2_STD_SECAM
;
591 err
= drv(inode
, file
, VIDIOC_S_STD
, &sid
);
593 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err
);
597 case VIDIOCGPICT
: /* get tone controls & partial capture format */
599 struct video_picture
*pict
= arg
;
601 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
607 pict
->brightness
= get_v4l_control(inode
, file
,
608 V4L2_CID_BRIGHTNESS
,drv
);
609 pict
->hue
= get_v4l_control(inode
, file
,
611 pict
->contrast
= get_v4l_control(inode
, file
,
612 V4L2_CID_CONTRAST
, drv
);
613 pict
->colour
= get_v4l_control(inode
, file
,
614 V4L2_CID_SATURATION
, drv
);
615 pict
->whiteness
= get_v4l_control(inode
, file
,
616 V4L2_CID_WHITENESS
, drv
);
618 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
619 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
621 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err
);
625 pict
->depth
= ((fmt2
->fmt
.pix
.bytesperline
<<3)
626 + (fmt2
->fmt
.pix
.width
-1) )
627 /fmt2
->fmt
.pix
.width
;
628 pict
->palette
= pixelformat_to_palette(
629 fmt2
->fmt
.pix
.pixelformat
);
632 case VIDIOCSPICT
: /* set tone controls & partial capture format */
634 struct video_picture
*pict
= arg
;
635 int mem_err
= 0, ovl_err
= 0;
637 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
642 memset(&fbuf2
, 0, sizeof(fbuf2
));
644 set_v4l_control(inode
, file
,
645 V4L2_CID_BRIGHTNESS
, pict
->brightness
, drv
);
646 set_v4l_control(inode
, file
,
647 V4L2_CID_HUE
, pict
->hue
, drv
);
648 set_v4l_control(inode
, file
,
649 V4L2_CID_CONTRAST
, pict
->contrast
, drv
);
650 set_v4l_control(inode
, file
,
651 V4L2_CID_SATURATION
, pict
->colour
, drv
);
652 set_v4l_control(inode
, file
,
653 V4L2_CID_WHITENESS
, pict
->whiteness
, drv
);
655 * V4L1 uses this ioctl to set both memory capture and overlay
656 * pixel format, while V4L2 has two different ioctls for this.
657 * Some cards may not support one or the other, and may support
658 * different pixel formats for memory vs overlay.
661 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
662 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
663 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
664 support memory capture. Trying to set the memory capture
665 parameters would be pointless. */
667 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err
);
668 mem_err
= -1000; /* didn't even try */
669 } else if (fmt2
->fmt
.pix
.pixelformat
!=
670 palette_to_pixelformat(pict
->palette
)) {
671 fmt2
->fmt
.pix
.pixelformat
= palette_to_pixelformat(
673 mem_err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
675 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
679 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf2
);
680 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
681 support overlay. Trying to set the overlay parameters
682 would be quite pointless. */
684 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err
);
685 ovl_err
= -1000; /* didn't even try */
686 } else if (fbuf2
.fmt
.pixelformat
!=
687 palette_to_pixelformat(pict
->palette
)) {
688 fbuf2
.fmt
.pixelformat
= palette_to_pixelformat(
690 ovl_err
= drv(inode
, file
, VIDIOC_S_FBUF
, &fbuf2
);
692 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
695 if (ovl_err
< 0 && mem_err
< 0)
696 /* ioctl failed, couldn't set either parameter */
697 if (mem_err
!= -1000) {
699 } else if (ovl_err
== -EPERM
) {
708 case VIDIOCGTUNER
: /* get tuner information */
710 struct video_tuner
*tun
= arg
;
712 memset(&tun2
,0,sizeof(tun2
));
713 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
715 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err
);
718 memcpy(tun
->name
, tun2
.name
,
719 min(sizeof(tun
->name
), sizeof(tun2
.name
)));
720 tun
->name
[sizeof(tun
->name
) - 1] = 0;
721 tun
->rangelow
= tun2
.rangelow
;
722 tun
->rangehigh
= tun2
.rangehigh
;
724 tun
->mode
= VIDEO_MODE_AUTO
;
726 for (i
= 0; i
< 64; i
++) {
727 memset(&std2
,0,sizeof(std2
));
729 if (0 != drv(inode
, file
, VIDIOC_ENUMSTD
, &std2
))
731 if (std2
.id
& V4L2_STD_PAL
)
732 tun
->flags
|= VIDEO_TUNER_PAL
;
733 if (std2
.id
& V4L2_STD_NTSC
)
734 tun
->flags
|= VIDEO_TUNER_NTSC
;
735 if (std2
.id
& V4L2_STD_SECAM
)
736 tun
->flags
|= VIDEO_TUNER_SECAM
;
739 err
= drv(inode
, file
, VIDIOC_G_STD
, &sid
);
741 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err
);
743 if (sid
& V4L2_STD_PAL
)
744 tun
->mode
= VIDEO_MODE_PAL
;
745 if (sid
& V4L2_STD_NTSC
)
746 tun
->mode
= VIDEO_MODE_NTSC
;
747 if (sid
& V4L2_STD_SECAM
)
748 tun
->mode
= VIDEO_MODE_SECAM
;
751 if (tun2
.capability
& V4L2_TUNER_CAP_LOW
)
752 tun
->flags
|= VIDEO_TUNER_LOW
;
753 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
754 tun
->flags
|= VIDEO_TUNER_STEREO_ON
;
755 tun
->signal
= tun2
.signal
;
758 case VIDIOCSTUNER
: /* select a tuner input */
760 struct video_tuner
*tun
= arg
;
762 memset(&t
,0,sizeof(t
));
766 err
= drv(inode
, file
, VIDIOC_S_INPUT
, &t
);
768 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err
);
772 case VIDIOCGFREQ
: /* get frequency */
774 unsigned long *freq
= arg
;
775 memset(&freq2
,0,sizeof(freq2
));
778 err
= drv(inode
, file
, VIDIOC_G_FREQUENCY
, &freq2
);
780 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err
);
782 *freq
= freq2
.frequency
;
785 case VIDIOCSFREQ
: /* set frequency */
787 unsigned long *freq
= arg
;
788 memset(&freq2
,0,sizeof(freq2
));
790 drv(inode
, file
, VIDIOC_G_FREQUENCY
, &freq2
);
791 freq2
.frequency
= *freq
;
792 err
= drv(inode
, file
, VIDIOC_S_FREQUENCY
, &freq2
);
794 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err
);
797 case VIDIOCGAUDIO
: /* get audio properties/controls */
799 struct video_audio
*aud
= arg
;
800 memset(&aud2
,0,sizeof(aud2
));
802 err
= drv(inode
, file
, VIDIOC_G_AUDIO
, &aud2
);
804 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err
);
807 memcpy(aud
->name
, aud2
.name
,
808 min(sizeof(aud
->name
), sizeof(aud2
.name
)));
809 aud
->name
[sizeof(aud
->name
) - 1] = 0;
810 aud
->audio
= aud2
.index
;
812 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_VOLUME
, drv
);
815 aud
->flags
|= VIDEO_AUDIO_VOLUME
;
817 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_BASS
, drv
);
820 aud
->flags
|= VIDEO_AUDIO_BASS
;
822 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_TREBLE
, drv
);
825 aud
->flags
|= VIDEO_AUDIO_TREBLE
;
827 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_BALANCE
, drv
);
830 aud
->flags
|= VIDEO_AUDIO_BALANCE
;
832 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_MUTE
, drv
);
835 aud
->flags
|= VIDEO_AUDIO_MUTE
;
836 aud
->flags
|= VIDEO_AUDIO_MUTABLE
;
839 qctrl2
.id
= V4L2_CID_AUDIO_VOLUME
;
840 if (drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
) == 0 &&
841 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
842 aud
->step
= qctrl2
.step
;
845 memset(&tun2
,0,sizeof(tun2
));
846 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
848 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err
);
853 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_LANG2
)
854 aud
->mode
= VIDEO_SOUND_LANG1
| VIDEO_SOUND_LANG2
;
855 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
856 aud
->mode
= VIDEO_SOUND_STEREO
;
857 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_MONO
)
858 aud
->mode
= VIDEO_SOUND_MONO
;
861 case VIDIOCSAUDIO
: /* set audio controls */
863 struct video_audio
*aud
= arg
;
865 memset(&aud2
,0,sizeof(aud2
));
866 memset(&tun2
,0,sizeof(tun2
));
868 aud2
.index
= aud
->audio
;
869 err
= drv(inode
, file
, VIDIOC_S_AUDIO
, &aud2
);
871 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err
);
875 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_VOLUME
,
877 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_BASS
,
879 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_TREBLE
,
881 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_BALANCE
,
883 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_MUTE
,
884 !!(aud
->flags
& VIDEO_AUDIO_MUTE
), drv
);
886 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
888 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err
);
892 case VIDEO_SOUND_MONO
:
893 case VIDEO_SOUND_LANG1
:
894 tun2
.audmode
= V4L2_TUNER_MODE_MONO
;
896 case VIDEO_SOUND_STEREO
:
897 tun2
.audmode
= V4L2_TUNER_MODE_STEREO
;
899 case VIDEO_SOUND_LANG2
:
900 tun2
.audmode
= V4L2_TUNER_MODE_LANG2
;
903 err
= drv(inode
, file
, VIDIOC_S_TUNER
, &tun2
);
905 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err
);
910 case VIDIOCMCAPTURE
: /* capture a frame */
912 struct video_mmap
*mm
= arg
;
914 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
919 memset(&buf2
,0,sizeof(buf2
));
921 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
922 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
924 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err
);
927 if (mm
->width
!= fmt2
->fmt
.pix
.width
||
928 mm
->height
!= fmt2
->fmt
.pix
.height
||
929 palette_to_pixelformat(mm
->format
) !=
930 fmt2
->fmt
.pix
.pixelformat
)
931 {/* New capture format... */
932 fmt2
->fmt
.pix
.width
= mm
->width
;
933 fmt2
->fmt
.pix
.height
= mm
->height
;
934 fmt2
->fmt
.pix
.pixelformat
=
935 palette_to_pixelformat(mm
->format
);
936 fmt2
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
937 fmt2
->fmt
.pix
.bytesperline
= 0;
938 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
940 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err
);
944 buf2
.index
= mm
->frame
;
945 buf2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
946 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf2
);
948 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err
);
951 err
= drv(inode
, file
, VIDIOC_QBUF
, &buf2
);
953 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err
);
956 err
= drv(inode
, file
, VIDIOC_STREAMON
, &captype
);
958 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err
);
961 case VIDIOCSYNC
: /* wait for a frame */
965 memset(&buf2
,0,sizeof(buf2
));
967 buf2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
968 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf2
);
971 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err
);
974 if (!(buf2
.flags
& V4L2_BUF_FLAG_MAPPED
)) {
975 /* Buffer is not mapped */
980 /* make sure capture actually runs so we don't block forever */
981 err
= drv(inode
, file
, VIDIOC_STREAMON
, &captype
);
983 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err
);
987 /* Loop as long as the buffer is queued, but not done */
989 (V4L2_BUF_FLAG_QUEUED
| V4L2_BUF_FLAG_DONE
))
990 == V4L2_BUF_FLAG_QUEUED
)
992 err
= poll_one(file
);
993 if (err
< 0 || /* error or sleep was interrupted */
994 err
== 0) /* timeout? Shouldn't occur. */
996 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf2
);
998 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err
);
1000 if (!(buf2
.flags
& V4L2_BUF_FLAG_DONE
)) /* not done */
1003 err
= drv(inode
, file
, VIDIOC_DQBUF
, &buf2
);
1005 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err
);
1006 } while (err
== 0 && buf2
.index
!= *i
);
1010 case VIDIOCGVBIFMT
: /* query VBI data capture format */
1012 struct vbi_format
*fmt
= arg
;
1014 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1019 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1021 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
1023 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err
);
1026 if (fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
) {
1030 memset(fmt
, 0, sizeof(*fmt
));
1031 fmt
->samples_per_line
= fmt2
->fmt
.vbi
.samples_per_line
;
1032 fmt
->sampling_rate
= fmt2
->fmt
.vbi
.sampling_rate
;
1033 fmt
->sample_format
= VIDEO_PALETTE_RAW
;
1034 fmt
->start
[0] = fmt2
->fmt
.vbi
.start
[0];
1035 fmt
->count
[0] = fmt2
->fmt
.vbi
.count
[0];
1036 fmt
->start
[1] = fmt2
->fmt
.vbi
.start
[1];
1037 fmt
->count
[1] = fmt2
->fmt
.vbi
.count
[1];
1038 fmt
->flags
= fmt2
->fmt
.vbi
.flags
& 0x03;
1043 struct vbi_format
*fmt
= arg
;
1045 if (VIDEO_PALETTE_RAW
!= fmt
->sample_format
) {
1050 fmt2
= kzalloc(sizeof(*fmt2
), GFP_KERNEL
);
1055 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1056 fmt2
->fmt
.vbi
.samples_per_line
= fmt
->samples_per_line
;
1057 fmt2
->fmt
.vbi
.sampling_rate
= fmt
->sampling_rate
;
1058 fmt2
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1059 fmt2
->fmt
.vbi
.start
[0] = fmt
->start
[0];
1060 fmt2
->fmt
.vbi
.count
[0] = fmt
->count
[0];
1061 fmt2
->fmt
.vbi
.start
[1] = fmt
->start
[1];
1062 fmt2
->fmt
.vbi
.count
[1] = fmt
->count
[1];
1063 fmt2
->fmt
.vbi
.flags
= fmt
->flags
;
1064 err
= drv(inode
, file
, VIDIOC_TRY_FMT
, fmt2
);
1066 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err
);
1070 if (fmt2
->fmt
.vbi
.samples_per_line
!= fmt
->samples_per_line
||
1071 fmt2
->fmt
.vbi
.sampling_rate
!= fmt
->sampling_rate
||
1072 fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
||
1073 fmt2
->fmt
.vbi
.start
[0] != fmt
->start
[0] ||
1074 fmt2
->fmt
.vbi
.count
[0] != fmt
->count
[0] ||
1075 fmt2
->fmt
.vbi
.start
[1] != fmt
->start
[1] ||
1076 fmt2
->fmt
.vbi
.count
[1] != fmt
->count
[1] ||
1077 fmt2
->fmt
.vbi
.flags
!= fmt
->flags
) {
1081 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
1083 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err
);
1097 EXPORT_SYMBOL(v4l_compat_translate_ioctl
);