uvc_v4l2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * uvc_v4l2.c -- USB Video Class Gadget driver
  4. *
  5. * Copyright (C) 2009-2010
  6. * Laurent Pinchart ([email protected])
  7. */
  8. #include <linux/device.h>
  9. #include <linux/errno.h>
  10. #include <linux/kernel.h>
  11. #include <linux/list.h>
  12. #include <linux/usb/g_uvc.h>
  13. #include <linux/videodev2.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/wait.h>
  16. #include <media/v4l2-dev.h>
  17. #include <media/v4l2-event.h>
  18. #include <media/v4l2-ioctl.h>
  19. #include <media/v4l2-uvc.h>
  20. #include "f_uvc.h"
  21. #include "uvc.h"
  22. #include "uvc_queue.h"
  23. #include "uvc_video.h"
  24. #include "uvc_v4l2.h"
  25. #include "uvc_configfs.h"
  26. static struct uvc_format_desc *to_uvc_format(struct uvcg_format *uformat)
  27. {
  28. char guid[16] = UVC_GUID_FORMAT_MJPEG;
  29. struct uvc_format_desc *format;
  30. struct uvcg_uncompressed *unc;
  31. if (uformat->type == UVCG_UNCOMPRESSED) {
  32. unc = to_uvcg_uncompressed(&uformat->group.cg_item);
  33. if (!unc)
  34. return ERR_PTR(-EINVAL);
  35. memcpy(guid, unc->desc.guidFormat, sizeof(guid));
  36. }
  37. format = uvc_format_by_guid(guid);
  38. if (!format)
  39. return ERR_PTR(-EINVAL);
  40. return format;
  41. }
  42. static int uvc_v4l2_get_bytesperline(struct uvcg_format *uformat,
  43. struct uvcg_frame *uframe)
  44. {
  45. struct uvcg_uncompressed *u;
  46. if (uformat->type == UVCG_UNCOMPRESSED) {
  47. u = to_uvcg_uncompressed(&uformat->group.cg_item);
  48. if (!u)
  49. return 0;
  50. return u->desc.bBitsPerPixel * uframe->frame.w_width / 8;
  51. }
  52. return 0;
  53. }
  54. static int uvc_get_frame_size(struct uvcg_format *uformat,
  55. struct uvcg_frame *uframe)
  56. {
  57. unsigned int bpl = uvc_v4l2_get_bytesperline(uformat, uframe);
  58. return bpl ? bpl * uframe->frame.w_height :
  59. uframe->frame.dw_max_video_frame_buffer_size;
  60. }
  61. static struct uvcg_format *find_format_by_index(struct uvc_device *uvc, int index)
  62. {
  63. struct uvcg_format_ptr *format;
  64. struct uvcg_format *uformat = NULL;
  65. int i = 1;
  66. list_for_each_entry(format, &uvc->header->formats, entry) {
  67. if (index == i) {
  68. uformat = format->fmt;
  69. break;
  70. }
  71. i++;
  72. }
  73. return uformat;
  74. }
  75. static struct uvcg_frame *find_frame_by_index(struct uvc_device *uvc,
  76. struct uvcg_format *uformat,
  77. int index)
  78. {
  79. struct uvcg_format_ptr *format;
  80. struct uvcg_frame_ptr *frame;
  81. struct uvcg_frame *uframe = NULL;
  82. list_for_each_entry(format, &uvc->header->formats, entry) {
  83. if (format->fmt->type != uformat->type)
  84. continue;
  85. list_for_each_entry(frame, &format->fmt->frames, entry) {
  86. if (index == frame->frm->frame.b_frame_index) {
  87. uframe = frame->frm;
  88. break;
  89. }
  90. }
  91. }
  92. return uframe;
  93. }
  94. static struct uvcg_format *find_format_by_pix(struct uvc_device *uvc,
  95. u32 pixelformat)
  96. {
  97. struct uvcg_format_ptr *format;
  98. struct uvcg_format *uformat = NULL;
  99. list_for_each_entry(format, &uvc->header->formats, entry) {
  100. struct uvc_format_desc *fmtdesc = to_uvc_format(format->fmt);
  101. if (fmtdesc->fcc == pixelformat) {
  102. uformat = format->fmt;
  103. break;
  104. }
  105. }
  106. return uformat;
  107. }
  108. static struct uvcg_frame *find_closest_frame_by_size(struct uvc_device *uvc,
  109. struct uvcg_format *uformat,
  110. u16 rw, u16 rh)
  111. {
  112. struct uvc_video *video = &uvc->video;
  113. struct uvcg_format_ptr *format;
  114. struct uvcg_frame_ptr *frame;
  115. struct uvcg_frame *uframe = NULL;
  116. unsigned int d, maxd;
  117. /* Find the closest image size. The distance between image sizes is
  118. * the size in pixels of the non-overlapping regions between the
  119. * requested size and the frame-specified size.
  120. */
  121. maxd = (unsigned int)-1;
  122. list_for_each_entry(format, &uvc->header->formats, entry) {
  123. if (format->fmt->type != uformat->type)
  124. continue;
  125. list_for_each_entry(frame, &format->fmt->frames, entry) {
  126. u16 w, h;
  127. w = frame->frm->frame.w_width;
  128. h = frame->frm->frame.w_height;
  129. d = min(w, rw) * min(h, rh);
  130. d = w*h + rw*rh - 2*d;
  131. if (d < maxd) {
  132. maxd = d;
  133. uframe = frame->frm;
  134. }
  135. if (maxd == 0)
  136. break;
  137. }
  138. }
  139. if (!uframe)
  140. uvcg_dbg(&video->uvc->func, "Unsupported size %ux%u\n", rw, rh);
  141. return uframe;
  142. }
  143. /* --------------------------------------------------------------------------
  144. * Requests handling
  145. */
  146. static int
  147. uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
  148. {
  149. struct usb_composite_dev *cdev = uvc->func.config->cdev;
  150. struct usb_request *req = uvc->control_req;
  151. if (data->length < 0)
  152. return usb_ep_set_halt(cdev->gadget->ep0);
  153. req->length = min_t(unsigned int, uvc->event_length, data->length);
  154. req->zero = data->length < uvc->event_length;
  155. memcpy(req->buf, data->data, req->length);
  156. return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL);
  157. }
  158. /* --------------------------------------------------------------------------
  159. * V4L2 ioctls
  160. */
  161. static int
  162. uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
  163. {
  164. struct video_device *vdev = video_devdata(file);
  165. struct uvc_device *uvc = video_get_drvdata(vdev);
  166. struct usb_composite_dev *cdev = uvc->func.config->cdev;
  167. strscpy(cap->driver, "g_uvc", sizeof(cap->driver));
  168. strscpy(cap->card, cdev->gadget->name, sizeof(cap->card));
  169. strscpy(cap->bus_info, dev_name(&cdev->gadget->dev),
  170. sizeof(cap->bus_info));
  171. return 0;
  172. }
  173. static int
  174. uvc_v4l2_get_format(struct file *file, void *fh, struct v4l2_format *fmt)
  175. {
  176. struct video_device *vdev = video_devdata(file);
  177. struct uvc_device *uvc = video_get_drvdata(vdev);
  178. struct uvc_video *video = &uvc->video;
  179. fmt->fmt.pix.pixelformat = video->fcc;
  180. fmt->fmt.pix.width = video->width;
  181. fmt->fmt.pix.height = video->height;
  182. fmt->fmt.pix.field = V4L2_FIELD_NONE;
  183. fmt->fmt.pix.bytesperline = video->bpp * video->width / 8;
  184. fmt->fmt.pix.sizeimage = video->imagesize;
  185. fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  186. fmt->fmt.pix.priv = 0;
  187. return 0;
  188. }
  189. static int
  190. uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt)
  191. {
  192. struct video_device *vdev = video_devdata(file);
  193. struct uvc_device *uvc = video_get_drvdata(vdev);
  194. struct uvc_video *video = &uvc->video;
  195. struct uvcg_format *uformat;
  196. struct uvcg_frame *uframe;
  197. u8 *fcc;
  198. if (fmt->type != video->queue.queue.type)
  199. return -EINVAL;
  200. fcc = (u8 *)&fmt->fmt.pix.pixelformat;
  201. uvcg_dbg(&uvc->func, "Trying format 0x%08x (%c%c%c%c): %ux%u\n",
  202. fmt->fmt.pix.pixelformat,
  203. fcc[0], fcc[1], fcc[2], fcc[3],
  204. fmt->fmt.pix.width, fmt->fmt.pix.height);
  205. uformat = find_format_by_pix(uvc, fmt->fmt.pix.pixelformat);
  206. if (!uformat)
  207. return -EINVAL;
  208. uframe = find_closest_frame_by_size(uvc, uformat,
  209. fmt->fmt.pix.width, fmt->fmt.pix.height);
  210. if (!uframe)
  211. return -EINVAL;
  212. fmt->fmt.pix.width = uframe->frame.w_width;
  213. fmt->fmt.pix.height = uframe->frame.w_height;
  214. fmt->fmt.pix.field = V4L2_FIELD_NONE;
  215. fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe);
  216. fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe);
  217. fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc;
  218. fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  219. fmt->fmt.pix.priv = 0;
  220. return 0;
  221. }
  222. static int
  223. uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt)
  224. {
  225. struct video_device *vdev = video_devdata(file);
  226. struct uvc_device *uvc = video_get_drvdata(vdev);
  227. struct uvc_video *video = &uvc->video;
  228. int ret;
  229. ret = uvc_v4l2_try_format(file, fh, fmt);
  230. if (ret)
  231. return ret;
  232. video->fcc = fmt->fmt.pix.pixelformat;
  233. video->bpp = fmt->fmt.pix.bytesperline * 8 / video->width;
  234. video->width = fmt->fmt.pix.width;
  235. video->height = fmt->fmt.pix.height;
  236. video->imagesize = fmt->fmt.pix.sizeimage;
  237. return ret;
  238. }
  239. static int
  240. uvc_v4l2_enum_frameintervals(struct file *file, void *fh,
  241. struct v4l2_frmivalenum *fival)
  242. {
  243. struct video_device *vdev = video_devdata(file);
  244. struct uvc_device *uvc = video_get_drvdata(vdev);
  245. struct uvcg_format *uformat = NULL;
  246. struct uvcg_frame *uframe = NULL;
  247. struct uvcg_frame_ptr *frame;
  248. uformat = find_format_by_pix(uvc, fival->pixel_format);
  249. if (!uformat)
  250. return -EINVAL;
  251. list_for_each_entry(frame, &uformat->frames, entry) {
  252. if (frame->frm->frame.w_width == fival->width &&
  253. frame->frm->frame.w_height == fival->height) {
  254. uframe = frame->frm;
  255. break;
  256. }
  257. }
  258. if (!uframe)
  259. return -EINVAL;
  260. if (fival->index >= uframe->frame.b_frame_interval_type)
  261. return -EINVAL;
  262. fival->discrete.numerator =
  263. uframe->dw_frame_interval[fival->index];
  264. /* TODO: handle V4L2_FRMIVAL_TYPE_STEPWISE */
  265. fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  266. fival->discrete.denominator = 10000000;
  267. v4l2_simplify_fraction(&fival->discrete.numerator,
  268. &fival->discrete.denominator, 8, 333);
  269. return 0;
  270. }
  271. static int
  272. uvc_v4l2_enum_framesizes(struct file *file, void *fh,
  273. struct v4l2_frmsizeenum *fsize)
  274. {
  275. struct video_device *vdev = video_devdata(file);
  276. struct uvc_device *uvc = video_get_drvdata(vdev);
  277. struct uvcg_format *uformat = NULL;
  278. struct uvcg_frame *uframe = NULL;
  279. uformat = find_format_by_pix(uvc, fsize->pixel_format);
  280. if (!uformat)
  281. return -EINVAL;
  282. if (fsize->index >= uformat->num_frames)
  283. return -EINVAL;
  284. uframe = find_frame_by_index(uvc, uformat, fsize->index + 1);
  285. if (!uframe)
  286. return -EINVAL;
  287. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  288. fsize->discrete.width = uframe->frame.w_width;
  289. fsize->discrete.height = uframe->frame.w_height;
  290. return 0;
  291. }
  292. static int
  293. uvc_v4l2_enum_format(struct file *file, void *fh, struct v4l2_fmtdesc *f)
  294. {
  295. struct video_device *vdev = video_devdata(file);
  296. struct uvc_device *uvc = video_get_drvdata(vdev);
  297. struct uvc_format_desc *fmtdesc;
  298. struct uvcg_format *uformat;
  299. if (f->index >= uvc->header->num_fmt)
  300. return -EINVAL;
  301. uformat = find_format_by_index(uvc, f->index + 1);
  302. if (!uformat)
  303. return -EINVAL;
  304. if (uformat->type != UVCG_UNCOMPRESSED)
  305. f->flags |= V4L2_FMT_FLAG_COMPRESSED;
  306. fmtdesc = to_uvc_format(uformat);
  307. f->pixelformat = fmtdesc->fcc;
  308. strscpy(f->description, fmtdesc->name, sizeof(f->description));
  309. f->description[strlen(fmtdesc->name) - 1] = 0;
  310. return 0;
  311. }
  312. static int
  313. uvc_v4l2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *b)
  314. {
  315. struct video_device *vdev = video_devdata(file);
  316. struct uvc_device *uvc = video_get_drvdata(vdev);
  317. struct uvc_video *video = &uvc->video;
  318. if (b->type != video->queue.queue.type)
  319. return -EINVAL;
  320. return uvcg_alloc_buffers(&video->queue, b);
  321. }
  322. static int
  323. uvc_v4l2_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
  324. {
  325. struct video_device *vdev = video_devdata(file);
  326. struct uvc_device *uvc = video_get_drvdata(vdev);
  327. struct uvc_video *video = &uvc->video;
  328. return uvcg_query_buffer(&video->queue, b);
  329. }
  330. static int
  331. uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
  332. {
  333. struct video_device *vdev = video_devdata(file);
  334. struct uvc_device *uvc = video_get_drvdata(vdev);
  335. struct uvc_video *video = &uvc->video;
  336. int ret;
  337. ret = uvcg_queue_buffer(&video->queue, b);
  338. if (ret < 0)
  339. return ret;
  340. if (uvc->state == UVC_STATE_STREAMING)
  341. queue_work(video->async_wq, &video->pump);
  342. return ret;
  343. }
  344. static int
  345. uvc_v4l2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
  346. {
  347. struct video_device *vdev = video_devdata(file);
  348. struct uvc_device *uvc = video_get_drvdata(vdev);
  349. struct uvc_video *video = &uvc->video;
  350. return uvcg_dequeue_buffer(&video->queue, b, file->f_flags & O_NONBLOCK);
  351. }
  352. static int
  353. uvc_v4l2_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
  354. {
  355. struct video_device *vdev = video_devdata(file);
  356. struct uvc_device *uvc = video_get_drvdata(vdev);
  357. struct uvc_video *video = &uvc->video;
  358. int ret;
  359. if (type != video->queue.queue.type)
  360. return -EINVAL;
  361. /* Enable UVC video. */
  362. ret = uvcg_video_enable(video);
  363. if (ret < 0)
  364. return ret;
  365. /*
  366. * Complete the alternate setting selection setup phase now that
  367. * userspace is ready to provide video frames.
  368. */
  369. uvc_function_setup_continue(uvc, 0);
  370. uvc->state = UVC_STATE_STREAMING;
  371. return 0;
  372. }
  373. static int
  374. uvc_v4l2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
  375. {
  376. struct video_device *vdev = video_devdata(file);
  377. struct uvc_device *uvc = video_get_drvdata(vdev);
  378. struct uvc_video *video = &uvc->video;
  379. int ret = 0;
  380. if (type != video->queue.queue.type)
  381. return -EINVAL;
  382. ret = uvcg_video_disable(video);
  383. if (ret < 0)
  384. return ret;
  385. uvc->state = UVC_STATE_CONNECTED;
  386. uvc_function_setup_continue(uvc, 1);
  387. return 0;
  388. }
  389. static int
  390. uvc_v4l2_subscribe_event(struct v4l2_fh *fh,
  391. const struct v4l2_event_subscription *sub)
  392. {
  393. struct uvc_device *uvc = video_get_drvdata(fh->vdev);
  394. struct uvc_file_handle *handle = to_uvc_file_handle(fh);
  395. int ret;
  396. if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST)
  397. return -EINVAL;
  398. if (sub->type == UVC_EVENT_SETUP && uvc->func_connected)
  399. return -EBUSY;
  400. ret = v4l2_event_subscribe(fh, sub, 2, NULL);
  401. if (ret < 0)
  402. return ret;
  403. if (sub->type == UVC_EVENT_SETUP) {
  404. uvc->func_connected = true;
  405. handle->is_uvc_app_handle = true;
  406. uvc_function_connect(uvc);
  407. }
  408. return 0;
  409. }
  410. static void uvc_v4l2_disable(struct uvc_device *uvc)
  411. {
  412. uvc_function_disconnect(uvc);
  413. uvcg_video_disable(&uvc->video);
  414. uvcg_free_buffers(&uvc->video.queue);
  415. uvc->func_connected = false;
  416. wake_up_interruptible(&uvc->func_connected_queue);
  417. }
  418. static int
  419. uvc_v4l2_unsubscribe_event(struct v4l2_fh *fh,
  420. const struct v4l2_event_subscription *sub)
  421. {
  422. struct uvc_device *uvc = video_get_drvdata(fh->vdev);
  423. struct uvc_file_handle *handle = to_uvc_file_handle(fh);
  424. int ret;
  425. ret = v4l2_event_unsubscribe(fh, sub);
  426. if (ret < 0)
  427. return ret;
  428. if (sub->type == UVC_EVENT_SETUP && handle->is_uvc_app_handle) {
  429. uvc_v4l2_disable(uvc);
  430. handle->is_uvc_app_handle = false;
  431. }
  432. return 0;
  433. }
  434. static long
  435. uvc_v4l2_ioctl_default(struct file *file, void *fh, bool valid_prio,
  436. unsigned int cmd, void *arg)
  437. {
  438. struct video_device *vdev = video_devdata(file);
  439. struct uvc_device *uvc = video_get_drvdata(vdev);
  440. switch (cmd) {
  441. case UVCIOC_SEND_RESPONSE:
  442. return uvc_send_response(uvc, arg);
  443. default:
  444. return -ENOIOCTLCMD;
  445. }
  446. }
  447. const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops = {
  448. .vidioc_querycap = uvc_v4l2_querycap,
  449. .vidioc_try_fmt_vid_out = uvc_v4l2_try_format,
  450. .vidioc_g_fmt_vid_out = uvc_v4l2_get_format,
  451. .vidioc_s_fmt_vid_out = uvc_v4l2_set_format,
  452. .vidioc_enum_frameintervals = uvc_v4l2_enum_frameintervals,
  453. .vidioc_enum_framesizes = uvc_v4l2_enum_framesizes,
  454. .vidioc_enum_fmt_vid_out = uvc_v4l2_enum_format,
  455. .vidioc_reqbufs = uvc_v4l2_reqbufs,
  456. .vidioc_querybuf = uvc_v4l2_querybuf,
  457. .vidioc_qbuf = uvc_v4l2_qbuf,
  458. .vidioc_dqbuf = uvc_v4l2_dqbuf,
  459. .vidioc_streamon = uvc_v4l2_streamon,
  460. .vidioc_streamoff = uvc_v4l2_streamoff,
  461. .vidioc_subscribe_event = uvc_v4l2_subscribe_event,
  462. .vidioc_unsubscribe_event = uvc_v4l2_unsubscribe_event,
  463. .vidioc_default = uvc_v4l2_ioctl_default,
  464. };
  465. /* --------------------------------------------------------------------------
  466. * V4L2
  467. */
  468. static int
  469. uvc_v4l2_open(struct file *file)
  470. {
  471. struct video_device *vdev = video_devdata(file);
  472. struct uvc_device *uvc = video_get_drvdata(vdev);
  473. struct uvc_file_handle *handle;
  474. handle = kzalloc(sizeof(*handle), GFP_KERNEL);
  475. if (handle == NULL)
  476. return -ENOMEM;
  477. v4l2_fh_init(&handle->vfh, vdev);
  478. v4l2_fh_add(&handle->vfh);
  479. handle->device = &uvc->video;
  480. file->private_data = &handle->vfh;
  481. return 0;
  482. }
  483. static int
  484. uvc_v4l2_release(struct file *file)
  485. {
  486. struct video_device *vdev = video_devdata(file);
  487. struct uvc_device *uvc = video_get_drvdata(vdev);
  488. struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data);
  489. struct uvc_video *video = handle->device;
  490. mutex_lock(&video->mutex);
  491. if (handle->is_uvc_app_handle)
  492. uvc_v4l2_disable(uvc);
  493. mutex_unlock(&video->mutex);
  494. file->private_data = NULL;
  495. v4l2_fh_del(&handle->vfh);
  496. v4l2_fh_exit(&handle->vfh);
  497. kfree(handle);
  498. return 0;
  499. }
  500. static int
  501. uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
  502. {
  503. struct video_device *vdev = video_devdata(file);
  504. struct uvc_device *uvc = video_get_drvdata(vdev);
  505. return uvcg_queue_mmap(&uvc->video.queue, vma);
  506. }
  507. static __poll_t
  508. uvc_v4l2_poll(struct file *file, poll_table *wait)
  509. {
  510. struct video_device *vdev = video_devdata(file);
  511. struct uvc_device *uvc = video_get_drvdata(vdev);
  512. return uvcg_queue_poll(&uvc->video.queue, file, wait);
  513. }
  514. #ifndef CONFIG_MMU
  515. static unsigned long uvcg_v4l2_get_unmapped_area(struct file *file,
  516. unsigned long addr, unsigned long len, unsigned long pgoff,
  517. unsigned long flags)
  518. {
  519. struct video_device *vdev = video_devdata(file);
  520. struct uvc_device *uvc = video_get_drvdata(vdev);
  521. return uvcg_queue_get_unmapped_area(&uvc->video.queue, pgoff);
  522. }
  523. #endif
  524. const struct v4l2_file_operations uvc_v4l2_fops = {
  525. .owner = THIS_MODULE,
  526. .open = uvc_v4l2_open,
  527. .release = uvc_v4l2_release,
  528. .unlocked_ioctl = video_ioctl2,
  529. .mmap = uvc_v4l2_mmap,
  530. .poll = uvc_v4l2_poll,
  531. #ifndef CONFIG_MMU
  532. .get_unmapped_area = uvcg_v4l2_get_unmapped_area,
  533. #endif
  534. };