uvc_v4l2.c 32.2 KB
Newer Older
1 2 3
/*
 *      uvc_v4l2.c  --  USB Video Class driver - V4L2 API
 *
4 5
 *      Copyright (C) 2005-2010
 *          Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 7 8 9 10 11 12 13
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 */

14
#include <linux/compat.h>
15 16 17 18
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/list.h>
#include <linux/module.h>
19
#include <linux/slab.h>
20 21 22 23 24
#include <linux/usb.h>
#include <linux/videodev2.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/wait.h>
A
Arun Sharma 已提交
25
#include <linux/atomic.h>
26 27

#include <media/v4l2-common.h>
28 29
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
30
#include <media/v4l2-ioctl.h>
31 32 33

#include "uvcvideo.h"

34 35 36
/* ------------------------------------------------------------------------
 * UVC ioctls
 */
37
static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
38
	struct uvc_xu_control_mapping *xmap)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
{
	struct uvc_control_mapping *map;
	unsigned int size;
	int ret;

	map = kzalloc(sizeof *map, GFP_KERNEL);
	if (map == NULL)
		return -ENOMEM;

	map->id = xmap->id;
	memcpy(map->name, xmap->name, sizeof map->name);
	memcpy(map->entity, xmap->entity, sizeof map->entity);
	map->selector = xmap->selector;
	map->size = xmap->size;
	map->offset = xmap->offset;
	map->v4l2_type = xmap->v4l2_type;
	map->data_type = xmap->data_type;

	switch (xmap->v4l2_type) {
	case V4L2_CTRL_TYPE_INTEGER:
	case V4L2_CTRL_TYPE_BOOLEAN:
	case V4L2_CTRL_TYPE_BUTTON:
		break;

	case V4L2_CTRL_TYPE_MENU:
64 65 66 67 68 69 70 71 72
		/* Prevent excessive memory consumption, as well as integer
		 * overflows.
		 */
		if (xmap->menu_count == 0 ||
		    xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) {
			ret = -EINVAL;
			goto done;
		}

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
		size = xmap->menu_count * sizeof(*map->menu_info);
		map->menu_info = kmalloc(size, GFP_KERNEL);
		if (map->menu_info == NULL) {
			ret = -ENOMEM;
			goto done;
		}

		if (copy_from_user(map->menu_info, xmap->menu_info, size)) {
			ret = -EFAULT;
			goto done;
		}

		map->menu_count = xmap->menu_count;
		break;

	default:
89 90
		uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type "
			  "%u.\n", xmap->v4l2_type);
91
		ret = -ENOTTY;
92 93 94
		goto done;
	}

95
	ret = uvc_ctrl_add_mapping(chain, map);
96 97

done:
98 99
	kfree(map->menu_info);
	kfree(map);
100 101 102 103

	return ret;
}

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
/* ------------------------------------------------------------------------
 * V4L2 interface
 */

/*
 * Find the frame interval closest to the requested frame interval for the
 * given frame format and size. This should be done by the device as part of
 * the Video Probe and Commit negotiation, but some hardware don't implement
 * that feature.
 */
static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval)
{
	unsigned int i;

	if (frame->bFrameIntervalType) {
		__u32 best = -1, dist;

		for (i = 0; i < frame->bFrameIntervalType; ++i) {
			dist = interval > frame->dwFrameInterval[i]
			     ? interval - frame->dwFrameInterval[i]
			     : frame->dwFrameInterval[i] - interval;

			if (dist > best)
				break;

			best = dist;
		}

		interval = frame->dwFrameInterval[i-1];
	} else {
		const __u32 min = frame->dwFrameInterval[0];
		const __u32 max = frame->dwFrameInterval[1];
		const __u32 step = frame->dwFrameInterval[2];

		interval = min + (interval - min + step/2) / step * step;
		if (interval > max)
			interval = max;
	}

	return interval;
}

146
static int uvc_v4l2_try_format(struct uvc_streaming *stream,
147 148 149 150 151 152 153 154 155 156 157 158
	struct v4l2_format *fmt, struct uvc_streaming_control *probe,
	struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
{
	struct uvc_format *format = NULL;
	struct uvc_frame *frame = NULL;
	__u16 rw, rh;
	unsigned int d, maxd;
	unsigned int i;
	__u32 interval;
	int ret = 0;
	__u8 *fcc;

159
	if (fmt->type != stream->type)
160 161 162 163 164 165 166 167
		return -EINVAL;

	fcc = (__u8 *)&fmt->fmt.pix.pixelformat;
	uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n",
			fmt->fmt.pix.pixelformat,
			fcc[0], fcc[1], fcc[2], fcc[3],
			fmt->fmt.pix.width, fmt->fmt.pix.height);

168 169 170
	/* Check if the hardware supports the requested format, use the default
	 * format otherwise.
	 */
171 172
	for (i = 0; i < stream->nformats; ++i) {
		format = &stream->format[i];
173 174 175 176
		if (format->fcc == fmt->fmt.pix.pixelformat)
			break;
	}

177 178 179
	if (i == stream->nformats) {
		format = stream->def_format;
		fmt->fmt.pix.pixelformat = format->fcc;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
	}

	/* Find the closest image size. The distance between image sizes is
	 * the size in pixels of the non-overlapping regions between the
	 * requested size and the frame-specified size.
	 */
	rw = fmt->fmt.pix.width;
	rh = fmt->fmt.pix.height;
	maxd = (unsigned int)-1;

	for (i = 0; i < format->nframes; ++i) {
		__u16 w = format->frame[i].wWidth;
		__u16 h = format->frame[i].wHeight;

		d = min(w, rw) * min(h, rh);
		d = w*h + rw*rh - 2*d;
		if (d < maxd) {
			maxd = d;
			frame = &format->frame[i];
		}

		if (maxd == 0)
			break;
	}

	if (frame == NULL) {
		uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n",
				fmt->fmt.pix.width, fmt->fmt.pix.height);
		return -EINVAL;
	}

	/* Use the default frame interval. */
	interval = frame->dwDefaultFrameInterval;
	uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us "
		"(%u.%u fps).\n", interval/10, interval%10, 10000000/interval,
		(100000000/interval)%10);

	/* Set the format index, frame index and frame interval. */
	memset(probe, 0, sizeof *probe);
	probe->bmHint = 1;	/* dwFrameInterval */
	probe->bFormatIndex = format->index;
	probe->bFrameIndex = frame->bFrameIndex;
	probe->dwFrameInterval = uvc_try_frame_interval(frame, interval);
	/* Some webcams stall the probe control set request when the
	 * dwMaxVideoFrameSize field is set to zero. The UVC specification
	 * clearly states that the field is read-only from the host, so this
	 * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by
	 * the webcam to work around the problem.
	 *
	 * The workaround could probably be enabled for all webcams, so the
	 * quirk can be removed if needed. It's currently useful to detect
	 * webcam bugs and fix them before they hit the market (providing
	 * developers test their webcams with the Linux driver as well as with
	 * the Windows driver).
	 */
235
	mutex_lock(&stream->mutex);
236
	if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
237
		probe->dwMaxVideoFrameSize =
238
			stream->ctrl.dwMaxVideoFrameSize;
239

240
	/* Probe the device. */
241
	ret = uvc_probe_video(stream, probe);
242
	mutex_unlock(&stream->mutex);
243
	if (ret < 0)
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
		goto done;

	fmt->fmt.pix.width = frame->wWidth;
	fmt->fmt.pix.height = frame->wHeight;
	fmt->fmt.pix.field = V4L2_FIELD_NONE;
	fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
	fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
	fmt->fmt.pix.colorspace = format->colorspace;
	fmt->fmt.pix.priv = 0;

	if (uvc_format != NULL)
		*uvc_format = format;
	if (uvc_frame != NULL)
		*uvc_frame = frame;

done:
	return ret;
}

263
static int uvc_v4l2_get_format(struct uvc_streaming *stream,
264 265
	struct v4l2_format *fmt)
{
266 267 268
	struct uvc_format *format;
	struct uvc_frame *frame;
	int ret = 0;
269

270
	if (fmt->type != stream->type)
271 272
		return -EINVAL;

273 274 275 276 277 278 279 280
	mutex_lock(&stream->mutex);
	format = stream->cur_format;
	frame = stream->cur_frame;

	if (format == NULL || frame == NULL) {
		ret = -EINVAL;
		goto done;
	}
281 282 283 284 285 286

	fmt->fmt.pix.pixelformat = format->fcc;
	fmt->fmt.pix.width = frame->wWidth;
	fmt->fmt.pix.height = frame->wHeight;
	fmt->fmt.pix.field = V4L2_FIELD_NONE;
	fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
287
	fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize;
288 289 290
	fmt->fmt.pix.colorspace = format->colorspace;
	fmt->fmt.pix.priv = 0;

291 292 293
done:
	mutex_unlock(&stream->mutex);
	return ret;
294 295
}

296
static int uvc_v4l2_set_format(struct uvc_streaming *stream,
297 298 299 300 301 302 303
	struct v4l2_format *fmt)
{
	struct uvc_streaming_control probe;
	struct uvc_format *format;
	struct uvc_frame *frame;
	int ret;

304
	if (fmt->type != stream->type)
305 306
		return -EINVAL;

307
	ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);
308 309 310
	if (ret < 0)
		return ret;

311 312 313 314 315 316 317
	mutex_lock(&stream->mutex);

	if (uvc_queue_allocated(&stream->queue)) {
		ret = -EBUSY;
		goto done;
	}

318 319 320
	memcpy(&stream->ctrl, &probe, sizeof probe);
	stream->cur_format = format;
	stream->cur_frame = frame;
321

322 323 324
done:
	mutex_unlock(&stream->mutex);
	return ret;
325 326
}

327
static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
328 329 330 331
		struct v4l2_streamparm *parm)
{
	uint32_t numerator, denominator;

332
	if (parm->type != stream->type)
333 334
		return -EINVAL;

335
	mutex_lock(&stream->mutex);
336
	numerator = stream->ctrl.dwFrameInterval;
337 338
	mutex_unlock(&stream->mutex);

339 340 341 342
	denominator = 10000000;
	uvc_simplify_fraction(&numerator, &denominator, 8, 333);

	memset(parm, 0, sizeof *parm);
343
	parm->type = stream->type;
344

345
	if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
346 347 348 349 350 351 352 353 354 355 356 357
		parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
		parm->parm.capture.capturemode = 0;
		parm->parm.capture.timeperframe.numerator = numerator;
		parm->parm.capture.timeperframe.denominator = denominator;
		parm->parm.capture.extendedmode = 0;
		parm->parm.capture.readbuffers = 0;
	} else {
		parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
		parm->parm.output.outputmode = 0;
		parm->parm.output.timeperframe.numerator = numerator;
		parm->parm.output.timeperframe.denominator = denominator;
	}
358 359 360 361

	return 0;
}

362
static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
363 364 365
		struct v4l2_streamparm *parm)
{
	struct uvc_streaming_control probe;
366
	struct v4l2_fract timeperframe;
367 368 369
	uint32_t interval;
	int ret;

370
	if (parm->type != stream->type)
371 372
		return -EINVAL;

373 374 375 376 377 378 379
	if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
		timeperframe = parm->parm.capture.timeperframe;
	else
		timeperframe = parm->parm.output.timeperframe;

	interval = uvc_fraction_to_interval(timeperframe.numerator,
		timeperframe.denominator);
380
	uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n",
381
		timeperframe.numerator, timeperframe.denominator, interval);
382 383 384 385 386 387 388 389 390 391 392

	mutex_lock(&stream->mutex);

	if (uvc_queue_streaming(&stream->queue)) {
		mutex_unlock(&stream->mutex);
		return -EBUSY;
	}

	memcpy(&probe, &stream->ctrl, sizeof probe);
	probe.dwFrameInterval =
		uvc_try_frame_interval(stream->cur_frame, interval);
393 394

	/* Probe the device with the new settings. */
395
	ret = uvc_probe_video(stream, &probe);
396 397
	if (ret < 0) {
		mutex_unlock(&stream->mutex);
398
		return ret;
399
	}
400

401
	memcpy(&stream->ctrl, &probe, sizeof probe);
402
	mutex_unlock(&stream->mutex);
403 404

	/* Return the actual frame period. */
405 406 407 408 409 410 411 412 413
	timeperframe.numerator = probe.dwFrameInterval;
	timeperframe.denominator = 10000000;
	uvc_simplify_fraction(&timeperframe.numerator,
		&timeperframe.denominator, 8, 333);

	if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
		parm->parm.capture.timeperframe = timeperframe;
	else
		parm->parm.output.timeperframe = timeperframe;
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432

	return 0;
}

/* ------------------------------------------------------------------------
 * Privilege management
 */

/*
 * Privilege management is the multiple-open implementation basis. The current
 * implementation is completely transparent for the end-user and doesn't
 * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls.
 * Those ioctls enable finer control on the device (by making possible for a
 * user to request exclusive access to a device), but are not mature yet.
 * Switching to the V4L2 priority mechanism might be considered in the future
 * if this situation changes.
 *
 * Each open instance of a UVC device can either be in a privileged or
 * unprivileged state. Only a single instance can be in a privileged state at
433
 * a given time. Trying to perform an operation that requires privileges will
434
 * automatically acquire the required privileges if possible, or return -EBUSY
435 436
 * otherwise. Privileges are dismissed when closing the instance or when
 * freeing the video buffers using VIDIOC_REQBUFS.
437
 *
438
 * Operations that require privileges are:
439 440 441 442 443 444 445 446 447 448 449 450 451
 *
 * - VIDIOC_S_INPUT
 * - VIDIOC_S_PARM
 * - VIDIOC_S_FMT
 * - VIDIOC_REQBUFS
 */
static int uvc_acquire_privileges(struct uvc_fh *handle)
{
	/* Always succeed if the handle is already privileged. */
	if (handle->state == UVC_HANDLE_ACTIVE)
		return 0;

	/* Check if the device already has a privileged handle. */
452 453
	if (atomic_inc_return(&handle->stream->active) != 1) {
		atomic_dec(&handle->stream->active);
454
		return -EBUSY;
455 456 457
	}

	handle->state = UVC_HANDLE_ACTIVE;
458
	return 0;
459 460 461 462 463
}

static void uvc_dismiss_privileges(struct uvc_fh *handle)
{
	if (handle->state == UVC_HANDLE_ACTIVE)
464
		atomic_dec(&handle->stream->active);
465 466 467 468 469 470 471 472 473 474 475 476 477

	handle->state = UVC_HANDLE_PASSIVE;
}

static int uvc_has_privileges(struct uvc_fh *handle)
{
	return handle->state == UVC_HANDLE_ACTIVE;
}

/* ------------------------------------------------------------------------
 * V4L2 file operations
 */

478
static int uvc_v4l2_open(struct file *file)
479
{
480
	struct uvc_streaming *stream;
481 482 483 484
	struct uvc_fh *handle;
	int ret = 0;

	uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
485
	stream = video_drvdata(file);
486

487 488
	if (stream->dev->state & UVC_DEV_DISCONNECTED)
		return -ENODEV;
489

490
	ret = usb_autopm_get_interface(stream->dev->intf);
491
	if (ret < 0)
492
		return ret;
493 494 495 496

	/* Create the device handle. */
	handle = kzalloc(sizeof *handle, GFP_KERNEL);
	if (handle == NULL) {
497
		usb_autopm_put_interface(stream->dev->intf);
498
		return -ENOMEM;
499 500
	}

501 502 503 504 505
	if (atomic_inc_return(&stream->dev->users) == 1) {
		ret = uvc_status_start(stream->dev);
		if (ret < 0) {
			usb_autopm_put_interface(stream->dev->intf);
			atomic_dec(&stream->dev->users);
506
			kfree(handle);
507
			return ret;
508 509 510
		}
	}

511 512
	v4l2_fh_init(&handle->vfh, stream->vdev);
	v4l2_fh_add(&handle->vfh);
513
	handle->chain = stream->chain;
514
	handle->stream = stream;
515 516 517
	handle->state = UVC_HANDLE_PASSIVE;
	file->private_data = handle;

518
	return 0;
519 520
}

521
static int uvc_v4l2_release(struct file *file)
522
{
523
	struct uvc_fh *handle = file->private_data;
524
	struct uvc_streaming *stream = handle->stream;
525 526 527 528 529

	uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");

	/* Only free resources if this is a privileged handle. */
	if (uvc_has_privileges(handle)) {
530
		uvc_video_enable(stream, 0);
531
		uvc_free_buffers(&stream->queue);
532 533 534 535
	}

	/* Release the file handle. */
	uvc_dismiss_privileges(handle);
536 537
	v4l2_fh_del(&handle->vfh);
	v4l2_fh_exit(&handle->vfh);
538 539 540
	kfree(handle);
	file->private_data = NULL;

541 542
	if (atomic_dec_return(&stream->dev->users) == 0)
		uvc_status_stop(stream->dev);
543

544
	usb_autopm_put_interface(stream->dev->intf);
545 546 547
	return 0;
}

548
static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
549 550
{
	struct video_device *vdev = video_devdata(file);
551
	struct uvc_fh *handle = file->private_data;
552
	struct uvc_video_chain *chain = handle->chain;
553
	struct uvc_streaming *stream = handle->stream;
554
	long ret = 0;
555 556 557 558 559 560 561 562

	switch (cmd) {
	/* Query capabilities */
	case VIDIOC_QUERYCAP:
	{
		struct v4l2_capability *cap = arg;

		memset(cap, 0, sizeof *cap);
563 564
		strlcpy(cap->driver, "uvcvideo", sizeof cap->driver);
		strlcpy(cap->card, vdev->name, sizeof cap->card);
565
		usb_make_path(stream->dev->udev,
566
			      cap->bus_info, sizeof(cap->bus_info));
567
		cap->version = LINUX_VERSION_CODE;
568 569
		cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
				  | chain->caps;
570
		if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
571 572
			cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
					 | V4L2_CAP_STREAMING;
573
		else
574 575
			cap->device_caps = V4L2_CAP_VIDEO_OUTPUT
					 | V4L2_CAP_STREAMING;
576 577 578
		break;
	}

579 580 581 582 583 584 585 586 587 588 589 590 591
	/* Priority */
	case VIDIOC_G_PRIORITY:
		*(u32 *)arg = v4l2_prio_max(vdev->prio);
		break;

	case VIDIOC_S_PRIORITY:
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

		return v4l2_prio_change(vdev->prio, &handle->vfh.prio,
					*(u32 *)arg);

592 593
	/* Get, Set & Query control */
	case VIDIOC_QUERYCTRL:
594
		return uvc_query_v4l2_ctrl(chain, arg);
595 596 597 598 599 600 601 602 603

	case VIDIOC_G_CTRL:
	{
		struct v4l2_control *ctrl = arg;
		struct v4l2_ext_control xctrl;

		memset(&xctrl, 0, sizeof xctrl);
		xctrl.id = ctrl->id;

604 605
		ret = uvc_ctrl_begin(chain);
		if (ret < 0)
606 607
			return ret;

608
		ret = uvc_ctrl_get(chain, &xctrl);
609
		uvc_ctrl_rollback(handle);
610 611
		if (ret >= 0)
			ctrl->value = xctrl.value;
612 613 614 615 616 617 618 619
		break;
	}

	case VIDIOC_S_CTRL:
	{
		struct v4l2_control *ctrl = arg;
		struct v4l2_ext_control xctrl;

620 621 622 623
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

624 625 626 627
		memset(&xctrl, 0, sizeof xctrl);
		xctrl.id = ctrl->id;
		xctrl.value = ctrl->value;

628
		ret = uvc_ctrl_begin(chain);
629
		if (ret < 0)
630 631
			return ret;

632
		ret = uvc_ctrl_set(chain, &xctrl);
633
		if (ret < 0) {
634
			uvc_ctrl_rollback(handle);
635
			return ret;
636
		}
637
		ret = uvc_ctrl_commit(handle, &xctrl, 1);
638 639
		if (ret == 0)
			ctrl->value = xctrl.value;
640 641 642 643
		break;
	}

	case VIDIOC_QUERYMENU:
644
		return uvc_query_v4l2_menu(chain, arg);
645 646 647 648 649 650 651

	case VIDIOC_G_EXT_CTRLS:
	{
		struct v4l2_ext_controls *ctrls = arg;
		struct v4l2_ext_control *ctrl = ctrls->controls;
		unsigned int i;

652 653
		ret = uvc_ctrl_begin(chain);
		if (ret < 0)
654 655
			return ret;

656
		for (i = 0; i < ctrls->count; ++ctrl, ++i) {
657
			ret = uvc_ctrl_get(chain, ctrl);
658
			if (ret < 0) {
659
				uvc_ctrl_rollback(handle);
660 661
				ctrls->error_idx = ret == -ENOENT
						 ? ctrls->count : i;
662
				return ret;
663 664 665
			}
		}
		ctrls->error_idx = 0;
666
		ret = uvc_ctrl_rollback(handle);
667 668 669 670
		break;
	}

	case VIDIOC_S_EXT_CTRLS:
671 672 673 674
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;
		/* Fall through */
675 676 677 678 679 680
	case VIDIOC_TRY_EXT_CTRLS:
	{
		struct v4l2_ext_controls *ctrls = arg;
		struct v4l2_ext_control *ctrl = ctrls->controls;
		unsigned int i;

681
		ret = uvc_ctrl_begin(chain);
682 683 684 685
		if (ret < 0)
			return ret;

		for (i = 0; i < ctrls->count; ++ctrl, ++i) {
686
			ret = uvc_ctrl_set(chain, ctrl);
687
			if (ret < 0) {
688
				uvc_ctrl_rollback(handle);
689 690 691
				ctrls->error_idx = (ret == -ENOENT &&
						    cmd == VIDIOC_S_EXT_CTRLS)
						 ? ctrls->count : i;
692
				return ret;
693 694 695 696 697 698
			}
		}

		ctrls->error_idx = 0;

		if (cmd == VIDIOC_S_EXT_CTRLS)
699 700
			ret = uvc_ctrl_commit(handle,
					      ctrls->controls, ctrls->count);
701
		else
702
			ret = uvc_ctrl_rollback(handle);
703 704 705 706 707 708
		break;
	}

	/* Get, Set & Enum input */
	case VIDIOC_ENUMINPUT:
	{
709
		const struct uvc_entity *selector = chain->selector;
710 711 712 713 714 715
		struct v4l2_input *input = arg;
		struct uvc_entity *iterm = NULL;
		u32 index = input->index;
		int pin = 0;

		if (selector == NULL ||
716
		    (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
717 718
			if (index != 0)
				return -EINVAL;
719 720 721 722
			list_for_each_entry(iterm, &chain->entities, chain) {
				if (UVC_ENTITY_IS_ITERM(iterm))
					break;
			}
723
			pin = iterm->id;
724
		} else if (index < selector->bNrInPins) {
725
			pin = selector->baSourceID[index];
726 727 728
			list_for_each_entry(iterm, &chain->entities, chain) {
				if (!UVC_ENTITY_IS_ITERM(iterm))
					continue;
729 730 731 732 733 734 735 736 737 738
				if (iterm->id == pin)
					break;
			}
		}

		if (iterm == NULL || iterm->id != pin)
			return -EINVAL;

		memset(input, 0, sizeof *input);
		input->index = index;
739
		strlcpy(input->name, iterm->name, sizeof input->name);
740
		if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA)
741 742 743 744 745 746 747 748
			input->type = V4L2_INPUT_TYPE_CAMERA;
		break;
	}

	case VIDIOC_G_INPUT:
	{
		u8 input;

749 750
		if (chain->selector == NULL ||
		    (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
751 752 753 754
			*(int *)arg = 0;
			break;
		}

755 756
		ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
			chain->selector->id, chain->dev->intfnum,
757
			UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
758 759 760 761 762 763 764 765 766
		if (ret < 0)
			return ret;

		*(int *)arg = input - 1;
		break;
	}

	case VIDIOC_S_INPUT:
	{
767
		u32 input = *(u32 *)arg + 1;
768

769 770 771 772
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

773 774 775
		if ((ret = uvc_acquire_privileges(handle)) < 0)
			return ret;

776 777
		if (chain->selector == NULL ||
		    (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
778 779 780 781 782
			if (input != 1)
				return -EINVAL;
			break;
		}

783
		if (input == 0 || input > chain->selector->bNrInPins)
784 785
			return -EINVAL;

786 787
		return uvc_query_ctrl(chain->dev, UVC_SET_CUR,
			chain->selector->id, chain->dev->intfnum,
788
			UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
789 790 791 792 793 794 795
	}

	/* Try, Get, Set & Enum format */
	case VIDIOC_ENUM_FMT:
	{
		struct v4l2_fmtdesc *fmt = arg;
		struct uvc_format *format;
796 797
		enum v4l2_buf_type type = fmt->type;
		__u32 index = fmt->index;
798

799 800
		if (fmt->type != stream->type ||
		    fmt->index >= stream->nformats)
801 802
			return -EINVAL;

803 804 805 806
		memset(fmt, 0, sizeof(*fmt));
		fmt->index = index;
		fmt->type = type;

807
		format = &stream->format[fmt->index];
808 809 810
		fmt->flags = 0;
		if (format->flags & UVC_FMT_FLAG_COMPRESSED)
			fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
811
		strlcpy(fmt->description, format->name,
812 813 814 815 816 817 818 819 820 821
			sizeof fmt->description);
		fmt->description[sizeof fmt->description - 1] = 0;
		fmt->pixelformat = format->fcc;
		break;
	}

	case VIDIOC_TRY_FMT:
	{
		struct uvc_streaming_control probe;

822
		return uvc_v4l2_try_format(stream, arg, &probe, NULL, NULL);
823 824 825
	}

	case VIDIOC_S_FMT:
826 827 828 829
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

830 831 832
		if ((ret = uvc_acquire_privileges(handle)) < 0)
			return ret;

833
		return uvc_v4l2_set_format(stream, arg);
834 835

	case VIDIOC_G_FMT:
836
		return uvc_v4l2_get_format(stream, arg);
837 838 839 840 841 842 843 844 845 846

	/* Frame size enumeration */
	case VIDIOC_ENUM_FRAMESIZES:
	{
		struct v4l2_frmsizeenum *fsize = arg;
		struct uvc_format *format = NULL;
		struct uvc_frame *frame;
		int i;

		/* Look for the given pixel format */
847 848
		for (i = 0; i < stream->nformats; i++) {
			if (stream->format[i].fcc ==
849
					fsize->pixel_format) {
850
				format = &stream->format[i];
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
				break;
			}
		}
		if (format == NULL)
			return -EINVAL;

		if (fsize->index >= format->nframes)
			return -EINVAL;

		frame = &format->frame[fsize->index];
		fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
		fsize->discrete.width = frame->wWidth;
		fsize->discrete.height = frame->wHeight;
		break;
	}

	/* Frame interval enumeration */
	case VIDIOC_ENUM_FRAMEINTERVALS:
	{
		struct v4l2_frmivalenum *fival = arg;
		struct uvc_format *format = NULL;
		struct uvc_frame *frame = NULL;
		int i;

		/* Look for the given pixel format and frame size */
876 877
		for (i = 0; i < stream->nformats; i++) {
			if (stream->format[i].fcc ==
878
					fival->pixel_format) {
879
				format = &stream->format[i];
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
				break;
			}
		}
		if (format == NULL)
			return -EINVAL;

		for (i = 0; i < format->nframes; i++) {
			if (format->frame[i].wWidth == fival->width &&
			    format->frame[i].wHeight == fival->height) {
				frame = &format->frame[i];
				break;
			}
		}
		if (frame == NULL)
			return -EINVAL;

		if (frame->bFrameIntervalType) {
			if (fival->index >= frame->bFrameIntervalType)
				return -EINVAL;

			fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
			fival->discrete.numerator =
				frame->dwFrameInterval[fival->index];
			fival->discrete.denominator = 10000000;
			uvc_simplify_fraction(&fival->discrete.numerator,
				&fival->discrete.denominator, 8, 333);
		} else {
			fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
			fival->stepwise.min.numerator =
				frame->dwFrameInterval[0];
			fival->stepwise.min.denominator = 10000000;
			fival->stepwise.max.numerator =
				frame->dwFrameInterval[1];
			fival->stepwise.max.denominator = 10000000;
			fival->stepwise.step.numerator =
				frame->dwFrameInterval[2];
			fival->stepwise.step.denominator = 10000000;
			uvc_simplify_fraction(&fival->stepwise.min.numerator,
				&fival->stepwise.min.denominator, 8, 333);
			uvc_simplify_fraction(&fival->stepwise.max.numerator,
				&fival->stepwise.max.denominator, 8, 333);
			uvc_simplify_fraction(&fival->stepwise.step.numerator,
				&fival->stepwise.step.denominator, 8, 333);
		}
		break;
	}

	/* Get & Set streaming parameters */
	case VIDIOC_G_PARM:
929
		return uvc_v4l2_get_streamparm(stream, arg);
930 931

	case VIDIOC_S_PARM:
932 933 934 935
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

936 937 938
		if ((ret = uvc_acquire_privileges(handle)) < 0)
			return ret;

939
		return uvc_v4l2_set_streamparm(stream, arg);
940 941 942 943 944 945

	/* Cropping and scaling */
	case VIDIOC_CROPCAP:
	{
		struct v4l2_cropcap *ccap = arg;

946
		if (ccap->type != stream->type)
947 948 949 950
			return -EINVAL;

		ccap->bounds.left = 0;
		ccap->bounds.top = 0;
951 952 953 954 955

		mutex_lock(&stream->mutex);
		ccap->bounds.width = stream->cur_frame->wWidth;
		ccap->bounds.height = stream->cur_frame->wHeight;
		mutex_unlock(&stream->mutex);
956 957 958 959 960 961 962 963 964 965

		ccap->defrect = ccap->bounds;

		ccap->pixelaspect.numerator = 1;
		ccap->pixelaspect.denominator = 1;
		break;
	}

	case VIDIOC_G_CROP:
	case VIDIOC_S_CROP:
966
		return -ENOTTY;
967 968 969

	/* Buffers & streaming */
	case VIDIOC_REQBUFS:
970 971 972 973
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

974 975 976
		if ((ret = uvc_acquire_privileges(handle)) < 0)
			return ret;

977
		mutex_lock(&stream->mutex);
978
		ret = uvc_alloc_buffers(&stream->queue, arg);
979
		mutex_unlock(&stream->mutex);
980 981 982
		if (ret < 0)
			return ret;

983 984 985
		if (ret == 0)
			uvc_dismiss_privileges(handle);

986 987 988 989 990 991 992 993 994 995
		ret = 0;
		break;

	case VIDIOC_QUERYBUF:
	{
		struct v4l2_buffer *buf = arg;

		if (!uvc_has_privileges(handle))
			return -EBUSY;

996
		return uvc_query_buffer(&stream->queue, buf);
997 998 999 1000 1001 1002
	}

	case VIDIOC_QBUF:
		if (!uvc_has_privileges(handle))
			return -EBUSY;

1003
		return uvc_queue_buffer(&stream->queue, arg);
1004 1005 1006 1007 1008

	case VIDIOC_DQBUF:
		if (!uvc_has_privileges(handle))
			return -EBUSY;

1009
		return uvc_dequeue_buffer(&stream->queue, arg,
1010 1011 1012 1013 1014 1015
			file->f_flags & O_NONBLOCK);

	case VIDIOC_STREAMON:
	{
		int *type = arg;

1016
		if (*type != stream->type)
1017 1018
			return -EINVAL;

1019 1020 1021 1022
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

1023 1024 1025
		if (!uvc_has_privileges(handle))
			return -EBUSY;

1026
		mutex_lock(&stream->mutex);
1027
		ret = uvc_video_enable(stream, 1);
1028
		mutex_unlock(&stream->mutex);
1029
		if (ret < 0)
1030 1031 1032 1033 1034 1035 1036 1037
			return ret;
		break;
	}

	case VIDIOC_STREAMOFF:
	{
		int *type = arg;

1038
		if (*type != stream->type)
1039 1040
			return -EINVAL;

1041 1042 1043 1044
		ret = v4l2_prio_check(vdev->prio, handle->vfh.prio);
		if (ret < 0)
			return ret;

1045 1046 1047
		if (!uvc_has_privileges(handle))
			return -EBUSY;

1048
		return uvc_video_enable(stream, 0);
1049 1050
	}

1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
	case VIDIOC_SUBSCRIBE_EVENT:
	{
		struct v4l2_event_subscription *sub = arg;

		switch (sub->type) {
		case V4L2_EVENT_CTRL:
			return v4l2_event_subscribe(&handle->vfh, sub, 0,
						    &uvc_ctrl_sub_ev_ops);
		default:
			return -EINVAL;
		}
	}

	case VIDIOC_UNSUBSCRIBE_EVENT:
		return v4l2_event_unsubscribe(&handle->vfh, arg);

	case VIDIOC_DQEVENT:
		return v4l2_event_dequeue(&handle->vfh, arg,
					  file->f_flags & O_NONBLOCK);

1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
	/* Analog video standards make no sense for digital cameras. */
	case VIDIOC_ENUMSTD:
	case VIDIOC_QUERYSTD:
	case VIDIOC_G_STD:
	case VIDIOC_S_STD:

	case VIDIOC_OVERLAY:

	case VIDIOC_ENUMAUDIO:
	case VIDIOC_ENUMAUDOUT:

	case VIDIOC_ENUMOUTPUT:
		uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd);
1084
		return -ENOTTY;
1085 1086

	case UVCIOC_CTRL_MAP:
1087
		return uvc_ioctl_ctrl_map(chain, arg);
1088 1089 1090

	case UVCIOC_CTRL_QUERY:
		return uvc_xu_ctrl_query(chain, arg);
1091 1092

	default:
1093
		uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n", cmd);
1094
		return -ENOTTY;
1095 1096 1097 1098 1099
	}

	return ret;
}

1100
static long uvc_v4l2_ioctl(struct file *file,
1101 1102
		     unsigned int cmd, unsigned long arg)
{
1103 1104
	if (uvc_trace_param & UVC_TRACE_IOCTL) {
		uvc_printk(KERN_DEBUG, "uvc_v4l2_ioctl(");
1105
		v4l_printk_ioctl(NULL, cmd);
1106 1107 1108
		printk(")\n");
	}

1109
	return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl);
1110 1111
}

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
#ifdef CONFIG_COMPAT
struct uvc_xu_control_mapping32 {
	__u32 id;
	__u8 name[32];
	__u8 entity[16];
	__u8 selector;

	__u8 size;
	__u8 offset;
	__u32 v4l2_type;
	__u32 data_type;

	compat_caddr_t menu_info;
	__u32 menu_count;

	__u32 reserved[4];
};

static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
			const struct uvc_xu_control_mapping32 __user *up)
{
	struct uvc_menu_info __user *umenus;
	struct uvc_menu_info __user *kmenus;
	compat_caddr_t p;

	if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
	    __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) ||
	    __get_user(kp->menu_count, &up->menu_count))
		return -EFAULT;

	memset(kp->reserved, 0, sizeof(kp->reserved));

	if (kp->menu_count == 0) {
		kp->menu_info = NULL;
		return 0;
	}

	if (__get_user(p, &up->menu_info))
		return -EFAULT;
	umenus = compat_ptr(p);
	if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus)))
		return -EFAULT;

	kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus));
	if (kmenus == NULL)
		return -EFAULT;
	kp->menu_info = kmenus;

	if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus)))
		return -EFAULT;

	return 0;
}

static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
			struct uvc_xu_control_mapping32 __user *up)
{
	struct uvc_menu_info __user *umenus;
	struct uvc_menu_info __user *kmenus = kp->menu_info;
	compat_caddr_t p;

	if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
	    __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
	    __put_user(kp->menu_count, &up->menu_count))
		return -EFAULT;

1178 1179
	if (__clear_user(up->reserved, sizeof(up->reserved)))
		return -EFAULT;
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311

	if (kp->menu_count == 0)
		return 0;

	if (get_user(p, &up->menu_info))
		return -EFAULT;
	umenus = compat_ptr(p);

	if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus)))
		return -EFAULT;

	return 0;
}

struct uvc_xu_control_query32 {
	__u8 unit;
	__u8 selector;
	__u8 query;
	__u16 size;
	compat_caddr_t data;
};

static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
			const struct uvc_xu_control_query32 __user *up)
{
	u8 __user *udata;
	u8 __user *kdata;
	compat_caddr_t p;

	if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
	    __copy_from_user(kp, up, offsetof(typeof(*up), data)))
		return -EFAULT;

	if (kp->size == 0) {
		kp->data = NULL;
		return 0;
	}

	if (__get_user(p, &up->data))
		return -EFAULT;
	udata = compat_ptr(p);
	if (!access_ok(VERIFY_READ, udata, kp->size))
		return -EFAULT;

	kdata = compat_alloc_user_space(kp->size);
	if (kdata == NULL)
		return -EFAULT;
	kp->data = kdata;

	if (copy_in_user(kdata, udata, kp->size))
		return -EFAULT;

	return 0;
}

static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
			struct uvc_xu_control_query32 __user *up)
{
	u8 __user *udata;
	u8 __user *kdata = kp->data;
	compat_caddr_t p;

	if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
	    __copy_to_user(up, kp, offsetof(typeof(*up), data)))
		return -EFAULT;

	if (kp->size == 0)
		return 0;

	if (get_user(p, &up->data))
		return -EFAULT;
	udata = compat_ptr(p);
	if (!access_ok(VERIFY_READ, udata, kp->size))
		return -EFAULT;

	if (copy_in_user(udata, kdata, kp->size))
		return -EFAULT;

	return 0;
}

#define UVCIOC_CTRL_MAP32	_IOWR('u', 0x20, struct uvc_xu_control_mapping32)
#define UVCIOC_CTRL_QUERY32	_IOWR('u', 0x21, struct uvc_xu_control_query32)

static long uvc_v4l2_compat_ioctl32(struct file *file,
		     unsigned int cmd, unsigned long arg)
{
	union {
		struct uvc_xu_control_mapping xmap;
		struct uvc_xu_control_query xqry;
	} karg;
	void __user *up = compat_ptr(arg);
	mm_segment_t old_fs;
	long ret;

	switch (cmd) {
	case UVCIOC_CTRL_MAP32:
		cmd = UVCIOC_CTRL_MAP;
		ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
		break;

	case UVCIOC_CTRL_QUERY32:
		cmd = UVCIOC_CTRL_QUERY;
		ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
		break;

	default:
		return -ENOIOCTLCMD;
	}

	old_fs = get_fs();
	set_fs(KERNEL_DS);
	ret = uvc_v4l2_ioctl(file, cmd, (unsigned long)&karg);
	set_fs(old_fs);

	if (ret < 0)
		return ret;

	switch (cmd) {
	case UVCIOC_CTRL_MAP:
		ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up);
		break;

	case UVCIOC_CTRL_QUERY:
		ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
		break;
	}

	return ret;
}
#endif

1312 1313 1314 1315
static ssize_t uvc_v4l2_read(struct file *file, char __user *data,
		    size_t count, loff_t *ppos)
{
	uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n");
1316
	return -EINVAL;
1317 1318 1319 1320
}

static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
{
1321
	struct uvc_fh *handle = file->private_data;
1322
	struct uvc_streaming *stream = handle->stream;
1323 1324 1325

	uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n");

1326
	return uvc_queue_mmap(&stream->queue, vma);
1327 1328 1329 1330
}

static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
{
1331
	struct uvc_fh *handle = file->private_data;
1332
	struct uvc_streaming *stream = handle->stream;
1333 1334 1335

	uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");

1336
	return uvc_queue_poll(&stream->queue, file, wait);
1337 1338
}

1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
#ifndef CONFIG_MMU
static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
		unsigned long addr, unsigned long len, unsigned long pgoff,
		unsigned long flags)
{
	struct uvc_fh *handle = file->private_data;
	struct uvc_streaming *stream = handle->stream;

	uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n");

	return uvc_queue_get_unmapped_area(&stream->queue, pgoff);
}
#endif

1353
const struct v4l2_file_operations uvc_fops = {
1354 1355 1356
	.owner		= THIS_MODULE,
	.open		= uvc_v4l2_open,
	.release	= uvc_v4l2_release,
1357
	.unlocked_ioctl	= uvc_v4l2_ioctl,
1358 1359 1360
#ifdef CONFIG_COMPAT
	.compat_ioctl32	= uvc_v4l2_compat_ioctl32,
#endif
1361 1362 1363
	.read		= uvc_v4l2_read,
	.mmap		= uvc_v4l2_mmap,
	.poll		= uvc_v4l2_poll,
1364 1365 1366
#ifndef CONFIG_MMU
	.get_unmapped_area = uvc_v4l2_get_unmapped_area,
#endif
1367
};
1368