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