Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 1 | /* |
| 2 | * include/media/v4l2-int-device.h |
| 3 | * |
| 4 | * V4L2 internal ioctl interface. |
| 5 | * |
| 6 | * Copyright (C) 2007 Nokia Corporation. |
| 7 | * |
| 8 | * Contact: Sakari Ailus <sakari.ailus@nokia.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * version 2 as published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 22 | * 02110-1301 USA |
| 23 | */ |
| 24 | |
| 25 | #ifndef V4L2_INT_DEVICE_H |
| 26 | #define V4L2_INT_DEVICE_H |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | #include <media/v4l2-common.h> |
| 30 | |
| 31 | #define V4L2NAMESIZE 32 |
| 32 | |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 33 | /* |
| 34 | * |
| 35 | * The internal V4L2 device interface core. |
| 36 | * |
| 37 | */ |
| 38 | |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 39 | enum v4l2_int_type { |
| 40 | v4l2_int_type_master = 1, |
| 41 | v4l2_int_type_slave |
| 42 | }; |
| 43 | |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 44 | struct v4l2_int_device; |
| 45 | |
| 46 | struct v4l2_int_master { |
Sakari Ailus | 2c94a67 | 2007-10-30 05:52:52 -0300 | [diff] [blame] | 47 | int (*attach)(struct v4l2_int_device *slave); |
| 48 | void (*detach)(struct v4l2_int_device *slave); |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *); |
| 52 | typedef int (v4l2_int_ioctl_func_0)(struct v4l2_int_device *); |
| 53 | typedef int (v4l2_int_ioctl_func_1)(struct v4l2_int_device *, void *); |
| 54 | |
| 55 | struct v4l2_int_ioctl_desc { |
| 56 | int num; |
| 57 | v4l2_int_ioctl_func *func; |
| 58 | }; |
| 59 | |
| 60 | struct v4l2_int_slave { |
| 61 | /* Don't touch master. */ |
| 62 | struct v4l2_int_device *master; |
| 63 | |
| 64 | char attach_to[V4L2NAMESIZE]; |
| 65 | |
| 66 | int num_ioctls; |
| 67 | struct v4l2_int_ioctl_desc *ioctls; |
| 68 | }; |
| 69 | |
| 70 | struct v4l2_int_device { |
| 71 | /* Don't touch head. */ |
| 72 | struct list_head head; |
| 73 | |
| 74 | struct module *module; |
| 75 | |
| 76 | char name[V4L2NAMESIZE]; |
| 77 | |
| 78 | enum v4l2_int_type type; |
| 79 | union { |
| 80 | struct v4l2_int_master *master; |
| 81 | struct v4l2_int_slave *slave; |
| 82 | } u; |
| 83 | |
| 84 | void *priv; |
| 85 | }; |
| 86 | |
Sakari Ailus | 36499e5 | 2008-10-18 12:28:36 -0300 | [diff] [blame] | 87 | void v4l2_int_device_try_attach_all(void); |
| 88 | |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 89 | int v4l2_int_device_register(struct v4l2_int_device *d); |
| 90 | void v4l2_int_device_unregister(struct v4l2_int_device *d); |
| 91 | |
| 92 | int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd); |
| 93 | int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg); |
| 94 | |
| 95 | /* |
| 96 | * |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 97 | * Types and definitions for IOCTL commands. |
| 98 | * |
| 99 | */ |
| 100 | |
Sakari Ailus | 8438991 | 2008-10-18 12:27:50 -0300 | [diff] [blame] | 101 | enum v4l2_power { |
| 102 | V4L2_POWER_OFF = 0, |
| 103 | V4L2_POWER_ON, |
| 104 | V4L2_POWER_STANDBY, |
| 105 | }; |
| 106 | |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 107 | /* Slave interface type. */ |
| 108 | enum v4l2_if_type { |
Sakari Ailus | 08256ea | 2007-08-30 09:20:39 -0300 | [diff] [blame] | 109 | /* |
| 110 | * Parallel 8-, 10- or 12-bit interface, used by for example |
| 111 | * on certain image sensors. |
| 112 | */ |
| 113 | V4L2_IF_TYPE_BT656, |
| 114 | }; |
| 115 | |
| 116 | enum v4l2_if_type_bt656_mode { |
| 117 | /* |
| 118 | * Modes without Bt synchronisation codes. Separate |
| 119 | * synchronisation signal lines are used. |
| 120 | */ |
| 121 | V4L2_IF_TYPE_BT656_MODE_NOBT_8BIT, |
| 122 | V4L2_IF_TYPE_BT656_MODE_NOBT_10BIT, |
| 123 | V4L2_IF_TYPE_BT656_MODE_NOBT_12BIT, |
| 124 | /* |
| 125 | * Use Bt synchronisation codes. The vertical and horizontal |
| 126 | * synchronisation is done based on synchronisation codes. |
| 127 | */ |
| 128 | V4L2_IF_TYPE_BT656_MODE_BT_8BIT, |
| 129 | V4L2_IF_TYPE_BT656_MODE_BT_10BIT, |
| 130 | }; |
| 131 | |
| 132 | struct v4l2_if_type_bt656 { |
| 133 | /* |
| 134 | * 0: Frame begins when vsync is high. |
| 135 | * 1: Frame begins when vsync changes from low to high. |
| 136 | */ |
| 137 | unsigned frame_start_on_rising_vs:1; |
| 138 | /* Use Bt synchronisation codes for sync correction. */ |
| 139 | unsigned bt_sync_correct:1; |
| 140 | /* Swap every two adjacent image data elements. */ |
| 141 | unsigned swap:1; |
| 142 | /* Inverted latch clock polarity from slave. */ |
| 143 | unsigned latch_clk_inv:1; |
| 144 | /* Hs polarity. 0 is active high, 1 active low. */ |
| 145 | unsigned nobt_hs_inv:1; |
| 146 | /* Vs polarity. 0 is active high, 1 active low. */ |
| 147 | unsigned nobt_vs_inv:1; |
| 148 | enum v4l2_if_type_bt656_mode mode; |
| 149 | /* Minimum accepted bus clock for slave (in Hz). */ |
| 150 | u32 clock_min; |
| 151 | /* Maximum accepted bus clock for slave. */ |
| 152 | u32 clock_max; |
| 153 | /* |
| 154 | * Current wish of the slave. May only change in response to |
| 155 | * ioctls that affect image capture. |
| 156 | */ |
| 157 | u32 clock_curr; |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct v4l2_ifparm { |
| 161 | enum v4l2_if_type if_type; |
| 162 | union { |
Sakari Ailus | 08256ea | 2007-08-30 09:20:39 -0300 | [diff] [blame] | 163 | struct v4l2_if_type_bt656 bt656; |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 164 | } u; |
| 165 | }; |
| 166 | |
| 167 | /* IOCTL command numbers. */ |
| 168 | enum v4l2_int_ioctl_num { |
| 169 | /* |
| 170 | * |
| 171 | * "Proper" V4L ioctls, as in struct video_device. |
| 172 | * |
| 173 | */ |
| 174 | vidioc_int_enum_fmt_cap_num = 1, |
| 175 | vidioc_int_g_fmt_cap_num, |
| 176 | vidioc_int_s_fmt_cap_num, |
| 177 | vidioc_int_try_fmt_cap_num, |
| 178 | vidioc_int_queryctrl_num, |
| 179 | vidioc_int_g_ctrl_num, |
| 180 | vidioc_int_s_ctrl_num, |
Sameer Venkatraman | 621a373 | 2008-10-18 12:25:28 -0300 | [diff] [blame] | 181 | vidioc_int_cropcap_num, |
| 182 | vidioc_int_g_crop_num, |
| 183 | vidioc_int_s_crop_num, |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 184 | vidioc_int_g_parm_num, |
| 185 | vidioc_int_s_parm_num, |
Vaibhav Hiremath | 67bc04d | 2008-12-05 10:13:40 -0300 | [diff] [blame] | 186 | vidioc_int_querystd_num, |
| 187 | vidioc_int_s_std_num, |
| 188 | vidioc_int_s_video_routing_num, |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * |
| 192 | * Strictly internal ioctls. |
| 193 | * |
| 194 | */ |
| 195 | /* Initialise the device when slave attaches to the master. */ |
| 196 | vidioc_int_dev_init_num = 1000, |
| 197 | /* Delinitialise the device at slave detach. */ |
| 198 | vidioc_int_dev_exit_num, |
Sakari Ailus | 8438991 | 2008-10-18 12:27:50 -0300 | [diff] [blame] | 199 | /* Set device power state. */ |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 200 | vidioc_int_s_power_num, |
Sakari Ailus | 96014a9 | 2008-10-18 12:23:45 -0300 | [diff] [blame] | 201 | /* |
| 202 | * Get slave private data, e.g. platform-specific slave |
| 203 | * configuration used by the master. |
| 204 | */ |
| 205 | vidioc_int_g_priv_num, |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 206 | /* Get slave interface parameters. */ |
| 207 | vidioc_int_g_ifparm_num, |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 208 | /* Does the slave need to be reset after VIDIOC_DQBUF? */ |
| 209 | vidioc_int_g_needs_reset_num, |
Sakari Ailus | f496bc7 | 2008-10-18 12:29:15 -0300 | [diff] [blame] | 210 | vidioc_int_enum_framesizes_num, |
| 211 | vidioc_int_enum_frameintervals_num, |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * |
| 215 | * VIDIOC_INT_* ioctls. |
| 216 | * |
| 217 | */ |
| 218 | /* VIDIOC_INT_RESET */ |
| 219 | vidioc_int_reset_num, |
| 220 | /* VIDIOC_INT_INIT */ |
| 221 | vidioc_int_init_num, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 222 | /* VIDIOC_DBG_G_CHIP_IDENT */ |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 223 | vidioc_int_g_chip_ident_num, |
| 224 | |
| 225 | /* |
| 226 | * |
| 227 | * Start of private ioctls. |
| 228 | * |
| 229 | */ |
| 230 | vidioc_int_priv_start_num = 2000, |
| 231 | }; |
| 232 | |
| 233 | /* |
| 234 | * |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 235 | * IOCTL wrapper functions for better type checking. |
| 236 | * |
| 237 | */ |
| 238 | |
| 239 | #define V4L2_INT_WRAPPER_0(name) \ |
| 240 | static inline int vidioc_int_##name(struct v4l2_int_device *d) \ |
| 241 | { \ |
| 242 | return v4l2_int_ioctl_0(d, vidioc_int_##name##_num); \ |
| 243 | } \ |
| 244 | \ |
| 245 | static inline struct v4l2_int_ioctl_desc \ |
| 246 | vidioc_int_##name##_cb(int (*func) \ |
| 247 | (struct v4l2_int_device *)) \ |
| 248 | { \ |
| 249 | struct v4l2_int_ioctl_desc desc; \ |
| 250 | \ |
| 251 | desc.num = vidioc_int_##name##_num; \ |
| 252 | desc.func = (v4l2_int_ioctl_func *)func; \ |
| 253 | \ |
| 254 | return desc; \ |
| 255 | } |
| 256 | |
| 257 | #define V4L2_INT_WRAPPER_1(name, arg_type, asterisk) \ |
| 258 | static inline int vidioc_int_##name(struct v4l2_int_device *d, \ |
| 259 | arg_type asterisk arg) \ |
| 260 | { \ |
| 261 | return v4l2_int_ioctl_1(d, vidioc_int_##name##_num, \ |
Sakari Ailus | 63116fe | 2007-07-20 13:12:51 -0300 | [diff] [blame] | 262 | (void *)(unsigned long)arg); \ |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 263 | } \ |
| 264 | \ |
| 265 | static inline struct v4l2_int_ioctl_desc \ |
| 266 | vidioc_int_##name##_cb(int (*func) \ |
| 267 | (struct v4l2_int_device *, \ |
| 268 | arg_type asterisk)) \ |
| 269 | { \ |
| 270 | struct v4l2_int_ioctl_desc desc; \ |
| 271 | \ |
| 272 | desc.num = vidioc_int_##name##_num; \ |
| 273 | desc.func = (v4l2_int_ioctl_func *)func; \ |
| 274 | \ |
| 275 | return desc; \ |
| 276 | } |
| 277 | |
| 278 | V4L2_INT_WRAPPER_1(enum_fmt_cap, struct v4l2_fmtdesc, *); |
| 279 | V4L2_INT_WRAPPER_1(g_fmt_cap, struct v4l2_format, *); |
| 280 | V4L2_INT_WRAPPER_1(s_fmt_cap, struct v4l2_format, *); |
| 281 | V4L2_INT_WRAPPER_1(try_fmt_cap, struct v4l2_format, *); |
| 282 | V4L2_INT_WRAPPER_1(queryctrl, struct v4l2_queryctrl, *); |
| 283 | V4L2_INT_WRAPPER_1(g_ctrl, struct v4l2_control, *); |
| 284 | V4L2_INT_WRAPPER_1(s_ctrl, struct v4l2_control, *); |
Sameer Venkatraman | 621a373 | 2008-10-18 12:25:28 -0300 | [diff] [blame] | 285 | V4L2_INT_WRAPPER_1(cropcap, struct v4l2_cropcap, *); |
| 286 | V4L2_INT_WRAPPER_1(g_crop, struct v4l2_crop, *); |
| 287 | V4L2_INT_WRAPPER_1(s_crop, struct v4l2_crop, *); |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 288 | V4L2_INT_WRAPPER_1(g_parm, struct v4l2_streamparm, *); |
| 289 | V4L2_INT_WRAPPER_1(s_parm, struct v4l2_streamparm, *); |
Vaibhav Hiremath | 67bc04d | 2008-12-05 10:13:40 -0300 | [diff] [blame] | 290 | V4L2_INT_WRAPPER_1(querystd, v4l2_std_id, *); |
| 291 | V4L2_INT_WRAPPER_1(s_std, v4l2_std_id, *); |
| 292 | V4L2_INT_WRAPPER_1(s_video_routing, struct v4l2_routing, *); |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 293 | |
| 294 | V4L2_INT_WRAPPER_0(dev_init); |
| 295 | V4L2_INT_WRAPPER_0(dev_exit); |
Sakari Ailus | 8438991 | 2008-10-18 12:27:50 -0300 | [diff] [blame] | 296 | V4L2_INT_WRAPPER_1(s_power, enum v4l2_power, ); |
Sakari Ailus | 96014a9 | 2008-10-18 12:23:45 -0300 | [diff] [blame] | 297 | V4L2_INT_WRAPPER_1(g_priv, void, *); |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame] | 298 | V4L2_INT_WRAPPER_1(g_ifparm, struct v4l2_ifparm, *); |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 299 | V4L2_INT_WRAPPER_1(g_needs_reset, void, *); |
Sakari Ailus | f496bc7 | 2008-10-18 12:29:15 -0300 | [diff] [blame] | 300 | V4L2_INT_WRAPPER_1(enum_framesizes, struct v4l2_frmsizeenum, *); |
| 301 | V4L2_INT_WRAPPER_1(enum_frameintervals, struct v4l2_frmivalenum, *); |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 302 | |
| 303 | V4L2_INT_WRAPPER_0(reset); |
| 304 | V4L2_INT_WRAPPER_0(init); |
| 305 | V4L2_INT_WRAPPER_1(g_chip_ident, int, *); |
| 306 | |
| 307 | #endif |