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 <bdirks@pacbell.net>
19 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/smp_lock.h>
30 #include <linux/file.h>
31 #include <linux/string.h>
32 #include <linux/errno.h>
33 #include <linux/slab.h>
34 #include <linux/videodev.h>
36 #include <asm/uaccess.h>
37 #include <asm/system.h>
38 #include <asm/pgtable.h>
41 #include <linux/kmod.h>
44 static unsigned int debug = 0;
45 module_param(debug, int, 0644);
46 MODULE_PARM_DESC(debug,"enable debug messages");
47 MODULE_AUTHOR("Bill Dirks");
48 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
49 MODULE_LICENSE("GPL");
51 #define dprintk(fmt, arg...) if (debug) \
52 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg)
55 * I O C T L T R A N S L A T I O N
57 * From here on down is the code for translating the numerous
58 * ioctl commands from the old API to the new API.
62 get_v4l_control(struct inode *inode,
67 struct v4l2_queryctrl qctrl2;
68 struct v4l2_control ctrl2;
72 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
74 dprintk("VIDIOC_QUERYCTRL: %d\n",err);
76 !(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))
114 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
116 ctrl2.id = qctrl2.id;
118 (value * (qctrl2.maximum - qctrl2.minimum)
121 ctrl2.value += qctrl2.minimum;
122 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
124 dprintk("VIDIOC_S_CTRL: %d\n",err);
129 /* ----------------------------------------------------------------- */
131 static int palette2pixelformat[] = {
132 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
133 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
134 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
135 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
136 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
137 /* yuv packed pixel */
138 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
139 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
140 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
142 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
143 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
144 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
145 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
146 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
150 palette_to_pixelformat(unsigned int palette)
152 if (palette < ARRAY_SIZE(palette2pixelformat))
153 return palette2pixelformat[palette];
159 pixelformat_to_palette(int pixelformat)
164 case V4L2_PIX_FMT_GREY:
165 palette = VIDEO_PALETTE_GREY;
167 case V4L2_PIX_FMT_RGB555:
168 palette = VIDEO_PALETTE_RGB555;
170 case V4L2_PIX_FMT_RGB565:
171 palette = VIDEO_PALETTE_RGB565;
173 case V4L2_PIX_FMT_BGR24:
174 palette = VIDEO_PALETTE_RGB24;
176 case V4L2_PIX_FMT_BGR32:
177 palette = VIDEO_PALETTE_RGB32;
179 /* yuv packed pixel */
180 case V4L2_PIX_FMT_YUYV:
181 palette = VIDEO_PALETTE_YUYV;
183 case V4L2_PIX_FMT_UYVY:
184 palette = VIDEO_PALETTE_UYVY;
187 case V4L2_PIX_FMT_YUV410:
188 palette = VIDEO_PALETTE_YUV420;
190 case V4L2_PIX_FMT_YUV420:
191 palette = VIDEO_PALETTE_YUV420;
193 case V4L2_PIX_FMT_YUV411P:
194 palette = VIDEO_PALETTE_YUV411P;
196 case V4L2_PIX_FMT_YUV422P:
197 palette = VIDEO_PALETTE_YUV422P;
203 /* ----------------------------------------------------------------- */
205 static int poll_one(struct file *file)
209 struct poll_wqueues pwq;
215 set_current_state(TASK_INTERRUPTIBLE);
216 mask = file->f_op->poll(file, table);
220 if (signal_pending(current)) {
221 retval = -ERESTARTSYS;
226 set_current_state(TASK_RUNNING);
231 static int count_inputs(struct inode *inode,
235 struct v4l2_input input2;
239 memset(&input2,0,sizeof(input2));
241 if (0 != drv(inode,file,VIDIOC_ENUMINPUT, &input2))
247 static int check_size(struct inode *inode,
250 int *maxw, int *maxh)
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 /* ----------------------------------------------------------------- */
279 * This function is exported.
282 v4l_compat_translate_ioctl(struct inode *inode,
288 struct v4l2_capability *cap2 = NULL;
289 struct v4l2_format *fmt2 = NULL;
290 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
292 struct v4l2_framebuffer fbuf2;
293 struct v4l2_input input2;
294 struct v4l2_tuner tun2;
295 struct v4l2_standard std2;
296 struct v4l2_frequency freq2;
297 struct v4l2_audio aud2;
298 struct v4l2_queryctrl qctrl2;
299 struct v4l2_buffer buf2;
304 case VIDIOCGCAP: /* capability */
306 struct video_capability *cap = arg;
308 cap2 = kzalloc(sizeof(*cap2),GFP_KERNEL);
309 memset(cap, 0, sizeof(*cap));
310 memset(&fbuf2, 0, sizeof(fbuf2));
312 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
314 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n",err);
317 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
318 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
320 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n",err);
321 memset(&fbuf2, 0, sizeof(fbuf2));
326 memcpy(cap->name, cap2->card,
327 min(sizeof(cap->name), sizeof(cap2->card)));
328 cap->name[sizeof(cap->name) - 1] = 0;
329 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
330 cap->type |= VID_TYPE_CAPTURE;
331 if (cap2->capabilities & V4L2_CAP_TUNER)
332 cap->type |= VID_TYPE_TUNER;
333 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
334 cap->type |= VID_TYPE_TELETEXT;
335 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
336 cap->type |= VID_TYPE_OVERLAY;
337 if (fbuf2.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
338 cap->type |= VID_TYPE_CLIPPING;
340 cap->channels = count_inputs(inode,file,drv);
341 check_size(inode,file,drv,
342 &cap->maxwidth,&cap->maxheight);
343 cap->audios = 0; /* FIXME */
344 cap->minwidth = 48; /* FIXME */
345 cap->minheight = 32; /* FIXME */
348 case VIDIOCGFBUF: /* get frame buffer */
350 struct video_buffer *buffer = arg;
352 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
354 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err);
357 buffer->base = fbuf2.base;
358 buffer->height = fbuf2.fmt.height;
359 buffer->width = fbuf2.fmt.width;
361 switch (fbuf2.fmt.pixelformat) {
362 case V4L2_PIX_FMT_RGB332:
365 case V4L2_PIX_FMT_RGB555:
368 case V4L2_PIX_FMT_RGB565:
371 case V4L2_PIX_FMT_BGR24:
374 case V4L2_PIX_FMT_BGR32:
380 if (0 != fbuf2.fmt.bytesperline)
381 buffer->bytesperline = fbuf2.fmt.bytesperline;
383 buffer->bytesperline =
384 (buffer->width * buffer->depth + 7) & 7;
385 buffer->bytesperline >>= 3;
389 case VIDIOCSFBUF: /* set frame buffer */
391 struct video_buffer *buffer = arg;
393 memset(&fbuf2, 0, sizeof(fbuf2));
394 fbuf2.base = buffer->base;
395 fbuf2.fmt.height = buffer->height;
396 fbuf2.fmt.width = buffer->width;
397 switch (buffer->depth) {
399 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
402 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
405 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
408 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
411 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
414 fbuf2.fmt.bytesperline = buffer->bytesperline;
415 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
417 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err);
420 case VIDIOCGWIN: /* get window or capture dimensions */
422 struct video_window *win = arg;
424 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
425 memset(win,0,sizeof(*win));
427 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
428 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
430 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err);
432 win->x = fmt2->fmt.win.w.left;
433 win->y = fmt2->fmt.win.w.top;
434 win->width = fmt2->fmt.win.w.width;
435 win->height = fmt2->fmt.win.w.height;
436 win->chromakey = fmt2->fmt.win.chromakey;
442 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
443 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
445 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err);
450 win->width = fmt2->fmt.pix.width;
451 win->height = fmt2->fmt.pix.height;
457 case VIDIOCSWIN: /* set window and/or capture dimensions */
459 struct video_window *win = arg;
462 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
463 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
464 drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
465 err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
467 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err);
469 fmt2->fmt.pix.width = win->width;
470 fmt2->fmt.pix.height = win->height;
471 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
472 fmt2->fmt.pix.bytesperline = 0;
473 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
475 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
477 win->width = fmt2->fmt.pix.width;
478 win->height = fmt2->fmt.pix.height;
481 memset(fmt2,0,sizeof(*fmt2));
482 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
483 fmt2->fmt.win.w.left = win->x;
484 fmt2->fmt.win.w.top = win->y;
485 fmt2->fmt.win.w.width = win->width;
486 fmt2->fmt.win.w.height = win->height;
487 fmt2->fmt.win.chromakey = win->chromakey;
488 fmt2->fmt.win.clips = (void __user *)win->clips;
489 fmt2->fmt.win.clipcount = win->clipcount;
490 err2 = drv(inode, file, VIDIOC_S_FMT, fmt2);
492 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err);
494 if (err1 != 0 && err2 != 0)
498 case VIDIOCCAPTURE: /* turn on/off preview */
503 /* dirty hack time. But v4l1 has no STREAMOFF
504 * equivalent in the API, and this one at
505 * least comes close ... */
506 drv(inode, file, VIDIOC_STREAMOFF, &captype);
508 err = drv(inode, file, VIDIOC_OVERLAY, arg);
510 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err);
513 case VIDIOCGCHAN: /* get input information */
515 struct video_channel *chan = arg;
517 memset(&input2,0,sizeof(input2));
518 input2.index = chan->channel;
519 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
521 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
522 "channel=%d err=%d\n",chan->channel,err);
525 chan->channel = input2.index;
526 memcpy(chan->name, input2.name,
527 min(sizeof(chan->name), sizeof(input2.name)));
528 chan->name[sizeof(chan->name) - 1] = 0;
529 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
530 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
531 switch (input2.type) {
532 case V4L2_INPUT_TYPE_TUNER:
533 chan->type = VIDEO_TYPE_TV;
536 case V4L2_INPUT_TYPE_CAMERA:
537 chan->type = VIDEO_TYPE_CAMERA;
541 err = drv(inode, file, VIDIOC_G_STD, &sid);
543 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err);
545 if (sid & V4L2_STD_PAL)
546 chan->norm = VIDEO_MODE_PAL;
547 if (sid & V4L2_STD_NTSC)
548 chan->norm = VIDEO_MODE_NTSC;
549 if (sid & V4L2_STD_SECAM)
550 chan->norm = VIDEO_MODE_SECAM;
554 case VIDIOCSCHAN: /* set input */
556 struct video_channel *chan = arg;
559 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
561 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err);
562 switch (chan->norm) {
566 case VIDEO_MODE_NTSC:
569 case VIDEO_MODE_SECAM:
570 sid = V4L2_STD_SECAM;
574 err = drv(inode, file, VIDIOC_S_STD, &sid);
576 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err);
580 case VIDIOCGPICT: /* get tone controls & partial capture format */
582 struct video_picture *pict = arg;
584 pict->brightness = get_v4l_control(inode, file,
585 V4L2_CID_BRIGHTNESS,drv);
586 pict->hue = get_v4l_control(inode, file,
588 pict->contrast = get_v4l_control(inode, file,
589 V4L2_CID_CONTRAST, drv);
590 pict->colour = get_v4l_control(inode, file,
591 V4L2_CID_SATURATION, drv);
592 pict->whiteness = get_v4l_control(inode, file,
593 V4L2_CID_WHITENESS, drv);
595 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
596 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
597 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
599 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
602 pict->palette = pixelformat_to_palette(
603 fmt2->fmt.pix.pixelformat);
606 case VIDIOCSPICT: /* set tone controls & partial capture format */
608 struct video_picture *pict = arg;
610 set_v4l_control(inode, file,
611 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
612 set_v4l_control(inode, file,
613 V4L2_CID_HUE, pict->hue, drv);
614 set_v4l_control(inode, file,
615 V4L2_CID_CONTRAST, pict->contrast, drv);
616 set_v4l_control(inode, file,
617 V4L2_CID_SATURATION, pict->colour, drv);
618 set_v4l_control(inode, file,
619 V4L2_CID_WHITENESS, pict->whiteness, drv);
621 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
622 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
623 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
625 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err);
626 if (fmt2->fmt.pix.pixelformat !=
627 palette_to_pixelformat(pict->palette)) {
628 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
630 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
632 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",err);
635 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
637 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err);
638 if (fbuf2.fmt.pixelformat !=
639 palette_to_pixelformat(pict->palette)) {
640 fbuf2.fmt.pixelformat = palette_to_pixelformat(
642 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
644 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",err);
645 err = 0; /* likely fails for non-root */
649 case VIDIOCGTUNER: /* get tuner information */
651 struct video_tuner *tun = arg;
653 memset(&tun2,0,sizeof(tun2));
654 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
656 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err);
659 memcpy(tun->name, tun2.name,
660 min(sizeof(tun->name), sizeof(tun2.name)));
661 tun->name[sizeof(tun->name) - 1] = 0;
662 tun->rangelow = tun2.rangelow;
663 tun->rangehigh = tun2.rangehigh;
665 tun->mode = VIDEO_MODE_AUTO;
667 for (i = 0; i < 64; i++) {
668 memset(&std2,0,sizeof(std2));
670 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
672 if (std2.id & V4L2_STD_PAL)
673 tun->flags |= VIDEO_TUNER_PAL;
674 if (std2.id & V4L2_STD_NTSC)
675 tun->flags |= VIDEO_TUNER_NTSC;
676 if (std2.id & V4L2_STD_SECAM)
677 tun->flags |= VIDEO_TUNER_SECAM;
680 err = drv(inode, file, VIDIOC_G_STD, &sid);
682 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err);
684 if (sid & V4L2_STD_PAL)
685 tun->mode = VIDEO_MODE_PAL;
686 if (sid & V4L2_STD_NTSC)
687 tun->mode = VIDEO_MODE_NTSC;
688 if (sid & V4L2_STD_SECAM)
689 tun->mode = VIDEO_MODE_SECAM;
692 if (tun2.capability & V4L2_TUNER_CAP_LOW)
693 tun->flags |= VIDEO_TUNER_LOW;
694 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
695 tun->flags |= VIDEO_TUNER_STEREO_ON;
696 tun->signal = tun2.signal;
699 case VIDIOCSTUNER: /* select a tuner input */
704 case VIDIOCGFREQ: /* get frequency */
706 unsigned long *freq = arg;
709 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
711 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err);
713 *freq = freq2.frequency;
716 case VIDIOCSFREQ: /* set frequency */
718 unsigned long *freq = arg;
721 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
722 freq2.frequency = *freq;
723 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
725 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err);
728 case VIDIOCGAUDIO: /* get audio properties/controls */
730 struct video_audio *aud = arg;
732 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
734 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err);
737 memcpy(aud->name, aud2.name,
738 min(sizeof(aud->name), sizeof(aud2.name)));
739 aud->name[sizeof(aud->name) - 1] = 0;
740 aud->audio = aud2.index;
742 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
745 aud->flags |= VIDEO_AUDIO_VOLUME;
747 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
750 aud->flags |= VIDEO_AUDIO_BASS;
752 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
755 aud->flags |= VIDEO_AUDIO_TREBLE;
757 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
760 aud->flags |= VIDEO_AUDIO_BALANCE;
762 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
765 aud->flags |= VIDEO_AUDIO_MUTE;
766 aud->flags |= VIDEO_AUDIO_MUTABLE;
769 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
770 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
771 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
772 aud->step = qctrl2.step;
775 memset(&tun2,0,sizeof(tun2));
776 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
778 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err);
783 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
784 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
785 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
786 aud->mode = VIDEO_SOUND_STEREO;
787 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
788 aud->mode = VIDEO_SOUND_MONO;
791 case VIDIOCSAUDIO: /* set audio controls */
793 struct video_audio *aud = arg;
795 memset(&aud2,0,sizeof(aud2));
796 memset(&tun2,0,sizeof(tun2));
798 aud2.index = aud->audio;
799 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
801 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err);
805 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
807 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
809 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
811 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
813 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
814 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
816 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
818 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err);
822 case VIDEO_SOUND_MONO:
823 case VIDEO_SOUND_LANG1:
824 tun2.audmode = V4L2_TUNER_MODE_MONO;
826 case VIDEO_SOUND_STEREO:
827 tun2.audmode = V4L2_TUNER_MODE_STEREO;
829 case VIDEO_SOUND_LANG2:
830 tun2.audmode = V4L2_TUNER_MODE_LANG2;
833 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
835 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err);
840 case VIDIOCMCAPTURE: /* capture a frame */
842 struct video_mmap *mm = arg;
844 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
845 memset(&buf2,0,sizeof(buf2));
847 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
848 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
850 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err);
853 if (mm->width != fmt2->fmt.pix.width ||
854 mm->height != fmt2->fmt.pix.height ||
855 palette_to_pixelformat(mm->format) !=
856 fmt2->fmt.pix.pixelformat)
857 {/* New capture format... */
858 fmt2->fmt.pix.width = mm->width;
859 fmt2->fmt.pix.height = mm->height;
860 fmt2->fmt.pix.pixelformat =
861 palette_to_pixelformat(mm->format);
862 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
863 fmt2->fmt.pix.bytesperline = 0;
864 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
866 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err);
870 buf2.index = mm->frame;
871 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
872 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
874 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err);
877 err = drv(inode, file, VIDIOC_QBUF, &buf2);
879 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err);
882 err = drv(inode, file, VIDIOC_STREAMON, &captype);
884 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err);
887 case VIDIOCSYNC: /* wait for a frame */
892 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
893 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
896 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
899 if (!(buf2.flags & V4L2_BUF_FLAG_MAPPED)) {
900 /* Buffer is not mapped */
905 /* make sure capture actually runs so we don't block forever */
906 err = drv(inode, file, VIDIOC_STREAMON, &captype);
908 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err);
912 /* Loop as long as the buffer is queued, but not done */
914 (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
915 == V4L2_BUF_FLAG_QUEUED)
917 err = poll_one(file);
918 if (err < 0 || /* error or sleep was interrupted */
919 err == 0) /* timeout? Shouldn't occur. */
921 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
923 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
925 if (!(buf2.flags & V4L2_BUF_FLAG_DONE)) /* not done */
928 err = drv(inode, file, VIDIOC_DQBUF, &buf2);
930 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err);
931 } while (err == 0 && buf2.index != *i);
935 case VIDIOCGVBIFMT: /* query VBI data capture format */
937 struct vbi_format *fmt = arg;
939 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
940 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
942 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
944 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
947 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
951 memset(fmt, 0, sizeof(*fmt));
952 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
953 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
954 fmt->sample_format = VIDEO_PALETTE_RAW;
955 fmt->start[0] = fmt2->fmt.vbi.start[0];
956 fmt->count[0] = fmt2->fmt.vbi.count[0];
957 fmt->start[1] = fmt2->fmt.vbi.start[1];
958 fmt->count[1] = fmt2->fmt.vbi.count[1];
959 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
964 struct vbi_format *fmt = arg;
966 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
971 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
973 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
974 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
975 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
976 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
977 fmt2->fmt.vbi.start[0] = fmt->start[0];
978 fmt2->fmt.vbi.count[0] = fmt->count[0];
979 fmt2->fmt.vbi.start[1] = fmt->start[1];
980 fmt2->fmt.vbi.count[1] = fmt->count[1];
981 fmt2->fmt.vbi.flags = fmt->flags;
982 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
984 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
988 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
989 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
990 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
991 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
992 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
993 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
994 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
995 fmt2->fmt.vbi.flags != fmt->flags) {
999 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1001 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1015 EXPORT_SYMBOL(v4l_compat_translate_ioctl);