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