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