uvc_driver.c 66 KB

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