blob: a16fe2167976d9c88c1098a6b1f51f0a1ade24ce [file] [log] [blame]
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001/*
2 * uvc_v4l2.c -- USB Video Class driver - V4L2 API
3 *
Laurent Pinchart11fc5ba2010-09-20 06:10:10 -03004 * Copyright (C) 2005-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
Laurent Pinchartc0efd232008-06-30 15:04:50 -03006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
Laurent Pinchart1a5e4c82011-12-18 20:45:39 -030014#include <linux/compat.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030015#include <linux/kernel.h>
16#include <linux/version.h>
17#include <linux/list.h>
18#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030020#include <linux/usb.h>
21#include <linux/videodev2.h>
22#include <linux/vmalloc.h>
23#include <linux/mm.h>
24#include <linux/wait.h>
Arun Sharma600634972011-07-26 16:09:06 -070025#include <linux/atomic.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030026
27#include <media/v4l2-common.h>
Hans de Goedeb4012002012-04-08 12:59:51 -030028#include <media/v4l2-ctrls.h>
29#include <media/v4l2-event.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030#include <media/v4l2-ioctl.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030031
32#include "uvcvideo.h"
33
34/* ------------------------------------------------------------------------
Laurent Pinchart561474c22010-02-18 16:38:52 -030035 * UVC ioctls
36 */
Laurent Pinchartba2fa992010-09-20 05:53:21 -030037static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
Laurent Pinchart227bd5b2011-07-30 16:19:49 -030038 struct uvc_xu_control_mapping *xmap)
Laurent Pinchart561474c22010-02-18 16:38:52 -030039{
40 struct uvc_control_mapping *map;
41 unsigned int size;
42 int ret;
43
44 map = kzalloc(sizeof *map, GFP_KERNEL);
45 if (map == NULL)
46 return -ENOMEM;
47
48 map->id = xmap->id;
49 memcpy(map->name, xmap->name, sizeof map->name);
50 memcpy(map->entity, xmap->entity, sizeof map->entity);
51 map->selector = xmap->selector;
52 map->size = xmap->size;
53 map->offset = xmap->offset;
54 map->v4l2_type = xmap->v4l2_type;
55 map->data_type = xmap->data_type;
56
57 switch (xmap->v4l2_type) {
58 case V4L2_CTRL_TYPE_INTEGER:
59 case V4L2_CTRL_TYPE_BOOLEAN:
60 case V4L2_CTRL_TYPE_BUTTON:
61 break;
62
63 case V4L2_CTRL_TYPE_MENU:
Haogang Chen806e23e2011-11-29 18:32:25 -030064 /* Prevent excessive memory consumption, as well as integer
65 * overflows.
66 */
67 if (xmap->menu_count == 0 ||
68 xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) {
69 ret = -EINVAL;
70 goto done;
71 }
72
Laurent Pinchart561474c22010-02-18 16:38:52 -030073 size = xmap->menu_count * sizeof(*map->menu_info);
74 map->menu_info = kmalloc(size, GFP_KERNEL);
75 if (map->menu_info == NULL) {
76 ret = -ENOMEM;
77 goto done;
78 }
79
80 if (copy_from_user(map->menu_info, xmap->menu_info, size)) {
81 ret = -EFAULT;
82 goto done;
83 }
84
85 map->menu_count = xmap->menu_count;
86 break;
87
88 default:
Laurent Pinchartba2fa992010-09-20 05:53:21 -030089 uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type "
90 "%u.\n", xmap->v4l2_type);
Mauro Carvalho Chehab7a286cc2011-06-26 10:18:03 -030091 ret = -ENOTTY;
Laurent Pinchart561474c22010-02-18 16:38:52 -030092 goto done;
93 }
94
Laurent Pinchartba2fa992010-09-20 05:53:21 -030095 ret = uvc_ctrl_add_mapping(chain, map);
Laurent Pinchart561474c22010-02-18 16:38:52 -030096
97done:
Laurent Pinchartba2fa992010-09-20 05:53:21 -030098 kfree(map->menu_info);
99 kfree(map);
Laurent Pinchart561474c22010-02-18 16:38:52 -0300100
101 return ret;
102}
103
104/* ------------------------------------------------------------------------
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300105 * V4L2 interface
106 */
107
108/*
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300109 * Find the frame interval closest to the requested frame interval for the
110 * given frame format and size. This should be done by the device as part of
111 * the Video Probe and Commit negotiation, but some hardware don't implement
112 * that feature.
113 */
114static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval)
115{
116 unsigned int i;
117
118 if (frame->bFrameIntervalType) {
119 __u32 best = -1, dist;
120
121 for (i = 0; i < frame->bFrameIntervalType; ++i) {
122 dist = interval > frame->dwFrameInterval[i]
123 ? interval - frame->dwFrameInterval[i]
124 : frame->dwFrameInterval[i] - interval;
125
126 if (dist > best)
127 break;
128
129 best = dist;
130 }
131
132 interval = frame->dwFrameInterval[i-1];
133 } else {
134 const __u32 min = frame->dwFrameInterval[0];
135 const __u32 max = frame->dwFrameInterval[1];
136 const __u32 step = frame->dwFrameInterval[2];
137
138 interval = min + (interval - min + step/2) / step * step;
139 if (interval > max)
140 interval = max;
141 }
142
143 return interval;
144}
145
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300146static int uvc_v4l2_try_format(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300147 struct v4l2_format *fmt, struct uvc_streaming_control *probe,
148 struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
149{
150 struct uvc_format *format = NULL;
151 struct uvc_frame *frame = NULL;
152 __u16 rw, rh;
153 unsigned int d, maxd;
154 unsigned int i;
155 __u32 interval;
156 int ret = 0;
157 __u8 *fcc;
158
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300159 if (fmt->type != stream->type)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300160 return -EINVAL;
161
162 fcc = (__u8 *)&fmt->fmt.pix.pixelformat;
163 uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n",
164 fmt->fmt.pix.pixelformat,
165 fcc[0], fcc[1], fcc[2], fcc[3],
166 fmt->fmt.pix.width, fmt->fmt.pix.height);
167
Laurent Pinchart815adc42012-08-28 18:38:58 -0300168 /* Check if the hardware supports the requested format, use the default
169 * format otherwise.
170 */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300171 for (i = 0; i < stream->nformats; ++i) {
172 format = &stream->format[i];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300173 if (format->fcc == fmt->fmt.pix.pixelformat)
174 break;
175 }
176
Laurent Pinchart815adc42012-08-28 18:38:58 -0300177 if (i == stream->nformats) {
178 format = stream->def_format;
179 fmt->fmt.pix.pixelformat = format->fcc;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300180 }
181
182 /* Find the closest image size. The distance between image sizes is
183 * the size in pixels of the non-overlapping regions between the
184 * requested size and the frame-specified size.
185 */
186 rw = fmt->fmt.pix.width;
187 rh = fmt->fmt.pix.height;
188 maxd = (unsigned int)-1;
189
190 for (i = 0; i < format->nframes; ++i) {
191 __u16 w = format->frame[i].wWidth;
192 __u16 h = format->frame[i].wHeight;
193
194 d = min(w, rw) * min(h, rh);
195 d = w*h + rw*rh - 2*d;
196 if (d < maxd) {
197 maxd = d;
198 frame = &format->frame[i];
199 }
200
201 if (maxd == 0)
202 break;
203 }
204
205 if (frame == NULL) {
206 uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n",
207 fmt->fmt.pix.width, fmt->fmt.pix.height);
208 return -EINVAL;
209 }
210
211 /* Use the default frame interval. */
212 interval = frame->dwDefaultFrameInterval;
213 uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us "
214 "(%u.%u fps).\n", interval/10, interval%10, 10000000/interval,
215 (100000000/interval)%10);
216
217 /* Set the format index, frame index and frame interval. */
218 memset(probe, 0, sizeof *probe);
219 probe->bmHint = 1; /* dwFrameInterval */
220 probe->bFormatIndex = format->index;
221 probe->bFrameIndex = frame->bFrameIndex;
222 probe->dwFrameInterval = uvc_try_frame_interval(frame, interval);
223 /* Some webcams stall the probe control set request when the
224 * dwMaxVideoFrameSize field is set to zero. The UVC specification
225 * clearly states that the field is read-only from the host, so this
226 * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by
227 * the webcam to work around the problem.
228 *
229 * The workaround could probably be enabled for all webcams, so the
230 * quirk can be removed if needed. It's currently useful to detect
231 * webcam bugs and fix them before they hit the market (providing
232 * developers test their webcams with the Linux driver as well as with
233 * the Windows driver).
234 */
Laurent Pinchart69477562010-11-21 13:36:34 -0300235 mutex_lock(&stream->mutex);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300236 if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300237 probe->dwMaxVideoFrameSize =
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300238 stream->ctrl.dwMaxVideoFrameSize;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300239
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300240 /* Probe the device. */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300241 ret = uvc_probe_video(stream, probe);
Laurent Pinchart69477562010-11-21 13:36:34 -0300242 mutex_unlock(&stream->mutex);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300243 if (ret < 0)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300244 goto done;
245
246 fmt->fmt.pix.width = frame->wWidth;
247 fmt->fmt.pix.height = frame->wHeight;
248 fmt->fmt.pix.field = V4L2_FIELD_NONE;
249 fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
250 fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
251 fmt->fmt.pix.colorspace = format->colorspace;
252 fmt->fmt.pix.priv = 0;
253
254 if (uvc_format != NULL)
255 *uvc_format = format;
256 if (uvc_frame != NULL)
257 *uvc_frame = frame;
258
259done:
260 return ret;
261}
262
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300263static int uvc_v4l2_get_format(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300264 struct v4l2_format *fmt)
265{
Laurent Pinchart69477562010-11-21 13:36:34 -0300266 struct uvc_format *format;
267 struct uvc_frame *frame;
268 int ret = 0;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300269
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300270 if (fmt->type != stream->type)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300271 return -EINVAL;
272
Laurent Pinchart69477562010-11-21 13:36:34 -0300273 mutex_lock(&stream->mutex);
274 format = stream->cur_format;
275 frame = stream->cur_frame;
276
277 if (format == NULL || frame == NULL) {
278 ret = -EINVAL;
279 goto done;
280 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300281
282 fmt->fmt.pix.pixelformat = format->fcc;
283 fmt->fmt.pix.width = frame->wWidth;
284 fmt->fmt.pix.height = frame->wHeight;
285 fmt->fmt.pix.field = V4L2_FIELD_NONE;
286 fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300287 fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300288 fmt->fmt.pix.colorspace = format->colorspace;
289 fmt->fmt.pix.priv = 0;
290
Laurent Pinchart69477562010-11-21 13:36:34 -0300291done:
292 mutex_unlock(&stream->mutex);
293 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300294}
295
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300296static int uvc_v4l2_set_format(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300297 struct v4l2_format *fmt)
298{
299 struct uvc_streaming_control probe;
300 struct uvc_format *format;
301 struct uvc_frame *frame;
302 int ret;
303
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300304 if (fmt->type != stream->type)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300305 return -EINVAL;
306
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300307 ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300308 if (ret < 0)
309 return ret;
310
Laurent Pinchart69477562010-11-21 13:36:34 -0300311 mutex_lock(&stream->mutex);
312
313 if (uvc_queue_allocated(&stream->queue)) {
314 ret = -EBUSY;
315 goto done;
316 }
317
Ezequiel Garcia8c0d44e2013-01-14 15:22:55 -0300318 stream->ctrl = probe;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300319 stream->cur_format = format;
320 stream->cur_frame = frame;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300321
Laurent Pinchart69477562010-11-21 13:36:34 -0300322done:
323 mutex_unlock(&stream->mutex);
324 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300325}
326
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300327static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300328 struct v4l2_streamparm *parm)
329{
330 uint32_t numerator, denominator;
331
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300332 if (parm->type != stream->type)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300333 return -EINVAL;
334
Laurent Pinchart69477562010-11-21 13:36:34 -0300335 mutex_lock(&stream->mutex);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300336 numerator = stream->ctrl.dwFrameInterval;
Laurent Pinchart69477562010-11-21 13:36:34 -0300337 mutex_unlock(&stream->mutex);
338
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300339 denominator = 10000000;
340 uvc_simplify_fraction(&numerator, &denominator, 8, 333);
341
342 memset(parm, 0, sizeof *parm);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300343 parm->type = stream->type;
Laurent Pinchartff924202008-12-28 22:32:29 -0300344
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300345 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
Laurent Pinchartff924202008-12-28 22:32:29 -0300346 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
347 parm->parm.capture.capturemode = 0;
348 parm->parm.capture.timeperframe.numerator = numerator;
349 parm->parm.capture.timeperframe.denominator = denominator;
350 parm->parm.capture.extendedmode = 0;
351 parm->parm.capture.readbuffers = 0;
352 } else {
353 parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
354 parm->parm.output.outputmode = 0;
355 parm->parm.output.timeperframe.numerator = numerator;
356 parm->parm.output.timeperframe.denominator = denominator;
357 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300358
359 return 0;
360}
361
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300362static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300363 struct v4l2_streamparm *parm)
364{
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300365 struct uvc_streaming_control probe;
Laurent Pinchartff924202008-12-28 22:32:29 -0300366 struct v4l2_fract timeperframe;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300367 uint32_t interval;
368 int ret;
369
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300370 if (parm->type != stream->type)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300371 return -EINVAL;
372
Laurent Pinchartff924202008-12-28 22:32:29 -0300373 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
374 timeperframe = parm->parm.capture.timeperframe;
375 else
376 timeperframe = parm->parm.output.timeperframe;
377
Laurent Pinchartff924202008-12-28 22:32:29 -0300378 interval = uvc_fraction_to_interval(timeperframe.numerator,
379 timeperframe.denominator);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300380 uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n",
Laurent Pinchartff924202008-12-28 22:32:29 -0300381 timeperframe.numerator, timeperframe.denominator, interval);
Laurent Pinchart69477562010-11-21 13:36:34 -0300382
383 mutex_lock(&stream->mutex);
384
385 if (uvc_queue_streaming(&stream->queue)) {
386 mutex_unlock(&stream->mutex);
387 return -EBUSY;
388 }
389
Ezequiel Garcia8c0d44e2013-01-14 15:22:55 -0300390 probe = stream->ctrl;
Laurent Pinchart69477562010-11-21 13:36:34 -0300391 probe.dwFrameInterval =
392 uvc_try_frame_interval(stream->cur_frame, interval);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300393
394 /* Probe the device with the new settings. */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300395 ret = uvc_probe_video(stream, &probe);
Laurent Pinchart69477562010-11-21 13:36:34 -0300396 if (ret < 0) {
397 mutex_unlock(&stream->mutex);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300398 return ret;
Laurent Pinchart69477562010-11-21 13:36:34 -0300399 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300400
Ezequiel Garcia8c0d44e2013-01-14 15:22:55 -0300401 stream->ctrl = probe;
Laurent Pinchart69477562010-11-21 13:36:34 -0300402 mutex_unlock(&stream->mutex);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300403
404 /* Return the actual frame period. */
Laurent Pinchartff924202008-12-28 22:32:29 -0300405 timeperframe.numerator = probe.dwFrameInterval;
406 timeperframe.denominator = 10000000;
407 uvc_simplify_fraction(&timeperframe.numerator,
408 &timeperframe.denominator, 8, 333);
409
410 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
411 parm->parm.capture.timeperframe = timeperframe;
412 else
413 parm->parm.output.timeperframe = timeperframe;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300414
415 return 0;
416}
417
418/* ------------------------------------------------------------------------
419 * Privilege management
420 */
421
422/*
423 * Privilege management is the multiple-open implementation basis. The current
424 * implementation is completely transparent for the end-user and doesn't
425 * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls.
426 * Those ioctls enable finer control on the device (by making possible for a
427 * user to request exclusive access to a device), but are not mature yet.
428 * Switching to the V4L2 priority mechanism might be considered in the future
429 * if this situation changes.
430 *
431 * Each open instance of a UVC device can either be in a privileged or
432 * unprivileged state. Only a single instance can be in a privileged state at
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300433 * a given time. Trying to perform an operation that requires privileges will
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300434 * automatically acquire the required privileges if possible, or return -EBUSY
Laurent Pinchart1a969d92009-09-02 03:12:26 -0300435 * otherwise. Privileges are dismissed when closing the instance or when
436 * freeing the video buffers using VIDIOC_REQBUFS.
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300437 *
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300438 * Operations that require privileges are:
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300439 *
440 * - VIDIOC_S_INPUT
441 * - VIDIOC_S_PARM
442 * - VIDIOC_S_FMT
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300443 * - VIDIOC_REQBUFS
444 */
445static int uvc_acquire_privileges(struct uvc_fh *handle)
446{
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300447 /* Always succeed if the handle is already privileged. */
448 if (handle->state == UVC_HANDLE_ACTIVE)
449 return 0;
450
451 /* Check if the device already has a privileged handle. */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300452 if (atomic_inc_return(&handle->stream->active) != 1) {
453 atomic_dec(&handle->stream->active);
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300454 return -EBUSY;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300455 }
456
457 handle->state = UVC_HANDLE_ACTIVE;
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300458 return 0;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300459}
460
461static void uvc_dismiss_privileges(struct uvc_fh *handle)
462{
463 if (handle->state == UVC_HANDLE_ACTIVE)
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300464 atomic_dec(&handle->stream->active);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300465
466 handle->state = UVC_HANDLE_PASSIVE;
467}
468
469static int uvc_has_privileges(struct uvc_fh *handle)
470{
471 return handle->state == UVC_HANDLE_ACTIVE;
472}
473
474/* ------------------------------------------------------------------------
475 * V4L2 file operations
476 */
477
Hans Verkuilbec43662008-12-30 06:58:20 -0300478static int uvc_v4l2_open(struct file *file)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300479{
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300480 struct uvc_streaming *stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300481 struct uvc_fh *handle;
482 int ret = 0;
483
484 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300485 stream = video_drvdata(file);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300486
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300487 if (stream->dev->state & UVC_DEV_DISCONNECTED)
488 return -ENODEV;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300489
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300490 ret = usb_autopm_get_interface(stream->dev->intf);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300491 if (ret < 0)
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300492 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300493
494 /* Create the device handle. */
495 handle = kzalloc(sizeof *handle, GFP_KERNEL);
496 if (handle == NULL) {
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300497 usb_autopm_put_interface(stream->dev->intf);
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300498 return -ENOMEM;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300499 }
500
Laurent Pinchart17706f52013-04-25 22:28:51 -0300501 mutex_lock(&stream->dev->lock);
502 if (stream->dev->users == 0) {
503 ret = uvc_status_start(stream->dev, GFP_KERNEL);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300504 if (ret < 0) {
Laurent Pinchart17706f52013-04-25 22:28:51 -0300505 mutex_unlock(&stream->dev->lock);
Oliver Neukuma82a45f2013-01-10 07:04:55 -0300506 usb_autopm_put_interface(stream->dev->intf);
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300507 kfree(handle);
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300508 return ret;
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300509 }
510 }
511
Laurent Pinchart17706f52013-04-25 22:28:51 -0300512 stream->dev->users++;
513 mutex_unlock(&stream->dev->lock);
514
Hans de Goedeb4012002012-04-08 12:59:51 -0300515 v4l2_fh_init(&handle->vfh, stream->vdev);
516 v4l2_fh_add(&handle->vfh);
Laurent Pinchart8e113592009-07-01 20:24:47 -0300517 handle->chain = stream->chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300518 handle->stream = stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300519 handle->state = UVC_HANDLE_PASSIVE;
520 file->private_data = handle;
521
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300522 return 0;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300523}
524
Hans Verkuilbec43662008-12-30 06:58:20 -0300525static int uvc_v4l2_release(struct file *file)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300526{
Joe Perchesabf84382010-07-12 17:50:03 -0300527 struct uvc_fh *handle = file->private_data;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300528 struct uvc_streaming *stream = handle->stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300529
530 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
531
532 /* Only free resources if this is a privileged handle. */
533 if (uvc_has_privileges(handle)) {
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300534 uvc_video_enable(stream, 0);
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300535 uvc_free_buffers(&stream->queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300536 }
537
538 /* Release the file handle. */
539 uvc_dismiss_privileges(handle);
Hans de Goedeb4012002012-04-08 12:59:51 -0300540 v4l2_fh_del(&handle->vfh);
541 v4l2_fh_exit(&handle->vfh);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300542 kfree(handle);
543 file->private_data = NULL;
544
Laurent Pinchart17706f52013-04-25 22:28:51 -0300545 mutex_lock(&stream->dev->lock);
546 if (--stream->dev->users == 0)
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300547 uvc_status_stop(stream->dev);
Laurent Pinchart17706f52013-04-25 22:28:51 -0300548 mutex_unlock(&stream->dev->lock);
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300549
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300550 usb_autopm_put_interface(stream->dev->intf);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300551 return 0;
552}
553
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300554static int uvc_ioctl_querycap(struct file *file, void *fh,
555 struct v4l2_capability *cap)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300556{
557 struct video_device *vdev = video_devdata(file);
Joe Perchesabf84382010-07-12 17:50:03 -0300558 struct uvc_fh *handle = file->private_data;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300559 struct uvc_video_chain *chain = handle->chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300560 struct uvc_streaming *stream = handle->stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300561
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300562 strlcpy(cap->driver, "uvcvideo", sizeof(cap->driver));
563 strlcpy(cap->card, vdev->name, sizeof(cap->card));
564 usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info));
565 cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
566 | chain->caps;
567 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
568 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
569 else
570 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300571
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300572 return 0;
573}
574
575static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream,
576 struct v4l2_fmtdesc *fmt)
577{
578 struct uvc_format *format;
579 enum v4l2_buf_type type = fmt->type;
580 __u32 index = fmt->index;
581
582 if (fmt->type != stream->type || fmt->index >= stream->nformats)
583 return -EINVAL;
584
585 memset(fmt, 0, sizeof(*fmt));
586 fmt->index = index;
587 fmt->type = type;
588
589 format = &stream->format[fmt->index];
590 fmt->flags = 0;
591 if (format->flags & UVC_FMT_FLAG_COMPRESSED)
592 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
593 strlcpy(fmt->description, format->name, sizeof(fmt->description));
594 fmt->description[sizeof(fmt->description) - 1] = 0;
595 fmt->pixelformat = format->fcc;
596 return 0;
597}
598
599static int uvc_ioctl_enum_fmt_vid_cap(struct file *file, void *fh,
600 struct v4l2_fmtdesc *fmt)
601{
602 struct uvc_fh *handle = fh;
603 struct uvc_streaming *stream = handle->stream;
604
605 return uvc_ioctl_enum_fmt(stream, fmt);
606}
607
608static int uvc_ioctl_enum_fmt_vid_out(struct file *file, void *fh,
609 struct v4l2_fmtdesc *fmt)
610{
611 struct uvc_fh *handle = fh;
612 struct uvc_streaming *stream = handle->stream;
613
614 return uvc_ioctl_enum_fmt(stream, fmt);
615}
616
617static int uvc_ioctl_g_fmt_vid_cap(struct file *file, void *fh,
618 struct v4l2_format *fmt)
619{
620 struct uvc_fh *handle = fh;
621 struct uvc_streaming *stream = handle->stream;
622
623 return uvc_v4l2_get_format(stream, fmt);
624}
625
626static int uvc_ioctl_g_fmt_vid_out(struct file *file, void *fh,
627 struct v4l2_format *fmt)
628{
629 struct uvc_fh *handle = fh;
630 struct uvc_streaming *stream = handle->stream;
631
632 return uvc_v4l2_get_format(stream, fmt);
633}
634
635static int uvc_ioctl_s_fmt_vid_cap(struct file *file, void *fh,
636 struct v4l2_format *fmt)
637{
638 struct uvc_fh *handle = fh;
639 struct uvc_streaming *stream = handle->stream;
640 int ret;
641
642 ret = uvc_acquire_privileges(handle);
643 if (ret < 0)
644 return ret;
645
646 return uvc_v4l2_set_format(stream, fmt);
647}
648
649static int uvc_ioctl_s_fmt_vid_out(struct file *file, void *fh,
650 struct v4l2_format *fmt)
651{
652 struct uvc_fh *handle = fh;
653 struct uvc_streaming *stream = handle->stream;
654 int ret;
655
656 ret = uvc_acquire_privileges(handle);
657 if (ret < 0)
658 return ret;
659
660 return uvc_v4l2_set_format(stream, fmt);
661}
662
663static int uvc_ioctl_try_fmt_vid_cap(struct file *file, void *fh,
664 struct v4l2_format *fmt)
665{
666 struct uvc_fh *handle = fh;
667 struct uvc_streaming *stream = handle->stream;
668 struct uvc_streaming_control probe;
669
670 return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL);
671}
672
673static int uvc_ioctl_try_fmt_vid_out(struct file *file, void *fh,
674 struct v4l2_format *fmt)
675{
676 struct uvc_fh *handle = fh;
677 struct uvc_streaming *stream = handle->stream;
678 struct uvc_streaming_control probe;
679
680 return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL);
681}
682
683static int uvc_ioctl_reqbufs(struct file *file, void *fh,
684 struct v4l2_requestbuffers *rb)
685{
686 struct uvc_fh *handle = fh;
687 struct uvc_streaming *stream = handle->stream;
688 int ret;
689
690 ret = uvc_acquire_privileges(handle);
691 if (ret < 0)
692 return ret;
693
694 mutex_lock(&stream->mutex);
695 ret = uvc_alloc_buffers(&stream->queue, rb);
696 mutex_unlock(&stream->mutex);
697 if (ret < 0)
698 return ret;
699
700 if (ret == 0)
701 uvc_dismiss_privileges(handle);
702
703 return 0;
704}
705
706static int uvc_ioctl_querybuf(struct file *file, void *fh,
707 struct v4l2_buffer *buf)
708{
709 struct uvc_fh *handle = fh;
710 struct uvc_streaming *stream = handle->stream;
711
712 if (!uvc_has_privileges(handle))
713 return -EBUSY;
714
715 return uvc_query_buffer(&stream->queue, buf);
716}
717
718static int uvc_ioctl_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
719{
720 struct uvc_fh *handle = fh;
721 struct uvc_streaming *stream = handle->stream;
722
723 if (!uvc_has_privileges(handle))
724 return -EBUSY;
725
726 return uvc_queue_buffer(&stream->queue, buf);
727}
728
729static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
730{
731 struct uvc_fh *handle = fh;
732 struct uvc_streaming *stream = handle->stream;
733
734 if (!uvc_has_privileges(handle))
735 return -EBUSY;
736
737 return uvc_dequeue_buffer(&stream->queue, buf,
738 file->f_flags & O_NONBLOCK);
739}
740
741static int uvc_ioctl_create_bufs(struct file *file, void *fh,
742 struct v4l2_create_buffers *cb)
743{
744 struct uvc_fh *handle = fh;
745 struct uvc_streaming *stream = handle->stream;
746 int ret;
747
748 ret = uvc_acquire_privileges(handle);
749 if (ret < 0)
750 return ret;
751
752 return uvc_create_buffers(&stream->queue, cb);
753}
754
755static int uvc_ioctl_streamon(struct file *file, void *fh,
756 enum v4l2_buf_type type)
757{
758 struct uvc_fh *handle = fh;
759 struct uvc_streaming *stream = handle->stream;
760 int ret;
761
762 if (type != stream->type)
763 return -EINVAL;
764
765 if (!uvc_has_privileges(handle))
766 return -EBUSY;
767
768 mutex_lock(&stream->mutex);
769 ret = uvc_video_enable(stream, 1);
770 mutex_unlock(&stream->mutex);
771
772 return ret;
773}
774
775static int uvc_ioctl_streamoff(struct file *file, void *fh,
776 enum v4l2_buf_type type)
777{
778 struct uvc_fh *handle = fh;
779 struct uvc_streaming *stream = handle->stream;
780 int ret;
781
782 if (type != stream->type)
783 return -EINVAL;
784
785 if (!uvc_has_privileges(handle))
786 return -EBUSY;
787
788 mutex_lock(&stream->mutex);
789 ret = uvc_video_enable(stream, 0);
790 mutex_unlock(&stream->mutex);
791
792 return ret;
793}
794
795static int uvc_ioctl_enum_input(struct file *file, void *fh,
796 struct v4l2_input *input)
797{
798 struct uvc_fh *handle = fh;
799 struct uvc_video_chain *chain = handle->chain;
800 const struct uvc_entity *selector = chain->selector;
801 struct uvc_entity *iterm = NULL;
802 u32 index = input->index;
803 int pin = 0;
804
805 if (selector == NULL ||
806 (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
807 if (index != 0)
808 return -EINVAL;
809 list_for_each_entry(iterm, &chain->entities, chain) {
810 if (UVC_ENTITY_IS_ITERM(iterm))
811 break;
812 }
813 pin = iterm->id;
814 } else if (index < selector->bNrInPins) {
815 pin = selector->baSourceID[index];
816 list_for_each_entry(iterm, &chain->entities, chain) {
817 if (!UVC_ENTITY_IS_ITERM(iterm))
818 continue;
819 if (iterm->id == pin)
820 break;
821 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300822 }
823
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300824 if (iterm == NULL || iterm->id != pin)
825 return -EINVAL;
Laurent Pinchart05505132012-08-28 20:29:56 -0300826
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300827 memset(input, 0, sizeof(*input));
828 input->index = index;
829 strlcpy(input->name, iterm->name, sizeof(input->name));
830 if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA)
831 input->type = V4L2_INPUT_TYPE_CAMERA;
Laurent Pinchart05505132012-08-28 20:29:56 -0300832
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300833 return 0;
834}
Laurent Pinchart05505132012-08-28 20:29:56 -0300835
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300836static int uvc_ioctl_g_input(struct file *file, void *fh, unsigned int *input)
837{
838 struct uvc_fh *handle = fh;
839 struct uvc_video_chain *chain = handle->chain;
840 int ret;
841 u8 i;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300842
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300843 if (chain->selector == NULL ||
844 (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
845 *input = 0;
846 return 0;
847 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300848
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300849 ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, chain->selector->id,
850 chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL,
851 &i, 1);
852 if (ret < 0)
853 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300854
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300855 *input = i - 1;
856 return 0;
857}
Robert Krakora1fcbcc42009-06-12 13:51:03 -0300858
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300859static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input)
860{
861 struct uvc_fh *handle = fh;
862 struct uvc_video_chain *chain = handle->chain;
863 int ret;
864 u32 i;
865
866 ret = uvc_acquire_privileges(handle);
867 if (ret < 0)
868 return ret;
869
870 if (chain->selector == NULL ||
871 (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
872 if (input)
873 return -EINVAL;
874 return 0;
875 }
876
877 if (input >= chain->selector->bNrInPins)
878 return -EINVAL;
879
880 i = input + 1;
881 return uvc_query_ctrl(chain->dev, UVC_SET_CUR, chain->selector->id,
882 chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL,
883 &i, 1);
884}
885
886static int uvc_ioctl_queryctrl(struct file *file, void *fh,
887 struct v4l2_queryctrl *qc)
888{
889 struct uvc_fh *handle = fh;
890 struct uvc_video_chain *chain = handle->chain;
891
892 return uvc_query_v4l2_ctrl(chain, qc);
893}
894
895static int uvc_ioctl_g_ctrl(struct file *file, void *fh,
896 struct v4l2_control *ctrl)
897{
898 struct uvc_fh *handle = fh;
899 struct uvc_video_chain *chain = handle->chain;
900 struct v4l2_ext_control xctrl;
901 int ret;
902
903 memset(&xctrl, 0, sizeof(xctrl));
904 xctrl.id = ctrl->id;
905
906 ret = uvc_ctrl_begin(chain);
907 if (ret < 0)
908 return ret;
909
910 ret = uvc_ctrl_get(chain, &xctrl);
911 uvc_ctrl_rollback(handle);
912 if (ret < 0)
913 return ret;
914
915 ctrl->value = xctrl.value;
916 return 0;
917}
918
919static int uvc_ioctl_s_ctrl(struct file *file, void *fh,
920 struct v4l2_control *ctrl)
921{
922 struct uvc_fh *handle = fh;
923 struct uvc_video_chain *chain = handle->chain;
924 struct v4l2_ext_control xctrl;
925 int ret;
926
927 memset(&xctrl, 0, sizeof(xctrl));
928 xctrl.id = ctrl->id;
929 xctrl.value = ctrl->value;
930
931 ret = uvc_ctrl_begin(chain);
932 if (ret < 0)
933 return ret;
934
935 ret = uvc_ctrl_set(chain, &xctrl);
936 if (ret < 0) {
Hans de Goedeb4012002012-04-08 12:59:51 -0300937 uvc_ctrl_rollback(handle);
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300938 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300939 }
940
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300941 ret = uvc_ctrl_commit(handle, &xctrl, 1);
942 if (ret < 0)
943 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300944
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300945 ctrl->value = xctrl.value;
946 return 0;
947}
Laurent Pinchart05505132012-08-28 20:29:56 -0300948
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300949static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,
950 struct v4l2_ext_controls *ctrls)
951{
952 struct uvc_fh *handle = fh;
953 struct uvc_video_chain *chain = handle->chain;
954 struct v4l2_ext_control *ctrl = ctrls->controls;
955 unsigned int i;
956 int ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300957
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300958 ret = uvc_ctrl_begin(chain);
959 if (ret < 0)
960 return ret;
Robert Krakora1fcbcc42009-06-12 13:51:03 -0300961
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300962 for (i = 0; i < ctrls->count; ++ctrl, ++i) {
963 ret = uvc_ctrl_get(chain, ctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300964 if (ret < 0) {
Hans de Goedeb4012002012-04-08 12:59:51 -0300965 uvc_ctrl_rollback(handle);
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300966 ctrls->error_idx = i;
Rafael J. Wysocki9c016d62012-12-23 14:39:32 +0100967 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300968 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300969 }
970
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300971 ctrls->error_idx = 0;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300972
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300973 return uvc_ctrl_rollback(handle);
974}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300975
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300976static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
977 struct v4l2_ext_controls *ctrls,
978 bool commit)
979{
980 struct v4l2_ext_control *ctrl = ctrls->controls;
981 struct uvc_video_chain *chain = handle->chain;
982 unsigned int i;
983 int ret;
984
985 ret = uvc_ctrl_begin(chain);
986 if (ret < 0)
987 return ret;
988
989 for (i = 0; i < ctrls->count; ++ctrl, ++i) {
990 ret = uvc_ctrl_set(chain, ctrl);
991 if (ret < 0) {
992 uvc_ctrl_rollback(handle);
993 ctrls->error_idx = commit ? ctrls->count : i;
Robert Krakora1fcbcc42009-06-12 13:51:03 -0300994 return ret;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300995 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300996 }
997
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300998 ctrls->error_idx = 0;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300999
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001000 if (commit)
1001 return uvc_ctrl_commit(handle, ctrls->controls, ctrls->count);
1002 else
1003 return uvc_ctrl_rollback(handle);
1004}
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001005
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001006static int uvc_ioctl_s_ext_ctrls(struct file *file, void *fh,
1007 struct v4l2_ext_controls *ctrls)
1008{
1009 struct uvc_fh *handle = fh;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001010
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001011 return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, true);
1012}
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001013
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001014static int uvc_ioctl_try_ext_ctrls(struct file *file, void *fh,
1015 struct v4l2_ext_controls *ctrls)
1016{
1017 struct uvc_fh *handle = fh;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001018
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001019 return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, false);
1020}
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001021
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001022static int uvc_ioctl_querymenu(struct file *file, void *fh,
1023 struct v4l2_querymenu *qm)
1024{
1025 struct uvc_fh *handle = fh;
1026 struct uvc_video_chain *chain = handle->chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001027
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001028 return uvc_query_v4l2_menu(chain, qm);
1029}
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001030
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001031static int uvc_ioctl_cropcap(struct file *file, void *fh,
1032 struct v4l2_cropcap *ccap)
1033{
1034 struct uvc_fh *handle = fh;
1035 struct uvc_streaming *stream = handle->stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001036
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001037 if (ccap->type != stream->type)
1038 return -EINVAL;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001039
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001040 ccap->bounds.left = 0;
1041 ccap->bounds.top = 0;
1042 mutex_lock(&stream->mutex);
1043 ccap->bounds.width = stream->cur_frame->wWidth;
1044 ccap->bounds.height = stream->cur_frame->wHeight;
1045 mutex_unlock(&stream->mutex);
1046
1047 ccap->defrect = ccap->bounds;
1048
1049 ccap->pixelaspect.numerator = 1;
1050 ccap->pixelaspect.denominator = 1;
1051 return 0;
1052}
1053
1054static int uvc_ioctl_g_parm(struct file *file, void *fh,
1055 struct v4l2_streamparm *parm)
1056{
1057 struct uvc_fh *handle = fh;
1058 struct uvc_streaming *stream = handle->stream;
1059
1060 return uvc_v4l2_get_streamparm(stream, parm);
1061}
1062
1063static int uvc_ioctl_s_parm(struct file *file, void *fh,
1064 struct v4l2_streamparm *parm)
1065{
1066 struct uvc_fh *handle = fh;
1067 struct uvc_streaming *stream = handle->stream;
1068 int ret;
1069
1070 ret = uvc_acquire_privileges(handle);
1071 if (ret < 0)
1072 return ret;
1073
1074 return uvc_v4l2_set_streamparm(stream, parm);
1075}
1076
1077static int uvc_ioctl_enum_framesizes(struct file *file, void *fh,
1078 struct v4l2_frmsizeenum *fsize)
1079{
1080 struct uvc_fh *handle = fh;
1081 struct uvc_streaming *stream = handle->stream;
1082 struct uvc_format *format = NULL;
1083 struct uvc_frame *frame;
1084 int i;
1085
1086 /* Look for the given pixel format */
1087 for (i = 0; i < stream->nformats; i++) {
1088 if (stream->format[i].fcc == fsize->pixel_format) {
1089 format = &stream->format[i];
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001090 break;
1091 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001092 }
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001093 if (format == NULL)
1094 return -EINVAL;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001095
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001096 if (fsize->index >= format->nframes)
1097 return -EINVAL;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001098
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001099 frame = &format->frame[fsize->index];
1100 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1101 fsize->discrete.width = frame->wWidth;
1102 fsize->discrete.height = frame->wHeight;
1103 return 0;
1104}
Laurent Pinchart05505132012-08-28 20:29:56 -03001105
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001106static int uvc_ioctl_enum_frameintervals(struct file *file, void *fh,
1107 struct v4l2_frmivalenum *fival)
1108{
1109 struct uvc_fh *handle = fh;
1110 struct uvc_streaming *stream = handle->stream;
1111 struct uvc_format *format = NULL;
1112 struct uvc_frame *frame = NULL;
1113 int i;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001114
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001115 /* Look for the given pixel format and frame size */
1116 for (i = 0; i < stream->nformats; i++) {
1117 if (stream->format[i].fcc == fival->pixel_format) {
1118 format = &stream->format[i];
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001119 break;
1120 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001121 }
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001122 if (format == NULL)
1123 return -EINVAL;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001124
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001125 for (i = 0; i < format->nframes; i++) {
1126 if (format->frame[i].wWidth == fival->width &&
1127 format->frame[i].wHeight == fival->height) {
1128 frame = &format->frame[i];
1129 break;
Hans de Goedeb4012002012-04-08 12:59:51 -03001130 }
1131 }
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001132 if (frame == NULL)
1133 return -EINVAL;
Hans de Goedeb4012002012-04-08 12:59:51 -03001134
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001135 if (frame->bFrameIntervalType) {
1136 if (fival->index >= frame->bFrameIntervalType)
1137 return -EINVAL;
Hans de Goedeb4012002012-04-08 12:59:51 -03001138
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001139 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
1140 fival->discrete.numerator =
1141 frame->dwFrameInterval[fival->index];
1142 fival->discrete.denominator = 10000000;
1143 uvc_simplify_fraction(&fival->discrete.numerator,
1144 &fival->discrete.denominator, 8, 333);
1145 } else {
1146 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
1147 fival->stepwise.min.numerator = frame->dwFrameInterval[0];
1148 fival->stepwise.min.denominator = 10000000;
1149 fival->stepwise.max.numerator = frame->dwFrameInterval[1];
1150 fival->stepwise.max.denominator = 10000000;
1151 fival->stepwise.step.numerator = frame->dwFrameInterval[2];
1152 fival->stepwise.step.denominator = 10000000;
1153 uvc_simplify_fraction(&fival->stepwise.min.numerator,
1154 &fival->stepwise.min.denominator, 8, 333);
1155 uvc_simplify_fraction(&fival->stepwise.max.numerator,
1156 &fival->stepwise.max.denominator, 8, 333);
1157 uvc_simplify_fraction(&fival->stepwise.step.numerator,
1158 &fival->stepwise.step.denominator, 8, 333);
1159 }
Hans de Goedeb4012002012-04-08 12:59:51 -03001160
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001161 return 0;
1162}
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001163
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001164static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh,
1165 const struct v4l2_event_subscription *sub)
1166{
1167 switch (sub->type) {
1168 case V4L2_EVENT_CTRL:
1169 return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops);
1170 default:
1171 return -EINVAL;
1172 }
1173}
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001174
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001175static long uvc_ioctl_default(struct file *file, void *fh, bool valid_prio,
1176 unsigned int cmd, void *arg)
1177{
1178 struct uvc_fh *handle = fh;
1179 struct uvc_video_chain *chain = handle->chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001180
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001181 switch (cmd) {
1182 /* Dynamic controls. */
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001183 case UVCIOC_CTRL_MAP:
Laurent Pinchart227bd5b2011-07-30 16:19:49 -03001184 return uvc_ioctl_ctrl_map(chain, arg);
Martin Rublife78d182010-10-02 19:10:16 -03001185
1186 case UVCIOC_CTRL_QUERY:
1187 return uvc_xu_ctrl_query(chain, arg);
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001188
1189 default:
Laurent Pincharta3ec69b2011-12-18 20:22:50 -03001190 return -ENOTTY;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001191 }
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001192}
1193
Laurent Pinchart1a5e4c82011-12-18 20:45:39 -03001194#ifdef CONFIG_COMPAT
1195struct uvc_xu_control_mapping32 {
1196 __u32 id;
1197 __u8 name[32];
1198 __u8 entity[16];
1199 __u8 selector;
1200
1201 __u8 size;
1202 __u8 offset;
1203 __u32 v4l2_type;
1204 __u32 data_type;
1205
1206 compat_caddr_t menu_info;
1207 __u32 menu_count;
1208
1209 __u32 reserved[4];
1210};
1211
1212static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
1213 const struct uvc_xu_control_mapping32 __user *up)
1214{
1215 struct uvc_menu_info __user *umenus;
1216 struct uvc_menu_info __user *kmenus;
1217 compat_caddr_t p;
1218
1219 if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
1220 __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) ||
1221 __get_user(kp->menu_count, &up->menu_count))
1222 return -EFAULT;
1223
1224 memset(kp->reserved, 0, sizeof(kp->reserved));
1225
1226 if (kp->menu_count == 0) {
1227 kp->menu_info = NULL;
1228 return 0;
1229 }
1230
1231 if (__get_user(p, &up->menu_info))
1232 return -EFAULT;
1233 umenus = compat_ptr(p);
1234 if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus)))
1235 return -EFAULT;
1236
1237 kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus));
1238 if (kmenus == NULL)
1239 return -EFAULT;
1240 kp->menu_info = kmenus;
1241
1242 if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus)))
1243 return -EFAULT;
1244
1245 return 0;
1246}
1247
1248static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
1249 struct uvc_xu_control_mapping32 __user *up)
1250{
1251 struct uvc_menu_info __user *umenus;
1252 struct uvc_menu_info __user *kmenus = kp->menu_info;
1253 compat_caddr_t p;
1254
1255 if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
1256 __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
1257 __put_user(kp->menu_count, &up->menu_count))
1258 return -EFAULT;
1259
Hans de Goede57fb4a42012-04-08 12:59:48 -03001260 if (__clear_user(up->reserved, sizeof(up->reserved)))
1261 return -EFAULT;
Laurent Pinchart1a5e4c82011-12-18 20:45:39 -03001262
1263 if (kp->menu_count == 0)
1264 return 0;
1265
1266 if (get_user(p, &up->menu_info))
1267 return -EFAULT;
1268 umenus = compat_ptr(p);
Laurent Pinchart1a5e4c82011-12-18 20:45:39 -03001269
1270 if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus)))
1271 return -EFAULT;
1272
1273 return 0;
1274}
1275
1276struct uvc_xu_control_query32 {
1277 __u8 unit;
1278 __u8 selector;
1279 __u8 query;
1280 __u16 size;
1281 compat_caddr_t data;
1282};
1283
1284static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
1285 const struct uvc_xu_control_query32 __user *up)
1286{
1287 u8 __user *udata;
1288 u8 __user *kdata;
1289 compat_caddr_t p;
1290
1291 if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
1292 __copy_from_user(kp, up, offsetof(typeof(*up), data)))
1293 return -EFAULT;
1294
1295 if (kp->size == 0) {
1296 kp->data = NULL;
1297 return 0;
1298 }
1299
1300 if (__get_user(p, &up->data))
1301 return -EFAULT;
1302 udata = compat_ptr(p);
1303 if (!access_ok(VERIFY_READ, udata, kp->size))
1304 return -EFAULT;
1305
1306 kdata = compat_alloc_user_space(kp->size);
1307 if (kdata == NULL)
1308 return -EFAULT;
1309 kp->data = kdata;
1310
1311 if (copy_in_user(kdata, udata, kp->size))
1312 return -EFAULT;
1313
1314 return 0;
1315}
1316
1317static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
1318 struct uvc_xu_control_query32 __user *up)
1319{
1320 u8 __user *udata;
1321 u8 __user *kdata = kp->data;
1322 compat_caddr_t p;
1323
1324 if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
1325 __copy_to_user(up, kp, offsetof(typeof(*up), data)))
1326 return -EFAULT;
1327
1328 if (kp->size == 0)
1329 return 0;
1330
1331 if (get_user(p, &up->data))
1332 return -EFAULT;
1333 udata = compat_ptr(p);
1334 if (!access_ok(VERIFY_READ, udata, kp->size))
1335 return -EFAULT;
1336
1337 if (copy_in_user(udata, kdata, kp->size))
1338 return -EFAULT;
1339
1340 return 0;
1341}
1342
1343#define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32)
1344#define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32)
1345
1346static long uvc_v4l2_compat_ioctl32(struct file *file,
1347 unsigned int cmd, unsigned long arg)
1348{
1349 union {
1350 struct uvc_xu_control_mapping xmap;
1351 struct uvc_xu_control_query xqry;
1352 } karg;
1353 void __user *up = compat_ptr(arg);
1354 mm_segment_t old_fs;
1355 long ret;
1356
1357 switch (cmd) {
1358 case UVCIOC_CTRL_MAP32:
1359 cmd = UVCIOC_CTRL_MAP;
1360 ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
1361 break;
1362
1363 case UVCIOC_CTRL_QUERY32:
1364 cmd = UVCIOC_CTRL_QUERY;
1365 ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
1366 break;
1367
1368 default:
1369 return -ENOIOCTLCMD;
1370 }
1371
1372 old_fs = get_fs();
1373 set_fs(KERNEL_DS);
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001374 ret = video_ioctl2(file, cmd, (unsigned long)&karg);
Laurent Pinchart1a5e4c82011-12-18 20:45:39 -03001375 set_fs(old_fs);
1376
1377 if (ret < 0)
1378 return ret;
1379
1380 switch (cmd) {
1381 case UVCIOC_CTRL_MAP:
1382 ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up);
1383 break;
1384
1385 case UVCIOC_CTRL_QUERY:
1386 ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
1387 break;
1388 }
1389
1390 return ret;
1391}
1392#endif
1393
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001394static ssize_t uvc_v4l2_read(struct file *file, char __user *data,
1395 size_t count, loff_t *ppos)
1396{
1397 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n");
Laurent Pinchart350d6402009-11-04 11:53:49 -03001398 return -EINVAL;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001399}
1400
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001401static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1402{
Joe Perchesabf84382010-07-12 17:50:03 -03001403 struct uvc_fh *handle = file->private_data;
Laurent Pinchart35f02a62009-06-28 08:37:50 -03001404 struct uvc_streaming *stream = handle->stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001405
1406 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n");
1407
Laurent Pinchart4aa27592010-11-21 15:18:08 -03001408 return uvc_queue_mmap(&stream->queue, vma);
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001409}
1410
1411static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
1412{
Joe Perchesabf84382010-07-12 17:50:03 -03001413 struct uvc_fh *handle = file->private_data;
Laurent Pinchart35f02a62009-06-28 08:37:50 -03001414 struct uvc_streaming *stream = handle->stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001415
1416 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
1417
Laurent Pinchart35f02a62009-06-28 08:37:50 -03001418 return uvc_queue_poll(&stream->queue, file, wait);
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001419}
1420
Bob Liu72969442011-04-29 07:11:35 -03001421#ifndef CONFIG_MMU
1422static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
1423 unsigned long addr, unsigned long len, unsigned long pgoff,
1424 unsigned long flags)
1425{
1426 struct uvc_fh *handle = file->private_data;
1427 struct uvc_streaming *stream = handle->stream;
1428
1429 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n");
1430
1431 return uvc_queue_get_unmapped_area(&stream->queue, pgoff);
1432}
1433#endif
1434
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001435const struct v4l2_ioctl_ops uvc_ioctl_ops = {
1436 .vidioc_querycap = uvc_ioctl_querycap,
1437 .vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt_vid_cap,
1438 .vidioc_enum_fmt_vid_out = uvc_ioctl_enum_fmt_vid_out,
1439 .vidioc_g_fmt_vid_cap = uvc_ioctl_g_fmt_vid_cap,
1440 .vidioc_g_fmt_vid_out = uvc_ioctl_g_fmt_vid_out,
1441 .vidioc_s_fmt_vid_cap = uvc_ioctl_s_fmt_vid_cap,
1442 .vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt_vid_out,
1443 .vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt_vid_cap,
1444 .vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt_vid_out,
1445 .vidioc_reqbufs = uvc_ioctl_reqbufs,
1446 .vidioc_querybuf = uvc_ioctl_querybuf,
1447 .vidioc_qbuf = uvc_ioctl_qbuf,
1448 .vidioc_dqbuf = uvc_ioctl_dqbuf,
1449 .vidioc_create_bufs = uvc_ioctl_create_bufs,
1450 .vidioc_streamon = uvc_ioctl_streamon,
1451 .vidioc_streamoff = uvc_ioctl_streamoff,
1452 .vidioc_enum_input = uvc_ioctl_enum_input,
1453 .vidioc_g_input = uvc_ioctl_g_input,
1454 .vidioc_s_input = uvc_ioctl_s_input,
1455 .vidioc_queryctrl = uvc_ioctl_queryctrl,
1456 .vidioc_g_ctrl = uvc_ioctl_g_ctrl,
1457 .vidioc_s_ctrl = uvc_ioctl_s_ctrl,
1458 .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls,
1459 .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls,
1460 .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls,
1461 .vidioc_querymenu = uvc_ioctl_querymenu,
1462 .vidioc_cropcap = uvc_ioctl_cropcap,
1463 .vidioc_g_parm = uvc_ioctl_g_parm,
1464 .vidioc_s_parm = uvc_ioctl_s_parm,
1465 .vidioc_enum_framesizes = uvc_ioctl_enum_framesizes,
1466 .vidioc_enum_frameintervals = uvc_ioctl_enum_frameintervals,
1467 .vidioc_subscribe_event = uvc_ioctl_subscribe_event,
1468 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1469 .vidioc_default = uvc_ioctl_default,
1470};
1471
Hans Verkuilbec43662008-12-30 06:58:20 -03001472const struct v4l2_file_operations uvc_fops = {
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001473 .owner = THIS_MODULE,
1474 .open = uvc_v4l2_open,
1475 .release = uvc_v4l2_release,
Laurent Pinchartd5e90b72010-09-30 10:17:54 -03001476 .unlocked_ioctl = video_ioctl2,
Laurent Pinchart1a5e4c82011-12-18 20:45:39 -03001477#ifdef CONFIG_COMPAT
1478 .compat_ioctl32 = uvc_v4l2_compat_ioctl32,
1479#endif
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001480 .read = uvc_v4l2_read,
1481 .mmap = uvc_v4l2_mmap,
1482 .poll = uvc_v4l2_poll,
Bob Liu72969442011-04-29 07:11:35 -03001483#ifndef CONFIG_MMU
1484 .get_unmapped_area = uvc_v4l2_get_unmapped_area,
1485#endif
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001486};
Hans Verkuilf87086e2008-07-18 00:50:58 -03001487