v4l2-ctrls.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * V4L2 controls support header.
  4. *
  5. * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
  6. */
  7. #ifndef _V4L2_CTRLS_H
  8. #define _V4L2_CTRLS_H
  9. #include <linux/list.h>
  10. #include <linux/mutex.h>
  11. #include <linux/videodev2.h>
  12. #include <media/media-request.h>
  13. /* forward references */
  14. struct file;
  15. struct poll_table_struct;
  16. struct v4l2_ctrl;
  17. struct v4l2_ctrl_handler;
  18. struct v4l2_ctrl_helper;
  19. struct v4l2_fh;
  20. struct v4l2_fwnode_device_properties;
  21. struct v4l2_subdev;
  22. struct v4l2_subscribed_event;
  23. struct video_device;
  24. /**
  25. * union v4l2_ctrl_ptr - A pointer to a control value.
  26. * @p_s32: Pointer to a 32-bit signed value.
  27. * @p_s64: Pointer to a 64-bit signed value.
  28. * @p_u8: Pointer to a 8-bit unsigned value.
  29. * @p_u16: Pointer to a 16-bit unsigned value.
  30. * @p_u32: Pointer to a 32-bit unsigned value.
  31. * @p_char: Pointer to a string.
  32. * @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure.
  33. * @p_mpeg2_picture: Pointer to a MPEG2 picture structure.
  34. * @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure.
  35. * @p_fwht_params: Pointer to a FWHT stateless parameters structure.
  36. * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps.
  37. * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps.
  38. * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix.
  39. * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
  40. * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
  41. * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
  42. * @p_vp8_frame: Pointer to a VP8 frame params structure.
  43. * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.
  44. * @p_vp9_frame: Pointer to a VP9 frame params structure.
  45. * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
  46. * @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
  47. * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
  48. * @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure.
  49. * @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure.
  50. * @p_area: Pointer to an area.
  51. * @p_av1_sequence: Pointer to an AV1 sequence structure.
  52. * @p_av1_tile_group_entry: Pointer to an AV1 tile group entry structure.
  53. * @p_av1_frame: Pointer to an AV1 frame structure.
  54. * @p_av1_film_grain: Pointer to an AV1 film grain structure.
  55. * @p: Pointer to a compound value.
  56. * @p_const: Pointer to a constant compound value.
  57. */
  58. union v4l2_ctrl_ptr {
  59. s32 *p_s32;
  60. s64 *p_s64;
  61. u8 *p_u8;
  62. u16 *p_u16;
  63. u32 *p_u32;
  64. char *p_char;
  65. struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence;
  66. struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture;
  67. struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation;
  68. struct v4l2_ctrl_fwht_params *p_fwht_params;
  69. struct v4l2_ctrl_h264_sps *p_h264_sps;
  70. struct v4l2_ctrl_h264_pps *p_h264_pps;
  71. struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;
  72. struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
  73. struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
  74. struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
  75. struct v4l2_ctrl_vp8_frame *p_vp8_frame;
  76. struct v4l2_ctrl_hevc_sps *p_hevc_sps;
  77. struct v4l2_ctrl_hevc_pps *p_hevc_pps;
  78. struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
  79. struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs;
  80. struct v4l2_ctrl_vp9_frame *p_vp9_frame;
  81. struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
  82. struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
  83. struct v4l2_area *p_area;
  84. struct v4l2_ctrl_av1_sequence *p_av1_sequence;
  85. struct v4l2_ctrl_av1_tile_group_entry *p_av1_tile_group_entry;
  86. struct v4l2_ctrl_av1_frame *p_av1_frame;
  87. struct v4l2_ctrl_av1_film_grain *p_av1_film_grain;
  88. void *p;
  89. const void *p_const;
  90. };
  91. /**
  92. * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a
  93. * void pointer
  94. * @ptr: The void pointer
  95. */
  96. static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr)
  97. {
  98. union v4l2_ctrl_ptr p = { .p = ptr };
  99. return p;
  100. }
  101. /**
  102. * struct v4l2_ctrl_ops - The control operations that the driver has to provide.
  103. *
  104. * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
  105. * for volatile (and usually read-only) controls such as a control
  106. * that returns the current signal strength which changes
  107. * continuously.
  108. * If not set, then the currently cached value will be returned.
  109. * @try_ctrl: Test whether the control's value is valid. Only relevant when
  110. * the usual min/max/step checks are not sufficient.
  111. * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
  112. * ctrl->handler->lock is held when these ops are called, so no
  113. * one else can access controls owned by that handler.
  114. */
  115. struct v4l2_ctrl_ops {
  116. int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
  117. int (*try_ctrl)(struct v4l2_ctrl *ctrl);
  118. int (*s_ctrl)(struct v4l2_ctrl *ctrl);
  119. };
  120. /**
  121. * struct v4l2_ctrl_type_ops - The control type operations that the driver
  122. * has to provide.
  123. *
  124. * @equal: return true if all ctrl->elems array elements are equal.
  125. * @init: initialize the value for array elements from from_idx to ctrl->elems.
  126. * @log: log the value.
  127. * @validate: validate the value for ctrl->new_elems array elements.
  128. * Return 0 on success and a negative value otherwise.
  129. */
  130. struct v4l2_ctrl_type_ops {
  131. bool (*equal)(const struct v4l2_ctrl *ctrl,
  132. union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2);
  133. void (*init)(const struct v4l2_ctrl *ctrl, u32 from_idx,
  134. union v4l2_ctrl_ptr ptr);
  135. void (*log)(const struct v4l2_ctrl *ctrl);
  136. int (*validate)(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);
  137. };
  138. /**
  139. * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function
  140. * that should be called when a control value has changed.
  141. *
  142. * @ctrl: pointer to struct &v4l2_ctrl
  143. * @priv: control private data
  144. *
  145. * This typedef definition is used as an argument to v4l2_ctrl_notify()
  146. * and as an argument at struct &v4l2_ctrl_handler.
  147. */
  148. typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
  149. /**
  150. * struct v4l2_ctrl - The control structure.
  151. *
  152. * @node: The list node.
  153. * @ev_subs: The list of control event subscriptions.
  154. * @handler: The handler that owns the control.
  155. * @cluster: Point to start of cluster array.
  156. * @ncontrols: Number of controls in cluster array.
  157. * @done: Internal flag: set for each processed control.
  158. * @is_new: Set when the user specified a new value for this control. It
  159. * is also set when called from v4l2_ctrl_handler_setup(). Drivers
  160. * should never set this flag.
  161. * @has_changed: Set when the current value differs from the new value. Drivers
  162. * should never use this flag.
  163. * @is_private: If set, then this control is private to its handler and it
  164. * will not be added to any other handlers. Drivers can set
  165. * this flag.
  166. * @is_auto: If set, then this control selects whether the other cluster
  167. * members are in 'automatic' mode or 'manual' mode. This is
  168. * used for autogain/gain type clusters. Drivers should never
  169. * set this flag directly.
  170. * @is_int: If set, then this control has a simple integer value (i.e. it
  171. * uses ctrl->val).
  172. * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING.
  173. * @is_ptr: If set, then this control is an array and/or has type >=
  174. * %V4L2_CTRL_COMPOUND_TYPES
  175. * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct
  176. * v4l2_ext_control uses field p to point to the data.
  177. * @is_array: If set, then this control contains an N-dimensional array.
  178. * @is_dyn_array: If set, then this control contains a dynamically sized 1-dimensional array.
  179. * If this is set, then @is_array is also set.
  180. * @has_volatiles: If set, then one or more members of the cluster are volatile.
  181. * Drivers should never touch this flag.
  182. * @call_notify: If set, then call the handler's notify function whenever the
  183. * control's value changes.
  184. * @manual_mode_value: If the is_auto flag is set, then this is the value
  185. * of the auto control that determines if that control is in
  186. * manual mode. So if the value of the auto control equals this
  187. * value, then the whole cluster is in manual mode. Drivers should
  188. * never set this flag directly.
  189. * @ops: The control ops.
  190. * @type_ops: The control type ops.
  191. * @id: The control ID.
  192. * @name: The control name.
  193. * @type: The control type.
  194. * @minimum: The control's minimum value.
  195. * @maximum: The control's maximum value.
  196. * @default_value: The control's default value.
  197. * @step: The control's step value for non-menu controls.
  198. * @elems: The number of elements in the N-dimensional array.
  199. * @elem_size: The size in bytes of the control.
  200. * @new_elems: The number of elements in p_new. This is the same as @elems,
  201. * except for dynamic arrays. In that case it is in the range of
  202. * 1 to @p_array_alloc_elems.
  203. * @dims: The size of each dimension.
  204. * @nr_of_dims:The number of dimensions in @dims.
  205. * @menu_skip_mask: The control's skip mask for menu controls. This makes it
  206. * easy to skip menu items that are not valid. If bit X is set,
  207. * then menu item X is skipped. Of course, this only works for
  208. * menus with <= 32 menu items. There are no menus that come
  209. * close to that number, so this is OK. Should we ever need more,
  210. * then this will have to be extended to a u64 or a bit array.
  211. * @qmenu: A const char * array for all menu items. Array entries that are
  212. * empty strings ("") correspond to non-existing menu items (this
  213. * is in addition to the menu_skip_mask above). The last entry
  214. * must be NULL.
  215. * Used only if the @type is %V4L2_CTRL_TYPE_MENU.
  216. * @qmenu_int: A 64-bit integer array for with integer menu items.
  217. * The size of array must be equal to the menu size, e. g.:
  218. * :math:`ceil(\frac{maximum - minimum}{step}) + 1`.
  219. * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU.
  220. * @flags: The control's flags.
  221. * @priv: The control's private pointer. For use by the driver. It is
  222. * untouched by the control framework. Note that this pointer is
  223. * not freed when the control is deleted. Should this be needed
  224. * then a new internal bitfield can be added to tell the framework
  225. * to free this pointer.
  226. * @p_array: Pointer to the allocated array. Only valid if @is_array is true.
  227. * @p_array_alloc_elems: The number of elements in the allocated
  228. * array for both the cur and new values. So @p_array is actually
  229. * sized for 2 * @p_array_alloc_elems * @elem_size. Only valid if
  230. * @is_array is true.
  231. * @cur: Structure to store the current value.
  232. * @cur.val: The control's current value, if the @type is represented via
  233. * a u32 integer (see &enum v4l2_ctrl_type).
  234. * @val: The control's new s32 value.
  235. * @p_def: The control's default value represented via a union which
  236. * provides a standard way of accessing control types
  237. * through a pointer (for compound controls only).
  238. * @p_cur: The control's current value represented via a union which
  239. * provides a standard way of accessing control types
  240. * through a pointer.
  241. * @p_new: The control's new value represented via a union which provides
  242. * a standard way of accessing control types
  243. * through a pointer.
  244. */
  245. struct v4l2_ctrl {
  246. /* Administrative fields */
  247. struct list_head node;
  248. struct list_head ev_subs;
  249. struct v4l2_ctrl_handler *handler;
  250. struct v4l2_ctrl **cluster;
  251. unsigned int ncontrols;
  252. unsigned int done:1;
  253. unsigned int is_new:1;
  254. unsigned int has_changed:1;
  255. unsigned int is_private:1;
  256. unsigned int is_auto:1;
  257. unsigned int is_int:1;
  258. unsigned int is_string:1;
  259. unsigned int is_ptr:1;
  260. unsigned int is_array:1;
  261. unsigned int is_dyn_array:1;
  262. unsigned int has_volatiles:1;
  263. unsigned int call_notify:1;
  264. unsigned int manual_mode_value:8;
  265. const struct v4l2_ctrl_ops *ops;
  266. const struct v4l2_ctrl_type_ops *type_ops;
  267. u32 id;
  268. const char *name;
  269. enum v4l2_ctrl_type type;
  270. s64 minimum, maximum, default_value;
  271. u32 elems;
  272. u32 elem_size;
  273. u32 new_elems;
  274. u32 dims[V4L2_CTRL_MAX_DIMS];
  275. u32 nr_of_dims;
  276. union {
  277. u64 step;
  278. u64 menu_skip_mask;
  279. };
  280. union {
  281. const char * const *qmenu;
  282. const s64 *qmenu_int;
  283. };
  284. unsigned long flags;
  285. void *priv;
  286. void *p_array;
  287. u32 p_array_alloc_elems;
  288. s32 val;
  289. struct {
  290. s32 val;
  291. } cur;
  292. union v4l2_ctrl_ptr p_def;
  293. union v4l2_ctrl_ptr p_new;
  294. union v4l2_ctrl_ptr p_cur;
  295. };
  296. /**
  297. * struct v4l2_ctrl_ref - The control reference.
  298. *
  299. * @node: List node for the sorted list.
  300. * @next: Single-link list node for the hash.
  301. * @ctrl: The actual control information.
  302. * @helper: Pointer to helper struct. Used internally in
  303. * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``.
  304. * @from_other_dev: If true, then @ctrl was defined in another
  305. * device than the &struct v4l2_ctrl_handler.
  306. * @req_done: Internal flag: if the control handler containing this control
  307. * reference is bound to a media request, then this is set when
  308. * the control has been applied. This prevents applying controls
  309. * from a cluster with multiple controls twice (when the first
  310. * control of a cluster is applied, they all are).
  311. * @p_req_valid: If set, then p_req contains the control value for the request.
  312. * @p_req_array_enomem: If set, then p_req is invalid since allocating space for
  313. * an array failed. Attempting to read this value shall
  314. * result in ENOMEM. Only valid if ctrl->is_array is true.
  315. * @p_req_array_alloc_elems: The number of elements allocated for the
  316. * array. Only valid if @p_req_valid and ctrl->is_array are
  317. * true.
  318. * @p_req_elems: The number of elements in @p_req. This is the same as
  319. * ctrl->elems, except for dynamic arrays. In that case it is in
  320. * the range of 1 to @p_req_array_alloc_elems. Only valid if
  321. * @p_req_valid is true.
  322. * @p_req: If the control handler containing this control reference
  323. * is bound to a media request, then this points to the
  324. * value of the control that must be applied when the request
  325. * is executed, or to the value of the control at the time
  326. * that the request was completed. If @p_req_valid is false,
  327. * then this control was never set for this request and the
  328. * control will not be updated when this request is applied.
  329. *
  330. * Each control handler has a list of these refs. The list_head is used to
  331. * keep a sorted-by-control-ID list of all controls, while the next pointer
  332. * is used to link the control in the hash's bucket.
  333. */
  334. struct v4l2_ctrl_ref {
  335. struct list_head node;
  336. struct v4l2_ctrl_ref *next;
  337. struct v4l2_ctrl *ctrl;
  338. struct v4l2_ctrl_helper *helper;
  339. bool from_other_dev;
  340. bool req_done;
  341. bool p_req_valid;
  342. bool p_req_array_enomem;
  343. u32 p_req_array_alloc_elems;
  344. u32 p_req_elems;
  345. union v4l2_ctrl_ptr p_req;
  346. };
  347. /**
  348. * struct v4l2_ctrl_handler - The control handler keeps track of all the
  349. * controls: both the controls owned by the handler and those inherited
  350. * from other handlers.
  351. *
  352. * @_lock: Default for "lock".
  353. * @lock: Lock to control access to this handler and its controls.
  354. * May be replaced by the user right after init.
  355. * @ctrls: The list of controls owned by this handler.
  356. * @ctrl_refs: The list of control references.
  357. * @cached: The last found control reference. It is common that the same
  358. * control is needed multiple times, so this is a simple
  359. * optimization.
  360. * @buckets: Buckets for the hashing. Allows for quick control lookup.
  361. * @notify: A notify callback that is called whenever the control changes
  362. * value.
  363. * Note that the handler's lock is held when the notify function
  364. * is called!
  365. * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
  366. * @nr_of_buckets: Total number of buckets in the array.
  367. * @error: The error code of the first failed control addition.
  368. * @request_is_queued: True if the request was queued.
  369. * @requests: List to keep track of open control handler request objects.
  370. * For the parent control handler (@req_obj.ops == NULL) this
  371. * is the list header. When the parent control handler is
  372. * removed, it has to unbind and put all these requests since
  373. * they refer to the parent.
  374. * @requests_queued: List of the queued requests. This determines the order
  375. * in which these controls are applied. Once the request is
  376. * completed it is removed from this list.
  377. * @req_obj: The &struct media_request_object, used to link into a
  378. * &struct media_request. This request object has a refcount.
  379. */
  380. struct v4l2_ctrl_handler {
  381. struct mutex _lock;
  382. struct mutex *lock;
  383. struct list_head ctrls;
  384. struct list_head ctrl_refs;
  385. struct v4l2_ctrl_ref *cached;
  386. struct v4l2_ctrl_ref **buckets;
  387. v4l2_ctrl_notify_fnc notify;
  388. void *notify_priv;
  389. u16 nr_of_buckets;
  390. int error;
  391. bool request_is_queued;
  392. struct list_head requests;
  393. struct list_head requests_queued;
  394. struct media_request_object req_obj;
  395. };
  396. /**
  397. * struct v4l2_ctrl_config - Control configuration structure.
  398. *
  399. * @ops: The control ops.
  400. * @type_ops: The control type ops. Only needed for compound controls.
  401. * @id: The control ID.
  402. * @name: The control name.
  403. * @type: The control type.
  404. * @min: The control's minimum value.
  405. * @max: The control's maximum value.
  406. * @step: The control's step value for non-menu controls.
  407. * @def: The control's default value.
  408. * @p_def: The control's default value for compound controls.
  409. * @dims: The size of each dimension.
  410. * @elem_size: The size in bytes of the control.
  411. * @flags: The control's flags.
  412. * @menu_skip_mask: The control's skip mask for menu controls. This makes it
  413. * easy to skip menu items that are not valid. If bit X is set,
  414. * then menu item X is skipped. Of course, this only works for
  415. * menus with <= 64 menu items. There are no menus that come
  416. * close to that number, so this is OK. Should we ever need more,
  417. * then this will have to be extended to a bit array.
  418. * @qmenu: A const char * array for all menu items. Array entries that are
  419. * empty strings ("") correspond to non-existing menu items (this
  420. * is in addition to the menu_skip_mask above). The last entry
  421. * must be NULL.
  422. * @qmenu_int: A const s64 integer array for all menu items of the type
  423. * V4L2_CTRL_TYPE_INTEGER_MENU.
  424. * @is_private: If set, then this control is private to its handler and it
  425. * will not be added to any other handlers.
  426. */
  427. struct v4l2_ctrl_config {
  428. const struct v4l2_ctrl_ops *ops;
  429. const struct v4l2_ctrl_type_ops *type_ops;
  430. u32 id;
  431. const char *name;
  432. enum v4l2_ctrl_type type;
  433. s64 min;
  434. s64 max;
  435. u64 step;
  436. s64 def;
  437. union v4l2_ctrl_ptr p_def;
  438. u32 dims[V4L2_CTRL_MAX_DIMS];
  439. u32 elem_size;
  440. u32 flags;
  441. u64 menu_skip_mask;
  442. const char * const *qmenu;
  443. const s64 *qmenu_int;
  444. unsigned int is_private:1;
  445. };
  446. /**
  447. * v4l2_ctrl_fill - Fill in the control fields based on the control ID.
  448. *
  449. * @id: ID of the control
  450. * @name: pointer to be filled with a string with the name of the control
  451. * @type: pointer for storing the type of the control
  452. * @min: pointer for storing the minimum value for the control
  453. * @max: pointer for storing the maximum value for the control
  454. * @step: pointer for storing the control step
  455. * @def: pointer for storing the default value for the control
  456. * @flags: pointer for storing the flags to be used on the control
  457. *
  458. * This works for all standard V4L2 controls.
  459. * For non-standard controls it will only fill in the given arguments
  460. * and @name content will be set to %NULL.
  461. *
  462. * This function will overwrite the contents of @name, @type and @flags.
  463. * The contents of @min, @max, @step and @def may be modified depending on
  464. * the type.
  465. *
  466. * .. note::
  467. *
  468. * Do not use in drivers! It is used internally for backwards compatibility
  469. * control handling only. Once all drivers are converted to use the new
  470. * control framework this function will no longer be exported.
  471. */
  472. void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
  473. s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags);
  474. /**
  475. * v4l2_ctrl_handler_init_class() - Initialize the control handler.
  476. * @hdl: The control handler.
  477. * @nr_of_controls_hint: A hint of how many controls this handler is
  478. * expected to refer to. This is the total number, so including
  479. * any inherited controls. It doesn't have to be precise, but if
  480. * it is way off, then you either waste memory (too many buckets
  481. * are allocated) or the control lookup becomes slower (not enough
  482. * buckets are allocated, so there are more slow list lookups).
  483. * It will always work, though.
  484. * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
  485. * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
  486. *
  487. * .. attention::
  488. *
  489. * Never use this call directly, always use the v4l2_ctrl_handler_init()
  490. * macro that hides the @key and @name arguments.
  491. *
  492. * Return: returns an error if the buckets could not be allocated. This
  493. * error will also be stored in @hdl->error.
  494. */
  495. int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
  496. unsigned int nr_of_controls_hint,
  497. struct lock_class_key *key, const char *name);
  498. #ifdef CONFIG_LOCKDEP
  499. /**
  500. * v4l2_ctrl_handler_init - helper function to create a static struct
  501. * &lock_class_key and calls v4l2_ctrl_handler_init_class()
  502. *
  503. * @hdl: The control handler.
  504. * @nr_of_controls_hint: A hint of how many controls this handler is
  505. * expected to refer to. This is the total number, so including
  506. * any inherited controls. It doesn't have to be precise, but if
  507. * it is way off, then you either waste memory (too many buckets
  508. * are allocated) or the control lookup becomes slower (not enough
  509. * buckets are allocated, so there are more slow list lookups).
  510. * It will always work, though.
  511. *
  512. * This helper function creates a static struct &lock_class_key and
  513. * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock
  514. * validador.
  515. *
  516. * Use this helper function to initialize a control handler.
  517. */
  518. #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
  519. ( \
  520. ({ \
  521. static struct lock_class_key _key; \
  522. v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
  523. &_key, \
  524. KBUILD_BASENAME ":" \
  525. __stringify(__LINE__) ":" \
  526. "(" #hdl ")->_lock"); \
  527. }) \
  528. )
  529. #else
  530. #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
  531. v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
  532. #endif
  533. /**
  534. * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
  535. * the control list.
  536. * @hdl: The control handler.
  537. *
  538. * Does nothing if @hdl == NULL.
  539. */
  540. void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
  541. /**
  542. * v4l2_ctrl_lock() - Helper function to lock the handler
  543. * associated with the control.
  544. * @ctrl: The control to lock.
  545. */
  546. static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
  547. {
  548. mutex_lock(ctrl->handler->lock);
  549. }
  550. /**
  551. * v4l2_ctrl_unlock() - Helper function to unlock the handler
  552. * associated with the control.
  553. * @ctrl: The control to unlock.
  554. */
  555. static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
  556. {
  557. mutex_unlock(ctrl->handler->lock);
  558. }
  559. /**
  560. * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
  561. * to the handler to initialize the hardware to the current control values. The
  562. * caller is responsible for acquiring the control handler mutex on behalf of
  563. * __v4l2_ctrl_handler_setup().
  564. * @hdl: The control handler.
  565. *
  566. * Button controls will be skipped, as are read-only controls.
  567. *
  568. * If @hdl == NULL, then this just returns 0.
  569. */
  570. int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
  571. /**
  572. * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
  573. * to the handler to initialize the hardware to the current control values.
  574. * @hdl: The control handler.
  575. *
  576. * Button controls will be skipped, as are read-only controls.
  577. *
  578. * If @hdl == NULL, then this just returns 0.
  579. */
  580. int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
  581. /**
  582. * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
  583. * @hdl: The control handler.
  584. * @prefix: The prefix to use when logging the control values. If the
  585. * prefix does not end with a space, then ": " will be added
  586. * after the prefix. If @prefix == NULL, then no prefix will be
  587. * used.
  588. *
  589. * For use with VIDIOC_LOG_STATUS.
  590. *
  591. * Does nothing if @hdl == NULL.
  592. */
  593. void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
  594. const char *prefix);
  595. /**
  596. * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
  597. * control.
  598. *
  599. * @hdl: The control handler.
  600. * @cfg: The control's configuration data.
  601. * @priv: The control's driver-specific private data.
  602. *
  603. * If the &v4l2_ctrl struct could not be allocated then NULL is returned
  604. * and @hdl->error is set to the error code (if it wasn't set already).
  605. */
  606. struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
  607. const struct v4l2_ctrl_config *cfg,
  608. void *priv);
  609. /**
  610. * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu
  611. * control.
  612. *
  613. * @hdl: The control handler.
  614. * @ops: The control ops.
  615. * @id: The control ID.
  616. * @min: The control's minimum value.
  617. * @max: The control's maximum value.
  618. * @step: The control's step value
  619. * @def: The control's default value.
  620. *
  621. * If the &v4l2_ctrl struct could not be allocated, or the control
  622. * ID is not known, then NULL is returned and @hdl->error is set to the
  623. * appropriate error code (if it wasn't set already).
  624. *
  625. * If @id refers to a menu control, then this function will return NULL.
  626. *
  627. * Use v4l2_ctrl_new_std_menu() when adding menu controls.
  628. */
  629. struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
  630. const struct v4l2_ctrl_ops *ops,
  631. u32 id, s64 min, s64 max, u64 step,
  632. s64 def);
  633. /**
  634. * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2
  635. * menu control.
  636. *
  637. * @hdl: The control handler.
  638. * @ops: The control ops.
  639. * @id: The control ID.
  640. * @max: The control's maximum value.
  641. * @mask: The control's skip mask for menu controls. This makes it
  642. * easy to skip menu items that are not valid. If bit X is set,
  643. * then menu item X is skipped. Of course, this only works for
  644. * menus with <= 64 menu items. There are no menus that come
  645. * close to that number, so this is OK. Should we ever need more,
  646. * then this will have to be extended to a bit array.
  647. * @def: The control's default value.
  648. *
  649. * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
  650. * determines which menu items are to be skipped.
  651. *
  652. * If @id refers to a non-menu control, then this function will return NULL.
  653. */
  654. struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
  655. const struct v4l2_ctrl_ops *ops,
  656. u32 id, u8 max, u64 mask, u8 def);
  657. /**
  658. * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
  659. * with driver specific menu.
  660. *
  661. * @hdl: The control handler.
  662. * @ops: The control ops.
  663. * @id: The control ID.
  664. * @max: The control's maximum value.
  665. * @mask: The control's skip mask for menu controls. This makes it
  666. * easy to skip menu items that are not valid. If bit X is set,
  667. * then menu item X is skipped. Of course, this only works for
  668. * menus with <= 64 menu items. There are no menus that come
  669. * close to that number, so this is OK. Should we ever need more,
  670. * then this will have to be extended to a bit array.
  671. * @def: The control's default value.
  672. * @qmenu: The new menu.
  673. *
  674. * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
  675. * menu of this control.
  676. *
  677. */
  678. struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
  679. const struct v4l2_ctrl_ops *ops,
  680. u32 id, u8 max,
  681. u64 mask, u8 def,
  682. const char * const *qmenu);
  683. /**
  684. * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
  685. * compound control.
  686. *
  687. * @hdl: The control handler.
  688. * @ops: The control ops.
  689. * @id: The control ID.
  690. * @p_def: The control's default value.
  691. *
  692. * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
  693. * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
  694. * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
  695. * compound control should be all zeroes.
  696. *
  697. */
  698. struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
  699. const struct v4l2_ctrl_ops *ops,
  700. u32 id,
  701. const union v4l2_ctrl_ptr p_def);
  702. /**
  703. * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
  704. *
  705. * @hdl: The control handler.
  706. * @ops: The control ops.
  707. * @id: The control ID.
  708. * @max: The control's maximum value.
  709. * @def: The control's default value.
  710. * @qmenu_int: The control's menu entries.
  711. *
  712. * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally
  713. * takes as an argument an array of integers determining the menu items.
  714. *
  715. * If @id refers to a non-integer-menu control, then this function will
  716. * return %NULL.
  717. */
  718. struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
  719. const struct v4l2_ctrl_ops *ops,
  720. u32 id, u8 max, u8 def,
  721. const s64 *qmenu_int);
  722. /**
  723. * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
  724. * used when adding a control handler.
  725. *
  726. * @ctrl: pointer to struct &v4l2_ctrl.
  727. */
  728. typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl);
  729. /**
  730. * v4l2_ctrl_add_handler() - Add all controls from handler @add to
  731. * handler @hdl.
  732. *
  733. * @hdl: The control handler.
  734. * @add: The control handler whose controls you want to add to
  735. * the @hdl control handler.
  736. * @filter: This function will filter which controls should be added.
  737. * @from_other_dev: If true, then the controls in @add were defined in another
  738. * device than @hdl.
  739. *
  740. * Does nothing if either of the two handlers is a NULL pointer.
  741. * If @filter is NULL, then all controls are added. Otherwise only those
  742. * controls for which @filter returns true will be added.
  743. * In case of an error @hdl->error will be set to the error code (if it
  744. * wasn't set already).
  745. */
  746. int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
  747. struct v4l2_ctrl_handler *add,
  748. v4l2_ctrl_filter filter,
  749. bool from_other_dev);
  750. /**
  751. * v4l2_ctrl_radio_filter() - Standard filter for radio controls.
  752. *
  753. * @ctrl: The control that is filtered.
  754. *
  755. * This will return true for any controls that are valid for radio device
  756. * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
  757. * transmitter class controls.
  758. *
  759. * This function is to be used with v4l2_ctrl_add_handler().
  760. */
  761. bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
  762. /**
  763. * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging
  764. * to that cluster.
  765. *
  766. * @ncontrols: The number of controls in this cluster.
  767. * @controls: The cluster control array of size @ncontrols.
  768. */
  769. void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls);
  770. /**
  771. * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging
  772. * to that cluster and set it up for autofoo/foo-type handling.
  773. *
  774. * @ncontrols: The number of controls in this cluster.
  775. * @controls: The cluster control array of size @ncontrols. The first control
  776. * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
  777. * @manual_val: The value for the first control in the cluster that equals the
  778. * manual setting.
  779. * @set_volatile: If true, then all controls except the first auto control will
  780. * be volatile.
  781. *
  782. * Use for control groups where one control selects some automatic feature and
  783. * the other controls are only active whenever the automatic feature is turned
  784. * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
  785. * red and blue balance, etc.
  786. *
  787. * The behavior of such controls is as follows:
  788. *
  789. * When the autofoo control is set to automatic, then any manual controls
  790. * are set to inactive and any reads will call g_volatile_ctrl (if the control
  791. * was marked volatile).
  792. *
  793. * When the autofoo control is set to manual, then any manual controls will
  794. * be marked active, and any reads will just return the current value without
  795. * going through g_volatile_ctrl.
  796. *
  797. * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag
  798. * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
  799. * if autofoo is in auto mode.
  800. */
  801. void v4l2_ctrl_auto_cluster(unsigned int ncontrols,
  802. struct v4l2_ctrl **controls,
  803. u8 manual_val, bool set_volatile);
  804. /**
  805. * v4l2_ctrl_find() - Find a control with the given ID.
  806. *
  807. * @hdl: The control handler.
  808. * @id: The control ID to find.
  809. *
  810. * If @hdl == NULL this will return NULL as well. Will lock the handler so
  811. * do not use from inside &v4l2_ctrl_ops.
  812. */
  813. struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
  814. /**
  815. * v4l2_ctrl_activate() - Make the control active or inactive.
  816. * @ctrl: The control to (de)activate.
  817. * @active: True if the control should become active.
  818. *
  819. * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
  820. * Does nothing if @ctrl == NULL.
  821. * This will usually be called from within the s_ctrl op.
  822. * The V4L2_EVENT_CTRL event will be generated afterwards.
  823. *
  824. * This function assumes that the control handler is locked.
  825. */
  826. void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
  827. /**
  828. * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab.
  829. *
  830. * @ctrl: The control to (de)activate.
  831. * @grabbed: True if the control should become grabbed.
  832. *
  833. * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
  834. * Does nothing if @ctrl == NULL.
  835. * The V4L2_EVENT_CTRL event will be generated afterwards.
  836. * This will usually be called when starting or stopping streaming in the
  837. * driver.
  838. *
  839. * This function assumes that the control handler is locked by the caller.
  840. */
  841. void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
  842. /**
  843. * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
  844. *
  845. * @ctrl: The control to (de)activate.
  846. * @grabbed: True if the control should become grabbed.
  847. *
  848. * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
  849. * Does nothing if @ctrl == NULL.
  850. * The V4L2_EVENT_CTRL event will be generated afterwards.
  851. * This will usually be called when starting or stopping streaming in the
  852. * driver.
  853. *
  854. * This function assumes that the control handler is not locked and will
  855. * take the lock itself.
  856. */
  857. static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
  858. {
  859. if (!ctrl)
  860. return;
  861. v4l2_ctrl_lock(ctrl);
  862. __v4l2_ctrl_grab(ctrl, grabbed);
  863. v4l2_ctrl_unlock(ctrl);
  864. }
  865. /**
  866. *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
  867. *
  868. * @ctrl: The control to update.
  869. * @min: The control's minimum value.
  870. * @max: The control's maximum value.
  871. * @step: The control's step value
  872. * @def: The control's default value.
  873. *
  874. * Update the range of a control on the fly. This works for control types
  875. * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
  876. * @step value is interpreted as a menu_skip_mask.
  877. *
  878. * An error is returned if one of the range arguments is invalid for this
  879. * control type.
  880. *
  881. * The caller is responsible for acquiring the control handler mutex on behalf
  882. * of __v4l2_ctrl_modify_range().
  883. */
  884. int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
  885. s64 min, s64 max, u64 step, s64 def);
  886. /**
  887. * v4l2_ctrl_modify_range() - Update the range of a control.
  888. *
  889. * @ctrl: The control to update.
  890. * @min: The control's minimum value.
  891. * @max: The control's maximum value.
  892. * @step: The control's step value
  893. * @def: The control's default value.
  894. *
  895. * Update the range of a control on the fly. This works for control types
  896. * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
  897. * @step value is interpreted as a menu_skip_mask.
  898. *
  899. * An error is returned if one of the range arguments is invalid for this
  900. * control type.
  901. *
  902. * This function assumes that the control handler is not locked and will
  903. * take the lock itself.
  904. */
  905. static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
  906. s64 min, s64 max, u64 step, s64 def)
  907. {
  908. int rval;
  909. v4l2_ctrl_lock(ctrl);
  910. rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
  911. v4l2_ctrl_unlock(ctrl);
  912. return rval;
  913. }
  914. /**
  915. *__v4l2_ctrl_modify_dimensions() - Unlocked variant of v4l2_ctrl_modify_dimensions()
  916. *
  917. * @ctrl: The control to update.
  918. * @dims: The control's new dimensions.
  919. *
  920. * Update the dimensions of an array control on the fly. The elements of the
  921. * array are reset to their default value, even if the dimensions are
  922. * unchanged.
  923. *
  924. * An error is returned if @dims is invalid for this control.
  925. *
  926. * The caller is responsible for acquiring the control handler mutex on behalf
  927. * of __v4l2_ctrl_modify_dimensions().
  928. *
  929. * Note: calling this function when the same control is used in pending requests
  930. * is untested. It should work (a request with the wrong size of the control
  931. * will drop that control silently), but it will be very confusing.
  932. */
  933. int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
  934. u32 dims[V4L2_CTRL_MAX_DIMS]);
  935. /**
  936. * v4l2_ctrl_modify_dimensions() - Update the dimensions of an array control.
  937. *
  938. * @ctrl: The control to update.
  939. * @dims: The control's new dimensions.
  940. *
  941. * Update the dimensions of an array control on the fly. The elements of the
  942. * array are reset to their default value, even if the dimensions are
  943. * unchanged.
  944. *
  945. * An error is returned if @dims is invalid for this control type.
  946. *
  947. * This function assumes that the control handler is not locked and will
  948. * take the lock itself.
  949. *
  950. * Note: calling this function when the same control is used in pending requests
  951. * is untested. It should work (a request with the wrong size of the control
  952. * will drop that control silently), but it will be very confusing.
  953. */
  954. static inline int v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
  955. u32 dims[V4L2_CTRL_MAX_DIMS])
  956. {
  957. int rval;
  958. v4l2_ctrl_lock(ctrl);
  959. rval = __v4l2_ctrl_modify_dimensions(ctrl, dims);
  960. v4l2_ctrl_unlock(ctrl);
  961. return rval;
  962. }
  963. /**
  964. * v4l2_ctrl_notify() - Function to set a notify callback for a control.
  965. *
  966. * @ctrl: The control.
  967. * @notify: The callback function.
  968. * @priv: The callback private handle, passed as argument to the callback.
  969. *
  970. * This function sets a callback function for the control. If @ctrl is NULL,
  971. * then it will do nothing. If @notify is NULL, then the notify callback will
  972. * be removed.
  973. *
  974. * There can be only one notify. If another already exists, then a WARN_ON
  975. * will be issued and the function will do nothing.
  976. */
  977. void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify,
  978. void *priv);
  979. /**
  980. * v4l2_ctrl_get_name() - Get the name of the control
  981. *
  982. * @id: The control ID.
  983. *
  984. * This function returns the name of the given control ID or NULL if it isn't
  985. * a known control.
  986. */
  987. const char *v4l2_ctrl_get_name(u32 id);
  988. /**
  989. * v4l2_ctrl_get_menu() - Get the menu string array of the control
  990. *
  991. * @id: The control ID.
  992. *
  993. * This function returns the NULL-terminated menu string array name of the
  994. * given control ID or NULL if it isn't a known menu control.
  995. */
  996. const char * const *v4l2_ctrl_get_menu(u32 id);
  997. /**
  998. * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control
  999. *
  1000. * @id: The control ID.
  1001. * @len: The size of the integer array.
  1002. *
  1003. * This function returns the integer array of the given control ID or NULL if it
  1004. * if it isn't a known integer menu control.
  1005. */
  1006. const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
  1007. /**
  1008. * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from
  1009. * within a driver.
  1010. *
  1011. * @ctrl: The control.
  1012. *
  1013. * This returns the control's value safely by going through the control
  1014. * framework. This function will lock the control's handler, so it cannot be
  1015. * used from within the &v4l2_ctrl_ops functions.
  1016. *
  1017. * This function is for integer type controls only.
  1018. */
  1019. s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
  1020. /**
  1021. * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl().
  1022. *
  1023. * @ctrl: The control.
  1024. * @val: The new value.
  1025. *
  1026. * This sets the control's new value safely by going through the control
  1027. * framework. This function assumes the control's handler is already locked,
  1028. * allowing it to be used from within the &v4l2_ctrl_ops functions.
  1029. *
  1030. * This function is for integer type controls only.
  1031. */
  1032. int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
  1033. /**
  1034. * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from
  1035. * within a driver.
  1036. * @ctrl: The control.
  1037. * @val: The new value.
  1038. *
  1039. * This sets the control's new value safely by going through the control
  1040. * framework. This function will lock the control's handler, so it cannot be
  1041. * used from within the &v4l2_ctrl_ops functions.
  1042. *
  1043. * This function is for integer type controls only.
  1044. */
  1045. static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
  1046. {
  1047. int rval;
  1048. v4l2_ctrl_lock(ctrl);
  1049. rval = __v4l2_ctrl_s_ctrl(ctrl, val);
  1050. v4l2_ctrl_unlock(ctrl);
  1051. return rval;
  1052. }
  1053. /**
  1054. * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value
  1055. * from within a driver.
  1056. *
  1057. * @ctrl: The control.
  1058. *
  1059. * This returns the control's value safely by going through the control
  1060. * framework. This function will lock the control's handler, so it cannot be
  1061. * used from within the &v4l2_ctrl_ops functions.
  1062. *
  1063. * This function is for 64-bit integer type controls only.
  1064. */
  1065. s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
  1066. /**
  1067. * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64().
  1068. *
  1069. * @ctrl: The control.
  1070. * @val: The new value.
  1071. *
  1072. * This sets the control's new value safely by going through the control
  1073. * framework. This function assumes the control's handler is already locked,
  1074. * allowing it to be used from within the &v4l2_ctrl_ops functions.
  1075. *
  1076. * This function is for 64-bit integer type controls only.
  1077. */
  1078. int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
  1079. /**
  1080. * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value
  1081. * from within a driver.
  1082. *
  1083. * @ctrl: The control.
  1084. * @val: The new value.
  1085. *
  1086. * This sets the control's new value safely by going through the control
  1087. * framework. This function will lock the control's handler, so it cannot be
  1088. * used from within the &v4l2_ctrl_ops functions.
  1089. *
  1090. * This function is for 64-bit integer type controls only.
  1091. */
  1092. static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
  1093. {
  1094. int rval;
  1095. v4l2_ctrl_lock(ctrl);
  1096. rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val);
  1097. v4l2_ctrl_unlock(ctrl);
  1098. return rval;
  1099. }
  1100. /**
  1101. * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string().
  1102. *
  1103. * @ctrl: The control.
  1104. * @s: The new string.
  1105. *
  1106. * This sets the control's new string safely by going through the control
  1107. * framework. This function assumes the control's handler is already locked,
  1108. * allowing it to be used from within the &v4l2_ctrl_ops functions.
  1109. *
  1110. * This function is for string type controls only.
  1111. */
  1112. int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s);
  1113. /**
  1114. * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value
  1115. * from within a driver.
  1116. *
  1117. * @ctrl: The control.
  1118. * @s: The new string.
  1119. *
  1120. * This sets the control's new string safely by going through the control
  1121. * framework. This function will lock the control's handler, so it cannot be
  1122. * used from within the &v4l2_ctrl_ops functions.
  1123. *
  1124. * This function is for string type controls only.
  1125. */
  1126. static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
  1127. {
  1128. int rval;
  1129. v4l2_ctrl_lock(ctrl);
  1130. rval = __v4l2_ctrl_s_ctrl_string(ctrl, s);
  1131. v4l2_ctrl_unlock(ctrl);
  1132. return rval;
  1133. }
  1134. /**
  1135. * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control
  1136. *
  1137. * @ctrl: The control.
  1138. * @type: The type of the data.
  1139. * @p: The new compound payload.
  1140. *
  1141. * This sets the control's new compound payload safely by going through the
  1142. * control framework. This function assumes the control's handler is already
  1143. * locked, allowing it to be used from within the &v4l2_ctrl_ops functions.
  1144. *
  1145. * This function is for compound type controls only.
  1146. */
  1147. int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
  1148. enum v4l2_ctrl_type type, const void *p);
  1149. /**
  1150. * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control
  1151. * from within a driver.
  1152. *
  1153. * @ctrl: The control.
  1154. * @type: The type of the data.
  1155. * @p: The new compound payload.
  1156. *
  1157. * This sets the control's new compound payload safely by going through the
  1158. * control framework. This function will lock the control's handler, so it
  1159. * cannot be used from within the &v4l2_ctrl_ops functions.
  1160. *
  1161. * This function is for compound type controls only.
  1162. */
  1163. static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
  1164. enum v4l2_ctrl_type type,
  1165. const void *p)
  1166. {
  1167. int rval;
  1168. v4l2_ctrl_lock(ctrl);
  1169. rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p);
  1170. v4l2_ctrl_unlock(ctrl);
  1171. return rval;
  1172. }
  1173. /* Helper defines for area type controls */
  1174. #define __v4l2_ctrl_s_ctrl_area(ctrl, area) \
  1175. __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
  1176. #define v4l2_ctrl_s_ctrl_area(ctrl, area) \
  1177. v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area))
  1178. /* Internal helper functions that deal with control events. */
  1179. extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
  1180. /**
  1181. * v4l2_ctrl_replace - Function to be used as a callback to
  1182. * &struct v4l2_subscribed_event_ops replace\(\)
  1183. *
  1184. * @old: pointer to struct &v4l2_event with the reported
  1185. * event;
  1186. * @new: pointer to struct &v4l2_event with the modified
  1187. * event;
  1188. */
  1189. void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
  1190. /**
  1191. * v4l2_ctrl_merge - Function to be used as a callback to
  1192. * &struct v4l2_subscribed_event_ops merge(\)
  1193. *
  1194. * @old: pointer to struct &v4l2_event with the reported
  1195. * event;
  1196. * @new: pointer to struct &v4l2_event with the merged
  1197. * event;
  1198. */
  1199. void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
  1200. /**
  1201. * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl
  1202. *
  1203. * @file: pointer to struct file
  1204. * @fh: unused. Kept just to be compatible to the arguments expected by
  1205. * &struct v4l2_ioctl_ops.vidioc_log_status.
  1206. *
  1207. * Can be used as a vidioc_log_status function that just dumps all controls
  1208. * associated with the filehandle.
  1209. */
  1210. int v4l2_ctrl_log_status(struct file *file, void *fh);
  1211. /**
  1212. * v4l2_ctrl_subscribe_event - Subscribes to an event
  1213. *
  1214. *
  1215. * @fh: pointer to struct v4l2_fh
  1216. * @sub: pointer to &struct v4l2_event_subscription
  1217. *
  1218. * Can be used as a vidioc_subscribe_event function that just subscribes
  1219. * control events.
  1220. */
  1221. int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
  1222. const struct v4l2_event_subscription *sub);
  1223. /**
  1224. * v4l2_ctrl_poll - function to be used as a callback to the poll()
  1225. * That just polls for control events.
  1226. *
  1227. * @file: pointer to struct file
  1228. * @wait: pointer to struct poll_table_struct
  1229. */
  1230. __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
  1231. /**
  1232. * v4l2_ctrl_request_setup - helper function to apply control values in a request
  1233. *
  1234. * @req: The request
  1235. * @parent: The parent control handler ('priv' in media_request_object_find())
  1236. *
  1237. * This is a helper function to call the control handler's s_ctrl callback with
  1238. * the control values contained in the request. Do note that this approach of
  1239. * applying control values in a request is only applicable to memory-to-memory
  1240. * devices.
  1241. */
  1242. int v4l2_ctrl_request_setup(struct media_request *req,
  1243. struct v4l2_ctrl_handler *parent);
  1244. /**
  1245. * v4l2_ctrl_request_complete - Complete a control handler request object
  1246. *
  1247. * @req: The request
  1248. * @parent: The parent control handler ('priv' in media_request_object_find())
  1249. *
  1250. * This function is to be called on each control handler that may have had a
  1251. * request object associated with it, i.e. control handlers of a driver that
  1252. * supports requests.
  1253. *
  1254. * The function first obtains the values of any volatile controls in the control
  1255. * handler and attach them to the request. Then, the function completes the
  1256. * request object.
  1257. */
  1258. void v4l2_ctrl_request_complete(struct media_request *req,
  1259. struct v4l2_ctrl_handler *parent);
  1260. /**
  1261. * v4l2_ctrl_request_hdl_find - Find the control handler in the request
  1262. *
  1263. * @req: The request
  1264. * @parent: The parent control handler ('priv' in media_request_object_find())
  1265. *
  1266. * This function finds the control handler in the request. It may return
  1267. * NULL if not found. When done, you must call v4l2_ctrl_request_hdl_put()
  1268. * with the returned handler pointer.
  1269. *
  1270. * If the request is not in state VALIDATING or QUEUED, then this function
  1271. * will always return NULL.
  1272. *
  1273. * Note that in state VALIDATING the req_queue_mutex is held, so
  1274. * no objects can be added or deleted from the request.
  1275. *
  1276. * In state QUEUED it is the driver that will have to ensure this.
  1277. */
  1278. struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
  1279. struct v4l2_ctrl_handler *parent);
  1280. /**
  1281. * v4l2_ctrl_request_hdl_put - Put the control handler
  1282. *
  1283. * @hdl: Put this control handler
  1284. *
  1285. * This function released the control handler previously obtained from'
  1286. * v4l2_ctrl_request_hdl_find().
  1287. */
  1288. static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl)
  1289. {
  1290. if (hdl)
  1291. media_request_object_put(&hdl->req_obj);
  1292. }
  1293. /**
  1294. * v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID.
  1295. *
  1296. * @hdl: The control handler from the request.
  1297. * @id: The ID of the control to find.
  1298. *
  1299. * This function returns a pointer to the control if this control is
  1300. * part of the request or NULL otherwise.
  1301. */
  1302. struct v4l2_ctrl *
  1303. v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
  1304. /* Helpers for ioctl_ops */
  1305. /**
  1306. * v4l2_queryctrl - Helper function to implement
  1307. * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
  1308. *
  1309. * @hdl: pointer to &struct v4l2_ctrl_handler
  1310. * @qc: pointer to &struct v4l2_queryctrl
  1311. *
  1312. * If hdl == NULL then they will all return -EINVAL.
  1313. */
  1314. int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
  1315. /**
  1316. * v4l2_query_ext_ctrl - Helper function to implement
  1317. * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
  1318. *
  1319. * @hdl: pointer to &struct v4l2_ctrl_handler
  1320. * @qc: pointer to &struct v4l2_query_ext_ctrl
  1321. *
  1322. * If hdl == NULL then they will all return -EINVAL.
  1323. */
  1324. int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl,
  1325. struct v4l2_query_ext_ctrl *qc);
  1326. /**
  1327. * v4l2_querymenu - Helper function to implement
  1328. * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl
  1329. *
  1330. * @hdl: pointer to &struct v4l2_ctrl_handler
  1331. * @qm: pointer to &struct v4l2_querymenu
  1332. *
  1333. * If hdl == NULL then they will all return -EINVAL.
  1334. */
  1335. int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
  1336. /**
  1337. * v4l2_g_ctrl - Helper function to implement
  1338. * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
  1339. *
  1340. * @hdl: pointer to &struct v4l2_ctrl_handler
  1341. * @ctrl: pointer to &struct v4l2_control
  1342. *
  1343. * If hdl == NULL then they will all return -EINVAL.
  1344. */
  1345. int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
  1346. /**
  1347. * v4l2_s_ctrl - Helper function to implement
  1348. * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
  1349. *
  1350. * @fh: pointer to &struct v4l2_fh
  1351. * @hdl: pointer to &struct v4l2_ctrl_handler
  1352. *
  1353. * @ctrl: pointer to &struct v4l2_control
  1354. *
  1355. * If hdl == NULL then they will all return -EINVAL.
  1356. */
  1357. int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
  1358. struct v4l2_control *ctrl);
  1359. /**
  1360. * v4l2_g_ext_ctrls - Helper function to implement
  1361. * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
  1362. *
  1363. * @hdl: pointer to &struct v4l2_ctrl_handler
  1364. * @vdev: pointer to &struct video_device
  1365. * @mdev: pointer to &struct media_device
  1366. * @c: pointer to &struct v4l2_ext_controls
  1367. *
  1368. * If hdl == NULL then they will all return -EINVAL.
  1369. */
  1370. int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
  1371. struct media_device *mdev, struct v4l2_ext_controls *c);
  1372. /**
  1373. * v4l2_try_ext_ctrls - Helper function to implement
  1374. * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
  1375. *
  1376. * @hdl: pointer to &struct v4l2_ctrl_handler
  1377. * @vdev: pointer to &struct video_device
  1378. * @mdev: pointer to &struct media_device
  1379. * @c: pointer to &struct v4l2_ext_controls
  1380. *
  1381. * If hdl == NULL then they will all return -EINVAL.
  1382. */
  1383. int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
  1384. struct video_device *vdev,
  1385. struct media_device *mdev,
  1386. struct v4l2_ext_controls *c);
  1387. /**
  1388. * v4l2_s_ext_ctrls - Helper function to implement
  1389. * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
  1390. *
  1391. * @fh: pointer to &struct v4l2_fh
  1392. * @hdl: pointer to &struct v4l2_ctrl_handler
  1393. * @vdev: pointer to &struct video_device
  1394. * @mdev: pointer to &struct media_device
  1395. * @c: pointer to &struct v4l2_ext_controls
  1396. *
  1397. * If hdl == NULL then they will all return -EINVAL.
  1398. */
  1399. int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
  1400. struct video_device *vdev,
  1401. struct media_device *mdev,
  1402. struct v4l2_ext_controls *c);
  1403. /**
  1404. * v4l2_ctrl_subdev_subscribe_event - Helper function to implement
  1405. * as a &struct v4l2_subdev_core_ops subscribe_event function
  1406. * that just subscribes control events.
  1407. *
  1408. * @sd: pointer to &struct v4l2_subdev
  1409. * @fh: pointer to &struct v4l2_fh
  1410. * @sub: pointer to &struct v4l2_event_subscription
  1411. */
  1412. int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  1413. struct v4l2_event_subscription *sub);
  1414. /**
  1415. * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control
  1416. * handler.
  1417. *
  1418. * @sd: pointer to &struct v4l2_subdev
  1419. */
  1420. int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
  1421. /**
  1422. * v4l2_ctrl_new_fwnode_properties() - Register controls for the device
  1423. * properties
  1424. *
  1425. * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
  1426. * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
  1427. * @p: pointer to &struct v4l2_fwnode_device_properties
  1428. *
  1429. * This function registers controls associated to device properties, using the
  1430. * property values contained in @p parameter, if the property has been set to
  1431. * a value.
  1432. *
  1433. * Currently the following v4l2 controls are parsed and registered:
  1434. * - V4L2_CID_CAMERA_ORIENTATION
  1435. * - V4L2_CID_CAMERA_SENSOR_ROTATION;
  1436. *
  1437. * Controls already registered by the caller with the @hdl control handler are
  1438. * not overwritten. Callers should register the controls they want to handle
  1439. * themselves before calling this function.
  1440. *
  1441. * Return: 0 on success, a negative error code on failure.
  1442. */
  1443. int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
  1444. const struct v4l2_ctrl_ops *ctrl_ops,
  1445. const struct v4l2_fwnode_device_properties *p);
  1446. /**
  1447. * v4l2_ctrl_type_op_equal - Default v4l2_ctrl_type_ops equal callback.
  1448. *
  1449. * @ctrl: The v4l2_ctrl pointer.
  1450. * @ptr1: A v4l2 control value.
  1451. * @ptr2: A v4l2 control value.
  1452. *
  1453. * Return: true if values are equal, otherwise false.
  1454. */
  1455. bool v4l2_ctrl_type_op_equal(const struct v4l2_ctrl *ctrl,
  1456. union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2);
  1457. /**
  1458. * v4l2_ctrl_type_op_init - Default v4l2_ctrl_type_ops init callback.
  1459. *
  1460. * @ctrl: The v4l2_ctrl pointer.
  1461. * @from_idx: Starting element index.
  1462. * @ptr: The v4l2 control value.
  1463. *
  1464. * Return: void
  1465. */
  1466. void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx,
  1467. union v4l2_ctrl_ptr ptr);
  1468. /**
  1469. * v4l2_ctrl_type_op_log - Default v4l2_ctrl_type_ops log callback.
  1470. *
  1471. * @ctrl: The v4l2_ctrl pointer.
  1472. *
  1473. * Return: void
  1474. */
  1475. void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl);
  1476. /**
  1477. * v4l2_ctrl_type_op_validate - Default v4l2_ctrl_type_ops validate callback.
  1478. *
  1479. * @ctrl: The v4l2_ctrl pointer.
  1480. * @ptr: The v4l2 control value.
  1481. *
  1482. * Return: 0 on success, a negative error code on failure.
  1483. */
  1484. int v4l2_ctrl_type_op_validate(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);
  1485. #endif