Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1 | /* |
| 2 | V4L2 controls support header. |
| 3 | |
| 4 | Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl> |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef _V4L2_CTRLS_H |
| 22 | #define _V4L2_CTRLS_H |
| 23 | |
| 24 | #include <linux/list.h> |
Flemmard | 0a7467c | 2013-05-20 14:23:09 -0700 | [diff] [blame] | 25 | #include <linux/device.h> |
Laurent Pinchart | 01c40c0 | 2010-11-19 11:20:06 -0300 | [diff] [blame] | 26 | #include <linux/videodev2.h> |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 27 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 28 | struct v4l2_ctrl_handler; |
| 29 | struct v4l2_ctrl; |
| 30 | struct video_device; |
| 31 | struct v4l2_subdev; |
| 32 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 33 | struct v4l2_ctrl_ops { |
| 34 | int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl); |
| 35 | int (*try_ctrl)(struct v4l2_ctrl *ctrl); |
| 36 | int (*s_ctrl)(struct v4l2_ctrl *ctrl); |
| 37 | }; |
| 38 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 39 | struct v4l2_ctrl { |
Flemmard | 0a7467c | 2013-05-20 14:23:09 -0700 | [diff] [blame] | 40 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 41 | struct list_head node; |
| 42 | struct v4l2_ctrl_handler *handler; |
| 43 | struct v4l2_ctrl **cluster; |
| 44 | unsigned ncontrols; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 45 | unsigned int done:1; |
| 46 | |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 47 | unsigned int is_new:1; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 48 | unsigned int is_private:1; |
Flemmard | 0a7467c | 2013-05-20 14:23:09 -0700 | [diff] [blame] | 49 | unsigned int is_volatile:1; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 50 | |
| 51 | const struct v4l2_ctrl_ops *ops; |
| 52 | u32 id; |
| 53 | const char *name; |
| 54 | enum v4l2_ctrl_type type; |
| 55 | s32 minimum, maximum, default_value; |
| 56 | union { |
| 57 | u32 step; |
| 58 | u32 menu_skip_mask; |
| 59 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 60 | const char * const *qmenu; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 61 | unsigned long flags; |
| 62 | union { |
| 63 | s32 val; |
| 64 | s64 val64; |
| 65 | char *string; |
| 66 | } cur; |
| 67 | union { |
| 68 | s32 val; |
| 69 | s64 val64; |
| 70 | char *string; |
| 71 | }; |
| 72 | void *priv; |
| 73 | }; |
| 74 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 75 | struct v4l2_ctrl_ref { |
| 76 | struct list_head node; |
| 77 | struct v4l2_ctrl_ref *next; |
| 78 | struct v4l2_ctrl *ctrl; |
| 79 | }; |
| 80 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 81 | struct v4l2_ctrl_handler { |
| 82 | struct mutex lock; |
| 83 | struct list_head ctrls; |
| 84 | struct list_head ctrl_refs; |
| 85 | struct v4l2_ctrl_ref *cached; |
| 86 | struct v4l2_ctrl_ref **buckets; |
| 87 | u16 nr_of_buckets; |
| 88 | int error; |
| 89 | }; |
| 90 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 91 | struct v4l2_ctrl_config { |
| 92 | const struct v4l2_ctrl_ops *ops; |
| 93 | u32 id; |
| 94 | const char *name; |
| 95 | enum v4l2_ctrl_type type; |
| 96 | s32 min; |
| 97 | s32 max; |
| 98 | u32 step; |
| 99 | s32 def; |
| 100 | u32 flags; |
| 101 | u32 menu_skip_mask; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 102 | const char * const *qmenu; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 103 | unsigned int is_private:1; |
Flemmard | 0a7467c | 2013-05-20 14:23:09 -0700 | [diff] [blame] | 104 | unsigned int is_volatile:1; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 105 | }; |
| 106 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 107 | void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, |
| 108 | s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags); |
| 109 | |
| 110 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 111 | int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl, |
| 112 | unsigned nr_of_controls_hint); |
| 113 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 114 | void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); |
| 115 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 116 | int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); |
| 117 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 118 | void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, |
| 119 | const char *prefix); |
| 120 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 121 | struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, |
| 122 | const struct v4l2_ctrl_config *cfg, void *priv); |
| 123 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 124 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, |
| 125 | const struct v4l2_ctrl_ops *ops, |
| 126 | u32 id, s32 min, s32 max, u32 step, s32 def); |
| 127 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 128 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, |
| 129 | const struct v4l2_ctrl_ops *ops, |
| 130 | u32 id, s32 max, s32 mask, s32 def); |
| 131 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 132 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, |
| 133 | struct v4l2_ctrl *ctrl); |
| 134 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 135 | int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, |
| 136 | struct v4l2_ctrl_handler *add); |
| 137 | |
| 138 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 139 | void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls); |
| 140 | |
| 141 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 142 | struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); |
| 143 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 144 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active); |
| 145 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 146 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); |
| 147 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 148 | static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) |
| 149 | { |
| 150 | mutex_lock(&ctrl->handler->lock); |
| 151 | } |
| 152 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 153 | static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) |
| 154 | { |
| 155 | mutex_unlock(&ctrl->handler->lock); |
| 156 | } |
| 157 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 158 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); |
| 159 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 160 | int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); |
| 161 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 162 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 163 | int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc); |
| 164 | int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm); |
| 165 | int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); |
Flemmard | 0a7467c | 2013-05-20 14:23:09 -0700 | [diff] [blame] | 166 | int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 167 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); |
| 168 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); |
Flemmard | 0a7467c | 2013-05-20 14:23:09 -0700 | [diff] [blame] | 169 | int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 170 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 171 | int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc); |
| 172 | int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm); |
| 173 | int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); |
| 174 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); |
| 175 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); |
| 176 | int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); |
| 177 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); |
| 178 | |
| 179 | #endif |