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