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/moduleparam.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
28 #include <linux/file.h>
29 #include <linux/string.h>
30 #include <linux/errno.h>
31 #include <linux/slab.h>
32 #include <linux/videodev.h>
33 #include <media/v4l2-common.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
= 0;
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...) if (debug) \
51 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg)
54 * I O C T L T R A N S L A T I O N
56 * From here on down is the code for translating the numerous
57 * ioctl commands from the old API to the new API.
61 get_v4l_control(struct inode
*inode
,
66 struct v4l2_queryctrl qctrl2
;
67 struct v4l2_control ctrl2
;
71 err
= drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
);
73 dprintk("VIDIOC_QUERYCTRL: %d\n",err
);
75 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
78 err
= drv(inode
, file
, VIDIOC_G_CTRL
, &ctrl2
);
80 dprintk("VIDIOC_G_CTRL: %d\n",err
);
83 return ((ctrl2
.value
- qctrl2
.minimum
) * 65535
84 + (qctrl2
.maximum
- qctrl2
.minimum
) / 2)
85 / (qctrl2
.maximum
- qctrl2
.minimum
);
91 set_v4l_control(struct inode
*inode
,
97 struct v4l2_queryctrl qctrl2
;
98 struct v4l2_control ctrl2
;
102 err
= drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
);
104 dprintk("VIDIOC_QUERYCTRL: %d\n",err
);
106 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
) &&
107 !(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 const static 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 __attribute_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
)
163 case V4L2_PIX_FMT_GREY
:
164 palette
= VIDEO_PALETTE_GREY
;
166 case V4L2_PIX_FMT_RGB555
:
167 palette
= VIDEO_PALETTE_RGB555
;
169 case V4L2_PIX_FMT_RGB565
:
170 palette
= VIDEO_PALETTE_RGB565
;
172 case V4L2_PIX_FMT_BGR24
:
173 palette
= VIDEO_PALETTE_RGB24
;
175 case V4L2_PIX_FMT_BGR32
:
176 palette
= VIDEO_PALETTE_RGB32
;
178 /* yuv packed pixel */
179 case V4L2_PIX_FMT_YUYV
:
180 palette
= VIDEO_PALETTE_YUYV
;
182 case V4L2_PIX_FMT_UYVY
:
183 palette
= VIDEO_PALETTE_UYVY
;
186 case V4L2_PIX_FMT_YUV410
:
187 palette
= VIDEO_PALETTE_YUV420
;
189 case V4L2_PIX_FMT_YUV420
:
190 palette
= VIDEO_PALETTE_YUV420
;
192 case V4L2_PIX_FMT_YUV411P
:
193 palette
= VIDEO_PALETTE_YUV411P
;
195 case V4L2_PIX_FMT_YUV422P
:
196 palette
= VIDEO_PALETTE_YUV422P
;
202 /* ----------------------------------------------------------------- */
204 static int poll_one(struct file
*file
)
208 struct poll_wqueues pwq
;
214 set_current_state(TASK_INTERRUPTIBLE
);
215 mask
= file
->f_op
->poll(file
, table
);
219 if (signal_pending(current
)) {
220 retval
= -ERESTARTSYS
;
225 set_current_state(TASK_RUNNING
);
230 static int count_inputs(struct inode
*inode
,
234 struct v4l2_input input2
;
238 memset(&input2
,0,sizeof(input2
));
240 if (0 != drv(inode
,file
,VIDIOC_ENUMINPUT
, &input2
))
246 static int check_size(struct inode
*inode
,
249 int *maxw
, int *maxh
)
251 struct v4l2_fmtdesc desc2
;
252 struct v4l2_format fmt2
;
254 memset(&desc2
,0,sizeof(desc2
));
255 memset(&fmt2
,0,sizeof(fmt2
));
257 desc2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
258 if (0 != drv(inode
,file
,VIDIOC_ENUM_FMT
, &desc2
))
261 fmt2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
262 fmt2
.fmt
.pix
.width
= 10000;
263 fmt2
.fmt
.pix
.height
= 10000;
264 fmt2
.fmt
.pix
.pixelformat
= desc2
.pixelformat
;
265 if (0 != drv(inode
,file
,VIDIOC_TRY_FMT
, &fmt2
))
268 *maxw
= fmt2
.fmt
.pix
.width
;
269 *maxh
= fmt2
.fmt
.pix
.height
;
275 /* ----------------------------------------------------------------- */
278 * This function is exported.
281 v4l_compat_translate_ioctl(struct inode
*inode
,
287 struct v4l2_capability
*cap2
= NULL
;
288 struct v4l2_format
*fmt2
= NULL
;
289 enum v4l2_buf_type captype
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
291 struct v4l2_framebuffer fbuf2
;
292 struct v4l2_input input2
;
293 struct v4l2_tuner tun2
;
294 struct v4l2_standard std2
;
295 struct v4l2_frequency freq2
;
296 struct v4l2_audio aud2
;
297 struct v4l2_queryctrl qctrl2
;
298 struct v4l2_buffer buf2
;
303 case VIDIOCGCAP
: /* capability */
305 struct video_capability
*cap
= arg
;
307 cap2
= kzalloc(sizeof(*cap2
),GFP_KERNEL
);
308 memset(cap
, 0, sizeof(*cap
));
309 memset(&fbuf2
, 0, sizeof(fbuf2
));
311 err
= drv(inode
, file
, VIDIOC_QUERYCAP
, cap2
);
313 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n",err
);
316 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
) {
317 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf2
);
319 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n",err
);
320 memset(&fbuf2
, 0, sizeof(fbuf2
));
325 memcpy(cap
->name
, cap2
->card
,
326 min(sizeof(cap
->name
), sizeof(cap2
->card
)));
327 cap
->name
[sizeof(cap
->name
) - 1] = 0;
328 if (cap2
->capabilities
& V4L2_CAP_VIDEO_CAPTURE
)
329 cap
->type
|= VID_TYPE_CAPTURE
;
330 if (cap2
->capabilities
& V4L2_CAP_TUNER
)
331 cap
->type
|= VID_TYPE_TUNER
;
332 if (cap2
->capabilities
& V4L2_CAP_VBI_CAPTURE
)
333 cap
->type
|= VID_TYPE_TELETEXT
;
334 if (cap2
->capabilities
& V4L2_CAP_VIDEO_OVERLAY
)
335 cap
->type
|= VID_TYPE_OVERLAY
;
336 if (fbuf2
.capability
& V4L2_FBUF_CAP_LIST_CLIPPING
)
337 cap
->type
|= VID_TYPE_CLIPPING
;
339 cap
->channels
= count_inputs(inode
,file
,drv
);
340 check_size(inode
,file
,drv
,
341 &cap
->maxwidth
,&cap
->maxheight
);
342 cap
->audios
= 0; /* FIXME */
343 cap
->minwidth
= 48; /* FIXME */
344 cap
->minheight
= 32; /* FIXME */
347 case VIDIOCGFBUF
: /* get frame buffer */
349 struct video_buffer
*buffer
= arg
;
351 memset(buffer
, 0, sizeof(*buffer
));
352 memset(&fbuf2
, 0, sizeof(fbuf2
));
354 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf2
);
356 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err
);
359 buffer
->base
= fbuf2
.base
;
360 buffer
->height
= fbuf2
.fmt
.height
;
361 buffer
->width
= fbuf2
.fmt
.width
;
363 switch (fbuf2
.fmt
.pixelformat
) {
364 case V4L2_PIX_FMT_RGB332
:
367 case V4L2_PIX_FMT_RGB555
:
370 case V4L2_PIX_FMT_RGB565
:
373 case V4L2_PIX_FMT_BGR24
:
376 case V4L2_PIX_FMT_BGR32
:
382 if (fbuf2
.fmt
.bytesperline
) {
383 buffer
->bytesperline
= fbuf2
.fmt
.bytesperline
;
384 if (!buffer
->depth
&& buffer
->width
)
385 buffer
->depth
= ((fbuf2
.fmt
.bytesperline
<<3)
386 + (buffer
->width
-1) )
389 buffer
->bytesperline
=
390 (buffer
->width
* buffer
->depth
+ 7) & 7;
391 buffer
->bytesperline
>>= 3;
395 case VIDIOCSFBUF
: /* set frame buffer */
397 struct video_buffer
*buffer
= arg
;
399 memset(&fbuf2
, 0, sizeof(fbuf2
));
400 fbuf2
.base
= buffer
->base
;
401 fbuf2
.fmt
.height
= buffer
->height
;
402 fbuf2
.fmt
.width
= buffer
->width
;
403 switch (buffer
->depth
) {
405 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB332
;
408 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB555
;
411 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_RGB565
;
414 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR24
;
417 fbuf2
.fmt
.pixelformat
= V4L2_PIX_FMT_BGR32
;
420 fbuf2
.fmt
.bytesperline
= buffer
->bytesperline
;
421 err
= drv(inode
, file
, VIDIOC_S_FBUF
, &fbuf2
);
423 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err
);
426 case VIDIOCGWIN
: /* get window or capture dimensions */
428 struct video_window
*win
= arg
;
430 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
431 memset(win
,0,sizeof(*win
));
433 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
434 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
436 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err
);
438 win
->x
= fmt2
->fmt
.win
.w
.left
;
439 win
->y
= fmt2
->fmt
.win
.w
.top
;
440 win
->width
= fmt2
->fmt
.win
.w
.width
;
441 win
->height
= fmt2
->fmt
.win
.w
.height
;
442 win
->chromakey
= fmt2
->fmt
.win
.chromakey
;
448 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
449 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
451 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err
);
456 win
->width
= fmt2
->fmt
.pix
.width
;
457 win
->height
= fmt2
->fmt
.pix
.height
;
463 case VIDIOCSWIN
: /* set window and/or capture dimensions */
465 struct video_window
*win
= arg
;
468 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
469 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
470 drv(inode
, file
, VIDIOC_STREAMOFF
, &fmt2
->type
);
471 err1
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
473 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err
);
475 fmt2
->fmt
.pix
.width
= win
->width
;
476 fmt2
->fmt
.pix
.height
= win
->height
;
477 fmt2
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
478 fmt2
->fmt
.pix
.bytesperline
= 0;
479 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
481 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
483 win
->width
= fmt2
->fmt
.pix
.width
;
484 win
->height
= fmt2
->fmt
.pix
.height
;
487 memset(fmt2
,0,sizeof(*fmt2
));
488 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
489 fmt2
->fmt
.win
.w
.left
= win
->x
;
490 fmt2
->fmt
.win
.w
.top
= win
->y
;
491 fmt2
->fmt
.win
.w
.width
= win
->width
;
492 fmt2
->fmt
.win
.w
.height
= win
->height
;
493 fmt2
->fmt
.win
.chromakey
= win
->chromakey
;
494 fmt2
->fmt
.win
.clips
= (void __user
*)win
->clips
;
495 fmt2
->fmt
.win
.clipcount
= win
->clipcount
;
496 err2
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
498 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err
);
500 if (err1
!= 0 && err2
!= 0)
504 case VIDIOCCAPTURE
: /* turn on/off preview */
509 /* dirty hack time. But v4l1 has no STREAMOFF
510 * equivalent in the API, and this one at
511 * least comes close ... */
512 drv(inode
, file
, VIDIOC_STREAMOFF
, &captype
);
514 err
= drv(inode
, file
, VIDIOC_OVERLAY
, arg
);
516 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err
);
519 case VIDIOCGCHAN
: /* get input information */
521 struct video_channel
*chan
= arg
;
523 memset(&input2
,0,sizeof(input2
));
524 input2
.index
= chan
->channel
;
525 err
= drv(inode
, file
, VIDIOC_ENUMINPUT
, &input2
);
527 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
528 "channel=%d err=%d\n",chan
->channel
,err
);
531 chan
->channel
= input2
.index
;
532 memcpy(chan
->name
, input2
.name
,
533 min(sizeof(chan
->name
), sizeof(input2
.name
)));
534 chan
->name
[sizeof(chan
->name
) - 1] = 0;
535 chan
->tuners
= (input2
.type
== V4L2_INPUT_TYPE_TUNER
) ? 1 : 0;
536 chan
->flags
= (chan
->tuners
) ? VIDEO_VC_TUNER
: 0;
537 switch (input2
.type
) {
538 case V4L2_INPUT_TYPE_TUNER
:
539 chan
->type
= VIDEO_TYPE_TV
;
542 case V4L2_INPUT_TYPE_CAMERA
:
543 chan
->type
= VIDEO_TYPE_CAMERA
;
547 err
= drv(inode
, file
, VIDIOC_G_STD
, &sid
);
549 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err
);
551 if (sid
& V4L2_STD_PAL
)
552 chan
->norm
= VIDEO_MODE_PAL
;
553 if (sid
& V4L2_STD_NTSC
)
554 chan
->norm
= VIDEO_MODE_NTSC
;
555 if (sid
& V4L2_STD_SECAM
)
556 chan
->norm
= VIDEO_MODE_SECAM
;
560 case VIDIOCSCHAN
: /* set input */
562 struct video_channel
*chan
= arg
;
565 err
= drv(inode
, file
, VIDIOC_S_INPUT
, &chan
->channel
);
567 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err
);
568 switch (chan
->norm
) {
572 case VIDEO_MODE_NTSC
:
575 case VIDEO_MODE_SECAM
:
576 sid
= V4L2_STD_SECAM
;
580 err
= drv(inode
, file
, VIDIOC_S_STD
, &sid
);
582 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err
);
586 case VIDIOCGPICT
: /* get tone controls & partial capture format */
588 struct video_picture
*pict
= arg
;
590 pict
->brightness
= get_v4l_control(inode
, file
,
591 V4L2_CID_BRIGHTNESS
,drv
);
592 pict
->hue
= get_v4l_control(inode
, file
,
594 pict
->contrast
= get_v4l_control(inode
, file
,
595 V4L2_CID_CONTRAST
, drv
);
596 pict
->colour
= get_v4l_control(inode
, file
,
597 V4L2_CID_SATURATION
, drv
);
598 pict
->whiteness
= get_v4l_control(inode
, file
,
599 V4L2_CID_WHITENESS
, drv
);
601 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
602 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
603 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
605 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err
);
609 pict
->depth
= ((fmt2
->fmt
.pix
.bytesperline
<<3)
610 + (fmt2
->fmt
.pix
.width
-1) )
611 /fmt2
->fmt
.pix
.width
;
612 pict
->palette
= pixelformat_to_palette(
613 fmt2
->fmt
.pix
.pixelformat
);
616 case VIDIOCSPICT
: /* set tone controls & partial capture format */
618 struct video_picture
*pict
= arg
;
619 int mem_err
= 0, ovl_err
= 0;
621 memset(&fbuf2
, 0, sizeof(fbuf2
));
623 set_v4l_control(inode
, file
,
624 V4L2_CID_BRIGHTNESS
, pict
->brightness
, drv
);
625 set_v4l_control(inode
, file
,
626 V4L2_CID_HUE
, pict
->hue
, drv
);
627 set_v4l_control(inode
, file
,
628 V4L2_CID_CONTRAST
, pict
->contrast
, drv
);
629 set_v4l_control(inode
, file
,
630 V4L2_CID_SATURATION
, pict
->colour
, drv
);
631 set_v4l_control(inode
, file
,
632 V4L2_CID_WHITENESS
, pict
->whiteness
, drv
);
634 * V4L1 uses this ioctl to set both memory capture and overlay
635 * pixel format, while V4L2 has two different ioctls for this.
636 * Some cards may not support one or the other, and may support
637 * different pixel formats for memory vs overlay.
640 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
641 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
642 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
643 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
644 support memory capture. Trying to set the memory capture
645 parameters would be pointless. */
647 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err
);
648 mem_err
= -1000; /* didn't even try */
649 } else if (fmt2
->fmt
.pix
.pixelformat
!=
650 palette_to_pixelformat(pict
->palette
)) {
651 fmt2
->fmt
.pix
.pixelformat
= palette_to_pixelformat(
653 mem_err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
655 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
659 err
= drv(inode
, file
, VIDIOC_G_FBUF
, &fbuf2
);
660 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
661 support overlay. Trying to set the overlay parameters
662 would be quite pointless. */
664 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err
);
665 ovl_err
= -1000; /* didn't even try */
666 } else if (fbuf2
.fmt
.pixelformat
!=
667 palette_to_pixelformat(pict
->palette
)) {
668 fbuf2
.fmt
.pixelformat
= palette_to_pixelformat(
670 ovl_err
= drv(inode
, file
, VIDIOC_S_FBUF
, &fbuf2
);
672 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
675 if (ovl_err
< 0 && mem_err
< 0)
676 /* ioctl failed, couldn't set either parameter */
677 if (mem_err
!= -1000) {
679 } else if (ovl_err
== -EPERM
) {
688 case VIDIOCGTUNER
: /* get tuner information */
690 struct video_tuner
*tun
= arg
;
692 memset(&tun2
,0,sizeof(tun2
));
693 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
695 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err
);
698 memcpy(tun
->name
, tun2
.name
,
699 min(sizeof(tun
->name
), sizeof(tun2
.name
)));
700 tun
->name
[sizeof(tun
->name
) - 1] = 0;
701 tun
->rangelow
= tun2
.rangelow
;
702 tun
->rangehigh
= tun2
.rangehigh
;
704 tun
->mode
= VIDEO_MODE_AUTO
;
706 for (i
= 0; i
< 64; i
++) {
707 memset(&std2
,0,sizeof(std2
));
709 if (0 != drv(inode
, file
, VIDIOC_ENUMSTD
, &std2
))
711 if (std2
.id
& V4L2_STD_PAL
)
712 tun
->flags
|= VIDEO_TUNER_PAL
;
713 if (std2
.id
& V4L2_STD_NTSC
)
714 tun
->flags
|= VIDEO_TUNER_NTSC
;
715 if (std2
.id
& V4L2_STD_SECAM
)
716 tun
->flags
|= VIDEO_TUNER_SECAM
;
719 err
= drv(inode
, file
, VIDIOC_G_STD
, &sid
);
721 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err
);
723 if (sid
& V4L2_STD_PAL
)
724 tun
->mode
= VIDEO_MODE_PAL
;
725 if (sid
& V4L2_STD_NTSC
)
726 tun
->mode
= VIDEO_MODE_NTSC
;
727 if (sid
& V4L2_STD_SECAM
)
728 tun
->mode
= VIDEO_MODE_SECAM
;
731 if (tun2
.capability
& V4L2_TUNER_CAP_LOW
)
732 tun
->flags
|= VIDEO_TUNER_LOW
;
733 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
734 tun
->flags
|= VIDEO_TUNER_STEREO_ON
;
735 tun
->signal
= tun2
.signal
;
738 case VIDIOCSTUNER
: /* select a tuner input */
740 struct video_tuner
*tun
= arg
;
742 memset(&t
,0,sizeof(t
));
746 err
= drv(inode
, file
, VIDIOC_S_INPUT
, &t
);
748 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err
);
752 case VIDIOCGFREQ
: /* get frequency */
754 unsigned long *freq
= arg
;
755 memset(&freq2
,0,sizeof(freq2
));
758 err
= drv(inode
, file
, VIDIOC_G_FREQUENCY
, &freq2
);
760 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err
);
762 *freq
= freq2
.frequency
;
765 case VIDIOCSFREQ
: /* set frequency */
767 unsigned long *freq
= arg
;
768 memset(&freq2
,0,sizeof(freq2
));
770 drv(inode
, file
, VIDIOC_G_FREQUENCY
, &freq2
);
771 freq2
.frequency
= *freq
;
772 err
= drv(inode
, file
, VIDIOC_S_FREQUENCY
, &freq2
);
774 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err
);
777 case VIDIOCGAUDIO
: /* get audio properties/controls */
779 struct video_audio
*aud
= arg
;
780 memset(&aud2
,0,sizeof(aud2
));
782 err
= drv(inode
, file
, VIDIOC_G_AUDIO
, &aud2
);
784 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err
);
787 memcpy(aud
->name
, aud2
.name
,
788 min(sizeof(aud
->name
), sizeof(aud2
.name
)));
789 aud
->name
[sizeof(aud
->name
) - 1] = 0;
790 aud
->audio
= aud2
.index
;
792 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_VOLUME
, drv
);
795 aud
->flags
|= VIDEO_AUDIO_VOLUME
;
797 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_BASS
, drv
);
800 aud
->flags
|= VIDEO_AUDIO_BASS
;
802 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_TREBLE
, drv
);
805 aud
->flags
|= VIDEO_AUDIO_TREBLE
;
807 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_BALANCE
, drv
);
810 aud
->flags
|= VIDEO_AUDIO_BALANCE
;
812 i
= get_v4l_control(inode
, file
, V4L2_CID_AUDIO_MUTE
, drv
);
815 aud
->flags
|= VIDEO_AUDIO_MUTE
;
816 aud
->flags
|= VIDEO_AUDIO_MUTABLE
;
819 qctrl2
.id
= V4L2_CID_AUDIO_VOLUME
;
820 if (drv(inode
, file
, VIDIOC_QUERYCTRL
, &qctrl2
) == 0 &&
821 !(qctrl2
.flags
& V4L2_CTRL_FLAG_DISABLED
))
822 aud
->step
= qctrl2
.step
;
825 memset(&tun2
,0,sizeof(tun2
));
826 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
828 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err
);
833 if (tun2
.rxsubchans
& V4L2_TUNER_SUB_LANG2
)
834 aud
->mode
= VIDEO_SOUND_LANG1
| VIDEO_SOUND_LANG2
;
835 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_STEREO
)
836 aud
->mode
= VIDEO_SOUND_STEREO
;
837 else if (tun2
.rxsubchans
& V4L2_TUNER_SUB_MONO
)
838 aud
->mode
= VIDEO_SOUND_MONO
;
841 case VIDIOCSAUDIO
: /* set audio controls */
843 struct video_audio
*aud
= arg
;
845 memset(&aud2
,0,sizeof(aud2
));
846 memset(&tun2
,0,sizeof(tun2
));
848 aud2
.index
= aud
->audio
;
849 err
= drv(inode
, file
, VIDIOC_S_AUDIO
, &aud2
);
851 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err
);
855 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_VOLUME
,
857 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_BASS
,
859 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_TREBLE
,
861 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_BALANCE
,
863 set_v4l_control(inode
, file
, V4L2_CID_AUDIO_MUTE
,
864 !!(aud
->flags
& VIDEO_AUDIO_MUTE
), drv
);
866 err
= drv(inode
, file
, VIDIOC_G_TUNER
, &tun2
);
868 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err
);
872 case VIDEO_SOUND_MONO
:
873 case VIDEO_SOUND_LANG1
:
874 tun2
.audmode
= V4L2_TUNER_MODE_MONO
;
876 case VIDEO_SOUND_STEREO
:
877 tun2
.audmode
= V4L2_TUNER_MODE_STEREO
;
879 case VIDEO_SOUND_LANG2
:
880 tun2
.audmode
= V4L2_TUNER_MODE_LANG2
;
883 err
= drv(inode
, file
, VIDIOC_S_TUNER
, &tun2
);
885 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err
);
890 case VIDIOCMCAPTURE
: /* capture a frame */
892 struct video_mmap
*mm
= arg
;
894 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
895 memset(&buf2
,0,sizeof(buf2
));
897 fmt2
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
898 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
900 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err
);
903 if (mm
->width
!= fmt2
->fmt
.pix
.width
||
904 mm
->height
!= fmt2
->fmt
.pix
.height
||
905 palette_to_pixelformat(mm
->format
) !=
906 fmt2
->fmt
.pix
.pixelformat
)
907 {/* New capture format... */
908 fmt2
->fmt
.pix
.width
= mm
->width
;
909 fmt2
->fmt
.pix
.height
= mm
->height
;
910 fmt2
->fmt
.pix
.pixelformat
=
911 palette_to_pixelformat(mm
->format
);
912 fmt2
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
913 fmt2
->fmt
.pix
.bytesperline
= 0;
914 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
916 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err
);
920 buf2
.index
= mm
->frame
;
921 buf2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
922 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf2
);
924 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err
);
927 err
= drv(inode
, file
, VIDIOC_QBUF
, &buf2
);
929 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err
);
932 err
= drv(inode
, file
, VIDIOC_STREAMON
, &captype
);
934 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err
);
937 case VIDIOCSYNC
: /* wait for a frame */
941 memset(&buf2
,0,sizeof(buf2
));
943 buf2
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
944 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf2
);
947 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err
);
950 if (!(buf2
.flags
& V4L2_BUF_FLAG_MAPPED
)) {
951 /* Buffer is not mapped */
956 /* make sure capture actually runs so we don't block forever */
957 err
= drv(inode
, file
, VIDIOC_STREAMON
, &captype
);
959 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err
);
963 /* Loop as long as the buffer is queued, but not done */
965 (V4L2_BUF_FLAG_QUEUED
| V4L2_BUF_FLAG_DONE
))
966 == V4L2_BUF_FLAG_QUEUED
)
968 err
= poll_one(file
);
969 if (err
< 0 || /* error or sleep was interrupted */
970 err
== 0) /* timeout? Shouldn't occur. */
972 err
= drv(inode
, file
, VIDIOC_QUERYBUF
, &buf2
);
974 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err
);
976 if (!(buf2
.flags
& V4L2_BUF_FLAG_DONE
)) /* not done */
979 err
= drv(inode
, file
, VIDIOC_DQBUF
, &buf2
);
981 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err
);
982 } while (err
== 0 && buf2
.index
!= *i
);
986 case VIDIOCGVBIFMT
: /* query VBI data capture format */
988 struct vbi_format
*fmt
= arg
;
990 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
991 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
993 err
= drv(inode
, file
, VIDIOC_G_FMT
, fmt2
);
995 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err
);
998 if (fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
) {
1002 memset(fmt
, 0, sizeof(*fmt
));
1003 fmt
->samples_per_line
= fmt2
->fmt
.vbi
.samples_per_line
;
1004 fmt
->sampling_rate
= fmt2
->fmt
.vbi
.sampling_rate
;
1005 fmt
->sample_format
= VIDEO_PALETTE_RAW
;
1006 fmt
->start
[0] = fmt2
->fmt
.vbi
.start
[0];
1007 fmt
->count
[0] = fmt2
->fmt
.vbi
.count
[0];
1008 fmt
->start
[1] = fmt2
->fmt
.vbi
.start
[1];
1009 fmt
->count
[1] = fmt2
->fmt
.vbi
.count
[1];
1010 fmt
->flags
= fmt2
->fmt
.vbi
.flags
& 0x03;
1015 struct vbi_format
*fmt
= arg
;
1017 if (VIDEO_PALETTE_RAW
!= fmt
->sample_format
) {
1022 fmt2
= kzalloc(sizeof(*fmt2
),GFP_KERNEL
);
1024 fmt2
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1025 fmt2
->fmt
.vbi
.samples_per_line
= fmt
->samples_per_line
;
1026 fmt2
->fmt
.vbi
.sampling_rate
= fmt
->sampling_rate
;
1027 fmt2
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1028 fmt2
->fmt
.vbi
.start
[0] = fmt
->start
[0];
1029 fmt2
->fmt
.vbi
.count
[0] = fmt
->count
[0];
1030 fmt2
->fmt
.vbi
.start
[1] = fmt
->start
[1];
1031 fmt2
->fmt
.vbi
.count
[1] = fmt
->count
[1];
1032 fmt2
->fmt
.vbi
.flags
= fmt
->flags
;
1033 err
= drv(inode
, file
, VIDIOC_TRY_FMT
, fmt2
);
1035 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err
);
1039 if (fmt2
->fmt
.vbi
.samples_per_line
!= fmt
->samples_per_line
||
1040 fmt2
->fmt
.vbi
.sampling_rate
!= fmt
->sampling_rate
||
1041 fmt2
->fmt
.vbi
.sample_format
!= V4L2_PIX_FMT_GREY
||
1042 fmt2
->fmt
.vbi
.start
[0] != fmt
->start
[0] ||
1043 fmt2
->fmt
.vbi
.count
[0] != fmt
->count
[0] ||
1044 fmt2
->fmt
.vbi
.start
[1] != fmt
->start
[1] ||
1045 fmt2
->fmt
.vbi
.count
[1] != fmt
->count
[1] ||
1046 fmt2
->fmt
.vbi
.flags
!= fmt
->flags
) {
1050 err
= drv(inode
, file
, VIDIOC_S_FMT
, fmt2
);
1052 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err
);
1066 EXPORT_SYMBOL(v4l_compat_translate_ioctl
);