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 { |
| 47 | int (*attach)(struct v4l2_int_device *master, |
| 48 | struct v4l2_int_device *slave); |
| 49 | void (*detach)(struct v4l2_int_device *master); |
| 50 | }; |
| 51 | |
| 52 | typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *); |
| 53 | typedef int (v4l2_int_ioctl_func_0)(struct v4l2_int_device *); |
| 54 | typedef int (v4l2_int_ioctl_func_1)(struct v4l2_int_device *, void *); |
| 55 | |
| 56 | struct v4l2_int_ioctl_desc { |
| 57 | int num; |
| 58 | v4l2_int_ioctl_func *func; |
| 59 | }; |
| 60 | |
| 61 | struct v4l2_int_slave { |
| 62 | /* Don't touch master. */ |
| 63 | struct v4l2_int_device *master; |
| 64 | |
| 65 | char attach_to[V4L2NAMESIZE]; |
| 66 | |
| 67 | int num_ioctls; |
| 68 | struct v4l2_int_ioctl_desc *ioctls; |
| 69 | }; |
| 70 | |
| 71 | struct v4l2_int_device { |
| 72 | /* Don't touch head. */ |
| 73 | struct list_head head; |
| 74 | |
| 75 | struct module *module; |
| 76 | |
| 77 | char name[V4L2NAMESIZE]; |
| 78 | |
| 79 | enum v4l2_int_type type; |
| 80 | union { |
| 81 | struct v4l2_int_master *master; |
| 82 | struct v4l2_int_slave *slave; |
| 83 | } u; |
| 84 | |
| 85 | void *priv; |
| 86 | }; |
| 87 | |
| 88 | int v4l2_int_device_register(struct v4l2_int_device *d); |
| 89 | void v4l2_int_device_unregister(struct v4l2_int_device *d); |
| 90 | |
| 91 | int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd); |
| 92 | int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg); |
| 93 | |
| 94 | /* |
| 95 | * |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame^] | 96 | * Types and definitions for IOCTL commands. |
| 97 | * |
| 98 | */ |
| 99 | |
| 100 | /* Slave interface type. */ |
| 101 | enum v4l2_if_type { |
| 102 | }; |
| 103 | |
| 104 | struct v4l2_ifparm { |
| 105 | enum v4l2_if_type if_type; |
| 106 | union { |
| 107 | } u; |
| 108 | }; |
| 109 | |
| 110 | /* IOCTL command numbers. */ |
| 111 | enum v4l2_int_ioctl_num { |
| 112 | /* |
| 113 | * |
| 114 | * "Proper" V4L ioctls, as in struct video_device. |
| 115 | * |
| 116 | */ |
| 117 | vidioc_int_enum_fmt_cap_num = 1, |
| 118 | vidioc_int_g_fmt_cap_num, |
| 119 | vidioc_int_s_fmt_cap_num, |
| 120 | vidioc_int_try_fmt_cap_num, |
| 121 | vidioc_int_queryctrl_num, |
| 122 | vidioc_int_g_ctrl_num, |
| 123 | vidioc_int_s_ctrl_num, |
| 124 | vidioc_int_g_parm_num, |
| 125 | vidioc_int_s_parm_num, |
| 126 | |
| 127 | /* |
| 128 | * |
| 129 | * Strictly internal ioctls. |
| 130 | * |
| 131 | */ |
| 132 | /* Initialise the device when slave attaches to the master. */ |
| 133 | vidioc_int_dev_init_num = 1000, |
| 134 | /* Delinitialise the device at slave detach. */ |
| 135 | vidioc_int_dev_exit_num, |
| 136 | /* Set device power state: 0 is off, non-zero is on. */ |
| 137 | vidioc_int_s_power_num, |
| 138 | /* Get slave interface parameters. */ |
| 139 | vidioc_int_g_ifparm_num, |
| 140 | /* Get external clock speed for current slave settings. */ |
| 141 | vidioc_int_g_ext_clk_num, |
| 142 | /* |
| 143 | * Tell what the generated interface clock speed actually is. |
| 144 | */ |
| 145 | vidioc_int_s_ext_clk_num, |
| 146 | /* Does the slave need to be reset after VIDIOC_DQBUF? */ |
| 147 | vidioc_int_g_needs_reset_num, |
| 148 | |
| 149 | /* |
| 150 | * |
| 151 | * VIDIOC_INT_* ioctls. |
| 152 | * |
| 153 | */ |
| 154 | /* VIDIOC_INT_RESET */ |
| 155 | vidioc_int_reset_num, |
| 156 | /* VIDIOC_INT_INIT */ |
| 157 | vidioc_int_init_num, |
| 158 | /* VIDIOC_INT_G_CHIP_IDENT */ |
| 159 | vidioc_int_g_chip_ident_num, |
| 160 | |
| 161 | /* |
| 162 | * |
| 163 | * Start of private ioctls. |
| 164 | * |
| 165 | */ |
| 166 | vidioc_int_priv_start_num = 2000, |
| 167 | }; |
| 168 | |
| 169 | /* |
| 170 | * |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 171 | * IOCTL wrapper functions for better type checking. |
| 172 | * |
| 173 | */ |
| 174 | |
| 175 | #define V4L2_INT_WRAPPER_0(name) \ |
| 176 | static inline int vidioc_int_##name(struct v4l2_int_device *d) \ |
| 177 | { \ |
| 178 | return v4l2_int_ioctl_0(d, vidioc_int_##name##_num); \ |
| 179 | } \ |
| 180 | \ |
| 181 | static inline struct v4l2_int_ioctl_desc \ |
| 182 | vidioc_int_##name##_cb(int (*func) \ |
| 183 | (struct v4l2_int_device *)) \ |
| 184 | { \ |
| 185 | struct v4l2_int_ioctl_desc desc; \ |
| 186 | \ |
| 187 | desc.num = vidioc_int_##name##_num; \ |
| 188 | desc.func = (v4l2_int_ioctl_func *)func; \ |
| 189 | \ |
| 190 | return desc; \ |
| 191 | } |
| 192 | |
| 193 | #define V4L2_INT_WRAPPER_1(name, arg_type, asterisk) \ |
| 194 | static inline int vidioc_int_##name(struct v4l2_int_device *d, \ |
| 195 | arg_type asterisk arg) \ |
| 196 | { \ |
| 197 | return v4l2_int_ioctl_1(d, vidioc_int_##name##_num, \ |
Sakari Ailus | 63116fe | 2007-07-20 13:12:51 -0300 | [diff] [blame] | 198 | (void *)(unsigned long)arg); \ |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 199 | } \ |
| 200 | \ |
| 201 | static inline struct v4l2_int_ioctl_desc \ |
| 202 | vidioc_int_##name##_cb(int (*func) \ |
| 203 | (struct v4l2_int_device *, \ |
| 204 | arg_type asterisk)) \ |
| 205 | { \ |
| 206 | struct v4l2_int_ioctl_desc desc; \ |
| 207 | \ |
| 208 | desc.num = vidioc_int_##name##_num; \ |
| 209 | desc.func = (v4l2_int_ioctl_func *)func; \ |
| 210 | \ |
| 211 | return desc; \ |
| 212 | } |
| 213 | |
| 214 | V4L2_INT_WRAPPER_1(enum_fmt_cap, struct v4l2_fmtdesc, *); |
| 215 | V4L2_INT_WRAPPER_1(g_fmt_cap, struct v4l2_format, *); |
| 216 | V4L2_INT_WRAPPER_1(s_fmt_cap, struct v4l2_format, *); |
| 217 | V4L2_INT_WRAPPER_1(try_fmt_cap, struct v4l2_format, *); |
| 218 | V4L2_INT_WRAPPER_1(queryctrl, struct v4l2_queryctrl, *); |
| 219 | V4L2_INT_WRAPPER_1(g_ctrl, struct v4l2_control, *); |
| 220 | V4L2_INT_WRAPPER_1(s_ctrl, struct v4l2_control, *); |
| 221 | V4L2_INT_WRAPPER_1(g_parm, struct v4l2_streamparm, *); |
| 222 | V4L2_INT_WRAPPER_1(s_parm, struct v4l2_streamparm, *); |
| 223 | |
| 224 | V4L2_INT_WRAPPER_0(dev_init); |
| 225 | V4L2_INT_WRAPPER_0(dev_exit); |
| 226 | V4L2_INT_WRAPPER_1(s_power, int, ); |
Sakari Ailus | 098c645 | 2007-08-30 09:20:38 -0300 | [diff] [blame^] | 227 | V4L2_INT_WRAPPER_1(g_ifparm, struct v4l2_ifparm, *); |
Sakari Ailus | 9b5d0f1 | 2007-07-18 17:59:15 -0300 | [diff] [blame] | 228 | V4L2_INT_WRAPPER_1(s_ext_clk, u32, ); |
| 229 | V4L2_INT_WRAPPER_1(g_ext_clk, u32, *); |
| 230 | V4L2_INT_WRAPPER_1(g_needs_reset, void, *); |
| 231 | |
| 232 | V4L2_INT_WRAPPER_0(reset); |
| 233 | V4L2_INT_WRAPPER_0(init); |
| 234 | V4L2_INT_WRAPPER_1(g_chip_ident, int, *); |
| 235 | |
| 236 | #endif |