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);
307 memset(cap, 0, sizeof(*cap));
308 memset(&fbuf2, 0, sizeof(fbuf2));
310 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
312 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n",err);
315 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
316 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
318 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n",err);
319 memset(&fbuf2, 0, sizeof(fbuf2));
324 memcpy(cap->name, cap2->card,
325 min(sizeof(cap->name), sizeof(cap2->card)));
326 cap->name[sizeof(cap->name) - 1] = 0;
327 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
328 cap->type |= VID_TYPE_CAPTURE;
329 if (cap2->capabilities & V4L2_CAP_TUNER)
330 cap->type |= VID_TYPE_TUNER;
331 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
332 cap->type |= VID_TYPE_TELETEXT;
333 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
334 cap->type |= VID_TYPE_OVERLAY;
335 if (fbuf2.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
336 cap->type |= VID_TYPE_CLIPPING;
338 cap->channels = count_inputs(inode,file,drv);
339 check_size(inode,file,drv,
340 &cap->maxwidth,&cap->maxheight);
341 cap->audios = 0; /* FIXME */
342 cap->minwidth = 48; /* FIXME */
343 cap->minheight = 32; /* FIXME */
346 case VIDIOCGFBUF: /* get frame buffer */
348 struct video_buffer *buffer = arg;
350 memset(buffer, 0, sizeof(*buffer));
351 memset(&fbuf2, 0, sizeof(fbuf2));
353 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
355 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err);
358 buffer->base = fbuf2.base;
359 buffer->height = fbuf2.fmt.height;
360 buffer->width = fbuf2.fmt.width;
362 switch (fbuf2.fmt.pixelformat) {
363 case V4L2_PIX_FMT_RGB332:
366 case V4L2_PIX_FMT_RGB555:
369 case V4L2_PIX_FMT_RGB565:
372 case V4L2_PIX_FMT_BGR24:
375 case V4L2_PIX_FMT_BGR32:
381 if (fbuf2.fmt.bytesperline) {
382 buffer->bytesperline = fbuf2.fmt.bytesperline;
383 if (!buffer->depth && buffer->width)
384 buffer->depth = ((fbuf2.fmt.bytesperline<<3)
385 + (buffer->width-1) )
388 buffer->bytesperline =
389 (buffer->width * buffer->depth + 7) & 7;
390 buffer->bytesperline >>= 3;
394 case VIDIOCSFBUF: /* set frame buffer */
396 struct video_buffer *buffer = arg;
398 memset(&fbuf2, 0, sizeof(fbuf2));
399 fbuf2.base = buffer->base;
400 fbuf2.fmt.height = buffer->height;
401 fbuf2.fmt.width = buffer->width;
402 switch (buffer->depth) {
404 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
407 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
410 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
413 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
416 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
419 fbuf2.fmt.bytesperline = buffer->bytesperline;
420 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
422 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err);
425 case VIDIOCGWIN: /* get window or capture dimensions */
427 struct video_window *win = arg;
429 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
430 memset(win,0,sizeof(*win));
432 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
433 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
435 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err);
437 win->x = fmt2->fmt.win.w.left;
438 win->y = fmt2->fmt.win.w.top;
439 win->width = fmt2->fmt.win.w.width;
440 win->height = fmt2->fmt.win.w.height;
441 win->chromakey = fmt2->fmt.win.chromakey;
447 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
448 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
450 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err);
455 win->width = fmt2->fmt.pix.width;
456 win->height = fmt2->fmt.pix.height;
462 case VIDIOCSWIN: /* set window and/or capture dimensions */
464 struct video_window *win = arg;
467 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
468 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
469 drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
470 err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
472 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err);
474 fmt2->fmt.pix.width = win->width;
475 fmt2->fmt.pix.height = win->height;
476 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
477 fmt2->fmt.pix.bytesperline = 0;
478 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
480 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
482 win->width = fmt2->fmt.pix.width;
483 win->height = fmt2->fmt.pix.height;
486 memset(fmt2,0,sizeof(*fmt2));
487 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
488 fmt2->fmt.win.w.left = win->x;
489 fmt2->fmt.win.w.top = win->y;
490 fmt2->fmt.win.w.width = win->width;
491 fmt2->fmt.win.w.height = win->height;
492 fmt2->fmt.win.chromakey = win->chromakey;
493 fmt2->fmt.win.clips = (void __user *)win->clips;
494 fmt2->fmt.win.clipcount = win->clipcount;
495 err2 = drv(inode, file, VIDIOC_S_FMT, fmt2);
497 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err);
499 if (err1 != 0 && err2 != 0)
503 case VIDIOCCAPTURE: /* turn on/off preview */
508 /* dirty hack time. But v4l1 has no STREAMOFF
509 * equivalent in the API, and this one at
510 * least comes close ... */
511 drv(inode, file, VIDIOC_STREAMOFF, &captype);
513 err = drv(inode, file, VIDIOC_OVERLAY, arg);
515 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err);
518 case VIDIOCGCHAN: /* get input information */
520 struct video_channel *chan = arg;
522 memset(&input2,0,sizeof(input2));
523 input2.index = chan->channel;
524 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
526 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
527 "channel=%d err=%d\n",chan->channel,err);
530 chan->channel = input2.index;
531 memcpy(chan->name, input2.name,
532 min(sizeof(chan->name), sizeof(input2.name)));
533 chan->name[sizeof(chan->name) - 1] = 0;
534 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
535 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
536 switch (input2.type) {
537 case V4L2_INPUT_TYPE_TUNER:
538 chan->type = VIDEO_TYPE_TV;
541 case V4L2_INPUT_TYPE_CAMERA:
542 chan->type = VIDEO_TYPE_CAMERA;
546 err = drv(inode, file, VIDIOC_G_STD, &sid);
548 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err);
550 if (sid & V4L2_STD_PAL)
551 chan->norm = VIDEO_MODE_PAL;
552 if (sid & V4L2_STD_NTSC)
553 chan->norm = VIDEO_MODE_NTSC;
554 if (sid & V4L2_STD_SECAM)
555 chan->norm = VIDEO_MODE_SECAM;
559 case VIDIOCSCHAN: /* set input */
561 struct video_channel *chan = arg;
564 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
566 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err);
567 switch (chan->norm) {
571 case VIDEO_MODE_NTSC:
574 case VIDEO_MODE_SECAM:
575 sid = V4L2_STD_SECAM;
579 err = drv(inode, file, VIDIOC_S_STD, &sid);
581 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err);
585 case VIDIOCGPICT: /* get tone controls & partial capture format */
587 struct video_picture *pict = arg;
589 pict->brightness = get_v4l_control(inode, file,
590 V4L2_CID_BRIGHTNESS,drv);
591 pict->hue = get_v4l_control(inode, file,
593 pict->contrast = get_v4l_control(inode, file,
594 V4L2_CID_CONTRAST, drv);
595 pict->colour = get_v4l_control(inode, file,
596 V4L2_CID_SATURATION, drv);
597 pict->whiteness = get_v4l_control(inode, file,
598 V4L2_CID_WHITENESS, drv);
600 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
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.bytesperline<<3)
609 + (fmt2->fmt.pix.width-1) )
610 /fmt2->fmt.pix.width;
611 pict->palette = pixelformat_to_palette(
612 fmt2->fmt.pix.pixelformat);
615 case VIDIOCSPICT: /* set tone controls & partial capture format */
617 struct video_picture *pict = arg;
618 int mem_err = 0, ovl_err = 0;
620 memset(&fbuf2, 0, sizeof(fbuf2));
622 set_v4l_control(inode, file,
623 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
624 set_v4l_control(inode, file,
625 V4L2_CID_HUE, pict->hue, drv);
626 set_v4l_control(inode, file,
627 V4L2_CID_CONTRAST, pict->contrast, drv);
628 set_v4l_control(inode, file,
629 V4L2_CID_SATURATION, pict->colour, drv);
630 set_v4l_control(inode, file,
631 V4L2_CID_WHITENESS, pict->whiteness, drv);
633 * V4L1 uses this ioctl to set both memory capture and overlay
634 * pixel format, while V4L2 has two different ioctls for this.
635 * Some cards may not support one or the other, and may support
636 * different pixel formats for memory vs overlay.
639 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
640 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
641 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
642 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
643 support memory capture. Trying to set the memory capture
644 parameters would be pointless. */
646 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err);
647 mem_err = -1000; /* didn't even try */
648 } else if (fmt2->fmt.pix.pixelformat !=
649 palette_to_pixelformat(pict->palette)) {
650 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
652 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt2);
654 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
658 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
659 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
660 support overlay. Trying to set the overlay parameters
661 would be quite pointless. */
663 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err);
664 ovl_err = -1000; /* didn't even try */
665 } else if (fbuf2.fmt.pixelformat !=
666 palette_to_pixelformat(pict->palette)) {
667 fbuf2.fmt.pixelformat = palette_to_pixelformat(
669 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
671 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
674 if (ovl_err < 0 && mem_err < 0)
675 /* ioctl failed, couldn't set either parameter */
676 if (mem_err != -1000) {
678 } else if (ovl_err == -EPERM) {
687 case VIDIOCGTUNER: /* get tuner information */
689 struct video_tuner *tun = arg;
691 memset(&tun2,0,sizeof(tun2));
692 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
694 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err);
697 memcpy(tun->name, tun2.name,
698 min(sizeof(tun->name), sizeof(tun2.name)));
699 tun->name[sizeof(tun->name) - 1] = 0;
700 tun->rangelow = tun2.rangelow;
701 tun->rangehigh = tun2.rangehigh;
703 tun->mode = VIDEO_MODE_AUTO;
705 for (i = 0; i < 64; i++) {
706 memset(&std2,0,sizeof(std2));
708 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
710 if (std2.id & V4L2_STD_PAL)
711 tun->flags |= VIDEO_TUNER_PAL;
712 if (std2.id & V4L2_STD_NTSC)
713 tun->flags |= VIDEO_TUNER_NTSC;
714 if (std2.id & V4L2_STD_SECAM)
715 tun->flags |= VIDEO_TUNER_SECAM;
718 err = drv(inode, file, VIDIOC_G_STD, &sid);
720 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err);
722 if (sid & V4L2_STD_PAL)
723 tun->mode = VIDEO_MODE_PAL;
724 if (sid & V4L2_STD_NTSC)
725 tun->mode = VIDEO_MODE_NTSC;
726 if (sid & V4L2_STD_SECAM)
727 tun->mode = VIDEO_MODE_SECAM;
730 if (tun2.capability & V4L2_TUNER_CAP_LOW)
731 tun->flags |= VIDEO_TUNER_LOW;
732 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
733 tun->flags |= VIDEO_TUNER_STEREO_ON;
734 tun->signal = tun2.signal;
737 case VIDIOCSTUNER: /* select a tuner input */
739 struct video_tuner *tun = arg;
741 memset(&t,0,sizeof(t));
745 err = drv(inode, file, VIDIOC_S_INPUT, &t);
747 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err);
751 case VIDIOCGFREQ: /* get frequency */
753 unsigned long *freq = arg;
754 memset(&freq2,0,sizeof(freq2));
757 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
759 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err);
761 *freq = freq2.frequency;
764 case VIDIOCSFREQ: /* set frequency */
766 unsigned long *freq = arg;
767 memset(&freq2,0,sizeof(freq2));
769 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
770 freq2.frequency = *freq;
771 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
773 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err);
776 case VIDIOCGAUDIO: /* get audio properties/controls */
778 struct video_audio *aud = arg;
779 memset(&aud2,0,sizeof(aud2));
781 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
783 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err);
786 memcpy(aud->name, aud2.name,
787 min(sizeof(aud->name), sizeof(aud2.name)));
788 aud->name[sizeof(aud->name) - 1] = 0;
789 aud->audio = aud2.index;
791 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
794 aud->flags |= VIDEO_AUDIO_VOLUME;
796 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
799 aud->flags |= VIDEO_AUDIO_BASS;
801 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
804 aud->flags |= VIDEO_AUDIO_TREBLE;
806 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
809 aud->flags |= VIDEO_AUDIO_BALANCE;
811 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
814 aud->flags |= VIDEO_AUDIO_MUTE;
815 aud->flags |= VIDEO_AUDIO_MUTABLE;
818 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
819 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
820 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
821 aud->step = qctrl2.step;
824 memset(&tun2,0,sizeof(tun2));
825 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
827 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err);
832 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
833 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
834 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
835 aud->mode = VIDEO_SOUND_STEREO;
836 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
837 aud->mode = VIDEO_SOUND_MONO;
840 case VIDIOCSAUDIO: /* set audio controls */
842 struct video_audio *aud = arg;
844 memset(&aud2,0,sizeof(aud2));
845 memset(&tun2,0,sizeof(tun2));
847 aud2.index = aud->audio;
848 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
850 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err);
854 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
856 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
858 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
860 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
862 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
863 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
865 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
867 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err);
871 case VIDEO_SOUND_MONO:
872 case VIDEO_SOUND_LANG1:
873 tun2.audmode = V4L2_TUNER_MODE_MONO;
875 case VIDEO_SOUND_STEREO:
876 tun2.audmode = V4L2_TUNER_MODE_STEREO;
878 case VIDEO_SOUND_LANG2:
879 tun2.audmode = V4L2_TUNER_MODE_LANG2;
882 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
884 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err);
889 case VIDIOCMCAPTURE: /* capture a frame */
891 struct video_mmap *mm = arg;
893 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
894 memset(&buf2,0,sizeof(buf2));
896 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
897 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
899 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err);
902 if (mm->width != fmt2->fmt.pix.width ||
903 mm->height != fmt2->fmt.pix.height ||
904 palette_to_pixelformat(mm->format) !=
905 fmt2->fmt.pix.pixelformat)
906 {/* New capture format... */
907 fmt2->fmt.pix.width = mm->width;
908 fmt2->fmt.pix.height = mm->height;
909 fmt2->fmt.pix.pixelformat =
910 palette_to_pixelformat(mm->format);
911 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
912 fmt2->fmt.pix.bytesperline = 0;
913 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
915 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err);
919 buf2.index = mm->frame;
920 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
921 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
923 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err);
926 err = drv(inode, file, VIDIOC_QBUF, &buf2);
928 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err);
931 err = drv(inode, file, VIDIOC_STREAMON, &captype);
933 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err);
936 case VIDIOCSYNC: /* wait for a frame */
940 memset(&buf2,0,sizeof(buf2));
942 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
943 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
946 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
949 if (!(buf2.flags & V4L2_BUF_FLAG_MAPPED)) {
950 /* Buffer is not mapped */
955 /* make sure capture actually runs so we don't block forever */
956 err = drv(inode, file, VIDIOC_STREAMON, &captype);
958 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err);
962 /* Loop as long as the buffer is queued, but not done */
964 (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
965 == V4L2_BUF_FLAG_QUEUED)
967 err = poll_one(file);
968 if (err < 0 || /* error or sleep was interrupted */
969 err == 0) /* timeout? Shouldn't occur. */
971 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
973 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err);
975 if (!(buf2.flags & V4L2_BUF_FLAG_DONE)) /* not done */
978 err = drv(inode, file, VIDIOC_DQBUF, &buf2);
980 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err);
981 } while (err == 0 && buf2.index != *i);
985 case VIDIOCGVBIFMT: /* query VBI data capture format */
987 struct vbi_format *fmt = arg;
989 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
990 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
992 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
994 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
997 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1001 memset(fmt, 0, sizeof(*fmt));
1002 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1003 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1004 fmt->sample_format = VIDEO_PALETTE_RAW;
1005 fmt->start[0] = fmt2->fmt.vbi.start[0];
1006 fmt->count[0] = fmt2->fmt.vbi.count[0];
1007 fmt->start[1] = fmt2->fmt.vbi.start[1];
1008 fmt->count[1] = fmt2->fmt.vbi.count[1];
1009 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1014 struct vbi_format *fmt = arg;
1016 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1021 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
1023 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1024 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1025 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1026 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1027 fmt2->fmt.vbi.start[0] = fmt->start[0];
1028 fmt2->fmt.vbi.count[0] = fmt->count[0];
1029 fmt2->fmt.vbi.start[1] = fmt->start[1];
1030 fmt2->fmt.vbi.count[1] = fmt->count[1];
1031 fmt2->fmt.vbi.flags = fmt->flags;
1032 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1034 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1038 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1039 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1040 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1041 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1042 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1043 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1044 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1045 fmt2->fmt.vbi.flags != fmt->flags) {
1049 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1051 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1065 EXPORT_SYMBOL(v4l_compat_translate_ioctl);