Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 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 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef _V4L2_CTRLS_H |
| 22 | #define _V4L2_CTRLS_H |
| 23 | |
| 24 | #include <linux/list.h> |
Andrzej Hajda | a19dec6 | 2013-06-28 05:44:22 -0300 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Laurent Pinchart | 01c40c0 | 2010-11-19 11:20:06 -0300 | [diff] [blame] | 26 | #include <linux/videodev2.h> |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 27 | |
| 28 | /* forward references */ |
Laurent Pinchart | 528f0f7 | 2012-04-23 08:20:35 -0300 | [diff] [blame] | 29 | struct file; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 30 | struct v4l2_ctrl_handler; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 31 | struct v4l2_ctrl_helper; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 32 | struct v4l2_ctrl; |
| 33 | struct video_device; |
| 34 | struct v4l2_subdev; |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 35 | struct v4l2_subscribed_event; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 36 | struct v4l2_fh; |
Hans Verkuil | a26243b | 2012-01-27 16:18:42 -0300 | [diff] [blame] | 37 | struct poll_table_struct; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 38 | |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 39 | /** union v4l2_ctrl_ptr - A pointer to a control value. |
| 40 | * @p_s32: Pointer to a 32-bit signed value. |
| 41 | * @p_s64: Pointer to a 64-bit signed value. |
Hans Verkuil | dda4a4d | 2014-06-10 07:30:04 -0300 | [diff] [blame] | 42 | * @p_u8: Pointer to a 8-bit unsigned value. |
| 43 | * @p_u16: Pointer to a 16-bit unsigned value. |
Hans Verkuil | 811c508 | 2014-07-21 10:45:37 -0300 | [diff] [blame] | 44 | * @p_u32: Pointer to a 32-bit unsigned value. |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 45 | * @p_char: Pointer to a string. |
| 46 | * @p: Pointer to a compound value. |
| 47 | */ |
| 48 | union v4l2_ctrl_ptr { |
| 49 | s32 *p_s32; |
| 50 | s64 *p_s64; |
Hans Verkuil | dda4a4d | 2014-06-10 07:30:04 -0300 | [diff] [blame] | 51 | u8 *p_u8; |
| 52 | u16 *p_u16; |
Hans Verkuil | 811c508 | 2014-07-21 10:45:37 -0300 | [diff] [blame] | 53 | u32 *p_u32; |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 54 | char *p_char; |
| 55 | void *p; |
| 56 | }; |
| 57 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 58 | /** struct v4l2_ctrl_ops - The control operations that the driver has to provide. |
| 59 | * @g_volatile_ctrl: Get a new value for this control. Generally only relevant |
| 60 | * for volatile (and usually read-only) controls such as a control |
| 61 | * that returns the current signal strength which changes |
| 62 | * continuously. |
| 63 | * If not set, then the currently cached value will be returned. |
| 64 | * @try_ctrl: Test whether the control's value is valid. Only relevant when |
| 65 | * the usual min/max/step checks are not sufficient. |
| 66 | * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The |
| 67 | * ctrl->handler->lock is held when these ops are called, so no |
| 68 | * one else can access controls owned by that handler. |
| 69 | */ |
| 70 | struct v4l2_ctrl_ops { |
| 71 | int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl); |
| 72 | int (*try_ctrl)(struct v4l2_ctrl *ctrl); |
| 73 | int (*s_ctrl)(struct v4l2_ctrl *ctrl); |
| 74 | }; |
| 75 | |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 76 | /** struct v4l2_ctrl_type_ops - The control type operations that the driver has to provide. |
| 77 | * @equal: return true if both values are equal. |
| 78 | * @init: initialize the value. |
| 79 | * @log: log the value. |
| 80 | * @validate: validate the value. Return 0 on success and a negative value otherwise. |
| 81 | */ |
| 82 | struct v4l2_ctrl_type_ops { |
Hans Verkuil | 998e765 | 2014-06-10 07:55:00 -0300 | [diff] [blame] | 83 | bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx, |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 84 | union v4l2_ctrl_ptr ptr1, |
| 85 | union v4l2_ctrl_ptr ptr2); |
Hans Verkuil | 998e765 | 2014-06-10 07:55:00 -0300 | [diff] [blame] | 86 | void (*init)(const struct v4l2_ctrl *ctrl, u32 idx, |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 87 | union v4l2_ctrl_ptr ptr); |
| 88 | void (*log)(const struct v4l2_ctrl *ctrl); |
Hans Verkuil | 998e765 | 2014-06-10 07:55:00 -0300 | [diff] [blame] | 89 | int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx, |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 90 | union v4l2_ctrl_ptr ptr); |
| 91 | }; |
| 92 | |
Hans Verkuil | 8ac7a94 | 2012-09-07 04:46:39 -0300 | [diff] [blame] | 93 | typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); |
| 94 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 95 | /** struct v4l2_ctrl - The control structure. |
| 96 | * @node: The list node. |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 97 | * @ev_subs: The list of control event subscriptions. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 98 | * @handler: The handler that owns the control. |
| 99 | * @cluster: Point to start of cluster array. |
| 100 | * @ncontrols: Number of controls in cluster array. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 101 | * @done: Internal flag: set for each processed control. |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 102 | * @is_new: Set when the user specified a new value for this control. It |
| 103 | * is also set when called from v4l2_ctrl_handler_setup. Drivers |
| 104 | * should never set this flag. |
Hans Verkuil | 9ea1b7a | 2014-01-17 08:25:26 -0300 | [diff] [blame] | 105 | * @has_changed: Set when the current value differs from the new value. Drivers |
| 106 | * should never use this flag. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 107 | * @is_private: If set, then this control is private to its handler and it |
| 108 | * will not be added to any other handlers. Drivers can set |
| 109 | * this flag. |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 110 | * @is_auto: If set, then this control selects whether the other cluster |
| 111 | * members are in 'automatic' mode or 'manual' mode. This is |
| 112 | * used for autogain/gain type clusters. Drivers should never |
| 113 | * set this flag directly. |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 114 | * @is_int: If set, then this control has a simple integer value (i.e. it |
| 115 | * uses ctrl->val). |
| 116 | * @is_string: If set, then this control has type V4L2_CTRL_TYPE_STRING. |
| 117 | * @is_ptr: If set, then this control is an array and/or has type >= V4L2_CTRL_COMPOUND_TYPES |
| 118 | * and/or has type V4L2_CTRL_TYPE_STRING. In other words, struct |
| 119 | * v4l2_ext_control uses field p to point to the data. |
Hans Verkuil | 998e765 | 2014-06-10 07:55:00 -0300 | [diff] [blame] | 120 | * @is_array: If set, then this control contains an N-dimensional array. |
Hans Verkuil | 5626b8c | 2011-08-26 07:53:53 -0300 | [diff] [blame] | 121 | * @has_volatiles: If set, then one or more members of the cluster are volatile. |
| 122 | * Drivers should never touch this flag. |
Hans Verkuil | 8ac7a94 | 2012-09-07 04:46:39 -0300 | [diff] [blame] | 123 | * @call_notify: If set, then call the handler's notify function whenever the |
| 124 | * control's value changes. |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 125 | * @manual_mode_value: If the is_auto flag is set, then this is the value |
| 126 | * of the auto control that determines if that control is in |
| 127 | * manual mode. So if the value of the auto control equals this |
| 128 | * value, then the whole cluster is in manual mode. Drivers should |
| 129 | * never set this flag directly. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 130 | * @ops: The control ops. |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 131 | * @type_ops: The control type ops. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 132 | * @id: The control ID. |
| 133 | * @name: The control name. |
| 134 | * @type: The control type. |
| 135 | * @minimum: The control's minimum value. |
| 136 | * @maximum: The control's maximum value. |
| 137 | * @default_value: The control's default value. |
| 138 | * @step: The control's step value for non-menu controls. |
Hans Verkuil | 20d88ee | 2014-06-12 07:55:21 -0300 | [diff] [blame] | 139 | * @elems: The number of elements in the N-dimensional array. |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 140 | * @elem_size: The size in bytes of the control. |
Hans Verkuil | 20d88ee | 2014-06-12 07:55:21 -0300 | [diff] [blame] | 141 | * @dims: The size of each dimension. |
| 142 | * @nr_of_dims:The number of dimensions in @dims. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 143 | * @menu_skip_mask: The control's skip mask for menu controls. This makes it |
| 144 | * easy to skip menu items that are not valid. If bit X is set, |
| 145 | * then menu item X is skipped. Of course, this only works for |
| 146 | * menus with <= 32 menu items. There are no menus that come |
| 147 | * close to that number, so this is OK. Should we ever need more, |
| 148 | * then this will have to be extended to a u64 or a bit array. |
| 149 | * @qmenu: A const char * array for all menu items. Array entries that are |
| 150 | * empty strings ("") correspond to non-existing menu items (this |
| 151 | * is in addition to the menu_skip_mask above). The last entry |
| 152 | * must be NULL. |
| 153 | * @flags: The control's flags. |
| 154 | * @cur: The control's current value. |
| 155 | * @val: The control's new s32 value. |
| 156 | * @val64: The control's new s64 value. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 157 | * @priv: The control's private pointer. For use by the driver. It is |
| 158 | * untouched by the control framework. Note that this pointer is |
| 159 | * not freed when the control is deleted. Should this be needed |
| 160 | * then a new internal bitfield can be added to tell the framework |
| 161 | * to free this pointer. |
| 162 | */ |
| 163 | struct v4l2_ctrl { |
| 164 | /* Administrative fields */ |
| 165 | struct list_head node; |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 166 | struct list_head ev_subs; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 167 | struct v4l2_ctrl_handler *handler; |
| 168 | struct v4l2_ctrl **cluster; |
| 169 | unsigned ncontrols; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 170 | unsigned int done:1; |
| 171 | |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 172 | unsigned int is_new:1; |
Hans Verkuil | 9ea1b7a | 2014-01-17 08:25:26 -0300 | [diff] [blame] | 173 | unsigned int has_changed:1; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 174 | unsigned int is_private:1; |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 175 | unsigned int is_auto:1; |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 176 | unsigned int is_int:1; |
| 177 | unsigned int is_string:1; |
| 178 | unsigned int is_ptr:1; |
Hans Verkuil | 998e765 | 2014-06-10 07:55:00 -0300 | [diff] [blame] | 179 | unsigned int is_array:1; |
Hans Verkuil | 5626b8c | 2011-08-26 07:53:53 -0300 | [diff] [blame] | 180 | unsigned int has_volatiles:1; |
Hans Verkuil | 8ac7a94 | 2012-09-07 04:46:39 -0300 | [diff] [blame] | 181 | unsigned int call_notify:1; |
Hans Verkuil | 82a7c04 | 2011-06-28 10:43:13 -0300 | [diff] [blame] | 182 | unsigned int manual_mode_value:8; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 183 | |
| 184 | const struct v4l2_ctrl_ops *ops; |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 185 | const struct v4l2_ctrl_type_ops *type_ops; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 186 | u32 id; |
| 187 | const char *name; |
| 188 | enum v4l2_ctrl_type type; |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 189 | s64 minimum, maximum, default_value; |
Hans Verkuil | 20d88ee | 2014-06-12 07:55:21 -0300 | [diff] [blame] | 190 | u32 elems; |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 191 | u32 elem_size; |
Hans Verkuil | 20d88ee | 2014-06-12 07:55:21 -0300 | [diff] [blame] | 192 | u32 dims[V4L2_CTRL_MAX_DIMS]; |
| 193 | u32 nr_of_dims; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 194 | union { |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 195 | u64 step; |
| 196 | u64 menu_skip_mask; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 197 | }; |
Sakari Ailus | ce580fe | 2011-08-04 13:51:11 -0300 | [diff] [blame] | 198 | union { |
| 199 | const char * const *qmenu; |
| 200 | const s64 *qmenu_int; |
| 201 | }; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 202 | unsigned long flags; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 203 | void *priv; |
Hans Verkuil | 2a9ec37 | 2014-04-27 03:38:13 -0300 | [diff] [blame] | 204 | s32 val; |
| 205 | struct { |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 206 | s32 val; |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 207 | } cur; |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 208 | |
| 209 | union v4l2_ctrl_ptr p_new; |
| 210 | union v4l2_ctrl_ptr p_cur; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | /** struct v4l2_ctrl_ref - The control reference. |
| 214 | * @node: List node for the sorted list. |
| 215 | * @next: Single-link list node for the hash. |
| 216 | * @ctrl: The actual control information. |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 217 | * @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls(). |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 218 | * |
| 219 | * Each control handler has a list of these refs. The list_head is used to |
| 220 | * keep a sorted-by-control-ID list of all controls, while the next pointer |
| 221 | * is used to link the control in the hash's bucket. |
| 222 | */ |
| 223 | struct v4l2_ctrl_ref { |
| 224 | struct list_head node; |
| 225 | struct v4l2_ctrl_ref *next; |
| 226 | struct v4l2_ctrl *ctrl; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 227 | struct v4l2_ctrl_helper *helper; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | /** struct v4l2_ctrl_handler - The control handler keeps track of all the |
| 231 | * controls: both the controls owned by the handler and those inherited |
| 232 | * from other handlers. |
Sakari Ailus | 77e7c4e | 2012-01-24 21:05:34 -0300 | [diff] [blame] | 233 | * @_lock: Default for "lock". |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 234 | * @lock: Lock to control access to this handler and its controls. |
Sakari Ailus | 77e7c4e | 2012-01-24 21:05:34 -0300 | [diff] [blame] | 235 | * May be replaced by the user right after init. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 236 | * @ctrls: The list of controls owned by this handler. |
| 237 | * @ctrl_refs: The list of control references. |
| 238 | * @cached: The last found control reference. It is common that the same |
| 239 | * control is needed multiple times, so this is a simple |
| 240 | * optimization. |
| 241 | * @buckets: Buckets for the hashing. Allows for quick control lookup. |
Hans Verkuil | 8ac7a94 | 2012-09-07 04:46:39 -0300 | [diff] [blame] | 242 | * @notify: A notify callback that is called whenever the control changes value. |
| 243 | * Note that the handler's lock is held when the notify function |
| 244 | * is called! |
| 245 | * @notify_priv: Passed as argument to the v4l2_ctrl notify callback. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 246 | * @nr_of_buckets: Total number of buckets in the array. |
| 247 | * @error: The error code of the first failed control addition. |
| 248 | */ |
| 249 | struct v4l2_ctrl_handler { |
Sakari Ailus | 77e7c4e | 2012-01-24 21:05:34 -0300 | [diff] [blame] | 250 | struct mutex _lock; |
| 251 | struct mutex *lock; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 252 | struct list_head ctrls; |
| 253 | struct list_head ctrl_refs; |
| 254 | struct v4l2_ctrl_ref *cached; |
| 255 | struct v4l2_ctrl_ref **buckets; |
Hans Verkuil | 8ac7a94 | 2012-09-07 04:46:39 -0300 | [diff] [blame] | 256 | v4l2_ctrl_notify_fnc notify; |
| 257 | void *notify_priv; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 258 | u16 nr_of_buckets; |
| 259 | int error; |
| 260 | }; |
| 261 | |
| 262 | /** struct v4l2_ctrl_config - Control configuration structure. |
| 263 | * @ops: The control ops. |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 264 | * @type_ops: The control type ops. Only needed for compound controls. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 265 | * @id: The control ID. |
| 266 | * @name: The control name. |
| 267 | * @type: The control type. |
| 268 | * @min: The control's minimum value. |
| 269 | * @max: The control's maximum value. |
| 270 | * @step: The control's step value for non-menu controls. |
| 271 | * @def: The control's default value. |
Hans Verkuil | 20d88ee | 2014-06-12 07:55:21 -0300 | [diff] [blame] | 272 | * @dims: The size of each dimension. |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 273 | * @elem_size: The size in bytes of the control. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 274 | * @flags: The control's flags. |
| 275 | * @menu_skip_mask: The control's skip mask for menu controls. This makes it |
| 276 | * easy to skip menu items that are not valid. If bit X is set, |
| 277 | * then menu item X is skipped. Of course, this only works for |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 278 | * menus with <= 64 menu items. There are no menus that come |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 279 | * close to that number, so this is OK. Should we ever need more, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 280 | * then this will have to be extended to a bit array. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 281 | * @qmenu: A const char * array for all menu items. Array entries that are |
| 282 | * empty strings ("") correspond to non-existing menu items (this |
| 283 | * is in addition to the menu_skip_mask above). The last entry |
| 284 | * must be NULL. |
| 285 | * @is_private: If set, then this control is private to its handler and it |
| 286 | * will not be added to any other handlers. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 287 | */ |
| 288 | struct v4l2_ctrl_config { |
| 289 | const struct v4l2_ctrl_ops *ops; |
Hans Verkuil | 0176077 | 2014-04-27 03:22:17 -0300 | [diff] [blame] | 290 | const struct v4l2_ctrl_type_ops *type_ops; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 291 | u32 id; |
| 292 | const char *name; |
| 293 | enum v4l2_ctrl_type type; |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 294 | s64 min; |
| 295 | s64 max; |
| 296 | u64 step; |
| 297 | s64 def; |
Hans Verkuil | 20d88ee | 2014-06-12 07:55:21 -0300 | [diff] [blame] | 298 | u32 dims[V4L2_CTRL_MAX_DIMS]; |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 299 | u32 elem_size; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 300 | u32 flags; |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 301 | u64 menu_skip_mask; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 302 | const char * const *qmenu; |
Sakari Ailus | ce580fe | 2011-08-04 13:51:11 -0300 | [diff] [blame] | 303 | const s64 *qmenu_int; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 304 | unsigned int is_private:1; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | /** v4l2_ctrl_fill() - Fill in the control fields based on the control ID. |
| 308 | * |
| 309 | * This works for all standard V4L2 controls. |
| 310 | * For non-standard controls it will only fill in the given arguments |
| 311 | * and @name will be NULL. |
| 312 | * |
| 313 | * This function will overwrite the contents of @name, @type and @flags. |
| 314 | * The contents of @min, @max, @step and @def may be modified depending on |
| 315 | * the type. |
| 316 | * |
| 317 | * Do not use in drivers! It is used internally for backwards compatibility |
| 318 | * control handling only. Once all drivers are converted to use the new |
| 319 | * control framework this function will no longer be exported. |
| 320 | */ |
| 321 | void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 322 | s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 323 | |
| 324 | |
Andy Walls | 6cd247e | 2013-03-09 05:55:11 -0300 | [diff] [blame] | 325 | /** v4l2_ctrl_handler_init_class() - Initialize the control handler. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 326 | * @hdl: The control handler. |
| 327 | * @nr_of_controls_hint: A hint of how many controls this handler is |
| 328 | * expected to refer to. This is the total number, so including |
| 329 | * any inherited controls. It doesn't have to be precise, but if |
| 330 | * it is way off, then you either waste memory (too many buckets |
| 331 | * are allocated) or the control lookup becomes slower (not enough |
| 332 | * buckets are allocated, so there are more slow list lookups). |
| 333 | * It will always work, though. |
Andy Walls | 6cd247e | 2013-03-09 05:55:11 -0300 | [diff] [blame] | 334 | * @key: Used by the lock validator if CONFIG_LOCKDEP is set. |
| 335 | * @name: Used by the lock validator if CONFIG_LOCKDEP is set. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 336 | * |
| 337 | * Returns an error if the buckets could not be allocated. This error will |
| 338 | * also be stored in @hdl->error. |
Andy Walls | 6cd247e | 2013-03-09 05:55:11 -0300 | [diff] [blame] | 339 | * |
| 340 | * Never use this call directly, always use the v4l2_ctrl_handler_init |
| 341 | * macro that hides the @key and @name arguments. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 342 | */ |
Andy Walls | 6cd247e | 2013-03-09 05:55:11 -0300 | [diff] [blame] | 343 | int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, |
| 344 | unsigned nr_of_controls_hint, |
| 345 | struct lock_class_key *key, const char *name); |
| 346 | |
| 347 | #ifdef CONFIG_LOCKDEP |
| 348 | #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \ |
| 349 | ( \ |
| 350 | ({ \ |
| 351 | static struct lock_class_key _key; \ |
| 352 | v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \ |
| 353 | &_key, \ |
| 354 | KBUILD_BASENAME ":" \ |
| 355 | __stringify(__LINE__) ":" \ |
| 356 | "(" #hdl ")->_lock"); \ |
| 357 | }) \ |
| 358 | ) |
| 359 | #else |
| 360 | #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \ |
| 361 | v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL) |
| 362 | #endif |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 363 | |
| 364 | /** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free |
| 365 | * the control list. |
| 366 | * @hdl: The control handler. |
| 367 | * |
| 368 | * Does nothing if @hdl == NULL. |
| 369 | */ |
| 370 | void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); |
| 371 | |
Sakari Ailus | 605b384 | 2014-06-12 13:09:39 -0300 | [diff] [blame] | 372 | /** v4l2_ctrl_lock() - Helper function to lock the handler |
| 373 | * associated with the control. |
| 374 | * @ctrl: The control to lock. |
| 375 | */ |
| 376 | static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) |
| 377 | { |
| 378 | mutex_lock(ctrl->handler->lock); |
| 379 | } |
| 380 | |
| 381 | /** v4l2_ctrl_unlock() - Helper function to unlock the handler |
| 382 | * associated with the control. |
| 383 | * @ctrl: The control to unlock. |
| 384 | */ |
| 385 | static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) |
| 386 | { |
| 387 | mutex_unlock(ctrl->handler->lock); |
| 388 | } |
| 389 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 390 | /** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging |
| 391 | * to the handler to initialize the hardware to the current control values. |
| 392 | * @hdl: The control handler. |
| 393 | * |
| 394 | * Button controls will be skipped, as are read-only controls. |
| 395 | * |
| 396 | * If @hdl == NULL, then this just returns 0. |
| 397 | */ |
| 398 | int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); |
| 399 | |
| 400 | /** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler. |
| 401 | * @hdl: The control handler. |
| 402 | * @prefix: The prefix to use when logging the control values. If the |
| 403 | * prefix does not end with a space, then ": " will be added |
| 404 | * after the prefix. If @prefix == NULL, then no prefix will be |
| 405 | * used. |
| 406 | * |
| 407 | * For use with VIDIOC_LOG_STATUS. |
| 408 | * |
| 409 | * Does nothing if @hdl == NULL. |
| 410 | */ |
| 411 | void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, |
| 412 | const char *prefix); |
| 413 | |
| 414 | /** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2 |
| 415 | * control. |
| 416 | * @hdl: The control handler. |
| 417 | * @cfg: The control's configuration data. |
| 418 | * @priv: The control's driver-specific private data. |
| 419 | * |
| 420 | * If the &v4l2_ctrl struct could not be allocated then NULL is returned |
| 421 | * and @hdl->error is set to the error code (if it wasn't set already). |
| 422 | */ |
| 423 | struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, |
| 424 | const struct v4l2_ctrl_config *cfg, void *priv); |
| 425 | |
| 426 | /** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control. |
| 427 | * @hdl: The control handler. |
| 428 | * @ops: The control ops. |
| 429 | * @id: The control ID. |
| 430 | * @min: The control's minimum value. |
| 431 | * @max: The control's maximum value. |
| 432 | * @step: The control's step value |
| 433 | * @def: The control's default value. |
| 434 | * |
| 435 | * If the &v4l2_ctrl struct could not be allocated, or the control |
| 436 | * ID is not known, then NULL is returned and @hdl->error is set to the |
| 437 | * appropriate error code (if it wasn't set already). |
| 438 | * |
| 439 | * If @id refers to a menu control, then this function will return NULL. |
| 440 | * |
| 441 | * Use v4l2_ctrl_new_std_menu() when adding menu controls. |
| 442 | */ |
| 443 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, |
| 444 | const struct v4l2_ctrl_ops *ops, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 445 | u32 id, s64 min, s64 max, u64 step, s64 def); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 446 | |
| 447 | /** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control. |
| 448 | * @hdl: The control handler. |
| 449 | * @ops: The control ops. |
| 450 | * @id: The control ID. |
| 451 | * @max: The control's maximum value. |
| 452 | * @mask: The control's skip mask for menu controls. This makes it |
| 453 | * easy to skip menu items that are not valid. If bit X is set, |
| 454 | * then menu item X is skipped. Of course, this only works for |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 455 | * menus with <= 64 menu items. There are no menus that come |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 456 | * close to that number, so this is OK. Should we ever need more, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 457 | * then this will have to be extended to a bit array. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 458 | * @def: The control's default value. |
| 459 | * |
| 460 | * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value |
| 461 | * determines which menu items are to be skipped. |
| 462 | * |
| 463 | * If @id refers to a non-menu control, then this function will return NULL. |
| 464 | */ |
| 465 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, |
| 466 | const struct v4l2_ctrl_ops *ops, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 467 | u32 id, u8 max, u64 mask, u8 def); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 468 | |
Lad, Prabhakar | 117a711 | 2012-09-18 15:54:38 -0300 | [diff] [blame] | 469 | /** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control |
| 470 | * with driver specific menu. |
| 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 |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 478 | * menus with <= 64 menu items. There are no menus that come |
Lad, Prabhakar | 117a711 | 2012-09-18 15:54:38 -0300 | [diff] [blame] | 479 | * close to that number, so this is OK. Should we ever need more, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 480 | * then this will have to be extended to a bit array. |
Lad, Prabhakar | 117a711 | 2012-09-18 15:54:38 -0300 | [diff] [blame] | 481 | * @def: The control's default value. |
| 482 | * @qmenu: The new menu. |
| 483 | * |
| 484 | * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific |
| 485 | * menu of this control. |
| 486 | * |
| 487 | */ |
| 488 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 489 | const struct v4l2_ctrl_ops *ops, u32 id, u8 max, |
| 490 | u64 mask, u8 def, const char * const *qmenu); |
Lad, Prabhakar | 117a711 | 2012-09-18 15:54:38 -0300 | [diff] [blame] | 491 | |
Sylwester Nawrocki | 515f328 | 2012-05-06 15:30:44 -0300 | [diff] [blame] | 492 | /** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. |
| 493 | * @hdl: The control handler. |
| 494 | * @ops: The control ops. |
| 495 | * @id: The control ID. |
| 496 | * @max: The control's maximum value. |
| 497 | * @def: The control's default value. |
| 498 | * @qmenu_int: The control's menu entries. |
| 499 | * |
| 500 | * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly |
| 501 | * takes as an argument an array of integers determining the menu items. |
| 502 | * |
| 503 | * If @id refers to a non-integer-menu control, then this function will return NULL. |
| 504 | */ |
| 505 | struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, |
| 506 | const struct v4l2_ctrl_ops *ops, |
Hans Verkuil | 0ba2aeb | 2014-04-16 09:41:25 -0300 | [diff] [blame] | 507 | u32 id, u8 max, u8 def, const s64 *qmenu_int); |
Sylwester Nawrocki | 515f328 | 2012-05-06 15:30:44 -0300 | [diff] [blame] | 508 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 509 | /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. |
| 510 | * @hdl: The control handler. |
| 511 | * @ctrl: The control to add. |
| 512 | * |
| 513 | * It will return NULL if it was unable to add the control reference. |
| 514 | * If the control already belonged to the handler, then it will do |
| 515 | * nothing and just return @ctrl. |
| 516 | */ |
| 517 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, |
| 518 | struct v4l2_ctrl *ctrl); |
| 519 | |
| 520 | /** v4l2_ctrl_add_handler() - Add all controls from handler @add to |
| 521 | * handler @hdl. |
| 522 | * @hdl: The control handler. |
| 523 | * @add: The control handler whose controls you want to add to |
| 524 | * the @hdl control handler. |
Hans Verkuil | 34a6b7d | 2012-09-14 07:15:03 -0300 | [diff] [blame] | 525 | * @filter: This function will filter which controls should be added. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 526 | * |
Hans Verkuil | 34a6b7d | 2012-09-14 07:15:03 -0300 | [diff] [blame] | 527 | * Does nothing if either of the two handlers is a NULL pointer. |
| 528 | * If @filter is NULL, then all controls are added. Otherwise only those |
| 529 | * controls for which @filter returns true will be added. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 530 | * In case of an error @hdl->error will be set to the error code (if it |
| 531 | * wasn't set already). |
| 532 | */ |
| 533 | int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, |
Hans Verkuil | 34a6b7d | 2012-09-14 07:15:03 -0300 | [diff] [blame] | 534 | struct v4l2_ctrl_handler *add, |
| 535 | bool (*filter)(const struct v4l2_ctrl *ctrl)); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 536 | |
Hans Verkuil | 34a6b7d | 2012-09-14 07:15:03 -0300 | [diff] [blame] | 537 | /** v4l2_ctrl_radio_filter() - Standard filter for radio controls. |
| 538 | * @ctrl: The control that is filtered. |
| 539 | * |
| 540 | * This will return true for any controls that are valid for radio device |
| 541 | * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM |
| 542 | * transmitter class controls. |
| 543 | * |
| 544 | * This function is to be used with v4l2_ctrl_add_handler(). |
| 545 | */ |
| 546 | bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 547 | |
| 548 | /** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster. |
| 549 | * @ncontrols: The number of controls in this cluster. |
| 550 | * @controls: The cluster control array of size @ncontrols. |
| 551 | */ |
| 552 | void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls); |
| 553 | |
| 554 | |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 555 | /** v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to |
| 556 | * that cluster and set it up for autofoo/foo-type handling. |
| 557 | * @ncontrols: The number of controls in this cluster. |
| 558 | * @controls: The cluster control array of size @ncontrols. The first control |
| 559 | * must be the 'auto' control (e.g. autogain, autoexposure, etc.) |
| 560 | * @manual_val: The value for the first control in the cluster that equals the |
| 561 | * manual setting. |
| 562 | * @set_volatile: If true, then all controls except the first auto control will |
Hans Verkuil | 8836510 | 2011-08-26 07:35:14 -0300 | [diff] [blame] | 563 | * be volatile. |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 564 | * |
| 565 | * Use for control groups where one control selects some automatic feature and |
| 566 | * the other controls are only active whenever the automatic feature is turned |
| 567 | * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs |
| 568 | * red and blue balance, etc. |
| 569 | * |
| 570 | * The behavior of such controls is as follows: |
| 571 | * |
| 572 | * When the autofoo control is set to automatic, then any manual controls |
| 573 | * are set to inactive and any reads will call g_volatile_ctrl (if the control |
| 574 | * was marked volatile). |
| 575 | * |
| 576 | * When the autofoo control is set to manual, then any manual controls will |
| 577 | * be marked active, and any reads will just return the current value without |
| 578 | * going through g_volatile_ctrl. |
| 579 | * |
| 580 | * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag |
| 581 | * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s) |
| 582 | * if autofoo is in auto mode. |
| 583 | */ |
| 584 | void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls, |
| 585 | u8 manual_val, bool set_volatile); |
| 586 | |
| 587 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 588 | /** v4l2_ctrl_find() - Find a control with the given ID. |
| 589 | * @hdl: The control handler. |
| 590 | * @id: The control ID to find. |
| 591 | * |
| 592 | * If @hdl == NULL this will return NULL as well. Will lock the handler so |
| 593 | * do not use from inside &v4l2_ctrl_ops. |
| 594 | */ |
| 595 | struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); |
| 596 | |
| 597 | /** v4l2_ctrl_activate() - Make the control active or inactive. |
| 598 | * @ctrl: The control to (de)activate. |
| 599 | * @active: True if the control should become active. |
| 600 | * |
| 601 | * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically. |
| 602 | * Does nothing if @ctrl == NULL. |
| 603 | * This will usually be called from within the s_ctrl op. |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 604 | * The V4L2_EVENT_CTRL event will be generated afterwards. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 605 | * |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 606 | * This function assumes that the control handler is locked. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 607 | */ |
| 608 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active); |
| 609 | |
| 610 | /** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. |
| 611 | * @ctrl: The control to (de)activate. |
| 612 | * @grabbed: True if the control should become grabbed. |
| 613 | * |
| 614 | * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. |
| 615 | * Does nothing if @ctrl == NULL. |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 616 | * The V4L2_EVENT_CTRL event will be generated afterwards. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 617 | * This will usually be called when starting or stopping streaming in the |
| 618 | * driver. |
| 619 | * |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 620 | * This function assumes that the control handler is not locked and will |
| 621 | * take the lock itself. |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 622 | */ |
| 623 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); |
| 624 | |
Sakari Ailus | 5a57392 | 2014-06-12 13:09:40 -0300 | [diff] [blame] | 625 | |
| 626 | /** __v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range() */ |
| 627 | int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, |
| 628 | s64 min, s64 max, u64 step, s64 def); |
| 629 | |
Sylwester Nawrocki | 2ccbe77 | 2013-01-19 15:51:55 -0300 | [diff] [blame] | 630 | /** v4l2_ctrl_modify_range() - Update the range of a control. |
| 631 | * @ctrl: The control to update. |
| 632 | * @min: The control's minimum value. |
| 633 | * @max: The control's maximum value. |
| 634 | * @step: The control's step value |
| 635 | * @def: The control's default value. |
| 636 | * |
| 637 | * Update the range of a control on the fly. This works for control types |
| 638 | * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the |
| 639 | * @step value is interpreted as a menu_skip_mask. |
| 640 | * |
| 641 | * An error is returned if one of the range arguments is invalid for this |
| 642 | * control type. |
| 643 | * |
| 644 | * This function assumes that the control handler is not locked and will |
| 645 | * take the lock itself. |
| 646 | */ |
Sakari Ailus | 5a57392 | 2014-06-12 13:09:40 -0300 | [diff] [blame] | 647 | static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, |
| 648 | s64 min, s64 max, u64 step, s64 def) |
| 649 | { |
| 650 | int rval; |
| 651 | |
| 652 | v4l2_ctrl_lock(ctrl); |
| 653 | rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def); |
| 654 | v4l2_ctrl_unlock(ctrl); |
| 655 | |
| 656 | return rval; |
| 657 | } |
Sylwester Nawrocki | 2ccbe77 | 2013-01-19 15:51:55 -0300 | [diff] [blame] | 658 | |
Hans Verkuil | 8ac7a94 | 2012-09-07 04:46:39 -0300 | [diff] [blame] | 659 | /** v4l2_ctrl_notify() - Function to set a notify callback for a control. |
| 660 | * @ctrl: The control. |
| 661 | * @notify: The callback function. |
| 662 | * @priv: The callback private handle, passed as argument to the callback. |
| 663 | * |
| 664 | * This function sets a callback function for the control. If @ctrl is NULL, |
| 665 | * then it will do nothing. If @notify is NULL, then the notify callback will |
| 666 | * be removed. |
| 667 | * |
| 668 | * There can be only one notify. If another already exists, then a WARN_ON |
| 669 | * will be issued and the function will do nothing. |
| 670 | */ |
| 671 | void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv); |
| 672 | |
Hans Verkuil | 79fbc20 | 2014-11-23 09:39:54 -0300 | [diff] [blame] | 673 | /** v4l2_ctrl_get_name() - Get the name of the control |
| 674 | * @id: The control ID. |
| 675 | * |
| 676 | * This function returns the name of the given control ID or NULL if it isn't |
| 677 | * a known control. |
| 678 | */ |
| 679 | const char *v4l2_ctrl_get_name(u32 id); |
| 680 | |
| 681 | /** v4l2_ctrl_get_menu() - Get the menu string array of the control |
| 682 | * @id: The control ID. |
| 683 | * |
| 684 | * This function returns the NULL-terminated menu string array name of the |
| 685 | * given control ID or NULL if it isn't a known menu control. |
| 686 | */ |
| 687 | const char * const *v4l2_ctrl_get_menu(u32 id); |
| 688 | |
| 689 | /** v4l2_ctrl_get_int_menu() - Get the integer menu array of the control |
| 690 | * @id: The control ID. |
| 691 | * @len: The size of the integer array. |
| 692 | * |
| 693 | * This function returns the integer array of the given control ID or NULL if it |
| 694 | * if it isn't a known integer menu control. |
| 695 | */ |
| 696 | const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len); |
| 697 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 698 | /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. |
| 699 | * @ctrl: The control. |
| 700 | * |
| 701 | * This returns the control's value safely by going through the control |
| 702 | * framework. This function will lock the control's handler, so it cannot be |
| 703 | * used from within the &v4l2_ctrl_ops functions. |
| 704 | * |
| 705 | * This function is for integer type controls only. |
| 706 | */ |
| 707 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); |
| 708 | |
Sakari Ailus | 0c4348a | 2014-06-12 13:09:42 -0300 | [diff] [blame] | 709 | /** __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl(). */ |
| 710 | int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 711 | /** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver. |
| 712 | * @ctrl: The control. |
| 713 | * @val: The new value. |
| 714 | * |
| 715 | * This set the control's new value safely by going through the control |
| 716 | * framework. This function will lock the control's handler, so it cannot be |
| 717 | * used from within the &v4l2_ctrl_ops functions. |
| 718 | * |
| 719 | * This function is for integer type controls only. |
| 720 | */ |
Sakari Ailus | 0c4348a | 2014-06-12 13:09:42 -0300 | [diff] [blame] | 721 | static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) |
| 722 | { |
| 723 | int rval; |
| 724 | |
| 725 | v4l2_ctrl_lock(ctrl); |
| 726 | rval = __v4l2_ctrl_s_ctrl(ctrl, val); |
| 727 | v4l2_ctrl_unlock(ctrl); |
| 728 | |
| 729 | return rval; |
| 730 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 731 | |
Laurent Pinchart | 03d5285 | 2012-07-23 09:15:21 -0300 | [diff] [blame] | 732 | /** v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value from within a driver. |
| 733 | * @ctrl: The control. |
| 734 | * |
| 735 | * This returns the control's value safely by going through the control |
| 736 | * framework. This function will lock the control's handler, so it cannot be |
| 737 | * used from within the &v4l2_ctrl_ops functions. |
| 738 | * |
| 739 | * This function is for 64-bit integer type controls only. |
| 740 | */ |
| 741 | s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl); |
| 742 | |
Sakari Ailus | 0c4348a | 2014-06-12 13:09:42 -0300 | [diff] [blame] | 743 | /** __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64(). */ |
| 744 | int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val); |
| 745 | |
Laurent Pinchart | 03d5285 | 2012-07-23 09:15:21 -0300 | [diff] [blame] | 746 | /** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value from within a driver. |
| 747 | * @ctrl: The control. |
| 748 | * @val: The new value. |
| 749 | * |
| 750 | * This set the control's new value safely by going through the control |
| 751 | * framework. This function will lock the control's handler, so it cannot be |
| 752 | * used from within the &v4l2_ctrl_ops functions. |
| 753 | * |
| 754 | * This function is for 64-bit integer type controls only. |
| 755 | */ |
Sakari Ailus | 0c4348a | 2014-06-12 13:09:42 -0300 | [diff] [blame] | 756 | static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) |
| 757 | { |
| 758 | int rval; |
| 759 | |
| 760 | v4l2_ctrl_lock(ctrl); |
| 761 | rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val); |
| 762 | v4l2_ctrl_unlock(ctrl); |
| 763 | |
| 764 | return rval; |
| 765 | } |
Laurent Pinchart | 03d5285 | 2012-07-23 09:15:21 -0300 | [diff] [blame] | 766 | |
Hans Verkuil | 5d0360a | 2014-07-21 10:45:42 -0300 | [diff] [blame] | 767 | /** __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string(). */ |
| 768 | int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s); |
| 769 | |
| 770 | /** v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value from within a driver. |
| 771 | * @ctrl: The control. |
| 772 | * @s: The new string. |
| 773 | * |
| 774 | * This set the control's new string 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 string type controls only. |
| 779 | */ |
| 780 | static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) |
| 781 | { |
| 782 | int rval; |
| 783 | |
| 784 | v4l2_ctrl_lock(ctrl); |
| 785 | rval = __v4l2_ctrl_s_ctrl_string(ctrl, s); |
| 786 | v4l2_ctrl_unlock(ctrl); |
| 787 | |
| 788 | return rval; |
| 789 | } |
| 790 | |
Hans Verkuil | ce72757 | 2011-06-10 05:56:39 -0300 | [diff] [blame] | 791 | /* Internal helper functions that deal with control events. */ |
Hans de Goede | 3e366149 | 2012-04-08 12:59:47 -0300 | [diff] [blame] | 792 | extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops; |
| 793 | void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new); |
| 794 | void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 795 | |
Hans Verkuil | e2ecb25 | 2012-02-02 08:20:53 -0300 | [diff] [blame] | 796 | /* Can be used as a vidioc_log_status function that just dumps all controls |
| 797 | associated with the filehandle. */ |
| 798 | int v4l2_ctrl_log_status(struct file *file, void *fh); |
| 799 | |
Hans Verkuil | a26243b | 2012-01-27 16:18:42 -0300 | [diff] [blame] | 800 | /* Can be used as a vidioc_subscribe_event function that just subscribes |
| 801 | control events. */ |
| 802 | int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh, |
Hans Verkuil | 85f5fe3 | 2012-09-04 11:46:09 -0300 | [diff] [blame] | 803 | const struct v4l2_event_subscription *sub); |
Hans Verkuil | a26243b | 2012-01-27 16:18:42 -0300 | [diff] [blame] | 804 | |
| 805 | /* Can be used as a poll function that just polls for control events. */ |
| 806 | unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait); |
| 807 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 808 | /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */ |
| 809 | int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc); |
Hans Verkuil | d9a2547 | 2014-06-12 07:54:16 -0300 | [diff] [blame] | 810 | int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 811 | int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm); |
| 812 | int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 813 | int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
| 814 | struct v4l2_control *ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 815 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); |
| 816 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 817 | int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
| 818 | struct v4l2_ext_controls *c); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 819 | |
| 820 | /* Helpers for subdevices. If the associated ctrl_handler == NULL then they |
| 821 | will all return -EINVAL. */ |
| 822 | int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc); |
| 823 | int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm); |
| 824 | int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); |
| 825 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); |
| 826 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); |
| 827 | int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); |
| 828 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); |
| 829 | |
Sylwester Nawrocki | 22fa427 | 2013-01-22 19:00:23 -0300 | [diff] [blame] | 830 | /* Can be used as a subscribe_event function that just subscribes control |
| 831 | events. */ |
| 832 | int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, |
| 833 | struct v4l2_event_subscription *sub); |
| 834 | |
Sylwester Nawrocki | ffa9b9f | 2013-01-22 19:01:02 -0300 | [diff] [blame] | 835 | /* Log all controls owned by subdev's control handler. */ |
| 836 | int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd); |
| 837 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 838 | #endif |