uvc_ctrl.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  1. /*
  2. * uvc_ctrl.c -- USB Video Class driver - Controls
  3. *
  4. * Copyright (C) 2005-2009
  5. * Laurent Pinchart (laurent.pinchart@skynet.be)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/list.h>
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/usb.h>
  19. #include <linux/videodev2.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/wait.h>
  22. #include <asm/atomic.h>
  23. #include "uvcvideo.h"
  24. #define UVC_CTRL_DATA_CURRENT 0
  25. #define UVC_CTRL_DATA_BACKUP 1
  26. #define UVC_CTRL_DATA_MIN 2
  27. #define UVC_CTRL_DATA_MAX 3
  28. #define UVC_CTRL_DATA_RES 4
  29. #define UVC_CTRL_DATA_DEF 5
  30. #define UVC_CTRL_DATA_LAST 6
  31. /* ------------------------------------------------------------------------
  32. * Controls
  33. */
  34. static struct uvc_control_info uvc_ctrls[] = {
  35. {
  36. .entity = UVC_GUID_UVC_PROCESSING,
  37. .selector = UVC_PU_BRIGHTNESS_CONTROL,
  38. .index = 0,
  39. .size = 2,
  40. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  41. | UVC_CONTROL_RESTORE,
  42. },
  43. {
  44. .entity = UVC_GUID_UVC_PROCESSING,
  45. .selector = UVC_PU_CONTRAST_CONTROL,
  46. .index = 1,
  47. .size = 2,
  48. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  49. | UVC_CONTROL_RESTORE,
  50. },
  51. {
  52. .entity = UVC_GUID_UVC_PROCESSING,
  53. .selector = UVC_PU_HUE_CONTROL,
  54. .index = 2,
  55. .size = 2,
  56. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  57. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  58. },
  59. {
  60. .entity = UVC_GUID_UVC_PROCESSING,
  61. .selector = UVC_PU_SATURATION_CONTROL,
  62. .index = 3,
  63. .size = 2,
  64. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  65. | UVC_CONTROL_RESTORE,
  66. },
  67. {
  68. .entity = UVC_GUID_UVC_PROCESSING,
  69. .selector = UVC_PU_SHARPNESS_CONTROL,
  70. .index = 4,
  71. .size = 2,
  72. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  73. | UVC_CONTROL_RESTORE,
  74. },
  75. {
  76. .entity = UVC_GUID_UVC_PROCESSING,
  77. .selector = UVC_PU_GAMMA_CONTROL,
  78. .index = 5,
  79. .size = 2,
  80. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  81. | UVC_CONTROL_RESTORE,
  82. },
  83. {
  84. .entity = UVC_GUID_UVC_PROCESSING,
  85. .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
  86. .index = 6,
  87. .size = 2,
  88. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  89. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  90. },
  91. {
  92. .entity = UVC_GUID_UVC_PROCESSING,
  93. .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,
  94. .index = 7,
  95. .size = 4,
  96. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  97. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  98. },
  99. {
  100. .entity = UVC_GUID_UVC_PROCESSING,
  101. .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL,
  102. .index = 8,
  103. .size = 2,
  104. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  105. | UVC_CONTROL_RESTORE,
  106. },
  107. {
  108. .entity = UVC_GUID_UVC_PROCESSING,
  109. .selector = UVC_PU_GAIN_CONTROL,
  110. .index = 9,
  111. .size = 2,
  112. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  113. | UVC_CONTROL_RESTORE,
  114. },
  115. {
  116. .entity = UVC_GUID_UVC_PROCESSING,
  117. .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
  118. .index = 10,
  119. .size = 1,
  120. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  121. | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
  122. },
  123. {
  124. .entity = UVC_GUID_UVC_PROCESSING,
  125. .selector = UVC_PU_HUE_AUTO_CONTROL,
  126. .index = 11,
  127. .size = 1,
  128. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  129. | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
  130. },
  131. {
  132. .entity = UVC_GUID_UVC_PROCESSING,
  133. .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
  134. .index = 12,
  135. .size = 1,
  136. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  137. | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
  138. },
  139. {
  140. .entity = UVC_GUID_UVC_PROCESSING,
  141. .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
  142. .index = 13,
  143. .size = 1,
  144. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  145. | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
  146. },
  147. {
  148. .entity = UVC_GUID_UVC_PROCESSING,
  149. .selector = UVC_PU_DIGITAL_MULTIPLIER_CONTROL,
  150. .index = 14,
  151. .size = 2,
  152. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  153. | UVC_CONTROL_RESTORE,
  154. },
  155. {
  156. .entity = UVC_GUID_UVC_PROCESSING,
  157. .selector = UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,
  158. .index = 15,
  159. .size = 2,
  160. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  161. | UVC_CONTROL_RESTORE,
  162. },
  163. {
  164. .entity = UVC_GUID_UVC_PROCESSING,
  165. .selector = UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL,
  166. .index = 16,
  167. .size = 1,
  168. .flags = UVC_CONTROL_GET_CUR,
  169. },
  170. {
  171. .entity = UVC_GUID_UVC_PROCESSING,
  172. .selector = UVC_PU_ANALOG_LOCK_STATUS_CONTROL,
  173. .index = 17,
  174. .size = 1,
  175. .flags = UVC_CONTROL_GET_CUR,
  176. },
  177. {
  178. .entity = UVC_GUID_UVC_CAMERA,
  179. .selector = UVC_CT_SCANNING_MODE_CONTROL,
  180. .index = 0,
  181. .size = 1,
  182. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  183. | UVC_CONTROL_RESTORE,
  184. },
  185. {
  186. .entity = UVC_GUID_UVC_CAMERA,
  187. .selector = UVC_CT_AE_MODE_CONTROL,
  188. .index = 1,
  189. .size = 1,
  190. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  191. | UVC_CONTROL_GET_DEF | UVC_CONTROL_GET_RES
  192. | UVC_CONTROL_RESTORE,
  193. },
  194. {
  195. .entity = UVC_GUID_UVC_CAMERA,
  196. .selector = UVC_CT_AE_PRIORITY_CONTROL,
  197. .index = 2,
  198. .size = 1,
  199. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  200. | UVC_CONTROL_RESTORE,
  201. },
  202. {
  203. .entity = UVC_GUID_UVC_CAMERA,
  204. .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,
  205. .index = 3,
  206. .size = 4,
  207. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  208. | UVC_CONTROL_RESTORE,
  209. },
  210. {
  211. .entity = UVC_GUID_UVC_CAMERA,
  212. .selector = UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL,
  213. .index = 4,
  214. .size = 1,
  215. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_RESTORE,
  216. },
  217. {
  218. .entity = UVC_GUID_UVC_CAMERA,
  219. .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL,
  220. .index = 5,
  221. .size = 2,
  222. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  223. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  224. },
  225. {
  226. .entity = UVC_GUID_UVC_CAMERA,
  227. .selector = UVC_CT_FOCUS_RELATIVE_CONTROL,
  228. .index = 6,
  229. .size = 2,
  230. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
  231. | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
  232. | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
  233. },
  234. {
  235. .entity = UVC_GUID_UVC_CAMERA,
  236. .selector = UVC_CT_IRIS_ABSOLUTE_CONTROL,
  237. .index = 7,
  238. .size = 2,
  239. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  240. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  241. },
  242. {
  243. .entity = UVC_GUID_UVC_CAMERA,
  244. .selector = UVC_CT_IRIS_RELATIVE_CONTROL,
  245. .index = 8,
  246. .size = 1,
  247. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_AUTO_UPDATE,
  248. },
  249. {
  250. .entity = UVC_GUID_UVC_CAMERA,
  251. .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL,
  252. .index = 9,
  253. .size = 2,
  254. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  255. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  256. },
  257. {
  258. .entity = UVC_GUID_UVC_CAMERA,
  259. .selector = UVC_CT_ZOOM_RELATIVE_CONTROL,
  260. .index = 10,
  261. .size = 3,
  262. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
  263. | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
  264. | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
  265. },
  266. {
  267. .entity = UVC_GUID_UVC_CAMERA,
  268. .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL,
  269. .index = 11,
  270. .size = 8,
  271. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  272. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  273. },
  274. {
  275. .entity = UVC_GUID_UVC_CAMERA,
  276. .selector = UVC_CT_PANTILT_RELATIVE_CONTROL,
  277. .index = 12,
  278. .size = 4,
  279. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
  280. | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
  281. | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
  282. },
  283. {
  284. .entity = UVC_GUID_UVC_CAMERA,
  285. .selector = UVC_CT_ROLL_ABSOLUTE_CONTROL,
  286. .index = 13,
  287. .size = 2,
  288. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
  289. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  290. },
  291. {
  292. .entity = UVC_GUID_UVC_CAMERA,
  293. .selector = UVC_CT_ROLL_RELATIVE_CONTROL,
  294. .index = 14,
  295. .size = 2,
  296. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
  297. | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
  298. | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
  299. },
  300. {
  301. .entity = UVC_GUID_UVC_CAMERA,
  302. .selector = UVC_CT_FOCUS_AUTO_CONTROL,
  303. .index = 17,
  304. .size = 1,
  305. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  306. | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
  307. },
  308. {
  309. .entity = UVC_GUID_UVC_CAMERA,
  310. .selector = UVC_CT_PRIVACY_CONTROL,
  311. .index = 18,
  312. .size = 1,
  313. .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
  314. | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
  315. },
  316. };
  317. static struct uvc_menu_info power_line_frequency_controls[] = {
  318. { 0, "Disabled" },
  319. { 1, "50 Hz" },
  320. { 2, "60 Hz" },
  321. };
  322. static struct uvc_menu_info exposure_auto_controls[] = {
  323. { 2, "Auto Mode" },
  324. { 1, "Manual Mode" },
  325. { 4, "Shutter Priority Mode" },
  326. { 8, "Aperture Priority Mode" },
  327. };
  328. static __s32 uvc_ctrl_get_zoom(struct uvc_control_mapping *mapping,
  329. __u8 query, const __u8 *data)
  330. {
  331. __s8 zoom = (__s8)data[0];
  332. switch (query) {
  333. case UVC_GET_CUR:
  334. return (zoom == 0) ? 0 : (zoom > 0 ? data[2] : -data[2]);
  335. case UVC_GET_MIN:
  336. case UVC_GET_MAX:
  337. case UVC_GET_RES:
  338. case UVC_GET_DEF:
  339. default:
  340. return data[2];
  341. }
  342. }
  343. static void uvc_ctrl_set_zoom(struct uvc_control_mapping *mapping,
  344. __s32 value, __u8 *data)
  345. {
  346. data[0] = value == 0 ? 0 : (value > 0) ? 1 : 0xff;
  347. data[2] = min((int)abs(value), 0xff);
  348. }
  349. static struct uvc_control_mapping uvc_ctrl_mappings[] = {
  350. {
  351. .id = V4L2_CID_BRIGHTNESS,
  352. .name = "Brightness",
  353. .entity = UVC_GUID_UVC_PROCESSING,
  354. .selector = UVC_PU_BRIGHTNESS_CONTROL,
  355. .size = 16,
  356. .offset = 0,
  357. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  358. .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
  359. },
  360. {
  361. .id = V4L2_CID_CONTRAST,
  362. .name = "Contrast",
  363. .entity = UVC_GUID_UVC_PROCESSING,
  364. .selector = UVC_PU_CONTRAST_CONTROL,
  365. .size = 16,
  366. .offset = 0,
  367. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  368. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  369. },
  370. {
  371. .id = V4L2_CID_HUE,
  372. .name = "Hue",
  373. .entity = UVC_GUID_UVC_PROCESSING,
  374. .selector = UVC_PU_HUE_CONTROL,
  375. .size = 16,
  376. .offset = 0,
  377. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  378. .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
  379. },
  380. {
  381. .id = V4L2_CID_SATURATION,
  382. .name = "Saturation",
  383. .entity = UVC_GUID_UVC_PROCESSING,
  384. .selector = UVC_PU_SATURATION_CONTROL,
  385. .size = 16,
  386. .offset = 0,
  387. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  388. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  389. },
  390. {
  391. .id = V4L2_CID_SHARPNESS,
  392. .name = "Sharpness",
  393. .entity = UVC_GUID_UVC_PROCESSING,
  394. .selector = UVC_PU_SHARPNESS_CONTROL,
  395. .size = 16,
  396. .offset = 0,
  397. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  398. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  399. },
  400. {
  401. .id = V4L2_CID_GAMMA,
  402. .name = "Gamma",
  403. .entity = UVC_GUID_UVC_PROCESSING,
  404. .selector = UVC_PU_GAMMA_CONTROL,
  405. .size = 16,
  406. .offset = 0,
  407. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  408. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  409. },
  410. {
  411. .id = V4L2_CID_BACKLIGHT_COMPENSATION,
  412. .name = "Backlight Compensation",
  413. .entity = UVC_GUID_UVC_PROCESSING,
  414. .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL,
  415. .size = 16,
  416. .offset = 0,
  417. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  418. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  419. },
  420. {
  421. .id = V4L2_CID_GAIN,
  422. .name = "Gain",
  423. .entity = UVC_GUID_UVC_PROCESSING,
  424. .selector = UVC_PU_GAIN_CONTROL,
  425. .size = 16,
  426. .offset = 0,
  427. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  428. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  429. },
  430. {
  431. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  432. .name = "Power Line Frequency",
  433. .entity = UVC_GUID_UVC_PROCESSING,
  434. .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
  435. .size = 2,
  436. .offset = 0,
  437. .v4l2_type = V4L2_CTRL_TYPE_MENU,
  438. .data_type = UVC_CTRL_DATA_TYPE_ENUM,
  439. .menu_info = power_line_frequency_controls,
  440. .menu_count = ARRAY_SIZE(power_line_frequency_controls),
  441. },
  442. {
  443. .id = V4L2_CID_HUE_AUTO,
  444. .name = "Hue, Auto",
  445. .entity = UVC_GUID_UVC_PROCESSING,
  446. .selector = UVC_PU_HUE_AUTO_CONTROL,
  447. .size = 1,
  448. .offset = 0,
  449. .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
  450. .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN,
  451. },
  452. {
  453. .id = V4L2_CID_EXPOSURE_AUTO,
  454. .name = "Exposure, Auto",
  455. .entity = UVC_GUID_UVC_CAMERA,
  456. .selector = UVC_CT_AE_MODE_CONTROL,
  457. .size = 4,
  458. .offset = 0,
  459. .v4l2_type = V4L2_CTRL_TYPE_MENU,
  460. .data_type = UVC_CTRL_DATA_TYPE_BITMASK,
  461. .menu_info = exposure_auto_controls,
  462. .menu_count = ARRAY_SIZE(exposure_auto_controls),
  463. },
  464. {
  465. .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY,
  466. .name = "Exposure, Auto Priority",
  467. .entity = UVC_GUID_UVC_CAMERA,
  468. .selector = UVC_CT_AE_PRIORITY_CONTROL,
  469. .size = 1,
  470. .offset = 0,
  471. .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
  472. .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN,
  473. },
  474. {
  475. .id = V4L2_CID_EXPOSURE_ABSOLUTE,
  476. .name = "Exposure (Absolute)",
  477. .entity = UVC_GUID_UVC_CAMERA,
  478. .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,
  479. .size = 32,
  480. .offset = 0,
  481. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  482. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  483. },
  484. {
  485. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  486. .name = "White Balance Temperature, Auto",
  487. .entity = UVC_GUID_UVC_PROCESSING,
  488. .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
  489. .size = 1,
  490. .offset = 0,
  491. .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
  492. .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN,
  493. },
  494. {
  495. .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
  496. .name = "White Balance Temperature",
  497. .entity = UVC_GUID_UVC_PROCESSING,
  498. .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
  499. .size = 16,
  500. .offset = 0,
  501. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  502. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  503. },
  504. {
  505. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  506. .name = "White Balance Component, Auto",
  507. .entity = UVC_GUID_UVC_PROCESSING,
  508. .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
  509. .size = 1,
  510. .offset = 0,
  511. .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
  512. .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN,
  513. },
  514. {
  515. .id = V4L2_CID_BLUE_BALANCE,
  516. .name = "White Balance Blue Component",
  517. .entity = UVC_GUID_UVC_PROCESSING,
  518. .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,
  519. .size = 16,
  520. .offset = 0,
  521. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  522. .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
  523. },
  524. {
  525. .id = V4L2_CID_RED_BALANCE,
  526. .name = "White Balance Red Component",
  527. .entity = UVC_GUID_UVC_PROCESSING,
  528. .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,
  529. .size = 16,
  530. .offset = 16,
  531. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  532. .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
  533. },
  534. {
  535. .id = V4L2_CID_FOCUS_ABSOLUTE,
  536. .name = "Focus (absolute)",
  537. .entity = UVC_GUID_UVC_CAMERA,
  538. .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL,
  539. .size = 16,
  540. .offset = 0,
  541. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  542. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  543. },
  544. {
  545. .id = V4L2_CID_FOCUS_AUTO,
  546. .name = "Focus, Auto",
  547. .entity = UVC_GUID_UVC_CAMERA,
  548. .selector = UVC_CT_FOCUS_AUTO_CONTROL,
  549. .size = 1,
  550. .offset = 0,
  551. .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
  552. .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN,
  553. },
  554. {
  555. .id = V4L2_CID_IRIS_ABSOLUTE,
  556. .name = "Iris, Absolute",
  557. .entity = UVC_GUID_UVC_CAMERA,
  558. .selector = UVC_CT_IRIS_ABSOLUTE_CONTROL,
  559. .size = 16,
  560. .offset = 0,
  561. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  562. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  563. },
  564. {
  565. .id = V4L2_CID_IRIS_RELATIVE,
  566. .name = "Iris, Relative",
  567. .entity = UVC_GUID_UVC_CAMERA,
  568. .selector = UVC_CT_IRIS_RELATIVE_CONTROL,
  569. .size = 8,
  570. .offset = 0,
  571. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  572. .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
  573. },
  574. {
  575. .id = V4L2_CID_ZOOM_ABSOLUTE,
  576. .name = "Zoom, Absolute",
  577. .entity = UVC_GUID_UVC_CAMERA,
  578. .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL,
  579. .size = 16,
  580. .offset = 0,
  581. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  582. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  583. },
  584. {
  585. .id = V4L2_CID_ZOOM_CONTINUOUS,
  586. .name = "Zoom, Continuous",
  587. .entity = UVC_GUID_UVC_CAMERA,
  588. .selector = UVC_CT_ZOOM_RELATIVE_CONTROL,
  589. .size = 0,
  590. .offset = 0,
  591. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  592. .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
  593. .get = uvc_ctrl_get_zoom,
  594. .set = uvc_ctrl_set_zoom,
  595. },
  596. {
  597. .id = V4L2_CID_PAN_ABSOLUTE,
  598. .name = "Pan (Absolute)",
  599. .entity = UVC_GUID_UVC_CAMERA,
  600. .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL,
  601. .size = 32,
  602. .offset = 0,
  603. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  604. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  605. },
  606. {
  607. .id = V4L2_CID_TILT_ABSOLUTE,
  608. .name = "Tilt (Absolute)",
  609. .entity = UVC_GUID_UVC_CAMERA,
  610. .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL,
  611. .size = 32,
  612. .offset = 32,
  613. .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
  614. .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
  615. },
  616. {
  617. .id = V4L2_CID_PRIVACY,
  618. .name = "Privacy",
  619. .entity = UVC_GUID_UVC_CAMERA,
  620. .selector = UVC_CT_PRIVACY_CONTROL,
  621. .size = 1,
  622. .offset = 0,
  623. .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
  624. .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN,
  625. },
  626. };
  627. /* ------------------------------------------------------------------------
  628. * Utility functions
  629. */
  630. static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id)
  631. {
  632. return ctrl->uvc_data + id * ctrl->info->size;
  633. }
  634. static inline int uvc_test_bit(const __u8 *data, int bit)
  635. {
  636. return (data[bit >> 3] >> (bit & 7)) & 1;
  637. }
  638. static inline void uvc_clear_bit(__u8 *data, int bit)
  639. {
  640. data[bit >> 3] &= ~(1 << (bit & 7));
  641. }
  642. /* Extract the bit string specified by mapping->offset and mapping->size
  643. * from the little-endian data stored at 'data' and return the result as
  644. * a signed 32bit integer. Sign extension will be performed if the mapping
  645. * references a signed data type.
  646. */
  647. static __s32 uvc_get_le_value(struct uvc_control_mapping *mapping,
  648. __u8 query, const __u8 *data)
  649. {
  650. int bits = mapping->size;
  651. int offset = mapping->offset;
  652. __s32 value = 0;
  653. __u8 mask;
  654. data += offset / 8;
  655. offset &= 7;
  656. mask = ((1LL << bits) - 1) << offset;
  657. for (; bits > 0; data++) {
  658. __u8 byte = *data & mask;
  659. value |= offset > 0 ? (byte >> offset) : (byte << (-offset));
  660. bits -= 8 - (offset > 0 ? offset : 0);
  661. offset -= 8;
  662. mask = (1 << bits) - 1;
  663. }
  664. /* Sign-extend the value if needed. */
  665. if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED)
  666. value |= -(value & (1 << (mapping->size - 1)));
  667. return value;
  668. }
  669. /* Set the bit string specified by mapping->offset and mapping->size
  670. * in the little-endian data stored at 'data' to the value 'value'.
  671. */
  672. static void uvc_set_le_value(struct uvc_control_mapping *mapping,
  673. __s32 value, __u8 *data)
  674. {
  675. int bits = mapping->size;
  676. int offset = mapping->offset;
  677. __u8 mask;
  678. /* According to the v4l2 spec, writing any value to a button control
  679. * should result in the action belonging to the button control being
  680. * triggered. UVC devices however want to see a 1 written -> override
  681. * value.
  682. */
  683. if (mapping->v4l2_type == V4L2_CTRL_TYPE_BUTTON)
  684. value = -1;
  685. data += offset / 8;
  686. offset &= 7;
  687. for (; bits > 0; data++) {
  688. mask = ((1LL << bits) - 1) << offset;
  689. *data = (*data & ~mask) | ((value << offset) & mask);
  690. value >>= offset ? offset : 8;
  691. bits -= 8 - offset;
  692. offset = 0;
  693. }
  694. }
  695. /* ------------------------------------------------------------------------
  696. * Terminal and unit management
  697. */
  698. static const __u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING;
  699. static const __u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA;
  700. static const __u8 uvc_media_transport_input_guid[16] =
  701. UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT;
  702. static int uvc_entity_match_guid(struct uvc_entity *entity, __u8 guid[16])
  703. {
  704. switch (UVC_ENTITY_TYPE(entity)) {
  705. case UVC_ITT_CAMERA:
  706. return memcmp(uvc_camera_guid, guid, 16) == 0;
  707. case UVC_ITT_MEDIA_TRANSPORT_INPUT:
  708. return memcmp(uvc_media_transport_input_guid, guid, 16) == 0;
  709. case UVC_VC_PROCESSING_UNIT:
  710. return memcmp(uvc_processing_guid, guid, 16) == 0;
  711. case UVC_VC_EXTENSION_UNIT:
  712. return memcmp(entity->extension.guidExtensionCode,
  713. guid, 16) == 0;
  714. default:
  715. return 0;
  716. }
  717. }
  718. /* ------------------------------------------------------------------------
  719. * UVC Controls
  720. */
  721. static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id,
  722. struct uvc_control_mapping **mapping, struct uvc_control **control,
  723. int next)
  724. {
  725. struct uvc_control *ctrl;
  726. struct uvc_control_mapping *map;
  727. unsigned int i;
  728. if (entity == NULL)
  729. return;
  730. for (i = 0; i < entity->ncontrols; ++i) {
  731. ctrl = &entity->controls[i];
  732. if (ctrl->info == NULL)
  733. continue;
  734. list_for_each_entry(map, &ctrl->info->mappings, list) {
  735. if ((map->id == v4l2_id) && !next) {
  736. *control = ctrl;
  737. *mapping = map;
  738. return;
  739. }
  740. if ((*mapping == NULL || (*mapping)->id > map->id) &&
  741. (map->id > v4l2_id) && next) {
  742. *control = ctrl;
  743. *mapping = map;
  744. }
  745. }
  746. }
  747. }
  748. struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
  749. __u32 v4l2_id, struct uvc_control_mapping **mapping)
  750. {
  751. struct uvc_control *ctrl = NULL;
  752. struct uvc_entity *entity;
  753. int next = v4l2_id & V4L2_CTRL_FLAG_NEXT_CTRL;
  754. *mapping = NULL;
  755. /* Mask the query flags. */
  756. v4l2_id &= V4L2_CTRL_ID_MASK;
  757. /* Find the control. */
  758. list_for_each_entry(entity, &chain->entities, chain) {
  759. __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next);
  760. if (ctrl && !next)
  761. return ctrl;
  762. }
  763. if (ctrl == NULL && !next)
  764. uvc_trace(UVC_TRACE_CONTROL, "Control 0x%08x not found.\n",
  765. v4l2_id);
  766. return ctrl;
  767. }
  768. static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain,
  769. struct uvc_control *ctrl)
  770. {
  771. int ret;
  772. if (ctrl->info->flags & UVC_CONTROL_GET_DEF) {
  773. ret = uvc_query_ctrl(chain->dev, UVC_GET_DEF, ctrl->entity->id,
  774. chain->dev->intfnum, ctrl->info->selector,
  775. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF),
  776. ctrl->info->size);
  777. if (ret < 0)
  778. return ret;
  779. }
  780. if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {
  781. ret = uvc_query_ctrl(chain->dev, UVC_GET_MIN, ctrl->entity->id,
  782. chain->dev->intfnum, ctrl->info->selector,
  783. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN),
  784. ctrl->info->size);
  785. if (ret < 0)
  786. return ret;
  787. }
  788. if (ctrl->info->flags & UVC_CONTROL_GET_MAX) {
  789. ret = uvc_query_ctrl(chain->dev, UVC_GET_MAX, ctrl->entity->id,
  790. chain->dev->intfnum, ctrl->info->selector,
  791. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX),
  792. ctrl->info->size);
  793. if (ret < 0)
  794. return ret;
  795. }
  796. if (ctrl->info->flags & UVC_CONTROL_GET_RES) {
  797. ret = uvc_query_ctrl(chain->dev, UVC_GET_RES, ctrl->entity->id,
  798. chain->dev->intfnum, ctrl->info->selector,
  799. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES),
  800. ctrl->info->size);
  801. if (ret < 0)
  802. return ret;
  803. }
  804. ctrl->cached = 1;
  805. return 0;
  806. }
  807. int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
  808. struct v4l2_queryctrl *v4l2_ctrl)
  809. {
  810. struct uvc_control *ctrl;
  811. struct uvc_control_mapping *mapping;
  812. struct uvc_menu_info *menu;
  813. unsigned int i;
  814. int ret;
  815. ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
  816. if (ctrl == NULL)
  817. return -EINVAL;
  818. memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
  819. v4l2_ctrl->id = mapping->id;
  820. v4l2_ctrl->type = mapping->v4l2_type;
  821. strlcpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
  822. v4l2_ctrl->flags = 0;
  823. if (!(ctrl->info->flags & UVC_CONTROL_GET_CUR))
  824. v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
  825. if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR))
  826. v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  827. if (!ctrl->cached) {
  828. ret = uvc_ctrl_populate_cache(chain, ctrl);
  829. if (ret < 0)
  830. return ret;
  831. }
  832. if (ctrl->info->flags & UVC_CONTROL_GET_DEF) {
  833. v4l2_ctrl->default_value = mapping->get(mapping, UVC_GET_DEF,
  834. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF));
  835. }
  836. switch (mapping->v4l2_type) {
  837. case V4L2_CTRL_TYPE_MENU:
  838. v4l2_ctrl->minimum = 0;
  839. v4l2_ctrl->maximum = mapping->menu_count - 1;
  840. v4l2_ctrl->step = 1;
  841. menu = mapping->menu_info;
  842. for (i = 0; i < mapping->menu_count; ++i, ++menu) {
  843. if (menu->value == v4l2_ctrl->default_value) {
  844. v4l2_ctrl->default_value = i;
  845. break;
  846. }
  847. }
  848. return 0;
  849. case V4L2_CTRL_TYPE_BOOLEAN:
  850. v4l2_ctrl->minimum = 0;
  851. v4l2_ctrl->maximum = 1;
  852. v4l2_ctrl->step = 1;
  853. return 0;
  854. case V4L2_CTRL_TYPE_BUTTON:
  855. v4l2_ctrl->minimum = 0;
  856. v4l2_ctrl->maximum = 0;
  857. v4l2_ctrl->step = 0;
  858. return 0;
  859. default:
  860. break;
  861. }
  862. if (ctrl->info->flags & UVC_CONTROL_GET_MIN)
  863. v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN,
  864. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
  865. if (ctrl->info->flags & UVC_CONTROL_GET_MAX)
  866. v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX,
  867. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
  868. if (ctrl->info->flags & UVC_CONTROL_GET_RES)
  869. v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES,
  870. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
  871. return 0;
  872. }
  873. /* --------------------------------------------------------------------------
  874. * Control transactions
  875. *
  876. * To make extended set operations as atomic as the hardware allows, controls
  877. * are handled using begin/commit/rollback operations.
  878. *
  879. * At the beginning of a set request, uvc_ctrl_begin should be called to
  880. * initialize the request. This function acquires the control lock.
  881. *
  882. * When setting a control, the new value is stored in the control data field
  883. * at position UVC_CTRL_DATA_CURRENT. The control is then marked as dirty for
  884. * later processing. If the UVC and V4L2 control sizes differ, the current
  885. * value is loaded from the hardware before storing the new value in the data
  886. * field.
  887. *
  888. * After processing all controls in the transaction, uvc_ctrl_commit or
  889. * uvc_ctrl_rollback must be called to apply the pending changes to the
  890. * hardware or revert them. When applying changes, all controls marked as
  891. * dirty will be modified in the UVC device, and the dirty flag will be
  892. * cleared. When reverting controls, the control data field
  893. * UVC_CTRL_DATA_CURRENT is reverted to its previous value
  894. * (UVC_CTRL_DATA_BACKUP) for all dirty controls. Both functions release the
  895. * control lock.
  896. */
  897. int uvc_ctrl_begin(struct uvc_video_chain *chain)
  898. {
  899. return mutex_lock_interruptible(&chain->ctrl_mutex) ? -ERESTARTSYS : 0;
  900. }
  901. static int uvc_ctrl_commit_entity(struct uvc_device *dev,
  902. struct uvc_entity *entity, int rollback)
  903. {
  904. struct uvc_control *ctrl;
  905. unsigned int i;
  906. int ret;
  907. if (entity == NULL)
  908. return 0;
  909. for (i = 0; i < entity->ncontrols; ++i) {
  910. ctrl = &entity->controls[i];
  911. if (ctrl->info == NULL)
  912. continue;
  913. /* Reset the loaded flag for auto-update controls that were
  914. * marked as loaded in uvc_ctrl_get/uvc_ctrl_set to prevent
  915. * uvc_ctrl_get from using the cached value.
  916. */
  917. if (ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE)
  918. ctrl->loaded = 0;
  919. if (!ctrl->dirty)
  920. continue;
  921. if (!rollback)
  922. ret = uvc_query_ctrl(dev, UVC_SET_CUR, ctrl->entity->id,
  923. dev->intfnum, ctrl->info->selector,
  924. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  925. ctrl->info->size);
  926. else
  927. ret = 0;
  928. if (rollback || ret < 0)
  929. memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  930. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
  931. ctrl->info->size);
  932. ctrl->dirty = 0;
  933. if (ret < 0)
  934. return ret;
  935. }
  936. return 0;
  937. }
  938. int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback)
  939. {
  940. struct uvc_entity *entity;
  941. int ret = 0;
  942. /* Find the control. */
  943. list_for_each_entry(entity, &chain->entities, chain) {
  944. ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback);
  945. if (ret < 0)
  946. goto done;
  947. }
  948. done:
  949. mutex_unlock(&chain->ctrl_mutex);
  950. return ret;
  951. }
  952. int uvc_ctrl_get(struct uvc_video_chain *chain,
  953. struct v4l2_ext_control *xctrl)
  954. {
  955. struct uvc_control *ctrl;
  956. struct uvc_control_mapping *mapping;
  957. struct uvc_menu_info *menu;
  958. unsigned int i;
  959. int ret;
  960. ctrl = uvc_find_control(chain, xctrl->id, &mapping);
  961. if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0)
  962. return -EINVAL;
  963. if (!ctrl->loaded) {
  964. ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id,
  965. chain->dev->intfnum, ctrl->info->selector,
  966. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  967. ctrl->info->size);
  968. if (ret < 0)
  969. return ret;
  970. ctrl->loaded = 1;
  971. }
  972. xctrl->value = mapping->get(mapping, UVC_GET_CUR,
  973. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
  974. if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
  975. menu = mapping->menu_info;
  976. for (i = 0; i < mapping->menu_count; ++i, ++menu) {
  977. if (menu->value == xctrl->value) {
  978. xctrl->value = i;
  979. break;
  980. }
  981. }
  982. }
  983. return 0;
  984. }
  985. int uvc_ctrl_set(struct uvc_video_chain *chain,
  986. struct v4l2_ext_control *xctrl)
  987. {
  988. struct uvc_control *ctrl;
  989. struct uvc_control_mapping *mapping;
  990. s32 value;
  991. u32 step;
  992. s32 min;
  993. s32 max;
  994. int ret;
  995. ctrl = uvc_find_control(chain, xctrl->id, &mapping);
  996. if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0)
  997. return -EINVAL;
  998. /* Clamp out of range values. */
  999. switch (mapping->v4l2_type) {
  1000. case V4L2_CTRL_TYPE_INTEGER:
  1001. if (!ctrl->cached) {
  1002. ret = uvc_ctrl_populate_cache(chain, ctrl);
  1003. if (ret < 0)
  1004. return ret;
  1005. }
  1006. min = mapping->get(mapping, UVC_GET_MIN,
  1007. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
  1008. max = mapping->get(mapping, UVC_GET_MAX,
  1009. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
  1010. step = mapping->get(mapping, UVC_GET_RES,
  1011. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
  1012. if (step == 0)
  1013. step = 1;
  1014. xctrl->value = min + (xctrl->value - min + step/2) / step * step;
  1015. xctrl->value = clamp(xctrl->value, min, max);
  1016. value = xctrl->value;
  1017. break;
  1018. case V4L2_CTRL_TYPE_BOOLEAN:
  1019. xctrl->value = clamp(xctrl->value, 0, 1);
  1020. value = xctrl->value;
  1021. break;
  1022. case V4L2_CTRL_TYPE_MENU:
  1023. if (xctrl->value < 0 || xctrl->value >= mapping->menu_count)
  1024. return -ERANGE;
  1025. value = mapping->menu_info[xctrl->value].value;
  1026. break;
  1027. default:
  1028. value = xctrl->value;
  1029. break;
  1030. }
  1031. /* If the mapping doesn't span the whole UVC control, the current value
  1032. * needs to be loaded from the device to perform the read-modify-write
  1033. * operation.
  1034. */
  1035. if (!ctrl->loaded && (ctrl->info->size * 8) != mapping->size) {
  1036. if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) {
  1037. memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  1038. 0, ctrl->info->size);
  1039. } else {
  1040. ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
  1041. ctrl->entity->id, chain->dev->intfnum,
  1042. ctrl->info->selector,
  1043. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  1044. ctrl->info->size);
  1045. if (ret < 0)
  1046. return ret;
  1047. }
  1048. ctrl->loaded = 1;
  1049. }
  1050. /* Backup the current value in case we need to rollback later. */
  1051. if (!ctrl->dirty) {
  1052. memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
  1053. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  1054. ctrl->info->size);
  1055. }
  1056. mapping->set(mapping, value,
  1057. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
  1058. ctrl->dirty = 1;
  1059. ctrl->modified = 1;
  1060. return 0;
  1061. }
  1062. /* --------------------------------------------------------------------------
  1063. * Dynamic controls
  1064. */
  1065. int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
  1066. struct uvc_xu_control *xctrl, int set)
  1067. {
  1068. struct uvc_entity *entity;
  1069. struct uvc_control *ctrl = NULL;
  1070. unsigned int i, found = 0;
  1071. __u8 *data;
  1072. int ret;
  1073. /* Find the extension unit. */
  1074. list_for_each_entry(entity, &chain->entities, chain) {
  1075. if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
  1076. entity->id == xctrl->unit)
  1077. break;
  1078. }
  1079. if (entity->id != xctrl->unit) {
  1080. uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n",
  1081. xctrl->unit);
  1082. return -EINVAL;
  1083. }
  1084. /* Find the control. */
  1085. for (i = 0; i < entity->ncontrols; ++i) {
  1086. ctrl = &entity->controls[i];
  1087. if (ctrl->info == NULL)
  1088. continue;
  1089. if (ctrl->info->selector == xctrl->selector) {
  1090. found = 1;
  1091. break;
  1092. }
  1093. }
  1094. if (!found) {
  1095. uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u not found.\n",
  1096. entity->extension.guidExtensionCode, xctrl->selector);
  1097. return -EINVAL;
  1098. }
  1099. /* Validate control data size. */
  1100. if (ctrl->info->size != xctrl->size)
  1101. return -EINVAL;
  1102. if ((set && !(ctrl->info->flags & UVC_CONTROL_SET_CUR)) ||
  1103. (!set && !(ctrl->info->flags & UVC_CONTROL_GET_CUR)))
  1104. return -EINVAL;
  1105. if (mutex_lock_interruptible(&chain->ctrl_mutex))
  1106. return -ERESTARTSYS;
  1107. memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
  1108. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  1109. xctrl->size);
  1110. data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT);
  1111. if (set && copy_from_user(data, xctrl->data, xctrl->size)) {
  1112. ret = -EFAULT;
  1113. goto out;
  1114. }
  1115. ret = uvc_query_ctrl(chain->dev, set ? UVC_SET_CUR : UVC_GET_CUR,
  1116. xctrl->unit, chain->dev->intfnum, xctrl->selector,
  1117. data, xctrl->size);
  1118. if (ret < 0)
  1119. goto out;
  1120. if (!set && copy_to_user(xctrl->data, data, xctrl->size)) {
  1121. ret = -EFAULT;
  1122. goto out;
  1123. }
  1124. out:
  1125. if (ret)
  1126. memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
  1127. uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
  1128. xctrl->size);
  1129. mutex_unlock(&chain->ctrl_mutex);
  1130. return ret;
  1131. }
  1132. /* --------------------------------------------------------------------------
  1133. * Suspend/resume
  1134. */
  1135. /*
  1136. * Restore control values after resume, skipping controls that haven't been
  1137. * changed.
  1138. *
  1139. * TODO
  1140. * - Don't restore modified controls that are back to their default value.
  1141. * - Handle restore order (Auto-Exposure Mode should be restored before
  1142. * Exposure Time).
  1143. */
  1144. int uvc_ctrl_resume_device(struct uvc_device *dev)
  1145. {
  1146. struct uvc_control *ctrl;
  1147. struct uvc_entity *entity;
  1148. unsigned int i;
  1149. int ret;
  1150. /* Walk the entities list and restore controls when possible. */
  1151. list_for_each_entry(entity, &dev->entities, list) {
  1152. for (i = 0; i < entity->ncontrols; ++i) {
  1153. ctrl = &entity->controls[i];
  1154. if (ctrl->info == NULL || !ctrl->modified ||
  1155. (ctrl->info->flags & UVC_CONTROL_RESTORE) == 0)
  1156. continue;
  1157. printk(KERN_INFO "restoring control %pUl/%u/%u\n",
  1158. ctrl->info->entity, ctrl->info->index,
  1159. ctrl->info->selector);
  1160. ctrl->dirty = 1;
  1161. }
  1162. ret = uvc_ctrl_commit_entity(dev, entity, 0);
  1163. if (ret < 0)
  1164. return ret;
  1165. }
  1166. return 0;
  1167. }
  1168. /* --------------------------------------------------------------------------
  1169. * Control and mapping handling
  1170. */
  1171. static int uvc_ctrl_add_ctrl(struct uvc_device *dev,
  1172. struct uvc_control_info *info)
  1173. {
  1174. struct uvc_entity *entity;
  1175. struct uvc_control *ctrl = NULL;
  1176. int ret = 0, found = 0;
  1177. unsigned int i;
  1178. u8 *uvc_info;
  1179. u8 *uvc_data;
  1180. list_for_each_entry(entity, &dev->entities, list) {
  1181. if (!uvc_entity_match_guid(entity, info->entity))
  1182. continue;
  1183. for (i = 0; i < entity->ncontrols; ++i) {
  1184. ctrl = &entity->controls[i];
  1185. if (ctrl->index == info->index) {
  1186. found = 1;
  1187. break;
  1188. }
  1189. }
  1190. if (found)
  1191. break;
  1192. }
  1193. if (!found)
  1194. return 0;
  1195. uvc_data = kmalloc(info->size * UVC_CTRL_DATA_LAST + 1, GFP_KERNEL);
  1196. if (uvc_data == NULL)
  1197. return -ENOMEM;
  1198. uvc_info = uvc_data + info->size * UVC_CTRL_DATA_LAST;
  1199. if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) {
  1200. /* Check if the device control information and length match
  1201. * the user supplied information.
  1202. */
  1203. ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id,
  1204. dev->intfnum, info->selector, uvc_data, 2);
  1205. if (ret < 0) {
  1206. uvc_trace(UVC_TRACE_CONTROL,
  1207. "GET_LEN failed on control %pUl/%u (%d).\n",
  1208. info->entity, info->selector, ret);
  1209. goto done;
  1210. }
  1211. if (info->size != le16_to_cpu(*(__le16 *)uvc_data)) {
  1212. uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u size "
  1213. "doesn't match user supplied value.\n",
  1214. info->entity, info->selector);
  1215. ret = -EINVAL;
  1216. goto done;
  1217. }
  1218. ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id,
  1219. dev->intfnum, info->selector, uvc_info, 1);
  1220. if (ret < 0) {
  1221. uvc_trace(UVC_TRACE_CONTROL,
  1222. "GET_INFO failed on control %pUl/%u (%d).\n",
  1223. info->entity, info->selector, ret);
  1224. goto done;
  1225. }
  1226. if (((info->flags & UVC_CONTROL_GET_CUR) &&
  1227. !(*uvc_info & UVC_CONTROL_CAP_GET)) ||
  1228. ((info->flags & UVC_CONTROL_SET_CUR) &&
  1229. !(*uvc_info & UVC_CONTROL_CAP_SET))) {
  1230. uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u flags "
  1231. "don't match supported operations.\n",
  1232. info->entity, info->selector);
  1233. ret = -EINVAL;
  1234. goto done;
  1235. }
  1236. }
  1237. ctrl->info = info;
  1238. ctrl->uvc_data = uvc_data;
  1239. ctrl->uvc_info = uvc_info;
  1240. uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s "
  1241. "entity %u\n", ctrl->info->entity, ctrl->info->selector,
  1242. dev->udev->devpath, entity->id);
  1243. done:
  1244. if (ret < 0)
  1245. kfree(uvc_data);
  1246. return ret;
  1247. }
  1248. /*
  1249. * Add an item to the UVC control information list, and instantiate a control
  1250. * structure for each device that supports the control.
  1251. */
  1252. int uvc_ctrl_add_info(struct uvc_control_info *info)
  1253. {
  1254. struct uvc_control_info *ctrl;
  1255. struct uvc_device *dev;
  1256. int ret = 0;
  1257. /* Find matching controls by walking the devices, entities and
  1258. * controls list.
  1259. */
  1260. mutex_lock(&uvc_driver.ctrl_mutex);
  1261. /* First check if the list contains a control matching the new one.
  1262. * Bail out if it does.
  1263. */
  1264. list_for_each_entry(ctrl, &uvc_driver.controls, list) {
  1265. if (memcmp(ctrl->entity, info->entity, 16))
  1266. continue;
  1267. if (ctrl->selector == info->selector) {
  1268. uvc_trace(UVC_TRACE_CONTROL,
  1269. "Control %pUl/%u is already defined.\n",
  1270. info->entity, info->selector);
  1271. ret = -EEXIST;
  1272. goto end;
  1273. }
  1274. if (ctrl->index == info->index) {
  1275. uvc_trace(UVC_TRACE_CONTROL,
  1276. "Control %pUl/%u would overwrite index %d.\n",
  1277. info->entity, info->selector, info->index);
  1278. ret = -EEXIST;
  1279. goto end;
  1280. }
  1281. }
  1282. list_for_each_entry(dev, &uvc_driver.devices, list)
  1283. uvc_ctrl_add_ctrl(dev, info);
  1284. INIT_LIST_HEAD(&info->mappings);
  1285. list_add_tail(&info->list, &uvc_driver.controls);
  1286. end:
  1287. mutex_unlock(&uvc_driver.ctrl_mutex);
  1288. return ret;
  1289. }
  1290. int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping)
  1291. {
  1292. struct uvc_control_info *info;
  1293. struct uvc_control_mapping *map;
  1294. int ret = -EINVAL;
  1295. if (mapping->get == NULL)
  1296. mapping->get = uvc_get_le_value;
  1297. if (mapping->set == NULL)
  1298. mapping->set = uvc_set_le_value;
  1299. if (mapping->id & ~V4L2_CTRL_ID_MASK) {
  1300. uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s' with "
  1301. "invalid control id 0x%08x\n", mapping->name,
  1302. mapping->id);
  1303. return -EINVAL;
  1304. }
  1305. mutex_lock(&uvc_driver.ctrl_mutex);
  1306. list_for_each_entry(info, &uvc_driver.controls, list) {
  1307. if (memcmp(info->entity, mapping->entity, 16) ||
  1308. info->selector != mapping->selector)
  1309. continue;
  1310. if (info->size * 8 < mapping->size + mapping->offset) {
  1311. uvc_trace(UVC_TRACE_CONTROL,
  1312. "Mapping '%s' would overflow control %pUl/%u\n",
  1313. mapping->name, info->entity, info->selector);
  1314. ret = -EOVERFLOW;
  1315. goto end;
  1316. }
  1317. /* Check if the list contains a mapping matching the new one.
  1318. * Bail out if it does.
  1319. */
  1320. list_for_each_entry(map, &info->mappings, list) {
  1321. if (map->id == mapping->id) {
  1322. uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' is "
  1323. "already defined.\n", mapping->name);
  1324. ret = -EEXIST;
  1325. goto end;
  1326. }
  1327. }
  1328. mapping->ctrl = info;
  1329. list_add_tail(&mapping->list, &info->mappings);
  1330. uvc_trace(UVC_TRACE_CONTROL,
  1331. "Adding mapping %s to control %pUl/%u.\n",
  1332. mapping->name, info->entity, info->selector);
  1333. ret = 0;
  1334. break;
  1335. }
  1336. end:
  1337. mutex_unlock(&uvc_driver.ctrl_mutex);
  1338. return ret;
  1339. }
  1340. /*
  1341. * Prune an entity of its bogus controls using a blacklist. Bogus controls
  1342. * are currently the ones that crash the camera or unconditionally return an
  1343. * error when queried.
  1344. */
  1345. static void
  1346. uvc_ctrl_prune_entity(struct uvc_device *dev, struct uvc_entity *entity)
  1347. {
  1348. struct uvc_ctrl_blacklist {
  1349. struct usb_device_id id;
  1350. u8 index;
  1351. };
  1352. static const struct uvc_ctrl_blacklist processing_blacklist[] = {
  1353. { { USB_DEVICE(0x13d3, 0x509b) }, 9 }, /* Gain */
  1354. { { USB_DEVICE(0x1c4f, 0x3000) }, 6 }, /* WB Temperature */
  1355. { { USB_DEVICE(0x5986, 0x0241) }, 2 }, /* Hue */
  1356. };
  1357. static const struct uvc_ctrl_blacklist camera_blacklist[] = {
  1358. { { USB_DEVICE(0x06f8, 0x3005) }, 9 }, /* Zoom, Absolute */
  1359. };
  1360. const struct uvc_ctrl_blacklist *blacklist;
  1361. unsigned int size;
  1362. unsigned int count;
  1363. unsigned int i;
  1364. u8 *controls;
  1365. switch (UVC_ENTITY_TYPE(entity)) {
  1366. case UVC_VC_PROCESSING_UNIT:
  1367. blacklist = processing_blacklist;
  1368. count = ARRAY_SIZE(processing_blacklist);
  1369. controls = entity->processing.bmControls;
  1370. size = entity->processing.bControlSize;
  1371. break;
  1372. case UVC_ITT_CAMERA:
  1373. blacklist = camera_blacklist;
  1374. count = ARRAY_SIZE(camera_blacklist);
  1375. controls = entity->camera.bmControls;
  1376. size = entity->camera.bControlSize;
  1377. break;
  1378. default:
  1379. return;
  1380. }
  1381. for (i = 0; i < count; ++i) {
  1382. if (!usb_match_one_id(dev->intf, &blacklist[i].id))
  1383. continue;
  1384. if (blacklist[i].index >= 8 * size ||
  1385. !uvc_test_bit(controls, blacklist[i].index))
  1386. continue;
  1387. uvc_trace(UVC_TRACE_CONTROL, "%u/%u control is black listed, "
  1388. "removing it.\n", entity->id, blacklist[i].index);
  1389. uvc_clear_bit(controls, blacklist[i].index);
  1390. }
  1391. }
  1392. /*
  1393. * Initialize device controls.
  1394. */
  1395. int uvc_ctrl_init_device(struct uvc_device *dev)
  1396. {
  1397. struct uvc_control_info *info;
  1398. struct uvc_control *ctrl;
  1399. struct uvc_entity *entity;
  1400. unsigned int i;
  1401. /* Walk the entities list and instantiate controls */
  1402. list_for_each_entry(entity, &dev->entities, list) {
  1403. unsigned int bControlSize = 0, ncontrols = 0;
  1404. __u8 *bmControls = NULL;
  1405. if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) {
  1406. bmControls = entity->extension.bmControls;
  1407. bControlSize = entity->extension.bControlSize;
  1408. } else if (UVC_ENTITY_TYPE(entity) == UVC_VC_PROCESSING_UNIT) {
  1409. bmControls = entity->processing.bmControls;
  1410. bControlSize = entity->processing.bControlSize;
  1411. } else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) {
  1412. bmControls = entity->camera.bmControls;
  1413. bControlSize = entity->camera.bControlSize;
  1414. }
  1415. uvc_ctrl_prune_entity(dev, entity);
  1416. for (i = 0; i < bControlSize; ++i)
  1417. ncontrols += hweight8(bmControls[i]);
  1418. if (ncontrols == 0)
  1419. continue;
  1420. entity->controls = kzalloc(ncontrols*sizeof *ctrl, GFP_KERNEL);
  1421. if (entity->controls == NULL)
  1422. return -ENOMEM;
  1423. entity->ncontrols = ncontrols;
  1424. ctrl = entity->controls;
  1425. for (i = 0; i < bControlSize * 8; ++i) {
  1426. if (uvc_test_bit(bmControls, i) == 0)
  1427. continue;
  1428. ctrl->entity = entity;
  1429. ctrl->index = i;
  1430. ctrl++;
  1431. }
  1432. }
  1433. /* Walk the controls info list and associate them with the device
  1434. * controls, then add the device to the global device list. This has
  1435. * to be done while holding the controls lock, to make sure
  1436. * uvc_ctrl_add_info() will not get called in-between.
  1437. */
  1438. mutex_lock(&uvc_driver.ctrl_mutex);
  1439. list_for_each_entry(info, &uvc_driver.controls, list)
  1440. uvc_ctrl_add_ctrl(dev, info);
  1441. list_add_tail(&dev->list, &uvc_driver.devices);
  1442. mutex_unlock(&uvc_driver.ctrl_mutex);
  1443. return 0;
  1444. }
  1445. /*
  1446. * Cleanup device controls.
  1447. */
  1448. void uvc_ctrl_cleanup_device(struct uvc_device *dev)
  1449. {
  1450. struct uvc_entity *entity;
  1451. unsigned int i;
  1452. /* Remove the device from the global devices list */
  1453. mutex_lock(&uvc_driver.ctrl_mutex);
  1454. if (dev->list.next != NULL)
  1455. list_del(&dev->list);
  1456. mutex_unlock(&uvc_driver.ctrl_mutex);
  1457. list_for_each_entry(entity, &dev->entities, list) {
  1458. for (i = 0; i < entity->ncontrols; ++i)
  1459. kfree(entity->controls[i].uvc_data);
  1460. kfree(entity->controls);
  1461. }
  1462. }
  1463. void uvc_ctrl_cleanup(void)
  1464. {
  1465. struct uvc_control_info *info;
  1466. struct uvc_control_info *ni;
  1467. struct uvc_control_mapping *mapping;
  1468. struct uvc_control_mapping *nm;
  1469. list_for_each_entry_safe(info, ni, &uvc_driver.controls, list) {
  1470. if (!(info->flags & UVC_CONTROL_EXTENSION))
  1471. continue;
  1472. list_for_each_entry_safe(mapping, nm, &info->mappings, list) {
  1473. list_del(&mapping->list);
  1474. kfree(mapping->menu_info);
  1475. kfree(mapping);
  1476. }
  1477. list_del(&info->list);
  1478. kfree(info);
  1479. }
  1480. }
  1481. void uvc_ctrl_init(void)
  1482. {
  1483. struct uvc_control_info *ctrl = uvc_ctrls;
  1484. struct uvc_control_info *cend = ctrl + ARRAY_SIZE(uvc_ctrls);
  1485. struct uvc_control_mapping *mapping = uvc_ctrl_mappings;
  1486. struct uvc_control_mapping *mend =
  1487. mapping + ARRAY_SIZE(uvc_ctrl_mappings);
  1488. for (; ctrl < cend; ++ctrl)
  1489. uvc_ctrl_add_info(ctrl);
  1490. for (; mapping < mend; ++mapping)
  1491. uvc_ctrl_add_mapping(mapping);
  1492. }