uvc_driver.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315
  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. return 0;
  1536. error:
  1537. uvc_unregister_video(dev);
  1538. return -ENODEV;
  1539. }
  1540. static void uvc_disconnect(struct usb_interface *intf)
  1541. {
  1542. struct uvc_device *dev = usb_get_intfdata(intf);
  1543. /* Set the USB interface data to NULL. This can be done outside the
  1544. * lock, as there's no other reader.
  1545. */
  1546. usb_set_intfdata(intf, NULL);
  1547. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1548. UVC_SC_VIDEOSTREAMING)
  1549. return;
  1550. dev->state |= UVC_DEV_DISCONNECTED;
  1551. uvc_unregister_video(dev);
  1552. }
  1553. static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
  1554. {
  1555. struct uvc_device *dev = usb_get_intfdata(intf);
  1556. struct uvc_streaming *stream;
  1557. uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
  1558. intf->cur_altsetting->desc.bInterfaceNumber);
  1559. /* Controls are cached on the fly so they don't need to be saved. */
  1560. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1561. UVC_SC_VIDEOCONTROL)
  1562. return uvc_status_suspend(dev);
  1563. list_for_each_entry(stream, &dev->streams, list) {
  1564. if (stream->intf == intf)
  1565. return uvc_video_suspend(stream);
  1566. }
  1567. uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
  1568. "mismatch.\n");
  1569. return -EINVAL;
  1570. }
  1571. static int __uvc_resume(struct usb_interface *intf, int reset)
  1572. {
  1573. struct uvc_device *dev = usb_get_intfdata(intf);
  1574. struct uvc_streaming *stream;
  1575. uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
  1576. intf->cur_altsetting->desc.bInterfaceNumber);
  1577. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1578. UVC_SC_VIDEOCONTROL) {
  1579. if (reset) {
  1580. int ret = uvc_ctrl_resume_device(dev);
  1581. if (ret < 0)
  1582. return ret;
  1583. }
  1584. return uvc_status_resume(dev);
  1585. }
  1586. list_for_each_entry(stream, &dev->streams, list) {
  1587. if (stream->intf == intf)
  1588. return uvc_video_resume(stream);
  1589. }
  1590. uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
  1591. "mismatch.\n");
  1592. return -EINVAL;
  1593. }
  1594. static int uvc_resume(struct usb_interface *intf)
  1595. {
  1596. return __uvc_resume(intf, 0);
  1597. }
  1598. static int uvc_reset_resume(struct usb_interface *intf)
  1599. {
  1600. return __uvc_resume(intf, 1);
  1601. }
  1602. /* ------------------------------------------------------------------------
  1603. * Module parameters
  1604. */
  1605. static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
  1606. {
  1607. if (uvc_clock_param == CLOCK_MONOTONIC)
  1608. return sprintf(buffer, "CLOCK_MONOTONIC");
  1609. else
  1610. return sprintf(buffer, "CLOCK_REALTIME");
  1611. }
  1612. static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
  1613. {
  1614. if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
  1615. val += strlen("clock_");
  1616. if (strcasecmp(val, "monotonic") == 0)
  1617. uvc_clock_param = CLOCK_MONOTONIC;
  1618. else if (strcasecmp(val, "realtime") == 0)
  1619. uvc_clock_param = CLOCK_REALTIME;
  1620. else
  1621. return -EINVAL;
  1622. return 0;
  1623. }
  1624. module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
  1625. &uvc_clock_param, S_IRUGO|S_IWUSR);
  1626. MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
  1627. module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
  1628. MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
  1629. module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
  1630. MODULE_PARM_DESC(quirks, "Forced device quirks");
  1631. module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
  1632. MODULE_PARM_DESC(trace, "Trace level bitmask");
  1633. module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
  1634. MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
  1635. /* ------------------------------------------------------------------------
  1636. * Driver initialization and cleanup
  1637. */
  1638. /*
  1639. * The Logitech cameras listed below have their interface class set to
  1640. * VENDOR_SPEC because they don't announce themselves as UVC devices, even
  1641. * though they are compliant.
  1642. */
  1643. static struct usb_device_id uvc_ids[] = {
  1644. /* Genius eFace 2025 */
  1645. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1646. | USB_DEVICE_ID_MATCH_INT_INFO,
  1647. .idVendor = 0x0458,
  1648. .idProduct = 0x706e,
  1649. .bInterfaceClass = USB_CLASS_VIDEO,
  1650. .bInterfaceSubClass = 1,
  1651. .bInterfaceProtocol = 0,
  1652. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1653. /* Microsoft Lifecam NX-6000 */
  1654. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1655. | USB_DEVICE_ID_MATCH_INT_INFO,
  1656. .idVendor = 0x045e,
  1657. .idProduct = 0x00f8,
  1658. .bInterfaceClass = USB_CLASS_VIDEO,
  1659. .bInterfaceSubClass = 1,
  1660. .bInterfaceProtocol = 0,
  1661. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1662. /* Microsoft Lifecam VX-7000 */
  1663. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1664. | USB_DEVICE_ID_MATCH_INT_INFO,
  1665. .idVendor = 0x045e,
  1666. .idProduct = 0x0723,
  1667. .bInterfaceClass = USB_CLASS_VIDEO,
  1668. .bInterfaceSubClass = 1,
  1669. .bInterfaceProtocol = 0,
  1670. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1671. /* Logitech Quickcam Fusion */
  1672. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1673. | USB_DEVICE_ID_MATCH_INT_INFO,
  1674. .idVendor = 0x046d,
  1675. .idProduct = 0x08c1,
  1676. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1677. .bInterfaceSubClass = 1,
  1678. .bInterfaceProtocol = 0 },
  1679. /* Logitech Quickcam Orbit MP */
  1680. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1681. | USB_DEVICE_ID_MATCH_INT_INFO,
  1682. .idVendor = 0x046d,
  1683. .idProduct = 0x08c2,
  1684. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1685. .bInterfaceSubClass = 1,
  1686. .bInterfaceProtocol = 0 },
  1687. /* Logitech Quickcam Pro for Notebook */
  1688. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1689. | USB_DEVICE_ID_MATCH_INT_INFO,
  1690. .idVendor = 0x046d,
  1691. .idProduct = 0x08c3,
  1692. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1693. .bInterfaceSubClass = 1,
  1694. .bInterfaceProtocol = 0 },
  1695. /* Logitech Quickcam Pro 5000 */
  1696. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1697. | USB_DEVICE_ID_MATCH_INT_INFO,
  1698. .idVendor = 0x046d,
  1699. .idProduct = 0x08c5,
  1700. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1701. .bInterfaceSubClass = 1,
  1702. .bInterfaceProtocol = 0 },
  1703. /* Logitech Quickcam OEM Dell Notebook */
  1704. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1705. | USB_DEVICE_ID_MATCH_INT_INFO,
  1706. .idVendor = 0x046d,
  1707. .idProduct = 0x08c6,
  1708. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1709. .bInterfaceSubClass = 1,
  1710. .bInterfaceProtocol = 0 },
  1711. /* Logitech Quickcam OEM Cisco VT Camera II */
  1712. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1713. | USB_DEVICE_ID_MATCH_INT_INFO,
  1714. .idVendor = 0x046d,
  1715. .idProduct = 0x08c7,
  1716. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1717. .bInterfaceSubClass = 1,
  1718. .bInterfaceProtocol = 0 },
  1719. /* Chicony CNF7129 (Asus EEE 100HE) */
  1720. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1721. | USB_DEVICE_ID_MATCH_INT_INFO,
  1722. .idVendor = 0x04f2,
  1723. .idProduct = 0xb071,
  1724. .bInterfaceClass = USB_CLASS_VIDEO,
  1725. .bInterfaceSubClass = 1,
  1726. .bInterfaceProtocol = 0,
  1727. .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
  1728. /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
  1729. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1730. | USB_DEVICE_ID_MATCH_INT_INFO,
  1731. .idVendor = 0x058f,
  1732. .idProduct = 0x3820,
  1733. .bInterfaceClass = USB_CLASS_VIDEO,
  1734. .bInterfaceSubClass = 1,
  1735. .bInterfaceProtocol = 0,
  1736. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1737. /* Apple Built-In iSight */
  1738. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1739. | USB_DEVICE_ID_MATCH_INT_INFO,
  1740. .idVendor = 0x05ac,
  1741. .idProduct = 0x8501,
  1742. .bInterfaceClass = USB_CLASS_VIDEO,
  1743. .bInterfaceSubClass = 1,
  1744. .bInterfaceProtocol = 0,
  1745. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1746. | UVC_QUIRK_BUILTIN_ISIGHT },
  1747. /* Genesys Logic USB 2.0 PC Camera */
  1748. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1749. | USB_DEVICE_ID_MATCH_INT_INFO,
  1750. .idVendor = 0x05e3,
  1751. .idProduct = 0x0505,
  1752. .bInterfaceClass = USB_CLASS_VIDEO,
  1753. .bInterfaceSubClass = 1,
  1754. .bInterfaceProtocol = 0,
  1755. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1756. /* ViMicro Vega */
  1757. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1758. | USB_DEVICE_ID_MATCH_INT_INFO,
  1759. .idVendor = 0x0ac8,
  1760. .idProduct = 0x332d,
  1761. .bInterfaceClass = USB_CLASS_VIDEO,
  1762. .bInterfaceSubClass = 1,
  1763. .bInterfaceProtocol = 0,
  1764. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1765. /* ViMicro - Minoru3D */
  1766. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1767. | USB_DEVICE_ID_MATCH_INT_INFO,
  1768. .idVendor = 0x0ac8,
  1769. .idProduct = 0x3410,
  1770. .bInterfaceClass = USB_CLASS_VIDEO,
  1771. .bInterfaceSubClass = 1,
  1772. .bInterfaceProtocol = 0,
  1773. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1774. /* ViMicro Venus - Minoru3D */
  1775. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1776. | USB_DEVICE_ID_MATCH_INT_INFO,
  1777. .idVendor = 0x0ac8,
  1778. .idProduct = 0x3420,
  1779. .bInterfaceClass = USB_CLASS_VIDEO,
  1780. .bInterfaceSubClass = 1,
  1781. .bInterfaceProtocol = 0,
  1782. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1783. /* MT6227 */
  1784. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1785. | USB_DEVICE_ID_MATCH_INT_INFO,
  1786. .idVendor = 0x0e8d,
  1787. .idProduct = 0x0004,
  1788. .bInterfaceClass = USB_CLASS_VIDEO,
  1789. .bInterfaceSubClass = 1,
  1790. .bInterfaceProtocol = 0,
  1791. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1792. | UVC_QUIRK_PROBE_DEF },
  1793. /* IMC Networks (Medion Akoya) */
  1794. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1795. | USB_DEVICE_ID_MATCH_INT_INFO,
  1796. .idVendor = 0x13d3,
  1797. .idProduct = 0x5103,
  1798. .bInterfaceClass = USB_CLASS_VIDEO,
  1799. .bInterfaceSubClass = 1,
  1800. .bInterfaceProtocol = 0,
  1801. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1802. /* Syntek (HP Spartan) */
  1803. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1804. | USB_DEVICE_ID_MATCH_INT_INFO,
  1805. .idVendor = 0x174f,
  1806. .idProduct = 0x5212,
  1807. .bInterfaceClass = USB_CLASS_VIDEO,
  1808. .bInterfaceSubClass = 1,
  1809. .bInterfaceProtocol = 0,
  1810. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1811. /* Syntek (Samsung Q310) */
  1812. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1813. | USB_DEVICE_ID_MATCH_INT_INFO,
  1814. .idVendor = 0x174f,
  1815. .idProduct = 0x5931,
  1816. .bInterfaceClass = USB_CLASS_VIDEO,
  1817. .bInterfaceSubClass = 1,
  1818. .bInterfaceProtocol = 0,
  1819. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1820. /* Syntek (Packard Bell EasyNote MX52 */
  1821. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1822. | USB_DEVICE_ID_MATCH_INT_INFO,
  1823. .idVendor = 0x174f,
  1824. .idProduct = 0x8a12,
  1825. .bInterfaceClass = USB_CLASS_VIDEO,
  1826. .bInterfaceSubClass = 1,
  1827. .bInterfaceProtocol = 0,
  1828. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1829. /* Syntek (Asus F9SG) */
  1830. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1831. | USB_DEVICE_ID_MATCH_INT_INFO,
  1832. .idVendor = 0x174f,
  1833. .idProduct = 0x8a31,
  1834. .bInterfaceClass = USB_CLASS_VIDEO,
  1835. .bInterfaceSubClass = 1,
  1836. .bInterfaceProtocol = 0,
  1837. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1838. /* Syntek (Asus U3S) */
  1839. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1840. | USB_DEVICE_ID_MATCH_INT_INFO,
  1841. .idVendor = 0x174f,
  1842. .idProduct = 0x8a33,
  1843. .bInterfaceClass = USB_CLASS_VIDEO,
  1844. .bInterfaceSubClass = 1,
  1845. .bInterfaceProtocol = 0,
  1846. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1847. /* Syntek (JAOtech Smart Terminal) */
  1848. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1849. | USB_DEVICE_ID_MATCH_INT_INFO,
  1850. .idVendor = 0x174f,
  1851. .idProduct = 0x8a34,
  1852. .bInterfaceClass = USB_CLASS_VIDEO,
  1853. .bInterfaceSubClass = 1,
  1854. .bInterfaceProtocol = 0,
  1855. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1856. /* Miricle 307K */
  1857. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1858. | USB_DEVICE_ID_MATCH_INT_INFO,
  1859. .idVendor = 0x17dc,
  1860. .idProduct = 0x0202,
  1861. .bInterfaceClass = USB_CLASS_VIDEO,
  1862. .bInterfaceSubClass = 1,
  1863. .bInterfaceProtocol = 0,
  1864. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1865. /* Lenovo Thinkpad SL400/SL500 */
  1866. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1867. | USB_DEVICE_ID_MATCH_INT_INFO,
  1868. .idVendor = 0x17ef,
  1869. .idProduct = 0x480b,
  1870. .bInterfaceClass = USB_CLASS_VIDEO,
  1871. .bInterfaceSubClass = 1,
  1872. .bInterfaceProtocol = 0,
  1873. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1874. /* Aveo Technology USB 2.0 Camera */
  1875. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1876. | USB_DEVICE_ID_MATCH_INT_INFO,
  1877. .idVendor = 0x1871,
  1878. .idProduct = 0x0306,
  1879. .bInterfaceClass = USB_CLASS_VIDEO,
  1880. .bInterfaceSubClass = 1,
  1881. .bInterfaceProtocol = 0,
  1882. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1883. | UVC_QUIRK_PROBE_EXTRAFIELDS },
  1884. /* Ecamm Pico iMage */
  1885. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1886. | USB_DEVICE_ID_MATCH_INT_INFO,
  1887. .idVendor = 0x18cd,
  1888. .idProduct = 0xcafe,
  1889. .bInterfaceClass = USB_CLASS_VIDEO,
  1890. .bInterfaceSubClass = 1,
  1891. .bInterfaceProtocol = 0,
  1892. .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
  1893. /* Manta MM-353 Plako */
  1894. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1895. | USB_DEVICE_ID_MATCH_INT_INFO,
  1896. .idVendor = 0x18ec,
  1897. .idProduct = 0x3188,
  1898. .bInterfaceClass = USB_CLASS_VIDEO,
  1899. .bInterfaceSubClass = 1,
  1900. .bInterfaceProtocol = 0,
  1901. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1902. /* FSC WebCam V30S */
  1903. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1904. | USB_DEVICE_ID_MATCH_INT_INFO,
  1905. .idVendor = 0x18ec,
  1906. .idProduct = 0x3288,
  1907. .bInterfaceClass = USB_CLASS_VIDEO,
  1908. .bInterfaceSubClass = 1,
  1909. .bInterfaceProtocol = 0,
  1910. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1911. /* Arkmicro unbranded */
  1912. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1913. | USB_DEVICE_ID_MATCH_INT_INFO,
  1914. .idVendor = 0x18ec,
  1915. .idProduct = 0x3290,
  1916. .bInterfaceClass = USB_CLASS_VIDEO,
  1917. .bInterfaceSubClass = 1,
  1918. .bInterfaceProtocol = 0,
  1919. .driver_info = UVC_QUIRK_PROBE_DEF },
  1920. /* Bodelin ProScopeHR */
  1921. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1922. | USB_DEVICE_ID_MATCH_DEV_HI
  1923. | USB_DEVICE_ID_MATCH_INT_INFO,
  1924. .idVendor = 0x19ab,
  1925. .idProduct = 0x1000,
  1926. .bcdDevice_hi = 0x0126,
  1927. .bInterfaceClass = USB_CLASS_VIDEO,
  1928. .bInterfaceSubClass = 1,
  1929. .bInterfaceProtocol = 0,
  1930. .driver_info = UVC_QUIRK_STATUS_INTERVAL },
  1931. /* MSI StarCam 370i */
  1932. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1933. | USB_DEVICE_ID_MATCH_INT_INFO,
  1934. .idVendor = 0x1b3b,
  1935. .idProduct = 0x2951,
  1936. .bInterfaceClass = USB_CLASS_VIDEO,
  1937. .bInterfaceSubClass = 1,
  1938. .bInterfaceProtocol = 0,
  1939. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1940. /* SiGma Micro USB Web Camera */
  1941. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1942. | USB_DEVICE_ID_MATCH_INT_INFO,
  1943. .idVendor = 0x1c4f,
  1944. .idProduct = 0x3000,
  1945. .bInterfaceClass = USB_CLASS_VIDEO,
  1946. .bInterfaceSubClass = 1,
  1947. .bInterfaceProtocol = 0,
  1948. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1949. | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
  1950. /* Generic USB Video Class */
  1951. { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
  1952. {}
  1953. };
  1954. MODULE_DEVICE_TABLE(usb, uvc_ids);
  1955. struct uvc_driver uvc_driver = {
  1956. .driver = {
  1957. .name = "uvcvideo",
  1958. .probe = uvc_probe,
  1959. .disconnect = uvc_disconnect,
  1960. .suspend = uvc_suspend,
  1961. .resume = uvc_resume,
  1962. .reset_resume = uvc_reset_resume,
  1963. .id_table = uvc_ids,
  1964. .supports_autosuspend = 1,
  1965. },
  1966. };
  1967. static int __init uvc_init(void)
  1968. {
  1969. int result;
  1970. INIT_LIST_HEAD(&uvc_driver.devices);
  1971. INIT_LIST_HEAD(&uvc_driver.controls);
  1972. mutex_init(&uvc_driver.ctrl_mutex);
  1973. uvc_ctrl_init();
  1974. result = usb_register(&uvc_driver.driver);
  1975. if (result == 0)
  1976. printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
  1977. return result;
  1978. }
  1979. static void __exit uvc_cleanup(void)
  1980. {
  1981. usb_deregister(&uvc_driver.driver);
  1982. uvc_ctrl_cleanup();
  1983. }
  1984. module_init(uvc_init);
  1985. module_exit(uvc_cleanup);
  1986. MODULE_AUTHOR(DRIVER_AUTHOR);
  1987. MODULE_DESCRIPTION(DRIVER_DESC);
  1988. MODULE_LICENSE("GPL");
  1989. MODULE_VERSION(DRIVER_VERSION);