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