uvc_driver.c 54 KB

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