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;
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...) \
52 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);
76 if (err == 0 && !(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)) {
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 static const 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)
160 switch (pixelformat) {
161 case V4L2_PIX_FMT_GREY:
162 palette = VIDEO_PALETTE_GREY;
164 case V4L2_PIX_FMT_RGB555:
165 palette = VIDEO_PALETTE_RGB555;
167 case V4L2_PIX_FMT_RGB565:
168 palette = VIDEO_PALETTE_RGB565;
170 case V4L2_PIX_FMT_BGR24:
171 palette = VIDEO_PALETTE_RGB24;
173 case V4L2_PIX_FMT_BGR32:
174 palette = VIDEO_PALETTE_RGB32;
176 /* yuv packed pixel */
177 case V4L2_PIX_FMT_YUYV:
178 palette = VIDEO_PALETTE_YUYV;
180 case V4L2_PIX_FMT_UYVY:
181 palette = VIDEO_PALETTE_UYVY;
184 case V4L2_PIX_FMT_YUV410:
185 palette = VIDEO_PALETTE_YUV420;
187 case V4L2_PIX_FMT_YUV420:
188 palette = VIDEO_PALETTE_YUV420;
190 case V4L2_PIX_FMT_YUV411P:
191 palette = VIDEO_PALETTE_YUV411P;
193 case V4L2_PIX_FMT_YUV422P:
194 palette = VIDEO_PALETTE_YUV422P;
200 /* ----------------------------------------------------------------- */
202 static int poll_one(struct file *file)
206 struct poll_wqueues pwq;
212 set_current_state(TASK_INTERRUPTIBLE);
213 mask = file->f_op->poll(file, table);
217 if (signal_pending(current)) {
218 retval = -ERESTARTSYS;
223 set_current_state(TASK_RUNNING);
228 static int count_inputs(struct inode *inode,
232 struct v4l2_input input2;
236 memset(&input2, 0, sizeof(input2));
238 if (0 != drv(inode, file, VIDIOC_ENUMINPUT, &input2))
244 static int check_size(struct inode *inode,
247 int *maxw, int *maxh)
249 struct v4l2_fmtdesc desc2;
250 struct v4l2_format fmt2;
252 memset(&desc2, 0, sizeof(desc2));
253 memset(&fmt2, 0, sizeof(fmt2));
255 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
256 if (0 != drv(inode, file, VIDIOC_ENUM_FMT, &desc2))
259 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
260 fmt2.fmt.pix.width = 10000;
261 fmt2.fmt.pix.height = 10000;
262 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
263 if (0 != drv(inode, file, VIDIOC_TRY_FMT, &fmt2))
266 *maxw = fmt2.fmt.pix.width;
267 *maxh = fmt2.fmt.pix.height;
273 /* ----------------------------------------------------------------- */
276 * This function is exported.
279 v4l_compat_translate_ioctl(struct inode *inode,
285 struct v4l2_capability *cap2 = NULL;
286 struct v4l2_format *fmt2 = NULL;
287 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
289 struct v4l2_framebuffer fbuf2;
290 struct v4l2_input input2;
291 struct v4l2_tuner tun2;
292 struct v4l2_standard std2;
293 struct v4l2_frequency freq2;
294 struct v4l2_audio aud2;
295 struct v4l2_queryctrl qctrl2;
296 struct v4l2_buffer buf2;
301 case VIDIOCGCAP: /* capability */
303 struct video_capability *cap = arg;
305 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
310 memset(cap, 0, sizeof(*cap));
311 memset(&fbuf2, 0, sizeof(fbuf2));
313 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
315 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
318 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
319 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
321 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
322 memset(&fbuf2, 0, sizeof(fbuf2));
327 memcpy(cap->name, cap2->card,
328 min(sizeof(cap->name), sizeof(cap2->card)));
329 cap->name[sizeof(cap->name) - 1] = 0;
330 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
331 cap->type |= VID_TYPE_CAPTURE;
332 if (cap2->capabilities & V4L2_CAP_TUNER)
333 cap->type |= VID_TYPE_TUNER;
334 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
335 cap->type |= VID_TYPE_TELETEXT;
336 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
337 cap->type |= VID_TYPE_OVERLAY;
338 if (fbuf2.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
339 cap->type |= VID_TYPE_CLIPPING;
341 cap->channels = count_inputs(inode, file, drv);
342 check_size(inode, file, drv,
343 &cap->maxwidth, &cap->maxheight);
344 cap->audios = 0; /* FIXME */
345 cap->minwidth = 48; /* FIXME */
346 cap->minheight = 32; /* FIXME */
349 case VIDIOCGFBUF: /* get frame buffer */
351 struct video_buffer *buffer = arg;
353 memset(buffer, 0, sizeof(*buffer));
354 memset(&fbuf2, 0, sizeof(fbuf2));
356 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
358 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
361 buffer->base = fbuf2.base;
362 buffer->height = fbuf2.fmt.height;
363 buffer->width = fbuf2.fmt.width;
365 switch (fbuf2.fmt.pixelformat) {
366 case V4L2_PIX_FMT_RGB332:
369 case V4L2_PIX_FMT_RGB555:
372 case V4L2_PIX_FMT_RGB565:
375 case V4L2_PIX_FMT_BGR24:
378 case V4L2_PIX_FMT_BGR32:
384 if (fbuf2.fmt.bytesperline) {
385 buffer->bytesperline = fbuf2.fmt.bytesperline;
386 if (!buffer->depth && buffer->width)
387 buffer->depth = ((fbuf2.fmt.bytesperline<<3)
391 buffer->bytesperline =
392 (buffer->width * buffer->depth + 7) & 7;
393 buffer->bytesperline >>= 3;
397 case VIDIOCSFBUF: /* set frame buffer */
399 struct video_buffer *buffer = arg;
401 memset(&fbuf2, 0, sizeof(fbuf2));
402 fbuf2.base = buffer->base;
403 fbuf2.fmt.height = buffer->height;
404 fbuf2.fmt.width = buffer->width;
405 switch (buffer->depth) {
407 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
410 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
413 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
416 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
419 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
422 fbuf2.fmt.bytesperline = buffer->bytesperline;
423 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
425 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
428 case VIDIOCGWIN: /* get window or capture dimensions */
430 struct video_window *win = arg;
432 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
437 memset(win, 0, sizeof(*win));
439 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
440 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
442 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
444 win->x = fmt2->fmt.win.w.left;
445 win->y = fmt2->fmt.win.w.top;
446 win->width = fmt2->fmt.win.w.width;
447 win->height = fmt2->fmt.win.w.height;
448 win->chromakey = fmt2->fmt.win.chromakey;
454 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
455 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
457 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
462 win->width = fmt2->fmt.pix.width;
463 win->height = fmt2->fmt.pix.height;
469 case VIDIOCSWIN: /* set window and/or capture dimensions */
471 struct video_window *win = arg;
474 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
479 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
480 drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
481 err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
483 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err);
485 fmt2->fmt.pix.width = win->width;
486 fmt2->fmt.pix.height = win->height;
487 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
488 fmt2->fmt.pix.bytesperline = 0;
489 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
491 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
493 win->width = fmt2->fmt.pix.width;
494 win->height = fmt2->fmt.pix.height;
497 memset(fmt2, 0, sizeof(*fmt2));
498 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
499 fmt2->fmt.win.w.left = win->x;
500 fmt2->fmt.win.w.top = win->y;
501 fmt2->fmt.win.w.width = win->width;
502 fmt2->fmt.win.w.height = win->height;
503 fmt2->fmt.win.chromakey = win->chromakey;
504 fmt2->fmt.win.clips = (void __user *)win->clips;
505 fmt2->fmt.win.clipcount = win->clipcount;
506 err2 = drv(inode, file, VIDIOC_S_FMT, fmt2);
508 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err);
510 if (err1 != 0 && err2 != 0)
514 case VIDIOCCAPTURE: /* turn on/off preview */
519 /* dirty hack time. But v4l1 has no STREAMOFF
520 * equivalent in the API, and this one at
521 * least comes close ... */
522 drv(inode, file, VIDIOC_STREAMOFF, &captype);
524 err = drv(inode, file, VIDIOC_OVERLAY, arg);
526 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
529 case VIDIOCGCHAN: /* get input information */
531 struct video_channel *chan = arg;
533 memset(&input2, 0, sizeof(input2));
534 input2.index = chan->channel;
535 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
537 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
538 "channel=%d err=%d\n", chan->channel, err);
541 chan->channel = input2.index;
542 memcpy(chan->name, input2.name,
543 min(sizeof(chan->name), sizeof(input2.name)));
544 chan->name[sizeof(chan->name) - 1] = 0;
545 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
546 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
547 switch (input2.type) {
548 case V4L2_INPUT_TYPE_TUNER:
549 chan->type = VIDEO_TYPE_TV;
552 case V4L2_INPUT_TYPE_CAMERA:
553 chan->type = VIDEO_TYPE_CAMERA;
557 err = drv(inode, file, VIDIOC_G_STD, &sid);
559 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
561 if (sid & V4L2_STD_PAL)
562 chan->norm = VIDEO_MODE_PAL;
563 if (sid & V4L2_STD_NTSC)
564 chan->norm = VIDEO_MODE_NTSC;
565 if (sid & V4L2_STD_SECAM)
566 chan->norm = VIDEO_MODE_SECAM;
570 case VIDIOCSCHAN: /* set input */
572 struct video_channel *chan = arg;
575 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
577 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
578 switch (chan->norm) {
582 case VIDEO_MODE_NTSC:
585 case VIDEO_MODE_SECAM:
586 sid = V4L2_STD_SECAM;
590 err = drv(inode, file, VIDIOC_S_STD, &sid);
592 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
596 case VIDIOCGPICT: /* get tone controls & partial capture format */
598 struct video_picture *pict = arg;
600 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
606 pict->brightness = get_v4l_control(inode, file,
607 V4L2_CID_BRIGHTNESS, drv);
608 pict->hue = get_v4l_control(inode, file,
610 pict->contrast = get_v4l_control(inode, file,
611 V4L2_CID_CONTRAST, drv);
612 pict->colour = get_v4l_control(inode, file,
613 V4L2_CID_SATURATION, drv);
614 pict->whiteness = get_v4l_control(inode, file,
615 V4L2_CID_WHITENESS, drv);
617 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
618 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
620 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
624 pict->depth = ((fmt2->fmt.pix.bytesperline << 3)
625 + (fmt2->fmt.pix.width - 1))
626 / fmt2->fmt.pix.width;
627 pict->palette = pixelformat_to_palette(
628 fmt2->fmt.pix.pixelformat);
631 case VIDIOCSPICT: /* set tone controls & partial capture format */
633 struct video_picture *pict = arg;
634 int mem_err = 0, ovl_err = 0;
636 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
641 memset(&fbuf2, 0, sizeof(fbuf2));
643 set_v4l_control(inode, file,
644 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
645 set_v4l_control(inode, file,
646 V4L2_CID_HUE, pict->hue, drv);
647 set_v4l_control(inode, file,
648 V4L2_CID_CONTRAST, pict->contrast, drv);
649 set_v4l_control(inode, file,
650 V4L2_CID_SATURATION, pict->colour, drv);
651 set_v4l_control(inode, file,
652 V4L2_CID_WHITENESS, pict->whiteness, drv);
654 * V4L1 uses this ioctl to set both memory capture and overlay
655 * pixel format, while V4L2 has two different ioctls for this.
656 * Some cards may not support one or the other, and may support
657 * different pixel formats for memory vs overlay.
660 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
661 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
662 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
663 support memory capture. Trying to set the memory capture
664 parameters would be pointless. */
666 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
667 mem_err = -1000; /* didn't even try */
668 } else if (fmt2->fmt.pix.pixelformat !=
669 palette_to_pixelformat(pict->palette)) {
670 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
672 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt2);
674 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
678 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
679 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
680 support overlay. Trying to set the overlay parameters
681 would be quite pointless. */
683 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
684 ovl_err = -1000; /* didn't even try */
685 } else if (fbuf2.fmt.pixelformat !=
686 palette_to_pixelformat(pict->palette)) {
687 fbuf2.fmt.pixelformat = palette_to_pixelformat(
689 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
691 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
694 if (ovl_err < 0 && mem_err < 0) {
695 /* ioctl failed, couldn't set either parameter */
696 if (mem_err != -1000)
698 else if (ovl_err == -EPERM)
706 case VIDIOCGTUNER: /* get tuner information */
708 struct video_tuner *tun = arg;
710 memset(&tun2, 0, sizeof(tun2));
711 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
713 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
716 memcpy(tun->name, tun2.name,
717 min(sizeof(tun->name), sizeof(tun2.name)));
718 tun->name[sizeof(tun->name) - 1] = 0;
719 tun->rangelow = tun2.rangelow;
720 tun->rangehigh = tun2.rangehigh;
722 tun->mode = VIDEO_MODE_AUTO;
724 for (i = 0; i < 64; i++) {
725 memset(&std2, 0, sizeof(std2));
727 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
729 if (std2.id & V4L2_STD_PAL)
730 tun->flags |= VIDEO_TUNER_PAL;
731 if (std2.id & V4L2_STD_NTSC)
732 tun->flags |= VIDEO_TUNER_NTSC;
733 if (std2.id & V4L2_STD_SECAM)
734 tun->flags |= VIDEO_TUNER_SECAM;
737 err = drv(inode, file, VIDIOC_G_STD, &sid);
739 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
741 if (sid & V4L2_STD_PAL)
742 tun->mode = VIDEO_MODE_PAL;
743 if (sid & V4L2_STD_NTSC)
744 tun->mode = VIDEO_MODE_NTSC;
745 if (sid & V4L2_STD_SECAM)
746 tun->mode = VIDEO_MODE_SECAM;
749 if (tun2.capability & V4L2_TUNER_CAP_LOW)
750 tun->flags |= VIDEO_TUNER_LOW;
751 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
752 tun->flags |= VIDEO_TUNER_STEREO_ON;
753 tun->signal = tun2.signal;
756 case VIDIOCSTUNER: /* select a tuner input */
758 struct video_tuner *tun = arg;
760 memset(&t, 0, sizeof(t));
762 t.index = tun->tuner;
764 err = drv(inode, file, VIDIOC_S_INPUT, &t);
766 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
770 case VIDIOCGFREQ: /* get frequency */
772 unsigned long *freq = arg;
773 memset(&freq2, 0, sizeof(freq2));
776 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
778 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
780 *freq = freq2.frequency;
783 case VIDIOCSFREQ: /* set frequency */
785 unsigned long *freq = arg;
786 memset(&freq2, 0, sizeof(freq2));
788 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
789 freq2.frequency = *freq;
790 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
792 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
795 case VIDIOCGAUDIO: /* get audio properties/controls */
797 struct video_audio *aud = arg;
798 memset(&aud2, 0, sizeof(aud2));
800 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
802 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err);
805 memcpy(aud->name, aud2.name,
806 min(sizeof(aud->name), sizeof(aud2.name)));
807 aud->name[sizeof(aud->name) - 1] = 0;
808 aud->audio = aud2.index;
810 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
813 aud->flags |= VIDEO_AUDIO_VOLUME;
815 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
818 aud->flags |= VIDEO_AUDIO_BASS;
820 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
823 aud->flags |= VIDEO_AUDIO_TREBLE;
825 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
828 aud->flags |= VIDEO_AUDIO_BALANCE;
830 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
833 aud->flags |= VIDEO_AUDIO_MUTE;
834 aud->flags |= VIDEO_AUDIO_MUTABLE;
837 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
838 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
839 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
840 aud->step = qctrl2.step;
843 memset(&tun2, 0, sizeof(tun2));
844 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
846 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err);
851 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
852 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
853 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
854 aud->mode = VIDEO_SOUND_STEREO;
855 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
856 aud->mode = VIDEO_SOUND_MONO;
859 case VIDIOCSAUDIO: /* set audio controls */
861 struct video_audio *aud = arg;
863 memset(&aud2, 0, sizeof(aud2));
864 memset(&tun2, 0, sizeof(tun2));
866 aud2.index = aud->audio;
867 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
869 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err);
873 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
875 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
877 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
879 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
881 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
882 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
884 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
886 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err);
890 case VIDEO_SOUND_MONO:
891 case VIDEO_SOUND_LANG1:
892 tun2.audmode = V4L2_TUNER_MODE_MONO;
894 case VIDEO_SOUND_STEREO:
895 tun2.audmode = V4L2_TUNER_MODE_STEREO;
897 case VIDEO_SOUND_LANG2:
898 tun2.audmode = V4L2_TUNER_MODE_LANG2;
901 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
903 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err);
908 case VIDIOCMCAPTURE: /* capture a frame */
910 struct video_mmap *mm = arg;
912 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
917 memset(&buf2, 0, sizeof(buf2));
919 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
920 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
922 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err);
925 if (mm->width != fmt2->fmt.pix.width ||
926 mm->height != fmt2->fmt.pix.height ||
927 palette_to_pixelformat(mm->format) !=
928 fmt2->fmt.pix.pixelformat) {
929 /* New capture format... */
930 fmt2->fmt.pix.width = mm->width;
931 fmt2->fmt.pix.height = mm->height;
932 fmt2->fmt.pix.pixelformat =
933 palette_to_pixelformat(mm->format);
934 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
935 fmt2->fmt.pix.bytesperline = 0;
936 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
938 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err);
942 buf2.index = mm->frame;
943 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
944 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
946 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err);
949 err = drv(inode, file, VIDIOC_QBUF, &buf2);
951 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
954 err = drv(inode, file, VIDIOC_STREAMON, &captype);
956 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
959 case VIDIOCSYNC: /* wait for a frame */
963 memset(&buf2, 0, sizeof(buf2));
965 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
966 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
969 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
972 if (!(buf2.flags & V4L2_BUF_FLAG_MAPPED)) {
973 /* Buffer is not mapped */
978 /* make sure capture actually runs so we don't block forever */
979 err = drv(inode, file, VIDIOC_STREAMON, &captype);
981 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err);
985 /* Loop as long as the buffer is queued, but not done */
987 (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
988 == V4L2_BUF_FLAG_QUEUED) {
989 err = poll_one(file);
990 if (err < 0 || /* error or sleep was interrupted */
991 err == 0) /* timeout? Shouldn't occur. */
993 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
995 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
997 if (!(buf2.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1000 err = drv(inode, file, VIDIOC_DQBUF, &buf2);
1002 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err);
1003 } while (err == 0 && buf2.index != *i);
1007 case VIDIOCGVBIFMT: /* query VBI data capture format */
1009 struct vbi_format *fmt = arg;
1011 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1016 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1018 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
1020 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
1023 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1027 memset(fmt, 0, sizeof(*fmt));
1028 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1029 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1030 fmt->sample_format = VIDEO_PALETTE_RAW;
1031 fmt->start[0] = fmt2->fmt.vbi.start[0];
1032 fmt->count[0] = fmt2->fmt.vbi.count[0];
1033 fmt->start[1] = fmt2->fmt.vbi.start[1];
1034 fmt->count[1] = fmt2->fmt.vbi.count[1];
1035 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1040 struct vbi_format *fmt = arg;
1042 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1047 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1052 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1053 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1054 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1055 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1056 fmt2->fmt.vbi.start[0] = fmt->start[0];
1057 fmt2->fmt.vbi.count[0] = fmt->count[0];
1058 fmt2->fmt.vbi.start[1] = fmt->start[1];
1059 fmt2->fmt.vbi.count[1] = fmt->count[1];
1060 fmt2->fmt.vbi.flags = fmt->flags;
1061 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1063 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1067 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1068 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1069 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1070 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1071 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1072 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1073 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1074 fmt2->fmt.vbi.flags != fmt->flags) {
1078 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1080 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1093 EXPORT_SYMBOL(v4l_compat_translate_ioctl);