![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-or-later */ 0002 /* 0003 * V4L2 controls support header. 0004 * 0005 * Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl> 0006 */ 0007 0008 #ifndef _V4L2_CTRLS_H 0009 #define _V4L2_CTRLS_H 0010 0011 #include <linux/list.h> 0012 #include <linux/mutex.h> 0013 #include <linux/videodev2.h> 0014 #include <media/media-request.h> 0015 0016 /* forward references */ 0017 struct file; 0018 struct poll_table_struct; 0019 struct v4l2_ctrl; 0020 struct v4l2_ctrl_handler; 0021 struct v4l2_ctrl_helper; 0022 struct v4l2_fh; 0023 struct v4l2_fwnode_device_properties; 0024 struct v4l2_subdev; 0025 struct v4l2_subscribed_event; 0026 struct video_device; 0027 0028 /** 0029 * union v4l2_ctrl_ptr - A pointer to a control value. 0030 * @p_s32: Pointer to a 32-bit signed value. 0031 * @p_s64: Pointer to a 64-bit signed value. 0032 * @p_u8: Pointer to a 8-bit unsigned value. 0033 * @p_u16: Pointer to a 16-bit unsigned value. 0034 * @p_u32: Pointer to a 32-bit unsigned value. 0035 * @p_char: Pointer to a string. 0036 * @p_mpeg2_sequence: Pointer to a MPEG2 sequence structure. 0037 * @p_mpeg2_picture: Pointer to a MPEG2 picture structure. 0038 * @p_mpeg2_quantisation: Pointer to a MPEG2 quantisation data structure. 0039 * @p_fwht_params: Pointer to a FWHT stateless parameters structure. 0040 * @p_h264_sps: Pointer to a struct v4l2_ctrl_h264_sps. 0041 * @p_h264_pps: Pointer to a struct v4l2_ctrl_h264_pps. 0042 * @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix. 0043 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params. 0044 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params. 0045 * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights. 0046 * @p_vp8_frame: Pointer to a VP8 frame params structure. 0047 * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure. 0048 * @p_vp9_frame: Pointer to a VP9 frame params structure. 0049 * @p_hevc_sps: Pointer to an HEVC sequence parameter set structure. 0050 * @p_hevc_pps: Pointer to an HEVC picture parameter set structure. 0051 * @p_hevc_slice_params: Pointer to an HEVC slice parameters structure. 0052 * @p_hdr10_cll: Pointer to an HDR10 Content Light Level structure. 0053 * @p_hdr10_mastering: Pointer to an HDR10 Mastering Display structure. 0054 * @p_area: Pointer to an area. 0055 * @p: Pointer to a compound value. 0056 * @p_const: Pointer to a constant compound value. 0057 */ 0058 union v4l2_ctrl_ptr { 0059 s32 *p_s32; 0060 s64 *p_s64; 0061 u8 *p_u8; 0062 u16 *p_u16; 0063 u32 *p_u32; 0064 char *p_char; 0065 struct v4l2_ctrl_mpeg2_sequence *p_mpeg2_sequence; 0066 struct v4l2_ctrl_mpeg2_picture *p_mpeg2_picture; 0067 struct v4l2_ctrl_mpeg2_quantisation *p_mpeg2_quantisation; 0068 struct v4l2_ctrl_fwht_params *p_fwht_params; 0069 struct v4l2_ctrl_h264_sps *p_h264_sps; 0070 struct v4l2_ctrl_h264_pps *p_h264_pps; 0071 struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix; 0072 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params; 0073 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params; 0074 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights; 0075 struct v4l2_ctrl_vp8_frame *p_vp8_frame; 0076 struct v4l2_ctrl_hevc_sps *p_hevc_sps; 0077 struct v4l2_ctrl_hevc_pps *p_hevc_pps; 0078 struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params; 0079 struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs; 0080 struct v4l2_ctrl_vp9_frame *p_vp9_frame; 0081 struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll; 0082 struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering; 0083 struct v4l2_area *p_area; 0084 void *p; 0085 const void *p_const; 0086 }; 0087 0088 /** 0089 * v4l2_ctrl_ptr_create() - Helper function to return a v4l2_ctrl_ptr from a 0090 * void pointer 0091 * @ptr: The void pointer 0092 */ 0093 static inline union v4l2_ctrl_ptr v4l2_ctrl_ptr_create(void *ptr) 0094 { 0095 union v4l2_ctrl_ptr p = { .p = ptr }; 0096 0097 return p; 0098 } 0099 0100 /** 0101 * struct v4l2_ctrl_ops - The control operations that the driver has to provide. 0102 * 0103 * @g_volatile_ctrl: Get a new value for this control. Generally only relevant 0104 * for volatile (and usually read-only) controls such as a control 0105 * that returns the current signal strength which changes 0106 * continuously. 0107 * If not set, then the currently cached value will be returned. 0108 * @try_ctrl: Test whether the control's value is valid. Only relevant when 0109 * the usual min/max/step checks are not sufficient. 0110 * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The 0111 * ctrl->handler->lock is held when these ops are called, so no 0112 * one else can access controls owned by that handler. 0113 */ 0114 struct v4l2_ctrl_ops { 0115 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl); 0116 int (*try_ctrl)(struct v4l2_ctrl *ctrl); 0117 int (*s_ctrl)(struct v4l2_ctrl *ctrl); 0118 }; 0119 0120 /** 0121 * struct v4l2_ctrl_type_ops - The control type operations that the driver 0122 * has to provide. 0123 * 0124 * @equal: return true if both values are equal. 0125 * @init: initialize the value. 0126 * @log: log the value. 0127 * @validate: validate the value. Return 0 on success and a negative value 0128 * otherwise. 0129 */ 0130 struct v4l2_ctrl_type_ops { 0131 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx, 0132 union v4l2_ctrl_ptr ptr1, 0133 union v4l2_ctrl_ptr ptr2); 0134 void (*init)(const struct v4l2_ctrl *ctrl, u32 idx, 0135 union v4l2_ctrl_ptr ptr); 0136 void (*log)(const struct v4l2_ctrl *ctrl); 0137 int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx, 0138 union v4l2_ctrl_ptr ptr); 0139 }; 0140 0141 /** 0142 * typedef v4l2_ctrl_notify_fnc - typedef for a notify argument with a function 0143 * that should be called when a control value has changed. 0144 * 0145 * @ctrl: pointer to struct &v4l2_ctrl 0146 * @priv: control private data 0147 * 0148 * This typedef definition is used as an argument to v4l2_ctrl_notify() 0149 * and as an argument at struct &v4l2_ctrl_handler. 0150 */ 0151 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); 0152 0153 /** 0154 * struct v4l2_ctrl - The control structure. 0155 * 0156 * @node: The list node. 0157 * @ev_subs: The list of control event subscriptions. 0158 * @handler: The handler that owns the control. 0159 * @cluster: Point to start of cluster array. 0160 * @ncontrols: Number of controls in cluster array. 0161 * @done: Internal flag: set for each processed control. 0162 * @is_new: Set when the user specified a new value for this control. It 0163 * is also set when called from v4l2_ctrl_handler_setup(). Drivers 0164 * should never set this flag. 0165 * @has_changed: Set when the current value differs from the new value. Drivers 0166 * should never use this flag. 0167 * @is_private: If set, then this control is private to its handler and it 0168 * will not be added to any other handlers. Drivers can set 0169 * this flag. 0170 * @is_auto: If set, then this control selects whether the other cluster 0171 * members are in 'automatic' mode or 'manual' mode. This is 0172 * used for autogain/gain type clusters. Drivers should never 0173 * set this flag directly. 0174 * @is_int: If set, then this control has a simple integer value (i.e. it 0175 * uses ctrl->val). 0176 * @is_string: If set, then this control has type %V4L2_CTRL_TYPE_STRING. 0177 * @is_ptr: If set, then this control is an array and/or has type >= 0178 * %V4L2_CTRL_COMPOUND_TYPES 0179 * and/or has type %V4L2_CTRL_TYPE_STRING. In other words, &struct 0180 * v4l2_ext_control uses field p to point to the data. 0181 * @is_array: If set, then this control contains an N-dimensional array. 0182 * @is_dyn_array: If set, then this control contains a dynamically sized 1-dimensional array. 0183 * If this is set, then @is_array is also set. 0184 * @has_volatiles: If set, then one or more members of the cluster are volatile. 0185 * Drivers should never touch this flag. 0186 * @call_notify: If set, then call the handler's notify function whenever the 0187 * control's value changes. 0188 * @manual_mode_value: If the is_auto flag is set, then this is the value 0189 * of the auto control that determines if that control is in 0190 * manual mode. So if the value of the auto control equals this 0191 * value, then the whole cluster is in manual mode. Drivers should 0192 * never set this flag directly. 0193 * @ops: The control ops. 0194 * @type_ops: The control type ops. 0195 * @id: The control ID. 0196 * @name: The control name. 0197 * @type: The control type. 0198 * @minimum: The control's minimum value. 0199 * @maximum: The control's maximum value. 0200 * @default_value: The control's default value. 0201 * @step: The control's step value for non-menu controls. 0202 * @elems: The number of elements in the N-dimensional array. 0203 * @elem_size: The size in bytes of the control. 0204 * @new_elems: The number of elements in p_new. This is the same as @elems, 0205 * except for dynamic arrays. In that case it is in the range of 0206 * 1 to @p_dyn_alloc_elems. 0207 * @dims: The size of each dimension. 0208 * @nr_of_dims:The number of dimensions in @dims. 0209 * @menu_skip_mask: The control's skip mask for menu controls. This makes it 0210 * easy to skip menu items that are not valid. If bit X is set, 0211 * then menu item X is skipped. Of course, this only works for 0212 * menus with <= 32 menu items. There are no menus that come 0213 * close to that number, so this is OK. Should we ever need more, 0214 * then this will have to be extended to a u64 or a bit array. 0215 * @qmenu: A const char * array for all menu items. Array entries that are 0216 * empty strings ("") correspond to non-existing menu items (this 0217 * is in addition to the menu_skip_mask above). The last entry 0218 * must be NULL. 0219 * Used only if the @type is %V4L2_CTRL_TYPE_MENU. 0220 * @qmenu_int: A 64-bit integer array for with integer menu items. 0221 * The size of array must be equal to the menu size, e. g.: 0222 * :math:`ceil(\frac{maximum - minimum}{step}) + 1`. 0223 * Used only if the @type is %V4L2_CTRL_TYPE_INTEGER_MENU. 0224 * @flags: The control's flags. 0225 * @priv: The control's private pointer. For use by the driver. It is 0226 * untouched by the control framework. Note that this pointer is 0227 * not freed when the control is deleted. Should this be needed 0228 * then a new internal bitfield can be added to tell the framework 0229 * to free this pointer. 0230 * @p_dyn: Pointer to the dynamically allocated array. Only valid if 0231 * @is_dyn_array is true. 0232 * @p_dyn_alloc_elems: The number of elements in the dynamically allocated 0233 * array for both the cur and new values. So @p_dyn is actually 0234 * sized for 2 * @p_dyn_alloc_elems * @elem_size. Only valid if 0235 * @is_dyn_array is true. 0236 * @cur: Structure to store the current value. 0237 * @cur.val: The control's current value, if the @type is represented via 0238 * a u32 integer (see &enum v4l2_ctrl_type). 0239 * @val: The control's new s32 value. 0240 * @p_def: The control's default value represented via a union which 0241 * provides a standard way of accessing control types 0242 * through a pointer (for compound controls only). 0243 * @p_cur: The control's current value represented via a union which 0244 * provides a standard way of accessing control types 0245 * through a pointer. 0246 * @p_new: The control's new value represented via a union which provides 0247 * a standard way of accessing control types 0248 * through a pointer. 0249 */ 0250 struct v4l2_ctrl { 0251 /* Administrative fields */ 0252 struct list_head node; 0253 struct list_head ev_subs; 0254 struct v4l2_ctrl_handler *handler; 0255 struct v4l2_ctrl **cluster; 0256 unsigned int ncontrols; 0257 0258 unsigned int done:1; 0259 0260 unsigned int is_new:1; 0261 unsigned int has_changed:1; 0262 unsigned int is_private:1; 0263 unsigned int is_auto:1; 0264 unsigned int is_int:1; 0265 unsigned int is_string:1; 0266 unsigned int is_ptr:1; 0267 unsigned int is_array:1; 0268 unsigned int is_dyn_array:1; 0269 unsigned int has_volatiles:1; 0270 unsigned int call_notify:1; 0271 unsigned int manual_mode_value:8; 0272 0273 const struct v4l2_ctrl_ops *ops; 0274 const struct v4l2_ctrl_type_ops *type_ops; 0275 u32 id; 0276 const char *name; 0277 enum v4l2_ctrl_type type; 0278 s64 minimum, maximum, default_value; 0279 u32 elems; 0280 u32 elem_size; 0281 u32 new_elems; 0282 u32 dims[V4L2_CTRL_MAX_DIMS]; 0283 u32 nr_of_dims; 0284 union { 0285 u64 step; 0286 u64 menu_skip_mask; 0287 }; 0288 union { 0289 const char * const *qmenu; 0290 const s64 *qmenu_int; 0291 }; 0292 unsigned long flags; 0293 void *priv; 0294 void *p_dyn; 0295 u32 p_dyn_alloc_elems; 0296 s32 val; 0297 struct { 0298 s32 val; 0299 } cur; 0300 0301 union v4l2_ctrl_ptr p_def; 0302 union v4l2_ctrl_ptr p_new; 0303 union v4l2_ctrl_ptr p_cur; 0304 }; 0305 0306 /** 0307 * struct v4l2_ctrl_ref - The control reference. 0308 * 0309 * @node: List node for the sorted list. 0310 * @next: Single-link list node for the hash. 0311 * @ctrl: The actual control information. 0312 * @helper: Pointer to helper struct. Used internally in 0313 * ``prepare_ext_ctrls`` function at ``v4l2-ctrl.c``. 0314 * @from_other_dev: If true, then @ctrl was defined in another 0315 * device than the &struct v4l2_ctrl_handler. 0316 * @req_done: Internal flag: if the control handler containing this control 0317 * reference is bound to a media request, then this is set when 0318 * the control has been applied. This prevents applying controls 0319 * from a cluster with multiple controls twice (when the first 0320 * control of a cluster is applied, they all are). 0321 * @p_req_valid: If set, then p_req contains the control value for the request. 0322 * @p_req_dyn_enomem: If set, then p_req is invalid since allocating space for 0323 * a dynamic array failed. Attempting to read this value shall 0324 * result in ENOMEM. Only valid if ctrl->is_dyn_array is true. 0325 * @p_req_dyn_alloc_elems: The number of elements allocated for the dynamic 0326 * array. Only valid if @p_req_valid and ctrl->is_dyn_array are 0327 * true. 0328 * @p_req_elems: The number of elements in @p_req. This is the same as 0329 * ctrl->elems, except for dynamic arrays. In that case it is in 0330 * the range of 1 to @p_req_dyn_alloc_elems. Only valid if 0331 * @p_req_valid is true. 0332 * @p_req: If the control handler containing this control reference 0333 * is bound to a media request, then this points to the 0334 * value of the control that must be applied when the request 0335 * is executed, or to the value of the control at the time 0336 * that the request was completed. If @p_req_valid is false, 0337 * then this control was never set for this request and the 0338 * control will not be updated when this request is applied. 0339 * 0340 * Each control handler has a list of these refs. The list_head is used to 0341 * keep a sorted-by-control-ID list of all controls, while the next pointer 0342 * is used to link the control in the hash's bucket. 0343 */ 0344 struct v4l2_ctrl_ref { 0345 struct list_head node; 0346 struct v4l2_ctrl_ref *next; 0347 struct v4l2_ctrl *ctrl; 0348 struct v4l2_ctrl_helper *helper; 0349 bool from_other_dev; 0350 bool req_done; 0351 bool p_req_valid; 0352 bool p_req_dyn_enomem; 0353 u32 p_req_dyn_alloc_elems; 0354 u32 p_req_elems; 0355 union v4l2_ctrl_ptr p_req; 0356 }; 0357 0358 /** 0359 * struct v4l2_ctrl_handler - The control handler keeps track of all the 0360 * controls: both the controls owned by the handler and those inherited 0361 * from other handlers. 0362 * 0363 * @_lock: Default for "lock". 0364 * @lock: Lock to control access to this handler and its controls. 0365 * May be replaced by the user right after init. 0366 * @ctrls: The list of controls owned by this handler. 0367 * @ctrl_refs: The list of control references. 0368 * @cached: The last found control reference. It is common that the same 0369 * control is needed multiple times, so this is a simple 0370 * optimization. 0371 * @buckets: Buckets for the hashing. Allows for quick control lookup. 0372 * @notify: A notify callback that is called whenever the control changes 0373 * value. 0374 * Note that the handler's lock is held when the notify function 0375 * is called! 0376 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback. 0377 * @nr_of_buckets: Total number of buckets in the array. 0378 * @error: The error code of the first failed control addition. 0379 * @request_is_queued: True if the request was queued. 0380 * @requests: List to keep track of open control handler request objects. 0381 * For the parent control handler (@req_obj.ops == NULL) this 0382 * is the list header. When the parent control handler is 0383 * removed, it has to unbind and put all these requests since 0384 * they refer to the parent. 0385 * @requests_queued: List of the queued requests. This determines the order 0386 * in which these controls are applied. Once the request is 0387 * completed it is removed from this list. 0388 * @req_obj: The &struct media_request_object, used to link into a 0389 * &struct media_request. This request object has a refcount. 0390 */ 0391 struct v4l2_ctrl_handler { 0392 struct mutex _lock; 0393 struct mutex *lock; 0394 struct list_head ctrls; 0395 struct list_head ctrl_refs; 0396 struct v4l2_ctrl_ref *cached; 0397 struct v4l2_ctrl_ref **buckets; 0398 v4l2_ctrl_notify_fnc notify; 0399 void *notify_priv; 0400 u16 nr_of_buckets; 0401 int error; 0402 bool request_is_queued; 0403 struct list_head requests; 0404 struct list_head requests_queued; 0405 struct media_request_object req_obj; 0406 }; 0407 0408 /** 0409 * struct v4l2_ctrl_config - Control configuration structure. 0410 * 0411 * @ops: The control ops. 0412 * @type_ops: The control type ops. Only needed for compound controls. 0413 * @id: The control ID. 0414 * @name: The control name. 0415 * @type: The control type. 0416 * @min: The control's minimum value. 0417 * @max: The control's maximum value. 0418 * @step: The control's step value for non-menu controls. 0419 * @def: The control's default value. 0420 * @p_def: The control's default value for compound controls. 0421 * @dims: The size of each dimension. 0422 * @elem_size: The size in bytes of the control. 0423 * @flags: The control's flags. 0424 * @menu_skip_mask: The control's skip mask for menu controls. This makes it 0425 * easy to skip menu items that are not valid. If bit X is set, 0426 * then menu item X is skipped. Of course, this only works for 0427 * menus with <= 64 menu items. There are no menus that come 0428 * close to that number, so this is OK. Should we ever need more, 0429 * then this will have to be extended to a bit array. 0430 * @qmenu: A const char * array for all menu items. Array entries that are 0431 * empty strings ("") correspond to non-existing menu items (this 0432 * is in addition to the menu_skip_mask above). The last entry 0433 * must be NULL. 0434 * @qmenu_int: A const s64 integer array for all menu items of the type 0435 * V4L2_CTRL_TYPE_INTEGER_MENU. 0436 * @is_private: If set, then this control is private to its handler and it 0437 * will not be added to any other handlers. 0438 */ 0439 struct v4l2_ctrl_config { 0440 const struct v4l2_ctrl_ops *ops; 0441 const struct v4l2_ctrl_type_ops *type_ops; 0442 u32 id; 0443 const char *name; 0444 enum v4l2_ctrl_type type; 0445 s64 min; 0446 s64 max; 0447 u64 step; 0448 s64 def; 0449 union v4l2_ctrl_ptr p_def; 0450 u32 dims[V4L2_CTRL_MAX_DIMS]; 0451 u32 elem_size; 0452 u32 flags; 0453 u64 menu_skip_mask; 0454 const char * const *qmenu; 0455 const s64 *qmenu_int; 0456 unsigned int is_private:1; 0457 }; 0458 0459 /** 0460 * v4l2_ctrl_fill - Fill in the control fields based on the control ID. 0461 * 0462 * @id: ID of the control 0463 * @name: pointer to be filled with a string with the name of the control 0464 * @type: pointer for storing the type of the control 0465 * @min: pointer for storing the minimum value for the control 0466 * @max: pointer for storing the maximum value for the control 0467 * @step: pointer for storing the control step 0468 * @def: pointer for storing the default value for the control 0469 * @flags: pointer for storing the flags to be used on the control 0470 * 0471 * This works for all standard V4L2 controls. 0472 * For non-standard controls it will only fill in the given arguments 0473 * and @name content will be set to %NULL. 0474 * 0475 * This function will overwrite the contents of @name, @type and @flags. 0476 * The contents of @min, @max, @step and @def may be modified depending on 0477 * the type. 0478 * 0479 * .. note:: 0480 * 0481 * Do not use in drivers! It is used internally for backwards compatibility 0482 * control handling only. Once all drivers are converted to use the new 0483 * control framework this function will no longer be exported. 0484 */ 0485 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 0486 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags); 0487 0488 0489 /** 0490 * v4l2_ctrl_handler_init_class() - Initialize the control handler. 0491 * @hdl: The control handler. 0492 * @nr_of_controls_hint: A hint of how many controls this handler is 0493 * expected to refer to. This is the total number, so including 0494 * any inherited controls. It doesn't have to be precise, but if 0495 * it is way off, then you either waste memory (too many buckets 0496 * are allocated) or the control lookup becomes slower (not enough 0497 * buckets are allocated, so there are more slow list lookups). 0498 * It will always work, though. 0499 * @key: Used by the lock validator if CONFIG_LOCKDEP is set. 0500 * @name: Used by the lock validator if CONFIG_LOCKDEP is set. 0501 * 0502 * .. attention:: 0503 * 0504 * Never use this call directly, always use the v4l2_ctrl_handler_init() 0505 * macro that hides the @key and @name arguments. 0506 * 0507 * Return: returns an error if the buckets could not be allocated. This 0508 * error will also be stored in @hdl->error. 0509 */ 0510 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, 0511 unsigned int nr_of_controls_hint, 0512 struct lock_class_key *key, const char *name); 0513 0514 #ifdef CONFIG_LOCKDEP 0515 0516 /** 0517 * v4l2_ctrl_handler_init - helper function to create a static struct 0518 * &lock_class_key and calls v4l2_ctrl_handler_init_class() 0519 * 0520 * @hdl: The control handler. 0521 * @nr_of_controls_hint: A hint of how many controls this handler is 0522 * expected to refer to. This is the total number, so including 0523 * any inherited controls. It doesn't have to be precise, but if 0524 * it is way off, then you either waste memory (too many buckets 0525 * are allocated) or the control lookup becomes slower (not enough 0526 * buckets are allocated, so there are more slow list lookups). 0527 * It will always work, though. 0528 * 0529 * This helper function creates a static struct &lock_class_key and 0530 * calls v4l2_ctrl_handler_init_class(), providing a proper name for the lock 0531 * validador. 0532 * 0533 * Use this helper function to initialize a control handler. 0534 */ 0535 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \ 0536 ( \ 0537 ({ \ 0538 static struct lock_class_key _key; \ 0539 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \ 0540 &_key, \ 0541 KBUILD_BASENAME ":" \ 0542 __stringify(__LINE__) ":" \ 0543 "(" #hdl ")->_lock"); \ 0544 }) \ 0545 ) 0546 #else 0547 #define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \ 0548 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL) 0549 #endif 0550 0551 /** 0552 * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free 0553 * the control list. 0554 * @hdl: The control handler. 0555 * 0556 * Does nothing if @hdl == NULL. 0557 */ 0558 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); 0559 0560 /** 0561 * v4l2_ctrl_lock() - Helper function to lock the handler 0562 * associated with the control. 0563 * @ctrl: The control to lock. 0564 */ 0565 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) 0566 { 0567 mutex_lock(ctrl->handler->lock); 0568 } 0569 0570 /** 0571 * v4l2_ctrl_unlock() - Helper function to unlock the handler 0572 * associated with the control. 0573 * @ctrl: The control to unlock. 0574 */ 0575 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) 0576 { 0577 mutex_unlock(ctrl->handler->lock); 0578 } 0579 0580 /** 0581 * __v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging 0582 * to the handler to initialize the hardware to the current control values. The 0583 * caller is responsible for acquiring the control handler mutex on behalf of 0584 * __v4l2_ctrl_handler_setup(). 0585 * @hdl: The control handler. 0586 * 0587 * Button controls will be skipped, as are read-only controls. 0588 * 0589 * If @hdl == NULL, then this just returns 0. 0590 */ 0591 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); 0592 0593 /** 0594 * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging 0595 * to the handler to initialize the hardware to the current control values. 0596 * @hdl: The control handler. 0597 * 0598 * Button controls will be skipped, as are read-only controls. 0599 * 0600 * If @hdl == NULL, then this just returns 0. 0601 */ 0602 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); 0603 0604 /** 0605 * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler. 0606 * @hdl: The control handler. 0607 * @prefix: The prefix to use when logging the control values. If the 0608 * prefix does not end with a space, then ": " will be added 0609 * after the prefix. If @prefix == NULL, then no prefix will be 0610 * used. 0611 * 0612 * For use with VIDIOC_LOG_STATUS. 0613 * 0614 * Does nothing if @hdl == NULL. 0615 */ 0616 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, 0617 const char *prefix); 0618 0619 /** 0620 * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2 0621 * control. 0622 * 0623 * @hdl: The control handler. 0624 * @cfg: The control's configuration data. 0625 * @priv: The control's driver-specific private data. 0626 * 0627 * If the &v4l2_ctrl struct could not be allocated then NULL is returned 0628 * and @hdl->error is set to the error code (if it wasn't set already). 0629 */ 0630 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, 0631 const struct v4l2_ctrl_config *cfg, 0632 void *priv); 0633 0634 /** 0635 * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu 0636 * control. 0637 * 0638 * @hdl: The control handler. 0639 * @ops: The control ops. 0640 * @id: The control ID. 0641 * @min: The control's minimum value. 0642 * @max: The control's maximum value. 0643 * @step: The control's step value 0644 * @def: The control's default value. 0645 * 0646 * If the &v4l2_ctrl struct could not be allocated, or the control 0647 * ID is not known, then NULL is returned and @hdl->error is set to the 0648 * appropriate error code (if it wasn't set already). 0649 * 0650 * If @id refers to a menu control, then this function will return NULL. 0651 * 0652 * Use v4l2_ctrl_new_std_menu() when adding menu controls. 0653 */ 0654 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, 0655 const struct v4l2_ctrl_ops *ops, 0656 u32 id, s64 min, s64 max, u64 step, 0657 s64 def); 0658 0659 /** 0660 * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 0661 * menu control. 0662 * 0663 * @hdl: The control handler. 0664 * @ops: The control ops. 0665 * @id: The control ID. 0666 * @max: The control's maximum value. 0667 * @mask: The control's skip mask for menu controls. This makes it 0668 * easy to skip menu items that are not valid. If bit X is set, 0669 * then menu item X is skipped. Of course, this only works for 0670 * menus with <= 64 menu items. There are no menus that come 0671 * close to that number, so this is OK. Should we ever need more, 0672 * then this will have to be extended to a bit array. 0673 * @def: The control's default value. 0674 * 0675 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value 0676 * determines which menu items are to be skipped. 0677 * 0678 * If @id refers to a non-menu control, then this function will return NULL. 0679 */ 0680 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, 0681 const struct v4l2_ctrl_ops *ops, 0682 u32 id, u8 max, u64 mask, u8 def); 0683 0684 /** 0685 * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control 0686 * with driver specific menu. 0687 * 0688 * @hdl: The control handler. 0689 * @ops: The control ops. 0690 * @id: The control ID. 0691 * @max: The control's maximum value. 0692 * @mask: The control's skip mask for menu controls. This makes it 0693 * easy to skip menu items that are not valid. If bit X is set, 0694 * then menu item X is skipped. Of course, this only works for 0695 * menus with <= 64 menu items. There are no menus that come 0696 * close to that number, so this is OK. Should we ever need more, 0697 * then this will have to be extended to a bit array. 0698 * @def: The control's default value. 0699 * @qmenu: The new menu. 0700 * 0701 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific 0702 * menu of this control. 0703 * 0704 */ 0705 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, 0706 const struct v4l2_ctrl_ops *ops, 0707 u32 id, u8 max, 0708 u64 mask, u8 def, 0709 const char * const *qmenu); 0710 0711 /** 0712 * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2 0713 * compound control. 0714 * 0715 * @hdl: The control handler. 0716 * @ops: The control ops. 0717 * @id: The control ID. 0718 * @p_def: The control's default value. 0719 * 0720 * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks 0721 * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a 0722 * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the 0723 * compound control should be all zeroes. 0724 * 0725 */ 0726 struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, 0727 const struct v4l2_ctrl_ops *ops, 0728 u32 id, 0729 const union v4l2_ctrl_ptr p_def); 0730 0731 /** 0732 * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 0733 * 0734 * @hdl: The control handler. 0735 * @ops: The control ops. 0736 * @id: The control ID. 0737 * @max: The control's maximum value. 0738 * @def: The control's default value. 0739 * @qmenu_int: The control's menu entries. 0740 * 0741 * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionally 0742 * takes as an argument an array of integers determining the menu items. 0743 * 0744 * If @id refers to a non-integer-menu control, then this function will 0745 * return %NULL. 0746 */ 0747 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, 0748 const struct v4l2_ctrl_ops *ops, 0749 u32 id, u8 max, u8 def, 0750 const s64 *qmenu_int); 0751 0752 /** 0753 * typedef v4l2_ctrl_filter - Typedef to define the filter function to be 0754 * used when adding a control handler. 0755 * 0756 * @ctrl: pointer to struct &v4l2_ctrl. 0757 */ 0758 0759 typedef bool (*v4l2_ctrl_filter)(const struct v4l2_ctrl *ctrl); 0760 0761 /** 0762 * v4l2_ctrl_add_handler() - Add all controls from handler @add to 0763 * handler @hdl. 0764 * 0765 * @hdl: The control handler. 0766 * @add: The control handler whose controls you want to add to 0767 * the @hdl control handler. 0768 * @filter: This function will filter which controls should be added. 0769 * @from_other_dev: If true, then the controls in @add were defined in another 0770 * device than @hdl. 0771 * 0772 * Does nothing if either of the two handlers is a NULL pointer. 0773 * If @filter is NULL, then all controls are added. Otherwise only those 0774 * controls for which @filter returns true will be added. 0775 * In case of an error @hdl->error will be set to the error code (if it 0776 * wasn't set already). 0777 */ 0778 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, 0779 struct v4l2_ctrl_handler *add, 0780 v4l2_ctrl_filter filter, 0781 bool from_other_dev); 0782 0783 /** 0784 * v4l2_ctrl_radio_filter() - Standard filter for radio controls. 0785 * 0786 * @ctrl: The control that is filtered. 0787 * 0788 * This will return true for any controls that are valid for radio device 0789 * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM 0790 * transmitter class controls. 0791 * 0792 * This function is to be used with v4l2_ctrl_add_handler(). 0793 */ 0794 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl); 0795 0796 /** 0797 * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging 0798 * to that cluster. 0799 * 0800 * @ncontrols: The number of controls in this cluster. 0801 * @controls: The cluster control array of size @ncontrols. 0802 */ 0803 void v4l2_ctrl_cluster(unsigned int ncontrols, struct v4l2_ctrl **controls); 0804 0805 0806 /** 0807 * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging 0808 * to that cluster and set it up for autofoo/foo-type handling. 0809 * 0810 * @ncontrols: The number of controls in this cluster. 0811 * @controls: The cluster control array of size @ncontrols. The first control 0812 * must be the 'auto' control (e.g. autogain, autoexposure, etc.) 0813 * @manual_val: The value for the first control in the cluster that equals the 0814 * manual setting. 0815 * @set_volatile: If true, then all controls except the first auto control will 0816 * be volatile. 0817 * 0818 * Use for control groups where one control selects some automatic feature and 0819 * the other controls are only active whenever the automatic feature is turned 0820 * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs 0821 * red and blue balance, etc. 0822 * 0823 * The behavior of such controls is as follows: 0824 * 0825 * When the autofoo control is set to automatic, then any manual controls 0826 * are set to inactive and any reads will call g_volatile_ctrl (if the control 0827 * was marked volatile). 0828 * 0829 * When the autofoo control is set to manual, then any manual controls will 0830 * be marked active, and any reads will just return the current value without 0831 * going through g_volatile_ctrl. 0832 * 0833 * In addition, this function will set the %V4L2_CTRL_FLAG_UPDATE flag 0834 * on the autofoo control and %V4L2_CTRL_FLAG_INACTIVE on the foo control(s) 0835 * if autofoo is in auto mode. 0836 */ 0837 void v4l2_ctrl_auto_cluster(unsigned int ncontrols, 0838 struct v4l2_ctrl **controls, 0839 u8 manual_val, bool set_volatile); 0840 0841 0842 /** 0843 * v4l2_ctrl_find() - Find a control with the given ID. 0844 * 0845 * @hdl: The control handler. 0846 * @id: The control ID to find. 0847 * 0848 * If @hdl == NULL this will return NULL as well. Will lock the handler so 0849 * do not use from inside &v4l2_ctrl_ops. 0850 */ 0851 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); 0852 0853 /** 0854 * v4l2_ctrl_activate() - Make the control active or inactive. 0855 * @ctrl: The control to (de)activate. 0856 * @active: True if the control should become active. 0857 * 0858 * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically. 0859 * Does nothing if @ctrl == NULL. 0860 * This will usually be called from within the s_ctrl op. 0861 * The V4L2_EVENT_CTRL event will be generated afterwards. 0862 * 0863 * This function assumes that the control handler is locked. 0864 */ 0865 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active); 0866 0867 /** 0868 * __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab. 0869 * 0870 * @ctrl: The control to (de)activate. 0871 * @grabbed: True if the control should become grabbed. 0872 * 0873 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. 0874 * Does nothing if @ctrl == NULL. 0875 * The V4L2_EVENT_CTRL event will be generated afterwards. 0876 * This will usually be called when starting or stopping streaming in the 0877 * driver. 0878 * 0879 * This function assumes that the control handler is locked by the caller. 0880 */ 0881 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); 0882 0883 /** 0884 * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. 0885 * 0886 * @ctrl: The control to (de)activate. 0887 * @grabbed: True if the control should become grabbed. 0888 * 0889 * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. 0890 * Does nothing if @ctrl == NULL. 0891 * The V4L2_EVENT_CTRL event will be generated afterwards. 0892 * This will usually be called when starting or stopping streaming in the 0893 * driver. 0894 * 0895 * This function assumes that the control handler is not locked and will 0896 * take the lock itself. 0897 */ 0898 static inline void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) 0899 { 0900 if (!ctrl) 0901 return; 0902 0903 v4l2_ctrl_lock(ctrl); 0904 __v4l2_ctrl_grab(ctrl, grabbed); 0905 v4l2_ctrl_unlock(ctrl); 0906 } 0907 0908 /** 0909 *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range() 0910 * 0911 * @ctrl: The control to update. 0912 * @min: The control's minimum value. 0913 * @max: The control's maximum value. 0914 * @step: The control's step value 0915 * @def: The control's default value. 0916 * 0917 * Update the range of a control on the fly. This works for control types 0918 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 0919 * @step value is interpreted as a menu_skip_mask. 0920 * 0921 * An error is returned if one of the range arguments is invalid for this 0922 * control type. 0923 * 0924 * The caller is responsible for acquiring the control handler mutex on behalf 0925 * of __v4l2_ctrl_modify_range(). 0926 */ 0927 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 0928 s64 min, s64 max, u64 step, s64 def); 0929 0930 /** 0931 * v4l2_ctrl_modify_range() - Update the range of a control. 0932 * 0933 * @ctrl: The control to update. 0934 * @min: The control's minimum value. 0935 * @max: The control's maximum value. 0936 * @step: The control's step value 0937 * @def: The control's default value. 0938 * 0939 * Update the range of a control on the fly. This works for control types 0940 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 0941 * @step value is interpreted as a menu_skip_mask. 0942 * 0943 * An error is returned if one of the range arguments is invalid for this 0944 * control type. 0945 * 0946 * This function assumes that the control handler is not locked and will 0947 * take the lock itself. 0948 */ 0949 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 0950 s64 min, s64 max, u64 step, s64 def) 0951 { 0952 int rval; 0953 0954 v4l2_ctrl_lock(ctrl); 0955 rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def); 0956 v4l2_ctrl_unlock(ctrl); 0957 0958 return rval; 0959 } 0960 0961 /** 0962 * v4l2_ctrl_notify() - Function to set a notify callback for a control. 0963 * 0964 * @ctrl: The control. 0965 * @notify: The callback function. 0966 * @priv: The callback private handle, passed as argument to the callback. 0967 * 0968 * This function sets a callback function for the control. If @ctrl is NULL, 0969 * then it will do nothing. If @notify is NULL, then the notify callback will 0970 * be removed. 0971 * 0972 * There can be only one notify. If another already exists, then a WARN_ON 0973 * will be issued and the function will do nothing. 0974 */ 0975 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, 0976 void *priv); 0977 0978 /** 0979 * v4l2_ctrl_get_name() - Get the name of the control 0980 * 0981 * @id: The control ID. 0982 * 0983 * This function returns the name of the given control ID or NULL if it isn't 0984 * a known control. 0985 */ 0986 const char *v4l2_ctrl_get_name(u32 id); 0987 0988 /** 0989 * v4l2_ctrl_get_menu() - Get the menu string array of the control 0990 * 0991 * @id: The control ID. 0992 * 0993 * This function returns the NULL-terminated menu string array name of the 0994 * given control ID or NULL if it isn't a known menu control. 0995 */ 0996 const char * const *v4l2_ctrl_get_menu(u32 id); 0997 0998 /** 0999 * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control 1000 * 1001 * @id: The control ID. 1002 * @len: The size of the integer array. 1003 * 1004 * This function returns the integer array of the given control ID or NULL if it 1005 * if it isn't a known integer menu control. 1006 */ 1007 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len); 1008 1009 /** 1010 * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from 1011 * within a driver. 1012 * 1013 * @ctrl: The control. 1014 * 1015 * This returns the control's value safely by going through the control 1016 * framework. This function will lock the control's handler, so it cannot be 1017 * used from within the &v4l2_ctrl_ops functions. 1018 * 1019 * This function is for integer type controls only. 1020 */ 1021 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); 1022 1023 /** 1024 * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl(). 1025 * 1026 * @ctrl: The control. 1027 * @val: The new value. 1028 * 1029 * This sets the control's new value safely by going through the control 1030 * framework. This function assumes the control's handler is already locked, 1031 * allowing it to be used from within the &v4l2_ctrl_ops functions. 1032 * 1033 * This function is for integer type controls only. 1034 */ 1035 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); 1036 1037 /** 1038 * v4l2_ctrl_s_ctrl() - Helper function to set the control's value from 1039 * within a driver. 1040 * @ctrl: The control. 1041 * @val: The new value. 1042 * 1043 * This sets the control's new value safely by going through the control 1044 * framework. This function will lock the control's handler, so it cannot be 1045 * used from within the &v4l2_ctrl_ops functions. 1046 * 1047 * This function is for integer type controls only. 1048 */ 1049 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) 1050 { 1051 int rval; 1052 1053 v4l2_ctrl_lock(ctrl); 1054 rval = __v4l2_ctrl_s_ctrl(ctrl, val); 1055 v4l2_ctrl_unlock(ctrl); 1056 1057 return rval; 1058 } 1059 1060 /** 1061 * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value 1062 * from within a driver. 1063 * 1064 * @ctrl: The control. 1065 * 1066 * This returns the control's value safely by going through the control 1067 * framework. This function will lock the control's handler, so it cannot be 1068 * used from within the &v4l2_ctrl_ops functions. 1069 * 1070 * This function is for 64-bit integer type controls only. 1071 */ 1072 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl); 1073 1074 /** 1075 * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64(). 1076 * 1077 * @ctrl: The control. 1078 * @val: The new value. 1079 * 1080 * This sets the control's new value safely by going through the control 1081 * framework. This function assumes the control's handler is already locked, 1082 * allowing it to be used from within the &v4l2_ctrl_ops functions. 1083 * 1084 * This function is for 64-bit integer type controls only. 1085 */ 1086 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val); 1087 1088 /** 1089 * v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value 1090 * from within a driver. 1091 * 1092 * @ctrl: The control. 1093 * @val: The new value. 1094 * 1095 * This sets the control's new value safely by going through the control 1096 * framework. This function will lock the control's handler, so it cannot be 1097 * used from within the &v4l2_ctrl_ops functions. 1098 * 1099 * This function is for 64-bit integer type controls only. 1100 */ 1101 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) 1102 { 1103 int rval; 1104 1105 v4l2_ctrl_lock(ctrl); 1106 rval = __v4l2_ctrl_s_ctrl_int64(ctrl, val); 1107 v4l2_ctrl_unlock(ctrl); 1108 1109 return rval; 1110 } 1111 1112 /** 1113 * __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string(). 1114 * 1115 * @ctrl: The control. 1116 * @s: The new string. 1117 * 1118 * This sets the control's new string safely by going through the control 1119 * framework. This function assumes the control's handler is already locked, 1120 * allowing it to be used from within the &v4l2_ctrl_ops functions. 1121 * 1122 * This function is for string type controls only. 1123 */ 1124 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s); 1125 1126 /** 1127 * v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value 1128 * from within a driver. 1129 * 1130 * @ctrl: The control. 1131 * @s: The new string. 1132 * 1133 * This sets the control's new string safely by going through the control 1134 * framework. This function will lock the control's handler, so it cannot be 1135 * used from within the &v4l2_ctrl_ops functions. 1136 * 1137 * This function is for string type controls only. 1138 */ 1139 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) 1140 { 1141 int rval; 1142 1143 v4l2_ctrl_lock(ctrl); 1144 rval = __v4l2_ctrl_s_ctrl_string(ctrl, s); 1145 v4l2_ctrl_unlock(ctrl); 1146 1147 return rval; 1148 } 1149 1150 /** 1151 * __v4l2_ctrl_s_ctrl_compound() - Unlocked variant to set a compound control 1152 * 1153 * @ctrl: The control. 1154 * @type: The type of the data. 1155 * @p: The new compound payload. 1156 * 1157 * This sets the control's new compound payload safely by going through the 1158 * control framework. This function assumes the control's handler is already 1159 * locked, allowing it to be used from within the &v4l2_ctrl_ops functions. 1160 * 1161 * This function is for compound type controls only. 1162 */ 1163 int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl, 1164 enum v4l2_ctrl_type type, const void *p); 1165 1166 /** 1167 * v4l2_ctrl_s_ctrl_compound() - Helper function to set a compound control 1168 * from within a driver. 1169 * 1170 * @ctrl: The control. 1171 * @type: The type of the data. 1172 * @p: The new compound payload. 1173 * 1174 * This sets the control's new compound payload safely by going through the 1175 * control framework. This function will lock the control's handler, so it 1176 * cannot be used from within the &v4l2_ctrl_ops functions. 1177 * 1178 * This function is for compound type controls only. 1179 */ 1180 static inline int v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl, 1181 enum v4l2_ctrl_type type, 1182 const void *p) 1183 { 1184 int rval; 1185 1186 v4l2_ctrl_lock(ctrl); 1187 rval = __v4l2_ctrl_s_ctrl_compound(ctrl, type, p); 1188 v4l2_ctrl_unlock(ctrl); 1189 1190 return rval; 1191 } 1192 1193 /* Helper defines for area type controls */ 1194 #define __v4l2_ctrl_s_ctrl_area(ctrl, area) \ 1195 __v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area)) 1196 #define v4l2_ctrl_s_ctrl_area(ctrl, area) \ 1197 v4l2_ctrl_s_ctrl_compound((ctrl), V4L2_CTRL_TYPE_AREA, (area)) 1198 1199 /* Internal helper functions that deal with control events. */ 1200 extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops; 1201 1202 /** 1203 * v4l2_ctrl_replace - Function to be used as a callback to 1204 * &struct v4l2_subscribed_event_ops replace\(\) 1205 * 1206 * @old: pointer to struct &v4l2_event with the reported 1207 * event; 1208 * @new: pointer to struct &v4l2_event with the modified 1209 * event; 1210 */ 1211 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new); 1212 1213 /** 1214 * v4l2_ctrl_merge - Function to be used as a callback to 1215 * &struct v4l2_subscribed_event_ops merge(\) 1216 * 1217 * @old: pointer to struct &v4l2_event with the reported 1218 * event; 1219 * @new: pointer to struct &v4l2_event with the merged 1220 * event; 1221 */ 1222 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new); 1223 1224 /** 1225 * v4l2_ctrl_log_status - helper function to implement %VIDIOC_LOG_STATUS ioctl 1226 * 1227 * @file: pointer to struct file 1228 * @fh: unused. Kept just to be compatible to the arguments expected by 1229 * &struct v4l2_ioctl_ops.vidioc_log_status. 1230 * 1231 * Can be used as a vidioc_log_status function that just dumps all controls 1232 * associated with the filehandle. 1233 */ 1234 int v4l2_ctrl_log_status(struct file *file, void *fh); 1235 1236 /** 1237 * v4l2_ctrl_subscribe_event - Subscribes to an event 1238 * 1239 * 1240 * @fh: pointer to struct v4l2_fh 1241 * @sub: pointer to &struct v4l2_event_subscription 1242 * 1243 * Can be used as a vidioc_subscribe_event function that just subscribes 1244 * control events. 1245 */ 1246 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh, 1247 const struct v4l2_event_subscription *sub); 1248 1249 /** 1250 * v4l2_ctrl_poll - function to be used as a callback to the poll() 1251 * That just polls for control events. 1252 * 1253 * @file: pointer to struct file 1254 * @wait: pointer to struct poll_table_struct 1255 */ 1256 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait); 1257 1258 /** 1259 * v4l2_ctrl_request_setup - helper function to apply control values in a request 1260 * 1261 * @req: The request 1262 * @parent: The parent control handler ('priv' in media_request_object_find()) 1263 * 1264 * This is a helper function to call the control handler's s_ctrl callback with 1265 * the control values contained in the request. Do note that this approach of 1266 * applying control values in a request is only applicable to memory-to-memory 1267 * devices. 1268 */ 1269 int v4l2_ctrl_request_setup(struct media_request *req, 1270 struct v4l2_ctrl_handler *parent); 1271 1272 /** 1273 * v4l2_ctrl_request_complete - Complete a control handler request object 1274 * 1275 * @req: The request 1276 * @parent: The parent control handler ('priv' in media_request_object_find()) 1277 * 1278 * This function is to be called on each control handler that may have had a 1279 * request object associated with it, i.e. control handlers of a driver that 1280 * supports requests. 1281 * 1282 * The function first obtains the values of any volatile controls in the control 1283 * handler and attach them to the request. Then, the function completes the 1284 * request object. 1285 */ 1286 void v4l2_ctrl_request_complete(struct media_request *req, 1287 struct v4l2_ctrl_handler *parent); 1288 1289 /** 1290 * v4l2_ctrl_request_hdl_find - Find the control handler in the request 1291 * 1292 * @req: The request 1293 * @parent: The parent control handler ('priv' in media_request_object_find()) 1294 * 1295 * This function finds the control handler in the request. It may return 1296 * NULL if not found. When done, you must call v4l2_ctrl_request_put_hdl() 1297 * with the returned handler pointer. 1298 * 1299 * If the request is not in state VALIDATING or QUEUED, then this function 1300 * will always return NULL. 1301 * 1302 * Note that in state VALIDATING the req_queue_mutex is held, so 1303 * no objects can be added or deleted from the request. 1304 * 1305 * In state QUEUED it is the driver that will have to ensure this. 1306 */ 1307 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req, 1308 struct v4l2_ctrl_handler *parent); 1309 1310 /** 1311 * v4l2_ctrl_request_hdl_put - Put the control handler 1312 * 1313 * @hdl: Put this control handler 1314 * 1315 * This function released the control handler previously obtained from' 1316 * v4l2_ctrl_request_hdl_find(). 1317 */ 1318 static inline void v4l2_ctrl_request_hdl_put(struct v4l2_ctrl_handler *hdl) 1319 { 1320 if (hdl) 1321 media_request_object_put(&hdl->req_obj); 1322 } 1323 1324 /** 1325 * v4l2_ctrl_request_hdl_ctrl_find() - Find a control with the given ID. 1326 * 1327 * @hdl: The control handler from the request. 1328 * @id: The ID of the control to find. 1329 * 1330 * This function returns a pointer to the control if this control is 1331 * part of the request or NULL otherwise. 1332 */ 1333 struct v4l2_ctrl * 1334 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); 1335 1336 /* Helpers for ioctl_ops */ 1337 1338 /** 1339 * v4l2_queryctrl - Helper function to implement 1340 * :ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl 1341 * 1342 * @hdl: pointer to &struct v4l2_ctrl_handler 1343 * @qc: pointer to &struct v4l2_queryctrl 1344 * 1345 * If hdl == NULL then they will all return -EINVAL. 1346 */ 1347 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc); 1348 1349 /** 1350 * v4l2_query_ext_ctrl - Helper function to implement 1351 * :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl 1352 * 1353 * @hdl: pointer to &struct v4l2_ctrl_handler 1354 * @qc: pointer to &struct v4l2_query_ext_ctrl 1355 * 1356 * If hdl == NULL then they will all return -EINVAL. 1357 */ 1358 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, 1359 struct v4l2_query_ext_ctrl *qc); 1360 1361 /** 1362 * v4l2_querymenu - Helper function to implement 1363 * :ref:`VIDIOC_QUERYMENU <vidioc_queryctrl>` ioctl 1364 * 1365 * @hdl: pointer to &struct v4l2_ctrl_handler 1366 * @qm: pointer to &struct v4l2_querymenu 1367 * 1368 * If hdl == NULL then they will all return -EINVAL. 1369 */ 1370 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm); 1371 1372 /** 1373 * v4l2_g_ctrl - Helper function to implement 1374 * :ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl 1375 * 1376 * @hdl: pointer to &struct v4l2_ctrl_handler 1377 * @ctrl: pointer to &struct v4l2_control 1378 * 1379 * If hdl == NULL then they will all return -EINVAL. 1380 */ 1381 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); 1382 1383 /** 1384 * v4l2_s_ctrl - Helper function to implement 1385 * :ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl 1386 * 1387 * @fh: pointer to &struct v4l2_fh 1388 * @hdl: pointer to &struct v4l2_ctrl_handler 1389 * 1390 * @ctrl: pointer to &struct v4l2_control 1391 * 1392 * If hdl == NULL then they will all return -EINVAL. 1393 */ 1394 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, 1395 struct v4l2_control *ctrl); 1396 1397 /** 1398 * v4l2_g_ext_ctrls - Helper function to implement 1399 * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl 1400 * 1401 * @hdl: pointer to &struct v4l2_ctrl_handler 1402 * @vdev: pointer to &struct video_device 1403 * @mdev: pointer to &struct media_device 1404 * @c: pointer to &struct v4l2_ext_controls 1405 * 1406 * If hdl == NULL then they will all return -EINVAL. 1407 */ 1408 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev, 1409 struct media_device *mdev, struct v4l2_ext_controls *c); 1410 1411 /** 1412 * v4l2_try_ext_ctrls - Helper function to implement 1413 * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl 1414 * 1415 * @hdl: pointer to &struct v4l2_ctrl_handler 1416 * @vdev: pointer to &struct video_device 1417 * @mdev: pointer to &struct media_device 1418 * @c: pointer to &struct v4l2_ext_controls 1419 * 1420 * If hdl == NULL then they will all return -EINVAL. 1421 */ 1422 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, 1423 struct video_device *vdev, 1424 struct media_device *mdev, 1425 struct v4l2_ext_controls *c); 1426 1427 /** 1428 * v4l2_s_ext_ctrls - Helper function to implement 1429 * :ref:`VIDIOC_S_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl 1430 * 1431 * @fh: pointer to &struct v4l2_fh 1432 * @hdl: pointer to &struct v4l2_ctrl_handler 1433 * @vdev: pointer to &struct video_device 1434 * @mdev: pointer to &struct media_device 1435 * @c: pointer to &struct v4l2_ext_controls 1436 * 1437 * If hdl == NULL then they will all return -EINVAL. 1438 */ 1439 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, 1440 struct video_device *vdev, 1441 struct media_device *mdev, 1442 struct v4l2_ext_controls *c); 1443 1444 /** 1445 * v4l2_ctrl_subdev_subscribe_event - Helper function to implement 1446 * as a &struct v4l2_subdev_core_ops subscribe_event function 1447 * that just subscribes control events. 1448 * 1449 * @sd: pointer to &struct v4l2_subdev 1450 * @fh: pointer to &struct v4l2_fh 1451 * @sub: pointer to &struct v4l2_event_subscription 1452 */ 1453 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, 1454 struct v4l2_event_subscription *sub); 1455 1456 /** 1457 * v4l2_ctrl_subdev_log_status - Log all controls owned by subdev's control 1458 * handler. 1459 * 1460 * @sd: pointer to &struct v4l2_subdev 1461 */ 1462 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd); 1463 1464 /** 1465 * v4l2_ctrl_new_fwnode_properties() - Register controls for the device 1466 * properties 1467 * 1468 * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on 1469 * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with 1470 * @p: pointer to &struct v4l2_fwnode_device_properties 1471 * 1472 * This function registers controls associated to device properties, using the 1473 * property values contained in @p parameter, if the property has been set to 1474 * a value. 1475 * 1476 * Currently the following v4l2 controls are parsed and registered: 1477 * - V4L2_CID_CAMERA_ORIENTATION 1478 * - V4L2_CID_CAMERA_SENSOR_ROTATION; 1479 * 1480 * Controls already registered by the caller with the @hdl control handler are 1481 * not overwritten. Callers should register the controls they want to handle 1482 * themselves before calling this function. 1483 * 1484 * Return: 0 on success, a negative error code on failure. 1485 */ 1486 int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl, 1487 const struct v4l2_ctrl_ops *ctrl_ops, 1488 const struct v4l2_fwnode_device_properties *p); 1489 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |