uvc_driver.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  1. /*
  2. * uvc_driver.c -- USB Video Class driver
  3. *
  4. * Copyright (C) 2005-2009
  5. * Laurent Pinchart (laurent.pinchart@skynet.be)
  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. /*
  14. * This driver aims to support video input and ouput devices compliant with the
  15. * 'USB Video Class' specification.
  16. *
  17. * The driver doesn't support the deprecated v4l1 interface. It implements the
  18. * mmap capture method only, and doesn't do any image format conversion in
  19. * software. If your user-space application doesn't support YUYV or MJPEG, fix
  20. * it :-). Please note that the MJPEG data have been stripped from their
  21. * Huffman tables (DHT marker), you will need to add it back if your JPEG
  22. * codec can't handle MJPEG data.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/list.h>
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/usb.h>
  29. #include <linux/videodev2.h>
  30. #include <linux/vmalloc.h>
  31. #include <linux/wait.h>
  32. #include <asm/atomic.h>
  33. #include <asm/unaligned.h>
  34. #include <media/v4l2-common.h>
  35. #include "uvcvideo.h"
  36. #define DRIVER_AUTHOR "Laurent Pinchart <laurent.pinchart@skynet.be>"
  37. #define DRIVER_DESC "USB Video Class driver"
  38. #ifndef DRIVER_VERSION
  39. #define DRIVER_VERSION "v0.1.0"
  40. #endif
  41. unsigned int uvc_clock_param = CLOCK_MONOTONIC;
  42. unsigned int uvc_no_drop_param;
  43. static unsigned int uvc_quirks_param = -1;
  44. unsigned int uvc_trace_param;
  45. unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
  46. /* ------------------------------------------------------------------------
  47. * Video formats
  48. */
  49. static struct uvc_format_desc uvc_fmts[] = {
  50. {
  51. .name = "YUV 4:2:2 (YUYV)",
  52. .guid = UVC_GUID_FORMAT_YUY2,
  53. .fcc = V4L2_PIX_FMT_YUYV,
  54. },
  55. {
  56. .name = "YUV 4:2:2 (YUYV)",
  57. .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
  58. .fcc = V4L2_PIX_FMT_YUYV,
  59. },
  60. {
  61. .name = "YUV 4:2:0 (NV12)",
  62. .guid = UVC_GUID_FORMAT_NV12,
  63. .fcc = V4L2_PIX_FMT_NV12,
  64. },
  65. {
  66. .name = "MJPEG",
  67. .guid = UVC_GUID_FORMAT_MJPEG,
  68. .fcc = V4L2_PIX_FMT_MJPEG,
  69. },
  70. {
  71. .name = "YVU 4:2:0 (YV12)",
  72. .guid = UVC_GUID_FORMAT_YV12,
  73. .fcc = V4L2_PIX_FMT_YVU420,
  74. },
  75. {
  76. .name = "YUV 4:2:0 (I420)",
  77. .guid = UVC_GUID_FORMAT_I420,
  78. .fcc = V4L2_PIX_FMT_YUV420,
  79. },
  80. {
  81. .name = "YUV 4:2:2 (UYVY)",
  82. .guid = UVC_GUID_FORMAT_UYVY,
  83. .fcc = V4L2_PIX_FMT_UYVY,
  84. },
  85. {
  86. .name = "Greyscale (8-bit)",
  87. .guid = UVC_GUID_FORMAT_Y800,
  88. .fcc = V4L2_PIX_FMT_GREY,
  89. },
  90. {
  91. .name = "Greyscale (16-bit)",
  92. .guid = UVC_GUID_FORMAT_Y16,
  93. .fcc = V4L2_PIX_FMT_Y16,
  94. },
  95. {
  96. .name = "RGB Bayer",
  97. .guid = UVC_GUID_FORMAT_BY8,
  98. .fcc = V4L2_PIX_FMT_SBGGR8,
  99. },
  100. };
  101. /* ------------------------------------------------------------------------
  102. * Utility functions
  103. */
  104. struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
  105. __u8 epaddr)
  106. {
  107. struct usb_host_endpoint *ep;
  108. unsigned int i;
  109. for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
  110. ep = &alts->endpoint[i];
  111. if (ep->desc.bEndpointAddress == epaddr)
  112. return ep;
  113. }
  114. return NULL;
  115. }
  116. static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
  117. {
  118. unsigned int len = ARRAY_SIZE(uvc_fmts);
  119. unsigned int i;
  120. for (i = 0; i < len; ++i) {
  121. if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
  122. return &uvc_fmts[i];
  123. }
  124. return NULL;
  125. }
  126. static __u32 uvc_colorspace(const __u8 primaries)
  127. {
  128. static const __u8 colorprimaries[] = {
  129. 0,
  130. V4L2_COLORSPACE_SRGB,
  131. V4L2_COLORSPACE_470_SYSTEM_M,
  132. V4L2_COLORSPACE_470_SYSTEM_BG,
  133. V4L2_COLORSPACE_SMPTE170M,
  134. V4L2_COLORSPACE_SMPTE240M,
  135. };
  136. if (primaries < ARRAY_SIZE(colorprimaries))
  137. return colorprimaries[primaries];
  138. return 0;
  139. }
  140. /* Simplify a fraction using a simple continued fraction decomposition. The
  141. * idea here is to convert fractions such as 333333/10000000 to 1/30 using
  142. * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
  143. * arbitrary parameters to remove non-significative terms from the simple
  144. * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
  145. * respectively seems to give nice results.
  146. */
  147. void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
  148. unsigned int n_terms, unsigned int threshold)
  149. {
  150. uint32_t *an;
  151. uint32_t x, y, r;
  152. unsigned int i, n;
  153. an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
  154. if (an == NULL)
  155. return;
  156. /* Convert the fraction to a simple continued fraction. See
  157. * http://mathforum.org/dr.math/faq/faq.fractions.html
  158. * Stop if the current term is bigger than or equal to the given
  159. * threshold.
  160. */
  161. x = *numerator;
  162. y = *denominator;
  163. for (n = 0; n < n_terms && y != 0; ++n) {
  164. an[n] = x / y;
  165. if (an[n] >= threshold) {
  166. if (n < 2)
  167. n++;
  168. break;
  169. }
  170. r = x - an[n] * y;
  171. x = y;
  172. y = r;
  173. }
  174. /* Expand the simple continued fraction back to an integer fraction. */
  175. x = 0;
  176. y = 1;
  177. for (i = n; i > 0; --i) {
  178. r = y;
  179. y = an[i-1] * y + x;
  180. x = r;
  181. }
  182. *numerator = y;
  183. *denominator = x;
  184. kfree(an);
  185. }
  186. /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
  187. * to compute numerator / denominator * 10000000 using 32 bit fixed point
  188. * arithmetic only.
  189. */
  190. uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
  191. {
  192. uint32_t multiplier;
  193. /* Saturate the result if the operation would overflow. */
  194. if (denominator == 0 ||
  195. numerator/denominator >= ((uint32_t)-1)/10000000)
  196. return (uint32_t)-1;
  197. /* Divide both the denominator and the multiplier by two until
  198. * numerator * multiplier doesn't overflow. If anyone knows a better
  199. * algorithm please let me know.
  200. */
  201. multiplier = 10000000;
  202. while (numerator > ((uint32_t)-1)/multiplier) {
  203. multiplier /= 2;
  204. denominator /= 2;
  205. }
  206. return denominator ? numerator * multiplier / denominator : 0;
  207. }
  208. /* ------------------------------------------------------------------------
  209. * Terminal and unit management
  210. */
  211. static struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
  212. {
  213. struct uvc_entity *entity;
  214. list_for_each_entry(entity, &dev->entities, list) {
  215. if (entity->id == id)
  216. return entity;
  217. }
  218. return NULL;
  219. }
  220. static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
  221. int id, struct uvc_entity *entity)
  222. {
  223. unsigned int i;
  224. if (entity == NULL)
  225. entity = list_entry(&dev->entities, struct uvc_entity, list);
  226. list_for_each_entry_continue(entity, &dev->entities, list) {
  227. for (i = 0; i < entity->bNrInPins; ++i)
  228. if (entity->baSourceID[i] == id)
  229. return entity;
  230. }
  231. return NULL;
  232. }
  233. static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
  234. {
  235. struct uvc_streaming *stream;
  236. list_for_each_entry(stream, &dev->streams, list) {
  237. if (stream->header.bTerminalLink == id)
  238. return stream;
  239. }
  240. return NULL;
  241. }
  242. /* ------------------------------------------------------------------------
  243. * Descriptors parsing
  244. */
  245. static int uvc_parse_format(struct uvc_device *dev,
  246. struct uvc_streaming *streaming, struct uvc_format *format,
  247. __u32 **intervals, unsigned char *buffer, int buflen)
  248. {
  249. struct usb_interface *intf = streaming->intf;
  250. struct usb_host_interface *alts = intf->cur_altsetting;
  251. struct uvc_format_desc *fmtdesc;
  252. struct uvc_frame *frame;
  253. const unsigned char *start = buffer;
  254. unsigned int interval;
  255. unsigned int i, n;
  256. __u8 ftype;
  257. format->type = buffer[2];
  258. format->index = buffer[3];
  259. switch (buffer[2]) {
  260. case UVC_VS_FORMAT_UNCOMPRESSED:
  261. case UVC_VS_FORMAT_FRAME_BASED:
  262. n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
  263. if (buflen < n) {
  264. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  265. "interface %d FORMAT error\n",
  266. dev->udev->devnum,
  267. alts->desc.bInterfaceNumber);
  268. return -EINVAL;
  269. }
  270. /* Find the format descriptor from its GUID. */
  271. fmtdesc = uvc_format_by_guid(&buffer[5]);
  272. if (fmtdesc != NULL) {
  273. strlcpy(format->name, fmtdesc->name,
  274. sizeof format->name);
  275. format->fcc = fmtdesc->fcc;
  276. } else {
  277. uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
  278. &buffer[5]);
  279. snprintf(format->name, sizeof(format->name), "%pUl\n",
  280. &buffer[5]);
  281. format->fcc = 0;
  282. }
  283. format->bpp = buffer[21];
  284. if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
  285. ftype = UVC_VS_FRAME_UNCOMPRESSED;
  286. } else {
  287. ftype = UVC_VS_FRAME_FRAME_BASED;
  288. if (buffer[27])
  289. format->flags = UVC_FMT_FLAG_COMPRESSED;
  290. }
  291. break;
  292. case UVC_VS_FORMAT_MJPEG:
  293. if (buflen < 11) {
  294. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  295. "interface %d FORMAT error\n",
  296. dev->udev->devnum,
  297. alts->desc.bInterfaceNumber);
  298. return -EINVAL;
  299. }
  300. strlcpy(format->name, "MJPEG", sizeof format->name);
  301. format->fcc = V4L2_PIX_FMT_MJPEG;
  302. format->flags = UVC_FMT_FLAG_COMPRESSED;
  303. format->bpp = 0;
  304. ftype = UVC_VS_FRAME_MJPEG;
  305. break;
  306. case UVC_VS_FORMAT_DV:
  307. if (buflen < 9) {
  308. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  309. "interface %d FORMAT error\n",
  310. dev->udev->devnum,
  311. alts->desc.bInterfaceNumber);
  312. return -EINVAL;
  313. }
  314. switch (buffer[8] & 0x7f) {
  315. case 0:
  316. strlcpy(format->name, "SD-DV", sizeof format->name);
  317. break;
  318. case 1:
  319. strlcpy(format->name, "SDL-DV", sizeof format->name);
  320. break;
  321. case 2:
  322. strlcpy(format->name, "HD-DV", sizeof format->name);
  323. break;
  324. default:
  325. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  326. "interface %d: unknown DV format %u\n",
  327. dev->udev->devnum,
  328. alts->desc.bInterfaceNumber, buffer[8]);
  329. return -EINVAL;
  330. }
  331. strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
  332. sizeof format->name);
  333. format->fcc = V4L2_PIX_FMT_DV;
  334. format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
  335. format->bpp = 0;
  336. ftype = 0;
  337. /* Create a dummy frame descriptor. */
  338. frame = &format->frame[0];
  339. memset(&format->frame[0], 0, sizeof format->frame[0]);
  340. frame->bFrameIntervalType = 1;
  341. frame->dwDefaultFrameInterval = 1;
  342. frame->dwFrameInterval = *intervals;
  343. *(*intervals)++ = 1;
  344. format->nframes = 1;
  345. break;
  346. case UVC_VS_FORMAT_MPEG2TS:
  347. case UVC_VS_FORMAT_STREAM_BASED:
  348. /* Not supported yet. */
  349. default:
  350. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  351. "interface %d unsupported format %u\n",
  352. dev->udev->devnum, alts->desc.bInterfaceNumber,
  353. buffer[2]);
  354. return -EINVAL;
  355. }
  356. uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
  357. buflen -= buffer[0];
  358. buffer += buffer[0];
  359. /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
  360. * based formats have frame descriptors.
  361. */
  362. while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  363. buffer[2] == ftype) {
  364. frame = &format->frame[format->nframes];
  365. if (ftype != UVC_VS_FRAME_FRAME_BASED)
  366. n = buflen > 25 ? buffer[25] : 0;
  367. else
  368. n = buflen > 21 ? buffer[21] : 0;
  369. n = n ? n : 3;
  370. if (buflen < 26 + 4*n) {
  371. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  372. "interface %d FRAME error\n", dev->udev->devnum,
  373. alts->desc.bInterfaceNumber);
  374. return -EINVAL;
  375. }
  376. frame->bFrameIndex = buffer[3];
  377. frame->bmCapabilities = buffer[4];
  378. frame->wWidth = get_unaligned_le16(&buffer[5]);
  379. frame->wHeight = get_unaligned_le16(&buffer[7]);
  380. frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
  381. frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
  382. if (ftype != UVC_VS_FRAME_FRAME_BASED) {
  383. frame->dwMaxVideoFrameBufferSize =
  384. get_unaligned_le32(&buffer[17]);
  385. frame->dwDefaultFrameInterval =
  386. get_unaligned_le32(&buffer[21]);
  387. frame->bFrameIntervalType = buffer[25];
  388. } else {
  389. frame->dwMaxVideoFrameBufferSize = 0;
  390. frame->dwDefaultFrameInterval =
  391. get_unaligned_le32(&buffer[17]);
  392. frame->bFrameIntervalType = buffer[21];
  393. }
  394. frame->dwFrameInterval = *intervals;
  395. /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
  396. * completely. Observed behaviours range from setting the
  397. * value to 1.1x the actual frame size to hardwiring the
  398. * 16 low bits to 0. This results in a higher than necessary
  399. * memory usage as well as a wrong image size information. For
  400. * uncompressed formats this can be fixed by computing the
  401. * value from the frame size.
  402. */
  403. if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
  404. frame->dwMaxVideoFrameBufferSize = format->bpp
  405. * frame->wWidth * frame->wHeight / 8;
  406. /* Some bogus devices report dwMinFrameInterval equal to
  407. * dwMaxFrameInterval and have dwFrameIntervalStep set to
  408. * zero. Setting all null intervals to 1 fixes the problem and
  409. * some other divisions by zero that could happen.
  410. */
  411. for (i = 0; i < n; ++i) {
  412. interval = get_unaligned_le32(&buffer[26+4*i]);
  413. *(*intervals)++ = interval ? interval : 1;
  414. }
  415. /* Make sure that the default frame interval stays between
  416. * the boundaries.
  417. */
  418. n -= frame->bFrameIntervalType ? 1 : 2;
  419. frame->dwDefaultFrameInterval =
  420. min(frame->dwFrameInterval[n],
  421. max(frame->dwFrameInterval[0],
  422. frame->dwDefaultFrameInterval));
  423. if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
  424. frame->bFrameIntervalType = 1;
  425. frame->dwFrameInterval[0] =
  426. frame->dwDefaultFrameInterval;
  427. }
  428. uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
  429. frame->wWidth, frame->wHeight,
  430. 10000000/frame->dwDefaultFrameInterval,
  431. (100000000/frame->dwDefaultFrameInterval)%10);
  432. format->nframes++;
  433. buflen -= buffer[0];
  434. buffer += buffer[0];
  435. }
  436. if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  437. buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
  438. buflen -= buffer[0];
  439. buffer += buffer[0];
  440. }
  441. if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  442. buffer[2] == UVC_VS_COLORFORMAT) {
  443. if (buflen < 6) {
  444. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  445. "interface %d COLORFORMAT error\n",
  446. dev->udev->devnum,
  447. alts->desc.bInterfaceNumber);
  448. return -EINVAL;
  449. }
  450. format->colorspace = uvc_colorspace(buffer[3]);
  451. buflen -= buffer[0];
  452. buffer += buffer[0];
  453. }
  454. return buffer - start;
  455. }
  456. static int uvc_parse_streaming(struct uvc_device *dev,
  457. struct usb_interface *intf)
  458. {
  459. struct uvc_streaming *streaming = NULL;
  460. struct uvc_format *format;
  461. struct uvc_frame *frame;
  462. struct usb_host_interface *alts = &intf->altsetting[0];
  463. unsigned char *_buffer, *buffer = alts->extra;
  464. int _buflen, buflen = alts->extralen;
  465. unsigned int nformats = 0, nframes = 0, nintervals = 0;
  466. unsigned int size, i, n, p;
  467. __u32 *interval;
  468. __u16 psize;
  469. int ret = -EINVAL;
  470. if (intf->cur_altsetting->desc.bInterfaceSubClass
  471. != UVC_SC_VIDEOSTREAMING) {
  472. uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
  473. "video streaming interface\n", dev->udev->devnum,
  474. intf->altsetting[0].desc.bInterfaceNumber);
  475. return -EINVAL;
  476. }
  477. if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
  478. uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
  479. "claimed\n", dev->udev->devnum,
  480. intf->altsetting[0].desc.bInterfaceNumber);
  481. return -EINVAL;
  482. }
  483. streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
  484. if (streaming == NULL) {
  485. usb_driver_release_interface(&uvc_driver.driver, intf);
  486. return -EINVAL;
  487. }
  488. mutex_init(&streaming->mutex);
  489. streaming->dev = dev;
  490. streaming->intf = usb_get_intf(intf);
  491. streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  492. /* The Pico iMage webcam has its class-specific interface descriptors
  493. * after the endpoint descriptors.
  494. */
  495. if (buflen == 0) {
  496. for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
  497. struct usb_host_endpoint *ep = &alts->endpoint[i];
  498. if (ep->extralen == 0)
  499. continue;
  500. if (ep->extralen > 2 &&
  501. ep->extra[1] == USB_DT_CS_INTERFACE) {
  502. uvc_trace(UVC_TRACE_DESCR, "trying extra data "
  503. "from endpoint %u.\n", i);
  504. buffer = alts->endpoint[i].extra;
  505. buflen = alts->endpoint[i].extralen;
  506. break;
  507. }
  508. }
  509. }
  510. /* Skip the standard interface descriptors. */
  511. while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
  512. buflen -= buffer[0];
  513. buffer += buffer[0];
  514. }
  515. if (buflen <= 2) {
  516. uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
  517. "interface descriptors found.\n");
  518. goto error;
  519. }
  520. /* Parse the header descriptor. */
  521. switch (buffer[2]) {
  522. case UVC_VS_OUTPUT_HEADER:
  523. streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  524. size = 9;
  525. break;
  526. case UVC_VS_INPUT_HEADER:
  527. streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  528. size = 13;
  529. break;
  530. default:
  531. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
  532. "%d HEADER descriptor not found.\n", dev->udev->devnum,
  533. alts->desc.bInterfaceNumber);
  534. goto error;
  535. }
  536. p = buflen >= 4 ? buffer[3] : 0;
  537. n = buflen >= size ? buffer[size-1] : 0;
  538. if (buflen < size + p*n) {
  539. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  540. "interface %d HEADER descriptor is invalid.\n",
  541. dev->udev->devnum, alts->desc.bInterfaceNumber);
  542. goto error;
  543. }
  544. streaming->header.bNumFormats = p;
  545. streaming->header.bEndpointAddress = buffer[6];
  546. if (buffer[2] == UVC_VS_INPUT_HEADER) {
  547. streaming->header.bmInfo = buffer[7];
  548. streaming->header.bTerminalLink = buffer[8];
  549. streaming->header.bStillCaptureMethod = buffer[9];
  550. streaming->header.bTriggerSupport = buffer[10];
  551. streaming->header.bTriggerUsage = buffer[11];
  552. } else {
  553. streaming->header.bTerminalLink = buffer[7];
  554. }
  555. streaming->header.bControlSize = n;
  556. streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
  557. GFP_KERNEL);
  558. if (streaming->header.bmaControls == NULL) {
  559. ret = -ENOMEM;
  560. goto error;
  561. }
  562. buflen -= buffer[0];
  563. buffer += buffer[0];
  564. _buffer = buffer;
  565. _buflen = buflen;
  566. /* Count the format and frame descriptors. */
  567. while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
  568. switch (_buffer[2]) {
  569. case UVC_VS_FORMAT_UNCOMPRESSED:
  570. case UVC_VS_FORMAT_MJPEG:
  571. case UVC_VS_FORMAT_FRAME_BASED:
  572. nformats++;
  573. break;
  574. case UVC_VS_FORMAT_DV:
  575. /* DV format has no frame descriptor. We will create a
  576. * dummy frame descriptor with a dummy frame interval.
  577. */
  578. nformats++;
  579. nframes++;
  580. nintervals++;
  581. break;
  582. case UVC_VS_FORMAT_MPEG2TS:
  583. case UVC_VS_FORMAT_STREAM_BASED:
  584. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  585. "interface %d FORMAT %u is not supported.\n",
  586. dev->udev->devnum,
  587. alts->desc.bInterfaceNumber, _buffer[2]);
  588. break;
  589. case UVC_VS_FRAME_UNCOMPRESSED:
  590. case UVC_VS_FRAME_MJPEG:
  591. nframes++;
  592. if (_buflen > 25)
  593. nintervals += _buffer[25] ? _buffer[25] : 3;
  594. break;
  595. case UVC_VS_FRAME_FRAME_BASED:
  596. nframes++;
  597. if (_buflen > 21)
  598. nintervals += _buffer[21] ? _buffer[21] : 3;
  599. break;
  600. }
  601. _buflen -= _buffer[0];
  602. _buffer += _buffer[0];
  603. }
  604. if (nformats == 0) {
  605. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
  606. "%d has no supported formats defined.\n",
  607. dev->udev->devnum, alts->desc.bInterfaceNumber);
  608. goto error;
  609. }
  610. size = nformats * sizeof *format + nframes * sizeof *frame
  611. + nintervals * sizeof *interval;
  612. format = kzalloc(size, GFP_KERNEL);
  613. if (format == NULL) {
  614. ret = -ENOMEM;
  615. goto error;
  616. }
  617. frame = (struct uvc_frame *)&format[nformats];
  618. interval = (__u32 *)&frame[nframes];
  619. streaming->format = format;
  620. streaming->nformats = nformats;
  621. /* Parse the format descriptors. */
  622. while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
  623. switch (buffer[2]) {
  624. case UVC_VS_FORMAT_UNCOMPRESSED:
  625. case UVC_VS_FORMAT_MJPEG:
  626. case UVC_VS_FORMAT_DV:
  627. case UVC_VS_FORMAT_FRAME_BASED:
  628. format->frame = frame;
  629. ret = uvc_parse_format(dev, streaming, format,
  630. &interval, buffer, buflen);
  631. if (ret < 0)
  632. goto error;
  633. frame += format->nframes;
  634. format++;
  635. buflen -= ret;
  636. buffer += ret;
  637. continue;
  638. default:
  639. break;
  640. }
  641. buflen -= buffer[0];
  642. buffer += buffer[0];
  643. }
  644. if (buflen)
  645. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
  646. "%d has %u bytes of trailing descriptor garbage.\n",
  647. dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
  648. /* Parse the alternate settings to find the maximum bandwidth. */
  649. for (i = 0; i < intf->num_altsetting; ++i) {
  650. struct usb_host_endpoint *ep;
  651. alts = &intf->altsetting[i];
  652. ep = uvc_find_endpoint(alts,
  653. streaming->header.bEndpointAddress);
  654. if (ep == NULL)
  655. continue;
  656. psize = le16_to_cpu(ep->desc.wMaxPacketSize);
  657. psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
  658. if (psize > streaming->maxpsize)
  659. streaming->maxpsize = psize;
  660. }
  661. list_add_tail(&streaming->list, &dev->streams);
  662. return 0;
  663. error:
  664. usb_driver_release_interface(&uvc_driver.driver, intf);
  665. usb_put_intf(intf);
  666. kfree(streaming->format);
  667. kfree(streaming->header.bmaControls);
  668. kfree(streaming);
  669. return ret;
  670. }
  671. static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
  672. unsigned int num_pads, unsigned int extra_size)
  673. {
  674. struct uvc_entity *entity;
  675. unsigned int num_inputs;
  676. unsigned int size;
  677. num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
  678. size = sizeof(*entity) + extra_size + num_inputs;
  679. entity = kzalloc(size, GFP_KERNEL);
  680. if (entity == NULL)
  681. return NULL;
  682. entity->id = id;
  683. entity->type = type;
  684. entity->bNrInPins = num_inputs;
  685. entity->baSourceID = ((__u8 *)entity) + sizeof(*entity) + extra_size;
  686. return entity;
  687. }
  688. /* Parse vendor-specific extensions. */
  689. static int uvc_parse_vendor_control(struct uvc_device *dev,
  690. const unsigned char *buffer, int buflen)
  691. {
  692. struct usb_device *udev = dev->udev;
  693. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  694. struct uvc_entity *unit;
  695. unsigned int n, p;
  696. int handled = 0;
  697. switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
  698. case 0x046d: /* Logitech */
  699. if (buffer[1] != 0x41 || buffer[2] != 0x01)
  700. break;
  701. /* Logitech implements several vendor specific functions
  702. * through vendor specific extension units (LXU).
  703. *
  704. * The LXU descriptors are similar to XU descriptors
  705. * (see "USB Device Video Class for Video Devices", section
  706. * 3.7.2.6 "Extension Unit Descriptor") with the following
  707. * differences:
  708. *
  709. * ----------------------------------------------------------
  710. * 0 bLength 1 Number
  711. * Size of this descriptor, in bytes: 24+p+n*2
  712. * ----------------------------------------------------------
  713. * 23+p+n bmControlsType N Bitmap
  714. * Individual bits in the set are defined:
  715. * 0: Absolute
  716. * 1: Relative
  717. *
  718. * This bitset is mapped exactly the same as bmControls.
  719. * ----------------------------------------------------------
  720. * 23+p+n*2 bReserved 1 Boolean
  721. * ----------------------------------------------------------
  722. * 24+p+n*2 iExtension 1 Index
  723. * Index of a string descriptor that describes this
  724. * extension unit.
  725. * ----------------------------------------------------------
  726. */
  727. p = buflen >= 22 ? buffer[21] : 0;
  728. n = buflen >= 25 + p ? buffer[22+p] : 0;
  729. if (buflen < 25 + p + 2*n) {
  730. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  731. "interface %d EXTENSION_UNIT error\n",
  732. udev->devnum, alts->desc.bInterfaceNumber);
  733. break;
  734. }
  735. unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
  736. p + 1, 2*n);
  737. if (unit == NULL)
  738. return -ENOMEM;
  739. memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
  740. unit->extension.bNumControls = buffer[20];
  741. memcpy(unit->baSourceID, &buffer[22], p);
  742. unit->extension.bControlSize = buffer[22+p];
  743. unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
  744. unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
  745. + n;
  746. memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
  747. if (buffer[24+p+2*n] != 0)
  748. usb_string(udev, buffer[24+p+2*n], unit->name,
  749. sizeof unit->name);
  750. else
  751. sprintf(unit->name, "Extension %u", buffer[3]);
  752. list_add_tail(&unit->list, &dev->entities);
  753. handled = 1;
  754. break;
  755. }
  756. return handled;
  757. }
  758. static int uvc_parse_standard_control(struct uvc_device *dev,
  759. const unsigned char *buffer, int buflen)
  760. {
  761. struct usb_device *udev = dev->udev;
  762. struct uvc_entity *unit, *term;
  763. struct usb_interface *intf;
  764. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  765. unsigned int i, n, p, len;
  766. __u16 type;
  767. switch (buffer[2]) {
  768. case UVC_VC_HEADER:
  769. n = buflen >= 12 ? buffer[11] : 0;
  770. if (buflen < 12 || buflen < 12 + n) {
  771. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  772. "interface %d HEADER error\n", udev->devnum,
  773. alts->desc.bInterfaceNumber);
  774. return -EINVAL;
  775. }
  776. dev->uvc_version = get_unaligned_le16(&buffer[3]);
  777. dev->clock_frequency = get_unaligned_le32(&buffer[7]);
  778. /* Parse all USB Video Streaming interfaces. */
  779. for (i = 0; i < n; ++i) {
  780. intf = usb_ifnum_to_if(udev, buffer[12+i]);
  781. if (intf == NULL) {
  782. uvc_trace(UVC_TRACE_DESCR, "device %d "
  783. "interface %d doesn't exists\n",
  784. udev->devnum, i);
  785. continue;
  786. }
  787. uvc_parse_streaming(dev, intf);
  788. }
  789. break;
  790. case UVC_VC_INPUT_TERMINAL:
  791. if (buflen < 8) {
  792. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  793. "interface %d INPUT_TERMINAL error\n",
  794. udev->devnum, alts->desc.bInterfaceNumber);
  795. return -EINVAL;
  796. }
  797. /* Make sure the terminal type MSB is not null, otherwise it
  798. * could be confused with a unit.
  799. */
  800. type = get_unaligned_le16(&buffer[4]);
  801. if ((type & 0xff00) == 0) {
  802. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  803. "interface %d INPUT_TERMINAL %d has invalid "
  804. "type 0x%04x, skipping\n", udev->devnum,
  805. alts->desc.bInterfaceNumber,
  806. buffer[3], type);
  807. return 0;
  808. }
  809. n = 0;
  810. p = 0;
  811. len = 8;
  812. if (type == UVC_ITT_CAMERA) {
  813. n = buflen >= 15 ? buffer[14] : 0;
  814. len = 15;
  815. } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
  816. n = buflen >= 9 ? buffer[8] : 0;
  817. p = buflen >= 10 + n ? buffer[9+n] : 0;
  818. len = 10;
  819. }
  820. if (buflen < len + n + p) {
  821. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  822. "interface %d INPUT_TERMINAL error\n",
  823. udev->devnum, alts->desc.bInterfaceNumber);
  824. return -EINVAL;
  825. }
  826. term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
  827. 1, n + p);
  828. if (term == NULL)
  829. return -ENOMEM;
  830. if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
  831. term->camera.bControlSize = n;
  832. term->camera.bmControls = (__u8 *)term + sizeof *term;
  833. term->camera.wObjectiveFocalLengthMin =
  834. get_unaligned_le16(&buffer[8]);
  835. term->camera.wObjectiveFocalLengthMax =
  836. get_unaligned_le16(&buffer[10]);
  837. term->camera.wOcularFocalLength =
  838. get_unaligned_le16(&buffer[12]);
  839. memcpy(term->camera.bmControls, &buffer[15], n);
  840. } else if (UVC_ENTITY_TYPE(term) ==
  841. UVC_ITT_MEDIA_TRANSPORT_INPUT) {
  842. term->media.bControlSize = n;
  843. term->media.bmControls = (__u8 *)term + sizeof *term;
  844. term->media.bTransportModeSize = p;
  845. term->media.bmTransportModes = (__u8 *)term
  846. + sizeof *term + n;
  847. memcpy(term->media.bmControls, &buffer[9], n);
  848. memcpy(term->media.bmTransportModes, &buffer[10+n], p);
  849. }
  850. if (buffer[7] != 0)
  851. usb_string(udev, buffer[7], term->name,
  852. sizeof term->name);
  853. else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
  854. sprintf(term->name, "Camera %u", buffer[3]);
  855. else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
  856. sprintf(term->name, "Media %u", buffer[3]);
  857. else
  858. sprintf(term->name, "Input %u", buffer[3]);
  859. list_add_tail(&term->list, &dev->entities);
  860. break;
  861. case UVC_VC_OUTPUT_TERMINAL:
  862. if (buflen < 9) {
  863. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  864. "interface %d OUTPUT_TERMINAL error\n",
  865. udev->devnum, alts->desc.bInterfaceNumber);
  866. return -EINVAL;
  867. }
  868. /* Make sure the terminal type MSB is not null, otherwise it
  869. * could be confused with a unit.
  870. */
  871. type = get_unaligned_le16(&buffer[4]);
  872. if ((type & 0xff00) == 0) {
  873. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  874. "interface %d OUTPUT_TERMINAL %d has invalid "
  875. "type 0x%04x, skipping\n", udev->devnum,
  876. alts->desc.bInterfaceNumber, buffer[3], type);
  877. return 0;
  878. }
  879. term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
  880. 1, 0);
  881. if (term == NULL)
  882. return -ENOMEM;
  883. memcpy(term->baSourceID, &buffer[7], 1);
  884. if (buffer[8] != 0)
  885. usb_string(udev, buffer[8], term->name,
  886. sizeof term->name);
  887. else
  888. sprintf(term->name, "Output %u", buffer[3]);
  889. list_add_tail(&term->list, &dev->entities);
  890. break;
  891. case UVC_VC_SELECTOR_UNIT:
  892. p = buflen >= 5 ? buffer[4] : 0;
  893. if (buflen < 5 || buflen < 6 + p) {
  894. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  895. "interface %d SELECTOR_UNIT error\n",
  896. udev->devnum, alts->desc.bInterfaceNumber);
  897. return -EINVAL;
  898. }
  899. unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
  900. if (unit == NULL)
  901. return -ENOMEM;
  902. memcpy(unit->baSourceID, &buffer[5], p);
  903. if (buffer[5+p] != 0)
  904. usb_string(udev, buffer[5+p], unit->name,
  905. sizeof unit->name);
  906. else
  907. sprintf(unit->name, "Selector %u", buffer[3]);
  908. list_add_tail(&unit->list, &dev->entities);
  909. break;
  910. case UVC_VC_PROCESSING_UNIT:
  911. n = buflen >= 8 ? buffer[7] : 0;
  912. p = dev->uvc_version >= 0x0110 ? 10 : 9;
  913. if (buflen < p + n) {
  914. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  915. "interface %d PROCESSING_UNIT error\n",
  916. udev->devnum, alts->desc.bInterfaceNumber);
  917. return -EINVAL;
  918. }
  919. unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
  920. if (unit == NULL)
  921. return -ENOMEM;
  922. memcpy(unit->baSourceID, &buffer[4], 1);
  923. unit->processing.wMaxMultiplier =
  924. get_unaligned_le16(&buffer[5]);
  925. unit->processing.bControlSize = buffer[7];
  926. unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
  927. memcpy(unit->processing.bmControls, &buffer[8], n);
  928. if (dev->uvc_version >= 0x0110)
  929. unit->processing.bmVideoStandards = buffer[9+n];
  930. if (buffer[8+n] != 0)
  931. usb_string(udev, buffer[8+n], unit->name,
  932. sizeof unit->name);
  933. else
  934. sprintf(unit->name, "Processing %u", buffer[3]);
  935. list_add_tail(&unit->list, &dev->entities);
  936. break;
  937. case UVC_VC_EXTENSION_UNIT:
  938. p = buflen >= 22 ? buffer[21] : 0;
  939. n = buflen >= 24 + p ? buffer[22+p] : 0;
  940. if (buflen < 24 + p + n) {
  941. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  942. "interface %d EXTENSION_UNIT error\n",
  943. udev->devnum, alts->desc.bInterfaceNumber);
  944. return -EINVAL;
  945. }
  946. unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
  947. if (unit == NULL)
  948. return -ENOMEM;
  949. memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
  950. unit->extension.bNumControls = buffer[20];
  951. memcpy(unit->baSourceID, &buffer[22], p);
  952. unit->extension.bControlSize = buffer[22+p];
  953. unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
  954. memcpy(unit->extension.bmControls, &buffer[23+p], n);
  955. if (buffer[23+p+n] != 0)
  956. usb_string(udev, buffer[23+p+n], unit->name,
  957. sizeof unit->name);
  958. else
  959. sprintf(unit->name, "Extension %u", buffer[3]);
  960. list_add_tail(&unit->list, &dev->entities);
  961. break;
  962. default:
  963. uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
  964. "descriptor (%u)\n", buffer[2]);
  965. break;
  966. }
  967. return 0;
  968. }
  969. static int uvc_parse_control(struct uvc_device *dev)
  970. {
  971. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  972. unsigned char *buffer = alts->extra;
  973. int buflen = alts->extralen;
  974. int ret;
  975. /* Parse the default alternate setting only, as the UVC specification
  976. * defines a single alternate setting, the default alternate setting
  977. * zero.
  978. */
  979. while (buflen > 2) {
  980. if (uvc_parse_vendor_control(dev, buffer, buflen) ||
  981. buffer[1] != USB_DT_CS_INTERFACE)
  982. goto next_descriptor;
  983. if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
  984. return ret;
  985. next_descriptor:
  986. buflen -= buffer[0];
  987. buffer += buffer[0];
  988. }
  989. /* Check if the optional status endpoint is present. Built-in iSight
  990. * webcams have an interrupt endpoint but spit proprietary data that
  991. * don't conform to the UVC status endpoint messages. Don't try to
  992. * handle the interrupt endpoint for those cameras.
  993. */
  994. if (alts->desc.bNumEndpoints == 1 &&
  995. !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
  996. struct usb_host_endpoint *ep = &alts->endpoint[0];
  997. struct usb_endpoint_descriptor *desc = &ep->desc;
  998. if (usb_endpoint_is_int_in(desc) &&
  999. le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
  1000. desc->bInterval != 0) {
  1001. uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
  1002. "(addr %02x).\n", desc->bEndpointAddress);
  1003. dev->int_ep = ep;
  1004. }
  1005. }
  1006. return 0;
  1007. }
  1008. /* ------------------------------------------------------------------------
  1009. * UVC device scan
  1010. */
  1011. /*
  1012. * Scan the UVC descriptors to locate a chain starting at an Output Terminal
  1013. * and containing the following units:
  1014. *
  1015. * - one or more Output Terminals (USB Streaming or Display)
  1016. * - zero or one Processing Unit
  1017. * - zero, one or more single-input Selector Units
  1018. * - zero or one multiple-input Selector Units, provided all inputs are
  1019. * connected to input terminals
  1020. * - zero, one or mode single-input Extension Units
  1021. * - one or more Input Terminals (Camera, External or USB Streaming)
  1022. *
  1023. * The terminal and units must match on of the following structures:
  1024. *
  1025. * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
  1026. * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
  1027. * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
  1028. *
  1029. * +---------+ +---------+ -> OTT_*(0)
  1030. * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
  1031. * +---------+ +---------+ -> OTT_*(n)
  1032. *
  1033. * The Processing Unit and Extension Units can be in any order. Additional
  1034. * Extension Units connected to the main chain as single-unit branches are
  1035. * also supported. Single-input Selector Units are ignored.
  1036. */
  1037. static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
  1038. struct uvc_entity *entity)
  1039. {
  1040. switch (UVC_ENTITY_TYPE(entity)) {
  1041. case UVC_VC_EXTENSION_UNIT:
  1042. if (uvc_trace_param & UVC_TRACE_PROBE)
  1043. printk(" <- XU %d", entity->id);
  1044. if (entity->bNrInPins != 1) {
  1045. uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
  1046. "than 1 input pin.\n", entity->id);
  1047. return -1;
  1048. }
  1049. break;
  1050. case UVC_VC_PROCESSING_UNIT:
  1051. if (uvc_trace_param & UVC_TRACE_PROBE)
  1052. printk(" <- PU %d", entity->id);
  1053. if (chain->processing != NULL) {
  1054. uvc_trace(UVC_TRACE_DESCR, "Found multiple "
  1055. "Processing Units in chain.\n");
  1056. return -1;
  1057. }
  1058. chain->processing = entity;
  1059. break;
  1060. case UVC_VC_SELECTOR_UNIT:
  1061. if (uvc_trace_param & UVC_TRACE_PROBE)
  1062. printk(" <- SU %d", entity->id);
  1063. /* Single-input selector units are ignored. */
  1064. if (entity->bNrInPins == 1)
  1065. break;
  1066. if (chain->selector != NULL) {
  1067. uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
  1068. "Units in chain.\n");
  1069. return -1;
  1070. }
  1071. chain->selector = entity;
  1072. break;
  1073. case UVC_ITT_VENDOR_SPECIFIC:
  1074. case UVC_ITT_CAMERA:
  1075. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  1076. if (uvc_trace_param & UVC_TRACE_PROBE)
  1077. printk(" <- IT %d\n", entity->id);
  1078. break;
  1079. case UVC_TT_STREAMING:
  1080. if (UVC_ENTITY_IS_ITERM(entity)) {
  1081. if (uvc_trace_param & UVC_TRACE_PROBE)
  1082. printk(" <- IT %d\n", entity->id);
  1083. } else {
  1084. if (uvc_trace_param & UVC_TRACE_PROBE)
  1085. printk(" OT %d", entity->id);
  1086. }
  1087. break;
  1088. default:
  1089. uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
  1090. "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
  1091. return -1;
  1092. }
  1093. list_add_tail(&entity->chain, &chain->entities);
  1094. return 0;
  1095. }
  1096. static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
  1097. struct uvc_entity *entity, struct uvc_entity *prev)
  1098. {
  1099. struct uvc_entity *forward;
  1100. int found;
  1101. /* Forward scan */
  1102. forward = NULL;
  1103. found = 0;
  1104. while (1) {
  1105. forward = uvc_entity_by_reference(chain->dev, entity->id,
  1106. forward);
  1107. if (forward == NULL)
  1108. break;
  1109. if (forward == prev)
  1110. continue;
  1111. switch (UVC_ENTITY_TYPE(forward)) {
  1112. case UVC_VC_EXTENSION_UNIT:
  1113. if (forward->bNrInPins != 1) {
  1114. uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
  1115. "has more than 1 input pin.\n",
  1116. entity->id);
  1117. return -EINVAL;
  1118. }
  1119. list_add_tail(&forward->chain, &chain->entities);
  1120. if (uvc_trace_param & UVC_TRACE_PROBE) {
  1121. if (!found)
  1122. printk(" (->");
  1123. printk(" XU %d", forward->id);
  1124. found = 1;
  1125. }
  1126. break;
  1127. case UVC_OTT_VENDOR_SPECIFIC:
  1128. case UVC_OTT_DISPLAY:
  1129. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1130. case UVC_TT_STREAMING:
  1131. if (UVC_ENTITY_IS_ITERM(forward)) {
  1132. uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
  1133. "terminal %u.\n", forward->id);
  1134. return -EINVAL;
  1135. }
  1136. list_add_tail(&forward->chain, &chain->entities);
  1137. if (uvc_trace_param & UVC_TRACE_PROBE) {
  1138. if (!found)
  1139. printk(" (->");
  1140. printk(" OT %d", forward->id);
  1141. found = 1;
  1142. }
  1143. break;
  1144. }
  1145. }
  1146. if (found)
  1147. printk(")");
  1148. return 0;
  1149. }
  1150. static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
  1151. struct uvc_entity **_entity)
  1152. {
  1153. struct uvc_entity *entity = *_entity;
  1154. struct uvc_entity *term;
  1155. int id = -EINVAL, i;
  1156. switch (UVC_ENTITY_TYPE(entity)) {
  1157. case UVC_VC_EXTENSION_UNIT:
  1158. case UVC_VC_PROCESSING_UNIT:
  1159. id = entity->baSourceID[0];
  1160. break;
  1161. case UVC_VC_SELECTOR_UNIT:
  1162. /* Single-input selector units are ignored. */
  1163. if (entity->bNrInPins == 1) {
  1164. id = entity->baSourceID[0];
  1165. break;
  1166. }
  1167. if (uvc_trace_param & UVC_TRACE_PROBE)
  1168. printk(" <- IT");
  1169. chain->selector = entity;
  1170. for (i = 0; i < entity->bNrInPins; ++i) {
  1171. id = entity->baSourceID[i];
  1172. term = uvc_entity_by_id(chain->dev, id);
  1173. if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
  1174. uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
  1175. "input %d isn't connected to an "
  1176. "input terminal\n", entity->id, i);
  1177. return -1;
  1178. }
  1179. if (uvc_trace_param & UVC_TRACE_PROBE)
  1180. printk(" %d", term->id);
  1181. list_add_tail(&term->chain, &chain->entities);
  1182. uvc_scan_chain_forward(chain, term, entity);
  1183. }
  1184. if (uvc_trace_param & UVC_TRACE_PROBE)
  1185. printk("\n");
  1186. id = 0;
  1187. break;
  1188. case UVC_ITT_VENDOR_SPECIFIC:
  1189. case UVC_ITT_CAMERA:
  1190. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  1191. case UVC_OTT_VENDOR_SPECIFIC:
  1192. case UVC_OTT_DISPLAY:
  1193. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1194. case UVC_TT_STREAMING:
  1195. id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
  1196. break;
  1197. }
  1198. if (id <= 0) {
  1199. *_entity = NULL;
  1200. return id;
  1201. }
  1202. entity = uvc_entity_by_id(chain->dev, id);
  1203. if (entity == NULL) {
  1204. uvc_trace(UVC_TRACE_DESCR, "Found reference to "
  1205. "unknown entity %d.\n", id);
  1206. return -EINVAL;
  1207. }
  1208. *_entity = entity;
  1209. return 0;
  1210. }
  1211. static int uvc_scan_chain(struct uvc_video_chain *chain,
  1212. struct uvc_entity *term)
  1213. {
  1214. struct uvc_entity *entity, *prev;
  1215. uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
  1216. entity = term;
  1217. prev = NULL;
  1218. while (entity != NULL) {
  1219. /* Entity must not be part of an existing chain */
  1220. if (entity->chain.next || entity->chain.prev) {
  1221. uvc_trace(UVC_TRACE_DESCR, "Found reference to "
  1222. "entity %d already in chain.\n", entity->id);
  1223. return -EINVAL;
  1224. }
  1225. /* Process entity */
  1226. if (uvc_scan_chain_entity(chain, entity) < 0)
  1227. return -EINVAL;
  1228. /* Forward scan */
  1229. if (uvc_scan_chain_forward(chain, entity, prev) < 0)
  1230. return -EINVAL;
  1231. /* Backward scan */
  1232. prev = entity;
  1233. if (uvc_scan_chain_backward(chain, &entity) < 0)
  1234. return -EINVAL;
  1235. }
  1236. return 0;
  1237. }
  1238. static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
  1239. char *buffer)
  1240. {
  1241. struct uvc_entity *term;
  1242. unsigned int nterms = 0;
  1243. char *p = buffer;
  1244. list_for_each_entry(term, terms, chain) {
  1245. if (!UVC_ENTITY_IS_TERM(term) ||
  1246. UVC_TERM_DIRECTION(term) != dir)
  1247. continue;
  1248. if (nterms)
  1249. p += sprintf(p, ",");
  1250. if (++nterms >= 4) {
  1251. p += sprintf(p, "...");
  1252. break;
  1253. }
  1254. p += sprintf(p, "%u", term->id);
  1255. }
  1256. return p - buffer;
  1257. }
  1258. static const char *uvc_print_chain(struct uvc_video_chain *chain)
  1259. {
  1260. static char buffer[43];
  1261. char *p = buffer;
  1262. p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
  1263. p += sprintf(p, " -> ");
  1264. uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
  1265. return buffer;
  1266. }
  1267. /*
  1268. * Scan the device for video chains and register video devices.
  1269. *
  1270. * Chains are scanned starting at their output terminals and walked backwards.
  1271. */
  1272. static int uvc_scan_device(struct uvc_device *dev)
  1273. {
  1274. struct uvc_video_chain *chain;
  1275. struct uvc_entity *term;
  1276. list_for_each_entry(term, &dev->entities, list) {
  1277. if (!UVC_ENTITY_IS_OTERM(term))
  1278. continue;
  1279. /* If the terminal is already included in a chain, skip it.
  1280. * This can happen for chains that have multiple output
  1281. * terminals, where all output terminals beside the first one
  1282. * will be inserted in the chain in forward scans.
  1283. */
  1284. if (term->chain.next || term->chain.prev)
  1285. continue;
  1286. chain = kzalloc(sizeof(*chain), GFP_KERNEL);
  1287. if (chain == NULL)
  1288. return -ENOMEM;
  1289. INIT_LIST_HEAD(&chain->entities);
  1290. mutex_init(&chain->ctrl_mutex);
  1291. chain->dev = dev;
  1292. if (uvc_scan_chain(chain, term) < 0) {
  1293. kfree(chain);
  1294. continue;
  1295. }
  1296. uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
  1297. uvc_print_chain(chain));
  1298. list_add_tail(&chain->list, &dev->chains);
  1299. }
  1300. if (list_empty(&dev->chains)) {
  1301. uvc_printk(KERN_INFO, "No valid video chain found.\n");
  1302. return -1;
  1303. }
  1304. return 0;
  1305. }
  1306. /* ------------------------------------------------------------------------
  1307. * Video device registration and unregistration
  1308. */
  1309. /*
  1310. * Delete the UVC device.
  1311. *
  1312. * Called by the kernel when the last reference to the uvc_device structure
  1313. * is released.
  1314. *
  1315. * As this function is called after or during disconnect(), all URBs have
  1316. * already been canceled by the USB core. There is no need to kill the
  1317. * interrupt URB manually.
  1318. */
  1319. static void uvc_delete(struct uvc_device *dev)
  1320. {
  1321. struct list_head *p, *n;
  1322. usb_put_intf(dev->intf);
  1323. usb_put_dev(dev->udev);
  1324. uvc_status_cleanup(dev);
  1325. uvc_ctrl_cleanup_device(dev);
  1326. list_for_each_safe(p, n, &dev->chains) {
  1327. struct uvc_video_chain *chain;
  1328. chain = list_entry(p, struct uvc_video_chain, list);
  1329. kfree(chain);
  1330. }
  1331. list_for_each_safe(p, n, &dev->entities) {
  1332. struct uvc_entity *entity;
  1333. entity = list_entry(p, struct uvc_entity, list);
  1334. kfree(entity);
  1335. }
  1336. list_for_each_safe(p, n, &dev->streams) {
  1337. struct uvc_streaming *streaming;
  1338. streaming = list_entry(p, struct uvc_streaming, list);
  1339. usb_driver_release_interface(&uvc_driver.driver,
  1340. streaming->intf);
  1341. usb_put_intf(streaming->intf);
  1342. kfree(streaming->format);
  1343. kfree(streaming->header.bmaControls);
  1344. kfree(streaming);
  1345. }
  1346. kfree(dev);
  1347. }
  1348. static void uvc_release(struct video_device *vdev)
  1349. {
  1350. struct uvc_streaming *stream = video_get_drvdata(vdev);
  1351. struct uvc_device *dev = stream->dev;
  1352. video_device_release(vdev);
  1353. /* Decrement the registered streams count and delete the device when it
  1354. * reaches zero.
  1355. */
  1356. if (atomic_dec_and_test(&dev->nstreams))
  1357. uvc_delete(dev);
  1358. }
  1359. /*
  1360. * Unregister the video devices.
  1361. */
  1362. static void uvc_unregister_video(struct uvc_device *dev)
  1363. {
  1364. struct uvc_streaming *stream;
  1365. /* Unregistering all video devices might result in uvc_delete() being
  1366. * called from inside the loop if there's no open file handle. To avoid
  1367. * that, increment the stream count before iterating over the streams
  1368. * and decrement it when done.
  1369. */
  1370. atomic_inc(&dev->nstreams);
  1371. list_for_each_entry(stream, &dev->streams, list) {
  1372. if (stream->vdev == NULL)
  1373. continue;
  1374. video_unregister_device(stream->vdev);
  1375. stream->vdev = NULL;
  1376. }
  1377. /* Decrement the stream count and call uvc_delete explicitly if there
  1378. * are no stream left.
  1379. */
  1380. if (atomic_dec_and_test(&dev->nstreams))
  1381. uvc_delete(dev);
  1382. }
  1383. static int uvc_register_video(struct uvc_device *dev,
  1384. struct uvc_streaming *stream)
  1385. {
  1386. struct video_device *vdev;
  1387. int ret;
  1388. /* Initialize the streaming interface with default streaming
  1389. * parameters.
  1390. */
  1391. ret = uvc_video_init(stream);
  1392. if (ret < 0) {
  1393. uvc_printk(KERN_ERR, "Failed to initialize the device "
  1394. "(%d).\n", ret);
  1395. return ret;
  1396. }
  1397. /* Register the device with V4L. */
  1398. vdev = video_device_alloc();
  1399. if (vdev == NULL) {
  1400. uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
  1401. ret);
  1402. return -ENOMEM;
  1403. }
  1404. /* We already hold a reference to dev->udev. The video device will be
  1405. * unregistered before the reference is released, so we don't need to
  1406. * get another one.
  1407. */
  1408. vdev->parent = &dev->intf->dev;
  1409. vdev->fops = &uvc_fops;
  1410. vdev->release = uvc_release;
  1411. strlcpy(vdev->name, dev->name, sizeof vdev->name);
  1412. /* Set the driver data before calling video_register_device, otherwise
  1413. * uvc_v4l2_open might race us.
  1414. */
  1415. stream->vdev = vdev;
  1416. video_set_drvdata(vdev, stream);
  1417. ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
  1418. if (ret < 0) {
  1419. uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
  1420. ret);
  1421. stream->vdev = NULL;
  1422. video_device_release(vdev);
  1423. return ret;
  1424. }
  1425. atomic_inc(&dev->nstreams);
  1426. return 0;
  1427. }
  1428. /*
  1429. * Register all video devices in all chains.
  1430. */
  1431. static int uvc_register_terms(struct uvc_device *dev,
  1432. struct uvc_video_chain *chain)
  1433. {
  1434. struct uvc_streaming *stream;
  1435. struct uvc_entity *term;
  1436. int ret;
  1437. list_for_each_entry(term, &chain->entities, chain) {
  1438. if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
  1439. continue;
  1440. stream = uvc_stream_by_id(dev, term->id);
  1441. if (stream == NULL) {
  1442. uvc_printk(KERN_INFO, "No streaming interface found "
  1443. "for terminal %u.", term->id);
  1444. continue;
  1445. }
  1446. stream->chain = chain;
  1447. ret = uvc_register_video(dev, stream);
  1448. if (ret < 0)
  1449. return ret;
  1450. }
  1451. return 0;
  1452. }
  1453. static int uvc_register_chains(struct uvc_device *dev)
  1454. {
  1455. struct uvc_video_chain *chain;
  1456. int ret;
  1457. list_for_each_entry(chain, &dev->chains, list) {
  1458. ret = uvc_register_terms(dev, chain);
  1459. if (ret < 0)
  1460. return ret;
  1461. }
  1462. return 0;
  1463. }
  1464. /* ------------------------------------------------------------------------
  1465. * USB probe, disconnect, suspend and resume
  1466. */
  1467. static int uvc_probe(struct usb_interface *intf,
  1468. const struct usb_device_id *id)
  1469. {
  1470. struct usb_device *udev = interface_to_usbdev(intf);
  1471. struct uvc_device *dev;
  1472. int ret;
  1473. if (id->idVendor && id->idProduct)
  1474. uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
  1475. "(%04x:%04x)\n", udev->devpath, id->idVendor,
  1476. id->idProduct);
  1477. else
  1478. uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
  1479. udev->devpath);
  1480. /* Allocate memory for the device and initialize it. */
  1481. if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
  1482. return -ENOMEM;
  1483. INIT_LIST_HEAD(&dev->entities);
  1484. INIT_LIST_HEAD(&dev->chains);
  1485. INIT_LIST_HEAD(&dev->streams);
  1486. atomic_set(&dev->nstreams, 0);
  1487. atomic_set(&dev->users, 0);
  1488. dev->udev = usb_get_dev(udev);
  1489. dev->intf = usb_get_intf(intf);
  1490. dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  1491. dev->quirks = (uvc_quirks_param == -1)
  1492. ? id->driver_info : uvc_quirks_param;
  1493. if (udev->product != NULL)
  1494. strlcpy(dev->name, udev->product, sizeof dev->name);
  1495. else
  1496. snprintf(dev->name, sizeof dev->name,
  1497. "UVC Camera (%04x:%04x)",
  1498. le16_to_cpu(udev->descriptor.idVendor),
  1499. le16_to_cpu(udev->descriptor.idProduct));
  1500. /* Parse the Video Class control descriptor. */
  1501. if (uvc_parse_control(dev) < 0) {
  1502. uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
  1503. "descriptors.\n");
  1504. goto error;
  1505. }
  1506. uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
  1507. dev->uvc_version >> 8, dev->uvc_version & 0xff,
  1508. udev->product ? udev->product : "<unnamed>",
  1509. le16_to_cpu(udev->descriptor.idVendor),
  1510. le16_to_cpu(udev->descriptor.idProduct));
  1511. if (dev->quirks != id->driver_info) {
  1512. uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
  1513. "parameter for testing purpose.\n", dev->quirks);
  1514. uvc_printk(KERN_INFO, "Please report required quirks to the "
  1515. "linux-uvc-devel mailing list.\n");
  1516. }
  1517. /* Initialize controls. */
  1518. if (uvc_ctrl_init_device(dev) < 0)
  1519. goto error;
  1520. /* Scan the device for video chains. */
  1521. if (uvc_scan_device(dev) < 0)
  1522. goto error;
  1523. /* Register video devices. */
  1524. if (uvc_register_chains(dev) < 0)
  1525. goto error;
  1526. /* Save our data pointer in the interface data. */
  1527. usb_set_intfdata(intf, dev);
  1528. /* Initialize the interrupt URB. */
  1529. if ((ret = uvc_status_init(dev)) < 0) {
  1530. uvc_printk(KERN_INFO, "Unable to initialize the status "
  1531. "endpoint (%d), status interrupt will not be "
  1532. "supported.\n", ret);
  1533. }
  1534. uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
  1535. usb_enable_autosuspend(udev);
  1536. return 0;
  1537. error:
  1538. uvc_unregister_video(dev);
  1539. return -ENODEV;
  1540. }
  1541. static void uvc_disconnect(struct usb_interface *intf)
  1542. {
  1543. struct uvc_device *dev = usb_get_intfdata(intf);
  1544. /* Set the USB interface data to NULL. This can be done outside the
  1545. * lock, as there's no other reader.
  1546. */
  1547. usb_set_intfdata(intf, NULL);
  1548. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1549. UVC_SC_VIDEOSTREAMING)
  1550. return;
  1551. dev->state |= UVC_DEV_DISCONNECTED;
  1552. uvc_unregister_video(dev);
  1553. }
  1554. static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
  1555. {
  1556. struct uvc_device *dev = usb_get_intfdata(intf);
  1557. struct uvc_streaming *stream;
  1558. uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
  1559. intf->cur_altsetting->desc.bInterfaceNumber);
  1560. /* Controls are cached on the fly so they don't need to be saved. */
  1561. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1562. UVC_SC_VIDEOCONTROL)
  1563. return uvc_status_suspend(dev);
  1564. list_for_each_entry(stream, &dev->streams, list) {
  1565. if (stream->intf == intf)
  1566. return uvc_video_suspend(stream);
  1567. }
  1568. uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
  1569. "mismatch.\n");
  1570. return -EINVAL;
  1571. }
  1572. static int __uvc_resume(struct usb_interface *intf, int reset)
  1573. {
  1574. struct uvc_device *dev = usb_get_intfdata(intf);
  1575. struct uvc_streaming *stream;
  1576. uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
  1577. intf->cur_altsetting->desc.bInterfaceNumber);
  1578. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1579. UVC_SC_VIDEOCONTROL) {
  1580. if (reset) {
  1581. int ret = uvc_ctrl_resume_device(dev);
  1582. if (ret < 0)
  1583. return ret;
  1584. }
  1585. return uvc_status_resume(dev);
  1586. }
  1587. list_for_each_entry(stream, &dev->streams, list) {
  1588. if (stream->intf == intf)
  1589. return uvc_video_resume(stream);
  1590. }
  1591. uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
  1592. "mismatch.\n");
  1593. return -EINVAL;
  1594. }
  1595. static int uvc_resume(struct usb_interface *intf)
  1596. {
  1597. return __uvc_resume(intf, 0);
  1598. }
  1599. static int uvc_reset_resume(struct usb_interface *intf)
  1600. {
  1601. return __uvc_resume(intf, 1);
  1602. }
  1603. /* ------------------------------------------------------------------------
  1604. * Module parameters
  1605. */
  1606. static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
  1607. {
  1608. if (uvc_clock_param == CLOCK_MONOTONIC)
  1609. return sprintf(buffer, "CLOCK_MONOTONIC");
  1610. else
  1611. return sprintf(buffer, "CLOCK_REALTIME");
  1612. }
  1613. static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
  1614. {
  1615. if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
  1616. val += strlen("clock_");
  1617. if (strcasecmp(val, "monotonic") == 0)
  1618. uvc_clock_param = CLOCK_MONOTONIC;
  1619. else if (strcasecmp(val, "realtime") == 0)
  1620. uvc_clock_param = CLOCK_REALTIME;
  1621. else
  1622. return -EINVAL;
  1623. return 0;
  1624. }
  1625. module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
  1626. &uvc_clock_param, S_IRUGO|S_IWUSR);
  1627. MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
  1628. module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
  1629. MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
  1630. module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
  1631. MODULE_PARM_DESC(quirks, "Forced device quirks");
  1632. module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
  1633. MODULE_PARM_DESC(trace, "Trace level bitmask");
  1634. module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
  1635. MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
  1636. /* ------------------------------------------------------------------------
  1637. * Driver initialization and cleanup
  1638. */
  1639. /*
  1640. * The Logitech cameras listed below have their interface class set to
  1641. * VENDOR_SPEC because they don't announce themselves as UVC devices, even
  1642. * though they are compliant.
  1643. */
  1644. static struct usb_device_id uvc_ids[] = {
  1645. /* Genius eFace 2025 */
  1646. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1647. | USB_DEVICE_ID_MATCH_INT_INFO,
  1648. .idVendor = 0x0458,
  1649. .idProduct = 0x706e,
  1650. .bInterfaceClass = USB_CLASS_VIDEO,
  1651. .bInterfaceSubClass = 1,
  1652. .bInterfaceProtocol = 0,
  1653. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1654. /* Microsoft Lifecam NX-6000 */
  1655. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1656. | USB_DEVICE_ID_MATCH_INT_INFO,
  1657. .idVendor = 0x045e,
  1658. .idProduct = 0x00f8,
  1659. .bInterfaceClass = USB_CLASS_VIDEO,
  1660. .bInterfaceSubClass = 1,
  1661. .bInterfaceProtocol = 0,
  1662. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1663. /* Microsoft Lifecam VX-7000 */
  1664. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1665. | USB_DEVICE_ID_MATCH_INT_INFO,
  1666. .idVendor = 0x045e,
  1667. .idProduct = 0x0723,
  1668. .bInterfaceClass = USB_CLASS_VIDEO,
  1669. .bInterfaceSubClass = 1,
  1670. .bInterfaceProtocol = 0,
  1671. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1672. /* Logitech Quickcam Fusion */
  1673. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1674. | USB_DEVICE_ID_MATCH_INT_INFO,
  1675. .idVendor = 0x046d,
  1676. .idProduct = 0x08c1,
  1677. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1678. .bInterfaceSubClass = 1,
  1679. .bInterfaceProtocol = 0 },
  1680. /* Logitech Quickcam Orbit MP */
  1681. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1682. | USB_DEVICE_ID_MATCH_INT_INFO,
  1683. .idVendor = 0x046d,
  1684. .idProduct = 0x08c2,
  1685. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1686. .bInterfaceSubClass = 1,
  1687. .bInterfaceProtocol = 0 },
  1688. /* Logitech Quickcam Pro for Notebook */
  1689. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1690. | USB_DEVICE_ID_MATCH_INT_INFO,
  1691. .idVendor = 0x046d,
  1692. .idProduct = 0x08c3,
  1693. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1694. .bInterfaceSubClass = 1,
  1695. .bInterfaceProtocol = 0 },
  1696. /* Logitech Quickcam Pro 5000 */
  1697. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1698. | USB_DEVICE_ID_MATCH_INT_INFO,
  1699. .idVendor = 0x046d,
  1700. .idProduct = 0x08c5,
  1701. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1702. .bInterfaceSubClass = 1,
  1703. .bInterfaceProtocol = 0 },
  1704. /* Logitech Quickcam OEM Dell Notebook */
  1705. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1706. | USB_DEVICE_ID_MATCH_INT_INFO,
  1707. .idVendor = 0x046d,
  1708. .idProduct = 0x08c6,
  1709. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1710. .bInterfaceSubClass = 1,
  1711. .bInterfaceProtocol = 0 },
  1712. /* Logitech Quickcam OEM Cisco VT Camera II */
  1713. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1714. | USB_DEVICE_ID_MATCH_INT_INFO,
  1715. .idVendor = 0x046d,
  1716. .idProduct = 0x08c7,
  1717. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1718. .bInterfaceSubClass = 1,
  1719. .bInterfaceProtocol = 0 },
  1720. /* Chicony CNF7129 (Asus EEE 100HE) */
  1721. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1722. | USB_DEVICE_ID_MATCH_INT_INFO,
  1723. .idVendor = 0x04f2,
  1724. .idProduct = 0xb071,
  1725. .bInterfaceClass = USB_CLASS_VIDEO,
  1726. .bInterfaceSubClass = 1,
  1727. .bInterfaceProtocol = 0,
  1728. .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
  1729. /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
  1730. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1731. | USB_DEVICE_ID_MATCH_INT_INFO,
  1732. .idVendor = 0x058f,
  1733. .idProduct = 0x3820,
  1734. .bInterfaceClass = USB_CLASS_VIDEO,
  1735. .bInterfaceSubClass = 1,
  1736. .bInterfaceProtocol = 0,
  1737. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1738. /* Apple Built-In iSight */
  1739. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1740. | USB_DEVICE_ID_MATCH_INT_INFO,
  1741. .idVendor = 0x05ac,
  1742. .idProduct = 0x8501,
  1743. .bInterfaceClass = USB_CLASS_VIDEO,
  1744. .bInterfaceSubClass = 1,
  1745. .bInterfaceProtocol = 0,
  1746. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1747. | UVC_QUIRK_BUILTIN_ISIGHT },
  1748. /* Genesys Logic USB 2.0 PC Camera */
  1749. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1750. | USB_DEVICE_ID_MATCH_INT_INFO,
  1751. .idVendor = 0x05e3,
  1752. .idProduct = 0x0505,
  1753. .bInterfaceClass = USB_CLASS_VIDEO,
  1754. .bInterfaceSubClass = 1,
  1755. .bInterfaceProtocol = 0,
  1756. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1757. /* ViMicro Vega */
  1758. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1759. | USB_DEVICE_ID_MATCH_INT_INFO,
  1760. .idVendor = 0x0ac8,
  1761. .idProduct = 0x332d,
  1762. .bInterfaceClass = USB_CLASS_VIDEO,
  1763. .bInterfaceSubClass = 1,
  1764. .bInterfaceProtocol = 0,
  1765. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1766. /* ViMicro - Minoru3D */
  1767. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1768. | USB_DEVICE_ID_MATCH_INT_INFO,
  1769. .idVendor = 0x0ac8,
  1770. .idProduct = 0x3410,
  1771. .bInterfaceClass = USB_CLASS_VIDEO,
  1772. .bInterfaceSubClass = 1,
  1773. .bInterfaceProtocol = 0,
  1774. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1775. /* ViMicro Venus - Minoru3D */
  1776. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1777. | USB_DEVICE_ID_MATCH_INT_INFO,
  1778. .idVendor = 0x0ac8,
  1779. .idProduct = 0x3420,
  1780. .bInterfaceClass = USB_CLASS_VIDEO,
  1781. .bInterfaceSubClass = 1,
  1782. .bInterfaceProtocol = 0,
  1783. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1784. /* MT6227 */
  1785. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1786. | USB_DEVICE_ID_MATCH_INT_INFO,
  1787. .idVendor = 0x0e8d,
  1788. .idProduct = 0x0004,
  1789. .bInterfaceClass = USB_CLASS_VIDEO,
  1790. .bInterfaceSubClass = 1,
  1791. .bInterfaceProtocol = 0,
  1792. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1793. | UVC_QUIRK_PROBE_DEF },
  1794. /* IMC Networks (Medion Akoya) */
  1795. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1796. | USB_DEVICE_ID_MATCH_INT_INFO,
  1797. .idVendor = 0x13d3,
  1798. .idProduct = 0x5103,
  1799. .bInterfaceClass = USB_CLASS_VIDEO,
  1800. .bInterfaceSubClass = 1,
  1801. .bInterfaceProtocol = 0,
  1802. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1803. /* Syntek (HP Spartan) */
  1804. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1805. | USB_DEVICE_ID_MATCH_INT_INFO,
  1806. .idVendor = 0x174f,
  1807. .idProduct = 0x5212,
  1808. .bInterfaceClass = USB_CLASS_VIDEO,
  1809. .bInterfaceSubClass = 1,
  1810. .bInterfaceProtocol = 0,
  1811. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1812. /* Syntek (Samsung Q310) */
  1813. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1814. | USB_DEVICE_ID_MATCH_INT_INFO,
  1815. .idVendor = 0x174f,
  1816. .idProduct = 0x5931,
  1817. .bInterfaceClass = USB_CLASS_VIDEO,
  1818. .bInterfaceSubClass = 1,
  1819. .bInterfaceProtocol = 0,
  1820. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1821. /* Syntek (Packard Bell EasyNote MX52 */
  1822. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1823. | USB_DEVICE_ID_MATCH_INT_INFO,
  1824. .idVendor = 0x174f,
  1825. .idProduct = 0x8a12,
  1826. .bInterfaceClass = USB_CLASS_VIDEO,
  1827. .bInterfaceSubClass = 1,
  1828. .bInterfaceProtocol = 0,
  1829. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1830. /* Syntek (Asus F9SG) */
  1831. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1832. | USB_DEVICE_ID_MATCH_INT_INFO,
  1833. .idVendor = 0x174f,
  1834. .idProduct = 0x8a31,
  1835. .bInterfaceClass = USB_CLASS_VIDEO,
  1836. .bInterfaceSubClass = 1,
  1837. .bInterfaceProtocol = 0,
  1838. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1839. /* Syntek (Asus U3S) */
  1840. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1841. | USB_DEVICE_ID_MATCH_INT_INFO,
  1842. .idVendor = 0x174f,
  1843. .idProduct = 0x8a33,
  1844. .bInterfaceClass = USB_CLASS_VIDEO,
  1845. .bInterfaceSubClass = 1,
  1846. .bInterfaceProtocol = 0,
  1847. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1848. /* Syntek (JAOtech Smart Terminal) */
  1849. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1850. | USB_DEVICE_ID_MATCH_INT_INFO,
  1851. .idVendor = 0x174f,
  1852. .idProduct = 0x8a34,
  1853. .bInterfaceClass = USB_CLASS_VIDEO,
  1854. .bInterfaceSubClass = 1,
  1855. .bInterfaceProtocol = 0,
  1856. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1857. /* Miricle 307K */
  1858. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1859. | USB_DEVICE_ID_MATCH_INT_INFO,
  1860. .idVendor = 0x17dc,
  1861. .idProduct = 0x0202,
  1862. .bInterfaceClass = USB_CLASS_VIDEO,
  1863. .bInterfaceSubClass = 1,
  1864. .bInterfaceProtocol = 0,
  1865. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1866. /* Lenovo Thinkpad SL400/SL500 */
  1867. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1868. | USB_DEVICE_ID_MATCH_INT_INFO,
  1869. .idVendor = 0x17ef,
  1870. .idProduct = 0x480b,
  1871. .bInterfaceClass = USB_CLASS_VIDEO,
  1872. .bInterfaceSubClass = 1,
  1873. .bInterfaceProtocol = 0,
  1874. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1875. /* Aveo Technology USB 2.0 Camera */
  1876. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1877. | USB_DEVICE_ID_MATCH_INT_INFO,
  1878. .idVendor = 0x1871,
  1879. .idProduct = 0x0306,
  1880. .bInterfaceClass = USB_CLASS_VIDEO,
  1881. .bInterfaceSubClass = 1,
  1882. .bInterfaceProtocol = 0,
  1883. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1884. | UVC_QUIRK_PROBE_EXTRAFIELDS },
  1885. /* Ecamm Pico iMage */
  1886. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1887. | USB_DEVICE_ID_MATCH_INT_INFO,
  1888. .idVendor = 0x18cd,
  1889. .idProduct = 0xcafe,
  1890. .bInterfaceClass = USB_CLASS_VIDEO,
  1891. .bInterfaceSubClass = 1,
  1892. .bInterfaceProtocol = 0,
  1893. .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
  1894. /* Manta MM-353 Plako */
  1895. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1896. | USB_DEVICE_ID_MATCH_INT_INFO,
  1897. .idVendor = 0x18ec,
  1898. .idProduct = 0x3188,
  1899. .bInterfaceClass = USB_CLASS_VIDEO,
  1900. .bInterfaceSubClass = 1,
  1901. .bInterfaceProtocol = 0,
  1902. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1903. /* FSC WebCam V30S */
  1904. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1905. | USB_DEVICE_ID_MATCH_INT_INFO,
  1906. .idVendor = 0x18ec,
  1907. .idProduct = 0x3288,
  1908. .bInterfaceClass = USB_CLASS_VIDEO,
  1909. .bInterfaceSubClass = 1,
  1910. .bInterfaceProtocol = 0,
  1911. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1912. /* Arkmicro unbranded */
  1913. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1914. | USB_DEVICE_ID_MATCH_INT_INFO,
  1915. .idVendor = 0x18ec,
  1916. .idProduct = 0x3290,
  1917. .bInterfaceClass = USB_CLASS_VIDEO,
  1918. .bInterfaceSubClass = 1,
  1919. .bInterfaceProtocol = 0,
  1920. .driver_info = UVC_QUIRK_PROBE_DEF },
  1921. /* Bodelin ProScopeHR */
  1922. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1923. | USB_DEVICE_ID_MATCH_DEV_HI
  1924. | USB_DEVICE_ID_MATCH_INT_INFO,
  1925. .idVendor = 0x19ab,
  1926. .idProduct = 0x1000,
  1927. .bcdDevice_hi = 0x0126,
  1928. .bInterfaceClass = USB_CLASS_VIDEO,
  1929. .bInterfaceSubClass = 1,
  1930. .bInterfaceProtocol = 0,
  1931. .driver_info = UVC_QUIRK_STATUS_INTERVAL },
  1932. /* MSI StarCam 370i */
  1933. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1934. | USB_DEVICE_ID_MATCH_INT_INFO,
  1935. .idVendor = 0x1b3b,
  1936. .idProduct = 0x2951,
  1937. .bInterfaceClass = USB_CLASS_VIDEO,
  1938. .bInterfaceSubClass = 1,
  1939. .bInterfaceProtocol = 0,
  1940. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1941. /* SiGma Micro USB Web Camera */
  1942. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1943. | USB_DEVICE_ID_MATCH_INT_INFO,
  1944. .idVendor = 0x1c4f,
  1945. .idProduct = 0x3000,
  1946. .bInterfaceClass = USB_CLASS_VIDEO,
  1947. .bInterfaceSubClass = 1,
  1948. .bInterfaceProtocol = 0,
  1949. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1950. | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
  1951. /* Generic USB Video Class */
  1952. { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
  1953. {}
  1954. };
  1955. MODULE_DEVICE_TABLE(usb, uvc_ids);
  1956. struct uvc_driver uvc_driver = {
  1957. .driver = {
  1958. .name = "uvcvideo",
  1959. .probe = uvc_probe,
  1960. .disconnect = uvc_disconnect,
  1961. .suspend = uvc_suspend,
  1962. .resume = uvc_resume,
  1963. .reset_resume = uvc_reset_resume,
  1964. .id_table = uvc_ids,
  1965. .supports_autosuspend = 1,
  1966. },
  1967. };
  1968. static int __init uvc_init(void)
  1969. {
  1970. int result;
  1971. INIT_LIST_HEAD(&uvc_driver.devices);
  1972. INIT_LIST_HEAD(&uvc_driver.controls);
  1973. mutex_init(&uvc_driver.ctrl_mutex);
  1974. uvc_ctrl_init();
  1975. result = usb_register(&uvc_driver.driver);
  1976. if (result == 0)
  1977. printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
  1978. return result;
  1979. }
  1980. static void __exit uvc_cleanup(void)
  1981. {
  1982. usb_deregister(&uvc_driver.driver);
  1983. uvc_ctrl_cleanup();
  1984. }
  1985. module_init(uvc_init);
  1986. module_exit(uvc_cleanup);
  1987. MODULE_AUTHOR(DRIVER_AUTHOR);
  1988. MODULE_DESCRIPTION(DRIVER_DESC);
  1989. MODULE_LICENSE("GPL");
  1990. MODULE_VERSION(DRIVER_VERSION);