Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | * uvc_v4l2.c -- USB Video Class driver - V4L2 API |
| 3 | * |
Laurent Pinchart | 11fc5ba | 2010-09-20 06:10:10 -0300 | [diff] [blame] | 4 | * Copyright (C) 2005-2010 |
| 5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 6 | * |
| 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 Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 14 | #include <linux/compat.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/version.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 20 | #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 Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 25 | #include <linux/atomic.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 26 | |
| 27 | #include <media/v4l2-common.h> |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 28 | #include <media/v4l2-ctrls.h> |
| 29 | #include <media/v4l2-event.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 30 | #include <media/v4l2-ioctl.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 31 | |
| 32 | #include "uvcvideo.h" |
| 33 | |
| 34 | /* ------------------------------------------------------------------------ |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 35 | * UVC ioctls |
| 36 | */ |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 37 | static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, |
Laurent Pinchart | 227bd5b | 2011-07-30 16:19:49 -0300 | [diff] [blame] | 38 | struct uvc_xu_control_mapping *xmap) |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 39 | { |
| 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 Chen | 806e23e | 2011-11-29 18:32:25 -0300 | [diff] [blame] | 64 | /* 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 Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 73 | 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 Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 89 | uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type " |
| 90 | "%u.\n", xmap->v4l2_type); |
Mauro Carvalho Chehab | 7a286cc | 2011-06-26 10:18:03 -0300 | [diff] [blame] | 91 | ret = -ENOTTY; |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 92 | goto done; |
| 93 | } |
| 94 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 95 | ret = uvc_ctrl_add_mapping(chain, map); |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 96 | |
| 97 | done: |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 98 | kfree(map->menu_info); |
| 99 | kfree(map); |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 100 | |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | /* ------------------------------------------------------------------------ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 105 | * V4L2 interface |
| 106 | */ |
| 107 | |
| 108 | /* |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 109 | * 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 | */ |
| 114 | static __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 Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 146 | static int uvc_v4l2_try_format(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 147 | 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 Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 159 | if (fmt->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 160 | 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 Pinchart | 815adc4 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 168 | /* Check if the hardware supports the requested format, use the default |
| 169 | * format otherwise. |
| 170 | */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 171 | for (i = 0; i < stream->nformats; ++i) { |
| 172 | format = &stream->format[i]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 173 | if (format->fcc == fmt->fmt.pix.pixelformat) |
| 174 | break; |
| 175 | } |
| 176 | |
Laurent Pinchart | 815adc4 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 177 | if (i == stream->nformats) { |
| 178 | format = stream->def_format; |
| 179 | fmt->fmt.pix.pixelformat = format->fcc; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 180 | } |
| 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 Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 235 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 236 | if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 237 | probe->dwMaxVideoFrameSize = |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 238 | stream->ctrl.dwMaxVideoFrameSize; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 239 | |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 240 | /* Probe the device. */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 241 | ret = uvc_probe_video(stream, probe); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 242 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 243 | if (ret < 0) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 244 | 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 | |
| 259 | done: |
| 260 | return ret; |
| 261 | } |
| 262 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 263 | static int uvc_v4l2_get_format(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 264 | struct v4l2_format *fmt) |
| 265 | { |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 266 | struct uvc_format *format; |
| 267 | struct uvc_frame *frame; |
| 268 | int ret = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 269 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 270 | if (fmt->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 273 | 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 Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 281 | |
| 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 Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 287 | fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 288 | fmt->fmt.pix.colorspace = format->colorspace; |
| 289 | fmt->fmt.pix.priv = 0; |
| 290 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 291 | done: |
| 292 | mutex_unlock(&stream->mutex); |
| 293 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 294 | } |
| 295 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 296 | static int uvc_v4l2_set_format(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 297 | 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 Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 304 | if (fmt->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 305 | return -EINVAL; |
| 306 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 307 | ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 308 | if (ret < 0) |
| 309 | return ret; |
| 310 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 311 | mutex_lock(&stream->mutex); |
| 312 | |
| 313 | if (uvc_queue_allocated(&stream->queue)) { |
| 314 | ret = -EBUSY; |
| 315 | goto done; |
| 316 | } |
| 317 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 318 | memcpy(&stream->ctrl, &probe, sizeof probe); |
| 319 | stream->cur_format = format; |
| 320 | stream->cur_frame = frame; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 321 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 322 | done: |
| 323 | mutex_unlock(&stream->mutex); |
| 324 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 325 | } |
| 326 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 327 | static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 328 | struct v4l2_streamparm *parm) |
| 329 | { |
| 330 | uint32_t numerator, denominator; |
| 331 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 332 | if (parm->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 333 | return -EINVAL; |
| 334 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 335 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 336 | numerator = stream->ctrl.dwFrameInterval; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 337 | mutex_unlock(&stream->mutex); |
| 338 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 339 | denominator = 10000000; |
| 340 | uvc_simplify_fraction(&numerator, &denominator, 8, 333); |
| 341 | |
| 342 | memset(parm, 0, sizeof *parm); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 343 | parm->type = stream->type; |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 344 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 345 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 346 | 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 Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 362 | static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 363 | struct v4l2_streamparm *parm) |
| 364 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 365 | struct uvc_streaming_control probe; |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 366 | struct v4l2_fract timeperframe; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 367 | uint32_t interval; |
| 368 | int ret; |
| 369 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 370 | if (parm->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 371 | return -EINVAL; |
| 372 | |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 373 | if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 374 | timeperframe = parm->parm.capture.timeperframe; |
| 375 | else |
| 376 | timeperframe = parm->parm.output.timeperframe; |
| 377 | |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 378 | interval = uvc_fraction_to_interval(timeperframe.numerator, |
| 379 | timeperframe.denominator); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 380 | uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n", |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 381 | timeperframe.numerator, timeperframe.denominator, interval); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 382 | |
| 383 | mutex_lock(&stream->mutex); |
| 384 | |
| 385 | if (uvc_queue_streaming(&stream->queue)) { |
| 386 | mutex_unlock(&stream->mutex); |
| 387 | return -EBUSY; |
| 388 | } |
| 389 | |
| 390 | memcpy(&probe, &stream->ctrl, sizeof probe); |
| 391 | probe.dwFrameInterval = |
| 392 | uvc_try_frame_interval(stream->cur_frame, interval); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 393 | |
| 394 | /* Probe the device with the new settings. */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 395 | ret = uvc_probe_video(stream, &probe); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 396 | if (ret < 0) { |
| 397 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 398 | return ret; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 399 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 400 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 401 | memcpy(&stream->ctrl, &probe, sizeof probe); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 402 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 403 | |
| 404 | /* Return the actual frame period. */ |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 405 | 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 Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 414 | |
| 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 Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 433 | * a given time. Trying to perform an operation that requires privileges will |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 434 | * automatically acquire the required privileges if possible, or return -EBUSY |
Laurent Pinchart | 1a969d9 | 2009-09-02 03:12:26 -0300 | [diff] [blame] | 435 | * otherwise. Privileges are dismissed when closing the instance or when |
| 436 | * freeing the video buffers using VIDIOC_REQBUFS. |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 437 | * |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 438 | * Operations that require privileges are: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 439 | * |
| 440 | * - VIDIOC_S_INPUT |
| 441 | * - VIDIOC_S_PARM |
| 442 | * - VIDIOC_S_FMT |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 443 | * - VIDIOC_REQBUFS |
| 444 | */ |
| 445 | static int uvc_acquire_privileges(struct uvc_fh *handle) |
| 446 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 447 | /* 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 Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 452 | if (atomic_inc_return(&handle->stream->active) != 1) { |
| 453 | atomic_dec(&handle->stream->active); |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 454 | return -EBUSY; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | handle->state = UVC_HANDLE_ACTIVE; |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 458 | return 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void uvc_dismiss_privileges(struct uvc_fh *handle) |
| 462 | { |
| 463 | if (handle->state == UVC_HANDLE_ACTIVE) |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 464 | atomic_dec(&handle->stream->active); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 465 | |
| 466 | handle->state = UVC_HANDLE_PASSIVE; |
| 467 | } |
| 468 | |
| 469 | static 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 Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 478 | static int uvc_v4l2_open(struct file *file) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 479 | { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 480 | struct uvc_streaming *stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 481 | struct uvc_fh *handle; |
| 482 | int ret = 0; |
| 483 | |
| 484 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 485 | stream = video_drvdata(file); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 486 | |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 487 | if (stream->dev->state & UVC_DEV_DISCONNECTED) |
| 488 | return -ENODEV; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 489 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 490 | ret = usb_autopm_get_interface(stream->dev->intf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 491 | if (ret < 0) |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 492 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 493 | |
| 494 | /* Create the device handle. */ |
| 495 | handle = kzalloc(sizeof *handle, GFP_KERNEL); |
| 496 | if (handle == NULL) { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 497 | usb_autopm_put_interface(stream->dev->intf); |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 498 | return -ENOMEM; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 499 | } |
| 500 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 501 | if (atomic_inc_return(&stream->dev->users) == 1) { |
| 502 | ret = uvc_status_start(stream->dev); |
| 503 | if (ret < 0) { |
| 504 | usb_autopm_put_interface(stream->dev->intf); |
| 505 | atomic_dec(&stream->dev->users); |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 506 | kfree(handle); |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 507 | return ret; |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 511 | v4l2_fh_init(&handle->vfh, stream->vdev); |
| 512 | v4l2_fh_add(&handle->vfh); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 513 | handle->chain = stream->chain; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 514 | handle->stream = stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 515 | handle->state = UVC_HANDLE_PASSIVE; |
| 516 | file->private_data = handle; |
| 517 | |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 518 | return 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 519 | } |
| 520 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 521 | static int uvc_v4l2_release(struct file *file) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 522 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 523 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 524 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 525 | |
| 526 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n"); |
| 527 | |
| 528 | /* Only free resources if this is a privileged handle. */ |
| 529 | if (uvc_has_privileges(handle)) { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 530 | uvc_video_enable(stream, 0); |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 531 | uvc_free_buffers(&stream->queue); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* Release the file handle. */ |
| 535 | uvc_dismiss_privileges(handle); |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 536 | v4l2_fh_del(&handle->vfh); |
| 537 | v4l2_fh_exit(&handle->vfh); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 538 | kfree(handle); |
| 539 | file->private_data = NULL; |
| 540 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 541 | if (atomic_dec_return(&stream->dev->users) == 0) |
| 542 | uvc_status_stop(stream->dev); |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 543 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 544 | usb_autopm_put_interface(stream->dev->intf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 548 | static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 549 | { |
| 550 | struct video_device *vdev = video_devdata(file); |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 551 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 552 | struct uvc_video_chain *chain = handle->chain; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 553 | struct uvc_streaming *stream = handle->stream; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 554 | long ret = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 555 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 556 | switch (cmd) { |
| 557 | /* Query capabilities */ |
| 558 | case VIDIOC_QUERYCAP: |
| 559 | { |
| 560 | struct v4l2_capability *cap = arg; |
| 561 | |
| 562 | memset(cap, 0, sizeof *cap); |
Laurent Pinchart | d0ebf30 | 2009-01-08 14:05:11 -0300 | [diff] [blame] | 563 | strlcpy(cap->driver, "uvcvideo", sizeof cap->driver); |
| 564 | strlcpy(cap->card, vdev->name, sizeof cap->card); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 565 | usb_make_path(stream->dev->udev, |
Thierry MERLE | b12049a | 2009-01-27 16:53:23 -0300 | [diff] [blame] | 566 | cap->bus_info, sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | fd3e582 | 2011-06-25 13:50:37 -0300 | [diff] [blame] | 567 | cap->version = LINUX_VERSION_CODE; |
Laurent Pinchart | f887e99 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 568 | cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING |
| 569 | | chain->caps; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 570 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Laurent Pinchart | f887e99 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 571 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
| 572 | | V4L2_CAP_STREAMING; |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 573 | else |
Laurent Pinchart | f887e99 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 574 | cap->device_caps = V4L2_CAP_VIDEO_OUTPUT |
| 575 | | V4L2_CAP_STREAMING; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 576 | break; |
| 577 | } |
| 578 | |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 579 | /* Priority */ |
| 580 | case VIDIOC_G_PRIORITY: |
| 581 | *(u32 *)arg = v4l2_prio_max(vdev->prio); |
| 582 | break; |
| 583 | |
| 584 | case VIDIOC_S_PRIORITY: |
| 585 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 586 | if (ret < 0) |
| 587 | return ret; |
| 588 | |
| 589 | return v4l2_prio_change(vdev->prio, &handle->vfh.prio, |
| 590 | *(u32 *)arg); |
| 591 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 592 | /* Get, Set & Query control */ |
| 593 | case VIDIOC_QUERYCTRL: |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 594 | return uvc_query_v4l2_ctrl(chain, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 595 | |
| 596 | case VIDIOC_G_CTRL: |
| 597 | { |
| 598 | struct v4l2_control *ctrl = arg; |
| 599 | struct v4l2_ext_control xctrl; |
| 600 | |
| 601 | memset(&xctrl, 0, sizeof xctrl); |
| 602 | xctrl.id = ctrl->id; |
| 603 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 604 | ret = uvc_ctrl_begin(chain); |
| 605 | if (ret < 0) |
Robert Krakora | 1fcbcc4 | 2009-06-12 13:51:03 -0300 | [diff] [blame] | 606 | return ret; |
| 607 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 608 | ret = uvc_ctrl_get(chain, &xctrl); |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 609 | uvc_ctrl_rollback(handle); |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 610 | if (ret < 0) |
| 611 | return ret == -ENOENT ? -EINVAL : ret; |
| 612 | |
| 613 | ctrl->value = xctrl.value; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 614 | break; |
| 615 | } |
| 616 | |
| 617 | case VIDIOC_S_CTRL: |
| 618 | { |
| 619 | struct v4l2_control *ctrl = arg; |
| 620 | struct v4l2_ext_control xctrl; |
| 621 | |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 622 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 623 | if (ret < 0) |
| 624 | return ret; |
| 625 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 626 | memset(&xctrl, 0, sizeof xctrl); |
| 627 | xctrl.id = ctrl->id; |
| 628 | xctrl.value = ctrl->value; |
| 629 | |
Laurent Pinchart | 8d55662 | 2010-02-04 21:43:37 -0300 | [diff] [blame] | 630 | ret = uvc_ctrl_begin(chain); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 631 | if (ret < 0) |
Robert Krakora | 1fcbcc4 | 2009-06-12 13:51:03 -0300 | [diff] [blame] | 632 | return ret; |
| 633 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 634 | ret = uvc_ctrl_set(chain, &xctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 635 | if (ret < 0) { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 636 | uvc_ctrl_rollback(handle); |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 637 | return ret == -ENOENT ? -EINVAL : ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 638 | } |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 639 | ret = uvc_ctrl_commit(handle, &xctrl, 1); |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 640 | if (ret == 0) |
| 641 | ctrl->value = xctrl.value; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 642 | break; |
| 643 | } |
| 644 | |
| 645 | case VIDIOC_QUERYMENU: |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 646 | return uvc_query_v4l2_menu(chain, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 647 | |
| 648 | case VIDIOC_G_EXT_CTRLS: |
| 649 | { |
| 650 | struct v4l2_ext_controls *ctrls = arg; |
| 651 | struct v4l2_ext_control *ctrl = ctrls->controls; |
| 652 | unsigned int i; |
| 653 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 654 | ret = uvc_ctrl_begin(chain); |
| 655 | if (ret < 0) |
Robert Krakora | 1fcbcc4 | 2009-06-12 13:51:03 -0300 | [diff] [blame] | 656 | return ret; |
| 657 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 658 | for (i = 0; i < ctrls->count; ++ctrl, ++i) { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 659 | ret = uvc_ctrl_get(chain, ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 660 | if (ret < 0) { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 661 | uvc_ctrl_rollback(handle); |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 662 | ctrls->error_idx = ret == -ENOENT |
| 663 | ? ctrls->count : i; |
| 664 | return ret == -ENOENT ? -EINVAL : ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | ctrls->error_idx = 0; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 668 | ret = uvc_ctrl_rollback(handle); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 669 | break; |
| 670 | } |
| 671 | |
| 672 | case VIDIOC_S_EXT_CTRLS: |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 673 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 674 | if (ret < 0) |
| 675 | return ret; |
| 676 | /* Fall through */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 677 | case VIDIOC_TRY_EXT_CTRLS: |
| 678 | { |
| 679 | struct v4l2_ext_controls *ctrls = arg; |
| 680 | struct v4l2_ext_control *ctrl = ctrls->controls; |
| 681 | unsigned int i; |
| 682 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 683 | ret = uvc_ctrl_begin(chain); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 684 | if (ret < 0) |
| 685 | return ret; |
| 686 | |
| 687 | for (i = 0; i < ctrls->count; ++ctrl, ++i) { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 688 | ret = uvc_ctrl_set(chain, ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 689 | if (ret < 0) { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 690 | uvc_ctrl_rollback(handle); |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 691 | ctrls->error_idx = (ret == -ENOENT && |
| 692 | cmd == VIDIOC_S_EXT_CTRLS) |
| 693 | ? ctrls->count : i; |
| 694 | return ret == -ENOENT ? -EINVAL : ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | ctrls->error_idx = 0; |
| 699 | |
| 700 | if (cmd == VIDIOC_S_EXT_CTRLS) |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 701 | ret = uvc_ctrl_commit(handle, |
| 702 | ctrls->controls, ctrls->count); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 703 | else |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 704 | ret = uvc_ctrl_rollback(handle); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | |
| 708 | /* Get, Set & Enum input */ |
| 709 | case VIDIOC_ENUMINPUT: |
| 710 | { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 711 | const struct uvc_entity *selector = chain->selector; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 712 | struct v4l2_input *input = arg; |
| 713 | struct uvc_entity *iterm = NULL; |
| 714 | u32 index = input->index; |
| 715 | int pin = 0; |
| 716 | |
| 717 | if (selector == NULL || |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 718 | (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 719 | if (index != 0) |
| 720 | return -EINVAL; |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 721 | list_for_each_entry(iterm, &chain->entities, chain) { |
| 722 | if (UVC_ENTITY_IS_ITERM(iterm)) |
| 723 | break; |
| 724 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 725 | pin = iterm->id; |
Laurent Pinchart | 31c5f0c | 2012-03-21 09:50:36 -0300 | [diff] [blame] | 726 | } else if (index < selector->bNrInPins) { |
Laurent Pinchart | 8ca5a63 | 2009-11-25 12:00:30 -0300 | [diff] [blame] | 727 | pin = selector->baSourceID[index]; |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 728 | list_for_each_entry(iterm, &chain->entities, chain) { |
| 729 | if (!UVC_ENTITY_IS_ITERM(iterm)) |
| 730 | continue; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 731 | if (iterm->id == pin) |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | if (iterm == NULL || iterm->id != pin) |
| 737 | return -EINVAL; |
| 738 | |
| 739 | memset(input, 0, sizeof *input); |
| 740 | input->index = index; |
Laurent Pinchart | d0ebf30 | 2009-01-08 14:05:11 -0300 | [diff] [blame] | 741 | strlcpy(input->name, iterm->name, sizeof input->name); |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 742 | if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 743 | input->type = V4L2_INPUT_TYPE_CAMERA; |
| 744 | break; |
| 745 | } |
| 746 | |
| 747 | case VIDIOC_G_INPUT: |
| 748 | { |
| 749 | u8 input; |
| 750 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 751 | if (chain->selector == NULL || |
| 752 | (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 753 | *(int *)arg = 0; |
| 754 | break; |
| 755 | } |
| 756 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 757 | ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, |
| 758 | chain->selector->id, chain->dev->intfnum, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 759 | UVC_SU_INPUT_SELECT_CONTROL, &input, 1); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 760 | if (ret < 0) |
| 761 | return ret; |
| 762 | |
| 763 | *(int *)arg = input - 1; |
| 764 | break; |
| 765 | } |
| 766 | |
| 767 | case VIDIOC_S_INPUT: |
| 768 | { |
Márton Németh | 9086c7b99 | 2009-04-15 09:01:58 -0300 | [diff] [blame] | 769 | u32 input = *(u32 *)arg + 1; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 770 | |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 771 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 772 | if (ret < 0) |
| 773 | return ret; |
| 774 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 775 | if ((ret = uvc_acquire_privileges(handle)) < 0) |
| 776 | return ret; |
| 777 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 778 | if (chain->selector == NULL || |
| 779 | (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 780 | if (input != 1) |
| 781 | return -EINVAL; |
| 782 | break; |
| 783 | } |
| 784 | |
Laurent Pinchart | 8ca5a63 | 2009-11-25 12:00:30 -0300 | [diff] [blame] | 785 | if (input == 0 || input > chain->selector->bNrInPins) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 786 | return -EINVAL; |
| 787 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 788 | return uvc_query_ctrl(chain->dev, UVC_SET_CUR, |
| 789 | chain->selector->id, chain->dev->intfnum, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 790 | UVC_SU_INPUT_SELECT_CONTROL, &input, 1); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | /* Try, Get, Set & Enum format */ |
| 794 | case VIDIOC_ENUM_FMT: |
| 795 | { |
| 796 | struct v4l2_fmtdesc *fmt = arg; |
| 797 | struct uvc_format *format; |
Márton Németh | 8bbd90c | 2009-03-27 11:13:57 -0300 | [diff] [blame] | 798 | enum v4l2_buf_type type = fmt->type; |
| 799 | __u32 index = fmt->index; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 800 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 801 | if (fmt->type != stream->type || |
| 802 | fmt->index >= stream->nformats) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 803 | return -EINVAL; |
| 804 | |
Márton Németh | 8bbd90c | 2009-03-27 11:13:57 -0300 | [diff] [blame] | 805 | memset(fmt, 0, sizeof(*fmt)); |
| 806 | fmt->index = index; |
| 807 | fmt->type = type; |
| 808 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 809 | format = &stream->format[fmt->index]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 810 | fmt->flags = 0; |
| 811 | if (format->flags & UVC_FMT_FLAG_COMPRESSED) |
| 812 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; |
Laurent Pinchart | d0ebf30 | 2009-01-08 14:05:11 -0300 | [diff] [blame] | 813 | strlcpy(fmt->description, format->name, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 814 | sizeof fmt->description); |
| 815 | fmt->description[sizeof fmt->description - 1] = 0; |
| 816 | fmt->pixelformat = format->fcc; |
| 817 | break; |
| 818 | } |
| 819 | |
| 820 | case VIDIOC_TRY_FMT: |
| 821 | { |
| 822 | struct uvc_streaming_control probe; |
| 823 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 824 | return uvc_v4l2_try_format(stream, arg, &probe, NULL, NULL); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | case VIDIOC_S_FMT: |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 828 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 829 | if (ret < 0) |
| 830 | return ret; |
| 831 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 832 | if ((ret = uvc_acquire_privileges(handle)) < 0) |
| 833 | return ret; |
| 834 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 835 | return uvc_v4l2_set_format(stream, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 836 | |
| 837 | case VIDIOC_G_FMT: |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 838 | return uvc_v4l2_get_format(stream, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 839 | |
| 840 | /* Frame size enumeration */ |
| 841 | case VIDIOC_ENUM_FRAMESIZES: |
| 842 | { |
| 843 | struct v4l2_frmsizeenum *fsize = arg; |
| 844 | struct uvc_format *format = NULL; |
| 845 | struct uvc_frame *frame; |
| 846 | int i; |
| 847 | |
| 848 | /* Look for the given pixel format */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 849 | for (i = 0; i < stream->nformats; i++) { |
| 850 | if (stream->format[i].fcc == |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 851 | fsize->pixel_format) { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 852 | format = &stream->format[i]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 853 | break; |
| 854 | } |
| 855 | } |
| 856 | if (format == NULL) |
| 857 | return -EINVAL; |
| 858 | |
| 859 | if (fsize->index >= format->nframes) |
| 860 | return -EINVAL; |
| 861 | |
| 862 | frame = &format->frame[fsize->index]; |
| 863 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 864 | fsize->discrete.width = frame->wWidth; |
| 865 | fsize->discrete.height = frame->wHeight; |
| 866 | break; |
| 867 | } |
| 868 | |
| 869 | /* Frame interval enumeration */ |
| 870 | case VIDIOC_ENUM_FRAMEINTERVALS: |
| 871 | { |
| 872 | struct v4l2_frmivalenum *fival = arg; |
| 873 | struct uvc_format *format = NULL; |
| 874 | struct uvc_frame *frame = NULL; |
| 875 | int i; |
| 876 | |
| 877 | /* Look for the given pixel format and frame size */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 878 | for (i = 0; i < stream->nformats; i++) { |
| 879 | if (stream->format[i].fcc == |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 880 | fival->pixel_format) { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 881 | format = &stream->format[i]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 882 | break; |
| 883 | } |
| 884 | } |
| 885 | if (format == NULL) |
| 886 | return -EINVAL; |
| 887 | |
| 888 | for (i = 0; i < format->nframes; i++) { |
| 889 | if (format->frame[i].wWidth == fival->width && |
| 890 | format->frame[i].wHeight == fival->height) { |
| 891 | frame = &format->frame[i]; |
| 892 | break; |
| 893 | } |
| 894 | } |
| 895 | if (frame == NULL) |
| 896 | return -EINVAL; |
| 897 | |
| 898 | if (frame->bFrameIntervalType) { |
| 899 | if (fival->index >= frame->bFrameIntervalType) |
| 900 | return -EINVAL; |
| 901 | |
| 902 | fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; |
| 903 | fival->discrete.numerator = |
| 904 | frame->dwFrameInterval[fival->index]; |
| 905 | fival->discrete.denominator = 10000000; |
| 906 | uvc_simplify_fraction(&fival->discrete.numerator, |
| 907 | &fival->discrete.denominator, 8, 333); |
| 908 | } else { |
| 909 | fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; |
| 910 | fival->stepwise.min.numerator = |
| 911 | frame->dwFrameInterval[0]; |
| 912 | fival->stepwise.min.denominator = 10000000; |
| 913 | fival->stepwise.max.numerator = |
| 914 | frame->dwFrameInterval[1]; |
| 915 | fival->stepwise.max.denominator = 10000000; |
| 916 | fival->stepwise.step.numerator = |
| 917 | frame->dwFrameInterval[2]; |
| 918 | fival->stepwise.step.denominator = 10000000; |
| 919 | uvc_simplify_fraction(&fival->stepwise.min.numerator, |
| 920 | &fival->stepwise.min.denominator, 8, 333); |
| 921 | uvc_simplify_fraction(&fival->stepwise.max.numerator, |
| 922 | &fival->stepwise.max.denominator, 8, 333); |
| 923 | uvc_simplify_fraction(&fival->stepwise.step.numerator, |
| 924 | &fival->stepwise.step.denominator, 8, 333); |
| 925 | } |
| 926 | break; |
| 927 | } |
| 928 | |
| 929 | /* Get & Set streaming parameters */ |
| 930 | case VIDIOC_G_PARM: |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 931 | return uvc_v4l2_get_streamparm(stream, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 932 | |
| 933 | case VIDIOC_S_PARM: |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 934 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 935 | if (ret < 0) |
| 936 | return ret; |
| 937 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 938 | if ((ret = uvc_acquire_privileges(handle)) < 0) |
| 939 | return ret; |
| 940 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 941 | return uvc_v4l2_set_streamparm(stream, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 942 | |
| 943 | /* Cropping and scaling */ |
| 944 | case VIDIOC_CROPCAP: |
| 945 | { |
| 946 | struct v4l2_cropcap *ccap = arg; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 947 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 948 | if (ccap->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 949 | return -EINVAL; |
| 950 | |
| 951 | ccap->bounds.left = 0; |
| 952 | ccap->bounds.top = 0; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 953 | |
| 954 | mutex_lock(&stream->mutex); |
| 955 | ccap->bounds.width = stream->cur_frame->wWidth; |
| 956 | ccap->bounds.height = stream->cur_frame->wHeight; |
| 957 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 958 | |
| 959 | ccap->defrect = ccap->bounds; |
| 960 | |
| 961 | ccap->pixelaspect.numerator = 1; |
| 962 | ccap->pixelaspect.denominator = 1; |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | case VIDIOC_G_CROP: |
| 967 | case VIDIOC_S_CROP: |
Laurent Pinchart | 69d1126 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 968 | return -ENOTTY; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 969 | |
| 970 | /* Buffers & streaming */ |
| 971 | case VIDIOC_REQBUFS: |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 972 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 973 | if (ret < 0) |
| 974 | return ret; |
| 975 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 976 | if ((ret = uvc_acquire_privileges(handle)) < 0) |
| 977 | return ret; |
| 978 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 979 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 980 | ret = uvc_alloc_buffers(&stream->queue, arg); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 981 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 982 | if (ret < 0) |
| 983 | return ret; |
| 984 | |
Laurent Pinchart | 1a969d9 | 2009-09-02 03:12:26 -0300 | [diff] [blame] | 985 | if (ret == 0) |
| 986 | uvc_dismiss_privileges(handle); |
| 987 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 988 | ret = 0; |
| 989 | break; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 990 | |
| 991 | case VIDIOC_QUERYBUF: |
| 992 | { |
| 993 | struct v4l2_buffer *buf = arg; |
| 994 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 995 | if (!uvc_has_privileges(handle)) |
| 996 | return -EBUSY; |
| 997 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 998 | return uvc_query_buffer(&stream->queue, buf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | case VIDIOC_QBUF: |
| 1002 | if (!uvc_has_privileges(handle)) |
| 1003 | return -EBUSY; |
| 1004 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1005 | return uvc_queue_buffer(&stream->queue, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1006 | |
| 1007 | case VIDIOC_DQBUF: |
| 1008 | if (!uvc_has_privileges(handle)) |
| 1009 | return -EBUSY; |
| 1010 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1011 | return uvc_dequeue_buffer(&stream->queue, arg, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1012 | file->f_flags & O_NONBLOCK); |
| 1013 | |
| 1014 | case VIDIOC_STREAMON: |
| 1015 | { |
| 1016 | int *type = arg; |
| 1017 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1018 | if (*type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1019 | return -EINVAL; |
| 1020 | |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 1021 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 1022 | if (ret < 0) |
| 1023 | return ret; |
| 1024 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1025 | if (!uvc_has_privileges(handle)) |
| 1026 | return -EBUSY; |
| 1027 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 1028 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1029 | ret = uvc_video_enable(stream, 1); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 1030 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1031 | if (ret < 0) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1032 | return ret; |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | case VIDIOC_STREAMOFF: |
| 1037 | { |
| 1038 | int *type = arg; |
| 1039 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1040 | if (*type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1041 | return -EINVAL; |
| 1042 | |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame^] | 1043 | ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); |
| 1044 | if (ret < 0) |
| 1045 | return ret; |
| 1046 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1047 | if (!uvc_has_privileges(handle)) |
| 1048 | return -EBUSY; |
| 1049 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1050 | return uvc_video_enable(stream, 0); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1051 | } |
| 1052 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1053 | case VIDIOC_SUBSCRIBE_EVENT: |
| 1054 | { |
| 1055 | struct v4l2_event_subscription *sub = arg; |
| 1056 | |
| 1057 | switch (sub->type) { |
| 1058 | case V4L2_EVENT_CTRL: |
| 1059 | return v4l2_event_subscribe(&handle->vfh, sub, 0, |
| 1060 | &uvc_ctrl_sub_ev_ops); |
| 1061 | default: |
| 1062 | return -EINVAL; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | case VIDIOC_UNSUBSCRIBE_EVENT: |
| 1067 | return v4l2_event_unsubscribe(&handle->vfh, arg); |
| 1068 | |
| 1069 | case VIDIOC_DQEVENT: |
| 1070 | return v4l2_event_dequeue(&handle->vfh, arg, |
| 1071 | file->f_flags & O_NONBLOCK); |
| 1072 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1073 | /* Analog video standards make no sense for digital cameras. */ |
| 1074 | case VIDIOC_ENUMSTD: |
| 1075 | case VIDIOC_QUERYSTD: |
| 1076 | case VIDIOC_G_STD: |
| 1077 | case VIDIOC_S_STD: |
| 1078 | |
| 1079 | case VIDIOC_OVERLAY: |
| 1080 | |
| 1081 | case VIDIOC_ENUMAUDIO: |
| 1082 | case VIDIOC_ENUMAUDOUT: |
| 1083 | |
| 1084 | case VIDIOC_ENUMOUTPUT: |
| 1085 | uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd); |
Laurent Pinchart | 69d1126 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1086 | return -ENOTTY; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1087 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1088 | case UVCIOC_CTRL_MAP: |
Laurent Pinchart | 227bd5b | 2011-07-30 16:19:49 -0300 | [diff] [blame] | 1089 | return uvc_ioctl_ctrl_map(chain, arg); |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1090 | |
| 1091 | case UVCIOC_CTRL_QUERY: |
| 1092 | return uvc_xu_ctrl_query(chain, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1093 | |
| 1094 | default: |
Hans Verkuil | 08af245 | 2010-12-24 10:33:19 -0300 | [diff] [blame] | 1095 | uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n", cmd); |
Laurent Pinchart | a3ec69b | 2011-12-18 20:22:50 -0300 | [diff] [blame] | 1096 | return -ENOTTY; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | return ret; |
| 1100 | } |
| 1101 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1102 | static long uvc_v4l2_ioctl(struct file *file, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1103 | unsigned int cmd, unsigned long arg) |
| 1104 | { |
Laurent Pinchart | 308bb52 | 2008-11-17 18:32:11 -0300 | [diff] [blame] | 1105 | if (uvc_trace_param & UVC_TRACE_IOCTL) { |
| 1106 | uvc_printk(KERN_DEBUG, "uvc_v4l2_ioctl("); |
Hans Verkuil | 4a08516 | 2012-06-22 06:38:06 -0300 | [diff] [blame] | 1107 | v4l_printk_ioctl(NULL, cmd); |
Laurent Pinchart | 308bb52 | 2008-11-17 18:32:11 -0300 | [diff] [blame] | 1108 | printk(")\n"); |
| 1109 | } |
| 1110 | |
Hans Verkuil | f473bf7 | 2008-11-01 08:25:11 -0300 | [diff] [blame] | 1111 | return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1112 | } |
| 1113 | |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1114 | #ifdef CONFIG_COMPAT |
| 1115 | struct uvc_xu_control_mapping32 { |
| 1116 | __u32 id; |
| 1117 | __u8 name[32]; |
| 1118 | __u8 entity[16]; |
| 1119 | __u8 selector; |
| 1120 | |
| 1121 | __u8 size; |
| 1122 | __u8 offset; |
| 1123 | __u32 v4l2_type; |
| 1124 | __u32 data_type; |
| 1125 | |
| 1126 | compat_caddr_t menu_info; |
| 1127 | __u32 menu_count; |
| 1128 | |
| 1129 | __u32 reserved[4]; |
| 1130 | }; |
| 1131 | |
| 1132 | static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp, |
| 1133 | const struct uvc_xu_control_mapping32 __user *up) |
| 1134 | { |
| 1135 | struct uvc_menu_info __user *umenus; |
| 1136 | struct uvc_menu_info __user *kmenus; |
| 1137 | compat_caddr_t p; |
| 1138 | |
| 1139 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 1140 | __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) || |
| 1141 | __get_user(kp->menu_count, &up->menu_count)) |
| 1142 | return -EFAULT; |
| 1143 | |
| 1144 | memset(kp->reserved, 0, sizeof(kp->reserved)); |
| 1145 | |
| 1146 | if (kp->menu_count == 0) { |
| 1147 | kp->menu_info = NULL; |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | if (__get_user(p, &up->menu_info)) |
| 1152 | return -EFAULT; |
| 1153 | umenus = compat_ptr(p); |
| 1154 | if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus))) |
| 1155 | return -EFAULT; |
| 1156 | |
| 1157 | kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus)); |
| 1158 | if (kmenus == NULL) |
| 1159 | return -EFAULT; |
| 1160 | kp->menu_info = kmenus; |
| 1161 | |
| 1162 | if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus))) |
| 1163 | return -EFAULT; |
| 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp, |
| 1169 | struct uvc_xu_control_mapping32 __user *up) |
| 1170 | { |
| 1171 | struct uvc_menu_info __user *umenus; |
| 1172 | struct uvc_menu_info __user *kmenus = kp->menu_info; |
| 1173 | compat_caddr_t p; |
| 1174 | |
| 1175 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
| 1176 | __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) || |
| 1177 | __put_user(kp->menu_count, &up->menu_count)) |
| 1178 | return -EFAULT; |
| 1179 | |
Hans de Goede | 57fb4a4 | 2012-04-08 12:59:48 -0300 | [diff] [blame] | 1180 | if (__clear_user(up->reserved, sizeof(up->reserved))) |
| 1181 | return -EFAULT; |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1182 | |
| 1183 | if (kp->menu_count == 0) |
| 1184 | return 0; |
| 1185 | |
| 1186 | if (get_user(p, &up->menu_info)) |
| 1187 | return -EFAULT; |
| 1188 | umenus = compat_ptr(p); |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1189 | |
| 1190 | if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus))) |
| 1191 | return -EFAULT; |
| 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
| 1196 | struct uvc_xu_control_query32 { |
| 1197 | __u8 unit; |
| 1198 | __u8 selector; |
| 1199 | __u8 query; |
| 1200 | __u16 size; |
| 1201 | compat_caddr_t data; |
| 1202 | }; |
| 1203 | |
| 1204 | static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp, |
| 1205 | const struct uvc_xu_control_query32 __user *up) |
| 1206 | { |
| 1207 | u8 __user *udata; |
| 1208 | u8 __user *kdata; |
| 1209 | compat_caddr_t p; |
| 1210 | |
| 1211 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 1212 | __copy_from_user(kp, up, offsetof(typeof(*up), data))) |
| 1213 | return -EFAULT; |
| 1214 | |
| 1215 | if (kp->size == 0) { |
| 1216 | kp->data = NULL; |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | if (__get_user(p, &up->data)) |
| 1221 | return -EFAULT; |
| 1222 | udata = compat_ptr(p); |
| 1223 | if (!access_ok(VERIFY_READ, udata, kp->size)) |
| 1224 | return -EFAULT; |
| 1225 | |
| 1226 | kdata = compat_alloc_user_space(kp->size); |
| 1227 | if (kdata == NULL) |
| 1228 | return -EFAULT; |
| 1229 | kp->data = kdata; |
| 1230 | |
| 1231 | if (copy_in_user(kdata, udata, kp->size)) |
| 1232 | return -EFAULT; |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp, |
| 1238 | struct uvc_xu_control_query32 __user *up) |
| 1239 | { |
| 1240 | u8 __user *udata; |
| 1241 | u8 __user *kdata = kp->data; |
| 1242 | compat_caddr_t p; |
| 1243 | |
| 1244 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
| 1245 | __copy_to_user(up, kp, offsetof(typeof(*up), data))) |
| 1246 | return -EFAULT; |
| 1247 | |
| 1248 | if (kp->size == 0) |
| 1249 | return 0; |
| 1250 | |
| 1251 | if (get_user(p, &up->data)) |
| 1252 | return -EFAULT; |
| 1253 | udata = compat_ptr(p); |
| 1254 | if (!access_ok(VERIFY_READ, udata, kp->size)) |
| 1255 | return -EFAULT; |
| 1256 | |
| 1257 | if (copy_in_user(udata, kdata, kp->size)) |
| 1258 | return -EFAULT; |
| 1259 | |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | #define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32) |
| 1264 | #define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32) |
| 1265 | |
| 1266 | static long uvc_v4l2_compat_ioctl32(struct file *file, |
| 1267 | unsigned int cmd, unsigned long arg) |
| 1268 | { |
| 1269 | union { |
| 1270 | struct uvc_xu_control_mapping xmap; |
| 1271 | struct uvc_xu_control_query xqry; |
| 1272 | } karg; |
| 1273 | void __user *up = compat_ptr(arg); |
| 1274 | mm_segment_t old_fs; |
| 1275 | long ret; |
| 1276 | |
| 1277 | switch (cmd) { |
| 1278 | case UVCIOC_CTRL_MAP32: |
| 1279 | cmd = UVCIOC_CTRL_MAP; |
| 1280 | ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up); |
| 1281 | break; |
| 1282 | |
| 1283 | case UVCIOC_CTRL_QUERY32: |
| 1284 | cmd = UVCIOC_CTRL_QUERY; |
| 1285 | ret = uvc_v4l2_get_xu_query(&karg.xqry, up); |
| 1286 | break; |
| 1287 | |
| 1288 | default: |
| 1289 | return -ENOIOCTLCMD; |
| 1290 | } |
| 1291 | |
| 1292 | old_fs = get_fs(); |
| 1293 | set_fs(KERNEL_DS); |
| 1294 | ret = uvc_v4l2_ioctl(file, cmd, (unsigned long)&karg); |
| 1295 | set_fs(old_fs); |
| 1296 | |
| 1297 | if (ret < 0) |
| 1298 | return ret; |
| 1299 | |
| 1300 | switch (cmd) { |
| 1301 | case UVCIOC_CTRL_MAP: |
| 1302 | ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up); |
| 1303 | break; |
| 1304 | |
| 1305 | case UVCIOC_CTRL_QUERY: |
| 1306 | ret = uvc_v4l2_put_xu_query(&karg.xqry, up); |
| 1307 | break; |
| 1308 | } |
| 1309 | |
| 1310 | return ret; |
| 1311 | } |
| 1312 | #endif |
| 1313 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1314 | static ssize_t uvc_v4l2_read(struct file *file, char __user *data, |
| 1315 | size_t count, loff_t *ppos) |
| 1316 | { |
| 1317 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n"); |
Laurent Pinchart | 350d640 | 2009-11-04 11:53:49 -0300 | [diff] [blame] | 1318 | return -EINVAL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1319 | } |
| 1320 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1321 | static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) |
| 1322 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1323 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1324 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1325 | |
| 1326 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n"); |
| 1327 | |
Laurent Pinchart | 4aa2759 | 2010-11-21 15:18:08 -0300 | [diff] [blame] | 1328 | return uvc_queue_mmap(&stream->queue, vma); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) |
| 1332 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1333 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1334 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1335 | |
| 1336 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n"); |
| 1337 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1338 | return uvc_queue_poll(&stream->queue, file, wait); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1339 | } |
| 1340 | |
Bob Liu | 7296944 | 2011-04-29 07:11:35 -0300 | [diff] [blame] | 1341 | #ifndef CONFIG_MMU |
| 1342 | static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, |
| 1343 | unsigned long addr, unsigned long len, unsigned long pgoff, |
| 1344 | unsigned long flags) |
| 1345 | { |
| 1346 | struct uvc_fh *handle = file->private_data; |
| 1347 | struct uvc_streaming *stream = handle->stream; |
| 1348 | |
| 1349 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n"); |
| 1350 | |
| 1351 | return uvc_queue_get_unmapped_area(&stream->queue, pgoff); |
| 1352 | } |
| 1353 | #endif |
| 1354 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1355 | const struct v4l2_file_operations uvc_fops = { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1356 | .owner = THIS_MODULE, |
| 1357 | .open = uvc_v4l2_open, |
| 1358 | .release = uvc_v4l2_release, |
Laurent Pinchart | 673eb9f | 2010-11-21 16:54:56 -0300 | [diff] [blame] | 1359 | .unlocked_ioctl = uvc_v4l2_ioctl, |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1360 | #ifdef CONFIG_COMPAT |
| 1361 | .compat_ioctl32 = uvc_v4l2_compat_ioctl32, |
| 1362 | #endif |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1363 | .read = uvc_v4l2_read, |
| 1364 | .mmap = uvc_v4l2_mmap, |
| 1365 | .poll = uvc_v4l2_poll, |
Bob Liu | 7296944 | 2011-04-29 07:11:35 -0300 | [diff] [blame] | 1366 | #ifndef CONFIG_MMU |
| 1367 | .get_unmapped_area = uvc_v4l2_get_unmapped_area, |
| 1368 | #endif |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1369 | }; |
Hans Verkuil | f87086e | 2008-07-18 00:50:58 -0300 | [diff] [blame] | 1370 | |