uvc_v4l2.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. /*
  2. * uvc_v4l2.c -- USB Video Class driver - V4L2 API
  3. *
  4. * Copyright (C) 2005-2010
  5. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  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. #include <linux/compat.h>
  14. #include <linux/kernel.h>
  15. #include <linux/version.h>
  16. #include <linux/list.h>
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  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>
  24. #include <linux/atomic.h>
  25. #include <media/v4l2-common.h>
  26. #include <media/v4l2-ctrls.h>
  27. #include <media/v4l2-event.h>
  28. #include <media/v4l2-ioctl.h>
  29. #include "uvcvideo.h"
  30. /* ------------------------------------------------------------------------
  31. * UVC ioctls
  32. */
  33. static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
  34. struct uvc_xu_control_mapping *xmap)
  35. {
  36. struct uvc_control_mapping *map;
  37. unsigned int size;
  38. int ret;
  39. map = kzalloc(sizeof *map, GFP_KERNEL);
  40. if (map == NULL)
  41. return -ENOMEM;
  42. map->id = xmap->id;
  43. memcpy(map->name, xmap->name, sizeof map->name);
  44. memcpy(map->entity, xmap->entity, sizeof map->entity);
  45. map->selector = xmap->selector;
  46. map->size = xmap->size;
  47. map->offset = xmap->offset;
  48. map->v4l2_type = xmap->v4l2_type;
  49. map->data_type = xmap->data_type;
  50. switch (xmap->v4l2_type) {
  51. case V4L2_CTRL_TYPE_INTEGER:
  52. case V4L2_CTRL_TYPE_BOOLEAN:
  53. case V4L2_CTRL_TYPE_BUTTON:
  54. break;
  55. case V4L2_CTRL_TYPE_MENU:
  56. /* Prevent excessive memory consumption, as well as integer
  57. * overflows.
  58. */
  59. if (xmap->menu_count == 0 ||
  60. xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) {
  61. ret = -EINVAL;
  62. goto done;
  63. }
  64. size = xmap->menu_count * sizeof(*map->menu_info);
  65. map->menu_info = kmalloc(size, GFP_KERNEL);
  66. if (map->menu_info == NULL) {
  67. ret = -ENOMEM;
  68. goto done;
  69. }
  70. if (copy_from_user(map->menu_info, xmap->menu_info, size)) {
  71. ret = -EFAULT;
  72. goto done;
  73. }
  74. map->menu_count = xmap->menu_count;
  75. break;
  76. default:
  77. uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type "
  78. "%u.\n", xmap->v4l2_type);
  79. ret = -ENOTTY;
  80. goto done;
  81. }
  82. ret = uvc_ctrl_add_mapping(chain, map);
  83. done:
  84. kfree(map->menu_info);
  85. kfree(map);
  86. return ret;
  87. }
  88. /* ------------------------------------------------------------------------
  89. * V4L2 interface
  90. */
  91. /*
  92. * Find the frame interval closest to the requested frame interval for the
  93. * given frame format and size. This should be done by the device as part of
  94. * the Video Probe and Commit negotiation, but some hardware don't implement
  95. * that feature.
  96. */
  97. static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval)
  98. {
  99. unsigned int i;
  100. if (frame->bFrameIntervalType) {
  101. __u32 best = -1, dist;
  102. for (i = 0; i < frame->bFrameIntervalType; ++i) {
  103. dist = interval > frame->dwFrameInterval[i]
  104. ? interval - frame->dwFrameInterval[i]
  105. : frame->dwFrameInterval[i] - interval;
  106. if (dist > best)
  107. break;
  108. best = dist;
  109. }
  110. interval = frame->dwFrameInterval[i-1];
  111. } else {
  112. const __u32 min = frame->dwFrameInterval[0];
  113. const __u32 max = frame->dwFrameInterval[1];
  114. const __u32 step = frame->dwFrameInterval[2];
  115. interval = min + (interval - min + step/2) / step * step;
  116. if (interval > max)
  117. interval = max;
  118. }
  119. return interval;
  120. }
  121. static int uvc_v4l2_try_format(struct uvc_streaming *stream,
  122. struct v4l2_format *fmt, struct uvc_streaming_control *probe,
  123. struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
  124. {
  125. struct uvc_format *format = NULL;
  126. struct uvc_frame *frame = NULL;
  127. __u16 rw, rh;
  128. unsigned int d, maxd;
  129. unsigned int i;
  130. __u32 interval;
  131. int ret = 0;
  132. __u8 *fcc;
  133. if (fmt->type != stream->type)
  134. return -EINVAL;
  135. fcc = (__u8 *)&fmt->fmt.pix.pixelformat;
  136. uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n",
  137. fmt->fmt.pix.pixelformat,
  138. fcc[0], fcc[1], fcc[2], fcc[3],
  139. fmt->fmt.pix.width, fmt->fmt.pix.height);
  140. /* Check if the hardware supports the requested format. */
  141. for (i = 0; i < stream->nformats; ++i) {
  142. format = &stream->format[i];
  143. if (format->fcc == fmt->fmt.pix.pixelformat)
  144. break;
  145. }
  146. if (format == NULL || format->fcc != fmt->fmt.pix.pixelformat) {
  147. uvc_trace(UVC_TRACE_FORMAT, "Unsupported format 0x%08x.\n",
  148. fmt->fmt.pix.pixelformat);
  149. return -EINVAL;
  150. }
  151. /* Find the closest image size. The distance between image sizes is
  152. * the size in pixels of the non-overlapping regions between the
  153. * requested size and the frame-specified size.
  154. */
  155. rw = fmt->fmt.pix.width;
  156. rh = fmt->fmt.pix.height;
  157. maxd = (unsigned int)-1;
  158. for (i = 0; i < format->nframes; ++i) {
  159. __u16 w = format->frame[i].wWidth;
  160. __u16 h = format->frame[i].wHeight;
  161. d = min(w, rw) * min(h, rh);
  162. d = w*h + rw*rh - 2*d;
  163. if (d < maxd) {
  164. maxd = d;
  165. frame = &format->frame[i];
  166. }
  167. if (maxd == 0)
  168. break;
  169. }
  170. if (frame == NULL) {
  171. uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n",
  172. fmt->fmt.pix.width, fmt->fmt.pix.height);
  173. return -EINVAL;
  174. }
  175. /* Use the default frame interval. */
  176. interval = frame->dwDefaultFrameInterval;
  177. uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us "
  178. "(%u.%u fps).\n", interval/10, interval%10, 10000000/interval,
  179. (100000000/interval)%10);
  180. /* Set the format index, frame index and frame interval. */
  181. memset(probe, 0, sizeof *probe);
  182. probe->bmHint = 1; /* dwFrameInterval */
  183. probe->bFormatIndex = format->index;
  184. probe->bFrameIndex = frame->bFrameIndex;
  185. probe->dwFrameInterval = uvc_try_frame_interval(frame, interval);
  186. /* Some webcams stall the probe control set request when the
  187. * dwMaxVideoFrameSize field is set to zero. The UVC specification
  188. * clearly states that the field is read-only from the host, so this
  189. * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by
  190. * the webcam to work around the problem.
  191. *
  192. * The workaround could probably be enabled for all webcams, so the
  193. * quirk can be removed if needed. It's currently useful to detect
  194. * webcam bugs and fix them before they hit the market (providing
  195. * developers test their webcams with the Linux driver as well as with
  196. * the Windows driver).
  197. */
  198. mutex_lock(&stream->mutex);
  199. if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
  200. probe->dwMaxVideoFrameSize =
  201. stream->ctrl.dwMaxVideoFrameSize;
  202. /* Probe the device. */
  203. ret = uvc_probe_video(stream, probe);
  204. mutex_unlock(&stream->mutex);
  205. if (ret < 0)
  206. goto done;
  207. fmt->fmt.pix.width = frame->wWidth;
  208. fmt->fmt.pix.height = frame->wHeight;
  209. fmt->fmt.pix.field = V4L2_FIELD_NONE;
  210. fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
  211. fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
  212. fmt->fmt.pix.colorspace = format->colorspace;
  213. fmt->fmt.pix.priv = 0;
  214. if (uvc_format != NULL)
  215. *uvc_format = format;
  216. if (uvc_frame != NULL)
  217. *uvc_frame = frame;
  218. done:
  219. return ret;
  220. }
  221. static int uvc_v4l2_get_format(struct uvc_streaming *stream,
  222. struct v4l2_format *fmt)
  223. {
  224. struct uvc_format *format;
  225. struct uvc_frame *frame;
  226. int ret = 0;
  227. if (fmt->type != stream->type)
  228. return -EINVAL;
  229. mutex_lock(&stream->mutex);
  230. format = stream->cur_format;
  231. frame = stream->cur_frame;
  232. if (format == NULL || frame == NULL) {
  233. ret = -EINVAL;
  234. goto done;
  235. }
  236. fmt->fmt.pix.pixelformat = format->fcc;
  237. fmt->fmt.pix.width = frame->wWidth;
  238. fmt->fmt.pix.height = frame->wHeight;
  239. fmt->fmt.pix.field = V4L2_FIELD_NONE;
  240. fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
  241. fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize;
  242. fmt->fmt.pix.colorspace = format->colorspace;
  243. fmt->fmt.pix.priv = 0;
  244. done:
  245. mutex_unlock(&stream->mutex);
  246. return ret;
  247. }
  248. static int uvc_v4l2_set_format(struct uvc_streaming *stream,
  249. struct v4l2_format *fmt)
  250. {
  251. struct uvc_streaming_control probe;
  252. struct uvc_format *format;
  253. struct uvc_frame *frame;
  254. int ret;
  255. if (fmt->type != stream->type)
  256. return -EINVAL;
  257. ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);
  258. if (ret < 0)
  259. return ret;
  260. mutex_lock(&stream->mutex);
  261. if (uvc_queue_allocated(&stream->queue)) {
  262. ret = -EBUSY;
  263. goto done;
  264. }
  265. memcpy(&stream->ctrl, &probe, sizeof probe);
  266. stream->cur_format = format;
  267. stream->cur_frame = frame;
  268. done:
  269. mutex_unlock(&stream->mutex);
  270. return ret;
  271. }
  272. static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
  273. struct v4l2_streamparm *parm)
  274. {
  275. uint32_t numerator, denominator;
  276. if (parm->type != stream->type)
  277. return -EINVAL;
  278. mutex_lock(&stream->mutex);
  279. numerator = stream->ctrl.dwFrameInterval;
  280. mutex_unlock(&stream->mutex);
  281. denominator = 10000000;
  282. uvc_simplify_fraction(&numerator, &denominator, 8, 333);
  283. memset(parm, 0, sizeof *parm);
  284. parm->type = stream->type;
  285. if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  286. parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  287. parm->parm.capture.capturemode = 0;
  288. parm->parm.capture.timeperframe.numerator = numerator;
  289. parm->parm.capture.timeperframe.denominator = denominator;
  290. parm->parm.capture.extendedmode = 0;
  291. parm->parm.capture.readbuffers = 0;
  292. } else {
  293. parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
  294. parm->parm.output.outputmode = 0;
  295. parm->parm.output.timeperframe.numerator = numerator;
  296. parm->parm.output.timeperframe.denominator = denominator;
  297. }
  298. return 0;
  299. }
  300. static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
  301. struct v4l2_streamparm *parm)
  302. {
  303. struct uvc_streaming_control probe;
  304. struct v4l2_fract timeperframe;
  305. uint32_t interval;
  306. int ret;
  307. if (parm->type != stream->type)
  308. return -EINVAL;
  309. if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  310. timeperframe = parm->parm.capture.timeperframe;
  311. else
  312. timeperframe = parm->parm.output.timeperframe;
  313. interval = uvc_fraction_to_interval(timeperframe.numerator,
  314. timeperframe.denominator);
  315. uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n",
  316. timeperframe.numerator, timeperframe.denominator, interval);
  317. mutex_lock(&stream->mutex);
  318. if (uvc_queue_streaming(&stream->queue)) {
  319. mutex_unlock(&stream->mutex);
  320. return -EBUSY;
  321. }
  322. memcpy(&probe, &stream->ctrl, sizeof probe);
  323. probe.dwFrameInterval =
  324. uvc_try_frame_interval(stream->cur_frame, interval);
  325. /* Probe the device with the new settings. */
  326. ret = uvc_probe_video(stream, &probe);
  327. if (ret < 0) {
  328. mutex_unlock(&stream->mutex);
  329. return ret;
  330. }
  331. memcpy(&stream->ctrl, &probe, sizeof probe);
  332. mutex_unlock(&stream->mutex);
  333. /* Return the actual frame period. */
  334. timeperframe.numerator = probe.dwFrameInterval;
  335. timeperframe.denominator = 10000000;
  336. uvc_simplify_fraction(&timeperframe.numerator,
  337. &timeperframe.denominator, 8, 333);
  338. if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  339. parm->parm.capture.timeperframe = timeperframe;
  340. else
  341. parm->parm.output.timeperframe = timeperframe;
  342. return 0;
  343. }
  344. /* ------------------------------------------------------------------------
  345. * Privilege management
  346. */
  347. /*
  348. * Privilege management is the multiple-open implementation basis. The current
  349. * implementation is completely transparent for the end-user and doesn't
  350. * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls.
  351. * Those ioctls enable finer control on the device (by making possible for a
  352. * user to request exclusive access to a device), but are not mature yet.
  353. * Switching to the V4L2 priority mechanism might be considered in the future
  354. * if this situation changes.
  355. *
  356. * Each open instance of a UVC device can either be in a privileged or
  357. * unprivileged state. Only a single instance can be in a privileged state at
  358. * a given time. Trying to perform an operation that requires privileges will
  359. * automatically acquire the required privileges if possible, or return -EBUSY
  360. * otherwise. Privileges are dismissed when closing the instance or when
  361. * freeing the video buffers using VIDIOC_REQBUFS.
  362. *
  363. * Operations that require privileges are:
  364. *
  365. * - VIDIOC_S_INPUT
  366. * - VIDIOC_S_PARM
  367. * - VIDIOC_S_FMT
  368. * - VIDIOC_REQBUFS
  369. */
  370. static int uvc_acquire_privileges(struct uvc_fh *handle)
  371. {
  372. /* Always succeed if the handle is already privileged. */
  373. if (handle->state == UVC_HANDLE_ACTIVE)
  374. return 0;
  375. /* Check if the device already has a privileged handle. */
  376. if (atomic_inc_return(&handle->stream->active) != 1) {
  377. atomic_dec(&handle->stream->active);
  378. return -EBUSY;
  379. }
  380. handle->state = UVC_HANDLE_ACTIVE;
  381. return 0;
  382. }
  383. static void uvc_dismiss_privileges(struct uvc_fh *handle)
  384. {
  385. if (handle->state == UVC_HANDLE_ACTIVE)
  386. atomic_dec(&handle->stream->active);
  387. handle->state = UVC_HANDLE_PASSIVE;
  388. }
  389. static int uvc_has_privileges(struct uvc_fh *handle)
  390. {
  391. return handle->state == UVC_HANDLE_ACTIVE;
  392. }
  393. /* ------------------------------------------------------------------------
  394. * V4L2 file operations
  395. */
  396. static int uvc_v4l2_open(struct file *file)
  397. {
  398. struct uvc_streaming *stream;
  399. struct uvc_fh *handle;
  400. int ret = 0;
  401. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
  402. stream = video_drvdata(file);
  403. if (stream->dev->state & UVC_DEV_DISCONNECTED)
  404. return -ENODEV;
  405. ret = usb_autopm_get_interface(stream->dev->intf);
  406. if (ret < 0)
  407. return ret;
  408. /* Create the device handle. */
  409. handle = kzalloc(sizeof *handle, GFP_KERNEL);
  410. if (handle == NULL) {
  411. usb_autopm_put_interface(stream->dev->intf);
  412. return -ENOMEM;
  413. }
  414. if (atomic_inc_return(&stream->dev->users) == 1) {
  415. ret = uvc_status_start(stream->dev);
  416. if (ret < 0) {
  417. usb_autopm_put_interface(stream->dev->intf);
  418. atomic_dec(&stream->dev->users);
  419. kfree(handle);
  420. return ret;
  421. }
  422. }
  423. v4l2_fh_init(&handle->vfh, stream->vdev);
  424. v4l2_fh_add(&handle->vfh);
  425. handle->chain = stream->chain;
  426. handle->stream = stream;
  427. handle->state = UVC_HANDLE_PASSIVE;
  428. file->private_data = handle;
  429. return 0;
  430. }
  431. static int uvc_v4l2_release(struct file *file)
  432. {
  433. struct uvc_fh *handle = file->private_data;
  434. struct uvc_streaming *stream = handle->stream;
  435. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
  436. /* Only free resources if this is a privileged handle. */
  437. if (uvc_has_privileges(handle)) {
  438. uvc_video_enable(stream, 0);
  439. uvc_free_buffers(&stream->queue);
  440. }
  441. /* Release the file handle. */
  442. uvc_dismiss_privileges(handle);
  443. v4l2_fh_del(&handle->vfh);
  444. v4l2_fh_exit(&handle->vfh);
  445. kfree(handle);
  446. file->private_data = NULL;
  447. if (atomic_dec_return(&stream->dev->users) == 0)
  448. uvc_status_stop(stream->dev);
  449. usb_autopm_put_interface(stream->dev->intf);
  450. return 0;
  451. }
  452. static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
  453. {
  454. struct video_device *vdev = video_devdata(file);
  455. struct uvc_fh *handle = file->private_data;
  456. struct uvc_video_chain *chain = handle->chain;
  457. struct uvc_streaming *stream = handle->stream;
  458. long ret = 0;
  459. switch (cmd) {
  460. /* Query capabilities */
  461. case VIDIOC_QUERYCAP:
  462. {
  463. struct v4l2_capability *cap = arg;
  464. memset(cap, 0, sizeof *cap);
  465. strlcpy(cap->driver, "uvcvideo", sizeof cap->driver);
  466. strlcpy(cap->card, vdev->name, sizeof cap->card);
  467. usb_make_path(stream->dev->udev,
  468. cap->bus_info, sizeof(cap->bus_info));
  469. cap->version = LINUX_VERSION_CODE;
  470. if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  471. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
  472. | V4L2_CAP_STREAMING;
  473. else
  474. cap->capabilities = V4L2_CAP_VIDEO_OUTPUT
  475. | V4L2_CAP_STREAMING;
  476. break;
  477. }
  478. /* Get, Set & Query control */
  479. case VIDIOC_QUERYCTRL:
  480. return uvc_query_v4l2_ctrl(chain, arg);
  481. case VIDIOC_G_CTRL:
  482. {
  483. struct v4l2_control *ctrl = arg;
  484. struct v4l2_ext_control xctrl;
  485. memset(&xctrl, 0, sizeof xctrl);
  486. xctrl.id = ctrl->id;
  487. ret = uvc_ctrl_begin(chain);
  488. if (ret < 0)
  489. return ret;
  490. ret = uvc_ctrl_get(chain, &xctrl);
  491. uvc_ctrl_rollback(handle);
  492. if (ret >= 0)
  493. ctrl->value = xctrl.value;
  494. break;
  495. }
  496. case VIDIOC_S_CTRL:
  497. {
  498. struct v4l2_control *ctrl = arg;
  499. struct v4l2_ext_control xctrl;
  500. memset(&xctrl, 0, sizeof xctrl);
  501. xctrl.id = ctrl->id;
  502. xctrl.value = ctrl->value;
  503. ret = uvc_ctrl_begin(chain);
  504. if (ret < 0)
  505. return ret;
  506. ret = uvc_ctrl_set(chain, &xctrl);
  507. if (ret < 0) {
  508. uvc_ctrl_rollback(handle);
  509. return ret;
  510. }
  511. ret = uvc_ctrl_commit(handle, &xctrl, 1);
  512. if (ret == 0)
  513. ctrl->value = xctrl.value;
  514. break;
  515. }
  516. case VIDIOC_QUERYMENU:
  517. return uvc_query_v4l2_menu(chain, arg);
  518. case VIDIOC_G_EXT_CTRLS:
  519. {
  520. struct v4l2_ext_controls *ctrls = arg;
  521. struct v4l2_ext_control *ctrl = ctrls->controls;
  522. unsigned int i;
  523. ret = uvc_ctrl_begin(chain);
  524. if (ret < 0)
  525. return ret;
  526. for (i = 0; i < ctrls->count; ++ctrl, ++i) {
  527. ret = uvc_ctrl_get(chain, ctrl);
  528. if (ret < 0) {
  529. uvc_ctrl_rollback(handle);
  530. ctrls->error_idx = i;
  531. return ret;
  532. }
  533. }
  534. ctrls->error_idx = 0;
  535. ret = uvc_ctrl_rollback(handle);
  536. break;
  537. }
  538. case VIDIOC_S_EXT_CTRLS:
  539. case VIDIOC_TRY_EXT_CTRLS:
  540. {
  541. struct v4l2_ext_controls *ctrls = arg;
  542. struct v4l2_ext_control *ctrl = ctrls->controls;
  543. unsigned int i;
  544. ret = uvc_ctrl_begin(chain);
  545. if (ret < 0)
  546. return ret;
  547. for (i = 0; i < ctrls->count; ++ctrl, ++i) {
  548. ret = uvc_ctrl_set(chain, ctrl);
  549. if (ret < 0) {
  550. uvc_ctrl_rollback(handle);
  551. ctrls->error_idx = i;
  552. return ret;
  553. }
  554. }
  555. ctrls->error_idx = 0;
  556. if (cmd == VIDIOC_S_EXT_CTRLS)
  557. ret = uvc_ctrl_commit(handle,
  558. ctrls->controls, ctrls->count);
  559. else
  560. ret = uvc_ctrl_rollback(handle);
  561. break;
  562. }
  563. /* Get, Set & Enum input */
  564. case VIDIOC_ENUMINPUT:
  565. {
  566. const struct uvc_entity *selector = chain->selector;
  567. struct v4l2_input *input = arg;
  568. struct uvc_entity *iterm = NULL;
  569. u32 index = input->index;
  570. int pin = 0;
  571. if (selector == NULL ||
  572. (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
  573. if (index != 0)
  574. return -EINVAL;
  575. list_for_each_entry(iterm, &chain->entities, chain) {
  576. if (UVC_ENTITY_IS_ITERM(iterm))
  577. break;
  578. }
  579. pin = iterm->id;
  580. } else if (index < selector->bNrInPins) {
  581. pin = selector->baSourceID[index];
  582. list_for_each_entry(iterm, &chain->entities, chain) {
  583. if (!UVC_ENTITY_IS_ITERM(iterm))
  584. continue;
  585. if (iterm->id == pin)
  586. break;
  587. }
  588. }
  589. if (iterm == NULL || iterm->id != pin)
  590. return -EINVAL;
  591. memset(input, 0, sizeof *input);
  592. input->index = index;
  593. strlcpy(input->name, iterm->name, sizeof input->name);
  594. if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA)
  595. input->type = V4L2_INPUT_TYPE_CAMERA;
  596. break;
  597. }
  598. case VIDIOC_G_INPUT:
  599. {
  600. u8 input;
  601. if (chain->selector == NULL ||
  602. (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
  603. *(int *)arg = 0;
  604. break;
  605. }
  606. ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
  607. chain->selector->id, chain->dev->intfnum,
  608. UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
  609. if (ret < 0)
  610. return ret;
  611. *(int *)arg = input - 1;
  612. break;
  613. }
  614. case VIDIOC_S_INPUT:
  615. {
  616. u32 input = *(u32 *)arg + 1;
  617. if ((ret = uvc_acquire_privileges(handle)) < 0)
  618. return ret;
  619. if (chain->selector == NULL ||
  620. (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
  621. if (input != 1)
  622. return -EINVAL;
  623. break;
  624. }
  625. if (input == 0 || input > chain->selector->bNrInPins)
  626. return -EINVAL;
  627. return uvc_query_ctrl(chain->dev, UVC_SET_CUR,
  628. chain->selector->id, chain->dev->intfnum,
  629. UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
  630. }
  631. /* Try, Get, Set & Enum format */
  632. case VIDIOC_ENUM_FMT:
  633. {
  634. struct v4l2_fmtdesc *fmt = arg;
  635. struct uvc_format *format;
  636. enum v4l2_buf_type type = fmt->type;
  637. __u32 index = fmt->index;
  638. if (fmt->type != stream->type ||
  639. fmt->index >= stream->nformats)
  640. return -EINVAL;
  641. memset(fmt, 0, sizeof(*fmt));
  642. fmt->index = index;
  643. fmt->type = type;
  644. format = &stream->format[fmt->index];
  645. fmt->flags = 0;
  646. if (format->flags & UVC_FMT_FLAG_COMPRESSED)
  647. fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
  648. strlcpy(fmt->description, format->name,
  649. sizeof fmt->description);
  650. fmt->description[sizeof fmt->description - 1] = 0;
  651. fmt->pixelformat = format->fcc;
  652. break;
  653. }
  654. case VIDIOC_TRY_FMT:
  655. {
  656. struct uvc_streaming_control probe;
  657. return uvc_v4l2_try_format(stream, arg, &probe, NULL, NULL);
  658. }
  659. case VIDIOC_S_FMT:
  660. if ((ret = uvc_acquire_privileges(handle)) < 0)
  661. return ret;
  662. return uvc_v4l2_set_format(stream, arg);
  663. case VIDIOC_G_FMT:
  664. return uvc_v4l2_get_format(stream, arg);
  665. /* Frame size enumeration */
  666. case VIDIOC_ENUM_FRAMESIZES:
  667. {
  668. struct v4l2_frmsizeenum *fsize = arg;
  669. struct uvc_format *format = NULL;
  670. struct uvc_frame *frame;
  671. int i;
  672. /* Look for the given pixel format */
  673. for (i = 0; i < stream->nformats; i++) {
  674. if (stream->format[i].fcc ==
  675. fsize->pixel_format) {
  676. format = &stream->format[i];
  677. break;
  678. }
  679. }
  680. if (format == NULL)
  681. return -EINVAL;
  682. if (fsize->index >= format->nframes)
  683. return -EINVAL;
  684. frame = &format->frame[fsize->index];
  685. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  686. fsize->discrete.width = frame->wWidth;
  687. fsize->discrete.height = frame->wHeight;
  688. break;
  689. }
  690. /* Frame interval enumeration */
  691. case VIDIOC_ENUM_FRAMEINTERVALS:
  692. {
  693. struct v4l2_frmivalenum *fival = arg;
  694. struct uvc_format *format = NULL;
  695. struct uvc_frame *frame = NULL;
  696. int i;
  697. /* Look for the given pixel format and frame size */
  698. for (i = 0; i < stream->nformats; i++) {
  699. if (stream->format[i].fcc ==
  700. fival->pixel_format) {
  701. format = &stream->format[i];
  702. break;
  703. }
  704. }
  705. if (format == NULL)
  706. return -EINVAL;
  707. for (i = 0; i < format->nframes; i++) {
  708. if (format->frame[i].wWidth == fival->width &&
  709. format->frame[i].wHeight == fival->height) {
  710. frame = &format->frame[i];
  711. break;
  712. }
  713. }
  714. if (frame == NULL)
  715. return -EINVAL;
  716. if (frame->bFrameIntervalType) {
  717. if (fival->index >= frame->bFrameIntervalType)
  718. return -EINVAL;
  719. fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  720. fival->discrete.numerator =
  721. frame->dwFrameInterval[fival->index];
  722. fival->discrete.denominator = 10000000;
  723. uvc_simplify_fraction(&fival->discrete.numerator,
  724. &fival->discrete.denominator, 8, 333);
  725. } else {
  726. fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
  727. fival->stepwise.min.numerator =
  728. frame->dwFrameInterval[0];
  729. fival->stepwise.min.denominator = 10000000;
  730. fival->stepwise.max.numerator =
  731. frame->dwFrameInterval[1];
  732. fival->stepwise.max.denominator = 10000000;
  733. fival->stepwise.step.numerator =
  734. frame->dwFrameInterval[2];
  735. fival->stepwise.step.denominator = 10000000;
  736. uvc_simplify_fraction(&fival->stepwise.min.numerator,
  737. &fival->stepwise.min.denominator, 8, 333);
  738. uvc_simplify_fraction(&fival->stepwise.max.numerator,
  739. &fival->stepwise.max.denominator, 8, 333);
  740. uvc_simplify_fraction(&fival->stepwise.step.numerator,
  741. &fival->stepwise.step.denominator, 8, 333);
  742. }
  743. break;
  744. }
  745. /* Get & Set streaming parameters */
  746. case VIDIOC_G_PARM:
  747. return uvc_v4l2_get_streamparm(stream, arg);
  748. case VIDIOC_S_PARM:
  749. if ((ret = uvc_acquire_privileges(handle)) < 0)
  750. return ret;
  751. return uvc_v4l2_set_streamparm(stream, arg);
  752. /* Cropping and scaling */
  753. case VIDIOC_CROPCAP:
  754. {
  755. struct v4l2_cropcap *ccap = arg;
  756. if (ccap->type != stream->type)
  757. return -EINVAL;
  758. ccap->bounds.left = 0;
  759. ccap->bounds.top = 0;
  760. mutex_lock(&stream->mutex);
  761. ccap->bounds.width = stream->cur_frame->wWidth;
  762. ccap->bounds.height = stream->cur_frame->wHeight;
  763. mutex_unlock(&stream->mutex);
  764. ccap->defrect = ccap->bounds;
  765. ccap->pixelaspect.numerator = 1;
  766. ccap->pixelaspect.denominator = 1;
  767. break;
  768. }
  769. case VIDIOC_G_CROP:
  770. case VIDIOC_S_CROP:
  771. return -EINVAL;
  772. /* Buffers & streaming */
  773. case VIDIOC_REQBUFS:
  774. if ((ret = uvc_acquire_privileges(handle)) < 0)
  775. return ret;
  776. mutex_lock(&stream->mutex);
  777. ret = uvc_alloc_buffers(&stream->queue, arg);
  778. mutex_unlock(&stream->mutex);
  779. if (ret < 0)
  780. return ret;
  781. if (ret == 0)
  782. uvc_dismiss_privileges(handle);
  783. ret = 0;
  784. break;
  785. case VIDIOC_QUERYBUF:
  786. {
  787. struct v4l2_buffer *buf = arg;
  788. if (!uvc_has_privileges(handle))
  789. return -EBUSY;
  790. return uvc_query_buffer(&stream->queue, buf);
  791. }
  792. case VIDIOC_QBUF:
  793. if (!uvc_has_privileges(handle))
  794. return -EBUSY;
  795. return uvc_queue_buffer(&stream->queue, arg);
  796. case VIDIOC_DQBUF:
  797. if (!uvc_has_privileges(handle))
  798. return -EBUSY;
  799. return uvc_dequeue_buffer(&stream->queue, arg,
  800. file->f_flags & O_NONBLOCK);
  801. case VIDIOC_STREAMON:
  802. {
  803. int *type = arg;
  804. if (*type != stream->type)
  805. return -EINVAL;
  806. if (!uvc_has_privileges(handle))
  807. return -EBUSY;
  808. mutex_lock(&stream->mutex);
  809. ret = uvc_video_enable(stream, 1);
  810. mutex_unlock(&stream->mutex);
  811. if (ret < 0)
  812. return ret;
  813. break;
  814. }
  815. case VIDIOC_STREAMOFF:
  816. {
  817. int *type = arg;
  818. if (*type != stream->type)
  819. return -EINVAL;
  820. if (!uvc_has_privileges(handle))
  821. return -EBUSY;
  822. return uvc_video_enable(stream, 0);
  823. }
  824. case VIDIOC_SUBSCRIBE_EVENT:
  825. {
  826. struct v4l2_event_subscription *sub = arg;
  827. switch (sub->type) {
  828. case V4L2_EVENT_CTRL:
  829. return v4l2_event_subscribe(&handle->vfh, sub, 0,
  830. &uvc_ctrl_sub_ev_ops);
  831. default:
  832. return -EINVAL;
  833. }
  834. }
  835. case VIDIOC_UNSUBSCRIBE_EVENT:
  836. return v4l2_event_unsubscribe(&handle->vfh, arg);
  837. case VIDIOC_DQEVENT:
  838. return v4l2_event_dequeue(&handle->vfh, arg,
  839. file->f_flags & O_NONBLOCK);
  840. /* Analog video standards make no sense for digital cameras. */
  841. case VIDIOC_ENUMSTD:
  842. case VIDIOC_QUERYSTD:
  843. case VIDIOC_G_STD:
  844. case VIDIOC_S_STD:
  845. case VIDIOC_OVERLAY:
  846. case VIDIOC_ENUMAUDIO:
  847. case VIDIOC_ENUMAUDOUT:
  848. case VIDIOC_ENUMOUTPUT:
  849. uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd);
  850. return -EINVAL;
  851. case UVCIOC_CTRL_MAP:
  852. return uvc_ioctl_ctrl_map(chain, arg);
  853. case UVCIOC_CTRL_QUERY:
  854. return uvc_xu_ctrl_query(chain, arg);
  855. default:
  856. uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n", cmd);
  857. return -ENOTTY;
  858. }
  859. return ret;
  860. }
  861. static long uvc_v4l2_ioctl(struct file *file,
  862. unsigned int cmd, unsigned long arg)
  863. {
  864. if (uvc_trace_param & UVC_TRACE_IOCTL) {
  865. uvc_printk(KERN_DEBUG, "uvc_v4l2_ioctl(");
  866. v4l_printk_ioctl(cmd);
  867. printk(")\n");
  868. }
  869. return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl);
  870. }
  871. #ifdef CONFIG_COMPAT
  872. struct uvc_xu_control_mapping32 {
  873. __u32 id;
  874. __u8 name[32];
  875. __u8 entity[16];
  876. __u8 selector;
  877. __u8 size;
  878. __u8 offset;
  879. __u32 v4l2_type;
  880. __u32 data_type;
  881. compat_caddr_t menu_info;
  882. __u32 menu_count;
  883. __u32 reserved[4];
  884. };
  885. static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
  886. const struct uvc_xu_control_mapping32 __user *up)
  887. {
  888. struct uvc_menu_info __user *umenus;
  889. struct uvc_menu_info __user *kmenus;
  890. compat_caddr_t p;
  891. if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
  892. __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) ||
  893. __get_user(kp->menu_count, &up->menu_count))
  894. return -EFAULT;
  895. memset(kp->reserved, 0, sizeof(kp->reserved));
  896. if (kp->menu_count == 0) {
  897. kp->menu_info = NULL;
  898. return 0;
  899. }
  900. if (__get_user(p, &up->menu_info))
  901. return -EFAULT;
  902. umenus = compat_ptr(p);
  903. if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus)))
  904. return -EFAULT;
  905. kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus));
  906. if (kmenus == NULL)
  907. return -EFAULT;
  908. kp->menu_info = kmenus;
  909. if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus)))
  910. return -EFAULT;
  911. return 0;
  912. }
  913. static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
  914. struct uvc_xu_control_mapping32 __user *up)
  915. {
  916. struct uvc_menu_info __user *umenus;
  917. struct uvc_menu_info __user *kmenus = kp->menu_info;
  918. compat_caddr_t p;
  919. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
  920. __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
  921. __put_user(kp->menu_count, &up->menu_count))
  922. return -EFAULT;
  923. if (__clear_user(up->reserved, sizeof(up->reserved)))
  924. return -EFAULT;
  925. if (kp->menu_count == 0)
  926. return 0;
  927. if (get_user(p, &up->menu_info))
  928. return -EFAULT;
  929. umenus = compat_ptr(p);
  930. if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus)))
  931. return -EFAULT;
  932. return 0;
  933. }
  934. struct uvc_xu_control_query32 {
  935. __u8 unit;
  936. __u8 selector;
  937. __u8 query;
  938. __u16 size;
  939. compat_caddr_t data;
  940. };
  941. static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
  942. const struct uvc_xu_control_query32 __user *up)
  943. {
  944. u8 __user *udata;
  945. u8 __user *kdata;
  946. compat_caddr_t p;
  947. if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
  948. __copy_from_user(kp, up, offsetof(typeof(*up), data)))
  949. return -EFAULT;
  950. if (kp->size == 0) {
  951. kp->data = NULL;
  952. return 0;
  953. }
  954. if (__get_user(p, &up->data))
  955. return -EFAULT;
  956. udata = compat_ptr(p);
  957. if (!access_ok(VERIFY_READ, udata, kp->size))
  958. return -EFAULT;
  959. kdata = compat_alloc_user_space(kp->size);
  960. if (kdata == NULL)
  961. return -EFAULT;
  962. kp->data = kdata;
  963. if (copy_in_user(kdata, udata, kp->size))
  964. return -EFAULT;
  965. return 0;
  966. }
  967. static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
  968. struct uvc_xu_control_query32 __user *up)
  969. {
  970. u8 __user *udata;
  971. u8 __user *kdata = kp->data;
  972. compat_caddr_t p;
  973. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
  974. __copy_to_user(up, kp, offsetof(typeof(*up), data)))
  975. return -EFAULT;
  976. if (kp->size == 0)
  977. return 0;
  978. if (get_user(p, &up->data))
  979. return -EFAULT;
  980. udata = compat_ptr(p);
  981. if (!access_ok(VERIFY_READ, udata, kp->size))
  982. return -EFAULT;
  983. if (copy_in_user(udata, kdata, kp->size))
  984. return -EFAULT;
  985. return 0;
  986. }
  987. #define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32)
  988. #define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32)
  989. static long uvc_v4l2_compat_ioctl32(struct file *file,
  990. unsigned int cmd, unsigned long arg)
  991. {
  992. union {
  993. struct uvc_xu_control_mapping xmap;
  994. struct uvc_xu_control_query xqry;
  995. } karg;
  996. void __user *up = compat_ptr(arg);
  997. mm_segment_t old_fs;
  998. long ret;
  999. switch (cmd) {
  1000. case UVCIOC_CTRL_MAP32:
  1001. cmd = UVCIOC_CTRL_MAP;
  1002. ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
  1003. break;
  1004. case UVCIOC_CTRL_QUERY32:
  1005. cmd = UVCIOC_CTRL_QUERY;
  1006. ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
  1007. break;
  1008. default:
  1009. return -ENOIOCTLCMD;
  1010. }
  1011. old_fs = get_fs();
  1012. set_fs(KERNEL_DS);
  1013. ret = uvc_v4l2_ioctl(file, cmd, (unsigned long)&karg);
  1014. set_fs(old_fs);
  1015. if (ret < 0)
  1016. return ret;
  1017. switch (cmd) {
  1018. case UVCIOC_CTRL_MAP:
  1019. ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up);
  1020. break;
  1021. case UVCIOC_CTRL_QUERY:
  1022. ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
  1023. break;
  1024. }
  1025. return ret;
  1026. }
  1027. #endif
  1028. static ssize_t uvc_v4l2_read(struct file *file, char __user *data,
  1029. size_t count, loff_t *ppos)
  1030. {
  1031. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n");
  1032. return -EINVAL;
  1033. }
  1034. static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
  1035. {
  1036. struct uvc_fh *handle = file->private_data;
  1037. struct uvc_streaming *stream = handle->stream;
  1038. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n");
  1039. return uvc_queue_mmap(&stream->queue, vma);
  1040. }
  1041. static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
  1042. {
  1043. struct uvc_fh *handle = file->private_data;
  1044. struct uvc_streaming *stream = handle->stream;
  1045. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
  1046. return uvc_queue_poll(&stream->queue, file, wait);
  1047. }
  1048. #ifndef CONFIG_MMU
  1049. static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
  1050. unsigned long addr, unsigned long len, unsigned long pgoff,
  1051. unsigned long flags)
  1052. {
  1053. struct uvc_fh *handle = file->private_data;
  1054. struct uvc_streaming *stream = handle->stream;
  1055. uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n");
  1056. return uvc_queue_get_unmapped_area(&stream->queue, pgoff);
  1057. }
  1058. #endif
  1059. const struct v4l2_file_operations uvc_fops = {
  1060. .owner = THIS_MODULE,
  1061. .open = uvc_v4l2_open,
  1062. .release = uvc_v4l2_release,
  1063. .unlocked_ioctl = uvc_v4l2_ioctl,
  1064. #ifdef CONFIG_COMPAT
  1065. .compat_ioctl32 = uvc_v4l2_compat_ioctl32,
  1066. #endif
  1067. .read = uvc_v4l2_read,
  1068. .mmap = uvc_v4l2_mmap,
  1069. .poll = uvc_v4l2_poll,
  1070. #ifndef CONFIG_MMU
  1071. .get_unmapped_area = uvc_v4l2_get_unmapped_area,
  1072. #endif
  1073. };