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