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> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 16 | #include <linux/list.h> |
| 17 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 19 | #include <linux/usb.h> |
| 20 | #include <linux/videodev2.h> |
| 21 | #include <linux/vmalloc.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/wait.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 24 | #include <linux/atomic.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 25 | |
| 26 | #include <media/v4l2-common.h> |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 27 | #include <media/v4l2-ctrls.h> |
| 28 | #include <media/v4l2-event.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 29 | #include <media/v4l2-ioctl.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 30 | |
| 31 | #include "uvcvideo.h" |
| 32 | |
| 33 | /* ------------------------------------------------------------------------ |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 34 | * UVC ioctls |
| 35 | */ |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 36 | static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, |
Laurent Pinchart | 227bd5b | 2011-07-30 16:19:49 -0300 | [diff] [blame] | 37 | struct uvc_xu_control_mapping *xmap) |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 38 | { |
| 39 | struct uvc_control_mapping *map; |
| 40 | unsigned int size; |
| 41 | int ret; |
| 42 | |
| 43 | map = kzalloc(sizeof *map, GFP_KERNEL); |
| 44 | if (map == NULL) |
| 45 | return -ENOMEM; |
| 46 | |
| 47 | map->id = xmap->id; |
| 48 | memcpy(map->name, xmap->name, sizeof map->name); |
| 49 | memcpy(map->entity, xmap->entity, sizeof map->entity); |
| 50 | map->selector = xmap->selector; |
| 51 | map->size = xmap->size; |
| 52 | map->offset = xmap->offset; |
| 53 | map->v4l2_type = xmap->v4l2_type; |
| 54 | map->data_type = xmap->data_type; |
| 55 | |
| 56 | switch (xmap->v4l2_type) { |
| 57 | case V4L2_CTRL_TYPE_INTEGER: |
| 58 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 59 | case V4L2_CTRL_TYPE_BUTTON: |
| 60 | break; |
| 61 | |
| 62 | case V4L2_CTRL_TYPE_MENU: |
Haogang Chen | 806e23e | 2011-11-29 18:32:25 -0300 | [diff] [blame] | 63 | /* Prevent excessive memory consumption, as well as integer |
| 64 | * overflows. |
| 65 | */ |
| 66 | if (xmap->menu_count == 0 || |
| 67 | xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) { |
| 68 | ret = -EINVAL; |
| 69 | goto done; |
| 70 | } |
| 71 | |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 72 | size = xmap->menu_count * sizeof(*map->menu_info); |
| 73 | map->menu_info = kmalloc(size, GFP_KERNEL); |
| 74 | if (map->menu_info == NULL) { |
| 75 | ret = -ENOMEM; |
| 76 | goto done; |
| 77 | } |
| 78 | |
| 79 | if (copy_from_user(map->menu_info, xmap->menu_info, size)) { |
| 80 | ret = -EFAULT; |
| 81 | goto done; |
| 82 | } |
| 83 | |
| 84 | map->menu_count = xmap->menu_count; |
| 85 | break; |
| 86 | |
| 87 | default: |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 88 | uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type " |
| 89 | "%u.\n", xmap->v4l2_type); |
Mauro Carvalho Chehab | 7a286cc | 2011-06-26 10:18:03 -0300 | [diff] [blame] | 90 | ret = -ENOTTY; |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 91 | goto done; |
| 92 | } |
| 93 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 94 | ret = uvc_ctrl_add_mapping(chain, map); |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 95 | |
| 96 | done: |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 97 | kfree(map->menu_info); |
| 98 | kfree(map); |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | /* ------------------------------------------------------------------------ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 104 | * V4L2 interface |
| 105 | */ |
| 106 | |
| 107 | /* |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 108 | * Find the frame interval closest to the requested frame interval for the |
| 109 | * given frame format and size. This should be done by the device as part of |
| 110 | * the Video Probe and Commit negotiation, but some hardware don't implement |
| 111 | * that feature. |
| 112 | */ |
| 113 | static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval) |
| 114 | { |
| 115 | unsigned int i; |
| 116 | |
| 117 | if (frame->bFrameIntervalType) { |
| 118 | __u32 best = -1, dist; |
| 119 | |
| 120 | for (i = 0; i < frame->bFrameIntervalType; ++i) { |
| 121 | dist = interval > frame->dwFrameInterval[i] |
| 122 | ? interval - frame->dwFrameInterval[i] |
| 123 | : frame->dwFrameInterval[i] - interval; |
| 124 | |
| 125 | if (dist > best) |
| 126 | break; |
| 127 | |
| 128 | best = dist; |
| 129 | } |
| 130 | |
| 131 | interval = frame->dwFrameInterval[i-1]; |
| 132 | } else { |
| 133 | const __u32 min = frame->dwFrameInterval[0]; |
| 134 | const __u32 max = frame->dwFrameInterval[1]; |
| 135 | const __u32 step = frame->dwFrameInterval[2]; |
| 136 | |
| 137 | interval = min + (interval - min + step/2) / step * step; |
| 138 | if (interval > max) |
| 139 | interval = max; |
| 140 | } |
| 141 | |
| 142 | return interval; |
| 143 | } |
| 144 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 145 | static int uvc_v4l2_try_format(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 146 | struct v4l2_format *fmt, struct uvc_streaming_control *probe, |
| 147 | struct uvc_format **uvc_format, struct uvc_frame **uvc_frame) |
| 148 | { |
| 149 | struct uvc_format *format = NULL; |
| 150 | struct uvc_frame *frame = NULL; |
| 151 | __u16 rw, rh; |
| 152 | unsigned int d, maxd; |
| 153 | unsigned int i; |
| 154 | __u32 interval; |
| 155 | int ret = 0; |
| 156 | __u8 *fcc; |
| 157 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 158 | if (fmt->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 159 | return -EINVAL; |
| 160 | |
| 161 | fcc = (__u8 *)&fmt->fmt.pix.pixelformat; |
| 162 | uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n", |
| 163 | fmt->fmt.pix.pixelformat, |
| 164 | fcc[0], fcc[1], fcc[2], fcc[3], |
| 165 | fmt->fmt.pix.width, fmt->fmt.pix.height); |
| 166 | |
Laurent Pinchart | 815adc4 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 167 | /* Check if the hardware supports the requested format, use the default |
| 168 | * format otherwise. |
| 169 | */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 170 | for (i = 0; i < stream->nformats; ++i) { |
| 171 | format = &stream->format[i]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 172 | if (format->fcc == fmt->fmt.pix.pixelformat) |
| 173 | break; |
| 174 | } |
| 175 | |
Laurent Pinchart | 815adc4 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 176 | if (i == stream->nformats) { |
| 177 | format = stream->def_format; |
| 178 | fmt->fmt.pix.pixelformat = format->fcc; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* Find the closest image size. The distance between image sizes is |
| 182 | * the size in pixels of the non-overlapping regions between the |
| 183 | * requested size and the frame-specified size. |
| 184 | */ |
| 185 | rw = fmt->fmt.pix.width; |
| 186 | rh = fmt->fmt.pix.height; |
| 187 | maxd = (unsigned int)-1; |
| 188 | |
| 189 | for (i = 0; i < format->nframes; ++i) { |
| 190 | __u16 w = format->frame[i].wWidth; |
| 191 | __u16 h = format->frame[i].wHeight; |
| 192 | |
| 193 | d = min(w, rw) * min(h, rh); |
| 194 | d = w*h + rw*rh - 2*d; |
| 195 | if (d < maxd) { |
| 196 | maxd = d; |
| 197 | frame = &format->frame[i]; |
| 198 | } |
| 199 | |
| 200 | if (maxd == 0) |
| 201 | break; |
| 202 | } |
| 203 | |
| 204 | if (frame == NULL) { |
| 205 | uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n", |
| 206 | fmt->fmt.pix.width, fmt->fmt.pix.height); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | /* Use the default frame interval. */ |
| 211 | interval = frame->dwDefaultFrameInterval; |
| 212 | uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us " |
| 213 | "(%u.%u fps).\n", interval/10, interval%10, 10000000/interval, |
| 214 | (100000000/interval)%10); |
| 215 | |
| 216 | /* Set the format index, frame index and frame interval. */ |
| 217 | memset(probe, 0, sizeof *probe); |
| 218 | probe->bmHint = 1; /* dwFrameInterval */ |
| 219 | probe->bFormatIndex = format->index; |
| 220 | probe->bFrameIndex = frame->bFrameIndex; |
| 221 | probe->dwFrameInterval = uvc_try_frame_interval(frame, interval); |
| 222 | /* Some webcams stall the probe control set request when the |
| 223 | * dwMaxVideoFrameSize field is set to zero. The UVC specification |
| 224 | * clearly states that the field is read-only from the host, so this |
| 225 | * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by |
| 226 | * the webcam to work around the problem. |
| 227 | * |
| 228 | * The workaround could probably be enabled for all webcams, so the |
| 229 | * quirk can be removed if needed. It's currently useful to detect |
| 230 | * webcam bugs and fix them before they hit the market (providing |
| 231 | * developers test their webcams with the Linux driver as well as with |
| 232 | * the Windows driver). |
| 233 | */ |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 234 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 235 | if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 236 | probe->dwMaxVideoFrameSize = |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 237 | stream->ctrl.dwMaxVideoFrameSize; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 238 | |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 239 | /* Probe the device. */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 240 | ret = uvc_probe_video(stream, probe); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 241 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 242 | if (ret < 0) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 243 | goto done; |
| 244 | |
| 245 | fmt->fmt.pix.width = frame->wWidth; |
| 246 | fmt->fmt.pix.height = frame->wHeight; |
| 247 | fmt->fmt.pix.field = V4L2_FIELD_NONE; |
| 248 | fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8; |
| 249 | fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize; |
| 250 | fmt->fmt.pix.colorspace = format->colorspace; |
| 251 | fmt->fmt.pix.priv = 0; |
| 252 | |
| 253 | if (uvc_format != NULL) |
| 254 | *uvc_format = format; |
| 255 | if (uvc_frame != NULL) |
| 256 | *uvc_frame = frame; |
| 257 | |
| 258 | done: |
| 259 | return ret; |
| 260 | } |
| 261 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 262 | static int uvc_v4l2_get_format(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 263 | struct v4l2_format *fmt) |
| 264 | { |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 265 | struct uvc_format *format; |
| 266 | struct uvc_frame *frame; |
| 267 | int ret = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 268 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 269 | if (fmt->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 270 | return -EINVAL; |
| 271 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 272 | mutex_lock(&stream->mutex); |
| 273 | format = stream->cur_format; |
| 274 | frame = stream->cur_frame; |
| 275 | |
| 276 | if (format == NULL || frame == NULL) { |
| 277 | ret = -EINVAL; |
| 278 | goto done; |
| 279 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 280 | |
| 281 | fmt->fmt.pix.pixelformat = format->fcc; |
| 282 | fmt->fmt.pix.width = frame->wWidth; |
| 283 | fmt->fmt.pix.height = frame->wHeight; |
| 284 | fmt->fmt.pix.field = V4L2_FIELD_NONE; |
| 285 | fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 286 | fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 287 | fmt->fmt.pix.colorspace = format->colorspace; |
| 288 | fmt->fmt.pix.priv = 0; |
| 289 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 290 | done: |
| 291 | mutex_unlock(&stream->mutex); |
| 292 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 293 | } |
| 294 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 295 | static int uvc_v4l2_set_format(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 296 | struct v4l2_format *fmt) |
| 297 | { |
| 298 | struct uvc_streaming_control probe; |
| 299 | struct uvc_format *format; |
| 300 | struct uvc_frame *frame; |
| 301 | int ret; |
| 302 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 303 | if (fmt->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 304 | return -EINVAL; |
| 305 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 306 | ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 307 | if (ret < 0) |
| 308 | return ret; |
| 309 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 310 | mutex_lock(&stream->mutex); |
| 311 | |
| 312 | if (uvc_queue_allocated(&stream->queue)) { |
| 313 | ret = -EBUSY; |
| 314 | goto done; |
| 315 | } |
| 316 | |
Ezequiel Garcia | 8c0d44e | 2013-01-14 15:22:55 -0300 | [diff] [blame] | 317 | stream->ctrl = probe; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 318 | stream->cur_format = format; |
| 319 | stream->cur_frame = frame; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 320 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 321 | done: |
| 322 | mutex_unlock(&stream->mutex); |
| 323 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 324 | } |
| 325 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 326 | static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 327 | struct v4l2_streamparm *parm) |
| 328 | { |
| 329 | uint32_t numerator, denominator; |
| 330 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 331 | if (parm->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 332 | return -EINVAL; |
| 333 | |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 334 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 335 | numerator = stream->ctrl.dwFrameInterval; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 336 | mutex_unlock(&stream->mutex); |
| 337 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 338 | denominator = 10000000; |
| 339 | uvc_simplify_fraction(&numerator, &denominator, 8, 333); |
| 340 | |
| 341 | memset(parm, 0, sizeof *parm); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 342 | parm->type = stream->type; |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 343 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 344 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 345 | parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; |
| 346 | parm->parm.capture.capturemode = 0; |
| 347 | parm->parm.capture.timeperframe.numerator = numerator; |
| 348 | parm->parm.capture.timeperframe.denominator = denominator; |
| 349 | parm->parm.capture.extendedmode = 0; |
| 350 | parm->parm.capture.readbuffers = 0; |
| 351 | } else { |
| 352 | parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; |
| 353 | parm->parm.output.outputmode = 0; |
| 354 | parm->parm.output.timeperframe.numerator = numerator; |
| 355 | parm->parm.output.timeperframe.denominator = denominator; |
| 356 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 361 | static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 362 | struct v4l2_streamparm *parm) |
| 363 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 364 | struct uvc_streaming_control probe; |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 365 | struct v4l2_fract timeperframe; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 366 | uint32_t interval; |
| 367 | int ret; |
| 368 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 369 | if (parm->type != stream->type) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 370 | return -EINVAL; |
| 371 | |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 372 | if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 373 | timeperframe = parm->parm.capture.timeperframe; |
| 374 | else |
| 375 | timeperframe = parm->parm.output.timeperframe; |
| 376 | |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 377 | interval = uvc_fraction_to_interval(timeperframe.numerator, |
| 378 | timeperframe.denominator); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 379 | 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] | 380 | timeperframe.numerator, timeperframe.denominator, interval); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 381 | |
| 382 | mutex_lock(&stream->mutex); |
| 383 | |
| 384 | if (uvc_queue_streaming(&stream->queue)) { |
| 385 | mutex_unlock(&stream->mutex); |
| 386 | return -EBUSY; |
| 387 | } |
| 388 | |
Ezequiel Garcia | 8c0d44e | 2013-01-14 15:22:55 -0300 | [diff] [blame] | 389 | probe = stream->ctrl; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 390 | probe.dwFrameInterval = |
| 391 | uvc_try_frame_interval(stream->cur_frame, interval); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 392 | |
| 393 | /* Probe the device with the new settings. */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 394 | ret = uvc_probe_video(stream, &probe); |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 395 | if (ret < 0) { |
| 396 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 397 | return ret; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 398 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 399 | |
Ezequiel Garcia | 8c0d44e | 2013-01-14 15:22:55 -0300 | [diff] [blame] | 400 | stream->ctrl = probe; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 401 | mutex_unlock(&stream->mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 402 | |
| 403 | /* Return the actual frame period. */ |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 404 | timeperframe.numerator = probe.dwFrameInterval; |
| 405 | timeperframe.denominator = 10000000; |
| 406 | uvc_simplify_fraction(&timeperframe.numerator, |
| 407 | &timeperframe.denominator, 8, 333); |
| 408 | |
| 409 | if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 410 | parm->parm.capture.timeperframe = timeperframe; |
| 411 | else |
| 412 | parm->parm.output.timeperframe = timeperframe; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | /* ------------------------------------------------------------------------ |
| 418 | * Privilege management |
| 419 | */ |
| 420 | |
| 421 | /* |
| 422 | * Privilege management is the multiple-open implementation basis. The current |
| 423 | * implementation is completely transparent for the end-user and doesn't |
| 424 | * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls. |
| 425 | * Those ioctls enable finer control on the device (by making possible for a |
| 426 | * user to request exclusive access to a device), but are not mature yet. |
| 427 | * Switching to the V4L2 priority mechanism might be considered in the future |
| 428 | * if this situation changes. |
| 429 | * |
| 430 | * Each open instance of a UVC device can either be in a privileged or |
| 431 | * 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] | 432 | * a given time. Trying to perform an operation that requires privileges will |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 433 | * automatically acquire the required privileges if possible, or return -EBUSY |
Laurent Pinchart | 1a969d9 | 2009-09-02 03:12:26 -0300 | [diff] [blame] | 434 | * otherwise. Privileges are dismissed when closing the instance or when |
| 435 | * freeing the video buffers using VIDIOC_REQBUFS. |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 436 | * |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 437 | * Operations that require privileges are: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 438 | * |
| 439 | * - VIDIOC_S_INPUT |
| 440 | * - VIDIOC_S_PARM |
| 441 | * - VIDIOC_S_FMT |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 442 | * - VIDIOC_REQBUFS |
| 443 | */ |
| 444 | static int uvc_acquire_privileges(struct uvc_fh *handle) |
| 445 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 446 | /* Always succeed if the handle is already privileged. */ |
| 447 | if (handle->state == UVC_HANDLE_ACTIVE) |
| 448 | return 0; |
| 449 | |
| 450 | /* Check if the device already has a privileged handle. */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 451 | if (atomic_inc_return(&handle->stream->active) != 1) { |
| 452 | atomic_dec(&handle->stream->active); |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 453 | return -EBUSY; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | handle->state = UVC_HANDLE_ACTIVE; |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 457 | return 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void uvc_dismiss_privileges(struct uvc_fh *handle) |
| 461 | { |
| 462 | if (handle->state == UVC_HANDLE_ACTIVE) |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 463 | atomic_dec(&handle->stream->active); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 464 | |
| 465 | handle->state = UVC_HANDLE_PASSIVE; |
| 466 | } |
| 467 | |
| 468 | static int uvc_has_privileges(struct uvc_fh *handle) |
| 469 | { |
| 470 | return handle->state == UVC_HANDLE_ACTIVE; |
| 471 | } |
| 472 | |
| 473 | /* ------------------------------------------------------------------------ |
| 474 | * V4L2 file operations |
| 475 | */ |
| 476 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 477 | static int uvc_v4l2_open(struct file *file) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 478 | { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 479 | struct uvc_streaming *stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 480 | struct uvc_fh *handle; |
| 481 | int ret = 0; |
| 482 | |
| 483 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 484 | stream = video_drvdata(file); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 485 | |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 486 | if (stream->dev->state & UVC_DEV_DISCONNECTED) |
| 487 | return -ENODEV; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 488 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 489 | ret = usb_autopm_get_interface(stream->dev->intf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 490 | if (ret < 0) |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 491 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 492 | |
| 493 | /* Create the device handle. */ |
| 494 | handle = kzalloc(sizeof *handle, GFP_KERNEL); |
| 495 | if (handle == NULL) { |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 496 | usb_autopm_put_interface(stream->dev->intf); |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 497 | return -ENOMEM; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 498 | } |
| 499 | |
Laurent Pinchart | 17706f5 | 2013-04-25 22:28:51 -0300 | [diff] [blame] | 500 | mutex_lock(&stream->dev->lock); |
| 501 | if (stream->dev->users == 0) { |
| 502 | ret = uvc_status_start(stream->dev, GFP_KERNEL); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 503 | if (ret < 0) { |
Laurent Pinchart | 17706f5 | 2013-04-25 22:28:51 -0300 | [diff] [blame] | 504 | mutex_unlock(&stream->dev->lock); |
Oliver Neukum | a82a45f | 2013-01-10 07:04:55 -0300 | [diff] [blame] | 505 | usb_autopm_put_interface(stream->dev->intf); |
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 | |
Laurent Pinchart | 17706f5 | 2013-04-25 22:28:51 -0300 | [diff] [blame] | 511 | stream->dev->users++; |
| 512 | mutex_unlock(&stream->dev->lock); |
| 513 | |
Hans Verkuil | d8da751 | 2015-03-09 13:34:11 -0300 | [diff] [blame] | 514 | v4l2_fh_init(&handle->vfh, &stream->vdev); |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 515 | v4l2_fh_add(&handle->vfh); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 516 | handle->chain = stream->chain; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 517 | handle->stream = stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 518 | handle->state = UVC_HANDLE_PASSIVE; |
| 519 | file->private_data = handle; |
| 520 | |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 521 | return 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 522 | } |
| 523 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 524 | static int uvc_v4l2_release(struct file *file) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 525 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 526 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 527 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 528 | |
| 529 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n"); |
| 530 | |
| 531 | /* Only free resources if this is a privileged handle. */ |
Laurent Pinchart | 3f02de2 | 2014-10-21 16:07:15 -0300 | [diff] [blame] | 532 | if (uvc_has_privileges(handle)) |
| 533 | uvc_queue_release(&stream->queue); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 534 | |
| 535 | /* Release the file handle. */ |
| 536 | uvc_dismiss_privileges(handle); |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 537 | v4l2_fh_del(&handle->vfh); |
| 538 | v4l2_fh_exit(&handle->vfh); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 539 | kfree(handle); |
| 540 | file->private_data = NULL; |
| 541 | |
Laurent Pinchart | 17706f5 | 2013-04-25 22:28:51 -0300 | [diff] [blame] | 542 | mutex_lock(&stream->dev->lock); |
| 543 | if (--stream->dev->users == 0) |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 544 | uvc_status_stop(stream->dev); |
Laurent Pinchart | 17706f5 | 2013-04-25 22:28:51 -0300 | [diff] [blame] | 545 | mutex_unlock(&stream->dev->lock); |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 546 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 547 | usb_autopm_put_interface(stream->dev->intf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 551 | static int uvc_ioctl_querycap(struct file *file, void *fh, |
| 552 | struct v4l2_capability *cap) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 553 | { |
| 554 | struct video_device *vdev = video_devdata(file); |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 555 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 556 | struct uvc_video_chain *chain = handle->chain; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 557 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 558 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 559 | strlcpy(cap->driver, "uvcvideo", sizeof(cap->driver)); |
| 560 | strlcpy(cap->card, vdev->name, sizeof(cap->card)); |
| 561 | usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
| 562 | cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING |
| 563 | | chain->caps; |
| 564 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 565 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
| 566 | else |
| 567 | cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 568 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream, |
| 573 | struct v4l2_fmtdesc *fmt) |
| 574 | { |
| 575 | struct uvc_format *format; |
| 576 | enum v4l2_buf_type type = fmt->type; |
| 577 | __u32 index = fmt->index; |
| 578 | |
| 579 | if (fmt->type != stream->type || fmt->index >= stream->nformats) |
| 580 | return -EINVAL; |
| 581 | |
| 582 | memset(fmt, 0, sizeof(*fmt)); |
| 583 | fmt->index = index; |
| 584 | fmt->type = type; |
| 585 | |
| 586 | format = &stream->format[fmt->index]; |
| 587 | fmt->flags = 0; |
| 588 | if (format->flags & UVC_FMT_FLAG_COMPRESSED) |
| 589 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; |
| 590 | strlcpy(fmt->description, format->name, sizeof(fmt->description)); |
| 591 | fmt->description[sizeof(fmt->description) - 1] = 0; |
| 592 | fmt->pixelformat = format->fcc; |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static int uvc_ioctl_enum_fmt_vid_cap(struct file *file, void *fh, |
| 597 | struct v4l2_fmtdesc *fmt) |
| 598 | { |
| 599 | struct uvc_fh *handle = fh; |
| 600 | struct uvc_streaming *stream = handle->stream; |
| 601 | |
| 602 | return uvc_ioctl_enum_fmt(stream, fmt); |
| 603 | } |
| 604 | |
| 605 | static int uvc_ioctl_enum_fmt_vid_out(struct file *file, void *fh, |
| 606 | struct v4l2_fmtdesc *fmt) |
| 607 | { |
| 608 | struct uvc_fh *handle = fh; |
| 609 | struct uvc_streaming *stream = handle->stream; |
| 610 | |
| 611 | return uvc_ioctl_enum_fmt(stream, fmt); |
| 612 | } |
| 613 | |
| 614 | static int uvc_ioctl_g_fmt_vid_cap(struct file *file, void *fh, |
| 615 | struct v4l2_format *fmt) |
| 616 | { |
| 617 | struct uvc_fh *handle = fh; |
| 618 | struct uvc_streaming *stream = handle->stream; |
| 619 | |
| 620 | return uvc_v4l2_get_format(stream, fmt); |
| 621 | } |
| 622 | |
| 623 | static int uvc_ioctl_g_fmt_vid_out(struct file *file, void *fh, |
| 624 | struct v4l2_format *fmt) |
| 625 | { |
| 626 | struct uvc_fh *handle = fh; |
| 627 | struct uvc_streaming *stream = handle->stream; |
| 628 | |
| 629 | return uvc_v4l2_get_format(stream, fmt); |
| 630 | } |
| 631 | |
| 632 | static int uvc_ioctl_s_fmt_vid_cap(struct file *file, void *fh, |
| 633 | struct v4l2_format *fmt) |
| 634 | { |
| 635 | struct uvc_fh *handle = fh; |
| 636 | struct uvc_streaming *stream = handle->stream; |
| 637 | int ret; |
| 638 | |
| 639 | ret = uvc_acquire_privileges(handle); |
| 640 | if (ret < 0) |
| 641 | return ret; |
| 642 | |
| 643 | return uvc_v4l2_set_format(stream, fmt); |
| 644 | } |
| 645 | |
| 646 | static int uvc_ioctl_s_fmt_vid_out(struct file *file, void *fh, |
| 647 | struct v4l2_format *fmt) |
| 648 | { |
| 649 | struct uvc_fh *handle = fh; |
| 650 | struct uvc_streaming *stream = handle->stream; |
| 651 | int ret; |
| 652 | |
| 653 | ret = uvc_acquire_privileges(handle); |
| 654 | if (ret < 0) |
| 655 | return ret; |
| 656 | |
| 657 | return uvc_v4l2_set_format(stream, fmt); |
| 658 | } |
| 659 | |
| 660 | static int uvc_ioctl_try_fmt_vid_cap(struct file *file, void *fh, |
| 661 | struct v4l2_format *fmt) |
| 662 | { |
| 663 | struct uvc_fh *handle = fh; |
| 664 | struct uvc_streaming *stream = handle->stream; |
| 665 | struct uvc_streaming_control probe; |
| 666 | |
| 667 | return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); |
| 668 | } |
| 669 | |
| 670 | static int uvc_ioctl_try_fmt_vid_out(struct file *file, void *fh, |
| 671 | struct v4l2_format *fmt) |
| 672 | { |
| 673 | struct uvc_fh *handle = fh; |
| 674 | struct uvc_streaming *stream = handle->stream; |
| 675 | struct uvc_streaming_control probe; |
| 676 | |
| 677 | return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); |
| 678 | } |
| 679 | |
| 680 | static int uvc_ioctl_reqbufs(struct file *file, void *fh, |
| 681 | struct v4l2_requestbuffers *rb) |
| 682 | { |
| 683 | struct uvc_fh *handle = fh; |
| 684 | struct uvc_streaming *stream = handle->stream; |
| 685 | int ret; |
| 686 | |
| 687 | ret = uvc_acquire_privileges(handle); |
| 688 | if (ret < 0) |
| 689 | return ret; |
| 690 | |
| 691 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 1b7f9c9 | 2014-10-21 16:02:00 -0300 | [diff] [blame] | 692 | ret = uvc_request_buffers(&stream->queue, rb); |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 693 | mutex_unlock(&stream->mutex); |
| 694 | if (ret < 0) |
| 695 | return ret; |
| 696 | |
| 697 | if (ret == 0) |
| 698 | uvc_dismiss_privileges(handle); |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | static int uvc_ioctl_querybuf(struct file *file, void *fh, |
| 704 | struct v4l2_buffer *buf) |
| 705 | { |
| 706 | struct uvc_fh *handle = fh; |
| 707 | struct uvc_streaming *stream = handle->stream; |
| 708 | |
| 709 | if (!uvc_has_privileges(handle)) |
| 710 | return -EBUSY; |
| 711 | |
| 712 | return uvc_query_buffer(&stream->queue, buf); |
| 713 | } |
| 714 | |
| 715 | static int uvc_ioctl_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf) |
| 716 | { |
| 717 | struct uvc_fh *handle = fh; |
| 718 | struct uvc_streaming *stream = handle->stream; |
| 719 | |
| 720 | if (!uvc_has_privileges(handle)) |
| 721 | return -EBUSY; |
| 722 | |
| 723 | return uvc_queue_buffer(&stream->queue, buf); |
| 724 | } |
| 725 | |
| 726 | static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) |
| 727 | { |
| 728 | struct uvc_fh *handle = fh; |
| 729 | struct uvc_streaming *stream = handle->stream; |
| 730 | |
| 731 | if (!uvc_has_privileges(handle)) |
| 732 | return -EBUSY; |
| 733 | |
| 734 | return uvc_dequeue_buffer(&stream->queue, buf, |
| 735 | file->f_flags & O_NONBLOCK); |
| 736 | } |
| 737 | |
| 738 | static int uvc_ioctl_create_bufs(struct file *file, void *fh, |
| 739 | struct v4l2_create_buffers *cb) |
| 740 | { |
| 741 | struct uvc_fh *handle = fh; |
| 742 | struct uvc_streaming *stream = handle->stream; |
| 743 | int ret; |
| 744 | |
| 745 | ret = uvc_acquire_privileges(handle); |
| 746 | if (ret < 0) |
| 747 | return ret; |
| 748 | |
| 749 | return uvc_create_buffers(&stream->queue, cb); |
| 750 | } |
| 751 | |
| 752 | static int uvc_ioctl_streamon(struct file *file, void *fh, |
| 753 | enum v4l2_buf_type type) |
| 754 | { |
| 755 | struct uvc_fh *handle = fh; |
| 756 | struct uvc_streaming *stream = handle->stream; |
| 757 | int ret; |
| 758 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 759 | if (!uvc_has_privileges(handle)) |
| 760 | return -EBUSY; |
| 761 | |
| 762 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 0da4ab9 | 2014-10-21 16:19:04 -0300 | [diff] [blame] | 763 | ret = uvc_queue_streamon(&stream->queue, type); |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 764 | mutex_unlock(&stream->mutex); |
| 765 | |
| 766 | return ret; |
| 767 | } |
| 768 | |
| 769 | static int uvc_ioctl_streamoff(struct file *file, void *fh, |
| 770 | enum v4l2_buf_type type) |
| 771 | { |
| 772 | struct uvc_fh *handle = fh; |
| 773 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 774 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 775 | if (!uvc_has_privileges(handle)) |
| 776 | return -EBUSY; |
| 777 | |
| 778 | mutex_lock(&stream->mutex); |
Laurent Pinchart | 0da4ab9 | 2014-10-21 16:19:04 -0300 | [diff] [blame] | 779 | uvc_queue_streamoff(&stream->queue, type); |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 780 | mutex_unlock(&stream->mutex); |
| 781 | |
Laurent Pinchart | b83bba2 | 2014-10-13 10:11:35 -0300 | [diff] [blame] | 782 | return 0; |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | static int uvc_ioctl_enum_input(struct file *file, void *fh, |
| 786 | struct v4l2_input *input) |
| 787 | { |
| 788 | struct uvc_fh *handle = fh; |
| 789 | struct uvc_video_chain *chain = handle->chain; |
| 790 | const struct uvc_entity *selector = chain->selector; |
| 791 | struct uvc_entity *iterm = NULL; |
| 792 | u32 index = input->index; |
| 793 | int pin = 0; |
| 794 | |
| 795 | if (selector == NULL || |
| 796 | (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { |
| 797 | if (index != 0) |
| 798 | return -EINVAL; |
| 799 | list_for_each_entry(iterm, &chain->entities, chain) { |
| 800 | if (UVC_ENTITY_IS_ITERM(iterm)) |
| 801 | break; |
| 802 | } |
| 803 | pin = iterm->id; |
| 804 | } else if (index < selector->bNrInPins) { |
| 805 | pin = selector->baSourceID[index]; |
| 806 | list_for_each_entry(iterm, &chain->entities, chain) { |
| 807 | if (!UVC_ENTITY_IS_ITERM(iterm)) |
| 808 | continue; |
| 809 | if (iterm->id == pin) |
| 810 | break; |
| 811 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 812 | } |
| 813 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 814 | if (iterm == NULL || iterm->id != pin) |
| 815 | return -EINVAL; |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame] | 816 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 817 | memset(input, 0, sizeof(*input)); |
| 818 | input->index = index; |
| 819 | strlcpy(input->name, iterm->name, sizeof(input->name)); |
| 820 | if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA) |
| 821 | input->type = V4L2_INPUT_TYPE_CAMERA; |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame] | 822 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 823 | return 0; |
| 824 | } |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame] | 825 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 826 | static int uvc_ioctl_g_input(struct file *file, void *fh, unsigned int *input) |
| 827 | { |
| 828 | struct uvc_fh *handle = fh; |
| 829 | struct uvc_video_chain *chain = handle->chain; |
| 830 | int ret; |
| 831 | u8 i; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 832 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 833 | if (chain->selector == NULL || |
| 834 | (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { |
| 835 | *input = 0; |
| 836 | return 0; |
| 837 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 838 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 839 | ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, chain->selector->id, |
| 840 | chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, |
| 841 | &i, 1); |
| 842 | if (ret < 0) |
| 843 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 844 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 845 | *input = i - 1; |
| 846 | return 0; |
| 847 | } |
Robert Krakora | 1fcbcc4 | 2009-06-12 13:51:03 -0300 | [diff] [blame] | 848 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 849 | static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input) |
| 850 | { |
| 851 | struct uvc_fh *handle = fh; |
| 852 | struct uvc_video_chain *chain = handle->chain; |
| 853 | int ret; |
| 854 | u32 i; |
| 855 | |
| 856 | ret = uvc_acquire_privileges(handle); |
| 857 | if (ret < 0) |
| 858 | return ret; |
| 859 | |
| 860 | if (chain->selector == NULL || |
| 861 | (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { |
| 862 | if (input) |
| 863 | return -EINVAL; |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | if (input >= chain->selector->bNrInPins) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | i = input + 1; |
| 871 | return uvc_query_ctrl(chain->dev, UVC_SET_CUR, chain->selector->id, |
| 872 | chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, |
| 873 | &i, 1); |
| 874 | } |
| 875 | |
| 876 | static int uvc_ioctl_queryctrl(struct file *file, void *fh, |
| 877 | struct v4l2_queryctrl *qc) |
| 878 | { |
| 879 | struct uvc_fh *handle = fh; |
| 880 | struct uvc_video_chain *chain = handle->chain; |
| 881 | |
| 882 | return uvc_query_v4l2_ctrl(chain, qc); |
| 883 | } |
| 884 | |
| 885 | static int uvc_ioctl_g_ctrl(struct file *file, void *fh, |
| 886 | struct v4l2_control *ctrl) |
| 887 | { |
| 888 | struct uvc_fh *handle = fh; |
| 889 | struct uvc_video_chain *chain = handle->chain; |
| 890 | struct v4l2_ext_control xctrl; |
| 891 | int ret; |
| 892 | |
| 893 | memset(&xctrl, 0, sizeof(xctrl)); |
| 894 | xctrl.id = ctrl->id; |
| 895 | |
| 896 | ret = uvc_ctrl_begin(chain); |
| 897 | if (ret < 0) |
| 898 | return ret; |
| 899 | |
| 900 | ret = uvc_ctrl_get(chain, &xctrl); |
| 901 | uvc_ctrl_rollback(handle); |
| 902 | if (ret < 0) |
| 903 | return ret; |
| 904 | |
| 905 | ctrl->value = xctrl.value; |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | static int uvc_ioctl_s_ctrl(struct file *file, void *fh, |
| 910 | struct v4l2_control *ctrl) |
| 911 | { |
| 912 | struct uvc_fh *handle = fh; |
| 913 | struct uvc_video_chain *chain = handle->chain; |
| 914 | struct v4l2_ext_control xctrl; |
| 915 | int ret; |
| 916 | |
| 917 | memset(&xctrl, 0, sizeof(xctrl)); |
| 918 | xctrl.id = ctrl->id; |
| 919 | xctrl.value = ctrl->value; |
| 920 | |
| 921 | ret = uvc_ctrl_begin(chain); |
| 922 | if (ret < 0) |
| 923 | return ret; |
| 924 | |
| 925 | ret = uvc_ctrl_set(chain, &xctrl); |
| 926 | if (ret < 0) { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 927 | uvc_ctrl_rollback(handle); |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 928 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 929 | } |
| 930 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 931 | ret = uvc_ctrl_commit(handle, &xctrl, 1); |
| 932 | if (ret < 0) |
| 933 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 934 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 935 | ctrl->value = xctrl.value; |
| 936 | return 0; |
| 937 | } |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame] | 938 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 939 | static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, |
| 940 | struct v4l2_ext_controls *ctrls) |
| 941 | { |
| 942 | struct uvc_fh *handle = fh; |
| 943 | struct uvc_video_chain *chain = handle->chain; |
| 944 | struct v4l2_ext_control *ctrl = ctrls->controls; |
| 945 | unsigned int i; |
| 946 | int ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 947 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 948 | ret = uvc_ctrl_begin(chain); |
| 949 | if (ret < 0) |
| 950 | return ret; |
Robert Krakora | 1fcbcc4 | 2009-06-12 13:51:03 -0300 | [diff] [blame] | 951 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 952 | for (i = 0; i < ctrls->count; ++ctrl, ++i) { |
| 953 | ret = uvc_ctrl_get(chain, ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 954 | if (ret < 0) { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 955 | uvc_ctrl_rollback(handle); |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 956 | ctrls->error_idx = i; |
Rafael J. Wysocki | 9c016d6 | 2012-12-23 14:39:32 +0100 | [diff] [blame] | 957 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 958 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 959 | } |
| 960 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 961 | ctrls->error_idx = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 962 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 963 | return uvc_ctrl_rollback(handle); |
| 964 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 965 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 966 | static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, |
| 967 | struct v4l2_ext_controls *ctrls, |
| 968 | bool commit) |
| 969 | { |
| 970 | struct v4l2_ext_control *ctrl = ctrls->controls; |
| 971 | struct uvc_video_chain *chain = handle->chain; |
| 972 | unsigned int i; |
| 973 | int ret; |
| 974 | |
| 975 | ret = uvc_ctrl_begin(chain); |
| 976 | if (ret < 0) |
| 977 | return ret; |
| 978 | |
| 979 | for (i = 0; i < ctrls->count; ++ctrl, ++i) { |
| 980 | ret = uvc_ctrl_set(chain, ctrl); |
| 981 | if (ret < 0) { |
| 982 | uvc_ctrl_rollback(handle); |
| 983 | ctrls->error_idx = commit ? ctrls->count : i; |
Robert Krakora | 1fcbcc4 | 2009-06-12 13:51:03 -0300 | [diff] [blame] | 984 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 985 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 986 | } |
| 987 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 988 | ctrls->error_idx = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 989 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 990 | if (commit) |
| 991 | return uvc_ctrl_commit(handle, ctrls->controls, ctrls->count); |
| 992 | else |
| 993 | return uvc_ctrl_rollback(handle); |
| 994 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 995 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 996 | static int uvc_ioctl_s_ext_ctrls(struct file *file, void *fh, |
| 997 | struct v4l2_ext_controls *ctrls) |
| 998 | { |
| 999 | struct uvc_fh *handle = fh; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1000 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1001 | return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, true); |
| 1002 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1003 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1004 | static int uvc_ioctl_try_ext_ctrls(struct file *file, void *fh, |
| 1005 | struct v4l2_ext_controls *ctrls) |
| 1006 | { |
| 1007 | struct uvc_fh *handle = fh; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1008 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1009 | return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, false); |
| 1010 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1011 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1012 | static int uvc_ioctl_querymenu(struct file *file, void *fh, |
| 1013 | struct v4l2_querymenu *qm) |
| 1014 | { |
| 1015 | struct uvc_fh *handle = fh; |
| 1016 | struct uvc_video_chain *chain = handle->chain; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1017 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1018 | return uvc_query_v4l2_menu(chain, qm); |
| 1019 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1020 | |
Hans Verkuil | 1461fe7 | 2015-04-03 06:53:42 -0300 | [diff] [blame^] | 1021 | static int uvc_ioctl_g_selection(struct file *file, void *fh, |
| 1022 | struct v4l2_selection *sel) |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1023 | { |
| 1024 | struct uvc_fh *handle = fh; |
| 1025 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1026 | |
Hans Verkuil | 1461fe7 | 2015-04-03 06:53:42 -0300 | [diff] [blame^] | 1027 | if (sel->type != stream->type) |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1028 | return -EINVAL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1029 | |
Hans Verkuil | 1461fe7 | 2015-04-03 06:53:42 -0300 | [diff] [blame^] | 1030 | switch (sel->target) { |
| 1031 | case V4L2_SEL_TGT_CROP_DEFAULT: |
| 1032 | case V4L2_SEL_TGT_CROP_BOUNDS: |
| 1033 | if (stream->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1034 | return -EINVAL; |
| 1035 | break; |
| 1036 | case V4L2_SEL_TGT_COMPOSE_DEFAULT: |
| 1037 | case V4L2_SEL_TGT_COMPOSE_BOUNDS: |
| 1038 | if (stream->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 1039 | return -EINVAL; |
| 1040 | break; |
| 1041 | default: |
| 1042 | return -EINVAL; |
| 1043 | } |
| 1044 | |
| 1045 | sel->r.left = 0; |
| 1046 | sel->r.top = 0; |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1047 | mutex_lock(&stream->mutex); |
Hans Verkuil | 1461fe7 | 2015-04-03 06:53:42 -0300 | [diff] [blame^] | 1048 | sel->r.width = stream->cur_frame->wWidth; |
| 1049 | sel->r.height = stream->cur_frame->wHeight; |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1050 | mutex_unlock(&stream->mutex); |
| 1051 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | static int uvc_ioctl_g_parm(struct file *file, void *fh, |
| 1056 | struct v4l2_streamparm *parm) |
| 1057 | { |
| 1058 | struct uvc_fh *handle = fh; |
| 1059 | struct uvc_streaming *stream = handle->stream; |
| 1060 | |
| 1061 | return uvc_v4l2_get_streamparm(stream, parm); |
| 1062 | } |
| 1063 | |
| 1064 | static int uvc_ioctl_s_parm(struct file *file, void *fh, |
| 1065 | struct v4l2_streamparm *parm) |
| 1066 | { |
| 1067 | struct uvc_fh *handle = fh; |
| 1068 | struct uvc_streaming *stream = handle->stream; |
| 1069 | int ret; |
| 1070 | |
| 1071 | ret = uvc_acquire_privileges(handle); |
| 1072 | if (ret < 0) |
| 1073 | return ret; |
| 1074 | |
| 1075 | return uvc_v4l2_set_streamparm(stream, parm); |
| 1076 | } |
| 1077 | |
| 1078 | static int uvc_ioctl_enum_framesizes(struct file *file, void *fh, |
| 1079 | struct v4l2_frmsizeenum *fsize) |
| 1080 | { |
| 1081 | struct uvc_fh *handle = fh; |
| 1082 | struct uvc_streaming *stream = handle->stream; |
| 1083 | struct uvc_format *format = NULL; |
| 1084 | struct uvc_frame *frame; |
| 1085 | int i; |
| 1086 | |
| 1087 | /* Look for the given pixel format */ |
| 1088 | for (i = 0; i < stream->nformats; i++) { |
| 1089 | if (stream->format[i].fcc == fsize->pixel_format) { |
| 1090 | format = &stream->format[i]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1091 | break; |
| 1092 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1093 | } |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1094 | if (format == NULL) |
| 1095 | return -EINVAL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1096 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1097 | if (fsize->index >= format->nframes) |
| 1098 | return -EINVAL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1099 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1100 | frame = &format->frame[fsize->index]; |
| 1101 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 1102 | fsize->discrete.width = frame->wWidth; |
| 1103 | fsize->discrete.height = frame->wHeight; |
| 1104 | return 0; |
| 1105 | } |
Laurent Pinchart | 0550513 | 2012-08-28 20:29:56 -0300 | [diff] [blame] | 1106 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1107 | static int uvc_ioctl_enum_frameintervals(struct file *file, void *fh, |
| 1108 | struct v4l2_frmivalenum *fival) |
| 1109 | { |
| 1110 | struct uvc_fh *handle = fh; |
| 1111 | struct uvc_streaming *stream = handle->stream; |
| 1112 | struct uvc_format *format = NULL; |
| 1113 | struct uvc_frame *frame = NULL; |
| 1114 | int i; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1115 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1116 | /* Look for the given pixel format and frame size */ |
| 1117 | for (i = 0; i < stream->nformats; i++) { |
| 1118 | if (stream->format[i].fcc == fival->pixel_format) { |
| 1119 | format = &stream->format[i]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1120 | break; |
| 1121 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1122 | } |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1123 | if (format == NULL) |
| 1124 | return -EINVAL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1125 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1126 | for (i = 0; i < format->nframes; i++) { |
| 1127 | if (format->frame[i].wWidth == fival->width && |
| 1128 | format->frame[i].wHeight == fival->height) { |
| 1129 | frame = &format->frame[i]; |
| 1130 | break; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1131 | } |
| 1132 | } |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1133 | if (frame == NULL) |
| 1134 | return -EINVAL; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1135 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1136 | if (frame->bFrameIntervalType) { |
| 1137 | if (fival->index >= frame->bFrameIntervalType) |
| 1138 | return -EINVAL; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1139 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1140 | fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; |
| 1141 | fival->discrete.numerator = |
| 1142 | frame->dwFrameInterval[fival->index]; |
| 1143 | fival->discrete.denominator = 10000000; |
| 1144 | uvc_simplify_fraction(&fival->discrete.numerator, |
| 1145 | &fival->discrete.denominator, 8, 333); |
| 1146 | } else { |
Laurent Pinchart | 1cdf60c | 2015-03-06 09:54:47 -0300 | [diff] [blame] | 1147 | if (fival->index) |
| 1148 | return -EINVAL; |
| 1149 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1150 | fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; |
| 1151 | fival->stepwise.min.numerator = frame->dwFrameInterval[0]; |
| 1152 | fival->stepwise.min.denominator = 10000000; |
| 1153 | fival->stepwise.max.numerator = frame->dwFrameInterval[1]; |
| 1154 | fival->stepwise.max.denominator = 10000000; |
| 1155 | fival->stepwise.step.numerator = frame->dwFrameInterval[2]; |
| 1156 | fival->stepwise.step.denominator = 10000000; |
| 1157 | uvc_simplify_fraction(&fival->stepwise.min.numerator, |
| 1158 | &fival->stepwise.min.denominator, 8, 333); |
| 1159 | uvc_simplify_fraction(&fival->stepwise.max.numerator, |
| 1160 | &fival->stepwise.max.denominator, 8, 333); |
| 1161 | uvc_simplify_fraction(&fival->stepwise.step.numerator, |
| 1162 | &fival->stepwise.step.denominator, 8, 333); |
| 1163 | } |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1164 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1167 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1168 | static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh, |
| 1169 | const struct v4l2_event_subscription *sub) |
| 1170 | { |
| 1171 | switch (sub->type) { |
| 1172 | case V4L2_EVENT_CTRL: |
| 1173 | return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops); |
| 1174 | default: |
| 1175 | return -EINVAL; |
| 1176 | } |
| 1177 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1178 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1179 | static long uvc_ioctl_default(struct file *file, void *fh, bool valid_prio, |
| 1180 | unsigned int cmd, void *arg) |
| 1181 | { |
| 1182 | struct uvc_fh *handle = fh; |
| 1183 | struct uvc_video_chain *chain = handle->chain; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1184 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1185 | switch (cmd) { |
| 1186 | /* Dynamic controls. */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1187 | case UVCIOC_CTRL_MAP: |
Laurent Pinchart | 227bd5b | 2011-07-30 16:19:49 -0300 | [diff] [blame] | 1188 | return uvc_ioctl_ctrl_map(chain, arg); |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1189 | |
| 1190 | case UVCIOC_CTRL_QUERY: |
| 1191 | return uvc_xu_ctrl_query(chain, arg); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1192 | |
| 1193 | default: |
Laurent Pinchart | a3ec69b | 2011-12-18 20:22:50 -0300 | [diff] [blame] | 1194 | return -ENOTTY; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1195 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1196 | } |
| 1197 | |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1198 | #ifdef CONFIG_COMPAT |
| 1199 | struct uvc_xu_control_mapping32 { |
| 1200 | __u32 id; |
| 1201 | __u8 name[32]; |
| 1202 | __u8 entity[16]; |
| 1203 | __u8 selector; |
| 1204 | |
| 1205 | __u8 size; |
| 1206 | __u8 offset; |
| 1207 | __u32 v4l2_type; |
| 1208 | __u32 data_type; |
| 1209 | |
| 1210 | compat_caddr_t menu_info; |
| 1211 | __u32 menu_count; |
| 1212 | |
| 1213 | __u32 reserved[4]; |
| 1214 | }; |
| 1215 | |
| 1216 | static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp, |
| 1217 | const struct uvc_xu_control_mapping32 __user *up) |
| 1218 | { |
| 1219 | struct uvc_menu_info __user *umenus; |
| 1220 | struct uvc_menu_info __user *kmenus; |
| 1221 | compat_caddr_t p; |
| 1222 | |
| 1223 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 1224 | __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) || |
| 1225 | __get_user(kp->menu_count, &up->menu_count)) |
| 1226 | return -EFAULT; |
| 1227 | |
| 1228 | memset(kp->reserved, 0, sizeof(kp->reserved)); |
| 1229 | |
| 1230 | if (kp->menu_count == 0) { |
| 1231 | kp->menu_info = NULL; |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
| 1235 | if (__get_user(p, &up->menu_info)) |
| 1236 | return -EFAULT; |
| 1237 | umenus = compat_ptr(p); |
| 1238 | if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus))) |
| 1239 | return -EFAULT; |
| 1240 | |
| 1241 | kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus)); |
| 1242 | if (kmenus == NULL) |
| 1243 | return -EFAULT; |
| 1244 | kp->menu_info = kmenus; |
| 1245 | |
| 1246 | if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus))) |
| 1247 | return -EFAULT; |
| 1248 | |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
| 1252 | static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp, |
| 1253 | struct uvc_xu_control_mapping32 __user *up) |
| 1254 | { |
| 1255 | struct uvc_menu_info __user *umenus; |
| 1256 | struct uvc_menu_info __user *kmenus = kp->menu_info; |
| 1257 | compat_caddr_t p; |
| 1258 | |
| 1259 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
| 1260 | __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) || |
| 1261 | __put_user(kp->menu_count, &up->menu_count)) |
| 1262 | return -EFAULT; |
| 1263 | |
Hans de Goede | 57fb4a4 | 2012-04-08 12:59:48 -0300 | [diff] [blame] | 1264 | if (__clear_user(up->reserved, sizeof(up->reserved))) |
| 1265 | return -EFAULT; |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1266 | |
| 1267 | if (kp->menu_count == 0) |
| 1268 | return 0; |
| 1269 | |
| 1270 | if (get_user(p, &up->menu_info)) |
| 1271 | return -EFAULT; |
| 1272 | umenus = compat_ptr(p); |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1273 | |
| 1274 | if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus))) |
| 1275 | return -EFAULT; |
| 1276 | |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | struct uvc_xu_control_query32 { |
| 1281 | __u8 unit; |
| 1282 | __u8 selector; |
| 1283 | __u8 query; |
| 1284 | __u16 size; |
| 1285 | compat_caddr_t data; |
| 1286 | }; |
| 1287 | |
| 1288 | static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp, |
| 1289 | const struct uvc_xu_control_query32 __user *up) |
| 1290 | { |
| 1291 | u8 __user *udata; |
| 1292 | u8 __user *kdata; |
| 1293 | compat_caddr_t p; |
| 1294 | |
| 1295 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 1296 | __copy_from_user(kp, up, offsetof(typeof(*up), data))) |
| 1297 | return -EFAULT; |
| 1298 | |
| 1299 | if (kp->size == 0) { |
| 1300 | kp->data = NULL; |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | if (__get_user(p, &up->data)) |
| 1305 | return -EFAULT; |
| 1306 | udata = compat_ptr(p); |
| 1307 | if (!access_ok(VERIFY_READ, udata, kp->size)) |
| 1308 | return -EFAULT; |
| 1309 | |
| 1310 | kdata = compat_alloc_user_space(kp->size); |
| 1311 | if (kdata == NULL) |
| 1312 | return -EFAULT; |
| 1313 | kp->data = kdata; |
| 1314 | |
| 1315 | if (copy_in_user(kdata, udata, kp->size)) |
| 1316 | return -EFAULT; |
| 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
| 1321 | static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp, |
| 1322 | struct uvc_xu_control_query32 __user *up) |
| 1323 | { |
| 1324 | u8 __user *udata; |
| 1325 | u8 __user *kdata = kp->data; |
| 1326 | compat_caddr_t p; |
| 1327 | |
| 1328 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
| 1329 | __copy_to_user(up, kp, offsetof(typeof(*up), data))) |
| 1330 | return -EFAULT; |
| 1331 | |
| 1332 | if (kp->size == 0) |
| 1333 | return 0; |
| 1334 | |
| 1335 | if (get_user(p, &up->data)) |
| 1336 | return -EFAULT; |
| 1337 | udata = compat_ptr(p); |
| 1338 | if (!access_ok(VERIFY_READ, udata, kp->size)) |
| 1339 | return -EFAULT; |
| 1340 | |
| 1341 | if (copy_in_user(udata, kdata, kp->size)) |
| 1342 | return -EFAULT; |
| 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | #define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32) |
| 1348 | #define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32) |
| 1349 | |
| 1350 | static long uvc_v4l2_compat_ioctl32(struct file *file, |
| 1351 | unsigned int cmd, unsigned long arg) |
| 1352 | { |
| 1353 | union { |
| 1354 | struct uvc_xu_control_mapping xmap; |
| 1355 | struct uvc_xu_control_query xqry; |
| 1356 | } karg; |
| 1357 | void __user *up = compat_ptr(arg); |
| 1358 | mm_segment_t old_fs; |
| 1359 | long ret; |
| 1360 | |
| 1361 | switch (cmd) { |
| 1362 | case UVCIOC_CTRL_MAP32: |
| 1363 | cmd = UVCIOC_CTRL_MAP; |
| 1364 | ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up); |
| 1365 | break; |
| 1366 | |
| 1367 | case UVCIOC_CTRL_QUERY32: |
| 1368 | cmd = UVCIOC_CTRL_QUERY; |
| 1369 | ret = uvc_v4l2_get_xu_query(&karg.xqry, up); |
| 1370 | break; |
| 1371 | |
| 1372 | default: |
| 1373 | return -ENOIOCTLCMD; |
| 1374 | } |
| 1375 | |
| 1376 | old_fs = get_fs(); |
| 1377 | set_fs(KERNEL_DS); |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1378 | ret = video_ioctl2(file, cmd, (unsigned long)&karg); |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1379 | set_fs(old_fs); |
| 1380 | |
| 1381 | if (ret < 0) |
| 1382 | return ret; |
| 1383 | |
| 1384 | switch (cmd) { |
| 1385 | case UVCIOC_CTRL_MAP: |
| 1386 | ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up); |
| 1387 | break; |
| 1388 | |
| 1389 | case UVCIOC_CTRL_QUERY: |
| 1390 | ret = uvc_v4l2_put_xu_query(&karg.xqry, up); |
| 1391 | break; |
| 1392 | } |
| 1393 | |
| 1394 | return ret; |
| 1395 | } |
| 1396 | #endif |
| 1397 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1398 | static ssize_t uvc_v4l2_read(struct file *file, char __user *data, |
| 1399 | size_t count, loff_t *ppos) |
| 1400 | { |
| 1401 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n"); |
Laurent Pinchart | 350d640 | 2009-11-04 11:53:49 -0300 | [diff] [blame] | 1402 | return -EINVAL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1403 | } |
| 1404 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1405 | static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) |
| 1406 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1407 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1408 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1409 | |
| 1410 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n"); |
| 1411 | |
Laurent Pinchart | 4aa2759 | 2010-11-21 15:18:08 -0300 | [diff] [blame] | 1412 | return uvc_queue_mmap(&stream->queue, vma); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) |
| 1416 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1417 | struct uvc_fh *handle = file->private_data; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1418 | struct uvc_streaming *stream = handle->stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1419 | |
| 1420 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n"); |
| 1421 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 1422 | return uvc_queue_poll(&stream->queue, file, wait); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1423 | } |
| 1424 | |
Bob Liu | 7296944 | 2011-04-29 07:11:35 -0300 | [diff] [blame] | 1425 | #ifndef CONFIG_MMU |
| 1426 | static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, |
| 1427 | unsigned long addr, unsigned long len, unsigned long pgoff, |
| 1428 | unsigned long flags) |
| 1429 | { |
| 1430 | struct uvc_fh *handle = file->private_data; |
| 1431 | struct uvc_streaming *stream = handle->stream; |
| 1432 | |
| 1433 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n"); |
| 1434 | |
| 1435 | return uvc_queue_get_unmapped_area(&stream->queue, pgoff); |
| 1436 | } |
| 1437 | #endif |
| 1438 | |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1439 | const struct v4l2_ioctl_ops uvc_ioctl_ops = { |
| 1440 | .vidioc_querycap = uvc_ioctl_querycap, |
| 1441 | .vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt_vid_cap, |
| 1442 | .vidioc_enum_fmt_vid_out = uvc_ioctl_enum_fmt_vid_out, |
| 1443 | .vidioc_g_fmt_vid_cap = uvc_ioctl_g_fmt_vid_cap, |
| 1444 | .vidioc_g_fmt_vid_out = uvc_ioctl_g_fmt_vid_out, |
| 1445 | .vidioc_s_fmt_vid_cap = uvc_ioctl_s_fmt_vid_cap, |
| 1446 | .vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt_vid_out, |
| 1447 | .vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt_vid_cap, |
| 1448 | .vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt_vid_out, |
| 1449 | .vidioc_reqbufs = uvc_ioctl_reqbufs, |
| 1450 | .vidioc_querybuf = uvc_ioctl_querybuf, |
| 1451 | .vidioc_qbuf = uvc_ioctl_qbuf, |
| 1452 | .vidioc_dqbuf = uvc_ioctl_dqbuf, |
| 1453 | .vidioc_create_bufs = uvc_ioctl_create_bufs, |
| 1454 | .vidioc_streamon = uvc_ioctl_streamon, |
| 1455 | .vidioc_streamoff = uvc_ioctl_streamoff, |
| 1456 | .vidioc_enum_input = uvc_ioctl_enum_input, |
| 1457 | .vidioc_g_input = uvc_ioctl_g_input, |
| 1458 | .vidioc_s_input = uvc_ioctl_s_input, |
| 1459 | .vidioc_queryctrl = uvc_ioctl_queryctrl, |
| 1460 | .vidioc_g_ctrl = uvc_ioctl_g_ctrl, |
| 1461 | .vidioc_s_ctrl = uvc_ioctl_s_ctrl, |
| 1462 | .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls, |
| 1463 | .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls, |
| 1464 | .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, |
| 1465 | .vidioc_querymenu = uvc_ioctl_querymenu, |
Hans Verkuil | 1461fe7 | 2015-04-03 06:53:42 -0300 | [diff] [blame^] | 1466 | .vidioc_g_selection = uvc_ioctl_g_selection, |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1467 | .vidioc_g_parm = uvc_ioctl_g_parm, |
| 1468 | .vidioc_s_parm = uvc_ioctl_s_parm, |
| 1469 | .vidioc_enum_framesizes = uvc_ioctl_enum_framesizes, |
| 1470 | .vidioc_enum_frameintervals = uvc_ioctl_enum_frameintervals, |
| 1471 | .vidioc_subscribe_event = uvc_ioctl_subscribe_event, |
| 1472 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
| 1473 | .vidioc_default = uvc_ioctl_default, |
| 1474 | }; |
| 1475 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1476 | const struct v4l2_file_operations uvc_fops = { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1477 | .owner = THIS_MODULE, |
| 1478 | .open = uvc_v4l2_open, |
| 1479 | .release = uvc_v4l2_release, |
Laurent Pinchart | d5e90b7 | 2010-09-30 10:17:54 -0300 | [diff] [blame] | 1480 | .unlocked_ioctl = video_ioctl2, |
Laurent Pinchart | 1a5e4c8 | 2011-12-18 20:45:39 -0300 | [diff] [blame] | 1481 | #ifdef CONFIG_COMPAT |
| 1482 | .compat_ioctl32 = uvc_v4l2_compat_ioctl32, |
| 1483 | #endif |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1484 | .read = uvc_v4l2_read, |
| 1485 | .mmap = uvc_v4l2_mmap, |
| 1486 | .poll = uvc_v4l2_poll, |
Bob Liu | 7296944 | 2011-04-29 07:11:35 -0300 | [diff] [blame] | 1487 | #ifndef CONFIG_MMU |
| 1488 | .get_unmapped_area = uvc_v4l2_get_unmapped_area, |
| 1489 | #endif |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1490 | }; |
Hans Verkuil | f87086e | 2008-07-18 00:50:58 -0300 | [diff] [blame] | 1491 | |