v4l2-ctrls.h 44 KB

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