2 * $Id: v4l1-compat.c,v 1.9 2005/06/12 04:19:19 mchehab Exp $
5 * Backward Compatibility Layer
7 * Support subroutines for providing V4L2 drivers with backward
8 * compatibility with applications using the old API.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * Author: Bill Dirks <bdirks@pacbell.net>
20 #include <linux/config.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/smp_lock.h>
31 #include <linux/file.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
34 #include <linux/slab.h>
35 #include <linux/videodev.h>
37 #include <asm/uaccess.h>
38 #include <asm/system.h>
39 #include <asm/pgtable.h>
42 #include <linux/kmod.h>
45 static unsigned int debug = 0;
46 module_param(debug, int, 0644);
47 MODULE_PARM_DESC(debug,"enable debug messages");
48 MODULE_AUTHOR("Bill Dirks");
49 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
50 MODULE_LICENSE("GPL");
52 #define dprintk(fmt, arg...) if (debug) \
53 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg)
56 * I O C T L T R A N S L A T I O N
58 * From here on down is the code for translating the numerous
59 * ioctl commands from the old API to the new API.
63 get_v4l_control(struct inode *inode,
68 struct v4l2_queryctrl qctrl2;
69 struct v4l2_control ctrl2;
73 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
75 dprintk("VIDIOC_QUERYCTRL: %d\n",err);
77 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
80 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2);
82 dprintk("VIDIOC_G_CTRL: %d\n",err);
85 return ((ctrl2.value - qctrl2.minimum) * 65535
86 + (qctrl2.maximum - qctrl2.minimum) / 2)
87 / (qctrl2.maximum - qctrl2.minimum);
93 set_v4l_control(struct inode *inode,
99 struct v4l2_queryctrl qctrl2;
100 struct v4l2_control ctrl2;
104 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
106 dprintk("VIDIOC_QUERYCTRL: %d\n",err);
108 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
109 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED))
115 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
117 ctrl2.id = qctrl2.id;
119 (value * (qctrl2.maximum - qctrl2.minimum)
122 ctrl2.value += qctrl2.minimum;
123 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
125 dprintk("VIDIOC_S_CTRL: %d\n",err);
130 /* ----------------------------------------------------------------- */
132 static int palette2pixelformat[] = {
133 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
134 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
135 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
136 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
137 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
138 /* yuv packed pixel */
139 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
140 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
141 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
143 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
144 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
145 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
146 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
147 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
151 palette_to_pixelformat(unsigned int palette)
153 if (palette < ARRAY_SIZE(palette2pixelformat))
154 return palette2pixelformat[palette];
160 pixelformat_to_palette(int pixelformat)
165 case V4L2_PIX_FMT_GREY:
166 palette = VIDEO_PALETTE_GREY;
168 case V4L2_PIX_FMT_RGB555:
169 palette = VIDEO_PALETTE_RGB555;
171 case V4L2_PIX_FMT_RGB565:
172 palette = VIDEO_PALETTE_RGB565;
174 case V4L2_PIX_FMT_BGR24:
175 palette = VIDEO_PALETTE_RGB24;
177 case V4L2_PIX_FMT_BGR32:
178 palette = VIDEO_PALETTE_RGB32;
180 /* yuv packed pixel */
181 case V4L2_PIX_FMT_YUYV:
182 palette = VIDEO_PALETTE_YUYV;
184 case V4L2_PIX_FMT_UYVY:
185 palette = VIDEO_PALETTE_UYVY;
188 case V4L2_PIX_FMT_YUV410:
189 palette = VIDEO_PALETTE_YUV420;
191 case V4L2_PIX_FMT_YUV420:
192 palette = VIDEO_PALETTE_YUV420;
194 case V4L2_PIX_FMT_YUV411P:
195 palette = VIDEO_PALETTE_YUV411P;
197 case V4L2_PIX_FMT_YUV422P:
198 palette = VIDEO_PALETTE_YUV422P;
204 /* ----------------------------------------------------------------- */
206 static int poll_one(struct file *file)
210 struct poll_wqueues pwq;
216 set_current_state(TASK_INTERRUPTIBLE);
217 mask = file->f_op->poll(file, table);
221 if (signal_pending(current)) {
222 retval = -ERESTARTSYS;
227 set_current_state(TASK_RUNNING);
232 static int count_inputs(struct inode *inode,
236 struct v4l2_input input2;
240 memset(&input2,0,sizeof(input2));
242 if (0 != drv(inode,file,VIDIOC_ENUMINPUT, &input2))
248 static int check_size(struct inode *inode,
251 int *maxw, int *maxh)
253 struct v4l2_fmtdesc desc2;
254 struct v4l2_format fmt2;
256 memset(&desc2,0,sizeof(desc2));
257 memset(&fmt2,0,sizeof(fmt2));
259 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
260 if (0 != drv(inode,file,VIDIOC_ENUM_FMT, &desc2))
263 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
264 fmt2.fmt.pix.width = 10000;
265 fmt2.fmt.pix.height = 10000;
266 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
267 if (0 != drv(inode,file,VIDIOC_TRY_FMT, &fmt2))
270 *maxw = fmt2.fmt.pix.width;
271 *maxh = fmt2.fmt.pix.height;
277 /* ----------------------------------------------------------------- */
280 * This function is exported.
283 v4l_compat_translate_ioctl(struct inode *inode,
289 struct v4l2_capability *cap2 = NULL;
290 struct v4l2_format *fmt2 = NULL;
291 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
293 struct v4l2_framebuffer fbuf2;
294 struct v4l2_input input2;
295 struct v4l2_tuner tun2;
296 struct v4l2_standard std2;
297 struct v4l2_frequency freq2;
298 struct v4l2_audio aud2;
299 struct v4l2_queryctrl qctrl2;
300 struct v4l2_buffer buf2;
305 case VIDIOCGCAP: /* capability */
307 struct video_capability *cap = arg;
309 cap2 = kmalloc(sizeof(*cap2),GFP_KERNEL);
310 memset(cap, 0, sizeof(*cap));
311 memset(cap2, 0, sizeof(*cap2));
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 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 (0 != fbuf2.fmt.bytesperline)
383 buffer->bytesperline = fbuf2.fmt.bytesperline;
385 buffer->bytesperline =
386 (buffer->width * buffer->depth + 7) & 7;
387 buffer->bytesperline >>= 3;
391 case VIDIOCSFBUF: /* set frame buffer */
393 struct video_buffer *buffer = arg;
395 memset(&fbuf2, 0, sizeof(fbuf2));
396 fbuf2.base = buffer->base;
397 fbuf2.fmt.height = buffer->height;
398 fbuf2.fmt.width = buffer->width;
399 switch (buffer->depth) {
401 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
404 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
407 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
410 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
413 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
416 fbuf2.fmt.bytesperline = buffer->bytesperline;
417 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
419 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err);
422 case VIDIOCGWIN: /* get window or capture dimensions */
424 struct video_window *win = arg;
426 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
427 memset(win,0,sizeof(*win));
428 memset(fmt2,0,sizeof(*fmt2));
430 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
431 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
433 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err);
435 win->x = fmt2->fmt.win.w.left;
436 win->y = fmt2->fmt.win.w.top;
437 win->width = fmt2->fmt.win.w.width;
438 win->height = fmt2->fmt.win.w.height;
439 win->chromakey = fmt2->fmt.win.chromakey;
445 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
446 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
448 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err);
453 win->width = fmt2->fmt.pix.width;
454 win->height = fmt2->fmt.pix.height;
460 case VIDIOCSWIN: /* set window and/or capture dimensions */
462 struct video_window *win = arg;
465 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
466 memset(fmt2,0,sizeof(*fmt2));
467 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
468 drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
469 err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
471 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err);
473 fmt2->fmt.pix.width = win->width;
474 fmt2->fmt.pix.height = win->height;
475 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
476 fmt2->fmt.pix.bytesperline = 0;
477 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
479 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
481 win->width = fmt2->fmt.pix.width;
482 win->height = fmt2->fmt.pix.height;
485 memset(fmt2,0,sizeof(*fmt2));
486 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
487 fmt2->fmt.win.w.left = win->x;
488 fmt2->fmt.win.w.top = win->y;
489 fmt2->fmt.win.w.width = win->width;
490 fmt2->fmt.win.w.height = win->height;
491 fmt2->fmt.win.chromakey = win->chromakey;
492 fmt2->fmt.win.clips = (void __user *)win->clips;
493 fmt2->fmt.win.clipcount = win->clipcount;
494 err2 = drv(inode, file, VIDIOC_S_FMT, fmt2);
496 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err);
498 if (err1 != 0 && err2 != 0)
502 case VIDIOCCAPTURE: /* turn on/off preview */
507 /* dirty hack time. But v4l1 has no STREAMOFF
508 * equivalent in the API, and this one at
509 * least comes close ... */
510 drv(inode, file, VIDIOC_STREAMOFF, &captype);
512 err = drv(inode, file, VIDIOC_OVERLAY, arg);
514 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err);
517 case VIDIOCGCHAN: /* get input information */
519 struct video_channel *chan = arg;
521 memset(&input2,0,sizeof(input2));
522 input2.index = chan->channel;
523 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
525 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
526 "channel=%d err=%d\n",chan->channel,err);
529 chan->channel = input2.index;
530 memcpy(chan->name, input2.name,
531 min(sizeof(chan->name), sizeof(input2.name)));
532 chan->name[sizeof(chan->name) - 1] = 0;
533 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
534 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
535 switch (input2.type) {
536 case V4L2_INPUT_TYPE_TUNER:
537 chan->type = VIDEO_TYPE_TV;
540 case V4L2_INPUT_TYPE_CAMERA:
541 chan->type = VIDEO_TYPE_CAMERA;
545 err = drv(inode, file, VIDIOC_G_STD, &sid);
547 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err);
549 if (sid & V4L2_STD_PAL)
550 chan->norm = VIDEO_MODE_PAL;
551 if (sid & V4L2_STD_NTSC)
552 chan->norm = VIDEO_MODE_NTSC;
553 if (sid & V4L2_STD_SECAM)
554 chan->norm = VIDEO_MODE_SECAM;
558 case VIDIOCSCHAN: /* set input */
560 struct video_channel *chan = arg;
563 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
565 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err);
566 switch (chan->norm) {
570 case VIDEO_MODE_NTSC:
573 case VIDEO_MODE_SECAM:
574 sid = V4L2_STD_SECAM;
578 err = drv(inode, file, VIDIOC_S_STD, &sid);
580 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err);
584 case VIDIOCGPICT: /* get tone controls & partial capture format */
586 struct video_picture *pict = arg;
588 pict->brightness = get_v4l_control(inode, file,
589 V4L2_CID_BRIGHTNESS,drv);
590 pict->hue = get_v4l_control(inode, file,
592 pict->contrast = get_v4l_control(inode, file,
593 V4L2_CID_CONTRAST, drv);
594 pict->colour = get_v4l_control(inode, file,
595 V4L2_CID_SATURATION, drv);
596 pict->whiteness = get_v4l_control(inode, file,
597 V4L2_CID_WHITENESS, drv);
599 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
600 memset(fmt2,0,sizeof(*fmt2));
601 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
602 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
604 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
608 pict->depth = fmt2->fmt.pix.depth;
610 pict->palette = pixelformat_to_palette(
611 fmt2->fmt.pix.pixelformat);
614 case VIDIOCSPICT: /* set tone controls & partial capture format */
616 struct video_picture *pict = arg;
618 set_v4l_control(inode, file,
619 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
620 set_v4l_control(inode, file,
621 V4L2_CID_HUE, pict->hue, drv);
622 set_v4l_control(inode, file,
623 V4L2_CID_CONTRAST, pict->contrast, drv);
624 set_v4l_control(inode, file,
625 V4L2_CID_SATURATION, pict->colour, drv);
626 set_v4l_control(inode, file,
627 V4L2_CID_WHITENESS, pict->whiteness, drv);
629 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
630 memset(fmt2,0,sizeof(*fmt2));
631 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
632 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
634 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err);
635 if (fmt2->fmt.pix.pixelformat !=
636 palette_to_pixelformat(pict->palette)) {
637 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
639 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
641 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",err);
644 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
646 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err);
647 if (fbuf2.fmt.pixelformat !=
648 palette_to_pixelformat(pict->palette)) {
649 fbuf2.fmt.pixelformat = palette_to_pixelformat(
651 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
653 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",err);
654 err = 0; /* likely fails for non-root */
658 case VIDIOCGTUNER: /* get tuner information */
660 struct video_tuner *tun = arg;
662 memset(&tun2,0,sizeof(tun2));
663 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
665 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err);
668 memcpy(tun->name, tun2.name,
669 min(sizeof(tun->name), sizeof(tun2.name)));
670 tun->name[sizeof(tun->name) - 1] = 0;
671 tun->rangelow = tun2.rangelow;
672 tun->rangehigh = tun2.rangehigh;
674 tun->mode = VIDEO_MODE_AUTO;
676 for (i = 0; i < 64; i++) {
677 memset(&std2,0,sizeof(std2));
679 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
681 if (std2.id & V4L2_STD_PAL)
682 tun->flags |= VIDEO_TUNER_PAL;
683 if (std2.id & V4L2_STD_NTSC)
684 tun->flags |= VIDEO_TUNER_NTSC;
685 if (std2.id & V4L2_STD_SECAM)
686 tun->flags |= VIDEO_TUNER_SECAM;
689 err = drv(inode, file, VIDIOC_G_STD, &sid);
691 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err);
693 if (sid & V4L2_STD_PAL)
694 tun->mode = VIDEO_MODE_PAL;
695 if (sid & V4L2_STD_NTSC)
696 tun->mode = VIDEO_MODE_NTSC;
697 if (sid & V4L2_STD_SECAM)
698 tun->mode = VIDEO_MODE_SECAM;
701 if (tun2.capability & V4L2_TUNER_CAP_LOW)
702 tun->flags |= VIDEO_TUNER_LOW;
703 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
704 tun->flags |= VIDEO_TUNER_STEREO_ON;
705 tun->signal = tun2.signal;
708 case VIDIOCSTUNER: /* select a tuner input */
711 err = drv(inode, file, VIDIOC_S_INPUT, &i);
713 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err);
719 case VIDIOCGFREQ: /* get frequency */
724 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
726 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err);
728 *freq = freq2.frequency;
731 case VIDIOCSFREQ: /* set frequency */
736 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
737 freq2.frequency = *freq;
738 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
740 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err);
743 case VIDIOCGAUDIO: /* get audio properties/controls */
745 struct video_audio *aud = arg;
747 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
749 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err);
752 memcpy(aud->name, aud2.name,
753 min(sizeof(aud->name), sizeof(aud2.name)));
754 aud->name[sizeof(aud->name) - 1] = 0;
755 aud->audio = aud2.index;
757 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
760 aud->flags |= VIDEO_AUDIO_VOLUME;
762 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
765 aud->flags |= VIDEO_AUDIO_BASS;
767 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
770 aud->flags |= VIDEO_AUDIO_TREBLE;
772 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
775 aud->flags |= VIDEO_AUDIO_BALANCE;
777 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
780 aud->flags |= VIDEO_AUDIO_MUTE;
781 aud->flags |= VIDEO_AUDIO_MUTABLE;
784 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
785 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
786 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
787 aud->step = qctrl2.step;
790 memset(&tun2,0,sizeof(tun2));
791 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
793 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err);
798 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
799 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
800 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
801 aud->mode = VIDEO_SOUND_STEREO;
802 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
803 aud->mode = VIDEO_SOUND_MONO;
806 case VIDIOCSAUDIO: /* set audio controls */
808 struct video_audio *aud = arg;
810 memset(&aud2,0,sizeof(aud2));
811 memset(&tun2,0,sizeof(tun2));
813 aud2.index = aud->audio;
814 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
816 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err);
820 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
822 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
824 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
826 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
828 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
829 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
831 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
833 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err);
837 case VIDEO_SOUND_MONO:
838 case VIDEO_SOUND_LANG1:
839 tun2.audmode = V4L2_TUNER_MODE_MONO;
841 case VIDEO_SOUND_STEREO:
842 tun2.audmode = V4L2_TUNER_MODE_STEREO;
844 case VIDEO_SOUND_LANG2:
845 tun2.audmode = V4L2_TUNER_MODE_LANG2;
848 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
850 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err);
857 /* v4l2 drivers must implement that themself. The
858 mmap() differences can't be translated fully
859 transparent, thus there is no point to try that */
861 case VIDIOCMCAPTURE: /* capture a frame */
863 struct video_mmap *mm = arg;
865 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
866 memset(&buf2,0,sizeof(buf2));
867 memset(fmt2,0,sizeof(*fmt2));
869 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
870 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
872 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err);
875 if (mm->width != fmt2->fmt.pix.width ||
876 mm->height != fmt2->fmt.pix.height ||
877 palette_to_pixelformat(mm->format) !=
878 fmt2->fmt.pix.pixelformat)
879 {/* New capture format... */
880 fmt2->fmt.pix.width = mm->width;
881 fmt2->fmt.pix.height = mm->height;
882 fmt2->fmt.pix.pixelformat =
883 palette_to_pixelformat(mm->format);
884 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
885 fmt2->fmt.pix.bytesperline = 0;
886 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
888 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err);
892 buf2.index = mm->frame;
893 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
894 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
896 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err);
899 err = drv(inode, file, VIDIOC_QBUF, &buf2);
901 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err);
904 err = drv(inode, file, VIDIOC_STREAMON, &captype);
906 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err);
909 case VIDIOCSYNC: /* wait for a frame */
914 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
915 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
918 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
921 if (!(buf2.flags & V4L2_BUF_FLAG_MAPPED)) {
922 /* Buffer is not mapped */
927 /* make sure capture actually runs so we don't block forever */
928 err = drv(inode, file, VIDIOC_STREAMON, &captype);
930 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err);
934 /* Loop as long as the buffer is queued, but not done */
936 (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
937 == V4L2_BUF_FLAG_QUEUED)
939 err = poll_one(file);
940 if (err < 0 || /* error or sleep was interrupted */
941 err == 0) /* timeout? Shouldn't occur. */
943 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
945 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
947 if (!(buf2.flags & V4L2_BUF_FLAG_DONE)) /* not done */
950 err = drv(inode, file, VIDIOC_DQBUF, &buf2);
952 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err);
953 } while (err == 0 && buf2.index != *i);
957 case VIDIOCGVBIFMT: /* query VBI data capture format */
959 struct vbi_format *fmt = arg;
961 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
962 memset(fmt2, 0, sizeof(*fmt2));
963 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
965 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
967 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
970 memset(fmt, 0, sizeof(*fmt));
971 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
972 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
973 fmt->sample_format = VIDEO_PALETTE_RAW;
974 fmt->start[0] = fmt2->fmt.vbi.start[0];
975 fmt->count[0] = fmt2->fmt.vbi.count[0];
976 fmt->start[1] = fmt2->fmt.vbi.start[1];
977 fmt->count[1] = fmt2->fmt.vbi.count[1];
978 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
983 struct vbi_format *fmt = arg;
985 fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
986 memset(fmt2, 0, sizeof(*fmt2));
988 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
989 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
990 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
991 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
992 fmt2->fmt.vbi.start[0] = fmt->start[0];
993 fmt2->fmt.vbi.count[0] = fmt->count[0];
994 fmt2->fmt.vbi.start[1] = fmt->start[1];
995 fmt2->fmt.vbi.count[1] = fmt->count[1];
996 fmt2->fmt.vbi.flags = fmt->flags;
997 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
999 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1003 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1004 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1005 VIDEO_PALETTE_RAW != fmt->sample_format ||
1006 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1007 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1008 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1009 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1010 fmt2->fmt.vbi.flags != fmt->flags) {
1014 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1016 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1032 EXPORT_SYMBOL(v4l_compat_translate_ioctl);