v4l2-ctrls.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. V4L2 controls support header.
  3. Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  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. /* forward references */
  22. struct file;
  23. struct v4l2_ctrl_handler;
  24. struct v4l2_ctrl_helper;
  25. struct v4l2_ctrl;
  26. struct video_device;
  27. struct v4l2_subdev;
  28. struct v4l2_subscribed_event;
  29. struct v4l2_fh;
  30. struct poll_table_struct;
  31. /** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
  32. * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
  33. * for volatile (and usually read-only) controls such as a control
  34. * that returns the current signal strength which changes
  35. * continuously.
  36. * If not set, then the currently cached value will be returned.
  37. * @try_ctrl: Test whether the control's value is valid. Only relevant when
  38. * the usual min/max/step checks are not sufficient.
  39. * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
  40. * ctrl->handler->lock is held when these ops are called, so no
  41. * one else can access controls owned by that handler.
  42. */
  43. struct v4l2_ctrl_ops {
  44. int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
  45. int (*try_ctrl)(struct v4l2_ctrl *ctrl);
  46. int (*s_ctrl)(struct v4l2_ctrl *ctrl);
  47. };
  48. typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
  49. /** struct v4l2_ctrl - The control structure.
  50. * @node: The list node.
  51. * @ev_subs: The list of control event subscriptions.
  52. * @handler: The handler that owns the control.
  53. * @cluster: Point to start of cluster array.
  54. * @ncontrols: Number of controls in cluster array.
  55. * @done: Internal flag: set for each processed control.
  56. * @is_new: Set when the user specified a new value for this control. It
  57. * is also set when called from v4l2_ctrl_handler_setup. Drivers
  58. * should never set this flag.
  59. * @is_private: If set, then this control is private to its handler and it
  60. * will not be added to any other handlers. Drivers can set
  61. * this flag.
  62. * @is_auto: If set, then this control selects whether the other cluster
  63. * members are in 'automatic' mode or 'manual' mode. This is
  64. * used for autogain/gain type clusters. Drivers should never
  65. * set this flag directly.
  66. * @has_volatiles: If set, then one or more members of the cluster are volatile.
  67. * Drivers should never touch this flag.
  68. * @call_notify: If set, then call the handler's notify function whenever the
  69. * control's value changes.
  70. * @manual_mode_value: If the is_auto flag is set, then this is the value
  71. * of the auto control that determines if that control is in
  72. * manual mode. So if the value of the auto control equals this
  73. * value, then the whole cluster is in manual mode. Drivers should
  74. * never set this flag directly.
  75. * @ops: The control ops.
  76. * @id: The control ID.
  77. * @name: The control name.
  78. * @type: The control type.
  79. * @minimum: The control's minimum value.
  80. * @maximum: The control's maximum value.
  81. * @default_value: The control's default value.
  82. * @step: The control's step value for non-menu controls.
  83. * @menu_skip_mask: The control's skip mask for menu controls. This makes it
  84. * easy to skip menu items that are not valid. If bit X is set,
  85. * then menu item X is skipped. Of course, this only works for
  86. * menus with <= 32 menu items. There are no menus that come
  87. * close to that number, so this is OK. Should we ever need more,
  88. * then this will have to be extended to a u64 or a bit array.
  89. * @qmenu: A const char * array for all menu items. Array entries that are
  90. * empty strings ("") correspond to non-existing menu items (this
  91. * is in addition to the menu_skip_mask above). The last entry
  92. * must be NULL.
  93. * @flags: The control's flags.
  94. * @cur: The control's current value.
  95. * @val: The control's new s32 value.
  96. * @val64: The control's new s64 value.
  97. * @string: The control's new string value.
  98. * @priv: The control's private pointer. For use by the driver. It is
  99. * untouched by the control framework. Note that this pointer is
  100. * not freed when the control is deleted. Should this be needed
  101. * then a new internal bitfield can be added to tell the framework
  102. * to free this pointer.
  103. */
  104. struct v4l2_ctrl {
  105. /* Administrative fields */
  106. struct list_head node;
  107. struct list_head ev_subs;
  108. struct v4l2_ctrl_handler *handler;
  109. struct v4l2_ctrl **cluster;
  110. unsigned ncontrols;
  111. unsigned int done:1;
  112. unsigned int is_new:1;
  113. unsigned int is_private:1;
  114. unsigned int is_auto:1;
  115. unsigned int has_volatiles:1;
  116. unsigned int call_notify:1;
  117. unsigned int manual_mode_value:8;
  118. const struct v4l2_ctrl_ops *ops;
  119. u32 id;
  120. const char *name;
  121. enum v4l2_ctrl_type type;
  122. s32 minimum, maximum, default_value;
  123. union {
  124. u32 step;
  125. u32 menu_skip_mask;
  126. };
  127. union {
  128. const char * const *qmenu;
  129. const s64 *qmenu_int;
  130. };
  131. unsigned long flags;
  132. union {
  133. s32 val;
  134. s64 val64;
  135. char *string;
  136. } cur;
  137. union {
  138. s32 val;
  139. s64 val64;
  140. char *string;
  141. };
  142. void *priv;
  143. };
  144. /** struct v4l2_ctrl_ref - The control reference.
  145. * @node: List node for the sorted list.
  146. * @next: Single-link list node for the hash.
  147. * @ctrl: The actual control information.
  148. * @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls().
  149. *
  150. * Each control handler has a list of these refs. The list_head is used to
  151. * keep a sorted-by-control-ID list of all controls, while the next pointer
  152. * is used to link the control in the hash's bucket.
  153. */
  154. struct v4l2_ctrl_ref {
  155. struct list_head node;
  156. struct v4l2_ctrl_ref *next;
  157. struct v4l2_ctrl *ctrl;
  158. struct v4l2_ctrl_helper *helper;
  159. };
  160. /** struct v4l2_ctrl_handler - The control handler keeps track of all the
  161. * controls: both the controls owned by the handler and those inherited
  162. * from other handlers.
  163. * @_lock: Default for "lock".
  164. * @lock: Lock to control access to this handler and its controls.
  165. * May be replaced by the user right after init.
  166. * @ctrls: The list of controls owned by this handler.
  167. * @ctrl_refs: The list of control references.
  168. * @cached: The last found control reference. It is common that the same
  169. * control is needed multiple times, so this is a simple
  170. * optimization.
  171. * @buckets: Buckets for the hashing. Allows for quick control lookup.
  172. * @notify: A notify callback that is called whenever the control changes value.
  173. * Note that the handler's lock is held when the notify function
  174. * is called!
  175. * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
  176. * @nr_of_buckets: Total number of buckets in the array.
  177. * @error: The error code of the first failed control addition.
  178. */
  179. struct v4l2_ctrl_handler {
  180. struct mutex _lock;
  181. struct mutex *lock;
  182. struct list_head ctrls;
  183. struct list_head ctrl_refs;
  184. struct v4l2_ctrl_ref *cached;
  185. struct v4l2_ctrl_ref **buckets;
  186. v4l2_ctrl_notify_fnc notify;
  187. void *notify_priv;
  188. u16 nr_of_buckets;
  189. int error;
  190. };
  191. /** struct v4l2_ctrl_config - Control configuration structure.
  192. * @ops: The control ops.
  193. * @id: The control ID.
  194. * @name: The control name.
  195. * @type: The control type.
  196. * @min: The control's minimum value.
  197. * @max: The control's maximum value.
  198. * @step: The control's step value for non-menu controls.
  199. * @def: The control's default value.
  200. * @flags: The control's flags.
  201. * @menu_skip_mask: The control's skip mask for menu controls. This makes it
  202. * easy to skip menu items that are not valid. If bit X is set,
  203. * then menu item X is skipped. Of course, this only works for
  204. * menus with <= 32 menu items. There are no menus that come
  205. * close to that number, so this is OK. Should we ever need more,
  206. * then this will have to be extended to a u64 or a bit array.
  207. * @qmenu: A const char * array for all menu items. Array entries that are
  208. * empty strings ("") correspond to non-existing menu items (this
  209. * is in addition to the menu_skip_mask above). The last entry
  210. * must be NULL.
  211. * @is_private: If set, then this control is private to its handler and it
  212. * will not be added to any other handlers.
  213. */
  214. struct v4l2_ctrl_config {
  215. const struct v4l2_ctrl_ops *ops;
  216. u32 id;
  217. const char *name;
  218. enum v4l2_ctrl_type type;
  219. s32 min;
  220. s32 max;
  221. u32 step;
  222. s32 def;
  223. u32 flags;
  224. u32 menu_skip_mask;
  225. const char * const *qmenu;
  226. const s64 *qmenu_int;
  227. unsigned int is_private:1;
  228. };
  229. /** v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
  230. *
  231. * This works for all standard V4L2 controls.
  232. * For non-standard controls it will only fill in the given arguments
  233. * and @name will be NULL.
  234. *
  235. * This function will overwrite the contents of @name, @type and @flags.
  236. * The contents of @min, @max, @step and @def may be modified depending on
  237. * the type.
  238. *
  239. * Do not use in drivers! It is used internally for backwards compatibility
  240. * control handling only. Once all drivers are converted to use the new
  241. * control framework this function will no longer be exported.
  242. */
  243. void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
  244. s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags);
  245. /** v4l2_ctrl_handler_init_class() - Initialize the control handler.
  246. * @hdl: The control handler.
  247. * @nr_of_controls_hint: A hint of how many controls this handler is
  248. * expected to refer to. This is the total number, so including
  249. * any inherited controls. It doesn't have to be precise, but if
  250. * it is way off, then you either waste memory (too many buckets
  251. * are allocated) or the control lookup becomes slower (not enough
  252. * buckets are allocated, so there are more slow list lookups).
  253. * It will always work, though.
  254. * @key: Used by the lock validator if CONFIG_LOCKDEP is set.
  255. * @name: Used by the lock validator if CONFIG_LOCKDEP is set.
  256. *
  257. * Returns an error if the buckets could not be allocated. This error will
  258. * also be stored in @hdl->error.
  259. *
  260. * Never use this call directly, always use the v4l2_ctrl_handler_init
  261. * macro that hides the @key and @name arguments.
  262. */
  263. int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
  264. unsigned nr_of_controls_hint,
  265. struct lock_class_key *key, const char *name);
  266. #ifdef CONFIG_LOCKDEP
  267. #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
  268. ( \
  269. ({ \
  270. static struct lock_class_key _key; \
  271. v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
  272. &_key, \
  273. KBUILD_BASENAME ":" \
  274. __stringify(__LINE__) ":" \
  275. "(" #hdl ")->_lock"); \
  276. }) \
  277. )
  278. #else
  279. #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
  280. v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
  281. #endif
  282. /** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
  283. * the control list.
  284. * @hdl: The control handler.
  285. *
  286. * Does nothing if @hdl == NULL.
  287. */
  288. void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
  289. /** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
  290. * to the handler to initialize the hardware to the current control values.
  291. * @hdl: The control handler.
  292. *
  293. * Button controls will be skipped, as are read-only controls.
  294. *
  295. * If @hdl == NULL, then this just returns 0.
  296. */
  297. int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
  298. /** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
  299. * @hdl: The control handler.
  300. * @prefix: The prefix to use when logging the control values. If the
  301. * prefix does not end with a space, then ": " will be added
  302. * after the prefix. If @prefix == NULL, then no prefix will be
  303. * used.
  304. *
  305. * For use with VIDIOC_LOG_STATUS.
  306. *
  307. * Does nothing if @hdl == NULL.
  308. */
  309. void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
  310. const char *prefix);
  311. /** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
  312. * control.
  313. * @hdl: The control handler.
  314. * @cfg: The control's configuration data.
  315. * @priv: The control's driver-specific private data.
  316. *
  317. * If the &v4l2_ctrl struct could not be allocated then NULL is returned
  318. * and @hdl->error is set to the error code (if it wasn't set already).
  319. */
  320. struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
  321. const struct v4l2_ctrl_config *cfg, void *priv);
  322. /** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control.
  323. * @hdl: The control handler.
  324. * @ops: The control ops.
  325. * @id: The control ID.
  326. * @min: The control's minimum value.
  327. * @max: The control's maximum value.
  328. * @step: The control's step value
  329. * @def: The control's default value.
  330. *
  331. * If the &v4l2_ctrl struct could not be allocated, or the control
  332. * ID is not known, then NULL is returned and @hdl->error is set to the
  333. * appropriate error code (if it wasn't set already).
  334. *
  335. * If @id refers to a menu control, then this function will return NULL.
  336. *
  337. * Use v4l2_ctrl_new_std_menu() when adding menu controls.
  338. */
  339. struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
  340. const struct v4l2_ctrl_ops *ops,
  341. u32 id, s32 min, s32 max, u32 step, s32 def);
  342. /** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control.
  343. * @hdl: The control handler.
  344. * @ops: The control ops.
  345. * @id: The control ID.
  346. * @max: The control's maximum value.
  347. * @mask: The control's skip mask for menu controls. This makes it
  348. * easy to skip menu items that are not valid. If bit X is set,
  349. * then menu item X is skipped. Of course, this only works for
  350. * menus with <= 32 menu items. There are no menus that come
  351. * close to that number, so this is OK. Should we ever need more,
  352. * then this will have to be extended to a u64 or a bit array.
  353. * @def: The control's default value.
  354. *
  355. * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
  356. * determines which menu items are to be skipped.
  357. *
  358. * If @id refers to a non-menu control, then this function will return NULL.
  359. */
  360. struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
  361. const struct v4l2_ctrl_ops *ops,
  362. u32 id, s32 max, s32 mask, s32 def);
  363. /** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
  364. * with driver specific menu.
  365. * @hdl: The control handler.
  366. * @ops: The control ops.
  367. * @id: The control ID.
  368. * @max: The control's maximum value.
  369. * @mask: The control's skip mask for menu controls. This makes it
  370. * easy to skip menu items that are not valid. If bit X is set,
  371. * then menu item X is skipped. Of course, this only works for
  372. * menus with <= 32 menu items. There are no menus that come
  373. * close to that number, so this is OK. Should we ever need more,
  374. * then this will have to be extended to a u64 or a bit array.
  375. * @def: The control's default value.
  376. * @qmenu: The new menu.
  377. *
  378. * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
  379. * menu of this control.
  380. *
  381. */
  382. struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
  383. const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
  384. s32 mask, s32 def, const char * const *qmenu);
  385. /** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
  386. * @hdl: The control handler.
  387. * @ops: The control ops.
  388. * @id: The control ID.
  389. * @max: The control's maximum value.
  390. * @def: The control's default value.
  391. * @qmenu_int: The control's menu entries.
  392. *
  393. * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
  394. * takes as an argument an array of integers determining the menu items.
  395. *
  396. * If @id refers to a non-integer-menu control, then this function will return NULL.
  397. */
  398. struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
  399. const struct v4l2_ctrl_ops *ops,
  400. u32 id, s32 max, s32 def, const s64 *qmenu_int);
  401. /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
  402. * @hdl: The control handler.
  403. * @ctrl: The control to add.
  404. *
  405. * It will return NULL if it was unable to add the control reference.
  406. * If the control already belonged to the handler, then it will do
  407. * nothing and just return @ctrl.
  408. */
  409. struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
  410. struct v4l2_ctrl *ctrl);
  411. /** v4l2_ctrl_add_handler() - Add all controls from handler @add to
  412. * handler @hdl.
  413. * @hdl: The control handler.
  414. * @add: The control handler whose controls you want to add to
  415. * the @hdl control handler.
  416. * @filter: This function will filter which controls should be added.
  417. *
  418. * Does nothing if either of the two handlers is a NULL pointer.
  419. * If @filter is NULL, then all controls are added. Otherwise only those
  420. * controls for which @filter returns true will be added.
  421. * In case of an error @hdl->error will be set to the error code (if it
  422. * wasn't set already).
  423. */
  424. int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
  425. struct v4l2_ctrl_handler *add,
  426. bool (*filter)(const struct v4l2_ctrl *ctrl));
  427. /** v4l2_ctrl_radio_filter() - Standard filter for radio controls.
  428. * @ctrl: The control that is filtered.
  429. *
  430. * This will return true for any controls that are valid for radio device
  431. * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
  432. * transmitter class controls.
  433. *
  434. * This function is to be used with v4l2_ctrl_add_handler().
  435. */
  436. bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
  437. /** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
  438. * @ncontrols: The number of controls in this cluster.
  439. * @controls: The cluster control array of size @ncontrols.
  440. */
  441. void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
  442. /** v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to
  443. * that cluster and set it up for autofoo/foo-type handling.
  444. * @ncontrols: The number of controls in this cluster.
  445. * @controls: The cluster control array of size @ncontrols. The first control
  446. * must be the 'auto' control (e.g. autogain, autoexposure, etc.)
  447. * @manual_val: The value for the first control in the cluster that equals the
  448. * manual setting.
  449. * @set_volatile: If true, then all controls except the first auto control will
  450. * be volatile.
  451. *
  452. * Use for control groups where one control selects some automatic feature and
  453. * the other controls are only active whenever the automatic feature is turned
  454. * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
  455. * red and blue balance, etc.
  456. *
  457. * The behavior of such controls is as follows:
  458. *
  459. * When the autofoo control is set to automatic, then any manual controls
  460. * are set to inactive and any reads will call g_volatile_ctrl (if the control
  461. * was marked volatile).
  462. *
  463. * When the autofoo control is set to manual, then any manual controls will
  464. * be marked active, and any reads will just return the current value without
  465. * going through g_volatile_ctrl.
  466. *
  467. * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag
  468. * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
  469. * if autofoo is in auto mode.
  470. */
  471. void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
  472. u8 manual_val, bool set_volatile);
  473. /** v4l2_ctrl_find() - Find a control with the given ID.
  474. * @hdl: The control handler.
  475. * @id: The control ID to find.
  476. *
  477. * If @hdl == NULL this will return NULL as well. Will lock the handler so
  478. * do not use from inside &v4l2_ctrl_ops.
  479. */
  480. struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
  481. /** v4l2_ctrl_activate() - Make the control active or inactive.
  482. * @ctrl: The control to (de)activate.
  483. * @active: True if the control should become active.
  484. *
  485. * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
  486. * Does nothing if @ctrl == NULL.
  487. * This will usually be called from within the s_ctrl op.
  488. * The V4L2_EVENT_CTRL event will be generated afterwards.
  489. *
  490. * This function assumes that the control handler is locked.
  491. */
  492. void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
  493. /** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
  494. * @ctrl: The control to (de)activate.
  495. * @grabbed: True if the control should become grabbed.
  496. *
  497. * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
  498. * Does nothing if @ctrl == NULL.
  499. * The V4L2_EVENT_CTRL event will be generated afterwards.
  500. * This will usually be called when starting or stopping streaming in the
  501. * driver.
  502. *
  503. * This function assumes that the control handler is not locked and will
  504. * take the lock itself.
  505. */
  506. void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
  507. /** v4l2_ctrl_modify_range() - Update the range of a control.
  508. * @ctrl: The control to update.
  509. * @min: The control's minimum value.
  510. * @max: The control's maximum value.
  511. * @step: The control's step value
  512. * @def: The control's default value.
  513. *
  514. * Update the range of a control on the fly. This works for control types
  515. * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
  516. * @step value is interpreted as a menu_skip_mask.
  517. *
  518. * An error is returned if one of the range arguments is invalid for this
  519. * control type.
  520. *
  521. * This function assumes that the control handler is not locked and will
  522. * take the lock itself.
  523. */
  524. int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
  525. s32 min, s32 max, u32 step, s32 def);
  526. /** v4l2_ctrl_lock() - Helper function to lock the handler
  527. * associated with the control.
  528. * @ctrl: The control to lock.
  529. */
  530. static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
  531. {
  532. mutex_lock(ctrl->handler->lock);
  533. }
  534. /** v4l2_ctrl_lock() - Helper function to unlock the handler
  535. * associated with the control.
  536. * @ctrl: The control to unlock.
  537. */
  538. static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
  539. {
  540. mutex_unlock(ctrl->handler->lock);
  541. }
  542. /** v4l2_ctrl_notify() - Function to set a notify callback for a control.
  543. * @ctrl: The control.
  544. * @notify: The callback function.
  545. * @priv: The callback private handle, passed as argument to the callback.
  546. *
  547. * This function sets a callback function for the control. If @ctrl is NULL,
  548. * then it will do nothing. If @notify is NULL, then the notify callback will
  549. * be removed.
  550. *
  551. * There can be only one notify. If another already exists, then a WARN_ON
  552. * will be issued and the function will do nothing.
  553. */
  554. void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv);
  555. /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
  556. * @ctrl: The control.
  557. *
  558. * This returns the control's value safely by going through the control
  559. * framework. This function will lock the control's handler, so it cannot be
  560. * used from within the &v4l2_ctrl_ops functions.
  561. *
  562. * This function is for integer type controls only.
  563. */
  564. s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
  565. /** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver.
  566. * @ctrl: The control.
  567. * @val: The new value.
  568. *
  569. * This set the control's new value safely by going through the control
  570. * framework. This function will lock the control's handler, so it cannot be
  571. * used from within the &v4l2_ctrl_ops functions.
  572. *
  573. * This function is for integer type controls only.
  574. */
  575. int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
  576. /** v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value from within a driver.
  577. * @ctrl: The control.
  578. *
  579. * This returns the control's value safely by going through the control
  580. * framework. This function will lock the control's handler, so it cannot be
  581. * used from within the &v4l2_ctrl_ops functions.
  582. *
  583. * This function is for 64-bit integer type controls only.
  584. */
  585. s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
  586. /** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value from within a driver.
  587. * @ctrl: The control.
  588. * @val: The new value.
  589. *
  590. * This set the control's new value safely by going through the control
  591. * framework. This function will lock the control's handler, so it cannot be
  592. * used from within the &v4l2_ctrl_ops functions.
  593. *
  594. * This function is for 64-bit integer type controls only.
  595. */
  596. int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
  597. /* Internal helper functions that deal with control events. */
  598. extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
  599. void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
  600. void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
  601. /* Can be used as a vidioc_log_status function that just dumps all controls
  602. associated with the filehandle. */
  603. int v4l2_ctrl_log_status(struct file *file, void *fh);
  604. /* Can be used as a vidioc_subscribe_event function that just subscribes
  605. control events. */
  606. int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
  607. const struct v4l2_event_subscription *sub);
  608. /* Can be used as a poll function that just polls for control events. */
  609. unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
  610. /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
  611. int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
  612. int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
  613. int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
  614. int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
  615. struct v4l2_control *ctrl);
  616. int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
  617. int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
  618. int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
  619. struct v4l2_ext_controls *c);
  620. /* Helpers for subdevices. If the associated ctrl_handler == NULL then they
  621. will all return -EINVAL. */
  622. int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
  623. int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
  624. int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
  625. int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
  626. int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
  627. int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
  628. int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
  629. /* Can be used as a subscribe_event function that just subscribes control
  630. events. */
  631. int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  632. struct v4l2_event_subscription *sub);
  633. /* Log all controls owned by subdev's control handler. */
  634. int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
  635. #endif