Merge branch 'linus' into x86/cleanups
[linux-2.6] / drivers / media / video / v4l1-compat.c
1 /*
2  *
3  *      Video for Linux Two
4  *      Backward Compatibility Layer
5  *
6  *      Support subroutines for providing V4L2 drivers with backward
7  *      compatibility with applications using the old API.
8  *
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.
13  *
14  * Author:      Bill Dirks <bill@thedirks.org>
15  *              et al.
16  *
17  */
18
19
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>
25 #include <linux/mm.h>
26 #include <linux/fs.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>
33 #include <media/v4l2-ioctl.h>
34
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
37 #include <asm/pgtable.h>
38
39 #ifdef CONFIG_KMOD
40 #include <linux/kmod.h>
41 #endif
42
43 static unsigned int debug;
44 module_param(debug, int, 0644);
45 MODULE_PARM_DESC(debug, "enable debug messages");
46 MODULE_AUTHOR("Bill Dirks");
47 MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
48 MODULE_LICENSE("GPL");
49
50 #define dprintk(fmt, arg...) \
51         do { \
52                 if (debug) \
53                         printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\
54         } while (0)
55
56 /*
57  *      I O C T L   T R A N S L A T I O N
58  *
59  *      From here on down is the code for translating the numerous
60  *      ioctl commands from the old API to the new API.
61  */
62
63 static int
64 get_v4l_control(struct inode            *inode,
65                 struct file             *file,
66                 int                     cid,
67                 v4l2_kioctl             drv)
68 {
69         struct v4l2_queryctrl   qctrl2;
70         struct v4l2_control     ctrl2;
71         int                     err;
72
73         qctrl2.id = cid;
74         err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
75         if (err < 0)
76                 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
77         if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
78                 ctrl2.id = qctrl2.id;
79                 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2);
80                 if (err < 0) {
81                         dprintk("VIDIOC_G_CTRL: %d\n", err);
82                         return 0;
83                 }
84                 return ((ctrl2.value - qctrl2.minimum) * 65535
85                          + (qctrl2.maximum - qctrl2.minimum) / 2)
86                         / (qctrl2.maximum - qctrl2.minimum);
87         }
88         return 0;
89 }
90
91 static int
92 set_v4l_control(struct inode            *inode,
93                 struct file             *file,
94                 int                     cid,
95                 int                     value,
96                 v4l2_kioctl             drv)
97 {
98         struct v4l2_queryctrl   qctrl2;
99         struct v4l2_control     ctrl2;
100         int                     err;
101
102         qctrl2.id = cid;
103         err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
104         if (err < 0)
105                 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
106         if (err == 0 &&
107             !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
108             !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
109                 if (value < 0)
110                         value = 0;
111                 if (value > 65535)
112                         value = 65535;
113                 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
114                         value = 65535;
115                 ctrl2.id = qctrl2.id;
116                 ctrl2.value =
117                         (value * (qctrl2.maximum - qctrl2.minimum)
118                          + 32767)
119                         / 65535;
120                 ctrl2.value += qctrl2.minimum;
121                 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
122                 if (err < 0)
123                         dprintk("VIDIOC_S_CTRL: %d\n", err);
124         }
125         return 0;
126 }
127
128 /* ----------------------------------------------------------------- */
129
130 static const unsigned int palette2pixelformat[] = {
131         [VIDEO_PALETTE_GREY]    = V4L2_PIX_FMT_GREY,
132         [VIDEO_PALETTE_RGB555]  = V4L2_PIX_FMT_RGB555,
133         [VIDEO_PALETTE_RGB565]  = V4L2_PIX_FMT_RGB565,
134         [VIDEO_PALETTE_RGB24]   = V4L2_PIX_FMT_BGR24,
135         [VIDEO_PALETTE_RGB32]   = V4L2_PIX_FMT_BGR32,
136         /* yuv packed pixel */
137         [VIDEO_PALETTE_YUYV]    = V4L2_PIX_FMT_YUYV,
138         [VIDEO_PALETTE_YUV422]  = V4L2_PIX_FMT_YUYV,
139         [VIDEO_PALETTE_UYVY]    = V4L2_PIX_FMT_UYVY,
140         /* yuv planar */
141         [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
142         [VIDEO_PALETTE_YUV420]  = V4L2_PIX_FMT_YUV420,
143         [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
144         [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
145         [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
146 };
147
148 static unsigned int __pure
149 palette_to_pixelformat(unsigned int palette)
150 {
151         if (palette < ARRAY_SIZE(palette2pixelformat))
152                 return palette2pixelformat[palette];
153         else
154                 return 0;
155 }
156
157 static unsigned int __attribute_const__
158 pixelformat_to_palette(unsigned int pixelformat)
159 {
160         int     palette = 0;
161         switch (pixelformat) {
162         case V4L2_PIX_FMT_GREY:
163                 palette = VIDEO_PALETTE_GREY;
164                 break;
165         case V4L2_PIX_FMT_RGB555:
166                 palette = VIDEO_PALETTE_RGB555;
167                 break;
168         case V4L2_PIX_FMT_RGB565:
169                 palette = VIDEO_PALETTE_RGB565;
170                 break;
171         case V4L2_PIX_FMT_BGR24:
172                 palette = VIDEO_PALETTE_RGB24;
173                 break;
174         case V4L2_PIX_FMT_BGR32:
175                 palette = VIDEO_PALETTE_RGB32;
176                 break;
177         /* yuv packed pixel */
178         case V4L2_PIX_FMT_YUYV:
179                 palette = VIDEO_PALETTE_YUYV;
180                 break;
181         case V4L2_PIX_FMT_UYVY:
182                 palette = VIDEO_PALETTE_UYVY;
183                 break;
184         /* yuv planar */
185         case V4L2_PIX_FMT_YUV410:
186                 palette = VIDEO_PALETTE_YUV420;
187                 break;
188         case V4L2_PIX_FMT_YUV420:
189                 palette = VIDEO_PALETTE_YUV420;
190                 break;
191         case V4L2_PIX_FMT_YUV411P:
192                 palette = VIDEO_PALETTE_YUV411P;
193                 break;
194         case V4L2_PIX_FMT_YUV422P:
195                 palette = VIDEO_PALETTE_YUV422P;
196                 break;
197         }
198         return palette;
199 }
200
201 /* ----------------------------------------------------------------- */
202
203 static int poll_one(struct file *file, struct poll_wqueues *pwq)
204 {
205         int retval = 1;
206         poll_table *table;
207
208         poll_initwait(pwq);
209         table = &pwq->pt;
210         for (;;) {
211                 int mask;
212                 set_current_state(TASK_INTERRUPTIBLE);
213                 mask = file->f_op->poll(file, table);
214                 if (mask & POLLIN)
215                         break;
216                 table = NULL;
217                 if (signal_pending(current)) {
218                         retval = -ERESTARTSYS;
219                         break;
220                 }
221                 schedule();
222         }
223         set_current_state(TASK_RUNNING);
224         poll_freewait(pwq);
225         return retval;
226 }
227
228 static int count_inputs(
229                         struct inode *inode,
230                         struct file *file,
231                         v4l2_kioctl drv)
232 {
233         struct v4l2_input input2;
234         int i;
235
236         for (i = 0;; i++) {
237                 memset(&input2, 0, sizeof(input2));
238                 input2.index = i;
239                 if (0 != drv(inode, file, VIDIOC_ENUMINPUT, &input2))
240                         break;
241         }
242         return i;
243 }
244
245 static int check_size(
246                 struct inode *inode,
247                 struct file *file,
248                 v4l2_kioctl drv,
249                 int *maxw,
250                 int *maxh)
251 {
252         struct v4l2_fmtdesc desc2;
253         struct v4l2_format  fmt2;
254
255         memset(&desc2, 0, sizeof(desc2));
256         memset(&fmt2, 0, sizeof(fmt2));
257
258         desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
259         if (0 != drv(inode, file, VIDIOC_ENUM_FMT, &desc2))
260                 goto done;
261
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))
267                 goto done;
268
269         *maxw = fmt2.fmt.pix.width;
270         *maxh = fmt2.fmt.pix.height;
271
272 done:
273         return 0;
274 }
275
276 /* ----------------------------------------------------------------- */
277
278 static noinline int v4l1_compat_get_capabilities(
279                                         struct video_capability *cap,
280                                         struct inode *inode,
281                                         struct file *file,
282                                         v4l2_kioctl drv)
283 {
284         int err;
285         struct v4l2_framebuffer fbuf;
286         struct v4l2_capability *cap2;
287
288         cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
289         if (!cap2) {
290                 err = -ENOMEM;
291                 return err;
292         }
293         memset(cap, 0, sizeof(*cap));
294         memset(&fbuf, 0, sizeof(fbuf));
295
296         err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
297         if (err < 0) {
298                 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
299                 goto done;
300         }
301         if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
302                 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
303                 if (err < 0) {
304                         dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
305                         memset(&fbuf, 0, sizeof(fbuf));
306                 }
307                 err = 0;
308         }
309
310         memcpy(cap->name, cap2->card,
311                min(sizeof(cap->name), sizeof(cap2->card)));
312         cap->name[sizeof(cap->name) - 1] = 0;
313         if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
314                 cap->type |= VID_TYPE_CAPTURE;
315         if (cap2->capabilities & V4L2_CAP_TUNER)
316                 cap->type |= VID_TYPE_TUNER;
317         if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
318                 cap->type |= VID_TYPE_TELETEXT;
319         if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
320                 cap->type |= VID_TYPE_OVERLAY;
321         if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
322                 cap->type |= VID_TYPE_CLIPPING;
323
324         cap->channels  = count_inputs(inode, file, drv);
325         check_size(inode, file, drv,
326                    &cap->maxwidth, &cap->maxheight);
327         cap->audios    =  0; /* FIXME */
328         cap->minwidth  = 48; /* FIXME */
329         cap->minheight = 32; /* FIXME */
330
331 done:
332         kfree(cap2);
333         return err;
334 }
335
336 static noinline int v4l1_compat_get_frame_buffer(
337                                         struct video_buffer *buffer,
338                                         struct inode *inode,
339                                         struct file *file,
340                                         v4l2_kioctl drv)
341 {
342         int err;
343         struct v4l2_framebuffer fbuf;
344
345         memset(buffer, 0, sizeof(*buffer));
346         memset(&fbuf, 0, sizeof(fbuf));
347
348         err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
349         if (err < 0) {
350                 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
351                 goto done;
352         }
353         buffer->base   = fbuf.base;
354         buffer->height = fbuf.fmt.height;
355         buffer->width  = fbuf.fmt.width;
356
357         switch (fbuf.fmt.pixelformat) {
358         case V4L2_PIX_FMT_RGB332:
359                 buffer->depth = 8;
360                 break;
361         case V4L2_PIX_FMT_RGB555:
362                 buffer->depth = 15;
363                 break;
364         case V4L2_PIX_FMT_RGB565:
365                 buffer->depth = 16;
366                 break;
367         case V4L2_PIX_FMT_BGR24:
368                 buffer->depth = 24;
369                 break;
370         case V4L2_PIX_FMT_BGR32:
371                 buffer->depth = 32;
372                 break;
373         default:
374                 buffer->depth = 0;
375         }
376         if (fbuf.fmt.bytesperline) {
377                 buffer->bytesperline = fbuf.fmt.bytesperline;
378                 if (!buffer->depth && buffer->width)
379                         buffer->depth   = ((fbuf.fmt.bytesperline<<3)
380                                           + (buffer->width-1))
381                                           / buffer->width;
382         } else {
383                 buffer->bytesperline =
384                         (buffer->width * buffer->depth + 7) & 7;
385                 buffer->bytesperline >>= 3;
386         }
387 done:
388         return err;
389 }
390
391 static noinline int v4l1_compat_set_frame_buffer(
392                                         struct video_buffer *buffer,
393                                         struct inode *inode,
394                                         struct file *file,
395                                         v4l2_kioctl drv)
396 {
397         int err;
398         struct v4l2_framebuffer fbuf;
399
400         memset(&fbuf, 0, sizeof(fbuf));
401         fbuf.base       = buffer->base;
402         fbuf.fmt.height = buffer->height;
403         fbuf.fmt.width  = buffer->width;
404         switch (buffer->depth) {
405         case 8:
406                 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
407                 break;
408         case 15:
409                 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
410                 break;
411         case 16:
412                 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
413                 break;
414         case 24:
415                 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
416                 break;
417         case 32:
418                 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
419                 break;
420         }
421         fbuf.fmt.bytesperline = buffer->bytesperline;
422         err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
423         if (err < 0)
424                 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
425         return err;
426 }
427
428 static noinline int v4l1_compat_get_win_cap_dimensions(
429                                         struct video_window *win,
430                                         struct inode *inode,
431                                         struct file *file,
432                                         v4l2_kioctl drv)
433 {
434         int err;
435         struct v4l2_format *fmt;
436
437         fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
438         if (!fmt) {
439                 err = -ENOMEM;
440                 return err;
441         }
442         memset(win, 0, sizeof(*win));
443
444         fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
445         err = drv(inode, file, VIDIOC_G_FMT, fmt);
446         if (err < 0)
447                 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
448         if (err == 0) {
449                 win->x         = fmt->fmt.win.w.left;
450                 win->y         = fmt->fmt.win.w.top;
451                 win->width     = fmt->fmt.win.w.width;
452                 win->height    = fmt->fmt.win.w.height;
453                 win->chromakey = fmt->fmt.win.chromakey;
454                 win->clips     = NULL;
455                 win->clipcount = 0;
456                 goto done;
457         }
458
459         fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
460         err = drv(inode, file, VIDIOC_G_FMT, fmt);
461         if (err < 0) {
462                 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
463                 goto done;
464         }
465         win->x         = 0;
466         win->y         = 0;
467         win->width     = fmt->fmt.pix.width;
468         win->height    = fmt->fmt.pix.height;
469         win->chromakey = 0;
470         win->clips     = NULL;
471         win->clipcount = 0;
472 done:
473         kfree(fmt);
474         return err;
475 }
476
477 static noinline int v4l1_compat_set_win_cap_dimensions(
478                                         struct video_window *win,
479                                         struct inode *inode,
480                                         struct file *file,
481                                         v4l2_kioctl drv)
482 {
483         int err, err1, err2;
484         struct v4l2_format *fmt;
485
486         fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
487         if (!fmt) {
488                 err = -ENOMEM;
489                 return err;
490         }
491         fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
492         drv(inode, file, VIDIOC_STREAMOFF, &fmt->type);
493         err1 = drv(inode, file, VIDIOC_G_FMT, fmt);
494         if (err1 < 0)
495                 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1);
496         if (err1 == 0) {
497                 fmt->fmt.pix.width  = win->width;
498                 fmt->fmt.pix.height = win->height;
499                 fmt->fmt.pix.field  = V4L2_FIELD_ANY;
500                 fmt->fmt.pix.bytesperline = 0;
501                 err = drv(inode, file, VIDIOC_S_FMT, fmt);
502                 if (err < 0)
503                         dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
504                                 err);
505                 win->width  = fmt->fmt.pix.width;
506                 win->height = fmt->fmt.pix.height;
507         }
508
509         memset(fmt, 0, sizeof(*fmt));
510         fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
511         fmt->fmt.win.w.left    = win->x;
512         fmt->fmt.win.w.top     = win->y;
513         fmt->fmt.win.w.width   = win->width;
514         fmt->fmt.win.w.height  = win->height;
515         fmt->fmt.win.chromakey = win->chromakey;
516         fmt->fmt.win.clips     = (void __user *)win->clips;
517         fmt->fmt.win.clipcount = win->clipcount;
518         err2 = drv(inode, file, VIDIOC_S_FMT, fmt);
519         if (err2 < 0)
520                 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2);
521
522         if (err1 != 0 && err2 != 0)
523                 err = err1;
524         else
525                 err = 0;
526         kfree(fmt);
527         return err;
528 }
529
530 static noinline int v4l1_compat_turn_preview_on_off(
531                                         int *on,
532                                         struct inode *inode,
533                                         struct file *file,
534                                         v4l2_kioctl drv)
535 {
536         int err;
537         enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
538
539         if (0 == *on) {
540                 /* dirty hack time.  But v4l1 has no STREAMOFF
541                  * equivalent in the API, and this one at
542                  * least comes close ... */
543                 drv(inode, file, VIDIOC_STREAMOFF, &captype);
544         }
545         err = drv(inode, file, VIDIOC_OVERLAY, on);
546         if (err < 0)
547                 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
548         return err;
549 }
550
551 static noinline int v4l1_compat_get_input_info(
552                                         struct video_channel *chan,
553                                         struct inode *inode,
554                                         struct file *file,
555                                         v4l2_kioctl drv)
556 {
557         int err;
558         struct v4l2_input       input2;
559         v4l2_std_id             sid;
560
561         memset(&input2, 0, sizeof(input2));
562         input2.index = chan->channel;
563         err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
564         if (err < 0) {
565                 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
566                         "channel=%d err=%d\n", chan->channel, err);
567                 goto done;
568         }
569         chan->channel = input2.index;
570         memcpy(chan->name, input2.name,
571                min(sizeof(chan->name), sizeof(input2.name)));
572         chan->name[sizeof(chan->name) - 1] = 0;
573         chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
574         chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
575         switch (input2.type) {
576         case V4L2_INPUT_TYPE_TUNER:
577                 chan->type = VIDEO_TYPE_TV;
578                 break;
579         default:
580         case V4L2_INPUT_TYPE_CAMERA:
581                 chan->type = VIDEO_TYPE_CAMERA;
582                 break;
583         }
584         chan->norm = 0;
585         err = drv(inode, file, VIDIOC_G_STD, &sid);
586         if (err < 0)
587                 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
588         if (err == 0) {
589                 if (sid & V4L2_STD_PAL)
590                         chan->norm = VIDEO_MODE_PAL;
591                 if (sid & V4L2_STD_NTSC)
592                         chan->norm = VIDEO_MODE_NTSC;
593                 if (sid & V4L2_STD_SECAM)
594                         chan->norm = VIDEO_MODE_SECAM;
595         }
596 done:
597         return err;
598 }
599
600 static noinline int v4l1_compat_set_input(
601                                         struct video_channel *chan,
602                                         struct inode *inode,
603                                         struct file *file,
604                                         v4l2_kioctl drv)
605 {
606         int err;
607         v4l2_std_id sid = 0;
608
609         err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
610         if (err < 0)
611                 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
612         switch (chan->norm) {
613         case VIDEO_MODE_PAL:
614                 sid = V4L2_STD_PAL;
615                 break;
616         case VIDEO_MODE_NTSC:
617                 sid = V4L2_STD_NTSC;
618                 break;
619         case VIDEO_MODE_SECAM:
620                 sid = V4L2_STD_SECAM;
621                 break;
622         }
623         if (0 != sid) {
624                 err = drv(inode, file, VIDIOC_S_STD, &sid);
625                 if (err < 0)
626                         dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
627         }
628         return err;
629 }
630
631 static noinline int v4l1_compat_get_picture(
632                                         struct video_picture *pict,
633                                         struct inode *inode,
634                                         struct file *file,
635                                         v4l2_kioctl drv)
636 {
637         int err;
638         struct v4l2_format *fmt;
639
640         fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
641         if (!fmt) {
642                 err = -ENOMEM;
643                 return err;
644         }
645
646         pict->brightness = get_v4l_control(inode, file,
647                                            V4L2_CID_BRIGHTNESS, drv);
648         pict->hue = get_v4l_control(inode, file,
649                                     V4L2_CID_HUE, drv);
650         pict->contrast = get_v4l_control(inode, file,
651                                          V4L2_CID_CONTRAST, drv);
652         pict->colour = get_v4l_control(inode, file,
653                                        V4L2_CID_SATURATION, drv);
654         pict->whiteness = get_v4l_control(inode, file,
655                                           V4L2_CID_WHITENESS, drv);
656
657         fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
658         err = drv(inode, file, VIDIOC_G_FMT, fmt);
659         if (err < 0) {
660                 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
661                 goto done;
662         }
663
664         pict->depth   = ((fmt->fmt.pix.bytesperline << 3)
665                          + (fmt->fmt.pix.width - 1))
666                          / fmt->fmt.pix.width;
667         pict->palette = pixelformat_to_palette(
668                 fmt->fmt.pix.pixelformat);
669 done:
670         kfree(fmt);
671         return err;
672 }
673
674 static noinline int v4l1_compat_set_picture(
675                                         struct video_picture *pict,
676                                         struct inode *inode,
677                                         struct file *file,
678                                         v4l2_kioctl drv)
679 {
680         int err;
681         struct v4l2_framebuffer fbuf;
682         int mem_err = 0, ovl_err = 0;
683         struct v4l2_format *fmt;
684
685         fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
686         if (!fmt) {
687                 err = -ENOMEM;
688                 return err;
689         }
690         memset(&fbuf, 0, sizeof(fbuf));
691
692         set_v4l_control(inode, file,
693                         V4L2_CID_BRIGHTNESS, pict->brightness, drv);
694         set_v4l_control(inode, file,
695                         V4L2_CID_HUE, pict->hue, drv);
696         set_v4l_control(inode, file,
697                         V4L2_CID_CONTRAST, pict->contrast, drv);
698         set_v4l_control(inode, file,
699                         V4L2_CID_SATURATION, pict->colour, drv);
700         set_v4l_control(inode, file,
701                         V4L2_CID_WHITENESS, pict->whiteness, drv);
702         /*
703          * V4L1 uses this ioctl to set both memory capture and overlay
704          * pixel format, while V4L2 has two different ioctls for this.
705          * Some cards may not support one or the other, and may support
706          * different pixel formats for memory vs overlay.
707          */
708
709         fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
710         err = drv(inode, file, VIDIOC_G_FMT, fmt);
711         /* If VIDIOC_G_FMT failed, then the driver likely doesn't
712            support memory capture.  Trying to set the memory capture
713            parameters would be pointless.  */
714         if (err < 0) {
715                 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
716                 mem_err = -1000;  /* didn't even try */
717         } else if (fmt->fmt.pix.pixelformat !=
718                  palette_to_pixelformat(pict->palette)) {
719                 fmt->fmt.pix.pixelformat = palette_to_pixelformat(
720                         pict->palette);
721                 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt);
722                 if (mem_err < 0)
723                         dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
724                                 mem_err);
725         }
726
727         err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
728         /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
729            support overlay.  Trying to set the overlay parameters
730            would be quite pointless.  */
731         if (err < 0) {
732                 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
733                 ovl_err = -1000;  /* didn't even try */
734         } else if (fbuf.fmt.pixelformat !=
735                  palette_to_pixelformat(pict->palette)) {
736                 fbuf.fmt.pixelformat = palette_to_pixelformat(
737                         pict->palette);
738                 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
739                 if (ovl_err < 0)
740                         dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
741                                 ovl_err);
742         }
743         if (ovl_err < 0 && mem_err < 0) {
744                 /* ioctl failed, couldn't set either parameter */
745                 if (mem_err != -1000)
746                         err = mem_err;
747                 else if (ovl_err == -EPERM)
748                         err = 0;
749                 else
750                         err = ovl_err;
751         } else
752                 err = 0;
753         kfree(fmt);
754         return err;
755 }
756
757 static noinline int v4l1_compat_get_tuner(
758                                         struct video_tuner *tun,
759                                         struct inode *inode,
760                                         struct file *file,
761                                         v4l2_kioctl drv)
762 {
763         int err, i;
764         struct v4l2_tuner       tun2;
765         struct v4l2_standard    std2;
766         v4l2_std_id             sid;
767
768         memset(&tun2, 0, sizeof(tun2));
769         err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
770         if (err < 0) {
771                 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
772                 goto done;
773         }
774         memcpy(tun->name, tun2.name,
775                min(sizeof(tun->name), sizeof(tun2.name)));
776         tun->name[sizeof(tun->name) - 1] = 0;
777         tun->rangelow = tun2.rangelow;
778         tun->rangehigh = tun2.rangehigh;
779         tun->flags = 0;
780         tun->mode = VIDEO_MODE_AUTO;
781
782         for (i = 0; i < 64; i++) {
783                 memset(&std2, 0, sizeof(std2));
784                 std2.index = i;
785                 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
786                         break;
787                 if (std2.id & V4L2_STD_PAL)
788                         tun->flags |= VIDEO_TUNER_PAL;
789                 if (std2.id & V4L2_STD_NTSC)
790                         tun->flags |= VIDEO_TUNER_NTSC;
791                 if (std2.id & V4L2_STD_SECAM)
792                         tun->flags |= VIDEO_TUNER_SECAM;
793         }
794
795         err = drv(inode, file, VIDIOC_G_STD, &sid);
796         if (err < 0)
797                 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
798         if (err == 0) {
799                 if (sid & V4L2_STD_PAL)
800                         tun->mode = VIDEO_MODE_PAL;
801                 if (sid & V4L2_STD_NTSC)
802                         tun->mode = VIDEO_MODE_NTSC;
803                 if (sid & V4L2_STD_SECAM)
804                         tun->mode = VIDEO_MODE_SECAM;
805         }
806
807         if (tun2.capability & V4L2_TUNER_CAP_LOW)
808                 tun->flags |= VIDEO_TUNER_LOW;
809         if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
810                 tun->flags |= VIDEO_TUNER_STEREO_ON;
811         tun->signal = tun2.signal;
812 done:
813         return err;
814 }
815
816 static noinline int v4l1_compat_select_tuner(
817                                         struct video_tuner *tun,
818                                         struct inode *inode,
819                                         struct file *file,
820                                         v4l2_kioctl drv)
821 {
822         int err;
823         struct v4l2_tuner       t;/*84 bytes on x86_64*/
824         memset(&t, 0, sizeof(t));
825
826         t.index = tun->tuner;
827
828         err = drv(inode, file, VIDIOC_S_INPUT, &t);
829         if (err < 0)
830                 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
831         return err;
832 }
833
834 static noinline int v4l1_compat_get_frequency(
835                                         unsigned long *freq,
836                                         struct inode *inode,
837                                         struct file *file,
838                                         v4l2_kioctl drv)
839 {
840         int err;
841         struct v4l2_frequency   freq2;
842         memset(&freq2, 0, sizeof(freq2));
843
844         freq2.tuner = 0;
845         err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
846         if (err < 0)
847                 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
848         if (0 == err)
849                 *freq = freq2.frequency;
850         return err;
851 }
852
853 static noinline int v4l1_compat_set_frequency(
854                                         unsigned long *freq,
855                                         struct inode *inode,
856                                         struct file *file,
857                                         v4l2_kioctl drv)
858 {
859         int err;
860         struct v4l2_frequency   freq2;
861         memset(&freq2, 0, sizeof(freq2));
862
863         drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
864         freq2.frequency = *freq;
865         err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
866         if (err < 0)
867                 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
868         return err;
869 }
870
871 static noinline int v4l1_compat_get_audio(
872                                         struct video_audio *aud,
873                                         struct inode *inode,
874                                         struct file *file,
875                                         v4l2_kioctl drv)
876 {
877         int err, i;
878         struct v4l2_queryctrl   qctrl2;
879         struct v4l2_audio       aud2;
880         struct v4l2_tuner       tun2;
881         memset(&aud2, 0, sizeof(aud2));
882
883         err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
884         if (err < 0) {
885                 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err);
886                 goto done;
887         }
888         memcpy(aud->name, aud2.name,
889                min(sizeof(aud->name), sizeof(aud2.name)));
890         aud->name[sizeof(aud->name) - 1] = 0;
891         aud->audio = aud2.index;
892         aud->flags = 0;
893         i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
894         if (i >= 0) {
895                 aud->volume = i;
896                 aud->flags |= VIDEO_AUDIO_VOLUME;
897         }
898         i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
899         if (i >= 0) {
900                 aud->bass = i;
901                 aud->flags |= VIDEO_AUDIO_BASS;
902         }
903         i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
904         if (i >= 0) {
905                 aud->treble = i;
906                 aud->flags |= VIDEO_AUDIO_TREBLE;
907         }
908         i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
909         if (i >= 0) {
910                 aud->balance = i;
911                 aud->flags |= VIDEO_AUDIO_BALANCE;
912         }
913         i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
914         if (i >= 0) {
915                 if (i)
916                         aud->flags |= VIDEO_AUDIO_MUTE;
917                 aud->flags |= VIDEO_AUDIO_MUTABLE;
918         }
919         aud->step = 1;
920         qctrl2.id = V4L2_CID_AUDIO_VOLUME;
921         if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
922             !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
923                 aud->step = qctrl2.step;
924         aud->mode = 0;
925
926         memset(&tun2, 0, sizeof(tun2));
927         err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
928         if (err < 0) {
929                 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err);
930                 err = 0;
931                 goto done;
932         }
933
934         if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
935                 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
936         else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
937                 aud->mode = VIDEO_SOUND_STEREO;
938         else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
939                 aud->mode = VIDEO_SOUND_MONO;
940 done:
941         return err;
942 }
943
944 static noinline int v4l1_compat_set_audio(
945                                         struct video_audio *aud,
946                                         struct inode *inode,
947                                         struct file *file,
948                                         v4l2_kioctl drv)
949 {
950         int err;
951         struct v4l2_audio       aud2;
952         struct v4l2_tuner       tun2;
953
954         memset(&aud2, 0, sizeof(aud2));
955         memset(&tun2, 0, sizeof(tun2));
956
957         aud2.index = aud->audio;
958         err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
959         if (err < 0) {
960                 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err);
961                 goto done;
962         }
963
964         set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
965                         aud->volume, drv);
966         set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
967                         aud->bass, drv);
968         set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
969                         aud->treble, drv);
970         set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
971                         aud->balance, drv);
972         set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
973                         !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
974
975         err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
976         if (err < 0)
977                 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err);
978         if (err == 0) {
979                 switch (aud->mode) {
980                 default:
981                 case VIDEO_SOUND_MONO:
982                 case VIDEO_SOUND_LANG1:
983                         tun2.audmode = V4L2_TUNER_MODE_MONO;
984                         break;
985                 case VIDEO_SOUND_STEREO:
986                         tun2.audmode = V4L2_TUNER_MODE_STEREO;
987                         break;
988                 case VIDEO_SOUND_LANG2:
989                         tun2.audmode = V4L2_TUNER_MODE_LANG2;
990                         break;
991                 }
992                 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
993                 if (err < 0)
994                         dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err);
995         }
996         err = 0;
997 done:
998         return err;
999 }
1000
1001 static noinline int v4l1_compat_capture_frame(
1002                                         struct video_mmap *mm,
1003                                         struct inode *inode,
1004                                         struct file *file,
1005                                         v4l2_kioctl drv)
1006 {
1007         int err;
1008         enum v4l2_buf_type      captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1009         struct v4l2_buffer      buf;
1010         struct v4l2_format      *fmt;
1011
1012         fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
1013         if (!fmt) {
1014                 err = -ENOMEM;
1015                 return err;
1016         }
1017         memset(&buf, 0, sizeof(buf));
1018
1019         fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1020         err = drv(inode, file, VIDIOC_G_FMT, fmt);
1021         if (err < 0) {
1022                 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err);
1023                 goto done;
1024         }
1025         if (mm->width   != fmt->fmt.pix.width  ||
1026             mm->height  != fmt->fmt.pix.height ||
1027             palette_to_pixelformat(mm->format) !=
1028             fmt->fmt.pix.pixelformat) {
1029                 /* New capture format...  */
1030                 fmt->fmt.pix.width = mm->width;
1031                 fmt->fmt.pix.height = mm->height;
1032                 fmt->fmt.pix.pixelformat =
1033                         palette_to_pixelformat(mm->format);
1034                 fmt->fmt.pix.field = V4L2_FIELD_ANY;
1035                 fmt->fmt.pix.bytesperline = 0;
1036                 err = drv(inode, file, VIDIOC_S_FMT, fmt);
1037                 if (err < 0) {
1038                         dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err);
1039                         goto done;
1040                 }
1041         }
1042         buf.index = mm->frame;
1043         buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1044         err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1045         if (err < 0) {
1046                 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err);
1047                 goto done;
1048         }
1049         err = drv(inode, file, VIDIOC_QBUF, &buf);
1050         if (err < 0) {
1051                 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
1052                 goto done;
1053         }
1054         err = drv(inode, file, VIDIOC_STREAMON, &captype);
1055         if (err < 0)
1056                 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
1057 done:
1058         kfree(fmt);
1059         return err;
1060 }
1061
1062 static noinline int v4l1_compat_sync(
1063                                 int *i,
1064                                 struct inode *inode,
1065                                 struct file *file,
1066                                 v4l2_kioctl drv)
1067 {
1068         int err;
1069         enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1070         struct v4l2_buffer buf;
1071         struct poll_wqueues *pwq;
1072
1073         memset(&buf, 0, sizeof(buf));
1074         buf.index = *i;
1075         buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1076         err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1077         if (err < 0) {
1078                 /*  No such buffer */
1079                 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1080                 goto done;
1081         }
1082         if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
1083                 /* Buffer is not mapped  */
1084                 err = -EINVAL;
1085                 goto done;
1086         }
1087
1088         /* make sure capture actually runs so we don't block forever */
1089         err = drv(inode, file, VIDIOC_STREAMON, &captype);
1090         if (err < 0) {
1091                 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err);
1092                 goto done;
1093         }
1094
1095         pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
1096         /*  Loop as long as the buffer is queued, but not done  */
1097         while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
1098                                                 == V4L2_BUF_FLAG_QUEUED) {
1099                 err = poll_one(file, pwq);
1100                 if (err < 0 ||  /* error or sleep was interrupted  */
1101                     err == 0)   /* timeout? Shouldn't occur.  */
1102                         break;
1103                 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1104                 if (err < 0)
1105                         dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1106         }
1107         kfree(pwq);
1108         if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1109                 goto done;
1110         do {
1111                 err = drv(inode, file, VIDIOC_DQBUF, &buf);
1112                 if (err < 0)
1113                         dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err);
1114         } while (err == 0 && buf.index != *i);
1115 done:
1116         return err;
1117 }
1118
1119 static noinline int v4l1_compat_get_vbi_format(
1120                                 struct vbi_format *fmt,
1121                                 struct inode *inode,
1122                                 struct file *file,
1123                                 v4l2_kioctl drv)
1124 {
1125         int err;
1126         struct v4l2_format *fmt2;
1127
1128         fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1129         if (!fmt2) {
1130                 err = -ENOMEM;
1131                 return err;
1132         }
1133         fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1134
1135         err = drv(inode, file, VIDIOC_G_FMT, fmt2);
1136         if (err < 0) {
1137                 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
1138                 goto done;
1139         }
1140         if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1141                 err = -EINVAL;
1142                 goto done;
1143         }
1144         memset(fmt, 0, sizeof(*fmt));
1145         fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1146         fmt->sampling_rate    = fmt2->fmt.vbi.sampling_rate;
1147         fmt->sample_format    = VIDEO_PALETTE_RAW;
1148         fmt->start[0]         = fmt2->fmt.vbi.start[0];
1149         fmt->count[0]         = fmt2->fmt.vbi.count[0];
1150         fmt->start[1]         = fmt2->fmt.vbi.start[1];
1151         fmt->count[1]         = fmt2->fmt.vbi.count[1];
1152         fmt->flags            = fmt2->fmt.vbi.flags & 0x03;
1153 done:
1154         kfree(fmt2);
1155         return err;
1156 }
1157
1158 static noinline int v4l1_compat_set_vbi_format(
1159                                 struct vbi_format *fmt,
1160                                 struct inode *inode,
1161                                 struct file *file,
1162                                 v4l2_kioctl drv)
1163 {
1164         int err;
1165         struct v4l2_format      *fmt2 = NULL;
1166
1167         if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1168                 err = -EINVAL;
1169                 return err;
1170         }
1171
1172         fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1173         if (!fmt2) {
1174                 err = -ENOMEM;
1175                 return err;
1176         }
1177         fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1178         fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1179         fmt2->fmt.vbi.sampling_rate    = fmt->sampling_rate;
1180         fmt2->fmt.vbi.sample_format    = V4L2_PIX_FMT_GREY;
1181         fmt2->fmt.vbi.start[0]         = fmt->start[0];
1182         fmt2->fmt.vbi.count[0]         = fmt->count[0];
1183         fmt2->fmt.vbi.start[1]         = fmt->start[1];
1184         fmt2->fmt.vbi.count[1]         = fmt->count[1];
1185         fmt2->fmt.vbi.flags            = fmt->flags;
1186         err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1187         if (err < 0) {
1188                 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1189                 goto done;
1190         }
1191
1192         if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1193             fmt2->fmt.vbi.sampling_rate    != fmt->sampling_rate    ||
1194             fmt2->fmt.vbi.sample_format    != V4L2_PIX_FMT_GREY     ||
1195             fmt2->fmt.vbi.start[0]         != fmt->start[0]         ||
1196             fmt2->fmt.vbi.count[0]         != fmt->count[0]         ||
1197             fmt2->fmt.vbi.start[1]         != fmt->start[1]         ||
1198             fmt2->fmt.vbi.count[1]         != fmt->count[1]         ||
1199             fmt2->fmt.vbi.flags            != fmt->flags) {
1200                 err = -EINVAL;
1201                 goto done;
1202         }
1203         err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1204         if (err < 0)
1205                 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1206 done:
1207         kfree(fmt2);
1208         return err;
1209 }
1210
1211 /*
1212  *      This function is exported.
1213  */
1214 int
1215 v4l_compat_translate_ioctl(struct inode         *inode,
1216                            struct file          *file,
1217                            int                  cmd,
1218                            void                 *arg,
1219                            v4l2_kioctl          drv)
1220 {
1221         int err;
1222
1223         switch (cmd) {
1224         case VIDIOCGCAP:        /* capability */
1225                 err = v4l1_compat_get_capabilities(arg, inode, file, drv);
1226                 break;
1227         case VIDIOCGFBUF: /*  get frame buffer  */
1228                 err = v4l1_compat_get_frame_buffer(arg, inode, file, drv);
1229                 break;
1230         case VIDIOCSFBUF: /*  set frame buffer  */
1231                 err = v4l1_compat_set_frame_buffer(arg, inode, file, drv);
1232                 break;
1233         case VIDIOCGWIN: /*  get window or capture dimensions  */
1234                 err = v4l1_compat_get_win_cap_dimensions(arg, inode, file, drv);
1235                 break;
1236         case VIDIOCSWIN: /*  set window and/or capture dimensions  */
1237                 err = v4l1_compat_set_win_cap_dimensions(arg, inode, file, drv);
1238                 break;
1239         case VIDIOCCAPTURE: /*  turn on/off preview  */
1240                 err = v4l1_compat_turn_preview_on_off(arg, inode, file, drv);
1241                 break;
1242         case VIDIOCGCHAN: /*  get input information  */
1243                 err = v4l1_compat_get_input_info(arg, inode, file, drv);
1244                 break;
1245         case VIDIOCSCHAN: /*  set input  */
1246                 err = v4l1_compat_set_input(arg, inode, file, drv);
1247                 break;
1248         case VIDIOCGPICT: /*  get tone controls & partial capture format  */
1249                 err = v4l1_compat_get_picture(arg, inode, file, drv);
1250                 break;
1251         case VIDIOCSPICT: /*  set tone controls & partial capture format  */
1252                 err = v4l1_compat_set_picture(arg, inode, file, drv);
1253                 break;
1254         case VIDIOCGTUNER: /*  get tuner information  */
1255                 err = v4l1_compat_get_tuner(arg, inode, file, drv);
1256                 break;
1257         case VIDIOCSTUNER: /*  select a tuner input  */
1258                 err = v4l1_compat_select_tuner(arg, inode, file, drv);
1259                 break;
1260         case VIDIOCGFREQ: /*  get frequency  */
1261                 err = v4l1_compat_get_frequency(arg, inode, file, drv);
1262                 break;
1263         case VIDIOCSFREQ: /*  set frequency  */
1264                 err = v4l1_compat_set_frequency(arg, inode, file, drv);
1265                 break;
1266         case VIDIOCGAUDIO: /*  get audio properties/controls  */
1267                 err = v4l1_compat_get_audio(arg, inode, file, drv);
1268                 break;
1269         case VIDIOCSAUDIO: /*  set audio controls  */
1270                 err = v4l1_compat_set_audio(arg, inode, file, drv);
1271                 break;
1272         case VIDIOCMCAPTURE: /*  capture a frame  */
1273                 err = v4l1_compat_capture_frame(arg, inode, file, drv);
1274                 break;
1275         case VIDIOCSYNC: /*  wait for a frame  */
1276                 err = v4l1_compat_sync(arg, inode, file, drv);
1277                 break;
1278         case VIDIOCGVBIFMT: /* query VBI data capture format */
1279                 err = v4l1_compat_get_vbi_format(arg, inode, file, drv);
1280                 break;
1281         case VIDIOCSVBIFMT:
1282                 err = v4l1_compat_set_vbi_format(arg, inode, file, drv);
1283                 break;
1284         default:
1285                 err = -ENOIOCTLCMD;
1286                 break;
1287         }
1288
1289         return err;
1290 }
1291 EXPORT_SYMBOL(v4l_compat_translate_ioctl);
1292
1293 /*
1294  * Local variables:
1295  * c-basic-offset: 8
1296  * End:
1297  */