uvc_driver.c 52 KB

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