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