uvc_driver.c 54 KB

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