1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * V4L2 controls support header. 4 * 5 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl> 6 */ 7 8 #ifndef _V4L2_CTRLS_H 9 #define _V4L2_CTRLS_H 10 11 #include <linux/list.h> 12 #include <linux/mutex.h> 13 #include <linux/videodev2.h> 14 #include <media/media-request.h> 15 16 /* 17 * Include the stateless codec compound control definitions. 18 * This will move to the public headers once this API is fully stable. 19 */ 20 #include <media/mpeg2-ctrls.h> 21 #include <media/fwht-ctrls.h> 22 #include <media/h264-ctrls.h> 23 #include <media/vp8-ctrls.h> 24 25 /* forward references */ 26 struct file; 27 struct v4l2_ctrl_handler; 28 struct v4l2_ctrl_helper; 29 struct v4l2_ctrl; 30 struct video_device; 31 struct v4l2_subdev; 32 struct v4l2_subscribed_event; 33 struct v4l2_fh; 34 struct poll_table_struct; 35 36 /** 37 * union v4l2_ctrl_ptr - A pointer to a control value. 38 * @p_s32: Pointer to a 32-bit signed value. 39 * @p_s64: Pointer to a 64-bit signed value. 40 * @p_u8: Pointer to a 8-bit unsigned value. 41 * @p_u16: Pointer to a 16-bit unsigned value. 42 * @p_u32: Pointer to a 32-bit unsigned value. 43 * @p_char: Pointer to a string. 44 * @p_mpeg2_slice_params: Pointer to a MPEG2 slice parameters structure. 45 * @p_mpeg2_quantization: Pointer to a MPEG2 quantization data structure. 46 * @p_fwht_params: Pointer to a FWHT stateless parameters structure. 47 * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps. 48 * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps. 49 * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix. 50 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params. 51 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params. 52 * @p_vp8_frame_header: Pointer to a VP8 frame header structure. 53 * @p_area: Pointer to an area. 54 * @p: Pointer to a compound value. 55 */ 56 union v4l2_ctrl_ptr { 57 s32 *p_s32; 58 s64 *p_s64; 59 u8 *p_u8; 60 u16 *p_u16; 61 u32 *p_u32; 62 char *p_char; 63 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; 64 struct v4l2_ctrl_mpeg2_quantization *p_mpeg2_quantization; 65 struct v4l2_ctrl_fwht_params *p_fwht_params; 66 struct v4l2_ctrl_h264_sps *p_h264_sps; 67 struct v4l2_ctrl_h264_pps *p_h264_pps; 68 struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix; 69 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params; 70 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params; 71 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header; 72 struct v4l2_area *p_area; 73 void *p; 74 }; 75 76 /** 77 * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a 78 * void pointer 79 * @ptr: The void pointer 80 */ 81 static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr) 82 { 83 union v4l2_ctrl_ptr p = { .p = ptr }; 84 85 return p; 86 } 87 88 /** 89 * struct v4l2_ctrl_ops - The control operations that the driver has to provide. 90 * 91 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant 92 * for volatile (and usually read-only) controls such as a control 93 * that returns the current signal strength which changes 94 * continuously. 95 * If not set, then the currently cached value will be returned. 96 * @try_ctrl: Test whether the control's value is valid. Only relevant when 97 * the usual min/max/step checks are not sufficient. 98 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The 99 * ctrl->handler->lock is held when these ops are called, so no 100 * one else can access controls owned by that handler. 101 */ 102 struct v4l2_ctrl_ops { 103 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl); 104 int (*try_ctrl)(struct v4l2_ctrl *ctrl); 105 int (*s_ctrl)(struct v4l2_ctrl *ctrl); 106 }; 107 108 /** 109 * struct v4l2_ctrl_type_ops - The control type operations that the driver 110 * has to provide. 111 * 112 * @equal: return true if both values are equal. 113 * @init: initialize the value. 114 * @log: log the value. 115 * @validate: validate the value. Return 0 on success and a negative value 116 * otherwise. 117 */ 118 struct v4l2_ctrl_type_ops { 119 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx, 120 union v4l2_ctrl_ptr ptr1, 121 union v4l2_ctrl_ptr ptr2); 122 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx, 123 union v4l2_ctrl_ptr ptr); 124 void (*log)(const struct v4l2_ctrl *ctrl); 125 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx, 126 union v4l2_ctrl_ptr ptr); 127 }; 128 129 /** 130 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function 131 * that should be called when a control value has changed. 132 * 133 * @ctrl: pointer to struct &v4l2_ctrl 134 * @priv: control private data 135 * 136 * This typedef definition is used as an argument to v4l2_ctrl_notify() 137 * and as an argument at struct &v4l2_ctrl_handler. 138 */ 139 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); 140 141 /** 142 * struct v4l2_ctrl - The control structure. 143 * 144 * @node: The list node. 145 * @ev_subs: The list of control event subscriptions. 146 * @handler: The handler that owns the control. 147 * @cluster: Point to start of cluster array. 148 * @ncontrols: Number of controls in cluster array. 149 * @done: Internal flag: set for each processed control. 150 * @is_new: Set when the user specified a new value for this control. It 151 * is also set when called from v4l2_ctrl_handler_setup(). Drivers 152 * should never set this flag. 153 * @has_changed: Set when the current value differs from the new value. Drivers 154 * should never use this flag. 155 * @is_private: If set, then this control is private to its handler and it 156 * will not be added to any other handlers. Drivers can set 157 * this flag. 158 * @is_auto: If set, then this control selects whether the other cluster 159 * members are in 'automatic' mode or 'manual' mode. This is 160 * used for autogain/gain type clusters. Drivers should never 161 * set this flag directly. 162 * @is_int: If set, then this control has a simple integer value (i.e. it 163 * uses ctrl->val). 164 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING. 165 * @is_ptr: If set, then this control is an array and/or has type >= 166 * %V4L2_CTRL_COMPOUND_TYPES 167 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct 168 * v4l2_ext_control uses field p to point to the data. 169 * @is_array: If set, then this control contains an N-dimensional array. 170 * @has_volatiles: If set, then one or more members of the cluster are volatile. 171 * Drivers should never touch this flag. 172 * @call_notify: If set, then call the handler's notify function whenever the 173 * control's value changes. 174 * @manual_mode_value: If the is_auto flag is set, then this is the value 175 * of the auto control that determines if that control is in 176 * manual mode. So if the value of the auto control equals this 177 * value, then the whole cluster is in manual mode. Drivers should 178 * never set this flag directly. 179 * @ops: The control ops. 180 * @type_ops: The control type ops. 181 * @id: The control ID. 182 * @name: The control name. 183 * @type: The control type. 184 * @minimum: The control's minimum value. 185 * @maximum: The control's maximum value. 186 * @default_value: The control's default value. 187 * @step: The control's step value for non-menu controls. 188 * @elems: The number of elements in the N-dimensional array. 189 * @elem_size: The size in bytes of the control. 190 * @dims: The size of each dimension. 191 * @nr_of_dims:The number of dimensions in @dims. 192 * @menu_skip_mask: The control's skip mask for menu controls. This makes it 193 * easy to skip menu items that are not valid. If bit X is set, 194 * then menu item X is skipped. Of course, this only works for 195 * menus with <= 32 menu items. There are no menus that come 196 * close to that number, so this is OK. Should we ever need more, 197 * then this will have to be extended to a u64 or a bit array. 198 * @qmenu: A const char * array for all menu items. Array entries that are 199 * empty strings ("") correspond to non-existing menu items (this 200 * is in addition to the menu_skip_mask above). The last entry 201 * must be NULL. 202 * Used only if the @type is %V4L2_CTRL_TYPE_MENU. 203 * @qmenu_int: A 64-bit integer array for with integer menu items. 204 * The size of array must be equal to the menu size, e. g.: 205 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`. 206 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU. 207 * @flags: The control's flags. 208 * @cur: Structure to store the current value. 209 * @cur.val: The control's current value, if the @type is represented via 210 * a u32 integer (see &enum v4l2_ctrl_type). 211 * @val: The control's new s32 value. 212 * @priv: The control's private pointer. For use by the driver. It is 213 * untouched by the control framework. Note that this pointer is 214 * not freed when the control is deleted. Should this be needed 215 * then a new internal bitfield can be added to tell the framework 216 * to free this pointer. 217 * @p_def: The control's default value represented via a union which 218 * provides a standard way of accessing control types 219 * through a pointer (for compound controls only). 220 * @p_cur: The control's current value represented via a union which 221 * provides a standard way of accessing control types 222 * through a pointer. 223 * @p_new: The control's new value represented via a union which provides 224 * a standard way of accessing control types 225 * through a pointer. 226 */ 227 struct v4l2_ctrl { 228 /* Administrative fields */ 229 struct list_head node; 230 struct list_head ev_subs; 231 struct v4l2_ctrl_handler *handler; 232 struct v4l2_ctrl **cluster; 233 unsigned int ncontrols; 234 235 unsigned int done:1; 236 237 unsigned int is_new:1; 238 unsigned int has_changed:1; 239 unsigned int is_private:1; 240 unsigned int is_auto:1; 241 unsigned int is_int:1; 242 unsigned int is_string:1; 243 unsigned int is_ptr:1; 244 unsigned int is_array:1; 245 unsigned int has_volatiles:1; 246 unsigned int call_notify:1; 247 unsigned int manual_mode_value:8; 248 249 const struct v4l2_ctrl_ops *ops; 250 const struct v4l2_ctrl_type_ops *type_ops; 251 u32 id; 252 const char *name; 253 enum v4l2_ctrl_type type; 254 s64 minimum, maximum, default_value; 255 u32 elems; 256 u32 elem_size; 257 u32 dims[V4L2_CTRL_MAX_DIMS]; 258 u32 nr_of_dims; 259 union { 260 u64 step; 261 u64 menu_skip_mask; 262 }; 263 union { 264 const char * const *qmenu; 265 const s64 *qmenu_int; 266 }; 267 unsigned long flags; 268 void *priv; 269 s32 val; 270 struct { 271 s32 val; 272 } cur; 273 274 union v4l2_ctrl_ptr p_def; 275 union v4l2_ctrl_ptr p_new; 276 union v4l2_ctrl_ptr p_cur; 277 }; 278 279 /** 280 * struct v4l2_ctrl_ref - The control reference. 281 * 282 * @node: List node for the sorted list. 283 * @next: Single-link list node for the hash. 284 * @ctrl: The actual control information. 285 * @helper: Pointer to helper struct. Used internally in 286 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``. 287 * @from_other_dev: If true, then @ctrl was defined in another 288 * device than the &struct v4l2_ctrl_handler. 289 * @req_done: Internal flag: if the control handler containing this control 290 * reference is bound to a media request, then this is set when 291 * the control has been applied. This prevents applying controls 292 * from a cluster with multiple controls twice (when the first 293 * control of a cluster is applied, they all are). 294 * @req: If set, this refers to another request that sets this control. 295 * @p_req: If the control handler containing this control reference 296 * is bound to a media request, then this points to the 297 * value of the control that should be applied when the request 298 * is executed, or to the value of the control at the time 299 * that the request was completed. 300 * 301 * Each control handler has a list of these refs. The list_head is used to 302 * keep a sorted-by-control-ID list of all controls, while the next pointer 303 * is used to link the control in the hash's bucket. 304 */ 305 struct v4l2_ctrl_ref { 306 struct list_head node; 307 struct v4l2_ctrl_ref *next; 308 struct v4l2_ctrl *ctrl; 309 struct v4l2_ctrl_helper *helper; 310 bool from_other_dev; 311 bool req_done; 312 struct v4l2_ctrl_ref *req; 313 union v4l2_ctrl_ptr p_req; 314 }; 315 316 /** 317 * struct v4l2_ctrl_handler - The control handler keeps track of all the 318 * controls: both the controls owned by the handler and those inherited 319 * from other handlers. 320 * 321 * @_lock: Default for "lock". 322 * @lock: Lock to control access to this handler and its controls. 323 * May be replaced by the user right after init. 324 * @ctrls: The list of controls owned by this handler. 325 * @ctrl_refs: The list of control references. 326 * @cached: The last found control reference. It is common that the same 327 * control is needed multiple times, so this is a simple 328 * optimization. 329 * @buckets: Buckets for the hashing. Allows for quick control lookup. 330 * @notify: A notify callback that is called whenever the control changes 331 * value. 332 * Note that the handler's lock is held when the notify function 333 * is called! 334 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback. 335 * @nr_of_buckets: Total number of buckets in the array. 336 * @error: The error code of the first failed control addition. 337 * @request_is_queued: True if the request was queued. 338 * @requests: List to keep track of open control handler request objects. 339 * For the parent control handler (@req_obj.req == NULL) this 340 * is the list header. When the parent control handler is 341 * removed, it has to unbind and put all these requests since 342 * they refer to the parent. 343 * @requests_queued: List of the queued requests. This determines the order 344 * in which these controls are applied. Once the request is 345 * completed it is removed from this list. 346 * @req_obj: The &struct media_request_object, used to link into a 347 * &struct media_request. This request object has a refcount. 348 */ 349 struct v4l2_ctrl_handler { 350 struct mutex _lock; 351 struct mutex *lock; 352 struct list_head ctrls; 353 struct list_head ctrl_refs; 354 struct v4l2_ctrl_ref *cached; 355 struct v4l2_ctrl_ref **buckets; 356 v4l2_ctrl_notify_fnc notify; 357 void *notify_priv; 358 u16 nr_of_buckets; 359 int error; 360 bool request_is_queued; 361 struct list_head requests; 362 struct list_head requests_queued; 363 struct media_request_object req_obj; 364 }; 365 366 /** 367 * struct v4l2_ctrl_config - Control configuration structure. 368 * 369 * @ops: The control ops. 370 * @type_ops: The control type ops. Only needed for compound controls. 371 * @id: The control ID. 372 * @name: The control name. 373 * @type: The control type. 374 * @min: The control's minimum value. 375 * @max: The control's maximum value. 376 * @step: The control's step value for non-menu controls. 377 * @def: The control's default value. 378 * @dims: The size of each dimension. 379 * @elem_size: The size in bytes of the control. 380 * @flags: The control's flags. 381 * @menu_skip_mask: The control's skip mask for menu controls. This makes it 382 * easy to skip menu items that are not valid. If bit X is set, 383 * then menu item X is skipped. Of course, this only works for 384 * menus with <= 64 menu items. There are no menus that come 385 * close to that number, so this is OK. Should we ever need more, 386 * then this will have to be extended to a bit array. 387 * @qmenu: A const char * array for all menu items. Array entries that are 388 * empty strings ("") correspond to non-existing menu items (this 389 * is in addition to the menu_skip_mask above). The last entry 390 * must be NULL. 391 * @qmenu_int: A const s64 integer array for all menu items of the type 392 * V4L2_CTRL_TYPE_INTEGER_MENU. 393 * @is_private: If set, then this control is private to its handler and it 394 * will not be added to any other handlers. 395 */ 396 struct v4l2_ctrl_config { 397 const struct v4l2_ctrl_ops *ops; 398 const struct v4l2_ctrl_type_ops *type_ops; 399 u32 id; 400 const char *name; 401 enum v4l2_ctrl_type type; 402 s64 min; 403 s64 max; 404 u64 step; 405 s64 def; 406 u32 dims[V4L2_CTRL_MAX_DIMS]; 407 u32 elem_size; 408 u32 flags; 409 u64 menu_skip_mask; 410 const char * const *qmenu; 411 const s64 *qmenu_int; 412 unsigned int is_private:1; 413 }; 414 415 /** 416 * v4l2_ctrl_fill - Fill in the control fields based on the control ID. 417 * 418 * @id: ID of the control 419 * @name: pointer to be filled with a string with the name of the control 420 * @type: pointer for storing the type of the control 421 * @min: pointer for storing the minimum value for the control 422 * @max: pointer for storing the maximum value for the control 423 * @step: pointer for storing the control step 424 * @def: pointer for storing the default value for the control 425 * @flags: pointer for storing the flags to be used on the control 426 * 427 * This works for all standard V4L2 controls. 428 * For non-standard controls it will only fill in the given arguments 429 * and @name content will be set to %NULL. 430 * 431 * This function will overwrite the contents of @name, @type and @flags. 432 * The contents of @min, @max, @step and @def may be modified depending on 433 * the type. 434 * 435 * .. note:: 436 * 437 * Do not use in drivers! It is used internally for backwards compatibility 438 * control handling only. Once all drivers are converted to use the new 439 * control framework this function will no longer be exported. 440 */ 441 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 442 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags); 443 444 445 /** 446 * v4l2_ctrl_handler_init_class() - Initialize the control handler. 447 * @hdl: The control handler. 448 * @nr_of_controls_hint: A hint of how many controls this handler is 449 * expected to refer to. This is the total number, so including 450 * any inherited controls. It doesn't have to be precise, but if 451 * it is way off, then you either waste memory (too many buckets 452 * are allocated) or the control lookup becomes slower (not enough 453 * buckets are allocated, so there are more slow list lookups). 454 * It will always work, though. 455 * @key: Used by the lock validator if CONFIG_LOCKDEP is set. 456 * @name: Used by the lock validator if CONFIG_LOCKDEP is set. 457 * 458 * .. attention:: 459 * 460 * Never use this call directly, always use the v4l2_ctrl_handler_init() 461 * macro that hides the @key and @name arguments. 462 * 463 * Return: returns an error if the buckets could not be allocated. This 464 * error will also be stored in @hdl->error. 465 */ 466 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, 467 unsigned int nr_of_controls_hint, 468 struct lock_class_key *key, const char *name); 469 470 #ifdef CONFIG_LOCKDEP 471 472 /** 473 * v4l2_ctrl_handler_init - helper function to create a static struct 474 * &lock_class_key and calls v4l2_ctrl_handler_init_class() 475 * 476 * @hdl: The control handler. 477 * @nr_of_controls_hint: A hint of how many controls this handler is 478 * expected to refer to. This is the total number, so including 479 * any inherited controls. It doesn't have to be precise, but if 480 * it is way off, then you either waste memory (too many buckets 481 * are allocated) or the control lookup becomes slower (not enough 482 * buckets are allocated, so there are more slow list lookups). 483 * It will always work, though. 484 * 485 * This helper function creates a static struct &lock_class_key and 486 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock 487 * validador. 488 * 489 * Use this helper function to initialize a control handler. 490 */ 491 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \ 492 ( \ 493 ({ \ 494 static struct lock_class_key _key; \ 495 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \ 496 &_key, \ 497 KBUILD_BASENAME ":" \ 498 __stringify(__LINE__) ":" \ 499 "(" #hdl ")->_lock"); \ 500 }) \ 501 ) 502 #else 503 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \ 504 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL) 505 #endif 506 507 /** 508 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free 509 * the control list. 510 * @hdl: The control handler. 511 * 512 * Does nothing if @hdl == NULL. 513 */ 514 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); 515 516 /** 517 * v4l2_ctrl_lock() - Helper function to lock the handler 518 * associated with the control. 519 * @ctrl: The control to lock. 520 */ 521 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) 522 { 523 mutex_lock(ctrl->handler->lock); 524 } 525 526 /** 527 * v4l2_ctrl_unlock() - Helper function to unlock the handler 528 * associated with the control. 529 * @ctrl: The control to unlock. 530 */ 531 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) 532 { 533 mutex_unlock(ctrl->handler->lock); 534 } 535 536 /** 537 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging 538 * to the handler to initialize the hardware to the current control values. The 539 * caller is responsible for acquiring the control handler mutex on behalf of 540 * __v4l2_ctrl_handler_setup(). 541 * @hdl: The control handler. 542 * 543 * Button controls will be skipped, as are read-only controls. 544 * 545 * If @hdl == NULL, then this just returns 0. 546 */ 547 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); 548 549 /** 550 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging 551 * to the handler to initialize the hardware to the current control values. 552 * @hdl: The control handler. 553 * 554 * Button controls will be skipped, as are read-only controls. 555 * 556 * If @hdl == NULL, then this just returns 0. 557 */ 558 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); 559 560 /** 561 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler. 562 * @hdl: The control handler. 563 * @prefix: The prefix to use when logging the control values. If the 564 * prefix does not end with a space, then ": " will be added 565 * after the prefix. If @prefix == NULL, then no prefix will be 566 * used. 567 * 568 * For use with VIDIOC_LOG_STATUS. 569 * 570 * Does nothing if @hdl == NULL. 571 */ 572 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, 573 const char *prefix); 574 575 /** 576 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2 577 * control. 578 * 579 * @hdl: The control handler. 580 * @cfg: The control's configuration data. 581 * @priv: The control's driver-specific private data. 582 * 583 * If the &v4l2_ctrl struct could not be allocated then NULL is returned 584 * and @hdl->error is set to the error code (if it wasn't set already). 585 */ 586 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, 587 const struct v4l2_ctrl_config *cfg, 588 void *priv); 589 590 /** 591 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu 592 * control. 593 * 594 * @hdl: The control handler. 595 * @ops: The control ops. 596 * @id: The control ID. 597 * @min: The control's minimum value. 598 * @max: The control's maximum value. 599 * @step: The control's step value 600 * @def: The control's default value. 601 * 602 * If the &v4l2_ctrl struct could not be allocated, or the control 603 * ID is not known, then NULL is returned and @hdl->error is set to the 604 * appropriate error code (if it wasn't set already). 605 * 606 * If @id refers to a menu control, then this function will return NULL. 607 * 608 * Use v4l2_ctrl_new_std_menu() when adding menu controls. 609 */ 610 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, 611 const struct v4l2_ctrl_ops *ops, 612 u32 id, s64 min, s64 max, u64 step, 613 s64 def); 614 615 /** 616 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 617 * menu control. 618 * 619 * @hdl: The control handler. 620 * @ops: The control ops. 621 * @id: The control ID. 622 * @max: The control's maximum value. 623 * @mask: The control's skip mask for menu controls. This makes it 624 * easy to skip menu items that are not valid. If bit X is set, 625 * then menu item X is skipped. Of course, this only works for 626 * menus with <= 64 menu items. There are no menus that come 627 * close to that number, so this is OK. Should we ever need more, 628 * then this will have to be extended to a bit array. 629 * @def: The control's default value. 630 * 631 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value 632 * determines which menu items are to be skipped. 633 * 634 * If @id refers to a non-menu control, then this function will return NULL. 635 */ 636 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, 637 const struct v4l2_ctrl_ops *ops, 638 u32 id, u8 max, u64 mask, u8 def); 639 640 /** 641 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control 642 * with driver specific menu. 643 * 644 * @hdl: The control handler. 645 * @ops: The control ops. 646 * @id: The control ID. 647 * @max: The control's maximum value. 648 * @mask: The control's skip mask for menu controls. This makes it 649 * easy to skip menu items that are not valid. If bit X is set, 650 * then menu item X is skipped. Of course, this only works for 651 * menus with <= 64 menu items. There are no menus that come 652 * close to that number, so this is OK. Should we ever need more, 653 * then this will have to be extended to a bit array. 654 * @def: The control's default value. 655 * @qmenu: The new menu. 656 * 657 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific 658 * menu of this control. 659 * 660 */ 661 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, 662 const struct v4l2_ctrl_ops *ops, 663 u32 id, u8 max, 664 u64 mask, u8 def, 665 const char * const *qmenu); 666 667 /** 668 * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2 669 * compound control. 670 * 671 * @hdl: The control handler. 672 * @ops: The control ops. 673 * @id: The control ID. 674 * @p_def: The control's default value. 675 * 676 * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks 677 * to the @p_def field. 678 * 679 */ 680 struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, 681 const struct v4l2_ctrl_ops *ops, 682 u32 id, 683 const union v4l2_ctrl_ptr p_def); 684 685 /** 686 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 687 * 688 * @hdl: The control handler. 689 * @ops: The control ops. 690 * @id: The control ID. 691 * @max: The control's maximum value. 692 * @def: The control's default value. 693 * @qmenu_int: The control's menu entries. 694 * 695 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally 696 * takes as an argument an array of integers determining the menu items. 697 * 698 * If @id refers to a non-integer-menu control, then this function will 699 * return %NULL. 700 */ 701 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, 702 const struct v4l2_ctrl_ops *ops, 703 u32 id, u8 max, u8 def, 704 const s64 *qmenu_int); 705 706 /** 707 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be 708 * used when adding a control handler. 709 * 710 * @ctrl: pointer to struct &v4l2_ctrl. 711 */ 712 713 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl); 714 715 /** 716 * v4l2_ctrl_add_handler() - Add all controls from handler @add to 717 * handler @hdl. 718 * 719 * @hdl: The control handler. 720 * @add: The control handler whose controls you want to add to 721 * the @hdl control handler. 722 * @filter: This function will filter which controls should be added. 723 * @from_other_dev: If true, then the controls in @add were defined in another 724 * device than @hdl. 725 * 726 * Does nothing if either of the two handlers is a NULL pointer. 727 * If @filter is NULL, then all controls are added. Otherwise only those 728 * controls for which @filter returns true will be added. 729 * In case of an error @hdl->error will be set to the error code (if it 730 * wasn't set already). 731 */ 732 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, 733 struct v4l2_ctrl_handler *add, 734 v4l2_ctrl_filter filter, 735 bool from_other_dev); 736 737 /** 738 * v4l2_ctrl_radio_filter() - Standard filter for radio controls. 739 * 740 * @ctrl: The control that is filtered. 741 * 742 * This will return true for any controls that are valid for radio device 743 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM 744 * transmitter class controls. 745 * 746 * This function is to be used with v4l2_ctrl_add_handler(). 747 */ 748 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl); 749 750 /** 751 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging 752 * to that cluster. 753 * 754 * @ncontrols: The number of controls in this cluster. 755 * @controls: The cluster control array of size @ncontrols. 756 */ 757 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls); 758 759 760 /** 761 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging 762 * to that cluster and set it up for autofoo/foo-type handling. 763 * 764 * @ncontrols: The number of controls in this cluster. 765 * @controls: The cluster control array of size @ncontrols. The first control 766 * must be the 'auto' control (e.g. autogain, autoexposure, etc.) 767 * @manual_val: The value for the first control in the cluster that equals the 768 * manual setting. 769 * @set_volatile: If true, then all controls except the first auto control will 770 * be volatile. 771 * 772 * Use for control groups where one control selects some automatic feature and 773 * the other controls are only active whenever the automatic feature is turned 774 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs 775 * red and blue balance, etc. 776 * 777 * The behavior of such controls is as follows: 778 * 779 * When the autofoo control is set to automatic, then any manual controls 780 * are set to inactive and any reads will call g_volatile_ctrl (if the control 781 * was marked volatile). 782 * 783 * When the autofoo control is set to manual, then any manual controls will 784 * be marked active, and any reads will just return the current value without 785 * going through g_volatile_ctrl. 786 * 787 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag 788 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s) 789 * if autofoo is in auto mode. 790 */ 791 void v4l2_ctrl_auto_cluster(unsigned int ncontrols, 792 struct v4l2_ctrl **controls, 793 u8 manual_val, bool set_volatile); 794 795 796 /** 797 * v4l2_ctrl_find() - Find a control with the given ID. 798 * 799 * @hdl: The control handler. 800 * @id: The control ID to find. 801 * 802 * If @hdl == NULL this will return NULL as well. Will lock the handler so 803 * do not use from inside &v4l2_ctrl_ops. 804 */ 805 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); 806 807 /** 808 * v4l2_ctrl_activate() - Make the control active or inactive. 809 * @ctrl: The control to (de)activate. 810 * @active: True if the control should become active. 811 * 812 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically. 813 * Does nothing if @ctrl == NULL. 814 * This will usually be called from within the s_ctrl op. 815 * The V4L2_EVENT_CTRL event will be generated afterwards. 816 * 817 * This function assumes that the control handler is locked. 818 */ 819 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active); 820 821 /** 822 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab. 823 * 824 * @ctrl: The control to (de)activate. 825 * @grabbed: True if the control should become grabbed. 826 * 827 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. 828 * Does nothing if @ctrl == NULL. 829 * The V4L2_EVENT_CTRL event will be generated afterwards. 830 * This will usually be called when starting or stopping streaming in the 831 * driver. 832 * 833 * This function assumes that the control handler is locked by the caller. 834 */ 835 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); 836 837 /** 838 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. 839 * 840 * @ctrl: The control to (de)activate. 841 * @grabbed: True if the control should become grabbed. 842 * 843 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. 844 * Does nothing if @ctrl == NULL. 845 * The V4L2_EVENT_CTRL event will be generated afterwards. 846 * This will usually be called when starting or stopping streaming in the 847 * driver. 848 * 849 * This function assumes that the control handler is not locked and will 850 * take the lock itself. 851 */ 852 static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) 853 { 854 if (!ctrl) 855 return; 856 857 v4l2_ctrl_lock(ctrl); 858 __v4l2_ctrl_grab(ctrl, grabbed); 859 v4l2_ctrl_unlock(ctrl); 860 } 861 862 /** 863 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range() 864 * 865 * @ctrl: The control to update. 866 * @min: The control's minimum value. 867 * @max: The control's maximum value. 868 * @step: The control's step value 869 * @def: The control's default value. 870 * 871 * Update the range of a control on the fly. This works for control types 872 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 873 * @step value is interpreted as a menu_skip_mask. 874 * 875 * An error is returned if one of the range arguments is invalid for this 876 * control type. 877 * 878 * The caller is responsible for acquiring the control handler mutex on behalf 879 * of __v4l2_ctrl_modify_range(). 880 */ 881 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 882 s64 min, s64 max, u64 step, s64 def); 883 884 /** 885 * v4l2_ctrl_modify_range() - Update the range of a control. 886 * 887 * @ctrl: The control to update. 888 * @min: The control's minimum value. 889 * @max: The control's maximum value. 890 * @step: The control's step value 891 * @def: The control's default value. 892 * 893 * Update the range of a control on the fly. This works for control types 894 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 895 * @step value is interpreted as a menu_skip_mask. 896 * 897 * An error is returned if one of the range arguments is invalid for this 898 * control type. 899 * 900 * This function assumes that the control handler is not locked and will 901 * take the lock itself. 902 */ 903 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 904 s64 min, s64 max, u64 step, s64 def) 905 { 906 int rval; 907 908 v4l2_ctrl_lock(ctrl); 909 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def); 910 v4l2_ctrl_unlock(ctrl); 911 912 return rval; 913 } 914 915 /** 916 * v4l2_ctrl_notify() - Function to set a notify callback for a control. 917 * 918 * @ctrl: The control. 919 * @notify: The callback function. 920 * @priv: The callback private handle, passed as argument to the callback. 921 * 922 * This function sets a callback function for the control. If @ctrl is NULL, 923 * then it will do nothing. If @notify is NULL, then the notify callback will 924 * be removed. 925 * 926 * There can be only one notify. If another already exists, then a WARN_ON 927 * will be issued and the function will do nothing. 928 */ 929 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, 930 void *priv); 931 932 /** 933 * v4l2_ctrl_get_name() - Get the name of the control 934 * 935 * @id: The control ID. 936 * 937 * This function returns the name of the given control ID or NULL if it isn't 938 * a known control. 939 */ 940 const char *v4l2_ctrl_get_name(u32 id); 941 942 /** 943 * v4l2_ctrl_get_menu() - Get the menu string array of the control 944 * 945 * @id: The control ID. 946 * 947 * This function returns the NULL-terminated menu string array name of the 948 * given control ID or NULL if it isn't a known menu control. 949 */ 950 const char * const *v4l2_ctrl_get_menu(u32 id); 951 952 /** 953 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control 954 * 955 * @id: The control ID. 956 * @len: The size of the integer array. 957 * 958 * This function returns the integer array of the given control ID or NULL if it 959 * if it isn't a known integer menu control. 960 */ 961 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len); 962 963 /** 964 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from 965 * within a driver. 966 * 967 * @ctrl: The control. 968 * 969 * This returns the control's value safely by going through the control 970 * framework. This function will lock the control's handler, so it cannot be 971 * used from within the &v4l2_ctrl_ops functions. 972 * 973 * This function is for integer type controls only. 974 */ 975 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); 976 977 /** 978 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl(). 979 * 980 * @ctrl: The control. 981 * @val: The new value. 982 * 983 * This sets the control's new value safely by going through the control 984 * framework. This function assumes the control's handler is already locked, 985 * allowing it to be used from within the &v4l2_ctrl_ops functions. 986 * 987 * This function is for integer type controls only. 988 */ 989 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); 990 991 /** 992 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from 993 * within a driver. 994 * @ctrl: The control. 995 * @val: The new value. 996 * 997 * This sets the control's new value safely by going through the control 998 * framework. This function will lock the control's handler, so it cannot be 999 * used from within the &v4l2_ctrl_ops functions. 1000 * 1001 * This function is for integer type controls only. 1002 */ 1003 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) 1004 { 1005 int rval; 1006 1007 v4l2_ctrl_lock(ctrl); 1008 rval = __v4l2_ctrl_s_ctrl(ctrl, val); 1009 v4l2_ctrl_unlock(ctrl); 1010 1011 return rval; 1012 } 1013 1014 /** 1015 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value 1016 * from within a driver. 1017 * 1018 * @ctrl: The control. 1019 * 1020 * This returns the control's value safely by going through the control 1021 * framework. This function will lock the control's handler, so it cannot be 1022 * used from within the &v4l2_ctrl_ops functions. 1023 * 1024 * This function is for 64-bit integer type controls only. 1025 */ 1026 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl); 1027 1028 /** 1029 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64(). 1030 * 1031 * @ctrl: The control. 1032 * @val: The new value. 1033 * 1034 * This sets the control's new value safely by going through the control 1035 * framework. This function assumes the control's handler is already locked, 1036 * allowing it to be used from within the &v4l2_ctrl_ops functions. 1037 * 1038 * This function is for 64-bit integer type controls only. 1039 */ 1040 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val); 1041 1042 /** 1043 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value 1044 * from within a driver. 1045 * 1046 * @ctrl: The control. 1047 * @val: The new value. 1048 * 1049 * This sets the control's new value safely by going through the control 1050 * framework. This function will lock the control's handler, so it cannot be 1051 * used from within the &v4l2_ctrl_ops functions. 1052 * 1053 * This function is for 64-bit integer type controls only. 1054 */ 1055 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) 1056 { 1057 int rval; 1058 1059 v4l2_ctrl_lock(ctrl); 1060 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val); 1061 v4l2_ctrl_unlock(ctrl); 1062 1063 return rval; 1064 } 1065 1066 /** 1067 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string(). 1068 * 1069 * @ctrl: The control. 1070 * @s: The new string. 1071 * 1072 * This sets the control's new string safely by going through the control 1073 * framework. This function assumes the control's handler is already locked, 1074 * allowing it to be used from within the &v4l2_ctrl_ops functions. 1075 * 1076 * This function is for string type controls only. 1077 */ 1078 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s); 1079 1080 /** 1081 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value 1082 * from within a driver. 1083 * 1084 * @ctrl: The control. 1085 * @s: The new string. 1086 * 1087 * This sets the control's new string safely by going through the control 1088 * framework. This function will lock the control's handler, so it cannot be 1089 * used from within the &v4l2_ctrl_ops functions. 1090 * 1091 * This function is for string type controls only. 1092 */ 1093 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) 1094 { 1095 int rval; 1096 1097 v4l2_ctrl_lock(ctrl); 1098 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s); 1099 v4l2_ctrl_unlock(ctrl); 1100 1101 return rval; 1102 } 1103 1104 /** 1105 * __v4l2_ctrl_s_ctrl_area() - Unlocked variant of v4l2_ctrl_s_ctrl_area(). 1106 * 1107 * @ctrl: The control. 1108 * @area: The new area. 1109 * 1110 * This sets the control's new area safely by going through the control 1111 * framework. This function assumes the control's handler is already locked, 1112 * allowing it to be used from within the &v4l2_ctrl_ops functions. 1113 * 1114 * This function is for area type controls only. 1115 */ 1116 int __v4l2_ctrl_s_ctrl_area(struct v4l2_ctrl *ctrl, 1117 const struct v4l2_area *area); 1118 1119 /** 1120 * v4l2_ctrl_s_ctrl_area() - Helper function to set a control's area value 1121 * from within a driver. 1122 * 1123 * @ctrl: The control. 1124 * @area: The new area. 1125 * 1126 * This sets the control's new area safely by going through the control 1127 * framework. This function will lock the control's handler, so it cannot be 1128 * used from within the &v4l2_ctrl_ops functions. 1129 * 1130 * This function is for area type controls only. 1131 */ 1132 static inline int v4l2_ctrl_s_ctrl_area(struct v4l2_ctrl *ctrl, 1133 const struct v4l2_area *area) 1134 { 1135 int rval; 1136 1137 v4l2_ctrl_lock(ctrl); 1138 rval = __v4l2_ctrl_s_ctrl_area(ctrl, area); 1139 v4l2_ctrl_unlock(ctrl); 1140 1141 return rval; 1142 } 1143 1144 /* Internal helper functions that deal with control events. */ 1145 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops; 1146 1147 /** 1148 * v4l2_ctrl_replace - Function to be used as a callback to 1149 * &struct v4l2_subscribed_event_ops replace\(\) 1150 * 1151 * @old: pointer to struct &v4l2_event with the reported 1152 * event; 1153 * @new: pointer to struct &v4l2_event with the modified 1154 * event; 1155 */ 1156 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new); 1157 1158 /** 1159 * v4l2_ctrl_merge - Function to be used as a callback to 1160 * &struct v4l2_subscribed_event_ops merge(\) 1161 * 1162 * @old: pointer to struct &v4l2_event with the reported 1163 * event; 1164 * @new: pointer to struct &v4l2_event with the merged 1165 * event; 1166 */ 1167 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new); 1168 1169 /** 1170 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl 1171 * 1172 * @file: pointer to struct file 1173 * @fh: unused. Kept just to be compatible to the arguments expected by 1174 * &struct v4l2_ioctl_ops.vidioc_log_status. 1175 * 1176 * Can be used as a vidioc_log_status function that just dumps all controls 1177 * associated with the filehandle. 1178 */ 1179 int v4l2_ctrl_log_status(struct file *file, void *fh); 1180 1181 /** 1182 * v4l2_ctrl_subscribe_event - Subscribes to an event 1183 * 1184 * 1185 * @fh: pointer to struct v4l2_fh 1186 * @sub: pointer to &struct v4l2_event_subscription 1187 * 1188 * Can be used as a vidioc_subscribe_event function that just subscribes 1189 * control events. 1190 */ 1191 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh, 1192 const struct v4l2_event_subscription *sub); 1193 1194 /** 1195 * v4l2_ctrl_poll - function to be used as a callback to the poll() 1196 * That just polls for control events. 1197 * 1198 * @file: pointer to struct file 1199 * @wait: pointer to struct poll_table_struct 1200 */ 1201 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait); 1202 1203 /** 1204 * v4l2_ctrl_request_setup - helper function to apply control values in a request 1205 * 1206 * @req: The request 1207 * @parent: The parent control handler ('priv' in media_request_object_find()) 1208 * 1209 * This is a helper function to call the control handler's s_ctrl callback with 1210 * the control values contained in the request. Do note that this approach of 1211 * applying control values in a request is only applicable to memory-to-memory 1212 * devices. 1213 */ 1214 int v4l2_ctrl_request_setup(struct media_request *req, 1215 struct v4l2_ctrl_handler *parent); 1216 1217 /** 1218 * v4l2_ctrl_request_complete - Complete a control handler request object 1219 * 1220 * @req: The request 1221 * @parent: The parent control handler ('priv' in media_request_object_find()) 1222 * 1223 * This function is to be called on each control handler that may have had a 1224 * request object associated with it, i.e. control handlers of a driver that 1225 * supports requests. 1226 * 1227 * The function first obtains the values of any volatile controls in the control 1228 * handler and attach them to the request. Then, the function completes the 1229 * request object. 1230 */ 1231 void v4l2_ctrl_request_complete(struct media_request *req, 1232 struct v4l2_ctrl_handler *parent); 1233 1234 /** 1235 * v4l2_ctrl_request_hdl_find - Find the control handler in the request 1236 * 1237 * @req: The request 1238 * @parent: The parent control handler ('priv' in media_request_object_find()) 1239 * 1240 * This function finds the control handler in the request. It may return 1241 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl() 1242 * with the returned handler pointer. 1243 * 1244 * If the request is not in state VALIDATING or QUEUED, then this function 1245 * will always return NULL. 1246 * 1247 * Note that in state VALIDATING the req_queue_mutex is held, so 1248 * no objects can be added or deleted from the request. 1249 * 1250 * In state QUEUED it is the driver that will have to ensure this. 1251 */ 1252 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req, 1253 struct v4l2_ctrl_handler *parent); 1254 1255 /** 1256 * v4l2_ctrl_request_hdl_put - Put the control handler 1257 * 1258 * @hdl: Put this control handler 1259 * 1260 * This function released the control handler previously obtained from' 1261 * v4l2_ctrl_request_hdl_find(). 1262 */ 1263 static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl) 1264 { 1265 if (hdl) 1266 media_request_object_put(&hdl->req_obj); 1267 } 1268 1269 /** 1270 * v4l2_ctrl_request_ctrl_find() - Find a control with the given ID. 1271 * 1272 * @hdl: The control handler from the request. 1273 * @id: The ID of the control to find. 1274 * 1275 * This function returns a pointer to the control if this control is 1276 * part of the request or NULL otherwise. 1277 */ 1278 struct v4l2_ctrl * 1279 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); 1280 1281 /* Helpers for ioctl_ops */ 1282 1283 /** 1284 * v4l2_queryctrl - Helper function to implement 1285 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl 1286 * 1287 * @hdl: pointer to &struct v4l2_ctrl_handler 1288 * @qc: pointer to &struct v4l2_queryctrl 1289 * 1290 * If hdl == NULL then they will all return -EINVAL. 1291 */ 1292 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc); 1293 1294 /** 1295 * v4l2_query_ext_ctrl - Helper function to implement 1296 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl 1297 * 1298 * @hdl: pointer to &struct v4l2_ctrl_handler 1299 * @qc: pointer to &struct v4l2_query_ext_ctrl 1300 * 1301 * If hdl == NULL then they will all return -EINVAL. 1302 */ 1303 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, 1304 struct v4l2_query_ext_ctrl *qc); 1305 1306 /** 1307 * v4l2_querymenu - Helper function to implement 1308 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl 1309 * 1310 * @hdl: pointer to &struct v4l2_ctrl_handler 1311 * @qm: pointer to &struct v4l2_querymenu 1312 * 1313 * If hdl == NULL then they will all return -EINVAL. 1314 */ 1315 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm); 1316 1317 /** 1318 * v4l2_g_ctrl - Helper function to implement 1319 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl 1320 * 1321 * @hdl: pointer to &struct v4l2_ctrl_handler 1322 * @ctrl: pointer to &struct v4l2_control 1323 * 1324 * If hdl == NULL then they will all return -EINVAL. 1325 */ 1326 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); 1327 1328 /** 1329 * v4l2_s_ctrl - Helper function to implement 1330 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl 1331 * 1332 * @fh: pointer to &struct v4l2_fh 1333 * @hdl: pointer to &struct v4l2_ctrl_handler 1334 * 1335 * @ctrl: pointer to &struct v4l2_control 1336 * 1337 * If hdl == NULL then they will all return -EINVAL. 1338 */ 1339 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, 1340 struct v4l2_control *ctrl); 1341 1342 /** 1343 * v4l2_g_ext_ctrls - Helper function to implement 1344 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl 1345 * 1346 * @hdl: pointer to &struct v4l2_ctrl_handler 1347 * @vdev: pointer to &struct video_device 1348 * @mdev: pointer to &struct media_device 1349 * @c: pointer to &struct v4l2_ext_controls 1350 * 1351 * If hdl == NULL then they will all return -EINVAL. 1352 */ 1353 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev, 1354 struct media_device *mdev, struct v4l2_ext_controls *c); 1355 1356 /** 1357 * v4l2_try_ext_ctrls - Helper function to implement 1358 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl 1359 * 1360 * @hdl: pointer to &struct v4l2_ctrl_handler 1361 * @vdev: pointer to &struct video_device 1362 * @mdev: pointer to &struct media_device 1363 * @c: pointer to &struct v4l2_ext_controls 1364 * 1365 * If hdl == NULL then they will all return -EINVAL. 1366 */ 1367 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, 1368 struct video_device *vdev, 1369 struct media_device *mdev, 1370 struct v4l2_ext_controls *c); 1371 1372 /** 1373 * v4l2_s_ext_ctrls - Helper function to implement 1374 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl 1375 * 1376 * @fh: pointer to &struct v4l2_fh 1377 * @hdl: pointer to &struct v4l2_ctrl_handler 1378 * @vdev: pointer to &struct video_device 1379 * @mdev: pointer to &struct media_device 1380 * @c: pointer to &struct v4l2_ext_controls 1381 * 1382 * If hdl == NULL then they will all return -EINVAL. 1383 */ 1384 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, 1385 struct video_device *vdev, 1386 struct media_device *mdev, 1387 struct v4l2_ext_controls *c); 1388 1389 /** 1390 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement 1391 * as a &struct v4l2_subdev_core_ops subscribe_event function 1392 * that just subscribes control events. 1393 * 1394 * @sd: pointer to &struct v4l2_subdev 1395 * @fh: pointer to &struct v4l2_fh 1396 * @sub: pointer to &struct v4l2_event_subscription 1397 */ 1398 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, 1399 struct v4l2_event_subscription *sub); 1400 1401 /** 1402 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control 1403 * handler. 1404 * 1405 * @sd: pointer to &struct v4l2_subdev 1406 */ 1407 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd); 1408 1409 #endif 1410