v4l2-ctrls.h 36 KB

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