uvc_driver.c 53 KB

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