uvc_driver.c 57 KB

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