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