uvc_driver.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439
  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. uvc_debugfs_cleanup_stream(stream);
  1419. }
  1420. /* Decrement the stream count and call uvc_delete explicitly if there
  1421. * are no stream left.
  1422. */
  1423. if (atomic_dec_and_test(&dev->nstreams))
  1424. uvc_delete(dev);
  1425. }
  1426. static int uvc_register_video(struct uvc_device *dev,
  1427. struct uvc_streaming *stream)
  1428. {
  1429. struct video_device *vdev;
  1430. int ret;
  1431. /* Initialize the streaming interface with default streaming
  1432. * parameters.
  1433. */
  1434. ret = uvc_video_init(stream);
  1435. if (ret < 0) {
  1436. uvc_printk(KERN_ERR, "Failed to initialize the device "
  1437. "(%d).\n", ret);
  1438. return ret;
  1439. }
  1440. uvc_debugfs_init_stream(stream);
  1441. /* Register the device with V4L. */
  1442. vdev = video_device_alloc();
  1443. if (vdev == NULL) {
  1444. uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
  1445. ret);
  1446. return -ENOMEM;
  1447. }
  1448. /* We already hold a reference to dev->udev. The video device will be
  1449. * unregistered before the reference is released, so we don't need to
  1450. * get another one.
  1451. */
  1452. vdev->v4l2_dev = &dev->vdev;
  1453. vdev->fops = &uvc_fops;
  1454. vdev->release = uvc_release;
  1455. strlcpy(vdev->name, dev->name, sizeof vdev->name);
  1456. /* Set the driver data before calling video_register_device, otherwise
  1457. * uvc_v4l2_open might race us.
  1458. */
  1459. stream->vdev = vdev;
  1460. video_set_drvdata(vdev, stream);
  1461. ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
  1462. if (ret < 0) {
  1463. uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
  1464. ret);
  1465. stream->vdev = NULL;
  1466. video_device_release(vdev);
  1467. return ret;
  1468. }
  1469. atomic_inc(&dev->nstreams);
  1470. return 0;
  1471. }
  1472. /*
  1473. * Register all video devices in all chains.
  1474. */
  1475. static int uvc_register_terms(struct uvc_device *dev,
  1476. struct uvc_video_chain *chain)
  1477. {
  1478. struct uvc_streaming *stream;
  1479. struct uvc_entity *term;
  1480. int ret;
  1481. list_for_each_entry(term, &chain->entities, chain) {
  1482. if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
  1483. continue;
  1484. stream = uvc_stream_by_id(dev, term->id);
  1485. if (stream == NULL) {
  1486. uvc_printk(KERN_INFO, "No streaming interface found "
  1487. "for terminal %u.", term->id);
  1488. continue;
  1489. }
  1490. stream->chain = chain;
  1491. ret = uvc_register_video(dev, stream);
  1492. if (ret < 0)
  1493. return ret;
  1494. term->vdev = stream->vdev;
  1495. }
  1496. return 0;
  1497. }
  1498. static int uvc_register_chains(struct uvc_device *dev)
  1499. {
  1500. struct uvc_video_chain *chain;
  1501. int ret;
  1502. list_for_each_entry(chain, &dev->chains, list) {
  1503. ret = uvc_register_terms(dev, chain);
  1504. if (ret < 0)
  1505. return ret;
  1506. #ifdef CONFIG_MEDIA_CONTROLLER
  1507. ret = uvc_mc_register_entities(chain);
  1508. if (ret < 0) {
  1509. uvc_printk(KERN_INFO, "Failed to register entites "
  1510. "(%d).\n", ret);
  1511. }
  1512. #endif
  1513. }
  1514. return 0;
  1515. }
  1516. /* ------------------------------------------------------------------------
  1517. * USB probe, disconnect, suspend and resume
  1518. */
  1519. static int uvc_probe(struct usb_interface *intf,
  1520. const struct usb_device_id *id)
  1521. {
  1522. struct usb_device *udev = interface_to_usbdev(intf);
  1523. struct uvc_device *dev;
  1524. int ret;
  1525. if (id->idVendor && id->idProduct)
  1526. uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
  1527. "(%04x:%04x)\n", udev->devpath, id->idVendor,
  1528. id->idProduct);
  1529. else
  1530. uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
  1531. udev->devpath);
  1532. /* Allocate memory for the device and initialize it. */
  1533. if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
  1534. return -ENOMEM;
  1535. INIT_LIST_HEAD(&dev->entities);
  1536. INIT_LIST_HEAD(&dev->chains);
  1537. INIT_LIST_HEAD(&dev->streams);
  1538. atomic_set(&dev->nstreams, 0);
  1539. atomic_set(&dev->users, 0);
  1540. atomic_set(&dev->nmappings, 0);
  1541. dev->udev = usb_get_dev(udev);
  1542. dev->intf = usb_get_intf(intf);
  1543. dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  1544. dev->quirks = (uvc_quirks_param == -1)
  1545. ? id->driver_info : uvc_quirks_param;
  1546. if (udev->product != NULL)
  1547. strlcpy(dev->name, udev->product, sizeof dev->name);
  1548. else
  1549. snprintf(dev->name, sizeof dev->name,
  1550. "UVC Camera (%04x:%04x)",
  1551. le16_to_cpu(udev->descriptor.idVendor),
  1552. le16_to_cpu(udev->descriptor.idProduct));
  1553. /* Parse the Video Class control descriptor. */
  1554. if (uvc_parse_control(dev) < 0) {
  1555. uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
  1556. "descriptors.\n");
  1557. goto error;
  1558. }
  1559. uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
  1560. dev->uvc_version >> 8, dev->uvc_version & 0xff,
  1561. udev->product ? udev->product : "<unnamed>",
  1562. le16_to_cpu(udev->descriptor.idVendor),
  1563. le16_to_cpu(udev->descriptor.idProduct));
  1564. if (dev->quirks != id->driver_info) {
  1565. uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
  1566. "parameter for testing purpose.\n", dev->quirks);
  1567. uvc_printk(KERN_INFO, "Please report required quirks to the "
  1568. "linux-uvc-devel mailing list.\n");
  1569. }
  1570. /* Register the media and V4L2 devices. */
  1571. #ifdef CONFIG_MEDIA_CONTROLLER
  1572. dev->mdev.dev = &intf->dev;
  1573. strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
  1574. if (udev->serial)
  1575. strlcpy(dev->mdev.serial, udev->serial,
  1576. sizeof(dev->mdev.serial));
  1577. strcpy(dev->mdev.bus_info, udev->devpath);
  1578. dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
  1579. dev->mdev.driver_version = LINUX_VERSION_CODE;
  1580. if (media_device_register(&dev->mdev) < 0)
  1581. goto error;
  1582. dev->vdev.mdev = &dev->mdev;
  1583. #endif
  1584. if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
  1585. goto error;
  1586. /* Initialize controls. */
  1587. if (uvc_ctrl_init_device(dev) < 0)
  1588. goto error;
  1589. /* Scan the device for video chains. */
  1590. if (uvc_scan_device(dev) < 0)
  1591. goto error;
  1592. /* Register video device nodes. */
  1593. if (uvc_register_chains(dev) < 0)
  1594. goto error;
  1595. /* Save our data pointer in the interface data. */
  1596. usb_set_intfdata(intf, dev);
  1597. /* Initialize the interrupt URB. */
  1598. if ((ret = uvc_status_init(dev)) < 0) {
  1599. uvc_printk(KERN_INFO, "Unable to initialize the status "
  1600. "endpoint (%d), status interrupt will not be "
  1601. "supported.\n", ret);
  1602. }
  1603. uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
  1604. usb_enable_autosuspend(udev);
  1605. return 0;
  1606. error:
  1607. uvc_unregister_video(dev);
  1608. return -ENODEV;
  1609. }
  1610. static void uvc_disconnect(struct usb_interface *intf)
  1611. {
  1612. struct uvc_device *dev = usb_get_intfdata(intf);
  1613. /* Set the USB interface data to NULL. This can be done outside the
  1614. * lock, as there's no other reader.
  1615. */
  1616. usb_set_intfdata(intf, NULL);
  1617. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1618. UVC_SC_VIDEOSTREAMING)
  1619. return;
  1620. dev->state |= UVC_DEV_DISCONNECTED;
  1621. uvc_unregister_video(dev);
  1622. }
  1623. static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
  1624. {
  1625. struct uvc_device *dev = usb_get_intfdata(intf);
  1626. struct uvc_streaming *stream;
  1627. uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
  1628. intf->cur_altsetting->desc.bInterfaceNumber);
  1629. /* Controls are cached on the fly so they don't need to be saved. */
  1630. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1631. UVC_SC_VIDEOCONTROL)
  1632. return uvc_status_suspend(dev);
  1633. list_for_each_entry(stream, &dev->streams, list) {
  1634. if (stream->intf == intf)
  1635. return uvc_video_suspend(stream);
  1636. }
  1637. uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
  1638. "mismatch.\n");
  1639. return -EINVAL;
  1640. }
  1641. static int __uvc_resume(struct usb_interface *intf, int reset)
  1642. {
  1643. struct uvc_device *dev = usb_get_intfdata(intf);
  1644. struct uvc_streaming *stream;
  1645. uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
  1646. intf->cur_altsetting->desc.bInterfaceNumber);
  1647. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1648. UVC_SC_VIDEOCONTROL) {
  1649. if (reset) {
  1650. int ret = uvc_ctrl_resume_device(dev);
  1651. if (ret < 0)
  1652. return ret;
  1653. }
  1654. return uvc_status_resume(dev);
  1655. }
  1656. list_for_each_entry(stream, &dev->streams, list) {
  1657. if (stream->intf == intf)
  1658. return uvc_video_resume(stream, reset);
  1659. }
  1660. uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
  1661. "mismatch.\n");
  1662. return -EINVAL;
  1663. }
  1664. static int uvc_resume(struct usb_interface *intf)
  1665. {
  1666. return __uvc_resume(intf, 0);
  1667. }
  1668. static int uvc_reset_resume(struct usb_interface *intf)
  1669. {
  1670. return __uvc_resume(intf, 1);
  1671. }
  1672. /* ------------------------------------------------------------------------
  1673. * Module parameters
  1674. */
  1675. static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
  1676. {
  1677. if (uvc_clock_param == CLOCK_MONOTONIC)
  1678. return sprintf(buffer, "CLOCK_MONOTONIC");
  1679. else
  1680. return sprintf(buffer, "CLOCK_REALTIME");
  1681. }
  1682. static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
  1683. {
  1684. if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
  1685. val += strlen("clock_");
  1686. if (strcasecmp(val, "monotonic") == 0)
  1687. uvc_clock_param = CLOCK_MONOTONIC;
  1688. else if (strcasecmp(val, "realtime") == 0)
  1689. uvc_clock_param = CLOCK_REALTIME;
  1690. else
  1691. return -EINVAL;
  1692. return 0;
  1693. }
  1694. module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
  1695. &uvc_clock_param, S_IRUGO|S_IWUSR);
  1696. MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
  1697. module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
  1698. MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
  1699. module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
  1700. MODULE_PARM_DESC(quirks, "Forced device quirks");
  1701. module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
  1702. MODULE_PARM_DESC(trace, "Trace level bitmask");
  1703. module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
  1704. MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
  1705. /* ------------------------------------------------------------------------
  1706. * Driver initialization and cleanup
  1707. */
  1708. /*
  1709. * The Logitech cameras listed below have their interface class set to
  1710. * VENDOR_SPEC because they don't announce themselves as UVC devices, even
  1711. * though they are compliant.
  1712. */
  1713. static struct usb_device_id uvc_ids[] = {
  1714. /* LogiLink Wireless Webcam */
  1715. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1716. | USB_DEVICE_ID_MATCH_INT_INFO,
  1717. .idVendor = 0x0416,
  1718. .idProduct = 0xa91a,
  1719. .bInterfaceClass = USB_CLASS_VIDEO,
  1720. .bInterfaceSubClass = 1,
  1721. .bInterfaceProtocol = 0,
  1722. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1723. /* Genius eFace 2025 */
  1724. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1725. | USB_DEVICE_ID_MATCH_INT_INFO,
  1726. .idVendor = 0x0458,
  1727. .idProduct = 0x706e,
  1728. .bInterfaceClass = USB_CLASS_VIDEO,
  1729. .bInterfaceSubClass = 1,
  1730. .bInterfaceProtocol = 0,
  1731. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1732. /* Microsoft Lifecam NX-6000 */
  1733. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1734. | USB_DEVICE_ID_MATCH_INT_INFO,
  1735. .idVendor = 0x045e,
  1736. .idProduct = 0x00f8,
  1737. .bInterfaceClass = USB_CLASS_VIDEO,
  1738. .bInterfaceSubClass = 1,
  1739. .bInterfaceProtocol = 0,
  1740. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1741. /* Microsoft Lifecam VX-7000 */
  1742. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1743. | USB_DEVICE_ID_MATCH_INT_INFO,
  1744. .idVendor = 0x045e,
  1745. .idProduct = 0x0723,
  1746. .bInterfaceClass = USB_CLASS_VIDEO,
  1747. .bInterfaceSubClass = 1,
  1748. .bInterfaceProtocol = 0,
  1749. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1750. /* Logitech Quickcam Fusion */
  1751. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1752. | USB_DEVICE_ID_MATCH_INT_INFO,
  1753. .idVendor = 0x046d,
  1754. .idProduct = 0x08c1,
  1755. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1756. .bInterfaceSubClass = 1,
  1757. .bInterfaceProtocol = 0 },
  1758. /* Logitech Quickcam Orbit MP */
  1759. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1760. | USB_DEVICE_ID_MATCH_INT_INFO,
  1761. .idVendor = 0x046d,
  1762. .idProduct = 0x08c2,
  1763. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1764. .bInterfaceSubClass = 1,
  1765. .bInterfaceProtocol = 0 },
  1766. /* Logitech Quickcam Pro for Notebook */
  1767. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1768. | USB_DEVICE_ID_MATCH_INT_INFO,
  1769. .idVendor = 0x046d,
  1770. .idProduct = 0x08c3,
  1771. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1772. .bInterfaceSubClass = 1,
  1773. .bInterfaceProtocol = 0 },
  1774. /* Logitech Quickcam Pro 5000 */
  1775. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1776. | USB_DEVICE_ID_MATCH_INT_INFO,
  1777. .idVendor = 0x046d,
  1778. .idProduct = 0x08c5,
  1779. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1780. .bInterfaceSubClass = 1,
  1781. .bInterfaceProtocol = 0 },
  1782. /* Logitech Quickcam OEM Dell Notebook */
  1783. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1784. | USB_DEVICE_ID_MATCH_INT_INFO,
  1785. .idVendor = 0x046d,
  1786. .idProduct = 0x08c6,
  1787. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1788. .bInterfaceSubClass = 1,
  1789. .bInterfaceProtocol = 0 },
  1790. /* Logitech Quickcam OEM Cisco VT Camera II */
  1791. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1792. | USB_DEVICE_ID_MATCH_INT_INFO,
  1793. .idVendor = 0x046d,
  1794. .idProduct = 0x08c7,
  1795. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1796. .bInterfaceSubClass = 1,
  1797. .bInterfaceProtocol = 0 },
  1798. /* Chicony CNF7129 (Asus EEE 100HE) */
  1799. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1800. | USB_DEVICE_ID_MATCH_INT_INFO,
  1801. .idVendor = 0x04f2,
  1802. .idProduct = 0xb071,
  1803. .bInterfaceClass = USB_CLASS_VIDEO,
  1804. .bInterfaceSubClass = 1,
  1805. .bInterfaceProtocol = 0,
  1806. .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
  1807. /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
  1808. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1809. | USB_DEVICE_ID_MATCH_INT_INFO,
  1810. .idVendor = 0x058f,
  1811. .idProduct = 0x3820,
  1812. .bInterfaceClass = USB_CLASS_VIDEO,
  1813. .bInterfaceSubClass = 1,
  1814. .bInterfaceProtocol = 0,
  1815. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1816. /* Apple Built-In iSight */
  1817. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1818. | USB_DEVICE_ID_MATCH_INT_INFO,
  1819. .idVendor = 0x05ac,
  1820. .idProduct = 0x8501,
  1821. .bInterfaceClass = USB_CLASS_VIDEO,
  1822. .bInterfaceSubClass = 1,
  1823. .bInterfaceProtocol = 0,
  1824. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1825. | UVC_QUIRK_BUILTIN_ISIGHT },
  1826. /* Foxlink ("HP Webcam" on HP Mini 5103) */
  1827. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1828. | USB_DEVICE_ID_MATCH_INT_INFO,
  1829. .idVendor = 0x05c8,
  1830. .idProduct = 0x0403,
  1831. .bInterfaceClass = USB_CLASS_VIDEO,
  1832. .bInterfaceSubClass = 1,
  1833. .bInterfaceProtocol = 0,
  1834. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1835. /* Genesys Logic USB 2.0 PC Camera */
  1836. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1837. | USB_DEVICE_ID_MATCH_INT_INFO,
  1838. .idVendor = 0x05e3,
  1839. .idProduct = 0x0505,
  1840. .bInterfaceClass = USB_CLASS_VIDEO,
  1841. .bInterfaceSubClass = 1,
  1842. .bInterfaceProtocol = 0,
  1843. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1844. /* Hercules Classic Silver */
  1845. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1846. | USB_DEVICE_ID_MATCH_INT_INFO,
  1847. .idVendor = 0x06f8,
  1848. .idProduct = 0x300c,
  1849. .bInterfaceClass = USB_CLASS_VIDEO,
  1850. .bInterfaceSubClass = 1,
  1851. .bInterfaceProtocol = 0,
  1852. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1853. /* ViMicro Vega */
  1854. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1855. | USB_DEVICE_ID_MATCH_INT_INFO,
  1856. .idVendor = 0x0ac8,
  1857. .idProduct = 0x332d,
  1858. .bInterfaceClass = USB_CLASS_VIDEO,
  1859. .bInterfaceSubClass = 1,
  1860. .bInterfaceProtocol = 0,
  1861. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1862. /* ViMicro - Minoru3D */
  1863. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1864. | USB_DEVICE_ID_MATCH_INT_INFO,
  1865. .idVendor = 0x0ac8,
  1866. .idProduct = 0x3410,
  1867. .bInterfaceClass = USB_CLASS_VIDEO,
  1868. .bInterfaceSubClass = 1,
  1869. .bInterfaceProtocol = 0,
  1870. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1871. /* ViMicro Venus - Minoru3D */
  1872. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1873. | USB_DEVICE_ID_MATCH_INT_INFO,
  1874. .idVendor = 0x0ac8,
  1875. .idProduct = 0x3420,
  1876. .bInterfaceClass = USB_CLASS_VIDEO,
  1877. .bInterfaceSubClass = 1,
  1878. .bInterfaceProtocol = 0,
  1879. .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
  1880. /* MT6227 */
  1881. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1882. | USB_DEVICE_ID_MATCH_INT_INFO,
  1883. .idVendor = 0x0e8d,
  1884. .idProduct = 0x0004,
  1885. .bInterfaceClass = USB_CLASS_VIDEO,
  1886. .bInterfaceSubClass = 1,
  1887. .bInterfaceProtocol = 0,
  1888. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1889. | UVC_QUIRK_PROBE_DEF },
  1890. /* IMC Networks (Medion Akoya) */
  1891. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1892. | USB_DEVICE_ID_MATCH_INT_INFO,
  1893. .idVendor = 0x13d3,
  1894. .idProduct = 0x5103,
  1895. .bInterfaceClass = USB_CLASS_VIDEO,
  1896. .bInterfaceSubClass = 1,
  1897. .bInterfaceProtocol = 0,
  1898. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1899. /* JMicron USB2.0 XGA WebCam */
  1900. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1901. | USB_DEVICE_ID_MATCH_INT_INFO,
  1902. .idVendor = 0x152d,
  1903. .idProduct = 0x0310,
  1904. .bInterfaceClass = USB_CLASS_VIDEO,
  1905. .bInterfaceSubClass = 1,
  1906. .bInterfaceProtocol = 0,
  1907. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  1908. /* Syntek (HP Spartan) */
  1909. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1910. | USB_DEVICE_ID_MATCH_INT_INFO,
  1911. .idVendor = 0x174f,
  1912. .idProduct = 0x5212,
  1913. .bInterfaceClass = USB_CLASS_VIDEO,
  1914. .bInterfaceSubClass = 1,
  1915. .bInterfaceProtocol = 0,
  1916. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1917. /* Syntek (Samsung Q310) */
  1918. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1919. | USB_DEVICE_ID_MATCH_INT_INFO,
  1920. .idVendor = 0x174f,
  1921. .idProduct = 0x5931,
  1922. .bInterfaceClass = USB_CLASS_VIDEO,
  1923. .bInterfaceSubClass = 1,
  1924. .bInterfaceProtocol = 0,
  1925. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1926. /* Syntek (Packard Bell EasyNote MX52 */
  1927. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1928. | USB_DEVICE_ID_MATCH_INT_INFO,
  1929. .idVendor = 0x174f,
  1930. .idProduct = 0x8a12,
  1931. .bInterfaceClass = USB_CLASS_VIDEO,
  1932. .bInterfaceSubClass = 1,
  1933. .bInterfaceProtocol = 0,
  1934. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1935. /* Syntek (Asus F9SG) */
  1936. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1937. | USB_DEVICE_ID_MATCH_INT_INFO,
  1938. .idVendor = 0x174f,
  1939. .idProduct = 0x8a31,
  1940. .bInterfaceClass = USB_CLASS_VIDEO,
  1941. .bInterfaceSubClass = 1,
  1942. .bInterfaceProtocol = 0,
  1943. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1944. /* Syntek (Asus U3S) */
  1945. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1946. | USB_DEVICE_ID_MATCH_INT_INFO,
  1947. .idVendor = 0x174f,
  1948. .idProduct = 0x8a33,
  1949. .bInterfaceClass = USB_CLASS_VIDEO,
  1950. .bInterfaceSubClass = 1,
  1951. .bInterfaceProtocol = 0,
  1952. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1953. /* Syntek (JAOtech Smart Terminal) */
  1954. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1955. | USB_DEVICE_ID_MATCH_INT_INFO,
  1956. .idVendor = 0x174f,
  1957. .idProduct = 0x8a34,
  1958. .bInterfaceClass = USB_CLASS_VIDEO,
  1959. .bInterfaceSubClass = 1,
  1960. .bInterfaceProtocol = 0,
  1961. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1962. /* Miricle 307K */
  1963. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1964. | USB_DEVICE_ID_MATCH_INT_INFO,
  1965. .idVendor = 0x17dc,
  1966. .idProduct = 0x0202,
  1967. .bInterfaceClass = USB_CLASS_VIDEO,
  1968. .bInterfaceSubClass = 1,
  1969. .bInterfaceProtocol = 0,
  1970. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1971. /* Lenovo Thinkpad SL400/SL500 */
  1972. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1973. | USB_DEVICE_ID_MATCH_INT_INFO,
  1974. .idVendor = 0x17ef,
  1975. .idProduct = 0x480b,
  1976. .bInterfaceClass = USB_CLASS_VIDEO,
  1977. .bInterfaceSubClass = 1,
  1978. .bInterfaceProtocol = 0,
  1979. .driver_info = UVC_QUIRK_STREAM_NO_FID },
  1980. /* Aveo Technology USB 2.0 Camera */
  1981. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1982. | USB_DEVICE_ID_MATCH_INT_INFO,
  1983. .idVendor = 0x1871,
  1984. .idProduct = 0x0306,
  1985. .bInterfaceClass = USB_CLASS_VIDEO,
  1986. .bInterfaceSubClass = 1,
  1987. .bInterfaceProtocol = 0,
  1988. .driver_info = UVC_QUIRK_PROBE_MINMAX
  1989. | UVC_QUIRK_PROBE_EXTRAFIELDS },
  1990. /* Ecamm Pico iMage */
  1991. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  1992. | USB_DEVICE_ID_MATCH_INT_INFO,
  1993. .idVendor = 0x18cd,
  1994. .idProduct = 0xcafe,
  1995. .bInterfaceClass = USB_CLASS_VIDEO,
  1996. .bInterfaceSubClass = 1,
  1997. .bInterfaceProtocol = 0,
  1998. .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
  1999. /* Manta MM-353 Plako */
  2000. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2001. | USB_DEVICE_ID_MATCH_INT_INFO,
  2002. .idVendor = 0x18ec,
  2003. .idProduct = 0x3188,
  2004. .bInterfaceClass = USB_CLASS_VIDEO,
  2005. .bInterfaceSubClass = 1,
  2006. .bInterfaceProtocol = 0,
  2007. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  2008. /* FSC WebCam V30S */
  2009. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2010. | USB_DEVICE_ID_MATCH_INT_INFO,
  2011. .idVendor = 0x18ec,
  2012. .idProduct = 0x3288,
  2013. .bInterfaceClass = USB_CLASS_VIDEO,
  2014. .bInterfaceSubClass = 1,
  2015. .bInterfaceProtocol = 0,
  2016. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  2017. /* Arkmicro unbranded */
  2018. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2019. | USB_DEVICE_ID_MATCH_INT_INFO,
  2020. .idVendor = 0x18ec,
  2021. .idProduct = 0x3290,
  2022. .bInterfaceClass = USB_CLASS_VIDEO,
  2023. .bInterfaceSubClass = 1,
  2024. .bInterfaceProtocol = 0,
  2025. .driver_info = UVC_QUIRK_PROBE_DEF },
  2026. /* The Imaging Source USB CCD cameras */
  2027. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2028. | USB_DEVICE_ID_MATCH_INT_INFO,
  2029. .idVendor = 0x199e,
  2030. .idProduct = 0x8102,
  2031. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2032. .bInterfaceSubClass = 1,
  2033. .bInterfaceProtocol = 0 },
  2034. /* Bodelin ProScopeHR */
  2035. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2036. | USB_DEVICE_ID_MATCH_DEV_HI
  2037. | USB_DEVICE_ID_MATCH_INT_INFO,
  2038. .idVendor = 0x19ab,
  2039. .idProduct = 0x1000,
  2040. .bcdDevice_hi = 0x0126,
  2041. .bInterfaceClass = USB_CLASS_VIDEO,
  2042. .bInterfaceSubClass = 1,
  2043. .bInterfaceProtocol = 0,
  2044. .driver_info = UVC_QUIRK_STATUS_INTERVAL },
  2045. /* MSI StarCam 370i */
  2046. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2047. | USB_DEVICE_ID_MATCH_INT_INFO,
  2048. .idVendor = 0x1b3b,
  2049. .idProduct = 0x2951,
  2050. .bInterfaceClass = USB_CLASS_VIDEO,
  2051. .bInterfaceSubClass = 1,
  2052. .bInterfaceProtocol = 0,
  2053. .driver_info = UVC_QUIRK_PROBE_MINMAX },
  2054. /* SiGma Micro USB Web Camera */
  2055. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2056. | USB_DEVICE_ID_MATCH_INT_INFO,
  2057. .idVendor = 0x1c4f,
  2058. .idProduct = 0x3000,
  2059. .bInterfaceClass = USB_CLASS_VIDEO,
  2060. .bInterfaceSubClass = 1,
  2061. .bInterfaceProtocol = 0,
  2062. .driver_info = UVC_QUIRK_PROBE_MINMAX
  2063. | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
  2064. /* Generic USB Video Class */
  2065. { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
  2066. {}
  2067. };
  2068. MODULE_DEVICE_TABLE(usb, uvc_ids);
  2069. struct uvc_driver uvc_driver = {
  2070. .driver = {
  2071. .name = "uvcvideo",
  2072. .probe = uvc_probe,
  2073. .disconnect = uvc_disconnect,
  2074. .suspend = uvc_suspend,
  2075. .resume = uvc_resume,
  2076. .reset_resume = uvc_reset_resume,
  2077. .id_table = uvc_ids,
  2078. .supports_autosuspend = 1,
  2079. },
  2080. };
  2081. static int __init uvc_init(void)
  2082. {
  2083. int ret;
  2084. uvc_debugfs_init();
  2085. ret = usb_register(&uvc_driver.driver);
  2086. if (ret < 0) {
  2087. uvc_debugfs_cleanup();
  2088. return ret;
  2089. }
  2090. printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
  2091. return 0;
  2092. }
  2093. static void __exit uvc_cleanup(void)
  2094. {
  2095. usb_deregister(&uvc_driver.driver);
  2096. uvc_debugfs_cleanup();
  2097. }
  2098. module_init(uvc_init);
  2099. module_exit(uvc_cleanup);
  2100. MODULE_AUTHOR(DRIVER_AUTHOR);
  2101. MODULE_DESCRIPTION(DRIVER_DESC);
  2102. MODULE_LICENSE("GPL");
  2103. MODULE_VERSION(DRIVER_VERSION);