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