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