f_uvc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * uvc_gadget.c -- USB Video Class Gadget driver
  4. *
  5. * Copyright (C) 2009-2010
  6. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  7. */
  8. #include <linux/device.h>
  9. #include <linux/errno.h>
  10. #include <linux/fs.h>
  11. #include <linux/kernel.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/mutex.h>
  15. #include <linux/string.h>
  16. #include <linux/usb/ch9.h>
  17. #include <linux/usb/gadget.h>
  18. #include <linux/usb/g_uvc.h>
  19. #include <linux/usb/video.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/wait.h>
  22. #include <media/v4l2-dev.h>
  23. #include <media/v4l2-event.h>
  24. #include "uvc.h"
  25. #include "uvc_configfs.h"
  26. #include "uvc_v4l2.h"
  27. #include "uvc_video.h"
  28. unsigned int uvc_gadget_trace_param;
  29. module_param_named(trace, uvc_gadget_trace_param, uint, 0644);
  30. MODULE_PARM_DESC(trace, "Trace level bitmask");
  31. /* --------------------------------------------------------------------------
  32. * Function descriptors
  33. */
  34. /* string IDs are assigned dynamically */
  35. static struct usb_string uvc_en_us_strings[] = {
  36. /* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
  37. [UVC_STRING_STREAMING_IDX].s = "Video Streaming",
  38. { }
  39. };
  40. static struct usb_gadget_strings uvc_stringtab = {
  41. .language = 0x0409, /* en-us */
  42. .strings = uvc_en_us_strings,
  43. };
  44. static struct usb_gadget_strings *uvc_function_strings[] = {
  45. &uvc_stringtab,
  46. NULL,
  47. };
  48. #define UVC_INTF_VIDEO_CONTROL 0
  49. #define UVC_INTF_VIDEO_STREAMING 1
  50. #define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */
  51. static struct usb_interface_assoc_descriptor uvc_iad = {
  52. .bLength = sizeof(uvc_iad),
  53. .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
  54. .bFirstInterface = 0,
  55. .bInterfaceCount = 2,
  56. .bFunctionClass = USB_CLASS_VIDEO,
  57. .bFunctionSubClass = UVC_SC_VIDEO_INTERFACE_COLLECTION,
  58. .bFunctionProtocol = 0x00,
  59. .iFunction = 0,
  60. };
  61. static struct usb_interface_descriptor uvc_control_intf = {
  62. .bLength = USB_DT_INTERFACE_SIZE,
  63. .bDescriptorType = USB_DT_INTERFACE,
  64. .bInterfaceNumber = UVC_INTF_VIDEO_CONTROL,
  65. .bAlternateSetting = 0,
  66. .bNumEndpoints = 0,
  67. .bInterfaceClass = USB_CLASS_VIDEO,
  68. .bInterfaceSubClass = UVC_SC_VIDEOCONTROL,
  69. .bInterfaceProtocol = 0x00,
  70. .iInterface = 0,
  71. };
  72. static struct usb_endpoint_descriptor uvc_interrupt_ep = {
  73. .bLength = USB_DT_ENDPOINT_SIZE,
  74. .bDescriptorType = USB_DT_ENDPOINT,
  75. .bEndpointAddress = USB_DIR_IN,
  76. .bmAttributes = USB_ENDPOINT_XFER_INT,
  77. .wMaxPacketSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
  78. .bInterval = 8,
  79. };
  80. static struct usb_ss_ep_comp_descriptor uvc_ss_interrupt_comp = {
  81. .bLength = sizeof(uvc_ss_interrupt_comp),
  82. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  83. /* The following 3 values can be tweaked if necessary. */
  84. .bMaxBurst = 0,
  85. .bmAttributes = 0,
  86. .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
  87. };
  88. static struct uvc_control_endpoint_descriptor uvc_interrupt_cs_ep = {
  89. .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE,
  90. .bDescriptorType = USB_DT_CS_ENDPOINT,
  91. .bDescriptorSubType = UVC_EP_INTERRUPT,
  92. .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
  93. };
  94. static struct usb_interface_descriptor uvc_streaming_intf_alt0 = {
  95. .bLength = USB_DT_INTERFACE_SIZE,
  96. .bDescriptorType = USB_DT_INTERFACE,
  97. .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING,
  98. .bAlternateSetting = 0,
  99. .bNumEndpoints = 0,
  100. .bInterfaceClass = USB_CLASS_VIDEO,
  101. .bInterfaceSubClass = UVC_SC_VIDEOSTREAMING,
  102. .bInterfaceProtocol = 0x00,
  103. .iInterface = 0,
  104. };
  105. static struct usb_interface_descriptor uvc_streaming_intf_alt1 = {
  106. .bLength = USB_DT_INTERFACE_SIZE,
  107. .bDescriptorType = USB_DT_INTERFACE,
  108. .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING,
  109. .bAlternateSetting = 1,
  110. .bNumEndpoints = 1,
  111. .bInterfaceClass = USB_CLASS_VIDEO,
  112. .bInterfaceSubClass = UVC_SC_VIDEOSTREAMING,
  113. .bInterfaceProtocol = 0x00,
  114. .iInterface = 0,
  115. };
  116. static struct usb_endpoint_descriptor uvc_fs_streaming_ep = {
  117. .bLength = USB_DT_ENDPOINT_SIZE,
  118. .bDescriptorType = USB_DT_ENDPOINT,
  119. .bEndpointAddress = USB_DIR_IN,
  120. .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
  121. | USB_ENDPOINT_XFER_ISOC,
  122. /*
  123. * The wMaxPacketSize and bInterval values will be initialized from
  124. * module parameters.
  125. */
  126. };
  127. static struct usb_endpoint_descriptor uvc_hs_streaming_ep = {
  128. .bLength = USB_DT_ENDPOINT_SIZE,
  129. .bDescriptorType = USB_DT_ENDPOINT,
  130. .bEndpointAddress = USB_DIR_IN,
  131. .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
  132. | USB_ENDPOINT_XFER_ISOC,
  133. /*
  134. * The wMaxPacketSize and bInterval values will be initialized from
  135. * module parameters.
  136. */
  137. };
  138. static struct usb_endpoint_descriptor uvc_ss_streaming_ep = {
  139. .bLength = USB_DT_ENDPOINT_SIZE,
  140. .bDescriptorType = USB_DT_ENDPOINT,
  141. .bEndpointAddress = USB_DIR_IN,
  142. .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
  143. | USB_ENDPOINT_XFER_ISOC,
  144. /*
  145. * The wMaxPacketSize and bInterval values will be initialized from
  146. * module parameters.
  147. */
  148. };
  149. static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = {
  150. .bLength = sizeof(uvc_ss_streaming_comp),
  151. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  152. /*
  153. * The bMaxBurst, bmAttributes and wBytesPerInterval values will be
  154. * initialized from module parameters.
  155. */
  156. };
  157. static const struct usb_descriptor_header * const uvc_fs_streaming[] = {
  158. (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
  159. (struct usb_descriptor_header *) &uvc_fs_streaming_ep,
  160. NULL,
  161. };
  162. static const struct usb_descriptor_header * const uvc_hs_streaming[] = {
  163. (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
  164. (struct usb_descriptor_header *) &uvc_hs_streaming_ep,
  165. NULL,
  166. };
  167. static const struct usb_descriptor_header * const uvc_ss_streaming[] = {
  168. (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
  169. (struct usb_descriptor_header *) &uvc_ss_streaming_ep,
  170. (struct usb_descriptor_header *) &uvc_ss_streaming_comp,
  171. NULL,
  172. };
  173. /* --------------------------------------------------------------------------
  174. * Control requests
  175. */
  176. static void
  177. uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req)
  178. {
  179. struct uvc_device *uvc = req->context;
  180. struct v4l2_event v4l2_event;
  181. struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
  182. if (uvc->event_setup_out) {
  183. uvc->event_setup_out = 0;
  184. memset(&v4l2_event, 0, sizeof(v4l2_event));
  185. v4l2_event.type = UVC_EVENT_DATA;
  186. uvc_event->data.length = min_t(unsigned int, req->actual,
  187. sizeof(uvc_event->data.data));
  188. memcpy(&uvc_event->data.data, req->buf, uvc_event->data.length);
  189. v4l2_event_queue(&uvc->vdev, &v4l2_event);
  190. }
  191. }
  192. static int
  193. uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
  194. {
  195. struct uvc_device *uvc = to_uvc(f);
  196. struct v4l2_event v4l2_event;
  197. struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
  198. unsigned int interface = le16_to_cpu(ctrl->wIndex) & 0xff;
  199. struct usb_ctrlrequest *mctrl;
  200. if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) {
  201. uvcg_info(f, "invalid request type\n");
  202. return -EINVAL;
  203. }
  204. /* Stall too big requests. */
  205. if (le16_to_cpu(ctrl->wLength) > UVC_MAX_REQUEST_SIZE)
  206. return -EINVAL;
  207. /*
  208. * Tell the complete callback to generate an event for the next request
  209. * that will be enqueued by UVCIOC_SEND_RESPONSE.
  210. */
  211. uvc->event_setup_out = !(ctrl->bRequestType & USB_DIR_IN);
  212. uvc->event_length = le16_to_cpu(ctrl->wLength);
  213. memset(&v4l2_event, 0, sizeof(v4l2_event));
  214. v4l2_event.type = UVC_EVENT_SETUP;
  215. memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req));
  216. /* check for the interface number, fixup the interface number in
  217. * the ctrl request so the userspace doesn't have to bother with
  218. * offset and configfs parsing
  219. */
  220. mctrl = &uvc_event->req;
  221. mctrl->wIndex &= ~cpu_to_le16(0xff);
  222. if (interface == uvc->streaming_intf)
  223. mctrl->wIndex = cpu_to_le16(UVC_STRING_STREAMING_IDX);
  224. v4l2_event_queue(&uvc->vdev, &v4l2_event);
  225. return 0;
  226. }
  227. void uvc_function_setup_continue(struct uvc_device *uvc, int disable_ep)
  228. {
  229. struct usb_composite_dev *cdev = uvc->func.config->cdev;
  230. if (disable_ep && uvc->video.ep)
  231. usb_ep_disable(uvc->video.ep);
  232. usb_composite_setup_continue(cdev);
  233. }
  234. static int
  235. uvc_function_get_alt(struct usb_function *f, unsigned interface)
  236. {
  237. struct uvc_device *uvc = to_uvc(f);
  238. uvcg_info(f, "%s(%u)\n", __func__, interface);
  239. if (interface == uvc->control_intf)
  240. return 0;
  241. else if (interface != uvc->streaming_intf)
  242. return -EINVAL;
  243. else
  244. return uvc->video.ep->enabled ? 1 : 0;
  245. }
  246. static int
  247. uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
  248. {
  249. struct uvc_device *uvc = to_uvc(f);
  250. struct usb_composite_dev *cdev = f->config->cdev;
  251. struct v4l2_event v4l2_event;
  252. struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
  253. int ret;
  254. uvcg_info(f, "%s(%u, %u)\n", __func__, interface, alt);
  255. if (interface == uvc->control_intf) {
  256. if (alt)
  257. return -EINVAL;
  258. if (uvc->enable_interrupt_ep) {
  259. uvcg_info(f, "reset UVC interrupt endpoint\n");
  260. usb_ep_disable(uvc->interrupt_ep);
  261. if (!uvc->interrupt_ep->desc)
  262. if (config_ep_by_speed(cdev->gadget, f,
  263. uvc->interrupt_ep))
  264. return -EINVAL;
  265. usb_ep_enable(uvc->interrupt_ep);
  266. }
  267. if (uvc->state == UVC_STATE_DISCONNECTED) {
  268. memset(&v4l2_event, 0, sizeof(v4l2_event));
  269. v4l2_event.type = UVC_EVENT_CONNECT;
  270. uvc_event->speed = cdev->gadget->speed;
  271. v4l2_event_queue(&uvc->vdev, &v4l2_event);
  272. uvc->state = UVC_STATE_CONNECTED;
  273. }
  274. return 0;
  275. }
  276. if (interface != uvc->streaming_intf)
  277. return -EINVAL;
  278. /* TODO
  279. if (usb_endpoint_xfer_bulk(&uvc->desc.vs_ep))
  280. return alt ? -EINVAL : 0;
  281. */
  282. switch (alt) {
  283. case 0:
  284. if (uvc->state != UVC_STATE_STREAMING)
  285. return 0;
  286. memset(&v4l2_event, 0, sizeof(v4l2_event));
  287. v4l2_event.type = UVC_EVENT_STREAMOFF;
  288. v4l2_event_queue(&uvc->vdev, &v4l2_event);
  289. return USB_GADGET_DELAYED_STATUS;
  290. case 1:
  291. if (uvc->state != UVC_STATE_CONNECTED)
  292. return 0;
  293. if (!uvc->video.ep)
  294. return -EINVAL;
  295. uvcg_info(f, "reset UVC\n");
  296. usb_ep_disable(uvc->video.ep);
  297. ret = config_ep_by_speed(f->config->cdev->gadget,
  298. &(uvc->func), uvc->video.ep);
  299. if (ret)
  300. return ret;
  301. usb_ep_enable(uvc->video.ep);
  302. memset(&v4l2_event, 0, sizeof(v4l2_event));
  303. v4l2_event.type = UVC_EVENT_STREAMON;
  304. v4l2_event_queue(&uvc->vdev, &v4l2_event);
  305. return USB_GADGET_DELAYED_STATUS;
  306. default:
  307. return -EINVAL;
  308. }
  309. }
  310. static void
  311. uvc_function_disable(struct usb_function *f)
  312. {
  313. struct uvc_device *uvc = to_uvc(f);
  314. struct v4l2_event v4l2_event;
  315. uvcg_info(f, "%s()\n", __func__);
  316. memset(&v4l2_event, 0, sizeof(v4l2_event));
  317. v4l2_event.type = UVC_EVENT_DISCONNECT;
  318. v4l2_event_queue(&uvc->vdev, &v4l2_event);
  319. uvc->state = UVC_STATE_DISCONNECTED;
  320. usb_ep_disable(uvc->video.ep);
  321. if (uvc->enable_interrupt_ep)
  322. usb_ep_disable(uvc->interrupt_ep);
  323. }
  324. /* --------------------------------------------------------------------------
  325. * Connection / disconnection
  326. */
  327. void
  328. uvc_function_connect(struct uvc_device *uvc)
  329. {
  330. int ret;
  331. if ((ret = usb_function_activate(&uvc->func)) < 0)
  332. uvcg_info(&uvc->func, "UVC connect failed with %d\n", ret);
  333. }
  334. void
  335. uvc_function_disconnect(struct uvc_device *uvc)
  336. {
  337. int ret;
  338. if ((ret = usb_function_deactivate(&uvc->func)) < 0)
  339. uvcg_info(&uvc->func, "UVC disconnect failed with %d\n", ret);
  340. }
  341. /* --------------------------------------------------------------------------
  342. * USB probe and disconnect
  343. */
  344. static ssize_t function_name_show(struct device *dev,
  345. struct device_attribute *attr, char *buf)
  346. {
  347. struct uvc_device *uvc = dev_get_drvdata(dev);
  348. return sprintf(buf, "%s\n", uvc->func.fi->group.cg_item.ci_name);
  349. }
  350. static DEVICE_ATTR_RO(function_name);
  351. static int
  352. uvc_register_video(struct uvc_device *uvc)
  353. {
  354. struct usb_composite_dev *cdev = uvc->func.config->cdev;
  355. int ret;
  356. /* TODO reference counting. */
  357. memset(&uvc->vdev, 0, sizeof(uvc->vdev));
  358. uvc->vdev.v4l2_dev = &uvc->v4l2_dev;
  359. uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev;
  360. uvc->vdev.fops = &uvc_v4l2_fops;
  361. uvc->vdev.ioctl_ops = &uvc_v4l2_ioctl_ops;
  362. uvc->vdev.release = video_device_release_empty;
  363. uvc->vdev.vfl_dir = VFL_DIR_TX;
  364. uvc->vdev.lock = &uvc->video.mutex;
  365. uvc->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
  366. strscpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
  367. video_set_drvdata(&uvc->vdev, uvc);
  368. ret = video_register_device(&uvc->vdev, VFL_TYPE_VIDEO, -1);
  369. if (ret < 0)
  370. return ret;
  371. ret = device_create_file(&uvc->vdev.dev, &dev_attr_function_name);
  372. if (ret < 0) {
  373. video_unregister_device(&uvc->vdev);
  374. return ret;
  375. }
  376. return 0;
  377. }
  378. #define UVC_COPY_DESCRIPTOR(mem, dst, desc) \
  379. do { \
  380. memcpy(mem, desc, (desc)->bLength); \
  381. *(dst)++ = mem; \
  382. mem += (desc)->bLength; \
  383. } while (0);
  384. #define UVC_COPY_DESCRIPTORS(mem, dst, src) \
  385. do { \
  386. const struct usb_descriptor_header * const *__src; \
  387. for (__src = src; *__src; ++__src) { \
  388. memcpy(mem, *__src, (*__src)->bLength); \
  389. *dst++ = mem; \
  390. mem += (*__src)->bLength; \
  391. } \
  392. } while (0)
  393. #define UVC_COPY_XU_DESCRIPTOR(mem, dst, desc) \
  394. do { \
  395. *(dst)++ = mem; \
  396. memcpy(mem, desc, 22); /* bLength to bNrInPins */ \
  397. mem += 22; \
  398. \
  399. memcpy(mem, (desc)->baSourceID, (desc)->bNrInPins); \
  400. mem += (desc)->bNrInPins; \
  401. \
  402. memcpy(mem, &(desc)->bControlSize, 1); \
  403. mem++; \
  404. \
  405. memcpy(mem, (desc)->bmControls, (desc)->bControlSize); \
  406. mem += (desc)->bControlSize; \
  407. \
  408. memcpy(mem, &(desc)->iExtension, 1); \
  409. mem++; \
  410. } while (0)
  411. static struct usb_descriptor_header **
  412. uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
  413. {
  414. struct uvc_input_header_descriptor *uvc_streaming_header;
  415. struct uvc_header_descriptor *uvc_control_header;
  416. const struct uvc_descriptor_header * const *uvc_control_desc;
  417. const struct uvc_descriptor_header * const *uvc_streaming_cls;
  418. const struct usb_descriptor_header * const *uvc_streaming_std;
  419. const struct usb_descriptor_header * const *src;
  420. struct usb_descriptor_header **dst;
  421. struct usb_descriptor_header **hdr;
  422. struct uvcg_extension *xu;
  423. unsigned int control_size;
  424. unsigned int streaming_size;
  425. unsigned int n_desc;
  426. unsigned int bytes;
  427. void *mem;
  428. switch (speed) {
  429. case USB_SPEED_SUPER_PLUS:
  430. case USB_SPEED_SUPER:
  431. uvc_control_desc = uvc->desc.ss_control;
  432. uvc_streaming_cls = uvc->desc.ss_streaming;
  433. uvc_streaming_std = uvc_ss_streaming;
  434. break;
  435. case USB_SPEED_HIGH:
  436. uvc_control_desc = uvc->desc.fs_control;
  437. uvc_streaming_cls = uvc->desc.hs_streaming;
  438. uvc_streaming_std = uvc_hs_streaming;
  439. break;
  440. case USB_SPEED_FULL:
  441. default:
  442. uvc_control_desc = uvc->desc.fs_control;
  443. uvc_streaming_cls = uvc->desc.fs_streaming;
  444. uvc_streaming_std = uvc_fs_streaming;
  445. break;
  446. }
  447. if (!uvc_control_desc || !uvc_streaming_cls)
  448. return ERR_PTR(-ENODEV);
  449. /*
  450. * Descriptors layout
  451. *
  452. * uvc_iad
  453. * uvc_control_intf
  454. * Class-specific UVC control descriptors
  455. * uvc_interrupt_ep
  456. * uvc_interrupt_cs_ep
  457. * uvc_ss_interrupt_comp (for SS only)
  458. * uvc_streaming_intf_alt0
  459. * Class-specific UVC streaming descriptors
  460. * uvc_{fs|hs}_streaming
  461. */
  462. /* Count descriptors and compute their size. */
  463. control_size = 0;
  464. streaming_size = 0;
  465. bytes = uvc_iad.bLength + uvc_control_intf.bLength
  466. + uvc_streaming_intf_alt0.bLength;
  467. n_desc = 3;
  468. if (uvc->enable_interrupt_ep) {
  469. bytes += uvc_interrupt_ep.bLength + uvc_interrupt_cs_ep.bLength;
  470. n_desc += 2;
  471. if (speed == USB_SPEED_SUPER ||
  472. speed == USB_SPEED_SUPER_PLUS) {
  473. bytes += uvc_ss_interrupt_comp.bLength;
  474. n_desc += 1;
  475. }
  476. }
  477. for (src = (const struct usb_descriptor_header **)uvc_control_desc;
  478. *src; ++src) {
  479. control_size += (*src)->bLength;
  480. bytes += (*src)->bLength;
  481. n_desc++;
  482. }
  483. list_for_each_entry(xu, uvc->desc.extension_units, list) {
  484. control_size += xu->desc.bLength;
  485. bytes += xu->desc.bLength;
  486. n_desc++;
  487. }
  488. for (src = (const struct usb_descriptor_header **)uvc_streaming_cls;
  489. *src; ++src) {
  490. streaming_size += (*src)->bLength;
  491. bytes += (*src)->bLength;
  492. n_desc++;
  493. }
  494. for (src = uvc_streaming_std; *src; ++src) {
  495. bytes += (*src)->bLength;
  496. n_desc++;
  497. }
  498. mem = kmalloc((n_desc + 1) * sizeof(*src) + bytes, GFP_KERNEL);
  499. if (mem == NULL)
  500. return NULL;
  501. hdr = mem;
  502. dst = mem;
  503. mem += (n_desc + 1) * sizeof(*src);
  504. /* Copy the descriptors. */
  505. UVC_COPY_DESCRIPTOR(mem, dst, &uvc_iad);
  506. UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_intf);
  507. uvc_control_header = mem;
  508. UVC_COPY_DESCRIPTORS(mem, dst,
  509. (const struct usb_descriptor_header **)uvc_control_desc);
  510. list_for_each_entry(xu, uvc->desc.extension_units, list)
  511. UVC_COPY_XU_DESCRIPTOR(mem, dst, &xu->desc);
  512. uvc_control_header->wTotalLength = cpu_to_le16(control_size);
  513. uvc_control_header->bInCollection = 1;
  514. uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf;
  515. if (uvc->enable_interrupt_ep) {
  516. UVC_COPY_DESCRIPTOR(mem, dst, &uvc_interrupt_ep);
  517. if (speed == USB_SPEED_SUPER ||
  518. speed == USB_SPEED_SUPER_PLUS)
  519. UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_interrupt_comp);
  520. UVC_COPY_DESCRIPTOR(mem, dst, &uvc_interrupt_cs_ep);
  521. }
  522. UVC_COPY_DESCRIPTOR(mem, dst, &uvc_streaming_intf_alt0);
  523. uvc_streaming_header = mem;
  524. UVC_COPY_DESCRIPTORS(mem, dst,
  525. (const struct usb_descriptor_header**)uvc_streaming_cls);
  526. uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size);
  527. uvc_streaming_header->bEndpointAddress = uvc->video.ep->address;
  528. UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std);
  529. *dst = NULL;
  530. return hdr;
  531. }
  532. static int
  533. uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
  534. {
  535. struct usb_composite_dev *cdev = c->cdev;
  536. struct uvc_device *uvc = to_uvc(f);
  537. struct uvcg_extension *xu;
  538. struct usb_string *us;
  539. unsigned int max_packet_mult;
  540. unsigned int max_packet_size;
  541. struct usb_ep *ep;
  542. struct f_uvc_opts *opts;
  543. int ret = -EINVAL;
  544. uvcg_info(f, "%s()\n", __func__);
  545. opts = fi_to_f_uvc_opts(f->fi);
  546. /* Sanity check the streaming endpoint module parameters. */
  547. opts->streaming_interval = clamp(opts->streaming_interval, 1U, 16U);
  548. opts->streaming_maxpacket = clamp(opts->streaming_maxpacket, 1U, 3072U);
  549. opts->streaming_maxburst = min(opts->streaming_maxburst, 15U);
  550. /* For SS, wMaxPacketSize has to be 1024 if bMaxBurst is not 0 */
  551. if (opts->streaming_maxburst &&
  552. (opts->streaming_maxpacket % 1024) != 0) {
  553. opts->streaming_maxpacket = roundup(opts->streaming_maxpacket, 1024);
  554. uvcg_info(f, "overriding streaming_maxpacket to %d\n",
  555. opts->streaming_maxpacket);
  556. }
  557. /*
  558. * Fill in the FS/HS/SS Video Streaming specific descriptors from the
  559. * module parameters.
  560. *
  561. * NOTE: We assume that the user knows what they are doing and won't
  562. * give parameters that their UDC doesn't support.
  563. */
  564. if (opts->streaming_maxpacket <= 1024) {
  565. max_packet_mult = 1;
  566. max_packet_size = opts->streaming_maxpacket;
  567. } else if (opts->streaming_maxpacket <= 2048) {
  568. max_packet_mult = 2;
  569. max_packet_size = opts->streaming_maxpacket / 2;
  570. } else {
  571. max_packet_mult = 3;
  572. max_packet_size = opts->streaming_maxpacket / 3;
  573. }
  574. uvc_fs_streaming_ep.wMaxPacketSize =
  575. cpu_to_le16(min(opts->streaming_maxpacket, 1023U));
  576. uvc_fs_streaming_ep.bInterval = opts->streaming_interval;
  577. uvc_hs_streaming_ep.wMaxPacketSize =
  578. cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11));
  579. /* A high-bandwidth endpoint must specify a bInterval value of 1 */
  580. if (max_packet_mult > 1)
  581. uvc_hs_streaming_ep.bInterval = 1;
  582. else
  583. uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
  584. uvc_ss_streaming_ep.wMaxPacketSize = cpu_to_le16(max_packet_size);
  585. uvc_ss_streaming_ep.bInterval = opts->streaming_interval;
  586. uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1;
  587. uvc_ss_streaming_comp.bMaxBurst = opts->streaming_maxburst;
  588. uvc_ss_streaming_comp.wBytesPerInterval =
  589. cpu_to_le16(max_packet_size * max_packet_mult *
  590. (opts->streaming_maxburst + 1));
  591. /* Allocate endpoints. */
  592. if (opts->enable_interrupt_ep) {
  593. ep = usb_ep_autoconfig(cdev->gadget, &uvc_interrupt_ep);
  594. if (!ep) {
  595. uvcg_info(f, "Unable to allocate interrupt EP\n");
  596. goto error;
  597. }
  598. uvc->interrupt_ep = ep;
  599. uvc_control_intf.bNumEndpoints = 1;
  600. }
  601. uvc->enable_interrupt_ep = opts->enable_interrupt_ep;
  602. /*
  603. * gadget_is_{super|dual}speed() API check UDC controller capitblity. It should pass down
  604. * highest speed endpoint descriptor to UDC controller. So UDC controller driver can reserve
  605. * enough resource at check_config(), especially mult and maxburst. So UDC driver (such as
  606. * cdns3) can know need at least (mult + 1) * (maxburst + 1) * wMaxPacketSize internal
  607. * memory for this uvc functions. This is the only straightforward method to resolve the UDC
  608. * resource allocation issue in the current gadget framework.
  609. */
  610. if (gadget_is_superspeed(c->cdev->gadget))
  611. ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep,
  612. &uvc_ss_streaming_comp);
  613. else if (gadget_is_dualspeed(cdev->gadget))
  614. ep = usb_ep_autoconfig(cdev->gadget, &uvc_hs_streaming_ep);
  615. else
  616. ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep);
  617. if (!ep) {
  618. uvcg_info(f, "Unable to allocate streaming EP\n");
  619. goto error;
  620. }
  621. uvc->video.ep = ep;
  622. uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
  623. uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
  624. uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;
  625. /*
  626. * XUs can have an arbitrary string descriptor describing them. If they
  627. * have one pick up the ID.
  628. */
  629. list_for_each_entry(xu, &opts->extension_units, list)
  630. if (xu->string_descriptor_index)
  631. xu->desc.iExtension = cdev->usb_strings[xu->string_descriptor_index].id;
  632. /*
  633. * We attach the hard-coded defaults incase the user does not provide
  634. * any more appropriate strings through configfs.
  635. */
  636. uvc_en_us_strings[UVC_STRING_CONTROL_IDX].s = opts->function_name;
  637. us = usb_gstrings_attach(cdev, uvc_function_strings,
  638. ARRAY_SIZE(uvc_en_us_strings));
  639. if (IS_ERR(us)) {
  640. ret = PTR_ERR(us);
  641. goto error;
  642. }
  643. uvc_iad.iFunction = opts->iad_index ? cdev->usb_strings[opts->iad_index].id :
  644. us[UVC_STRING_CONTROL_IDX].id;
  645. uvc_streaming_intf_alt0.iInterface = opts->vs0_index ?
  646. cdev->usb_strings[opts->vs0_index].id :
  647. us[UVC_STRING_STREAMING_IDX].id;
  648. uvc_streaming_intf_alt1.iInterface = opts->vs1_index ?
  649. cdev->usb_strings[opts->vs1_index].id :
  650. us[UVC_STRING_STREAMING_IDX].id;
  651. /* Allocate interface IDs. */
  652. if ((ret = usb_interface_id(c, f)) < 0)
  653. goto error;
  654. uvc_iad.bFirstInterface = ret;
  655. uvc_control_intf.bInterfaceNumber = ret;
  656. uvc->control_intf = ret;
  657. opts->control_interface = ret;
  658. if ((ret = usb_interface_id(c, f)) < 0)
  659. goto error;
  660. uvc_streaming_intf_alt0.bInterfaceNumber = ret;
  661. uvc_streaming_intf_alt1.bInterfaceNumber = ret;
  662. uvc->streaming_intf = ret;
  663. opts->streaming_interface = ret;
  664. /* Copy descriptors */
  665. f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL);
  666. if (IS_ERR(f->fs_descriptors)) {
  667. ret = PTR_ERR(f->fs_descriptors);
  668. f->fs_descriptors = NULL;
  669. goto error;
  670. }
  671. f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH);
  672. if (IS_ERR(f->hs_descriptors)) {
  673. ret = PTR_ERR(f->hs_descriptors);
  674. f->hs_descriptors = NULL;
  675. goto error;
  676. }
  677. f->ss_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER);
  678. if (IS_ERR(f->ss_descriptors)) {
  679. ret = PTR_ERR(f->ss_descriptors);
  680. f->ss_descriptors = NULL;
  681. goto error;
  682. }
  683. f->ssp_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER_PLUS);
  684. if (IS_ERR(f->ssp_descriptors)) {
  685. ret = PTR_ERR(f->ssp_descriptors);
  686. f->ssp_descriptors = NULL;
  687. goto error;
  688. }
  689. /* Preallocate control endpoint request. */
  690. uvc->control_req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
  691. uvc->control_buf = kmalloc(UVC_MAX_REQUEST_SIZE, GFP_KERNEL);
  692. if (uvc->control_req == NULL || uvc->control_buf == NULL) {
  693. ret = -ENOMEM;
  694. goto error;
  695. }
  696. uvc->control_req->buf = uvc->control_buf;
  697. uvc->control_req->complete = uvc_function_ep0_complete;
  698. uvc->control_req->context = uvc;
  699. if (v4l2_device_register(&cdev->gadget->dev, &uvc->v4l2_dev)) {
  700. uvcg_err(f, "failed to register V4L2 device\n");
  701. goto error;
  702. }
  703. /* Initialise video. */
  704. ret = uvcg_video_init(&uvc->video, uvc);
  705. if (ret < 0)
  706. goto v4l2_error;
  707. /* Register a V4L2 device. */
  708. ret = uvc_register_video(uvc);
  709. if (ret < 0) {
  710. uvcg_err(f, "failed to register video device\n");
  711. goto v4l2_error;
  712. }
  713. return 0;
  714. v4l2_error:
  715. v4l2_device_unregister(&uvc->v4l2_dev);
  716. error:
  717. if (uvc->control_req)
  718. usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
  719. kfree(uvc->control_buf);
  720. usb_free_all_descriptors(f);
  721. return ret;
  722. }
  723. /* --------------------------------------------------------------------------
  724. * USB gadget function
  725. */
  726. static void uvc_free_inst(struct usb_function_instance *f)
  727. {
  728. struct f_uvc_opts *opts = fi_to_f_uvc_opts(f);
  729. mutex_destroy(&opts->lock);
  730. kfree(opts);
  731. }
  732. static struct usb_function_instance *uvc_alloc_inst(void)
  733. {
  734. struct f_uvc_opts *opts;
  735. struct uvc_camera_terminal_descriptor *cd;
  736. struct uvc_processing_unit_descriptor *pd;
  737. struct uvc_output_terminal_descriptor *od;
  738. struct uvc_descriptor_header **ctl_cls;
  739. int ret;
  740. opts = kzalloc(sizeof(*opts), GFP_KERNEL);
  741. if (!opts)
  742. return ERR_PTR(-ENOMEM);
  743. opts->func_inst.free_func_inst = uvc_free_inst;
  744. mutex_init(&opts->lock);
  745. cd = &opts->uvc_camera_terminal;
  746. cd->bLength = UVC_DT_CAMERA_TERMINAL_SIZE(3);
  747. cd->bDescriptorType = USB_DT_CS_INTERFACE;
  748. cd->bDescriptorSubType = UVC_VC_INPUT_TERMINAL;
  749. cd->bTerminalID = 1;
  750. cd->wTerminalType = cpu_to_le16(0x0201);
  751. cd->bAssocTerminal = 0;
  752. cd->iTerminal = 0;
  753. cd->wObjectiveFocalLengthMin = cpu_to_le16(0);
  754. cd->wObjectiveFocalLengthMax = cpu_to_le16(0);
  755. cd->wOcularFocalLength = cpu_to_le16(0);
  756. cd->bControlSize = 3;
  757. cd->bmControls[0] = 2;
  758. cd->bmControls[1] = 0;
  759. cd->bmControls[2] = 0;
  760. pd = &opts->uvc_processing;
  761. pd->bLength = UVC_DT_PROCESSING_UNIT_SIZE(2);
  762. pd->bDescriptorType = USB_DT_CS_INTERFACE;
  763. pd->bDescriptorSubType = UVC_VC_PROCESSING_UNIT;
  764. pd->bUnitID = 2;
  765. pd->bSourceID = 1;
  766. pd->wMaxMultiplier = cpu_to_le16(16*1024);
  767. pd->bControlSize = 2;
  768. pd->bmControls[0] = 1;
  769. pd->bmControls[1] = 0;
  770. pd->iProcessing = 0;
  771. pd->bmVideoStandards = 0;
  772. od = &opts->uvc_output_terminal;
  773. od->bLength = UVC_DT_OUTPUT_TERMINAL_SIZE;
  774. od->bDescriptorType = USB_DT_CS_INTERFACE;
  775. od->bDescriptorSubType = UVC_VC_OUTPUT_TERMINAL;
  776. od->bTerminalID = 3;
  777. od->wTerminalType = cpu_to_le16(0x0101);
  778. od->bAssocTerminal = 0;
  779. od->bSourceID = 2;
  780. od->iTerminal = 0;
  781. /*
  782. * With the ability to add XUs to the UVC function graph, we need to be
  783. * able to allocate unique unit IDs to them. The IDs are 1-based, with
  784. * the CT, PU and OT above consuming the first 3.
  785. */
  786. opts->last_unit_id = 3;
  787. /* Prepare fs control class descriptors for configfs-based gadgets */
  788. ctl_cls = opts->uvc_fs_control_cls;
  789. ctl_cls[0] = NULL; /* assigned elsewhere by configfs */
  790. ctl_cls[1] = (struct uvc_descriptor_header *)cd;
  791. ctl_cls[2] = (struct uvc_descriptor_header *)pd;
  792. ctl_cls[3] = (struct uvc_descriptor_header *)od;
  793. ctl_cls[4] = NULL; /* NULL-terminate */
  794. opts->fs_control =
  795. (const struct uvc_descriptor_header * const *)ctl_cls;
  796. /* Prepare hs control class descriptors for configfs-based gadgets */
  797. ctl_cls = opts->uvc_ss_control_cls;
  798. ctl_cls[0] = NULL; /* assigned elsewhere by configfs */
  799. ctl_cls[1] = (struct uvc_descriptor_header *)cd;
  800. ctl_cls[2] = (struct uvc_descriptor_header *)pd;
  801. ctl_cls[3] = (struct uvc_descriptor_header *)od;
  802. ctl_cls[4] = NULL; /* NULL-terminate */
  803. opts->ss_control =
  804. (const struct uvc_descriptor_header * const *)ctl_cls;
  805. INIT_LIST_HEAD(&opts->extension_units);
  806. opts->streaming_interval = 1;
  807. opts->streaming_maxpacket = 1024;
  808. snprintf(opts->function_name, sizeof(opts->function_name), "UVC Camera");
  809. ret = uvcg_attach_configfs(opts);
  810. if (ret < 0) {
  811. kfree(opts);
  812. return ERR_PTR(ret);
  813. }
  814. return &opts->func_inst;
  815. }
  816. static void uvc_free(struct usb_function *f)
  817. {
  818. struct uvc_device *uvc = to_uvc(f);
  819. struct f_uvc_opts *opts = container_of(f->fi, struct f_uvc_opts,
  820. func_inst);
  821. if (!opts->header)
  822. config_item_put(&uvc->header->item);
  823. --opts->refcnt;
  824. kfree(uvc);
  825. }
  826. static void uvc_function_unbind(struct usb_configuration *c,
  827. struct usb_function *f)
  828. {
  829. struct usb_composite_dev *cdev = c->cdev;
  830. struct uvc_device *uvc = to_uvc(f);
  831. struct uvc_video *video = &uvc->video;
  832. long wait_ret = 1;
  833. uvcg_info(f, "%s()\n", __func__);
  834. if (video->async_wq)
  835. destroy_workqueue(video->async_wq);
  836. /*
  837. * If we know we're connected via v4l2, then there should be a cleanup
  838. * of the device from userspace either via UVC_EVENT_DISCONNECT or
  839. * though the video device removal uevent. Allow some time for the
  840. * application to close out before things get deleted.
  841. */
  842. if (uvc->func_connected) {
  843. uvcg_dbg(f, "waiting for clean disconnect\n");
  844. wait_ret = wait_event_interruptible_timeout(uvc->func_connected_queue,
  845. uvc->func_connected == false, msecs_to_jiffies(500));
  846. uvcg_dbg(f, "done waiting with ret: %ld\n", wait_ret);
  847. }
  848. device_remove_file(&uvc->vdev.dev, &dev_attr_function_name);
  849. video_unregister_device(&uvc->vdev);
  850. v4l2_device_unregister(&uvc->v4l2_dev);
  851. if (uvc->func_connected) {
  852. /*
  853. * Wait for the release to occur to ensure there are no longer any
  854. * pending operations that may cause panics when resources are cleaned
  855. * up.
  856. */
  857. uvcg_warn(f, "%s no clean disconnect, wait for release\n", __func__);
  858. wait_ret = wait_event_interruptible_timeout(uvc->func_connected_queue,
  859. uvc->func_connected == false, msecs_to_jiffies(1000));
  860. uvcg_dbg(f, "done waiting for release with ret: %ld\n", wait_ret);
  861. }
  862. usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
  863. kfree(uvc->control_buf);
  864. usb_free_all_descriptors(f);
  865. }
  866. static struct usb_function *uvc_alloc(struct usb_function_instance *fi)
  867. {
  868. struct uvc_device *uvc;
  869. struct f_uvc_opts *opts;
  870. struct uvc_descriptor_header **strm_cls;
  871. struct config_item *streaming, *header, *h;
  872. uvc = kzalloc(sizeof(*uvc), GFP_KERNEL);
  873. if (uvc == NULL)
  874. return ERR_PTR(-ENOMEM);
  875. mutex_init(&uvc->video.mutex);
  876. uvc->state = UVC_STATE_DISCONNECTED;
  877. init_waitqueue_head(&uvc->func_connected_queue);
  878. opts = fi_to_f_uvc_opts(fi);
  879. mutex_lock(&opts->lock);
  880. if (opts->uvc_fs_streaming_cls) {
  881. strm_cls = opts->uvc_fs_streaming_cls;
  882. opts->fs_streaming =
  883. (const struct uvc_descriptor_header * const *)strm_cls;
  884. }
  885. if (opts->uvc_hs_streaming_cls) {
  886. strm_cls = opts->uvc_hs_streaming_cls;
  887. opts->hs_streaming =
  888. (const struct uvc_descriptor_header * const *)strm_cls;
  889. }
  890. if (opts->uvc_ss_streaming_cls) {
  891. strm_cls = opts->uvc_ss_streaming_cls;
  892. opts->ss_streaming =
  893. (const struct uvc_descriptor_header * const *)strm_cls;
  894. }
  895. uvc->desc.fs_control = opts->fs_control;
  896. uvc->desc.ss_control = opts->ss_control;
  897. uvc->desc.fs_streaming = opts->fs_streaming;
  898. uvc->desc.hs_streaming = opts->hs_streaming;
  899. uvc->desc.ss_streaming = opts->ss_streaming;
  900. if (opts->header) {
  901. uvc->header = opts->header;
  902. } else {
  903. streaming = config_group_find_item(&opts->func_inst.group, "streaming");
  904. if (!streaming)
  905. goto err_config;
  906. header = config_group_find_item(to_config_group(streaming), "header");
  907. config_item_put(streaming);
  908. if (!header)
  909. goto err_config;
  910. h = config_group_find_item(to_config_group(header), "h");
  911. config_item_put(header);
  912. if (!h)
  913. goto err_config;
  914. uvc->header = to_uvcg_streaming_header(h);
  915. if (!uvc->header->linked) {
  916. mutex_unlock(&opts->lock);
  917. kfree(uvc);
  918. return ERR_PTR(-EBUSY);
  919. }
  920. }
  921. uvc->desc.extension_units = &opts->extension_units;
  922. ++opts->refcnt;
  923. mutex_unlock(&opts->lock);
  924. /* Register the function. */
  925. uvc->func.name = "uvc";
  926. uvc->func.bind = uvc_function_bind;
  927. uvc->func.unbind = uvc_function_unbind;
  928. uvc->func.get_alt = uvc_function_get_alt;
  929. uvc->func.set_alt = uvc_function_set_alt;
  930. uvc->func.disable = uvc_function_disable;
  931. uvc->func.setup = uvc_function_setup;
  932. uvc->func.free_func = uvc_free;
  933. uvc->func.bind_deactivated = true;
  934. return &uvc->func;
  935. err_config:
  936. mutex_unlock(&opts->lock);
  937. kfree(uvc);
  938. return ERR_PTR(-ENOENT);
  939. }
  940. DECLARE_USB_FUNCTION_INIT(uvc, uvc_alloc_inst, uvc_alloc);
  941. MODULE_DESCRIPTION("USB Video Class Gadget driver");
  942. MODULE_LICENSE("GPL");
  943. MODULE_AUTHOR("Laurent Pinchart");