uvc_driver.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * uvc_driver.c -- USB Video Class driver
  4. *
  5. * Copyright (C) 2005-2010
  6. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  7. */
  8. #include <linux/atomic.h>
  9. #include <linux/bits.h>
  10. #include <linux/gpio/consumer.h>
  11. #include <linux/kernel.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/usb.h>
  16. #include <linux/usb/quirks.h>
  17. #include <linux/usb/uvc.h>
  18. #include <linux/videodev2.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/wait.h>
  21. #include <linux/unaligned.h>
  22. #include <media/v4l2-common.h>
  23. #include <media/v4l2-ioctl.h>
  24. #include "uvcvideo.h"
  25. #define DRIVER_AUTHOR "Laurent Pinchart " \
  26. "<laurent.pinchart@ideasonboard.com>"
  27. #define DRIVER_DESC "USB Video Class driver"
  28. unsigned int uvc_clock_param = CLOCK_MONOTONIC;
  29. unsigned int uvc_hw_timestamps_param;
  30. unsigned int uvc_no_drop_param = 1;
  31. static unsigned int uvc_quirks_param = -1;
  32. unsigned int uvc_dbg_param;
  33. unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
  34. static struct usb_driver uvc_driver;
  35. /* ------------------------------------------------------------------------
  36. * Utility functions
  37. */
  38. struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
  39. u8 epaddr)
  40. {
  41. struct usb_host_endpoint *ep;
  42. unsigned int i;
  43. for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
  44. ep = &alts->endpoint[i];
  45. if (ep->desc.bEndpointAddress == epaddr)
  46. return ep;
  47. }
  48. return NULL;
  49. }
  50. static enum v4l2_colorspace uvc_colorspace(const u8 primaries)
  51. {
  52. static const enum v4l2_colorspace colorprimaries[] = {
  53. V4L2_COLORSPACE_SRGB, /* Unspecified */
  54. V4L2_COLORSPACE_SRGB,
  55. V4L2_COLORSPACE_470_SYSTEM_M,
  56. V4L2_COLORSPACE_470_SYSTEM_BG,
  57. V4L2_COLORSPACE_SMPTE170M,
  58. V4L2_COLORSPACE_SMPTE240M,
  59. };
  60. if (primaries < ARRAY_SIZE(colorprimaries))
  61. return colorprimaries[primaries];
  62. return V4L2_COLORSPACE_SRGB; /* Reserved */
  63. }
  64. static enum v4l2_xfer_func uvc_xfer_func(const u8 transfer_characteristics)
  65. {
  66. /*
  67. * V4L2 does not currently have definitions for all possible values of
  68. * UVC transfer characteristics. If v4l2_xfer_func is extended with new
  69. * values, the mapping below should be updated.
  70. *
  71. * Substitutions are taken from the mapping given for
  72. * V4L2_XFER_FUNC_DEFAULT documented in videodev2.h.
  73. */
  74. static const enum v4l2_xfer_func xfer_funcs[] = {
  75. V4L2_XFER_FUNC_DEFAULT, /* Unspecified */
  76. V4L2_XFER_FUNC_709,
  77. V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 M */
  78. V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 B, G */
  79. V4L2_XFER_FUNC_709, /* Substitution for SMPTE 170M */
  80. V4L2_XFER_FUNC_SMPTE240M,
  81. V4L2_XFER_FUNC_NONE,
  82. V4L2_XFER_FUNC_SRGB,
  83. };
  84. if (transfer_characteristics < ARRAY_SIZE(xfer_funcs))
  85. return xfer_funcs[transfer_characteristics];
  86. return V4L2_XFER_FUNC_DEFAULT; /* Reserved */
  87. }
  88. static enum v4l2_ycbcr_encoding uvc_ycbcr_enc(const u8 matrix_coefficients)
  89. {
  90. /*
  91. * V4L2 does not currently have definitions for all possible values of
  92. * UVC matrix coefficients. If v4l2_ycbcr_encoding is extended with new
  93. * values, the mapping below should be updated.
  94. *
  95. * Substitutions are taken from the mapping given for
  96. * V4L2_YCBCR_ENC_DEFAULT documented in videodev2.h.
  97. *
  98. * FCC is assumed to be close enough to 601.
  99. */
  100. static const enum v4l2_ycbcr_encoding ycbcr_encs[] = {
  101. V4L2_YCBCR_ENC_DEFAULT, /* Unspecified */
  102. V4L2_YCBCR_ENC_709,
  103. V4L2_YCBCR_ENC_601, /* Substitution for FCC */
  104. V4L2_YCBCR_ENC_601, /* Substitution for BT.470-2 B, G */
  105. V4L2_YCBCR_ENC_601,
  106. V4L2_YCBCR_ENC_SMPTE240M,
  107. };
  108. if (matrix_coefficients < ARRAY_SIZE(ycbcr_encs))
  109. return ycbcr_encs[matrix_coefficients];
  110. return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */
  111. }
  112. /* ------------------------------------------------------------------------
  113. * Terminal and unit management
  114. */
  115. struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
  116. {
  117. struct uvc_entity *entity;
  118. if (id == UVC_INVALID_ENTITY_ID)
  119. return NULL;
  120. list_for_each_entry(entity, &dev->entities, list) {
  121. if (entity->id == id)
  122. return entity;
  123. }
  124. return NULL;
  125. }
  126. static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
  127. int id, struct uvc_entity *entity)
  128. {
  129. unsigned int i;
  130. if (entity == NULL)
  131. entity = list_entry(&dev->entities, struct uvc_entity, list);
  132. list_for_each_entry_continue(entity, &dev->entities, list) {
  133. for (i = 0; i < entity->bNrInPins; ++i)
  134. if (entity->baSourceID[i] == id)
  135. return entity;
  136. }
  137. return NULL;
  138. }
  139. static struct uvc_streaming *uvc_stream_for_terminal(struct uvc_device *dev,
  140. struct uvc_entity *term)
  141. {
  142. u16 id = UVC_HARDWARE_ENTITY_ID(term->id);
  143. struct uvc_streaming *stream;
  144. list_for_each_entry(stream, &dev->streams, list) {
  145. if (stream->header.bTerminalLink == id)
  146. return stream;
  147. }
  148. return NULL;
  149. }
  150. /* ------------------------------------------------------------------------
  151. * Streaming Object Management
  152. */
  153. static void uvc_stream_delete(struct uvc_streaming *stream)
  154. {
  155. if (stream->async_wq)
  156. destroy_workqueue(stream->async_wq);
  157. usb_put_intf(stream->intf);
  158. kfree(stream->formats);
  159. kfree(stream->header.bmaControls);
  160. kfree(stream);
  161. }
  162. static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev,
  163. struct usb_interface *intf)
  164. {
  165. struct uvc_streaming *stream;
  166. stream = kzalloc_obj(*stream);
  167. if (stream == NULL)
  168. return NULL;
  169. stream->dev = dev;
  170. stream->intf = usb_get_intf(intf);
  171. stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  172. /* Allocate a stream specific work queue for asynchronous tasks. */
  173. stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | WQ_HIGHPRI,
  174. 0);
  175. if (!stream->async_wq) {
  176. uvc_stream_delete(stream);
  177. return NULL;
  178. }
  179. return stream;
  180. }
  181. /* ------------------------------------------------------------------------
  182. * Descriptors parsing
  183. */
  184. static int uvc_parse_frame(struct uvc_device *dev,
  185. struct uvc_streaming *streaming,
  186. struct uvc_format *format, struct uvc_frame *frame,
  187. u32 **intervals, u8 ftype, int width_multiplier,
  188. const unsigned char *buffer, int buflen)
  189. {
  190. struct usb_host_interface *alts = streaming->intf->cur_altsetting;
  191. unsigned int maxIntervalIndex;
  192. unsigned int interval;
  193. unsigned int i, n;
  194. if (ftype != UVC_VS_FRAME_FRAME_BASED)
  195. n = buflen > 25 ? buffer[25] : 0;
  196. else
  197. n = buflen > 21 ? buffer[21] : 0;
  198. n = n ? n : 3;
  199. if (buflen < 26 + 4 * n) {
  200. uvc_dbg(dev, DESCR,
  201. "device %d videostreaming interface %d FRAME error\n",
  202. dev->udev->devnum, alts->desc.bInterfaceNumber);
  203. return -EINVAL;
  204. }
  205. frame->bFrameIndex = buffer[3];
  206. frame->bmCapabilities = buffer[4];
  207. frame->wWidth = get_unaligned_le16(&buffer[5]) * width_multiplier;
  208. frame->wHeight = get_unaligned_le16(&buffer[7]);
  209. frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
  210. frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
  211. if (ftype != UVC_VS_FRAME_FRAME_BASED) {
  212. frame->dwMaxVideoFrameBufferSize =
  213. get_unaligned_le32(&buffer[17]);
  214. frame->dwDefaultFrameInterval =
  215. get_unaligned_le32(&buffer[21]);
  216. frame->bFrameIntervalType = buffer[25];
  217. } else {
  218. frame->dwMaxVideoFrameBufferSize = 0;
  219. frame->dwDefaultFrameInterval =
  220. get_unaligned_le32(&buffer[17]);
  221. frame->bFrameIntervalType = buffer[21];
  222. }
  223. /*
  224. * Copy the frame intervals.
  225. *
  226. * Some bogus devices report dwMinFrameInterval equal to
  227. * dwMaxFrameInterval and have dwFrameIntervalStep set to zero. Setting
  228. * all null intervals to 1 fixes the problem and some other divisions
  229. * by zero that could happen.
  230. */
  231. frame->dwFrameInterval = *intervals;
  232. for (i = 0; i < n; ++i) {
  233. interval = get_unaligned_le32(&buffer[26 + 4 * i]);
  234. (*intervals)[i] = interval ? interval : 1;
  235. }
  236. /*
  237. * Apply more fixes, quirks and workarounds to handle incorrect or
  238. * broken descriptors.
  239. */
  240. /*
  241. * Several UVC chipsets screw up dwMaxVideoFrameBufferSize completely.
  242. * Observed behaviours range from setting the value to 1.1x the actual
  243. * frame size to hardwiring the 16 low bits to 0. This results in a
  244. * higher than necessary memory usage as well as a wrong image size
  245. * information. For uncompressed formats this can be fixed by computing
  246. * the value from the frame size.
  247. */
  248. if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
  249. frame->dwMaxVideoFrameBufferSize = format->bpp * frame->wWidth
  250. * frame->wHeight / 8;
  251. /*
  252. * Clamp the default frame interval to the boundaries. A zero
  253. * bFrameIntervalType value indicates a continuous frame interval
  254. * range, with dwFrameInterval[0] storing the minimum value and
  255. * dwFrameInterval[1] storing the maximum value.
  256. */
  257. maxIntervalIndex = frame->bFrameIntervalType ? n - 1 : 1;
  258. frame->dwDefaultFrameInterval =
  259. clamp(frame->dwDefaultFrameInterval,
  260. frame->dwFrameInterval[0],
  261. frame->dwFrameInterval[maxIntervalIndex]);
  262. /*
  263. * Some devices report frame intervals that are not functional. If the
  264. * corresponding quirk is set, restrict operation to the first interval
  265. * only.
  266. */
  267. if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
  268. frame->bFrameIntervalType = 1;
  269. (*intervals)[0] = frame->dwDefaultFrameInterval;
  270. }
  271. uvc_dbg(dev, DESCR, "- %ux%u (%u.%u fps)\n",
  272. frame->wWidth, frame->wHeight,
  273. 10000000 / frame->dwDefaultFrameInterval,
  274. (100000000 / frame->dwDefaultFrameInterval) % 10);
  275. *intervals += n;
  276. return buffer[0];
  277. }
  278. static int uvc_parse_format(struct uvc_device *dev,
  279. struct uvc_streaming *streaming, struct uvc_format *format,
  280. struct uvc_frame *frames, u32 **intervals, const unsigned char *buffer,
  281. int buflen)
  282. {
  283. struct usb_host_interface *alts = streaming->intf->cur_altsetting;
  284. const struct uvc_format_desc *fmtdesc;
  285. struct uvc_frame *frame;
  286. const unsigned char *start = buffer;
  287. unsigned int width_multiplier = 1;
  288. unsigned int i, n;
  289. u8 ftype;
  290. int ret;
  291. if (buflen < 4)
  292. return -EINVAL;
  293. format->type = buffer[2];
  294. format->index = buffer[3];
  295. format->frames = frames;
  296. switch (buffer[2]) {
  297. case UVC_VS_FORMAT_UNCOMPRESSED:
  298. case UVC_VS_FORMAT_FRAME_BASED:
  299. n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
  300. if (buflen < n) {
  301. uvc_dbg(dev, DESCR,
  302. "device %d videostreaming interface %d FORMAT error\n",
  303. dev->udev->devnum,
  304. alts->desc.bInterfaceNumber);
  305. return -EINVAL;
  306. }
  307. /* Find the format descriptor from its GUID. */
  308. fmtdesc = uvc_format_by_guid(&buffer[5]);
  309. if (!fmtdesc) {
  310. /*
  311. * Unknown video formats are not fatal errors, the
  312. * caller will skip this descriptor.
  313. */
  314. dev_info(&streaming->intf->dev,
  315. "Unknown video format %pUl\n", &buffer[5]);
  316. return 0;
  317. }
  318. format->fcc = fmtdesc->fcc;
  319. format->bpp = buffer[21];
  320. /*
  321. * Some devices report a format that doesn't match what they
  322. * really send.
  323. */
  324. if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
  325. if (format->fcc == V4L2_PIX_FMT_YUYV) {
  326. format->fcc = V4L2_PIX_FMT_GREY;
  327. format->bpp = 8;
  328. width_multiplier = 2;
  329. }
  330. }
  331. /* Some devices report bpp that doesn't match the format. */
  332. if (dev->quirks & UVC_QUIRK_FORCE_BPP) {
  333. const struct v4l2_format_info *info =
  334. v4l2_format_info(format->fcc);
  335. if (info) {
  336. unsigned int div = info->hdiv * info->vdiv;
  337. n = info->bpp[0] * div;
  338. for (i = 1; i < info->comp_planes; i++)
  339. n += info->bpp[i];
  340. format->bpp = DIV_ROUND_UP(8 * n, div);
  341. }
  342. }
  343. if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
  344. ftype = UVC_VS_FRAME_UNCOMPRESSED;
  345. } else {
  346. ftype = UVC_VS_FRAME_FRAME_BASED;
  347. if (buffer[27])
  348. format->flags = UVC_FMT_FLAG_COMPRESSED;
  349. }
  350. break;
  351. case UVC_VS_FORMAT_MJPEG:
  352. if (buflen < 11) {
  353. uvc_dbg(dev, DESCR,
  354. "device %d videostreaming interface %d FORMAT error\n",
  355. dev->udev->devnum,
  356. alts->desc.bInterfaceNumber);
  357. return -EINVAL;
  358. }
  359. format->fcc = V4L2_PIX_FMT_MJPEG;
  360. format->flags = UVC_FMT_FLAG_COMPRESSED;
  361. format->bpp = 0;
  362. ftype = UVC_VS_FRAME_MJPEG;
  363. break;
  364. case UVC_VS_FORMAT_DV:
  365. if (buflen < 9) {
  366. uvc_dbg(dev, DESCR,
  367. "device %d videostreaming interface %d FORMAT error\n",
  368. dev->udev->devnum,
  369. alts->desc.bInterfaceNumber);
  370. return -EINVAL;
  371. }
  372. if ((buffer[8] & 0x7f) > 2) {
  373. uvc_dbg(dev, DESCR,
  374. "device %d videostreaming interface %d: unknown DV format %u\n",
  375. dev->udev->devnum,
  376. alts->desc.bInterfaceNumber, buffer[8]);
  377. return -EINVAL;
  378. }
  379. format->fcc = V4L2_PIX_FMT_DV;
  380. format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
  381. format->bpp = 0;
  382. ftype = 0;
  383. /* Create a dummy frame descriptor. */
  384. frame = &frames[0];
  385. memset(frame, 0, sizeof(*frame));
  386. frame->bFrameIntervalType = 1;
  387. frame->dwDefaultFrameInterval = 1;
  388. frame->dwFrameInterval = *intervals;
  389. *(*intervals)++ = 1;
  390. format->nframes = 1;
  391. break;
  392. case UVC_VS_FORMAT_MPEG2TS:
  393. case UVC_VS_FORMAT_STREAM_BASED:
  394. /* Not supported yet. */
  395. default:
  396. uvc_dbg(dev, DESCR,
  397. "device %d videostreaming interface %d unsupported format %u\n",
  398. dev->udev->devnum, alts->desc.bInterfaceNumber,
  399. buffer[2]);
  400. return -EINVAL;
  401. }
  402. uvc_dbg(dev, DESCR, "Found format %p4cc", &format->fcc);
  403. buflen -= buffer[0];
  404. buffer += buffer[0];
  405. /*
  406. * Parse the frame descriptors. Only uncompressed, MJPEG and frame
  407. * based formats have frame descriptors.
  408. */
  409. if (ftype) {
  410. while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  411. buffer[2] == ftype) {
  412. frame = &frames[format->nframes];
  413. ret = uvc_parse_frame(dev, streaming, format, frame,
  414. intervals, ftype, width_multiplier,
  415. buffer, buflen);
  416. if (ret < 0)
  417. return ret;
  418. format->nframes++;
  419. buflen -= ret;
  420. buffer += ret;
  421. }
  422. }
  423. if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  424. buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
  425. buflen -= buffer[0];
  426. buffer += buffer[0];
  427. }
  428. if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
  429. buffer[2] == UVC_VS_COLORFORMAT) {
  430. if (buflen < 6) {
  431. uvc_dbg(dev, DESCR,
  432. "device %d videostreaming interface %d COLORFORMAT error\n",
  433. dev->udev->devnum,
  434. alts->desc.bInterfaceNumber);
  435. return -EINVAL;
  436. }
  437. format->colorspace = uvc_colorspace(buffer[3]);
  438. format->xfer_func = uvc_xfer_func(buffer[4]);
  439. format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
  440. buflen -= buffer[0];
  441. buffer += buffer[0];
  442. } else {
  443. format->colorspace = V4L2_COLORSPACE_SRGB;
  444. }
  445. return buffer - start;
  446. }
  447. static int uvc_parse_streaming(struct uvc_device *dev,
  448. struct usb_interface *intf)
  449. {
  450. struct uvc_streaming *streaming = NULL;
  451. struct uvc_format *format;
  452. struct uvc_frame *frame;
  453. struct usb_host_interface *alts = &intf->altsetting[0];
  454. const unsigned char *_buffer, *buffer = alts->extra;
  455. int _buflen, buflen = alts->extralen;
  456. unsigned int nformats = 0, nframes = 0, nintervals = 0;
  457. unsigned int size, i, n, p;
  458. u32 *interval;
  459. u32 psize;
  460. int ret = -EINVAL;
  461. if (intf->cur_altsetting->desc.bInterfaceSubClass
  462. != UVC_SC_VIDEOSTREAMING) {
  463. uvc_dbg(dev, DESCR,
  464. "device %d interface %d isn't a video streaming interface\n",
  465. dev->udev->devnum,
  466. intf->altsetting[0].desc.bInterfaceNumber);
  467. return -EINVAL;
  468. }
  469. if (usb_driver_claim_interface(&uvc_driver, intf, dev)) {
  470. uvc_dbg(dev, DESCR,
  471. "device %d interface %d is already claimed\n",
  472. dev->udev->devnum,
  473. intf->altsetting[0].desc.bInterfaceNumber);
  474. return -EINVAL;
  475. }
  476. streaming = uvc_stream_new(dev, intf);
  477. if (streaming == NULL) {
  478. usb_driver_release_interface(&uvc_driver, intf);
  479. return -ENOMEM;
  480. }
  481. /*
  482. * The Pico iMage webcam has its class-specific interface descriptors
  483. * after the endpoint descriptors.
  484. */
  485. if (buflen == 0) {
  486. for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
  487. struct usb_host_endpoint *ep = &alts->endpoint[i];
  488. if (ep->extralen == 0)
  489. continue;
  490. if (ep->extralen > 2 &&
  491. ep->extra[1] == USB_DT_CS_INTERFACE) {
  492. uvc_dbg(dev, DESCR,
  493. "trying extra data from endpoint %u\n",
  494. i);
  495. buffer = alts->endpoint[i].extra;
  496. buflen = alts->endpoint[i].extralen;
  497. break;
  498. }
  499. }
  500. }
  501. /* Skip the standard interface descriptors. */
  502. while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
  503. buflen -= buffer[0];
  504. buffer += buffer[0];
  505. }
  506. if (buflen <= 2) {
  507. uvc_dbg(dev, DESCR,
  508. "no class-specific streaming interface descriptors found\n");
  509. goto error;
  510. }
  511. /* Parse the header descriptor. */
  512. switch (buffer[2]) {
  513. case UVC_VS_OUTPUT_HEADER:
  514. streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  515. size = 9;
  516. break;
  517. case UVC_VS_INPUT_HEADER:
  518. streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  519. size = 13;
  520. break;
  521. default:
  522. uvc_dbg(dev, DESCR,
  523. "device %d videostreaming interface %d HEADER descriptor not found\n",
  524. dev->udev->devnum, alts->desc.bInterfaceNumber);
  525. goto error;
  526. }
  527. p = buflen >= 4 ? buffer[3] : 0;
  528. n = buflen >= size ? buffer[size-1] : 0;
  529. if (buflen < size + p*n) {
  530. uvc_dbg(dev, DESCR,
  531. "device %d videostreaming interface %d HEADER descriptor is invalid\n",
  532. dev->udev->devnum, alts->desc.bInterfaceNumber);
  533. goto error;
  534. }
  535. streaming->header.bNumFormats = p;
  536. streaming->header.bEndpointAddress = buffer[6];
  537. if (buffer[2] == UVC_VS_INPUT_HEADER) {
  538. streaming->header.bmInfo = buffer[7];
  539. streaming->header.bTerminalLink = buffer[8];
  540. streaming->header.bStillCaptureMethod = buffer[9];
  541. streaming->header.bTriggerSupport = buffer[10];
  542. streaming->header.bTriggerUsage = buffer[11];
  543. } else {
  544. streaming->header.bTerminalLink = buffer[7];
  545. }
  546. streaming->header.bControlSize = n;
  547. streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
  548. GFP_KERNEL);
  549. if (streaming->header.bmaControls == NULL) {
  550. ret = -ENOMEM;
  551. goto error;
  552. }
  553. buflen -= buffer[0];
  554. buffer += buffer[0];
  555. _buffer = buffer;
  556. _buflen = buflen;
  557. /* Count the format and frame descriptors. */
  558. while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
  559. switch (_buffer[2]) {
  560. case UVC_VS_FORMAT_UNCOMPRESSED:
  561. case UVC_VS_FORMAT_MJPEG:
  562. case UVC_VS_FORMAT_FRAME_BASED:
  563. nformats++;
  564. break;
  565. case UVC_VS_FORMAT_DV:
  566. /*
  567. * DV format has no frame descriptor. We will create a
  568. * dummy frame descriptor with a dummy frame interval.
  569. */
  570. nformats++;
  571. nframes++;
  572. nintervals++;
  573. break;
  574. case UVC_VS_FORMAT_MPEG2TS:
  575. case UVC_VS_FORMAT_STREAM_BASED:
  576. uvc_dbg(dev, DESCR,
  577. "device %d videostreaming interface %d FORMAT %u is not supported\n",
  578. dev->udev->devnum,
  579. alts->desc.bInterfaceNumber, _buffer[2]);
  580. break;
  581. case UVC_VS_FRAME_UNCOMPRESSED:
  582. case UVC_VS_FRAME_MJPEG:
  583. nframes++;
  584. if (_buflen > 25)
  585. nintervals += _buffer[25] ? _buffer[25] : 3;
  586. break;
  587. case UVC_VS_FRAME_FRAME_BASED:
  588. nframes++;
  589. if (_buflen > 21)
  590. nintervals += _buffer[21] ? _buffer[21] : 3;
  591. break;
  592. }
  593. _buflen -= _buffer[0];
  594. _buffer += _buffer[0];
  595. }
  596. if (nformats == 0) {
  597. uvc_dbg(dev, DESCR,
  598. "device %d videostreaming interface %d has no supported formats defined\n",
  599. dev->udev->devnum, alts->desc.bInterfaceNumber);
  600. goto error;
  601. }
  602. /*
  603. * Allocate memory for the formats, the frames and the intervals,
  604. * plus any required padding to guarantee that everything has the
  605. * correct alignment.
  606. */
  607. size = nformats * sizeof(*format);
  608. size = ALIGN(size, __alignof__(*frame)) + nframes * sizeof(*frame);
  609. size = ALIGN(size, __alignof__(*interval))
  610. + nintervals * sizeof(*interval);
  611. format = kzalloc(size, GFP_KERNEL);
  612. if (!format) {
  613. ret = -ENOMEM;
  614. goto error;
  615. }
  616. frame = (void *)format + nformats * sizeof(*format);
  617. frame = PTR_ALIGN(frame, __alignof__(*frame));
  618. interval = (void *)frame + nframes * sizeof(*frame);
  619. interval = PTR_ALIGN(interval, __alignof__(*interval));
  620. streaming->formats = format;
  621. streaming->nformats = 0;
  622. /* Parse the format descriptors. */
  623. while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
  624. switch (buffer[2]) {
  625. case UVC_VS_FORMAT_UNCOMPRESSED:
  626. case UVC_VS_FORMAT_MJPEG:
  627. case UVC_VS_FORMAT_DV:
  628. case UVC_VS_FORMAT_FRAME_BASED:
  629. ret = uvc_parse_format(dev, streaming, format, frame,
  630. &interval, buffer, buflen);
  631. if (ret < 0)
  632. goto error;
  633. if (!ret)
  634. break;
  635. streaming->nformats++;
  636. frame += format->nframes;
  637. format++;
  638. buflen -= ret;
  639. buffer += ret;
  640. continue;
  641. default:
  642. break;
  643. }
  644. buflen -= buffer[0];
  645. buffer += buffer[0];
  646. }
  647. if (buflen)
  648. uvc_dbg(dev, DESCR,
  649. "device %d videostreaming interface %d has %u bytes of trailing descriptor garbage\n",
  650. dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
  651. /* Parse the alternate settings to find the maximum bandwidth. */
  652. for (i = 0; i < intf->num_altsetting; ++i) {
  653. struct usb_host_endpoint *ep;
  654. alts = &intf->altsetting[i];
  655. ep = uvc_find_endpoint(alts,
  656. streaming->header.bEndpointAddress);
  657. if (ep == NULL)
  658. continue;
  659. psize = usb_endpoint_max_periodic_payload(dev->udev, ep);
  660. if (psize > streaming->maxpsize)
  661. streaming->maxpsize = psize;
  662. }
  663. list_add_tail(&streaming->list, &dev->streams);
  664. return 0;
  665. error:
  666. usb_driver_release_interface(&uvc_driver, intf);
  667. uvc_stream_delete(streaming);
  668. return ret;
  669. }
  670. static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA;
  671. static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER;
  672. static const u8 uvc_media_transport_input_guid[16] =
  673. UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT;
  674. static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING;
  675. static struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type,
  676. u16 id, unsigned int num_pads,
  677. unsigned int extra_size)
  678. {
  679. struct uvc_entity *entity;
  680. unsigned int num_inputs;
  681. unsigned int size;
  682. unsigned int i;
  683. /* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */
  684. if (id == 0) {
  685. dev_err(&dev->intf->dev, "Found Unit with invalid ID 0\n");
  686. id = UVC_INVALID_ENTITY_ID;
  687. }
  688. /* Per UVC 1.1+ spec 3.7.2, the ID is unique. */
  689. if (uvc_entity_by_id(dev, UVC_HARDWARE_ENTITY_ID(id)))
  690. dev_err(&dev->intf->dev, "Found multiple Units with ID %u\n",
  691. UVC_HARDWARE_ENTITY_ID(id));
  692. if (uvc_entity_by_id(dev, id))
  693. id = UVC_INVALID_ENTITY_ID;
  694. extra_size = roundup(extra_size, sizeof(*entity->pads));
  695. if (num_pads)
  696. num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
  697. else
  698. num_inputs = 0;
  699. size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
  700. + num_inputs;
  701. entity = kzalloc(size, GFP_KERNEL);
  702. if (entity == NULL)
  703. return ERR_PTR(-ENOMEM);
  704. entity->id = id;
  705. entity->type = type;
  706. /*
  707. * Set the GUID for standard entity types. For extension units, the GUID
  708. * is initialized by the caller.
  709. */
  710. switch (type) {
  711. case UVC_EXT_GPIO_UNIT:
  712. memcpy(entity->guid, uvc_gpio_guid, 16);
  713. break;
  714. case UVC_ITT_CAMERA:
  715. memcpy(entity->guid, uvc_camera_guid, 16);
  716. break;
  717. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  718. memcpy(entity->guid, uvc_media_transport_input_guid, 16);
  719. break;
  720. case UVC_VC_PROCESSING_UNIT:
  721. memcpy(entity->guid, uvc_processing_guid, 16);
  722. break;
  723. }
  724. entity->num_links = 0;
  725. entity->num_pads = num_pads;
  726. entity->pads = ((void *)(entity + 1)) + extra_size;
  727. for (i = 0; i < num_inputs; ++i)
  728. entity->pads[i].flags = MEDIA_PAD_FL_SINK;
  729. if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
  730. entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
  731. entity->bNrInPins = num_inputs;
  732. entity->baSourceID = (u8 *)(&entity->pads[num_pads]);
  733. return entity;
  734. }
  735. static void uvc_entity_set_name(struct uvc_device *dev, struct uvc_entity *entity,
  736. const char *type_name, u8 string_id)
  737. {
  738. int ret;
  739. /*
  740. * First attempt to read the entity name from the device. If the entity
  741. * has no associated string, or if reading the string fails (most
  742. * likely due to a buggy firmware), fall back to default names based on
  743. * the entity type.
  744. */
  745. if (string_id) {
  746. ret = usb_string(dev->udev, string_id, entity->name,
  747. sizeof(entity->name));
  748. if (!ret)
  749. return;
  750. }
  751. sprintf(entity->name, "%s %u", type_name, entity->id);
  752. }
  753. /* Parse vendor-specific extensions. */
  754. static int uvc_parse_vendor_control(struct uvc_device *dev,
  755. const unsigned char *buffer, int buflen)
  756. {
  757. struct usb_device *udev = dev->udev;
  758. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  759. struct uvc_entity *unit;
  760. unsigned int n, p;
  761. int handled = 0;
  762. switch (le16_to_cpu(udev->descriptor.idVendor)) {
  763. case 0x046d: /* Logitech */
  764. if (buffer[1] != 0x41 || buffer[2] != 0x01)
  765. break;
  766. /*
  767. * Logitech implements several vendor specific functions
  768. * through vendor specific extension units (LXU).
  769. *
  770. * The LXU descriptors are similar to XU descriptors
  771. * (see "USB Device Video Class for Video Devices", section
  772. * 3.7.2.6 "Extension Unit Descriptor") with the following
  773. * differences:
  774. *
  775. * ----------------------------------------------------------
  776. * 0 bLength 1 Number
  777. * Size of this descriptor, in bytes: 24+p+n*2
  778. * ----------------------------------------------------------
  779. * 23+p+n bmControlsType N Bitmap
  780. * Individual bits in the set are defined:
  781. * 0: Absolute
  782. * 1: Relative
  783. *
  784. * This bitset is mapped exactly the same as bmControls.
  785. * ----------------------------------------------------------
  786. * 23+p+n*2 bReserved 1 Boolean
  787. * ----------------------------------------------------------
  788. * 24+p+n*2 iExtension 1 Index
  789. * Index of a string descriptor that describes this
  790. * extension unit.
  791. * ----------------------------------------------------------
  792. */
  793. p = buflen >= 22 ? buffer[21] : 0;
  794. n = buflen >= 25 + p ? buffer[22+p] : 0;
  795. if (buflen < 25 + p + 2*n) {
  796. uvc_dbg(dev, DESCR,
  797. "device %d videocontrol interface %d EXTENSION_UNIT error\n",
  798. udev->devnum, alts->desc.bInterfaceNumber);
  799. break;
  800. }
  801. unit = uvc_alloc_new_entity(dev, UVC_VC_EXTENSION_UNIT,
  802. buffer[3], p + 1, 2 * n);
  803. if (IS_ERR(unit))
  804. return PTR_ERR(unit);
  805. memcpy(unit->guid, &buffer[4], 16);
  806. unit->extension.bNumControls = buffer[20];
  807. memcpy(unit->baSourceID, &buffer[22], p);
  808. unit->extension.bControlSize = buffer[22+p];
  809. unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
  810. unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit)
  811. + n;
  812. memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
  813. uvc_entity_set_name(dev, unit, "Extension", buffer[24+p+2*n]);
  814. list_add_tail(&unit->list, &dev->entities);
  815. handled = 1;
  816. break;
  817. }
  818. return handled;
  819. }
  820. static int uvc_parse_standard_control(struct uvc_device *dev,
  821. const unsigned char *buffer, int buflen)
  822. {
  823. struct usb_device *udev = dev->udev;
  824. struct uvc_entity *unit, *term;
  825. struct usb_interface *intf;
  826. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  827. unsigned int i, n, p, len;
  828. const char *type_name;
  829. unsigned int id;
  830. u16 type;
  831. switch (buffer[2]) {
  832. case UVC_VC_HEADER:
  833. n = buflen >= 12 ? buffer[11] : 0;
  834. if (buflen < 12 + n) {
  835. uvc_dbg(dev, DESCR,
  836. "device %d videocontrol interface %d HEADER error\n",
  837. udev->devnum, alts->desc.bInterfaceNumber);
  838. return -EINVAL;
  839. }
  840. dev->uvc_version = get_unaligned_le16(&buffer[3]);
  841. dev->clock_frequency = get_unaligned_le32(&buffer[7]);
  842. /* Parse all USB Video Streaming interfaces. */
  843. for (i = 0; i < n; ++i) {
  844. intf = usb_ifnum_to_if(udev, buffer[12+i]);
  845. if (intf == NULL) {
  846. uvc_dbg(dev, DESCR,
  847. "device %d interface %d doesn't exists\n",
  848. udev->devnum, i);
  849. continue;
  850. }
  851. uvc_parse_streaming(dev, intf);
  852. }
  853. break;
  854. case UVC_VC_INPUT_TERMINAL:
  855. if (buflen < 8) {
  856. uvc_dbg(dev, DESCR,
  857. "device %d videocontrol interface %d INPUT_TERMINAL error\n",
  858. udev->devnum, alts->desc.bInterfaceNumber);
  859. return -EINVAL;
  860. }
  861. /*
  862. * Reject invalid terminal types that would cause issues:
  863. *
  864. * - The high byte must be non-zero, otherwise it would be
  865. * confused with a unit.
  866. *
  867. * - Bit 15 must be 0, as we use it internally as a terminal
  868. * direction flag.
  869. *
  870. * Other unknown types are accepted.
  871. */
  872. type = get_unaligned_le16(&buffer[4]);
  873. if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
  874. uvc_dbg(dev, DESCR,
  875. "device %d videocontrol interface %d INPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
  876. udev->devnum, alts->desc.bInterfaceNumber,
  877. buffer[3], type);
  878. return 0;
  879. }
  880. n = 0;
  881. p = 0;
  882. len = 8;
  883. if (type == UVC_ITT_CAMERA) {
  884. n = buflen >= 15 ? buffer[14] : 0;
  885. len = 15;
  886. } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
  887. n = buflen >= 9 ? buffer[8] : 0;
  888. p = buflen >= 10 + n ? buffer[9+n] : 0;
  889. len = 10;
  890. }
  891. if (buflen < len + n + p) {
  892. uvc_dbg(dev, DESCR,
  893. "device %d videocontrol interface %d INPUT_TERMINAL error\n",
  894. udev->devnum, alts->desc.bInterfaceNumber);
  895. return -EINVAL;
  896. }
  897. term = uvc_alloc_new_entity(dev, type | UVC_TERM_INPUT,
  898. buffer[3], 1, n + p);
  899. if (IS_ERR(term))
  900. return PTR_ERR(term);
  901. if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
  902. term->camera.bControlSize = n;
  903. term->camera.bmControls = (u8 *)term + sizeof(*term);
  904. term->camera.wObjectiveFocalLengthMin =
  905. get_unaligned_le16(&buffer[8]);
  906. term->camera.wObjectiveFocalLengthMax =
  907. get_unaligned_le16(&buffer[10]);
  908. term->camera.wOcularFocalLength =
  909. get_unaligned_le16(&buffer[12]);
  910. memcpy(term->camera.bmControls, &buffer[15], n);
  911. } else if (UVC_ENTITY_TYPE(term) ==
  912. UVC_ITT_MEDIA_TRANSPORT_INPUT) {
  913. term->media.bControlSize = n;
  914. term->media.bmControls = (u8 *)term + sizeof(*term);
  915. term->media.bTransportModeSize = p;
  916. term->media.bmTransportModes = (u8 *)term
  917. + sizeof(*term) + n;
  918. memcpy(term->media.bmControls, &buffer[9], n);
  919. memcpy(term->media.bmTransportModes, &buffer[10+n], p);
  920. }
  921. if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
  922. type_name = "Camera";
  923. else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
  924. type_name = "Media";
  925. else
  926. type_name = "Input";
  927. uvc_entity_set_name(dev, term, type_name, buffer[7]);
  928. list_add_tail(&term->list, &dev->entities);
  929. break;
  930. case UVC_VC_OUTPUT_TERMINAL:
  931. if (buflen < 9) {
  932. uvc_dbg(dev, DESCR,
  933. "device %d videocontrol interface %d OUTPUT_TERMINAL error\n",
  934. udev->devnum, alts->desc.bInterfaceNumber);
  935. return -EINVAL;
  936. }
  937. /*
  938. * Make sure the terminal type MSB is not null, otherwise it
  939. * could be confused with a unit.
  940. */
  941. type = get_unaligned_le16(&buffer[4]);
  942. if ((type & 0xff00) == 0) {
  943. uvc_dbg(dev, DESCR,
  944. "device %d videocontrol interface %d OUTPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
  945. udev->devnum, alts->desc.bInterfaceNumber,
  946. buffer[3], type);
  947. return 0;
  948. }
  949. id = buffer[3];
  950. /*
  951. * Some devices, such as the Grandstream GUV3100, exhibit entity
  952. * ID collisions between units and streaming output terminals.
  953. * Move streaming output terminals to their own ID namespace by
  954. * setting bit UVC_TERM_OUTPUT (15), above the ID's 8-bit value.
  955. * The bit is ignored in uvc_stream_for_terminal() when looking
  956. * up the streaming interface for the terminal.
  957. *
  958. * This hack is safe to enable unconditionally, as the ID is not
  959. * used for any other purpose (streaming output terminals have
  960. * no controls and are never referenced as sources in UVC
  961. * descriptors). Other types output terminals can have controls,
  962. * so limit usage of this separate namespace to streaming output
  963. * terminals.
  964. */
  965. if (type & UVC_TT_STREAMING)
  966. id |= UVC_TERM_OUTPUT;
  967. term = uvc_alloc_new_entity(dev, type | UVC_TERM_OUTPUT,
  968. id, 1, 0);
  969. if (IS_ERR(term))
  970. return PTR_ERR(term);
  971. memcpy(term->baSourceID, &buffer[7], 1);
  972. uvc_entity_set_name(dev, term, "Output", buffer[8]);
  973. list_add_tail(&term->list, &dev->entities);
  974. break;
  975. case UVC_VC_SELECTOR_UNIT:
  976. p = buflen >= 5 ? buffer[4] : 0;
  977. if (buflen < 5 || buflen < 6 + p) {
  978. uvc_dbg(dev, DESCR,
  979. "device %d videocontrol interface %d SELECTOR_UNIT error\n",
  980. udev->devnum, alts->desc.bInterfaceNumber);
  981. return -EINVAL;
  982. }
  983. unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3],
  984. p + 1, 0);
  985. if (IS_ERR(unit))
  986. return PTR_ERR(unit);
  987. memcpy(unit->baSourceID, &buffer[5], p);
  988. uvc_entity_set_name(dev, unit, "Selector", buffer[5+p]);
  989. list_add_tail(&unit->list, &dev->entities);
  990. break;
  991. case UVC_VC_PROCESSING_UNIT:
  992. n = buflen >= 8 ? buffer[7] : 0;
  993. p = dev->uvc_version >= 0x0110 ? 10 : 9;
  994. if (buflen < p + n) {
  995. uvc_dbg(dev, DESCR,
  996. "device %d videocontrol interface %d PROCESSING_UNIT error\n",
  997. udev->devnum, alts->desc.bInterfaceNumber);
  998. return -EINVAL;
  999. }
  1000. unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3], 2, n);
  1001. if (IS_ERR(unit))
  1002. return PTR_ERR(unit);
  1003. memcpy(unit->baSourceID, &buffer[4], 1);
  1004. unit->processing.wMaxMultiplier =
  1005. get_unaligned_le16(&buffer[5]);
  1006. unit->processing.bControlSize = buffer[7];
  1007. unit->processing.bmControls = (u8 *)unit + sizeof(*unit);
  1008. memcpy(unit->processing.bmControls, &buffer[8], n);
  1009. if (dev->uvc_version >= 0x0110)
  1010. unit->processing.bmVideoStandards = buffer[9+n];
  1011. uvc_entity_set_name(dev, unit, "Processing", buffer[8+n]);
  1012. list_add_tail(&unit->list, &dev->entities);
  1013. break;
  1014. case UVC_VC_EXTENSION_UNIT:
  1015. p = buflen >= 22 ? buffer[21] : 0;
  1016. n = buflen >= 24 + p ? buffer[22+p] : 0;
  1017. if (buflen < 24 + p + n) {
  1018. uvc_dbg(dev, DESCR,
  1019. "device %d videocontrol interface %d EXTENSION_UNIT error\n",
  1020. udev->devnum, alts->desc.bInterfaceNumber);
  1021. return -EINVAL;
  1022. }
  1023. unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3],
  1024. p + 1, n);
  1025. if (IS_ERR(unit))
  1026. return PTR_ERR(unit);
  1027. memcpy(unit->guid, &buffer[4], 16);
  1028. unit->extension.bNumControls = buffer[20];
  1029. memcpy(unit->baSourceID, &buffer[22], p);
  1030. unit->extension.bControlSize = buffer[22+p];
  1031. unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
  1032. memcpy(unit->extension.bmControls, &buffer[23+p], n);
  1033. uvc_entity_set_name(dev, unit, "Extension", buffer[23+p+n]);
  1034. list_add_tail(&unit->list, &dev->entities);
  1035. break;
  1036. default:
  1037. uvc_dbg(dev, DESCR,
  1038. "Found an unknown CS_INTERFACE descriptor (%u)\n",
  1039. buffer[2]);
  1040. break;
  1041. }
  1042. return 0;
  1043. }
  1044. static int uvc_parse_control(struct uvc_device *dev)
  1045. {
  1046. struct usb_host_interface *alts = dev->intf->cur_altsetting;
  1047. const unsigned char *buffer = alts->extra;
  1048. int buflen = alts->extralen;
  1049. int ret;
  1050. /*
  1051. * Parse the default alternate setting only, as the UVC specification
  1052. * defines a single alternate setting, the default alternate setting
  1053. * zero.
  1054. */
  1055. while (buflen > 2) {
  1056. if (uvc_parse_vendor_control(dev, buffer, buflen) ||
  1057. buffer[1] != USB_DT_CS_INTERFACE)
  1058. goto next_descriptor;
  1059. ret = uvc_parse_standard_control(dev, buffer, buflen);
  1060. if (ret < 0)
  1061. return ret;
  1062. next_descriptor:
  1063. buflen -= buffer[0];
  1064. buffer += buffer[0];
  1065. }
  1066. /*
  1067. * Check if the optional status endpoint is present. Built-in iSight
  1068. * webcams have an interrupt endpoint but spit proprietary data that
  1069. * don't conform to the UVC status endpoint messages. Don't try to
  1070. * handle the interrupt endpoint for those cameras.
  1071. */
  1072. if (alts->desc.bNumEndpoints == 1 &&
  1073. !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
  1074. struct usb_host_endpoint *ep = &alts->endpoint[0];
  1075. struct usb_endpoint_descriptor *desc = &ep->desc;
  1076. if (usb_endpoint_is_int_in(desc) &&
  1077. le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
  1078. desc->bInterval != 0) {
  1079. uvc_dbg(dev, DESCR,
  1080. "Found a Status endpoint (addr %02x)\n",
  1081. desc->bEndpointAddress);
  1082. dev->int_ep = ep;
  1083. }
  1084. }
  1085. return 0;
  1086. }
  1087. /* -----------------------------------------------------------------------------
  1088. * Privacy GPIO
  1089. */
  1090. static void uvc_gpio_event(struct uvc_device *dev)
  1091. {
  1092. struct uvc_entity *unit = dev->gpio_unit;
  1093. struct uvc_video_chain *chain;
  1094. u8 new_val;
  1095. if (!unit)
  1096. return;
  1097. new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy);
  1098. /* GPIO entities are always on the first chain. */
  1099. chain = list_first_entry(&dev->chains, struct uvc_video_chain, list);
  1100. uvc_ctrl_status_event(chain, unit->controls, &new_val);
  1101. }
  1102. static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
  1103. u8 cs, void *data, u16 size)
  1104. {
  1105. if (cs != UVC_CT_PRIVACY_CONTROL || size < 1)
  1106. return -EINVAL;
  1107. *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy);
  1108. return 0;
  1109. }
  1110. static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity,
  1111. u8 cs, u8 *caps)
  1112. {
  1113. if (cs != UVC_CT_PRIVACY_CONTROL)
  1114. return -EINVAL;
  1115. *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE;
  1116. return 0;
  1117. }
  1118. static irqreturn_t uvc_gpio_irq(int irq, void *data)
  1119. {
  1120. struct uvc_device *dev = data;
  1121. uvc_gpio_event(dev);
  1122. return IRQ_HANDLED;
  1123. }
  1124. static int uvc_gpio_parse(struct uvc_device *dev)
  1125. {
  1126. struct uvc_entity *unit;
  1127. struct gpio_desc *gpio_privacy;
  1128. int irq;
  1129. gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy",
  1130. GPIOD_IN);
  1131. if (!gpio_privacy)
  1132. return 0;
  1133. if (IS_ERR(gpio_privacy))
  1134. return dev_err_probe(&dev->intf->dev,
  1135. PTR_ERR(gpio_privacy),
  1136. "Can't get privacy GPIO\n");
  1137. irq = gpiod_to_irq(gpio_privacy);
  1138. if (irq < 0)
  1139. return dev_err_probe(&dev->intf->dev, irq,
  1140. "No IRQ for privacy GPIO\n");
  1141. unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT,
  1142. UVC_EXT_GPIO_UNIT_ID, 0, 1);
  1143. if (IS_ERR(unit))
  1144. return PTR_ERR(unit);
  1145. unit->gpio.gpio_privacy = gpio_privacy;
  1146. unit->gpio.irq = irq;
  1147. unit->gpio.bControlSize = 1;
  1148. unit->gpio.bmControls = (u8 *)unit + sizeof(*unit);
  1149. unit->gpio.bmControls[0] = 1;
  1150. unit->get_cur = uvc_gpio_get_cur;
  1151. unit->get_info = uvc_gpio_get_info;
  1152. strscpy(unit->name, "GPIO", sizeof(unit->name));
  1153. list_add_tail(&unit->list, &dev->entities);
  1154. dev->gpio_unit = unit;
  1155. return 0;
  1156. }
  1157. static int uvc_gpio_init_irq(struct uvc_device *dev)
  1158. {
  1159. struct uvc_entity *unit = dev->gpio_unit;
  1160. int ret;
  1161. if (!unit || unit->gpio.irq < 0)
  1162. return 0;
  1163. ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq,
  1164. IRQF_ONESHOT | IRQF_TRIGGER_FALLING |
  1165. IRQF_TRIGGER_RISING,
  1166. "uvc_privacy_gpio", dev);
  1167. unit->gpio.initialized = !ret;
  1168. return ret;
  1169. }
  1170. static void uvc_gpio_deinit(struct uvc_device *dev)
  1171. {
  1172. if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized)
  1173. return;
  1174. free_irq(dev->gpio_unit->gpio.irq, dev);
  1175. }
  1176. /* ------------------------------------------------------------------------
  1177. * UVC device scan
  1178. */
  1179. /*
  1180. * Scan the UVC descriptors to locate a chain starting at an Output Terminal
  1181. * and containing the following units:
  1182. *
  1183. * - one or more Output Terminals (USB Streaming or Display)
  1184. * - zero or one Processing Unit
  1185. * - zero, one or more single-input Selector Units
  1186. * - zero or one multiple-input Selector Units, provided all inputs are
  1187. * connected to input terminals
  1188. * - zero, one or mode single-input Extension Units
  1189. * - one or more Input Terminals (Camera, External or USB Streaming)
  1190. *
  1191. * The terminal and units must match on of the following structures:
  1192. *
  1193. * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
  1194. * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
  1195. * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
  1196. *
  1197. * +---------+ +---------+ -> OTT_*(0)
  1198. * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
  1199. * +---------+ +---------+ -> OTT_*(n)
  1200. *
  1201. * The Processing Unit and Extension Units can be in any order. Additional
  1202. * Extension Units connected to the main chain as single-unit branches are
  1203. * also supported. Single-input Selector Units are ignored.
  1204. */
  1205. static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
  1206. struct uvc_entity *entity)
  1207. {
  1208. switch (UVC_ENTITY_TYPE(entity)) {
  1209. case UVC_VC_EXTENSION_UNIT:
  1210. uvc_dbg_cont(PROBE, " <- XU %d", entity->id);
  1211. if (entity->bNrInPins != 1) {
  1212. uvc_dbg(chain->dev, DESCR,
  1213. "Extension unit %d has more than 1 input pin\n",
  1214. entity->id);
  1215. return -1;
  1216. }
  1217. break;
  1218. case UVC_VC_PROCESSING_UNIT:
  1219. uvc_dbg_cont(PROBE, " <- PU %d", entity->id);
  1220. if (chain->processing != NULL) {
  1221. uvc_dbg(chain->dev, DESCR,
  1222. "Found multiple Processing Units in chain\n");
  1223. return -1;
  1224. }
  1225. chain->processing = entity;
  1226. break;
  1227. case UVC_VC_SELECTOR_UNIT:
  1228. uvc_dbg_cont(PROBE, " <- SU %d", entity->id);
  1229. /* Single-input selector units are ignored. */
  1230. if (entity->bNrInPins == 1)
  1231. break;
  1232. if (chain->selector != NULL) {
  1233. uvc_dbg(chain->dev, DESCR,
  1234. "Found multiple Selector Units in chain\n");
  1235. return -1;
  1236. }
  1237. chain->selector = entity;
  1238. break;
  1239. case UVC_ITT_VENDOR_SPECIFIC:
  1240. case UVC_ITT_CAMERA:
  1241. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  1242. uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
  1243. break;
  1244. case UVC_OTT_VENDOR_SPECIFIC:
  1245. case UVC_OTT_DISPLAY:
  1246. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1247. uvc_dbg_cont(PROBE, " OT %d", entity->id);
  1248. break;
  1249. case UVC_TT_STREAMING:
  1250. if (UVC_ENTITY_IS_ITERM(entity))
  1251. uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
  1252. else
  1253. uvc_dbg_cont(PROBE, " OT %d", entity->id);
  1254. break;
  1255. default:
  1256. uvc_dbg(chain->dev, DESCR,
  1257. "Unsupported entity type 0x%04x found in chain\n",
  1258. UVC_ENTITY_TYPE(entity));
  1259. return -1;
  1260. }
  1261. list_add_tail(&entity->chain, &chain->entities);
  1262. return 0;
  1263. }
  1264. static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
  1265. struct uvc_entity *entity, struct uvc_entity *prev)
  1266. {
  1267. struct uvc_entity *forward;
  1268. int found;
  1269. /* Forward scan */
  1270. forward = NULL;
  1271. found = 0;
  1272. while (1) {
  1273. forward = uvc_entity_by_reference(chain->dev, entity->id,
  1274. forward);
  1275. if (forward == NULL)
  1276. break;
  1277. if (forward == prev)
  1278. continue;
  1279. if (forward->chain.next || forward->chain.prev) {
  1280. uvc_dbg(chain->dev, DESCR,
  1281. "Found reference to entity %d already in chain\n",
  1282. forward->id);
  1283. return -EINVAL;
  1284. }
  1285. switch (UVC_ENTITY_TYPE(forward)) {
  1286. case UVC_VC_EXTENSION_UNIT:
  1287. if (forward->bNrInPins != 1) {
  1288. uvc_dbg(chain->dev, DESCR,
  1289. "Extension unit %d has more than 1 input pin\n",
  1290. forward->id);
  1291. return -EINVAL;
  1292. }
  1293. /*
  1294. * Some devices reference an output terminal as the
  1295. * source of extension units. This is incorrect, as
  1296. * output terminals only have an input pin, and thus
  1297. * can't be connected to any entity in the forward
  1298. * direction. The resulting topology would cause issues
  1299. * when registering the media controller graph. To
  1300. * avoid this problem, connect the extension unit to
  1301. * the source of the output terminal instead.
  1302. */
  1303. if (UVC_ENTITY_IS_OTERM(entity)) {
  1304. struct uvc_entity *source;
  1305. source = uvc_entity_by_id(chain->dev,
  1306. entity->baSourceID[0]);
  1307. if (!source) {
  1308. uvc_dbg(chain->dev, DESCR,
  1309. "Can't connect extension unit %u in chain\n",
  1310. forward->id);
  1311. break;
  1312. }
  1313. forward->baSourceID[0] = source->id;
  1314. }
  1315. list_add_tail(&forward->chain, &chain->entities);
  1316. if (!found)
  1317. uvc_dbg_cont(PROBE, " (->");
  1318. uvc_dbg_cont(PROBE, " XU %d", forward->id);
  1319. found = 1;
  1320. break;
  1321. case UVC_OTT_VENDOR_SPECIFIC:
  1322. case UVC_OTT_DISPLAY:
  1323. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1324. case UVC_TT_STREAMING:
  1325. if (UVC_ENTITY_IS_ITERM(forward)) {
  1326. uvc_dbg(chain->dev, DESCR,
  1327. "Unsupported input terminal %u\n",
  1328. forward->id);
  1329. return -EINVAL;
  1330. }
  1331. if (UVC_ENTITY_IS_OTERM(entity)) {
  1332. uvc_dbg(chain->dev, DESCR,
  1333. "Unsupported connection between output terminals %u and %u\n",
  1334. entity->id, forward->id);
  1335. break;
  1336. }
  1337. list_add_tail(&forward->chain, &chain->entities);
  1338. if (!found)
  1339. uvc_dbg_cont(PROBE, " (->");
  1340. uvc_dbg_cont(PROBE, " OT %d", forward->id);
  1341. found = 1;
  1342. break;
  1343. }
  1344. }
  1345. if (found)
  1346. uvc_dbg_cont(PROBE, ")");
  1347. return 0;
  1348. }
  1349. static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
  1350. struct uvc_entity **_entity)
  1351. {
  1352. struct uvc_entity *entity = *_entity;
  1353. struct uvc_entity *term;
  1354. int id = -EINVAL, i;
  1355. switch (UVC_ENTITY_TYPE(entity)) {
  1356. case UVC_VC_EXTENSION_UNIT:
  1357. case UVC_VC_PROCESSING_UNIT:
  1358. id = entity->baSourceID[0];
  1359. break;
  1360. case UVC_VC_SELECTOR_UNIT:
  1361. /* Single-input selector units are ignored. */
  1362. if (entity->bNrInPins == 1) {
  1363. id = entity->baSourceID[0];
  1364. break;
  1365. }
  1366. uvc_dbg_cont(PROBE, " <- IT");
  1367. chain->selector = entity;
  1368. for (i = 0; i < entity->bNrInPins; ++i) {
  1369. id = entity->baSourceID[i];
  1370. term = uvc_entity_by_id(chain->dev, id);
  1371. if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
  1372. uvc_dbg(chain->dev, DESCR,
  1373. "Selector unit %d input %d isn't connected to an input terminal\n",
  1374. entity->id, i);
  1375. return -1;
  1376. }
  1377. if (term->chain.next || term->chain.prev) {
  1378. uvc_dbg(chain->dev, DESCR,
  1379. "Found reference to entity %d already in chain\n",
  1380. term->id);
  1381. return -EINVAL;
  1382. }
  1383. uvc_dbg_cont(PROBE, " %d", term->id);
  1384. list_add_tail(&term->chain, &chain->entities);
  1385. uvc_scan_chain_forward(chain, term, entity);
  1386. }
  1387. uvc_dbg_cont(PROBE, "\n");
  1388. id = 0;
  1389. break;
  1390. case UVC_ITT_VENDOR_SPECIFIC:
  1391. case UVC_ITT_CAMERA:
  1392. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  1393. case UVC_OTT_VENDOR_SPECIFIC:
  1394. case UVC_OTT_DISPLAY:
  1395. case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
  1396. case UVC_TT_STREAMING:
  1397. id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
  1398. break;
  1399. }
  1400. if (id <= 0) {
  1401. *_entity = NULL;
  1402. return id;
  1403. }
  1404. entity = uvc_entity_by_id(chain->dev, id);
  1405. if (entity == NULL) {
  1406. uvc_dbg(chain->dev, DESCR,
  1407. "Found reference to unknown entity %d\n", id);
  1408. return -EINVAL;
  1409. }
  1410. *_entity = entity;
  1411. return 0;
  1412. }
  1413. static int uvc_scan_chain(struct uvc_video_chain *chain,
  1414. struct uvc_entity *term)
  1415. {
  1416. struct uvc_entity *entity, *prev;
  1417. uvc_dbg(chain->dev, PROBE, "Scanning UVC chain:");
  1418. entity = term;
  1419. prev = NULL;
  1420. while (entity != NULL) {
  1421. /* Entity must not be part of an existing chain */
  1422. if (entity->chain.next || entity->chain.prev) {
  1423. uvc_dbg(chain->dev, DESCR,
  1424. "Found reference to entity %d already in chain\n",
  1425. entity->id);
  1426. return -EINVAL;
  1427. }
  1428. /* Process entity */
  1429. if (uvc_scan_chain_entity(chain, entity) < 0)
  1430. return -EINVAL;
  1431. /* Forward scan */
  1432. if (uvc_scan_chain_forward(chain, entity, prev) < 0)
  1433. return -EINVAL;
  1434. /* Backward scan */
  1435. prev = entity;
  1436. if (uvc_scan_chain_backward(chain, &entity) < 0)
  1437. return -EINVAL;
  1438. }
  1439. return 0;
  1440. }
  1441. static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
  1442. char *buffer)
  1443. {
  1444. struct uvc_entity *term;
  1445. unsigned int nterms = 0;
  1446. char *p = buffer;
  1447. list_for_each_entry(term, terms, chain) {
  1448. if (!UVC_ENTITY_IS_TERM(term) ||
  1449. UVC_TERM_DIRECTION(term) != dir)
  1450. continue;
  1451. if (nterms)
  1452. p += sprintf(p, ",");
  1453. if (++nterms >= 4) {
  1454. p += sprintf(p, "...");
  1455. break;
  1456. }
  1457. p += sprintf(p, "%u", term->id);
  1458. }
  1459. return p - buffer;
  1460. }
  1461. static const char *uvc_print_chain(struct uvc_video_chain *chain)
  1462. {
  1463. static char buffer[43];
  1464. char *p = buffer;
  1465. p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
  1466. p += sprintf(p, " -> ");
  1467. uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
  1468. return buffer;
  1469. }
  1470. static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
  1471. {
  1472. struct uvc_video_chain *chain;
  1473. chain = kzalloc_obj(*chain);
  1474. if (chain == NULL)
  1475. return NULL;
  1476. INIT_LIST_HEAD(&chain->entities);
  1477. mutex_init(&chain->ctrl_mutex);
  1478. chain->dev = dev;
  1479. v4l2_prio_init(&chain->prio);
  1480. return chain;
  1481. }
  1482. /*
  1483. * Fallback heuristic for devices that don't connect units and terminals in a
  1484. * valid chain.
  1485. *
  1486. * Some devices have invalid baSourceID references, causing uvc_scan_chain()
  1487. * to fail, but if we just take the entities we can find and put them together
  1488. * in the most sensible chain we can think of, turns out they do work anyway.
  1489. * Note: This heuristic assumes there is a single chain.
  1490. *
  1491. * At the time of writing, devices known to have such a broken chain are
  1492. * - Acer Integrated Camera (5986:055a)
  1493. * - Realtek rtl157a7 (0bda:57a7)
  1494. */
  1495. static int uvc_scan_fallback(struct uvc_device *dev)
  1496. {
  1497. struct uvc_video_chain *chain;
  1498. struct uvc_entity *iterm = NULL;
  1499. struct uvc_entity *oterm = NULL;
  1500. struct uvc_entity *entity;
  1501. struct uvc_entity *prev;
  1502. /*
  1503. * Start by locating the input and output terminals. We only support
  1504. * devices with exactly one of each for now.
  1505. */
  1506. list_for_each_entry(entity, &dev->entities, list) {
  1507. if (UVC_ENTITY_IS_ITERM(entity)) {
  1508. if (iterm)
  1509. return -EINVAL;
  1510. iterm = entity;
  1511. }
  1512. if (UVC_ENTITY_IS_OTERM(entity)) {
  1513. if (oterm)
  1514. return -EINVAL;
  1515. oterm = entity;
  1516. }
  1517. }
  1518. if (iterm == NULL || oterm == NULL)
  1519. return -EINVAL;
  1520. /* Allocate the chain and fill it. */
  1521. chain = uvc_alloc_chain(dev);
  1522. if (chain == NULL)
  1523. return -ENOMEM;
  1524. if (uvc_scan_chain_entity(chain, oterm) < 0)
  1525. goto error;
  1526. prev = oterm;
  1527. /*
  1528. * Add all Processing and Extension Units with two pads. The order
  1529. * doesn't matter much, use reverse list traversal to connect units in
  1530. * UVC descriptor order as we build the chain from output to input. This
  1531. * leads to units appearing in the order meant by the manufacturer for
  1532. * the cameras known to require this heuristic.
  1533. */
  1534. list_for_each_entry_reverse(entity, &dev->entities, list) {
  1535. if (entity->type != UVC_VC_PROCESSING_UNIT &&
  1536. entity->type != UVC_VC_EXTENSION_UNIT)
  1537. continue;
  1538. if (entity->num_pads != 2)
  1539. continue;
  1540. if (uvc_scan_chain_entity(chain, entity) < 0)
  1541. goto error;
  1542. prev->baSourceID[0] = entity->id;
  1543. prev = entity;
  1544. }
  1545. if (uvc_scan_chain_entity(chain, iterm) < 0)
  1546. goto error;
  1547. prev->baSourceID[0] = iterm->id;
  1548. list_add_tail(&chain->list, &dev->chains);
  1549. uvc_dbg(dev, PROBE, "Found a video chain by fallback heuristic (%s)\n",
  1550. uvc_print_chain(chain));
  1551. return 0;
  1552. error:
  1553. kfree(chain);
  1554. return -EINVAL;
  1555. }
  1556. /*
  1557. * Scan the device for video chains and register video devices.
  1558. *
  1559. * Chains are scanned starting at their output terminals and walked backwards.
  1560. */
  1561. static int uvc_scan_device(struct uvc_device *dev)
  1562. {
  1563. struct uvc_video_chain *chain;
  1564. struct uvc_entity *term;
  1565. list_for_each_entry(term, &dev->entities, list) {
  1566. if (!UVC_ENTITY_IS_OTERM(term))
  1567. continue;
  1568. /*
  1569. * If the terminal is already included in a chain, skip it.
  1570. * This can happen for chains that have multiple output
  1571. * terminals, where all output terminals beside the first one
  1572. * will be inserted in the chain in forward scans.
  1573. */
  1574. if (term->chain.next || term->chain.prev)
  1575. continue;
  1576. chain = uvc_alloc_chain(dev);
  1577. if (chain == NULL)
  1578. return -ENOMEM;
  1579. term->flags |= UVC_ENTITY_FLAG_DEFAULT;
  1580. if (uvc_scan_chain(chain, term) < 0) {
  1581. kfree(chain);
  1582. continue;
  1583. }
  1584. uvc_dbg(dev, PROBE, "Found a valid video chain (%s)\n",
  1585. uvc_print_chain(chain));
  1586. list_add_tail(&chain->list, &dev->chains);
  1587. }
  1588. if (list_empty(&dev->chains))
  1589. uvc_scan_fallback(dev);
  1590. if (list_empty(&dev->chains)) {
  1591. dev_info(&dev->intf->dev, "No valid video chain found.\n");
  1592. return -ENODEV;
  1593. }
  1594. /* Add GPIO entity to the first chain. */
  1595. if (dev->gpio_unit) {
  1596. chain = list_first_entry(&dev->chains,
  1597. struct uvc_video_chain, list);
  1598. list_add_tail(&dev->gpio_unit->chain, &chain->entities);
  1599. }
  1600. return 0;
  1601. }
  1602. /* ------------------------------------------------------------------------
  1603. * Video device registration and unregistration
  1604. */
  1605. /*
  1606. * Delete the UVC device.
  1607. *
  1608. * Called by the kernel when the last reference to the uvc_device structure
  1609. * is released.
  1610. *
  1611. * As this function is called after or during disconnect(), all URBs have
  1612. * already been cancelled by the USB core. There is no need to kill the
  1613. * interrupt URB manually.
  1614. */
  1615. static void uvc_delete(struct kref *kref)
  1616. {
  1617. struct uvc_device *dev = container_of(kref, struct uvc_device, ref);
  1618. struct list_head *p, *n;
  1619. uvc_status_cleanup(dev);
  1620. uvc_ctrl_cleanup_device(dev);
  1621. usb_put_intf(dev->intf);
  1622. usb_put_dev(dev->udev);
  1623. #ifdef CONFIG_MEDIA_CONTROLLER
  1624. media_device_cleanup(&dev->mdev);
  1625. #endif
  1626. list_for_each_safe(p, n, &dev->chains) {
  1627. struct uvc_video_chain *chain;
  1628. chain = list_entry(p, struct uvc_video_chain, list);
  1629. kfree(chain);
  1630. }
  1631. list_for_each_safe(p, n, &dev->entities) {
  1632. struct uvc_entity *entity;
  1633. entity = list_entry(p, struct uvc_entity, list);
  1634. #ifdef CONFIG_MEDIA_CONTROLLER
  1635. uvc_mc_cleanup_entity(entity);
  1636. #endif
  1637. kfree(entity);
  1638. }
  1639. list_for_each_safe(p, n, &dev->streams) {
  1640. struct uvc_streaming *streaming;
  1641. streaming = list_entry(p, struct uvc_streaming, list);
  1642. usb_driver_release_interface(&uvc_driver, streaming->intf);
  1643. uvc_stream_delete(streaming);
  1644. }
  1645. kfree(dev);
  1646. }
  1647. static void uvc_release(struct video_device *vdev)
  1648. {
  1649. struct uvc_streaming *stream = video_get_drvdata(vdev);
  1650. struct uvc_device *dev = stream->dev;
  1651. kref_put(&dev->ref, uvc_delete);
  1652. }
  1653. /*
  1654. * Unregister the video devices.
  1655. */
  1656. static void uvc_unregister_video(struct uvc_device *dev)
  1657. {
  1658. struct uvc_streaming *stream;
  1659. uvc_gpio_deinit(dev);
  1660. list_for_each_entry(stream, &dev->streams, list) {
  1661. /* Nothing to do here, continue. */
  1662. if (!video_is_registered(&stream->queue.vdev))
  1663. continue;
  1664. vb2_video_unregister_device(&stream->queue.vdev);
  1665. vb2_video_unregister_device(&stream->meta.queue.vdev);
  1666. /*
  1667. * Now both vdevs are not streaming and all the ioctls will
  1668. * return -ENODEV.
  1669. */
  1670. uvc_debugfs_cleanup_stream(stream);
  1671. }
  1672. uvc_status_unregister(dev);
  1673. if (dev->vdev.dev)
  1674. v4l2_device_unregister(&dev->vdev);
  1675. #ifdef CONFIG_MEDIA_CONTROLLER
  1676. if (media_devnode_is_registered(dev->mdev.devnode))
  1677. media_device_unregister(&dev->mdev);
  1678. #endif
  1679. }
  1680. int uvc_register_video_device(struct uvc_device *dev,
  1681. struct uvc_streaming *stream,
  1682. struct uvc_video_queue *queue,
  1683. enum v4l2_buf_type type,
  1684. const struct v4l2_file_operations *fops,
  1685. const struct v4l2_ioctl_ops *ioctl_ops)
  1686. {
  1687. struct video_device *vdev = &queue->vdev;
  1688. int ret;
  1689. /* Initialize the video buffers queue. */
  1690. ret = uvc_queue_init(queue, type);
  1691. if (ret)
  1692. return ret;
  1693. /* Register the device with V4L. */
  1694. /*
  1695. * We already hold a reference to dev->udev. The video device will be
  1696. * unregistered before the reference is released, so we don't need to
  1697. * get another one.
  1698. */
  1699. vdev->v4l2_dev = &dev->vdev;
  1700. vdev->fops = fops;
  1701. vdev->ioctl_ops = ioctl_ops;
  1702. vdev->release = uvc_release;
  1703. vdev->prio = &stream->chain->prio;
  1704. vdev->queue = &queue->queue;
  1705. vdev->lock = &queue->mutex;
  1706. if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  1707. vdev->vfl_dir = VFL_DIR_TX;
  1708. else
  1709. vdev->vfl_dir = VFL_DIR_RX;
  1710. switch (type) {
  1711. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  1712. default:
  1713. vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  1714. break;
  1715. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  1716. vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
  1717. break;
  1718. case V4L2_BUF_TYPE_META_CAPTURE:
  1719. vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING;
  1720. break;
  1721. }
  1722. strscpy(vdev->name, dev->name, sizeof(vdev->name));
  1723. /*
  1724. * Set the driver data before calling video_register_device, otherwise
  1725. * the file open() handler might race us.
  1726. */
  1727. video_set_drvdata(vdev, stream);
  1728. ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
  1729. if (ret < 0) {
  1730. dev_err(&stream->intf->dev,
  1731. "Failed to register %s device (%d).\n",
  1732. v4l2_type_names[type], ret);
  1733. return ret;
  1734. }
  1735. kref_get(&dev->ref);
  1736. return 0;
  1737. }
  1738. static int uvc_register_video(struct uvc_device *dev,
  1739. struct uvc_streaming *stream)
  1740. {
  1741. int ret;
  1742. /* Initialize the streaming interface with default parameters. */
  1743. ret = uvc_video_init(stream);
  1744. if (ret < 0) {
  1745. dev_err(&stream->intf->dev,
  1746. "Failed to initialize the device (%d).\n", ret);
  1747. return ret;
  1748. }
  1749. if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1750. stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE
  1751. | V4L2_CAP_META_CAPTURE;
  1752. else
  1753. stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
  1754. uvc_debugfs_init_stream(stream);
  1755. /* Register the device with V4L. */
  1756. return uvc_register_video_device(dev, stream, &stream->queue,
  1757. stream->type, &uvc_fops,
  1758. &uvc_ioctl_ops);
  1759. }
  1760. /*
  1761. * Register all video devices in all chains.
  1762. */
  1763. static int uvc_register_terms(struct uvc_device *dev,
  1764. struct uvc_video_chain *chain)
  1765. {
  1766. struct uvc_streaming *stream;
  1767. struct uvc_entity *term;
  1768. int ret;
  1769. list_for_each_entry(term, &chain->entities, chain) {
  1770. if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
  1771. continue;
  1772. stream = uvc_stream_for_terminal(dev, term);
  1773. if (!stream) {
  1774. dev_info(&dev->intf->dev,
  1775. "No streaming interface found for terminal %u.",
  1776. term->id);
  1777. continue;
  1778. }
  1779. stream->chain = chain;
  1780. ret = uvc_register_video(dev, stream);
  1781. if (ret < 0)
  1782. return ret;
  1783. /*
  1784. * Register a metadata node, but ignore a possible failure,
  1785. * complete registration of video nodes anyway.
  1786. */
  1787. uvc_meta_register(stream);
  1788. term->vdev = &stream->queue.vdev;
  1789. }
  1790. return 0;
  1791. }
  1792. static int uvc_register_chains(struct uvc_device *dev)
  1793. {
  1794. struct uvc_video_chain *chain;
  1795. int ret;
  1796. list_for_each_entry(chain, &dev->chains, list) {
  1797. ret = uvc_register_terms(dev, chain);
  1798. if (ret < 0)
  1799. return ret;
  1800. #ifdef CONFIG_MEDIA_CONTROLLER
  1801. ret = uvc_mc_register_entities(chain);
  1802. if (ret < 0)
  1803. dev_info(&dev->intf->dev,
  1804. "Failed to register entities (%d).\n", ret);
  1805. #endif
  1806. }
  1807. return 0;
  1808. }
  1809. /* ------------------------------------------------------------------------
  1810. * USB probe, disconnect, suspend and resume
  1811. */
  1812. static const struct uvc_device_info uvc_quirk_none = { 0 };
  1813. static int uvc_probe(struct usb_interface *intf,
  1814. const struct usb_device_id *id)
  1815. {
  1816. struct usb_device *udev = interface_to_usbdev(intf);
  1817. struct uvc_device *dev;
  1818. const struct uvc_device_info *info =
  1819. (const struct uvc_device_info *)id->driver_info;
  1820. int function;
  1821. int ret;
  1822. /* Allocate memory for the device and initialize it. */
  1823. dev = kzalloc_obj(*dev);
  1824. if (dev == NULL)
  1825. return -ENOMEM;
  1826. INIT_LIST_HEAD(&dev->entities);
  1827. INIT_LIST_HEAD(&dev->chains);
  1828. INIT_LIST_HEAD(&dev->streams);
  1829. kref_init(&dev->ref);
  1830. atomic_set(&dev->nmappings, 0);
  1831. dev->udev = usb_get_dev(udev);
  1832. dev->intf = usb_get_intf(intf);
  1833. dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
  1834. dev->info = info ? info : &uvc_quirk_none;
  1835. dev->quirks = uvc_quirks_param == -1
  1836. ? dev->info->quirks : uvc_quirks_param;
  1837. if (id->idVendor && id->idProduct)
  1838. uvc_dbg(dev, PROBE, "Probing known UVC device %s (%04x:%04x)\n",
  1839. udev->devpath, id->idVendor, id->idProduct);
  1840. else
  1841. uvc_dbg(dev, PROBE, "Probing generic UVC device %s\n",
  1842. udev->devpath);
  1843. if (udev->product != NULL)
  1844. strscpy(dev->name, udev->product, sizeof(dev->name));
  1845. else
  1846. snprintf(dev->name, sizeof(dev->name),
  1847. "UVC Camera (%04x:%04x)",
  1848. le16_to_cpu(udev->descriptor.idVendor),
  1849. le16_to_cpu(udev->descriptor.idProduct));
  1850. /*
  1851. * Add iFunction or iInterface to names when available as additional
  1852. * distinguishers between interfaces. iFunction is prioritized over
  1853. * iInterface which matches Windows behavior at the point of writing.
  1854. */
  1855. if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
  1856. function = intf->intf_assoc->iFunction;
  1857. else
  1858. function = intf->cur_altsetting->desc.iInterface;
  1859. if (function != 0) {
  1860. size_t len;
  1861. strlcat(dev->name, ": ", sizeof(dev->name));
  1862. len = strlen(dev->name);
  1863. usb_string(udev, function, dev->name + len,
  1864. sizeof(dev->name) - len);
  1865. }
  1866. /* Initialize the media device. */
  1867. #ifdef CONFIG_MEDIA_CONTROLLER
  1868. dev->mdev.dev = &intf->dev;
  1869. strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
  1870. if (udev->serial)
  1871. strscpy(dev->mdev.serial, udev->serial,
  1872. sizeof(dev->mdev.serial));
  1873. usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
  1874. dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
  1875. media_device_init(&dev->mdev);
  1876. dev->vdev.mdev = &dev->mdev;
  1877. #endif
  1878. /* Parse the Video Class control descriptor. */
  1879. ret = uvc_parse_control(dev);
  1880. if (ret < 0) {
  1881. uvc_dbg(dev, PROBE, "Unable to parse UVC descriptors\n");
  1882. goto error;
  1883. }
  1884. /* Parse the associated GPIOs. */
  1885. ret = uvc_gpio_parse(dev);
  1886. if (ret < 0)
  1887. goto error;
  1888. dev_info(&dev->intf->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n",
  1889. dev->uvc_version >> 8, dev->uvc_version & 0xff,
  1890. udev->product ? udev->product : "<unnamed>",
  1891. le16_to_cpu(udev->descriptor.idVendor),
  1892. le16_to_cpu(udev->descriptor.idProduct));
  1893. if (dev->quirks != dev->info->quirks) {
  1894. dev_info(&dev->intf->dev,
  1895. "Forcing device quirks to 0x%x by module parameter for testing purpose.\n",
  1896. dev->quirks);
  1897. dev_info(&dev->intf->dev,
  1898. "Please report required quirks to the linux-media mailing list.\n");
  1899. }
  1900. if (dev->info->uvc_version) {
  1901. dev->uvc_version = dev->info->uvc_version;
  1902. dev_info(&dev->intf->dev, "Forcing UVC version to %u.%02x\n",
  1903. dev->uvc_version >> 8, dev->uvc_version & 0xff);
  1904. }
  1905. /* Register the V4L2 device. */
  1906. ret = v4l2_device_register(&intf->dev, &dev->vdev);
  1907. if (ret < 0)
  1908. goto error;
  1909. /* Scan the device for video chains. */
  1910. ret = uvc_scan_device(dev);
  1911. if (ret < 0)
  1912. goto error;
  1913. /* Initialize controls. */
  1914. ret = uvc_ctrl_init_device(dev);
  1915. if (ret < 0)
  1916. goto error;
  1917. /* Register video device nodes. */
  1918. ret = uvc_register_chains(dev);
  1919. if (ret < 0)
  1920. goto error;
  1921. #ifdef CONFIG_MEDIA_CONTROLLER
  1922. /* Register the media device node */
  1923. ret = media_device_register(&dev->mdev);
  1924. if (ret < 0)
  1925. goto error;
  1926. #endif
  1927. /* Save our data pointer in the interface data. */
  1928. usb_set_intfdata(intf, dev);
  1929. /* Initialize the interrupt URB. */
  1930. ret = uvc_status_init(dev);
  1931. if (ret < 0) {
  1932. dev_info(&dev->intf->dev,
  1933. "Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n",
  1934. ret);
  1935. }
  1936. ret = uvc_gpio_init_irq(dev);
  1937. if (ret < 0) {
  1938. dev_err(&dev->intf->dev,
  1939. "Unable to request privacy GPIO IRQ (%d)\n", ret);
  1940. goto error;
  1941. }
  1942. ret = uvc_meta_init(dev);
  1943. if (ret < 0) {
  1944. dev_err(&dev->intf->dev,
  1945. "Error initializing the metadata formats (%d)\n", ret);
  1946. goto error;
  1947. }
  1948. if (dev->quirks & UVC_QUIRK_NO_RESET_RESUME)
  1949. udev->quirks &= ~USB_QUIRK_RESET_RESUME;
  1950. if (!(dev->quirks & UVC_QUIRK_DISABLE_AUTOSUSPEND))
  1951. usb_enable_autosuspend(udev);
  1952. uvc_dbg(dev, PROBE, "UVC device initialized\n");
  1953. return 0;
  1954. error:
  1955. uvc_unregister_video(dev);
  1956. kref_put(&dev->ref, uvc_delete);
  1957. return ret;
  1958. }
  1959. static void uvc_disconnect(struct usb_interface *intf)
  1960. {
  1961. struct uvc_device *dev = usb_get_intfdata(intf);
  1962. /*
  1963. * Set the USB interface data to NULL. This can be done outside the
  1964. * lock, as there's no other reader.
  1965. */
  1966. usb_set_intfdata(intf, NULL);
  1967. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1968. UVC_SC_VIDEOSTREAMING)
  1969. return;
  1970. uvc_unregister_video(dev);
  1971. kref_put(&dev->ref, uvc_delete);
  1972. }
  1973. static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
  1974. {
  1975. struct uvc_device *dev = usb_get_intfdata(intf);
  1976. struct uvc_streaming *stream;
  1977. uvc_dbg(dev, SUSPEND, "Suspending interface %u\n",
  1978. intf->cur_altsetting->desc.bInterfaceNumber);
  1979. /* Controls are cached on the fly so they don't need to be saved. */
  1980. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  1981. UVC_SC_VIDEOCONTROL) {
  1982. uvc_status_suspend(dev);
  1983. return 0;
  1984. }
  1985. list_for_each_entry(stream, &dev->streams, list) {
  1986. if (stream->intf == intf)
  1987. return uvc_video_suspend(stream);
  1988. }
  1989. uvc_dbg(dev, SUSPEND,
  1990. "Suspend: video streaming USB interface mismatch\n");
  1991. return -EINVAL;
  1992. }
  1993. static int __uvc_resume(struct usb_interface *intf, int reset)
  1994. {
  1995. struct uvc_device *dev = usb_get_intfdata(intf);
  1996. struct uvc_streaming *stream;
  1997. int ret = 0;
  1998. uvc_dbg(dev, SUSPEND, "Resuming interface %u\n",
  1999. intf->cur_altsetting->desc.bInterfaceNumber);
  2000. if (intf->cur_altsetting->desc.bInterfaceSubClass ==
  2001. UVC_SC_VIDEOCONTROL) {
  2002. if (reset) {
  2003. ret = uvc_ctrl_restore_values(dev);
  2004. if (ret < 0)
  2005. return ret;
  2006. }
  2007. return uvc_status_resume(dev);
  2008. }
  2009. list_for_each_entry(stream, &dev->streams, list) {
  2010. if (stream->intf == intf) {
  2011. ret = uvc_video_resume(stream, reset);
  2012. if (ret < 0) {
  2013. mutex_lock(&stream->queue.mutex);
  2014. vb2_streamoff(&stream->queue.queue,
  2015. stream->queue.queue.type);
  2016. mutex_unlock(&stream->queue.mutex);
  2017. }
  2018. return ret;
  2019. }
  2020. }
  2021. uvc_dbg(dev, SUSPEND,
  2022. "Resume: video streaming USB interface mismatch\n");
  2023. return -EINVAL;
  2024. }
  2025. static int uvc_resume(struct usb_interface *intf)
  2026. {
  2027. return __uvc_resume(intf, 0);
  2028. }
  2029. static int uvc_reset_resume(struct usb_interface *intf)
  2030. {
  2031. return __uvc_resume(intf, 1);
  2032. }
  2033. /* ------------------------------------------------------------------------
  2034. * Module parameters
  2035. */
  2036. static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
  2037. {
  2038. if (uvc_clock_param == CLOCK_MONOTONIC)
  2039. return sprintf(buffer, "CLOCK_MONOTONIC");
  2040. else
  2041. return sprintf(buffer, "CLOCK_REALTIME");
  2042. }
  2043. static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
  2044. {
  2045. if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
  2046. val += strlen("clock_");
  2047. if (strcasecmp(val, "monotonic") == 0)
  2048. uvc_clock_param = CLOCK_MONOTONIC;
  2049. else if (strcasecmp(val, "realtime") == 0)
  2050. uvc_clock_param = CLOCK_REALTIME;
  2051. else
  2052. return -EINVAL;
  2053. return 0;
  2054. }
  2055. module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
  2056. &uvc_clock_param, 0644);
  2057. MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
  2058. module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, 0644);
  2059. MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
  2060. static int param_set_nodrop(const char *val, const struct kernel_param *kp)
  2061. {
  2062. pr_warn_once("uvcvideo: "
  2063. DEPRECATED
  2064. "nodrop parameter will be eventually removed.\n");
  2065. return param_set_bool(val, kp);
  2066. }
  2067. static const struct kernel_param_ops param_ops_nodrop = {
  2068. .set = param_set_nodrop,
  2069. .get = param_get_uint,
  2070. };
  2071. param_check_uint(nodrop, &uvc_no_drop_param);
  2072. module_param_cb(nodrop, &param_ops_nodrop, &uvc_no_drop_param, 0644);
  2073. __MODULE_PARM_TYPE(nodrop, "uint");
  2074. MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
  2075. module_param_named(quirks, uvc_quirks_param, uint, 0644);
  2076. MODULE_PARM_DESC(quirks, "Forced device quirks");
  2077. module_param_named(trace, uvc_dbg_param, uint, 0644);
  2078. MODULE_PARM_DESC(trace, "Trace level bitmask");
  2079. module_param_named(timeout, uvc_timeout_param, uint, 0644);
  2080. MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
  2081. /* ------------------------------------------------------------------------
  2082. * Driver initialization and cleanup
  2083. */
  2084. static const struct uvc_device_info uvc_quirk_probe_minmax = {
  2085. .quirks = UVC_QUIRK_PROBE_MINMAX,
  2086. };
  2087. static const struct uvc_device_info uvc_quirk_fix_bandwidth = {
  2088. .quirks = UVC_QUIRK_FIX_BANDWIDTH,
  2089. };
  2090. static const struct uvc_device_info uvc_quirk_probe_def = {
  2091. .quirks = UVC_QUIRK_PROBE_DEF,
  2092. };
  2093. static const struct uvc_device_info uvc_quirk_stream_no_fid = {
  2094. .quirks = UVC_QUIRK_STREAM_NO_FID,
  2095. };
  2096. static const struct uvc_device_info uvc_quirk_force_y8 = {
  2097. .quirks = UVC_QUIRK_FORCE_Y8,
  2098. };
  2099. #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q}
  2100. #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \
  2101. {.meta_format = m}
  2102. /*
  2103. * The Logitech cameras listed below have their interface class set to
  2104. * VENDOR_SPEC because they don't announce themselves as UVC devices, even
  2105. * though they are compliant.
  2106. *
  2107. * Sort these by vendor/product ID.
  2108. */
  2109. static const struct usb_device_id uvc_ids[] = {
  2110. /* HP Webcam HD 2300 */
  2111. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2112. | USB_DEVICE_ID_MATCH_INT_INFO,
  2113. .idVendor = 0x03f0,
  2114. .idProduct = 0xe207,
  2115. .bInterfaceClass = USB_CLASS_VIDEO,
  2116. .bInterfaceSubClass = 1,
  2117. .bInterfaceProtocol = 0,
  2118. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2119. /* Quanta ACER HD User Facing */
  2120. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2121. | USB_DEVICE_ID_MATCH_INT_INFO,
  2122. .idVendor = 0x0408,
  2123. .idProduct = 0x4033,
  2124. .bInterfaceClass = USB_CLASS_VIDEO,
  2125. .bInterfaceSubClass = 1,
  2126. .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
  2127. .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
  2128. .uvc_version = 0x010a,
  2129. } },
  2130. /* Quanta ACER HD User Facing */
  2131. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2132. | USB_DEVICE_ID_MATCH_INT_INFO,
  2133. .idVendor = 0x0408,
  2134. .idProduct = 0x4035,
  2135. .bInterfaceClass = USB_CLASS_VIDEO,
  2136. .bInterfaceSubClass = 1,
  2137. .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
  2138. .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
  2139. .uvc_version = 0x010a,
  2140. } },
  2141. /* LogiLink Wireless Webcam */
  2142. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2143. | USB_DEVICE_ID_MATCH_INT_INFO,
  2144. .idVendor = 0x0416,
  2145. .idProduct = 0xa91a,
  2146. .bInterfaceClass = USB_CLASS_VIDEO,
  2147. .bInterfaceSubClass = 1,
  2148. .bInterfaceProtocol = 0,
  2149. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2150. /* Genius eFace 2025 */
  2151. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2152. | USB_DEVICE_ID_MATCH_INT_INFO,
  2153. .idVendor = 0x0458,
  2154. .idProduct = 0x706e,
  2155. .bInterfaceClass = USB_CLASS_VIDEO,
  2156. .bInterfaceSubClass = 1,
  2157. .bInterfaceProtocol = 0,
  2158. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2159. /* Microsoft Lifecam NX-6000 */
  2160. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2161. | USB_DEVICE_ID_MATCH_INT_INFO,
  2162. .idVendor = 0x045e,
  2163. .idProduct = 0x00f8,
  2164. .bInterfaceClass = USB_CLASS_VIDEO,
  2165. .bInterfaceSubClass = 1,
  2166. .bInterfaceProtocol = 0,
  2167. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2168. /* Microsoft Lifecam NX-3000 */
  2169. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2170. | USB_DEVICE_ID_MATCH_INT_INFO,
  2171. .idVendor = 0x045e,
  2172. .idProduct = 0x0721,
  2173. .bInterfaceClass = USB_CLASS_VIDEO,
  2174. .bInterfaceSubClass = 1,
  2175. .bInterfaceProtocol = 0,
  2176. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2177. /* Microsoft Lifecam VX-7000 */
  2178. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2179. | USB_DEVICE_ID_MATCH_INT_INFO,
  2180. .idVendor = 0x045e,
  2181. .idProduct = 0x0723,
  2182. .bInterfaceClass = USB_CLASS_VIDEO,
  2183. .bInterfaceSubClass = 1,
  2184. .bInterfaceProtocol = 0,
  2185. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2186. /* Logitech, Webcam C910 */
  2187. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2188. | USB_DEVICE_ID_MATCH_INT_INFO,
  2189. .idVendor = 0x046d,
  2190. .idProduct = 0x0821,
  2191. .bInterfaceClass = USB_CLASS_VIDEO,
  2192. .bInterfaceSubClass = 1,
  2193. .bInterfaceProtocol = 0,
  2194. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
  2195. /* Logitech, Webcam B910 */
  2196. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2197. | USB_DEVICE_ID_MATCH_INT_INFO,
  2198. .idVendor = 0x046d,
  2199. .idProduct = 0x0823,
  2200. .bInterfaceClass = USB_CLASS_VIDEO,
  2201. .bInterfaceSubClass = 1,
  2202. .bInterfaceProtocol = 0,
  2203. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
  2204. /* Logitech Quickcam Fusion */
  2205. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2206. | USB_DEVICE_ID_MATCH_INT_INFO,
  2207. .idVendor = 0x046d,
  2208. .idProduct = 0x08c1,
  2209. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2210. .bInterfaceSubClass = 1,
  2211. .bInterfaceProtocol = 0 },
  2212. /* Logitech Quickcam Orbit MP */
  2213. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2214. | USB_DEVICE_ID_MATCH_INT_INFO,
  2215. .idVendor = 0x046d,
  2216. .idProduct = 0x08c2,
  2217. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2218. .bInterfaceSubClass = 1,
  2219. .bInterfaceProtocol = 0 },
  2220. /* Logitech Quickcam Pro for Notebook */
  2221. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2222. | USB_DEVICE_ID_MATCH_INT_INFO,
  2223. .idVendor = 0x046d,
  2224. .idProduct = 0x08c3,
  2225. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2226. .bInterfaceSubClass = 1,
  2227. .bInterfaceProtocol = 0 },
  2228. /* Logitech Quickcam Pro 5000 */
  2229. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2230. | USB_DEVICE_ID_MATCH_INT_INFO,
  2231. .idVendor = 0x046d,
  2232. .idProduct = 0x08c5,
  2233. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2234. .bInterfaceSubClass = 1,
  2235. .bInterfaceProtocol = 0 },
  2236. /* Logitech Quickcam OEM Dell Notebook */
  2237. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2238. | USB_DEVICE_ID_MATCH_INT_INFO,
  2239. .idVendor = 0x046d,
  2240. .idProduct = 0x08c6,
  2241. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2242. .bInterfaceSubClass = 1,
  2243. .bInterfaceProtocol = 0 },
  2244. /* Logitech Quickcam OEM Cisco VT Camera II */
  2245. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2246. | USB_DEVICE_ID_MATCH_INT_INFO,
  2247. .idVendor = 0x046d,
  2248. .idProduct = 0x08c7,
  2249. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2250. .bInterfaceSubClass = 1,
  2251. .bInterfaceProtocol = 0 },
  2252. /* Logitech HD Pro Webcam C920 */
  2253. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2254. | USB_DEVICE_ID_MATCH_INT_INFO,
  2255. .idVendor = 0x046d,
  2256. .idProduct = 0x082d,
  2257. .bInterfaceClass = USB_CLASS_VIDEO,
  2258. .bInterfaceSubClass = 1,
  2259. .bInterfaceProtocol = 0,
  2260. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT
  2261. | UVC_QUIRK_INVALID_DEVICE_SOF) },
  2262. /* Logitech HD Pro Webcam C922 */
  2263. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2264. | USB_DEVICE_ID_MATCH_INT_INFO,
  2265. .idVendor = 0x046d,
  2266. .idProduct = 0x085c,
  2267. .bInterfaceClass = USB_CLASS_VIDEO,
  2268. .bInterfaceSubClass = 1,
  2269. .bInterfaceProtocol = 0,
  2270. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_INVALID_DEVICE_SOF) },
  2271. /* Logitech Rally Bar Huddle */
  2272. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2273. | USB_DEVICE_ID_MATCH_INT_INFO,
  2274. .idVendor = 0x046d,
  2275. .idProduct = 0x087c,
  2276. .bInterfaceClass = USB_CLASS_VIDEO,
  2277. .bInterfaceSubClass = 1,
  2278. .bInterfaceProtocol = 0,
  2279. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
  2280. /* Logitech Rally Bar */
  2281. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2282. | USB_DEVICE_ID_MATCH_INT_INFO,
  2283. .idVendor = 0x046d,
  2284. .idProduct = 0x089b,
  2285. .bInterfaceClass = USB_CLASS_VIDEO,
  2286. .bInterfaceSubClass = 1,
  2287. .bInterfaceProtocol = 0,
  2288. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
  2289. /* Logitech Rally Bar Mini */
  2290. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2291. | USB_DEVICE_ID_MATCH_INT_INFO,
  2292. .idVendor = 0x046d,
  2293. .idProduct = 0x08d3,
  2294. .bInterfaceClass = USB_CLASS_VIDEO,
  2295. .bInterfaceSubClass = 1,
  2296. .bInterfaceProtocol = 0,
  2297. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
  2298. /* Chicony CNF7129 (Asus EEE 100HE) */
  2299. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2300. | USB_DEVICE_ID_MATCH_INT_INFO,
  2301. .idVendor = 0x04f2,
  2302. .idProduct = 0xb071,
  2303. .bInterfaceClass = USB_CLASS_VIDEO,
  2304. .bInterfaceSubClass = 1,
  2305. .bInterfaceProtocol = 0,
  2306. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },
  2307. /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
  2308. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2309. | USB_DEVICE_ID_MATCH_INT_INFO,
  2310. .idVendor = 0x058f,
  2311. .idProduct = 0x3820,
  2312. .bInterfaceClass = USB_CLASS_VIDEO,
  2313. .bInterfaceSubClass = 1,
  2314. .bInterfaceProtocol = 0,
  2315. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2316. /* Dell XPS m1530 */
  2317. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2318. | USB_DEVICE_ID_MATCH_INT_INFO,
  2319. .idVendor = 0x05a9,
  2320. .idProduct = 0x2640,
  2321. .bInterfaceClass = USB_CLASS_VIDEO,
  2322. .bInterfaceSubClass = 1,
  2323. .bInterfaceProtocol = 0,
  2324. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2325. /* Dell SP2008WFP Monitor */
  2326. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2327. | USB_DEVICE_ID_MATCH_INT_INFO,
  2328. .idVendor = 0x05a9,
  2329. .idProduct = 0x2641,
  2330. .bInterfaceClass = USB_CLASS_VIDEO,
  2331. .bInterfaceSubClass = 1,
  2332. .bInterfaceProtocol = 0,
  2333. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2334. /* Dell Alienware X51 */
  2335. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2336. | USB_DEVICE_ID_MATCH_INT_INFO,
  2337. .idVendor = 0x05a9,
  2338. .idProduct = 0x2643,
  2339. .bInterfaceClass = USB_CLASS_VIDEO,
  2340. .bInterfaceSubClass = 1,
  2341. .bInterfaceProtocol = 0,
  2342. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2343. /* Dell Studio Hybrid 140g (OmniVision webcam) */
  2344. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2345. | USB_DEVICE_ID_MATCH_INT_INFO,
  2346. .idVendor = 0x05a9,
  2347. .idProduct = 0x264a,
  2348. .bInterfaceClass = USB_CLASS_VIDEO,
  2349. .bInterfaceSubClass = 1,
  2350. .bInterfaceProtocol = 0,
  2351. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2352. /* Dell XPS M1330 (OmniVision OV7670 webcam) */
  2353. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2354. | USB_DEVICE_ID_MATCH_INT_INFO,
  2355. .idVendor = 0x05a9,
  2356. .idProduct = 0x7670,
  2357. .bInterfaceClass = USB_CLASS_VIDEO,
  2358. .bInterfaceSubClass = 1,
  2359. .bInterfaceProtocol = 0,
  2360. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2361. /* Apple Built-In iSight */
  2362. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2363. | USB_DEVICE_ID_MATCH_INT_INFO,
  2364. .idVendor = 0x05ac,
  2365. .idProduct = 0x8501,
  2366. .bInterfaceClass = USB_CLASS_VIDEO,
  2367. .bInterfaceSubClass = 1,
  2368. .bInterfaceProtocol = 0,
  2369. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
  2370. | UVC_QUIRK_BUILTIN_ISIGHT) },
  2371. /* Apple FaceTime HD Camera (Built-In) */
  2372. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2373. | USB_DEVICE_ID_MATCH_INT_INFO,
  2374. .idVendor = 0x05ac,
  2375. .idProduct = 0x8514,
  2376. .bInterfaceClass = USB_CLASS_VIDEO,
  2377. .bInterfaceSubClass = 1,
  2378. .bInterfaceProtocol = 0,
  2379. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2380. /* Apple Built-In iSight via iBridge */
  2381. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2382. | USB_DEVICE_ID_MATCH_INT_INFO,
  2383. .idVendor = 0x05ac,
  2384. .idProduct = 0x8600,
  2385. .bInterfaceClass = USB_CLASS_VIDEO,
  2386. .bInterfaceSubClass = 1,
  2387. .bInterfaceProtocol = 0,
  2388. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2389. /* Foxlink ("HP Webcam" on HP Mini 5103) */
  2390. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2391. | USB_DEVICE_ID_MATCH_INT_INFO,
  2392. .idVendor = 0x05c8,
  2393. .idProduct = 0x0403,
  2394. .bInterfaceClass = USB_CLASS_VIDEO,
  2395. .bInterfaceSubClass = 1,
  2396. .bInterfaceProtocol = 0,
  2397. .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
  2398. /* Genesys Logic USB 2.0 PC Camera */
  2399. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2400. | USB_DEVICE_ID_MATCH_INT_INFO,
  2401. .idVendor = 0x05e3,
  2402. .idProduct = 0x0505,
  2403. .bInterfaceClass = USB_CLASS_VIDEO,
  2404. .bInterfaceSubClass = 1,
  2405. .bInterfaceProtocol = 0,
  2406. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2407. /* Hercules Classic Silver */
  2408. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2409. | USB_DEVICE_ID_MATCH_INT_INFO,
  2410. .idVendor = 0x06f8,
  2411. .idProduct = 0x300c,
  2412. .bInterfaceClass = USB_CLASS_VIDEO,
  2413. .bInterfaceSubClass = 1,
  2414. .bInterfaceProtocol = 0,
  2415. .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
  2416. /* ViMicro Vega */
  2417. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2418. | USB_DEVICE_ID_MATCH_INT_INFO,
  2419. .idVendor = 0x0ac8,
  2420. .idProduct = 0x332d,
  2421. .bInterfaceClass = USB_CLASS_VIDEO,
  2422. .bInterfaceSubClass = 1,
  2423. .bInterfaceProtocol = 0,
  2424. .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
  2425. /* ViMicro - Minoru3D */
  2426. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2427. | USB_DEVICE_ID_MATCH_INT_INFO,
  2428. .idVendor = 0x0ac8,
  2429. .idProduct = 0x3410,
  2430. .bInterfaceClass = USB_CLASS_VIDEO,
  2431. .bInterfaceSubClass = 1,
  2432. .bInterfaceProtocol = 0,
  2433. .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
  2434. /* ViMicro Venus - Minoru3D */
  2435. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2436. | USB_DEVICE_ID_MATCH_INT_INFO,
  2437. .idVendor = 0x0ac8,
  2438. .idProduct = 0x3420,
  2439. .bInterfaceClass = USB_CLASS_VIDEO,
  2440. .bInterfaceSubClass = 1,
  2441. .bInterfaceProtocol = 0,
  2442. .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
  2443. /* Ophir Optronics - SPCAM 620U */
  2444. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2445. | USB_DEVICE_ID_MATCH_INT_INFO,
  2446. .idVendor = 0x0bd3,
  2447. .idProduct = 0x0555,
  2448. .bInterfaceClass = USB_CLASS_VIDEO,
  2449. .bInterfaceSubClass = 1,
  2450. .bInterfaceProtocol = 0,
  2451. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2452. /* Sonix Technology Co. Ltd. - 292A IPC AR0330 */
  2453. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2454. | USB_DEVICE_ID_MATCH_INT_INFO,
  2455. .idVendor = 0x0c45,
  2456. .idProduct = 0x6366,
  2457. .bInterfaceClass = USB_CLASS_VIDEO,
  2458. .bInterfaceSubClass = 1,
  2459. .bInterfaceProtocol = 0,
  2460. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) },
  2461. /* MT6227 */
  2462. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2463. | USB_DEVICE_ID_MATCH_INT_INFO,
  2464. .idVendor = 0x0e8d,
  2465. .idProduct = 0x0004,
  2466. .bInterfaceClass = USB_CLASS_VIDEO,
  2467. .bInterfaceSubClass = 1,
  2468. .bInterfaceProtocol = 0,
  2469. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
  2470. | UVC_QUIRK_PROBE_DEF) },
  2471. /* IMC Networks (Medion Akoya) */
  2472. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2473. | USB_DEVICE_ID_MATCH_INT_INFO,
  2474. .idVendor = 0x13d3,
  2475. .idProduct = 0x5103,
  2476. .bInterfaceClass = USB_CLASS_VIDEO,
  2477. .bInterfaceSubClass = 1,
  2478. .bInterfaceProtocol = 0,
  2479. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2480. /* JMicron USB2.0 XGA WebCam */
  2481. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2482. | USB_DEVICE_ID_MATCH_INT_INFO,
  2483. .idVendor = 0x152d,
  2484. .idProduct = 0x0310,
  2485. .bInterfaceClass = USB_CLASS_VIDEO,
  2486. .bInterfaceSubClass = 1,
  2487. .bInterfaceProtocol = 0,
  2488. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2489. /* Kurokesu C1 PRO */
  2490. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2491. | USB_DEVICE_ID_MATCH_INT_INFO,
  2492. .idVendor = 0x16d0,
  2493. .idProduct = 0x0ed1,
  2494. .bInterfaceClass = USB_CLASS_VIDEO,
  2495. .bInterfaceSubClass = 1,
  2496. .bInterfaceProtocol = 0,
  2497. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) },
  2498. /* Syntek (HP Spartan) */
  2499. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2500. | USB_DEVICE_ID_MATCH_INT_INFO,
  2501. .idVendor = 0x174f,
  2502. .idProduct = 0x5212,
  2503. .bInterfaceClass = USB_CLASS_VIDEO,
  2504. .bInterfaceSubClass = 1,
  2505. .bInterfaceProtocol = 0,
  2506. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2507. /* Syntek (Samsung Q310) */
  2508. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2509. | USB_DEVICE_ID_MATCH_INT_INFO,
  2510. .idVendor = 0x174f,
  2511. .idProduct = 0x5931,
  2512. .bInterfaceClass = USB_CLASS_VIDEO,
  2513. .bInterfaceSubClass = 1,
  2514. .bInterfaceProtocol = 0,
  2515. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2516. /* Syntek (Packard Bell EasyNote MX52 */
  2517. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2518. | USB_DEVICE_ID_MATCH_INT_INFO,
  2519. .idVendor = 0x174f,
  2520. .idProduct = 0x8a12,
  2521. .bInterfaceClass = USB_CLASS_VIDEO,
  2522. .bInterfaceSubClass = 1,
  2523. .bInterfaceProtocol = 0,
  2524. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2525. /* Syntek (Asus F9SG) */
  2526. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2527. | USB_DEVICE_ID_MATCH_INT_INFO,
  2528. .idVendor = 0x174f,
  2529. .idProduct = 0x8a31,
  2530. .bInterfaceClass = USB_CLASS_VIDEO,
  2531. .bInterfaceSubClass = 1,
  2532. .bInterfaceProtocol = 0,
  2533. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2534. /* Syntek (Asus U3S) */
  2535. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2536. | USB_DEVICE_ID_MATCH_INT_INFO,
  2537. .idVendor = 0x174f,
  2538. .idProduct = 0x8a33,
  2539. .bInterfaceClass = USB_CLASS_VIDEO,
  2540. .bInterfaceSubClass = 1,
  2541. .bInterfaceProtocol = 0,
  2542. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2543. /* Syntek (JAOtech Smart Terminal) */
  2544. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2545. | USB_DEVICE_ID_MATCH_INT_INFO,
  2546. .idVendor = 0x174f,
  2547. .idProduct = 0x8a34,
  2548. .bInterfaceClass = USB_CLASS_VIDEO,
  2549. .bInterfaceSubClass = 1,
  2550. .bInterfaceProtocol = 0,
  2551. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2552. /* Miricle 307K */
  2553. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2554. | USB_DEVICE_ID_MATCH_INT_INFO,
  2555. .idVendor = 0x17dc,
  2556. .idProduct = 0x0202,
  2557. .bInterfaceClass = USB_CLASS_VIDEO,
  2558. .bInterfaceSubClass = 1,
  2559. .bInterfaceProtocol = 0,
  2560. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2561. /* Lenovo Thinkpad SL400/SL500 */
  2562. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2563. | USB_DEVICE_ID_MATCH_INT_INFO,
  2564. .idVendor = 0x17ef,
  2565. .idProduct = 0x480b,
  2566. .bInterfaceClass = USB_CLASS_VIDEO,
  2567. .bInterfaceSubClass = 1,
  2568. .bInterfaceProtocol = 0,
  2569. .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
  2570. /* Aveo Technology USB 2.0 Camera */
  2571. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2572. | USB_DEVICE_ID_MATCH_INT_INFO,
  2573. .idVendor = 0x1871,
  2574. .idProduct = 0x0306,
  2575. .bInterfaceClass = USB_CLASS_VIDEO,
  2576. .bInterfaceSubClass = 1,
  2577. .bInterfaceProtocol = 0,
  2578. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
  2579. | UVC_QUIRK_PROBE_EXTRAFIELDS) },
  2580. /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
  2581. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2582. | USB_DEVICE_ID_MATCH_INT_INFO,
  2583. .idVendor = 0x1871,
  2584. .idProduct = 0x0516,
  2585. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2586. .bInterfaceSubClass = 1,
  2587. .bInterfaceProtocol = 0 },
  2588. /* Ecamm Pico iMage */
  2589. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2590. | USB_DEVICE_ID_MATCH_INT_INFO,
  2591. .idVendor = 0x18cd,
  2592. .idProduct = 0xcafe,
  2593. .bInterfaceClass = USB_CLASS_VIDEO,
  2594. .bInterfaceSubClass = 1,
  2595. .bInterfaceProtocol = 0,
  2596. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) },
  2597. /* Manta MM-353 Plako */
  2598. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2599. | USB_DEVICE_ID_MATCH_INT_INFO,
  2600. .idVendor = 0x18ec,
  2601. .idProduct = 0x3188,
  2602. .bInterfaceClass = USB_CLASS_VIDEO,
  2603. .bInterfaceSubClass = 1,
  2604. .bInterfaceProtocol = 0,
  2605. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2606. /* FSC WebCam V30S */
  2607. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2608. | USB_DEVICE_ID_MATCH_INT_INFO,
  2609. .idVendor = 0x18ec,
  2610. .idProduct = 0x3288,
  2611. .bInterfaceClass = USB_CLASS_VIDEO,
  2612. .bInterfaceSubClass = 1,
  2613. .bInterfaceProtocol = 0,
  2614. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2615. /* Arkmicro unbranded */
  2616. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2617. | USB_DEVICE_ID_MATCH_INT_INFO,
  2618. .idVendor = 0x18ec,
  2619. .idProduct = 0x3290,
  2620. .bInterfaceClass = USB_CLASS_VIDEO,
  2621. .bInterfaceSubClass = 1,
  2622. .bInterfaceProtocol = 0,
  2623. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
  2624. /* The Imaging Source USB CCD cameras */
  2625. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2626. | USB_DEVICE_ID_MATCH_INT_INFO,
  2627. .idVendor = 0x199e,
  2628. .idProduct = 0x8102,
  2629. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2630. .bInterfaceSubClass = 1,
  2631. .bInterfaceProtocol = 0 },
  2632. /* Bodelin ProScopeHR */
  2633. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2634. | USB_DEVICE_ID_MATCH_DEV_HI
  2635. | USB_DEVICE_ID_MATCH_INT_INFO,
  2636. .idVendor = 0x19ab,
  2637. .idProduct = 0x1000,
  2638. .bcdDevice_hi = 0x0126,
  2639. .bInterfaceClass = USB_CLASS_VIDEO,
  2640. .bInterfaceSubClass = 1,
  2641. .bInterfaceProtocol = 0,
  2642. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) },
  2643. /* MSI StarCam 370i */
  2644. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2645. | USB_DEVICE_ID_MATCH_INT_INFO,
  2646. .idVendor = 0x1b3b,
  2647. .idProduct = 0x2951,
  2648. .bInterfaceClass = USB_CLASS_VIDEO,
  2649. .bInterfaceSubClass = 1,
  2650. .bInterfaceProtocol = 0,
  2651. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2652. /* Generalplus Technology Inc. 808 Camera */
  2653. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2654. | USB_DEVICE_ID_MATCH_INT_INFO,
  2655. .idVendor = 0x1b3f,
  2656. .idProduct = 0x2002,
  2657. .bInterfaceClass = USB_CLASS_VIDEO,
  2658. .bInterfaceSubClass = 1,
  2659. .bInterfaceProtocol = 0,
  2660. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2661. /* Shenzhen Aoni Electronic Co.,Ltd 2K FHD camera */
  2662. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2663. | USB_DEVICE_ID_MATCH_INT_INFO,
  2664. .idVendor = 0x1bcf,
  2665. .idProduct = 0x0b40,
  2666. .bInterfaceClass = USB_CLASS_VIDEO,
  2667. .bInterfaceSubClass = 1,
  2668. .bInterfaceProtocol = 0,
  2669. .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
  2670. .uvc_version = 0x010a,
  2671. } },
  2672. /* SiGma Micro USB Web Camera */
  2673. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2674. | USB_DEVICE_ID_MATCH_INT_INFO,
  2675. .idVendor = 0x1c4f,
  2676. .idProduct = 0x3000,
  2677. .bInterfaceClass = USB_CLASS_VIDEO,
  2678. .bInterfaceSubClass = 1,
  2679. .bInterfaceProtocol = 0,
  2680. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
  2681. | UVC_QUIRK_IGNORE_SELECTOR_UNIT) },
  2682. /* Actions Microelectronics Co. Display capture-UVC05 */
  2683. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2684. | USB_DEVICE_ID_MATCH_INT_INFO,
  2685. .idVendor = 0x1de1,
  2686. .idProduct = 0xf105,
  2687. .bInterfaceClass = USB_CLASS_VIDEO,
  2688. .bInterfaceSubClass = 1,
  2689. .bInterfaceProtocol = 0,
  2690. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) },
  2691. /* NXP Semiconductors IR VIDEO */
  2692. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2693. | USB_DEVICE_ID_MATCH_INT_INFO,
  2694. .idVendor = 0x1fc9,
  2695. .idProduct = 0x009b,
  2696. .bInterfaceClass = USB_CLASS_VIDEO,
  2697. .bInterfaceSubClass = 1,
  2698. .bInterfaceProtocol = 0,
  2699. .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
  2700. /* Oculus VR Positional Tracker DK2 */
  2701. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2702. | USB_DEVICE_ID_MATCH_INT_INFO,
  2703. .idVendor = 0x2833,
  2704. .idProduct = 0x0201,
  2705. .bInterfaceClass = USB_CLASS_VIDEO,
  2706. .bInterfaceSubClass = 1,
  2707. .bInterfaceProtocol = 0,
  2708. .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
  2709. /* Oculus VR Rift Sensor */
  2710. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2711. | USB_DEVICE_ID_MATCH_INT_INFO,
  2712. .idVendor = 0x2833,
  2713. .idProduct = 0x0211,
  2714. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  2715. .bInterfaceSubClass = 1,
  2716. .bInterfaceProtocol = 0,
  2717. .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
  2718. /* GEO Semiconductor GC6500 */
  2719. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2720. | USB_DEVICE_ID_MATCH_INT_INFO,
  2721. .idVendor = 0x29fe,
  2722. .idProduct = 0x4d53,
  2723. .bInterfaceClass = USB_CLASS_VIDEO,
  2724. .bInterfaceSubClass = 1,
  2725. .bInterfaceProtocol = 0,
  2726. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) },
  2727. /* Insta360 Link */
  2728. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2729. | USB_DEVICE_ID_MATCH_INT_INFO,
  2730. .idVendor = 0x2e1a,
  2731. .idProduct = 0x4c01,
  2732. .bInterfaceClass = USB_CLASS_VIDEO,
  2733. .bInterfaceSubClass = 1,
  2734. .bInterfaceProtocol = 0,
  2735. .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) },
  2736. /* Intel D410/ASR depth camera */
  2737. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2738. | USB_DEVICE_ID_MATCH_INT_INFO,
  2739. .idVendor = 0x8086,
  2740. .idProduct = 0x0ad2,
  2741. .bInterfaceClass = USB_CLASS_VIDEO,
  2742. .bInterfaceSubClass = 1,
  2743. .bInterfaceProtocol = 0,
  2744. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2745. /* Intel D415/ASRC depth camera */
  2746. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2747. | USB_DEVICE_ID_MATCH_INT_INFO,
  2748. .idVendor = 0x8086,
  2749. .idProduct = 0x0ad3,
  2750. .bInterfaceClass = USB_CLASS_VIDEO,
  2751. .bInterfaceSubClass = 1,
  2752. .bInterfaceProtocol = 0,
  2753. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2754. /* Intel D430/AWG depth camera */
  2755. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2756. | USB_DEVICE_ID_MATCH_INT_INFO,
  2757. .idVendor = 0x8086,
  2758. .idProduct = 0x0ad4,
  2759. .bInterfaceClass = USB_CLASS_VIDEO,
  2760. .bInterfaceSubClass = 1,
  2761. .bInterfaceProtocol = 0,
  2762. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2763. /* Intel RealSense D4M */
  2764. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2765. | USB_DEVICE_ID_MATCH_INT_INFO,
  2766. .idVendor = 0x8086,
  2767. .idProduct = 0x0b03,
  2768. .bInterfaceClass = USB_CLASS_VIDEO,
  2769. .bInterfaceSubClass = 1,
  2770. .bInterfaceProtocol = 0,
  2771. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2772. /* Intel D435/AWGC depth camera */
  2773. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2774. | USB_DEVICE_ID_MATCH_INT_INFO,
  2775. .idVendor = 0x8086,
  2776. .idProduct = 0x0b07,
  2777. .bInterfaceClass = USB_CLASS_VIDEO,
  2778. .bInterfaceSubClass = 1,
  2779. .bInterfaceProtocol = 0,
  2780. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2781. /* Intel D435i depth camera */
  2782. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2783. | USB_DEVICE_ID_MATCH_INT_INFO,
  2784. .idVendor = 0x8086,
  2785. .idProduct = 0x0b3a,
  2786. .bInterfaceClass = USB_CLASS_VIDEO,
  2787. .bInterfaceSubClass = 1,
  2788. .bInterfaceProtocol = 0,
  2789. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2790. /* Intel D405 Depth Camera */
  2791. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2792. | USB_DEVICE_ID_MATCH_INT_INFO,
  2793. .idVendor = 0x8086,
  2794. .idProduct = 0x0b5b,
  2795. .bInterfaceClass = USB_CLASS_VIDEO,
  2796. .bInterfaceSubClass = 1,
  2797. .bInterfaceProtocol = 0,
  2798. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2799. /* Intel D455 Depth Camera */
  2800. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2801. | USB_DEVICE_ID_MATCH_INT_INFO,
  2802. .idVendor = 0x8086,
  2803. .idProduct = 0x0b5c,
  2804. .bInterfaceClass = USB_CLASS_VIDEO,
  2805. .bInterfaceSubClass = 1,
  2806. .bInterfaceProtocol = 0,
  2807. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2808. /* Intel D421 Depth Module */
  2809. { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
  2810. | USB_DEVICE_ID_MATCH_INT_INFO,
  2811. .idVendor = 0x8086,
  2812. .idProduct = 0x1155,
  2813. .bInterfaceClass = USB_CLASS_VIDEO,
  2814. .bInterfaceSubClass = 1,
  2815. .bInterfaceProtocol = 0,
  2816. .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
  2817. /* Generic USB Video Class */
  2818. { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
  2819. { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
  2820. {}
  2821. };
  2822. MODULE_DEVICE_TABLE(usb, uvc_ids);
  2823. static struct usb_driver uvc_driver = {
  2824. .name = "uvcvideo",
  2825. .probe = uvc_probe,
  2826. .disconnect = uvc_disconnect,
  2827. .suspend = uvc_suspend,
  2828. .resume = uvc_resume,
  2829. .reset_resume = uvc_reset_resume,
  2830. .id_table = uvc_ids,
  2831. .supports_autosuspend = 1,
  2832. };
  2833. static int __init uvc_init(void)
  2834. {
  2835. int ret;
  2836. uvc_debugfs_init();
  2837. ret = usb_register(&uvc_driver);
  2838. if (ret < 0) {
  2839. uvc_debugfs_cleanup();
  2840. return ret;
  2841. }
  2842. return 0;
  2843. }
  2844. static void __exit uvc_cleanup(void)
  2845. {
  2846. usb_deregister(&uvc_driver);
  2847. uvc_debugfs_cleanup();
  2848. }
  2849. module_init(uvc_init);
  2850. module_exit(uvc_cleanup);
  2851. MODULE_AUTHOR(DRIVER_AUTHOR);
  2852. MODULE_DESCRIPTION(DRIVER_DESC);
  2853. MODULE_LICENSE("GPL");
  2854. MODULE_VERSION(DRIVER_VERSION);