uvc_driver.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419
  1. /*
  2. * uvc_driver.c -- USB Video Class driver
  3. *
  4. * Copyright (C) 2005-2010
  5. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  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/slab.h>
  28. #include <linux/usb.h>
  29. #include <linux/videodev2.h>
  30. #include <linux/vmalloc.h>
  31. #include <linux/wait.h>
  32. #include <linux/version.h>
  33. #include <asm/atomic.h>
  34. #include <asm/unaligned.h>
  35. #include <media/v4l2-common.h>
  36. #include "uvcvideo.h"
  37. #define DRIVER_AUTHOR "Laurent Pinchart " \
  38. "<laurent.pinchart@ideasonboard.com>"
  39. #define DRIVER_DESC "USB Video Class driver"
  40. unsigned int uvc_clock_param = CLOCK_MONOTONIC;
  41. unsigned int uvc_no_drop_param;
  42. static unsigned int uvc_quirks_param = -1;
  43. unsigned int uvc_trace_param;
  44. unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
  45. /* ------------------------------------------------------------------------
  46. * Video formats
  47. */
  48. static struct uvc_format_desc uvc_fmts[] = {
  49. {
  50. .name = "YUV 4:2:2 (YUYV)",
  51. .guid = UVC_GUID_FORMAT_YUY2,
  52. .fcc = V4L2_PIX_FMT_YUYV,
  53. },
  54. {
  55. .name = "YUV 4:2:2 (YUYV)",
  56. .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
  57. .fcc = V4L2_PIX_FMT_YUYV,
  58. },
  59. {
  60. .name = "YUV 4:2:0 (NV12)",
  61. .guid = UVC_GUID_FORMAT_NV12,
  62. .fcc = V4L2_PIX_FMT_NV12,
  63. },
  64. {
  65. .name = "MJPEG",
  66. .guid = UVC_GUID_FORMAT_MJPEG,
  67. .fcc = V4L2_PIX_FMT_MJPEG,
  68. },
  69. {
  70. .name = "YVU 4:2:0 (YV12)",
  71. .guid = UVC_GUID_FORMAT_YV12,
  72. .fcc = V4L2_PIX_FMT_YVU420,
  73. },
  74. {
  75. .name = "YUV 4:2:0 (I420)",
  76. .guid = UVC_GUID_FORMAT_I420,
  77. .fcc = V4L2_PIX_FMT_YUV420,
  78. },
  79. {
  80. .name = "YUV 4:2:0 (M420)",
  81. .guid = UVC_GUID_FORMAT_M420,
  82. .fcc = V4L2_PIX_FMT_M420,
  83. },
  84. {
  85. .name = "YUV 4:2:2 (UYVY)",
  86. .guid = UVC_GUID_FORMAT_UYVY,
  87. .fcc = V4L2_PIX_FMT_UYVY,
  88. },
  89. {
  90. .name = "Greyscale (8-bit)",
  91. .guid = UVC_GUID_FORMAT_Y800,
  92. .fcc = V4L2_PIX_FMT_GREY,
  93. },
  94. {
  95. .name = "Greyscale (16-bit)",
  96. .guid = UVC_GUID_FORMAT_Y16,
  97. .fcc = V4L2_PIX_FMT_Y16,
  98. },
  99. {
  100. .name = "RGB Bayer",
  101. .guid = UVC_GUID_FORMAT_BY8,
  102. .fcc = V4L2_PIX_FMT_SBGGR8,
  103. },
  104. {
  105. .name = "RGB565",
  106. .guid = UVC_GUID_FORMAT_RGBP,
  107. .fcc = V4L2_PIX_FMT_RGB565,
  108. },
  109. {
  110. .name = "H.264",
  111. .guid = UVC_GUID_FORMAT_H264,
  112. .fcc = V4L2_PIX_FMT_H264,
  113. },
  114. };
  115. /* ------------------------------------------------------------------------
  116. * Utility functions
  117. */
  118. struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
  119. __u8 epaddr)
  120. {
  121. struct usb_host_endpoint *ep;
  122. unsigned int i;
  123. for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
  124. ep = &alts->endpoint[i];
  125. if (ep->desc.bEndpointAddress == epaddr)
  126. return ep;
  127. }
  128. return NULL;
  129. }
  130. static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
  131. {
  132. unsigned int len = ARRAY_SIZE(uvc_fmts);
  133. unsigned int i;
  134. for (i = 0; i < len; ++i) {
  135. if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
  136. return &uvc_fmts[i];
  137. }
  138. return NULL;
  139. }
  140. static __u32 uvc_colorspace(const __u8 primaries)
  141. {
  142. static const __u8 colorprimaries[] = {
  143. 0,
  144. V4L2_COLORSPACE_SRGB,
  145. V4L2_COLORSPACE_470_SYSTEM_M,
  146. V4L2_COLORSPACE_470_SYSTEM_BG,
  147. V4L2_COLORSPACE_SMPTE170M,
  148. V4L2_COLORSPACE_SMPTE240M,
  149. };
  150. if (primaries < ARRAY_SIZE(colorprimaries))
  151. return colorprimaries[primaries];
  152. return 0;
  153. }
  154. /* Simplify a fraction using a simple continued fraction decomposition. The
  155. * idea here is to convert fractions such as 333333/10000000 to 1/30 using
  156. * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
  157. * arbitrary parameters to remove non-significative terms from the simple
  158. * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
  159. * respectively seems to give nice results.
  160. */
  161. void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
  162. unsigned int n_terms, unsigned int threshold)
  163. {
  164. uint32_t *an;
  165. uint32_t x, y, r;
  166. unsigned int i, n;
  167. an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
  168. if (an == NULL)
  169. return;
  170. /* Convert the fraction to a simple continued fraction. See
  171. * http://mathforum.org/dr.math/faq/faq.fractions.html
  172. * Stop if the current term is bigger than or equal to the given
  173. * threshold.
  174. */
  175. x = *numerator;
  176. y = *denominator;
  177. for (n = 0; n < n_terms && y != 0; ++n) {
  178. an[n] = x / y;
  179. if (an[n] >= threshold) {
  180. if (n < 2)
  181. n++;
  182. break;
  183. }
  184. r = x - an[n] * y;
  185. x = y;
  186. y = r;
  187. }
  188. /* Expand the simple continued fraction back to an integer fraction. */
  189. x = 0;
  190. y = 1;
  191. for (i = n; i > 0; --i) {
  192. r = y;
  193. y = an[i-1] * y + x;
  194. x = r;
  195. }
  196. *numerator = y;
  197. *denominator = x;
  198. kfree(an);
  199. }
  200. /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
  201. * to compute numerator / denominator * 10000000 using 32 bit fixed point
  202. * arithmetic only.
  203. */
  204. uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
  205. {
  206. uint32_t multiplier;
  207. /* Saturate the result if the operation would overflow. */
  208. if (denominator == 0 ||
  209. numerator/denominator >= ((uint32_t)-1)/10000000)
  210. return (uint32_t)-1;
  211. /* Divide both the denominator and the multiplier by two until
  212. * numerator * multiplier doesn't overflow. If anyone knows a better
  213. * algorithm please let me know.
  214. */
  215. multiplier = 10000000;
  216. while (numerator > ((uint32_t)-1)/multiplier) {
  217. multiplier /= 2;
  218. denominator /= 2;
  219. }
  220. return denominator ? numerator * multiplier / denominator : 0;
  221. }
  222. /* ------------------------------------------------------------------------
  223. * Terminal and unit management
  224. */
  225. struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
  226. {
  227. struct uvc_entity *entity;
  228. list_for_each_entry(entity, &dev->entities, list) {
  229. if (entity->id == id)
  230. return entity;
  231. }
  232. return NULL;
  233. }
  234. static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
  235. int id, struct uvc_entity *entity)
  236. {
  237. unsigned int i;
  238. if (entity == NULL)
  239. entity = list_entry(&dev->entities, struct uvc_entity, list);
  240. list_for_each_entry_continue(entity, &dev->entities, list) {
  241. for (i = 0; i < entity->bNrInPins; ++i)
  242. if (entity->baSourceID[i] == id)
  243. return entity;
  244. }
  245. return NULL;
  246. }
  247. static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
  248. {
  249. struct uvc_streaming *stream;
  250. list_for_each_entry(stream, &dev->streams, list) {
  251. if (stream->header.bTerminalLink == id)
  252. return stream;
  253. }
  254. return NULL;
  255. }
  256. /* ------------------------------------------------------------------------
  257. * Descriptors parsing
  258. */
  259. static int uvc_parse_format(struct uvc_device *dev,
  260. struct uvc_streaming *streaming, struct uvc_format *format,
  261. __u32 **intervals, unsigned char *buffer, int buflen)
  262. {
  263. struct usb_interface *intf = streaming->intf;
  264. struct usb_host_interface *alts = intf->cur_altsetting;
  265. struct uvc_format_desc *fmtdesc;
  266. struct uvc_frame *frame;
  267. const unsigned char *start = buffer;
  268. unsigned int interval;
  269. unsigned int i, n;
  270. __u8 ftype;
  271. format->type = buffer[2];
  272. format->index = buffer[3];
  273. switch (buffer[2]) {
  274. case UVC_VS_FORMAT_UNCOMPRESSED:
  275. case UVC_VS_FORMAT_FRAME_BASED:
  276. n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
  277. if (buflen < n) {
  278. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  279. "interface %d FORMAT error\n",
  280. dev->udev->devnum,
  281. alts->desc.bInterfaceNumber);
  282. return -EINVAL;
  283. }
  284. /* Find the format descriptor from its GUID. */
  285. fmtdesc = uvc_format_by_guid(&buffer[5]);
  286. if (fmtdesc != NULL) {
  287. strlcpy(format->name, fmtdesc->name,
  288. sizeof format->name);
  289. format->fcc = fmtdesc->fcc;
  290. } else {
  291. uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
  292. &buffer[5]);
  293. snprintf(format->name, sizeof(format->name), "%pUl\n",
  294. &buffer[5]);
  295. format->fcc = 0;
  296. }
  297. format->bpp = buffer[21];
  298. if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
  299. ftype = UVC_VS_FRAME_UNCOMPRESSED;
  300. } else {
  301. ftype = UVC_VS_FRAME_FRAME_BASED;
  302. if (buffer[27])
  303. format->flags = UVC_FMT_FLAG_COMPRESSED;
  304. }
  305. break;
  306. case UVC_VS_FORMAT_MJPEG:
  307. if (buflen < 11) {
  308. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  309. "interface %d FORMAT error\n",
  310. dev->udev->devnum,
  311. alts->desc.bInterfaceNumber);
  312. return -EINVAL;
  313. }
  314. strlcpy(format->name, "MJPEG", sizeof format->name);
  315. format->fcc = V4L2_PIX_FMT_MJPEG;
  316. format->flags = UVC_FMT_FLAG_COMPRESSED;
  317. format->bpp = 0;
  318. ftype = UVC_VS_FRAME_MJPEG;
  319. break;
  320. case UVC_VS_FORMAT_DV:
  321. if (buflen < 9) {
  322. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  323. "interface %d FORMAT error\n",
  324. dev->udev->devnum,
  325. alts->desc.bInterfaceNumber);
  326. return -EINVAL;
  327. }
  328. switch (buffer[8] & 0x7f) {
  329. case 0:
  330. strlcpy(format->name, "SD-DV", sizeof format->name);
  331. break;
  332. case 1:
  333. strlcpy(format->name, "SDL-DV", sizeof format->name);
  334. break;
  335. case 2:
  336. strlcpy(format->name, "HD-DV", sizeof format->name);
  337. break;
  338. default:
  339. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  340. "interface %d: unknown DV format %u\n",
  341. dev->udev->devnum,
  342. alts->desc.bInterfaceNumber, buffer[8]);
  343. return -EINVAL;
  344. }
  345. strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
  346. sizeof format->name);
  347. format->fcc = V4L2_PIX_FMT_DV;
  348. format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
  349. format->bpp = 0;
  350. ftype = 0;
  351. /* Create a dummy frame descriptor. */
  352. frame = &format->frame[0];
  353. memset(&format->frame[0], 0, sizeof format->frame[0]);
  354. frame->bFrameIntervalType = 1;
  355. frame->dwDefaultFrameInterval = 1;
  356. frame->dwFrameInterval = *intervals;
  357. *(*intervals)++ = 1;
  358. format->nframes = 1;
  359. break;
  360. case UVC_VS_FORMAT_MPEG2TS:
  361. case UVC_VS_FORMAT_STREAM_BASED:
  362. /* Not supported yet. */
  363. default:
  364. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  365. "interface %d unsupported format %u\n",
  366. dev->udev->devnum, alts->desc.bInterfaceNumber,
  367. buffer[2]);
  368. return -EINVAL;
  369. }
  370. uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
  371. buflen -= buffer[0];
  372. buffer += buffer[0];
  373. /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
  374. * based formats have frame descriptors.
  375. */
  376. while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  377. buffer[2] == ftype) {
  378. frame = &format->frame[format->nframes];
  379. if (ftype != UVC_VS_FRAME_FRAME_BASED)
  380. n = buflen > 25 ? buffer[25] : 0;
  381. else
  382. n = buflen > 21 ? buffer[21] : 0;
  383. n = n ? n : 3;
  384. if (buflen < 26 + 4*n) {
  385. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  386. "interface %d FRAME error\n", dev->udev->devnum,
  387. alts->desc.bInterfaceNumber);
  388. return -EINVAL;
  389. }
  390. frame->bFrameIndex = buffer[3];
  391. frame->bmCapabilities = buffer[4];
  392. frame->wWidth = get_unaligned_le16(&buffer[5]);
  393. frame->wHeight = get_unaligned_le16(&buffer[7]);
  394. frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
  395. frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
  396. if (ftype != UVC_VS_FRAME_FRAME_BASED) {
  397. frame->dwMaxVideoFrameBufferSize =
  398. get_unaligned_le32(&buffer[17]);
  399. frame->dwDefaultFrameInterval =
  400. get_unaligned_le32(&buffer[21]);
  401. frame->bFrameIntervalType = buffer[25];
  402. } else {
  403. frame->dwMaxVideoFrameBufferSize = 0;
  404. frame->dwDefaultFrameInterval =
  405. get_unaligned_le32(&buffer[17]);
  406. frame->bFrameIntervalType = buffer[21];
  407. }
  408. frame->dwFrameInterval = *intervals;
  409. /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
  410. * completely. Observed behaviours range from setting the
  411. * value to 1.1x the actual frame size to hardwiring the
  412. * 16 low bits to 0. This results in a higher than necessary
  413. * memory usage as well as a wrong image size information. For
  414. * uncompressed formats this can be fixed by computing the
  415. * value from the frame size.
  416. */
  417. if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
  418. frame->dwMaxVideoFrameBufferSize = format->bpp
  419. * frame->wWidth * frame->wHeight / 8;
  420. /* Some bogus devices report dwMinFrameInterval equal to
  421. * dwMaxFrameInterval and have dwFrameIntervalStep set to
  422. * zero. Setting all null intervals to 1 fixes the problem and
  423. * some other divisions by zero that could happen.
  424. */
  425. for (i = 0; i < n; ++i) {
  426. interval = get_unaligned_le32(&buffer[26+4*i]);
  427. *(*intervals)++ = interval ? interval : 1;
  428. }
  429. /* Make sure that the default frame interval stays between
  430. * the boundaries.
  431. */
  432. n -= frame->bFrameIntervalType ? 1 : 2;
  433. frame->dwDefaultFrameInterval =
  434. min(frame->dwFrameInterval[n],
  435. max(frame->dwFrameInterval[0],
  436. frame->dwDefaultFrameInterval));
  437. if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
  438. frame->bFrameIntervalType = 1;
  439. frame->dwFrameInterval[0] =
  440. frame->dwDefaultFrameInterval;
  441. }
  442. uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
  443. frame->wWidth, frame->wHeight,
  444. 10000000/frame->dwDefaultFrameInterval,
  445. (100000000/frame->dwDefaultFrameInterval)%10);
  446. format->nframes++;
  447. buflen -= buffer[0];
  448. buffer += buffer[0];
  449. }
  450. if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  451. buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
  452. buflen -= buffer[0];
  453. buffer += buffer[0];
  454. }
  455. if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  456. buffer[2] == UVC_VS_COLORFORMAT) {
  457. if (buflen < 6) {
  458. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  459. "interface %d COLORFORMAT error\n",
  460. dev->udev->devnum,
  461. alts->desc.bInterfaceNumber);
  462. return -EINVAL;
  463. }
  464. format->colorspace = uvc_colorspace(buffer[3]);
  465. buflen -= buffer[0];
  466. buffer += buffer[0];
  467. }
  468. return buffer - start;
  469. }
  470. static int uvc_parse_streaming(struct uvc_device *dev,
  471. struct usb_interface *intf)
  472. {
  473. struct uvc_streaming *streaming = NULL;
  474. struct uvc_format *format;
  475. struct uvc_frame *frame;
  476. struct usb_host_interface *alts = &intf->altsetting[0];
  477. unsigned char *_buffer, *buffer = alts->extra;
  478. int _buflen, buflen = alts->extralen;
  479. unsigned int nformats = 0, nframes = 0, nintervals = 0;
  480. unsigned int size, i, n, p;
  481. __u32 *interval;
  482. __u16 psize;
  483. int ret = -EINVAL;
  484. if (intf->cur_altsetting->desc.bInterfaceSubClass
  485. != UVC_SC_VIDEOSTREAMING) {
  486. uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
  487. "video streaming interface\n", dev->udev->devnum,
  488. intf->altsetting[0].desc.bInterfaceNumber);
  489. return -EINVAL;
  490. }
  491. if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
  492. uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
  493. "claimed\n", dev->udev->devnum,
  494. intf->altsetting[0].desc.bInterfaceNumber);
  495. return -EINVAL;
  496. }
  497. streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
  498. if (streaming == NULL) {
  499. usb_driver_release_interface(&uvc_driver.driver, intf);
  500. return -EINVAL;
  501. }
  502. mutex_init(&streaming->mutex);
  503. streaming->dev = dev;
  504. streaming->intf = usb_get_intf(intf);
  505. streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  506. /* The Pico iMage webcam has its class-specific interface descriptors
  507. * after the endpoint descriptors.
  508. */
  509. if (buflen == 0) {
  510. for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
  511. struct usb_host_endpoint *ep = &alts->endpoint[i];
  512. if (ep->extralen == 0)
  513. continue;
  514. if (ep->extralen > 2 &&
  515. ep->extra[1] == USB_DT_CS_INTERFACE) {
  516. uvc_trace(UVC_TRACE_DESCR, "trying extra data "
  517. "from endpoint %u.\n", i);
  518. buffer = alts->endpoint[i].extra;
  519. buflen = alts->endpoint[i].extralen;
  520. break;
  521. }
  522. }
  523. }
  524. /* Skip the standard interface descriptors. */
  525. while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
  526. buflen -= buffer[0];
  527. buffer += buffer[0];
  528. }
  529. if (buflen <= 2) {
  530. uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
  531. "interface descriptors found.\n");
  532. goto error;
  533. }
  534. /* Parse the header descriptor. */
  535. switch (buffer[2]) {
  536. case UVC_VS_OUTPUT_HEADER:
  537. streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  538. size = 9;
  539. break;
  540. case UVC_VS_INPUT_HEADER:
  541. streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  542. size = 13;
  543. break;
  544. default:
  545. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
  546. "%d HEADER descriptor not found.\n", dev->udev->devnum,
  547. alts->desc.bInterfaceNumber);
  548. goto error;
  549. }
  550. p = buflen >= 4 ? buffer[3] : 0;
  551. n = buflen >= size ? buffer[size-1] : 0;
  552. if (buflen < size + p*n) {
  553. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  554. "interface %d HEADER descriptor is invalid.\n",
  555. dev->udev->devnum, alts->desc.bInterfaceNumber);
  556. goto error;
  557. }
  558. streaming->header.bNumFormats = p;
  559. streaming->header.bEndpointAddress = buffer[6];
  560. if (buffer[2] == UVC_VS_INPUT_HEADER) {
  561. streaming->header.bmInfo = buffer[7];
  562. streaming->header.bTerminalLink = buffer[8];
  563. streaming->header.bStillCaptureMethod = buffer[9];
  564. streaming->header.bTriggerSupport = buffer[10];
  565. streaming->header.bTriggerUsage = buffer[11];
  566. } else {
  567. streaming->header.bTerminalLink = buffer[7];
  568. }
  569. streaming->header.bControlSize = n;
  570. streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
  571. GFP_KERNEL);
  572. if (streaming->header.bmaControls == NULL) {
  573. ret = -ENOMEM;
  574. goto error;
  575. }
  576. buflen -= buffer[0];
  577. buffer += buffer[0];
  578. _buffer = buffer;
  579. _buflen = buflen;
  580. /* Count the format and frame descriptors. */
  581. while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
  582. switch (_buffer[2]) {
  583. case UVC_VS_FORMAT_UNCOMPRESSED:
  584. case UVC_VS_FORMAT_MJPEG:
  585. case UVC_VS_FORMAT_FRAME_BASED:
  586. nformats++;
  587. break;
  588. case UVC_VS_FORMAT_DV:
  589. /* DV format has no frame descriptor. We will create a
  590. * dummy frame descriptor with a dummy frame interval.
  591. */
  592. nformats++;
  593. nframes++;
  594. nintervals++;
  595. break;
  596. case UVC_VS_FORMAT_MPEG2TS:
  597. case UVC_VS_FORMAT_STREAM_BASED:
  598. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
  599. "interface %d FORMAT %u is not supported.\n",
  600. dev->udev->devnum,
  601. alts->desc.bInterfaceNumber, _buffer[2]);
  602. break;
  603. case UVC_VS_FRAME_UNCOMPRESSED:
  604. case UVC_VS_FRAME_MJPEG:
  605. nframes++;
  606. if (_buflen > 25)
  607. nintervals += _buffer[25] ? _buffer[25] : 3;
  608. break;
  609. case UVC_VS_FRAME_FRAME_BASED:
  610. nframes++;
  611. if (_buflen > 21)
  612. nintervals += _buffer[21] ? _buffer[21] : 3;
  613. break;
  614. }
  615. _buflen -= _buffer[0];
  616. _buffer += _buffer[0];
  617. }
  618. if (nformats == 0) {
  619. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
  620. "%d has no supported formats defined.\n",
  621. dev->udev->devnum, alts->desc.bInterfaceNumber);
  622. goto error;
  623. }
  624. size = nformats * sizeof *format + nframes * sizeof *frame
  625. + nintervals * sizeof *interval;
  626. format = kzalloc(size, GFP_KERNEL);
  627. if (format == NULL) {
  628. ret = -ENOMEM;
  629. goto error;
  630. }
  631. frame = (struct uvc_frame *)&format[nformats];
  632. interval = (__u32 *)&frame[nframes];
  633. streaming->format = format;
  634. streaming->nformats = nformats;
  635. /* Parse the format descriptors. */
  636. while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
  637. switch (buffer[2]) {
  638. case UVC_VS_FORMAT_UNCOMPRESSED:
  639. case UVC_VS_FORMAT_MJPEG:
  640. case UVC_VS_FORMAT_DV:
  641. case UVC_VS_FORMAT_FRAME_BASED:
  642. format->frame = frame;
  643. ret = uvc_parse_format(dev, streaming, format,
  644. &interval, buffer, buflen);
  645. if (ret < 0)
  646. goto error;
  647. frame += format->nframes;
  648. format++;
  649. buflen -= ret;
  650. buffer += ret;
  651. continue;
  652. default:
  653. break;
  654. }
  655. buflen -= buffer[0];
  656. buffer += buffer[0];
  657. }
  658. if (buflen)
  659. uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
  660. "%d has %u bytes of trailing descriptor garbage.\n",
  661. dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
  662. /* Parse the alternate settings to find the maximum bandwidth. */
  663. for (i = 0; i < intf->num_altsetting; ++i) {
  664. struct usb_host_endpoint *ep;
  665. alts = &intf->altsetting[i];
  666. ep = uvc_find_endpoint(alts,
  667. streaming->header.bEndpointAddress);
  668. if (ep == NULL)
  669. continue;
  670. psize = le16_to_cpu(ep->desc.wMaxPacketSize);
  671. psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
  672. if (psize > streaming->maxpsize)
  673. streaming->maxpsize = psize;
  674. }
  675. list_add_tail(&streaming->list, &dev->streams);
  676. return 0;
  677. error:
  678. usb_driver_release_interface(&uvc_driver.driver, intf);
  679. usb_put_intf(intf);
  680. kfree(streaming->format);
  681. kfree(streaming->header.bmaControls);
  682. kfree(streaming);
  683. return ret;
  684. }
  685. static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
  686. unsigned int num_pads, unsigned int extra_size)
  687. {
  688. struct uvc_entity *entity;
  689. unsigned int num_inputs;
  690. unsigned int size;
  691. unsigned int i;
  692. extra_size = ALIGN(extra_size, sizeof(*entity->pads));
  693. num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
  694. size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
  695. + num_inputs;
  696. entity = kzalloc(size, GFP_KERNEL);
  697. if (entity == NULL)
  698. return NULL;
  699. entity->id = id;
  700. entity->type = type;
  701. entity->num_links = 0;
  702. entity->num_pads = num_pads;
  703. entity->pads = ((void *)(entity + 1)) + extra_size;
  704. for (i = 0; i < num_inputs; ++i)
  705. entity->pads[i].flags = MEDIA_PAD_FL_SINK;
  706. if (!UVC_ENTITY_IS_OTERM(entity))
  707. entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
  708. entity->bNrInPins = num_inputs;
  709. entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
  710. return entity;
  711. }
  712. /* Parse vendor-specific extensions. */
  713. static int uvc_parse_vendor_control(struct uvc_device *dev,
  714. const unsigned char *buffer, int buflen)
  715. {
  716. struct usb_device *udev = dev->udev;
  717. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  718. struct uvc_entity *unit;
  719. unsigned int n, p;
  720. int handled = 0;
  721. switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
  722. case 0x046d: /* Logitech */
  723. if (buffer[1] != 0x41 || buffer[2] != 0x01)
  724. break;
  725. /* Logitech implements several vendor specific functions
  726. * through vendor specific extension units (LXU).
  727. *
  728. * The LXU descriptors are similar to XU descriptors
  729. * (see "USB Device Video Class for Video Devices", section
  730. * 3.7.2.6 "Extension Unit Descriptor") with the following
  731. * differences:
  732. *
  733. * ----------------------------------------------------------
  734. * 0 bLength 1 Number
  735. * Size of this descriptor, in bytes: 24+p+n*2
  736. * ----------------------------------------------------------
  737. * 23+p+n bmControlsType N Bitmap
  738. * Individual bits in the set are defined:
  739. * 0: Absolute
  740. * 1: Relative
  741. *
  742. * This bitset is mapped exactly the same as bmControls.
  743. * ----------------------------------------------------------
  744. * 23+p+n*2 bReserved 1 Boolean
  745. * ----------------------------------------------------------
  746. * 24+p+n*2 iExtension 1 Index
  747. * Index of a string descriptor that describes this
  748. * extension unit.
  749. * ----------------------------------------------------------
  750. */
  751. p = buflen >= 22 ? buffer[21] : 0;
  752. n = buflen >= 25 + p ? buffer[22+p] : 0;
  753. if (buflen < 25 + p + 2*n) {
  754. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  755. "interface %d EXTENSION_UNIT error\n",
  756. udev->devnum, alts->desc.bInterfaceNumber);
  757. break;
  758. }
  759. unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
  760. p + 1, 2*n);
  761. if (unit == NULL)
  762. return -ENOMEM;
  763. memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
  764. unit->extension.bNumControls = buffer[20];
  765. memcpy(unit->baSourceID, &buffer[22], p);
  766. unit->extension.bControlSize = buffer[22+p];
  767. unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
  768. unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
  769. + n;
  770. memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
  771. if (buffer[24+p+2*n] != 0)
  772. usb_string(udev, buffer[24+p+2*n], unit->name,
  773. sizeof unit->name);
  774. else
  775. sprintf(unit->name, "Extension %u", buffer[3]);
  776. list_add_tail(&unit->list, &dev->entities);
  777. handled = 1;
  778. break;
  779. }
  780. return handled;
  781. }
  782. static int uvc_parse_standard_control(struct uvc_device *dev,
  783. const unsigned char *buffer, int buflen)
  784. {
  785. struct usb_device *udev = dev->udev;
  786. struct uvc_entity *unit, *term;
  787. struct usb_interface *intf;
  788. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  789. unsigned int i, n, p, len;
  790. __u16 type;
  791. switch (buffer[2]) {
  792. case UVC_VC_HEADER:
  793. n = buflen >= 12 ? buffer[11] : 0;
  794. if (buflen < 12 || buflen < 12 + n) {
  795. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  796. "interface %d HEADER error\n", udev->devnum,
  797. alts->desc.bInterfaceNumber);
  798. return -EINVAL;
  799. }
  800. dev->uvc_version = get_unaligned_le16(&buffer[3]);
  801. dev->clock_frequency = get_unaligned_le32(&buffer[7]);
  802. /* Parse all USB Video Streaming interfaces. */
  803. for (i = 0; i < n; ++i) {
  804. intf = usb_ifnum_to_if(udev, buffer[12+i]);
  805. if (intf == NULL) {
  806. uvc_trace(UVC_TRACE_DESCR, "device %d "
  807. "interface %d doesn't exists\n",
  808. udev->devnum, i);
  809. continue;
  810. }
  811. uvc_parse_streaming(dev, intf);
  812. }
  813. break;
  814. case UVC_VC_INPUT_TERMINAL:
  815. if (buflen < 8) {
  816. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  817. "interface %d INPUT_TERMINAL error\n",
  818. udev->devnum, alts->desc.bInterfaceNumber);
  819. return -EINVAL;
  820. }
  821. /* Make sure the terminal type MSB is not null, otherwise it
  822. * could be confused with a unit.
  823. */
  824. type = get_unaligned_le16(&buffer[4]);
  825. if ((type & 0xff00) == 0) {
  826. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  827. "interface %d INPUT_TERMINAL %d has invalid "
  828. "type 0x%04x, skipping\n", udev->devnum,
  829. alts->desc.bInterfaceNumber,
  830. buffer[3], type);
  831. return 0;
  832. }
  833. n = 0;
  834. p = 0;
  835. len = 8;
  836. if (type == UVC_ITT_CAMERA) {
  837. n = buflen >= 15 ? buffer[14] : 0;
  838. len = 15;
  839. } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
  840. n = buflen >= 9 ? buffer[8] : 0;
  841. p = buflen >= 10 + n ? buffer[9+n] : 0;
  842. len = 10;
  843. }
  844. if (buflen < len + n + p) {
  845. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  846. "interface %d INPUT_TERMINAL error\n",
  847. udev->devnum, alts->desc.bInterfaceNumber);
  848. return -EINVAL;
  849. }
  850. term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
  851. 1, n + p);
  852. if (term == NULL)
  853. return -ENOMEM;
  854. if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
  855. term->camera.bControlSize = n;
  856. term->camera.bmControls = (__u8 *)term + sizeof *term;
  857. term->camera.wObjectiveFocalLengthMin =
  858. get_unaligned_le16(&buffer[8]);
  859. term->camera.wObjectiveFocalLengthMax =
  860. get_unaligned_le16(&buffer[10]);
  861. term->camera.wOcularFocalLength =
  862. get_unaligned_le16(&buffer[12]);
  863. memcpy(term->camera.bmControls, &buffer[15], n);
  864. } else if (UVC_ENTITY_TYPE(term) ==
  865. UVC_ITT_MEDIA_TRANSPORT_INPUT) {
  866. term->media.bControlSize = n;
  867. term->media.bmControls = (__u8 *)term + sizeof *term;
  868. term->media.bTransportModeSize = p;
  869. term->media.bmTransportModes = (__u8 *)term
  870. + sizeof *term + n;
  871. memcpy(term->media.bmControls, &buffer[9], n);
  872. memcpy(term->media.bmTransportModes, &buffer[10+n], p);
  873. }
  874. if (buffer[7] != 0)
  875. usb_string(udev, buffer[7], term->name,
  876. sizeof term->name);
  877. else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
  878. sprintf(term->name, "Camera %u", buffer[3]);
  879. else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
  880. sprintf(term->name, "Media %u", buffer[3]);
  881. else
  882. sprintf(term->name, "Input %u", buffer[3]);
  883. list_add_tail(&term->list, &dev->entities);
  884. break;
  885. case UVC_VC_OUTPUT_TERMINAL:
  886. if (buflen < 9) {
  887. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  888. "interface %d OUTPUT_TERMINAL error\n",
  889. udev->devnum, alts->desc.bInterfaceNumber);
  890. return -EINVAL;
  891. }
  892. /* Make sure the terminal type MSB is not null, otherwise it
  893. * could be confused with a unit.
  894. */
  895. type = get_unaligned_le16(&buffer[4]);
  896. if ((type & 0xff00) == 0) {
  897. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  898. "interface %d OUTPUT_TERMINAL %d has invalid "
  899. "type 0x%04x, skipping\n", udev->devnum,
  900. alts->desc.bInterfaceNumber, buffer[3], type);
  901. return 0;
  902. }
  903. term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
  904. 1, 0);
  905. if (term == NULL)
  906. return -ENOMEM;
  907. memcpy(term->baSourceID, &buffer[7], 1);
  908. if (buffer[8] != 0)
  909. usb_string(udev, buffer[8], term->name,
  910. sizeof term->name);
  911. else
  912. sprintf(term->name, "Output %u", buffer[3]);
  913. list_add_tail(&term->list, &dev->entities);
  914. break;
  915. case UVC_VC_SELECTOR_UNIT:
  916. p = buflen >= 5 ? buffer[4] : 0;
  917. if (buflen < 5 || buflen < 6 + p) {
  918. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  919. "interface %d SELECTOR_UNIT error\n",
  920. udev->devnum, alts->desc.bInterfaceNumber);
  921. return -EINVAL;
  922. }
  923. unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
  924. if (unit == NULL)
  925. return -ENOMEM;
  926. memcpy(unit->baSourceID, &buffer[5], p);
  927. if (buffer[5+p] != 0)
  928. usb_string(udev, buffer[5+p], unit->name,
  929. sizeof unit->name);
  930. else
  931. sprintf(unit->name, "Selector %u", buffer[3]);
  932. list_add_tail(&unit->list, &dev->entities);
  933. break;
  934. case UVC_VC_PROCESSING_UNIT:
  935. n = buflen >= 8 ? buffer[7] : 0;
  936. p = dev->uvc_version >= 0x0110 ? 10 : 9;
  937. if (buflen < p + n) {
  938. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  939. "interface %d PROCESSING_UNIT error\n",
  940. udev->devnum, alts->desc.bInterfaceNumber);
  941. return -EINVAL;
  942. }
  943. unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
  944. if (unit == NULL)
  945. return -ENOMEM;
  946. memcpy(unit->baSourceID, &buffer[4], 1);
  947. unit->processing.wMaxMultiplier =
  948. get_unaligned_le16(&buffer[5]);
  949. unit->processing.bControlSize = buffer[7];
  950. unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
  951. memcpy(unit->processing.bmControls, &buffer[8], n);
  952. if (dev->uvc_version >= 0x0110)
  953. unit->processing.bmVideoStandards = buffer[9+n];
  954. if (buffer[8+n] != 0)
  955. usb_string(udev, buffer[8+n], unit->name,
  956. sizeof unit->name);
  957. else
  958. sprintf(unit->name, "Processing %u", buffer[3]);
  959. list_add_tail(&unit->list, &dev->entities);
  960. break;
  961. case UVC_VC_EXTENSION_UNIT:
  962. p = buflen >= 22 ? buffer[21] : 0;
  963. n = buflen >= 24 + p ? buffer[22+p] : 0;
  964. if (buflen < 24 + p + n) {
  965. uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
  966. "interface %d EXTENSION_UNIT error\n",
  967. udev->devnum, alts->desc.bInterfaceNumber);
  968. return -EINVAL;
  969. }
  970. unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
  971. if (unit == NULL)
  972. return -ENOMEM;
  973. memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
  974. unit->extension.bNumControls = buffer[20];
  975. memcpy(unit->baSourceID, &buffer[22], p);
  976. unit->extension.bControlSize = buffer[22+p];
  977. unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
  978. memcpy(unit->extension.bmControls, &buffer[23+p], n);
  979. if (buffer[23+p+n] != 0)
  980. usb_string(udev, buffer[23+p+n], unit->name,
  981. sizeof unit->name);
  982. else
  983. sprintf(unit->name, "Extension %u", buffer[3]);
  984. list_add_tail(&unit->list, &dev->entities);
  985. break;
  986. default:
  987. uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
  988. "descriptor (%u)\n", buffer[2]);
  989. break;
  990. }
  991. return 0;
  992. }
  993. static int uvc_parse_control(struct uvc_device *dev)
  994. {
  995. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  996. unsigned char *buffer = alts->extra;
  997. int buflen = alts->extralen;
  998. int ret;
  999. /* Parse the default alternate setting only, as the UVC specification
  1000. * defines a single alternate setting, the default alternate setting
  1001. * zero.
  1002. */
  1003. while (buflen > 2) {
  1004. if (uvc_parse_vendor_control(dev, buffer, buflen) ||
  1005. buffer[1] != USB_DT_CS_INTERFACE)
  1006. goto next_descriptor;
  1007. if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
  1008. return ret;
  1009. next_descriptor:
  1010. buflen -= buffer[0];
  1011. buffer += buffer[0];
  1012. }
  1013. /* Check if the optional status endpoint is present. Built-in iSight
  1014. * webcams have an interrupt endpoint but spit proprietary data that
  1015. * don't conform to the UVC status endpoint messages. Don't try to
  1016. * handle the interrupt endpoint for those cameras.
  1017. */
  1018. if (alts->desc.bNumEndpoints == 1 &&
  1019. !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
  1020. struct usb_host_endpoint *ep = &alts->endpoint[0];
  1021. struct usb_endpoint_descriptor *desc = &ep->desc;
  1022. if (usb_endpoint_is_int_in(desc) &&
  1023. le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
  1024. desc->bInterval != 0) {
  1025. uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
  1026. "(addr %02x).\n", desc->bEndpointAddress);
  1027. dev->int_ep = ep;
  1028. }
  1029. }
  1030. return 0;
  1031. }
  1032. /* ------------------------------------------------------------------------
  1033. * UVC device scan
  1034. */
  1035. /*
  1036. * Scan the UVC descriptors to locate a chain starting at an Output Terminal
  1037. * and containing the following units:
  1038. *
  1039. * - one or more Output Terminals (USB Streaming or Display)
  1040. * - zero or one Processing Unit
  1041. * - zero, one or more single-input Selector Units
  1042. * - zero or one multiple-input Selector Units, provided all inputs are
  1043. * connected to input terminals
  1044. * - zero, one or mode single-input Extension Units
  1045. * - one or more Input Terminals (Camera, External or USB Streaming)
  1046. *
  1047. * The terminal and units must match on of the following structures:
  1048. *
  1049. * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
  1050. * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
  1051. * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
  1052. *
  1053. * +---------+ +---------+ -> OTT_*(0)
  1054. * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
  1055. * +---------+ +---------+ -> OTT_*(n)
  1056. *
  1057. * The Processing Unit and Extension Units can be in any order. Additional
  1058. * Extension Units connected to the main chain as single-unit branches are
  1059. * also supported. Single-input Selector Units are ignored.
  1060. */
  1061. static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
  1062. struct uvc_entity *entity)
  1063. {
  1064. switch (UVC_ENTITY_TYPE(entity)) {
  1065. case UVC_VC_EXTENSION_UNIT:
  1066. if (uvc_trace_param & UVC_TRACE_PROBE)
  1067. printk(" <- XU %d", entity->id);
  1068. if (entity->bNrInPins != 1) {
  1069. uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
  1070. "than 1 input pin.\n", entity->id);
  1071. return -1;
  1072. }
  1073. break;
  1074. case UVC_VC_PROCESSING_UNIT:
  1075. if (uvc_trace_param & UVC_TRACE_PROBE)
  1076. printk(" <- PU %d", entity->id);
  1077. if (chain->processing != NULL) {
  1078. uvc_trace(UVC_TRACE_DESCR, "Found multiple "
  1079. "Processing Units in chain.\n");
  1080. return -1;
  1081. }
  1082. chain->processing = entity;
  1083. break;
  1084. case UVC_VC_SELECTOR_UNIT:
  1085. if (uvc_trace_param & UVC_TRACE_PROBE)
  1086. printk(" <- SU %d", entity->id);
  1087. /* Single-input selector units are ignored. */
  1088. if (entity->bNrInPins == 1)
  1089. break;
  1090. if (chain->selector != NULL) {
  1091. uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
  1092. "Units in chain.\n");
  1093. return -1;
  1094. }
  1095. chain->selector = entity;
  1096. break;
  1097. case UVC_ITT_VENDOR_SPECIFIC:
  1098. case UVC_ITT_CAMERA:
  1099. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  1100. if (uvc_trace_param & UVC_TRACE_PROBE)
  1101. printk(" <- IT %d\n", entity->id);
  1102. break;
  1103. case UVC_OTT_VENDOR_SPECIFIC:
  1104. case UVC_OTT_DISPLAY:
  1105. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1106. if (uvc_trace_param & UVC_TRACE_PROBE)
  1107. printk(" OT %d", entity->id);
  1108. break;
  1109. case UVC_TT_STREAMING:
  1110. if (UVC_ENTITY_IS_ITERM(entity)) {
  1111. if (uvc_trace_param & UVC_TRACE_PROBE)
  1112. printk(" <- IT %d\n", entity->id);
  1113. } else {
  1114. if (uvc_trace_param & UVC_TRACE_PROBE)
  1115. printk(" OT %d", entity->id);
  1116. }
  1117. break;
  1118. default:
  1119. uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
  1120. "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
  1121. return -1;
  1122. }
  1123. list_add_tail(&entity->chain, &chain->entities);
  1124. return 0;
  1125. }
  1126. static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
  1127. struct uvc_entity *entity, struct uvc_entity *prev)
  1128. {
  1129. struct uvc_entity *forward;
  1130. int found;
  1131. /* Forward scan */
  1132. forward = NULL;
  1133. found = 0;
  1134. while (1) {
  1135. forward = uvc_entity_by_reference(chain->dev, entity->id,
  1136. forward);
  1137. if (forward == NULL)
  1138. break;
  1139. if (forward == prev)
  1140. continue;
  1141. switch (UVC_ENTITY_TYPE(forward)) {
  1142. case UVC_VC_EXTENSION_UNIT:
  1143. if (forward->bNrInPins != 1) {
  1144. uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
  1145. "has more than 1 input pin.\n",
  1146. entity->id);
  1147. return -EINVAL;
  1148. }
  1149. list_add_tail(&forward->chain, &chain->entities);
  1150. if (uvc_trace_param & UVC_TRACE_PROBE) {
  1151. if (!found)
  1152. printk(" (->");
  1153. printk(" XU %d", forward->id);
  1154. found = 1;
  1155. }
  1156. break;
  1157. case UVC_OTT_VENDOR_SPECIFIC:
  1158. case UVC_OTT_DISPLAY:
  1159. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1160. case UVC_TT_STREAMING:
  1161. if (UVC_ENTITY_IS_ITERM(forward)) {
  1162. uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
  1163. "terminal %u.\n", forward->id);
  1164. return -EINVAL;
  1165. }
  1166. list_add_tail(&forward->chain, &chain->entities);
  1167. if (uvc_trace_param & UVC_TRACE_PROBE) {
  1168. if (!found)
  1169. printk(" (->");
  1170. printk(" OT %d", forward->id);
  1171. found = 1;
  1172. }
  1173. break;
  1174. }
  1175. }
  1176. if (found)
  1177. printk(")");
  1178. return 0;
  1179. }
  1180. static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
  1181. struct uvc_entity **_entity)
  1182. {
  1183. struct uvc_entity *entity = *_entity;
  1184. struct uvc_entity *term;
  1185. int id = -EINVAL, i;
  1186. switch (UVC_ENTITY_TYPE(entity)) {
  1187. case UVC_VC_EXTENSION_UNIT:
  1188. case UVC_VC_PROCESSING_UNIT:
  1189. id = entity->baSourceID[0];
  1190. break;
  1191. case UVC_VC_SELECTOR_UNIT:
  1192. /* Single-input selector units are ignored. */
  1193. if (entity->bNrInPins == 1) {
  1194. id = entity->baSourceID[0];
  1195. break;
  1196. }
  1197. if (uvc_trace_param & UVC_TRACE_PROBE)
  1198. printk(" <- IT");
  1199. chain->selector = entity;
  1200. for (i = 0; i < entity->bNrInPins; ++i) {
  1201. id = entity->baSourceID[i];
  1202. term = uvc_entity_by_id(chain->dev, id);
  1203. if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
  1204. uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
  1205. "input %d isn't connected to an "
  1206. "input terminal\n", entity->id, i);
  1207. return -1;
  1208. }
  1209. if (uvc_trace_param & UVC_TRACE_PROBE)
  1210. printk(" %d", term->id);
  1211. list_add_tail(&term->chain, &chain->entities);
  1212. uvc_scan_chain_forward(chain, term, entity);
  1213. }
  1214. if (uvc_trace_param & UVC_TRACE_PROBE)
  1215. printk("\n");
  1216. id = 0;
  1217. break;
  1218. case UVC_ITT_VENDOR_SPECIFIC:
  1219. case UVC_ITT_CAMERA:
  1220. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  1221. case UVC_OTT_VENDOR_SPECIFIC:
  1222. case UVC_OTT_DISPLAY:
  1223. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1224. case UVC_TT_STREAMING:
  1225. id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
  1226. break;
  1227. }
  1228. if (id <= 0) {
  1229. *_entity = NULL;
  1230. return id;
  1231. }
  1232. entity = uvc_entity_by_id(chain->dev, id);
  1233. if (entity == NULL) {
  1234. uvc_trace(UVC_TRACE_DESCR, "Found reference to "
  1235. "unknown entity %d.\n", id);
  1236. return -EINVAL;
  1237. }
  1238. *_entity = entity;
  1239. return 0;
  1240. }
  1241. static int uvc_scan_chain(struct uvc_video_chain *chain,
  1242. struct uvc_entity *term)
  1243. {
  1244. struct uvc_entity *entity, *prev;
  1245. uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
  1246. entity = term;
  1247. prev = NULL;
  1248. while (entity != NULL) {
  1249. /* Entity must not be part of an existing chain */
  1250. if (entity->chain.next || entity->chain.prev) {
  1251. uvc_trace(UVC_TRACE_DESCR, "Found reference to "
  1252. "entity %d already in chain.\n", entity->id);
  1253. return -EINVAL;
  1254. }
  1255. /* Process entity */
  1256. if (uvc_scan_chain_entity(chain, entity) < 0)
  1257. return -EINVAL;
  1258. /* Forward scan */
  1259. if (uvc_scan_chain_forward(chain, entity, prev) < 0)
  1260. return -EINVAL;
  1261. /* Backward scan */
  1262. prev = entity;
  1263. if (uvc_scan_chain_backward(chain, &entity) < 0)
  1264. return -EINVAL;
  1265. }
  1266. return 0;
  1267. }
  1268. static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
  1269. char *buffer)
  1270. {
  1271. struct uvc_entity *term;
  1272. unsigned int nterms = 0;
  1273. char *p = buffer;
  1274. list_for_each_entry(term, terms, chain) {
  1275. if (!UVC_ENTITY_IS_TERM(term) ||
  1276. UVC_TERM_DIRECTION(term) != dir)
  1277. continue;
  1278. if (nterms)
  1279. p += sprintf(p, ",");
  1280. if (++nterms >= 4) {
  1281. p += sprintf(p, "...");
  1282. break;
  1283. }
  1284. p += sprintf(p, "%u", term->id);
  1285. }
  1286. return p - buffer;
  1287. }
  1288. static const char *uvc_print_chain(struct uvc_video_chain *chain)
  1289. {
  1290. static char buffer[43];
  1291. char *p = buffer;
  1292. p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
  1293. p += sprintf(p, " -> ");
  1294. uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
  1295. return buffer;
  1296. }
  1297. /*
  1298. * Scan the device for video chains and register video devices.
  1299. *
  1300. * Chains are scanned starting at their output terminals and walked backwards.
  1301. */
  1302. static int uvc_scan_device(struct uvc_device *dev)
  1303. {
  1304. struct uvc_video_chain *chain;
  1305. struct uvc_entity *term;
  1306. list_for_each_entry(term, &dev->entities, list) {
  1307. if (!UVC_ENTITY_IS_OTERM(term))
  1308. continue;
  1309. /* If the terminal is already included in a chain, skip it.
  1310. * This can happen for chains that have multiple output
  1311. * terminals, where all output terminals beside the first one
  1312. * will be inserted in the chain in forward scans.
  1313. */
  1314. if (term->chain.next || term->chain.prev)
  1315. continue;
  1316. chain = kzalloc(sizeof(*chain), GFP_KERNEL);
  1317. if (chain == NULL)
  1318. return -ENOMEM;
  1319. INIT_LIST_HEAD(&chain->entities);
  1320. mutex_init(&chain->ctrl_mutex);
  1321. chain->dev = dev;
  1322. if (uvc_scan_chain(chain, term) < 0) {
  1323. kfree(chain);
  1324. continue;
  1325. }
  1326. uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
  1327. uvc_print_chain(chain));
  1328. list_add_tail(&chain->list, &dev->chains);
  1329. }
  1330. if (list_empty(&dev->chains)) {
  1331. uvc_printk(KERN_INFO, "No valid video chain found.\n");
  1332. return -1;
  1333. }
  1334. return 0;
  1335. }
  1336. /* ------------------------------------------------------------------------
  1337. * Video device registration and unregistration
  1338. */
  1339. /*
  1340. * Delete the UVC device.
  1341. *
  1342. * Called by the kernel when the last reference to the uvc_device structure
  1343. * is released.
  1344. *
  1345. * As this function is called after or during disconnect(), all URBs have
  1346. * already been canceled by the USB core. There is no need to kill the
  1347. * interrupt URB manually.
  1348. */
  1349. static void uvc_delete(struct uvc_device *dev)
  1350. {
  1351. struct list_head *p, *n;
  1352. usb_put_intf(dev->intf);
  1353. usb_put_dev(dev->udev);
  1354. uvc_status_cleanup(dev);
  1355. uvc_ctrl_cleanup_device(dev);
  1356. if (dev->vdev.dev)
  1357. v4l2_device_unregister(&dev->vdev);
  1358. #ifdef CONFIG_MEDIA_CONTROLLER
  1359. if (media_devnode_is_registered(&dev->mdev.devnode))
  1360. media_device_unregister(&dev->mdev);
  1361. #endif
  1362. list_for_each_safe(p, n, &dev->chains) {
  1363. struct uvc_video_chain *chain;
  1364. chain = list_entry(p, struct uvc_video_chain, list);
  1365. kfree(chain);
  1366. }
  1367. list_for_each_safe(p, n, &dev->entities) {
  1368. struct uvc_entity *entity;
  1369. entity = list_entry(p, struct uvc_entity, list);
  1370. #ifdef CONFIG_MEDIA_CONTROLLER
  1371. uvc_mc_cleanup_entity(entity);
  1372. #endif
  1373. if (entity->vdev) {
  1374. video_device_release(entity->vdev);
  1375. entity->vdev = NULL;
  1376. }
  1377. kfree(entity);
  1378. }
  1379. list_for_each_safe(p, n, &dev->streams) {
  1380. struct uvc_streaming *streaming;
  1381. streaming = list_entry(p, struct uvc_streaming, list);
  1382. usb_driver_release_interface(&uvc_driver.driver,
  1383. streaming->intf);
  1384. usb_put_intf(streaming->intf);
  1385. kfree(streaming->format);
  1386. kfree(streaming->header.bmaControls);
  1387. kfree(streaming);
  1388. }
  1389. kfree(dev);
  1390. }
  1391. static void uvc_release(struct video_device *vdev)
  1392. {
  1393. struct uvc_streaming *stream = video_get_drvdata(vdev);
  1394. struct uvc_device *dev = stream->dev;
  1395. /* Decrement the registered streams count and delete the device when it
  1396. * reaches zero.
  1397. */
  1398. if (atomic_dec_and_test(&dev->nstreams))
  1399. uvc_delete(dev);
  1400. }
  1401. /*
  1402. * Unregister the video devices.
  1403. */
  1404. static void uvc_unregister_video(struct uvc_device *dev)
  1405. {
  1406. struct uvc_streaming *stream;
  1407. /* Unregistering all video devices might result in uvc_delete() being
  1408. * called from inside the loop if there's no open file handle. To avoid
  1409. * that, increment the stream count before iterating over the streams
  1410. * and decrement it when done.
  1411. */
  1412. atomic_inc(&dev->nstreams);
  1413. list_for_each_entry(stream, &dev->streams, list) {
  1414. if (stream->vdev == NULL)
  1415. continue;
  1416. video_unregister_device(stream->vdev);
  1417. stream->vdev = NULL;
  1418. }
  1419. /* Decrement the stream count and call uvc_delete explicitly if there
  1420. * are no stream left.
  1421. */
  1422. if (atomic_dec_and_test(&dev->nstreams))
  1423. uvc_delete(dev);
  1424. }
  1425. static int uvc_register_video(struct uvc_device *dev,
  1426. struct uvc_streaming *stream)
  1427. {
  1428. struct video_device *vdev;
  1429. int ret;
  1430. /* Initialize the streaming interface with default streaming
  1431. * parameters.
  1432. */
  1433. ret = uvc_video_init(stream);
  1434. if (ret < 0) {
  1435. uvc_printk(KERN_ERR, "Failed to initialize the device "
  1436. "(%d).\n", ret);
  1437. return ret;
  1438. }
  1439. /* Register the device with V4L. */
  1440. vdev = video_device_alloc();
  1441. if (vdev == NULL) {
  1442. uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
  1443. ret);
  1444. return -ENOMEM;
  1445. }
  1446. /* We already hold a reference to dev->udev. The video device will be
  1447. * unregistered before the reference is released, so we don't need to
  1448. * get another one.
  1449. */
  1450. vdev->v4l2_dev = &dev->vdev;
  1451. vdev->fops = &uvc_fops;
  1452. vdev->release = uvc_release;
  1453. strlcpy(vdev->name, dev->name, sizeof vdev->name);
  1454. /* Set the driver data before calling video_register_device, otherwise
  1455. * uvc_v4l2_open might race us.
  1456. */
  1457. stream->vdev = vdev;
  1458. video_set_drvdata(vdev, stream);
  1459. ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
  1460. if (ret < 0) {
  1461. uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
  1462. ret);
  1463. stream->vdev = NULL;
  1464. video_device_release(vdev);
  1465. return ret;
  1466. }
  1467. atomic_inc(&dev->nstreams);
  1468. return 0;
  1469. }
  1470. /*
  1471. * Register all video devices in all chains.
  1472. */
  1473. static int uvc_register_terms(struct uvc_device *dev,
  1474. struct uvc_video_chain *chain)
  1475. {
  1476. struct uvc_streaming *stream;
  1477. struct uvc_entity *term;
  1478. int ret;
  1479. list_for_each_entry(term, &chain->entities, chain) {
  1480. if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
  1481. continue;
  1482. stream = uvc_stream_by_id(dev, term->id);
  1483. if (stream == NULL) {
  1484. uvc_printk(KERN_INFO, "No streaming interface found "
  1485. "for terminal %u.", term->id);
  1486. continue;
  1487. }
  1488. stream->chain = chain;
  1489. ret = uvc_register_video(dev, stream);
  1490. if (ret < 0)
  1491. return ret;
  1492. term->vdev = stream->vdev;
  1493. }
  1494. return 0;
  1495. }
  1496. static int uvc_register_chains(struct uvc_device *dev)
  1497. {
  1498. struct uvc_video_chain *chain;
  1499. int ret;
  1500. list_for_each_entry(chain, &dev->chains, list) {
  1501. ret = uvc_register_terms(dev, chain);
  1502. if (ret < 0)
  1503. return ret;
  1504. #ifdef CONFIG_MEDIA_CONTROLLER
  1505. ret = uvc_mc_register_entities(chain);
  1506. if (ret < 0) {
  1507. uvc_printk(KERN_INFO, "Failed to register entites "
  1508. "(%d).\n", ret);
  1509. }
  1510. #endif
  1511. }
  1512. return 0;
  1513. }
  1514. /* ------------------------------------------------------------------------
  1515. * USB probe, disconnect, suspend and resume
  1516. */
  1517. static int uvc_probe(struct usb_interface *intf,
  1518. const struct usb_device_id *id)
  1519. {
  1520. struct usb_device *udev = interface_to_usbdev(intf);
  1521. struct uvc_device *dev;
  1522. int ret;
  1523. if (id->idVendor && id->idProduct)
  1524. uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
  1525. "(%04x:%04x)\n", udev->devpath, id->idVendor,
  1526. id->idProduct);
  1527. else
  1528. uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
  1529. udev->devpath);
  1530. /* Allocate memory for the device and initialize it. */
  1531. if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
  1532. return -ENOMEM;
  1533. INIT_LIST_HEAD(&dev->entities);
  1534. INIT_LIST_HEAD(&dev->chains);
  1535. INIT_LIST_HEAD(&dev->streams);
  1536. atomic_set(&dev->nstreams, 0);
  1537. atomic_set(&dev->users, 0);
  1538. atomic_set(&dev->nmappings, 0);
  1539. dev->udev = usb_get_dev(udev);
  1540. dev->intf = usb_get_intf(intf);
  1541. dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  1542. dev->quirks = (uvc_quirks_param == -1)
  1543. ? id->driver_info : uvc_quirks_param;
  1544. if (udev->product != NULL)
  1545. strlcpy(dev->name, udev->product, sizeof dev->name);
  1546. else
  1547. snprintf(dev->name, sizeof dev->name,
  1548. "UVC Camera (%04x:%04x)",
  1549. le16_to_cpu(udev->descriptor.idVendor),
  1550. le16_to_cpu(udev->descriptor.idProduct));
  1551. /* Parse the Video Class control descriptor. */
  1552. if (uvc_parse_control(dev) < 0) {
  1553. uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
  1554. "descriptors.\n");
  1555. goto error;
  1556. }
  1557. uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
  1558. dev->uvc_version >> 8, dev->uvc_version & 0xff,
  1559. udev->product ? udev->product : "<unnamed>",
  1560. le16_to_cpu(udev->descriptor.idVendor),
  1561. le16_to_cpu(udev->descriptor.idProduct));
  1562. if (dev->quirks != id->driver_info) {
  1563. uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
  1564. "parameter for testing purpose.\n", dev->quirks);
  1565. uvc_printk(KERN_INFO, "Please report required quirks to the "
  1566. "linux-uvc-devel mailing list.\n");
  1567. }
  1568. /* Register the media and V4L2 devices. */
  1569. #ifdef CONFIG_MEDIA_CONTROLLER
  1570. dev->mdev.dev = &intf->dev;
  1571. strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
  1572. if (udev->serial)
  1573. strlcpy(dev->mdev.serial, udev->serial,
  1574. sizeof(dev->mdev.serial));
  1575. strcpy(dev->mdev.bus_info, udev->devpath);
  1576. dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
  1577. dev->mdev.driver_version = LINUX_VERSION_CODE;
  1578. if (media_device_register(&dev->mdev) < 0)
  1579. goto error;
  1580. dev->vdev.mdev = &dev->mdev;
  1581. #endif
  1582. if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
  1583. goto error;
  1584. /* Initialize controls. */
  1585. if (uvc_ctrl_init_device(dev) < 0)
  1586. goto error;
  1587. /* Scan the device for video chains. */
  1588. if (uvc_scan_device(dev) < 0)
  1589. goto error;
  1590. /* Register video device nodes. */
  1591. if (uvc_register_chains(dev) < 0)
  1592. goto error;
  1593. /* Save our data pointer in the interface data. */
  1594. usb_set_intfdata(intf, dev);
  1595. /* Initialize the interrupt URB. */
  1596. if ((ret = uvc_status_init(dev)) < 0) {
  1597. uvc_printk(KERN_INFO, "Unable to initialize the status "
  1598. "endpoint (%d), status interrupt will not be "
  1599. "supported.\n", ret);
  1600. }
  1601. uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
  1602. usb_enable_autosuspend(udev);
  1603. return 0;
  1604. error:
  1605. uvc_unregister_video(dev);
  1606. return -ENODEV;
  1607. }
  1608. static void uvc_disconnect(struct usb_interface *intf)
  1609. {
  1610. struct uvc_device *dev = usb_get_intfdata(intf);
  1611. /* Set the USB interface data to NULL. This can be done outside the
  1612. * lock, as there's no other reader.
  1613. */
  1614. usb_set_intfdata(intf, NULL);
  1615. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1616. UVC_SC_VIDEOSTREAMING)
  1617. return;
  1618. dev->state |= UVC_DEV_DISCONNECTED;
  1619. uvc_unregister_video(dev);
  1620. }
  1621. static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
  1622. {
  1623. struct uvc_device *dev = usb_get_intfdata(intf);
  1624. struct uvc_streaming *stream;
  1625. uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
  1626. intf->cur_altsetting->desc.bInterfaceNumber);
  1627. /* Controls are cached on the fly so they don't need to be saved. */
  1628. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1629. UVC_SC_VIDEOCONTROL)
  1630. return uvc_status_suspend(dev);
  1631. list_for_each_entry(stream, &dev->streams, list) {
  1632. if (stream->intf == intf)
  1633. return uvc_video_suspend(stream);
  1634. }
  1635. uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
  1636. "mismatch.\n");
  1637. return -EINVAL;
  1638. }
  1639. static int __uvc_resume(struct usb_interface *intf, int reset)
  1640. {
  1641. struct uvc_device *dev = usb_get_intfdata(intf);
  1642. struct uvc_streaming *stream;
  1643. uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
  1644. intf->cur_altsetting->desc.bInterfaceNumber);
  1645. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1646. UVC_SC_VIDEOCONTROL) {
  1647. if (reset) {
  1648. int ret = uvc_ctrl_resume_device(dev);
  1649. if (ret < 0)
  1650. return ret;
  1651. }
  1652. return uvc_status_resume(dev);
  1653. }
  1654. list_for_each_entry(stream, &dev->streams, list) {
  1655. if (stream->intf == intf)
  1656. return uvc_video_resume(stream, reset);
  1657. }
  1658. uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
  1659. "mismatch.\n");
  1660. return -EINVAL;
  1661. }
  1662. static int uvc_resume(struct usb_interface *intf)
  1663. {
  1664. return __uvc_resume(intf, 0);
  1665. }
  1666. static int uvc_reset_resume(struct usb_interface *intf)
  1667. {
  1668. return __uvc_resume(intf, 1);
  1669. }
  1670. /* ------------------------------------------------------------------------
  1671. * Module parameters
  1672. */
  1673. static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
  1674. {
  1675. if (uvc_clock_param == CLOCK_MONOTONIC)
  1676. return sprintf(buffer, "CLOCK_MONOTONIC");
  1677. else
  1678. return sprintf(buffer, "CLOCK_REALTIME");
  1679. }
  1680. static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
  1681. {
  1682. if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
  1683. val += strlen("clock_");
  1684. if (strcasecmp(val, "monotonic") == 0)
  1685. uvc_clock_param = CLOCK_MONOTONIC;
  1686. else if (strcasecmp(val, "realtime") == 0)
  1687. uvc_clock_param = CLOCK_REALTIME;
  1688. else
  1689. return -EINVAL;
  1690. return 0;
  1691. }
  1692. module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
  1693. &uvc_clock_param, S_IRUGO|S_IWUSR);
  1694. MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
  1695. module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
  1696. MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
  1697. module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
  1698. MODULE_PARM_DESC(quirks, "Forced device quirks");
  1699. module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
  1700. MODULE_PARM_DESC(trace, "Trace level bitmask");
  1701. module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
  1702. MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
  1703. /* ------------------------------------------------------------------------
  1704. * Driver initialization and cleanup
  1705. */
  1706. /*
  1707. * The Logitech cameras listed below have their interface class set to
  1708. * VENDOR_SPEC because they don't announce themselves as UVC devices, even
  1709. * though they are compliant.
  1710. */
  1711. static struct usb_device_id uvc_ids[] = {
  1712. /* Genius eFace 2025 */
  1713. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1714. | USB_DEVICE_ID_MATCH_INT_INFO,
  1715. .idVendor = 0x0458,
  1716. .idProduct = 0x706e,
  1717. .bInterfaceClass = USB_CLASS_VIDEO,
  1718. .bInterfaceSubClass = 1,
  1719. .bInterfaceProtocol = 0,
  1720. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1721. /* Microsoft Lifecam NX-6000 */
  1722. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1723. | USB_DEVICE_ID_MATCH_INT_INFO,
  1724. .idVendor = 0x045e,
  1725. .idProduct = 0x00f8,
  1726. .bInterfaceClass = USB_CLASS_VIDEO,
  1727. .bInterfaceSubClass = 1,
  1728. .bInterfaceProtocol = 0,
  1729. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1730. /* Microsoft Lifecam VX-7000 */
  1731. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1732. | USB_DEVICE_ID_MATCH_INT_INFO,
  1733. .idVendor = 0x045e,
  1734. .idProduct = 0x0723,
  1735. .bInterfaceClass = USB_CLASS_VIDEO,
  1736. .bInterfaceSubClass = 1,
  1737. .bInterfaceProtocol = 0,
  1738. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1739. /* Logitech Quickcam Fusion */
  1740. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1741. | USB_DEVICE_ID_MATCH_INT_INFO,
  1742. .idVendor = 0x046d,
  1743. .idProduct = 0x08c1,
  1744. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1745. .bInterfaceSubClass = 1,
  1746. .bInterfaceProtocol = 0 },
  1747. /* Logitech Quickcam Orbit MP */
  1748. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1749. | USB_DEVICE_ID_MATCH_INT_INFO,
  1750. .idVendor = 0x046d,
  1751. .idProduct = 0x08c2,
  1752. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1753. .bInterfaceSubClass = 1,
  1754. .bInterfaceProtocol = 0 },
  1755. /* Logitech Quickcam Pro for Notebook */
  1756. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1757. | USB_DEVICE_ID_MATCH_INT_INFO,
  1758. .idVendor = 0x046d,
  1759. .idProduct = 0x08c3,
  1760. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1761. .bInterfaceSubClass = 1,
  1762. .bInterfaceProtocol = 0 },
  1763. /* Logitech Quickcam Pro 5000 */
  1764. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1765. | USB_DEVICE_ID_MATCH_INT_INFO,
  1766. .idVendor = 0x046d,
  1767. .idProduct = 0x08c5,
  1768. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1769. .bInterfaceSubClass = 1,
  1770. .bInterfaceProtocol = 0 },
  1771. /* Logitech Quickcam OEM Dell Notebook */
  1772. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1773. | USB_DEVICE_ID_MATCH_INT_INFO,
  1774. .idVendor = 0x046d,
  1775. .idProduct = 0x08c6,
  1776. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1777. .bInterfaceSubClass = 1,
  1778. .bInterfaceProtocol = 0 },
  1779. /* Logitech Quickcam OEM Cisco VT Camera II */
  1780. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1781. | USB_DEVICE_ID_MATCH_INT_INFO,
  1782. .idVendor = 0x046d,
  1783. .idProduct = 0x08c7,
  1784. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1785. .bInterfaceSubClass = 1,
  1786. .bInterfaceProtocol = 0 },
  1787. /* Chicony CNF7129 (Asus EEE 100HE) */
  1788. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1789. | USB_DEVICE_ID_MATCH_INT_INFO,
  1790. .idVendor = 0x04f2,
  1791. .idProduct = 0xb071,
  1792. .bInterfaceClass = USB_CLASS_VIDEO,
  1793. .bInterfaceSubClass = 1,
  1794. .bInterfaceProtocol = 0,
  1795. .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
  1796. /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
  1797. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1798. | USB_DEVICE_ID_MATCH_INT_INFO,
  1799. .idVendor = 0x058f,
  1800. .idProduct = 0x3820,
  1801. .bInterfaceClass = USB_CLASS_VIDEO,
  1802. .bInterfaceSubClass = 1,
  1803. .bInterfaceProtocol = 0,
  1804. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1805. /* Apple Built-In iSight */
  1806. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1807. | USB_DEVICE_ID_MATCH_INT_INFO,
  1808. .idVendor = 0x05ac,
  1809. .idProduct = 0x8501,
  1810. .bInterfaceClass = USB_CLASS_VIDEO,
  1811. .bInterfaceSubClass = 1,
  1812. .bInterfaceProtocol = 0,
  1813. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1814. | UVC_QUIRK_BUILTIN_ISIGHT },
  1815. /* Foxlink ("HP Webcam" on HP Mini 5103) */
  1816. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1817. | USB_DEVICE_ID_MATCH_INT_INFO,
  1818. .idVendor = 0x05c8,
  1819. .idProduct = 0x0403,
  1820. .bInterfaceClass = USB_CLASS_VIDEO,
  1821. .bInterfaceSubClass = 1,
  1822. .bInterfaceProtocol = 0,
  1823. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1824. /* Genesys Logic USB 2.0 PC Camera */
  1825. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1826. | USB_DEVICE_ID_MATCH_INT_INFO,
  1827. .idVendor = 0x05e3,
  1828. .idProduct = 0x0505,
  1829. .bInterfaceClass = USB_CLASS_VIDEO,
  1830. .bInterfaceSubClass = 1,
  1831. .bInterfaceProtocol = 0,
  1832. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1833. /* Hercules Classic Silver */
  1834. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1835. | USB_DEVICE_ID_MATCH_INT_INFO,
  1836. .idVendor = 0x06f8,
  1837. .idProduct = 0x300c,
  1838. .bInterfaceClass = USB_CLASS_VIDEO,
  1839. .bInterfaceSubClass = 1,
  1840. .bInterfaceProtocol = 0,
  1841. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1842. /* ViMicro Vega */
  1843. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1844. | USB_DEVICE_ID_MATCH_INT_INFO,
  1845. .idVendor = 0x0ac8,
  1846. .idProduct = 0x332d,
  1847. .bInterfaceClass = USB_CLASS_VIDEO,
  1848. .bInterfaceSubClass = 1,
  1849. .bInterfaceProtocol = 0,
  1850. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1851. /* ViMicro - Minoru3D */
  1852. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1853. | USB_DEVICE_ID_MATCH_INT_INFO,
  1854. .idVendor = 0x0ac8,
  1855. .idProduct = 0x3410,
  1856. .bInterfaceClass = USB_CLASS_VIDEO,
  1857. .bInterfaceSubClass = 1,
  1858. .bInterfaceProtocol = 0,
  1859. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1860. /* ViMicro Venus - Minoru3D */
  1861. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1862. | USB_DEVICE_ID_MATCH_INT_INFO,
  1863. .idVendor = 0x0ac8,
  1864. .idProduct = 0x3420,
  1865. .bInterfaceClass = USB_CLASS_VIDEO,
  1866. .bInterfaceSubClass = 1,
  1867. .bInterfaceProtocol = 0,
  1868. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1869. /* MT6227 */
  1870. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1871. | USB_DEVICE_ID_MATCH_INT_INFO,
  1872. .idVendor = 0x0e8d,
  1873. .idProduct = 0x0004,
  1874. .bInterfaceClass = USB_CLASS_VIDEO,
  1875. .bInterfaceSubClass = 1,
  1876. .bInterfaceProtocol = 0,
  1877. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1878. | UVC_QUIRK_PROBE_DEF },
  1879. /* IMC Networks (Medion Akoya) */
  1880. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1881. | USB_DEVICE_ID_MATCH_INT_INFO,
  1882. .idVendor = 0x13d3,
  1883. .idProduct = 0x5103,
  1884. .bInterfaceClass = USB_CLASS_VIDEO,
  1885. .bInterfaceSubClass = 1,
  1886. .bInterfaceProtocol = 0,
  1887. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1888. /* JMicron USB2.0 XGA WebCam */
  1889. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1890. | USB_DEVICE_ID_MATCH_INT_INFO,
  1891. .idVendor = 0x152d,
  1892. .idProduct = 0x0310,
  1893. .bInterfaceClass = USB_CLASS_VIDEO,
  1894. .bInterfaceSubClass = 1,
  1895. .bInterfaceProtocol = 0,
  1896. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1897. /* Syntek (HP Spartan) */
  1898. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1899. | USB_DEVICE_ID_MATCH_INT_INFO,
  1900. .idVendor = 0x174f,
  1901. .idProduct = 0x5212,
  1902. .bInterfaceClass = USB_CLASS_VIDEO,
  1903. .bInterfaceSubClass = 1,
  1904. .bInterfaceProtocol = 0,
  1905. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1906. /* Syntek (Samsung Q310) */
  1907. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1908. | USB_DEVICE_ID_MATCH_INT_INFO,
  1909. .idVendor = 0x174f,
  1910. .idProduct = 0x5931,
  1911. .bInterfaceClass = USB_CLASS_VIDEO,
  1912. .bInterfaceSubClass = 1,
  1913. .bInterfaceProtocol = 0,
  1914. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1915. /* Syntek (Packard Bell EasyNote MX52 */
  1916. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1917. | USB_DEVICE_ID_MATCH_INT_INFO,
  1918. .idVendor = 0x174f,
  1919. .idProduct = 0x8a12,
  1920. .bInterfaceClass = USB_CLASS_VIDEO,
  1921. .bInterfaceSubClass = 1,
  1922. .bInterfaceProtocol = 0,
  1923. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1924. /* Syntek (Asus F9SG) */
  1925. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1926. | USB_DEVICE_ID_MATCH_INT_INFO,
  1927. .idVendor = 0x174f,
  1928. .idProduct = 0x8a31,
  1929. .bInterfaceClass = USB_CLASS_VIDEO,
  1930. .bInterfaceSubClass = 1,
  1931. .bInterfaceProtocol = 0,
  1932. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1933. /* Syntek (Asus U3S) */
  1934. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1935. | USB_DEVICE_ID_MATCH_INT_INFO,
  1936. .idVendor = 0x174f,
  1937. .idProduct = 0x8a33,
  1938. .bInterfaceClass = USB_CLASS_VIDEO,
  1939. .bInterfaceSubClass = 1,
  1940. .bInterfaceProtocol = 0,
  1941. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1942. /* Syntek (JAOtech Smart Terminal) */
  1943. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1944. | USB_DEVICE_ID_MATCH_INT_INFO,
  1945. .idVendor = 0x174f,
  1946. .idProduct = 0x8a34,
  1947. .bInterfaceClass = USB_CLASS_VIDEO,
  1948. .bInterfaceSubClass = 1,
  1949. .bInterfaceProtocol = 0,
  1950. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1951. /* Miricle 307K */
  1952. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1953. | USB_DEVICE_ID_MATCH_INT_INFO,
  1954. .idVendor = 0x17dc,
  1955. .idProduct = 0x0202,
  1956. .bInterfaceClass = USB_CLASS_VIDEO,
  1957. .bInterfaceSubClass = 1,
  1958. .bInterfaceProtocol = 0,
  1959. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1960. /* Lenovo Thinkpad SL400/SL500 */
  1961. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1962. | USB_DEVICE_ID_MATCH_INT_INFO,
  1963. .idVendor = 0x17ef,
  1964. .idProduct = 0x480b,
  1965. .bInterfaceClass = USB_CLASS_VIDEO,
  1966. .bInterfaceSubClass = 1,
  1967. .bInterfaceProtocol = 0,
  1968. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1969. /* Aveo Technology USB 2.0 Camera */
  1970. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1971. | USB_DEVICE_ID_MATCH_INT_INFO,
  1972. .idVendor = 0x1871,
  1973. .idProduct = 0x0306,
  1974. .bInterfaceClass = USB_CLASS_VIDEO,
  1975. .bInterfaceSubClass = 1,
  1976. .bInterfaceProtocol = 0,
  1977. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1978. | UVC_QUIRK_PROBE_EXTRAFIELDS },
  1979. /* Ecamm Pico iMage */
  1980. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1981. | USB_DEVICE_ID_MATCH_INT_INFO,
  1982. .idVendor = 0x18cd,
  1983. .idProduct = 0xcafe,
  1984. .bInterfaceClass = USB_CLASS_VIDEO,
  1985. .bInterfaceSubClass = 1,
  1986. .bInterfaceProtocol = 0,
  1987. .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
  1988. /* Manta MM-353 Plako */
  1989. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1990. | USB_DEVICE_ID_MATCH_INT_INFO,
  1991. .idVendor = 0x18ec,
  1992. .idProduct = 0x3188,
  1993. .bInterfaceClass = USB_CLASS_VIDEO,
  1994. .bInterfaceSubClass = 1,
  1995. .bInterfaceProtocol = 0,
  1996. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1997. /* FSC WebCam V30S */
  1998. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1999. | USB_DEVICE_ID_MATCH_INT_INFO,
  2000. .idVendor = 0x18ec,
  2001. .idProduct = 0x3288,
  2002. .bInterfaceClass = USB_CLASS_VIDEO,
  2003. .bInterfaceSubClass = 1,
  2004. .bInterfaceProtocol = 0,
  2005. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  2006. /* Arkmicro unbranded */
  2007. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2008. | USB_DEVICE_ID_MATCH_INT_INFO,
  2009. .idVendor = 0x18ec,
  2010. .idProduct = 0x3290,
  2011. .bInterfaceClass = USB_CLASS_VIDEO,
  2012. .bInterfaceSubClass = 1,
  2013. .bInterfaceProtocol = 0,
  2014. .driver_info = UVC_QUIRK_PROBE_DEF },
  2015. /* The Imaging Source USB CCD cameras */
  2016. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2017. | USB_DEVICE_ID_MATCH_INT_INFO,
  2018. .idVendor = 0x199e,
  2019. .idProduct = 0x8102,
  2020. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2021. .bInterfaceSubClass = 1,
  2022. .bInterfaceProtocol = 0 },
  2023. /* Bodelin ProScopeHR */
  2024. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2025. | USB_DEVICE_ID_MATCH_DEV_HI
  2026. | USB_DEVICE_ID_MATCH_INT_INFO,
  2027. .idVendor = 0x19ab,
  2028. .idProduct = 0x1000,
  2029. .bcdDevice_hi = 0x0126,
  2030. .bInterfaceClass = USB_CLASS_VIDEO,
  2031. .bInterfaceSubClass = 1,
  2032. .bInterfaceProtocol = 0,
  2033. .driver_info = UVC_QUIRK_STATUS_INTERVAL },
  2034. /* MSI StarCam 370i */
  2035. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2036. | USB_DEVICE_ID_MATCH_INT_INFO,
  2037. .idVendor = 0x1b3b,
  2038. .idProduct = 0x2951,
  2039. .bInterfaceClass = USB_CLASS_VIDEO,
  2040. .bInterfaceSubClass = 1,
  2041. .bInterfaceProtocol = 0,
  2042. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  2043. /* SiGma Micro USB Web Camera */
  2044. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2045. | USB_DEVICE_ID_MATCH_INT_INFO,
  2046. .idVendor = 0x1c4f,
  2047. .idProduct = 0x3000,
  2048. .bInterfaceClass = USB_CLASS_VIDEO,
  2049. .bInterfaceSubClass = 1,
  2050. .bInterfaceProtocol = 0,
  2051. .driver_info = UVC_QUIRK_PROBE_MINMAX
  2052. | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
  2053. /* Generic USB Video Class */
  2054. { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
  2055. {}
  2056. };
  2057. MODULE_DEVICE_TABLE(usb, uvc_ids);
  2058. struct uvc_driver uvc_driver = {
  2059. .driver = {
  2060. .name = "uvcvideo",
  2061. .probe = uvc_probe,
  2062. .disconnect = uvc_disconnect,
  2063. .suspend = uvc_suspend,
  2064. .resume = uvc_resume,
  2065. .reset_resume = uvc_reset_resume,
  2066. .id_table = uvc_ids,
  2067. .supports_autosuspend = 1,
  2068. },
  2069. };
  2070. static int __init uvc_init(void)
  2071. {
  2072. int result;
  2073. result = usb_register(&uvc_driver.driver);
  2074. if (result == 0)
  2075. printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
  2076. return result;
  2077. }
  2078. static void __exit uvc_cleanup(void)
  2079. {
  2080. usb_deregister(&uvc_driver.driver);
  2081. }
  2082. module_init(uvc_init);
  2083. module_exit(uvc_cleanup);
  2084. MODULE_AUTHOR(DRIVER_AUTHOR);
  2085. MODULE_DESCRIPTION(DRIVER_DESC);
  2086. MODULE_LICENSE("GPL");
  2087. MODULE_VERSION(DRIVER_VERSION);