uvc_driver.c 54 KB

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