uvc_driver.c 64 KB

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