v4l2-ctrls.h 54 KB

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