uvc_driver.c 64 KB

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