uvc_driver.c 56 KB

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