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; | |
206 | set_current_state(TASK_INTERRUPTIBLE); | |
207 | mask = file->f_op->poll(file, table); | |
208 | if (mask & POLLIN) | |
209 | break; | |
210 | table = NULL; | |
211 | if (signal_pending(current)) { | |
212 | retval = -ERESTARTSYS; | |
213 | break; | |
214 | } | |
215 | schedule(); | |
216 | } | |
217 | set_current_state(TASK_RUNNING); | |
76e41e48 | 218 | poll_freewait(pwq); |
1da177e4 LT |
219 | return retval; |
220 | } | |
221 | ||
b524f7b0 | 222 | static int count_inputs( |
b524f7b0 MS |
223 | struct file *file, |
224 | v4l2_kioctl drv) | |
1da177e4 LT |
225 | { |
226 | struct v4l2_input input2; | |
227 | int i; | |
228 | ||
229 | for (i = 0;; i++) { | |
8b3b90ac | 230 | memset(&input2, 0, sizeof(input2)); |
1da177e4 | 231 | input2.index = i; |
b1f88407 | 232 | if (0 != drv(file, VIDIOC_ENUMINPUT, &input2)) |
1da177e4 LT |
233 | break; |
234 | } | |
235 | return i; | |
236 | } | |
237 | ||
b524f7b0 | 238 | static int check_size( |
b524f7b0 MS |
239 | struct file *file, |
240 | v4l2_kioctl drv, | |
241 | int *maxw, | |
242 | int *maxh) | |
1da177e4 LT |
243 | { |
244 | struct v4l2_fmtdesc desc2; | |
245 | struct v4l2_format fmt2; | |
246 | ||
8b3b90ac MS |
247 | memset(&desc2, 0, sizeof(desc2)); |
248 | memset(&fmt2, 0, sizeof(fmt2)); | |
1da177e4 LT |
249 | |
250 | desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
b1f88407 | 251 | if (0 != drv(file, VIDIOC_ENUM_FMT, &desc2)) |
1da177e4 LT |
252 | goto done; |
253 | ||
254 | fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
255 | fmt2.fmt.pix.width = 10000; | |
256 | fmt2.fmt.pix.height = 10000; | |
257 | fmt2.fmt.pix.pixelformat = desc2.pixelformat; | |
b1f88407 | 258 | if (0 != drv(file, VIDIOC_TRY_FMT, &fmt2)) |
1da177e4 LT |
259 | goto done; |
260 | ||
261 | *maxw = fmt2.fmt.pix.width; | |
262 | *maxh = fmt2.fmt.pix.height; | |
263 | ||
b524f7b0 | 264 | done: |
1da177e4 LT |
265 | return 0; |
266 | } | |
267 | ||
268 | /* ----------------------------------------------------------------- */ | |
269 | ||
069b7479 | 270 | static noinline long v4l1_compat_get_capabilities( |
b524f7b0 | 271 | struct video_capability *cap, |
b524f7b0 MS |
272 | struct file *file, |
273 | v4l2_kioctl drv) | |
1da177e4 | 274 | { |
069b7479 | 275 | long err; |
b524f7b0 MS |
276 | struct v4l2_framebuffer fbuf; |
277 | struct v4l2_capability *cap2; | |
278 | ||
279 | cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL); | |
280 | if (!cap2) { | |
281 | err = -ENOMEM; | |
282 | return err; | |
283 | } | |
284 | memset(cap, 0, sizeof(*cap)); | |
285 | memset(&fbuf, 0, sizeof(fbuf)); | |
1da177e4 | 286 | |
b1f88407 | 287 | err = drv(file, VIDIOC_QUERYCAP, cap2); |
b524f7b0 | 288 | if (err < 0) { |
069b7479 | 289 | dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %ld\n", err); |
b524f7b0 MS |
290 | goto done; |
291 | } | |
292 | if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) { | |
b1f88407 | 293 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
1da177e4 | 294 | if (err < 0) { |
069b7479 | 295 | dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %ld\n", err); |
b524f7b0 | 296 | memset(&fbuf, 0, sizeof(fbuf)); |
1da177e4 | 297 | } |
b524f7b0 | 298 | err = 0; |
1da177e4 | 299 | } |
1da177e4 | 300 | |
b524f7b0 MS |
301 | memcpy(cap->name, cap2->card, |
302 | min(sizeof(cap->name), sizeof(cap2->card))); | |
303 | cap->name[sizeof(cap->name) - 1] = 0; | |
304 | if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE) | |
305 | cap->type |= VID_TYPE_CAPTURE; | |
306 | if (cap2->capabilities & V4L2_CAP_TUNER) | |
307 | cap->type |= VID_TYPE_TUNER; | |
308 | if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE) | |
309 | cap->type |= VID_TYPE_TELETEXT; | |
310 | if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) | |
311 | cap->type |= VID_TYPE_OVERLAY; | |
312 | if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING) | |
313 | cap->type |= VID_TYPE_CLIPPING; | |
314 | ||
b1f88407 MCC |
315 | cap->channels = count_inputs(file, drv); |
316 | check_size(file, drv, | |
b524f7b0 MS |
317 | &cap->maxwidth, &cap->maxheight); |
318 | cap->audios = 0; /* FIXME */ | |
319 | cap->minwidth = 48; /* FIXME */ | |
320 | cap->minheight = 32; /* FIXME */ | |
321 | ||
322 | done: | |
323 | kfree(cap2); | |
324 | return err; | |
325 | } | |
37026278 | 326 | |
069b7479 | 327 | static noinline long v4l1_compat_get_frame_buffer( |
b524f7b0 | 328 | struct video_buffer *buffer, |
b524f7b0 MS |
329 | struct file *file, |
330 | v4l2_kioctl drv) | |
331 | { | |
069b7479 | 332 | long err; |
b524f7b0 | 333 | struct v4l2_framebuffer fbuf; |
1da177e4 | 334 | |
b524f7b0 MS |
335 | memset(buffer, 0, sizeof(*buffer)); |
336 | memset(&fbuf, 0, sizeof(fbuf)); | |
337 | ||
b1f88407 | 338 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
b524f7b0 | 339 | if (err < 0) { |
069b7479 | 340 | dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %ld\n", err); |
b524f7b0 MS |
341 | goto done; |
342 | } | |
343 | buffer->base = fbuf.base; | |
344 | buffer->height = fbuf.fmt.height; | |
345 | buffer->width = fbuf.fmt.width; | |
346 | ||
347 | switch (fbuf.fmt.pixelformat) { | |
348 | case V4L2_PIX_FMT_RGB332: | |
349 | buffer->depth = 8; | |
1da177e4 | 350 | break; |
b524f7b0 MS |
351 | case V4L2_PIX_FMT_RGB555: |
352 | buffer->depth = 15; | |
353 | break; | |
354 | case V4L2_PIX_FMT_RGB565: | |
355 | buffer->depth = 16; | |
356 | break; | |
357 | case V4L2_PIX_FMT_BGR24: | |
358 | buffer->depth = 24; | |
359 | break; | |
360 | case V4L2_PIX_FMT_BGR32: | |
361 | buffer->depth = 32; | |
362 | break; | |
363 | default: | |
364 | buffer->depth = 0; | |
1da177e4 | 365 | } |
b524f7b0 MS |
366 | if (fbuf.fmt.bytesperline) { |
367 | buffer->bytesperline = fbuf.fmt.bytesperline; | |
368 | if (!buffer->depth && buffer->width) | |
369 | buffer->depth = ((fbuf.fmt.bytesperline<<3) | |
370 | + (buffer->width-1)) | |
371 | / buffer->width; | |
372 | } else { | |
373 | buffer->bytesperline = | |
374 | (buffer->width * buffer->depth + 7) & 7; | |
375 | buffer->bytesperline >>= 3; | |
376 | } | |
377 | done: | |
378 | return err; | |
379 | } | |
380 | ||
069b7479 | 381 | static noinline long v4l1_compat_set_frame_buffer( |
b524f7b0 | 382 | struct video_buffer *buffer, |
b524f7b0 MS |
383 | struct file *file, |
384 | v4l2_kioctl drv) | |
385 | { | |
069b7479 | 386 | long err; |
b524f7b0 MS |
387 | struct v4l2_framebuffer fbuf; |
388 | ||
389 | memset(&fbuf, 0, sizeof(fbuf)); | |
390 | fbuf.base = buffer->base; | |
391 | fbuf.fmt.height = buffer->height; | |
392 | fbuf.fmt.width = buffer->width; | |
393 | switch (buffer->depth) { | |
394 | case 8: | |
395 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332; | |
396 | break; | |
397 | case 15: | |
398 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555; | |
399 | break; | |
400 | case 16: | |
401 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565; | |
402 | break; | |
403 | case 24: | |
404 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24; | |
405 | break; | |
406 | case 32: | |
407 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32; | |
1da177e4 LT |
408 | break; |
409 | } | |
b524f7b0 | 410 | fbuf.fmt.bytesperline = buffer->bytesperline; |
b1f88407 | 411 | err = drv(file, VIDIOC_S_FBUF, &fbuf); |
b524f7b0 | 412 | if (err < 0) |
069b7479 | 413 | dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %ld\n", err); |
b524f7b0 MS |
414 | return err; |
415 | } | |
1da177e4 | 416 | |
069b7479 | 417 | static noinline long v4l1_compat_get_win_cap_dimensions( |
b524f7b0 | 418 | struct video_window *win, |
b524f7b0 MS |
419 | struct file *file, |
420 | v4l2_kioctl drv) | |
421 | { | |
069b7479 | 422 | long err; |
b524f7b0 | 423 | struct v4l2_format *fmt; |
1da177e4 | 424 | |
b524f7b0 MS |
425 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
426 | if (!fmt) { | |
427 | err = -ENOMEM; | |
428 | return err; | |
429 | } | |
430 | memset(win, 0, sizeof(*win)); | |
1da177e4 | 431 | |
b524f7b0 | 432 | fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY; |
b1f88407 | 433 | err = drv(file, VIDIOC_G_FMT, fmt); |
b524f7b0 | 434 | if (err < 0) |
069b7479 | 435 | dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %ld\n", err); |
b524f7b0 MS |
436 | if (err == 0) { |
437 | win->x = fmt->fmt.win.w.left; | |
438 | win->y = fmt->fmt.win.w.top; | |
439 | win->width = fmt->fmt.win.w.width; | |
440 | win->height = fmt->fmt.win.w.height; | |
441 | win->chromakey = fmt->fmt.win.chromakey; | |
1da177e4 LT |
442 | win->clips = NULL; |
443 | win->clipcount = 0; | |
b524f7b0 | 444 | goto done; |
1da177e4 | 445 | } |
1da177e4 | 446 | |
b524f7b0 | 447 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
b1f88407 | 448 | err = drv(file, VIDIOC_G_FMT, fmt); |
b524f7b0 | 449 | if (err < 0) { |
069b7479 | 450 | dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %ld\n", err); |
b524f7b0 MS |
451 | goto done; |
452 | } | |
453 | win->x = 0; | |
454 | win->y = 0; | |
455 | win->width = fmt->fmt.pix.width; | |
456 | win->height = fmt->fmt.pix.height; | |
457 | win->chromakey = 0; | |
458 | win->clips = NULL; | |
459 | win->clipcount = 0; | |
460 | done: | |
461 | kfree(fmt); | |
462 | return err; | |
463 | } | |
1da177e4 | 464 | |
069b7479 | 465 | static noinline long v4l1_compat_set_win_cap_dimensions( |
b524f7b0 | 466 | struct video_window *win, |
b524f7b0 MS |
467 | struct file *file, |
468 | v4l2_kioctl drv) | |
469 | { | |
069b7479 | 470 | long err, err1, err2; |
b524f7b0 MS |
471 | struct v4l2_format *fmt; |
472 | ||
473 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); | |
474 | if (!fmt) { | |
475 | err = -ENOMEM; | |
476 | return err; | |
1da177e4 | 477 | } |
b524f7b0 | 478 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
b1f88407 MCC |
479 | drv(file, VIDIOC_STREAMOFF, &fmt->type); |
480 | err1 = drv(file, VIDIOC_G_FMT, fmt); | |
b524f7b0 | 481 | if (err1 < 0) |
069b7479 | 482 | dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %ld\n", err1); |
b524f7b0 MS |
483 | if (err1 == 0) { |
484 | fmt->fmt.pix.width = win->width; | |
485 | fmt->fmt.pix.height = win->height; | |
486 | fmt->fmt.pix.field = V4L2_FIELD_ANY; | |
487 | fmt->fmt.pix.bytesperline = 0; | |
b1f88407 | 488 | err = drv(file, VIDIOC_S_FMT, fmt); |
1da177e4 | 489 | if (err < 0) |
069b7479 | 490 | dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %ld\n", |
b524f7b0 MS |
491 | err); |
492 | win->width = fmt->fmt.pix.width; | |
493 | win->height = fmt->fmt.pix.height; | |
1da177e4 | 494 | } |
1da177e4 | 495 | |
b524f7b0 MS |
496 | memset(fmt, 0, sizeof(*fmt)); |
497 | fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY; | |
498 | fmt->fmt.win.w.left = win->x; | |
499 | fmt->fmt.win.w.top = win->y; | |
500 | fmt->fmt.win.w.width = win->width; | |
501 | fmt->fmt.win.w.height = win->height; | |
502 | fmt->fmt.win.chromakey = win->chromakey; | |
503 | fmt->fmt.win.clips = (void __user *)win->clips; | |
504 | fmt->fmt.win.clipcount = win->clipcount; | |
b1f88407 | 505 | err2 = drv(file, VIDIOC_S_FMT, fmt); |
b524f7b0 | 506 | if (err2 < 0) |
069b7479 | 507 | dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %ld\n", err2); |
b524f7b0 MS |
508 | |
509 | if (err1 != 0 && err2 != 0) | |
510 | err = err1; | |
511 | else | |
512 | err = 0; | |
513 | kfree(fmt); | |
514 | return err; | |
515 | } | |
1da177e4 | 516 | |
069b7479 | 517 | static noinline long v4l1_compat_turn_preview_on_off( |
b524f7b0 | 518 | int *on, |
b524f7b0 MS |
519 | struct file *file, |
520 | v4l2_kioctl drv) | |
521 | { | |
069b7479 | 522 | long err; |
b524f7b0 MS |
523 | enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
524 | ||
525 | if (0 == *on) { | |
526 | /* dirty hack time. But v4l1 has no STREAMOFF | |
527 | * equivalent in the API, and this one at | |
528 | * least comes close ... */ | |
b1f88407 | 529 | drv(file, VIDIOC_STREAMOFF, &captype); |
1da177e4 | 530 | } |
b1f88407 | 531 | err = drv(file, VIDIOC_OVERLAY, on); |
b524f7b0 | 532 | if (err < 0) |
069b7479 | 533 | dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %ld\n", err); |
b524f7b0 MS |
534 | return err; |
535 | } | |
c77990e7 | 536 | |
069b7479 | 537 | static noinline long v4l1_compat_get_input_info( |
b524f7b0 | 538 | struct video_channel *chan, |
b524f7b0 MS |
539 | struct file *file, |
540 | v4l2_kioctl drv) | |
541 | { | |
069b7479 | 542 | long err; |
b524f7b0 MS |
543 | struct v4l2_input input2; |
544 | v4l2_std_id sid; | |
8a016dcc | 545 | |
b524f7b0 MS |
546 | memset(&input2, 0, sizeof(input2)); |
547 | input2.index = chan->channel; | |
b1f88407 | 548 | err = drv(file, VIDIOC_ENUMINPUT, &input2); |
b524f7b0 MS |
549 | if (err < 0) { |
550 | dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: " | |
069b7479 | 551 | "channel=%d err=%ld\n", chan->channel, err); |
b524f7b0 MS |
552 | goto done; |
553 | } | |
554 | chan->channel = input2.index; | |
555 | memcpy(chan->name, input2.name, | |
556 | min(sizeof(chan->name), sizeof(input2.name))); | |
557 | chan->name[sizeof(chan->name) - 1] = 0; | |
558 | chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0; | |
559 | chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0; | |
560 | switch (input2.type) { | |
561 | case V4L2_INPUT_TYPE_TUNER: | |
562 | chan->type = VIDEO_TYPE_TV; | |
563 | break; | |
564 | default: | |
565 | case V4L2_INPUT_TYPE_CAMERA: | |
566 | chan->type = VIDEO_TYPE_CAMERA; | |
1da177e4 LT |
567 | break; |
568 | } | |
b524f7b0 | 569 | chan->norm = 0; |
b1f88407 | 570 | err = drv(file, VIDIOC_G_STD, &sid); |
b524f7b0 | 571 | if (err < 0) |
069b7479 | 572 | dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %ld\n", err); |
b524f7b0 MS |
573 | if (err == 0) { |
574 | if (sid & V4L2_STD_PAL) | |
575 | chan->norm = VIDEO_MODE_PAL; | |
576 | if (sid & V4L2_STD_NTSC) | |
577 | chan->norm = VIDEO_MODE_NTSC; | |
578 | if (sid & V4L2_STD_SECAM) | |
579 | chan->norm = VIDEO_MODE_SECAM; | |
580 | } | |
581 | done: | |
582 | return err; | |
583 | } | |
bbe2486f | 584 | |
069b7479 | 585 | static noinline long v4l1_compat_set_input( |
b524f7b0 | 586 | struct video_channel *chan, |
b524f7b0 MS |
587 | struct file *file, |
588 | v4l2_kioctl drv) | |
589 | { | |
069b7479 | 590 | long err; |
b524f7b0 | 591 | v4l2_std_id sid = 0; |
1da177e4 | 592 | |
b1f88407 | 593 | err = drv(file, VIDIOC_S_INPUT, &chan->channel); |
b524f7b0 | 594 | if (err < 0) |
069b7479 | 595 | dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %ld\n", err); |
b524f7b0 MS |
596 | switch (chan->norm) { |
597 | case VIDEO_MODE_PAL: | |
598 | sid = V4L2_STD_PAL; | |
599 | break; | |
600 | case VIDEO_MODE_NTSC: | |
601 | sid = V4L2_STD_NTSC; | |
602 | break; | |
603 | case VIDEO_MODE_SECAM: | |
604 | sid = V4L2_STD_SECAM; | |
1da177e4 LT |
605 | break; |
606 | } | |
b524f7b0 | 607 | if (0 != sid) { |
b1f88407 | 608 | err = drv(file, VIDIOC_S_STD, &sid); |
1da177e4 | 609 | if (err < 0) |
069b7479 | 610 | dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err); |
1da177e4 | 611 | } |
b524f7b0 MS |
612 | return err; |
613 | } | |
2aa92ffd | 614 | |
069b7479 | 615 | static noinline long v4l1_compat_get_picture( |
b524f7b0 | 616 | struct video_picture *pict, |
b524f7b0 MS |
617 | struct file *file, |
618 | v4l2_kioctl drv) | |
619 | { | |
069b7479 | 620 | long err; |
b524f7b0 | 621 | struct v4l2_format *fmt; |
2aa92ffd | 622 | |
b524f7b0 MS |
623 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
624 | if (!fmt) { | |
625 | err = -ENOMEM; | |
626 | return err; | |
1da177e4 | 627 | } |
1da177e4 | 628 | |
b1f88407 | 629 | pict->brightness = get_v4l_control(file, |
b524f7b0 | 630 | V4L2_CID_BRIGHTNESS, drv); |
b1f88407 | 631 | pict->hue = get_v4l_control(file, |
b524f7b0 | 632 | V4L2_CID_HUE, drv); |
b1f88407 | 633 | pict->contrast = get_v4l_control(file, |
b524f7b0 | 634 | V4L2_CID_CONTRAST, drv); |
b1f88407 | 635 | pict->colour = get_v4l_control(file, |
b524f7b0 | 636 | V4L2_CID_SATURATION, drv); |
b1f88407 | 637 | pict->whiteness = get_v4l_control(file, |
b524f7b0 MS |
638 | V4L2_CID_WHITENESS, drv); |
639 | ||
640 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
b1f88407 | 641 | err = drv(file, VIDIOC_G_FMT, fmt); |
b524f7b0 | 642 | if (err < 0) { |
069b7479 | 643 | dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %ld\n", err); |
b524f7b0 | 644 | goto done; |
1da177e4 | 645 | } |
1da177e4 | 646 | |
b524f7b0 MS |
647 | pict->depth = ((fmt->fmt.pix.bytesperline << 3) |
648 | + (fmt->fmt.pix.width - 1)) | |
649 | / fmt->fmt.pix.width; | |
650 | pict->palette = pixelformat_to_palette( | |
651 | fmt->fmt.pix.pixelformat); | |
652 | done: | |
653 | kfree(fmt); | |
654 | return err; | |
655 | } | |
656 | ||
069b7479 | 657 | static noinline long v4l1_compat_set_picture( |
b524f7b0 | 658 | struct video_picture *pict, |
b524f7b0 MS |
659 | struct file *file, |
660 | v4l2_kioctl drv) | |
661 | { | |
069b7479 | 662 | long err; |
b524f7b0 MS |
663 | struct v4l2_framebuffer fbuf; |
664 | int mem_err = 0, ovl_err = 0; | |
665 | struct v4l2_format *fmt; | |
666 | ||
667 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); | |
668 | if (!fmt) { | |
669 | err = -ENOMEM; | |
670 | return err; | |
671 | } | |
672 | memset(&fbuf, 0, sizeof(fbuf)); | |
673 | ||
b1f88407 | 674 | set_v4l_control(file, |
b524f7b0 | 675 | V4L2_CID_BRIGHTNESS, pict->brightness, drv); |
b1f88407 | 676 | set_v4l_control(file, |
b524f7b0 | 677 | V4L2_CID_HUE, pict->hue, drv); |
b1f88407 | 678 | set_v4l_control(file, |
b524f7b0 | 679 | V4L2_CID_CONTRAST, pict->contrast, drv); |
b1f88407 | 680 | set_v4l_control(file, |
b524f7b0 | 681 | V4L2_CID_SATURATION, pict->colour, drv); |
b1f88407 | 682 | set_v4l_control(file, |
b524f7b0 MS |
683 | V4L2_CID_WHITENESS, pict->whiteness, drv); |
684 | /* | |
685 | * V4L1 uses this ioctl to set both memory capture and overlay | |
686 | * pixel format, while V4L2 has two different ioctls for this. | |
687 | * Some cards may not support one or the other, and may support | |
688 | * different pixel formats for memory vs overlay. | |
689 | */ | |
690 | ||
691 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
b1f88407 | 692 | err = drv(file, VIDIOC_G_FMT, fmt); |
b524f7b0 MS |
693 | /* If VIDIOC_G_FMT failed, then the driver likely doesn't |
694 | support memory capture. Trying to set the memory capture | |
695 | parameters would be pointless. */ | |
696 | if (err < 0) { | |
069b7479 | 697 | dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err); |
b524f7b0 MS |
698 | mem_err = -1000; /* didn't even try */ |
699 | } else if (fmt->fmt.pix.pixelformat != | |
700 | palette_to_pixelformat(pict->palette)) { | |
701 | fmt->fmt.pix.pixelformat = palette_to_pixelformat( | |
702 | pict->palette); | |
b1f88407 | 703 | mem_err = drv(file, VIDIOC_S_FMT, fmt); |
b524f7b0 MS |
704 | if (mem_err < 0) |
705 | dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n", | |
706 | mem_err); | |
1da177e4 | 707 | } |
1da177e4 | 708 | |
b1f88407 | 709 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
b524f7b0 MS |
710 | /* If VIDIOC_G_FBUF failed, then the driver likely doesn't |
711 | support overlay. Trying to set the overlay parameters | |
712 | would be quite pointless. */ | |
713 | if (err < 0) { | |
069b7479 | 714 | dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err); |
b524f7b0 MS |
715 | ovl_err = -1000; /* didn't even try */ |
716 | } else if (fbuf.fmt.pixelformat != | |
717 | palette_to_pixelformat(pict->palette)) { | |
718 | fbuf.fmt.pixelformat = palette_to_pixelformat( | |
719 | pict->palette); | |
b1f88407 | 720 | ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf); |
b524f7b0 MS |
721 | if (ovl_err < 0) |
722 | dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n", | |
723 | ovl_err); | |
724 | } | |
725 | if (ovl_err < 0 && mem_err < 0) { | |
726 | /* ioctl failed, couldn't set either parameter */ | |
727 | if (mem_err != -1000) | |
728 | err = mem_err; | |
729 | else if (ovl_err == -EPERM) | |
1da177e4 | 730 | err = 0; |
b524f7b0 MS |
731 | else |
732 | err = ovl_err; | |
733 | } else | |
734 | err = 0; | |
735 | kfree(fmt); | |
736 | return err; | |
737 | } | |
738 | ||
069b7479 | 739 | static noinline long v4l1_compat_get_tuner( |
b524f7b0 | 740 | struct video_tuner *tun, |
b524f7b0 MS |
741 | struct file *file, |
742 | v4l2_kioctl drv) | |
743 | { | |
069b7479 HV |
744 | long err; |
745 | int i; | |
b524f7b0 MS |
746 | struct v4l2_tuner tun2; |
747 | struct v4l2_standard std2; | |
748 | v4l2_std_id sid; | |
749 | ||
750 | memset(&tun2, 0, sizeof(tun2)); | |
b1f88407 | 751 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
b524f7b0 | 752 | if (err < 0) { |
069b7479 | 753 | dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err); |
b524f7b0 MS |
754 | goto done; |
755 | } | |
756 | memcpy(tun->name, tun2.name, | |
757 | min(sizeof(tun->name), sizeof(tun2.name))); | |
758 | tun->name[sizeof(tun->name) - 1] = 0; | |
759 | tun->rangelow = tun2.rangelow; | |
760 | tun->rangehigh = tun2.rangehigh; | |
761 | tun->flags = 0; | |
762 | tun->mode = VIDEO_MODE_AUTO; | |
763 | ||
764 | for (i = 0; i < 64; i++) { | |
765 | memset(&std2, 0, sizeof(std2)); | |
766 | std2.index = i; | |
b1f88407 | 767 | if (0 != drv(file, VIDIOC_ENUMSTD, &std2)) |
1da177e4 | 768 | break; |
b524f7b0 MS |
769 | if (std2.id & V4L2_STD_PAL) |
770 | tun->flags |= VIDEO_TUNER_PAL; | |
771 | if (std2.id & V4L2_STD_NTSC) | |
772 | tun->flags |= VIDEO_TUNER_NTSC; | |
773 | if (std2.id & V4L2_STD_SECAM) | |
774 | tun->flags |= VIDEO_TUNER_SECAM; | |
775 | } | |
ac19ecc6 | 776 | |
b1f88407 | 777 | err = drv(file, VIDIOC_G_STD, &sid); |
b524f7b0 | 778 | if (err < 0) |
069b7479 | 779 | dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %ld\n", err); |
b524f7b0 MS |
780 | if (err == 0) { |
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; | |
794 | done: | |
795 | return err; | |
796 | } | |
1da177e4 | 797 | |
069b7479 | 798 | static 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 | ||
b1f88407 | 809 | err = drv(file, VIDIOC_S_INPUT, &t); |
b524f7b0 | 810 | if (err < 0) |
069b7479 | 811 | dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %ld\n", err); |
b524f7b0 MS |
812 | return err; |
813 | } | |
814 | ||
069b7479 | 815 | static 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 | 833 | static 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 | 850 | static 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; | |
919 | done: | |
920 | return err; | |
921 | } | |
1da177e4 | 922 | |
069b7479 | 923 | static 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; |
975 | done: | |
976 | return err; | |
977 | } | |
1da177e4 | 978 | |
069b7479 | 979 | static 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 |
1034 | done: |
1035 | kfree(fmt); | |
1036 | return err; | |
1037 | } | |
1da177e4 | 1038 | |
069b7479 | 1039 | static 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); |
1091 | done: | |
1092 | return err; | |
1093 | } | |
1da177e4 | 1094 | |
069b7479 | 1095 | static 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; | |
1128 | done: | |
1129 | kfree(fmt2); | |
1130 | return err; | |
1131 | } | |
67f1570a | 1132 | |
069b7479 | 1133 | static 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 |
1180 | done: |
1181 | kfree(fmt2); | |
1182 | return err; | |
1183 | } | |
1184 | ||
1185 | /* | |
1186 | * This function is exported. | |
1187 | */ | |
069b7479 | 1188 | long |
b1f88407 | 1189 | v4l_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 |
1264 | EXPORT_SYMBOL(v4l_compat_translate_ioctl); |
1265 | ||
1266 | /* | |
1267 | * Local variables: | |
1268 | * c-basic-offset: 8 | |
1269 | * End: | |
1270 | */ |